Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unload kernel module for only a specific device (preferrably from code in another kernel module)

I'm working on a project where I have a management system that exports PCIe hardware devices to other systems via PCI Express. I have a working management kernel module but need to find a way to ensure that a device I export doesn't have a driver already loaded for it on the management system. Without that, the device will end up with conflicts since the same driver will be accessing it from 2 different systems & obviously cause problems.

For example, assume I have a dual-port Intel 100MBps NIC device installed on the Manager which will show up 2 PCIe Endpoints in the system (eg Fn 0 & 1). The Intel module e1000 will be loaded for both devices. If I want to export port 2 of that device to another system, I would like to "detach" it from the e1000 module.

Does anyone know a clean way of doing this without hacking the kernel or tweaking the e1000's driver's probe function? I can't simply do an rmmod because that will remove the module all-together for both NIC devices. I would like the NIC I'm not exporting to remain functional in the Management system with the e1000 driver still loaded for it.

Essentially, rmmod does this but will remove the driver for all devices probed for & owned by the driver. Any way to tell Linux just "unload module for only this specific device"? On Windows, I guess this would be the equivalent of right-clicking on a device in Device Manager & select "Disable".

like image 465
user3015665 Avatar asked Nov 21 '13 02:11

user3015665


1 Answers

You can disable driver for your device by writting following method:

  • Use sudo -i or before any command write sudo to operate as root user.And follow below procedure:
  • Goto /sys/bus/pci/<driver_name>/ folder.
  • Give command echo -n 0000:03:00.1 > unbind
  • Where 0000:03:00.1 is device you want to detech your driver.
  • Read this link for getting idea about sysfs for pci bus.
like image 190
RDX Avatar answered Nov 15 '22 09:11

RDX