Added support for changing mellanox mlx4 devices to ethernet to use them as 10g
[bootimage-initfs.git] / etc / hardware.sh
1 #!/bin/ash
2
3 . /etc/library.sh
4
5 # -----------------------------------------------------------------------
6 # load the output file created by the breakin program
7 # -----------------------------------------------------------------------
8 if [ -e /var/run/breakin.dat ]
9 then
10         . /var/run/breakin.dat
11 fi
12
13 # FIXME:
14
15 NET_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/net"
16 SCSI_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/scsi"
17 LIBATA_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/ata"
18 MD_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/md"
19 FUSIONMPT_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/message/fusion"
20 MODULE_PREFIX="/lib/modules/`uname -r`/kernel/drivers"
21 SENSOR_ENABLE=0
22
23 dhcp_on_interface() {
24         INTERFACE=${1}
25
26
27         # this is a stop gap for my laptop
28         if [ "${INTERFACE}" = "ath0" ]
29         then
30                 return 1
31         fi
32
33
34         # work around Cisco portfast implementation not being fast
35
36         if [ "${spantree}" != "" ]
37         then
38                 msg "Sleeping for ${spantree} seconds for spanning tree"
39                 sleep ${spantree}
40         fi
41
42         msg -n "Trying DHCP on ${i} interface"
43
44         /sbin/udhcpc -i ${INTERFACE} -T 5 -n -s /etc/ifup.udhcp.sh \
45                 -p /tmp/dhcp.${INTERFACE}.pid >> /tmp/stdout.log 2>> /tmp/stderr.log
46
47         if [ "$?" = 0 ]
48         then
49                 . /tmp/network.dhcp
50                 ok_msg
51                 return 0
52         else
53                 fail_msg
54                 return 1
55         fi
56 }
57
58
59
60 header "Loading network card modules"
61 for i in `find ${NET_MODULE_PATH} -name \*.ko`
62 do
63         load_module "${i}"
64 done
65
66 header "Switching mlx4 devices to ethernet"
67
68 for i in `find /sys/ -name mlx4_port* 2> /dev/null`
69 do
70
71         msg "Setting ${i} to eth"
72         echo "eth" > $i
73 done
74
75 header "Finding ethernet devices"
76
77 NET_DEVICES=`/sbin/ifconfig -a | grep "^[a-z]" | cut -d" " -f1`
78 NET_DEVICE_COUNT=0
79 NET_DEVICE=""
80
81 for i in ${NET_DEVICES}
82 do
83
84         # we want to skip the loopback interfaces since they don't really count
85         if [ "${i}" = "lo" ]
86         then
87                 continue
88         fi
89
90         NET_DEVICE_COUNT=`expr ${NET_DEVICE_COUNT} + 1`
91
92         /bin/ip link set dev ${i} up
93         /sbin/ifconfig ${i} up
94
95         msg "Sleeping for 15 seconds for link to come up on ${i}"
96         sleep 15
97
98         msg -n "Checking link status for ${i}"
99         LINK=`/usr/bin/ethtool ${i} | grep Link | awk '{print $3}' 2> /dev/null`
100
101         if [ "${LINK}" != "yes" ];
102         then
103                 fail_msg
104         else
105                 ok_msg
106                 dhcp_on_interface ${i}
107                 if [ "$?" = "0" ]
108                 then
109                         NET_DEVICE="${i}"
110                 fi
111         fi
112 done
113
114 if [ "${NET_DEVICE}" = "" ];
115 then
116         msg ""
117         msg "Unable to find interface with link, manually trying each interface"
118         for i in ${NET_DEVICES}
119         do
120                 if [ "${i}" = "lo" ]
121                 then
122                         continue
123                 fi
124
125                 dhcp_on_interface ${i}
126                 if [ "$?" = "0" ]
127                 then
128                         NET_DEVICE="${i}"
129                         break
130                 fi
131         done
132 fi
133
134 #msg -n "Setting hostname to be HW address  "
135 #HOST=`echo ${NET_MACADDR} | sed 's/://g'`
136 #msg -n " ${NET_MACADDR}"
137 #hostname ${HOST} >> /tmp/stdout.log 2> /tmp/stderr.log
138 #if [ "$?" = 0 ]
139 #then
140         #ok_msg
141 #else
142         #fail_msg
143 #fi
144
145 for i in /lib/modules/`uname -r`/kernel/drivers/edac/*
146 do
147         MOD_NAME=`basename ${i} | cut -d"." -f1`
148         modprobe_module ${MOD_NAME}
149 done
150
151 for i in /lib/modules/`uname -r`/kernel/drivers/i2c/busses/*
152 do
153         MOD_NAME=`basename ${i} | cut -d"." -f1`
154         modprobe_module ${MOD_NAME}
155 done
156
157 # XXX: this may cause lockups, if so we need a better way
158 header "Loading all SCSI/SATA disk modules"
159
160 for i in `find ${LIBATA_MODULE_PATH} ${SCSI_MODULE_PATH} ${FUSIONMPT_MODULE_PATH} ${MD_MODULE_PATH} -name \*.ko`
161 do
162         MOD_NAME=`basename ${i} | cut -d"." -f1`
163         modprobe_module ${MOD_NAME}
164 done
165
166 header "Loading other modules"
167 for i in `cat /etc/modules_other.conf`
168 do
169         modprobe_module ${i}    
170 done
171
172 msg "Waiting 10 seconds for block devices to settle."
173 sleep 10
174
175 # mount a logging device
176 . /etc/logdev.sh
177
178 . /etc/hardware_output.sh