Linux drivers manually bind and Unbind

Source: Internet
Author: User
Tags volatile

Starting with 2.6.13-RC3, the Linux kernel provides the ability to dynamically bind and Unbind devices and device drivers in user space. Prior to this, the insmod can only be bound and reconciled through the modprobe and rmmod, and this binding and bundling is for the driver and all devices. The new feature can set the connection between the driver and the individual device.
Here, we take the NVMe SSD for PCI bus as an example, first execute LSPCI display all NVMe SSDs.

# Lspci | grep memory01:00.0 non-volatile Memory Controller:samsung Electronics Co Ltd Device a802 (rev.) 09:00.0 Non-volatile Mem Ory Controller:samsung Electronics Co Ltd Device a802 (rev. 01)

Like so many NVMe SSDs, we can see multiple nvme devices in/dev (the default loading of NVME drivers after OS boot).

# LS/DEV/NVME*/DEV/NVME0/DEV/NVME0N1P2/DEV/NVME0N1/DEV/NVME0N1P3/DEV/NVME0N1P1/DEV/NVME1/DEV/NVME1N1

At the same time, for all nvme devices (here we take the PCI bus BDF number 09:00.0 SSD as an example), can be seen under the NVMe drive. Of these, bind and unbind files are key files that involve binding and unbinding.

/sys/bus/pci/drivers/nvme# lltotal 0drwxr-xr-x  2 root root     0 Jan  4 17:10 ./drwxr-xr-x 30 root root     0 JAN  4 17:10&NBSP, .... /lrwxrwxrwx  1 root root    0 jan  4 20:49  0000:01:00.0 ->&NBSP, .... /.. /.. /.. /devices/pci0000:00/0000:00:01.0/0000:01:00.0/lrwxrwxrwx  1 root root     0 JAN  4 20:49 0000:09:00.0 ->&NBSP, .... /.. /.. /.. /devices/pci0000:00/0000:00:03.0/0000:05:00.0/0000:06:0a.0/0000:07:00.0/0000:08:01.0/0000:09:00.0/--w-------   1 root root 4096 jan  4 20:46 bindlrwxrwxrwx  1  ROOT ROOT    0 JAN  4 20:49 MODULE ->&NBSP, .... /.. /.. /.. /module/nvme/--w-------  1 root root 4096 jan  4 20:49 new_id--w-------  1 root root 4096 jan   4 20:49 remove_id--w-------  1 root root 4096 Jan   4 17:10 uevent--w-------  1 root root 4096 jan  4  17:10 unbind

to unbind a nvme device, simply write the PCI bus BDF number of the device to/SYS/BUS/PCI/DRIVERS/NVME (different device drivers are different)/unbind:

/sys/bus/pci/drivers/nvme# echo -n  "0000:09:00.0"  > unbind unbind successfully, then view the file under directory, The driver no longer has the corresponding device. At the same time, there is no corresponding nvme device in/dev. /sys/bus/pci/drivers/nvme# lltotal 0drwxr-xr-x  2 root root     0 Jan  4 20:51 ./drwxr-xr-x 30 root root     0 JAN  4 20:49&NBSP, .... /lrwxrwxrwx  1 root root    0 jan  4 20:49  0000:01:00.0 ->&NBSP, .... /.. /.. /.. /devices/pci0000:00/0000:00:01.0/0000:01:00.0/--w-------  1 root root 4096 jan   4 20:46 bindlrwxrwxrwx  1 root root    0  JAN  4 20:49 MODULE ->&NBSP, .... /.. /.. /.. /module/nvme/--w-------  1 root root 4096 jan  4 20:49 new_ Id--w-------  1 root root 4096 jan  4 20:49 remove_id--w-------  1 root root 4096 Jan   4 20:49 uevent--w-------  1 root root 4096 jan  4  20:51 unbind

bind a nvme device, and, similarly, write the PCI bus BDF number of the device to/SYS/BUS/PCI/DRIVERS/NVME (different device drivers are different)/bind:

/sys/bus/pci/drivers/nvme# echo -n  "0000:09:00.0"  > bind The binding succeeds, showing all the files in that directory again, You can see that the corresponding device appears again. /sys/bus/pci/drivers/nvme# lltotal 0/sys/bus/pci/drivers/nvme# lltotal 0drwxr-xr-x   2 root root    0 Jan  5 09:13 ./drwxr-xr-x  30 ROOT ROOT    0 JAN  4 20:49&NBSP, .... /lrwxrwxrwx  1 root root    0 jan  4 20:49  0000:01:00.0 ->&NBSP, .... /.. /.. /.. /devices/pci0000:00/0000:00:01.0/0000:01:00.0/lrwxrwxrwx  1 root root     0 JAN  5 09:13 0000:09:00.0 ->&NBSP, .... /.. /.. /.. /devices/pci0000:00/0000:00:03.0/0000:05:00.0/0000:06:0a.0/0000:07:00.0/0000:08:01.0/0000:09:00.0/--w-------   1 root root 4096 jan  5 09:13 bindlrwxrwxrwx  1  root root&nBSP;   0 JAN  4 20:49 MODULE ->&NBSP, .... /.. /.. /.. /module/nvme/--w-------  1 root root 4096 jan  4 20:49 new_ Id--w-------  1 root root 4096 jan  4 20:49 remove_ id--w-------  1 root root 4096 jan  4 20:49 uevent--w-------   1 root root 4096 jan  4 20:51 unbind


Linux drivers manually bind and Unbind

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.