DISCLAIMER. English language used here only for compatibility (ASCII only), so any suggestions about my bad grammar (and not only it) will be greatly appreciated.

вторник, 1 февраля 2011 г.

Intel AMT IDE Redirection and linux

(updated version)

    Shortly: it works -)

    Now with more details.  Module 'ata_generic' (CONFIG_ATA_GENERIC) may drive
    IDER controller.  Though, it will not take over this device without option
    'all_generic_ide=1' (perhaps, because IDER controller match with "any"
    alias, but not device-specific one?):

        # modinfo ata_generic
        ..
        alias:          pci:v*d*sv*sd*bc01sc01i*
        ..

    So, we should load it like

        # modprobe ata_generic all_generic_ide=1

    Now we can check, that it successfully takes over IDER controller

        # lspci -nn | grep IDER
        00:03.2 IDE interface [0101]: Intel Corporation Mobile PM965/GM965 PT IDER Controller [8086:2a06] (rev 0c)
        # ls -l /sys/bus/pci/devices/0000:00:03.2/driver
        lrwxrwxrwx 1 root root 0 Jan 31 17:44 /sys/bus/pci/devices/0000:00:03.2/driver -> ../../../bus/pci/drivers/ata_generic

    But in order to have kernel see scsi targets on this IDER controller, we
    need to enable IDE Redirection in remote management console (you may use
    Manageability Commander Tool from Intel Manageability Developer Tool Kit
    for testing). There will be two scsi targets on this scsi host: floppy
    (bus=0, id=0, lun=0)  and cdrom (bus=0, id=1, lun=0). Floppy will be
    handled by sd, and cdrom by sr_mod:

        # ls -l /sys/bus/pci/devices/0000:00:03.2/host21/
        total 0
        drwxr-xr-x 2 root root    0 Jan 31 18:16 power
        drwxr-xr-x 3 root root    0 Jan 31 18:16 scsi_host
        lrwxrwxrwx 1 root root    0 Jan 31 17:44 subsystem -> ../../../../bus/scsi
        drwxr-xr-x 4 root root    0 Jan 31 17:44 target21:0:0
        drwxr-xr-x 4 root root    0 Jan 31 17:44 target21:0:1
        -rw-r--r-- 1 root root 4096 Jan 31 17:44 uevent
        # ls -l /sys/bus/pci/devices/0000:00:03.2/host21/target21:0:0/21:0:0:0/driver
        lrwxrwxrwx 1 root root 0 Jan 31 17:44 /sys/bus/pci/devices/0000:00:03.2/host21/target21:0:0/21:0:0:0/driver -> ../../../../../../bus/scsi/drivers/sd
        # ls -l /sys/bus/pci/devices/0000:00:03.2/host21/target21:0:1/21:0:1:0/driver
        lrwxrwxrwx 1 root root 0 Jan 31 17:45 /sys/bus/pci/devices/0000:00:03.2/host21/target21:0:1/21:0:1:0/driver -> ../../../../../../bus/scsi/drivers/sr

    And now the only left is to make these modules autoload during boot.  Here
    is one thing to note: we should load all specific ata modules (for other
    hardware, if any) _before_ 'ata_generic'.  Otherwise with parameter
    'all_generic_ide' it'll take over all available ata controllers.  Order of
    ata drivers and scsi drivers (sr_mod, sd) does not matter. So, something
    like this should be written in modprobe.conf:
    
        modprobe.conf:

            options ata_generic all_generic_ide=1
            install ata_generic /sbin/modprobe ata_piix ; /sbin/modprobe --ignore-install ata_generic

    or

        modprobe.conf:

            options ata_generic all_generic_ide=1
            install ata_generic /sbin/modprobe ata_piix ; /sbin/modprobe --ignore-install ata_generic $CMDLINE_OPTS

    though, adding $CMDLINE_OPTS (to add all options from the command line) is
    useless here - 'ata_generic' has only one option.


    Also there is another one module, which can drive IDER controller -
    'ide_pci_generic' (CONFIG_BLK_DEV_GENERIC). Unlike 'ata_generic', which
    uses libata, this module uses old ATA subsystem (CONFIG_IDE) (are terms
    here used correctly?). If you use this driver, cdrom drive will no longer
    be present as scsi device. Now it'll be handled by 'ide_cd' driver
    (CONFIG_BLK_DEV_IDECD).  'ide_pci_generic' driver also requires option
    'all_generic_ide' set in order to take over any device.

    Here are some results from booting linux with different ATA drivers used
    (though root partition in these tests is on the hard drive).

    All three boot scenarios require SATA AHCI controller to be in
    compatibility mode, otherwise ATA drivers can not work with it and kernel
    can't access root partition.
    1. ata_piix.  Here ata_piix driver is compiled in and handles all ATA
       controllers.  It correctly takes over AHCI controller (in
       compatiblility mode) and over PATA controller.  ata_generic was loaded
       as module later to handle IDER controller.

       Here is some info about such system config:

            # ls -l /sys/bus/pci/devices/*/driver
            ..
            lrwxrwxrwx 1 root root 0 Feb  1 13:06 /sys/bus/pci/devices/0000:00:03.2/driver -> ../../../bus/pci/drivers/ata_generic
            ..
            lrwxrwxrwx 1 root root 0 Feb  1 13:06 /sys/bus/pci/devices/0000:00:1f.2/driver -> ../../../bus/pci/drivers/ata_piix
            ..
            # lspci -nn | grep IDE
            00:03.2 IDE interface [0101]: Intel Corporation Mobile PM965/GM965 PT IDER Controller [8086:2a06] (rev 0c)
            00:1f.2 IDE interface [0101]: Intel Corporation 82801HBM/HEM (ICH8M/ICH8M-E) SATA IDE Controller [8086:2828] (rev 03)
            # ls -l /sys/bus/pci/devices/0000\:00\:1f.2/
            total 0
            ..
            lrwxrwxrwx 1 root root    0 Feb  1 13:06 driver -> ../../../bus/pci/drivers/ata_piix
            ..
            drwxr-xr-x 5 root root    0 Feb  1  2011 host0
            drwxr-xr-x 5 root root    0 Feb  1  2011 host1
            ..
            # ls -l /sys/bus/pci/devices/0000\:00\:1f.2/host0/
            total 0
            drwxr-xr-x 2 root root    0 Feb  1 13:13 power
            drwxr-xr-x 3 root root    0 Feb  1  2011 scsi_host
            lrwxrwxrwx 1 root root    0 Feb  1  2011 subsystem -> ../../../../bus/scsi
            drwxr-xr-x 4 root root    0 Feb  1  2011 target0:0:0
            -rw-r--r-- 1 root root 4096 Feb  1  2011 uevent
            # ls -l /sys/bus/pci/devices/0000\:00\:1f.2/host0/target0\:0\:0/0\:0\:0\:0/driver
            lrwxrwxrwx 1 root root 0 Feb  1 13:13 /sys/bus/pci/devices/0000:00:1f.2/host0/target0:0:0/0:0:0:0/driver -> ../../../../../../bus/scsi/drivers/sd
            # ls -l /sys/bus/pci/devices/0000\:00\:1f.2/host1/
            total 0
            drwxr-xr-x 2 root root    0 Feb  1 13:11 power
            drwxr-xr-x 3 root root    0 Feb  1  2011 scsi_host
            lrwxrwxrwx 1 root root    0 Feb  1  2011 subsystem -> ../../../../bus/scsi
            drwxr-xr-x 4 root root    0 Feb  1  2011 target1:0:0
            -rw-r--r-- 1 root root 4096 Feb  1  2011 uevent
            # ls -l /sys/bus/pci/devices/0000\:00\:1f.2/host1/target1\:0\:0/1\:0\:0\:0/driver
            lrwxrwxrwx 1 root root 0 Feb  1 13:09 /sys/bus/pci/devices/0000:00:1f.2/host1/target1:0:0/1:0:0:0/driver -> ../../../../../../bus/scsi/drivers/sr


    2. ata_generic.  Here ata_generic driver is compiled in and handles all
       ATA controllers.  It successfully takes over AHCI controller (in
       compatibility mode), PATA controller and IDER controller. Though, if
       IDE Redirection is enabled in management console (kernel can see
       devices attached to IDER controller), ATA devices may be named in not
       the order you expect, so 'root=' kernel parameter should be adjust
       correspondingly (or udev from initramfs should be used).  To take over
       any device this driver requires 'all-generic-ide' option set at kernel
       command line:

            ata_generic.all_generic_ide=1

       or

            ata-generic.all-generic-ide=1

       Here is some info about such system config:

            # ls -l /sys/bus/pci/devices/*/driver
            ..
            lrwxrwxrwx 1 root root 0 Feb  1 14:20 /sys/bus/pci/devices/0000:00:03.2/driver -> ../../../bus/pci/drivers/ata_generic
            ..
            lrwxrwxrwx 1 root root 0 Feb  1 14:20 /sys/bus/pci/devices/0000:00:1f.2/driver -> ../../../bus/pci/drivers/ata_generic
            ..
            # lspci -nn | grep IDE
            00:03.2 IDE interface [0101]: Intel Corporation Mobile PM965/GM965 PT IDER Controller [8086:2a06] (rev 0c)
            00:1f.2 IDE interface [0101]: Intel Corporation 82801HBM/HEM (ICH8M/ICH8M-E) SATA IDE Controller [8086:2828] (rev 03)
            # ls -l /sys/bus/pci/devices/0000\:00\:03.2/
            ..
            lrwxrwxrwx 1 root root    0 Feb  1 14:20 driver -> ../../../bus/pci/drivers/ata_generic
            ..
            drwxr-xr-x 6 root root    0 Feb  1  2011 host0
            drwxr-xr-x 4 root root    0 Feb  1  2011 host1
            ..
            # readlink -f /sys/class/block/sda/device
            /sys/devices/pci0000:00/0000:00:03.2/host0/target0:0:0/0:0:0:0
            # ls -l /sys/bus/pci/devices/0000\:00\:1f.2/host2/
            total 0
            drwxr-xr-x 2 root root    0 Feb  1 14:23 power
            drwxr-xr-x 3 root root    0 Feb  1  2011 scsi_host
            lrwxrwxrwx 1 root root    0 Feb  1  2011 subsystem -> ../../../../bus/scsi
            drwxr-xr-x 4 root root    0 Feb  1  2011 target2:0:0
            -rw-r--r-- 1 root root 4096 Feb  1  2011 uevent
            # ls -l /sys/bus/pci/devices/0000:00:1f.2/host2/target2:0:0/2:0:0:0/driver
            lrwxrwxrwx 1 root root 0 Feb  1 14:23 /sys/bus/pci/devices/0000:00:1f.2/host2/target2:0:0/2:0:0:0/driver -> ../../../../../../bus/scsi/drivers/sd
            # ls -l /sys/bus/pci/devices/0000:00:1f.2/host3/
            total 0
            drwxr-xr-x 2 root root    0 Feb  1 14:24 power
            drwxr-xr-x 3 root root    0 Feb  1  2011 scsi_host
            lrwxrwxrwx 1 root root    0 Feb  1  2011 subsystem -> ../../../../bus/scsi
            drwxr-xr-x 4 root root    0 Feb  1  2011 target3:0:0
            -rw-r--r-- 1 root root 4096 Feb  1  2011 uevent
            # ls -l /sys/bus/pci/devices/0000:00:1f.2/host3/target3:0:0/3:0:0:0/driver
            lrwxrwxrwx 1 root root 0 Feb  1 14:24 /sys/bus/pci/devices/0000:00:1f.2/host3/target3:0:0/3:0:0:0/driver -> ../../../../../../bus/scsi/drivers/sr
            # ls -l /sys/class/block/sd*
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/sda -> ../../devices/pci0000:00/0000:00:03.2/host0/target0:0:0/0:0:0:0/block/sda
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/sdb -> ../../devices/pci0000:00/0000:00:1f.2/host2/target2:0:0/2:0:0:0/block/sdb
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/sdb1 -> ../../devices/pci0000:00/0000:00:1f.2/host2/target2:0:0/2:0:0:0/block/sdb/sdb1
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/sdb2 -> ../../devices/pci0000:00/0000:00:1f.2/host2/target2:0:0/2:0:0:0/block/sdb/sdb2
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/sdb3 -> ../../devices/pci0000:00/0000:00:1f.2/host2/target2:0:0/2:0:0:0/block/sdb/sdb3
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/sdb4 -> ../../devices/pci0000:00/0000:00:1f.2/host2/target2:0:0/2:0:0:0/block/sdb/sdb4
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/sdb5 -> ../../devices/pci0000:00/0000:00:1f.2/host2/target2:0:0/2:0:0:0/block/sdb/sdb5
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/sdb6 -> ../../devices/pci0000:00/0000:00:1f.2/host2/target2:0:0/2:0:0:0/block/sdb/sdb6


    3. ide_pci_generic.  Here ide_pci_generic driver is compiled in and
       handles all ATA controllers. This driver represents old IDE subsystem,
       and noticeable difference from new ATA subsystem (libata) is that it
       names devices as /dev/hd* instead of /dev/sd*.  As well as ata_generic
       it successfully takes over all AHCI, PATA and IDER controllers. Device
       names here are also different from all what was before, so, 'root='
       kernel parameter should be adjusted. To take over any device this
       driver requires 'all-generic-ide' option set at kernel command line:

            ide-pci-generic.all-generic-ide

       or

            ide-pci-generic.all-generic-ide

       Here is some info about such system config:

            # ls -l /sys/bus/pci/devices/*/driver
            ..
            lrwxrwxrwx 1 root root 0 Feb  1 14:49 /sys/bus/pci/devices/0000:00:03.2/driver -> ../../../bus/pci/drivers/PCI_IDE
            ..
            lrwxrwxrwx 1 root root 0 Feb  1 14:49 /sys/bus/pci/devices/0000:00:1f.2/driver -> ../../../bus/pci/drivers/PCI_IDE
            ..
            # ls -l /sys/bus/pci/devices/0000:00:03.2/
            total 0
            ..
            lrwxrwxrwx 1 root root    0 Feb  1 14:49 driver -> ../../../bus/pci/drivers/PCI_IDE
            ..
            drwxr-xr-x 6 root root    0 Feb  1  2011 ide0
            drwxr-xr-x 4 root root    0 Feb  1  2011 ide1
            ..
            # ls -l /sys/bus/pci/devices/0000:00:03.2/ide0/
            total 0
            drwxr-xr-x 3 root root    0 Feb  1  2011 0.0
            drwxr-xr-x 5 root root    0 Feb  1  2011 0.1
            drwxr-xr-x 3 root root    0 Feb  1  2011 ide_port
            drwxr-xr-x 2 root root    0 Feb  1 14:49 power
            -rw-r--r-- 1 root root 4096 Feb  1  2011 uevent
            # ls -l /sys/bus/pci/devices/0000:00:03.2/ide0/0.0/
            (no 'driver' symlink - module required for floppy to work was not compiled (what module is needed?))
            # ls -l /sys/bus/pci/devices/0000:00:03.2/ide0/0.1/
            ..
            lrwxrwxrwx 1 root root    0 Feb  1 14:50 driver -> ../../../../../bus/ide/drivers/ide-cdrom
            ..
            # ls -l /sys/bus/pci/devices/0000:00:1f.2/
            ..
            lrwxrwxrwx 1 root root    0 Feb  1 14:49 driver -> ../../../bus/pci/drivers/PCI_IDE
            ..
            drwxr-xr-x 5 root root    0 Feb  1  2011 ide2
            drwxr-xr-x 5 root root    0 Feb  1  2011 ide3
            ..
            # ls -l /sys/bus/pci/devices/0000:00:1f.2/ide2/
            total 0
            drwxr-xr-x 5 root root    0 Feb  1  2011 2.0
            drwxr-xr-x 3 root root    0 Feb  1  2011 ide_port
            drwxr-xr-x 2 root root    0 Feb  1 14:51 power
            -rw-r--r-- 1 root root 4096 Feb  1  2011 uevent
            # ls -l /sys/bus/pci/devices/0000:00:1f.2/ide2/2.0/
            ..
            lrwxrwxrwx 1 root root    0 Feb  1 14:51 driver -> ../../../../../bus/ide/drivers/ide-gd
            ..
            # ls -l /sys/bus/pci/devices/0000:00:1f.2/ide2/2.0/block/
            total 0
            drwxr-xr-x 12 root root 0 Feb  1  2011 hde
            # ls -l /sys/bus/pci/devices/0000:00:1f.2/ide3/
            total 0
            drwxr-xr-x 5 root root    0 Feb  1  2011 3.0
            drwxr-xr-x 3 root root    0 Feb  1  2011 ide_port
            drwxr-xr-x 2 root root    0 Feb  1 14:51 power
            -rw-r--r-- 1 root root 4096 Feb  1  2011 uevent
            # ls -l /sys/bus/pci/devices/0000:00:1f.2/ide3/3.0/
            ..
            lrwxrwxrwx 1 root root    0 Feb  1 14:52 driver -> ../../../../../bus/ide/drivers/ide-cdrom
            ..
            # ls -l /sys/bus/pci/devices/0000:00:1f.2/ide3/3.0/block/
            total 0
            drwxr-xr-x 6 root root 0 Feb  1  2011 hdg
            # ls -l /sys/class/block/hd*
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/hdb -> ../../devices/pci0000:00/0000:00:03.2/ide0/0.1/block/hdb
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/hde -> ../../devices/pci0000:00/0000:00:1f.2/ide2/2.0/block/hde
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/hde1 -> ../../devices/pci0000:00/0000:00:1f.2/ide2/2.0/block/hde/hde1
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/hde2 -> ../../devices/pci0000:00/0000:00:1f.2/ide2/2.0/block/hde/hde2
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/hde3 -> ../../devices/pci0000:00/0000:00:1f.2/ide2/2.0/block/hde/hde3
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/hde4 -> ../../devices/pci0000:00/0000:00:1f.2/ide2/2.0/block/hde/hde4
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/hde5 -> ../../devices/pci0000:00/0000:00:1f.2/ide2/2.0/block/hde/hde5
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/hde6 -> ../../devices/pci0000:00/0000:00:1f.2/ide2/2.0/block/hde/hde6
            lrwxrwxrwx 1 root root 0 Feb  1  2011 /sys/class/block/hdg -> ../../devices/pci0000:00/0000:00:1f.2/ide3/3.0/block/hdg
            # ls -l /sys/bus/pci/drivers/PCI_IDE/module
            lrwxrwxrwx 1 root root 0 Feb  1 15:01 /sys/bus/pci/drivers/PCI_IDE/module -> ../../../../module/ide_pci_generic


    Hence, to boot linux from cdrom drive on IDER controller, we just need to
    have compiled into the kernel either ata_generic or ide_pci_generic
    driver.  I test this with gentoo livecd and SystemRescueCd. First one has
    ide_pci_generic driver compiled in and should be booted like

        gentoo ide-pci-generic.all-generic-ide

    second one has ata_generic driver compiled and should be booted like

        <..system rescue cd boot options..> ata-generic.all-generic-ide=1

    PS. This was tested on motherboard with Intel PM965 chipset (Centrino
    vPro) with AMT 2.6 (or 2.5?) and kernel 2.6.36.