• 重新加载网卡默认驱动


    shell

    #!/bin/bash
    
    N3=enp134s0f0
    N3=0000:86:00.0
    N6=enp134s0f3
    N6=86:00.3
    
    function get_nic_bdf(){
      IFC=$1
      # echo "Load driver for interface: $IFC"
      ls /sys/class/net/$IFC/device > /dev/null
      if [ $? -ne 0 ]; then
        echo "No interface: $IFC. Need to provide the PCI address for $IFC.";
        return 1
      fi
      bdf=`ls /sys/class/net/$IFC/device -l | awk -F'/' '{print $9}'`
      echo $bdf
    }
    
    
    
    function get_nic_bdf(){
      IFC=$1
      # echo "Load driver for interface: $IFC"
      ls /sys/class/net/$IFC/device > /dev/null
      if [ $? -ne 0 ]; then
        echo "No interface: $IFC. Need to provide the PCI address for $IFC.";
        return 1
      fi
      bdf=`ls /sys/class/net/$IFC/device -l | awk -F'/' '{print $9}'`
      echo $bdf
    }
    
    
    function load_driver(){
      addr=$1
      bdf=""
      if [[ $addr =~ ^0{4}:[0-9a-f]{2}:[0-9a-f]{2}.[0-9]$ ]]; then
        bdf=$1
        echo "load driver for PCI device: $addr"
      elif [[ $addr =~ ^[0-9a-f]{2}:[0-9a-f]{2}.[0-9]$ ]]; then
        bdf=0000:$1
        echo "load driver for PCI device: $addr"
      fi
      if [ -z "$bdf" ]; then
        IFC=$1
        echo "Load driver for interface: $IFC"
        ls /sys/class/net/$IFC/device > /dev/null
        if [ $? -ne 0 ]; then
          echo "No BDF found for interface: $IFC, let's guess from the name."
          if [[ $IFC =~ ^.*p[0-9]{1,3}s[0-9]{1,3}f[0-9]$ ]]; then
            bdf=${IFC#*p}
            b=${bdf%%s*}
            b=`printf '%0.2x
    ' $b`
            s=${bdf%%f*}
            s=${s##*s}
            s=`printf '%0.2x
    ' $s`
            f=${bdf##*f}
            bdf="0000:$b:$s.$f"
            echo "Guess interface: $IFC PCI address is $bdf"
          else
            echo "No interface: $IFC. Need to provide the PCI address for $IFC.";
            return 1
          fi
        else
          bdf=`ls /sys/class/net/$IFC/device -l | awk -F'/' '{print $9}'`
        fi
      fi
      path=/sys/bus/pci/devices/$bdf
      VDID=`lspci -nnv |grep ^${bdf#*:} | grep -E -o '[0-9a-f]{4}:[0-9a-f]{4}'`
      DID=${VDID#*:}
      VID=${VDID%:*}
      driver=$(grep "v0000${VID}d0000${DID}" /lib/modules/$(uname -r)/modules.alias |awk '{print $3}')
      cdriver=`ls /sys/bus/pci/devices/0000:88:00.0/driver -l`
      if [ $? -eq 0 ]; then
        cdriver=${cdriver##*/}
        # if [ "$driver" == "$cdriver" ]; then
        #   echo "Driver is $driver, No need to reload, exit."
        #   return 0
        # fi
        if [ -n "$cdriver" ]; then
          echo "Unload $bdf driver: $cdriver"
          echo "echo $bdf | sudo tee /sys/bus/pci/drivers/$cdriver/unbind"
          echo "$bdf" | sudo tee /sys/bus/pci/drivers/$cdriver/unbind
          sleep 1
        fi
      fi
      echo "echo "$VID $DID" | sudo tee /sys/bus/pci/drivers/$driver/new_id"
      echo "$VID $DID" | sudo tee /sys/bus/pci/drivers/$driver/new_id
      echo "echo "${bdf}" > /sys/bus/pci/drivers/$driver/bind"
      echo ${bdf} > /sys/bus/pci/drivers/$driver/bind
      ls -d /sys/bus/pci/drivers/$driver/$bdf
      if [ -f "${path}/driver_override" ]; then
        echo "echo $driver >  ${path}/driver_override"
        echo "$driver" > ${path}/driver_override
      fi
    
      ls -d /sys/bus/pci/drivers/$driver/$bdf
      if [ $? -ne 0 ]; then echo "Bind $driver for $bdf failed"; fi
      cdriver=`ls /sys/bus/pci/devices/0000:88:00.0/driver -l`
      if [ $? -eq 0 ]; then
        cdriver=${cdriver##*/}
        if [ "$driver" == "$cdriver" ]; then
          echo "Load driver: $driver for $bdf successfully."
        fi
      fi
      echo "$bdf, $driver, $VDID"
      echo ""
    }
    
    
    load_driver $N3
    
    load_driver $N6
  • 相关阅读:
    最短路之浇水
    agc031_d A Sequence of Permutations
    loj 3236 [POI2019 R1] Układ scalony
    CodeForces 1237H Balanced Reversals
    CodeForces 1320F Blocks and Sensors
    CodeForces 1340D Nastya and Time Machine
    agc037_f Counting of Subarrays
    nikkei2019_2_qual_e Non-triangular Triplets
    CodeForces 603E Pastoral Oddities
    Vue router / ElementUI,Ant Design Vue 重复点击导航路由报错解决方法
  • 原文地址:https://www.cnblogs.com/shaohef/p/15130951.html
Copyright © 2020-2023  润新知