Linux Usb Driver Probe Not Called If Device Already Plugged

Linux USB driver probe not called if device already plugged

Some software from us was opening the device from /proc/bus/usb and the device was claimed by the usbfs driver, so the new driver couldn't claim the device.

Linux USB driver probe() problem

If it is the USB mass storage driver stealing it before you get a chance you might want to blacklist the VID/PID for the device with that driver.

Since you mentioned it's a USB WiMAX adapter I'm going to have a wild guess though that it's presenting a USB mass storage device that contains a driver for it on Windows. If that's the case you would be better off working with USB Modeswitch, which already handles this for 3G modems. Typically the devices expect some magic bytes (which often is actually a SCSI eject command) to persuade them to stop being mass storage devices and become the real modem. (That has a different PID normally too).

Even if your device can't be persuaded to show the real device instead of the driver with one of the existing USB Modeswitch rules it would be more appropriate to fix the problem with that than a kernel hack.

Doing it with USB Modeswitch has a number of advantages over what you proposed:

  1. Keeps everything modular:
    1. Your driver only has to care about WiMAX and one VID/PID for the device
    2. The mass storage driver doesn't need to care about crazy devices - it just looks like plugging and unplugging a device. Teaching the mass storage driver about every single one of these sort of devices isn't appropriate, your device doesn't seem to be a special case.
    3. The knowledge about the split personalities of the device is only relevant to USB Modeswitch, which only exists to solve this problem.
  2. It doesn't break the USB mass storage aspects of the device - users might want to view the Windows driver under Linux for some reason, blacklisting this device would make that impossible. This might be important if you end up using some firmware shipped with the Windows driver under Linux too.
  3. It follows the existing setup and keeps your changes local to your module. This might well be important if you want to get your driver in the mainline kernel ever.

When does the probe function for a Linux kernel driver gets called?

Found the answer after some research, For a "platform" device the probe function is invoked when a platform device is registered and it's device name matchs the name specified on the device driver.

More details here:
http://comments.gmane.org/gmane.linux.kernel.kernelnewbies/37050

Now I just need to figure why the device is not being registered :\

How to load a module (not a driver) when a USB device is plugged in

In modern Linux the functionality for loading drivers/modules (or invoking any other commands) whenever new hardware is detected is handled by udev. You will have to write a udev rule for your device that will instruct the kernel to load your module when your device has been detected and the corresponding event has occurred. Read more about it here.

Determining filesystem for block device if module not loaded

In short: Unless some user space configuration file is aware of a filesystem, mount will fail to auto-detect this filesystem if its driver is not loaded.

.. usually the kernel tries to probe the different filesystems by calling the appropiate *_fill_super function of the respective module.

This is not quite true. The mount system call accepts filesystem name as a parameter, and this parameter is required for all cases except re-mount, which is out of scope of the current question. Moreover, the filesystem driver is expected to be already loaded at the time mount system call is performed.

That is, the kernel by itself never "probes" a filesystems, the kernel just tries the filesystem requested by the user space.

Actually, it is user space tool mount which performs probing.

Before probing, the mount tool could attempts to deduce a filesystem by inspecting /etc/fstab, by using blkid or other mechanisms.

After all deducing mechanisms have failed, the mount tool probes filesystems according to /etc/filesystems file. This file could contain a predefined (static) list of filesystems.

After attempts for every line in /etc/filesystems have failed (or if the file doesn't exist), the mount tool probes filesystems listed in /proc/filesystems. This file is provided by the kernel and contains all filesystems which are registered (for which a driver is loaded).

After attempts for every line in /proc/filesystems have failed, the mount tool reports an error.


The algorithm of choosing a filesystem by the mount tool is described in man mount under the paragraph "If no -t option is given ..". The question and its answers describe similar things.



Related Topics



Leave a reply



Submit