Add loading of VNIC driver and creation of VNIC interfaces
to openibd

Signed-off-by: Ramachandra K <ramachandra.kuchimanchi@qlogic.com>
---

 ofed_scripts/ofa_kernel.spec |    6 ++++++
 ofed_scripts/openibd         |   37 ++++++++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/ofed_scripts/ofa_kernel.spec b/ofed_scripts/ofa_kernel.spec
index 738adaf..505bfa6 100755
--- a/ofed_scripts/ofa_kernel.spec
+++ b/ofed_scripts/ofa_kernel.spec
@@ -508,6 +508,12 @@ fi
        echo "RDS_LOAD=no" >> %{IB_CONF_DIR}/openib.conf
 %endif
 
+%if %{build_vnic}
+       echo >> %{IB_CONF_DIR}/openib.conf
+       echo "# Load VNIC module" >> %{IB_CONF_DIR}/openib.conf
+       echo "VNIC_LOAD=yes" >> %{IB_CONF_DIR}/openib.conf
+%endif
+
 fi # 1 : closed
 # END of post -n kernel-ib
 
diff --git a/ofed_scripts/openibd b/ofed_scripts/openibd
index 39e1e60..ed440b5 100755
--- a/ofed_scripts/openibd
+++ b/ofed_scripts/openibd
@@ -227,7 +227,7 @@ POST_LOAD_MODULES=""
 if [ "X${SDP_LOAD}" == "Xyes" ]; then
     POST_LOAD_MODULES="$POST_LOAD_MODULES ib_sdp"
     IPOIB_LOAD="yes"
-fi    
+fi
 
 IPOIB=0
 IPOIB_MTU=${IPOIB_MTU:-65520}
@@ -239,6 +239,10 @@ if [ "X${SRP_LOAD}" == "Xyes" ]; then
     POST_LOAD_MODULES="$POST_LOAD_MODULES ib_srp"
 fi    
 
+if [ "X${VNIC_LOAD}" == "Xyes" ]; then
+    POST_LOAD_MODULES="$POST_LOAD_MODULES ib_vnic"
+fi
+
 if [ "X${SRP_TARGET_LOAD}" == "Xyes" ]; then
     POST_LOAD_MODULES="$POST_LOAD_MODULES ib_srp_target"
 fi    
@@ -265,11 +269,11 @@ fi
 
 GEN1_UNLOAD_MODULES="ib_srp_target scsi_target ib_srp kdapltest_module ib_kdapl ib_sdp ib_useraccess ib_useraccess_cm ib_cm ib_dapl_srv ib_ip2pr ib_ipoib ib_tavor mod_thh mod_rhh ib_dm_client ib_sa_client ib_client_query ib_poll ib_mad ib_core ib_services"
 
-UNLOAD_MODULES="ib_ipoib ib_madeye ib_rds rds ib_ucm kdapl ib_srp_target scsi_target ib_srp"
+UNLOAD_MODULES="ib_ipoib ib_madeye ib_rds rds ib_ucm kdapl ib_srp_target scsi_target ib_srp ib_vnic"
 UNLOAD_MODULES="$UNLOAD_MODULES ib_iser ib_sdp rdma_ucm rdma_cm ib_addr ib_cm ib_local_sa findex"
 UNLOAD_MODULES="$UNLOAD_MODULES ib_sa ib_uverbs ib_umad ib_mthca ib_ipath ipath_core ib_ehca ib_mad ib_core"
 
-STATUS_MODULES="rdma_ucm ib_rds rds ib_srp ib_sdp rdma_cm ib_addr ib_local_sa findex ib_ipoib ib_ehca ib_ipath ipath_core ib_mthca ib_uverbs ib_umad ib_ucm ib_sa ib_cm ib_mad ib_core"
+STATUS_MODULES="rdma_ucm ib_rds rds ib_srp ib_vnic ib_sdp rdma_cm ib_addr ib_local_sa findex ib_ipoib ib_ehca ib_ipath ipath_core ib_mthca ib_uverbs ib_umad ib_ucm ib_sa ib_cm ib_mad ib_core"
 
 ipoib_ha_pidfile=/var/run/ipoib_ha.pid
 srp_daemon_pidfile=/var/run/srp_daemon.pid
@@ -850,6 +854,33 @@ EOF
             fi
     fi
 
+   # Create vnic interfaces. This needs to be done after udevstart
+    if [ X${VNIC_LOAD} == "Xyes" ]; then
+            if [[ ! -e /dev/infiniband/umad0  &&  ! -e /dev/infiniband/umad1 ]]; then
+                echo "/dev/infiniband/umad0 or /dev/infiniband/umad1 not present."
+                echo "Cannot create VNIC interfaces."
+                echo_failure $"Bringing up VNIC interfaces"
+            elif is_module ib_vnic; then
+                echo "Setting up VNIC interfaces..."
+                vnic_parser.pl -v > /dev/null 2>&1
+                res=$?
+                if [ $res != 0 ]; then
+                    if [ $res == 2 ]; then
+                        echo "Created VNIC interfaces but with errors. Please refer to /var/log/messages."
+                        echo_failure $"Bringing up VNIC interfaces"
+                    else
+                        echo "Error in parsing VNIC configuration file. Please refer to /var/log/messages."
+                        echo_failure $"Bringing up VNIC interfaces"
+                    fi
+                else
+                    echo_success $"Bringing up VNIC interfaces"
+                fi
+            else
+                echo "Module ib_vnic not loaded."
+                echo_failure $"Bringing up VNIC interfaces"
+            fi
+    fi
+
     if [ X${RENICE_IB_MAD} == "Xyes" ]; then
         # Set max_ports_num_in_hca variable
         count_ib_ports
