[嵌入式linux]PCIe 热拔插(rescan)

linux下可通过/sys/bus/pci/devices/0000\:[bus number]\:[device number].[function number]/ 目录下的节点进行热拔插操作。

板子上电前PCIe插槽有一块NVME的固态硬盘

[    0.198515] pci 0000:00:00.0: [16c3:abcd] type 01 class 0x060400
[    0.199284] pci 0000:01:00.0: [126f:2263] type 00 class 0x010802
[    8.161374] nvme nvme0: pci function 0000:01:00.0
[    8.166407] nvme 0000:01:00.0: enabling device (0000 -> 0002)

# ls /sys/bus/pci/devices/0000\:01\:00.0
broken_parity_status      enable                    rescan
class                     irq                       reset
config                    local_cpulist             resource
consistent_dma_mask_bits  local_cpus                subsystem
device                    modalias                  subsystem_device
devspec                   msi_bus                   subsystem_vendor
dma_mask_bits             power                     uevent
driver_override           remove                    vendor

现在需要在板子保持开机运行的状态下,先取下NVME的固态硬盘,再换上一块PCIe 网卡,并让网卡正常工作。

  • remove 原有设备,然后lspci查看, 0000:01:00.0: [126f:2263]已经不见了
# echo 1 > /sys/bus/pci/devices/0000\:01\:00.0/remove
#
# lspci
00:00.0 Class 0604: 16c3:abcd
  • 现在可以从插槽取下固态硬盘,插上网卡
  • 通过上游bus进行rescan
 echo 1 > /sys/bus/pci/devices/0000\:00\:00.0/rescan
[   72.436704] pci 0000:00:00.0: bridge configuration invalid ([bus 00-00]), reconfiguring
[   72.445041] pci 0000:01:00.0: [10ec:8168] type 00 class 0x020000
[   72.451319] pci 0000:01:00.0: reg 0x10: initial BAR value 0x00000000 invalid
[   72.458380] pci 0000:01:00.0: reg 0x10: [io  size 0x0100]
[   72.464113] pci 0000:01:00.0: reg 0x18: [mem 0x00000000-0x00000fff 64bit]
[   72.471112] pci 0000:01:00.0: reg 0x20: [mem 0x00000000-0x00003fff 64bit]
[   72.479299] pci 0000:01:00.0: supports D1 D2
[   72.483583] pci 0000:01:00.0: PME# supported from D0 D1 D2 D3hot D3cold
[   72.490667] pci_bus 0000:01: busn_res: [bus 01] end is updated to 01
[   72.497090] pci 0000:00:00.0: BAR 7: assigned [io  0x1000-0x1fff]
[   72.503202] pci 0000:01:00.0: BAR 4: assigned [mem 0xf1100000-0xf1103fff 64bit]
[   72.510683] pci 0000:01:00.0: BAR 2: assigned [mem 0xf1104000-0xf1104fff 64bit]
[   72.518162] pci 0000:01:00.0: BAR 0: assigned [io  0x1000-0x10ff]
# [   72.569018] r8169 0000:01:00.0: no of_node; not parsing pinctrl DT
[   72.575313] r8169 Gigabit Ethernet driver 2.3LK-NAPI loaded
[   72.580996] r8169 0000:01:00.0: enabling device (0000 -> 0003)
[   72.603261] r8169 0000:01:00.0 eth1: RTL8168h/8111h at 0xc8ea0000, e8:4e:06:72:f5:8a, XID 14100800 IRQ 66
[   72.612886] r8169 0000:01:00.0 eth1: jumbo features [frames: 9200 bytes, tx checksumming: ko]
[   72.846167] r8169 0000:01:00.0: Direct firmware load for rtl_nic/rtl8168h-2.fw failed with error -2
[   72.855262] r8169 0000:01:00.0 eth1: unable to load firmware patch rtl_nic/rtl8168h-2.fw (-2)
[   72.876122] r8169 0000:01:00.0 eth1: link down

 

  • 查看新的网卡设备,多了一个eth1
# lspci
00:00.0 Class 0604: 16c3:abcd
01:00.0 Class 0200: 10ec:8168
#
#
# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:67:AB:81:02:BB
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:16

eth1      Link encap:Ethernet  HWaddr E8:4E:06:72:F5:8A
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

 

  • 7
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值