#!/bin/bash #/etc/rc.d/rc.usb # initialise USB modules #---------------------- HOSTNAME=`hostname` LSPCI=/usr/sbin/lspci #---------------------- #results of trying some hardware #Summary: of 5 machines, 4 could be made to work well. #An old machine with on-board USB wouldn't work, even with #a USB 2.0 card installed. #The data #5 machines tried. #3 machines worked with their on-board USB host controller out of the box. #These were fairly new machines (>2000 I'd guess) #An old machine without any USB worked fine with a USB 2.0 pci card #An old machine with on board USB, didn't work (hung on copying files) #with any drivers. When the onboard USB was turned off, and the USB 2.0 #card inserted, it hung on copy too. #USB controllers known to work #USB 2.0 #snow, patty, PCI usb card: USB 2.0 ohci ehci-hcd #00:0a.0 USB Controller: NEC Corporation USB (rev 41) #00:0a.1 USB Controller: NEC Corporation USB (rev 41) #00:0a.2 USB Controller: NEC Corporation: Unknown device 00e0 (rev 02) #USB 1.1 #albert USB 1.1 #usb-uhci - worked fine, load average=6 for single copy #00:1f.2 USB Controller: Intel Corp. 82801BA/BAM USB (Hub (rev 04) #00:1f.4 USB Controller: Intel Corp. 82801BA/BAM USB (Hub (rev 04) #goofy USB 1.1 #usb-uhci - worked fine, load average=4 for single copy #00:1f.2 USB Controller: Intel Corporation: Unknown device 2442 (rev 04) #00:1f.4 USB Controller: Intel Corporation: Unknown device 2444 (rev 04) #dennis, USB 1.1 #uhci #00:07.2 USB Controller: Intel Corp. 82371AB/EB/MB PIIX4 USB (rev 01) (prog-if 00 [UHCI]) #known not to work #USB 1.1 #pip SMP pentium pro #usb-uhci uhci - not at all #00:07.2 USB Controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01) #Info for each machine. #pip SMP pentium pro #usb-uhci - sometimes #uhci - not at all #pip:~# lspci #00:07.2 USB Controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01) #when add the USB 2.0 card that works with snow, #you can't load the ohci driver (module_init doesn't work). #Presumably the modules get confused if there are two types of host controllers. #Turned of the on-board USB at the BIOS and then installed the USB 2.0 card. #It was recognised etc, but copy only went a little while before hanging. #snow, UMP pentium classic with USB 2.0 card #ohci ehci-hcd - worked fine, load average while copying, about 2 #snow:/src/arch/pip# lspci | grep -i usb #00:0a.0 USB Controller: NEC Corporation USB (rev 41) #00:0a.1 USB Controller: NEC Corporation USB (rev 41) #00:0a.2 USB Controller: NEC Corporation: Unknown device 00e0 (rev 02) #albert, unknown linux box at work (approx 2001) #usb-uhci - worked fine, load average=6 for single copy #albert:# lspci | grep -i usb #00:1f.2 USB Controller: Intel Corp. 82801BA/BAM USB (Hub (rev 04) #00:1f.4 USB Controller: Intel Corp. 82801BA/BAM USB (Hub (rev 04) #goofy, Dell 800MHz UMP Pentium II/III (?), onboard USB #usb-uhci - worked fine, load average=4 for single copy #goofy :# lspci | grep -i usb #00:1f.2 USB Controller: Intel Corporation: Unknown device 2442 (rev 04) #00:1f.4 USB Controller: Intel Corporation: Unknown device 2444 (rev 04) #dennis, tyan pentium classis UMP machine with on-board USB (about 1997) #uhci - worked fine, high load average, about 20 for 6 copies at once #usb-uhci - locked up instantly on accessing disk. #dennis :# lspci | grep -i usb #00:07.2 USB Controller: Intel Corp. 82371AB/EB/MB PIIX4 USB (rev 01) (prog-if 00 [UHCI]) #usb-uhci #Intel, #somewhat simple, bound up with Intel IP problems, #and requires much work by driver #"u" = universal #uhci #the alternate uhci controller #works at home on my Tyan UMP box #usb-ohci #Response to Intel by other manufacturers, eg Compaq #to produce a chipset with less IP restrictions #"o" = open source #Compaq #ehci-hcd #USB 2.0 layer, requires prior loading of usb-uhci|uhci|usb-ohci #driver=usb-uhci|uhci|usb-ohci #in case we need a few of these, put them in order in quotes #---------------------- get_driver_by_hostname() { if [ "$HOSTNAME" = "snow" ] then drivers="usb-ohci ehci-hcd" elif [ "$HOSTNAME" = "patty" ] then drivers="usb-ohci ehci-hcd" elif [ "$HOSTNAME" = "dennis" ] then drivers="uhci" elif [ "$HOSTNAME" = "pip" ] then drivers="usb-uhci" echo "$0, haven't got pip to work with USB yet" return 1 fi } get_driver_by_lspci() { # #get an updated list of pci.ids from #http://pciids.sourceforge.net/ # #get lspci (which will include an older version of pci.ids) from pciutils #ftp://metalab.unc.edu/pub/Linux/hardware/pciutils-x.x.x.tar.gz #The tarball includes a script to download the latest pci.ids (by cron). # #Warnings: #1. # the pciutils Makefile installs everything in --prefix=/usr/local/. # #2. # The location for installation of pci.ids is set by # $SHAREDIR in the Makefile, which writes it into lib/config.h # I put pci.ids in /etc. # #3. `make install` will overwrite your newly downloaded pci.ids #with the old one from pciutils. #To fix this change the install line in the Makefile to # # if [ pci.ids -nt ${SHAREDIR}/pci.ids ]; then $(INSTALL) -c -m 644 pci.ids $(SHAREDIR) ;fi # #4. run `make -n install` first, #to make sure everything goes in the right place. # #USB 2.0 card by NEC. #has sloping pcboard, 4 external, 1 internal connectors # snow:~# more /proc/bus/usb/devices # T: Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=480 MxCh= 5 # B: Alloc= 0/800 us ( 0%), #Int= 0, #Iso= 0 # D: Ver= 2.00 Cls=09(hub ) Sub=00 Prot=01 MxPS= 8 #Cfgs= 1 # P: Vendor=0000 ProdID=0000 Rev= 2.04 # S: Manufacturer=Linux 2.4.26 ehci_hcd # S: Product=NEC Corporation USB 2.0 # S: SerialNumber=00:14.2 # C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA # I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub # E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=256ms # T: Bus=03 Lev=01 Prnt=01 Port=04 Cnt=01 Dev#= 2 Spd=480 MxCh= 0 # D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 # P: Vendor=05e3 ProdID=0702 Rev= 0.02 # S: Manufacturer=PENR525 # S: Product=VERSION 1.1 # C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr= 70mA # I: If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage # E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms # E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=125us # T: Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 3 # B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0 # D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 # P: Vendor=0000 ProdID=0000 Rev= 0.00 # S: Product=USB OHCI Root Hub # S: SerialNumber=c99c3000 # C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA # I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub # E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms # T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 # B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0 # D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 # P: Vendor=0000 ProdID=0000 Rev= 0.00 # S: Product=USB OHCI Root Hub # S: SerialNumber=c99c1000 # C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA # I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub # E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms # if [ `$LSPCI | grep -c "USB Controller: NEC Corporation USB 2.0"` != "0" ] then drivers="usb-ohci ehci-hcd" fi #USB 1.x on mobo # dennis:~# more /proc/bus/usb/devices # T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 # B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0 # D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 # P: Vendor=0000 ProdID=0000 Rev= 0.00 # S: Product=USB UHCI-alt Root Hub # S: SerialNumber=6300 # C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA # I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub # E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms # T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 0 # D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 # P: Vendor=05e3 ProdID=0702 Rev= 0.02 # S: Manufacturer=PENR525 # S: Product=VERSION 1.1 # C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr= 70mA # I: If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage # E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms # E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms # if [ `$LSPCI | grep -c "USB Controller: Intel Corp. 82371AB/EB/MB PIIX4 USB (rev 01)"` != "0" ] then drivers="uhci" fi } #---------------------- usb_start() { echo -n "usb " /sbin/modprobe usbcore #get driver_by_hostname get_driver_by_lspci for driver in $drivers do echo -n "$driver " /sbin/modprobe $driver done #needs this entry in /etc/fstab #none /proc/bus/usb usbdevfs noauto 0 0 COUNT=`grep -c /proc/bus/usb /etc/mtab` if [ "$COUNT" = "0" ] then mount /proc/bus/usb else true #echo "$0, /proc/bus/usb already mounted" fi echo -n "usb-storage " /sbin/modprobe usb-storage echo "" } usb_stop() { #seems I only have usb set up for disk storage. #when I get a usb keyboard I'll have to change all this. #Is usb disk storage installed at all? USB_STORAGE=`lsmod | grep -c ^usb-storage` if [ "$USB_STORAGE" = "0" ] then #do nothing true else #any disks mounted? COUNT=`lsmod | grep ^usb-storage | awk '{print $3}'` if [ "$COUNT" = "0" ] then #can't seem to rmmod usbcore for file in usb-storage usb-ohci usb-uhci uhci ehci-hcd do COUNT=`/sbin/lsmod | grep -c ^${file}` if [ "$COUNT" != "0" ] then rmmod $file if [ "$?" != "0" ] then echo "$0: failure removing module $file" logger "$0: failure removing module $file" fi fi done else echo "$0 error: usb-storage module count should be zero" echo "before removing module (is $COUNT)." echo "No action has been taken to bring down usb." echo "Here's the lsmod output" lsmod | grep ^usb-storage echo "Disk may be mounted or being accessed (eg fdisk, mke2fs, fsck, dd)." echo "Stop access to disk and then re-run this program." return 1 exit fi fi } usb_restart() { usb_stop sleep 2 usb_start } case "$1" in 'start') usb_start ;; 'stop') usb_stop ;; 'restart') usb_restart ;; *) echo "usage $0 start|stop|restart" esac #---------------------------------