]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Merge branch 'for-2.6.26' into for-next
authorNeil Brown <neilb@suse.de>
Thu, 10 Jul 2008 06:51:26 +0000 (16:51 +1000)
committerNeil Brown <neilb@suse.de>
Thu, 10 Jul 2008 06:51:26 +0000 (16:51 +1000)
Conflicts:

drivers/md/raid5.c

316 files changed:
.gitignore
CREDITS
Documentation/accounting/taskstats-struct.txt
Documentation/auxdisplay/cfag12864b
Documentation/auxdisplay/cfag12864b-example.c
Documentation/auxdisplay/ks0108
Documentation/cgroups.txt
Documentation/controllers/devices.txt
Documentation/cpusets.txt
Documentation/feature-removal-schedule.txt
Documentation/i2c/writing-clients
Documentation/kernel-parameters.txt
Documentation/md.txt
Documentation/networking/ip-sysctl.txt
Documentation/networking/s2io.txt
Documentation/video4linux/CARDLIST.au0828
Documentation/vm/slabinfo.c
Documentation/vm/slub.txt
MAINTAINERS
Makefile
arch/alpha/kernel/vmlinux.lds.S
arch/arm/common/dmabounce.c
arch/arm/mach-omap2/gpmc.c
arch/arm/mach-realview/platsmp.c
arch/arm/plat-omap/dma.c
arch/blackfin/kernel/cplb-nompu/cplbinit.c
arch/blackfin/kernel/irqchip.c
arch/ia64/kernel/setup.c
arch/ia64/kernel/time.c
arch/mips/Kconfig
arch/mips/kernel/cevt-txx9.c
arch/mips/sgi-ip32/ip32-irq.c
arch/mn10300/kernel/mn10300_ksyms.c
arch/mn10300/kernel/process.c
arch/mn10300/lib/Makefile
arch/mn10300/lib/__ucmpdi2.S [new file with mode: 0644]
arch/powerpc/boot/Makefile
arch/powerpc/kernel/legacy_serial.c
arch/powerpc/platforms/52xx/lite5200_pm.c
arch/x86/Kconfig
arch/x86/kernel/acpi/realmode/wakeup.S
arch/x86/kernel/acpi/realmode/wakeup.h
arch/x86/kernel/acpi/sleep.c
arch/x86/kernel/efi_32.c
arch/x86/kernel/head_64.S
arch/x86/kernel/i387.c
arch/x86/kernel/smpboot.c
arch/x86/mm/init_64.c
arch/x86/xen/mmu.c
block/as-iosched.c
drivers/acpi/bay.c
drivers/acpi/dock.c
drivers/acpi/glue.c
drivers/acpi/sleep/main.c
drivers/acpi/sleep/proc.c
drivers/ata/ahci.c
drivers/ata/libata-sff.c
drivers/ata/sata_mv.c
drivers/ata/sata_sil24.c
drivers/ata/sata_uli.c
drivers/auxdisplay/Kconfig
drivers/auxdisplay/cfag12864b.c
drivers/auxdisplay/cfag12864bfb.c
drivers/auxdisplay/ks0108.c
drivers/base/node.c
drivers/block/cciss.c
drivers/char/drm/i915_irq.c
drivers/char/tty_io.c
drivers/connector/connector.c
drivers/firewire/fw-sbp2.c
drivers/gpio/Kconfig
drivers/gpio/pca953x.c
drivers/hwmon/hdaps.c
drivers/i2c/busses/i2c-s3c2410.c
drivers/ide/Kconfig
drivers/ide/arm/Makefile
drivers/ide/arm/bast-ide.c [new file with mode: 0644]
drivers/ide/ide-probe.c
drivers/ide/ide-proc.c
drivers/ide/ide.c
drivers/input/ff-core.c
drivers/md/bitmap.c
drivers/md/dm-crypt.c
drivers/md/linear.c
drivers/md/md.c
drivers/md/multipath.c
drivers/md/raid1.c
drivers/md/raid10.c
drivers/md/raid5.c
drivers/media/common/ir-keymaps.c
drivers/media/common/tuners/tda18271-common.c
drivers/media/common/tuners/tda18271-fe.c
drivers/media/common/tuners/xc5000.c
drivers/media/common/tuners/xc5000_priv.h
drivers/media/dvb/dvb-usb/gl861.c
drivers/media/dvb/dvb-usb/umt-010.c
drivers/media/dvb/frontends/au8522.c
drivers/media/dvb/frontends/stv0299.c
drivers/media/dvb/frontends/tda10023.c
drivers/media/dvb/frontends/tda1004x.c
drivers/media/dvb/ttpci/Kconfig
drivers/media/dvb/ttpci/av7110_hw.c
drivers/media/video/Kconfig
drivers/media/video/Makefile
drivers/media/video/au0828/au0828-cards.c
drivers/media/video/cx18/Kconfig
drivers/media/video/cx18/cx18-av-core.c
drivers/media/video/cx18/cx18-av-core.h
drivers/media/video/cx18/cx18-cards.c
drivers/media/video/cx18/cx18-cards.h
drivers/media/video/cx18/cx18-dvb.c
drivers/media/video/cx18/cx18-gpio.c
drivers/media/video/cx18/cx18-gpio.h
drivers/media/video/cx18/cx18-i2c.c
drivers/media/video/cx25840/cx25840-core.c
drivers/media/video/cx88/cx88-alsa.c
drivers/media/video/em28xx/em28xx-audio.c
drivers/media/video/em28xx/em28xx-cards.c
drivers/media/video/em28xx/em28xx-dvb.c
drivers/media/video/em28xx/em28xx-reg.h
drivers/media/video/em28xx/em28xx-video.c
drivers/media/video/pxa_camera.c
drivers/media/video/saa7134/saa7134-alsa.c
drivers/media/video/saa7134/saa7134-cards.c
drivers/media/video/saa7134/saa7134-dvb.c
drivers/media/video/saa7134/saa7134-empress.c
drivers/media/video/saa7134/saa7134-input.c
drivers/media/video/soc_camera.c
drivers/media/video/uvc/Makefile [new file with mode: 0644]
drivers/media/video/uvc/uvc_ctrl.c [new file with mode: 0644]
drivers/media/video/uvc/uvc_driver.c [new file with mode: 0644]
drivers/media/video/uvc/uvc_isight.c [new file with mode: 0644]
drivers/media/video/uvc/uvc_queue.c [new file with mode: 0644]
drivers/media/video/uvc/uvc_status.c [new file with mode: 0644]
drivers/media/video/uvc/uvc_v4l2.c [new file with mode: 0644]
drivers/media/video/uvc/uvc_video.c [new file with mode: 0644]
drivers/media/video/uvc/uvcvideo.h [new file with mode: 0644]
drivers/media/video/videodev.c
drivers/media/video/vivi.c
drivers/mmc/host/sdhci.c
drivers/net/3c59x.c
drivers/net/e100.c
drivers/net/e1000/e1000_ethtool.c
drivers/net/e1000e/netdev.c
drivers/net/hamradio/dmascc.c
drivers/net/igb/igb_main.c
drivers/net/ipg.c
drivers/net/ixgbe/ixgbe_main.c
drivers/net/netxen/netxen_nic_main.c
drivers/net/pcmcia/axnet_cs.c
drivers/net/pcmcia/pcnet_cs.c
drivers/net/qla3xxx.c
drivers/net/r6040.c
drivers/net/s2io.c
drivers/net/s2io.h
drivers/net/tc35815.c
drivers/net/wan/x25_asy.c
drivers/net/wireless/b43/leds.c
drivers/net/wireless/b43/main.c
drivers/net/wireless/b43legacy/dma.c
drivers/net/wireless/b43legacy/main.c
drivers/net/wireless/hostap/hostap_80211_rx.c
drivers/net/wireless/hostap/hostap_ap.c
drivers/net/wireless/hostap/hostap_cs.c
drivers/net/wireless/hostap/hostap_hw.c
drivers/net/wireless/hostap/hostap_main.c
drivers/net/wireless/iwlwifi/iwl3945-base.c
drivers/net/wireless/iwlwifi/iwl4965-base.c
drivers/net/wireless/prism54/islpci_eth.c
drivers/net/wireless/rt2x00/rt2500usb.c
drivers/net/wireless/rt2x00/rt2x00.h
drivers/net/wireless/rt2x00/rt2x00dev.c
drivers/net/wireless/rt2x00/rt2x00mac.c
drivers/net/wireless/rt2x00/rt73usb.c
drivers/pci/access.c
drivers/pci/hotplug/acpiphp_glue.c
drivers/pci/pci-sysfs.c
drivers/pci/pci.h
drivers/pci/quirks.c
drivers/rtc/interface.c
drivers/rtc/rtc-sa1100.c
drivers/rtc/rtc-x1205.c
drivers/scsi/esp_scsi.c
drivers/scsi/ses.c
drivers/serial/serial_core.c
drivers/spi/spidev.c
drivers/thermal/Kconfig
drivers/thermal/thermal_sys.c
drivers/usb/class/cdc-acm.c
drivers/usb/core/hcd.c
drivers/usb/core/hub.c
drivers/usb/host/ehci.h
drivers/usb/host/ohci-hcd.c
drivers/usb/host/ohci-q.c
drivers/usb/misc/sisusbvga/sisusb.c
drivers/usb/serial/ftdi_sio.c
drivers/usb/serial/ftdi_sio.h
drivers/usb/serial/ipaq.c
drivers/usb/serial/option.c
drivers/usb/serial/pl2303.c
drivers/usb/serial/pl2303.h
drivers/usb/storage/unusual_devs.h
drivers/video/Kconfig
drivers/video/fsl-diu-fb.c
drivers/video/pxafb.c
drivers/video/w100fb.c
fs/9p/v9fs_vfs.h
fs/9p/vfs_file.c
fs/9p/vfs_inode.c
fs/Kconfig
fs/block_dev.c
fs/buffer.c
fs/dcache.c
fs/ecryptfs/miscdev.c
fs/ext3/super.c
fs/ext4/super.c
fs/libfs.c
fs/locks.c
fs/namei.c
fs/open.c
fs/pipe.c
fs/proc/task_mmu.c
fs/reiserfs/super.c
fs/udf/super.c
fs/utimes.c
include/asm-generic/Kbuild.asm
include/asm-generic/atomic.h
include/asm-mips/atomic.h
include/asm-powerpc/Kbuild
include/asm-x86/msr.h
include/linux/Kbuild
include/linux/audit.h
include/linux/capability.h
include/linux/cfag12864b.h
include/linux/cpumask.h
include/linux/dcache.h
include/linux/debug_locks.h
include/linux/firmware.h
include/linux/fs.h
include/linux/i2c.h
include/linux/inet_lro.h
include/linux/input.h
include/linux/kernel.h
include/linux/ks0108.h
include/linux/netdevice.h
include/linux/pci_ids.h
include/linux/raid/bitmap.h
include/linux/raid/md.h
include/linux/raid/md_k.h
include/linux/raid/raid5.h
include/linux/rculist.h [new file with mode: 0644]
include/linux/securebits.h
include/linux/slab.h
include/linux/slub_def.h
include/linux/thermal.h
include/media/cx25840.h
include/media/ir-common.h
include/media/v4l2-dev.h
include/net/mac80211.h
include/net/sch_generic.h
kernel/audit.c
kernel/auditfilter.c
kernel/capability.c
kernel/hrtimer.c
kernel/rcuclassic.c
kernel/sched.c
kernel/softlockup.c
kernel/workqueue.c
lib/bug.c
lib/debugobjects.c
lib/radix-tree.c
lib/ts_bm.c
mm/allocpercpu.c
mm/memory.c
mm/mempolicy.c
mm/migrate.c
mm/page_alloc.c
mm/slub.c
mm/sparse-vmemmap.c
net/core/dev.c
net/core/fib_rules.c
net/core/filter.c
net/core/skbuff.c
net/ipv4/inet_fragment.c
net/ipv4/inet_lro.c
net/ipv4/ip_fragment.c
net/ipv4/tcp.c
net/ipv4/tcp_ipv4.c
net/ipv6/netfilter/ip6table_mangle.c
net/ipv6/netfilter/nf_conntrack_reasm.c
net/ipv6/reassembly.c
net/ipv6/route.c
net/ipv6/tcp_ipv6.c
net/mac80211/key.c
net/mac80211/wext.c
net/mac80211/wme.c
net/netfilter/nf_conntrack_proto_tcp.c
net/netlabel/netlabel_unlabeled.c
net/netlink/af_netlink.c
net/netlink/attr.c
net/sched/Kconfig
net/sched/sch_api.c
net/sched/sch_atm.c
net/sched/sch_cbq.c
net/sched/sch_dsmark.c
net/sched/sch_generic.c
net/sched/sch_hfsc.c
net/sched/sch_htb.c
net/sched/sch_ingress.c
net/sched/sch_prio.c
net/sched/sch_sfq.c
net/sunrpc/auth_gss/svcauth_gss.c
net/unix/af_unix.c
net/wireless/reg.c
security/commoncap.c
security/device_cgroup.c

index 9bb1cb6d825d540bc92dfe5c34343438b860b009..869e1a3b64b6bf969eeced820691e955e03e3068 100644 (file)
@@ -3,6 +3,10 @@
 # subdirectories here. Add them in the ".gitignore" file
 # in that subdirectory instead.
 #
+# NOTE! Please use 'git-ls-files -i --exclude-standard'
+# command after changing this file, to see if there are
+# any tracked files which get ignored after the change.
+#
 # Normal rules
 #
 .*
 *.lst
 *.symtypes
 *.order
+*.elf
+*.bin
+*.gz
 
 #
 # Top-level generic files
 #
 tags
 TAGS
-vmlinux*
-!vmlinux.lds.S
-!vmlinux.lds.h
+vmlinux
 System.map
 Module.markers
 Module.symvers
 !.gitignore
+!.mailmap
 
 #
 # Generated include files
diff --git a/CREDITS b/CREDITS
index 8fec7b3f96d5668fa441bd50fc81626d34f0f0c2..e97bea06b59ff12bc827c0661fb57974a6eff4d6 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -2611,8 +2611,9 @@ S: Perth, Western Australia
 S: Australia
 
 N: Miguel Ojeda Sandonis
-E: maxextreme@gmail.com
-W: http://maxextreme.googlepages.com/
+E: miguel.ojeda.sandonis@gmail.com
+W: http://miguelojeda.es
+W: http://jair.lab.fi.uva.es/~migojed/
 D: Author of the ks0108, cfag12864b and cfag12864bfb auxiliary display drivers.
 D: Maintainer of the auxiliary display drivers tree (drivers/auxdisplay/*)
 S: C/ Mieses 20, 9-B
index 8aa7529f8258a12725f6d34b5a7b349aa104a48a..cd784f46bf8abefb9ed24257aaf5fcf4df2ecb00 100644 (file)
@@ -24,6 +24,8 @@ There are three different groups of fields in the struct taskstats:
 
 4) Per-task and per-thread context switch count statistics
 
+5) Time accounting for SMT machines
+
 Future extension should add fields to the end of the taskstats struct, and
 should not change the relative position of each field within the struct.
 
@@ -164,4 +166,8 @@ struct taskstats {
        __u64   nvcsw;                  /* Context voluntary switch counter */
        __u64   nivcsw;                 /* Context involuntary switch counter */
 
+5) Time accounting for SMT machines
+       __u64   ac_utimescaled;         /* utime scaled on frequency etc */
+       __u64   ac_stimescaled;         /* stime scaled on frequency etc */
+       __u64   cpu_scaled_run_real_total; /* scaled cpu_run_real_total */
 }
index b714183d412515abc2a39c32e898cdab52d21eff..eb7be393a51061c6e1cd844dc884edc1a276c53e 100644 (file)
@@ -3,7 +3,7 @@
        ===================================
 
 License:               GPLv2
-Author & Maintainer:   Miguel Ojeda Sandonis <maxextreme@gmail.com>
+Author & Maintainer:   Miguel Ojeda Sandonis
 Date:                  2006-10-27
 
 
@@ -22,7 +22,7 @@ Date:                 2006-10-27
 1. DRIVER INFORMATION
 ---------------------
 
-This driver support one cfag12864b display at time.
+This driver supports a cfag12864b LCD.
 
 
 ---------------------
index 7bfac354d4c9f0181d311a0d80e798fdf502f75c..2caeea5e49932e1c3e132a55794373c3fe65dbad 100644 (file)
@@ -4,7 +4,7 @@
  * Description: cfag12864b LCD userspace example program
  *     License: GPLv2
  *
- *      Author: Copyright (C) Miguel Ojeda Sandonis <maxextreme@gmail.com>
+ *      Author: Copyright (C) Miguel Ojeda Sandonis
  *        Date: 2006-10-31
  *
  *  This program is free software; you can redistribute it and/or modify
index 92b03b60c613f3344bc5c771a65ad40e2f71da7a..8ddda0c8ceefa485f5fe1743a75d79e961e47174 100644 (file)
@@ -3,7 +3,7 @@
        ==========================================
 
 License:               GPLv2
-Author & Maintainer:   Miguel Ojeda Sandonis <maxextreme@gmail.com>
+Author & Maintainer:   Miguel Ojeda Sandonis
 Date:                  2006-10-27
 
 
@@ -21,7 +21,7 @@ Date:                 2006-10-27
 1. DRIVER INFORMATION
 ---------------------
 
-This driver support the ks0108 LCD controller.
+This driver supports the ks0108 LCD controller.
 
 
 ---------------------
index 824fc02744719ecb02b29177c11c55034229af35..d9014aa0eb68b469836b29afe932532b168a63ee 100644 (file)
@@ -390,6 +390,10 @@ If you have several tasks to attach, you have to do it one after another:
        ...
 # /bin/echo PIDn > tasks
 
+You can attach the current shell task by echoing 0:
+
+# echo 0 > tasks
+
 3. Kernel API
 =============
 
index 4dcea42432c279d4e58eb732010d0feae4e2a4ff..7cc6e6a60672c9e247d63a313d279a3a1739e3e2 100644 (file)
@@ -13,7 +13,7 @@ either an integer or * for all.  Access is a composition of r
 The root device cgroup starts with rwm to 'all'.  A child device
 cgroup gets a copy of the parent.  Administrators can then remove
 devices from the whitelist or add new entries.  A child cgroup can
-never receive a device access which is denied its parent.  However
+never receive a device access which is denied by its parent.  However
 when a device access is removed from a parent it will not also be
 removed from the child(ren).
 
@@ -29,7 +29,11 @@ allows cgroup 1 to read and mknod the device usually known as
 
        echo a > /cgroups/1/devices.deny
 
-will remove the default 'a *:* mrw' entry.
+will remove the default 'a *:* rwm' entry. Doing
+
+       echo a > /cgroups/1/devices.allow
+
+will add the 'a *:* rwm' entry to the whitelist.
 
 3. Security
 
index 353504de3084a645931788b6bd4d7e529428562e..1f5a924d1e56430bc3c8a0a6bb74e7524fab1670 100644 (file)
@@ -154,13 +154,15 @@ browsing and modifying the cpusets presently known to the kernel.  No
 new system calls are added for cpusets - all support for querying and
 modifying cpusets is via this cpuset file system.
 
-The /proc/<pid>/status file for each task has two added lines,
+The /proc/<pid>/status file for each task has four added lines,
 displaying the tasks cpus_allowed (on which CPUs it may be scheduled)
 and mems_allowed (on which Memory Nodes it may obtain memory),
-in the format seen in the following example:
+in the two formats seen in the following example:
 
   Cpus_allowed:   ffffffff,ffffffff,ffffffff,ffffffff
+  Cpus_allowed_list:      0-127
   Mems_allowed:   ffffffff,ffffffff
+  Mems_allowed_list:      0-63
 
 Each cpuset is represented by a directory in the cgroup file system
 containing (on top of the standard cgroup files) the following
@@ -544,6 +546,9 @@ otherwise initial value -1 that indicates the cpuset has no request.
  ( 4  : search nodes in a chunk of node [on NUMA system] )
  ( 5  : search system wide [on NUMA system] )
 
+The system default is architecture dependent.  The system default
+can be changed using the relax_domain_level= boot parameter.
+
 This file is per-cpuset and affect the sched domain where the cpuset
 belongs to.  Therefore if the flag 'sched_load_balance' of a cpuset
 is disabled, then 'sched_relax_domain_level' have no effect since
index 5b3f31faed56872b84fbd293494613f6d627a987..46ece3fba6f94c2924c94d6f96b4402984705102 100644 (file)
@@ -312,3 +312,12 @@ When:      2.6.26
 Why:   Implementation became generic; users should now include
        linux/semaphore.h instead.
 Who:   Matthew Wilcox <willy@linux.intel.com>
+
+---------------------------
+
+What:  CONFIG_THERMAL_HWMON
+When:  January 2009
+Why:   This option was introduced just to allow older lm-sensors userspace
+       to keep working over the upgrade to 2.6.26. At the scheduled time of
+       removal fixed lm-sensors (2.x or 3.x) should be readily available.
+Who:   Rene Herman <rene.herman@gmail.com>
index ee75cbace28d529cb690e573ec4c2cb67f75bd0f..d4cd4126d1adeca025e76a2511b0881cd6d0c00c 100644 (file)
@@ -25,12 +25,23 @@ routines, and should be zero-initialized except for fields with data you
 provide.  A client structure holds device-specific information like the
 driver model device node, and its I2C address.
 
+/* iff driver uses driver model ("new style") binding model: */
+
+static struct i2c_device_id foo_idtable[] = {
+       { "foo", my_id_for_foo },
+       { "bar", my_id_for_bar },
+       { }
+};
+
+MODULE_DEVICE_TABLE(i2c, foo_idtable);
+
 static struct i2c_driver foo_driver = {
        .driver = {
                .name   = "foo",
        },
 
        /* iff driver uses driver model ("new style") binding model: */
+       .id_table       = foo_ids,
        .probe          = foo_probe,
        .remove         = foo_remove,
 
@@ -173,10 +184,9 @@ handle may be used during foo_probe().  If foo_probe() reports success
 (zero not a negative status code) it may save the handle and use it until
 foo_remove() returns.  That binding model is used by most Linux drivers.
 
-Drivers match devices when i2c_client.driver_name and the driver name are
-the same; this approach is used in several other busses that don't have
-device typing support in the hardware.  The driver and module name should
-match, so hotplug/coldplug mechanisms will modprobe the driver.
+The probe function is called when an entry in the id_table name field
+matches the device's name. It is passed the entry that was matched so
+the driver knows which one in the table matched.
 
 
 Device Creation (Standard driver model)
index e07c432c731ff9a516fe8b23228af0fe6fa1d29a..b52f47d588b40fea417bf4bca4ffdbfef4d02152 100644 (file)
@@ -295,7 +295,7 @@ and is between 256 and 4096 characters. It is defined in the file
                        when initialising the APIC and IO-APIC components.
 
        apm=            [APM] Advanced Power Management
-                       See header of arch/i386/kernel/apm.c.
+                       See header of arch/x86/kernel/apm_32.c.
 
        arcrimi=        [HW,NET] ARCnet - "RIM I" (entirely mem-mapped) cards
                        Format: <io>,<irq>,<nodeID>
@@ -638,7 +638,7 @@ and is between 256 and 4096 characters. It is defined in the file
 
        elanfreq=       [X86-32]
                        See comment before function elanfreq_setup() in
-                       arch/i386/kernel/cpu/cpufreq/elanfreq.c.
+                       arch/x86/kernel/cpu/cpufreq/elanfreq.c.
 
        elevator=       [IOSCHED]
                        Format: {"anticipatory" | "cfq" | "deadline" | "noop"}
@@ -1679,6 +1679,10 @@ and is between 256 and 4096 characters. It is defined in the file
                        Format: <reboot_mode>[,<reboot_mode2>[,...]]
                        See arch/*/kernel/reboot.c or arch/*/kernel/process.c                   
 
+       relax_domain_level=
+                       [KNL, SMP] Set scheduler's default relax_domain_level.
+                       See Documentation/cpusets.txt.
+
        reserve=        [KNL,BUGS] Force the kernel to ignore some iomem area
 
        reservetop=     [X86-32]
index a8b430627473aa243995ab6f6e173b9cf1ff819e..e06cc59437e4a0b58422ed06450186054b9c38ab 100644 (file)
@@ -236,6 +236,11 @@ All md devices contain:
      writing the word for the desired state, however some states
      cannot be explicitly set, and some transitions are not allowed.
 
+     Select/poll works on this file.  All changes except between
+       active_idle and active (which can be frequent and are not
+       very interesting) are notified.  active->active_idle is
+       reported if the metadata is externally managed.
+
      clear
          No devices, no size, no level
          Writing is equivalent to STOP_ARRAY ioctl
@@ -292,6 +297,10 @@ Each directory contains:
              writemostly - device will only be subject to read
                         requests if there are no other options.
                         This applies only to raid1 arrays.
+             blocked  - device has failed, metadata is "external",
+                        and the failure hasn't been acknowledged yet.
+                        Writes that would write to this device if
+                        it were not faulty are blocked.
              spare    - device is working, but not a full member.
                         This includes spares that are in the process
                         of being recovered to
@@ -301,6 +310,12 @@ Each directory contains:
        Writing "remove" removes the device from the array.
        Writing "writemostly" sets the writemostly flag.
        Writing "-writemostly" clears the writemostly flag.
+       Writing "blocked" sets the "blocked" flag.
+       Writing "-blocked" clear the "blocked" flag and allows writes
+               to complete.
+
+       This file responds to select/poll. Any change to 'faulty'
+       or 'blocked' causes an event.
 
       errors
        An approximate count of read errors that have been detected on
@@ -381,6 +396,19 @@ also have
        'check' and 'repair' will start the appropriate process
            providing the current state is 'idle'.
 
+      This file responds to select/poll.  Any important change in the value
+      triggers a poll event.  Sometimes the value will briefly be
+      "recover" if a recovery seems to be needed, but cannot be
+      achieved. In that case, the transition to "recover" isn't
+      notified, but the transition away is.
+
+   degraded
+      This contains a count of the number of devices by which the
+      arrays is degraded.  So an optimal array with show '0'.  A
+      single failed/missing drive will show '1', etc.
+      This file responds to select/poll, any increase or decrease
+      in the count of missing devices will trigger an event.
+
    mismatch_count
       When performing 'check' and 'repair', and possibly when
       performing 'resync', md will count the number of errors that are
index 17a6e46fbd43abfce8ad5558f99200f8389ac650..17f1f91af35c7db3e80fed84c5833c80bc48526b 100644 (file)
@@ -81,23 +81,23 @@ inet_peer_minttl - INTEGER
        Minimum time-to-live of entries.  Should be enough to cover fragment
        time-to-live on the reassembling side.  This minimum time-to-live  is
        guaranteed if the pool size is less than inet_peer_threshold.
-       Measured in jiffies(1).
+       Measured in seconds.
 
 inet_peer_maxttl - INTEGER
        Maximum time-to-live of entries.  Unused entries will expire after
        this period of time if there is no memory pressure on the pool (i.e.
        when the number of entries in the pool is very small).
-       Measured in jiffies(1).
+       Measured in seconds.
 
 inet_peer_gc_mintime - INTEGER
        Minimum interval between garbage collection passes.  This interval is
        in effect under high memory pressure on the pool.
-       Measured in jiffies(1).
+       Measured in seconds.
 
 inet_peer_gc_maxtime - INTEGER
        Minimum interval between garbage collection passes.  This interval is
        in effect under low (or absent) memory pressure on the pool.
-       Measured in jiffies(1).
+       Measured in seconds.
 
 TCP variables: 
 
@@ -794,10 +794,6 @@ tag - INTEGER
        Allows you to write a number, which can be used as required.
        Default value is 0.
 
-(1) Jiffie: internal timeunit for the kernel. On the i386 1/100s, on the
-Alpha 1/1024s. See the HZ define in /usr/include/asm/param.h for the exact
-value on your system. 
-
 Alexey Kuznetsov.
 kuznet@ms2.inr.ac.ru
 
index 4bde53e85f3f02df27191234af82b3ba06b9f7a5..1e28e2ddb90a6e202ce65bd60778ff701afa8ee1 100644 (file)
@@ -83,9 +83,9 @@ Valid range: Limited by memory on system
 Default: 30 
 
 e. intr_type
-Specifies interrupt type. Possible values 1(INTA), 2(MSI), 3(MSI-X)
-Valid range: 1-3
-Default: 
+Specifies interrupt type. Possible values 0(INTA), 2(MSI-X)
+Valid values: 0, 2
+Default: 2
 
 5.  Performance suggestions
 General:
index aaae360312e479a547d583c8c1d172d3106fa48d..86d1c8e7b18f3c31b39dca8176acc3e9bdfdf96a 100644 (file)
@@ -1,4 +1,4 @@
   0 -> Unknown board                            (au0828)
-  1 -> Hauppauge HVR950Q                        (au0828)        [2040:7200]
+  1 -> Hauppauge HVR950Q                        (au0828)        [2040:7200,2040:7210,2040:7217,2040:721b,2040:721f,2040:7280,0fd9:0008]
   2 -> Hauppauge HVR850                         (au0828)        [2040:7240]
   3 -> DViCO FusionHDTV USB                     (au0828)        [0fe9:d620]
index e4230ed16ee7d1b45e757fd0c1c3a39848542c59..df3227605d59bf594c3a962a7bf08d9e8d5097a9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Slabinfo: Tool to get reports about slabs
  *
- * (C) 2007 sgi, Christoph Lameter <clameter@sgi.com>
+ * (C) 2007 sgi, Christoph Lameter
  *
  * Compile by:
  *
@@ -99,7 +99,7 @@ void fatal(const char *x, ...)
 
 void usage(void)
 {
-       printf("slabinfo 5/7/2007. (c) 2007 sgi. clameter@sgi.com\n\n"
+       printf("slabinfo 5/7/2007. (c) 2007 sgi.\n\n"
                "slabinfo [-ahnpvtsz] [-d debugopts] [slab-regexp]\n"
                "-a|--aliases           Show aliases\n"
                "-A|--activity          Most active slabs first\n"
index 7c13f22a0c9ee44aac54dd0c40ea65a828a545d9..bb1f5c6e28b3eaf89fc2f8a3b401311c855f8b26 100644 (file)
@@ -266,4 +266,4 @@ of other objects.
 
        slub_debug=FZ,dentry
 
-Christoph Lameter, <clameter@sgi.com>, May 30, 2007
+Christoph Lameter, May 30, 2007
index 8f0ec46a7096132683b5ba7368c239c6519f127d..6476125363e0f49f4cebf99b4c8e2745072a295c 100644 (file)
@@ -763,9 +763,10 @@ S: Maintained
 
 AUXILIARY DISPLAY DRIVERS
 P:     Miguel Ojeda Sandonis
-M:     maxextreme@gmail.com
+M:     miguel.ojeda.sandonis@gmail.com
 L:     linux-kernel@vger.kernel.org
-W:     http://auxdisplay.googlepages.com/
+W:     http://miguelojeda.es/auxdisplay.htm
+W:     http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm
 S:     Maintained
 
 AVR32 ARCHITECTURE
@@ -1055,16 +1056,18 @@ S:      Supported
 
 CFAG12864B LCD DRIVER
 P:     Miguel Ojeda Sandonis
-M:     maxextreme@gmail.com
+M:     miguel.ojeda.sandonis@gmail.com
 L:     linux-kernel@vger.kernel.org
-W:     http://auxdisplay.googlepages.com/
+W:     http://miguelojeda.es/auxdisplay.htm
+W:     http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm
 S:     Maintained
 
 CFAG12864BFB LCD FRAMEBUFFER DRIVER
 P:     Miguel Ojeda Sandonis
-M:     maxextreme@gmail.com
+M:     miguel.ojeda.sandonis@gmail.com
 L:     linux-kernel@vger.kernel.org
-W:     http://auxdisplay.googlepages.com/
+W:     http://miguelojeda.es/auxdisplay.htm
+W:     http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm
 S:     Maintained
 
 CFG80211 and NL80211
@@ -1420,6 +1423,14 @@ M:       kristen.c.accardi@intel.com
 L:     linux-acpi@vger.kernel.org
 S:     Supported
 
+DOCUMENTATION (/Documentation directory)
+P:     Michael Kerrisk
+M:     mtk.manpages@gmail.com
+P:     Randy Dunlap
+M:     rdunlap@xenotime.net
+L:     linux-doc@vger.kernel.org
+S:     Maintained
+
 DOUBLETALK DRIVER
 P:     James R. Van Zandt
 M:     jrv@vanzandt.mv.com
@@ -1626,13 +1637,13 @@ S:      Maintained
 
 EXT3 FILE SYSTEM
 P:     Stephen Tweedie, Andrew Morton
-M:     sct@redhat.com, akpm@linux-foundation.org, adilger@clusterfs.com
+M:     sct@redhat.com, akpm@linux-foundation.org, adilger@sun.com
 L:     linux-ext4@vger.kernel.org
 S:     Maintained
 
 EXT4 FILE SYSTEM
 P:     Stephen Tweedie, Andrew Morton
-M:     sct@redhat.com, akpm@linux-foundation.org, adilger@clusterfs.com
+M:     sct@redhat.com, akpm@linux-foundation.org, adilger@sun.com
 L:     linux-ext4@vger.kernel.org
 S:     Maintained
 
@@ -2428,9 +2439,10 @@ S:       Maintained
 
 KS0108 LCD CONTROLLER DRIVER
 P:     Miguel Ojeda Sandonis
-M:     maxextreme@gmail.com
+M:     miguel.ojeda.sandonis@gmail.com
 L:     linux-kernel@vger.kernel.org
-W:     http://auxdisplay.googlepages.com/
+W:     http://miguelojeda.es/auxdisplay.htm
+W:     http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm
 S:     Maintained
 
 LAPB module
@@ -2474,9 +2486,11 @@ M:       James.Bottomley@HansenPartnership.com
 W:     http://www.hansenpartnership.com/voyager
 S:     Maintained
 
-LINUX FOR POWERPC
+LINUX FOR POWERPC (32-BIT AND 64-BIT)
 P:     Paul Mackerras
 M:     paulus@samba.org
+P:     Benjamin Herrenschmidt
+M:     benh@kernel.crashing.org
 W:     http://www.penguinppc.org/
 L:     linuxppc-dev@ozlabs.org
 T:     git kernel.org:/pub/scm/linux/kernel/git/paulus/powerpc.git
@@ -2516,13 +2530,6 @@ W:       http://wiki.secretlab.ca/index.php/Linux_on_Xilinx_Virtex
 L:     linuxppc-dev@ozlabs.org
 S:     Maintained
 
-LINUX FOR POWERPC BOOT CODE
-P:     Tom Rini
-M:     trini@kernel.crashing.org
-W:     http://www.penguinppc.org/
-L:     linuxppc-dev@ozlabs.org
-S:     Maintained
-
 LINUX FOR POWERPC EMBEDDED PPC8XX
 P:     Vitaly Bordug
 M:     vitb@kernel.crashing.org
@@ -2551,17 +2558,6 @@ P:       Arnaldo Carvalho de Melo
 M:     acme@ghostprotocols.net
 S:     Maintained
 
-LINUX FOR 64BIT POWERPC
-P:     Paul Mackerras
-M:     paulus@samba.org
-M:     paulus@au.ibm.com
-P:     Anton Blanchard
-M:     anton@samba.org
-M:     anton@au.ibm.com
-W:     http://www.penguinppc.org/ppc64/
-L:     linuxppc-dev@ozlabs.org
-S:     Supported
-
 LINUX SECURITY MODULE (LSM) FRAMEWORK
 P:     Chris Wright
 M:     chrisw@sous-sol.org
@@ -2680,8 +2676,8 @@ S:        Supported
 MAN-PAGES: MANUAL PAGES FOR LINUX -- Sections 2, 3, 4, 5, and 7
 P:     Michael Kerrisk
 M:     mtk.manpages@gmail.com
-W:     ftp://ftp.kernel.org/pub/linux/docs/manpages
-S:     Maintained
+W:     http://www.kernel.org/doc/man-pages
+S:     Supported
 
 MARVELL LIBERTAS WIRELESS DRIVER
 P:     Dan Williams
@@ -2814,6 +2810,12 @@ W:       https://tango.0pointer.de/mailman/listinfo/s270-linux
 W:     http://0pointer.de/lennart/tchibo.html
 S:     Maintained
 
+MULTIFUNCTION DEVICES (MFD)
+P:     Samuel Ortiz
+M:     sameo@openedhand.com
+L:     linux-kernel@vger.kernel.org
+S:     Supported
+
 MULTIMEDIA CARD (MMC), SECURE DIGITAL (SD) AND SDIO SUBSYSTEM
 P:     Pierre Ossman
 M:     drzeus-mmc@drzeus.cx
@@ -3195,8 +3197,8 @@ L:        netdev@vger.kernel.org
 S:     Maintained
 
 PER-TASK DELAY ACCOUNTING
-P:     Shailabh Nagar
-M:     nagar@watson.ibm.com
+P:     Balbir Singh
+M:     balbir@linux.vnet.ibm.com
 L:     linux-kernel@vger.kernel.org
 S:     Maintained
 
@@ -3688,7 +3690,7 @@ S:        Maintained
 
 SLAB ALLOCATOR
 P:     Christoph Lameter
-M:     clameter@sgi.com
+M:     cl@linux-foundation.org
 P:     Pekka Enberg
 M:     penberg@cs.helsinki.fi
 P:     Matt Mackall
@@ -3898,8 +3900,8 @@ M:        hch@infradead.org
 S:     Maintained
 
 TASKSTATS STATISTICS INTERFACE
-P:     Shailabh Nagar
-M:     nagar@watson.ibm.com
+P:     Balbir Singh
+M:     balbir@linux.vnet.ibm.com
 L:     linux-kernel@vger.kernel.org
 S:     Maintained
 
@@ -3995,7 +3997,8 @@ W:        http://www.buzzard.org.uk/toshiba/
 S:     Maintained
 
 TPM DEVICE DRIVER
-P:     Kylene Hall
+P:     Debora Velarde
+P:     Rajiv Andrade
 M:     tpmdd-devel@lists.sourceforge.net
 W:     http://tpmdd.sourceforge.net
 P:     Marcel Selhorst
@@ -4314,6 +4317,14 @@ L:       netdev@vger.kernel.org
 W:     http://www.linux-usb.org/usbnet
 S:     Maintained
 
+USB VIDEO CLASS
+P:     Laurent Pinchart
+M:     laurent.pinchart@skynet.be
+L:     linx-uvc-devel@berlios.de
+L:     video4linux-list@redhat.com
+W:     http://linux-uvc.berlios.de
+S:     Maintained
+
 USB W996[87]CF DRIVER
 P:     Luca Risolia
 M:     luca.risolia@studio.unibo.it
index 6aff5f47c21d1f13c633de4f14835688c49244db..6315424a00b9fb2634f38f17833d7f302968a664 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 6
 SUBLEVEL = 26
-EXTRAVERSION = -rc8
+EXTRAVERSION = -rc9
 NAME = Rotary Wombat
 
 # *DOCUMENTATION*
index f13249be17c50736e23686158854799164582aeb..ef37fc1acaeae91eb7bb9ac1010444856ce177b2 100644 (file)
@@ -25,6 +25,13 @@ SECTIONS
        } :kernel
        _etext = .;     /* End of text section */
 
+       NOTES :kernel :note
+       .dummy : {
+               *(.dummy)
+       } :kernel
+
+       RODATA
+
        /* Exception table */
        . = ALIGN(16);
        __ex_table : {
@@ -33,13 +40,6 @@ SECTIONS
                __stop___ex_table = .;
        }
 
-       NOTES :kernel :note
-       .dummy : {
-               *(.dummy)
-       } :kernel
-
-       RODATA
-
        /* Will be freed after init */
        . = ALIGN(PAGE_SIZE);
        /* Init code and data */
index 52fc6a883281120f7c80e2d332247971658b1ffa..2744673314b470cb84b68d1ff9a040a0356d34af 100644 (file)
@@ -650,7 +650,8 @@ EXPORT_SYMBOL(dma_map_sg);
 EXPORT_SYMBOL(dma_unmap_sg);
 EXPORT_SYMBOL(dma_sync_single_for_cpu);
 EXPORT_SYMBOL(dma_sync_single_for_device);
-EXPORT_SYMBOL(dma_sync_sg);
+EXPORT_SYMBOL(dma_sync_sg_for_cpu);
+EXPORT_SYMBOL(dma_sync_sg_for_device);
 EXPORT_SYMBOL(dmabounce_register_dev);
 EXPORT_SYMBOL(dmabounce_unregister_dev);
 
index 02cede295e89795b02e77f9167c70f375c06fd48..dbf68dc50ae2fa1502a21edea0eba88dbee4b52b 100644 (file)
@@ -42,7 +42,7 @@
 #define GPMC_STATUS            0x54
 #define GPMC_PREFETCH_CONFIG1  0x1e0
 #define GPMC_PREFETCH_CONFIG2  0x1e4
-#define GPMC_PREFETCH_CONTROL  0x1e8
+#define GPMC_PREFETCH_CONTROL  0x1ec
 #define GPMC_PREFETCH_STATUS   0x1f0
 #define GPMC_ECC_CONFIG                0x1f4
 #define GPMC_ECC_CONTROL       0x1f8
index 3e57428affeedac7f32b8fd883bb159810b63181..8e813ed575194d95af51fb326747e8cd86b975c8 100644 (file)
@@ -74,6 +74,8 @@ static DEFINE_SPINLOCK(boot_lock);
 
 void __cpuinit platform_secondary_init(unsigned int cpu)
 {
+       trace_hardirqs_off();
+
        /*
         * the primary core may have used a "cross call" soft interrupt
         * to get this processor out of WFI in the BootMonitor - make
index c00eda588cd81b2ad87d51646a27b7ffcd577549..39c637b0ffeacdceba864caf3a23c1e7f0eeb3b4 100644 (file)
@@ -501,8 +501,6 @@ static inline void omap_enable_channel_irq(int lch)
 
        /* Enable some nice interrupts. */
        OMAP_DMA_CICR_REG(lch) = dma_chan[lch].enabled_irqs;
-
-       dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
 }
 
 static void omap_disable_channel_irq(int lch)
index 917325bfbd849723899d6bfaa26e21c39d566ed8..6be0c50122e8c627102fbcbe5692cc26013b0135 100644 (file)
@@ -254,7 +254,8 @@ close_cplbtab(struct cplb_tab *table)
 }
 
 /* helper function */
-static void __fill_code_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
+static void __init
+__fill_code_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
 {
        if (cplb_data[i].psize) {
                fill_cplbtab(t,
@@ -291,7 +292,8 @@ static void __fill_code_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_en
        }
 }
 
-static void __fill_data_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
+static void __init
+__fill_data_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
 {
        if (cplb_data[i].psize) {
                fill_cplbtab(t,
index 73647c158774e0acd31efcf3e7385dd2b104365a..07402f57c9dea2f401bb40110f92dc57e5601281 100644 (file)
@@ -60,9 +60,14 @@ static struct irq_chip bad_chip = {
 };
 
 static struct irq_desc bad_irq_desc = {
+       .status = IRQ_DISABLED,
        .chip = &bad_chip,
        .handle_irq = handle_bad_irq,
        .depth = 1,
+       .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
+#ifdef CONFIG_SMP
+       .affinity = CPU_MASK_ALL
+#endif
 };
 
 int show_interrupts(struct seq_file *p, void *v)
index 4ae15c8c2488fa8741086943ea58ee915bfbf69a..632cda8f2e7667fab870c85dd97af1fb2ed118f7 100644 (file)
@@ -547,7 +547,8 @@ setup_arch (char **cmdline_p)
 # ifdef CONFIG_ACPI_NUMA
        acpi_numa_init();
        per_cpu_scan_finalize((cpus_weight(early_cpu_possible_map) == 0 ?
-               32 : cpus_weight(early_cpu_possible_map)), additional_cpus);
+               32 : cpus_weight(early_cpu_possible_map)),
+               additional_cpus > 0 ? additional_cpus : 0);
 # endif
 #else
 # ifdef CONFIG_SMP
index 8c73643f2d664a5d9f8dd103ed67e5e5bbf037d4..aad1b7b1fff95e19ee19d3175ce3f9a5a7c8c1a6 100644 (file)
@@ -117,6 +117,7 @@ void account_system_vtime(struct task_struct *tsk)
 
        local_irq_restore(flags);
 }
+EXPORT_SYMBOL_GPL(account_system_vtime);
 
 /*
  * Called from the timer interrupt handler to charge accumulated user time
index e5a7c5d96364f73f5cf700a9ac70d9ee67d3bda8..24c5dee9176872d5358eb228a6228071fe28da25 100644 (file)
@@ -1006,7 +1006,7 @@ config BOOT_ELF32
 config MIPS_L1_CACHE_SHIFT
        int
        default "4" if MACH_DECSTATION
-       default "7" if SGI_IP27 || SGI_IP28 || SNI_RM
+       default "7" if SGI_IP22 || SGI_IP27 || SGI_IP28 || SNI_RM
        default "4" if PMC_MSP4200_EVAL
        default "5"
 
index 795cb8fb0d740b6de17b17de1d12b61c7036d80c..b5fc4eb412d2e53b3544f0d67f032cecf4933095 100644 (file)
@@ -161,6 +161,9 @@ void __init txx9_tmr_init(unsigned long baseaddr)
        struct txx9_tmr_reg __iomem *tmrptr;
 
        tmrptr = ioremap(baseaddr, sizeof(struct txx9_tmr_reg));
+       /* Start once to make CounterResetEnable effective */
+       __raw_writel(TXx9_TMTCR_CRE | TXx9_TMTCR_TCE, &tmrptr->tcr);
+       /* Stop and reset the counter */
        __raw_writel(TXx9_TMTCR_CRE, &tmrptr->tcr);
        __raw_writel(0, &tmrptr->tisr);
        __raw_writel(0xffffffff, &tmrptr->cpra);
index b0ea0e43ba482b542f533d172277c6c03cee7bbd..0d6b6663d5f6756e1beb4c1426573a7424bc8c25 100644 (file)
@@ -425,6 +425,11 @@ static void ip32_irq0(void)
        BUILD_BUG_ON(MACEISA_SERIAL2_RDMAOR_IRQ - MACEISA_AUDIO_SW_IRQ != 31);
 
        crime_int = crime->istat & crime_mask;
+
+       /* crime sometime delivers spurious interrupts, ignore them */
+       if (unlikely(crime_int == 0))
+               return;
+
        irq = MACE_VID_IN1_IRQ + __ffs(crime_int);
 
        if (crime_int & CRIME_MACEISA_INT_MASK) {
index 6d19628634e3a0fb5635d6a4f2e959c16a2b5c47..f9eb9753a4043341c79d33bd5d328ab028dce308 100644 (file)
  */
 #include <linux/module.h>
 #include <asm/uaccess.h>
+#include <asm/pgtable.h>
 
 
+EXPORT_SYMBOL(empty_zero_page);
+
 EXPORT_SYMBOL(change_bit);
 EXPORT_SYMBOL(test_and_change_bit);
 
@@ -31,7 +34,9 @@ extern u64 __ashrdi3(u64, unsigned);
 extern u64 __ashldi3(u64, unsigned);
 extern u64 __lshrdi3(u64, unsigned);
 extern s64 __negdi2(s64);
+extern int __ucmpdi2(u64, u64);
 EXPORT_SYMBOL(__ashrdi3);
 EXPORT_SYMBOL(__ashldi3);
 EXPORT_SYMBOL(__lshrdi3);
 EXPORT_SYMBOL(__negdi2);
+EXPORT_SYMBOL(__ucmpdi2);
index 9c623c88387bbb4ee844c39f43513398131588b5..b28c9a60445bda4df1f4f83de51346b121e36067 100644 (file)
@@ -153,6 +153,7 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
        return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0,
                       NULL, NULL);
 }
+EXPORT_SYMBOL(kernel_thread);
 
 /*
  * free current thread data structures etc..
index fdfa9ec5b5bbec14a0471599ec76bdae5e6ada5c..0cd2346f4c136884a7320679a2a76557c312e6e0 100644 (file)
@@ -4,4 +4,4 @@
 
 lib-y = delay.o usercopy.o checksum.o bitops.o memcpy.o memmove.o memset.o
 lib-y += do_csum.o
-lib-y += __ashldi3.o __ashrdi3.o __lshrdi3.o negdi2.o
+lib-y += __ashldi3.o __ashrdi3.o __lshrdi3.o negdi2.o __ucmpdi2.o
diff --git a/arch/mn10300/lib/__ucmpdi2.S b/arch/mn10300/lib/__ucmpdi2.S
new file mode 100644 (file)
index 0000000..60dcbdf
--- /dev/null
@@ -0,0 +1,43 @@
+/* __ucmpdi2.S: 64-bit unsigned compare
+ *
+ * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+
+        .text
+        .p2align       4
+
+###############################################################################
+#
+# int __ucmpdi2(unsigned long long a [D0:D1],
+#              unsigned long long b [(SP,12),(SP,16)])
+#
+# - returns 0, 1, or 2 as a <, =, > b respectively.
+#
+###############################################################################
+        .globl         __ucmpdi2
+        .type          __ucmpdi2,@function
+__ucmpdi2:
+       mov             (12,sp),a0              # b.lsw
+       mov             (16,sp),a1              # b.msw
+
+       sub             a0,d0
+       subc            a1,d1                   # may clear Z, never sets it
+       bne             __ucmpdi2_differ        # a.msw != b.msw
+       mov             +1,d0
+       rets
+
+__ucmpdi2_differ:
+       # C flag is set if LE, clear if GE
+       subc            d0,d0                   # -1 if LE, 0 if GE
+       add             +1,d0                   #  0 if LE, 1 if GE
+       add             d0,d0                   #  0 if LE, 2 if GE
+       rets
+
+       .size           __ucmpdi2, .-__ucmpdi2
index 1cee2f9fdf06bb0255d182ddb40bede780b88c6f..095e04db1c0e1f75e39cbd01c6419c8b890295c2 100644 (file)
@@ -273,7 +273,8 @@ endif
 initrd-  := $(patsubst zImage%, zImage.initrd%, $(image-n) $(image-))
 initrd-y := $(patsubst zImage%, zImage.initrd%, \
                $(patsubst dtbImage%, dtbImage.initrd%, \
-               $(patsubst treeImage%, treeImage.initrd%, $(image-y))))
+               $(patsubst simpleImage%, simpleImage.initrd%, \
+               $(patsubst treeImage%, treeImage.initrd%, $(image-y)))))
 initrd-y := $(filter-out $(image-y), $(initrd-y))
 targets        += $(image-y) $(initrd-y)
 
index 61dd17449ddceb06267babf5373505984f7abd9c..cf37f5ca4b71e6b30c2a3d7bb46fb17f8bf66f50 100644 (file)
@@ -136,6 +136,11 @@ static int __init add_legacy_soc_port(struct device_node *np,
        if (of_get_property(np, "clock-frequency", NULL) == NULL)
                return -1;
 
+       /* if reg-shift or offset, don't try to use it */
+       if ((of_get_property(np, "reg-shift", NULL) != NULL) ||
+               (of_get_property(np, "reg-offset", NULL) != NULL))
+               return -1;
+
        /* if rtas uses this device, don't try to use it as well */
        if (of_get_property(np, "used-by-rtas", NULL) != NULL)
                return -1;
index 41c7fd91e99e5836cbaef5c7d6803334bc37a206..fe92e65103edad4851465f0a00b4615011c76676 100644 (file)
@@ -14,6 +14,7 @@ static struct mpc52xx_sdma __iomem *bes;
 static struct mpc52xx_xlb __iomem *xlb;
 static struct mpc52xx_gpio __iomem *gps;
 static struct mpc52xx_gpio_wkup __iomem *gpw;
+static void __iomem *pci;
 static void __iomem *sram;
 static const int sram_size = 0x4000;   /* 16 kBytes */
 static void __iomem *mbar;
@@ -50,6 +51,8 @@ static int lite5200_pm_prepare(void)
                { .type = "builtin", .compatible = "mpc5200", }, /* efika */
                {}
        };
+       u64 regaddr64 = 0;
+       const u32 *regaddr_p;
 
        /* deep sleep? let mpc52xx code handle that */
        if (lite5200_pm_target_state == PM_SUSPEND_STANDBY)
@@ -60,8 +63,12 @@ static int lite5200_pm_prepare(void)
 
        /* map registers */
        np = of_find_matching_node(NULL, immr_ids);
-       mbar = of_iomap(np, 0);
+       regaddr_p = of_get_address(np, 0, NULL, NULL);
+       if (regaddr_p)
+               regaddr64 = of_translate_address(np, regaddr_p);
        of_node_put(np);
+
+       mbar = ioremap((u32) regaddr64, 0xC000);
        if (!mbar) {
                printk(KERN_ERR "%s:%i Error mapping registers\n", __func__, __LINE__);
                return -ENOSYS;
@@ -71,6 +78,7 @@ static int lite5200_pm_prepare(void)
        pic = mbar + 0x500;
        gps = mbar + 0xb00;
        gpw = mbar + 0xc00;
+       pci = mbar + 0xd00;
        bes = mbar + 0x1200;
        xlb = mbar + 0x1f00;
        sram = mbar + 0x8000;
@@ -85,6 +93,7 @@ static struct mpc52xx_sdma sbes;
 static struct mpc52xx_xlb sxlb;
 static struct mpc52xx_gpio sgps;
 static struct mpc52xx_gpio_wkup sgpw;
+static char spci[0x200];
 
 static void lite5200_save_regs(void)
 {
@@ -94,6 +103,7 @@ static void lite5200_save_regs(void)
        _memcpy_fromio(&sxlb, xlb, sizeof(*xlb));
        _memcpy_fromio(&sgps, gps, sizeof(*gps));
        _memcpy_fromio(&sgpw, gpw, sizeof(*gpw));
+       _memcpy_fromio(spci, pci, 0x200);
 
        _memcpy_fromio(saved_sram, sram, sram_size);
 }
@@ -103,6 +113,8 @@ static void lite5200_restore_regs(void)
        int i;
        _memcpy_toio(sram, saved_sram, sram_size);
 
+       /* PCI Configuration */
+       _memcpy_toio(pci, spci, 0x200);
 
        /*
         * GPIOs. Interrupt Master Enable has higher address then other
index e0edaaa6920af63832979a04d4f525acafe64e8a..bf07b6f50fa178268f9d81388a615a7a8abff32b 100644 (file)
@@ -966,8 +966,8 @@ config NUMA_EMU
          number of nodes. This is only useful for debugging.
 
 config NODES_SHIFT
-       int "Max num nodes shift(1-15)"
-       range 1 15  if X86_64
+       int "Max num nodes shift(1-9)"
+       range 1 9  if X86_64
        default "6" if X86_64
        default "4" if X86_NUMAQ
        default "3"
index f9b77fb37e5b7ccb9ca4e07f74296fe00f572daa..3355973b12ac6f8ca11ea0f5486a6643373d8042 100644 (file)
@@ -5,6 +5,7 @@
 #include <asm/msr-index.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
+#include <asm/processor-flags.h>
 
        .code16
        .section ".header", "a"
@@ -24,6 +25,11 @@ pmode_gdt:   .quad   0
 realmode_flags:        .long   0
 real_magic:    .long   0
 trampoline_segment:    .word 0
+_pad1:         .byte   0
+wakeup_jmp:    .byte   0xea    /* ljmpw */
+wakeup_jmp_off:        .word   3f
+wakeup_jmp_seg:        .word   0
+wakeup_gdt:    .quad   0, 0, 0
 signature:     .long   0x51ee1111
 
        .text
@@ -34,11 +40,34 @@ _start:
        cli
        cld
 
+       /* Apparently some dimwit BIOS programmers don't know how to
+          program a PM to RM transition, and we might end up here with
+          junk in the data segment descriptor registers.  The only way
+          to repair that is to go into PM and fix it ourselves... */
+       movw    $16, %cx
+       lgdtl   %cs:wakeup_gdt
+       movl    %cr0, %eax
+       orb     $X86_CR0_PE, %al
+       movl    %eax, %cr0
+       jmp     1f
+1:     ljmpw   $8, $2f
+2:
+       movw    %cx, %ds
+       movw    %cx, %es
+       movw    %cx, %ss
+       movw    %cx, %fs
+       movw    %cx, %gs
+
+       andb    $~X86_CR0_PE, %al
+       movl    %eax, %cr0
+       jmp     wakeup_jmp
+3:
        /* Set up segments */
        movw    %cs, %ax
        movw    %ax, %ds
        movw    %ax, %es
        movw    %ax, %ss
+       lidtl   wakeup_idt
 
        movl    $wakeup_stack_end, %esp
 
@@ -98,7 +127,14 @@ bogus_real_magic:
        jmp     1b
 
        .data
-       .balign 4
+       .balign 8
+
+       /* This is the standard real-mode IDT */
+wakeup_idt:
+       .word   0xffff          /* limit */
+       .long   0               /* address */
+       .word   0
+
        .globl  HEAP, heap_end
 HEAP:
        .long   wakeup_heap
index ef8166fe8020ec0aaf7de3b1f57f3662f6c20527..69d38d0b2b6436cd83886a6200405eef603c6eda 100644 (file)
@@ -24,6 +24,11 @@ struct wakeup_header {
        u32 realmode_flags;
        u32 real_magic;
        u16 trampoline_segment; /* segment with trampoline code, 64-bit only */
+       u8  _pad1;
+       u8  wakeup_jmp;
+       u16 wakeup_jmp_off;
+       u16 wakeup_jmp_seg;
+       u64 wakeup_gdt[3];
        u32 signature;          /* To check we have correct structure */
 } __attribute__((__packed__));
 
index afc25ee9964b6628ba4808e13b48c192caeec87b..36af01f029eddbfe7b2bdc05a0f2b59ab5c3666a 100644 (file)
@@ -50,6 +50,20 @@ int acpi_save_state_mem(void)
 
        header->video_mode = saved_video_mode;
 
+       header->wakeup_jmp_seg = acpi_wakeup_address >> 4;
+       /* GDT[0]: GDT self-pointer */
+       header->wakeup_gdt[0] =
+               (u64)(sizeof(header->wakeup_gdt) - 1) +
+               ((u64)(acpi_wakeup_address +
+                       ((char *)&header->wakeup_gdt - (char *)acpi_realmode))
+                               << 16);
+       /* GDT[1]: real-mode-like code segment */
+       header->wakeup_gdt[1] = (0x009bULL << 40) +
+               ((u64)acpi_wakeup_address << 16) + 0xffff;
+       /* GDT[2]: real-mode-like data segment */
+       header->wakeup_gdt[2] = (0x0093ULL << 40) +
+               ((u64)acpi_wakeup_address << 16) + 0xffff;
+
 #ifndef CONFIG_64BIT
        store_gdt((struct desc_ptr *)&header->pmode_gdt);
 
@@ -111,7 +125,7 @@ void __init acpi_reserve_bootmem(void)
                return;
        }
 
-       acpi_wakeup_address = acpi_realmode;
+       acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
 }
 
 
index 5d23d85624d46c130cc595517b05c773a6daa2c8..4b63c8e1f13b1b078a42dc113403c1952c52f3cc 100644 (file)
@@ -49,13 +49,13 @@ void efi_call_phys_prelog(void)
        local_irq_save(efi_rt_eflags);
 
        /*
-        * If I don't have PSE, I should just duplicate two entries in page
-        * directory. If I have PSE, I just need to duplicate one entry in
+        * If I don't have PAE, I should just duplicate two entries in page
+        * directory. If I have PAE, I just need to duplicate one entry in
         * page directory.
         */
        cr4 = read_cr4();
 
-       if (cr4 & X86_CR4_PSE) {
+       if (cr4 & X86_CR4_PAE) {
                efi_bak_pg_dir_pointer[0].pgd =
                    swapper_pg_dir[pgd_index(0)].pgd;
                swapper_pg_dir[0].pgd =
@@ -93,7 +93,7 @@ void efi_call_phys_epilog(void)
 
        cr4 = read_cr4();
 
-       if (cr4 & X86_CR4_PSE) {
+       if (cr4 & X86_CR4_PAE) {
                swapper_pg_dir[pgd_index(0)].pgd =
                    efi_bak_pg_dir_pointer[0].pgd;
        } else {
index 10a1955bb1d17df7f90bff735ae733b648f58c15..b817974ef9420bba5702327a1089156dcb5d72c3 100644 (file)
@@ -128,7 +128,7 @@ ident_complete:
        /* Fixup phys_base */
        addq    %rbp, phys_base(%rip)
 
-#ifdef CONFIG_SMP
+#ifdef CONFIG_X86_TRAMPOLINE
        addq    %rbp, trampoline_level4_pgt + 0(%rip)
        addq    %rbp, trampoline_level4_pgt + (511*8)(%rip)
 #endif
index eb9ddd8efb828175e7be0efcc0616257c67c5943..95e80e5033c3b5c36fb66fd5ac7be4d99f04d421 100644 (file)
@@ -162,7 +162,7 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
        int ret;
 
        if (!cpu_has_fxsr)
-               return -ENODEV;
+               return -EIO;
 
        ret = init_fpu(target);
        if (ret)
@@ -179,7 +179,7 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
        int ret;
 
        if (!cpu_has_fxsr)
-               return -ENODEV;
+               return -EIO;
 
        ret = init_fpu(target);
        if (ret)
index 56078d61c79315847ee3a2e761184846b9e1345f..3e1cecedde42747261c94053a53191ffa7291107 100644 (file)
@@ -996,7 +996,6 @@ do_rest:
 #endif
                cpu_clear(cpu, cpu_callout_map); /* was set by do_boot_cpu() */
                cpu_clear(cpu, cpu_initialized); /* was set by cpu_init() */
-               cpu_clear(cpu, cpu_possible_map);
                cpu_clear(cpu, cpu_present_map);
                per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID;
        }
index 156e6d7b0e329cd84b06342dffd37e46ec28ac9a..819dad973b1375bc5da5a90297c5c41788d2a652 100644 (file)
@@ -135,7 +135,7 @@ static __init void *spp_getpage(void)
        return ptr;
 }
 
-static void
+static __init void
 set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot)
 {
        pgd_t *pgd;
@@ -214,7 +214,7 @@ void __init cleanup_highmap(void)
 }
 
 /* NOTE: this is meant to be run only at boot */
-void __set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
+void __init __set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
 {
        unsigned long address = __fix_to_virt(idx);
 
@@ -526,7 +526,8 @@ static void __init early_memtest(unsigned long start, unsigned long end)
                                t_size = end - t_start;
 
                        printk(KERN_CONT "\n  %016llx - %016llx pattern %d",
-                               t_start, t_start + t_size, pattern);
+                               (unsigned long long)t_start,
+                               (unsigned long long)t_start + t_size, pattern);
 
                        memtest(t_start, t_size, pattern);
 
index df40bf74ea751da4a0556a5b6603af1f3989a39b..4e527e7893a8c134481aac1c3e7ed621882745ad 100644 (file)
@@ -185,7 +185,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
        if (val & _PAGE_PRESENT) {
                unsigned long mfn = (val & PTE_MASK) >> PAGE_SHIFT;
                pteval_t flags = val & ~PTE_MASK;
-               val = (mfn_to_pfn(mfn) << PAGE_SHIFT) | flags;
+               val = ((pteval_t)mfn_to_pfn(mfn) << PAGE_SHIFT) | flags;
        }
 
        return val;
@@ -196,7 +196,7 @@ static pteval_t pte_pfn_to_mfn(pteval_t val)
        if (val & _PAGE_PRESENT) {
                unsigned long pfn = (val & PTE_MASK) >> PAGE_SHIFT;
                pteval_t flags = val & ~PTE_MASK;
-               val = (pfn_to_mfn(pfn) << PAGE_SHIFT) | flags;
+               val = ((pteval_t)pfn_to_mfn(pfn) << PAGE_SHIFT) | flags;
        }
 
        return val;
index 8c3946787dbbbaedd3381a195ab7851e84ec8272..743f33a01a079166c503167038d3657f8850dadd 100644 (file)
@@ -831,6 +831,8 @@ static void as_completed_request(struct request_queue *q, struct request *rq)
        }
 
        if (ad->changed_batch && ad->nr_dispatched == 1) {
+               ad->current_batch_expires = jiffies +
+                                       ad->batch_expire[ad->batch_data_dir];
                kblockd_schedule_work(&ad->antic_work);
                ad->changed_batch = 0;
 
index 26038c2a2a71bb20026a0631e890b6d57705805e..61b6c5beb2d347d32d1fe1e3ee1ff8195e5f731d 100644 (file)
@@ -377,6 +377,9 @@ static int __init bay_init(void)
 
        INIT_LIST_HEAD(&drive_bays);
 
+       if (acpi_disabled)
+               return -ENODEV;
+
        /* look for dockable drive bays */
        acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
                ACPI_UINT32_MAX, find_bay, &bays, NULL);
index 96c542f7fded0c3abe8bfb3e07eec1a15a52ae41..bb7c51f712bd6cde630e4e8e5a771ca9d9e5fc55 100644 (file)
@@ -917,6 +917,9 @@ static int __init dock_init(void)
 
        dock_station = NULL;
 
+       if (acpi_disabled)
+               return 0;
+
        /* look for a dock station */
        acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
                            ACPI_UINT32_MAX, find_dock, &num, NULL);
index 2808dc60fd670065a94ddf4c0be90876fd3fc20a..9b227d4dc9c9bbd43b7649b66b7ee311371f7eaf 100644 (file)
@@ -333,6 +333,9 @@ static int __init acpi_rtc_init(void)
 {
        struct device *dev = get_rtc_dev();
 
+       if (acpi_disabled)
+               return 0;
+
        if (dev) {
                rtc_wake_setup();
                rtc_info.wake_on = rtc_wake_on;
index c3b0cd88d09f22972342af30e02abfafe18fadcc..495c63a3e0afb1fce2e4fcb6801020ad2f8413ad 100644 (file)
@@ -36,9 +36,8 @@ static int acpi_sleep_prepare(u32 acpi_state)
                if (!acpi_wakeup_address) {
                        return -EFAULT;
                }
-               acpi_set_firmware_waking_vector((acpi_physical_address)
-                                               virt_to_phys((void *)
-                                                            acpi_wakeup_address));
+               acpi_set_firmware_waking_vector(
+                               (acpi_physical_address)acpi_wakeup_address);
 
        }
        ACPI_FLUSH_CPU_CACHE();
index 224c57c0338106e2d283f1b811de2bdd66b74b7f..4ebbba2b6b194f4f6c6532ad698d9a0582e2519f 100644 (file)
@@ -315,8 +315,11 @@ acpi_system_write_alarm(struct file *file,
                cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control);
        if (acpi_gbl_FADT.month_alarm)
                cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control);
-       if (acpi_gbl_FADT.century)
+       if (acpi_gbl_FADT.century) {
+               if (adjust)
+                       yr += cmos_bcd_read(acpi_gbl_FADT.century, rtc_control) * 100;
                cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control);
+       }
        /* enable the rtc alarm interrupt */
        rtc_control |= RTC_AIE;
        CMOS_WRITE(rtc_control, RTC_CONTROL);
index 6a4a2a25d97a6bd258f1fee4c7cad287d7ef8c0d..5e6468a7ca4bd2a051b6ee9244297933a3ee7a60 100644 (file)
@@ -1777,7 +1777,7 @@ static irqreturn_t ahci_interrupt(int irq, void *dev_instance)
        struct ahci_host_priv *hpriv;
        unsigned int i, handled = 0;
        void __iomem *mmio;
-       u32 irq_stat, irq_ack = 0;
+       u32 irq_stat, irq_masked;
 
        VPRINTK("ENTER\n");
 
@@ -1786,16 +1786,17 @@ static irqreturn_t ahci_interrupt(int irq, void *dev_instance)
 
        /* sigh.  0xffffffff is a valid return from h/w */
        irq_stat = readl(mmio + HOST_IRQ_STAT);
-       irq_stat &= hpriv->port_map;
        if (!irq_stat)
                return IRQ_NONE;
 
+       irq_masked = irq_stat & hpriv->port_map;
+
        spin_lock(&host->lock);
 
        for (i = 0; i < host->n_ports; i++) {
                struct ata_port *ap;
 
-               if (!(irq_stat & (1 << i)))
+               if (!(irq_masked & (1 << i)))
                        continue;
 
                ap = host->ports[i];
@@ -1809,14 +1810,20 @@ static irqreturn_t ahci_interrupt(int irq, void *dev_instance)
                                        "interrupt on disabled port %u\n", i);
                }
 
-               irq_ack |= (1 << i);
-       }
-
-       if (irq_ack) {
-               writel(irq_ack, mmio + HOST_IRQ_STAT);
                handled = 1;
        }
 
+       /* HOST_IRQ_STAT behaves as level triggered latch meaning that
+        * it should be cleared after all the port events are cleared;
+        * otherwise, it will raise a spurious interrupt after each
+        * valid one.  Please read section 10.6.2 of ahci 1.1 for more
+        * information.
+        *
+        * Also, use the unmasked value to clear interrupt as spurious
+        * pending event on a dummy port might cause screaming IRQ.
+        */
+       writel(irq_stat, mmio + HOST_IRQ_STAT);
+
        spin_unlock(&host->lock);
 
        VPRINTK("EXIT\n");
index 215d18672a5a9c62a00c43d5b3678b3bc5638242..c0908c225483bcd352508a1b9fc239a48b50f36c 100644 (file)
@@ -1094,6 +1094,7 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
 int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
                     u8 status, int in_wq)
 {
+       struct ata_eh_info *ehi = &ap->link.eh_info;
        unsigned long flags = 0;
        int poll_next;
 
@@ -1125,9 +1126,12 @@ fsm_start:
                        if (likely(status & (ATA_ERR | ATA_DF)))
                                /* device stops HSM for abort/error */
                                qc->err_mask |= AC_ERR_DEV;
-                       else
+                       else {
                                /* HSM violation. Let EH handle this */
+                               ata_ehi_push_desc(ehi,
+                                       "ST_FIRST: !(DRQ|ERR|DF)");
                                qc->err_mask |= AC_ERR_HSM;
+                       }
 
                        ap->hsm_task_state = HSM_ST_ERR;
                        goto fsm_start;
@@ -1146,9 +1150,9 @@ fsm_start:
                         * the CDB.
                         */
                        if (!(qc->dev->horkage & ATA_HORKAGE_STUCK_ERR)) {
-                               ata_port_printk(ap, KERN_WARNING,
-                                               "DRQ=1 with device error, "
-                                               "dev_stat 0x%X\n", status);
+                               ata_ehi_push_desc(ehi, "ST_FIRST: "
+                                       "DRQ=1 with device error, "
+                                       "dev_stat 0x%X", status);
                                qc->err_mask |= AC_ERR_HSM;
                                ap->hsm_task_state = HSM_ST_ERR;
                                goto fsm_start;
@@ -1205,9 +1209,9 @@ fsm_start:
                         * let the EH abort the command or reset the device.
                         */
                        if (unlikely(status & (ATA_ERR | ATA_DF))) {
-                               ata_port_printk(ap, KERN_WARNING, "DRQ=1 with "
-                                               "device error, dev_stat 0x%X\n",
-                                               status);
+                               ata_ehi_push_desc(ehi, "ST-ATAPI: "
+                                       "DRQ=1 with device error, "
+                                       "dev_stat 0x%X", status);
                                qc->err_mask |= AC_ERR_HSM;
                                ap->hsm_task_state = HSM_ST_ERR;
                                goto fsm_start;
@@ -1226,13 +1230,17 @@ fsm_start:
                                if (likely(status & (ATA_ERR | ATA_DF)))
                                        /* device stops HSM for abort/error */
                                        qc->err_mask |= AC_ERR_DEV;
-                               else
+                               else {
                                        /* HSM violation. Let EH handle this.
                                         * Phantom devices also trigger this
                                         * condition.  Mark hint.
                                         */
+                                       ata_ehi_push_desc(ehi, "ST-ATA: "
+                                               "DRQ=1 with device error, "
+                                               "dev_stat 0x%X", status);
                                        qc->err_mask |= AC_ERR_HSM |
                                                        AC_ERR_NODEV_HINT;
+                               }
 
                                ap->hsm_task_state = HSM_ST_ERR;
                                goto fsm_start;
@@ -1257,8 +1265,12 @@ fsm_start:
                                        status = ata_wait_idle(ap);
                                }
 
-                               if (status & (ATA_BUSY | ATA_DRQ))
+                               if (status & (ATA_BUSY | ATA_DRQ)) {
+                                       ata_ehi_push_desc(ehi, "ST-ATA: "
+                                               "BUSY|DRQ persists on ERR|DF, "
+                                               "dev_stat 0x%X", status);
                                        qc->err_mask |= AC_ERR_HSM;
+                               }
 
                                /* ata_pio_sectors() might change the
                                 * state to HSM_ST_LAST. so, the state
index 28092bc50146a04bf0298f48166550c8efa4320b..ad169ffbc4cb2a0ad8387c478b6a9540992f99b6 100644 (file)
@@ -1607,7 +1607,7 @@ static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
                 * Much of the time, this could just work regardless.
                 * So for now, just log the incident, and allow the attempt.
                 */
-               if (limit_warnings && (qc->nbytes / qc->sect_size) > 1) {
+               if (limit_warnings > 0 && (qc->nbytes / qc->sect_size) > 1) {
                        --limit_warnings;
                        ata_link_printk(qc->dev->link, KERN_WARNING, DRV_NAME
                                        ": attempting PIO w/multiple DRQ: "
index 8ee6b5b4ede7bca0940783b37756b8b5f4aba158..84ffcc26a74bec944506096c20e578a49c516bcf 100644 (file)
@@ -370,6 +370,7 @@ static const struct pci_device_id sil24_pci_tbl[] = {
        { PCI_VDEVICE(INTEL, 0x3124), BID_SIL3124 },
        { PCI_VDEVICE(CMD, 0x3132), BID_SIL3132 },
        { PCI_VDEVICE(CMD, 0x0242), BID_SIL3132 },
+       { PCI_VDEVICE(CMD, 0x0244), BID_SIL3132 },
        { PCI_VDEVICE(CMD, 0x3131), BID_SIL3131 },
        { PCI_VDEVICE(CMD, 0x3531), BID_SIL3131 },
 
index f277cea904ce89bc90adc909ca5fe0809a13c621..db529b8499482fc08c3f4b6de08fcc4d43a6f2cc 100644 (file)
@@ -83,6 +83,7 @@ static struct ata_port_operations uli_ops = {
        .inherits               = &ata_bmdma_port_ops,
        .scr_read               = uli_scr_read,
        .scr_write              = uli_scr_write,
+       .hardreset              = ATA_OP_NULL,
 };
 
 static const struct ata_port_info uli_port_info = {
index 043353bd0600fb4c8d517672cab3116047a3fd50..14b9d5f4c203d28d3bcc639e6f1f8580d77093f0 100644 (file)
@@ -64,7 +64,7 @@ config KS0108_DELAY
          Amount of time the ks0108 should wait between each control write
          to the parallel port.
 
-         If your driver seems to miss random writings, increment this.
+         If your LCD seems to miss random writings, increment this.
 
          If you don't know what I'm talking about, ignore it.
 
index 80bb061053877806bc7d6de0256e27b706a18977..683509f013abaabdc1711e3436dc94474cd1429c 100644 (file)
@@ -5,7 +5,7 @@
  *     License: GPLv2
  *     Depends: ks0108
  *
- *      Author: Copyright (C) Miguel Ojeda Sandonis <maxextreme@gmail.com>
+ *      Author: Copyright (C) Miguel Ojeda Sandonis
  *        Date: 2006-10-31
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -398,5 +398,5 @@ module_init(cfag12864b_init);
 module_exit(cfag12864b_exit);
 
 MODULE_LICENSE("GPL v2");
-MODULE_AUTHOR("Miguel Ojeda Sandonis <maxextreme@gmail.com>");
+MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
 MODULE_DESCRIPTION("cfag12864b LCD driver");
index 307c190699e04193815004207549a5f7d8706284..fe3a865be4e556c615fbac9fd49cae7bfcaf444d 100644 (file)
@@ -5,7 +5,7 @@
  *     License: GPLv2
  *     Depends: cfag12864b
  *
- *      Author: Copyright (C) Miguel Ojeda Sandonis <maxextreme@gmail.com>
+ *      Author: Copyright (C) Miguel Ojeda Sandonis
  *        Date: 2006-10-31
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -186,5 +186,5 @@ module_init(cfag12864bfb_init);
 module_exit(cfag12864bfb_exit);
 
 MODULE_LICENSE("GPL v2");
-MODULE_AUTHOR("Miguel Ojeda Sandonis <maxextreme@gmail.com>");
+MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
 MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");
index e6c3646ef18ce007c4446b6d96738202d0cf0874..5b93852392b8c342cc3c772979a346dedd261439 100644 (file)
@@ -5,7 +5,7 @@
  *     License: GPLv2
  *     Depends: parport
  *
- *      Author: Copyright (C) Miguel Ojeda Sandonis <maxextreme@gmail.com>
+ *      Author: Copyright (C) Miguel Ojeda Sandonis
  *        Date: 2006-10-31
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -173,6 +173,6 @@ module_init(ks0108_init);
 module_exit(ks0108_exit);
 
 MODULE_LICENSE("GPL v2");
-MODULE_AUTHOR("Miguel Ojeda Sandonis <maxextreme@gmail.com>");
+MODULE_AUTHOR("Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>");
 MODULE_DESCRIPTION("ks0108 LCD Controller driver");
 
index 39f3d1b3a21354aa112f5fb222b862d99daafb04..0f867a0833387fc7cfa5094450593c94f4905486 100644 (file)
@@ -84,8 +84,8 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
                       nid, K(i.totalram),
                       nid, K(i.freeram),
                       nid, K(i.totalram - i.freeram),
-                      nid, node_page_state(nid, NR_ACTIVE),
-                      nid, node_page_state(nid, NR_INACTIVE),
+                      nid, K(node_page_state(nid, NR_ACTIVE)),
+                      nid, K(node_page_state(nid, NR_INACTIVE)),
 #ifdef CONFIG_HIGHMEM
                       nid, K(i.totalhigh),
                       nid, K(i.freehigh),
index 5f1e1cc6165a91b5b5388dcabc8bac06d13db782..d81632cd7d062fd01bb2e2987dd8095b567c1e87 100644 (file)
@@ -106,35 +106,34 @@ MODULE_DEVICE_TABLE(pci, cciss_pci_device_id);
 /*  board_id = Subsystem Device ID & Vendor ID
  *  product = Marketing Name for the board
  *  access = Address of the struct of function pointers
- *  nr_cmds = Number of commands supported by controller
  */
 static struct board_type products[] = {
-       {0x40700E11, "Smart Array 5300", &SA5_access, 512},
-       {0x40800E11, "Smart Array 5i", &SA5B_access, 512},
-       {0x40820E11, "Smart Array 532", &SA5B_access, 512},
-       {0x40830E11, "Smart Array 5312", &SA5B_access, 512},
-       {0x409A0E11, "Smart Array 641", &SA5_access, 512},
-       {0x409B0E11, "Smart Array 642", &SA5_access, 512},
-       {0x409C0E11, "Smart Array 6400", &SA5_access, 512},
-       {0x409D0E11, "Smart Array 6400 EM", &SA5_access, 512},
-       {0x40910E11, "Smart Array 6i", &SA5_access, 512},
-       {0x3225103C, "Smart Array P600", &SA5_access, 512},
-       {0x3223103C, "Smart Array P800", &SA5_access, 512},
-       {0x3234103C, "Smart Array P400", &SA5_access, 512},
-       {0x3235103C, "Smart Array P400i", &SA5_access, 512},
-       {0x3211103C, "Smart Array E200i", &SA5_access, 120},
-       {0x3212103C, "Smart Array E200", &SA5_access, 120},
-       {0x3213103C, "Smart Array E200i", &SA5_access, 120},
-       {0x3214103C, "Smart Array E200i", &SA5_access, 120},
-       {0x3215103C, "Smart Array E200i", &SA5_access, 120},
-       {0x3237103C, "Smart Array E500", &SA5_access, 512},
-       {0x323D103C, "Smart Array P700m", &SA5_access, 512},
-       {0x3241103C, "Smart Array P212", &SA5_access, 384},
-       {0x3243103C, "Smart Array P410", &SA5_access, 384},
-       {0x3245103C, "Smart Array P410i", &SA5_access, 384},
-       {0x3247103C, "Smart Array P411", &SA5_access, 384},
-       {0x3249103C, "Smart Array P812", &SA5_access, 384},
-       {0xFFFF103C, "Unknown Smart Array", &SA5_access, 120},
+       {0x40700E11, "Smart Array 5300", &SA5_access},
+       {0x40800E11, "Smart Array 5i", &SA5B_access},
+       {0x40820E11, "Smart Array 532", &SA5B_access},
+       {0x40830E11, "Smart Array 5312", &SA5B_access},
+       {0x409A0E11, "Smart Array 641", &SA5_access},
+       {0x409B0E11, "Smart Array 642", &SA5_access},
+       {0x409C0E11, "Smart Array 6400", &SA5_access},
+       {0x409D0E11, "Smart Array 6400 EM", &SA5_access},
+       {0x40910E11, "Smart Array 6i", &SA5_access},
+       {0x3225103C, "Smart Array P600", &SA5_access},
+       {0x3223103C, "Smart Array P800", &SA5_access},
+       {0x3234103C, "Smart Array P400", &SA5_access},
+       {0x3235103C, "Smart Array P400i", &SA5_access},
+       {0x3211103C, "Smart Array E200i", &SA5_access},
+       {0x3212103C, "Smart Array E200", &SA5_access},
+       {0x3213103C, "Smart Array E200i", &SA5_access},
+       {0x3214103C, "Smart Array E200i", &SA5_access},
+       {0x3215103C, "Smart Array E200i", &SA5_access},
+       {0x3237103C, "Smart Array E500", &SA5_access},
+       {0x323D103C, "Smart Array P700m", &SA5_access},
+       {0x3241103C, "Smart Array P212", &SA5_access},
+       {0x3243103C, "Smart Array P410", &SA5_access},
+       {0x3245103C, "Smart Array P410i", &SA5_access},
+       {0x3247103C, "Smart Array P411", &SA5_access},
+       {0x3249103C, "Smart Array P812", &SA5_access},
+       {0xFFFF103C, "Unknown Smart Array", &SA5_access},
 };
 
 /* How long to wait (in milliseconds) for board to go into simple mode */
@@ -3086,11 +3085,20 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
        print_cfg_table(c->cfgtable);
 #endif                         /* CCISS_DEBUG */
 
+       /* Some controllers support Zero Memory Raid (ZMR).
+        * When configured in ZMR mode the number of supported
+        * commands drops to 64. So instead of just setting an
+        * arbitrary value we make the driver a little smarter.
+        * We read the config table to tell us how many commands
+        * are supported on the controller then subtract 4 to
+        * leave a little room for ioctl calls.
+        */
+       c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
        for (i = 0; i < ARRAY_SIZE(products); i++) {
                if (board_id == products[i].board_id) {
                        c->product_name = products[i].product_name;
                        c->access = *(products[i].access);
-                       c->nr_cmds = products[i].nr_cmds;
+                       c->nr_cmds = c->max_commands - 4;
                        break;
                }
        }
@@ -3110,7 +3118,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
                if (subsystem_vendor_id == PCI_VENDOR_ID_HP) {
                        c->product_name = products[i-1].product_name;
                        c->access = *(products[i-1].access);
-                       c->nr_cmds = products[i-1].nr_cmds;
+                       c->nr_cmds = c->max_commands - 4;
                        printk(KERN_WARNING "cciss: This is an unknown "
                                "Smart Array controller.\n"
                                "cciss: Please update to the latest driver "
@@ -3546,6 +3554,10 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
        for (j = 0; j <= hba[i]->highest_lun; j++)
                add_disk(hba[i]->gendisk[j]);
 
+       /* we must register the controller even if no disks exist */
+       if (hba[i]->highest_lun == -1)
+               add_disk(hba[i]->gendisk[0]);
+
        return 1;
 
       clean4:
index f7f16e7a8bf3c8d724065268052b9659c99a2d61..df036118b8b14ad1c3c1fd33ccf940e6a7fcf830 100644 (file)
@@ -62,11 +62,11 @@ static void i915_vblank_tasklet(struct drm_device *dev)
        u32 ropcpp = (0xcc << 16) | ((cpp - 1) << 24);
        RING_LOCALS;
 
-       if (sarea_priv->front_tiled) {
+       if (IS_I965G(dev) && sarea_priv->front_tiled) {
                cmd |= XY_SRC_COPY_BLT_DST_TILED;
                dst_pitch >>= 2;
        }
-       if (sarea_priv->back_tiled) {
+       if (IS_I965G(dev) && sarea_priv->back_tiled) {
                cmd |= XY_SRC_COPY_BLT_SRC_TILED;
                src_pitch >>= 2;
        }
index e94bee0323148548d9374852e7b140999af40b81..750131010af01875d06d1c5e11818112c02ecbd2 100644 (file)
@@ -3322,7 +3322,7 @@ static int send_break(struct tty_struct *tty, unsigned int duration)
                msleep_interruptible(duration);
        tty->ops->break_ctl(tty, 0);
        tty_write_unlock(tty);
-       if (!signal_pending(current))
+       if (signal_pending(current))
                return -EINTR;
        return 0;
 }
index 85e2ba7fcfbab1b4533079da8bd812f22203952d..bf4830082a135e126d9f35f1a72a7bf5b18fbecf 100644 (file)
@@ -27,6 +27,8 @@
 #include <linux/moduleparam.h>
 #include <linux/connector.h>
 #include <linux/mutex.h>
+#include <linux/proc_fs.h>
+#include <linux/spinlock.h>
 
 #include <net/sock.h>
 
@@ -403,6 +405,40 @@ static void cn_callback(void *data)
        mutex_unlock(&notify_lock);
 }
 
+static int cn_proc_show(struct seq_file *m, void *v)
+{
+       struct cn_queue_dev *dev = cdev.cbdev;
+       struct cn_callback_entry *cbq;
+
+       seq_printf(m, "Name            ID\n");
+
+       spin_lock_bh(&dev->queue_lock);
+
+       list_for_each_entry(cbq, &dev->queue_list, callback_entry) {
+               seq_printf(m, "%-15s %u:%u\n",
+                          cbq->id.name,
+                          cbq->id.id.idx,
+                          cbq->id.id.val);
+       }
+
+       spin_unlock_bh(&dev->queue_lock);
+
+       return 0;
+}
+
+static int cn_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, cn_proc_show, NULL);
+}
+
+static const struct file_operations cn_file_ops = {
+       .owner   = THIS_MODULE,
+       .open    = cn_proc_open,
+       .read    = seq_read,
+       .llseek  = seq_lseek,
+       .release = single_release
+};
+
 static int __devinit cn_init(void)
 {
        struct cn_dev *dev = &cdev;
@@ -434,6 +470,8 @@ static int __devinit cn_init(void)
                return -EINVAL;
        }
 
+       proc_net_fops_create(&init_net, "connector", S_IRUGO, &cn_file_ops);
+
        return 0;
 }
 
@@ -443,6 +481,8 @@ static void __devexit cn_fini(void)
 
        cn_already_initialized = 0;
 
+       proc_net_remove(&init_net, "connector");
+
        cn_del_callback(&dev->id);
        cn_queue_free_dev(dev->cbdev);
        netlink_kernel_release(dev->nls);
index b2458bb8e9cade2fd79fea620b60eb9edd0aa7e0..227d2e036cd812f4e259fd13413298a818d16d6f 100644 (file)
@@ -1051,7 +1051,8 @@ static int sbp2_scan_unit_dir(struct sbp2_target *tgt, u32 *directory,
                        break;
 
                case SBP2_CSR_LOGICAL_UNIT_DIRECTORY:
-                       if (sbp2_scan_logical_unit_dir(tgt, ci.p + value) < 0)
+                       /* Adjust for the increment in the iterator */
+                       if (sbp2_scan_logical_unit_dir(tgt, ci.p - 1 + value) < 0)
                                return -ENOMEM;
                        break;
                }
index bbd28342e771f415a4b7365653e3383757a398a2..008c38ba774f588f3a739983bb6f47e48ef618f5 100644 (file)
@@ -28,12 +28,18 @@ config DEBUG_GPIO
 comment "I2C GPIO expanders:"
 
 config GPIO_PCA953X
-       tristate "PCA953x I/O ports"
+       tristate "PCA953x, PCA955x, and MAX7310 I/O ports"
        depends on I2C
        help
-         Say yes here to support the PCA9534 (8-bit), PCA9535 (16-bit),
-         PCA9536 (4-bit), PCA9537 (4-bit), PCA9538 (8-bit), and PCA9539
-         (16-bit) I/O ports. These parts are made by NXP and TI.
+         Say yes here to provide access to several register-oriented
+         SMBus I/O expanders, made mostly by NXP or TI.  Compatible
+         models include:
+
+         4 bits:       pca9536, pca9537
+
+         8 bits:       max7310, pca9534, pca9538, pca9554, pca9557
+
+         16 bits:      pca9535, pca9539, pca9555
 
          This driver can also be built as a module.  If so, the module
          will be called pca953x.
index 7e40e8a55edf247968690de9cb5348969df5c75b..a380730b61abe49800af8e655eaf5735d0524ad0 100644 (file)
@@ -33,7 +33,7 @@ static const struct i2c_device_id pca953x_id[] = {
        { "pca9554", 8, },
        { "pca9555", 16, },
        { "pca9557", 8, },
-       /* REVISIT several pca955x parts should work here too */
+       { "max7310", 8, },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, pca953x_id);
index 26df06f840eb4d16a08f4f4d9e8170c8bac5f241..50f22690d6114a51518f40003083a578693c11f9 100644 (file)
@@ -516,17 +516,23 @@ static struct dmi_system_id __initdata hdaps_whitelist[] = {
        HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R51"),
        HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R52"),
        HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad R61i"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad R61"),
        HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T41p"),
        HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T41"),
        HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p"),
        HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"),
        HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"),
        HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61p"),
        HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61"),
        HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X40"),
        HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X41"),
        HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X60"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X61s"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X61"),
        HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad Z60m"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad Z61m"),
+       HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad Z61p"),
        { .ident = NULL }
 };
 
index 1305ef190fc10dfbee90b1f52705885731935071..9e8c875437bec533ec4e32579602f31f4336bbe9 100644 (file)
@@ -290,12 +290,12 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
                 * bus, or started a new i2c message
                 */
                
-               if (iicstat  & S3C2410_IICSTAT_LASTBIT &&
+               if (iicstat & S3C2410_IICSTAT_LASTBIT &&
                    !(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
                        /* ack was not received... */
 
                        dev_dbg(i2c->dev, "ack was not received\n");
-                       s3c24xx_i2c_stop(i2c, -EREMOTEIO);
+                       s3c24xx_i2c_stop(i2c, -ENXIO);
                        goto out_ack;
                }
 
@@ -305,7 +305,7 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
                        i2c->state = STATE_WRITE;
 
                /* terminate the transfer if there is nothing to do
-                * (used by the i2c probe to find devices */
+                * as this is used by the i2c probe to find devices. */
 
                if (is_lastmsg(i2c) && i2c->msg->len == 0) {
                        s3c24xx_i2c_stop(i2c, 0);
@@ -323,7 +323,17 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
                 * end of the message, and if so, work out what to do
                 */
 
+               if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
+                       if (iicstat & S3C2410_IICSTAT_LASTBIT) {
+                               dev_dbg(i2c->dev, "WRITE: No Ack\n");
+
+                               s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
+                               goto out_ack;
+                       }
+               }
+
        retry_write:
+
                if (!is_msgend(i2c)) {
                        byte = i2c->msg->buf[i2c->msg_ptr++];
                        writeb(byte, i2c->regs + S3C2410_IICDS);
@@ -377,17 +387,6 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
                 * going to do any more read/write
                 */
 
-               if (!(i2c->msg->flags & I2C_M_IGNORE_NAK) &&
-                   !(is_msglast(i2c) && is_lastmsg(i2c))) {
-
-                       if (iicstat & S3C2410_IICSTAT_LASTBIT) {
-                               dev_dbg(i2c->dev, "READ: No Ack\n");
-
-                               s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
-                               goto out_ack;
-                       }
-               }
-
                byte = readb(i2c->regs + S3C2410_IICDS);
                i2c->msg->buf[i2c->msg_ptr++] = byte;
 
@@ -949,3 +948,4 @@ MODULE_DESCRIPTION("S3C24XX I2C Bus driver");
 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:s3c2410-i2c");
+MODULE_ALIAS("platform:s3c2440-i2c");
index 8e07de23d220911988d811f121bcd2b8d17e6699..1607536ff5fb3ec7da44b500157c1631703b3604 100644 (file)
@@ -823,6 +823,13 @@ config BLK_DEV_IDE_RAPIDE
          Say Y here if you want to support the Yellowstone RapIDE controller
          manufactured for use with Acorn computers.
 
+config BLK_DEV_IDE_BAST
+       tristate "Simtec BAST / Thorcom VR1000 IDE support"
+       depends on ARM && (ARCH_BAST || MACH_VR1000)
+       help
+         Say Y here if you want to support the onboard IDE channels on the
+         Simtec BAST or the Thorcom VR1000
+
 config IDE_H8300
        tristate "H8300 IDE support"
        depends on H8300
index 5bc26053afa609c83e05426edc3d999cdef8d3a7..936e7b0237f5499fe0305845679c12a96d025d16 100644 (file)
@@ -1,6 +1,7 @@
 
 obj-$(CONFIG_BLK_DEV_IDE_ICSIDE)       += icside.o
 obj-$(CONFIG_BLK_DEV_IDE_RAPIDE)       += rapide.o
+obj-$(CONFIG_BLK_DEV_IDE_BAST)         += bast-ide.o
 obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710)  += palm_bk3710.o
 
 ifeq ($(CONFIG_IDE_ARM), m)
diff --git a/drivers/ide/arm/bast-ide.c b/drivers/ide/arm/bast-ide.c
new file mode 100644 (file)
index 0000000..8e8c281
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2003-2004 Simtec Electronics
+ *  Ben Dooks <ben@simtec.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+*/
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/ide.h>
+#include <linux/init.h>
+
+#include <asm/mach-types.h>
+
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/arch/map.h>
+#include <asm/arch/bast-map.h>
+#include <asm/arch/bast-irq.h>
+
+#define DRV_NAME "bast-ide"
+
+static int __init bastide_register(unsigned int base, unsigned int aux, int irq)
+{
+       ide_hwif_t *hwif;
+       hw_regs_t hw;
+       int i;
+       u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
+
+       memset(&hw, 0, sizeof(hw));
+
+       base += BAST_IDE_CS;
+       aux  += BAST_IDE_CS;
+
+       for (i = 0; i <= 7; i++) {
+               hw.io_ports_array[i] = (unsigned long)base;
+               base += 0x20;
+       }
+
+       hw.io_ports.ctl_addr = aux + (6 * 0x20);
+       hw.irq = irq;
+       hw.chipset = ide_generic;
+
+       hwif = ide_find_port();
+       if (hwif == NULL)
+               goto out;
+
+       i = hwif->index;
+
+       ide_init_port_data(hwif, i);
+       ide_init_port_hw(hwif, &hw);
+       hwif->port_ops = NULL;
+
+       idx[0] = i;
+
+       ide_device_add(idx, NULL);
+out:
+       return 0;
+}
+
+static int __init bastide_init(void)
+{
+       unsigned long base = BAST_VA_IDEPRI + BAST_IDE_CS;
+
+       /* we can treat the VR1000 and the BAST the same */
+
+       if (!(machine_is_bast() || machine_is_vr1000()))
+               return 0;
+
+       printk("BAST: IDE driver, (c) 2003-2004 Simtec Electronics\n");
+
+       if (!request_mem_region(base, 0x400000, DRV_NAME)) {
+               printk(KERN_ERR "%s: resources busy\n", DRV_NAME);
+               return -EBUSY;
+       }
+
+       bastide_register(BAST_VA_IDEPRI, BAST_VA_IDEPRIAUX, IRQ_IDE0);
+       bastide_register(BAST_VA_IDESEC, BAST_VA_IDESECAUX, IRQ_IDE1);
+
+       return 0;
+}
+
+module_init(bastide_init);
+
+MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Simtec BAST / Thorcom VR1000 IDE driver");
index 380fa0c8cc84d40f2f9897d0b41d234815bc6a92..d27061b393243a8038e39e6fdb5fe92bef250bbb 100644 (file)
@@ -646,8 +646,6 @@ static int ide_register_port(ide_hwif_t *hwif)
                goto out;
        }
 
-       get_device(&hwif->gendev);
-
        hwif->portdev = device_create_drvdata(ide_port_class, &hwif->gendev,
                                              MKDEV(0, 0), hwif, hwif->name);
        if (IS_ERR(hwif->portdev)) {
index 55ec7f798772d6d60a7d704371eca12c5854616f..8af88bf0969bde8bf41926e1e5834deed20022f6 100644 (file)
@@ -76,7 +76,7 @@ static int proc_ide_read_mate
        ide_hwif_t      *hwif = (ide_hwif_t *) data;
        int             len;
 
-       if (hwif && hwif->mate && hwif->mate->present)
+       if (hwif && hwif->mate)
                len = sprintf(page, "%s\n", hwif->mate->name);
        else
                len = sprintf(page, "(none)\n");
index c758dcb13b14209a97bfdca02ef056ee113712a7..300431d080a97310ca829beff00f8b7dd49bb3aa 100644 (file)
@@ -315,13 +315,14 @@ void ide_unregister(ide_hwif_t *hwif)
 
        BUG_ON(in_interrupt());
        BUG_ON(irqs_disabled());
+
        mutex_lock(&ide_cfg_mtx);
-       spin_lock_irq(&ide_lock);
-       if (!hwif->present)
-               goto abort;
-       __ide_port_unregister_devices(hwif);
-       hwif->present = 0;
 
+       spin_lock_irq(&ide_lock);
+       if (hwif->present) {
+               __ide_port_unregister_devices(hwif);
+               hwif->present = 0;
+       }
        spin_unlock_irq(&ide_lock);
 
        ide_proc_unregister_port(hwif);
@@ -351,16 +352,15 @@ void ide_unregister(ide_hwif_t *hwif)
        blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
        kfree(hwif->sg_table);
        unregister_blkdev(hwif->major, hwif->name);
-       spin_lock_irq(&ide_lock);
 
        if (hwif->dma_base)
                ide_release_dma_engine(hwif);
 
+       spin_lock_irq(&ide_lock);
        /* restore hwif data to pristine status */
        ide_init_port_data(hwif, hwif->index);
-
-abort:
        spin_unlock_irq(&ide_lock);
+
        mutex_unlock(&ide_cfg_mtx);
 }
 
@@ -1094,13 +1094,6 @@ struct bus_type ide_bus_type = {
 
 EXPORT_SYMBOL_GPL(ide_bus_type);
 
-static void ide_port_class_release(struct device *portdev)
-{
-       ide_hwif_t *hwif = dev_get_drvdata(portdev);
-
-       put_device(&hwif->gendev);
-}
-
 int ide_vlb_clk;
 EXPORT_SYMBOL_GPL(ide_vlb_clk);
 
@@ -1305,7 +1298,6 @@ static int __init ide_init(void)
                ret = PTR_ERR(ide_port_class);
                goto out_port_class;
        }
-       ide_port_class->dev_release = ide_port_class_release;
 
        init_ide_data();
 
index eebc72465fc9beb44d2ecfa77a78d24cbd31f891..72c63e5dd630709ddffccf8dc945147857bf41ba 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/input.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/sched.h>
 
 /*
  * Check that the effect_id is a valid effect and whether the user
@@ -166,8 +167,10 @@ int input_ff_upload(struct input_dev *dev, struct ff_effect *effect,
        if (ret)
                goto out;
 
+       spin_lock_irq(&dev->event_lock);
        ff->effects[id] = *effect;
        ff->effect_owners[id] = file;
+       spin_unlock_irq(&dev->event_lock);
 
  out:
        mutex_unlock(&ff->mutex);
@@ -189,16 +192,22 @@ static int erase_effect(struct input_dev *dev, int effect_id,
        if (error)
                return error;
 
+       spin_lock_irq(&dev->event_lock);
        ff->playback(dev, effect_id, 0);
+       ff->effect_owners[effect_id] = NULL;
+       spin_unlock_irq(&dev->event_lock);
 
        if (ff->erase) {
                error = ff->erase(dev, effect_id);
-               if (error)
+               if (error) {
+                       spin_lock_irq(&dev->event_lock);
+                       ff->effect_owners[effect_id] = file;
+                       spin_unlock_irq(&dev->event_lock);
+
                        return error;
+               }
        }
 
-       ff->effect_owners[effect_id] = NULL;
-
        return 0;
 }
 
@@ -263,8 +272,6 @@ int input_ff_event(struct input_dev *dev, unsigned int type,
        if (type != EV_FF)
                return 0;
 
-       mutex_lock(&ff->mutex);
-
        switch (code) {
        case FF_GAIN:
                if (!test_bit(FF_GAIN, dev->ffbit) || value > 0xffff)
@@ -286,7 +293,6 @@ int input_ff_event(struct input_dev *dev, unsigned int type,
                break;
        }
 
-       mutex_unlock(&ff->mutex);
        return 0;
 }
 EXPORT_SYMBOL_GPL(input_ff_event);
index b26927ce889cead2717db3f4d3896bbd9bacc4e2..dedba16d42f723cb75f87396659e31899d010fc8 100644 (file)
@@ -454,8 +454,11 @@ void bitmap_update_sb(struct bitmap *bitmap)
        spin_unlock_irqrestore(&bitmap->lock, flags);
        sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0);
        sb->events = cpu_to_le64(bitmap->mddev->events);
-       if (!bitmap->mddev->degraded)
-               sb->events_cleared = cpu_to_le64(bitmap->mddev->events);
+       if (bitmap->mddev->events < bitmap->events_cleared) {
+               /* rocking back to read-only */
+               bitmap->events_cleared = bitmap->mddev->events;
+               sb->events_cleared = cpu_to_le64(bitmap->events_cleared);
+       }
        kunmap_atomic(sb, KM_USER0);
        write_page(bitmap, bitmap->sb_page, 1);
 }
@@ -1085,9 +1088,19 @@ void bitmap_daemon_work(struct bitmap *bitmap)
                        } else
                                spin_unlock_irqrestore(&bitmap->lock, flags);
                        lastpage = page;
-/*
-                       printk("bitmap clean at page %lu\n", j);
-*/
+
+                       /* We are possibly going to clear some bits, so make
+                        * sure that events_cleared is up-to-date.
+                        */
+                       if (bitmap->need_sync) {
+                               bitmap_super_t *sb;
+                               bitmap->need_sync = 0;
+                               sb = kmap_atomic(bitmap->sb_page, KM_USER0);
+                               sb->events_cleared =
+                                       cpu_to_le64(bitmap->events_cleared);
+                               kunmap_atomic(sb, KM_USER0);
+                               write_page(bitmap, bitmap->sb_page, 1);
+                       }
                        spin_lock_irqsave(&bitmap->lock, flags);
                        clear_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
                }
@@ -1257,6 +1270,12 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto
                        return;
                }
 
+               if (success &&
+                   bitmap->events_cleared < bitmap->mddev->events) {
+                       bitmap->events_cleared = bitmap->mddev->events;
+                       bitmap->need_sync = 1;
+               }
+
                if (!success && ! (*bmc & NEEDED_MASK))
                        *bmc |= NEEDED_MASK;
 
index 835def11419d36d7b56e0e216028714d384ad0f9..ab6a61db63ce2248b5553ec43678fab61642e9a7 100644 (file)
@@ -432,6 +432,7 @@ static int crypt_convert(struct crypt_config *cc,
                case 0:
                        atomic_dec(&ctx->pending);
                        ctx->sector++;
+                       cond_resched();
                        continue;
 
                /* error */
index 10748240cb2fde2bd8942dbb19e300cc6c32961c..ec921f58fbb8224cec0772494a75926fbc660be7 100644 (file)
@@ -126,7 +126,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
                int j = rdev->raid_disk;
                dev_info_t *disk = conf->disks + j;
 
-               if (j < 0 || j > raid_disks || disk->rdev) {
+               if (j < 0 || j >= raid_disks || disk->rdev) {
                        printk("linear: disk numbering problem. Aborting!\n");
                        goto out;
                }
index 2580ac1b9b0ff06f34d37f12ea829682017e5ef1..73399d17ac3e515968fcf8036669ef9a640d49bb 100644 (file)
@@ -169,7 +169,6 @@ void md_new_event(mddev_t *mddev)
 {
        atomic_inc(&md_event_count);
        wake_up(&md_event_waiters);
-       sysfs_notify(&mddev->kobj, NULL, "sync_action");
 }
 EXPORT_SYMBOL_GPL(md_new_event);
 
@@ -278,6 +277,7 @@ static mddev_t * mddev_find(dev_t unit)
        init_waitqueue_head(&new->sb_wait);
        init_waitqueue_head(&new->recovery_wait);
        new->reshape_position = MaxSector;
+       new->resync_min = 0;
        new->resync_max = MaxSector;
        new->level = LEVEL_NONE;
 
@@ -564,7 +564,7 @@ static int sb_equal(mdp_super_t *sb1, mdp_super_t *sb2)
 
        if (!tmp1 || !tmp2) {
                ret = 0;
-               printk(KERN_INFO "md.c: sb1 is not equal to sb2!\n");
+               printk(KERN_INFO "md.c sb_equal(): failed to allocate memory!\n");
                goto abort;
        }
 
@@ -658,11 +658,14 @@ static unsigned int calc_sb_csum(mdp_super_t * sb)
  */
 
 struct super_type  {
-       char            *name;
-       struct module   *owner;
-       int             (*load_super)(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version);
-       int             (*validate_super)(mddev_t *mddev, mdk_rdev_t *rdev);
-       void            (*sync_super)(mddev_t *mddev, mdk_rdev_t *rdev);
+       char                *name;
+       struct module       *owner;
+       int                 (*load_super)(mdk_rdev_t *rdev, mdk_rdev_t *refdev,
+                                         int minor_version);
+       int                 (*validate_super)(mddev_t *mddev, mdk_rdev_t *rdev);
+       void                (*sync_super)(mddev_t *mddev, mdk_rdev_t *rdev);
+       unsigned long long  (*rdev_size_change)(mdk_rdev_t *rdev,
+                                               unsigned long long size);
 };
 
 /*
@@ -1003,6 +1006,27 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
        sb->sb_csum = calc_sb_csum(sb);
 }
 
+/*
+ * rdev_size_change for 0.90.0
+ */
+static unsigned long long
+super_90_rdev_size_change(mdk_rdev_t *rdev, unsigned long long size)
+{
+       if (size && size < rdev->mddev->size)
+               return 0; /* component must fit device */
+       size *= 2; /* convert to sectors */
+       if (rdev->mddev->bitmap_offset)
+               return 0; /* can't move bitmap */
+       rdev->sb_offset = calc_dev_sboffset(rdev->bdev);
+       if (!size || size > rdev->sb_offset*2)
+               size = rdev->sb_offset*2;
+       md_super_write(rdev->mddev, rdev, rdev->sb_offset << 1, rdev->sb_size,
+                      rdev->sb_page);
+       md_super_wait(rdev->mddev);
+       return size/2; /* kB for sysfs */
+}
+
+
 /*
  * version 1 superblock
  */
@@ -1328,21 +1352,59 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
        sb->sb_csum = calc_sb_1_csum(sb);
 }
 
+static unsigned long long
+super_1_rdev_size_change(mdk_rdev_t *rdev, unsigned long long size)
+{
+       struct mdp_superblock_1 *sb;
+       unsigned long long max_size;
+       if (size && size < rdev->mddev->size)
+               return 0; /* component must fit device */
+       size *= 2; /* convert to sectors */
+       if (rdev->sb_offset < rdev->data_offset/2) {
+               /* minor versions 1 and 2; superblock before data */
+               max_size = (rdev->bdev->bd_inode->i_size >> 9);
+               max_size -= rdev->data_offset;
+               if (!size || size > max_size)
+                       size = max_size;
+       } else if (rdev->mddev->bitmap_offset) {
+               /* minor version 0 with bitmap we can't move */
+               return 0;
+       } else {
+               /* minor version 0; superblock after data */
+               sector_t sb_offset;
+               sb_offset = (rdev->bdev->bd_inode->i_size >> 9) - 8*2;
+               sb_offset &= ~(sector_t)(4*2 - 1);
+               max_size = rdev->size*2 + sb_offset - rdev->sb_offset*2;
+               if (!size || size > max_size)
+                       size = max_size;
+               rdev->sb_offset = sb_offset/2;
+       }
+       sb = (struct mdp_superblock_1 *) page_address(rdev->sb_page);
+       sb->data_size = cpu_to_le64(size);
+       sb->super_offset = rdev->sb_offset*2;
+       sb->sb_csum = calc_sb_1_csum(sb);
+       md_super_write(rdev->mddev, rdev, rdev->sb_offset << 1, rdev->sb_size,
+                      rdev->sb_page);
+       md_super_wait(rdev->mddev);
+       return size/2; /* kB for sysfs */
+}
 
 static struct super_type super_types[] = {
        [0] = {
                .name   = "0.90.0",
                .owner  = THIS_MODULE,
-               .load_super     = super_90_load,
-               .validate_super = super_90_validate,
-               .sync_super     = super_90_sync,
+               .load_super         = super_90_load,
+               .validate_super     = super_90_validate,
+               .sync_super         = super_90_sync,
+               .rdev_size_change   = super_90_rdev_size_change,
        },
        [1] = {
                .name   = "md-1",
                .owner  = THIS_MODULE,
-               .load_super     = super_1_load,
-               .validate_super = super_1_validate,
-               .sync_super     = super_1_sync,
+               .load_super         = super_1_load,
+               .validate_super     = super_1_validate,
+               .sync_super         = super_1_sync,
+               .rdev_size_change   = super_1_rdev_size_change,
        },
 };
 
@@ -1787,7 +1849,7 @@ repeat:
 
 }
 
-/* words written to sysfs files may, or my not, be \n terminated.
+/* words written to sysfs files may, or may not, be \n terminated.
  * We want to accept with case. For this we use cmd_match.
  */
 static int cmd_match(const char *cmd, const char *str)
@@ -1886,6 +1948,8 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
 
                err = 0;
        }
+       if (!err)
+               sysfs_notify(&rdev->kobj, NULL, "state");
        return err ? err : len;
 }
 static struct rdev_sysfs_entry rdev_state =
@@ -1931,7 +1995,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
                slot = -1;
        else if (e==buf || (*e && *e!= '\n'))
                return -EINVAL;
-       if (rdev->mddev->pers) {
+       if (rdev->mddev->pers && slot == -1) {
                /* Setting 'slot' on an active array requires also
                 * updating the 'rd%d' link, and communicating
                 * with the personality with ->hot_*_disk.
@@ -1939,8 +2003,6 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
                 * failed/spare devices.  This normally happens automatically,
                 * but not when the metadata is externally managed.
                 */
-               if (slot != -1)
-                       return -EBUSY;
                if (rdev->raid_disk == -1)
                        return -EEXIST;
                /* personality does all needed checks */
@@ -1954,6 +2016,43 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
                sysfs_remove_link(&rdev->mddev->kobj, nm);
                set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
                md_wakeup_thread(rdev->mddev->thread);
+       } else if (rdev->mddev->pers) {
+               mdk_rdev_t *rdev2;
+               struct list_head *tmp;
+               /* Activating a spare .. or possibly reactivating
+                * if we every get bitmaps working here.
+                */
+
+               if (rdev->raid_disk != -1)
+                       return -EBUSY;
+
+               if (rdev->mddev->pers->hot_add_disk == NULL)
+                       return -EINVAL;
+
+               rdev_for_each(rdev2, tmp, rdev->mddev)
+                       if (rdev2->raid_disk == slot)
+                               return -EEXIST;
+
+               rdev->raid_disk = slot;
+               if (test_bit(In_sync, &rdev->flags))
+                       rdev->saved_raid_disk = slot;
+               else
+                       rdev->saved_raid_disk = -1;
+               err = rdev->mddev->pers->
+                       hot_add_disk(rdev->mddev, rdev);
+               if (err) {
+                       rdev->raid_disk = -1;
+                       return err;
+               } else
+                       sysfs_notify(&rdev->kobj, NULL, "state");
+               sprintf(nm, "rd%d", rdev->raid_disk);
+               if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm))
+                       printk(KERN_WARNING
+                              "md: cannot register "
+                              "%s for %s\n",
+                              nm, mdname(rdev->mddev));
+
+               /* don't wakeup anyone, leave that to userspace. */
        } else {
                if (slot >= rdev->mddev->raid_disks)
                        return -ENOSPC;
@@ -1962,6 +2061,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
                clear_bit(Faulty, &rdev->flags);
                clear_bit(WriteMostly, &rdev->flags);
                set_bit(In_sync, &rdev->flags);
+               sysfs_notify(&rdev->kobj, NULL, "state");
        }
        return len;
 }
@@ -1983,7 +2083,7 @@ offset_store(mdk_rdev_t *rdev, const char *buf, size_t len)
        unsigned long long offset = simple_strtoull(buf, &e, 10);
        if (e==buf || (*e && *e != '\n'))
                return -EINVAL;
-       if (rdev->mddev->pers)
+       if (rdev->mddev->pers && rdev->raid_disk >= 0)
                return -EBUSY;
        if (rdev->size && rdev->mddev->external)
                /* Must set offset before size, so overlap checks
@@ -2022,8 +2122,20 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
 
        if (e==buf || (*e && *e != '\n'))
                return -EINVAL;
-       if (my_mddev->pers)
-               return -EBUSY;
+       if (my_mddev->pers && rdev->raid_disk >= 0) {
+               if (rdev->mddev->persistent) {
+                       size = super_types[rdev->mddev->major_version].
+                               rdev_size_change(rdev, size);
+                       if (!size)
+                               return -EBUSY;
+               } else if (!size) {
+                       size = (rdev->bdev->bd_inode->i_size >> 10);
+                       size -= rdev->data_offset/2;
+               }
+               if (size < rdev->mddev->size)
+                       return -EINVAL; /* component must fit device */
+       }
+
        rdev->size = size;
        if (size > oldsize && rdev->mddev->external) {
                /* need to check that all other rdevs with the same ->bdev
@@ -2512,7 +2624,7 @@ __ATTR(resync_start, S_IRUGO|S_IWUSR, resync_start_show, resync_start_store);
  *     When written, doesn't tear down array, but just stops it
  * suspended (not supported yet)
  *     All IO requests will block. The array can be reconfigured.
- *     Writing this, if accepted, will block until array is quiessent
+ *     Writing this, if accepted, will block until array is quiescent
  * readonly
  *     no resync can happen.  no superblocks get written.
  *     write requests fail
@@ -2681,8 +2793,10 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
        }
        if (err)
                return err;
-       else
+       else {
+               sysfs_notify(&mddev->kobj, NULL, "array_state");
                return len;
+       }
 }
 static struct md_sysfs_entry md_array_state =
 __ATTR(array_state, S_IRUGO|S_IWUSR, array_state_show, array_state_store);
@@ -2899,7 +3013,7 @@ action_show(mddev_t *mddev, char *page)
                                type = "check";
                        else
                                type = "repair";
-               } else
+               } else if (test_bit(MD_RECOVERY_RECOVER, &mddev->recovery))
                        type = "recover";
        }
        return sprintf(page, "%s\n", type);
@@ -2921,15 +3035,19 @@ action_store(mddev_t *mddev, const char *page, size_t len)
        } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
                   test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))
                return -EBUSY;
-       else if (cmd_match(page, "resync") || cmd_match(page, "recover"))
+       else if (cmd_match(page, "resync"))
+               set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
+       else if (cmd_match(page, "recover")) {
+               set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
                set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
-       else if (cmd_match(page, "reshape")) {
+       else if (cmd_match(page, "reshape")) {
                int err;
                if (mddev->pers->start_reshape == NULL)
                        return -EINVAL;
                err = mddev->pers->start_reshape(mddev);
                if (err)
                        return err;
+               sysfs_notify(&mddev->kobj, NULL, "degraded");
        } else {
                if (cmd_match(page, "check"))
                        set_bit(MD_RECOVERY_CHECK, &mddev->recovery);
@@ -2940,6 +3058,7 @@ action_store(mddev_t *mddev, const char *page, size_t len)
        }
        set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
        md_wakeup_thread(mddev->thread);
+       sysfs_notify(&mddev->kobj, NULL, "sync_action");
        return len;
 }
 
@@ -3049,11 +3168,11 @@ static ssize_t
 sync_speed_show(mddev_t *mddev, char *page)
 {
        unsigned long resync, dt, db;
-       resync = (mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active));
-       dt = ((jiffies - mddev->resync_mark) / HZ);
+       resync = mddev->curr_mark_cnt - atomic_read(&mddev->recovery_active);
+       dt = (jiffies - mddev->resync_mark) / HZ;
        if (!dt) dt++;
-       db = resync - (mddev->resync_mark_cnt);
-       return sprintf(page, "%ld\n", db/dt/2); /* K/sec */
+       db = resync - mddev->resync_mark_cnt;
+       return sprintf(page, "%lu\n", db/dt/2); /* K/sec */
 }
 
 static struct md_sysfs_entry md_sync_speed = __ATTR_RO(sync_speed);
@@ -3074,6 +3193,36 @@ sync_completed_show(mddev_t *mddev, char *page)
 
 static struct md_sysfs_entry md_sync_completed = __ATTR_RO(sync_completed);
 
+static ssize_t
+min_sync_show(mddev_t *mddev, char *page)
+{
+       return sprintf(page, "%llu\n",
+                      (unsigned long long)mddev->resync_min);
+}
+static ssize_t
+min_sync_store(mddev_t *mddev, const char *buf, size_t len)
+{
+       unsigned long long min;
+       if (strict_strtoull(buf, 10, &min))
+               return -EINVAL;
+       if (min > mddev->resync_max)
+               return -EINVAL;
+       if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
+               return -EBUSY;
+
+       /* Must be a multiple of chunk_size */
+       if (mddev->chunk_size) {
+               if (min & (sector_t)((mddev->chunk_size>>9)-1))
+                       return -EINVAL;
+       }
+       mddev->resync_min = min;
+
+       return len;
+}
+
+static struct md_sysfs_entry md_min_sync =
+__ATTR(sync_min, S_IRUGO|S_IWUSR, min_sync_show, min_sync_store);
+
 static ssize_t
 max_sync_show(mddev_t *mddev, char *page)
 {
@@ -3089,9 +3238,10 @@ max_sync_store(mddev_t *mddev, const char *buf, size_t len)
        if (strncmp(buf, "max", 3) == 0)
                mddev->resync_max = MaxSector;
        else {
-               char *ep;
-               unsigned long long max = simple_strtoull(buf, &ep, 10);
-               if (ep == buf || (*ep != 0 && *ep != '\n'))
+               unsigned long long max;
+               if (strict_strtoull(buf, 10, &max))
+                       return -EINVAL;
+               if (max < mddev->resync_min)
                        return -EINVAL;
                if (max < mddev->resync_max &&
                    test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))
@@ -3222,6 +3372,7 @@ static struct attribute *md_redundancy_attrs[] = {
        &md_sync_speed.attr,
        &md_sync_force_parallel.attr,
        &md_sync_completed.attr,
+       &md_min_sync.attr,
        &md_max_sync.attr,
        &md_suspend_lo.attr,
        &md_suspend_hi.attr,
@@ -3326,9 +3477,9 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
        disk->queue = mddev->queue;
        add_disk(disk);
        mddev->gendisk = disk;
-       mutex_unlock(&disks_mutex);
        error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->dev.kobj,
                                     "%s", "md");
+       mutex_unlock(&disks_mutex);
        if (error)
                printk(KERN_WARNING "md: cannot register %s/md - name in use\n",
                       disk->disk_name);
@@ -3341,7 +3492,11 @@ static void md_safemode_timeout(unsigned long data)
 {
        mddev_t *mddev = (mddev_t *) data;
 
-       mddev->safemode = 1;
+       if (!atomic_read(&mddev->writes_pending)) {
+               mddev->safemode = 1;
+               if (mddev->external)
+                       sysfs_notify(&mddev->kobj, NULL, "array_state");
+       }
        md_wakeup_thread(mddev->thread);
 }
 
@@ -3448,6 +3603,7 @@ static int do_md_run(mddev_t * mddev)
                                return -EINVAL;
                        }
                }
+               sysfs_notify(&rdev->kobj, NULL, "state");
        }
 
        md_probe(mddev->unit, NULL, NULL);
@@ -3519,7 +3675,9 @@ static int do_md_run(mddev_t * mddev)
                mddev->ro = 2; /* read-only, but switch on first write */
 
        err = mddev->pers->run(mddev);
-       if (!err && mddev->pers->sync_request) {
+       if (err)
+               printk(KERN_ERR "md: pers->run() failed ...\n");
+       else if (mddev->pers->sync_request) {
                err = bitmap_create(mddev);
                if (err) {
                        printk(KERN_ERR "%s: failed to create bitmap (%d)\n",
@@ -3528,7 +3686,6 @@ static int do_md_run(mddev_t * mddev)
                }
        }
        if (err) {
-               printk(KERN_ERR "md: pers->run() failed ...\n");
                module_put(mddev->pers->owner);
                mddev->pers = NULL;
                bitmap_destroy(mddev);
@@ -3608,6 +3765,9 @@ static int do_md_run(mddev_t * mddev)
 
        mddev->changed = 1;
        md_new_event(mddev);
+       sysfs_notify(&mddev->kobj, NULL, "array_state");
+       sysfs_notify(&mddev->kobj, NULL, "sync_action");
+       sysfs_notify(&mddev->kobj, NULL, "degraded");
        kobject_uevent(&mddev->gendisk->dev.kobj, KOBJ_CHANGE);
        return 0;
 }
@@ -3642,6 +3802,8 @@ static int restart_array(mddev_t *mddev)
                md_wakeup_thread(mddev->thread);
                md_wakeup_thread(mddev->sync_thread);
                err = 0;
+               sysfs_notify(&mddev->kobj, NULL, "array_state");
+
        } else
                err = -EINVAL;
 
@@ -3777,6 +3939,7 @@ static int do_md_stop(mddev_t * mddev, int mode)
                mddev->size = 0;
                mddev->raid_disks = 0;
                mddev->recovery_cp = 0;
+               mddev->resync_min = 0;
                mddev->resync_max = MaxSector;
                mddev->reshape_position = MaxSector;
                mddev->external = 0;
@@ -3811,6 +3974,7 @@ static int do_md_stop(mddev_t * mddev, int mode)
                        mdname(mddev));
        err = 0;
        md_new_event(mddev);
+       sysfs_notify(&mddev->kobj, NULL, "array_state");
 out:
        return err;
 }
@@ -4009,9 +4173,11 @@ static int get_bitmap_file(mddev_t * mddev, void __user * arg)
        char *ptr, *buf = NULL;
        int err = -ENOMEM;
 
-       md_allow_write(mddev);
+       if (md_allow_write(mddev))
+               file = kmalloc(sizeof(*file), GFP_NOIO);
+       else
+               file = kmalloc(sizeof(*file), GFP_KERNEL);
 
-       file = kmalloc(sizeof(*file), GFP_KERNEL);
        if (!file)
                goto out;
 
@@ -4172,8 +4338,12 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
                }
                if (err)
                        export_rdev(rdev);
+               else
+                       sysfs_notify(&rdev->kobj, NULL, "state");
 
                md_update_sb(mddev, 1);
+               if (mddev->degraded)
+                       set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
                set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
                md_wakeup_thread(mddev->thread);
                return err;
@@ -4232,9 +4402,6 @@ static int hot_remove_disk(mddev_t * mddev, dev_t dev)
        char b[BDEVNAME_SIZE];
        mdk_rdev_t *rdev;
 
-       if (!mddev->pers)
-               return -ENODEV;
-
        rdev = find_rdev(mddev, dev);
        if (!rdev)
                return -ENXIO;
@@ -4641,6 +4808,12 @@ static int set_disk_faulty(mddev_t *mddev, dev_t dev)
        return 0;
 }
 
+/*
+ * We have a problem here : there is no easy way to give a CHS
+ * virtual geometry. We currently pretend that we have a 2 heads
+ * 4 sectors (with a BIG number of cylinders...). This drives
+ * dosfs just mad... ;-)
+ */
 static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 {
        mddev_t *mddev = bdev->bd_disk->private_data;
@@ -4792,12 +4965,6 @@ static int md_ioctl(struct inode *inode, struct file *file,
                        err = do_md_stop (mddev, 1);
                        goto done_unlock;
 
-       /*
-        * We have a problem here : there is no easy way to give a CHS
-        * virtual geometry. We currently pretend that we have a 2 heads
-        * 4 sectors (with a BIG number of cylinders...). This drives
-        * dosfs just mad... ;-)
-        */
        }
 
        /*
@@ -4807,13 +4974,12 @@ static int md_ioctl(struct inode *inode, struct file *file,
         * here and hit the 'default' below, so only disallow
         * 'md' ioctls, and switch to rw mode if started auto-readonly.
         */
-       if (_IOC_TYPE(cmd) == MD_MAJOR &&
-           mddev->ro && mddev->pers) {
+       if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) {
                if (mddev->ro == 2) {
                        mddev->ro = 0;
-               set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
-               md_wakeup_thread(mddev->thread);
-
+                       sysfs_notify(&mddev->kobj, NULL, "array_state");
+                       set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
+                       md_wakeup_thread(mddev->thread);
                } else {
                        err = -EROFS;
                        goto abort_unlock;
@@ -5029,6 +5195,9 @@ void md_error(mddev_t *mddev, mdk_rdev_t *rdev)
        if (!mddev->pers->error_handler)
                return;
        mddev->pers->error_handler(mddev,rdev);
+       if (mddev->degraded)
+               set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
+       set_bit(StateChanged, &rdev->flags);
        set_bit(MD_RECOVERY_INTR, &mddev->recovery);
        set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
        md_wakeup_thread(mddev->thread);
@@ -5451,6 +5620,7 @@ void md_done_sync(mddev_t *mddev, int blocks, int ok)
  */
 void md_write_start(mddev_t *mddev, struct bio *bi)
 {
+       int did_change = 0;
        if (bio_data_dir(bi) != WRITE)
                return;
 
@@ -5461,6 +5631,7 @@ void md_write_start(mddev_t *mddev, struct bio *bi)
                set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
                md_wakeup_thread(mddev->thread);
                md_wakeup_thread(mddev->sync_thread);
+               did_change = 1;
        }
        atomic_inc(&mddev->writes_pending);
        if (mddev->safemode == 1)
@@ -5471,10 +5642,12 @@ void md_write_start(mddev_t *mddev, struct bio *bi)
                        mddev->in_sync = 0;
                        set_bit(MD_CHANGE_CLEAN, &mddev->flags);
                        md_wakeup_thread(mddev->thread);
+                       did_change = 1;
                }
                spin_unlock_irq(&mddev->write_lock);
-               sysfs_notify(&mddev->kobj, NULL, "array_state");
        }
+       if (did_change)
+               sysfs_notify(&mddev->kobj, NULL, "array_state");
        wait_event(mddev->sb_wait,
                   !test_bit(MD_CHANGE_CLEAN, &mddev->flags) &&
                   !test_bit(MD_CHANGE_PENDING, &mddev->flags));
@@ -5495,13 +5668,18 @@ void md_write_end(mddev_t *mddev)
  * may proceed without blocking.  It is important to call this before
  * attempting a GFP_KERNEL allocation while holding the mddev lock.
  * Must be called with mddev_lock held.
+ *
+ * In the ->external case MD_CHANGE_CLEAN can not be cleared until mddev->lock
+ * is dropped, so return -EAGAIN after notifying userspace.
  */
-void md_allow_write(mddev_t *mddev)
+int md_allow_write(mddev_t *mddev)
 {
        if (!mddev->pers)
-               return;
+               return 0;
        if (mddev->ro)
-               return;
+               return 0;
+       if (!mddev->pers->sync_request)
+               return 0;
 
        spin_lock_irq(&mddev->write_lock);
        if (mddev->in_sync) {
@@ -5512,14 +5690,14 @@ void md_allow_write(mddev_t *mddev)
                        mddev->safemode = 1;
                spin_unlock_irq(&mddev->write_lock);
                md_update_sb(mddev, 0);
-
                sysfs_notify(&mddev->kobj, NULL, "array_state");
-               /* wait for the dirty state to be recorded in the metadata */
-               wait_event(mddev->sb_wait,
-                          !test_bit(MD_CHANGE_CLEAN, &mddev->flags) &&
-                          !test_bit(MD_CHANGE_PENDING, &mddev->flags));
        } else
                spin_unlock_irq(&mddev->write_lock);
+
+       if (test_bit(MD_CHANGE_CLEAN, &mddev->flags))
+               return -EAGAIN;
+       else
+               return 0;
 }
 EXPORT_SYMBOL_GPL(md_allow_write);
 
@@ -5625,9 +5803,11 @@ void md_do_sync(mddev_t *mddev)
                max_sectors = mddev->resync_max_sectors;
                mddev->resync_mismatches = 0;
                /* we don't use the checkpoint if there's a bitmap */
-               if (!mddev->bitmap &&
-                   !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
+               if (test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
+                       j = mddev->resync_min;
+               else if (!mddev->bitmap)
                        j = mddev->recovery_cp;
+
        } else if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery))
                max_sectors = mddev->size << 1;
        else {
@@ -5796,6 +5976,7 @@ void md_do_sync(mddev_t *mddev)
 
  skip:
        mddev->curr_resync = 0;
+       mddev->resync_min = 0;
        mddev->resync_max = MaxSector;
        sysfs_notify(&mddev->kobj, NULL, "sync_completed");
        wake_up(&resync_wait);
@@ -5845,7 +6026,8 @@ static int remove_and_add_spares(mddev_t *mddev)
                        if (rdev->raid_disk < 0
                            && !test_bit(Faulty, &rdev->flags)) {
                                rdev->recovery_offset = 0;
-                               if (mddev->pers->hot_add_disk(mddev,rdev)) {
+                               if (mddev->pers->
+                                   hot_add_disk(mddev, rdev) == 0) {
                                        char nm[20];
                                        sprintf(nm, "rd%d", rdev->raid_disk);
                                        if (sysfs_create_link(&mddev->kobj,
@@ -5920,23 +6102,31 @@ void md_check_recovery(mddev_t *mddev)
                int spares = 0;
 
                if (!mddev->external) {
+                       int did_change = 0;
                        spin_lock_irq(&mddev->write_lock);
                        if (mddev->safemode &&
                            !atomic_read(&mddev->writes_pending) &&
                            !mddev->in_sync &&
                            mddev->recovery_cp == MaxSector) {
                                mddev->in_sync = 1;
+                               did_change = 1;
                                if (mddev->persistent)
                                        set_bit(MD_CHANGE_CLEAN, &mddev->flags);
                        }
                        if (mddev->safemode == 1)
                                mddev->safemode = 0;
                        spin_unlock_irq(&mddev->write_lock);
+                       if (did_change)
+                               sysfs_notify(&mddev->kobj, NULL, "array_state");
                }
 
                if (mddev->flags)
                        md_update_sb(mddev, 0);
 
+               rdev_for_each(rdev, rtmp, mddev)
+                       if (test_and_clear_bit(StateChanged, &rdev->flags))
+                               sysfs_notify(&rdev->kobj, NULL, "state");
+
 
                if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) &&
                    !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) {
@@ -5951,7 +6141,9 @@ void md_check_recovery(mddev_t *mddev)
                        if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
                                /* success...*/
                                /* activate any spares */
-                               mddev->pers->spare_active(mddev);
+                               if (mddev->pers->spare_active(mddev))
+                                       sysfs_notify(&mddev->kobj, NULL,
+                                                    "degraded");
                        }
                        md_update_sb(mddev, 1);
 
@@ -5965,13 +6157,18 @@ void md_check_recovery(mddev_t *mddev)
                        mddev->recovery = 0;
                        /* flag recovery needed just to double check */
                        set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
+                       sysfs_notify(&mddev->kobj, NULL, "sync_action");
                        md_new_event(mddev);
                        goto unlock;
                }
+               /* Set RUNNING before clearing NEEDED to avoid
+                * any transients in the value of "sync_action".
+                */
+               set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
+               clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
                /* Clear some bits that don't mean anything, but
                 * might be left set
                 */
-               clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
                clear_bit(MD_RECOVERY_INTR, &mddev->recovery);
                clear_bit(MD_RECOVERY_DONE, &mddev->recovery);
 
@@ -5989,17 +6186,19 @@ void md_check_recovery(mddev_t *mddev)
                                /* Cannot proceed */
                                goto unlock;
                        set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
+                       clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
                } else if ((spares = remove_and_add_spares(mddev))) {
                        clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
                        clear_bit(MD_RECOVERY_CHECK, &mddev->recovery);
+                       set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
                } else if (mddev->recovery_cp < MaxSector) {
                        set_bit(MD_RECOVERY_SYNC, &mddev->recovery);
+                       clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
                } else if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
                        /* nothing to be done ... */
                        goto unlock;
 
                if (mddev->pers->sync_request) {
-                       set_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
                        if (spares && mddev->bitmap && ! mddev->bitmap->file) {
                                /* We are adding a device or devices to an array
                                 * which has the bitmap stored on all devices.
@@ -6018,9 +6217,16 @@ void md_check_recovery(mddev_t *mddev)
                                mddev->recovery = 0;
                        } else
                                md_wakeup_thread(mddev->sync_thread);
+                       sysfs_notify(&mddev->kobj, NULL, "sync_action");
                        md_new_event(mddev);
                }
        unlock:
+               if (!mddev->sync_thread) {
+                       clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
+                       if (test_and_clear_bit(MD_RECOVERY_RECOVER,
+                                              &mddev->recovery))
+                               sysfs_notify(&mddev->kobj, NULL, "sync_action");
+               }
                mddev_unlock(mddev);
        }
 }
index e968116e0de9699d2bef0f114ae79f638506bf1c..541cbe3414bd29dc2e0260b322b3a45fa3d04c55 100644 (file)
@@ -281,13 +281,18 @@ static int multipath_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
 {
        multipath_conf_t *conf = mddev->private;
        struct request_queue *q;
-       int found = 0;
+       int err = -EEXIST;
        int path;
        struct multipath_info *p;
+       int first = 0;
+       int last = mddev->raid_disks - 1;
+
+       if (rdev->raid_disk >= 0)
+               first = last = rdev->raid_disk;
 
        print_multipath_conf(conf);
 
-       for (path=0; path<mddev->raid_disks; path++) 
+       for (path = first; path <= last; path++)
                if ((p=conf->multipaths+path)->rdev == NULL) {
                        q = rdev->bdev->bd_disk->queue;
                        blk_queue_stack_limits(mddev->queue, q);
@@ -307,11 +312,13 @@ static int multipath_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
                        rdev->raid_disk = path;
                        set_bit(In_sync, &rdev->flags);
                        rcu_assign_pointer(p->rdev, rdev);
-                       found = 1;
+                       err = 0;
+                       break;
                }
 
        print_multipath_conf(conf);
-       return found;
+
+       return err;
 }
 
 static int multipath_remove_disk(mddev_t *mddev, int number)
index c610b947218afb73f49982d59dd178a7fdbd0959..491dc2d4ad5fe7dc81c95bfb168e97d98a67a95d 100644 (file)
@@ -1100,11 +1100,16 @@ static int raid1_spare_active(mddev_t *mddev)
 static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
 {
        conf_t *conf = mddev->private;
-       int found = 0;
+       int err = -EEXIST;
        int mirror = 0;
        mirror_info_t *p;
+       int first = 0;
+       int last = mddev->raid_disks - 1;
 
-       for (mirror=0; mirror < mddev->raid_disks; mirror++)
+       if (rdev->raid_disk >= 0)
+               first = last = rdev->raid_disk;
+
+       for (mirror = first; mirror <= last; mirror++)
                if ( !(p=conf->mirrors+mirror)->rdev) {
 
                        blk_queue_stack_limits(mddev->queue,
@@ -1119,7 +1124,7 @@ static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
 
                        p->head_position = 0;
                        rdev->raid_disk = mirror;
-                       found = 1;
+                       err = 0;
                        /* As all devices are equivalent, we don't need a full recovery
                         * if this was recently any drive of the array
                         */
@@ -1130,7 +1135,7 @@ static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
                }
 
        print_conf(conf);
-       return found;
+       return err;
 }
 
 static int raid1_remove_disk(mddev_t *mddev, int number)
@@ -2131,7 +2136,7 @@ static int raid1_reshape(mddev_t *mddev)
        conf_t *conf = mddev_to_conf(mddev);
        int cnt, raid_disks;
        unsigned long flags;
-       int d, d2;
+       int d, d2, err;
 
        /* Cannot change chunk_size, layout, or level */
        if (mddev->chunk_size != mddev->new_chunk ||
@@ -2143,7 +2148,9 @@ static int raid1_reshape(mddev_t *mddev)
                return -EINVAL;
        }
 
-       md_allow_write(mddev);
+       err = md_allow_write(mddev);
+       if (err)
+               return err;
 
        raid_disks = mddev->raid_disks + mddev->delta_disks;
 
index a71277b640ab036bea60206e29900c034ddd50a3..df08a9fa3a1fc8c694f42a1a626736709f8b808d 100644 (file)
@@ -1113,24 +1113,30 @@ static int raid10_spare_active(mddev_t *mddev)
 static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
 {
        conf_t *conf = mddev->private;
-       int found = 0;
+       int err = -EEXIST;
        int mirror;
        mirror_info_t *p;
+       int first = 0;
+       int last = mddev->raid_disks - 1;
 
        if (mddev->recovery_cp < MaxSector)
                /* only hot-add to in-sync arrays, as recovery is
                 * very different from resync
                 */
-               return 0;
+               return -EBUSY;
        if (!enough(conf))
-               return 0;
+               return -EINVAL;
+
+       if (rdev->raid_disk)
+               first = last = rdev->raid_disk;
 
        if (rdev->saved_raid_disk >= 0 &&
+           rdev->saved_raid_disk >= first &&
            conf->mirrors[rdev->saved_raid_disk].rdev == NULL)
                mirror = rdev->saved_raid_disk;
        else
-               mirror = 0;
-       for ( ; mirror < mddev->raid_disks; mirror++)
+               mirror = first;
+       for ( ; mirror <= last ; mirror++)
                if ( !(p=conf->mirrors+mirror)->rdev) {
 
                        blk_queue_stack_limits(mddev->queue,
@@ -1145,7 +1151,7 @@ static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
 
                        p->head_position = 0;
                        rdev->raid_disk = mirror;
-                       found = 1;
+                       err = 0;
                        if (rdev->saved_raid_disk != mirror)
                                conf->fullsync = 1;
                        rcu_assign_pointer(p->rdev, rdev);
@@ -1153,7 +1159,7 @@ static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
                }
 
        print_conf(conf);
-       return found;
+       return err;
 }
 
 static int raid10_remove_disk(mddev_t *mddev, int number)
index 3b27df52456b510219c4f3f22dfb2c644ff3845c..8f4c70a5321067a21d780eb60b8d47ed5a8082ab 100644 (file)
@@ -115,15 +115,20 @@ static void return_io(struct bio *return_bi)
                return_bi = bi->bi_next;
                bi->bi_next = NULL;
                bi->bi_size = 0;
-               bi->bi_end_io(bi,
-                             test_bit(BIO_UPTODATE, &bi->bi_flags)
-                               ? 0 : -EIO);
+               bio_endio(bi, 0);
                bi = return_bi;
        }
 }
 
 static void print_raid5_conf (raid5_conf_t *conf);
 
+static int stripe_operations_active(struct stripe_head *sh)
+{
+       return sh->check_state || sh->reconstruct_state ||
+              test_bit(STRIPE_BIOFILL_RUN, &sh->state) ||
+              test_bit(STRIPE_COMPUTE_RUN, &sh->state);
+}
+
 static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
 {
        if (atomic_dec_and_test(&sh->count)) {
@@ -143,7 +148,7 @@ static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
                        }
                        md_wakeup_thread(conf->mddev->thread);
                } else {
-                       BUG_ON(sh->ops.pending);
+                       BUG_ON(stripe_operations_active(sh));
                        if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) {
                                atomic_dec(&conf->preread_active_stripes);
                                if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD)
@@ -245,7 +250,7 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx, int
 
        BUG_ON(atomic_read(&sh->count) != 0);
        BUG_ON(test_bit(STRIPE_HANDLE, &sh->state));
-       BUG_ON(sh->ops.pending || sh->ops.ack || sh->ops.complete);
+       BUG_ON(stripe_operations_active(sh));
 
        CHECK_DEVLOCK();
        pr_debug("init_stripe called, stripe %llu\n",
@@ -346,62 +351,18 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
        return sh;
 }
 
-/* test_and_ack_op() ensures that we only dequeue an operation once */
-#define test_and_ack_op(op, pend) \
-do {                                                   \
-       if (test_bit(op, &sh->ops.pending) &&           \
-               !test_bit(op, &sh->ops.complete)) {     \
-               if (test_and_set_bit(op, &sh->ops.ack)) \
-                       clear_bit(op, &pend);           \
-               else                                    \
-                       ack++;                          \
-       } else                                          \
-               clear_bit(op, &pend);                   \
-} while (0)
-
-/* find new work to run, do not resubmit work that is already
- * in flight
- */
-static unsigned long get_stripe_work(struct stripe_head *sh)
-{
-       unsigned long pending;
-       int ack = 0;
-
-       pending = sh->ops.pending;
-
-       test_and_ack_op(STRIPE_OP_BIOFILL, pending);
-       test_and_ack_op(STRIPE_OP_COMPUTE_BLK, pending);
-       test_and_ack_op(STRIPE_OP_PREXOR, pending);
-       test_and_ack_op(STRIPE_OP_BIODRAIN, pending);
-       test_and_ack_op(STRIPE_OP_POSTXOR, pending);
-       test_and_ack_op(STRIPE_OP_CHECK, pending);
-       if (test_and_clear_bit(STRIPE_OP_IO, &sh->ops.pending))
-               ack++;
-
-       sh->ops.count -= ack;
-       if (unlikely(sh->ops.count < 0)) {
-               printk(KERN_ERR "pending: %#lx ops.pending: %#lx ops.ack: %#lx "
-                       "ops.complete: %#lx\n", pending, sh->ops.pending,
-                       sh->ops.ack, sh->ops.complete);
-               BUG();
-       }
-
-       return pending;
-}
-
 static void
 raid5_end_read_request(struct bio *bi, int error);
 static void
 raid5_end_write_request(struct bio *bi, int error);
 
-static void ops_run_io(struct stripe_head *sh)
+static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
 {
        raid5_conf_t *conf = sh->raid_conf;
        int i, disks = sh->disks;
 
        might_sleep();
 
-       set_bit(STRIPE_IO_STARTED, &sh->state);
        for (i = disks; i--; ) {
                int rw;
                struct bio *bi;
@@ -430,11 +391,11 @@ static void ops_run_io(struct stripe_head *sh)
                rcu_read_unlock();
 
                if (rdev) {
-                       if (test_bit(STRIPE_SYNCING, &sh->state) ||
-                               test_bit(STRIPE_EXPAND_SOURCE, &sh->state) ||
-                               test_bit(STRIPE_EXPAND_READY, &sh->state))
+                       if (s->syncing || s->expanding || s->expanded)
                                md_sync_acct(rdev->bdev, STRIPE_SECTORS);
 
+                       set_bit(STRIPE_IO_STARTED, &sh->state);
+
                        bi->bi_bdev = rdev->bdev;
                        pr_debug("%s: for %llu schedule op %ld on disc %d\n",
                                __func__, (unsigned long long)sh->sector,
@@ -528,38 +489,34 @@ static void ops_complete_biofill(void *stripe_head_ref)
                (unsigned long long)sh->sector);
 
        /* clear completed biofills */
+       spin_lock_irq(&conf->device_lock);
        for (i = sh->disks; i--; ) {
                struct r5dev *dev = &sh->dev[i];
 
                /* acknowledge completion of a biofill operation */
                /* and check if we need to reply to a read request,
                 * new R5_Wantfill requests are held off until
-                * !test_bit(STRIPE_OP_BIOFILL, &sh->ops.pending)
+                * !STRIPE_BIOFILL_RUN
                 */
                if (test_and_clear_bit(R5_Wantfill, &dev->flags)) {
                        struct bio *rbi, *rbi2;
 
-                       /* The access to dev->read is outside of the
-                        * spin_lock_irq(&conf->device_lock), but is protected
-                        * by the STRIPE_OP_BIOFILL pending bit
-                        */
                        BUG_ON(!dev->read);
                        rbi = dev->read;
                        dev->read = NULL;
                        while (rbi && rbi->bi_sector <
                                dev->sector + STRIPE_SECTORS) {
                                rbi2 = r5_next_bio(rbi, dev->sector);
-                               spin_lock_irq(&conf->device_lock);
                                if (--rbi->bi_phys_segments == 0) {
                                        rbi->bi_next = return_bi;
                                        return_bi = rbi;
                                }
-                               spin_unlock_irq(&conf->device_lock);
                                rbi = rbi2;
                        }
                }
        }
-       set_bit(STRIPE_OP_BIOFILL, &sh->ops.complete);
+       spin_unlock_irq(&conf->device_lock);
+       clear_bit(STRIPE_BIOFILL_RUN, &sh->state);
 
        return_io(return_bi);
 
@@ -610,13 +567,14 @@ static void ops_complete_compute5(void *stripe_head_ref)
        set_bit(R5_UPTODATE, &tgt->flags);
        BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags));
        clear_bit(R5_Wantcompute, &tgt->flags);
-       set_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete);
+       clear_bit(STRIPE_COMPUTE_RUN, &sh->state);
+       if (sh->check_state == check_state_compute_run)
+               sh->check_state = check_state_compute_result;
        set_bit(STRIPE_HANDLE, &sh->state);
        release_stripe(sh);
 }
 
-static struct dma_async_tx_descriptor *
-ops_run_compute5(struct stripe_head *sh, unsigned long pending)
+static struct dma_async_tx_descriptor *ops_run_compute5(struct stripe_head *sh)
 {
        /* kernel stack size limits the total number of disks */
        int disks = sh->disks;
@@ -646,10 +604,6 @@ ops_run_compute5(struct stripe_head *sh, unsigned long pending)
                        ASYNC_TX_XOR_ZERO_DST, NULL,
                        ops_complete_compute5, sh);
 
-       /* ack now if postxor is not set to be run */
-       if (tx && !test_bit(STRIPE_OP_POSTXOR, &pending))
-               async_tx_ack(tx);
-
        return tx;
 }
 
@@ -659,8 +613,6 @@ static void ops_complete_prexor(void *stripe_head_ref)
 
        pr_debug("%s: stripe %llu\n", __func__,
                (unsigned long long)sh->sector);
-
-       set_bit(STRIPE_OP_PREXOR, &sh->ops.complete);
 }
 
 static struct dma_async_tx_descriptor *
@@ -680,7 +632,7 @@ ops_run_prexor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx)
        for (i = disks; i--; ) {
                struct r5dev *dev = &sh->dev[i];
                /* Only process blocks that are known to be uptodate */
-               if (dev->towrite && test_bit(R5_Wantprexor, &dev->flags))
+               if (test_bit(R5_Wantdrain, &dev->flags))
                        xor_srcs[count++] = dev->page;
        }
 
@@ -692,16 +644,10 @@ ops_run_prexor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx)
 }
 
 static struct dma_async_tx_descriptor *
-ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
-                unsigned long pending)
+ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx)
 {
        int disks = sh->disks;
-       int pd_idx = sh->pd_idx, i;
-
-       /* check if prexor is active which means only process blocks
-        * that are part of a read-modify-write (Wantprexor)
-        */
-       int prexor = test_bit(STRIPE_OP_PREXOR, &pending);
+       int i;
 
        pr_debug("%s: stripe %llu\n", __func__,
                (unsigned long long)sh->sector);
@@ -709,20 +655,8 @@ ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
        for (i = disks; i--; ) {
                struct r5dev *dev = &sh->dev[i];
                struct bio *chosen;
-               int towrite;
-
-               towrite = 0;
-               if (prexor) { /* rmw */
-                       if (dev->towrite &&
-                           test_bit(R5_Wantprexor, &dev->flags))
-                               towrite = 1;
-               } else { /* rcw */
-                       if (i != pd_idx && dev->towrite &&
-                               test_bit(R5_LOCKED, &dev->flags))
-                               towrite = 1;
-               }
 
-               if (towrite) {
+               if (test_and_clear_bit(R5_Wantdrain, &dev->flags)) {
                        struct bio *wbi;
 
                        spin_lock(&sh->lock);
@@ -745,18 +679,6 @@ ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
 }
 
 static void ops_complete_postxor(void *stripe_head_ref)
-{
-       struct stripe_head *sh = stripe_head_ref;
-
-       pr_debug("%s: stripe %llu\n", __func__,
-               (unsigned long long)sh->sector);
-
-       set_bit(STRIPE_OP_POSTXOR, &sh->ops.complete);
-       set_bit(STRIPE_HANDLE, &sh->state);
-       release_stripe(sh);
-}
-
-static void ops_complete_write(void *stripe_head_ref)
 {
        struct stripe_head *sh = stripe_head_ref;
        int disks = sh->disks, i, pd_idx = sh->pd_idx;
@@ -770,16 +692,21 @@ static void ops_complete_write(void *stripe_head_ref)
                        set_bit(R5_UPTODATE, &dev->flags);
        }
 
-       set_bit(STRIPE_OP_BIODRAIN, &sh->ops.complete);
-       set_bit(STRIPE_OP_POSTXOR, &sh->ops.complete);
+       if (sh->reconstruct_state == reconstruct_state_drain_run)
+               sh->reconstruct_state = reconstruct_state_drain_result;
+       else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run)
+               sh->reconstruct_state = reconstruct_state_prexor_drain_result;
+       else {
+               BUG_ON(sh->reconstruct_state != reconstruct_state_run);
+               sh->reconstruct_state = reconstruct_state_result;
+       }
 
        set_bit(STRIPE_HANDLE, &sh->state);
        release_stripe(sh);
 }
 
 static void
-ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
-               unsigned long pending)
+ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx)
 {
        /* kernel stack size limits the total number of disks */
        int disks = sh->disks;
@@ -787,9 +714,8 @@ ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
 
        int count = 0, pd_idx = sh->pd_idx, i;
        struct page *xor_dest;
-       int prexor = test_bit(STRIPE_OP_PREXOR, &pending);
+       int prexor = 0;
        unsigned long flags;
-       dma_async_tx_callback callback;
 
        pr_debug("%s: stripe %llu\n", __func__,
                (unsigned long long)sh->sector);
@@ -797,7 +723,8 @@ ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
        /* check if prexor is active which means only process blocks
         * that are part of a read-modify-write (written)
         */
-       if (prexor) {
+       if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) {
+               prexor = 1;
                xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page;
                for (i = disks; i--; ) {
                        struct r5dev *dev = &sh->dev[i];
@@ -813,10 +740,6 @@ ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
                }
        }
 
-       /* check whether this postxor is part of a write */
-       callback = test_bit(STRIPE_OP_BIODRAIN, &pending) ?
-               ops_complete_write : ops_complete_postxor;
-
        /* 1/ if we prexor'd then the dest is reused as a source
         * 2/ if we did not prexor then we are redoing the parity
         * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST
@@ -830,25 +753,20 @@ ops_run_postxor(struct stripe_head *sh, struct dma_async_tx_descriptor *tx,
        if (unlikely(count == 1)) {
                flags &= ~(ASYNC_TX_XOR_DROP_DST | ASYNC_TX_XOR_ZERO_DST);
                tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE,
-                       flags, tx, callback, sh);
+                       flags, tx, ops_complete_postxor, sh);
        } else
                tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE,
-                       flags, tx, callback, sh);
+                       flags, tx, ops_complete_postxor, sh);
 }
 
 static void ops_complete_check(void *stripe_head_ref)
 {
        struct stripe_head *sh = stripe_head_ref;
-       int pd_idx = sh->pd_idx;
 
        pr_debug("%s: stripe %llu\n", __func__,
                (unsigned long long)sh->sector);
 
-       if (test_and_clear_bit(STRIPE_OP_MOD_DMA_CHECK, &sh->ops.pending) &&
-               sh->ops.zero_sum_result == 0)
-               set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags);
-
-       set_bit(STRIPE_OP_CHECK, &sh->ops.complete);
+       sh->check_state = check_state_check_result;
        set_bit(STRIPE_HANDLE, &sh->state);
        release_stripe(sh);
 }
@@ -875,46 +793,42 @@ static void ops_run_check(struct stripe_head *sh)
        tx = async_xor_zero_sum(xor_dest, xor_srcs, 0, count, STRIPE_SIZE,
                &sh->ops.zero_sum_result, 0, NULL, NULL, NULL);
 
-       if (tx)
-               set_bit(STRIPE_OP_MOD_DMA_CHECK, &sh->ops.pending);
-       else
-               clear_bit(STRIPE_OP_MOD_DMA_CHECK, &sh->ops.pending);
-
        atomic_inc(&sh->count);
        tx = async_trigger_callback(ASYNC_TX_DEP_ACK | ASYNC_TX_ACK, tx,
                ops_complete_check, sh);
 }
 
-static void raid5_run_ops(struct stripe_head *sh, unsigned long pending)
+static void raid5_run_ops(struct stripe_head *sh, unsigned long ops_request)
 {
        int overlap_clear = 0, i, disks = sh->disks;
        struct dma_async_tx_descriptor *tx = NULL;
 
-       if (test_bit(STRIPE_OP_BIOFILL, &pending)) {
+       if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) {
                ops_run_biofill(sh);
                overlap_clear++;
        }
 
-       if (test_bit(STRIPE_OP_COMPUTE_BLK, &pending))
-               tx = ops_run_compute5(sh, pending);
+       if (test_bit(STRIPE_OP_COMPUTE_BLK, &ops_request)) {
+               tx = ops_run_compute5(sh);
+               /* terminate the chain if postxor is not set to be run */
+               if (tx && !test_bit(STRIPE_OP_POSTXOR, &ops_request))
+                       async_tx_ack(tx);
+       }
 
-       if (test_bit(STRIPE_OP_PREXOR, &pending))
+       if (test_bit(STRIPE_OP_PREXOR, &ops_request))
                tx = ops_run_prexor(sh, tx);
 
-       if (test_bit(STRIPE_OP_BIODRAIN, &pending)) {
-               tx = ops_run_biodrain(sh, tx, pending);
+       if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) {
+               tx = ops_run_biodrain(sh, tx);
                overlap_clear++;
        }
 
-       if (test_bit(STRIPE_OP_POSTXOR, &pending))
-               ops_run_postxor(sh, tx, pending);
+       if (test_bit(STRIPE_OP_POSTXOR, &ops_request))
+               ops_run_postxor(sh, tx);
 
-       if (test_bit(STRIPE_OP_CHECK, &pending))
+       if (test_bit(STRIPE_OP_CHECK, &ops_request))
                ops_run_check(sh);
 
-       if (test_bit(STRIPE_OP_IO, &pending))
-               ops_run_io(sh);
-
        if (overlap_clear)
                for (i = disks; i--; ) {
                        struct r5dev *dev = &sh->dev[i];
@@ -997,14 +911,16 @@ static int resize_stripes(raid5_conf_t *conf, int newsize)
        struct stripe_head *osh, *nsh;
        LIST_HEAD(newstripes);
        struct disk_info *ndisks;
-       int err = 0;
+       int err;
        struct kmem_cache *sc;
        int i;
 
        if (newsize <= conf->pool_size)
                return 0; /* never bother to shrink */
 
-       md_allow_write(conf->mddev);
+       err = md_allow_write(conf->mddev);
+       if (err)
+               return err;
 
        /* Step 1 */
        sc = kmem_cache_create(conf->cache_name[1-conf->active_name],
@@ -1703,11 +1619,11 @@ static void compute_block_2(struct stripe_head *sh, int dd_idx1, int dd_idx2)
        }
 }
 
-static int
-handle_write_operations5(struct stripe_head *sh, int rcw, int expand)
+static void
+schedule_reconstruction5(struct stripe_head *sh, struct stripe_head_state *s,
+                        int rcw, int expand)
 {
        int i, pd_idx = sh->pd_idx, disks = sh->disks;
-       int locked = 0;
 
        if (rcw) {
                /* if we are not expanding this is a proper write request, and
@@ -1715,53 +1631,48 @@ handle_write_operations5(struct stripe_head *sh, int rcw, int expand)
                 * stripe cache
                 */
                if (!expand) {
-                       set_bit(STRIPE_OP_BIODRAIN, &sh->ops.pending);
-                       sh->ops.count++;
-               }
+                       sh->reconstruct_state = reconstruct_state_drain_run;
+                       set_bit(STRIPE_OP_BIODRAIN, &s->ops_request);
+               } else
+                       sh->reconstruct_state = reconstruct_state_run;
 
-               set_bit(STRIPE_OP_POSTXOR, &sh->ops.pending);
-               sh->ops.count++;
+               set_bit(STRIPE_OP_POSTXOR, &s->ops_request);
 
                for (i = disks; i--; ) {
                        struct r5dev *dev = &sh->dev[i];
 
                        if (dev->towrite) {
                                set_bit(R5_LOCKED, &dev->flags);
+                               set_bit(R5_Wantdrain, &dev->flags);
                                if (!expand)
                                        clear_bit(R5_UPTODATE, &dev->flags);
-                               locked++;
+                               s->locked++;
                        }
                }
-               if (locked + 1 == disks)
+               if (s->locked + 1 == disks)
                        if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state))
                                atomic_inc(&sh->raid_conf->pending_full_writes);
        } else {
                BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) ||
                        test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags)));
 
-               set_bit(STRIPE_OP_PREXOR, &sh->ops.pending);
-               set_bit(STRIPE_OP_BIODRAIN, &sh->ops.pending);
-               set_bit(STRIPE_OP_POSTXOR, &sh->ops.pending);
-
-               sh->ops.count += 3;
+               sh->reconstruct_state = reconstruct_state_prexor_drain_run;
+               set_bit(STRIPE_OP_PREXOR, &s->ops_request);
+               set_bit(STRIPE_OP_BIODRAIN, &s->ops_request);
+               set_bit(STRIPE_OP_POSTXOR, &s->ops_request);
 
                for (i = disks; i--; ) {
                        struct r5dev *dev = &sh->dev[i];
                        if (i == pd_idx)
                                continue;
 
-                       /* For a read-modify write there may be blocks that are
-                        * locked for reading while others are ready to be
-                        * written so we distinguish these blocks by the
-                        * R5_Wantprexor bit
-                        */
                        if (dev->towrite &&
                            (test_bit(R5_UPTODATE, &dev->flags) ||
-                           test_bit(R5_Wantcompute, &dev->flags))) {
-                               set_bit(R5_Wantprexor, &dev->flags);
+                            test_bit(R5_Wantcompute, &dev->flags))) {
+                               set_bit(R5_Wantdrain, &dev->flags);
                                set_bit(R5_LOCKED, &dev->flags);
                                clear_bit(R5_UPTODATE, &dev->flags);
-                               locked++;
+                               s->locked++;
                        }
                }
        }
@@ -1771,13 +1682,11 @@ handle_write_operations5(struct stripe_head *sh, int rcw, int expand)
         */
        set_bit(R5_LOCKED, &sh->dev[pd_idx].flags);
        clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags);
-       locked++;
+       s->locked++;
 
-       pr_debug("%s: stripe %llu locked: %d pending: %lx\n",
+       pr_debug("%s: stripe %llu locked: %d ops_request: %lx\n",
                __func__, (unsigned long long)sh->sector,
-               locked, sh->ops.pending);
-
-       return locked;
+               s->locked, s->ops_request);
 }
 
 /*
@@ -1876,7 +1785,7 @@ static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int disks)
 }
 
 static void
-handle_requests_to_failed_array(raid5_conf_t *conf, struct stripe_head *sh,
+handle_failed_stripe(raid5_conf_t *conf, struct stripe_head *sh,
                                struct stripe_head_state *s, int disks,
                                struct bio **return_bi)
 {
@@ -1967,48 +1876,38 @@ handle_requests_to_failed_array(raid5_conf_t *conf, struct stripe_head *sh,
                        md_wakeup_thread(conf->mddev->thread);
 }
 
-/* __handle_issuing_new_read_requests5 - returns 0 if there are no more disks
- * to process
+/* fetch_block5 - checks the given member device to see if its data needs
+ * to be read or computed to satisfy a request.
+ *
+ * Returns 1 when no more member devices need to be checked, otherwise returns
+ * 0 to tell the loop in handle_stripe_fill5 to continue
  */
-static int __handle_issuing_new_read_requests5(struct stripe_head *sh,
-                       struct stripe_head_state *s, int disk_idx, int disks)
+static int fetch_block5(struct stripe_head *sh, struct stripe_head_state *s,
+                       int disk_idx, int disks)
 {
        struct r5dev *dev = &sh->dev[disk_idx];
        struct r5dev *failed_dev = &sh->dev[s->failed_num];
 
-       /* don't schedule compute operations or reads on the parity block while
-        * a check is in flight
-        */
-       if ((disk_idx == sh->pd_idx) &&
-            test_bit(STRIPE_OP_CHECK, &sh->ops.pending))
-               return ~0;
-
        /* is the data in this block needed, and can we get it? */
        if (!test_bit(R5_LOCKED, &dev->flags) &&
-           !test_bit(R5_UPTODATE, &dev->flags) && (dev->toread ||
-           (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) ||
-            s->syncing || s->expanding || (s->failed &&
-            (failed_dev->toread || (failed_dev->towrite &&
-            !test_bit(R5_OVERWRITE, &failed_dev->flags)
-            ))))) {
-               /* 1/ We would like to get this block, possibly by computing it,
-                * but we might not be able to.
-                *
-                * 2/ Since parity check operations potentially make the parity
-                * block !uptodate it will need to be refreshed before any
-                * compute operations on data disks are scheduled.
-                *
-                * 3/ We hold off parity block re-reads until check operations
-                * have quiesced.
+           !test_bit(R5_UPTODATE, &dev->flags) &&
+           (dev->toread ||
+            (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) ||
+            s->syncing || s->expanding ||
+            (s->failed &&
+             (failed_dev->toread ||
+              (failed_dev->towrite &&
+               !test_bit(R5_OVERWRITE, &failed_dev->flags)))))) {
+               /* We would like to get this block, possibly by computing it,
+                * otherwise read it if the backing disk is insync
                 */
                if ((s->uptodate == disks - 1) &&
-                   (s->failed && disk_idx == s->failed_num) &&
-                   !test_bit(STRIPE_OP_CHECK, &sh->ops.pending)) {
-                       set_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending);
+                   (s->failed && disk_idx == s->failed_num)) {
+                       set_bit(STRIPE_COMPUTE_RUN, &sh->state);
+                       set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request);
                        set_bit(R5_Wantcompute, &dev->flags);
                        sh->ops.target = disk_idx;
                        s->req_compute = 1;
-                       sh->ops.count++;
                        /* Careful: from this point on 'uptodate' is in the eye
                         * of raid5_run_ops which services 'compute' operations
                         * before writes. R5_Wantcompute flags a block that will
@@ -2016,53 +1915,40 @@ static int __handle_issuing_new_read_requests5(struct stripe_head *sh,
                         * subsequent operation.
                         */
                        s->uptodate++;
-                       return 0; /* uptodate + compute == disks */
+                       return 1; /* uptodate + compute == disks */
                } else if (test_bit(R5_Insync, &dev->flags)) {
                        set_bit(R5_LOCKED, &dev->flags);
                        set_bit(R5_Wantread, &dev->flags);
-                       if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending))
-                               sh->ops.count++;
                        s->locked++;
                        pr_debug("Reading block %d (sync=%d)\n", disk_idx,
                                s->syncing);
                }
        }
 
-       return ~0;
+       return 0;
 }
 
-static void handle_issuing_new_read_requests5(struct stripe_head *sh,
+/**
+ * handle_stripe_fill5 - read or compute data to satisfy pending requests.
+ */
+static void handle_stripe_fill5(struct stripe_head *sh,
                        struct stripe_head_state *s, int disks)
 {
        int i;
 
-       /* Clear completed compute operations.  Parity recovery
-        * (STRIPE_OP_MOD_REPAIR_PD) implies a write-back which is handled
-        * later on in this routine
-        */
-       if (test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete) &&
-               !test_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending)) {
-               clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete);
-               clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.ack);
-               clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending);
-       }
-
        /* look for blocks to read/compute, skip this if a compute
         * is already in flight, or if the stripe contents are in the
         * midst of changing due to a write
         */
-       if (!test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending) &&
-               !test_bit(STRIPE_OP_PREXOR, &sh->ops.pending) &&
-               !test_bit(STRIPE_OP_POSTXOR, &sh->ops.pending)) {
+       if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state &&
+           !sh->reconstruct_state)
                for (i = disks; i--; )
-                       if (__handle_issuing_new_read_requests5(
-                               sh, s, i, disks) == 0)
+                       if (fetch_block5(sh, s, i, disks))
                                break;
-       }
        set_bit(STRIPE_HANDLE, &sh->state);
 }
 
-static void handle_issuing_new_read_requests6(struct stripe_head *sh,
+static void handle_stripe_fill6(struct stripe_head *sh,
                        struct stripe_head_state *s, struct r6_state *r6s,
                        int disks)
 {
@@ -2121,12 +2007,12 @@ static void handle_issuing_new_read_requests6(struct stripe_head *sh,
 }
 
 
-/* handle_completed_write_requests
+/* handle_stripe_clean_event
  * any written block on an uptodate or failed drive can be returned.
  * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but
  * never LOCKED, so we don't need to test 'failed' directly.
  */
-static void handle_completed_write_requests(raid5_conf_t *conf,
+static void handle_stripe_clean_event(raid5_conf_t *conf,
        struct stripe_head *sh, int disks, struct bio **return_bi)
 {
        int i;
@@ -2171,7 +2057,7 @@ static void handle_completed_write_requests(raid5_conf_t *conf,
                        md_wakeup_thread(conf->mddev->thread);
 }
 
-static void handle_issuing_new_write_requests5(raid5_conf_t *conf,
+static void handle_stripe_dirtying5(raid5_conf_t *conf,
                struct stripe_head *sh, struct stripe_head_state *s, int disks)
 {
        int rmw = 0, rcw = 0, i;
@@ -2215,9 +2101,6 @@ static void handle_issuing_new_write_requests5(raid5_conf_t *conf,
                                                "%d for r-m-w\n", i);
                                        set_bit(R5_LOCKED, &dev->flags);
                                        set_bit(R5_Wantread, &dev->flags);
-                                       if (!test_and_set_bit(
-                                               STRIPE_OP_IO, &sh->ops.pending))
-                                               sh->ops.count++;
                                        s->locked++;
                                } else {
                                        set_bit(STRIPE_DELAYED, &sh->state);
@@ -2241,9 +2124,6 @@ static void handle_issuing_new_write_requests5(raid5_conf_t *conf,
                                                "%d for Reconstruct\n", i);
                                        set_bit(R5_LOCKED, &dev->flags);
                                        set_bit(R5_Wantread, &dev->flags);
-                                       if (!test_and_set_bit(
-                                               STRIPE_OP_IO, &sh->ops.pending))
-                                               sh->ops.count++;
                                        s->locked++;
                                } else {
                                        set_bit(STRIPE_DELAYED, &sh->state);
@@ -2261,14 +2141,13 @@ static void handle_issuing_new_write_requests5(raid5_conf_t *conf,
         * simultaneously.  If this is not the case then new writes need to be
         * held off until the compute completes.
         */
-       if ((s->req_compute ||
-           !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending)) &&
-               (s->locked == 0 && (rcw == 0 || rmw == 0) &&
-               !test_bit(STRIPE_BIT_DELAY, &sh->state)))
-               s->locked += handle_write_operations5(sh, rcw == 0, 0);
+       if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) &&
+           (s->locked == 0 && (rcw == 0 || rmw == 0) &&
+           !test_bit(STRIPE_BIT_DELAY, &sh->state)))
+               schedule_reconstruction5(sh, s, rcw == 0, 0);
 }
 
-static void handle_issuing_new_write_requests6(raid5_conf_t *conf,
+static void handle_stripe_dirtying6(raid5_conf_t *conf,
                struct stripe_head *sh, struct stripe_head_state *s,
                struct r6_state *r6s, int disks)
 {
@@ -2371,92 +2250,86 @@ static void handle_issuing_new_write_requests6(raid5_conf_t *conf,
 static void handle_parity_checks5(raid5_conf_t *conf, struct stripe_head *sh,
                                struct stripe_head_state *s, int disks)
 {
-       int canceled_check = 0;
+       struct r5dev *dev = NULL;
 
        set_bit(STRIPE_HANDLE, &sh->state);
 
-       /* complete a check operation */
-       if (test_and_clear_bit(STRIPE_OP_CHECK, &sh->ops.complete)) {
-               clear_bit(STRIPE_OP_CHECK, &sh->ops.ack);
-               clear_bit(STRIPE_OP_CHECK, &sh->ops.pending);
+       switch (sh->check_state) {
+       case check_state_idle:
+               /* start a new check operation if there are no failures */
                if (s->failed == 0) {
-                       if (sh->ops.zero_sum_result == 0)
-                               /* parity is correct (on disc,
-                                * not in buffer any more)
-                                */
-                               set_bit(STRIPE_INSYNC, &sh->state);
-                       else {
-                               conf->mddev->resync_mismatches +=
-                                       STRIPE_SECTORS;
-                               if (test_bit(
-                                    MD_RECOVERY_CHECK, &conf->mddev->recovery))
-                                       /* don't try to repair!! */
-                                       set_bit(STRIPE_INSYNC, &sh->state);
-                               else {
-                                       set_bit(STRIPE_OP_COMPUTE_BLK,
-                                               &sh->ops.pending);
-                                       set_bit(STRIPE_OP_MOD_REPAIR_PD,
-                                               &sh->ops.pending);
-                                       set_bit(R5_Wantcompute,
-                                               &sh->dev[sh->pd_idx].flags);
-                                       sh->ops.target = sh->pd_idx;
-                                       sh->ops.count++;
-                                       s->uptodate++;
-                               }
-                       }
-               } else
-                       canceled_check = 1; /* STRIPE_INSYNC is not set */
-       }
-
-       /* start a new check operation if there are no failures, the stripe is
-        * not insync, and a repair is not in flight
-        */
-       if (s->failed == 0 &&
-           !test_bit(STRIPE_INSYNC, &sh->state) &&
-           !test_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending)) {
-               if (!test_and_set_bit(STRIPE_OP_CHECK, &sh->ops.pending)) {
                        BUG_ON(s->uptodate != disks);
+                       sh->check_state = check_state_run;
+                       set_bit(STRIPE_OP_CHECK, &s->ops_request);
                        clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags);
-                       sh->ops.count++;
                        s->uptodate--;
+                       break;
                }
-       }
-
-       /* check if we can clear a parity disk reconstruct */
-       if (test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete) &&
-           test_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending)) {
-
-               clear_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending);
-               clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.complete);
-               clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.ack);
-               clear_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending);
-       }
-
+               dev = &sh->dev[s->failed_num];
+               /* fall through */
+       case check_state_compute_result:
+               sh->check_state = check_state_idle;
+               if (!dev)
+                       dev = &sh->dev[sh->pd_idx];
+
+               /* check that a write has not made the stripe insync */
+               if (test_bit(STRIPE_INSYNC, &sh->state))
+                       break;
 
-       /* Wait for check parity and compute block operations to complete
-        * before write-back.  If a failure occurred while the check operation
-        * was in flight we need to cycle this stripe through handle_stripe
-        * since the parity block may not be uptodate
-        */
-       if (!canceled_check && !test_bit(STRIPE_INSYNC, &sh->state) &&
-           !test_bit(STRIPE_OP_CHECK, &sh->ops.pending) &&
-           !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending)) {
-               struct r5dev *dev;
                /* either failed parity check, or recovery is happening */
-               if (s->failed == 0)
-                       s->failed_num = sh->pd_idx;
-               dev = &sh->dev[s->failed_num];
                BUG_ON(!test_bit(R5_UPTODATE, &dev->flags));
                BUG_ON(s->uptodate != disks);
 
                set_bit(R5_LOCKED, &dev->flags);
+               s->locked++;
                set_bit(R5_Wantwrite, &dev->flags);
-               if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending))
-                       sh->ops.count++;
 
                clear_bit(STRIPE_DEGRADED, &sh->state);
-               s->locked++;
                set_bit(STRIPE_INSYNC, &sh->state);
+               break;
+       case check_state_run:
+               break; /* we will be called again upon completion */
+       case check_state_check_result:
+               sh->check_state = check_state_idle;
+
+               /* if a failure occurred during the check operation, leave
+                * STRIPE_INSYNC not set and let the stripe be handled again
+                */
+               if (s->failed)
+                       break;
+
+               /* handle a successful check operation, if parity is correct
+                * we are done.  Otherwise update the mismatch count and repair
+                * parity if !MD_RECOVERY_CHECK
+                */
+               if (sh->ops.zero_sum_result == 0)
+                       /* parity is correct (on disc,
+                        * not in buffer any more)
+                        */
+                       set_bit(STRIPE_INSYNC, &sh->state);
+               else {
+                       conf->mddev->resync_mismatches += STRIPE_SECTORS;
+                       if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery))
+                               /* don't try to repair!! */
+                               set_bit(STRIPE_INSYNC, &sh->state);
+                       else {
+                               sh->check_state = check_state_compute_run;
+                               set_bit(STRIPE_COMPUTE_RUN, &sh->state);
+                               set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request);
+                               set_bit(R5_Wantcompute,
+                                       &sh->dev[sh->pd_idx].flags);
+                               sh->ops.target = sh->pd_idx;
+                               s->uptodate++;
+                       }
+               }
+               break;
+       case check_state_compute_run:
+               break;
+       default:
+               printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n",
+                      __func__, sh->check_state,
+                      (unsigned long long) sh->sector);
+               BUG();
        }
 }
 
@@ -2641,15 +2514,14 @@ static void handle_stripe5(struct stripe_head *sh)
        struct bio *return_bi = NULL;
        struct stripe_head_state s;
        struct r5dev *dev;
-       unsigned long pending = 0;
        mdk_rdev_t *blocked_rdev = NULL;
        int prexor;
 
        memset(&s, 0, sizeof(s));
-       pr_debug("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d "
-               "ops=%lx:%lx:%lx\n", (unsigned long long)sh->sector, sh->state,
-               atomic_read(&sh->count), sh->pd_idx,
-               sh->ops.pending, sh->ops.ack, sh->ops.complete);
+       pr_debug("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d check:%d "
+                "reconstruct:%d\n", (unsigned long long)sh->sector, sh->state,
+                atomic_read(&sh->count), sh->pd_idx, sh->check_state,
+                sh->reconstruct_state);
 
        spin_lock(&sh->lock);
        clear_bit(STRIPE_HANDLE, &sh->state);
@@ -2658,15 +2530,8 @@ static void handle_stripe5(struct stripe_head *sh)
        s.syncing = test_bit(STRIPE_SYNCING, &sh->state);
        s.expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state);
        s.expanded = test_bit(STRIPE_EXPAND_READY, &sh->state);
-       /* Now to look around and see what can be done */
-
-       /* clean-up completed biofill operations */
-       if (test_bit(STRIPE_OP_BIOFILL, &sh->ops.complete)) {
-               clear_bit(STRIPE_OP_BIOFILL, &sh->ops.pending);
-               clear_bit(STRIPE_OP_BIOFILL, &sh->ops.ack);
-               clear_bit(STRIPE_OP_BIOFILL, &sh->ops.complete);
-       }
 
+       /* Now to look around and see what can be done */
        rcu_read_lock();
        for (i=disks; i--; ) {
                mdk_rdev_t *rdev;
@@ -2680,10 +2545,10 @@ static void handle_stripe5(struct stripe_head *sh)
                /* maybe we can request a biofill operation
                 *
                 * new wantfill requests are only permitted while
-                * STRIPE_OP_BIOFILL is clear
+                * ops_complete_biofill is guaranteed to be inactive
                 */
                if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread &&
-                       !test_bit(STRIPE_OP_BIOFILL, &sh->ops.pending))
+                   !test_bit(STRIPE_BIOFILL_RUN, &sh->state))
                        set_bit(R5_Wantfill, &dev->flags);
 
                /* now count some things */
@@ -2727,8 +2592,10 @@ static void handle_stripe5(struct stripe_head *sh)
                goto unlock;
        }
 
-       if (s.to_fill && !test_and_set_bit(STRIPE_OP_BIOFILL, &sh->ops.pending))
-               sh->ops.count++;
+       if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) {
+               set_bit(STRIPE_OP_BIOFILL, &s.ops_request);
+               set_bit(STRIPE_BIOFILL_RUN, &sh->state);
+       }
 
        pr_debug("locked=%d uptodate=%d to_read=%d"
                " to_write=%d failed=%d failed_num=%d\n",
@@ -2738,8 +2605,7 @@ static void handle_stripe5(struct stripe_head *sh)
         * need to be failed
         */
        if (s.failed > 1 && s.to_read+s.to_write+s.written)
-               handle_requests_to_failed_array(conf, sh, &s, disks,
-                                               &return_bi);
+               handle_failed_stripe(conf, sh, &s, disks, &return_bi);
        if (s.failed > 1 && s.syncing) {
                md_done_sync(conf->mddev, STRIPE_SECTORS,0);
                clear_bit(STRIPE_SYNCING, &sh->state);
@@ -2755,48 +2621,25 @@ static void handle_stripe5(struct stripe_head *sh)
               !test_bit(R5_LOCKED, &dev->flags) &&
               test_bit(R5_UPTODATE, &dev->flags)) ||
               (s.failed == 1 && s.failed_num == sh->pd_idx)))
-               handle_completed_write_requests(conf, sh, disks, &return_bi);
+               handle_stripe_clean_event(conf, sh, disks, &return_bi);
 
        /* Now we might consider reading some blocks, either to check/generate
         * parity, or to satisfy requests
         * or to load a block that is being partially written.
         */
        if (s.to_read || s.non_overwrite ||
-           (s.syncing && (s.uptodate + s.compute < disks)) || s.expanding ||
-           test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending))
-               handle_issuing_new_read_requests5(sh, &s, disks);
+           (s.syncing && (s.uptodate + s.compute < disks)) || s.expanding)
+               handle_stripe_fill5(sh, &s, disks);
 
        /* Now we check to see if any write operations have recently
         * completed
         */
-
-       /* leave prexor set until postxor is done, allows us to distinguish
-        * a rmw from a rcw during biodrain
-        */
        prexor = 0;
-       if (test_bit(STRIPE_OP_PREXOR, &sh->ops.complete) &&
-               test_bit(STRIPE_OP_POSTXOR, &sh->ops.complete)) {
-
+       if (sh->reconstruct_state == reconstruct_state_prexor_drain_result)
                prexor = 1;
-               clear_bit(STRIPE_OP_PREXOR, &sh->ops.complete);
-               clear_bit(STRIPE_OP_PREXOR, &sh->ops.ack);
-               clear_bit(STRIPE_OP_PREXOR, &sh->ops.pending);
-
-               for (i = disks; i--; )
-                       clear_bit(R5_Wantprexor, &sh->dev[i].flags);
-       }
-
-       /* if only POSTXOR is set then this is an 'expand' postxor */
-       if (test_bit(STRIPE_OP_BIODRAIN, &sh->ops.complete) &&
-               test_bit(STRIPE_OP_POSTXOR, &sh->ops.complete)) {
-
-               clear_bit(STRIPE_OP_BIODRAIN, &sh->ops.complete);
-               clear_bit(STRIPE_OP_BIODRAIN, &sh->ops.ack);
-               clear_bit(STRIPE_OP_BIODRAIN, &sh->ops.pending);
-
-               clear_bit(STRIPE_OP_POSTXOR, &sh->ops.complete);
-               clear_bit(STRIPE_OP_POSTXOR, &sh->ops.ack);
-               clear_bit(STRIPE_OP_POSTXOR, &sh->ops.pending);
+       if (sh->reconstruct_state == reconstruct_state_drain_result ||
+           sh->reconstruct_state == reconstruct_state_prexor_drain_result) {
+               sh->reconstruct_state = reconstruct_state_idle;
 
                /* All the 'written' buffers and the parity block are ready to
                 * be written back to disk
@@ -2808,9 +2651,6 @@ static void handle_stripe5(struct stripe_head *sh)
                                (i == sh->pd_idx || dev->written)) {
                                pr_debug("Writing block %d\n", i);
                                set_bit(R5_Wantwrite, &dev->flags);
-                               if (!test_and_set_bit(
-                                   STRIPE_OP_IO, &sh->ops.pending))
-                                       sh->ops.count++;
                                if (prexor)
                                        continue;
                                if (!test_bit(R5_Insync, &dev->flags) ||
@@ -2832,20 +2672,18 @@ static void handle_stripe5(struct stripe_head *sh)
         * 2/ A 'check' operation is in flight, as it may clobber the parity
         *    block.
         */
-       if (s.to_write && !test_bit(STRIPE_OP_POSTXOR, &sh->ops.pending) &&
-                         !test_bit(STRIPE_OP_CHECK, &sh->ops.pending))
-               handle_issuing_new_write_requests5(conf, sh, &s, disks);
+       if (s.to_write && !sh->reconstruct_state && !sh->check_state)
+               handle_stripe_dirtying5(conf, sh, &s, disks);
 
        /* maybe we need to check and possibly fix the parity for this stripe
         * Any reads will already have been scheduled, so we just see if enough
         * data is available.  The parity check is held off while parity
         * dependent operations are in flight.
         */
-       if ((s.syncing && s.locked == 0 &&
-            !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending) &&
-            !test_bit(STRIPE_INSYNC, &sh->state)) ||
-             test_bit(STRIPE_OP_CHECK, &sh->ops.pending) ||
-             test_bit(STRIPE_OP_MOD_REPAIR_PD, &sh->ops.pending))
+       if (sh->check_state ||
+           (s.syncing && s.locked == 0 &&
+            !test_bit(STRIPE_COMPUTE_RUN, &sh->state) &&
+            !test_bit(STRIPE_INSYNC, &sh->state)))
                handle_parity_checks5(conf, sh, &s, disks);
 
        if (s.syncing && s.locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) {
@@ -2864,52 +2702,35 @@ static void handle_stripe5(struct stripe_head *sh)
                dev = &sh->dev[s.failed_num];
                if (!test_bit(R5_ReWrite, &dev->flags)) {
                        set_bit(R5_Wantwrite, &dev->flags);
-                       if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending))
-                               sh->ops.count++;
                        set_bit(R5_ReWrite, &dev->flags);
                        set_bit(R5_LOCKED, &dev->flags);
                        s.locked++;
                } else {
                        /* let's read it back */
                        set_bit(R5_Wantread, &dev->flags);
-                       if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending))
-                               sh->ops.count++;
                        set_bit(R5_LOCKED, &dev->flags);
                        s.locked++;
                }
        }
 
-       /* Finish postxor operations initiated by the expansion
-        * process
-        */
-       if (test_bit(STRIPE_OP_POSTXOR, &sh->ops.complete) &&
-               !test_bit(STRIPE_OP_BIODRAIN, &sh->ops.pending)) {
-
+       /* Finish reconstruct operations initiated by the expansion process */
+       if (sh->reconstruct_state == reconstruct_state_result) {
+               sh->reconstruct_state = reconstruct_state_idle;
                clear_bit(STRIPE_EXPANDING, &sh->state);
-
-               clear_bit(STRIPE_OP_POSTXOR, &sh->ops.pending);
-               clear_bit(STRIPE_OP_POSTXOR, &sh->ops.ack);
-               clear_bit(STRIPE_OP_POSTXOR, &sh->ops.complete);
-
-               for (i = conf->raid_disks; i--; ) {
+               for (i = conf->raid_disks; i--; )
                        set_bit(R5_Wantwrite, &sh->dev[i].flags);
                        set_bit(R5_LOCKED, &dev->flags);
                        s.locked++;
-                       if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending))
-                               sh->ops.count++;
-               }
        }
 
        if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) &&
-               !test_bit(STRIPE_OP_POSTXOR, &sh->ops.pending)) {
+           !sh->reconstruct_state) {
                /* Need to write out all blocks after computing parity */
                sh->disks = conf->raid_disks;
                sh->pd_idx = stripe_to_pdidx(sh->sector, conf,
                        conf->raid_disks);
-               s.locked += handle_write_operations5(sh, 1, 1);
-       } else if (s.expanded &&
-                  s.locked == 0 &&
-               !test_bit(STRIPE_OP_POSTXOR, &sh->ops.pending)) {
+               schedule_reconstruction5(sh, &s, 1, 1);
+       } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) {
                clear_bit(STRIPE_EXPAND_READY, &sh->state);
                atomic_dec(&conf->reshape_stripes);
                wake_up(&conf->wait_for_overlap);
@@ -2917,12 +2738,9 @@ static void handle_stripe5(struct stripe_head *sh)
        }
 
        if (s.expanding && s.locked == 0 &&
-           !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending))
+           !test_bit(STRIPE_COMPUTE_RUN, &sh->state))
                handle_stripe_expansion(conf, sh, NULL);
 
-       if (sh->ops.count)
-               pending = get_stripe_work(sh);
-
  unlock:
        spin_unlock(&sh->lock);
 
@@ -2930,11 +2748,12 @@ static void handle_stripe5(struct stripe_head *sh)
        if (unlikely(blocked_rdev))
                md_wait_for_blocked_rdev(blocked_rdev, conf->mddev);
 
-       if (pending)
-               raid5_run_ops(sh, pending);
+       if (s.ops_request)
+               raid5_run_ops(sh, s.ops_request);
 
-       return_io(return_bi);
+       ops_run_io(sh, &s);
 
+       return_io(return_bi);
 }
 
 static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
@@ -3042,8 +2861,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
         * might need to be failed
         */
        if (s.failed > 2 && s.to_read+s.to_write+s.written)
-               handle_requests_to_failed_array(conf, sh, &s, disks,
-                                               &return_bi);
+               handle_failed_stripe(conf, sh, &s, disks, &return_bi);
        if (s.failed > 2 && s.syncing) {
                md_done_sync(conf->mddev, STRIPE_SECTORS,0);
                clear_bit(STRIPE_SYNCING, &sh->state);
@@ -3068,7 +2886,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
             ( r6s.q_failed || ((test_bit(R5_Insync, &qdev->flags)
                             && !test_bit(R5_LOCKED, &qdev->flags)
                             && test_bit(R5_UPTODATE, &qdev->flags)))))
-               handle_completed_write_requests(conf, sh, disks, &return_bi);
+               handle_stripe_clean_event(conf, sh, disks, &return_bi);
 
        /* Now we might consider reading some blocks, either to check/generate
         * parity, or to satisfy requests
@@ -3076,11 +2894,11 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
         */
        if (s.to_read || s.non_overwrite || (s.to_write && s.failed) ||
            (s.syncing && (s.uptodate < disks)) || s.expanding)
-               handle_issuing_new_read_requests6(sh, &s, &r6s, disks);
+               handle_stripe_fill6(sh, &s, &r6s, disks);
 
        /* now to consider writing and what else, if anything should be read */
        if (s.to_write)
-               handle_issuing_new_write_requests6(conf, sh, &s, &r6s, disks);
+               handle_stripe_dirtying6(conf, sh, &s, &r6s, disks);
 
        /* maybe we need to check and possibly fix the parity for this stripe
         * Any reads will already have been scheduled, so we just see if enough
@@ -3136,7 +2954,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
        }
 
        if (s.expanding && s.locked == 0 &&
-           !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending))
+           !test_bit(STRIPE_COMPUTE_RUN, &sh->state))
                handle_stripe_expansion(conf, sh, &r6s);
 
  unlock:
@@ -3146,68 +2964,9 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
        if (unlikely(blocked_rdev))
                md_wait_for_blocked_rdev(blocked_rdev, conf->mddev);
 
-       return_io(return_bi);
-
-       for (i=disks; i-- ;) {
-               int rw;
-               struct bio *bi;
-               mdk_rdev_t *rdev;
-               if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags))
-                       rw = WRITE;
-               else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags))
-                       rw = READ;
-               else
-                       continue;
-
-               set_bit(STRIPE_IO_STARTED, &sh->state);
-
-               bi = &sh->dev[i].req;
-
-               bi->bi_rw = rw;
-               if (rw == WRITE)
-                       bi->bi_end_io = raid5_end_write_request;
-               else
-                       bi->bi_end_io = raid5_end_read_request;
-
-               rcu_read_lock();
-               rdev = rcu_dereference(conf->disks[i].rdev);
-               if (rdev && test_bit(Faulty, &rdev->flags))
-                       rdev = NULL;
-               if (rdev)
-                       atomic_inc(&rdev->nr_pending);
-               rcu_read_unlock();
+       ops_run_io(sh, &s);
 
-               if (rdev) {
-                       if (s.syncing || s.expanding || s.expanded)
-                               md_sync_acct(rdev->bdev, STRIPE_SECTORS);
-
-                       bi->bi_bdev = rdev->bdev;
-                       pr_debug("for %llu schedule op %ld on disc %d\n",
-                               (unsigned long long)sh->sector, bi->bi_rw, i);
-                       atomic_inc(&sh->count);
-                       bi->bi_sector = sh->sector + rdev->data_offset;
-                       bi->bi_flags = 1 << BIO_UPTODATE;
-                       bi->bi_vcnt = 1;
-                       bi->bi_max_vecs = 1;
-                       bi->bi_idx = 0;
-                       bi->bi_io_vec = &sh->dev[i].vec;
-                       bi->bi_io_vec[0].bv_len = STRIPE_SIZE;
-                       bi->bi_io_vec[0].bv_offset = 0;
-                       bi->bi_size = STRIPE_SIZE;
-                       bi->bi_next = NULL;
-                       if (rw == WRITE &&
-                           test_bit(R5_ReWrite, &sh->dev[i].flags))
-                               atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
-                       generic_make_request(bi);
-               } else {
-                       if (rw == WRITE)
-                               set_bit(STRIPE_DEGRADED, &sh->state);
-                       pr_debug("skip op %ld on disc %d for sector %llu\n",
-                               bi->bi_rw, i, (unsigned long long)sh->sector);
-                       clear_bit(R5_LOCKED, &sh->dev[i].flags);
-                       set_bit(STRIPE_HANDLE, &sh->state);
-               }
-       }
+       return_io(return_bi);
 }
 
 static void handle_stripe(struct stripe_head *sh, struct page *tmp_page)
@@ -3695,9 +3454,7 @@ static int make_request(struct request_queue *q, struct bio * bi)
                if ( rw == WRITE )
                        md_write_end(mddev);
 
-               bi->bi_end_io(bi,
-                             test_bit(BIO_UPTODATE, &bi->bi_flags)
-                               ? 0 : -EIO);
+               bio_endio(bi, 0);
        }
        return 0;
 }
@@ -4000,12 +3757,8 @@ static int  retry_aligned_read(raid5_conf_t *conf, struct bio *raid_bio)
        spin_lock_irq(&conf->device_lock);
        remaining = --raid_bio->bi_phys_segments;
        spin_unlock_irq(&conf->device_lock);
-       if (remaining == 0) {
-
-               raid_bio->bi_end_io(raid_bio,
-                             test_bit(BIO_UPTODATE, &raid_bio->bi_flags)
-                               ? 0 : -EIO);
-       }
+       if (remaining == 0)
+               bio_endio(raid_bio, 0);
        if (atomic_dec_and_test(&conf->active_aligned_reads))
                wake_up(&conf->wait_for_stripe);
        return handled;
@@ -4092,6 +3845,8 @@ raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
 {
        raid5_conf_t *conf = mddev_to_conf(mddev);
        unsigned long new;
+       int err;
+
        if (len >= PAGE_SIZE)
                return -EINVAL;
        if (!conf)
@@ -4107,7 +3862,9 @@ raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
                else
                        break;
        }
-       md_allow_write(mddev);
+       err = md_allow_write(mddev);
+       if (err)
+               return err;
        while (new > conf->max_nr_stripes) {
                if (grow_one_stripe(conf))
                        conf->max_nr_stripes++;
@@ -4607,35 +4364,41 @@ abort:
 static int raid5_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
 {
        raid5_conf_t *conf = mddev->private;
-       int found = 0;
+       int err = -EEXIST;
        int disk;
        struct disk_info *p;
+       int first = 0;
+       int last = conf->raid_disks - 1;
 
        if (mddev->degraded > conf->max_degraded)
                /* no point adding a device */
-               return 0;
+               return -EINVAL;
+
+       if (rdev->raid_disk >= 0)
+               first = last = rdev->raid_disk;
 
        /*
         * find the disk ... but prefer rdev->saved_raid_disk
         * if possible.
         */
        if (rdev->saved_raid_disk >= 0 &&
+           rdev->saved_raid_disk >= first &&
            conf->disks[rdev->saved_raid_disk].rdev == NULL)
                disk = rdev->saved_raid_disk;
        else
-               disk = 0;
-       for ( ; disk < conf->raid_disks; disk++)
+               disk = first;
+       for ( ; disk <= last ; disk++)
                if ((p=conf->disks + disk)->rdev == NULL) {
                        clear_bit(In_sync, &rdev->flags);
                        rdev->raid_disk = disk;
-                       found = 1;
+                       err = 0;
                        if (rdev->saved_raid_disk != disk)
                                conf->fullsync = 1;
                        rcu_assign_pointer(p->rdev, rdev);
                        break;
                }
        print_raid5_conf(conf);
-       return found;
+       return err;
 }
 
 static int raid5_resize(mddev_t *mddev, sector_t sectors)
@@ -4736,7 +4499,7 @@ static int raid5_start_reshape(mddev_t *mddev)
        rdev_for_each(rdev, rtmp, mddev)
                if (rdev->raid_disk < 0 &&
                    !test_bit(Faulty, &rdev->flags)) {
-                       if (raid5_add_disk(mddev, rdev)) {
+                       if (raid5_add_disk(mddev, rdev) == 0) {
                                char nm[20];
                                set_bit(In_sync, &rdev->flags);
                                added_devices++;
index a3485817e46c9e06b765bda262fdd9f8215b7168..8fa91f846d591bcd35d544d87aec42edbbfc5b96 100644 (file)
@@ -2201,3 +2201,41 @@ IR_KEYTAB_TYPE ir_codes_powercolor_real_angel[IR_KEYTAB_SIZE] = {
        [0x25] = KEY_POWER,             /* power */
 };
 EXPORT_SYMBOL_GPL(ir_codes_powercolor_real_angel);
+
+IR_KEYTAB_TYPE ir_codes_avermedia_a16d[IR_KEYTAB_SIZE] = {
+       [0x20] = KEY_LIST,
+       [0x00] = KEY_POWER,
+       [0x28] = KEY_1,
+       [0x18] = KEY_2,
+       [0x38] = KEY_3,
+       [0x24] = KEY_4,
+       [0x14] = KEY_5,
+       [0x34] = KEY_6,
+       [0x2c] = KEY_7,
+       [0x1c] = KEY_8,
+       [0x3c] = KEY_9,
+       [0x12] = KEY_SUBTITLE,
+       [0x22] = KEY_0,
+       [0x32] = KEY_REWIND,
+       [0x3a] = KEY_SHUFFLE,
+       [0x02] = KEY_PRINT,
+       [0x11] = KEY_CHANNELDOWN,
+       [0x31] = KEY_CHANNELUP,
+       [0x0c] = KEY_ZOOM,
+       [0x1e] = KEY_VOLUMEDOWN,
+       [0x3e] = KEY_VOLUMEUP,
+       [0x0a] = KEY_MUTE,
+       [0x04] = KEY_AUDIO,
+       [0x26] = KEY_RECORD,
+       [0x06] = KEY_PLAY,
+       [0x36] = KEY_STOP,
+       [0x16] = KEY_PAUSE,
+       [0x2e] = KEY_REWIND,
+       [0x0e] = KEY_FASTFORWARD,
+       [0x30] = KEY_TEXT,
+       [0x21] = KEY_GREEN,
+       [0x01] = KEY_BLUE,
+       [0x08] = KEY_EPG,
+       [0x2a] = KEY_MENU,
+};
+EXPORT_SYMBOL_GPL(ir_codes_avermedia_a16d);
index f1894fec32b930343d69f0665a698ed267b8e731..6fb5b45865690b3a4279e891d09cf43e222a7dee 100644 (file)
@@ -649,9 +649,17 @@ int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq)
        u8 val;
 
        int ret = tda18271_lookup_map(fe, RF_CAL, freq, &val);
+       /* The TDA18271HD/C1 rf_cal map lookup is expected to go out of range
+        * for frequencies above 61.1 MHz.  In these cases, the internal RF
+        * tracking filters calibration mechanism is used.
+        *
+        * There is no need to warn the user about this.
+        */
+       if (ret < 0)
+               goto fail;
 
        regs[R_EB14] = val;
-
+fail:
        return ret;
 }
 
index 89c01fb1f85981c5cbfa909e1579c2f75212cf07..93063c6fbbf634e42aac29b3502de2b66104e232 100644 (file)
@@ -45,6 +45,21 @@ static inline int charge_pump_source(struct dvb_frontend *fe, int force)
                                           TDA18271_MAIN_PLL, force);
 }
 
+static inline void tda18271_set_if_notch(struct dvb_frontend *fe)
+{
+       struct tda18271_priv *priv = fe->tuner_priv;
+       unsigned char *regs = priv->tda18271_regs;
+
+       switch (priv->mode) {
+       case TDA18271_ANALOG:
+               regs[R_MPD]  &= ~0x80; /* IF notch = 0 */
+               break;
+       case TDA18271_DIGITAL:
+               regs[R_MPD]  |= 0x80; /* IF notch = 1 */
+               break;
+       }
+}
+
 static int tda18271_channel_configuration(struct dvb_frontend *fe,
                                          struct tda18271_std_map_item *map,
                                          u32 freq, u32 bw)
@@ -60,25 +75,18 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
        regs[R_EP3]  &= ~0x1f; /* clear std bits */
        regs[R_EP3]  |= (map->agc_mode << 3) | map->std;
 
-       /* set rfagc to high speed mode */
-       regs[R_EP3] &= ~0x04;
+       if (priv->id == TDA18271HDC2) {
+               /* set rfagc to high speed mode */
+               regs[R_EP3] &= ~0x04;
+       }
 
        /* set cal mode to normal */
        regs[R_EP4]  &= ~0x03;
 
-       /* update IF output level & IF notch frequency */
+       /* update IF output level */
        regs[R_EP4]  &= ~0x1c; /* clear if level bits */
        regs[R_EP4]  |= (map->if_lvl << 2);
 
-       switch (priv->mode) {
-       case TDA18271_ANALOG:
-               regs[R_MPD]  &= ~0x80; /* IF notch = 0 */
-               break;
-       case TDA18271_DIGITAL:
-               regs[R_MPD]  |= 0x80; /* IF notch = 1 */
-               break;
-       }
-
        /* update FM_RFn */
        regs[R_EP4]  &= ~0x80;
        regs[R_EP4]  |= map->fm_rfn << 7;
@@ -95,6 +103,9 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
        /* disable Power Level Indicator */
        regs[R_EP1]  |= 0x40;
 
+       /* make sure thermometer is off */
+       regs[R_TM]   &= ~0x10;
+
        /* frequency dependent parameters */
 
        tda18271_calc_ir_measure(fe, &freq);
@@ -135,6 +146,7 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
        switch (priv->role) {
        case TDA18271_MASTER:
                tda18271_calc_main_pll(fe, N);
+               tda18271_set_if_notch(fe);
                tda18271_write_regs(fe, R_MPD, 4);
                break;
        case TDA18271_SLAVE:
@@ -142,6 +154,7 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
                tda18271_write_regs(fe, R_CPD, 4);
 
                regs[R_MPD] = regs[R_CPD] & 0x7f;
+               tda18271_set_if_notch(fe);
                tda18271_write_regs(fe, R_MPD, 1);
                break;
        }
@@ -160,12 +173,14 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
 
        msleep(20);
 
-       /* set rfagc to normal speed mode */
-       if (map->fm_rfn)
-               regs[R_EP3] &= ~0x04;
-       else
-               regs[R_EP3] |= 0x04;
-       ret = tda18271_write_regs(fe, R_EP3, 1);
+       if (priv->id == TDA18271HDC2) {
+               /* set rfagc to normal speed mode */
+               if (map->fm_rfn)
+                       regs[R_EP3] &= ~0x04;
+               else
+                       regs[R_EP3] |= 0x04;
+               ret = tda18271_write_regs(fe, R_EP3, 1);
+       }
 fail:
        return ret;
 }
@@ -507,7 +522,7 @@ static int tda18271_powerscan_init(struct dvb_frontend *fe)
        /* set cal mode to normal */
        regs[R_EP4]  &= ~0x03;
 
-       /* update IF output level & IF notch frequency */
+       /* update IF output level */
        regs[R_EP4]  &= ~0x1c; /* clear if level bits */
 
        ret = tda18271_write_regs(fe, R_EP3, 2);
index ceae6db901ecaa9543f5e4ef4bcd727e3d10cc42..7cf4f5bdb2ecef54de97f6af81407bb098964932 100644 (file)
@@ -177,6 +177,7 @@ static XC_TV_STANDARD XC5000_Standard[MAX_TV_STANDARD] = {
        {"FM Radio-INPUT1",   0x0208, 0x9002}
 };
 
+static int  xc5000_is_firmware_loaded(struct dvb_frontend *fe);
 static int  xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len);
 static int  xc5000_readregs(struct xc5000_priv *priv, u8 *buf, u8 len);
 static void xc5000_TunerReset(struct dvb_frontend *fe);
@@ -352,7 +353,7 @@ static int xc_SetTVStandard(struct xc5000_priv *priv,
 
 static int xc_shutdown(struct xc5000_priv *priv)
 {
-       return 0;
+       return XC_RESULT_SUCCESS;
        /* Fixme: cannot bring tuner back alive once shutdown
         *        without reloading the driver modules.
         *    return xc_write_reg(priv, XREG_POWER_DOWN, 0);
@@ -685,6 +686,25 @@ static int xc5000_set_params(struct dvb_frontend *fe,
        return 0;
 }
 
+static int xc5000_is_firmware_loaded(struct dvb_frontend *fe)
+{
+       struct xc5000_priv *priv = fe->tuner_priv;
+       int ret;
+       u16 id;
+
+       ret = xc5000_readreg(priv, XREG_PRODUCT_ID, &id);
+       if (ret == XC_RESULT_SUCCESS) {
+               if (id == XC_PRODUCT_ID_FW_NOT_LOADED)
+                       ret = XC_RESULT_RESET_FAILURE;
+               else
+                       ret = XC_RESULT_SUCCESS;
+       }
+
+       dprintk(1, "%s() returns %s id = 0x%x\n", __func__,
+               ret == XC_RESULT_SUCCESS ? "True" : "False", id);
+       return ret;
+}
+
 static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe);
 
 static int xc5000_set_analog_params(struct dvb_frontend *fe,
@@ -693,7 +713,7 @@ static int xc5000_set_analog_params(struct dvb_frontend *fe,
        struct xc5000_priv *priv = fe->tuner_priv;
        int ret;
 
-       if(priv->fwloaded == 0)
+       if (xc5000_is_firmware_loaded(fe) != XC_RESULT_SUCCESS)
                xc_load_fw_and_init_tuner(fe);
 
        dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n",
@@ -808,11 +828,10 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe)
        struct xc5000_priv *priv = fe->tuner_priv;
        int ret = 0;
 
-       if (priv->fwloaded == 0) {
+       if (xc5000_is_firmware_loaded(fe) != XC_RESULT_SUCCESS) {
                ret = xc5000_fwupload(fe);
                if (ret != XC_RESULT_SUCCESS)
                        return ret;
-               priv->fwloaded = 1;
        }
 
        /* Start the tuner self-calibration process */
@@ -852,7 +871,6 @@ static int xc5000_sleep(struct dvb_frontend *fe)
                return -EREMOTEIO;
        }
        else {
-               /* priv->fwloaded = 0; */
                return XC_RESULT_SUCCESS;
        }
 }
@@ -933,7 +951,6 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
                        cfg->i2c_address);
                printk(KERN_INFO
                        "xc5000: Firmware has been loaded previously\n");
-               priv->fwloaded = 1;
                break;
        case XC_PRODUCT_ID_FW_NOT_LOADED:
                printk(KERN_INFO
@@ -941,7 +958,6 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
                        cfg->i2c_address);
                printk(KERN_INFO
                        "xc5000: Firmware has not been loaded previously\n");
-               priv->fwloaded = 0;
                break;
        default:
                printk(KERN_ERR
index ecebfe4745adcadf30e3f2a82d31b00c3b21210e..a72a9887fe7ffeab488da51193be130ba7d98767 100644 (file)
@@ -30,7 +30,6 @@ struct xc5000_priv {
        u32 bandwidth;
        u8  video_standard;
        u8  rf_mode;
-       u8  fwloaded;
 
        void *devptr;
 };
index 0a8ac64a4e33a6a345cd6eea538b7397a33c6536..037f7ffb47b297e6696fd167b8849143cac654f6 100644 (file)
@@ -47,6 +47,8 @@ static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
                return -EINVAL;
        }
 
+       msleep(1); /* avoid I2C errors */
+
        return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
                               value, index, rbuf, rlen, 2000);
 }
@@ -92,16 +94,6 @@ static struct i2c_algorithm gl861_i2c_algo = {
 };
 
 /* Callbacks for DVB USB */
-static int gl861_identify_state(struct usb_device *udev,
-                               struct dvb_usb_device_properties *props,
-                               struct dvb_usb_device_description **desc,
-                               int *cold)
-{
-       *cold = 0;
-
-       return 0;
-}
-
 static struct zl10353_config gl861_zl10353_config = {
        .demod_address = 0x0f,
        .no_tuner = 1,
@@ -172,7 +164,6 @@ static struct dvb_usb_device_properties gl861_properties = {
 
        .size_of_priv     = 0,
 
-       .identify_state   = gl861_identify_state,
        .num_adapters = 1,
        .adapter = {{
 
@@ -194,13 +185,15 @@ static struct dvb_usb_device_properties gl861_properties = {
 
        .num_device_descs = 2,
        .devices = {
-               {   "MSI Mega Sky 55801 DVB-T USB2.0",
-                       { &gl861_table[0], NULL },
-                       { NULL },
+               {
+                       .name = "MSI Mega Sky 55801 DVB-T USB2.0",
+                       .cold_ids = { NULL },
+                       .warm_ids = { &gl861_table[0], NULL },
                },
-               {   "A-LINK DTU DVB-T USB2.0",
-                       { &gl861_table[1], NULL },
-                       { NULL },
+               {
+                       .name = "A-LINK DTU DVB-T USB2.0",
+                       .cold_ids = { NULL },
+                       .warm_ids = { &gl861_table[1], NULL },
                },
        }
 };
index 9e7653bb3b660bc4c44985db551cf94e0f65ee5e..118aab1a3e540943e7a325f5836999e4c4819d5f 100644 (file)
@@ -107,7 +107,7 @@ static struct dvb_usb_device_properties umt_properties = {
                        /* parameter for the MPEG2-data transfer */
                        .stream = {
                                .type = USB_BULK,
-                               .count = 20,
+                               .count = MAX_NO_URBS_FOR_DATA_STREAM,
                                .endpoint = 0x06,
                                .u = {
                                        .bulk = {
index 084a280c2d7f97cbf6835e1f6e5bf73cf363f8d3..03900d241a76da067545aaba61916d4c88385291 100644 (file)
@@ -463,10 +463,13 @@ static int au8522_set_frontend(struct dvb_frontend *fe,
                               struct dvb_frontend_parameters *p)
 {
        struct au8522_state *state = fe->demodulator_priv;
+       int ret = -EINVAL;
 
        dprintk("%s(frequency=%d)\n", __func__, p->frequency);
 
-       state->current_frequency = p->frequency;
+       if ((state->current_frequency == p->frequency) &&
+           (state->current_modulation == p->u.vsb.modulation))
+               return 0;
 
        au8522_enable_modulation(fe, p->u.vsb.modulation);
 
@@ -476,11 +479,16 @@ static int au8522_set_frontend(struct dvb_frontend *fe,
        if (fe->ops.tuner_ops.set_params) {
                if (fe->ops.i2c_gate_ctrl)
                        fe->ops.i2c_gate_ctrl(fe, 1);
-               fe->ops.tuner_ops.set_params(fe, p);
+               ret = fe->ops.tuner_ops.set_params(fe, p);
                if (fe->ops.i2c_gate_ctrl)
                        fe->ops.i2c_gate_ctrl(fe, 0);
        }
 
+       if (ret < 0)
+               return ret;
+
+       state->current_frequency = p->frequency;
+
        return 0;
 }
 
@@ -498,6 +506,16 @@ static int au8522_init(struct dvb_frontend *fe)
        return 0;
 }
 
+static int au8522_sleep(struct dvb_frontend *fe)
+{
+       struct au8522_state *state = fe->demodulator_priv;
+       dprintk("%s()\n", __func__);
+
+       state->current_frequency = 0;
+
+       return 0;
+}
+
 static int au8522_read_status(struct dvb_frontend *fe, fe_status_t *status)
 {
        struct au8522_state *state = fe->demodulator_priv;
@@ -509,10 +527,8 @@ static int au8522_read_status(struct dvb_frontend *fe, fe_status_t *status)
        if (state->current_modulation == VSB_8) {
                dprintk("%s() Checking VSB_8\n", __func__);
                reg = au8522_readreg(state, 0x4088);
-               if (reg & 0x01)
-                       *status |= FE_HAS_VITERBI;
-               if (reg & 0x02)
-                       *status |= FE_HAS_LOCK | FE_HAS_SYNC;
+               if ((reg & 0x03) == 0x03)
+                       *status |= FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI;
        } else {
                dprintk("%s() Checking QAM\n", __func__);
                reg = au8522_readreg(state, 0x4541);
@@ -672,6 +688,7 @@ static struct dvb_frontend_ops au8522_ops = {
        },
 
        .init                 = au8522_init,
+       .sleep                = au8522_sleep,
        .i2c_gate_ctrl        = au8522_i2c_gate_ctrl,
        .set_frontend         = au8522_set_frontend,
        .get_frontend         = au8522_get_frontend,
index 17556183e871629c2ae4fabc116c598ce233ea70..35435bef8e7992af4e1e8648a8c408b0f2d62f18 100644 (file)
@@ -63,6 +63,7 @@ struct stv0299_state {
        u32 symbol_rate;
        fe_code_rate_t fec_inner;
        int errmode;
+       u32 ucblocks;
 };
 
 #define STATUS_BER 0
@@ -501,8 +502,10 @@ static int stv0299_read_ber(struct dvb_frontend* fe, u32* ber)
 {
        struct stv0299_state* state = fe->demodulator_priv;
 
-       if (state->errmode != STATUS_BER) return 0;
-       *ber = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e);
+       if (state->errmode != STATUS_BER)
+               return -ENOSYS;
+
+       *ber = stv0299_readreg(state, 0x1e) | (stv0299_readreg(state, 0x1d) << 8);
 
        return 0;
 }
@@ -540,8 +543,12 @@ static int stv0299_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
 {
        struct stv0299_state* state = fe->demodulator_priv;
 
-       if (state->errmode != STATUS_UCBLOCKS) *ucblocks = 0;
-       else *ucblocks = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e);
+       if (state->errmode != STATUS_UCBLOCKS)
+               return -ENOSYS;
+
+       state->ucblocks += stv0299_readreg(state, 0x1e);
+       state->ucblocks += (stv0299_readreg(state, 0x1d) << 8);
+       *ucblocks = state->ucblocks;
 
        return 0;
 }
index 0727b80bc4d296a83f56317b9266fdbac705f562..c6ff5b82ff80d481e58151cbe47ee336fe76868d 100644 (file)
@@ -116,9 +116,12 @@ static u8 tda10023_readreg (struct tda10023_state* state, u8 reg)
        int ret;
 
        ret = i2c_transfer (state->i2c, msg, 2);
-       if (ret != 2)
-               printk("DVB: TDA10023: %s: readreg error (ret == %i)\n",
-                                __func__, ret);
+       if (ret != 2) {
+               int num = state->frontend.dvb ? state->frontend.dvb->num : -1;
+               printk(KERN_ERR "DVB: TDA10023(%d): %s: readreg error "
+                       "(reg == 0x%02x, ret == %i)\n",
+                       num, __func__, reg, ret);
+       }
        return b1[0];
 }
 
@@ -129,11 +132,12 @@ static int tda10023_writereg (struct tda10023_state* state, u8 reg, u8 data)
        int ret;
 
        ret = i2c_transfer (state->i2c, &msg, 1);
-       if (ret != 1)
-               printk("DVB: TDA10023(%d): %s, writereg error "
+       if (ret != 1) {
+               int num = state->frontend.dvb ? state->frontend.dvb->num : -1;
+               printk(KERN_ERR "DVB: TDA10023(%d): %s, writereg error "
                        "(reg == 0x%02x, val == 0x%02x, ret == %i)\n",
-                       state->frontend.dvb->num, __func__, reg, data, ret);
-
+                       num, __func__, reg, data, ret);
+       }
        return (ret != 1) ? -EREMOTEIO : 0;
 }
 
@@ -464,7 +468,7 @@ struct dvb_frontend* tda10023_attach(const struct tda1002x_config* config,
        int i;
 
        /* allocate memory for the internal state */
-       state = kmalloc(sizeof(struct tda10023_state), GFP_KERNEL);
+       state = kzalloc(sizeof(struct tda10023_state), GFP_KERNEL);
        if (state == NULL) goto error;
 
        /* setup the state */
index 49973846373e843b5fc4d64e6aa97b14922f3a45..a0d6386535673223f557c8d068e233e9a900a239 100644 (file)
@@ -1248,11 +1248,14 @@ struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
                                     struct i2c_adapter* i2c)
 {
        struct tda1004x_state *state;
+       int id;
 
        /* allocate memory for the internal state */
        state = kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL);
-       if (!state)
+       if (!state) {
+               printk(KERN_ERR "Can't alocate memory for tda10045 state\n");
                return NULL;
+       }
 
        /* setup the state */
        state->config = config;
@@ -1260,7 +1263,15 @@ struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
        state->demod_type = TDA1004X_DEMOD_TDA10045;
 
        /* check if the demod is there */
-       if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x25) {
+       id = tda1004x_read_byte(state, TDA1004X_CHIPID);
+       if (id < 0) {
+               printk(KERN_ERR "tda10045: chip is not answering. Giving up.\n");
+               kfree(state);
+               return NULL;
+       }
+
+       if (id != 0x25) {
+               printk(KERN_ERR "Invalid tda1004x ID = 0x%02x. Can't proceed\n", id);
                kfree(state);
                return NULL;
        }
@@ -1307,11 +1318,14 @@ struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
                                     struct i2c_adapter* i2c)
 {
        struct tda1004x_state *state;
+       int id;
 
        /* allocate memory for the internal state */
        state = kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL);
-       if (!state)
+       if (!state) {
+               printk(KERN_ERR "Can't alocate memory for tda10046 state\n");
                return NULL;
+       }
 
        /* setup the state */
        state->config = config;
@@ -1319,7 +1333,14 @@ struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
        state->demod_type = TDA1004X_DEMOD_TDA10046;
 
        /* check if the demod is there */
-       if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x46) {
+       id = tda1004x_read_byte(state, TDA1004X_CHIPID);
+       if (id < 0) {
+               printk(KERN_ERR "tda10046: chip is not answering. Giving up.\n");
+               kfree(state);
+               return NULL;
+       }
+       if (id != 0x46) {
+               printk(KERN_ERR "Invalid tda1004x ID = 0x%02x. Can't proceed\n", id);
                kfree(state);
                return NULL;
        }
index d4339b1b3b6872e905532852ef31c4403158950b..07643e01009340cada617b9979a2837ad7747965 100644 (file)
@@ -101,6 +101,7 @@ config DVB_BUDGET
 config DVB_BUDGET_CI
        tristate "Budget cards with onboard CI connector"
        depends on DVB_BUDGET_CORE && I2C
+       depends on INPUT # due to IR
        select DVB_STV0297 if !DVB_FE_CUSTOMISE
        select DVB_STV0299 if !DVB_FE_CUSTOMISE
        select DVB_TDA1004X if !DVB_FE_CUSTOMISE
index 9d81074b31dfe7b2b3ca105234f3d518c2c8d3d8..3a3f5279e927287e68e326c1c7d91721ff704335 100644 (file)
@@ -427,6 +427,7 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
                        if (err) {
                                printk(KERN_ERR "%s: timeout waiting on busy %s QUEUE\n",
                                        __func__, type);
+                               av7110->arm_errors++;
                                return -ETIMEDOUT;
                        }
                        msleep(1);
@@ -853,10 +854,8 @@ static osd_raw_window_t bpp2bit[8] = {
 
 static inline int WaitUntilBmpLoaded(struct av7110 *av7110)
 {
-       int ret = wait_event_interruptible_timeout(av7110->bmpq,
+       int ret = wait_event_timeout(av7110->bmpq,
                                av7110->bmp_state != BMP_LOADING, 10*HZ);
-       if (ret == -ERESTARTSYS)
-               return ret;
        if (ret == 0) {
                printk("dvb-ttpci: warning: timeout waiting in LoadBitmap: %d, %d\n",
                       ret, av7110->bmp_state);
index 3b26fbd3e5589e5203ca0c99c96bf4e5fbb5e91c..5ccb0aeca8ccde50c4a605a42c3574c46358a045 100644 (file)
@@ -793,6 +793,14 @@ menuconfig V4L_USB_DRIVERS
 
 if V4L_USB_DRIVERS && USB
 
+config USB_VIDEO_CLASS
+       tristate "USB Video Class (UVC)"
+       ---help---
+         Support for the USB Video Class (UVC).  Currently only video
+         input devices, such as webcams, are supported.
+
+         For more information see: <http://linux-uvc.berlios.de/>
+
 source "drivers/media/video/pvrusb2/Kconfig"
 
 source "drivers/media/video/em28xx/Kconfig"
index dff0d6abe917f35ecb79eb7b381802361237ecde..ecbbfaab24d506daf49920a1755ef549277f4334 100644 (file)
@@ -136,6 +136,8 @@ obj-$(CONFIG_SOC_CAMERA_MT9V022)    += mt9v022.o
 
 obj-$(CONFIG_VIDEO_AU0828) += au0828/
 
+obj-$(CONFIG_USB_VIDEO_CLASS)  += uvc/
+
 EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
 EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
 EXTRA_CFLAGS += -Idrivers/media/common/tuners
index a2a6983444fa0d8fe146ceadcaabab3378e6d28f..898e12395e7c26e1f829beff5f773c85cd5671f8 100644 (file)
@@ -77,8 +77,14 @@ static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
 
        /* Make sure we support the board model */
        switch (tv.model) {
+       case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
        case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */
+       case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
+       case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
+       case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */
+       case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and basic analog video */
        case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and basic analog video */
+       case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
                break;
        default:
                printk(KERN_WARNING "%s: warning: "
@@ -175,6 +181,18 @@ struct usb_device_id au0828_usb_id_table [] = {
                .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
        { USB_DEVICE(0x0fe9, 0xd620),
                .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
+       { USB_DEVICE(0x2040, 0x7210),
+               .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
+       { USB_DEVICE(0x2040, 0x7217),
+               .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
+       { USB_DEVICE(0x2040, 0x721b),
+               .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
+       { USB_DEVICE(0x2040, 0x721f),
+               .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
+       { USB_DEVICE(0x2040, 0x7280),
+               .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
+       { USB_DEVICE(0x0fd9, 0x0008),
+               .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
        { },
 };
 
index 5f942690570c2079626c15c113cdaa02538d3e05..9aefdc5ea79a960983c9c78d5c3cd5e4348e1311 100644 (file)
@@ -10,8 +10,8 @@ config VIDEO_CX18
        select VIDEO_TVEEPROM
        select VIDEO_CX2341X
        select VIDEO_CS5345
-       select DVB_S5H1409
-       select MEDIA_TUNER_MXL5005S
+       select DVB_S5H1409 if !DVB_FE_CUSTOMISE
+       select MEDIA_TUNER_MXL5005S if !DVB_FE_CUSTOMISE
        ---help---
          This is a video4linux driver for Conexant cx23418 based
          PCI combo video recorder devices.
index 9a26751615c618d6dcf1d5d42e36d02ecda29ef5..faca43eb940f7aa17bfbb552c038e0ad2ecd07f3 100644 (file)
@@ -69,6 +69,58 @@ int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 and_mask,
                             or_value);
 }
 
+int cx18_av_write_no_acfg(struct cx18 *cx, u16 addr, u8 value, int no_acfg_mask)
+{
+       int retval;
+       u32 saved_reg[8] = {0};
+
+       if (no_acfg_mask & CXADEC_NO_ACFG_AFE) {
+               saved_reg[0] = cx18_av_read4(cx, CXADEC_CHIP_CTRL);
+               saved_reg[1] = cx18_av_read4(cx, CXADEC_AFE_CTRL);
+       }
+
+       if (no_acfg_mask & CXADEC_NO_ACFG_PLL) {
+               saved_reg[2] = cx18_av_read4(cx, CXADEC_PLL_CTRL1);
+               saved_reg[3] = cx18_av_read4(cx, CXADEC_VID_PLL_FRAC);
+       }
+
+       if (no_acfg_mask & CXADEC_NO_ACFG_VID) {
+               saved_reg[4] = cx18_av_read4(cx, CXADEC_HORIZ_TIM_CTRL);
+               saved_reg[5] = cx18_av_read4(cx, CXADEC_VERT_TIM_CTRL);
+               saved_reg[6] = cx18_av_read4(cx, CXADEC_SRC_COMB_CFG);
+               saved_reg[7] = cx18_av_read4(cx, CXADEC_CHROMA_VBIOFF_CFG);
+       }
+
+       retval = cx18_av_write(cx, addr, value);
+
+       if (no_acfg_mask & CXADEC_NO_ACFG_AFE) {
+               cx18_av_write4(cx, CXADEC_CHIP_CTRL, saved_reg[0]);
+               cx18_av_write4(cx, CXADEC_AFE_CTRL,  saved_reg[1]);
+       }
+
+       if (no_acfg_mask & CXADEC_NO_ACFG_PLL) {
+               cx18_av_write4(cx, CXADEC_PLL_CTRL1,    saved_reg[2]);
+               cx18_av_write4(cx, CXADEC_VID_PLL_FRAC, saved_reg[3]);
+       }
+
+       if (no_acfg_mask & CXADEC_NO_ACFG_VID) {
+               cx18_av_write4(cx, CXADEC_HORIZ_TIM_CTRL,    saved_reg[4]);
+               cx18_av_write4(cx, CXADEC_VERT_TIM_CTRL,     saved_reg[5]);
+               cx18_av_write4(cx, CXADEC_SRC_COMB_CFG,      saved_reg[6]);
+               cx18_av_write4(cx, CXADEC_CHROMA_VBIOFF_CFG, saved_reg[7]);
+       }
+
+       return retval;
+}
+
+int cx18_av_and_or_no_acfg(struct cx18 *cx, u16 addr, unsigned and_mask,
+                          u8 or_value, int no_acfg_mask)
+{
+       return cx18_av_write_no_acfg(cx, addr,
+                                    (cx18_av_read(cx, addr) & and_mask) |
+                                    or_value, no_acfg_mask);
+}
+
 /* ----------------------------------------------------------------------- */
 
 static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
@@ -170,13 +222,15 @@ static void input_change(struct cx18 *cx)
 
        /* Follow step 8c and 8d of section 3.16 in the cx18_av datasheet */
        if (std & V4L2_STD_SECAM)
-               cx18_av_write(cx, 0x402, 0);
+               cx18_av_write_no_acfg(cx, 0x402, 0, CXADEC_NO_ACFG_ALL);
        else {
-               cx18_av_write(cx, 0x402, 0x04);
+               cx18_av_write_no_acfg(cx, 0x402, 0x04, CXADEC_NO_ACFG_ALL);
                cx18_av_write(cx, 0x49f, (std & V4L2_STD_NTSC) ? 0x14 : 0x11);
        }
-       cx18_av_and_or(cx, 0x401, ~0x60, 0);
-       cx18_av_and_or(cx, 0x401, ~0x60, 0x60);
+       cx18_av_and_or_no_acfg(cx, 0x401, ~0x60, 0,
+                               CXADEC_NO_ACFG_PLL | CXADEC_NO_ACFG_VID);
+       cx18_av_and_or_no_acfg(cx, 0x401, ~0x60, 0x60,
+                               CXADEC_NO_ACFG_PLL | CXADEC_NO_ACFG_VID);
 
        if (std & V4L2_STD_525_60) {
                if (std == V4L2_STD_NTSC_M_JP) {
@@ -228,7 +282,7 @@ static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
 
                if ((vid_input & ~0xff0) ||
                    luma < CX18_AV_SVIDEO_LUMA1 ||
-                   luma > CX18_AV_SVIDEO_LUMA4 ||
+                   luma > CX18_AV_SVIDEO_LUMA8 ||
                    chroma < CX18_AV_SVIDEO_CHROMA4 ||
                    chroma > CX18_AV_SVIDEO_CHROMA8) {
                        CX18_ERR("0x%04x is not a valid video input!\n",
@@ -262,7 +316,8 @@ static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
 
        cx18_av_write(cx, 0x103, reg);
        /* Set INPUT_MODE to Composite (0) or S-Video (1) */
-       cx18_av_and_or(cx, 0x401, ~0x6, is_composite ? 0 : 0x02);
+       cx18_av_and_or_no_acfg(cx, 0x401, ~0x6, is_composite ? 0 : 0x02,
+                               CXADEC_NO_ACFG_PLL | CXADEC_NO_ACFG_VID);
        /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
        cx18_av_and_or(cx, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0);
        /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */
@@ -318,12 +373,12 @@ static int set_v4lstd(struct cx18 *cx)
           This happens for example with the Yuan MPC622. */
        if (fmt >= 4 && fmt < 8) {
                /* Set format to NTSC-M */
-               cx18_av_and_or(cx, 0x400, ~0xf, 1);
+               cx18_av_and_or_no_acfg(cx, 0x400, ~0xf, 1, CXADEC_NO_ACFG_AFE);
                /* Turn off LCOMB */
                cx18_av_and_or(cx, 0x47b, ~6, 0);
        }
-       cx18_av_and_or(cx, 0x400, ~0xf, fmt);
-       cx18_av_and_or(cx, 0x403, ~0x3, pal_m);
+       cx18_av_and_or_no_acfg(cx, 0x400, ~0xf, fmt, CXADEC_NO_ACFG_AFE);
+       cx18_av_and_or_no_acfg(cx, 0x403, ~0x3, pal_m, CXADEC_NO_ACFG_ALL);
        cx18_av_vbi_setup(cx);
        input_change(cx);
        return 0;
index 786901d72e9a84f96d2a48ae1607a90f15e497bb..c172823ce1d8801a93f384fbd5063057a1b6d2a3 100644 (file)
@@ -37,12 +37,16 @@ enum cx18_av_video_input {
        CX18_AV_COMPOSITE7,
        CX18_AV_COMPOSITE8,
 
-       /* S-Video inputs consist of one luma input (In1-In4) ORed with one
+       /* S-Video inputs consist of one luma input (In1-In8) ORed with one
           chroma input (In5-In8) */
        CX18_AV_SVIDEO_LUMA1 = 0x10,
        CX18_AV_SVIDEO_LUMA2 = 0x20,
        CX18_AV_SVIDEO_LUMA3 = 0x30,
        CX18_AV_SVIDEO_LUMA4 = 0x40,
+       CX18_AV_SVIDEO_LUMA5 = 0x50,
+       CX18_AV_SVIDEO_LUMA6 = 0x60,
+       CX18_AV_SVIDEO_LUMA7 = 0x70,
+       CX18_AV_SVIDEO_LUMA8 = 0x80,
        CX18_AV_SVIDEO_CHROMA4 = 0x400,
        CX18_AV_SVIDEO_CHROMA5 = 0x500,
        CX18_AV_SVIDEO_CHROMA6 = 0x600,
@@ -291,14 +295,24 @@ struct cx18_av_state {
 #define CXADEC_SELECT_AUDIO_STANDARD_FM    0xF9  /* FM radio */
 #define CXADEC_SELECT_AUDIO_STANDARD_AUTO  0xFF  /* Auto detect */
 
+/* Flags on what to preserve on write to 0x400-0x403 with cx18_av_.*_no_acfg()*/
+#define CXADEC_NO_ACFG_AFE     0x01 /* Preserve 0x100-0x107 */
+#define CXADEC_NO_ACFG_PLL     0x02 /* Preserve 0x108-0x10f */
+#define CXADEC_NO_ACFG_VID     0x04 /* Preserve 0x470-0x47f */
+#define CXADEC_NO_ACFG_ALL     0x07
+
 /* ----------------------------------------------------------------------- */
 /* cx18_av-core.c                                                         */
 int cx18_av_write(struct cx18 *cx, u16 addr, u8 value);
 int cx18_av_write4(struct cx18 *cx, u16 addr, u32 value);
+int cx18_av_write_no_acfg(struct cx18 *cx, u16 addr, u8 value,
+                               int no_acfg_mask);
 u8 cx18_av_read(struct cx18 *cx, u16 addr);
 u32 cx18_av_read4(struct cx18 *cx, u16 addr);
 int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned mask, u8 value);
 int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 mask, u32 value);
+int cx18_av_and_or_no_acfg(struct cx18 *cx, u16 addr, unsigned mask, u8 value,
+                               int no_acfg_mask);
 int cx18_av_cmd(struct cx18 *cx, unsigned int cmd, void *arg);
 
 /* ----------------------------------------------------------------------- */
index baccd079243d9682efbe949ee11a6a69bfc419bb..c26e0ef5b07583927c5d5ddd80fee3c304557741 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "cx18-driver.h"
 #include "cx18-cards.h"
+#include "cx18-av-core.h"
 #include "cx18-i2c.h"
 #include <media/cs5345.h>
 
@@ -54,22 +55,22 @@ static const struct cx18_card cx18_card_hvr1600_esmt = {
        .hw_all = CX18_HW_TVEEPROM | CX18_HW_TUNER |
                  CX18_HW_CS5345 | CX18_HW_DVB,
        .video_inputs = {
-               { CX18_CARD_INPUT_VID_TUNER,  0, CX23418_COMPOSITE7 },
-               { CX18_CARD_INPUT_SVIDEO1,    1, CX23418_SVIDEO1    },
-               { CX18_CARD_INPUT_COMPOSITE1, 1, CX23418_COMPOSITE3 },
-               { CX18_CARD_INPUT_SVIDEO2,    2, CX23418_SVIDEO2    },
-               { CX18_CARD_INPUT_COMPOSITE2, 2, CX23418_COMPOSITE4 },
+               { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE7 },
+               { CX18_CARD_INPUT_SVIDEO1,    1, CX18_AV_SVIDEO1    },
+               { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE3 },
+               { CX18_CARD_INPUT_SVIDEO2,    2, CX18_AV_SVIDEO2    },
+               { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE4 },
        },
        .audio_inputs = {
                { CX18_CARD_INPUT_AUD_TUNER,
-                 CX23418_AUDIO8, CS5345_IN_1 | CS5345_MCLK_1_5 },
+                 CX18_AV_AUDIO8, CS5345_IN_1 | CS5345_MCLK_1_5 },
                { CX18_CARD_INPUT_LINE_IN1,
-                 CX23418_AUDIO_SERIAL, CS5345_IN_2 },
+                 CX18_AV_AUDIO_SERIAL, CS5345_IN_2 },
                { CX18_CARD_INPUT_LINE_IN2,
-                 CX23418_AUDIO_SERIAL, CS5345_IN_2 },
+                 CX18_AV_AUDIO_SERIAL, CS5345_IN_3 },
        },
        .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
-                        CX23418_AUDIO_SERIAL, 0 },
+                        CX18_AV_AUDIO_SERIAL, CS5345_IN_4 },
        .ddr = {
                /* ESMT M13S128324A-5B memory */
                .chip_config = 0x003,
@@ -81,6 +82,11 @@ static const struct cx18_card cx18_card_hvr1600_esmt = {
        },
        .gpio_init.initial_value = 0x3001,
        .gpio_init.direction = 0x3001,
+       .gpio_i2c_slave_reset = {
+               .active_lo_mask = 0x3001,
+               .msecs_asserted = 10,
+               .msecs_recovery = 40,
+       },
        .i2c = &cx18_i2c_std,
 };
 
@@ -94,22 +100,22 @@ static const struct cx18_card cx18_card_hvr1600_samsung = {
        .hw_all = CX18_HW_TVEEPROM | CX18_HW_TUNER |
                  CX18_HW_CS5345 | CX18_HW_DVB,
        .video_inputs = {
-               { CX18_CARD_INPUT_VID_TUNER,  0, CX23418_COMPOSITE7 },
-               { CX18_CARD_INPUT_SVIDEO1,    1, CX23418_SVIDEO1    },
-               { CX18_CARD_INPUT_COMPOSITE1, 1, CX23418_COMPOSITE3 },
-               { CX18_CARD_INPUT_SVIDEO2,    2, CX23418_SVIDEO2    },
-               { CX18_CARD_INPUT_COMPOSITE2, 2, CX23418_COMPOSITE4 },
+               { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE7 },
+               { CX18_CARD_INPUT_SVIDEO1,    1, CX18_AV_SVIDEO1    },
+               { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE3 },
+               { CX18_CARD_INPUT_SVIDEO2,    2, CX18_AV_SVIDEO2    },
+               { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE4 },
        },
        .audio_inputs = {
                { CX18_CARD_INPUT_AUD_TUNER,
-                 CX23418_AUDIO8, CS5345_IN_1 | CS5345_MCLK_1_5 },
+                 CX18_AV_AUDIO8, CS5345_IN_1 | CS5345_MCLK_1_5 },
                { CX18_CARD_INPUT_LINE_IN1,
-                 CX23418_AUDIO_SERIAL, CS5345_IN_2 },
+                 CX18_AV_AUDIO_SERIAL, CS5345_IN_2 },
                { CX18_CARD_INPUT_LINE_IN2,
-                 CX23418_AUDIO_SERIAL, CS5345_IN_2 },
+                 CX18_AV_AUDIO_SERIAL, CS5345_IN_3 },
        },
        .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
-                        CX23418_AUDIO_SERIAL, 0 },
+                        CX18_AV_AUDIO_SERIAL, CS5345_IN_4 },
        .ddr = {
                /* Samsung K4D263238G-VC33 memory */
                .chip_config = 0x003,
@@ -121,6 +127,11 @@ static const struct cx18_card cx18_card_hvr1600_samsung = {
        },
        .gpio_init.initial_value = 0x3001,
        .gpio_init.direction = 0x3001,
+       .gpio_i2c_slave_reset = {
+               .active_lo_mask = 0x3001,
+               .msecs_asserted = 10,
+               .msecs_recovery = 40,
+       },
        .i2c = &cx18_i2c_std,
 };
 
@@ -141,19 +152,19 @@ static const struct cx18_card cx18_card_h900 = {
        .hw_audio_ctrl = CX18_HW_CX23418,
        .hw_all = CX18_HW_TUNER,
        .video_inputs = {
-               { CX18_CARD_INPUT_VID_TUNER,  0, CX23418_COMPOSITE2 },
+               { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
                { CX18_CARD_INPUT_SVIDEO1,    1,
-                       CX23418_SVIDEO_LUMA3 | CX23418_SVIDEO_CHROMA4 },
-               { CX18_CARD_INPUT_COMPOSITE1, 1, CX23418_COMPOSITE1 },
+                       CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
+               { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
        },
        .audio_inputs = {
                { CX18_CARD_INPUT_AUD_TUNER,
-                 CX23418_AUDIO8, 0 },
+                 CX18_AV_AUDIO8, 0 },
                { CX18_CARD_INPUT_LINE_IN1,
-                 CX23418_AUDIO_SERIAL, 0 },
+                 CX18_AV_AUDIO_SERIAL, 0 },
        },
        .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
-                        CX23418_AUDIO_SERIAL, 0 },
+                        CX18_AV_AUDIO_SERIAL, 0 },
        .tuners = {
                { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
        },
@@ -183,23 +194,26 @@ static const struct cx18_card_pci_info cx18_pci_mpc718[] = {
 static const struct cx18_card cx18_card_mpc718 = {
        .type = CX18_CARD_YUAN_MPC718,
        .name = "Yuan MPC718",
-       .comment = "Not yet supported!\n",
-       .v4l2_capabilities = 0,
+       .comment = "Some Composite and S-Video inputs are currently working.\n",
+       .v4l2_capabilities = CX18_CAP_ENCODER,
        .hw_audio_ctrl = CX18_HW_CX23418,
        .hw_all = CX18_HW_TUNER,
        .video_inputs = {
-               { CX18_CARD_INPUT_VID_TUNER,  0, CX23418_COMPOSITE7 },
-               { CX18_CARD_INPUT_SVIDEO1,    1, CX23418_SVIDEO1    },
-               { CX18_CARD_INPUT_COMPOSITE1, 1, CX23418_COMPOSITE3 },
+               { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
+               { CX18_CARD_INPUT_SVIDEO1,    1,
+                               CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
+               { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
+               { CX18_CARD_INPUT_SVIDEO2,    2,
+                               CX18_AV_SVIDEO_LUMA7 | CX18_AV_SVIDEO_CHROMA8 },
+               { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE6 },
+               { CX18_CARD_INPUT_COMPOSITE3, 2, CX18_AV_COMPOSITE3 },
        },
        .audio_inputs = {
-               { CX18_CARD_INPUT_AUD_TUNER,
-                 CX23418_AUDIO8, 0 },
-               { CX18_CARD_INPUT_LINE_IN1,
-                 CX23418_AUDIO_SERIAL, 0 },
+               { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,       0 },
+               { CX18_CARD_INPUT_LINE_IN1,  CX18_AV_AUDIO_SERIAL, 0 },
+               { CX18_CARD_INPUT_LINE_IN2,  CX18_AV_AUDIO_SERIAL, 0 },
        },
-       .radio_input = { CX18_CARD_INPUT_AUD_TUNER,
-                        CX23418_AUDIO_SERIAL, 0 },
+       .radio_input = { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO_SERIAL, 0 },
        .tuners = {
                /* XC3028 tuner */
                { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
index bccb67f0db16415a1efd6ffef20909b9d42cd46d..dc2dd945d4c3be4aefd2b324a6d4f368b8825c8c 100644 (file)
 #define        CX18_CARD_INPUT_COMPOSITE2      5
 #define        CX18_CARD_INPUT_COMPOSITE3      6
 
-enum cx34180_video_input {
-       /* Composite video inputs In1-In8 */
-       CX23418_COMPOSITE1 = 1,
-       CX23418_COMPOSITE2,
-       CX23418_COMPOSITE3,
-       CX23418_COMPOSITE4,
-       CX23418_COMPOSITE5,
-       CX23418_COMPOSITE6,
-       CX23418_COMPOSITE7,
-       CX23418_COMPOSITE8,
-
-       /* S-Video inputs consist of one luma input (In1-In4) ORed with one
-          chroma input (In5-In8) */
-       CX23418_SVIDEO_LUMA1 = 0x10,
-       CX23418_SVIDEO_LUMA2 = 0x20,
-       CX23418_SVIDEO_LUMA3 = 0x30,
-       CX23418_SVIDEO_LUMA4 = 0x40,
-       CX23418_SVIDEO_CHROMA4 = 0x400,
-       CX23418_SVIDEO_CHROMA5 = 0x500,
-       CX23418_SVIDEO_CHROMA6 = 0x600,
-       CX23418_SVIDEO_CHROMA7 = 0x700,
-       CX23418_SVIDEO_CHROMA8 = 0x800,
-
-       /* S-Video aliases for common luma/chroma combinations */
-       CX23418_SVIDEO1 = 0x510,
-       CX23418_SVIDEO2 = 0x620,
-       CX23418_SVIDEO3 = 0x730,
-       CX23418_SVIDEO4 = 0x840,
-};
-
 /* audio inputs */
 #define        CX18_CARD_INPUT_AUD_TUNER       1
 #define        CX18_CARD_INPUT_LINE_IN1        2
@@ -75,16 +45,6 @@ enum cx34180_video_input {
 #define CX18_CARD_MAX_AUDIO_INPUTS 3
 #define CX18_CARD_MAX_TUNERS      2
 
-enum cx23418_audio_input {
-       /* Audio inputs: serial or In4-In8 */
-       CX23418_AUDIO_SERIAL,
-       CX23418_AUDIO4 = 4,
-       CX23418_AUDIO5,
-       CX23418_AUDIO6,
-       CX23418_AUDIO7,
-       CX23418_AUDIO8,
-};
-
 /* V4L2 capability aliases */
 #define CX18_CAP_ENCODER (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | \
                          V4L2_CAP_AUDIO | V4L2_CAP_READWRITE)
@@ -118,6 +78,13 @@ struct cx18_gpio_init { /* set initial GPIO DIR and OUT values */
        u32 initial_value;
 };
 
+struct cx18_gpio_i2c_slave_reset {
+       u32 active_lo_mask; /* GPIO outputs that reset i2c chips when low */
+       u32 active_hi_mask; /* GPIO outputs that reset i2c chips when high */
+       int msecs_asserted; /* time period reset must remain asserted */
+       int msecs_recovery; /* time after deassert for chips to be ready */
+};
+
 struct cx18_card_tuner {
        v4l2_std_id std;        /* standard for which the tuner is suitable */
        int         tuner;      /* tuner ID (from tuner.h) */
@@ -154,7 +121,8 @@ struct cx18_card {
 
        /* GPIO card-specific settings */
        u8 xceive_pin;          /* XCeive tuner GPIO reset pin */
-       struct cx18_gpio_init           gpio_init;
+       struct cx18_gpio_init            gpio_init;
+       struct cx18_gpio_i2c_slave_reset gpio_i2c_slave_reset;
 
        struct cx18_card_tuner tuners[CX18_CARD_MAX_TUNERS];
        struct cx18_card_tuner_i2c *i2c;
index c9744173f9692d635455d844beb7a2f9aef2020a..cae38985b1313a306f4dedbe8c656f6208b737ca 100644 (file)
@@ -69,11 +69,21 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
        struct dvb_demux *demux = feed->demux;
        struct cx18_stream *stream = (struct cx18_stream *) demux->priv;
        struct cx18 *cx = stream->cx;
-       int ret = -EINVAL;
+       int ret;
        u32 v;
 
        CX18_DEBUG_INFO("Start feed: pid = 0x%x index = %d\n",
                        feed->pid, feed->index);
+
+       mutex_lock(&cx->serialize_lock);
+       ret = cx18_init_on_first_open(cx);
+       mutex_unlock(&cx->serialize_lock);
+       if (ret) {
+               CX18_ERR("Failed to initialize firmware starting DVB feed\n");
+               return ret;
+       }
+       ret = -EINVAL;
+
        switch (cx->card->type) {
        case CX18_CARD_HVR_1600_ESMT:
        case CX18_CARD_HVR_1600_SAMSUNG:
@@ -101,6 +111,11 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
                if (stream->dvb.feeding++ == 0) {
                        CX18_DEBUG_INFO("Starting Transport DMA\n");
                        ret = cx18_start_v4l2_encode_stream(stream);
+                       if (ret < 0) {
+                               CX18_DEBUG_INFO(
+                                       "Failed to start Transport DMA\n");
+                               stream->dvb.feeding--;
+                       }
                } else
                        ret = 0;
                mutex_unlock(&stream->dvb.feedlock);
index ceb63653c926f71e6b8dae4ce39e00e4e03314ea..b302833f6f9dd8d8250f4e716ed5fa9084d515d6 100644 (file)
@@ -53,10 +53,34 @@ static void gpio_write(struct cx18 *cx)
        write_reg(((dir & 0xffff) << 16) | (val & 0xffff),
                        CX18_REG_GPIO_OUT1);
        write_reg(dir & 0xffff0000, CX18_REG_GPIO_DIR2);
-       write_reg((dir & 0xffff0000) | ((val & 0xffff0000) >> 16),
+       write_reg_sync((dir & 0xffff0000) | ((val & 0xffff0000) >> 16),
                        CX18_REG_GPIO_OUT2);
 }
 
+void cx18_reset_i2c_slaves_gpio(struct cx18 *cx)
+{
+       const struct cx18_gpio_i2c_slave_reset *p;
+
+       p = &cx->card->gpio_i2c_slave_reset;
+
+       if ((p->active_lo_mask | p->active_hi_mask) == 0)
+               return;
+
+       /* Assuming that the masks are a subset of the bits in gpio_dir */
+
+       /* Assert */
+       cx->gpio_val =
+               (cx->gpio_val | p->active_hi_mask) & ~(p->active_lo_mask);
+       gpio_write(cx);
+       schedule_timeout_uninterruptible(msecs_to_jiffies(p->msecs_asserted));
+
+       /* Deassert */
+       cx->gpio_val =
+               (cx->gpio_val | p->active_lo_mask) & ~(p->active_hi_mask);
+       gpio_write(cx);
+       schedule_timeout_uninterruptible(msecs_to_jiffies(p->msecs_recovery));
+}
+
 void cx18_gpio_init(struct cx18 *cx)
 {
        cx->gpio_dir = cx->card->gpio_init.direction;
index 41bac8856b50e050871d85ee655082e2408ee886..525c328f748a3d0f677863bdc4fdde9ae4bdc0fb 100644 (file)
@@ -21,4 +21,5 @@
  */
 
 void cx18_gpio_init(struct cx18 *cx);
+void cx18_reset_i2c_slaves_gpio(struct cx18 *cx);
 int cx18_reset_tuner_gpio(void *dev, int cmd, int value);
index 1d6c51a753137652028763005bc3c318404e4011..680bc4e35b79a3c67d38e072af2471fb30e35e2d 100644 (file)
@@ -405,6 +405,8 @@ int init_cx18_i2c(struct cx18 *cx)
        cx18_setscl(&cx->i2c_algo_cb_data[1], 1);
        cx18_setsda(&cx->i2c_algo_cb_data[1], 1);
 
+       cx18_reset_i2c_slaves_gpio(cx);
+
        return i2c_bit_add_bus(&cx->i2c_adap[0]) ||
                i2c_bit_add_bus(&cx->i2c_adap[1]);
 }
index 607efdcd22f8d0eeae68ba7a57b01c2c171293cd..1da6f134888d6d524ee375d345c75574981706bc 100644 (file)
@@ -433,7 +433,7 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
                int chroma = vid_input & 0xf00;
 
                if ((vid_input & ~0xff0) ||
-                   luma < CX25840_SVIDEO_LUMA1 || luma > CX25840_SVIDEO_LUMA4 ||
+                   luma < CX25840_SVIDEO_LUMA1 || luma > CX25840_SVIDEO_LUMA8 ||
                    chroma < CX25840_SVIDEO_CHROMA4 || chroma > CX25840_SVIDEO_CHROMA8) {
                        v4l_err(client, "0x%04x is not a valid video input!\n",
                                vid_input);
index e976fc6bef7ccc7c6ec747fc5594f7a720aff505..80c8883e54b5c6ef853d5e8560da3424044376e3 100644 (file)
@@ -332,6 +332,12 @@ static int snd_cx88_pcm_open(struct snd_pcm_substream *substream)
        struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
+       if (!chip) {
+               printk(KERN_ERR "BUG: cx88 can't find device struct."
+                               " Can't proceed with open\n");
+               return -ENODEV;
+       }
+
        err = snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS);
        if (err < 0)
                goto _error;
index 92b2a6db4fdc15edea12a61ccbdcfa522da7a534..3c006103c1eb369c4817fd74522ef7ffebc91e61 100644 (file)
@@ -268,6 +268,12 @@ static int snd_em28xx_capture_open(struct snd_pcm_substream *substream)
 
        dprintk("opening device and trying to acquire exclusive lock\n");
 
+       if (!dev) {
+               printk(KERN_ERR "BUG: em28xx can't find device struct."
+                               " Can't proceed with open\n");
+               return -ENODEV;
+       }
+
        /* Sets volume, mute, etc */
 
        dev->mute = 0;
@@ -415,6 +421,12 @@ static int em28xx_audio_init(struct em28xx *dev)
        static int          devnr;
        int                 ret, err;
 
+       if (dev->has_audio_class) {
+               /* This device does not support the extension (in this case
+                  the device is expecting the snd-usb-audio module */
+               return 0;
+       }
+
        printk(KERN_INFO "em28xx-audio.c: probing for em28x1 "
                         "non standard usbaudio\n");
        printk(KERN_INFO "em28xx-audio.c: Copyright (C) 2006 Markus "
@@ -458,6 +470,12 @@ static int em28xx_audio_fini(struct em28xx *dev)
        if (dev == NULL)
                return 0;
 
+       if (dev->has_audio_class) {
+               /* This device does not support the extension (in this case
+                  the device is expecting the snd-usb-audio module */
+               return 0;
+       }
+
        if (dev->adev) {
                snd_card_free(dev->adev->sndcard);
                kfree(dev->adev);
index 3e4f3c7e92e78ee62231feaebde1628d0cae27ff..8cbda43727c3de59ba73a9427706b0961f7d80b1 100644 (file)
@@ -157,6 +157,7 @@ struct em28xx_board em28xx_boards[] = {
                .tda9887_conf = TDA9887_PRESENT,
                .tuner_type   = TUNER_XC2028,
                .mts_firmware = 1,
+               .has_dvb        = 1,
                .decoder      = EM28XX_TVP5150,
                .input          = { {
                        .type     = EM28XX_VMUX_TELEVISION,
@@ -524,6 +525,9 @@ void em28xx_pre_card_setup(struct em28xx *dev)
        rc = em28xx_read_reg(dev, EM28XX_R0A_CHIPID);
        if (rc > 0) {
                switch (rc) {
+               case CHIP_ID_EM2860:
+                       em28xx_info("chip ID is em2860\n");
+                       break;
                case CHIP_ID_EM2883:
                        em28xx_info("chip ID is em2882/em2883\n");
                        dev->wait_after_write = 0;
index 8cf4983f0039602ce617fbe929a1edad032baa26..0b2333ee07f8ea6c3bbf7200cd70f47b89c3a61f 100644 (file)
@@ -382,6 +382,11 @@ static int dvb_init(struct em28xx *dev)
        int result = 0;
        struct em28xx_dvb *dvb;
 
+       if (!dev->has_dvb) {
+               /* This device does not support the extension */
+               return 0;
+       }
+
        dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
 
        if (dvb == NULL) {
@@ -444,6 +449,11 @@ out_free:
 
 static int dvb_fini(struct em28xx *dev)
 {
+       if (!dev->has_dvb) {
+               /* This device does not support the extension */
+               return 0;
+       }
+
        if (dev->dvb) {
                unregister_dvb(dev->dvb);
                dev->dvb = NULL;
index 9058bed07953d839fc69fd2a44042061cb0c5b3a..fac1ab23f6216dd74d4fcbc0a65fd26868d0fcd6 100644 (file)
@@ -84,5 +84,6 @@
 
 /* FIXME: Need to be populated with the other chip ID's */
 enum em28xx_chip_id {
+       CHIP_ID_EM2860 = 34,
        CHIP_ID_EM2883 = 36,
 };
index fb163ecd921684a4014b69e4de056512fa22904e..285bc62bbe4670f203cde0e08c2c14e1e00743bc 100644 (file)
@@ -1848,32 +1848,28 @@ static DEFINE_MUTEX(em28xx_extension_devlist_lock);
 
 int em28xx_register_extension(struct em28xx_ops *ops)
 {
-       struct em28xx *h, *dev = NULL;
-
-       list_for_each_entry(h, &em28xx_devlist, devlist)
-               dev = h;
+       struct em28xx *dev = NULL;
 
        mutex_lock(&em28xx_extension_devlist_lock);
        list_add_tail(&ops->next, &em28xx_extension_devlist);
-       if (dev)
-               ops->init(dev);
-
+       list_for_each_entry(dev, &em28xx_devlist, devlist) {
+               if (dev)
+                       ops->init(dev);
+       }
        printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name);
        mutex_unlock(&em28xx_extension_devlist_lock);
-
        return 0;
 }
 EXPORT_SYMBOL(em28xx_register_extension);
 
 void em28xx_unregister_extension(struct em28xx_ops *ops)
 {
-       struct em28xx *h, *dev = NULL;
-
-       list_for_each_entry(h, &em28xx_devlist, devlist)
-               dev = h;
+       struct em28xx *dev = NULL;
 
-       if (dev)
-               ops->fini(dev);
+       list_for_each_entry(dev, &em28xx_devlist, devlist) {
+               if (dev)
+                       ops->fini(dev);
+       }
 
        mutex_lock(&em28xx_extension_devlist_lock);
        printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name);
index 7cc8e9b19fb794fb57139515692de6d460afbd96..5ec5bb9a94d2e848095d8e737eb2936e6803b14d 100644 (file)
@@ -1019,12 +1019,12 @@ static int pxa_camera_probe(struct platform_device *pdev)
        struct pxa_camera_dev *pcdev;
        struct resource *res;
        void __iomem *base;
-       unsigned int irq;
+       int irq;
        int err = 0;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        irq = platform_get_irq(pdev, 0);
-       if (!res || !irq) {
+       if (!res || irq < 0) {
                err = -ENODEV;
                goto exit;
        }
index ba3082422a01915dce20bce15832c495e9555d89..f118de6e36722950b43b5cb21d64520a32386f1f 100644 (file)
@@ -613,9 +613,15 @@ static int snd_card_saa7134_capture_open(struct snd_pcm_substream * substream)
        struct snd_pcm_runtime *runtime = substream->runtime;
        snd_card_saa7134_pcm_t *pcm;
        snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream);
-       struct saa7134_dev *dev = saa7134->dev;
+       struct saa7134_dev *dev;
        int amux, err;
 
+       if (!saa7134) {
+               printk(KERN_ERR "BUG: saa7134 can't find device struct."
+                               " Can't proceed with open\n");
+               return -ENODEV;
+       }
+       dev = saa7134->dev;
        mutex_lock(&dev->dmasound.lock);
 
        dev->dmasound.read_count  = 0;
index b111903aa322cd287a4d5ca0041396242b7e6c43..2618cfa592e7067287407a403f9501213575b8d0 100644 (file)
@@ -4114,11 +4114,7 @@ struct saa7134_board saa7134_boards[] = {
                .radio_type     = UNSET,
                .tuner_addr     = ADDR_UNSET,
                .radio_addr     = ADDR_UNSET,
-                /*
-                   TODO:
                 .mpeg           = SAA7134_MPEG_DVB,
-                */
-
                 .inputs         = {{
                         .name = name_tv,
                         .vmux = 1,
@@ -4157,7 +4153,7 @@ struct saa7134_board saa7134_boards[] = {
                } },
                .radio = {
                        .name = name_radio,
-                       .amux = LINE1,
+                       .amux = TV,
                },
        },
        [SAA7134_BOARD_AVERMEDIA_M115] = {
@@ -4167,6 +4163,7 @@ struct saa7134_board saa7134_boards[] = {
                .radio_type     = UNSET,
                .tuner_addr     = ADDR_UNSET,
                .radio_addr     = ADDR_UNSET,
+               .mpeg           = SAA7134_MPEG_DVB,
                .inputs         = {{
                        .name = name_tv,
                        .vmux = 1,
@@ -5351,22 +5348,21 @@ static int saa7134_xc2028_callback(struct saa7134_dev *dev,
 {
        switch (command) {
        case XC2028_TUNER_RESET:
-               saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x06e20000, 0x06e20000);
-               saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x06a20000, 0x06a20000);
-               mdelay(250);
-               saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x06e20000, 0);
-               saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x06a20000, 0);
-               mdelay(250);
-               saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x06e20000, 0x06e20000);
-               saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x06a20000, 0x06a20000);
-               mdelay(250);
-               saa_andorl(SAA7133_ANALOG_IO_SELECT >> 2, 0x02, 0x02);
-               saa_andorl(SAA7134_ANALOG_IN_CTRL1 >> 2, 0x81, 0x81);
-               saa_andorl(SAA7134_AUDIO_CLOCK0 >> 2, 0x03187de7, 0x03187de7);
-               saa_andorl(SAA7134_AUDIO_PLL_CTRL >> 2, 0x03, 0x03);
-               saa_andorl(SAA7134_AUDIO_CLOCKS_PER_FIELD0 >> 2,
-                          0x0001e000, 0x0001e000);
-               return 0;
+               saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x00008000, 0x00000000);
+               saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x00008000, 0x00008000);
+               switch (dev->board) {
+               case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
+                       saa7134_set_gpio(dev, 23, 0);
+                       msleep(10);
+                       saa7134_set_gpio(dev, 23, 1);
+               break;
+               case SAA7134_BOARD_AVERMEDIA_A16D:
+                       saa7134_set_gpio(dev, 21, 0);
+                       msleep(10);
+                       saa7134_set_gpio(dev, 21, 1);
+               break;
+               }
+       return 0;
        }
        return -EINVAL;
 }
@@ -5553,9 +5549,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
                saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x08000000, 0x00000000);
                break;
        case SAA7134_BOARD_AVERMEDIA_CARDBUS:
-       case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
        case SAA7134_BOARD_AVERMEDIA_M115:
-       case SAA7134_BOARD_AVERMEDIA_A16D:
                /* power-down tuner chip */
                saa_andorl(SAA7134_GPIO_GPMODE0 >> 2,   0xffffffff, 0);
                saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0xffffffff, 0);
@@ -5565,6 +5559,18 @@ int saa7134_board_init1(struct saa7134_dev *dev)
                saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0xffffffff, 0xffffffff);
                msleep(10);
                break;
+       case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
+               saa7134_set_gpio(dev, 23, 0);
+               msleep(10);
+               saa7134_set_gpio(dev, 23, 1);
+               break;
+       case SAA7134_BOARD_AVERMEDIA_A16D:
+               saa7134_set_gpio(dev, 21, 0);
+               msleep(10);
+               saa7134_set_gpio(dev, 21, 1);
+               msleep(1);
+               dev->has_remote = SAA7134_REMOTE_GPIO;
+               break;
        case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
                /* power-down tuner chip */
                saa_andorl(SAA7134_GPIO_GPMODE0 >> 2,   0x000A8004, 0x000A8004);
@@ -5615,7 +5621,8 @@ int saa7134_board_init1(struct saa7134_dev *dev)
                saa_andorl(SAA7134_GPIO_GPMODE0 >> 2,   0x80040100, 0x80040100);
                saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x80040100, 0x00040100);
                printk("%s: %s: hybrid analog/dvb card\n"
-                      "%s: Sorry, only the analog inputs are supported for now.\n",
+                      "%s: Sorry, only analog s-video and composite input "
+                      "are supported for now.\n",
                        dev->name, card(dev).name, dev->name);
                break;
        }
@@ -5675,6 +5682,7 @@ static void saa7134_tuner_setup(struct saa7134_dev *dev)
 
                switch (dev->board) {
                case SAA7134_BOARD_AVERMEDIA_A16D:
+               case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
                        ctl.demod = XC3028_FE_ZARLINK456;
                        break;
                default:
index 469f93aac0083a1e049cb55bc27ed985ca31596d..341b101b0357d457003438ecaa210d16640dc580 100644 (file)
@@ -153,12 +153,12 @@ static int mt352_aver777_init(struct dvb_frontend* fe)
        return 0;
 }
 
-static int mt352_aver_a16d_init(struct dvb_frontend *fe)
+static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
 {
-       static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x2d };
-       static u8 reset []         = { RESET,      0x80 };
-       static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
-       static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };
+       static u8 clock_config []  = { CLOCK_CTL, 0x38, 0x2d };
+       static u8 reset []         = { RESET, 0x80 };
+       static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
+       static u8 agc_cfg []       = { AGC_TARGET, 0xe };
        static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
 
        mt352_write(fe, clock_config,   sizeof(clock_config));
@@ -167,12 +167,9 @@ static int mt352_aver_a16d_init(struct dvb_frontend *fe)
        mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
        mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
        mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
-
        return 0;
 }
 
-
-
 static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
                                           struct dvb_frontend_parameters* params)
 {
@@ -215,14 +212,10 @@ static struct mt352_config avermedia_777 = {
        .demod_init    = mt352_aver777_init,
 };
 
-static struct mt352_config avermedia_16d = {
-       .demod_address = 0xf,
-       .demod_init    = mt352_aver_a16d_init,
-};
-
-static struct mt352_config avermedia_e506r_mt352_dev = {
+static struct mt352_config avermedia_xc3028_mt352_dev = {
        .demod_address   = (0x1e >> 1),
        .no_tuner        = 1,
+       .demod_init      = mt352_avermedia_xc3028_init,
 };
 
 /* ==================================================================
@@ -975,9 +968,10 @@ static int dvb_init(struct saa7134_dev *dev)
                }
                break;
        case SAA7134_BOARD_AVERMEDIA_A16D:
-               dprintk("avertv A16D dvb setup\n");
-               dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_16d,
-                                              &dev->i2c_adap);
+               dprintk("AverMedia A16D dvb setup\n");
+               dev->dvb.frontend = dvb_attach(mt352_attach,
+                                               &avermedia_xc3028_mt352_dev,
+                                               &dev->i2c_adap);
                attach_xc3028 = 1;
                break;
        case SAA7134_BOARD_MD7134:
@@ -1091,7 +1085,8 @@ static int dvb_init(struct saa7134_dev *dev)
                                        ads_tech_duo_config.tuner_address);
                                goto dettach_frontend;
                        }
-               }
+               } else
+                       wprintk("failed to attach tda10046\n");
                break;
        case SAA7134_BOARD_TEVION_DVBT_220RF:
                if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
@@ -1260,11 +1255,14 @@ static int dvb_init(struct saa7134_dev *dev)
                        goto dettach_frontend;
                break;
        case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
+               dprintk("AverMedia E506R dvb setup\n");
+               saa7134_set_gpio(dev, 25, 0);
+               msleep(10);
+               saa7134_set_gpio(dev, 25, 1);
                dev->dvb.frontend = dvb_attach(mt352_attach,
-                                              &avermedia_e506r_mt352_dev,
-                                              &dev->i2c_adap);
+                                               &avermedia_xc3028_mt352_dev,
+                                               &dev->i2c_adap);
                attach_xc3028 = 1;
-               break;
        case SAA7134_BOARD_MD7134_BRIDGE_2:
                dev->dvb.frontend = dvb_attach(tda10086_attach,
                                                &sd1878_4m, &dev->i2c_adap);
@@ -1338,7 +1336,8 @@ static int dvb_init(struct saa7134_dev *dev)
        return ret;
 
 dettach_frontend:
-       dvb_frontend_detach(dev->dvb.frontend);
+       if (dev->dvb.frontend)
+               dvb_frontend_detach(dev->dvb.frontend);
        dev->dvb.frontend = NULL;
 
        return -1;
index 81431ee418426894f5c285fdfef6f4609f2294a5..3ae71a3408223800ce442efc413c8589bb18ae4a 100644 (file)
@@ -110,9 +110,10 @@ static int ts_release(struct inode *inode, struct file *file)
 {
        struct saa7134_dev *dev = file->private_data;
 
+       mutex_lock(&dev->empress_tsq.vb_lock);
+
        videobuf_stop(&dev->empress_tsq);
        videobuf_mmap_free(&dev->empress_tsq);
-       dev->empress_users--;
 
        /* stop the encoder */
        ts_reset_encoder(dev);
@@ -121,6 +122,10 @@ static int ts_release(struct inode *inode, struct file *file)
        saa_writeb(SAA7134_AUDIO_MUTE_CTRL,
                saa_readb(SAA7134_AUDIO_MUTE_CTRL) | (1 << 6));
 
+       dev->empress_users--;
+
+       mutex_unlock(&dev->empress_tsq.vb_lock);
+
        return 0;
 }
 
@@ -218,8 +223,7 @@ static int empress_enum_fmt_cap(struct file *file, void  *priv,
 static int empress_g_fmt_cap(struct file *file, void *priv,
                                struct v4l2_format *f)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
+       struct saa7134_dev *dev = file->private_data;
 
        saa7134_i2c_call_clients(dev, VIDIOC_G_FMT, f);
 
@@ -232,8 +236,7 @@ static int empress_g_fmt_cap(struct file *file, void *priv,
 static int empress_s_fmt_cap(struct file *file, void *priv,
                                struct v4l2_format *f)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
+       struct saa7134_dev *dev = file->private_data;
 
        saa7134_i2c_call_clients(dev, VIDIOC_S_FMT, f);
 
@@ -247,8 +250,7 @@ static int empress_s_fmt_cap(struct file *file, void *priv,
 static int empress_reqbufs(struct file *file, void *priv,
                                        struct v4l2_requestbuffers *p)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
+       struct saa7134_dev *dev = file->private_data;
 
        return videobuf_reqbufs(&dev->empress_tsq, p);
 }
@@ -256,24 +258,21 @@ static int empress_reqbufs(struct file *file, void *priv,
 static int empress_querybuf(struct file *file, void *priv,
                                        struct v4l2_buffer *b)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
+       struct saa7134_dev *dev = file->private_data;
 
        return videobuf_querybuf(&dev->empress_tsq, b);
 }
 
 static int empress_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
+       struct saa7134_dev *dev = file->private_data;
 
        return videobuf_qbuf(&dev->empress_tsq, b);
 }
 
 static int empress_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
+       struct saa7134_dev *dev = file->private_data;
 
        return videobuf_dqbuf(&dev->empress_tsq, b,
                                file->f_flags & O_NONBLOCK);
@@ -282,8 +281,7 @@ static int empress_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
 static int empress_streamon(struct file *file, void *priv,
                                        enum v4l2_buf_type type)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
+       struct saa7134_dev *dev = file->private_data;
 
        return videobuf_streamon(&dev->empress_tsq);
 }
@@ -291,8 +289,7 @@ static int empress_streamon(struct file *file, void *priv,
 static int empress_streamoff(struct file *file, void *priv,
                                        enum v4l2_buf_type type)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
+       struct saa7134_dev *dev = file->private_data;
 
        return videobuf_streamoff(&dev->empress_tsq);
 }
@@ -300,8 +297,7 @@ static int empress_streamoff(struct file *file, void *priv,
 static int empress_s_ext_ctrls(struct file *file, void *priv,
                               struct v4l2_ext_controls *ctrls)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
+       struct saa7134_dev *dev = file->private_data;
 
        /* count == 0 is abused in saa6752hs.c, so that special
                case is handled here explicitly. */
@@ -320,8 +316,7 @@ static int empress_s_ext_ctrls(struct file *file, void *priv,
 static int empress_g_ext_ctrls(struct file *file, void *priv,
                               struct v4l2_ext_controls *ctrls)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
+       struct saa7134_dev *dev = file->private_data;
 
        if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
                return -EINVAL;
index 919632b10aae0ed20510fc68c2d89e944117b00c..76e6501d238d0d31ddaf68305484de9faa9c6368 100644 (file)
@@ -323,6 +323,15 @@ int saa7134_input_init1(struct saa7134_dev *dev)
                saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
                saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
                break;
+       case SAA7134_BOARD_AVERMEDIA_A16D:
+               ir_codes     = ir_codes_avermedia_a16d;
+               mask_keycode = 0x02F200;
+               mask_keydown = 0x000400;
+               polling      = 50; /* ms */
+               /* Without this we won't receive key up events */
+               saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
+               saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
+               break;
        case SAA7134_BOARD_KWORLD_TERMINATOR:
                ir_codes     = ir_codes_pixelview;
                mask_keycode = 0x00001f;
index a1b92446c8b4ac78052a4849e23a9f428ccba2c1..d015bfe00950c5fcf1a943154cb6413ce8db60f5 100644 (file)
@@ -763,15 +763,6 @@ static struct device_driver ic_drv = {
        .owner  = THIS_MODULE,
 };
 
-/*
- * Image capture host - this is a host device, not a bus device, so,
- * no bus reference, no probing.
- */
-static struct class soc_camera_host_class = {
-       .owner          = THIS_MODULE,
-       .name           = "camera_host",
-};
-
 static void dummy_release(struct device *dev)
 {
 }
@@ -801,7 +792,6 @@ int soc_camera_host_register(struct soc_camera_host *ici)
 
        /* Number might be equal to the platform device ID */
        sprintf(ici->dev.bus_id, "camera_host%d", ici->nr);
-       ici->dev.class = &soc_camera_host_class;
 
        mutex_lock(&list_lock);
        list_for_each_entry(ix, &hosts, list) {
@@ -1003,14 +993,9 @@ static int __init soc_camera_init(void)
        ret = driver_register(&ic_drv);
        if (ret)
                goto edrvr;
-       ret = class_register(&soc_camera_host_class);
-       if (ret)
-               goto eclr;
 
        return 0;
 
-eclr:
-       driver_unregister(&ic_drv);
 edrvr:
        bus_unregister(&soc_camera_bus_type);
        return ret;
@@ -1018,7 +1003,6 @@ edrvr:
 
 static void __exit soc_camera_exit(void)
 {
-       class_unregister(&soc_camera_host_class);
        driver_unregister(&ic_drv);
        bus_unregister(&soc_camera_bus_type);
 }
diff --git a/drivers/media/video/uvc/Makefile b/drivers/media/video/uvc/Makefile
new file mode 100644 (file)
index 0000000..968c199
--- /dev/null
@@ -0,0 +1,3 @@
+uvcvideo-objs  := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o \
+                 uvc_status.o uvc_isight.o
+obj-$(CONFIG_USB_VIDEO_CLASS) += uvcvideo.o
diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
new file mode 100644 (file)
index 0000000..f0ee46d
--- /dev/null
@@ -0,0 +1,1256 @@
+/*
+ *      uvc_ctrl.c  --  USB Video Class driver - Controls
+ *
+ *      Copyright (C) 2005-2008
+ *          Laurent Pinchart (laurent.pinchart@skynet.be)
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation; either version 2 of the License, or
+ *      (at your option) any later version.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/uaccess.h>
+#include <linux/usb.h>
+#include <linux/videodev2.h>
+#include <linux/vmalloc.h>
+#include <linux/wait.h>
+#include <asm/atomic.h>
+
+#include "uvcvideo.h"
+
+#define UVC_CTRL_NDATA         2
+#define UVC_CTRL_DATA_CURRENT  0
+#define UVC_CTRL_DATA_BACKUP   1
+
+/* ------------------------------------------------------------------------
+ * Control, formats, ...
+ */
+
+static struct uvc_control_info uvc_ctrls[] = {
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_BRIGHTNESS_CONTROL,
+               .index          = 0,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_CONTRAST_CONTROL,
+               .index          = 1,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_HUE_CONTROL,
+               .index          = 2,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_SATURATION_CONTROL,
+               .index          = 3,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_SHARPNESS_CONTROL,
+               .index          = 4,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_GAMMA_CONTROL,
+               .index          = 5,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_BACKLIGHT_COMPENSATION_CONTROL,
+               .index          = 8,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_GAIN_CONTROL,
+               .index          = 9,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_POWER_LINE_FREQUENCY_CONTROL,
+               .index          = 10,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_HUE_AUTO_CONTROL,
+               .index          = 11,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_AE_MODE_CONTROL,
+               .index          = 1,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_GET_RES
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_AE_PRIORITY_CONTROL,
+               .index          = 2,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_EXPOSURE_TIME_ABSOLUTE_CONTROL,
+               .index          = 3,
+               .size           = 4,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_FOCUS_ABSOLUTE_CONTROL,
+               .index          = 5,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_FOCUS_AUTO_CONTROL,
+               .index          = 17,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
+               .index          = 12,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
+               .index          = 6,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
+               .index          = 13,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_COMPONENT_CONTROL,
+               .index          = 7,
+               .size           = 4,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
+       },
+};
+
+static struct uvc_menu_info power_line_frequency_controls[] = {
+       { 0, "Disabled" },
+       { 1, "50 Hz" },
+       { 2, "60 Hz" },
+};
+
+static struct uvc_menu_info exposure_auto_controls[] = {
+       { 1, "Manual Mode" },
+       { 2, "Auto Mode" },
+       { 4, "Shutter Priority Mode" },
+       { 8, "Aperture Priority Mode" },
+};
+
+static struct uvc_control_mapping uvc_ctrl_mappings[] = {
+       {
+               .id             = V4L2_CID_BRIGHTNESS,
+               .name           = "Brightness",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_BRIGHTNESS_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_SIGNED,
+       },
+       {
+               .id             = V4L2_CID_CONTRAST,
+               .name           = "Contrast",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_CONTRAST_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+       },
+       {
+               .id             = V4L2_CID_HUE,
+               .name           = "Hue",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_HUE_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_SIGNED,
+       },
+       {
+               .id             = V4L2_CID_SATURATION,
+               .name           = "Saturation",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_SATURATION_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+       },
+       {
+               .id             = V4L2_CID_SHARPNESS,
+               .name           = "Sharpness",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_SHARPNESS_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+       },
+       {
+               .id             = V4L2_CID_GAMMA,
+               .name           = "Gamma",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_GAMMA_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+       },
+       {
+               .id             = V4L2_CID_BACKLIGHT_COMPENSATION,
+               .name           = "Backlight Compensation",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_BACKLIGHT_COMPENSATION_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+       },
+       {
+               .id             = V4L2_CID_GAIN,
+               .name           = "Gain",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_GAIN_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+       },
+       {
+               .id             = V4L2_CID_POWER_LINE_FREQUENCY,
+               .name           = "Power Line Frequency",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_POWER_LINE_FREQUENCY_CONTROL,
+               .size           = 2,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_MENU,
+               .data_type      = UVC_CTRL_DATA_TYPE_ENUM,
+               .menu_info      = power_line_frequency_controls,
+               .menu_count     = ARRAY_SIZE(power_line_frequency_controls),
+       },
+       {
+               .id             = V4L2_CID_HUE_AUTO,
+               .name           = "Hue, Auto",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_HUE_AUTO_CONTROL,
+               .size           = 1,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_BOOLEAN,
+               .data_type      = UVC_CTRL_DATA_TYPE_BOOLEAN,
+       },
+       {
+               .id             = V4L2_CID_EXPOSURE_AUTO,
+               .name           = "Exposure, Auto",
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_AE_MODE_CONTROL,
+               .size           = 4,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_MENU,
+               .data_type      = UVC_CTRL_DATA_TYPE_BITMASK,
+               .menu_info      = exposure_auto_controls,
+               .menu_count     = ARRAY_SIZE(exposure_auto_controls),
+       },
+       {
+               .id             = V4L2_CID_EXPOSURE_AUTO_PRIORITY,
+               .name           = "Exposure, Auto Priority",
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_AE_PRIORITY_CONTROL,
+               .size           = 1,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_BOOLEAN,
+               .data_type      = UVC_CTRL_DATA_TYPE_BOOLEAN,
+       },
+       {
+               .id             = V4L2_CID_EXPOSURE_ABSOLUTE,
+               .name           = "Exposure (Absolute)",
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_EXPOSURE_TIME_ABSOLUTE_CONTROL,
+               .size           = 32,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+       },
+       {
+               .id             = V4L2_CID_AUTO_WHITE_BALANCE,
+               .name           = "White Balance Temperature, Auto",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
+               .size           = 1,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_BOOLEAN,
+               .data_type      = UVC_CTRL_DATA_TYPE_BOOLEAN,
+       },
+       {
+               .id             = V4L2_CID_WHITE_BALANCE_TEMPERATURE,
+               .name           = "White Balance Temperature",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+       },
+       {
+               .id             = V4L2_CID_AUTO_WHITE_BALANCE,
+               .name           = "White Balance Component, Auto",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
+               .size           = 1,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_BOOLEAN,
+               .data_type      = UVC_CTRL_DATA_TYPE_BOOLEAN,
+       },
+       {
+               .id             = V4L2_CID_BLUE_BALANCE,
+               .name           = "White Balance Blue Component",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_COMPONENT_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_SIGNED,
+       },
+       {
+               .id             = V4L2_CID_RED_BALANCE,
+               .name           = "White Balance Red Component",
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_COMPONENT_CONTROL,
+               .size           = 16,
+               .offset         = 16,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_SIGNED,
+       },
+       {
+               .id             = V4L2_CID_FOCUS_ABSOLUTE,
+               .name           = "Focus (absolute)",
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_FOCUS_ABSOLUTE_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+       },
+       {
+               .id             = V4L2_CID_FOCUS_AUTO,
+               .name           = "Focus, Auto",
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_FOCUS_AUTO_CONTROL,
+               .size           = 1,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_BOOLEAN,
+               .data_type      = UVC_CTRL_DATA_TYPE_BOOLEAN,
+       },
+};
+
+/* ------------------------------------------------------------------------
+ * Utility functions
+ */
+
+static inline __u8 *uvc_ctrl_data(struct uvc_control *ctrl, int id)
+{
+       return ctrl->data + id * ctrl->info->size;
+}
+
+static inline int uvc_get_bit(const __u8 *data, int bit)
+{
+       return (data[bit >> 3] >> (bit & 7)) & 1;
+}
+
+/* Extract the bit string specified by mapping->offset and mapping->size
+ * from the little-endian data stored at 'data' and return the result as
+ * a signed 32bit integer. Sign extension will be performed if the mapping
+ * references a signed data type.
+ */
+static __s32 uvc_get_le_value(const __u8 *data,
+       struct uvc_control_mapping *mapping)
+{
+       int bits = mapping->size;
+       int offset = mapping->offset;
+       __s32 value = 0;
+       __u8 mask;
+
+       data += offset / 8;
+       offset &= 7;
+       mask = ((1LL << bits) - 1) << offset;
+
+       for (; bits > 0; data++) {
+               __u8 byte = *data & mask;
+               value |= offset > 0 ? (byte >> offset) : (byte << (-offset));
+               bits -= 8 - (offset > 0 ? offset : 0);
+               offset -= 8;
+               mask = (1 << bits) - 1;
+       }
+
+       /* Sign-extend the value if needed */
+       if (mapping->data_type == UVC_CTRL_DATA_TYPE_SIGNED)
+               value |= -(value & (1 << (mapping->size - 1)));
+
+       return value;
+}
+
+/* Set the bit string specified by mapping->offset and mapping->size
+ * in the little-endian data stored at 'data' to the value 'value'.
+ */
+static void uvc_set_le_value(__s32 value, __u8 *data,
+       struct uvc_control_mapping *mapping)
+{
+       int bits = mapping->size;
+       int offset = mapping->offset;
+       __u8 mask;
+
+       data += offset / 8;
+       offset &= 7;
+
+       for (; bits > 0; data++) {
+               mask = ((1LL << bits) - 1) << offset;
+               *data = (*data & ~mask) | ((value << offset) & mask);
+               value >>= offset ? offset : 8;
+               bits -= 8 - offset;
+               offset = 0;
+       }
+}
+
+/* ------------------------------------------------------------------------
+ * Terminal and unit management
+ */
+
+static const __u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING;
+static const __u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA;
+static const __u8 uvc_media_transport_input_guid[16] =
+       UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT;
+
+static int uvc_entity_match_guid(struct uvc_entity *entity, __u8 guid[16])
+{
+       switch (UVC_ENTITY_TYPE(entity)) {
+       case ITT_CAMERA:
+               return memcmp(uvc_camera_guid, guid, 16) == 0;
+
+       case ITT_MEDIA_TRANSPORT_INPUT:
+               return memcmp(uvc_media_transport_input_guid, guid, 16) == 0;
+
+       case VC_PROCESSING_UNIT:
+               return memcmp(uvc_processing_guid, guid, 16) == 0;
+
+       case VC_EXTENSION_UNIT:
+               return memcmp(entity->extension.guidExtensionCode,
+                             guid, 16) == 0;
+
+       default:
+               return 0;
+       }
+}
+
+/* ------------------------------------------------------------------------
+ * UVC Controls
+ */
+
+static void __uvc_find_control(struct uvc_entity *entity, __u32 v4l2_id,
+       struct uvc_control_mapping **mapping, struct uvc_control **control,
+       int next)
+{
+       struct uvc_control *ctrl;
+       struct uvc_control_mapping *map;
+       unsigned int i;
+
+       if (entity == NULL)
+               return;
+
+       for (i = 0; i < entity->ncontrols; ++i) {
+               ctrl = &entity->controls[i];
+               if (ctrl->info == NULL)
+                       continue;
+
+               list_for_each_entry(map, &ctrl->info->mappings, list) {
+                       if ((map->id == v4l2_id) && !next) {
+                               *control = ctrl;
+                               *mapping = map;
+                               return;
+                       }
+
+                       if ((*mapping == NULL || (*mapping)->id > map->id) &&
+                           (map->id > v4l2_id) && next) {
+                               *control = ctrl;
+                               *mapping = map;
+                       }
+               }
+       }
+}
+
+struct uvc_control *uvc_find_control(struct uvc_video_device *video,
+       __u32 v4l2_id, struct uvc_control_mapping **mapping)
+{
+       struct uvc_control *ctrl = NULL;
+       struct uvc_entity *entity;
+       int next = v4l2_id & V4L2_CTRL_FLAG_NEXT_CTRL;
+
+       *mapping = NULL;
+
+       /* Mask the query flags. */
+       v4l2_id &= V4L2_CTRL_ID_MASK;
+
+       /* Find the control. */
+       __uvc_find_control(video->processing, v4l2_id, mapping, &ctrl, next);
+       if (ctrl && !next)
+               return ctrl;
+
+       list_for_each_entry(entity, &video->iterms, chain) {
+               __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next);
+               if (ctrl && !next)
+                       return ctrl;
+       }
+
+       list_for_each_entry(entity, &video->extensions, chain) {
+               __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next);
+               if (ctrl && !next)
+                       return ctrl;
+       }
+
+       if (ctrl == NULL && !next)
+               uvc_trace(UVC_TRACE_CONTROL, "Control 0x%08x not found.\n",
+                               v4l2_id);
+
+       return ctrl;
+}
+
+int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
+       struct v4l2_queryctrl *v4l2_ctrl)
+{
+       struct uvc_control *ctrl;
+       struct uvc_control_mapping *mapping;
+       struct uvc_menu_info *menu;
+       unsigned int i;
+       __u8 data[8];
+       int ret;
+
+       ctrl = uvc_find_control(video, v4l2_ctrl->id, &mapping);
+       if (ctrl == NULL)
+               return -EINVAL;
+
+       v4l2_ctrl->id = mapping->id;
+       v4l2_ctrl->type = mapping->v4l2_type;
+       strncpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name);
+       v4l2_ctrl->flags = 0;
+
+       if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR))
+               v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
+       if (ctrl->info->flags & UVC_CONTROL_GET_DEF) {
+               if ((ret = uvc_query_ctrl(video->dev, GET_DEF, ctrl->entity->id,
+                               video->dev->intfnum, ctrl->info->selector,
+                               &data, ctrl->info->size)) < 0)
+                       return ret;
+               v4l2_ctrl->default_value = uvc_get_le_value(data, mapping);
+       }
+
+       if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
+               v4l2_ctrl->minimum = 0;
+               v4l2_ctrl->maximum = mapping->menu_count - 1;
+               v4l2_ctrl->step = 1;
+
+               menu = mapping->menu_info;
+               for (i = 0; i < mapping->menu_count; ++i, ++menu) {
+                       if (menu->value == v4l2_ctrl->default_value) {
+                               v4l2_ctrl->default_value = i;
+                               break;
+                       }
+               }
+
+               return 0;
+       }
+
+       if (ctrl->info->flags & UVC_CONTROL_GET_MIN) {
+               if ((ret = uvc_query_ctrl(video->dev, GET_MIN, ctrl->entity->id,
+                               video->dev->intfnum, ctrl->info->selector,
+                               &data, ctrl->info->size)) < 0)
+                       return ret;
+               v4l2_ctrl->minimum = uvc_get_le_value(data, mapping);
+       }
+       if (ctrl->info->flags & UVC_CONTROL_GET_MAX) {
+               if ((ret = uvc_query_ctrl(video->dev, GET_MAX, ctrl->entity->id,
+                               video->dev->intfnum, ctrl->info->selector,
+                               &data, ctrl->info->size)) < 0)
+                       return ret;
+               v4l2_ctrl->maximum = uvc_get_le_value(data, mapping);
+       }
+       if (ctrl->info->flags & UVC_CONTROL_GET_RES) {
+               if ((ret = uvc_query_ctrl(video->dev, GET_RES, ctrl->entity->id,
+                               video->dev->intfnum, ctrl->info->selector,
+                               &data, ctrl->info->size)) < 0)
+                       return ret;
+               v4l2_ctrl->step = uvc_get_le_value(data, mapping);
+       }
+
+       return 0;
+}
+
+
+/* --------------------------------------------------------------------------
+ * Control transactions
+ *
+ * To make extended set operations as atomic as the hardware allows, controls
+ * are handled using begin/commit/rollback operations.
+ *
+ * At the beginning of a set request, uvc_ctrl_begin should be called to
+ * initialize the request. This function acquires the control lock.
+ *
+ * When setting a control, the new value is stored in the control data field
+ * at position UVC_CTRL_DATA_CURRENT. The control is then marked as dirty for
+ * later processing. If the UVC and V4L2 control sizes differ, the current
+ * value is loaded from the hardware before storing the new value in the data
+ * field.
+ *
+ * After processing all controls in the transaction, uvc_ctrl_commit or
+ * uvc_ctrl_rollback must be called to apply the pending changes to the
+ * hardware or revert them. When applying changes, all controls marked as
+ * dirty will be modified in the UVC device, and the dirty flag will be
+ * cleared. When reverting controls, the control data field
+ * UVC_CTRL_DATA_CURRENT is reverted to its previous value
+ * (UVC_CTRL_DATA_BACKUP) for all dirty controls. Both functions release the
+ * control lock.
+ */
+int uvc_ctrl_begin(struct uvc_video_device *video)
+{
+       return mutex_lock_interruptible(&video->ctrl_mutex) ? -ERESTARTSYS : 0;
+}
+
+static int uvc_ctrl_commit_entity(struct uvc_device *dev,
+       struct uvc_entity *entity, int rollback)
+{
+       struct uvc_control *ctrl;
+       unsigned int i;
+       int ret;
+
+       if (entity == NULL)
+               return 0;
+
+       for (i = 0; i < entity->ncontrols; ++i) {
+               ctrl = &entity->controls[i];
+               if (ctrl->info == NULL || !ctrl->dirty)
+                       continue;
+
+               if (!rollback)
+                       ret = uvc_query_ctrl(dev, SET_CUR, ctrl->entity->id,
+                               dev->intfnum, ctrl->info->selector,
+                               uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+                               ctrl->info->size);
+               else
+                       ret = 0;
+
+               if (rollback || ret < 0)
+                       memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+                              uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
+                              ctrl->info->size);
+
+               if ((ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0)
+                       ctrl->loaded = 0;
+
+               ctrl->dirty = 0;
+
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+
+int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback)
+{
+       struct uvc_entity *entity;
+       int ret = 0;
+
+       /* Find the control. */
+       ret = uvc_ctrl_commit_entity(video->dev, video->processing, rollback);
+       if (ret < 0)
+               goto done;
+
+       list_for_each_entry(entity, &video->iterms, chain) {
+               ret = uvc_ctrl_commit_entity(video->dev, entity, rollback);
+               if (ret < 0)
+                       goto done;
+       }
+
+       list_for_each_entry(entity, &video->extensions, chain) {
+               ret = uvc_ctrl_commit_entity(video->dev, entity, rollback);
+               if (ret < 0)
+                       goto done;
+       }
+
+done:
+       mutex_unlock(&video->ctrl_mutex);
+       return ret;
+}
+
+int uvc_ctrl_get(struct uvc_video_device *video,
+       struct v4l2_ext_control *xctrl)
+{
+       struct uvc_control *ctrl;
+       struct uvc_control_mapping *mapping;
+       struct uvc_menu_info *menu;
+       unsigned int i;
+       int ret;
+
+       ctrl = uvc_find_control(video, xctrl->id, &mapping);
+       if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0)
+               return -EINVAL;
+
+       if (!ctrl->loaded) {
+               ret = uvc_query_ctrl(video->dev, GET_CUR, ctrl->entity->id,
+                               video->dev->intfnum, ctrl->info->selector,
+                               uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+                               ctrl->info->size);
+               if (ret < 0)
+                       return ret;
+
+               if ((ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE) == 0)
+                       ctrl->loaded = 1;
+       }
+
+       xctrl->value = uvc_get_le_value(
+               uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), mapping);
+
+       if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
+               menu = mapping->menu_info;
+               for (i = 0; i < mapping->menu_count; ++i, ++menu) {
+                       if (menu->value == xctrl->value) {
+                               xctrl->value = i;
+                               break;
+                       }
+               }
+       }
+
+       return 0;
+}
+
+int uvc_ctrl_set(struct uvc_video_device *video,
+       struct v4l2_ext_control *xctrl)
+{
+       struct uvc_control *ctrl;
+       struct uvc_control_mapping *mapping;
+       s32 value = xctrl->value;
+       int ret;
+
+       ctrl = uvc_find_control(video, xctrl->id, &mapping);
+       if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_SET_CUR) == 0)
+               return -EINVAL;
+
+       if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
+               if (value < 0 || value >= mapping->menu_count)
+                       return -EINVAL;
+               value = mapping->menu_info[value].value;
+       }
+
+       if (!ctrl->loaded && (ctrl->info->size * 8) != mapping->size) {
+               if ((ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0) {
+                       memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+                               0, ctrl->info->size);
+               } else {
+                       ret = uvc_query_ctrl(video->dev, GET_CUR,
+                               ctrl->entity->id, video->dev->intfnum,
+                               ctrl->info->selector,
+                               uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+                               ctrl->info->size);
+                       if (ret < 0)
+                               return ret;
+               }
+
+               if ((ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE) == 0)
+                       ctrl->loaded = 1;
+       }
+
+       if (!ctrl->dirty) {
+               memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
+                      uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+                      ctrl->info->size);
+       }
+
+       uvc_set_le_value(value,
+               uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), mapping);
+
+       ctrl->dirty = 1;
+       ctrl->modified = 1;
+       return 0;
+}
+
+/* --------------------------------------------------------------------------
+ * Dynamic controls
+ */
+
+int uvc_xu_ctrl_query(struct uvc_video_device *video,
+       struct uvc_xu_control *xctrl, int set)
+{
+       struct uvc_entity *entity;
+       struct uvc_control *ctrl = NULL;
+       unsigned int i, found = 0;
+       __u8 *data;
+       int ret;
+
+       /* Find the extension unit. */
+       list_for_each_entry(entity, &video->extensions, chain) {
+               if (entity->id == xctrl->unit)
+                       break;
+       }
+
+       if (entity->id != xctrl->unit) {
+               uvc_trace(UVC_TRACE_CONTROL, "Extension unit %u not found.\n",
+                       xctrl->unit);
+               return -EINVAL;
+       }
+
+       /* Find the control. */
+       for (i = 0; i < entity->ncontrols; ++i) {
+               ctrl = &entity->controls[i];
+               if (ctrl->info == NULL)
+                       continue;
+
+               if (ctrl->info->selector == xctrl->selector) {
+                       found = 1;
+                       break;
+               }
+       }
+
+       if (!found) {
+               uvc_trace(UVC_TRACE_CONTROL,
+                       "Control " UVC_GUID_FORMAT "/%u not found.\n",
+                       UVC_GUID_ARGS(entity->extension.guidExtensionCode),
+                       xctrl->selector);
+               return -EINVAL;
+       }
+
+       /* Validate control data size. */
+       if (ctrl->info->size != xctrl->size)
+               return -EINVAL;
+
+       if ((set && !(ctrl->info->flags & UVC_CONTROL_SET_CUR)) ||
+           (!set && !(ctrl->info->flags & UVC_CONTROL_GET_CUR)))
+               return -EINVAL;
+
+       if (mutex_lock_interruptible(&video->ctrl_mutex))
+               return -ERESTARTSYS;
+
+       memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
+              uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+              xctrl->size);
+       data = uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT);
+
+       if (set && copy_from_user(data, xctrl->data, xctrl->size)) {
+               ret = -EFAULT;
+               goto out;
+       }
+
+       ret = uvc_query_ctrl(video->dev, set ? SET_CUR : GET_CUR, xctrl->unit,
+                            video->dev->intfnum, xctrl->selector, data,
+                            xctrl->size);
+       if (ret < 0)
+               goto out;
+
+       if (!set && copy_to_user(xctrl->data, data, xctrl->size)) {
+               ret = -EFAULT;
+               goto out;
+       }
+
+out:
+       if (ret)
+               memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
+                      uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
+                      xctrl->size);
+
+       mutex_unlock(&video->ctrl_mutex);
+       return ret;
+}
+
+/* --------------------------------------------------------------------------
+ * Suspend/resume
+ */
+
+/*
+ * Restore control values after resume, skipping controls that haven't been
+ * changed.
+ *
+ * TODO
+ * - Don't restore modified controls that are back to their default value.
+ * - Handle restore order (Auto-Exposure Mode should be restored before
+ *   Exposure Time).
+ */
+int uvc_ctrl_resume_device(struct uvc_device *dev)
+{
+       struct uvc_control *ctrl;
+       struct uvc_entity *entity;
+       unsigned int i;
+       int ret;
+
+       /* Walk the entities list and restore controls when possible. */
+       list_for_each_entry(entity, &dev->entities, list) {
+
+               for (i = 0; i < entity->ncontrols; ++i) {
+                       ctrl = &entity->controls[i];
+
+                       if (ctrl->info == NULL || !ctrl->modified ||
+                           (ctrl->info->flags & UVC_CONTROL_RESTORE) == 0)
+                               continue;
+
+                       printk(KERN_INFO "restoring control " UVC_GUID_FORMAT
+                               "/%u/%u\n", UVC_GUID_ARGS(ctrl->info->entity),
+                               ctrl->info->index, ctrl->info->selector);
+                       ctrl->dirty = 1;
+               }
+
+               ret = uvc_ctrl_commit_entity(dev, entity, 0);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+
+/* --------------------------------------------------------------------------
+ * Control and mapping handling
+ */
+
+static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
+       struct uvc_control_info *info)
+{
+       struct uvc_entity *entity;
+       struct uvc_control *ctrl = NULL;
+       int ret, found = 0;
+       unsigned int i;
+
+       list_for_each_entry(entity, &dev->entities, list) {
+               if (!uvc_entity_match_guid(entity, info->entity))
+                       continue;
+
+               for (i = 0; i < entity->ncontrols; ++i) {
+                       ctrl = &entity->controls[i];
+                       if (ctrl->index == info->index) {
+                               found = 1;
+                               break;
+                       }
+               }
+
+               if (found)
+                       break;
+       }
+
+       if (!found)
+               return;
+
+       if (UVC_ENTITY_TYPE(entity) == VC_EXTENSION_UNIT) {
+               /* Check if the device control information and length match
+                * the user supplied information.
+                */
+               __u32 flags;
+               __le16 size;
+               __u8 inf;
+
+               if ((ret = uvc_query_ctrl(dev, GET_LEN, ctrl->entity->id,
+                       dev->intfnum, info->selector, (__u8 *)&size, 2)) < 0) {
+                       uvc_trace(UVC_TRACE_CONTROL, "GET_LEN failed on "
+                               "control " UVC_GUID_FORMAT "/%u (%d).\n",
+                               UVC_GUID_ARGS(info->entity), info->selector,
+                               ret);
+                       return;
+               }
+
+               if (info->size != le16_to_cpu(size)) {
+                       uvc_trace(UVC_TRACE_CONTROL, "Control " UVC_GUID_FORMAT
+                               "/%u size doesn't match user supplied "
+                               "value.\n", UVC_GUID_ARGS(info->entity),
+                               info->selector);
+                       return;
+               }
+
+               if ((ret = uvc_query_ctrl(dev, GET_INFO, ctrl->entity->id,
+                       dev->intfnum, info->selector, &inf, 1)) < 0) {
+                       uvc_trace(UVC_TRACE_CONTROL, "GET_INFO failed on "
+                               "control " UVC_GUID_FORMAT "/%u (%d).\n",
+                               UVC_GUID_ARGS(info->entity), info->selector,
+                               ret);
+                       return;
+               }
+
+               flags = info->flags;
+               if (((flags & UVC_CONTROL_GET_CUR) && !(inf & (1 << 0))) ||
+                   ((flags & UVC_CONTROL_SET_CUR) && !(inf & (1 << 1)))) {
+                       uvc_trace(UVC_TRACE_CONTROL, "Control "
+                               UVC_GUID_FORMAT "/%u flags don't match "
+                               "supported operations.\n",
+                               UVC_GUID_ARGS(info->entity), info->selector);
+                       return;
+               }
+       }
+
+       ctrl->info = info;
+       ctrl->data = kmalloc(ctrl->info->size * UVC_CTRL_NDATA, GFP_KERNEL);
+       uvc_trace(UVC_TRACE_CONTROL, "Added control " UVC_GUID_FORMAT "/%u "
+               "to device %s entity %u\n", UVC_GUID_ARGS(ctrl->info->entity),
+               ctrl->info->selector, dev->udev->devpath, entity->id);
+}
+
+/*
+ * Add an item to the UVC control information list, and instantiate a control
+ * structure for each device that supports the control.
+ */
+int uvc_ctrl_add_info(struct uvc_control_info *info)
+{
+       struct uvc_control_info *ctrl;
+       struct uvc_device *dev;
+       int ret = 0;
+
+       /* Find matching controls by walking the devices, entities and
+        * controls list.
+        */
+       mutex_lock(&uvc_driver.ctrl_mutex);
+
+       /* First check if the list contains a control matching the new one.
+        * Bail out if it does.
+        */
+       list_for_each_entry(ctrl, &uvc_driver.controls, list) {
+               if (memcmp(ctrl->entity, info->entity, 16))
+                       continue;
+
+               if (ctrl->selector == info->selector) {
+                       uvc_trace(UVC_TRACE_CONTROL, "Control "
+                               UVC_GUID_FORMAT "/%u is already defined.\n",
+                               UVC_GUID_ARGS(info->entity), info->selector);
+                       ret = -EEXIST;
+                       goto end;
+               }
+               if (ctrl->index == info->index) {
+                       uvc_trace(UVC_TRACE_CONTROL, "Control "
+                               UVC_GUID_FORMAT "/%u would overwrite index "
+                               "%d.\n", UVC_GUID_ARGS(info->entity),
+                               info->selector, info->index);
+                       ret = -EEXIST;
+                       goto end;
+               }
+       }
+
+       list_for_each_entry(dev, &uvc_driver.devices, list)
+               uvc_ctrl_add_ctrl(dev, info);
+
+       INIT_LIST_HEAD(&info->mappings);
+       list_add_tail(&info->list, &uvc_driver.controls);
+end:
+       mutex_unlock(&uvc_driver.ctrl_mutex);
+       return ret;
+}
+
+int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping)
+{
+       struct uvc_control_info *info;
+       struct uvc_control_mapping *map;
+       int ret = -EINVAL;
+
+       if (mapping->id & ~V4L2_CTRL_ID_MASK) {
+               uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s' with "
+                       "invalid control id 0x%08x\n", mapping->name,
+                       mapping->id);
+               return -EINVAL;
+       }
+
+       mutex_lock(&uvc_driver.ctrl_mutex);
+       list_for_each_entry(info, &uvc_driver.controls, list) {
+               if (memcmp(info->entity, mapping->entity, 16) ||
+                       info->selector != mapping->selector)
+                       continue;
+
+               if (info->size * 8 < mapping->size + mapping->offset) {
+                       uvc_trace(UVC_TRACE_CONTROL, "Mapping '%s' would "
+                               "overflow control " UVC_GUID_FORMAT "/%u\n",
+                               mapping->name, UVC_GUID_ARGS(info->entity),
+                               info->selector);
+                       ret = -EOVERFLOW;
+                       goto end;
+               }
+
+               /* Check if the list contains a mapping matching the new one.
+                * Bail out if it does.
+                */
+               list_for_each_entry(map, &info->mappings, list) {
+                       if (map->id == mapping->id) {
+                               uvc_trace(UVC_TRACE_CONTROL, "Mapping '%s' is "
+                                       "already defined.\n", mapping->name);
+                               ret = -EEXIST;
+                               goto end;
+                       }
+               }
+
+               mapping->ctrl = info;
+               list_add_tail(&mapping->list, &info->mappings);
+               uvc_trace(UVC_TRACE_CONTROL, "Adding mapping %s to control "
+                       UVC_GUID_FORMAT "/%u.\n", mapping->name,
+                       UVC_GUID_ARGS(info->entity), info->selector);
+
+               ret = 0;
+               break;
+       }
+end:
+       mutex_unlock(&uvc_driver.ctrl_mutex);
+       return ret;
+}
+
+/*
+ * Initialize device controls.
+ */
+int uvc_ctrl_init_device(struct uvc_device *dev)
+{
+       struct uvc_control_info *info;
+       struct uvc_control *ctrl;
+       struct uvc_entity *entity;
+       unsigned int i;
+
+       /* Walk the entities list and instantiate controls */
+       list_for_each_entry(entity, &dev->entities, list) {
+               unsigned int bControlSize = 0, ncontrols = 0;
+               __u8 *bmControls = NULL;
+
+               if (UVC_ENTITY_TYPE(entity) == VC_EXTENSION_UNIT) {
+                       bmControls = entity->extension.bmControls;
+                       bControlSize = entity->extension.bControlSize;
+               } else if (UVC_ENTITY_TYPE(entity) == VC_PROCESSING_UNIT) {
+                       bmControls = entity->processing.bmControls;
+                       bControlSize = entity->processing.bControlSize;
+               } else if (UVC_ENTITY_TYPE(entity) == ITT_CAMERA) {
+                       bmControls = entity->camera.bmControls;
+                       bControlSize = entity->camera.bControlSize;
+               }
+
+               for (i = 0; i < bControlSize; ++i)
+                       ncontrols += hweight8(bmControls[i]);
+
+               if (ncontrols == 0)
+                       continue;
+
+               entity->controls = kzalloc(ncontrols*sizeof *ctrl, GFP_KERNEL);
+               if (entity->controls == NULL)
+                       return -ENOMEM;
+
+               entity->ncontrols = ncontrols;
+
+               ctrl = entity->controls;
+               for (i = 0; i < bControlSize * 8; ++i) {
+                       if (uvc_get_bit(bmControls, i) == 0)
+                               continue;
+
+                       ctrl->entity = entity;
+                       ctrl->index = i;
+                       ctrl++;
+               }
+       }
+
+       /* Walk the controls info list and associate them with the device
+        * controls, then add the device to the global device list. This has
+        * to be done while holding the controls lock, to make sure
+        * uvc_ctrl_add_info() will not get called in-between.
+        */
+       mutex_lock(&uvc_driver.ctrl_mutex);
+       list_for_each_entry(info, &uvc_driver.controls, list)
+               uvc_ctrl_add_ctrl(dev, info);
+
+       list_add_tail(&dev->list, &uvc_driver.devices);
+       mutex_unlock(&uvc_driver.ctrl_mutex);
+
+       return 0;
+}
+
+/*
+ * Cleanup device controls.
+ */
+void uvc_ctrl_cleanup_device(struct uvc_device *dev)
+{
+       struct uvc_entity *entity;
+       unsigned int i;
+
+       /* Remove the device from the global devices list */
+       mutex_lock(&uvc_driver.ctrl_mutex);
+       if (dev->list.next != NULL)
+               list_del(&dev->list);
+       mutex_unlock(&uvc_driver.ctrl_mutex);
+
+       list_for_each_entry(entity, &dev->entities, list) {
+               for (i = 0; i < entity->ncontrols; ++i)
+                       kfree(entity->controls[i].data);
+
+               kfree(entity->controls);
+       }
+}
+
+void uvc_ctrl_init(void)
+{
+       struct uvc_control_info *ctrl = uvc_ctrls;
+       struct uvc_control_info *cend = ctrl + ARRAY_SIZE(uvc_ctrls);
+       struct uvc_control_mapping *mapping = uvc_ctrl_mappings;
+       struct uvc_control_mapping *mend =
+               mapping + ARRAY_SIZE(uvc_ctrl_mappings);
+
+       for (; ctrl < cend; ++ctrl)
+               uvc_ctrl_add_info(ctrl);
+
+       for (; mapping < mend; ++mapping)
+               uvc_ctrl_add_mapping(mapping);
+}
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c
new file mode 100644 (file)
index 0000000..60ced58
--- /dev/null
@@ -0,0 +1,1955 @@
+/*
+ *      uvc_driver.c  --  USB Video Class driver
+ *
+ *      Copyright (C) 2005-2008
+ *          Laurent Pinchart (laurent.pinchart@skynet.be)
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation; either version 2 of the License, or
+ *      (at your option) any later version.
+ *
+ */
+
+/*
+ * This driver aims to support video input devices compliant with the 'USB
+ * Video Class' specification.
+ *
+ * The driver doesn't support the deprecated v4l1 interface. It implements the
+ * mmap capture method only, and doesn't do any image format conversion in
+ * software. If your user-space application doesn't support YUYV or MJPEG, fix
+ * it :-). Please note that the MJPEG data have been stripped from their
+ * Huffman tables (DHT marker), you will need to add it back if your JPEG
+ * codec can't handle MJPEG data.
+ */
+
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+#include <linux/videodev2.h>
+#include <linux/vmalloc.h>
+#include <linux/wait.h>
+#include <asm/atomic.h>
+
+#include <media/v4l2-common.h>
+
+#include "uvcvideo.h"
+
+#define DRIVER_AUTHOR          "Laurent Pinchart <laurent.pinchart@skynet.be>"
+#define DRIVER_DESC            "USB Video Class driver"
+#ifndef DRIVER_VERSION
+#define DRIVER_VERSION         "v0.1.0"
+#endif
+
+static unsigned int uvc_quirks_param;
+unsigned int uvc_trace_param;
+
+/* ------------------------------------------------------------------------
+ * Control, formats, ...
+ */
+
+static struct uvc_format_desc uvc_fmts[] = {
+       {
+               .name           = "YUV 4:2:2 (YUYV)",
+               .guid           = UVC_GUID_FORMAT_YUY2,
+               .fcc            = V4L2_PIX_FMT_YUYV,
+       },
+       {
+               .name           = "YUV 4:2:0 (NV12)",
+               .guid           = UVC_GUID_FORMAT_NV12,
+               .fcc            = V4L2_PIX_FMT_NV12,
+       },
+       {
+               .name           = "MJPEG",
+               .guid           = UVC_GUID_FORMAT_MJPEG,
+               .fcc            = V4L2_PIX_FMT_MJPEG,
+       },
+       {
+               .name           = "YVU 4:2:0 (YV12)",
+               .guid           = UVC_GUID_FORMAT_YV12,
+               .fcc            = V4L2_PIX_FMT_YVU420,
+       },
+       {
+               .name           = "YUV 4:2:0 (I420)",
+               .guid           = UVC_GUID_FORMAT_I420,
+               .fcc            = V4L2_PIX_FMT_YUV420,
+       },
+       {
+               .name           = "YUV 4:2:2 (UYVY)",
+               .guid           = UVC_GUID_FORMAT_UYVY,
+               .fcc            = V4L2_PIX_FMT_UYVY,
+       },
+       {
+               .name           = "Greyscale",
+               .guid           = UVC_GUID_FORMAT_Y800,
+               .fcc            = V4L2_PIX_FMT_GREY,
+       },
+       {
+               .name           = "RGB Bayer",
+               .guid           = UVC_GUID_FORMAT_BY8,
+               .fcc            = V4L2_PIX_FMT_SBGGR8,
+       },
+};
+
+/* ------------------------------------------------------------------------
+ * Utility functions
+ */
+
+struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
+               __u8 epaddr)
+{
+       struct usb_host_endpoint *ep;
+       unsigned int i;
+
+       for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
+               ep = &alts->endpoint[i];
+               if (ep->desc.bEndpointAddress == epaddr)
+                       return ep;
+       }
+
+       return NULL;
+}
+
+static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
+{
+       unsigned int len = ARRAY_SIZE(uvc_fmts);
+       unsigned int i;
+
+       for (i = 0; i < len; ++i) {
+               if (memcmp(guid, uvc_fmts[i].guid, 16) == 0)
+                       return &uvc_fmts[i];
+       }
+
+       return NULL;
+}
+
+static __u32 uvc_colorspace(const __u8 primaries)
+{
+       static const __u8 colorprimaries[] = {
+               0,
+               V4L2_COLORSPACE_SRGB,
+               V4L2_COLORSPACE_470_SYSTEM_M,
+               V4L2_COLORSPACE_470_SYSTEM_BG,
+               V4L2_COLORSPACE_SMPTE170M,
+               V4L2_COLORSPACE_SMPTE240M,
+       };
+
+       if (primaries < ARRAY_SIZE(colorprimaries))
+               return colorprimaries[primaries];
+
+       return 0;
+}
+
+/* Simplify a fraction using a simple continued fraction decomposition. The
+ * idea here is to convert fractions such as 333333/10000000 to 1/30 using
+ * 32 bit arithmetic only. The algorithm is not perfect and relies upon two
+ * arbitrary parameters to remove non-significative terms from the simple
+ * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
+ * respectively seems to give nice results.
+ */
+void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
+               unsigned int n_terms, unsigned int threshold)
+{
+       uint32_t *an;
+       uint32_t x, y, r;
+       unsigned int i, n;
+
+       an = kmalloc(n_terms * sizeof *an, GFP_KERNEL);
+       if (an == NULL)
+               return;
+
+       /* Convert the fraction to a simple continued fraction. See
+        * http://mathforum.org/dr.math/faq/faq.fractions.html
+        * Stop if the current term is bigger than or equal to the given
+        * threshold.
+        */
+       x = *numerator;
+       y = *denominator;
+
+       for (n = 0; n < n_terms && y != 0; ++n) {
+               an[n] = x / y;
+               if (an[n] >= threshold) {
+                       if (n < 2)
+                               n++;
+                       break;
+               }
+
+               r = x - an[n] * y;
+               x = y;
+               y = r;
+       }
+
+       /* Expand the simple continued fraction back to an integer fraction. */
+       x = 0;
+       y = 1;
+
+       for (i = n; i > 0; --i) {
+               r = y;
+               y = an[i-1] * y + x;
+               x = r;
+       }
+
+       *numerator = y;
+       *denominator = x;
+       kfree(an);
+}
+
+/* Convert a fraction to a frame interval in 100ns multiples. The idea here is
+ * to compute numerator / denominator * 10000000 using 32 bit fixed point
+ * arithmetic only.
+ */
+uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator)
+{
+       uint32_t multiplier;
+
+       /* Saturate the result if the operation would overflow. */
+       if (denominator == 0 ||
+           numerator/denominator >= ((uint32_t)-1)/10000000)
+               return (uint32_t)-1;
+
+       /* Divide both the denominator and the multiplier by two until
+        * numerator * multiplier doesn't overflow. If anyone knows a better
+        * algorithm please let me know.
+        */
+       multiplier = 10000000;
+       while (numerator > ((uint32_t)-1)/multiplier) {
+               multiplier /= 2;
+               denominator /= 2;
+       }
+
+       return denominator ? numerator * multiplier / denominator : 0;
+}
+
+/* ------------------------------------------------------------------------
+ * Terminal and unit management
+ */
+
+static struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id)
+{
+       struct uvc_entity *entity;
+
+       list_for_each_entry(entity, &dev->entities, list) {
+               if (entity->id == id)
+                       return entity;
+       }
+
+       return NULL;
+}
+
+static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,
+       int id, struct uvc_entity *entity)
+{
+       unsigned int i;
+
+       if (entity == NULL)
+               entity = list_entry(&dev->entities, struct uvc_entity, list);
+
+       list_for_each_entry_continue(entity, &dev->entities, list) {
+               switch (UVC_ENTITY_TYPE(entity)) {
+               case TT_STREAMING:
+                       if (entity->output.bSourceID == id)
+                               return entity;
+                       break;
+
+               case VC_PROCESSING_UNIT:
+                       if (entity->processing.bSourceID == id)
+                               return entity;
+                       break;
+
+               case VC_SELECTOR_UNIT:
+                       for (i = 0; i < entity->selector.bNrInPins; ++i)
+                               if (entity->selector.baSourceID[i] == id)
+                                       return entity;
+                       break;
+
+               case VC_EXTENSION_UNIT:
+                       for (i = 0; i < entity->extension.bNrInPins; ++i)
+                               if (entity->extension.baSourceID[i] == id)
+                                       return entity;
+                       break;
+               }
+       }
+
+       return NULL;
+}
+
+/* ------------------------------------------------------------------------
+ * Descriptors handling
+ */
+
+static int uvc_parse_format(struct uvc_device *dev,
+       struct uvc_streaming *streaming, struct uvc_format *format,
+       __u32 **intervals, unsigned char *buffer, int buflen)
+{
+       struct usb_interface *intf = streaming->intf;
+       struct usb_host_interface *alts = intf->cur_altsetting;
+       struct uvc_format_desc *fmtdesc;
+       struct uvc_frame *frame;
+       const unsigned char *start = buffer;
+       unsigned int interval;
+       unsigned int i, n;
+       __u8 ftype;
+
+       format->type = buffer[2];
+       format->index = buffer[3];
+
+       switch (buffer[2]) {
+       case VS_FORMAT_UNCOMPRESSED:
+       case VS_FORMAT_FRAME_BASED:
+               if (buflen < 27) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming"
+                              "interface %d FORMAT error\n",
+                              dev->udev->devnum,
+                              alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               /* Find the format descriptor from its GUID. */
+               fmtdesc = uvc_format_by_guid(&buffer[5]);
+
+               if (fmtdesc != NULL) {
+                       strncpy(format->name, fmtdesc->name,
+                               sizeof format->name);
+                       format->fcc = fmtdesc->fcc;
+               } else {
+                       uvc_printk(KERN_INFO, "Unknown video format "
+                               UVC_GUID_FORMAT "\n",
+                               UVC_GUID_ARGS(&buffer[5]));
+                       snprintf(format->name, sizeof format->name,
+                               UVC_GUID_FORMAT, UVC_GUID_ARGS(&buffer[5]));
+                       format->fcc = 0;
+               }
+
+               format->bpp = buffer[21];
+               if (buffer[2] == VS_FORMAT_UNCOMPRESSED) {
+                       ftype = VS_FRAME_UNCOMPRESSED;
+               } else {
+                       ftype = VS_FRAME_FRAME_BASED;
+                       if (buffer[27])
+                               format->flags = UVC_FMT_FLAG_COMPRESSED;
+               }
+               break;
+
+       case VS_FORMAT_MJPEG:
+               if (buflen < 11) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming"
+                              "interface %d FORMAT error\n",
+                              dev->udev->devnum,
+                              alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               strncpy(format->name, "MJPEG", sizeof format->name);
+               format->fcc = V4L2_PIX_FMT_MJPEG;
+               format->flags = UVC_FMT_FLAG_COMPRESSED;
+               format->bpp = 0;
+               ftype = VS_FRAME_MJPEG;
+               break;
+
+       case VS_FORMAT_DV:
+               if (buflen < 9) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming"
+                              "interface %d FORMAT error\n",
+                              dev->udev->devnum,
+                              alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               switch (buffer[8] & 0x7f) {
+               case 0:
+                       strncpy(format->name, "SD-DV", sizeof format->name);
+                       break;
+               case 1:
+                       strncpy(format->name, "SDL-DV", sizeof format->name);
+                       break;
+               case 2:
+                       strncpy(format->name, "HD-DV", sizeof format->name);
+                       break;
+               default:
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming"
+                              "interface %d: unknown DV format %u\n",
+                              dev->udev->devnum,
+                              alts->desc.bInterfaceNumber, buffer[8]);
+                       return -EINVAL;
+               }
+
+               strncat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
+                       sizeof format->name);
+
+               format->fcc = V4L2_PIX_FMT_DV;
+               format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
+               format->bpp = 0;
+               ftype = 0;
+
+               /* Create a dummy frame descriptor. */
+               frame = &format->frame[0];
+               memset(&format->frame[0], 0, sizeof format->frame[0]);
+               frame->bFrameIntervalType = 1;
+               frame->dwDefaultFrameInterval = 1;
+               frame->dwFrameInterval = *intervals;
+               *(*intervals)++ = 1;
+               format->nframes = 1;
+               break;
+
+       case VS_FORMAT_MPEG2TS:
+       case VS_FORMAT_STREAM_BASED:
+               /* Not supported yet. */
+       default:
+               uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming"
+                      "interface %d unsupported format %u\n",
+                      dev->udev->devnum, alts->desc.bInterfaceNumber,
+                      buffer[2]);
+               return -EINVAL;
+       }
+
+       uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name);
+
+       buflen -= buffer[0];
+       buffer += buffer[0];
+
+       /* Parse the frame descriptors. Only uncompressed, MJPEG and frame
+        * based formats have frame descriptors.
+        */
+       while (buflen > 2 && buffer[2] == ftype) {
+               frame = &format->frame[format->nframes];
+
+               if (ftype != VS_FRAME_FRAME_BASED)
+                       n = buflen > 25 ? buffer[25] : 0;
+               else
+                       n = buflen > 21 ? buffer[21] : 0;
+
+               n = n ? n : 3;
+
+               if (buflen < 26 + 4*n) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming"
+                              "interface %d FRAME error\n", dev->udev->devnum,
+                              alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               frame->bFrameIndex = buffer[3];
+               frame->bmCapabilities = buffer[4];
+               frame->wWidth = le16_to_cpup((__le16 *)&buffer[5]);
+               frame->wHeight = le16_to_cpup((__le16 *)&buffer[7]);
+               frame->dwMinBitRate = le32_to_cpup((__le32 *)&buffer[9]);
+               frame->dwMaxBitRate = le32_to_cpup((__le32 *)&buffer[13]);
+               if (ftype != VS_FRAME_FRAME_BASED) {
+                       frame->dwMaxVideoFrameBufferSize =
+                               le32_to_cpup((__le32 *)&buffer[17]);
+                       frame->dwDefaultFrameInterval =
+                               le32_to_cpup((__le32 *)&buffer[21]);
+                       frame->bFrameIntervalType = buffer[25];
+               } else {
+                       frame->dwMaxVideoFrameBufferSize = 0;
+                       frame->dwDefaultFrameInterval =
+                               le32_to_cpup((__le32 *)&buffer[17]);
+                       frame->bFrameIntervalType = buffer[21];
+               }
+               frame->dwFrameInterval = *intervals;
+
+               /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize
+                * completely. Observed behaviours range from setting the
+                * value to 1.1x the actual frame size of hardwiring the
+                * 16 low bits to 0. This results in a higher than necessary
+                * memory usage as well as a wrong image size information. For
+                * uncompressed formats this can be fixed by computing the
+                * value from the frame size.
+                */
+               if (!(format->flags & UVC_FMT_FLAG_COMPRESSED))
+                       frame->dwMaxVideoFrameBufferSize = format->bpp
+                               * frame->wWidth * frame->wHeight / 8;
+
+               /* Some bogus devices report dwMinFrameInterval equal to
+                * dwMaxFrameInterval and have dwFrameIntervalStep set to
+                * zero. Setting all null intervals to 1 fixes the problem and
+                * some other divisions by zero which could happen.
+                */
+               for (i = 0; i < n; ++i) {
+                       interval = le32_to_cpup((__le32 *)&buffer[26+4*i]);
+                       *(*intervals)++ = interval ? interval : 1;
+               }
+
+               /* Make sure that the default frame interval stays between
+                * the boundaries.
+                */
+               n -= frame->bFrameIntervalType ? 1 : 2;
+               frame->dwDefaultFrameInterval =
+                       min(frame->dwFrameInterval[n],
+                           max(frame->dwFrameInterval[0],
+                               frame->dwDefaultFrameInterval));
+
+               uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
+                       frame->wWidth, frame->wHeight,
+                       10000000/frame->dwDefaultFrameInterval,
+                       (100000000/frame->dwDefaultFrameInterval)%10);
+
+               format->nframes++;
+               buflen -= buffer[0];
+               buffer += buffer[0];
+       }
+
+       if (buflen > 2 && buffer[2] == VS_STILL_IMAGE_FRAME) {
+               buflen -= buffer[0];
+               buffer += buffer[0];
+       }
+
+       if (buflen > 2 && buffer[2] == VS_COLORFORMAT) {
+               if (buflen < 6) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming"
+                              "interface %d COLORFORMAT error\n",
+                              dev->udev->devnum,
+                              alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               format->colorspace = uvc_colorspace(buffer[3]);
+
+               buflen -= buffer[0];
+               buffer += buffer[0];
+       }
+
+       return buffer - start;
+}
+
+static int uvc_parse_streaming(struct uvc_device *dev,
+       struct usb_interface *intf)
+{
+       struct uvc_streaming *streaming = NULL;
+       struct uvc_format *format;
+       struct uvc_frame *frame;
+       struct usb_host_interface *alts = &intf->altsetting[0];
+       unsigned char *_buffer, *buffer = alts->extra;
+       int _buflen, buflen = alts->extralen;
+       unsigned int nformats = 0, nframes = 0, nintervals = 0;
+       unsigned int size, i, n, p;
+       __u32 *interval;
+       __u16 psize;
+       int ret = -EINVAL;
+
+       if (intf->cur_altsetting->desc.bInterfaceSubClass
+               != SC_VIDEOSTREAMING) {
+               uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a "
+                       "video streaming interface\n", dev->udev->devnum,
+                       intf->altsetting[0].desc.bInterfaceNumber);
+               return -EINVAL;
+       }
+
+       if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) {
+               uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already "
+                       "claimed\n", dev->udev->devnum,
+                       intf->altsetting[0].desc.bInterfaceNumber);
+               return -EINVAL;
+       }
+
+       streaming = kzalloc(sizeof *streaming, GFP_KERNEL);
+       if (streaming == NULL) {
+               usb_driver_release_interface(&uvc_driver.driver, intf);
+               return -EINVAL;
+       }
+
+       mutex_init(&streaming->mutex);
+       streaming->intf = usb_get_intf(intf);
+       streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
+
+       /* The Pico iMage webcam has its class-specific interface descriptors
+        * after the endpoint descriptors.
+        */
+       if (buflen == 0) {
+               for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
+                       struct usb_host_endpoint *ep = &alts->endpoint[i];
+
+                       if (ep->extralen == 0)
+                               continue;
+
+                       if (ep->extralen > 2 &&
+                           ep->extra[1] == USB_DT_CS_INTERFACE) {
+                               uvc_trace(UVC_TRACE_DESCR, "trying extra data "
+                                       "from endpoint %u.\n", i);
+                               buffer = alts->endpoint[i].extra;
+                               buflen = alts->endpoint[i].extralen;
+                               break;
+                       }
+               }
+       }
+
+       /* Skip the standard interface descriptors. */
+       while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) {
+               buflen -= buffer[0];
+               buffer += buffer[0];
+       }
+
+       if (buflen <= 2) {
+               uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming "
+                       "interface descriptors found.\n");
+               goto error;
+       }
+
+       /* Parse the header descriptor. */
+       if (buffer[2] == VS_OUTPUT_HEADER) {
+               uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
+                       "%d OUTPUT HEADER descriptor is not supported.\n",
+                       dev->udev->devnum, alts->desc.bInterfaceNumber);
+               goto error;
+       } else if (buffer[2] == VS_INPUT_HEADER) {
+               p = buflen >= 5 ? buffer[3] : 0;
+               n = buflen >= 12 ? buffer[12] : 0;
+
+               if (buflen < 13 + p*n || buffer[2] != VS_INPUT_HEADER) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
+                               "interface %d INPUT HEADER descriptor is "
+                               "invalid.\n", dev->udev->devnum,
+                               alts->desc.bInterfaceNumber);
+                       goto error;
+               }
+
+               streaming->header.bNumFormats = p;
+               streaming->header.bEndpointAddress = buffer[6];
+               streaming->header.bmInfo = buffer[7];
+               streaming->header.bTerminalLink = buffer[8];
+               streaming->header.bStillCaptureMethod = buffer[9];
+               streaming->header.bTriggerSupport = buffer[10];
+               streaming->header.bTriggerUsage = buffer[11];
+               streaming->header.bControlSize = n;
+
+               streaming->header.bmaControls = kmalloc(p*n, GFP_KERNEL);
+               if (streaming->header.bmaControls == NULL) {
+                       ret = -ENOMEM;
+                       goto error;
+               }
+
+               memcpy(streaming->header.bmaControls, &buffer[13], p*n);
+       } else {
+               uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
+                       "%d HEADER descriptor not found.\n", dev->udev->devnum,
+                       alts->desc.bInterfaceNumber);
+               goto error;
+       }
+
+       buflen -= buffer[0];
+       buffer += buffer[0];
+
+       _buffer = buffer;
+       _buflen = buflen;
+
+       /* Count the format and frame descriptors. */
+       while (_buflen > 2) {
+               switch (_buffer[2]) {
+               case VS_FORMAT_UNCOMPRESSED:
+               case VS_FORMAT_MJPEG:
+               case VS_FORMAT_FRAME_BASED:
+                       nformats++;
+                       break;
+
+               case VS_FORMAT_DV:
+                       /* DV format has no frame descriptor. We will create a
+                        * dummy frame descriptor with a dummy frame interval.
+                        */
+                       nformats++;
+                       nframes++;
+                       nintervals++;
+                       break;
+
+               case VS_FORMAT_MPEG2TS:
+               case VS_FORMAT_STREAM_BASED:
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
+                               "interface %d FORMAT %u is not supported.\n",
+                               dev->udev->devnum,
+                               alts->desc.bInterfaceNumber, _buffer[2]);
+                       break;
+
+               case VS_FRAME_UNCOMPRESSED:
+               case VS_FRAME_MJPEG:
+                       nframes++;
+                       if (_buflen > 25)
+                               nintervals += _buffer[25] ? _buffer[25] : 3;
+                       break;
+
+               case VS_FRAME_FRAME_BASED:
+                       nframes++;
+                       if (_buflen > 21)
+                               nintervals += _buffer[21] ? _buffer[21] : 3;
+                       break;
+               }
+
+               _buflen -= _buffer[0];
+               _buffer += _buffer[0];
+       }
+
+       if (nformats == 0) {
+               uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface "
+                       "%d has no supported formats defined.\n",
+                       dev->udev->devnum, alts->desc.bInterfaceNumber);
+               goto error;
+       }
+
+       size = nformats * sizeof *format + nframes * sizeof *frame
+            + nintervals * sizeof *interval;
+       format = kzalloc(size, GFP_KERNEL);
+       if (format == NULL) {
+               ret = -ENOMEM;
+               goto error;
+       }
+
+       frame = (struct uvc_frame *)&format[nformats];
+       interval = (__u32 *)&frame[nframes];
+
+       streaming->format = format;
+       streaming->nformats = nformats;
+
+       /* Parse the format descriptors. */
+       while (buflen > 2) {
+               switch (buffer[2]) {
+               case VS_FORMAT_UNCOMPRESSED:
+               case VS_FORMAT_MJPEG:
+               case VS_FORMAT_DV:
+               case VS_FORMAT_FRAME_BASED:
+                       format->frame = frame;
+                       ret = uvc_parse_format(dev, streaming, format,
+                               &interval, buffer, buflen);
+                       if (ret < 0)
+                               goto error;
+
+                       frame += format->nframes;
+                       format++;
+
+                       buflen -= ret;
+                       buffer += ret;
+                       continue;
+
+               default:
+                       break;
+               }
+
+               buflen -= buffer[0];
+               buffer += buffer[0];
+       }
+
+       /* Parse the alternate settings to find the maximum bandwidth. */
+       for (i = 0; i < intf->num_altsetting; ++i) {
+               struct usb_host_endpoint *ep;
+               alts = &intf->altsetting[i];
+               ep = uvc_find_endpoint(alts,
+                               streaming->header.bEndpointAddress);
+               if (ep == NULL)
+                       continue;
+
+               psize = le16_to_cpu(ep->desc.wMaxPacketSize);
+               psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
+               if (psize > streaming->maxpsize)
+                       streaming->maxpsize = psize;
+       }
+
+       list_add_tail(&streaming->list, &dev->streaming);
+       return 0;
+
+error:
+       usb_driver_release_interface(&uvc_driver.driver, intf);
+       usb_put_intf(intf);
+       kfree(streaming->format);
+       kfree(streaming->header.bmaControls);
+       kfree(streaming);
+       return ret;
+}
+
+/* Parse vendor-specific extensions. */
+static int uvc_parse_vendor_control(struct uvc_device *dev,
+       const unsigned char *buffer, int buflen)
+{
+       struct usb_device *udev = dev->udev;
+       struct usb_host_interface *alts = dev->intf->cur_altsetting;
+       struct uvc_entity *unit;
+       unsigned int n, p;
+       int handled = 0;
+
+       switch (le16_to_cpu(dev->udev->descriptor.idVendor)) {
+       case 0x046d:            /* Logitech */
+               if (buffer[1] != 0x41 || buffer[2] != 0x01)
+                       break;
+
+               /* Logitech implements several vendor specific functions
+                * through vendor specific extension units (LXU).
+                *
+                * The LXU descriptors are similar to XU descriptors
+                * (see "USB Device Video Class for Video Devices", section
+                * 3.7.2.6 "Extension Unit Descriptor") with the following
+                * differences:
+                *
+                * ----------------------------------------------------------
+                * 0            bLength         1        Number
+                *      Size of this descriptor, in bytes: 24+p+n*2
+                * ----------------------------------------------------------
+                * 23+p+n       bmControlsType  N       Bitmap
+                *      Individual bits in the set are defined:
+                *      0: Absolute
+                *      1: Relative
+                *
+                *      This bitset is mapped exactly the same as bmControls.
+                * ----------------------------------------------------------
+                * 23+p+n*2     bReserved       1       Boolean
+                * ----------------------------------------------------------
+                * 24+p+n*2     iExtension      1       Index
+                *      Index of a string descriptor that describes this
+                *      extension unit.
+                * ----------------------------------------------------------
+                */
+               p = buflen >= 22 ? buffer[21] : 0;
+               n = buflen >= 25 + p ? buffer[22+p] : 0;
+
+               if (buflen < 25 + p + 2*n) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
+                               "interface %d EXTENSION_UNIT error\n",
+                               udev->devnum, alts->desc.bInterfaceNumber);
+                       break;
+               }
+
+               unit = kzalloc(sizeof *unit + p + 2*n, GFP_KERNEL);
+               if (unit == NULL)
+                       return -ENOMEM;
+
+               unit->id = buffer[3];
+               unit->type = VC_EXTENSION_UNIT;
+               memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
+               unit->extension.bNumControls = buffer[20];
+               unit->extension.bNrInPins =
+                       le16_to_cpup((__le16 *)&buffer[21]);
+               unit->extension.baSourceID = (__u8 *)unit + sizeof *unit;
+               memcpy(unit->extension.baSourceID, &buffer[22], p);
+               unit->extension.bControlSize = buffer[22+p];
+               unit->extension.bmControls = (__u8 *)unit + sizeof *unit + p;
+               unit->extension.bmControlsType = (__u8 *)unit + sizeof *unit
+                                              + p + n;
+               memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
+
+               if (buffer[24+p+2*n] != 0)
+                       usb_string(udev, buffer[24+p+2*n], unit->name,
+                                  sizeof unit->name);
+               else
+                       sprintf(unit->name, "Extension %u", buffer[3]);
+
+               list_add_tail(&unit->list, &dev->entities);
+               handled = 1;
+               break;
+       }
+
+       return handled;
+}
+
+static int uvc_parse_standard_control(struct uvc_device *dev,
+       const unsigned char *buffer, int buflen)
+{
+       struct usb_device *udev = dev->udev;
+       struct uvc_entity *unit, *term;
+       struct usb_interface *intf;
+       struct usb_host_interface *alts = dev->intf->cur_altsetting;
+       unsigned int i, n, p, len;
+       __u16 type;
+
+       switch (buffer[2]) {
+       case VC_HEADER:
+               n = buflen >= 12 ? buffer[11] : 0;
+
+               if (buflen < 12 || buflen < 12 + n) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
+                               "interface %d HEADER error\n", udev->devnum,
+                               alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               dev->uvc_version = le16_to_cpup((__le16 *)&buffer[3]);
+               dev->clock_frequency = le32_to_cpup((__le32 *)&buffer[7]);
+
+               /* Parse all USB Video Streaming interfaces. */
+               for (i = 0; i < n; ++i) {
+                       intf = usb_ifnum_to_if(udev, buffer[12+i]);
+                       if (intf == NULL) {
+                               uvc_trace(UVC_TRACE_DESCR, "device %d "
+                                       "interface %d doesn't exists\n",
+                                       udev->devnum, i);
+                               continue;
+                       }
+
+                       uvc_parse_streaming(dev, intf);
+               }
+               break;
+
+       case VC_INPUT_TERMINAL:
+               if (buflen < 8) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
+                               "interface %d INPUT_TERMINAL error\n",
+                               udev->devnum, alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               /* Make sure the terminal type MSB is not null, otherwise it
+                * could be confused with a unit.
+                */
+               type = le16_to_cpup((__le16 *)&buffer[4]);
+               if ((type & 0xff00) == 0) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
+                               "interface %d INPUT_TERMINAL %d has invalid "
+                               "type 0x%04x, skipping\n", udev->devnum,
+                               alts->desc.bInterfaceNumber,
+                               buffer[3], type);
+                       return 0;
+               }
+
+               n = 0;
+               p = 0;
+               len = 8;
+
+               if (type == ITT_CAMERA) {
+                       n = buflen >= 15 ? buffer[14] : 0;
+                       len = 15;
+
+               } else if (type == ITT_MEDIA_TRANSPORT_INPUT) {
+                       n = buflen >= 9 ? buffer[8] : 0;
+                       p = buflen >= 10 + n ? buffer[9+n] : 0;
+                       len = 10;
+               }
+
+               if (buflen < len + n + p) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
+                               "interface %d INPUT_TERMINAL error\n",
+                               udev->devnum, alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               term = kzalloc(sizeof *term + n + p, GFP_KERNEL);
+               if (term == NULL)
+                       return -ENOMEM;
+
+               term->id = buffer[3];
+               term->type = type | UVC_TERM_INPUT;
+
+               if (UVC_ENTITY_TYPE(term) == ITT_CAMERA) {
+                       term->camera.bControlSize = n;
+                       term->camera.bmControls = (__u8 *)term + sizeof *term;
+                       term->camera.wObjectiveFocalLengthMin =
+                               le16_to_cpup((__le16 *)&buffer[8]);
+                       term->camera.wObjectiveFocalLengthMax =
+                               le16_to_cpup((__le16 *)&buffer[10]);
+                       term->camera.wOcularFocalLength =
+                               le16_to_cpup((__le16 *)&buffer[12]);
+                       memcpy(term->camera.bmControls, &buffer[15], n);
+               } else if (UVC_ENTITY_TYPE(term) == ITT_MEDIA_TRANSPORT_INPUT) {
+                       term->media.bControlSize = n;
+                       term->media.bmControls = (__u8 *)term + sizeof *term;
+                       term->media.bTransportModeSize = p;
+                       term->media.bmTransportModes = (__u8 *)term
+                                                    + sizeof *term + n;
+                       memcpy(term->media.bmControls, &buffer[9], n);
+                       memcpy(term->media.bmTransportModes, &buffer[10+n], p);
+               }
+
+               if (buffer[7] != 0)
+                       usb_string(udev, buffer[7], term->name,
+                                  sizeof term->name);
+               else if (UVC_ENTITY_TYPE(term) == ITT_CAMERA)
+                       sprintf(term->name, "Camera %u", buffer[3]);
+               else if (UVC_ENTITY_TYPE(term) == ITT_MEDIA_TRANSPORT_INPUT)
+                       sprintf(term->name, "Media %u", buffer[3]);
+               else
+                       sprintf(term->name, "Input %u", buffer[3]);
+
+               list_add_tail(&term->list, &dev->entities);
+               break;
+
+       case VC_OUTPUT_TERMINAL:
+               if (buflen < 9) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
+                               "interface %d OUTPUT_TERMINAL error\n",
+                               udev->devnum, alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               /* Make sure the terminal type MSB is not null, otherwise it
+                * could be confused with a unit.
+                */
+               type = le16_to_cpup((__le16 *)&buffer[4]);
+               if ((type & 0xff00) == 0) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
+                               "interface %d OUTPUT_TERMINAL %d has invalid "
+                               "type 0x%04x, skipping\n", udev->devnum,
+                               alts->desc.bInterfaceNumber, buffer[3], type);
+                       return 0;
+               }
+
+               term = kzalloc(sizeof *term, GFP_KERNEL);
+               if (term == NULL)
+                       return -ENOMEM;
+
+               term->id = buffer[3];
+               term->type = type | UVC_TERM_OUTPUT;
+               term->output.bSourceID = buffer[7];
+
+               if (buffer[8] != 0)
+                       usb_string(udev, buffer[8], term->name,
+                                  sizeof term->name);
+               else
+                       sprintf(term->name, "Output %u", buffer[3]);
+
+               list_add_tail(&term->list, &dev->entities);
+               break;
+
+       case VC_SELECTOR_UNIT:
+               p = buflen >= 5 ? buffer[4] : 0;
+
+               if (buflen < 5 || buflen < 6 + p) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
+                               "interface %d SELECTOR_UNIT error\n",
+                               udev->devnum, alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               unit = kzalloc(sizeof *unit + p, GFP_KERNEL);
+               if (unit == NULL)
+                       return -ENOMEM;
+
+               unit->id = buffer[3];
+               unit->type = buffer[2];
+               unit->selector.bNrInPins = buffer[4];
+               unit->selector.baSourceID = (__u8 *)unit + sizeof *unit;
+               memcpy(unit->selector.baSourceID, &buffer[5], p);
+
+               if (buffer[5+p] != 0)
+                       usb_string(udev, buffer[5+p], unit->name,
+                                  sizeof unit->name);
+               else
+                       sprintf(unit->name, "Selector %u", buffer[3]);
+
+               list_add_tail(&unit->list, &dev->entities);
+               break;
+
+       case VC_PROCESSING_UNIT:
+               n = buflen >= 8 ? buffer[7] : 0;
+               p = dev->uvc_version >= 0x0110 ? 10 : 9;
+
+               if (buflen < p + n) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
+                               "interface %d PROCESSING_UNIT error\n",
+                               udev->devnum, alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               unit = kzalloc(sizeof *unit + n, GFP_KERNEL);
+               if (unit == NULL)
+                       return -ENOMEM;
+
+               unit->id = buffer[3];
+               unit->type = buffer[2];
+               unit->processing.bSourceID = buffer[4];
+               unit->processing.wMaxMultiplier =
+                       le16_to_cpup((__le16 *)&buffer[5]);
+               unit->processing.bControlSize = buffer[7];
+               unit->processing.bmControls = (__u8 *)unit + sizeof *unit;
+               memcpy(unit->processing.bmControls, &buffer[8], n);
+               if (dev->uvc_version >= 0x0110)
+                       unit->processing.bmVideoStandards = buffer[9+n];
+
+               if (buffer[8+n] != 0)
+                       usb_string(udev, buffer[8+n], unit->name,
+                                  sizeof unit->name);
+               else
+                       sprintf(unit->name, "Processing %u", buffer[3]);
+
+               list_add_tail(&unit->list, &dev->entities);
+               break;
+
+       case VC_EXTENSION_UNIT:
+               p = buflen >= 22 ? buffer[21] : 0;
+               n = buflen >= 24 + p ? buffer[22+p] : 0;
+
+               if (buflen < 24 + p + n) {
+                       uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
+                               "interface %d EXTENSION_UNIT error\n",
+                               udev->devnum, alts->desc.bInterfaceNumber);
+                       return -EINVAL;
+               }
+
+               unit = kzalloc(sizeof *unit + p + n, GFP_KERNEL);
+               if (unit == NULL)
+                       return -ENOMEM;
+
+               unit->id = buffer[3];
+               unit->type = buffer[2];
+               memcpy(unit->extension.guidExtensionCode, &buffer[4], 16);
+               unit->extension.bNumControls = buffer[20];
+               unit->extension.bNrInPins =
+                       le16_to_cpup((__le16 *)&buffer[21]);
+               unit->extension.baSourceID = (__u8 *)unit + sizeof *unit;
+               memcpy(unit->extension.baSourceID, &buffer[22], p);
+               unit->extension.bControlSize = buffer[22+p];
+               unit->extension.bmControls = (__u8 *)unit + sizeof *unit + p;
+               memcpy(unit->extension.bmControls, &buffer[23+p], n);
+
+               if (buffer[23+p+n] != 0)
+                       usb_string(udev, buffer[23+p+n], unit->name,
+                                  sizeof unit->name);
+               else
+                       sprintf(unit->name, "Extension %u", buffer[3]);
+
+               list_add_tail(&unit->list, &dev->entities);
+               break;
+
+       default:
+               uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE "
+                       "descriptor (%u)\n", buffer[2]);
+               break;
+       }
+
+       return 0;
+}
+
+static int uvc_parse_control(struct uvc_device *dev)
+{
+       struct usb_host_interface *alts = dev->intf->cur_altsetting;
+       unsigned char *buffer = alts->extra;
+       int buflen = alts->extralen;
+       int ret;
+
+       /* Parse the default alternate setting only, as the UVC specification
+        * defines a single alternate setting, the default alternate setting
+        * zero.
+        */
+
+       while (buflen > 2) {
+               if (uvc_parse_vendor_control(dev, buffer, buflen) ||
+                   buffer[1] != USB_DT_CS_INTERFACE)
+                       goto next_descriptor;
+
+               if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)
+                       return ret;
+
+next_descriptor:
+               buflen -= buffer[0];
+               buffer += buffer[0];
+       }
+
+       /* Check if the optional status endpoint is present. */
+       if (alts->desc.bNumEndpoints == 1) {
+               struct usb_host_endpoint *ep = &alts->endpoint[0];
+               struct usb_endpoint_descriptor *desc = &ep->desc;
+
+               if (usb_endpoint_is_int_in(desc) &&
+                   le16_to_cpu(desc->wMaxPacketSize) >= 8 &&
+                   desc->bInterval != 0) {
+                       uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint "
+                               "(addr %02x).\n", desc->bEndpointAddress);
+                       dev->int_ep = ep;
+               }
+       }
+
+       return 0;
+}
+
+/* ------------------------------------------------------------------------
+ * USB probe and disconnect
+ */
+
+/*
+ * Unregister the video devices.
+ */
+static void uvc_unregister_video(struct uvc_device *dev)
+{
+       if (dev->video.vdev) {
+               if (dev->video.vdev->minor == -1)
+                       video_device_release(dev->video.vdev);
+               else
+                       video_unregister_device(dev->video.vdev);
+               dev->video.vdev = NULL;
+       }
+}
+
+/*
+ * Scan the UVC descriptors to locate a chain starting at an Output Terminal
+ * and containing the following units:
+ *
+ * - a USB Streaming Output Terminal
+ * - zero or one Processing Unit
+ * - zero, one or mode single-input Selector Units
+ * - zero or one multiple-input Selector Units, provided all inputs are
+ *   connected to input terminals
+ * - zero, one or mode single-input Extension Units
+ * - one Camera Input Terminal, or one or more External terminals.
+ *
+ * A side forward scan is made on each detected entity to check for additional
+ * extension units.
+ */
+static int uvc_scan_chain_entity(struct uvc_video_device *video,
+       struct uvc_entity *entity)
+{
+       switch (UVC_ENTITY_TYPE(entity)) {
+       case VC_EXTENSION_UNIT:
+               if (uvc_trace_param & UVC_TRACE_PROBE)
+                       printk(" <- XU %d", entity->id);
+
+               if (entity->extension.bNrInPins != 1) {
+                       uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more "
+                               "than 1 input pin.\n", entity->id);
+                       return -1;
+               }
+
+               list_add_tail(&entity->chain, &video->extensions);
+               break;
+
+       case VC_PROCESSING_UNIT:
+               if (uvc_trace_param & UVC_TRACE_PROBE)
+                       printk(" <- PU %d", entity->id);
+
+               if (video->processing != NULL) {
+                       uvc_trace(UVC_TRACE_DESCR, "Found multiple "
+                               "Processing Units in chain.\n");
+                       return -1;
+               }
+
+               video->processing = entity;
+               break;
+
+       case VC_SELECTOR_UNIT:
+               if (uvc_trace_param & UVC_TRACE_PROBE)
+                       printk(" <- SU %d", entity->id);
+
+               /* Single-input selector units are ignored. */
+               if (entity->selector.bNrInPins == 1)
+                       break;
+
+               if (video->selector != NULL) {
+                       uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector "
+                               "Units in chain.\n");
+                       return -1;
+               }
+
+               video->selector = entity;
+               break;
+
+       case ITT_VENDOR_SPECIFIC:
+       case ITT_CAMERA:
+       case ITT_MEDIA_TRANSPORT_INPUT:
+               if (uvc_trace_param & UVC_TRACE_PROBE)
+                       printk(" <- IT %d\n", entity->id);
+
+               list_add_tail(&entity->chain, &video->iterms);
+               break;
+
+       default:
+               uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type "
+                       "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity));
+               return -1;
+       }
+
+       return 0;
+}
+
+static int uvc_scan_chain_forward(struct uvc_video_device *video,
+       struct uvc_entity *entity, struct uvc_entity *prev)
+{
+       struct uvc_entity *forward;
+       int found;
+
+       /* Forward scan */
+       forward = NULL;
+       found = 0;
+
+       while (1) {
+               forward = uvc_entity_by_reference(video->dev, entity->id,
+                       forward);
+               if (forward == NULL)
+                       break;
+
+               if (UVC_ENTITY_TYPE(forward) != VC_EXTENSION_UNIT ||
+                   forward == prev)
+                       continue;
+
+               if (forward->extension.bNrInPins != 1) {
+                       uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has"
+                               "more than 1 input pin.\n", entity->id);
+                       return -1;
+               }
+
+               list_add_tail(&forward->chain, &video->extensions);
+               if (uvc_trace_param & UVC_TRACE_PROBE) {
+                       if (!found)
+                               printk(" (-> XU");
+
+                       printk(" %d", forward->id);
+                       found = 1;
+               }
+       }
+       if (found)
+               printk(")");
+
+       return 0;
+}
+
+static int uvc_scan_chain_backward(struct uvc_video_device *video,
+       struct uvc_entity *entity)
+{
+       struct uvc_entity *term;
+       int id = -1, i;
+
+       switch (UVC_ENTITY_TYPE(entity)) {
+       case VC_EXTENSION_UNIT:
+               id = entity->extension.baSourceID[0];
+               break;
+
+       case VC_PROCESSING_UNIT:
+               id = entity->processing.bSourceID;
+               break;
+
+       case VC_SELECTOR_UNIT:
+               /* Single-input selector units are ignored. */
+               if (entity->selector.bNrInPins == 1) {
+                       id = entity->selector.baSourceID[0];
+                       break;
+               }
+
+               if (uvc_trace_param & UVC_TRACE_PROBE)
+                       printk(" <- IT");
+
+               video->selector = entity;
+               for (i = 0; i < entity->selector.bNrInPins; ++i) {
+                       id = entity->selector.baSourceID[i];
+                       term = uvc_entity_by_id(video->dev, id);
+                       if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) {
+                               uvc_trace(UVC_TRACE_DESCR, "Selector unit %d "
+                                       "input %d isn't connected to an "
+                                       "input terminal\n", entity->id, i);
+                               return -1;
+                       }
+
+                       if (uvc_trace_param & UVC_TRACE_PROBE)
+                               printk(" %d", term->id);
+
+                       list_add_tail(&term->chain, &video->iterms);
+                       uvc_scan_chain_forward(video, term, entity);
+               }
+
+               if (uvc_trace_param & UVC_TRACE_PROBE)
+                       printk("\n");
+
+               id = 0;
+               break;
+       }
+
+       return id;
+}
+
+static int uvc_scan_chain(struct uvc_video_device *video)
+{
+       struct uvc_entity *entity, *prev;
+       int id;
+
+       entity = video->oterm;
+       uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain: OT %d", entity->id);
+       id = entity->output.bSourceID;
+       while (id != 0) {
+               prev = entity;
+               entity = uvc_entity_by_id(video->dev, id);
+               if (entity == NULL) {
+                       uvc_trace(UVC_TRACE_DESCR, "Found reference to "
+                               "unknown entity %d.\n", id);
+                       return -1;
+               }
+
+               /* Process entity */
+               if (uvc_scan_chain_entity(video, entity) < 0)
+                       return -1;
+
+               /* Forward scan */
+               if (uvc_scan_chain_forward(video, entity, prev) < 0)
+                       return -1;
+
+               /* Stop when a terminal is found. */
+               if (!UVC_ENTITY_IS_UNIT(entity))
+                       break;
+
+               /* Backward scan */
+               id = uvc_scan_chain_backward(video, entity);
+               if (id < 0)
+                       return id;
+       }
+
+       /* Initialize the video buffers queue. */
+       uvc_queue_init(&video->queue);
+
+       return 0;
+}
+
+/*
+ * Register the video devices.
+ *
+ * The driver currently supports a single video device per control interface
+ * only. The terminal and units must match the following structure:
+ *
+ * ITT_CAMERA -> VC_PROCESSING_UNIT -> VC_EXTENSION_UNIT{0,n} -> TT_STREAMING
+ *
+ * The Extension Units, if present, must have a single input pin. The
+ * Processing Unit and Extension Units can be in any order. Additional
+ * Extension Units connected to the main chain as single-unit branches are
+ * also supported.
+ */
+static int uvc_register_video(struct uvc_device *dev)
+{
+       struct video_device *vdev;
+       struct uvc_entity *term;
+       int found = 0, ret;
+
+       /* Check if the control interface matches the structure we expect. */
+       list_for_each_entry(term, &dev->entities, list) {
+               struct uvc_streaming *streaming;
+
+               if (UVC_ENTITY_TYPE(term) != TT_STREAMING)
+                       continue;
+
+               memset(&dev->video, 0, sizeof dev->video);
+               mutex_init(&dev->video.ctrl_mutex);
+               INIT_LIST_HEAD(&dev->video.iterms);
+               INIT_LIST_HEAD(&dev->video.extensions);
+               dev->video.oterm = term;
+               dev->video.dev = dev;
+               if (uvc_scan_chain(&dev->video) < 0)
+                       continue;
+
+               list_for_each_entry(streaming, &dev->streaming, list) {
+                       if (streaming->header.bTerminalLink == term->id) {
+                               dev->video.streaming = streaming;
+                               found = 1;
+                               break;
+                       }
+               }
+
+               if (found)
+                       break;
+       }
+
+       if (!found) {
+               uvc_printk(KERN_INFO, "No valid video chain found.\n");
+               return -1;
+       }
+
+       if (uvc_trace_param & UVC_TRACE_PROBE) {
+               uvc_printk(KERN_INFO, "Found a valid video chain (");
+               list_for_each_entry(term, &dev->video.iterms, chain) {
+                       printk("%d", term->id);
+                       if (term->chain.next != &dev->video.iterms)
+                               printk(",");
+               }
+               printk(" -> %d).\n", dev->video.oterm->id);
+       }
+
+       /* Initialize the streaming interface with default streaming
+        * parameters.
+        */
+       if ((ret = uvc_video_init(&dev->video)) < 0) {
+               uvc_printk(KERN_ERR, "Failed to initialize the device "
+                       "(%d).\n", ret);
+               return ret;
+       }
+
+       /* Register the device with V4L. */
+       vdev = video_device_alloc();
+       if (vdev == NULL)
+               return -1;
+
+       /* We already hold a reference to dev->udev. The video device will be
+        * unregistered before the reference is released, so we don't need to
+        * get another one.
+        */
+       vdev->dev = &dev->intf->dev;
+       vdev->type = 0;
+       vdev->type2 = 0;
+       vdev->minor = -1;
+       vdev->fops = &uvc_fops;
+       vdev->release = video_device_release;
+       strncpy(vdev->name, dev->name, sizeof vdev->name);
+
+       /* Set the driver data before calling video_register_device, otherwise
+        * uvc_v4l2_open might race us.
+        *
+        * FIXME: usb_set_intfdata hasn't been called so far. Is that a
+        *        problem ? Does any function which could be called here get
+        *        a pointer to the usb_interface ?
+        */
+       dev->video.vdev = vdev;
+       video_set_drvdata(vdev, &dev->video);
+
+       if (video_register_device(vdev, VFL_TYPE_GRABBER, -1) < 0) {
+               dev->video.vdev = NULL;
+               video_device_release(vdev);
+               return -1;
+       }
+
+       return 0;
+}
+
+/*
+ * Delete the UVC device.
+ *
+ * Called by the kernel when the last reference to the uvc_device structure
+ * is released.
+ *
+ * Unregistering the video devices is done here because every opened instance
+ * must be closed before the device can be unregistered. An alternative would
+ * have been to use another reference count for uvc_v4l2_open/uvc_release, and
+ * unregister the video devices on disconnect when that reference count drops
+ * to zero.
+ *
+ * As this function is called after or during disconnect(), all URBs have
+ * already been canceled by the USB core. There is no need to kill the
+ * interrupt URB manually.
+ */
+void uvc_delete(struct kref *kref)
+{
+       struct uvc_device *dev = container_of(kref, struct uvc_device, kref);
+       struct list_head *p, *n;
+
+       /* Unregister the video device */
+       uvc_unregister_video(dev);
+       usb_put_intf(dev->intf);
+       usb_put_dev(dev->udev);
+
+       uvc_status_cleanup(dev);
+       uvc_ctrl_cleanup_device(dev);
+
+       list_for_each_safe(p, n, &dev->entities) {
+               struct uvc_entity *entity;
+               entity = list_entry(p, struct uvc_entity, list);
+               kfree(entity);
+       }
+
+       list_for_each_safe(p, n, &dev->streaming) {
+               struct uvc_streaming *streaming;
+               streaming = list_entry(p, struct uvc_streaming, list);
+               usb_driver_release_interface(&uvc_driver.driver,
+                       streaming->intf);
+               usb_put_intf(streaming->intf);
+               kfree(streaming->format);
+               kfree(streaming->header.bmaControls);
+               kfree(streaming);
+       }
+
+       kfree(dev);
+}
+
+static int uvc_probe(struct usb_interface *intf,
+                    const struct usb_device_id *id)
+{
+       struct usb_device *udev = interface_to_usbdev(intf);
+       struct uvc_device *dev;
+       int ret;
+
+       if (id->idVendor && id->idProduct)
+               uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s "
+                               "(%04x:%04x)\n", udev->devpath, id->idVendor,
+                               id->idProduct);
+       else
+               uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n",
+                               udev->devpath);
+
+       /* Allocate memory for the device and initialize it */
+       if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)
+               return -ENOMEM;
+
+       INIT_LIST_HEAD(&dev->entities);
+       INIT_LIST_HEAD(&dev->streaming);
+       kref_init(&dev->kref);
+
+       dev->udev = usb_get_dev(udev);
+       dev->intf = usb_get_intf(intf);
+       dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
+       dev->quirks = id->driver_info | uvc_quirks_param;
+
+       if (udev->product != NULL)
+               strncpy(dev->name, udev->product, sizeof dev->name);
+       else
+               snprintf(dev->name, sizeof dev->name,
+                       "UVC Camera (%04x:%04x)",
+                       le16_to_cpu(udev->descriptor.idVendor),
+                       le16_to_cpu(udev->descriptor.idProduct));
+
+       /* Parse the Video Class control descriptor */
+       if (uvc_parse_control(dev) < 0) {
+               uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
+                       "descriptors.\n");
+               goto error;
+       }
+
+       uvc_printk(KERN_INFO, "Found UVC %u.%02u device %s (%04x:%04x)\n",
+               dev->uvc_version >> 8, dev->uvc_version & 0xff,
+               udev->product ? udev->product : "<unnamed>",
+               le16_to_cpu(udev->descriptor.idVendor),
+               le16_to_cpu(udev->descriptor.idProduct));
+
+       if (uvc_quirks_param != 0) {
+               uvc_printk(KERN_INFO, "Forcing device quirks 0x%x by module "
+                       "parameter for testing purpose.\n", uvc_quirks_param);
+               uvc_printk(KERN_INFO, "Please report required quirks to the "
+                       "linux-uvc-devel mailing list.\n");
+       }
+
+       /* Initialize controls */
+       if (uvc_ctrl_init_device(dev) < 0)
+               goto error;
+
+       /* Register the video devices */
+       if (uvc_register_video(dev) < 0)
+               goto error;
+
+       /* Save our data pointer in the interface data */
+       usb_set_intfdata(intf, dev);
+
+       /* Initialize the interrupt URB */
+       if ((ret = uvc_status_init(dev)) < 0) {
+               uvc_printk(KERN_INFO, "Unable to initialize the status "
+                       "endpoint (%d), status interrupt will not be "
+                       "supported.\n", ret);
+       }
+
+       uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n");
+       return 0;
+
+error:
+       kref_put(&dev->kref, uvc_delete);
+       return -ENODEV;
+}
+
+static void uvc_disconnect(struct usb_interface *intf)
+{
+       struct uvc_device *dev = usb_get_intfdata(intf);
+
+       /* Set the USB interface data to NULL. This can be done outside the
+        * lock, as there's no other reader.
+        */
+       usb_set_intfdata(intf, NULL);
+
+       if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOSTREAMING)
+               return;
+
+       /* uvc_v4l2_open() might race uvc_disconnect(). A static driver-wide
+        * lock is needed to prevent uvc_disconnect from releasing its
+        * reference to the uvc_device instance after uvc_v4l2_open() received
+        * the pointer to the device (video_devdata) but before it got the
+        * chance to increase the reference count (kref_get).
+        */
+       mutex_lock(&uvc_driver.open_mutex);
+
+       dev->state |= UVC_DEV_DISCONNECTED;
+       kref_put(&dev->kref, uvc_delete);
+
+       mutex_unlock(&uvc_driver.open_mutex);
+}
+
+static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
+{
+       struct uvc_device *dev = usb_get_intfdata(intf);
+
+       uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n",
+               intf->cur_altsetting->desc.bInterfaceNumber);
+
+       /* Controls are cached on the fly so they don't need to be saved. */
+       if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOCONTROL)
+               return uvc_status_suspend(dev);
+
+       if (dev->video.streaming->intf != intf) {
+               uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB "
+                               "interface mismatch.\n");
+               return -EINVAL;
+       }
+
+       return uvc_video_suspend(&dev->video);
+}
+
+static int uvc_resume(struct usb_interface *intf)
+{
+       struct uvc_device *dev = usb_get_intfdata(intf);
+       int ret;
+
+       uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n",
+               intf->cur_altsetting->desc.bInterfaceNumber);
+
+       if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOCONTROL) {
+               if ((ret = uvc_ctrl_resume_device(dev)) < 0)
+                       return ret;
+
+               return uvc_status_resume(dev);
+       }
+
+       if (dev->video.streaming->intf != intf) {
+               uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB "
+                               "interface mismatch.\n");
+               return -EINVAL;
+       }
+
+       return uvc_video_resume(&dev->video);
+}
+
+/* ------------------------------------------------------------------------
+ * Driver initialization and cleanup
+ */
+
+/*
+ * The Logitech cameras listed below have their interface class set to
+ * VENDOR_SPEC because they don't announce themselves as UVC devices, even
+ * though they are compliant.
+ */
+static struct usb_device_id uvc_ids[] = {
+       /* ALi M5606 (Clevo M540SR) */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x0402,
+         .idProduct            = 0x5606,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Creative Live! Optia */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x041e,
+         .idProduct            = 0x4057,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Microsoft Lifecam NX-6000 */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x045e,
+         .idProduct            = 0x00f8,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Microsoft Lifecam VX-7000 */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x045e,
+         .idProduct            = 0x0723,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Logitech Quickcam Fusion */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x046d,
+         .idProduct            = 0x08c1,
+         .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0 },
+       /* Logitech Quickcam Orbit MP */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x046d,
+         .idProduct            = 0x08c2,
+         .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0 },
+       /* Logitech Quickcam Pro for Notebook */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x046d,
+         .idProduct            = 0x08c3,
+         .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0 },
+       /* Logitech Quickcam Pro 5000 */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x046d,
+         .idProduct            = 0x08c5,
+         .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0 },
+       /* Logitech Quickcam OEM Dell Notebook */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x046d,
+         .idProduct            = 0x08c6,
+         .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0 },
+       /* Logitech Quickcam OEM Cisco VT Camera II */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x046d,
+         .idProduct            = 0x08c7,
+         .bInterfaceClass      = USB_CLASS_VENDOR_SPEC,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0 },
+       /* Apple Built-In iSight */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x05ac,
+         .idProduct            = 0x8501,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX
+                               | UVC_QUIRK_BUILTIN_ISIGHT },
+       /* Genesys Logic USB 2.0 PC Camera */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x05e3,
+         .idProduct            = 0x0505,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_STREAM_NO_FID },
+       /* Silicon Motion SM371 */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x090c,
+         .idProduct            = 0xb371,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* MT6227 */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x0e8d,
+         .idProduct            = 0x0004,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Syntek (HP Spartan) */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x174f,
+         .idProduct            = 0x5212,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_STREAM_NO_FID },
+       /* Syntek (Asus U3S) */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x174f,
+         .idProduct            = 0x8a33,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_STREAM_NO_FID },
+       /* Ecamm Pico iMage */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x18cd,
+         .idProduct            = 0xcafe,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_EXTRAFIELDS },
+       /* Bodelin ProScopeHR */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_DEV_HI
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x19ab,
+         .idProduct            = 0x1000,
+         .bcdDevice_hi         = 0x0126,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_STATUS_INTERVAL },
+       /* SiGma Micro USB Web Camera */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x1c4f,
+         .idProduct            = 0x3000,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX
+                               | UVC_QUIRK_IGNORE_SELECTOR_UNIT},
+       /* Acer OEM Webcam - Unknown vendor */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x5986,
+         .idProduct            = 0x0100,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Packard Bell OEM Webcam */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x5986,
+         .idProduct            = 0x0101,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Acer Crystal Eye webcam */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x5986,
+         .idProduct            = 0x0102,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Acer OrbiCam - Unknown vendor */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x5986,
+         .idProduct            = 0x0200,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Generic USB Video Class */
+       { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },
+       {}
+};
+
+MODULE_DEVICE_TABLE(usb, uvc_ids);
+
+struct uvc_driver uvc_driver = {
+       .driver = {
+               .name           = "uvcvideo",
+               .probe          = uvc_probe,
+               .disconnect     = uvc_disconnect,
+               .suspend        = uvc_suspend,
+               .resume         = uvc_resume,
+               .id_table       = uvc_ids,
+               .supports_autosuspend = 1,
+       },
+};
+
+static int __init uvc_init(void)
+{
+       int result;
+
+       INIT_LIST_HEAD(&uvc_driver.devices);
+       INIT_LIST_HEAD(&uvc_driver.controls);
+       mutex_init(&uvc_driver.open_mutex);
+       mutex_init(&uvc_driver.ctrl_mutex);
+
+       uvc_ctrl_init();
+
+       result = usb_register(&uvc_driver.driver);
+       if (result == 0)
+               printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n");
+       return result;
+}
+
+static void __exit uvc_cleanup(void)
+{
+       usb_deregister(&uvc_driver.driver);
+}
+
+module_init(uvc_init);
+module_exit(uvc_cleanup);
+
+module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(quirks, "Forced device quirks");
+module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(trace, "Trace level bitmask");
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRIVER_VERSION);
diff --git a/drivers/media/video/uvc/uvc_isight.c b/drivers/media/video/uvc/uvc_isight.c
new file mode 100644 (file)
index 0000000..37bdefd
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ *      uvc_isight.c  --  USB Video Class driver - iSight support
+ *
+ *     Copyright (C) 2006-2007
+ *             Ivan N. Zlatev <contact@i-nz.net>
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation; either version 2 of the License, or
+ *      (at your option) any later version.
+ *
+ */
+
+#include <linux/usb.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+
+#include "uvcvideo.h"
+
+/* Built-in iSight webcams implements most of UVC 1.0 except a
+ * different packet format. Instead of sending a header at the
+ * beginning of each isochronous transfer payload, the webcam sends a
+ * single header per image (on its own in a packet), followed by
+ * packets containing data only.
+ *
+ * Offset   Size (bytes)       Description
+ * ------------------------------------------------------------------
+ * 0x00        1       Header length
+ * 0x01        1       Flags (UVC-compliant)
+ * 0x02        4       Always equal to '11223344'
+ * 0x06        8       Always equal to 'deadbeefdeadface'
+ * 0x0e        16      Unknown
+ *
+ * The header can be prefixed by an optional, unknown-purpose byte.
+ */
+
+static int isight_decode(struct uvc_video_queue *queue, struct uvc_buffer *buf,
+               const __u8 *data, unsigned int len)
+{
+       static const __u8 hdr[] = {
+               0x11, 0x22, 0x33, 0x44,
+               0xde, 0xad, 0xbe, 0xef,
+               0xde, 0xad, 0xfa, 0xce
+       };
+
+       unsigned int maxlen, nbytes;
+       __u8 *mem;
+       int is_header = 0;
+
+       if (buf == NULL)
+               return 0;
+
+       if ((len >= 14 && memcmp(&data[2], hdr, 12) == 0) ||
+           (len >= 15 && memcmp(&data[3], hdr, 12) == 0)) {
+               uvc_trace(UVC_TRACE_FRAME, "iSight header found\n");
+               is_header = 1;
+       }
+
+       /* Synchronize to the input stream by waiting for a header packet. */
+       if (buf->state != UVC_BUF_STATE_ACTIVE) {
+               if (!is_header) {
+                       uvc_trace(UVC_TRACE_FRAME, "Dropping packet (out of "
+                                 "sync).\n");
+                       return 0;
+               }
+
+               buf->state = UVC_BUF_STATE_ACTIVE;
+       }
+
+       /* Mark the buffer as done if we're at the beginning of a new frame.
+        *
+        * Empty buffers (bytesused == 0) don't trigger end of frame detection
+        * as it doesn't make sense to return an empty buffer.
+        */
+       if (is_header && buf->buf.bytesused != 0) {
+               buf->state = UVC_BUF_STATE_DONE;
+               return -EAGAIN;
+       }
+
+       /* Copy the video data to the buffer. Skip header packets, as they
+        * contain no data.
+        */
+       if (!is_header) {
+               maxlen = buf->buf.length - buf->buf.bytesused;
+               mem = queue->mem + buf->buf.m.offset + buf->buf.bytesused;
+               nbytes = min(len, maxlen);
+               memcpy(mem, data, nbytes);
+               buf->buf.bytesused += nbytes;
+
+               if (len > maxlen || buf->buf.bytesused == buf->buf.length) {
+                       uvc_trace(UVC_TRACE_FRAME, "Frame complete "
+                                 "(overflow).\n");
+                       buf->state = UVC_BUF_STATE_DONE;
+               }
+       }
+
+       return 0;
+}
+
+void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video,
+               struct uvc_buffer *buf)
+{
+       int ret, i;
+
+       for (i = 0; i < urb->number_of_packets; ++i) {
+               if (urb->iso_frame_desc[i].status < 0) {
+                       uvc_trace(UVC_TRACE_FRAME, "USB isochronous frame "
+                                 "lost (%d).\n",
+                                 urb->iso_frame_desc[i].status);
+               }
+
+               /* Decode the payload packet.
+                * uvc_video_decode is entered twice when a frame transition
+                * has been detected because the end of frame can only be
+                * reliably detected when the first packet of the new frame
+                * is processed. The first pass detects the transition and
+                * closes the previous frame's buffer, the second pass
+                * processes the data of the first payload of the new frame.
+                */
+               do {
+                       ret = isight_decode(&video->queue, buf,
+                                       urb->transfer_buffer +
+                                       urb->iso_frame_desc[i].offset,
+                                       urb->iso_frame_desc[i].actual_length);
+
+                       if (buf == NULL)
+                               break;
+
+                       if (buf->state == UVC_BUF_STATE_DONE ||
+                           buf->state == UVC_BUF_STATE_ERROR)
+                               buf = uvc_queue_next_buffer(&video->queue, buf);
+               } while (ret == -EAGAIN);
+       }
+}
diff --git a/drivers/media/video/uvc/uvc_queue.c b/drivers/media/video/uvc/uvc_queue.c
new file mode 100644 (file)
index 0000000..0923f0e
--- /dev/null
@@ -0,0 +1,477 @@
+/*
+ *      uvc_queue.c  --  USB Video Class driver - Buffers management
+ *
+ *      Copyright (C) 2005-2008
+ *          Laurent Pinchart (laurent.pinchart@skynet.be)
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation; either version 2 of the License, or
+ *      (at your option) any later version.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+#include <linux/videodev2.h>
+#include <linux/vmalloc.h>
+#include <linux/wait.h>
+#include <asm/atomic.h>
+
+#include "uvcvideo.h"
+
+/* ------------------------------------------------------------------------
+ * Video buffers queue management.
+ *
+ * Video queues is initialized by uvc_queue_init(). The function performs
+ * basic initialization of the uvc_video_queue struct and never fails.
+ *
+ * Video buffer allocation and freeing are performed by uvc_alloc_buffers and
+ * uvc_free_buffers respectively. The former acquires the video queue lock,
+ * while the later must be called with the lock held (so that allocation can
+ * free previously allocated buffers). Trying to free buffers that are mapped
+ * to user space will return -EBUSY.
+ *
+ * Video buffers are managed using two queues. However, unlike most USB video
+ * drivers which use an in queue and an out queue, we use a main queue which
+ * holds all queued buffers (both 'empty' and 'done' buffers), and an irq
+ * queue which holds empty buffers. This design (copied from video-buf)
+ * minimizes locking in interrupt, as only one queue is shared between
+ * interrupt and user contexts.
+ *
+ * Use cases
+ * ---------
+ *
+ * Unless stated otherwise, all operations which modify the irq buffers queue
+ * are protected by the irq spinlock.
+ *
+ * 1. The user queues the buffers, starts streaming and dequeues a buffer.
+ *
+ *    The buffers are added to the main and irq queues. Both operations are
+ *    protected by the queue lock, and the latert is protected by the irq
+ *    spinlock as well.
+ *
+ *    The completion handler fetches a buffer from the irq queue and fills it
+ *    with video data. If no buffer is available (irq queue empty), the handler
+ *    returns immediately.
+ *
+ *    When the buffer is full, the completion handler removes it from the irq
+ *    queue, marks it as ready (UVC_BUF_STATE_DONE) and wake its wait queue.
+ *    At that point, any process waiting on the buffer will be woken up. If a
+ *    process tries to dequeue a buffer after it has been marked ready, the
+ *    dequeing will succeed immediately.
+ *
+ * 2. Buffers are queued, user is waiting on a buffer and the device gets
+ *    disconnected.
+ *
+ *    When the device is disconnected, the kernel calls the completion handler
+ *    with an appropriate status code. The handler marks all buffers in the
+ *    irq queue as being erroneous (UVC_BUF_STATE_ERROR) and wakes them up so
+ *    that any process waiting on a buffer gets woken up.
+ *
+ *    Waking up up the first buffer on the irq list is not enough, as the
+ *    process waiting on the buffer might restart the dequeue operation
+ *    immediately.
+ *
+ */
+
+void uvc_queue_init(struct uvc_video_queue *queue)
+{
+       mutex_init(&queue->mutex);
+       spin_lock_init(&queue->irqlock);
+       INIT_LIST_HEAD(&queue->mainqueue);
+       INIT_LIST_HEAD(&queue->irqqueue);
+}
+
+/*
+ * Allocate the video buffers.
+ *
+ * Pages are reserved to make sure they will not be swaped, as they will be
+ * filled in URB completion handler.
+ *
+ * Buffers will be individually mapped, so they must all be page aligned.
+ */
+int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers,
+               unsigned int buflength)
+{
+       unsigned int bufsize = PAGE_ALIGN(buflength);
+       unsigned int i;
+       void *mem = NULL;
+       int ret;
+
+       if (nbuffers > UVC_MAX_VIDEO_BUFFERS)
+               nbuffers = UVC_MAX_VIDEO_BUFFERS;
+
+       mutex_lock(&queue->mutex);
+
+       if ((ret = uvc_free_buffers(queue)) < 0)
+               goto done;
+
+       /* Bail out if no buffers should be allocated. */
+       if (nbuffers == 0)
+               goto done;
+
+       /* Decrement the number of buffers until allocation succeeds. */
+       for (; nbuffers > 0; --nbuffers) {
+               mem = vmalloc_32(nbuffers * bufsize);
+               if (mem != NULL)
+                       break;
+       }
+
+       if (mem == NULL) {
+               ret = -ENOMEM;
+               goto done;
+       }
+
+       for (i = 0; i < nbuffers; ++i) {
+               memset(&queue->buffer[i], 0, sizeof queue->buffer[i]);
+               queue->buffer[i].buf.index = i;
+               queue->buffer[i].buf.m.offset = i * bufsize;
+               queue->buffer[i].buf.length = buflength;
+               queue->buffer[i].buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+               queue->buffer[i].buf.sequence = 0;
+               queue->buffer[i].buf.field = V4L2_FIELD_NONE;
+               queue->buffer[i].buf.memory = V4L2_MEMORY_MMAP;
+               queue->buffer[i].buf.flags = 0;
+               init_waitqueue_head(&queue->buffer[i].wait);
+       }
+
+       queue->mem = mem;
+       queue->count = nbuffers;
+       queue->buf_size = bufsize;
+       ret = nbuffers;
+
+done:
+       mutex_unlock(&queue->mutex);
+       return ret;
+}
+
+/*
+ * Free the video buffers.
+ *
+ * This function must be called with the queue lock held.
+ */
+int uvc_free_buffers(struct uvc_video_queue *queue)
+{
+       unsigned int i;
+
+       for (i = 0; i < queue->count; ++i) {
+               if (queue->buffer[i].vma_use_count != 0)
+                       return -EBUSY;
+       }
+
+       if (queue->count) {
+               vfree(queue->mem);
+               queue->count = 0;
+       }
+
+       return 0;
+}
+
+static void __uvc_query_buffer(struct uvc_buffer *buf,
+               struct v4l2_buffer *v4l2_buf)
+{
+       memcpy(v4l2_buf, &buf->buf, sizeof *v4l2_buf);
+
+       if (buf->vma_use_count)
+               v4l2_buf->flags |= V4L2_BUF_FLAG_MAPPED;
+
+       switch (buf->state) {
+       case UVC_BUF_STATE_ERROR:
+       case UVC_BUF_STATE_DONE:
+               v4l2_buf->flags |= V4L2_BUF_FLAG_DONE;
+               break;
+       case UVC_BUF_STATE_QUEUED:
+       case UVC_BUF_STATE_ACTIVE:
+               v4l2_buf->flags |= V4L2_BUF_FLAG_QUEUED;
+               break;
+       case UVC_BUF_STATE_IDLE:
+       default:
+               break;
+       }
+}
+
+int uvc_query_buffer(struct uvc_video_queue *queue,
+               struct v4l2_buffer *v4l2_buf)
+{
+       int ret = 0;
+
+       mutex_lock(&queue->mutex);
+       if (v4l2_buf->index >= queue->count) {
+               ret = -EINVAL;
+               goto done;
+       }
+
+       __uvc_query_buffer(&queue->buffer[v4l2_buf->index], v4l2_buf);
+
+done:
+       mutex_unlock(&queue->mutex);
+       return ret;
+}
+
+/*
+ * Queue a video buffer. Attempting to queue a buffer that has already been
+ * queued will return -EINVAL.
+ */
+int uvc_queue_buffer(struct uvc_video_queue *queue,
+       struct v4l2_buffer *v4l2_buf)
+{
+       struct uvc_buffer *buf;
+       unsigned long flags;
+       int ret = 0;
+
+       uvc_trace(UVC_TRACE_CAPTURE, "Queuing buffer %u.\n", v4l2_buf->index);
+
+       if (v4l2_buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
+           v4l2_buf->memory != V4L2_MEMORY_MMAP) {
+               uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) "
+                       "and/or memory (%u).\n", v4l2_buf->type,
+                       v4l2_buf->memory);
+               return -EINVAL;
+       }
+
+       mutex_lock(&queue->mutex);
+       if (v4l2_buf->index >= queue->count)  {
+               uvc_trace(UVC_TRACE_CAPTURE, "[E] Out of range index.\n");
+               ret = -EINVAL;
+               goto done;
+       }
+
+       buf = &queue->buffer[v4l2_buf->index];
+       if (buf->state != UVC_BUF_STATE_IDLE) {
+               uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state "
+                       "(%u).\n", buf->state);
+               ret = -EINVAL;
+               goto done;
+       }
+
+       spin_lock_irqsave(&queue->irqlock, flags);
+       if (queue->flags & UVC_QUEUE_DISCONNECTED) {
+               spin_unlock_irqrestore(&queue->irqlock, flags);
+               ret = -ENODEV;
+               goto done;
+       }
+       buf->state = UVC_BUF_STATE_QUEUED;
+       buf->buf.bytesused = 0;
+       list_add_tail(&buf->stream, &queue->mainqueue);
+       list_add_tail(&buf->queue, &queue->irqqueue);
+       spin_unlock_irqrestore(&queue->irqlock, flags);
+
+done:
+       mutex_unlock(&queue->mutex);
+       return ret;
+}
+
+static int uvc_queue_waiton(struct uvc_buffer *buf, int nonblocking)
+{
+       if (nonblocking) {
+               return (buf->state != UVC_BUF_STATE_QUEUED &&
+                       buf->state != UVC_BUF_STATE_ACTIVE)
+                       ? 0 : -EAGAIN;
+       }
+
+       return wait_event_interruptible(buf->wait,
+               buf->state != UVC_BUF_STATE_QUEUED &&
+               buf->state != UVC_BUF_STATE_ACTIVE);
+}
+
+/*
+ * Dequeue a video buffer. If nonblocking is false, block until a buffer is
+ * available.
+ */
+int uvc_dequeue_buffer(struct uvc_video_queue *queue,
+               struct v4l2_buffer *v4l2_buf, int nonblocking)
+{
+       struct uvc_buffer *buf;
+       int ret = 0;
+
+       if (v4l2_buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
+           v4l2_buf->memory != V4L2_MEMORY_MMAP) {
+               uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) "
+                       "and/or memory (%u).\n", v4l2_buf->type,
+                       v4l2_buf->memory);
+               return -EINVAL;
+       }
+
+       mutex_lock(&queue->mutex);
+       if (list_empty(&queue->mainqueue)) {
+               uvc_trace(UVC_TRACE_CAPTURE, "[E] Empty buffer queue.\n");
+               ret = -EINVAL;
+               goto done;
+       }
+
+       buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream);
+       if ((ret = uvc_queue_waiton(buf, nonblocking)) < 0)
+               goto done;
+
+       uvc_trace(UVC_TRACE_CAPTURE, "Dequeuing buffer %u (%u, %u bytes).\n",
+               buf->buf.index, buf->state, buf->buf.bytesused);
+
+       switch (buf->state) {
+       case UVC_BUF_STATE_ERROR:
+               uvc_trace(UVC_TRACE_CAPTURE, "[W] Corrupted data "
+                       "(transmission error).\n");
+               ret = -EIO;
+       case UVC_BUF_STATE_DONE:
+               buf->state = UVC_BUF_STATE_IDLE;
+               break;
+
+       case UVC_BUF_STATE_IDLE:
+       case UVC_BUF_STATE_QUEUED:
+       case UVC_BUF_STATE_ACTIVE:
+       default:
+               uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state %u "
+                       "(driver bug?).\n", buf->state);
+               ret = -EINVAL;
+               goto done;
+       }
+
+       list_del(&buf->stream);
+       __uvc_query_buffer(buf, v4l2_buf);
+
+done:
+       mutex_unlock(&queue->mutex);
+       return ret;
+}
+
+/*
+ * Poll the video queue.
+ *
+ * This function implements video queue polling and is intended to be used by
+ * the device poll handler.
+ */
+unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file,
+               poll_table *wait)
+{
+       struct uvc_buffer *buf;
+       unsigned int mask = 0;
+
+       mutex_lock(&queue->mutex);
+       if (list_empty(&queue->mainqueue)) {
+               mask |= POLLERR;
+               goto done;
+       }
+       buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream);
+
+       poll_wait(file, &buf->wait, wait);
+       if (buf->state == UVC_BUF_STATE_DONE ||
+           buf->state == UVC_BUF_STATE_ERROR)
+               mask |= POLLIN | POLLRDNORM;
+
+done:
+       mutex_unlock(&queue->mutex);
+       return mask;
+}
+
+/*
+ * Enable or disable the video buffers queue.
+ *
+ * The queue must be enabled before starting video acquisition and must be
+ * disabled after stopping it. This ensures that the video buffers queue
+ * state can be properly initialized before buffers are accessed from the
+ * interrupt handler.
+ *
+ * Enabling the video queue initializes parameters (such as sequence number,
+ * sync pattern, ...). If the queue is already enabled, return -EBUSY.
+ *
+ * Disabling the video queue cancels the queue and removes all buffers from
+ * the main queue.
+ *
+ * This function can't be called from interrupt context. Use
+ * uvc_queue_cancel() instead.
+ */
+int uvc_queue_enable(struct uvc_video_queue *queue, int enable)
+{
+       unsigned int i;
+       int ret = 0;
+
+       mutex_lock(&queue->mutex);
+       if (enable) {
+               if (uvc_queue_streaming(queue)) {
+                       ret = -EBUSY;
+                       goto done;
+               }
+               queue->sequence = 0;
+               queue->flags |= UVC_QUEUE_STREAMING;
+       } else {
+               uvc_queue_cancel(queue, 0);
+               INIT_LIST_HEAD(&queue->mainqueue);
+
+               for (i = 0; i < queue->count; ++i)
+                       queue->buffer[i].state = UVC_BUF_STATE_IDLE;
+
+               queue->flags &= ~UVC_QUEUE_STREAMING;
+       }
+
+done:
+       mutex_unlock(&queue->mutex);
+       return ret;
+}
+
+/*
+ * Cancel the video buffers queue.
+ *
+ * Cancelling the queue marks all buffers on the irq queue as erroneous,
+ * wakes them up and remove them from the queue.
+ *
+ * If the disconnect parameter is set, further calls to uvc_queue_buffer will
+ * fail with -ENODEV.
+ *
+ * This function acquires the irq spinlock and can be called from interrupt
+ * context.
+ */
+void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect)
+{
+       struct uvc_buffer *buf;
+       unsigned long flags;
+
+       spin_lock_irqsave(&queue->irqlock, flags);
+       while (!list_empty(&queue->irqqueue)) {
+               buf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
+                                      queue);
+               list_del(&buf->queue);
+               buf->state = UVC_BUF_STATE_ERROR;
+               wake_up(&buf->wait);
+       }
+       /* This must be protected by the irqlock spinlock to avoid race
+        * conditions between uvc_queue_buffer and the disconnection event that
+        * could result in an interruptible wait in uvc_dequeue_buffer. Do not
+        * blindly replace this logic by checking for the UVC_DEV_DISCONNECTED
+        * state outside the queue code.
+        */
+       if (disconnect)
+               queue->flags |= UVC_QUEUE_DISCONNECTED;
+       spin_unlock_irqrestore(&queue->irqlock, flags);
+}
+
+struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
+               struct uvc_buffer *buf)
+{
+       struct uvc_buffer *nextbuf;
+       unsigned long flags;
+
+       if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) &&
+           buf->buf.length != buf->buf.bytesused) {
+               buf->state = UVC_BUF_STATE_QUEUED;
+               buf->buf.bytesused = 0;
+               return buf;
+       }
+
+       spin_lock_irqsave(&queue->irqlock, flags);
+       list_del(&buf->queue);
+       if (!list_empty(&queue->irqqueue))
+               nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
+                                          queue);
+       else
+               nextbuf = NULL;
+       spin_unlock_irqrestore(&queue->irqlock, flags);
+
+       buf->buf.sequence = queue->sequence++;
+       do_gettimeofday(&buf->buf.timestamp);
+
+       wake_up(&buf->wait);
+       return nextbuf;
+}
diff --git a/drivers/media/video/uvc/uvc_status.c b/drivers/media/video/uvc/uvc_status.c
new file mode 100644 (file)
index 0000000..be9084e
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ *      uvc_status.c  --  USB Video Class driver - Status endpoint
+ *
+ *      Copyright (C) 2007-2008
+ *          Laurent Pinchart (laurent.pinchart@skynet.be)
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation; either version 2 of the License, or
+ *      (at your option) any later version.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/input.h>
+#include <linux/usb.h>
+#include <linux/usb/input.h>
+
+#include "uvcvideo.h"
+
+/* --------------------------------------------------------------------------
+ * Input device
+ */
+static int uvc_input_init(struct uvc_device *dev)
+{
+       struct usb_device *udev = dev->udev;
+       struct input_dev *input;
+       char *phys = NULL;
+       int ret;
+
+       input = input_allocate_device();
+       if (input == NULL)
+               return -ENOMEM;
+
+       phys = kmalloc(6 + strlen(udev->bus->bus_name) + strlen(udev->devpath),
+                       GFP_KERNEL);
+       if (phys == NULL) {
+               ret = -ENOMEM;
+               goto error;
+       }
+       sprintf(phys, "usb-%s-%s", udev->bus->bus_name, udev->devpath);
+
+       input->name = dev->name;
+       input->phys = phys;
+       usb_to_input_id(udev, &input->id);
+       input->dev.parent = &dev->intf->dev;
+
+       set_bit(EV_KEY, input->evbit);
+       set_bit(BTN_0, input->keybit);
+
+       if ((ret = input_register_device(input)) < 0)
+               goto error;
+
+       dev->input = input;
+       return 0;
+
+error:
+       input_free_device(input);
+       kfree(phys);
+       return ret;
+}
+
+static void uvc_input_cleanup(struct uvc_device *dev)
+{
+       if (dev->input)
+               input_unregister_device(dev->input);
+}
+
+/* --------------------------------------------------------------------------
+ * Status interrupt endpoint
+ */
+static void uvc_event_streaming(struct uvc_device *dev, __u8 *data, int len)
+{
+       if (len < 3) {
+               uvc_trace(UVC_TRACE_STATUS, "Invalid streaming status event "
+                               "received.\n");
+               return;
+       }
+
+       if (data[2] == 0) {
+               if (len < 4)
+                       return;
+               uvc_trace(UVC_TRACE_STATUS, "Button (intf %u) %s len %d\n",
+                       data[1], data[3] ? "pressed" : "released", len);
+               if (dev->input)
+                       input_report_key(dev->input, BTN_0, data[3]);
+       } else {
+               uvc_trace(UVC_TRACE_STATUS, "Stream %u error event %02x %02x "
+                       "len %d.\n", data[1], data[2], data[3], len);
+       }
+}
+
+static void uvc_event_control(struct uvc_device *dev, __u8 *data, int len)
+{
+       char *attrs[3] = { "value", "info", "failure" };
+
+       if (len < 6 || data[2] != 0 || data[4] > 2) {
+               uvc_trace(UVC_TRACE_STATUS, "Invalid control status event "
+                               "received.\n");
+               return;
+       }
+
+       uvc_trace(UVC_TRACE_STATUS, "Control %u/%u %s change len %d.\n",
+               data[1], data[3], attrs[data[4]], len);
+}
+
+static void uvc_status_complete(struct urb *urb)
+{
+       struct uvc_device *dev = urb->context;
+       int len, ret;
+
+       switch (urb->status) {
+       case 0:
+               break;
+
+       case -ENOENT:           /* usb_kill_urb() called. */
+       case -ECONNRESET:       /* usb_unlink_urb() called. */
+       case -ESHUTDOWN:        /* The endpoint is being disabled. */
+       case -EPROTO:           /* Device is disconnected (reported by some
+                                * host controller). */
+               return;
+
+       default:
+               uvc_printk(KERN_WARNING, "Non-zero status (%d) in status "
+                       "completion handler.\n", urb->status);
+               return;
+       }
+
+       len = urb->actual_length;
+       if (len > 0) {
+               switch (dev->status[0] & 0x0f) {
+               case UVC_STATUS_TYPE_CONTROL:
+                       uvc_event_control(dev, dev->status, len);
+                       break;
+
+               case UVC_STATUS_TYPE_STREAMING:
+                       uvc_event_streaming(dev, dev->status, len);
+                       break;
+
+               default:
+                       uvc_printk(KERN_INFO, "unknown event type %u.\n",
+                               dev->status[0]);
+                       break;
+               }
+       }
+
+       /* Resubmit the URB. */
+       urb->interval = dev->int_ep->desc.bInterval;
+       if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
+               uvc_printk(KERN_ERR, "Failed to resubmit status URB (%d).\n",
+                       ret);
+       }
+}
+
+int uvc_status_init(struct uvc_device *dev)
+{
+       struct usb_host_endpoint *ep = dev->int_ep;
+       unsigned int pipe;
+       int interval;
+
+       if (ep == NULL)
+               return 0;
+
+       uvc_input_init(dev);
+
+       dev->int_urb = usb_alloc_urb(0, GFP_KERNEL);
+       if (dev->int_urb == NULL)
+               return -ENOMEM;
+
+       pipe = usb_rcvintpipe(dev->udev, ep->desc.bEndpointAddress);
+
+       /* For high-speed interrupt endpoints, the bInterval value is used as
+        * an exponent of two. Some developers forgot about it.
+        */
+       interval = ep->desc.bInterval;
+       if (interval > 16 && dev->udev->speed == USB_SPEED_HIGH &&
+           (dev->quirks & UVC_QUIRK_STATUS_INTERVAL))
+               interval = fls(interval) - 1;
+
+       usb_fill_int_urb(dev->int_urb, dev->udev, pipe,
+               dev->status, sizeof dev->status, uvc_status_complete,
+               dev, interval);
+
+       return usb_submit_urb(dev->int_urb, GFP_KERNEL);
+}
+
+void uvc_status_cleanup(struct uvc_device *dev)
+{
+       usb_kill_urb(dev->int_urb);
+       usb_free_urb(dev->int_urb);
+       uvc_input_cleanup(dev);
+}
+
+int uvc_status_suspend(struct uvc_device *dev)
+{
+       usb_kill_urb(dev->int_urb);
+       return 0;
+}
+
+int uvc_status_resume(struct uvc_device *dev)
+{
+       if (dev->int_urb == NULL)
+               return 0;
+
+       return usb_submit_urb(dev->int_urb, GFP_KERNEL);
+}
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
new file mode 100644 (file)
index 0000000..2e0a665
--- /dev/null
@@ -0,0 +1,1105 @@
+/*
+ *      uvc_v4l2.c  --  USB Video Class driver - V4L2 API
+ *
+ *      Copyright (C) 2005-2008
+ *          Laurent Pinchart (laurent.pinchart@skynet.be)
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation; either version 2 of the License, or
+ *      (at your option) any later version.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+#include <linux/videodev2.h>
+#include <linux/vmalloc.h>
+#include <linux/mm.h>
+#include <linux/wait.h>
+#include <asm/atomic.h>
+
+#include <media/v4l2-common.h>
+
+#include "uvcvideo.h"
+
+/* ------------------------------------------------------------------------
+ * V4L2 interface
+ */
+
+/*
+ * Mapping V4L2 controls to UVC controls can be straighforward if done well.
+ * Most of the UVC controls exist in V4L2, and can be mapped directly. Some
+ * must be grouped (for instance the Red Balance, Blue Balance and Do White
+ * Balance V4L2 controls use the White Balance Component UVC control) or
+ * otherwise translated. The approach we take here is to use a translation
+ * table for the controls which can be mapped directly, and handle the others
+ * manually.
+ */
+static int uvc_v4l2_query_menu(struct uvc_video_device *video,
+       struct v4l2_querymenu *query_menu)
+{
+       struct uvc_menu_info *menu_info;
+       struct uvc_control_mapping *mapping;
+       struct uvc_control *ctrl;
+
+       ctrl = uvc_find_control(video, query_menu->id, &mapping);
+       if (ctrl == NULL || mapping->v4l2_type != V4L2_CTRL_TYPE_MENU)
+               return -EINVAL;
+
+       if (query_menu->index >= mapping->menu_count)
+               return -EINVAL;
+
+       menu_info = &mapping->menu_info[query_menu->index];
+       strncpy(query_menu->name, menu_info->name, 32);
+       return 0;
+}
+
+/*
+ * Find the frame interval closest to the requested frame interval for the
+ * given frame format and size. This should be done by the device as part of
+ * the Video Probe and Commit negotiation, but some hardware don't implement
+ * that feature.
+ */
+static __u32 uvc_try_frame_interval(struct uvc_frame *frame, __u32 interval)
+{
+       unsigned int i;
+
+       if (frame->bFrameIntervalType) {
+               __u32 best = -1, dist;
+
+               for (i = 0; i < frame->bFrameIntervalType; ++i) {
+                       dist = interval > frame->dwFrameInterval[i]
+                            ? interval - frame->dwFrameInterval[i]
+                            : frame->dwFrameInterval[i] - interval;
+
+                       if (dist > best)
+                               break;
+
+                       best = dist;
+               }
+
+               interval = frame->dwFrameInterval[i-1];
+       } else {
+               const __u32 min = frame->dwFrameInterval[0];
+               const __u32 max = frame->dwFrameInterval[1];
+               const __u32 step = frame->dwFrameInterval[2];
+
+               interval = min + (interval - min + step/2) / step * step;
+               if (interval > max)
+                       interval = max;
+       }
+
+       return interval;
+}
+
+static int uvc_v4l2_try_format(struct uvc_video_device *video,
+       struct v4l2_format *fmt, struct uvc_streaming_control *probe,
+       struct uvc_format **uvc_format, struct uvc_frame **uvc_frame)
+{
+       struct uvc_format *format = NULL;
+       struct uvc_frame *frame = NULL;
+       __u16 rw, rh;
+       unsigned int d, maxd;
+       unsigned int i;
+       __u32 interval;
+       int ret = 0;
+       __u8 *fcc;
+
+       if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
+
+       fcc = (__u8 *)&fmt->fmt.pix.pixelformat;
+       uvc_trace(UVC_TRACE_FORMAT, "Trying format 0x%08x (%c%c%c%c): %ux%u.\n",
+                       fmt->fmt.pix.pixelformat,
+                       fcc[0], fcc[1], fcc[2], fcc[3],
+                       fmt->fmt.pix.width, fmt->fmt.pix.height);
+
+       /* Check if the hardware supports the requested format. */
+       for (i = 0; i < video->streaming->nformats; ++i) {
+               format = &video->streaming->format[i];
+               if (format->fcc == fmt->fmt.pix.pixelformat)
+                       break;
+       }
+
+       if (format == NULL || format->fcc != fmt->fmt.pix.pixelformat) {
+               uvc_trace(UVC_TRACE_FORMAT, "Unsupported format 0x%08x.\n",
+                               fmt->fmt.pix.pixelformat);
+               return -EINVAL;
+       }
+
+       /* Find the closest image size. The distance between image sizes is
+        * the size in pixels of the non-overlapping regions between the
+        * requested size and the frame-specified size.
+        */
+       rw = fmt->fmt.pix.width;
+       rh = fmt->fmt.pix.height;
+       maxd = (unsigned int)-1;
+
+       for (i = 0; i < format->nframes; ++i) {
+               __u16 w = format->frame[i].wWidth;
+               __u16 h = format->frame[i].wHeight;
+
+               d = min(w, rw) * min(h, rh);
+               d = w*h + rw*rh - 2*d;
+               if (d < maxd) {
+                       maxd = d;
+                       frame = &format->frame[i];
+               }
+
+               if (maxd == 0)
+                       break;
+       }
+
+       if (frame == NULL) {
+               uvc_trace(UVC_TRACE_FORMAT, "Unsupported size %ux%u.\n",
+                               fmt->fmt.pix.width, fmt->fmt.pix.height);
+               return -EINVAL;
+       }
+
+       /* Use the default frame interval. */
+       interval = frame->dwDefaultFrameInterval;
+       uvc_trace(UVC_TRACE_FORMAT, "Using default frame interval %u.%u us "
+               "(%u.%u fps).\n", interval/10, interval%10, 10000000/interval,
+               (100000000/interval)%10);
+
+       /* Set the format index, frame index and frame interval. */
+       memset(probe, 0, sizeof *probe);
+       probe->bmHint = 1;      /* dwFrameInterval */
+       probe->bFormatIndex = format->index;
+       probe->bFrameIndex = frame->bFrameIndex;
+       probe->dwFrameInterval = uvc_try_frame_interval(frame, interval);
+       /* Some webcams stall the probe control set request when the
+        * dwMaxVideoFrameSize field is set to zero. The UVC specification
+        * clearly states that the field is read-only from the host, so this
+        * is a webcam bug. Set dwMaxVideoFrameSize to the value reported by
+        * the webcam to work around the problem.
+        *
+        * The workaround could probably be enabled for all webcams, so the
+        * quirk can be removed if needed. It's currently useful to detect
+        * webcam bugs and fix them before they hit the market (providing
+        * developers test their webcams with the Linux driver as well as with
+        * the Windows driver).
+        */
+       if (video->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS)
+               probe->dwMaxVideoFrameSize =
+                       video->streaming->ctrl.dwMaxVideoFrameSize;
+
+       /* Probe the device */
+       if ((ret = uvc_probe_video(video, probe)) < 0)
+               goto done;
+
+       fmt->fmt.pix.width = frame->wWidth;
+       fmt->fmt.pix.height = frame->wHeight;
+       fmt->fmt.pix.field = V4L2_FIELD_NONE;
+       fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
+       fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize;
+       fmt->fmt.pix.colorspace = format->colorspace;
+       fmt->fmt.pix.priv = 0;
+
+       if (uvc_format != NULL)
+               *uvc_format = format;
+       if (uvc_frame != NULL)
+               *uvc_frame = frame;
+
+done:
+       return ret;
+}
+
+static int uvc_v4l2_get_format(struct uvc_video_device *video,
+       struct v4l2_format *fmt)
+{
+       struct uvc_format *format = video->streaming->cur_format;
+       struct uvc_frame *frame = video->streaming->cur_frame;
+
+       if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
+
+       if (format == NULL || frame == NULL)
+               return -EINVAL;
+
+       fmt->fmt.pix.pixelformat = format->fcc;
+       fmt->fmt.pix.width = frame->wWidth;
+       fmt->fmt.pix.height = frame->wHeight;
+       fmt->fmt.pix.field = V4L2_FIELD_NONE;
+       fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8;
+       fmt->fmt.pix.sizeimage = video->streaming->ctrl.dwMaxVideoFrameSize;
+       fmt->fmt.pix.colorspace = format->colorspace;
+       fmt->fmt.pix.priv = 0;
+
+       return 0;
+}
+
+static int uvc_v4l2_set_format(struct uvc_video_device *video,
+       struct v4l2_format *fmt)
+{
+       struct uvc_streaming_control probe;
+       struct uvc_format *format;
+       struct uvc_frame *frame;
+       int ret;
+
+       if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
+
+       if (uvc_queue_streaming(&video->queue))
+               return -EBUSY;
+
+       ret = uvc_v4l2_try_format(video, fmt, &probe, &format, &frame);
+       if (ret < 0)
+               return ret;
+
+       if ((ret = uvc_set_video_ctrl(video, &probe, 0)) < 0)
+               return ret;
+
+       memcpy(&video->streaming->ctrl, &probe, sizeof probe);
+       video->streaming->cur_format = format;
+       video->streaming->cur_frame = frame;
+
+       return 0;
+}
+
+static int uvc_v4l2_get_streamparm(struct uvc_video_device *video,
+               struct v4l2_streamparm *parm)
+{
+       uint32_t numerator, denominator;
+
+       if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
+
+       numerator = video->streaming->ctrl.dwFrameInterval;
+       denominator = 10000000;
+       uvc_simplify_fraction(&numerator, &denominator, 8, 333);
+
+       memset(parm, 0, sizeof *parm);
+       parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+       parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
+       parm->parm.capture.capturemode = 0;
+       parm->parm.capture.timeperframe.numerator = numerator;
+       parm->parm.capture.timeperframe.denominator = denominator;
+       parm->parm.capture.extendedmode = 0;
+       parm->parm.capture.readbuffers = 0;
+
+       return 0;
+}
+
+static int uvc_v4l2_set_streamparm(struct uvc_video_device *video,
+               struct v4l2_streamparm *parm)
+{
+       struct uvc_frame *frame = video->streaming->cur_frame;
+       struct uvc_streaming_control probe;
+       uint32_t interval;
+       int ret;
+
+       if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
+
+       if (uvc_queue_streaming(&video->queue))
+               return -EBUSY;
+
+       memcpy(&probe, &video->streaming->ctrl, sizeof probe);
+       interval = uvc_fraction_to_interval(
+                       parm->parm.capture.timeperframe.numerator,
+                       parm->parm.capture.timeperframe.denominator);
+
+       uvc_trace(UVC_TRACE_FORMAT, "Setting frame interval to %u/%u (%u).\n",
+                       parm->parm.capture.timeperframe.numerator,
+                       parm->parm.capture.timeperframe.denominator,
+                       interval);
+       probe.dwFrameInterval = uvc_try_frame_interval(frame, interval);
+
+       /* Probe the device with the new settings. */
+       if ((ret = uvc_probe_video(video, &probe)) < 0)
+               return ret;
+
+       /* Commit the new settings. */
+       if ((ret = uvc_set_video_ctrl(video, &probe, 0)) < 0)
+               return ret;
+
+       memcpy(&video->streaming->ctrl, &probe, sizeof probe);
+
+       /* Return the actual frame period. */
+       parm->parm.capture.timeperframe.numerator = probe.dwFrameInterval;
+       parm->parm.capture.timeperframe.denominator = 10000000;
+       uvc_simplify_fraction(&parm->parm.capture.timeperframe.numerator,
+                               &parm->parm.capture.timeperframe.denominator,
+                               8, 333);
+
+       return 0;
+}
+
+/* ------------------------------------------------------------------------
+ * Privilege management
+ */
+
+/*
+ * Privilege management is the multiple-open implementation basis. The current
+ * implementation is completely transparent for the end-user and doesn't
+ * require explicit use of the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioctls.
+ * Those ioctls enable finer control on the device (by making possible for a
+ * user to request exclusive access to a device), but are not mature yet.
+ * Switching to the V4L2 priority mechanism might be considered in the future
+ * if this situation changes.
+ *
+ * Each open instance of a UVC device can either be in a privileged or
+ * unprivileged state. Only a single instance can be in a privileged state at
+ * a given time. Trying to perform an operation which requires privileges will
+ * automatically acquire the required privileges if possible, or return -EBUSY
+ * otherwise. Privileges are dismissed when closing the instance.
+ *
+ * Operations which require privileges are:
+ *
+ * - VIDIOC_S_INPUT
+ * - VIDIOC_S_PARM
+ * - VIDIOC_S_FMT
+ * - VIDIOC_TRY_FMT
+ * - VIDIOC_REQBUFS
+ */
+static int uvc_acquire_privileges(struct uvc_fh *handle)
+{
+       int ret = 0;
+
+       /* Always succeed if the handle is already privileged. */
+       if (handle->state == UVC_HANDLE_ACTIVE)
+               return 0;
+
+       /* Check if the device already has a privileged handle. */
+       mutex_lock(&uvc_driver.open_mutex);
+       if (atomic_inc_return(&handle->device->active) != 1) {
+               atomic_dec(&handle->device->active);
+               ret = -EBUSY;
+               goto done;
+       }
+
+       handle->state = UVC_HANDLE_ACTIVE;
+
+done:
+       mutex_unlock(&uvc_driver.open_mutex);
+       return ret;
+}
+
+static void uvc_dismiss_privileges(struct uvc_fh *handle)
+{
+       if (handle->state == UVC_HANDLE_ACTIVE)
+               atomic_dec(&handle->device->active);
+
+       handle->state = UVC_HANDLE_PASSIVE;
+}
+
+static int uvc_has_privileges(struct uvc_fh *handle)
+{
+       return handle->state == UVC_HANDLE_ACTIVE;
+}
+
+/* ------------------------------------------------------------------------
+ * V4L2 file operations
+ */
+
+static int uvc_v4l2_open(struct inode *inode, struct file *file)
+{
+       struct video_device *vdev;
+       struct uvc_video_device *video;
+       struct uvc_fh *handle;
+       int ret = 0;
+
+       uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
+       mutex_lock(&uvc_driver.open_mutex);
+       vdev = video_devdata(file);
+       video = video_get_drvdata(vdev);
+
+       if (video->dev->state & UVC_DEV_DISCONNECTED) {
+               ret = -ENODEV;
+               goto done;
+       }
+
+       ret = usb_autopm_get_interface(video->dev->intf);
+       if (ret < 0)
+               goto done;
+
+       /* Create the device handle. */
+       handle = kzalloc(sizeof *handle, GFP_KERNEL);
+       if (handle == NULL) {
+               usb_autopm_put_interface(video->dev->intf);
+               ret = -ENOMEM;
+               goto done;
+       }
+
+       handle->device = video;
+       handle->state = UVC_HANDLE_PASSIVE;
+       file->private_data = handle;
+
+       kref_get(&video->dev->kref);
+
+done:
+       mutex_unlock(&uvc_driver.open_mutex);
+       return ret;
+}
+
+static int uvc_v4l2_release(struct inode *inode, struct file *file)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct uvc_video_device *video = video_get_drvdata(vdev);
+       struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
+
+       uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n");
+
+       /* Only free resources if this is a privileged handle. */
+       if (uvc_has_privileges(handle)) {
+               uvc_video_enable(video, 0);
+
+               mutex_lock(&video->queue.mutex);
+               if (uvc_free_buffers(&video->queue) < 0)
+                       uvc_printk(KERN_ERR, "uvc_v4l2_release: Unable to "
+                                       "free buffers.\n");
+               mutex_unlock(&video->queue.mutex);
+       }
+
+       /* Release the file handle. */
+       uvc_dismiss_privileges(handle);
+       kfree(handle);
+       file->private_data = NULL;
+
+       usb_autopm_put_interface(video->dev->intf);
+       kref_put(&video->dev->kref, uvc_delete);
+       return 0;
+}
+
+static int uvc_v4l2_do_ioctl(struct inode *inode, struct file *file,
+                    unsigned int cmd, void *arg)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct uvc_video_device *video = video_get_drvdata(vdev);
+       struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
+       int ret = 0;
+
+       if (uvc_trace_param & UVC_TRACE_IOCTL)
+               v4l_printk_ioctl(cmd);
+
+       switch (cmd) {
+       /* Query capabilities */
+       case VIDIOC_QUERYCAP:
+       {
+               struct v4l2_capability *cap = arg;
+
+               memset(cap, 0, sizeof *cap);
+               strncpy(cap->driver, "uvcvideo", sizeof cap->driver);
+               strncpy(cap->card, vdev->name, 32);
+               strncpy(cap->bus_info, video->dev->udev->bus->bus_name,
+                       sizeof cap->bus_info);
+               cap->version = DRIVER_VERSION_NUMBER;
+               cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
+                                 | V4L2_CAP_STREAMING;
+               break;
+       }
+
+       /* Get, Set & Query control */
+       case VIDIOC_QUERYCTRL:
+               return uvc_query_v4l2_ctrl(video, arg);
+
+       case VIDIOC_G_CTRL:
+       {
+               struct v4l2_control *ctrl = arg;
+               struct v4l2_ext_control xctrl;
+
+               memset(&xctrl, 0, sizeof xctrl);
+               xctrl.id = ctrl->id;
+
+               uvc_ctrl_begin(video);
+               ret = uvc_ctrl_get(video, &xctrl);
+               uvc_ctrl_rollback(video);
+               if (ret >= 0)
+                       ctrl->value = xctrl.value;
+               break;
+       }
+
+       case VIDIOC_S_CTRL:
+       {
+               struct v4l2_control *ctrl = arg;
+               struct v4l2_ext_control xctrl;
+
+               memset(&xctrl, 0, sizeof xctrl);
+               xctrl.id = ctrl->id;
+               xctrl.value = ctrl->value;
+
+               uvc_ctrl_begin(video);
+               ret = uvc_ctrl_set(video, &xctrl);
+               if (ret < 0) {
+                       uvc_ctrl_rollback(video);
+                       return ret;
+               }
+               ret = uvc_ctrl_commit(video);
+               break;
+       }
+
+       case VIDIOC_QUERYMENU:
+               return uvc_v4l2_query_menu(video, arg);
+
+       case VIDIOC_G_EXT_CTRLS:
+       {
+               struct v4l2_ext_controls *ctrls = arg;
+               struct v4l2_ext_control *ctrl = ctrls->controls;
+               unsigned int i;
+
+               uvc_ctrl_begin(video);
+               for (i = 0; i < ctrls->count; ++ctrl, ++i) {
+                       ret = uvc_ctrl_get(video, ctrl);
+                       if (ret < 0) {
+                               uvc_ctrl_rollback(video);
+                               ctrls->error_idx = i;
+                               return ret;
+                       }
+               }
+               ctrls->error_idx = 0;
+               ret = uvc_ctrl_rollback(video);
+               break;
+       }
+
+       case VIDIOC_S_EXT_CTRLS:
+       case VIDIOC_TRY_EXT_CTRLS:
+       {
+               struct v4l2_ext_controls *ctrls = arg;
+               struct v4l2_ext_control *ctrl = ctrls->controls;
+               unsigned int i;
+
+               ret = uvc_ctrl_begin(video);
+               if (ret < 0)
+                       return ret;
+
+               for (i = 0; i < ctrls->count; ++ctrl, ++i) {
+                       ret = uvc_ctrl_set(video, ctrl);
+                       if (ret < 0) {
+                               uvc_ctrl_rollback(video);
+                               ctrls->error_idx = i;
+                               return ret;
+                       }
+               }
+
+               ctrls->error_idx = 0;
+
+               if (cmd == VIDIOC_S_EXT_CTRLS)
+                       ret = uvc_ctrl_commit(video);
+               else
+                       ret = uvc_ctrl_rollback(video);
+               break;
+       }
+
+       /* Get, Set & Enum input */
+       case VIDIOC_ENUMINPUT:
+       {
+               const struct uvc_entity *selector = video->selector;
+               struct v4l2_input *input = arg;
+               struct uvc_entity *iterm = NULL;
+               u32 index = input->index;
+               int pin = 0;
+
+               if (selector == NULL ||
+                   (video->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
+                       if (index != 0)
+                               return -EINVAL;
+                       iterm = list_first_entry(&video->iterms,
+                                       struct uvc_entity, chain);
+                       pin = iterm->id;
+               } else if (pin < selector->selector.bNrInPins) {
+                       pin = selector->selector.baSourceID[index];
+                       list_for_each_entry(iterm, video->iterms.next, chain) {
+                               if (iterm->id == pin)
+                                       break;
+                       }
+               }
+
+               if (iterm == NULL || iterm->id != pin)
+                       return -EINVAL;
+
+               memset(input, 0, sizeof *input);
+               input->index = index;
+               strncpy(input->name, iterm->name, sizeof input->name);
+               if (UVC_ENTITY_TYPE(iterm) == ITT_CAMERA)
+                       input->type = V4L2_INPUT_TYPE_CAMERA;
+               break;
+       }
+
+       case VIDIOC_G_INPUT:
+       {
+               u8 input;
+
+               if (video->selector == NULL ||
+                   (video->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
+                       *(int *)arg = 0;
+                       break;
+               }
+
+               ret = uvc_query_ctrl(video->dev, GET_CUR, video->selector->id,
+                       video->dev->intfnum, SU_INPUT_SELECT_CONTROL,
+                       &input, 1);
+               if (ret < 0)
+                       return ret;
+
+               *(int *)arg = input - 1;
+               break;
+       }
+
+       case VIDIOC_S_INPUT:
+       {
+               u8 input = *(u32 *)arg + 1;
+
+               if ((ret = uvc_acquire_privileges(handle)) < 0)
+                       return ret;
+
+               if (video->selector == NULL ||
+                   (video->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
+                       if (input != 1)
+                               return -EINVAL;
+                       break;
+               }
+
+               if (input > video->selector->selector.bNrInPins)
+                       return -EINVAL;
+
+               return uvc_query_ctrl(video->dev, SET_CUR, video->selector->id,
+                       video->dev->intfnum, SU_INPUT_SELECT_CONTROL,
+                       &input, 1);
+       }
+
+       /* Try, Get, Set & Enum format */
+       case VIDIOC_ENUM_FMT:
+       {
+               struct v4l2_fmtdesc *fmt = arg;
+               struct uvc_format *format;
+
+               if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
+                   fmt->index >= video->streaming->nformats)
+                       return -EINVAL;
+
+               format = &video->streaming->format[fmt->index];
+               fmt->flags = 0;
+               if (format->flags & UVC_FMT_FLAG_COMPRESSED)
+                       fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
+               strncpy(fmt->description, format->name,
+                       sizeof fmt->description);
+               fmt->description[sizeof fmt->description - 1] = 0;
+               fmt->pixelformat = format->fcc;
+               break;
+       }
+
+       case VIDIOC_TRY_FMT:
+       {
+               struct uvc_streaming_control probe;
+
+               if ((ret = uvc_acquire_privileges(handle)) < 0)
+                       return ret;
+
+               return uvc_v4l2_try_format(video, arg, &probe, NULL, NULL);
+       }
+
+       case VIDIOC_S_FMT:
+               if ((ret = uvc_acquire_privileges(handle)) < 0)
+                       return ret;
+
+               return uvc_v4l2_set_format(video, arg);
+
+       case VIDIOC_G_FMT:
+               return uvc_v4l2_get_format(video, arg);
+
+       /* Frame size enumeration */
+       case VIDIOC_ENUM_FRAMESIZES:
+       {
+               struct v4l2_frmsizeenum *fsize = arg;
+               struct uvc_format *format = NULL;
+               struct uvc_frame *frame;
+               int i;
+
+               /* Look for the given pixel format */
+               for (i = 0; i < video->streaming->nformats; i++) {
+                       if (video->streaming->format[i].fcc ==
+                                       fsize->pixel_format) {
+                               format = &video->streaming->format[i];
+                               break;
+                       }
+               }
+               if (format == NULL)
+                       return -EINVAL;
+
+               if (fsize->index >= format->nframes)
+                       return -EINVAL;
+
+               frame = &format->frame[fsize->index];
+               fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
+               fsize->discrete.width = frame->wWidth;
+               fsize->discrete.height = frame->wHeight;
+               break;
+       }
+
+       /* Frame interval enumeration */
+       case VIDIOC_ENUM_FRAMEINTERVALS:
+       {
+               struct v4l2_frmivalenum *fival = arg;
+               struct uvc_format *format = NULL;
+               struct uvc_frame *frame = NULL;
+               int i;
+
+               /* Look for the given pixel format and frame size */
+               for (i = 0; i < video->streaming->nformats; i++) {
+                       if (video->streaming->format[i].fcc ==
+                                       fival->pixel_format) {
+                               format = &video->streaming->format[i];
+                               break;
+                       }
+               }
+               if (format == NULL)
+                       return -EINVAL;
+
+               for (i = 0; i < format->nframes; i++) {
+                       if (format->frame[i].wWidth == fival->width &&
+                           format->frame[i].wHeight == fival->height) {
+                               frame = &format->frame[i];
+                               break;
+                       }
+               }
+               if (frame == NULL)
+                       return -EINVAL;
+
+               if (frame->bFrameIntervalType) {
+                       if (fival->index >= frame->bFrameIntervalType)
+                               return -EINVAL;
+
+                       fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
+                       fival->discrete.numerator =
+                               frame->dwFrameInterval[fival->index];
+                       fival->discrete.denominator = 10000000;
+                       uvc_simplify_fraction(&fival->discrete.numerator,
+                               &fival->discrete.denominator, 8, 333);
+               } else {
+                       fival->type = V4L2_FRMIVAL_TYPE_STEPWISE;
+                       fival->stepwise.min.numerator =
+                               frame->dwFrameInterval[0];
+                       fival->stepwise.min.denominator = 10000000;
+                       fival->stepwise.max.numerator =
+                               frame->dwFrameInterval[1];
+                       fival->stepwise.max.denominator = 10000000;
+                       fival->stepwise.step.numerator =
+                               frame->dwFrameInterval[2];
+                       fival->stepwise.step.denominator = 10000000;
+                       uvc_simplify_fraction(&fival->stepwise.min.numerator,
+                               &fival->stepwise.min.denominator, 8, 333);
+                       uvc_simplify_fraction(&fival->stepwise.max.numerator,
+                               &fival->stepwise.max.denominator, 8, 333);
+                       uvc_simplify_fraction(&fival->stepwise.step.numerator,
+                               &fival->stepwise.step.denominator, 8, 333);
+               }
+               break;
+       }
+
+       /* Get & Set streaming parameters */
+       case VIDIOC_G_PARM:
+               return uvc_v4l2_get_streamparm(video, arg);
+
+       case VIDIOC_S_PARM:
+               if ((ret = uvc_acquire_privileges(handle)) < 0)
+                       return ret;
+
+               return uvc_v4l2_set_streamparm(video, arg);
+
+       /* Cropping and scaling */
+       case VIDIOC_CROPCAP:
+       {
+               struct v4l2_cropcap *ccap = arg;
+               struct uvc_frame *frame = video->streaming->cur_frame;
+
+               if (ccap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+                       return -EINVAL;
+
+               ccap->bounds.left = 0;
+               ccap->bounds.top = 0;
+               ccap->bounds.width = frame->wWidth;
+               ccap->bounds.height = frame->wHeight;
+
+               ccap->defrect = ccap->bounds;
+
+               ccap->pixelaspect.numerator = 1;
+               ccap->pixelaspect.denominator = 1;
+               break;
+       }
+
+       case VIDIOC_G_CROP:
+       case VIDIOC_S_CROP:
+               return -EINVAL;
+
+       /* Buffers & streaming */
+       case VIDIOC_REQBUFS:
+       {
+               struct v4l2_requestbuffers *rb = arg;
+               unsigned int bufsize =
+                       video->streaming->ctrl.dwMaxVideoFrameSize;
+
+               if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
+                   rb->memory != V4L2_MEMORY_MMAP)
+                       return -EINVAL;
+
+               if ((ret = uvc_acquire_privileges(handle)) < 0)
+                       return ret;
+
+               ret = uvc_alloc_buffers(&video->queue, rb->count, bufsize);
+               if (ret < 0)
+                       return ret;
+
+               if (!(video->streaming->cur_format->flags &
+                   UVC_FMT_FLAG_COMPRESSED))
+                       video->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE;
+
+               rb->count = ret;
+               ret = 0;
+               break;
+       }
+
+       case VIDIOC_QUERYBUF:
+       {
+               struct v4l2_buffer *buf = arg;
+
+               if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+                       return -EINVAL;
+
+               if (!uvc_has_privileges(handle))
+                       return -EBUSY;
+
+               return uvc_query_buffer(&video->queue, buf);
+       }
+
+       case VIDIOC_QBUF:
+               if (!uvc_has_privileges(handle))
+                       return -EBUSY;
+
+               return uvc_queue_buffer(&video->queue, arg);
+
+       case VIDIOC_DQBUF:
+               if (!uvc_has_privileges(handle))
+                       return -EBUSY;
+
+               return uvc_dequeue_buffer(&video->queue, arg,
+                       file->f_flags & O_NONBLOCK);
+
+       case VIDIOC_STREAMON:
+       {
+               int *type = arg;
+
+               if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+                       return -EINVAL;
+
+               if (!uvc_has_privileges(handle))
+                       return -EBUSY;
+
+               if ((ret = uvc_video_enable(video, 1)) < 0)
+                       return ret;
+               break;
+       }
+
+       case VIDIOC_STREAMOFF:
+       {
+               int *type = arg;
+
+               if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+                       return -EINVAL;
+
+               if (!uvc_has_privileges(handle))
+                       return -EBUSY;
+
+               return uvc_video_enable(video, 0);
+       }
+
+       /* Analog video standards make no sense for digital cameras. */
+       case VIDIOC_ENUMSTD:
+       case VIDIOC_QUERYSTD:
+       case VIDIOC_G_STD:
+       case VIDIOC_S_STD:
+
+       case VIDIOC_OVERLAY:
+
+       case VIDIOC_ENUMAUDIO:
+       case VIDIOC_ENUMAUDOUT:
+
+       case VIDIOC_ENUMOUTPUT:
+               uvc_trace(UVC_TRACE_IOCTL, "Unsupported ioctl 0x%08x\n", cmd);
+               return -EINVAL;
+
+       /* Dynamic controls. */
+       case UVCIOC_CTRL_ADD:
+       {
+               struct uvc_xu_control_info *xinfo = arg;
+               struct uvc_control_info *info;
+
+               if (!capable(CAP_SYS_ADMIN))
+                       return -EPERM;
+
+               info = kmalloc(sizeof *info, GFP_KERNEL);
+               if (info == NULL)
+                       return -ENOMEM;
+
+               memcpy(info->entity, xinfo->entity, sizeof info->entity);
+               info->index = xinfo->index;
+               info->selector = xinfo->selector;
+               info->size = xinfo->size;
+               info->flags = xinfo->flags;
+
+               info->flags |= UVC_CONTROL_GET_MIN | UVC_CONTROL_GET_MAX |
+                               UVC_CONTROL_GET_RES | UVC_CONTROL_GET_DEF;
+
+               ret = uvc_ctrl_add_info(info);
+               if (ret < 0)
+                       kfree(info);
+               break;
+       }
+
+       case UVCIOC_CTRL_MAP:
+       {
+               struct uvc_xu_control_mapping *xmap = arg;
+               struct uvc_control_mapping *map;
+
+               if (!capable(CAP_SYS_ADMIN))
+                       return -EPERM;
+
+               map = kmalloc(sizeof *map, GFP_KERNEL);
+               if (map == NULL)
+                       return -ENOMEM;
+
+               map->id = xmap->id;
+               memcpy(map->name, xmap->name, sizeof map->name);
+               memcpy(map->entity, xmap->entity, sizeof map->entity);
+               map->selector = xmap->selector;
+               map->size = xmap->size;
+               map->offset = xmap->offset;
+               map->v4l2_type = xmap->v4l2_type;
+               map->data_type = xmap->data_type;
+
+               ret = uvc_ctrl_add_mapping(map);
+               if (ret < 0)
+                       kfree(map);
+               break;
+       }
+
+       case UVCIOC_CTRL_GET:
+               return uvc_xu_ctrl_query(video, arg, 0);
+
+       case UVCIOC_CTRL_SET:
+               return uvc_xu_ctrl_query(video, arg, 1);
+
+       default:
+               if ((ret = v4l_compat_translate_ioctl(inode, file, cmd, arg,
+                       uvc_v4l2_do_ioctl)) == -ENOIOCTLCMD)
+                       uvc_trace(UVC_TRACE_IOCTL, "Unknown ioctl 0x%08x\n",
+                                 cmd);
+               return ret;
+       }
+
+       return ret;
+}
+
+static int uvc_v4l2_ioctl(struct inode *inode, struct file *file,
+                    unsigned int cmd, unsigned long arg)
+{
+       uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_ioctl\n");
+       return video_usercopy(inode, file, cmd, arg, uvc_v4l2_do_ioctl);
+}
+
+static ssize_t uvc_v4l2_read(struct file *file, char __user *data,
+                   size_t count, loff_t *ppos)
+{
+       uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read: not implemented.\n");
+       return -ENODEV;
+}
+
+/*
+ * VMA operations.
+ */
+static void uvc_vm_open(struct vm_area_struct *vma)
+{
+       struct uvc_buffer *buffer = vma->vm_private_data;
+       buffer->vma_use_count++;
+}
+
+static void uvc_vm_close(struct vm_area_struct *vma)
+{
+       struct uvc_buffer *buffer = vma->vm_private_data;
+       buffer->vma_use_count--;
+}
+
+static struct vm_operations_struct uvc_vm_ops = {
+       .open           = uvc_vm_open,
+       .close          = uvc_vm_close,
+};
+
+static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct uvc_video_device *video = video_get_drvdata(vdev);
+       struct uvc_buffer *buffer;
+       struct page *page;
+       unsigned long addr, start, size;
+       unsigned int i;
+       int ret = 0;
+
+       uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_mmap\n");
+
+       start = vma->vm_start;
+       size = vma->vm_end - vma->vm_start;
+
+       mutex_lock(&video->queue.mutex);
+
+       for (i = 0; i < video->queue.count; ++i) {
+               buffer = &video->queue.buffer[i];
+               if ((buffer->buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
+                       break;
+       }
+
+       if (i == video->queue.count || size != video->queue.buf_size) {
+               ret = -EINVAL;
+               goto done;
+       }
+
+       /*
+        * VM_IO marks the area as being an mmaped region for I/O to a
+        * device. It also prevents the region from being core dumped.
+        */
+       vma->vm_flags |= VM_IO;
+
+       addr = (unsigned long)video->queue.mem + buffer->buf.m.offset;
+       while (size > 0) {
+               page = vmalloc_to_page((void *)addr);
+               if ((ret = vm_insert_page(vma, start, page)) < 0)
+                       goto done;
+
+               start += PAGE_SIZE;
+               addr += PAGE_SIZE;
+               size -= PAGE_SIZE;
+       }
+
+       vma->vm_ops = &uvc_vm_ops;
+       vma->vm_private_data = buffer;
+       uvc_vm_open(vma);
+
+done:
+       mutex_unlock(&video->queue.mutex);
+       return ret;
+}
+
+static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct uvc_video_device *video = video_get_drvdata(vdev);
+
+       uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n");
+
+       return uvc_queue_poll(&video->queue, file, wait);
+}
+
+struct file_operations uvc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = uvc_v4l2_open,
+       .release        = uvc_v4l2_release,
+       .ioctl          = uvc_v4l2_ioctl,
+       .compat_ioctl   = v4l_compat_ioctl32,
+       .llseek         = no_llseek,
+       .read           = uvc_v4l2_read,
+       .mmap           = uvc_v4l2_mmap,
+       .poll           = uvc_v4l2_poll,
+};
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c
new file mode 100644 (file)
index 0000000..6faf1fb
--- /dev/null
@@ -0,0 +1,934 @@
+/*
+ *      uvc_video.c  --  USB Video Class driver - Video handling
+ *
+ *      Copyright (C) 2005-2008
+ *          Laurent Pinchart (laurent.pinchart@skynet.be)
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation; either version 2 of the License, or
+ *      (at your option) any later version.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+#include <linux/videodev2.h>
+#include <linux/vmalloc.h>
+#include <linux/wait.h>
+#include <asm/atomic.h>
+#include <asm/unaligned.h>
+
+#include <media/v4l2-common.h>
+
+#include "uvcvideo.h"
+
+/* ------------------------------------------------------------------------
+ * UVC Controls
+ */
+
+static int __uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
+                       __u8 intfnum, __u8 cs, void *data, __u16 size,
+                       int timeout)
+{
+       __u8 type = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
+       unsigned int pipe;
+       int ret;
+
+       pipe = (query & 0x80) ? usb_rcvctrlpipe(dev->udev, 0)
+                             : usb_sndctrlpipe(dev->udev, 0);
+       type |= (query & 0x80) ? USB_DIR_IN : USB_DIR_OUT;
+
+       ret = usb_control_msg(dev->udev, pipe, query, type, cs << 8,
+                       unit << 8 | intfnum, data, size, timeout);
+
+       if (ret != size) {
+               uvc_printk(KERN_ERR, "Failed to query (%u) UVC control %u "
+                       "(unit %u) : %d (exp. %u).\n", query, cs, unit, ret,
+                       size);
+               return -EIO;
+       }
+
+       return 0;
+}
+
+int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
+                       __u8 intfnum, __u8 cs, void *data, __u16 size)
+{
+       return __uvc_query_ctrl(dev, query, unit, intfnum, cs, data, size,
+                               UVC_CTRL_CONTROL_TIMEOUT);
+}
+
+static void uvc_fixup_buffer_size(struct uvc_video_device *video,
+       struct uvc_streaming_control *ctrl)
+{
+       struct uvc_format *format;
+       struct uvc_frame *frame;
+
+       if (ctrl->bFormatIndex <= 0 ||
+           ctrl->bFormatIndex > video->streaming->nformats)
+               return;
+
+       format = &video->streaming->format[ctrl->bFormatIndex - 1];
+
+       if (ctrl->bFrameIndex <= 0 ||
+           ctrl->bFrameIndex > format->nframes)
+               return;
+
+       frame = &format->frame[ctrl->bFrameIndex - 1];
+
+       if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) ||
+            (ctrl->dwMaxVideoFrameSize == 0 &&
+             video->dev->uvc_version < 0x0110))
+               ctrl->dwMaxVideoFrameSize =
+                       frame->dwMaxVideoFrameBufferSize;
+}
+
+static int uvc_get_video_ctrl(struct uvc_video_device *video,
+       struct uvc_streaming_control *ctrl, int probe, __u8 query)
+{
+       __u8 data[34];
+       __u8 size;
+       int ret;
+
+       size = video->dev->uvc_version >= 0x0110 ? 34 : 26;
+       ret = __uvc_query_ctrl(video->dev, query, 0, video->streaming->intfnum,
+               probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, &data, size,
+               UVC_CTRL_STREAMING_TIMEOUT);
+
+       if (ret < 0)
+               return ret;
+
+       ctrl->bmHint = le16_to_cpup((__le16 *)&data[0]);
+       ctrl->bFormatIndex = data[2];
+       ctrl->bFrameIndex = data[3];
+       ctrl->dwFrameInterval = le32_to_cpup((__le32 *)&data[4]);
+       ctrl->wKeyFrameRate = le16_to_cpup((__le16 *)&data[8]);
+       ctrl->wPFrameRate = le16_to_cpup((__le16 *)&data[10]);
+       ctrl->wCompQuality = le16_to_cpup((__le16 *)&data[12]);
+       ctrl->wCompWindowSize = le16_to_cpup((__le16 *)&data[14]);
+       ctrl->wDelay = le16_to_cpup((__le16 *)&data[16]);
+       ctrl->dwMaxVideoFrameSize =
+               le32_to_cpu(get_unaligned((__le32 *)&data[18]));
+       ctrl->dwMaxPayloadTransferSize =
+               le32_to_cpu(get_unaligned((__le32 *)&data[22]));
+
+       if (size == 34) {
+               ctrl->dwClockFrequency =
+                       le32_to_cpu(get_unaligned((__le32 *)&data[26]));
+               ctrl->bmFramingInfo = data[30];
+               ctrl->bPreferedVersion = data[31];
+               ctrl->bMinVersion = data[32];
+               ctrl->bMaxVersion = data[33];
+       } else {
+               ctrl->dwClockFrequency = video->dev->clock_frequency;
+               ctrl->bmFramingInfo = 0;
+               ctrl->bPreferedVersion = 0;
+               ctrl->bMinVersion = 0;
+               ctrl->bMaxVersion = 0;
+       }
+
+       /* Some broken devices return a null or wrong dwMaxVideoFrameSize.
+        * Try to get the value from the format and frame descriptor.
+        */
+       uvc_fixup_buffer_size(video, ctrl);
+
+       return 0;
+}
+
+int uvc_set_video_ctrl(struct uvc_video_device *video,
+       struct uvc_streaming_control *ctrl, int probe)
+{
+       __u8 data[34];
+       __u8 size;
+
+       size = video->dev->uvc_version >= 0x0110 ? 34 : 26;
+       memset(data, 0, sizeof data);
+
+       *(__le16 *)&data[0] = cpu_to_le16(ctrl->bmHint);
+       data[2] = ctrl->bFormatIndex;
+       data[3] = ctrl->bFrameIndex;
+       *(__le32 *)&data[4] = cpu_to_le32(ctrl->dwFrameInterval);
+       *(__le16 *)&data[8] = cpu_to_le16(ctrl->wKeyFrameRate);
+       *(__le16 *)&data[10] = cpu_to_le16(ctrl->wPFrameRate);
+       *(__le16 *)&data[12] = cpu_to_le16(ctrl->wCompQuality);
+       *(__le16 *)&data[14] = cpu_to_le16(ctrl->wCompWindowSize);
+       *(__le16 *)&data[16] = cpu_to_le16(ctrl->wDelay);
+       /* Note: Some of the fields below are not required for IN devices (see
+        * UVC spec, 4.3.1.1), but we still copy them in case support for OUT
+        * devices is added in the future. */
+       put_unaligned(cpu_to_le32(ctrl->dwMaxVideoFrameSize),
+               (__le32 *)&data[18]);
+       put_unaligned(cpu_to_le32(ctrl->dwMaxPayloadTransferSize),
+               (__le32 *)&data[22]);
+
+       if (size == 34) {
+               put_unaligned(cpu_to_le32(ctrl->dwClockFrequency),
+                       (__le32 *)&data[26]);
+               data[30] = ctrl->bmFramingInfo;
+               data[31] = ctrl->bPreferedVersion;
+               data[32] = ctrl->bMinVersion;
+               data[33] = ctrl->bMaxVersion;
+       }
+
+       return __uvc_query_ctrl(video->dev, SET_CUR, 0,
+               video->streaming->intfnum,
+               probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, &data, size,
+               UVC_CTRL_STREAMING_TIMEOUT);
+}
+
+int uvc_probe_video(struct uvc_video_device *video,
+       struct uvc_streaming_control *probe)
+{
+       struct uvc_streaming_control probe_min, probe_max;
+       __u16 bandwidth;
+       unsigned int i;
+       int ret;
+
+       mutex_lock(&video->streaming->mutex);
+
+       /* Perform probing. The device should adjust the requested values
+        * according to its capabilities. However, some devices, namely the
+        * first generation UVC Logitech webcams, don't implement the Video
+        * Probe control properly, and just return the needed bandwidth. For
+        * that reason, if the needed bandwidth exceeds the maximum available
+        * bandwidth, try to lower the quality.
+        */
+       if ((ret = uvc_set_video_ctrl(video, probe, 1)) < 0)
+               goto done;
+
+       /* Get the minimum and maximum values for compression settings. */
+       if (!(video->dev->quirks & UVC_QUIRK_PROBE_MINMAX)) {
+               ret = uvc_get_video_ctrl(video, &probe_min, 1, GET_MIN);
+               if (ret < 0)
+                       goto done;
+               ret = uvc_get_video_ctrl(video, &probe_max, 1, GET_MAX);
+               if (ret < 0)
+                       goto done;
+
+               probe->wCompQuality = probe_max.wCompQuality;
+       }
+
+       for (i = 0; i < 2; ++i) {
+               if ((ret = uvc_set_video_ctrl(video, probe, 1)) < 0 ||
+                   (ret = uvc_get_video_ctrl(video, probe, 1, GET_CUR)) < 0)
+                       goto done;
+
+               if (video->streaming->intf->num_altsetting == 1)
+                       break;
+
+               bandwidth = probe->dwMaxPayloadTransferSize;
+               if (bandwidth <= video->streaming->maxpsize)
+                       break;
+
+               if (video->dev->quirks & UVC_QUIRK_PROBE_MINMAX) {
+                       ret = -ENOSPC;
+                       goto done;
+               }
+
+               /* TODO: negotiate compression parameters */
+               probe->wKeyFrameRate = probe_min.wKeyFrameRate;
+               probe->wPFrameRate = probe_min.wPFrameRate;
+               probe->wCompQuality = probe_max.wCompQuality;
+               probe->wCompWindowSize = probe_min.wCompWindowSize;
+       }
+
+done:
+       mutex_unlock(&video->streaming->mutex);
+       return ret;
+}
+
+/* ------------------------------------------------------------------------
+ * Video codecs
+ */
+
+/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
+#define UVC_STREAM_EOH (1 << 7)
+#define UVC_STREAM_ERR (1 << 6)
+#define UVC_STREAM_STI (1 << 5)
+#define UVC_STREAM_RES (1 << 4)
+#define UVC_STREAM_SCR (1 << 3)
+#define UVC_STREAM_PTS (1 << 2)
+#define UVC_STREAM_EOF (1 << 1)
+#define UVC_STREAM_FID (1 << 0)
+
+/* Video payload decoding is handled by uvc_video_decode_start(),
+ * uvc_video_decode_data() and uvc_video_decode_end().
+ *
+ * uvc_video_decode_start is called with URB data at the start of a bulk or
+ * isochronous payload. It processes header data and returns the header size
+ * in bytes if successful. If an error occurs, it returns a negative error
+ * code. The following error codes have special meanings.
+ *
+ * - EAGAIN informs the caller that the current video buffer should be marked
+ *   as done, and that the function should be called again with the same data
+ *   and a new video buffer. This is used when end of frame conditions can be
+ *   reliably detected at the beginning of the next frame only.
+ *
+ * If an error other than -EAGAIN is returned, the caller will drop the current
+ * payload. No call to uvc_video_decode_data and uvc_video_decode_end will be
+ * made until the next payload. -ENODATA can be used to drop the current
+ * payload if no other error code is appropriate.
+ *
+ * uvc_video_decode_data is called for every URB with URB data. It copies the
+ * data to the video buffer.
+ *
+ * uvc_video_decode_end is called with header data at the end of a bulk or
+ * isochronous payload. It performs any additional header data processing and
+ * returns 0 or a negative error code if an error occured. As header data have
+ * already been processed by uvc_video_decode_start, this functions isn't
+ * required to perform sanity checks a second time.
+ *
+ * For isochronous transfers where a payload is always transfered in a single
+ * URB, the three functions will be called in a row.
+ *
+ * To let the decoder process header data and update its internal state even
+ * when no video buffer is available, uvc_video_decode_start must be prepared
+ * to be called with a NULL buf parameter. uvc_video_decode_data and
+ * uvc_video_decode_end will never be called with a NULL buffer.
+ */
+static int uvc_video_decode_start(struct uvc_video_device *video,
+               struct uvc_buffer *buf, const __u8 *data, int len)
+{
+       __u8 fid;
+
+       /* Sanity checks:
+        * - packet must be at least 2 bytes long
+        * - bHeaderLength value must be at least 2 bytes (see above)
+        * - bHeaderLength value can't be larger than the packet size.
+        */
+       if (len < 2 || data[0] < 2 || data[0] > len)
+               return -EINVAL;
+
+       /* Skip payloads marked with the error bit ("error frames"). */
+       if (data[1] & UVC_STREAM_ERR) {
+               uvc_trace(UVC_TRACE_FRAME, "Dropping payload (error bit "
+                         "set).\n");
+               return -ENODATA;
+       }
+
+       fid = data[1] & UVC_STREAM_FID;
+
+       /* Store the payload FID bit and return immediately when the buffer is
+        * NULL.
+        */
+       if (buf == NULL) {
+               video->last_fid = fid;
+               return -ENODATA;
+       }
+
+       /* Synchronize to the input stream by waiting for the FID bit to be
+        * toggled when the the buffer state is not UVC_BUF_STATE_ACTIVE.
+        * queue->last_fid is initialized to -1, so the first isochronous
+        * frame will always be in sync.
+        *
+        * If the device doesn't toggle the FID bit, invert video->last_fid
+        * when the EOF bit is set to force synchronisation on the next packet.
+        */
+       if (buf->state != UVC_BUF_STATE_ACTIVE) {
+               if (fid == video->last_fid) {
+                       uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of "
+                               "sync).\n");
+                       if ((video->dev->quirks & UVC_QUIRK_STREAM_NO_FID) &&
+                           (data[1] & UVC_STREAM_EOF))
+                               video->last_fid ^= UVC_STREAM_FID;
+                       return -ENODATA;
+               }
+
+               /* TODO: Handle PTS and SCR. */
+               buf->state = UVC_BUF_STATE_ACTIVE;
+       }
+
+       /* Mark the buffer as done if we're at the beginning of a new frame.
+        * End of frame detection is better implemented by checking the EOF
+        * bit (FID bit toggling is delayed by one frame compared to the EOF
+        * bit), but some devices don't set the bit at end of frame (and the
+        * last payload can be lost anyway). We thus must check if the FID has
+        * been toggled.
+        *
+        * queue->last_fid is initialized to -1, so the first isochronous
+        * frame will never trigger an end of frame detection.
+        *
+        * Empty buffers (bytesused == 0) don't trigger end of frame detection
+        * as it doesn't make sense to return an empty buffer. This also
+        * avoids detecting and of frame conditions at FID toggling if the
+        * previous payload had the EOF bit set.
+        */
+       if (fid != video->last_fid && buf->buf.bytesused != 0) {
+               uvc_trace(UVC_TRACE_FRAME, "Frame complete (FID bit "
+                               "toggled).\n");
+               buf->state = UVC_BUF_STATE_DONE;
+               return -EAGAIN;
+       }
+
+       video->last_fid = fid;
+
+       return data[0];
+}
+
+static void uvc_video_decode_data(struct uvc_video_device *video,
+               struct uvc_buffer *buf, const __u8 *data, int len)
+{
+       struct uvc_video_queue *queue = &video->queue;
+       unsigned int maxlen, nbytes;
+       void *mem;
+
+       if (len <= 0)
+               return;
+
+       /* Copy the video data to the buffer. */
+       maxlen = buf->buf.length - buf->buf.bytesused;
+       mem = queue->mem + buf->buf.m.offset + buf->buf.bytesused;
+       nbytes = min((unsigned int)len, maxlen);
+       memcpy(mem, data, nbytes);
+       buf->buf.bytesused += nbytes;
+
+       /* Complete the current frame if the buffer size was exceeded. */
+       if (len > maxlen) {
+               uvc_trace(UVC_TRACE_FRAME, "Frame complete (overflow).\n");
+               buf->state = UVC_BUF_STATE_DONE;
+       }
+}
+
+static void uvc_video_decode_end(struct uvc_video_device *video,
+               struct uvc_buffer *buf, const __u8 *data, int len)
+{
+       /* Mark the buffer as done if the EOF marker is set. */
+       if (data[1] & UVC_STREAM_EOF && buf->buf.bytesused != 0) {
+               uvc_trace(UVC_TRACE_FRAME, "Frame complete (EOF found).\n");
+               if (data[0] == len)
+                       uvc_trace(UVC_TRACE_FRAME, "EOF in empty payload.\n");
+               buf->state = UVC_BUF_STATE_DONE;
+               if (video->dev->quirks & UVC_QUIRK_STREAM_NO_FID)
+                       video->last_fid ^= UVC_STREAM_FID;
+       }
+}
+
+/* ------------------------------------------------------------------------
+ * URB handling
+ */
+
+/*
+ * Completion handler for video URBs.
+ */
+static void uvc_video_decode_isoc(struct urb *urb,
+       struct uvc_video_device *video, struct uvc_buffer *buf)
+{
+       u8 *mem;
+       int ret, i;
+
+       for (i = 0; i < urb->number_of_packets; ++i) {
+               if (urb->iso_frame_desc[i].status < 0) {
+                       uvc_trace(UVC_TRACE_FRAME, "USB isochronous frame "
+                               "lost (%d).\n", urb->iso_frame_desc[i].status);
+                       continue;
+               }
+
+               /* Decode the payload header. */
+               mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
+               do {
+                       ret = uvc_video_decode_start(video, buf, mem,
+                               urb->iso_frame_desc[i].actual_length);
+                       if (ret == -EAGAIN)
+                               buf = uvc_queue_next_buffer(&video->queue, buf);
+               } while (ret == -EAGAIN);
+
+               if (ret < 0)
+                       continue;
+
+               /* Decode the payload data. */
+               uvc_video_decode_data(video, buf, mem + ret,
+                       urb->iso_frame_desc[i].actual_length - ret);
+
+               /* Process the header again. */
+               uvc_video_decode_end(video, buf, mem, ret);
+
+               if (buf->state == UVC_BUF_STATE_DONE ||
+                   buf->state == UVC_BUF_STATE_ERROR)
+                       buf = uvc_queue_next_buffer(&video->queue, buf);
+       }
+}
+
+static void uvc_video_decode_bulk(struct urb *urb,
+       struct uvc_video_device *video, struct uvc_buffer *buf)
+{
+       u8 *mem;
+       int len, ret;
+
+       mem = urb->transfer_buffer;
+       len = urb->actual_length;
+       video->bulk.payload_size += len;
+
+       /* If the URB is the first of its payload, decode and save the
+        * header.
+        */
+       if (video->bulk.header_size == 0) {
+               do {
+                       ret = uvc_video_decode_start(video, buf, mem, len);
+                       if (ret == -EAGAIN)
+                               buf = uvc_queue_next_buffer(&video->queue, buf);
+               } while (ret == -EAGAIN);
+
+               /* If an error occured skip the rest of the payload. */
+               if (ret < 0 || buf == NULL) {
+                       video->bulk.skip_payload = 1;
+                       return;
+               }
+
+               video->bulk.header_size = ret;
+               memcpy(video->bulk.header, mem, video->bulk.header_size);
+
+               mem += ret;
+               len -= ret;
+       }
+
+       /* The buffer queue might have been cancelled while a bulk transfer
+        * was in progress, so we can reach here with buf equal to NULL. Make
+        * sure buf is never dereferenced if NULL.
+        */
+
+       /* Process video data. */
+       if (!video->bulk.skip_payload && buf != NULL)
+               uvc_video_decode_data(video, buf, mem, len);
+
+       /* Detect the payload end by a URB smaller than the maximum size (or
+        * a payload size equal to the maximum) and process the header again.
+        */
+       if (urb->actual_length < urb->transfer_buffer_length ||
+           video->bulk.payload_size >= video->bulk.max_payload_size) {
+               if (!video->bulk.skip_payload && buf != NULL) {
+                       uvc_video_decode_end(video, buf, video->bulk.header,
+                               video->bulk.header_size);
+                       if (buf->state == UVC_BUF_STATE_DONE ||
+                           buf->state == UVC_BUF_STATE_ERROR)
+                               buf = uvc_queue_next_buffer(&video->queue, buf);
+               }
+
+               video->bulk.header_size = 0;
+               video->bulk.skip_payload = 0;
+               video->bulk.payload_size = 0;
+       }
+}
+
+static void uvc_video_complete(struct urb *urb)
+{
+       struct uvc_video_device *video = urb->context;
+       struct uvc_video_queue *queue = &video->queue;
+       struct uvc_buffer *buf = NULL;
+       unsigned long flags;
+       int ret;
+
+       switch (urb->status) {
+       case 0:
+               break;
+
+       default:
+               uvc_printk(KERN_WARNING, "Non-zero status (%d) in video "
+                       "completion handler.\n", urb->status);
+
+       case -ENOENT:           /* usb_kill_urb() called. */
+               if (video->frozen)
+                       return;
+
+       case -ECONNRESET:       /* usb_unlink_urb() called. */
+       case -ESHUTDOWN:        /* The endpoint is being disabled. */
+               uvc_queue_cancel(queue, urb->status == -ESHUTDOWN);
+               return;
+       }
+
+       spin_lock_irqsave(&queue->irqlock, flags);
+       if (!list_empty(&queue->irqqueue))
+               buf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
+                                      queue);
+       spin_unlock_irqrestore(&queue->irqlock, flags);
+
+       video->decode(urb, video, buf);
+
+       if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
+               uvc_printk(KERN_ERR, "Failed to resubmit video URB (%d).\n",
+                       ret);
+       }
+}
+
+/*
+ * Uninitialize isochronous/bulk URBs and free transfer buffers.
+ */
+static void uvc_uninit_video(struct uvc_video_device *video)
+{
+       struct urb *urb;
+       unsigned int i;
+
+       for (i = 0; i < UVC_URBS; ++i) {
+               if ((urb = video->urb[i]) == NULL)
+                       continue;
+
+               usb_kill_urb(urb);
+               /* urb->transfer_buffer_length is not touched by USB core, so
+                * we can use it here as the buffer length.
+                */
+               if (video->urb_buffer[i]) {
+                       usb_buffer_free(video->dev->udev,
+                               urb->transfer_buffer_length,
+                               video->urb_buffer[i], urb->transfer_dma);
+                       video->urb_buffer[i] = NULL;
+               }
+
+               usb_free_urb(urb);
+               video->urb[i] = NULL;
+       }
+}
+
+/*
+ * Initialize isochronous URBs and allocate transfer buffers. The packet size
+ * is given by the endpoint.
+ */
+static int uvc_init_video_isoc(struct uvc_video_device *video,
+       struct usb_host_endpoint *ep)
+{
+       struct urb *urb;
+       unsigned int npackets, i, j;
+       __u16 psize;
+       __u32 size;
+
+       /* Compute the number of isochronous packets to allocate by dividing
+        * the maximum video frame size by the packet size. Limit the result
+        * to UVC_MAX_ISO_PACKETS.
+        */
+       psize = le16_to_cpu(ep->desc.wMaxPacketSize);
+       psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
+
+       size = video->streaming->ctrl.dwMaxVideoFrameSize;
+       if (size > UVC_MAX_FRAME_SIZE)
+               return -EINVAL;
+
+       npackets = (size + psize - 1) / psize;
+       if (npackets > UVC_MAX_ISO_PACKETS)
+               npackets = UVC_MAX_ISO_PACKETS;
+
+       size = npackets * psize;
+
+       for (i = 0; i < UVC_URBS; ++i) {
+               urb = usb_alloc_urb(npackets, GFP_KERNEL);
+               if (urb == NULL) {
+                       uvc_uninit_video(video);
+                       return -ENOMEM;
+               }
+
+               video->urb_buffer[i] = usb_buffer_alloc(video->dev->udev,
+                       size, GFP_KERNEL, &urb->transfer_dma);
+               if (video->urb_buffer[i] == NULL) {
+                       usb_free_urb(urb);
+                       uvc_uninit_video(video);
+                       return -ENOMEM;
+               }
+
+               urb->dev = video->dev->udev;
+               urb->context = video;
+               urb->pipe = usb_rcvisocpipe(video->dev->udev,
+                               ep->desc.bEndpointAddress);
+               urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
+               urb->interval = ep->desc.bInterval;
+               urb->transfer_buffer = video->urb_buffer[i];
+               urb->complete = uvc_video_complete;
+               urb->number_of_packets = npackets;
+               urb->transfer_buffer_length = size;
+
+               for (j = 0; j < npackets; ++j) {
+                       urb->iso_frame_desc[j].offset = j * psize;
+                       urb->iso_frame_desc[j].length = psize;
+               }
+
+               video->urb[i] = urb;
+       }
+
+       return 0;
+}
+
+/*
+ * Initialize bulk URBs and allocate transfer buffers. The packet size is
+ * given by the endpoint.
+ */
+static int uvc_init_video_bulk(struct uvc_video_device *video,
+       struct usb_host_endpoint *ep)
+{
+       struct urb *urb;
+       unsigned int pipe, i;
+       __u16 psize;
+       __u32 size;
+
+       /* Compute the bulk URB size. Some devices set the maximum payload
+        * size to a value too high for memory-constrained devices. We must
+        * then transfer the payload accross multiple URBs. To be consistant
+        * with isochronous mode, allocate maximum UVC_MAX_ISO_PACKETS per bulk
+        * URB.
+        */
+       psize = le16_to_cpu(ep->desc.wMaxPacketSize) & 0x07ff;
+       size = video->streaming->ctrl.dwMaxPayloadTransferSize;
+       video->bulk.max_payload_size = size;
+       if (size > psize * UVC_MAX_ISO_PACKETS)
+               size = psize * UVC_MAX_ISO_PACKETS;
+
+       pipe = usb_rcvbulkpipe(video->dev->udev, ep->desc.bEndpointAddress);
+
+       for (i = 0; i < UVC_URBS; ++i) {
+               urb = usb_alloc_urb(0, GFP_KERNEL);
+               if (urb == NULL) {
+                       uvc_uninit_video(video);
+                       return -ENOMEM;
+               }
+
+               video->urb_buffer[i] = usb_buffer_alloc(video->dev->udev,
+                       size, GFP_KERNEL, &urb->transfer_dma);
+               if (video->urb_buffer[i] == NULL) {
+                       usb_free_urb(urb);
+                       uvc_uninit_video(video);
+                       return -ENOMEM;
+               }
+
+               usb_fill_bulk_urb(urb, video->dev->udev, pipe,
+                       video->urb_buffer[i], size, uvc_video_complete,
+                       video);
+               urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
+
+               video->urb[i] = urb;
+       }
+
+       return 0;
+}
+
+/*
+ * Initialize isochronous/bulk URBs and allocate transfer buffers.
+ */
+static int uvc_init_video(struct uvc_video_device *video)
+{
+       struct usb_interface *intf = video->streaming->intf;
+       struct usb_host_interface *alts;
+       struct usb_host_endpoint *ep = NULL;
+       int intfnum = video->streaming->intfnum;
+       unsigned int bandwidth, psize, i;
+       int ret;
+
+       video->last_fid = -1;
+       video->bulk.header_size = 0;
+       video->bulk.skip_payload = 0;
+       video->bulk.payload_size = 0;
+
+       if (intf->num_altsetting > 1) {
+               /* Isochronous endpoint, select the alternate setting. */
+               bandwidth = video->streaming->ctrl.dwMaxPayloadTransferSize;
+
+               if (bandwidth == 0) {
+                       uvc_printk(KERN_WARNING, "device %s requested null "
+                               "bandwidth, defaulting to lowest.\n",
+                               video->vdev->name);
+                       bandwidth = 1;
+               }
+
+               for (i = 0; i < intf->num_altsetting; ++i) {
+                       alts = &intf->altsetting[i];
+                       ep = uvc_find_endpoint(alts,
+                               video->streaming->header.bEndpointAddress);
+                       if (ep == NULL)
+                               continue;
+
+                       /* Check if the bandwidth is high enough. */
+                       psize = le16_to_cpu(ep->desc.wMaxPacketSize);
+                       psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
+                       if (psize >= bandwidth)
+                               break;
+               }
+
+               if (i >= intf->num_altsetting)
+                       return -EIO;
+
+               if ((ret = usb_set_interface(video->dev->udev, intfnum, i)) < 0)
+                       return ret;
+
+               ret = uvc_init_video_isoc(video, ep);
+       } else {
+               /* Bulk endpoint, proceed to URB initialization. */
+               ep = uvc_find_endpoint(&intf->altsetting[0],
+                               video->streaming->header.bEndpointAddress);
+               if (ep == NULL)
+                       return -EIO;
+
+               ret = uvc_init_video_bulk(video, ep);
+       }
+
+       if (ret < 0)
+               return ret;
+
+       /* Submit the URBs. */
+       for (i = 0; i < UVC_URBS; ++i) {
+               if ((ret = usb_submit_urb(video->urb[i], GFP_KERNEL)) < 0) {
+                       uvc_printk(KERN_ERR, "Failed to submit URB %u "
+                                       "(%d).\n", i, ret);
+                       uvc_uninit_video(video);
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+
+/* --------------------------------------------------------------------------
+ * Suspend/resume
+ */
+
+/*
+ * Stop streaming without disabling the video queue.
+ *
+ * To let userspace applications resume without trouble, we must not touch the
+ * video buffers in any way. We mark the device as frozen to make sure the URB
+ * completion handler won't try to cancel the queue when we kill the URBs.
+ */
+int uvc_video_suspend(struct uvc_video_device *video)
+{
+       if (!uvc_queue_streaming(&video->queue))
+               return 0;
+
+       video->frozen = 1;
+       uvc_uninit_video(video);
+       usb_set_interface(video->dev->udev, video->streaming->intfnum, 0);
+       return 0;
+}
+
+/*
+ * Reconfigure the video interface and restart streaming if it was enable
+ * before suspend.
+ *
+ * If an error occurs, disable the video queue. This will wake all pending
+ * buffers, making sure userspace applications are notified of the problem
+ * instead of waiting forever.
+ */
+int uvc_video_resume(struct uvc_video_device *video)
+{
+       int ret;
+
+       video->frozen = 0;
+
+       if ((ret = uvc_set_video_ctrl(video, &video->streaming->ctrl, 0)) < 0) {
+               uvc_queue_enable(&video->queue, 0);
+               return ret;
+       }
+
+       if (!uvc_queue_streaming(&video->queue))
+               return 0;
+
+       if ((ret = uvc_init_video(video)) < 0)
+               uvc_queue_enable(&video->queue, 0);
+
+       return ret;
+}
+
+/* ------------------------------------------------------------------------
+ * Video device
+ */
+
+/*
+ * Initialize the UVC video device by retrieving the default format and
+ * committing it.
+ *
+ * Some cameras (namely the Fuji Finepix) set the format and frame
+ * indexes to zero. The UVC standard doesn't clearly make this a spec
+ * violation, so try to silently fix the values if possible.
+ *
+ * This function is called before registering the device with V4L.
+ */
+int uvc_video_init(struct uvc_video_device *video)
+{
+       struct uvc_streaming_control *probe = &video->streaming->ctrl;
+       struct uvc_format *format = NULL;
+       struct uvc_frame *frame = NULL;
+       unsigned int i;
+       int ret;
+
+       if (video->streaming->nformats == 0) {
+               uvc_printk(KERN_INFO, "No supported video formats found.\n");
+               return -EINVAL;
+       }
+
+       /* Alternate setting 0 should be the default, yet the XBox Live Vision
+        * Cam (and possibly other devices) crash or otherwise misbehave if
+        * they don't receive a SET_INTERFACE request before any other video
+        * control request.
+        */
+       usb_set_interface(video->dev->udev, video->streaming->intfnum, 0);
+
+       /* Some webcams don't suport GET_DEF request on the probe control. We
+        * fall back to GET_CUR if GET_DEF fails.
+        */
+       if ((ret = uvc_get_video_ctrl(video, probe, 1, GET_DEF)) < 0 &&
+           (ret = uvc_get_video_ctrl(video, probe, 1, GET_CUR)) < 0)
+               return ret;
+
+       /* Check if the default format descriptor exists. Use the first
+        * available format otherwise.
+        */
+       for (i = video->streaming->nformats; i > 0; --i) {
+               format = &video->streaming->format[i-1];
+               if (format->index == probe->bFormatIndex)
+                       break;
+       }
+
+       if (format->nframes == 0) {
+               uvc_printk(KERN_INFO, "No frame descriptor found for the "
+                       "default format.\n");
+               return -EINVAL;
+       }
+
+       /* Zero bFrameIndex might be correct. Stream-based formats (including
+        * MPEG-2 TS and DV) do not support frames but have a dummy frame
+        * descriptor with bFrameIndex set to zero. If the default frame
+        * descriptor is not found, use the first avalable frame.
+        */
+       for (i = format->nframes; i > 0; --i) {
+               frame = &format->frame[i-1];
+               if (frame->bFrameIndex == probe->bFrameIndex)
+                       break;
+       }
+
+       /* Commit the default settings. */
+       probe->bFormatIndex = format->index;
+       probe->bFrameIndex = frame->bFrameIndex;
+       if ((ret = uvc_set_video_ctrl(video, probe, 0)) < 0)
+               return ret;
+
+       video->streaming->cur_format = format;
+       video->streaming->cur_frame = frame;
+       atomic_set(&video->active, 0);
+
+       /* Select the video decoding function */
+       if (video->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT)
+               video->decode = uvc_video_decode_isight;
+       else if (video->streaming->intf->num_altsetting > 1)
+               video->decode = uvc_video_decode_isoc;
+       else
+               video->decode = uvc_video_decode_bulk;
+
+       return 0;
+}
+
+/*
+ * Enable or disable the video stream.
+ */
+int uvc_video_enable(struct uvc_video_device *video, int enable)
+{
+       int ret;
+
+       if (!enable) {
+               uvc_uninit_video(video);
+               usb_set_interface(video->dev->udev,
+                       video->streaming->intfnum, 0);
+               uvc_queue_enable(&video->queue, 0);
+               return 0;
+       }
+
+       if ((ret = uvc_queue_enable(&video->queue, 1)) < 0)
+               return ret;
+
+       return uvc_init_video(video);
+}
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h
new file mode 100644 (file)
index 0000000..a995a78
--- /dev/null
@@ -0,0 +1,796 @@
+#ifndef _USB_VIDEO_H_
+#define _USB_VIDEO_H_
+
+#include <linux/kernel.h>
+#include <linux/videodev2.h>
+
+
+/*
+ * Dynamic controls
+ */
+
+/* Data types for UVC control data */
+#define UVC_CTRL_DATA_TYPE_RAW         0
+#define UVC_CTRL_DATA_TYPE_SIGNED      1
+#define UVC_CTRL_DATA_TYPE_UNSIGNED    2
+#define UVC_CTRL_DATA_TYPE_BOOLEAN     3
+#define UVC_CTRL_DATA_TYPE_ENUM                4
+#define UVC_CTRL_DATA_TYPE_BITMASK     5
+
+/* Control flags */
+#define UVC_CONTROL_SET_CUR    (1 << 0)
+#define UVC_CONTROL_GET_CUR    (1 << 1)
+#define UVC_CONTROL_GET_MIN    (1 << 2)
+#define UVC_CONTROL_GET_MAX    (1 << 3)
+#define UVC_CONTROL_GET_RES    (1 << 4)
+#define UVC_CONTROL_GET_DEF    (1 << 5)
+/* Control should be saved at suspend and restored at resume. */
+#define UVC_CONTROL_RESTORE    (1 << 6)
+/* Control can be updated by the camera. */
+#define UVC_CONTROL_AUTO_UPDATE        (1 << 7)
+
+#define UVC_CONTROL_GET_RANGE  (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \
+                                UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \
+                                UVC_CONTROL_GET_DEF)
+
+struct uvc_xu_control_info {
+       __u8 entity[16];
+       __u8 index;
+       __u8 selector;
+       __u16 size;
+       __u32 flags;
+};
+
+struct uvc_xu_control_mapping {
+       __u32 id;
+       __u8 name[32];
+       __u8 entity[16];
+       __u8 selector;
+
+       __u8 size;
+       __u8 offset;
+       enum v4l2_ctrl_type v4l2_type;
+       __u32 data_type;
+};
+
+struct uvc_xu_control {
+       __u8 unit;
+       __u8 selector;
+       __u16 size;
+       __u8 __user *data;
+};
+
+#define UVCIOC_CTRL_ADD                _IOW('U', 1, struct uvc_xu_control_info)
+#define UVCIOC_CTRL_MAP                _IOWR('U', 2, struct uvc_xu_control_mapping)
+#define UVCIOC_CTRL_GET                _IOWR('U', 3, struct uvc_xu_control)
+#define UVCIOC_CTRL_SET                _IOW('U', 4, struct uvc_xu_control)
+
+#ifdef __KERNEL__
+
+#include <linux/poll.h>
+
+/* --------------------------------------------------------------------------
+ * UVC constants
+ */
+
+#define SC_UNDEFINED                    0x00
+#define SC_VIDEOCONTROL                 0x01
+#define SC_VIDEOSTREAMING               0x02
+#define SC_VIDEO_INTERFACE_COLLECTION   0x03
+
+#define PC_PROTOCOL_UNDEFINED           0x00
+
+#define CS_UNDEFINED                    0x20
+#define CS_DEVICE                       0x21
+#define CS_CONFIGURATION                0x22
+#define CS_STRING                       0x23
+#define CS_INTERFACE                    0x24
+#define CS_ENDPOINT                     0x25
+
+/* VideoControl class specific interface descriptor */
+#define VC_DESCRIPTOR_UNDEFINED         0x00
+#define VC_HEADER                       0x01
+#define VC_INPUT_TERMINAL               0x02
+#define VC_OUTPUT_TERMINAL              0x03
+#define VC_SELECTOR_UNIT                0x04
+#define VC_PROCESSING_UNIT              0x05
+#define VC_EXTENSION_UNIT               0x06
+
+/* VideoStreaming class specific interface descriptor */
+#define VS_UNDEFINED                    0x00
+#define VS_INPUT_HEADER                 0x01
+#define VS_OUTPUT_HEADER                0x02
+#define VS_STILL_IMAGE_FRAME            0x03
+#define VS_FORMAT_UNCOMPRESSED          0x04
+#define VS_FRAME_UNCOMPRESSED           0x05
+#define VS_FORMAT_MJPEG                 0x06
+#define VS_FRAME_MJPEG                  0x07
+#define VS_FORMAT_MPEG2TS               0x0a
+#define VS_FORMAT_DV                    0x0c
+#define VS_COLORFORMAT                  0x0d
+#define VS_FORMAT_FRAME_BASED           0x10
+#define VS_FRAME_FRAME_BASED            0x11
+#define VS_FORMAT_STREAM_BASED          0x12
+
+/* Endpoint type */
+#define EP_UNDEFINED                    0x00
+#define EP_GENERAL                      0x01
+#define EP_ENDPOINT                     0x02
+#define EP_INTERRUPT                    0x03
+
+/* Request codes */
+#define RC_UNDEFINED                    0x00
+#define SET_CUR                         0x01
+#define GET_CUR                         0x81
+#define GET_MIN                         0x82
+#define GET_MAX                         0x83
+#define GET_RES                         0x84
+#define GET_LEN                         0x85
+#define GET_INFO                        0x86
+#define GET_DEF                         0x87
+
+/* VideoControl interface controls */
+#define VC_CONTROL_UNDEFINED            0x00
+#define VC_VIDEO_POWER_MODE_CONTROL     0x01
+#define VC_REQUEST_ERROR_CODE_CONTROL   0x02
+
+/* Terminal controls */
+#define TE_CONTROL_UNDEFINED            0x00
+
+/* Selector Unit controls */
+#define SU_CONTROL_UNDEFINED            0x00
+#define SU_INPUT_SELECT_CONTROL         0x01
+
+/* Camera Terminal controls */
+#define CT_CONTROL_UNDEFINED                           0x00
+#define CT_SCANNING_MODE_CONTROL                       0x01
+#define CT_AE_MODE_CONTROL                             0x02
+#define CT_AE_PRIORITY_CONTROL                         0x03
+#define CT_EXPOSURE_TIME_ABSOLUTE_CONTROL               0x04
+#define CT_EXPOSURE_TIME_RELATIVE_CONTROL               0x05
+#define CT_FOCUS_ABSOLUTE_CONTROL                      0x06
+#define CT_FOCUS_RELATIVE_CONTROL                      0x07
+#define CT_FOCUS_AUTO_CONTROL                          0x08
+#define CT_IRIS_ABSOLUTE_CONTROL                       0x09
+#define CT_IRIS_RELATIVE_CONTROL                       0x0a
+#define CT_ZOOM_ABSOLUTE_CONTROL                       0x0b
+#define CT_ZOOM_RELATIVE_CONTROL                       0x0c
+#define CT_PANTILT_ABSOLUTE_CONTROL                    0x0d
+#define CT_PANTILT_RELATIVE_CONTROL                    0x0e
+#define CT_ROLL_ABSOLUTE_CONTROL                       0x0f
+#define CT_ROLL_RELATIVE_CONTROL                       0x10
+#define CT_PRIVACY_CONTROL                             0x11
+
+/* Processing Unit controls */
+#define PU_CONTROL_UNDEFINED                           0x00
+#define PU_BACKLIGHT_COMPENSATION_CONTROL               0x01
+#define PU_BRIGHTNESS_CONTROL                          0x02
+#define PU_CONTRAST_CONTROL                            0x03
+#define PU_GAIN_CONTROL                                0x04
+#define PU_POWER_LINE_FREQUENCY_CONTROL                0x05
+#define PU_HUE_CONTROL                                 0x06
+#define PU_SATURATION_CONTROL                          0x07
+#define PU_SHARPNESS_CONTROL                           0x08
+#define PU_GAMMA_CONTROL                               0x09
+#define PU_WHITE_BALANCE_TEMPERATURE_CONTROL            0x0a
+#define PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL       0x0b
+#define PU_WHITE_BALANCE_COMPONENT_CONTROL              0x0c
+#define PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL         0x0d
+#define PU_DIGITAL_MULTIPLIER_CONTROL                  0x0e
+#define PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL             0x0f
+#define PU_HUE_AUTO_CONTROL                            0x10
+#define PU_ANALOG_VIDEO_STANDARD_CONTROL                0x11
+#define PU_ANALOG_LOCK_STATUS_CONTROL                  0x12
+
+#define LXU_MOTOR_PANTILT_RELATIVE_CONTROL             0x01
+#define LXU_MOTOR_PANTILT_RESET_CONTROL                        0x02
+#define LXU_MOTOR_FOCUS_MOTOR_CONTROL                  0x03
+
+/* VideoStreaming interface controls */
+#define VS_CONTROL_UNDEFINED            0x00
+#define VS_PROBE_CONTROL                0x01
+#define VS_COMMIT_CONTROL               0x02
+#define VS_STILL_PROBE_CONTROL          0x03
+#define VS_STILL_COMMIT_CONTROL         0x04
+#define VS_STILL_IMAGE_TRIGGER_CONTROL  0x05
+#define VS_STREAM_ERROR_CODE_CONTROL    0x06
+#define VS_GENERATE_KEY_FRAME_CONTROL   0x07
+#define VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08
+#define VS_SYNC_DELAY_CONTROL           0x09
+
+#define TT_VENDOR_SPECIFIC              0x0100
+#define TT_STREAMING                    0x0101
+
+/* Input Terminal types */
+#define ITT_VENDOR_SPECIFIC             0x0200
+#define ITT_CAMERA                      0x0201
+#define ITT_MEDIA_TRANSPORT_INPUT       0x0202
+
+/* Output Terminal types */
+#define OTT_VENDOR_SPECIFIC             0x0300
+#define OTT_DISPLAY                     0x0301
+#define OTT_MEDIA_TRANSPORT_OUTPUT      0x0302
+
+/* External Terminal types */
+#define EXTERNAL_VENDOR_SPECIFIC        0x0400
+#define COMPOSITE_CONNECTOR             0x0401
+#define SVIDEO_CONNECTOR                0x0402
+#define COMPONENT_CONNECTOR             0x0403
+
+#define UVC_TERM_INPUT                 0x0000
+#define UVC_TERM_OUTPUT                        0x8000
+
+#define UVC_ENTITY_TYPE(entity)                ((entity)->type & 0x7fff)
+#define UVC_ENTITY_IS_UNIT(entity)     (((entity)->type & 0xff00) == 0)
+#define UVC_ENTITY_IS_TERM(entity)     (((entity)->type & 0xff00) != 0)
+#define UVC_ENTITY_IS_ITERM(entity) \
+       (((entity)->type & 0x8000) == UVC_TERM_INPUT)
+#define UVC_ENTITY_IS_OTERM(entity) \
+       (((entity)->type & 0x8000) == UVC_TERM_OUTPUT)
+
+#define UVC_STATUS_TYPE_CONTROL                1
+#define UVC_STATUS_TYPE_STREAMING      2
+
+/* ------------------------------------------------------------------------
+ * GUIDs
+ */
+#define UVC_GUID_UVC_CAMERA \
+       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
+#define UVC_GUID_UVC_OUTPUT \
+       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
+#define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \
+       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
+#define UVC_GUID_UVC_PROCESSING \
+       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01}
+#define UVC_GUID_UVC_SELECTOR \
+       {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}
+
+#define UVC_GUID_LOGITECH_DEV_INFO \
+       {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
+        0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1e}
+#define UVC_GUID_LOGITECH_USER_HW \
+       {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
+        0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1f}
+#define UVC_GUID_LOGITECH_VIDEO \
+       {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
+        0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x50}
+#define UVC_GUID_LOGITECH_MOTOR \
+       {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \
+        0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x56}
+
+#define UVC_GUID_FORMAT_MJPEG \
+       { 'M',  'J',  'P',  'G', 0x00, 0x00, 0x10, 0x00, \
+        0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_YUY2 \
+       { 'Y',  'U',  'Y',  '2', 0x00, 0x00, 0x10, 0x00, \
+        0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_NV12 \
+       { 'N',  'V',  '1',  '2', 0x00, 0x00, 0x10, 0x00, \
+        0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_YV12 \
+       { 'Y',  'V',  '1',  '2', 0x00, 0x00, 0x10, 0x00, \
+        0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_I420 \
+       { 'I',  '4',  '2',  '0', 0x00, 0x00, 0x10, 0x00, \
+        0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_UYVY \
+       { 'U',  'Y',  'V',  'Y', 0x00, 0x00, 0x10, 0x00, \
+        0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_Y800 \
+       { 'Y',  '8',  '0',  '0', 0x00, 0x00, 0x10, 0x00, \
+        0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_BY8 \
+       { 'B',  'Y',  '8',  ' ', 0x00, 0x00, 0x10, 0x00, \
+        0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+
+
+/* ------------------------------------------------------------------------
+ * Driver specific constants.
+ */
+
+#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(0, 1, 0)
+
+/* Number of isochronous URBs. */
+#define UVC_URBS               5
+/* Maximum number of packets per isochronous URB. */
+#define UVC_MAX_ISO_PACKETS    40
+/* Maximum frame size in bytes, for sanity checking. */
+#define UVC_MAX_FRAME_SIZE     (16*1024*1024)
+/* Maximum number of video buffers. */
+#define UVC_MAX_VIDEO_BUFFERS  32
+
+#define UVC_CTRL_CONTROL_TIMEOUT       300
+#define UVC_CTRL_STREAMING_TIMEOUT     1000
+
+/* Devices quirks */
+#define UVC_QUIRK_STATUS_INTERVAL      0x00000001
+#define UVC_QUIRK_PROBE_MINMAX         0x00000002
+#define UVC_QUIRK_PROBE_EXTRAFIELDS    0x00000004
+#define UVC_QUIRK_BUILTIN_ISIGHT       0x00000008
+#define UVC_QUIRK_STREAM_NO_FID                0x00000010
+#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
+
+/* Format flags */
+#define UVC_FMT_FLAG_COMPRESSED                0x00000001
+#define UVC_FMT_FLAG_STREAM            0x00000002
+
+/* ------------------------------------------------------------------------
+ * Structures.
+ */
+
+struct uvc_device;
+
+/* TODO: Put the most frequently accessed fields at the beginning of
+ * structures to maximize cache efficiency.
+ */
+struct uvc_streaming_control {
+       __u16 bmHint;
+       __u8  bFormatIndex;
+       __u8  bFrameIndex;
+       __u32 dwFrameInterval;
+       __u16 wKeyFrameRate;
+       __u16 wPFrameRate;
+       __u16 wCompQuality;
+       __u16 wCompWindowSize;
+       __u16 wDelay;
+       __u32 dwMaxVideoFrameSize;
+       __u32 dwMaxPayloadTransferSize;
+       __u32 dwClockFrequency;
+       __u8  bmFramingInfo;
+       __u8  bPreferedVersion;
+       __u8  bMinVersion;
+       __u8  bMaxVersion;
+};
+
+struct uvc_menu_info {
+       __u32 value;
+       __u8 name[32];
+};
+
+struct uvc_control_info {
+       struct list_head list;
+       struct list_head mappings;
+
+       __u8 entity[16];
+       __u8 index;
+       __u8 selector;
+
+       __u16 size;
+       __u32 flags;
+};
+
+struct uvc_control_mapping {
+       struct list_head list;
+
+       struct uvc_control_info *ctrl;
+
+       __u32 id;
+       __u8 name[32];
+       __u8 entity[16];
+       __u8 selector;
+
+       __u8 size;
+       __u8 offset;
+       enum v4l2_ctrl_type v4l2_type;
+       __u32 data_type;
+
+       struct uvc_menu_info *menu_info;
+       __u32 menu_count;
+};
+
+struct uvc_control {
+       struct uvc_entity *entity;
+       struct uvc_control_info *info;
+
+       __u8 index;     /* Used to match the uvc_control entry with a
+                          uvc_control_info. */
+       __u8 dirty : 1,
+            loaded : 1,
+            modified : 1;
+
+       __u8 *data;
+};
+
+struct uvc_format_desc {
+       char *name;
+       __u8 guid[16];
+       __u32 fcc;
+};
+
+/* The term 'entity' refers to both UVC units and UVC terminals.
+ *
+ * The type field is either the terminal type (wTerminalType in the terminal
+ * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
+ * As the bDescriptorSubtype field is one byte long, the type value will
+ * always have a null MSB for units. All terminal types defined by the UVC
+ * specification have a non-null MSB, so it is safe to use the MSB to
+ * differentiate between units and terminals as long as the descriptor parsing
+ * code makes sure terminal types have a non-null MSB.
+ *
+ * For terminals, the type's most significant bit stores the terminal
+ * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
+ * always be accessed with the UVC_ENTITY_* macros and never directly.
+ */
+
+struct uvc_entity {
+       struct list_head list;          /* Entity as part of a UVC device. */
+       struct list_head chain;         /* Entity as part of a video device
+                                        * chain. */
+       __u8 id;
+       __u16 type;
+       char name[64];
+
+       union {
+               struct {
+                       __u16 wObjectiveFocalLengthMin;
+                       __u16 wObjectiveFocalLengthMax;
+                       __u16 wOcularFocalLength;
+                       __u8  bControlSize;
+                       __u8  *bmControls;
+               } camera;
+
+               struct {
+                       __u8  bControlSize;
+                       __u8  *bmControls;
+                       __u8  bTransportModeSize;
+                       __u8  *bmTransportModes;
+               } media;
+
+               struct {
+                       __u8  bSourceID;
+               } output;
+
+               struct {
+                       __u8  bSourceID;
+                       __u16 wMaxMultiplier;
+                       __u8  bControlSize;
+                       __u8  *bmControls;
+                       __u8  bmVideoStandards;
+               } processing;
+
+               struct {
+                       __u8  bNrInPins;
+                       __u8  *baSourceID;
+               } selector;
+
+               struct {
+                       __u8  guidExtensionCode[16];
+                       __u8  bNumControls;
+                       __u8  bNrInPins;
+                       __u8  *baSourceID;
+                       __u8  bControlSize;
+                       __u8  *bmControls;
+                       __u8  *bmControlsType;
+               } extension;
+       };
+
+       unsigned int ncontrols;
+       struct uvc_control *controls;
+};
+
+struct uvc_frame {
+       __u8  bFrameIndex;
+       __u8  bmCapabilities;
+       __u16 wWidth;
+       __u16 wHeight;
+       __u32 dwMinBitRate;
+       __u32 dwMaxBitRate;
+       __u32 dwMaxVideoFrameBufferSize;
+       __u8  bFrameIntervalType;
+       __u32 dwDefaultFrameInterval;
+       __u32 *dwFrameInterval;
+};
+
+struct uvc_format {
+       __u8 type;
+       __u8 index;
+       __u8 bpp;
+       __u8 colorspace;
+       __u32 fcc;
+       __u32 flags;
+
+       char name[32];
+
+       unsigned int nframes;
+       struct uvc_frame *frame;
+};
+
+struct uvc_streaming_header {
+       __u8 bNumFormats;
+       __u8 bEndpointAddress;
+       __u8 bTerminalLink;
+       __u8 bControlSize;
+       __u8 *bmaControls;
+       /* The following fields are used by input headers only. */
+       __u8 bmInfo;
+       __u8 bStillCaptureMethod;
+       __u8 bTriggerSupport;
+       __u8 bTriggerUsage;
+};
+
+struct uvc_streaming {
+       struct list_head list;
+
+       struct usb_interface *intf;
+       int intfnum;
+       __u16 maxpsize;
+
+       struct uvc_streaming_header header;
+
+       unsigned int nformats;
+       struct uvc_format *format;
+
+       struct uvc_streaming_control ctrl;
+       struct uvc_format *cur_format;
+       struct uvc_frame *cur_frame;
+
+       struct mutex mutex;
+};
+
+enum uvc_buffer_state {
+       UVC_BUF_STATE_IDLE       = 0,
+       UVC_BUF_STATE_QUEUED     = 1,
+       UVC_BUF_STATE_ACTIVE     = 2,
+       UVC_BUF_STATE_DONE       = 3,
+       UVC_BUF_STATE_ERROR      = 4,
+};
+
+struct uvc_buffer {
+       unsigned long vma_use_count;
+       struct list_head stream;
+
+       /* Touched by interrupt handler. */
+       struct v4l2_buffer buf;
+       struct list_head queue;
+       wait_queue_head_t wait;
+       enum uvc_buffer_state state;
+};
+
+#define UVC_QUEUE_STREAMING            (1 << 0)
+#define UVC_QUEUE_DISCONNECTED         (1 << 1)
+#define UVC_QUEUE_DROP_INCOMPLETE      (1 << 2)
+
+struct uvc_video_queue {
+       void *mem;
+       unsigned int flags;
+       __u32 sequence;
+
+       unsigned int count;
+       unsigned int buf_size;
+       struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
+       struct mutex mutex;     /* protects buffers and mainqueue */
+       spinlock_t irqlock;     /* protects irqqueue */
+
+       struct list_head mainqueue;
+       struct list_head irqqueue;
+};
+
+struct uvc_video_device {
+       struct uvc_device *dev;
+       struct video_device *vdev;
+       atomic_t active;
+       unsigned int frozen : 1;
+
+       struct list_head iterms;
+       struct uvc_entity *oterm;
+       struct uvc_entity *processing;
+       struct uvc_entity *selector;
+       struct list_head extensions;
+       struct mutex ctrl_mutex;
+
+       struct uvc_video_queue queue;
+
+       /* Video streaming object, must always be non-NULL. */
+       struct uvc_streaming *streaming;
+
+       void (*decode) (struct urb *urb, struct uvc_video_device *video,
+                       struct uvc_buffer *buf);
+
+       /* Context data used by the bulk completion handler. */
+       struct {
+               __u8 header[256];
+               unsigned int header_size;
+               int skip_payload;
+               __u32 payload_size;
+               __u32 max_payload_size;
+       } bulk;
+
+       struct urb *urb[UVC_URBS];
+       char *urb_buffer[UVC_URBS];
+
+       __u8 last_fid;
+};
+
+enum uvc_device_state {
+       UVC_DEV_DISCONNECTED = 1,
+};
+
+struct uvc_device {
+       struct usb_device *udev;
+       struct usb_interface *intf;
+       __u32 quirks;
+       int intfnum;
+       char name[32];
+
+       enum uvc_device_state state;
+       struct kref kref;
+       struct list_head list;
+
+       /* Video control interface */
+       __u16 uvc_version;
+       __u32 clock_frequency;
+
+       struct list_head entities;
+
+       struct uvc_video_device video;
+
+       /* Status Interrupt Endpoint */
+       struct usb_host_endpoint *int_ep;
+       struct urb *int_urb;
+       __u8 status[16];
+       struct input_dev *input;
+
+       /* Video Streaming interfaces */
+       struct list_head streaming;
+};
+
+enum uvc_handle_state {
+       UVC_HANDLE_PASSIVE      = 0,
+       UVC_HANDLE_ACTIVE       = 1,
+};
+
+struct uvc_fh {
+       struct uvc_video_device *device;
+       enum uvc_handle_state state;
+};
+
+struct uvc_driver {
+       struct usb_driver driver;
+
+       struct mutex open_mutex;        /* protects from open/disconnect race */
+
+       struct list_head devices;       /* struct uvc_device list */
+       struct list_head controls;      /* struct uvc_control_info list */
+       struct mutex ctrl_mutex;        /* protects controls and devices
+                                          lists */
+};
+
+/* ------------------------------------------------------------------------
+ * Debugging, printing and logging
+ */
+
+#define UVC_TRACE_PROBE                (1 << 0)
+#define UVC_TRACE_DESCR                (1 << 1)
+#define UVC_TRACE_CONTROL      (1 << 2)
+#define UVC_TRACE_FORMAT       (1 << 3)
+#define UVC_TRACE_CAPTURE      (1 << 4)
+#define UVC_TRACE_CALLS                (1 << 5)
+#define UVC_TRACE_IOCTL                (1 << 6)
+#define UVC_TRACE_FRAME                (1 << 7)
+#define UVC_TRACE_SUSPEND      (1 << 8)
+#define UVC_TRACE_STATUS       (1 << 9)
+
+extern unsigned int uvc_trace_param;
+
+#define uvc_trace(flag, msg...) \
+       do { \
+               if (uvc_trace_param & flag) \
+                       printk(KERN_DEBUG "uvcvideo: " msg); \
+       } while (0)
+
+#define uvc_printk(level, msg...) \
+       printk(level "uvcvideo: " msg)
+
+#define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \
+                       "%02x%02x%02x%02x%02x%02x"
+#define UVC_GUID_ARGS(guid) \
+       (guid)[3],  (guid)[2],  (guid)[1],  (guid)[0], \
+       (guid)[5],  (guid)[4], \
+       (guid)[7],  (guid)[6], \
+       (guid)[8],  (guid)[9], \
+       (guid)[10], (guid)[11], (guid)[12], \
+       (guid)[13], (guid)[14], (guid)[15]
+
+/* --------------------------------------------------------------------------
+ * Internal functions.
+ */
+
+/* Core driver */
+extern struct uvc_driver uvc_driver;
+extern void uvc_delete(struct kref *kref);
+
+/* Video buffers queue management. */
+extern void uvc_queue_init(struct uvc_video_queue *queue);
+extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
+               unsigned int nbuffers, unsigned int buflength);
+extern int uvc_free_buffers(struct uvc_video_queue *queue);
+extern int uvc_query_buffer(struct uvc_video_queue *queue,
+               struct v4l2_buffer *v4l2_buf);
+extern int uvc_queue_buffer(struct uvc_video_queue *queue,
+               struct v4l2_buffer *v4l2_buf);
+extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
+               struct v4l2_buffer *v4l2_buf, int nonblocking);
+extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
+extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
+extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
+               struct uvc_buffer *buf);
+extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
+               struct file *file, poll_table *wait);
+static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
+{
+       return queue->flags & UVC_QUEUE_STREAMING;
+}
+
+/* V4L2 interface */
+extern struct file_operations uvc_fops;
+
+/* Video */
+extern int uvc_video_init(struct uvc_video_device *video);
+extern int uvc_video_suspend(struct uvc_video_device *video);
+extern int uvc_video_resume(struct uvc_video_device *video);
+extern int uvc_video_enable(struct uvc_video_device *video, int enable);
+extern int uvc_probe_video(struct uvc_video_device *video,
+               struct uvc_streaming_control *probe);
+extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
+               __u8 intfnum, __u8 cs, void *data, __u16 size);
+extern int uvc_set_video_ctrl(struct uvc_video_device *video,
+               struct uvc_streaming_control *ctrl, int probe);
+
+/* Status */
+extern int uvc_status_init(struct uvc_device *dev);
+extern void uvc_status_cleanup(struct uvc_device *dev);
+extern int uvc_status_suspend(struct uvc_device *dev);
+extern int uvc_status_resume(struct uvc_device *dev);
+
+/* Controls */
+extern struct uvc_control *uvc_find_control(struct uvc_video_device *video,
+               __u32 v4l2_id, struct uvc_control_mapping **mapping);
+extern int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
+               struct v4l2_queryctrl *v4l2_ctrl);
+
+extern int uvc_ctrl_add_info(struct uvc_control_info *info);
+extern int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping);
+extern int uvc_ctrl_init_device(struct uvc_device *dev);
+extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
+extern int uvc_ctrl_resume_device(struct uvc_device *dev);
+extern void uvc_ctrl_init(void);
+
+extern int uvc_ctrl_begin(struct uvc_video_device *video);
+extern int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback);
+static inline int uvc_ctrl_commit(struct uvc_video_device *video)
+{
+       return __uvc_ctrl_commit(video, 0);
+}
+static inline int uvc_ctrl_rollback(struct uvc_video_device *video)
+{
+       return __uvc_ctrl_commit(video, 1);
+}
+
+extern int uvc_ctrl_get(struct uvc_video_device *video,
+               struct v4l2_ext_control *xctrl);
+extern int uvc_ctrl_set(struct uvc_video_device *video,
+               struct v4l2_ext_control *xctrl);
+
+extern int uvc_xu_ctrl_query(struct uvc_video_device *video,
+               struct uvc_xu_control *ctrl, int set);
+
+/* Utility functions */
+extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
+               unsigned int n_terms, unsigned int threshold);
+extern uint32_t uvc_fraction_to_interval(uint32_t numerator,
+               uint32_t denominator);
+extern struct usb_host_endpoint *uvc_find_endpoint(
+               struct usb_host_interface *alts, __u8 epaddr);
+
+/* Quirks support */
+void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video,
+               struct uvc_buffer *buf);
+
+#endif /* __KERNEL__ */
+
+#endif
index 31e8af0ba2785e105e60587b8153602b948f55eb..67a661cf5219bc65e225f304d5872579c034313b 100644 (file)
 #define VIDEO_NUM_DEVICES      256
 #define VIDEO_NAME              "video4linux"
 
+struct std_descr {
+       v4l2_std_id std;
+       const char *descr;
+};
+
+static const struct std_descr standards[] = {
+       { V4L2_STD_NTSC,        "NTSC"      },
+       { V4L2_STD_NTSC_M,      "NTSC-M"    },
+       { V4L2_STD_NTSC_M_JP,   "NTSC-M-JP" },
+       { V4L2_STD_NTSC_M_KR,   "NTSC-M-KR" },
+       { V4L2_STD_NTSC_443,    "NTSC-443"  },
+       { V4L2_STD_PAL,         "PAL"       },
+       { V4L2_STD_PAL_BG,      "PAL-BG"    },
+       { V4L2_STD_PAL_B,       "PAL-B"     },
+       { V4L2_STD_PAL_B1,      "PAL-B1"    },
+       { V4L2_STD_PAL_G,       "PAL-G"     },
+       { V4L2_STD_PAL_H,       "PAL-H"     },
+       { V4L2_STD_PAL_I,       "PAL-I"     },
+       { V4L2_STD_PAL_DK,      "PAL-DK"    },
+       { V4L2_STD_PAL_D,       "PAL-D"     },
+       { V4L2_STD_PAL_D1,      "PAL-D1"    },
+       { V4L2_STD_PAL_K,       "PAL-K"     },
+       { V4L2_STD_PAL_M,       "PAL-M"     },
+       { V4L2_STD_PAL_N,       "PAL-N"     },
+       { V4L2_STD_PAL_Nc,      "PAL-Nc"    },
+       { V4L2_STD_PAL_60,      "PAL-60"    },
+       { V4L2_STD_SECAM,       "SECAM"     },
+       { V4L2_STD_SECAM_B,     "SECAM-B"   },
+       { V4L2_STD_SECAM_G,     "SECAM-G"   },
+       { V4L2_STD_SECAM_H,     "SECAM-H"   },
+       { V4L2_STD_SECAM_DK,    "SECAM-DK"  },
+       { V4L2_STD_SECAM_D,     "SECAM-D"   },
+       { V4L2_STD_SECAM_K,     "SECAM-K"   },
+       { V4L2_STD_SECAM_K1,    "SECAM-K1"  },
+       { V4L2_STD_SECAM_L,     "SECAM-L"   },
+       { V4L2_STD_SECAM_LC,    "SECAM-Lc"  },
+       { 0,                    "Unknown"   }
+};
+
 /* video4linux standard ID conversion to standard name
  */
-char *v4l2_norm_to_name(v4l2_std_id id)
+const char *v4l2_norm_to_name(v4l2_std_id id)
 {
-       char *name;
        u32 myid = id;
+       int i;
 
        /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
           64 bit comparations. So, on that architecture, with some gcc
@@ -64,110 +103,17 @@ char *v4l2_norm_to_name(v4l2_std_id id)
         */
        BUG_ON(myid != id);
 
-       switch (myid) {
-       case V4L2_STD_PAL:
-               name = "PAL";
-               break;
-       case V4L2_STD_PAL_BG:
-               name = "PAL-BG";
-               break;
-       case V4L2_STD_PAL_DK:
-               name = "PAL-DK";
-               break;
-       case V4L2_STD_PAL_B:
-               name = "PAL-B";
-               break;
-       case V4L2_STD_PAL_B1:
-               name = "PAL-B1";
-               break;
-       case V4L2_STD_PAL_G:
-               name = "PAL-G";
-               break;
-       case V4L2_STD_PAL_H:
-               name = "PAL-H";
-               break;
-       case V4L2_STD_PAL_I:
-               name = "PAL-I";
-               break;
-       case V4L2_STD_PAL_D:
-               name = "PAL-D";
-               break;
-       case V4L2_STD_PAL_D1:
-               name = "PAL-D1";
-               break;
-       case V4L2_STD_PAL_K:
-               name = "PAL-K";
-               break;
-       case V4L2_STD_PAL_M:
-               name = "PAL-M";
-               break;
-       case V4L2_STD_PAL_N:
-               name = "PAL-N";
-               break;
-       case V4L2_STD_PAL_Nc:
-               name = "PAL-Nc";
-               break;
-       case V4L2_STD_PAL_60:
-               name = "PAL-60";
-               break;
-       case V4L2_STD_NTSC:
-               name = "NTSC";
-               break;
-       case V4L2_STD_NTSC_M:
-               name = "NTSC-M";
-               break;
-       case V4L2_STD_NTSC_M_JP:
-               name = "NTSC-M-JP";
-               break;
-       case V4L2_STD_NTSC_443:
-               name = "NTSC-443";
-               break;
-       case V4L2_STD_NTSC_M_KR:
-               name = "NTSC-M-KR";
-               break;
-       case V4L2_STD_SECAM:
-               name = "SECAM";
-               break;
-       case V4L2_STD_SECAM_DK:
-               name = "SECAM-DK";
-               break;
-       case V4L2_STD_SECAM_B:
-               name = "SECAM-B";
-               break;
-       case V4L2_STD_SECAM_D:
-               name = "SECAM-D";
-               break;
-       case V4L2_STD_SECAM_G:
-               name = "SECAM-G";
-               break;
-       case V4L2_STD_SECAM_H:
-               name = "SECAM-H";
-               break;
-       case V4L2_STD_SECAM_K:
-               name = "SECAM-K";
-               break;
-       case V4L2_STD_SECAM_K1:
-               name = "SECAM-K1";
-               break;
-       case V4L2_STD_SECAM_L:
-               name = "SECAM-L";
-               break;
-       case V4L2_STD_SECAM_LC:
-               name = "SECAM-LC";
-               break;
-       default:
-               name = "Unknown";
-               break;
-       }
-
-       return name;
+       for (i = 0; standards[i].std; i++)
+               if (myid == standards[i].std)
+                       break;
+       return standards[i].descr;
 }
 EXPORT_SYMBOL(v4l2_norm_to_name);
 
 /* Fill in the fields of a v4l2_standard structure according to the
    'id' and 'transmission' parameters.  Returns negative on error.  */
 int v4l2_video_std_construct(struct v4l2_standard *vs,
-                            int id, char *name)
+                            int id, const char *name)
 {
        u32 index = vs->index;
 
@@ -1218,95 +1164,40 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
        case VIDIOC_ENUMSTD:
        {
                struct v4l2_standard *p = arg;
-               v4l2_std_id id = vfd->tvnorms,curr_id=0;
-               unsigned int index = p->index,i;
-
-               if (index<0) {
-                       ret=-EINVAL;
-                       break;
-               }
-
-               /* Return norm array on a canonical way */
-               for (i=0;i<= index && id; i++) {
-                       if ( (id & V4L2_STD_PAL) == V4L2_STD_PAL) {
-                               curr_id = V4L2_STD_PAL;
-                       } else if ( (id & V4L2_STD_PAL_BG) == V4L2_STD_PAL_BG) {
-                               curr_id = V4L2_STD_PAL_BG;
-                       } else if ( (id & V4L2_STD_PAL_DK) == V4L2_STD_PAL_DK) {
-                               curr_id = V4L2_STD_PAL_DK;
-                       } else if ( (id & V4L2_STD_PAL_B) == V4L2_STD_PAL_B) {
-                               curr_id = V4L2_STD_PAL_B;
-                       } else if ( (id & V4L2_STD_PAL_B1) == V4L2_STD_PAL_B1) {
-                               curr_id = V4L2_STD_PAL_B1;
-                       } else if ( (id & V4L2_STD_PAL_G) == V4L2_STD_PAL_G) {
-                               curr_id = V4L2_STD_PAL_G;
-                       } else if ( (id & V4L2_STD_PAL_H) == V4L2_STD_PAL_H) {
-                               curr_id = V4L2_STD_PAL_H;
-                       } else if ( (id & V4L2_STD_PAL_I) == V4L2_STD_PAL_I) {
-                               curr_id = V4L2_STD_PAL_I;
-                       } else if ( (id & V4L2_STD_PAL_D) == V4L2_STD_PAL_D) {
-                               curr_id = V4L2_STD_PAL_D;
-                       } else if ( (id & V4L2_STD_PAL_D1) == V4L2_STD_PAL_D1) {
-                               curr_id = V4L2_STD_PAL_D1;
-                       } else if ( (id & V4L2_STD_PAL_K) == V4L2_STD_PAL_K) {
-                               curr_id = V4L2_STD_PAL_K;
-                       } else if ( (id & V4L2_STD_PAL_M) == V4L2_STD_PAL_M) {
-                               curr_id = V4L2_STD_PAL_M;
-                       } else if ( (id & V4L2_STD_PAL_N) == V4L2_STD_PAL_N) {
-                               curr_id = V4L2_STD_PAL_N;
-                       } else if ( (id & V4L2_STD_PAL_Nc) == V4L2_STD_PAL_Nc) {
-                               curr_id = V4L2_STD_PAL_Nc;
-                       } else if ( (id & V4L2_STD_PAL_60) == V4L2_STD_PAL_60) {
-                               curr_id = V4L2_STD_PAL_60;
-                       } else if ( (id & V4L2_STD_NTSC) == V4L2_STD_NTSC) {
-                               curr_id = V4L2_STD_NTSC;
-                       } else if ( (id & V4L2_STD_NTSC_M) == V4L2_STD_NTSC_M) {
-                               curr_id = V4L2_STD_NTSC_M;
-                       } else if ( (id & V4L2_STD_NTSC_M_JP) == V4L2_STD_NTSC_M_JP) {
-                               curr_id = V4L2_STD_NTSC_M_JP;
-                       } else if ( (id & V4L2_STD_NTSC_443) == V4L2_STD_NTSC_443) {
-                               curr_id = V4L2_STD_NTSC_443;
-                       } else if ( (id & V4L2_STD_NTSC_M_KR) == V4L2_STD_NTSC_M_KR) {
-                               curr_id = V4L2_STD_NTSC_M_KR;
-                       } else if ( (id & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
-                               curr_id = V4L2_STD_SECAM;
-                       } else if ( (id & V4L2_STD_SECAM_DK) == V4L2_STD_SECAM_DK) {
-                               curr_id = V4L2_STD_SECAM_DK;
-                       } else if ( (id & V4L2_STD_SECAM_B) == V4L2_STD_SECAM_B) {
-                               curr_id = V4L2_STD_SECAM_B;
-                       } else if ( (id & V4L2_STD_SECAM_D) == V4L2_STD_SECAM_D) {
-                               curr_id = V4L2_STD_SECAM_D;
-                       } else if ( (id & V4L2_STD_SECAM_G) == V4L2_STD_SECAM_G) {
-                               curr_id = V4L2_STD_SECAM_G;
-                       } else if ( (id & V4L2_STD_SECAM_H) == V4L2_STD_SECAM_H) {
-                               curr_id = V4L2_STD_SECAM_H;
-                       } else if ( (id & V4L2_STD_SECAM_K) == V4L2_STD_SECAM_K) {
-                               curr_id = V4L2_STD_SECAM_K;
-                       } else if ( (id & V4L2_STD_SECAM_K1) == V4L2_STD_SECAM_K1) {
-                               curr_id = V4L2_STD_SECAM_K1;
-                       } else if ( (id & V4L2_STD_SECAM_L) == V4L2_STD_SECAM_L) {
-                               curr_id = V4L2_STD_SECAM_L;
-                       } else if ( (id & V4L2_STD_SECAM_LC) == V4L2_STD_SECAM_LC) {
-                               curr_id = V4L2_STD_SECAM_LC;
-                       } else {
+               v4l2_std_id id = vfd->tvnorms, curr_id = 0;
+               unsigned int index = p->index, i, j = 0;
+               const char *descr = "";
+
+               /* Return norm array in a canonical way */
+               for (i = 0; i <= index && id; i++) {
+                       /* last std value in the standards array is 0, so this
+                          while always ends there since (id & 0) == 0. */
+                       while ((id & standards[j].std) != standards[j].std)
+                               j++;
+                       curr_id = standards[j].std;
+                       descr = standards[j].descr;
+                       j++;
+                       if (curr_id == 0)
                                break;
-                       }
-                       id &= ~curr_id;
+                       if (curr_id != V4L2_STD_PAL &&
+                           curr_id != V4L2_STD_SECAM &&
+                           curr_id != V4L2_STD_NTSC)
+                               id &= ~curr_id;
                }
-               if (i<=index)
+               if (i <= index)
                        return -EINVAL;
 
-               v4l2_video_std_construct(p, curr_id,v4l2_norm_to_name(curr_id));
+               v4l2_video_std_construct(p, curr_id, descr);
                p->index = index;
 
-               dbgarg (cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
+               dbgarg(cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
                                "framelines=%d\n", p->index,
                                (unsigned long long)p->id, p->name,
                                p->frameperiod.numerator,
                                p->frameperiod.denominator,
                                p->framelines);
 
-               ret=0;
+               ret = 0;
                break;
        }
        case VIDIOC_G_STD:
index 845be1864f685a01fad3a225bc9826ab09d61985..5ff9a58b6135b98b8644af14d042cc31cc824a5a 100644 (file)
@@ -327,13 +327,14 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
        int hmax  = buf->vb.height;
        int wmax  = buf->vb.width;
        struct timeval ts;
-       char *tmpbuf = kmalloc(wmax * 2, GFP_ATOMIC);
+       char *tmpbuf;
        void *vbuf = videobuf_to_vmalloc(&buf->vb);
 
-       if (!tmpbuf)
+       if (!vbuf)
                return;
 
-       if (!vbuf)
+       tmpbuf = kmalloc(wmax * 2, GFP_ATOMIC);
+       if (!tmpbuf)
                return;
 
        for (h = 0; h < hmax; h++) {
index 07c2048b230ba0ec37d8ca3d140921162ae96253..b413aa6c246b938649f47e63a2af5482f76fdc11 100644 (file)
@@ -55,6 +55,10 @@ static unsigned int debug_quirks = 0;
 #define SDHCI_QUIRK_32BIT_DMA_SIZE                     (1<<7)
 /* Controller needs to be reset after each request to stay stable */
 #define SDHCI_QUIRK_RESET_AFTER_REQUEST                        (1<<8)
+/* Controller needs voltage and power writes to happen separately */
+#define SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER            (1<<9)
+/* Controller has an off-by-one issue with timeout value */
+#define SDHCI_QUIRK_INCR_TIMEOUT_CONTROL               (1<<10)
 
 static const struct pci_device_id pci_ids[] __devinitdata = {
        {
@@ -115,7 +119,8 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
                .subvendor      = PCI_ANY_ID,
                .subdevice      = PCI_ANY_ID,
                .driver_data    = SDHCI_QUIRK_SINGLE_POWER_WRITE |
-                                 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS,
+                                 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
+                                 SDHCI_QUIRK_BROKEN_DMA,
        },
 
        {
@@ -124,7 +129,17 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
                .subvendor      = PCI_ANY_ID,
                .subdevice      = PCI_ANY_ID,
                .driver_data    = SDHCI_QUIRK_SINGLE_POWER_WRITE |
-                                 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS,
+                                 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
+                                 SDHCI_QUIRK_BROKEN_DMA,
+       },
+
+       {
+               .vendor         = PCI_VENDOR_ID_MARVELL,
+               .device         = PCI_DEVICE_ID_MARVELL_CAFE_SD,
+               .subvendor      = PCI_ANY_ID,
+               .subdevice      = PCI_ANY_ID,
+               .driver_data    = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
+                                 SDHCI_QUIRK_INCR_TIMEOUT_CONTROL,
        },
 
        {
@@ -469,6 +484,13 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
                        break;
        }
 
+       /*
+        * Compensate for an off-by-one error in the CaFe hardware; otherwise,
+        * a too-small count gives us interrupt timeouts.
+        */
+       if ((host->chip->quirks & SDHCI_QUIRK_INCR_TIMEOUT_CONTROL))
+               count++;
+
        if (count >= 0xF) {
                printk(KERN_WARNING "%s: Too large timeout requested!\n",
                        mmc_hostname(host->mmc));
@@ -774,6 +796,14 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
                BUG();
        }
 
+       /*
+        * At least the CaFe chip gets confused if we set the voltage
+        * and set turn on power at the same time, so set the voltage first.
+        */
+       if ((host->chip->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER))
+               writeb(pwr & ~SDHCI_POWER_ON,
+                               host->ioaddr + SDHCI_POWER_CONTROL);
+
        writeb(pwr, host->ioaddr + SDHCI_POWER_CONTROL);
 
 out:
index 2edda8cc7f9999af1e5f772df389c20719373190..aabad8ce7458c852a496422991c0683c0fe43d26 100644 (file)
@@ -1768,9 +1768,10 @@ vortex_timer(unsigned long data)
        case XCVR_MII: case XCVR_NWAY:
                {
                        ok = 1;
-                       spin_lock_bh(&vp->lock);
+                       /* Interrupts are already disabled */
+                       spin_lock(&vp->lock);
                        vortex_check_media(dev, 0);
-                       spin_unlock_bh(&vp->lock);
+                       spin_unlock(&vp->lock);
                }
                break;
          default:                                      /* Other media types handled by Tx timeouts. */
index f3cba5e24ec511a7a08ea6c0659155850a165b00..1037b1332312998aa36274b279381263419f0371 100644 (file)
@@ -1803,6 +1803,8 @@ static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx)
        if (rx->prev->skb) {
                struct rfd *prev_rfd = (struct rfd *)rx->prev->skb->data;
                put_unaligned_le32(rx->dma_addr, &prev_rfd->link);
+               pci_dma_sync_single_for_device(nic->pdev, rx->prev->dma_addr,
+                       sizeof(struct rfd), PCI_DMA_TODEVICE);
        }
 
        return 0;
index 701531e72e7b3b4d1ddab378e5b05795c320d052..a3f6a9c72ec8546b11ab987b27ea330ca1fba5e2 100644 (file)
@@ -347,7 +347,7 @@ e1000_set_tso(struct net_device *netdev, u32 data)
        else
                netdev->features &= ~NETIF_F_TSO;
 
-       if (data)
+       if (data && (adapter->hw.mac_type > e1000_82547_rev_2))
                netdev->features |= NETIF_F_TSO6;
        else
                netdev->features &= ~NETIF_F_TSO6;
index cab1835173cd9bb7096f82647a5f59ae13eaba18..648a87bbf4670ae8f87ffce4f123769d66de84f6 100644 (file)
@@ -2535,7 +2535,8 @@ void e1000e_down(struct e1000_adapter *adapter)
        adapter->link_speed = 0;
        adapter->link_duplex = 0;
 
-       e1000e_reset(adapter);
+       if (!pci_channel_offline(adapter->pdev))
+               e1000e_reset(adapter);
        e1000_clean_tx_ring(adapter);
        e1000_clean_rx_ring(adapter);
 
index 0b94833e23f7a48b76d16e3f5419d24d7f0556a7..e8cfadefa4b6751dbb74bd663a0f101e76a98d54 100644 (file)
@@ -1077,8 +1077,6 @@ static inline void rx_off(struct scc_priv *priv)
 
 static void start_timer(struct scc_priv *priv, int t, int r15)
 {
-       unsigned long flags;
-
        outb(priv->tmr_mode, priv->tmr_ctrl);
        if (t == 0) {
                tm_isr(priv);
index ae398f04c7b44d8ef8865ed4f902dba1d12a0172..e79a26a886c883e0fc56ba0318a1aaa87b41e366 100644 (file)
@@ -718,7 +718,8 @@ void igb_down(struct igb_adapter *adapter)
        adapter->link_speed = 0;
        adapter->link_duplex = 0;
 
-       igb_reset(adapter);
+       if (!pci_channel_offline(adapter->pdev))
+               igb_reset(adapter);
        igb_clean_all_tx_rings(adapter);
        igb_clean_all_rx_rings(adapter);
 }
index 679a0826780e3471346a902c516daf534811e80c..2c03f4e2ccc44427206e8a868412be0bb92fac49 100644 (file)
@@ -1271,7 +1271,7 @@ static void ipg_nic_rx_with_end(struct net_device *dev,
 
                        framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN;
 
-                       endframeLen = framelen - jumbo->current_size;
+                       endframelen = framelen - jumbo->current_size;
                        /*
                        if (framelen > IPG_RXFRAG_SIZE)
                                framelen=IPG_RXFRAG_SIZE;
@@ -1279,8 +1279,8 @@ static void ipg_nic_rx_with_end(struct net_device *dev,
                        if (framelen > IPG_RXSUPPORT_SIZE)
                                dev_kfree_skb_irq(jumbo->skb);
                        else {
-                               memcpy(skb_put(jumbo->skb, endframeLen),
-                                      skb->data, endframeLen);
+                               memcpy(skb_put(jumbo->skb, endframelen),
+                                      skb->data, endframelen);
 
                                jumbo->skb->protocol =
                                    eth_type_trans(jumbo->skb, dev);
@@ -1352,16 +1352,16 @@ static int ipg_nic_rx(struct net_device *dev)
 
                switch (ipg_nic_rx_check_frame_type(dev)) {
                case FRAME_WITH_START_WITH_END:
-                       ipg_nic_rx_with_start_and_end(dev, tp, rxfd, entry);
+                       ipg_nic_rx_with_start_and_end(dev, sp, rxfd, entry);
                        break;
                case FRAME_WITH_START:
-                       ipg_nic_rx_with_start(dev, tp, rxfd, entry);
+                       ipg_nic_rx_with_start(dev, sp, rxfd, entry);
                        break;
                case FRAME_WITH_END:
-                       ipg_nic_rx_with_end(dev, tp, rxfd, entry);
+                       ipg_nic_rx_with_end(dev, sp, rxfd, entry);
                        break;
                case FRAME_NO_START_NO_END:
-                       ipg_nic_rx_no_start_no_end(dev, tp, rxfd, entry);
+                       ipg_nic_rx_no_start_no_end(dev, sp, rxfd, entry);
                        break;
                }
        }
@@ -1808,7 +1808,7 @@ static int ipg_nic_open(struct net_device *dev)
        /* initialize JUMBO Frame control variable */
        sp->jumbo.found_start = 0;
        sp->jumbo.current_size = 0;
-       sp->jumbo.skb = 0;
+       sp->jumbo.skb = NULL;
        dev->mtu = IPG_TXFRAG_SIZE;
 #endif
 
index 7b859220c255b3b81017f156548df2dcca2f32e7..8f04609011538e257b820e9b521359750073cc63 100644 (file)
@@ -1969,7 +1969,8 @@ void ixgbe_down(struct ixgbe_adapter *adapter)
        netif_carrier_off(netdev);
        netif_stop_queue(netdev);
 
-       ixgbe_reset(adapter);
+       if (!pci_channel_offline(adapter->pdev))
+               ixgbe_reset(adapter);
        ixgbe_clean_all_tx_rings(adapter);
        ixgbe_clean_all_rx_rings(adapter);
 
index 6797ed069f1f43ed659147da5d925bda1036e9e8..63cd67b931e7537cde2c407c63812c9fd3ffac02 100644 (file)
@@ -71,14 +71,18 @@ static irqreturn_t netxen_intr(int irq, void *data);
 static irqreturn_t netxen_msi_intr(int irq, void *data);
 
 /*  PCI Device ID Table  */
+#define ENTRY(device) \
+       {PCI_DEVICE(0x4040, (device)), \
+       .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
+
 static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
-       {PCI_DEVICE(0x4040, 0x0001), PCI_DEVICE_CLASS(0x020000, ~0)},
-       {PCI_DEVICE(0x4040, 0x0002), PCI_DEVICE_CLASS(0x020000, ~0)},
-       {PCI_DEVICE(0x4040, 0x0003), PCI_DEVICE_CLASS(0x020000, ~0)},
-       {PCI_DEVICE(0x4040, 0x0004), PCI_DEVICE_CLASS(0x020000, ~0)},
-       {PCI_DEVICE(0x4040, 0x0005), PCI_DEVICE_CLASS(0x020000, ~0)},
-       {PCI_DEVICE(0x4040, 0x0024), PCI_DEVICE_CLASS(0x020000, ~0)},
-       {PCI_DEVICE(0x4040, 0x0025), PCI_DEVICE_CLASS(0x020000, ~0)},
+       ENTRY(0x0001),
+       ENTRY(0x0002),
+       ENTRY(0x0003),
+       ENTRY(0x0004),
+       ENTRY(0x0005),
+       ENTRY(0x0024),
+       ENTRY(0x0025),
        {0,}
 };
 
index ce95c5d168fe9922382726ce71e295392548f2a3..70d012e90dcf35bb1aea12b0bcc6ee7f6e3d1260 100644 (file)
@@ -525,12 +525,14 @@ static int axnet_open(struct net_device *dev)
     int ret;
     axnet_dev_t *info = PRIV(dev);
     struct pcmcia_device *link = info->p_dev;
+    unsigned int nic_base = dev->base_addr;
     
     DEBUG(2, "axnet_open('%s')\n", dev->name);
 
     if (!pcmcia_dev_present(link))
        return -ENODEV;
 
+    outb_p(0xFF, nic_base + EN0_ISR); /* Clear bogus intr. */
     ret = request_irq(dev->irq, ei_irq_wrapper, IRQF_SHARED, "axnet_cs", dev);
     if (ret)
            return ret;
index fd8158a86f6490ce7dbaf389595b8e34a3d51821..2d4c4ad89b8dbda9fdcd773b7c9825d4de1889b8 100644 (file)
@@ -969,6 +969,7 @@ static int pcnet_open(struct net_device *dev)
     int ret;
     pcnet_dev_t *info = PRIV(dev);
     struct pcmcia_device *link = info->p_dev;
+    unsigned int nic_base = dev->base_addr;
 
     DEBUG(2, "pcnet_open('%s')\n", dev->name);
 
@@ -976,6 +977,8 @@ static int pcnet_open(struct net_device *dev)
        return -ENODEV;
 
     set_misc_reg(dev);
+
+    outb_p(0xFF, nic_base + EN0_ISR); /* Clear bogus intr. */
     ret = request_irq(dev->irq, ei_irq_wrapper, IRQF_SHARED, dev_info, dev);
     if (ret)
            return ret;
index b7f7b2227d5697df09413841074d143c5ef8ac88..bccee68bd48a53fb671f2634d2b7bc3dd64cb36e 100644 (file)
@@ -3701,7 +3701,9 @@ static int ql_cycle_adapter(struct ql3_adapter *qdev, int reset)
                printk(KERN_ERR PFX
                                "%s: Driver up/down cycle failed, "
                                "closing device\n",qdev->ndev->name);
+               rtnl_lock();
                dev_close(qdev->ndev);
+               rtnl_unlock();
                return -1;
        }
        return 0;
index 858b191517b3dfc17800147191d0afe4e3f22b1b..504a48ff73c83e5cbac2eaa96c25bdc754bbd40e 100644 (file)
@@ -273,7 +273,7 @@ static void r6040_init_ring_desc(struct r6040_descriptor *desc_ring,
        dma_addr_t mapping = desc_dma;
 
        while (size-- > 0) {
-               mapping += sizeof(sizeof(*desc));
+               mapping += sizeof(*desc);
                desc->ndesc = cpu_to_le32(mapping);
                desc->vndescp = desc + 1;
                desc++;
index b5c1e663417d874aaba92270b2f765fe5cab8ee0..ae7b697456b4c88245ec36e6599efb17e6dc280f 100644 (file)
@@ -2625,9 +2625,7 @@ static int fill_rx_buffers(struct ring_info *ring)
                        rxdp1->Buffer0_ptr = pci_map_single
                            (ring->pdev, skb->data, size - NET_IP_ALIGN,
                                PCI_DMA_FROMDEVICE);
-                       if( (rxdp1->Buffer0_ptr == 0) ||
-                               (rxdp1->Buffer0_ptr ==
-                               DMA_ERROR_CODE))
+                       if(pci_dma_mapping_error(rxdp1->Buffer0_ptr))
                                goto pci_map_failed;
 
                        rxdp->Control_2 =
@@ -2657,6 +2655,7 @@ static int fill_rx_buffers(struct ring_info *ring)
                        skb->data = (void *) (unsigned long)tmp;
                        skb_reset_tail_pointer(skb);
 
+                       /* AK: check is wrong. 0 can be valid dma address */
                        if (!(rxdp3->Buffer0_ptr))
                                rxdp3->Buffer0_ptr =
                                   pci_map_single(ring->pdev, ba->ba_0,
@@ -2665,8 +2664,7 @@ static int fill_rx_buffers(struct ring_info *ring)
                                pci_dma_sync_single_for_device(ring->pdev,
                                (dma_addr_t) rxdp3->Buffer0_ptr,
                                    BUF0_LEN, PCI_DMA_FROMDEVICE);
-                       if( (rxdp3->Buffer0_ptr == 0) ||
-                               (rxdp3->Buffer0_ptr == DMA_ERROR_CODE))
+                       if (pci_dma_mapping_error(rxdp3->Buffer0_ptr))
                                goto pci_map_failed;
 
                        rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
@@ -2681,18 +2679,17 @@ static int fill_rx_buffers(struct ring_info *ring)
                                (ring->pdev, skb->data, ring->mtu + 4,
                                                PCI_DMA_FROMDEVICE);
 
-                               if( (rxdp3->Buffer2_ptr == 0) ||
-                                       (rxdp3->Buffer2_ptr == DMA_ERROR_CODE))
+                               if (pci_dma_mapping_error(rxdp3->Buffer2_ptr))
                                        goto pci_map_failed;
 
+                               /* AK: check is wrong */
                                if (!rxdp3->Buffer1_ptr)
                                        rxdp3->Buffer1_ptr =
                                                pci_map_single(ring->pdev,
                                                ba->ba_1, BUF1_LEN,
                                                PCI_DMA_FROMDEVICE);
 
-                               if( (rxdp3->Buffer1_ptr == 0) ||
-                                       (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) {
+                               if (pci_dma_mapping_error(rxdp3->Buffer1_ptr)) {
                                        pci_unmap_single
                                                (ring->pdev,
                                                (dma_addr_t)(unsigned long)
@@ -4264,16 +4261,14 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
                txdp->Buffer_Pointer = pci_map_single(sp->pdev,
                                        fifo->ufo_in_band_v,
                                        sizeof(u64), PCI_DMA_TODEVICE);
-               if((txdp->Buffer_Pointer == 0) ||
-                       (txdp->Buffer_Pointer == DMA_ERROR_CODE))
+               if (pci_dma_mapping_error(txdp->Buffer_Pointer))
                        goto pci_map_failed;
                txdp++;
        }
 
        txdp->Buffer_Pointer = pci_map_single
            (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
-       if((txdp->Buffer_Pointer == 0) ||
-               (txdp->Buffer_Pointer == DMA_ERROR_CODE))
+       if (pci_dma_mapping_error(txdp->Buffer_Pointer))
                goto pci_map_failed;
 
        txdp->Host_Control = (unsigned long) skb;
@@ -6884,10 +6879,8 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
                                pci_map_single( sp->pdev, (*skb)->data,
                                        size - NET_IP_ALIGN,
                                        PCI_DMA_FROMDEVICE);
-                       if( (rxdp1->Buffer0_ptr == 0) ||
-                               (rxdp1->Buffer0_ptr == DMA_ERROR_CODE)) {
+                       if (pci_dma_mapping_error(rxdp1->Buffer0_ptr))
                                goto memalloc_failed;
-                       }
                        rxdp->Host_Control = (unsigned long) (*skb);
                }
        } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) {
@@ -6913,15 +6906,12 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
                                pci_map_single(sp->pdev, (*skb)->data,
                                               dev->mtu + 4,
                                               PCI_DMA_FROMDEVICE);
-                       if( (rxdp3->Buffer2_ptr == 0) ||
-                               (rxdp3->Buffer2_ptr == DMA_ERROR_CODE)) {
+                       if (pci_dma_mapping_error(rxdp3->Buffer2_ptr))
                                goto memalloc_failed;
-                       }
                        rxdp3->Buffer0_ptr = *temp0 =
                                pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN,
                                                PCI_DMA_FROMDEVICE);
-                       if( (rxdp3->Buffer0_ptr == 0) ||
-                               (rxdp3->Buffer0_ptr == DMA_ERROR_CODE)) {
+                       if (pci_dma_mapping_error(rxdp3->Buffer0_ptr)) {
                                pci_unmap_single (sp->pdev,
                                        (dma_addr_t)rxdp3->Buffer2_ptr,
                                        dev->mtu + 4, PCI_DMA_FROMDEVICE);
@@ -6933,8 +6923,7 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
                        rxdp3->Buffer1_ptr = *temp1 =
                                pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN,
                                                PCI_DMA_FROMDEVICE);
-                       if( (rxdp3->Buffer1_ptr == 0) ||
-                               (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) {
+                       if (pci_dma_mapping_error(rxdp3->Buffer1_ptr)) {
                                pci_unmap_single (sp->pdev,
                                        (dma_addr_t)rxdp3->Buffer0_ptr,
                                        BUF0_LEN, PCI_DMA_FROMDEVICE);
index 4706f7f9acb628b423834e90a467f273f2245fd7..1827b6686c986ff4ab2c70c8521f3dc8cfe0c35d 100644 (file)
@@ -75,10 +75,6 @@ static int debug_level = ERR_DBG;
 /* DEBUG message print. */
 #define DBG_PRINT(dbg_level, args...)  if(!(debug_level<dbg_level)) printk(args)
 
-#ifndef DMA_ERROR_CODE
-#define DMA_ERROR_CODE          (~(dma_addr_t)0x0)
-#endif
-
 /* Protocol assist features of the NIC */
 #define L3_CKSUM_OK 0xFFFF
 #define L4_CKSUM_OK 0xFFFF
index 10e4e85da3fcae7af7e9435145f06dad72abd35f..b07b8cbadeaf8eb4a34dbbfe848ad5499f2a628b 100644 (file)
@@ -1394,6 +1394,7 @@ tc35815_open(struct net_device *dev)
        tc35815_chip_init(dev);
        spin_unlock_irq(&lp->lock);
 
+       netif_carrier_off(dev);
        /* schedule a link state check */
        phy_start(lp->phy_dev);
 
@@ -1735,7 +1736,6 @@ tc35815_rx(struct net_device *dev)
                        skb = lp->rx_skbs[cur_bd].skb;
                        prefetch(skb->data);
                        lp->rx_skbs[cur_bd].skb = NULL;
-                       lp->fbl_count--;
                        pci_unmap_single(lp->pci_dev,
                                         lp->rx_skbs[cur_bd].skb_dma,
                                         RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
@@ -1791,6 +1791,7 @@ tc35815_rx(struct net_device *dev)
 #ifdef TC35815_USE_PACKEDBUFFER
                        while (lp->fbl_curid != id)
 #else
+                       lp->fbl_count--;
                        while (lp->fbl_count < RX_BUF_NUM)
 #endif
                        {
@@ -2453,6 +2454,7 @@ static int tc35815_resume(struct pci_dev *pdev)
                return 0;
        pci_set_power_state(pdev, PCI_D0);
        tc35815_restart(dev);
+       netif_carrier_off(dev);
        if (lp->phy_dev)
                phy_start(lp->phy_dev);
        netif_device_attach(dev);
index 249e18053d5fa4a2d6e29a60e33878bbe1f78c90..069f8bb0a99fa401e254a03ff94a77a4217d58b5 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/x25.h>
 #include <linux/lapb.h>
 #include <linux/init.h>
+#include <linux/rtnetlink.h>
 #include "x25_asy.h"
 
 #include <net/x25device.h>
@@ -601,8 +602,10 @@ static void x25_asy_close_tty(struct tty_struct *tty)
        if (!sl || sl->magic != X25_ASY_MAGIC)
                return;
 
+       rtnl_lock();
        if (sl->dev->flags & IFF_UP)
                dev_close(sl->dev);
+       rtnl_unlock();
 
        tty->disc_data = NULL;
        sl->tty = NULL;
index 36a9c42df835c3fa77241533cf90f1eb6c14e9e4..76f4c7bad8b83e52b30000ccc62f86a77113e45b 100644 (file)
@@ -72,6 +72,9 @@ static void b43_led_brightness_set(struct led_classdev *led_dev,
        struct b43_wldev *dev = led->dev;
        bool radio_enabled;
 
+       if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED))
+               return;
+
        /* Checking the radio-enabled status here is slightly racy,
         * but we want to avoid the locking overhead and we don't care
         * whether the LED has the wrong state for a second. */
index fa4b0d8b74a26df90df59f8f3fa57dc8925d023e..a70827793086e68aa14291ecb1f3086a29cdf384 100644 (file)
@@ -2883,12 +2883,11 @@ static int b43_op_tx(struct ieee80211_hw *hw,
 
        if (unlikely(skb->len < 2 + 2 + 6)) {
                /* Too short, this can't be a valid frame. */
-               dev_kfree_skb_any(skb);
-               return NETDEV_TX_OK;
+               goto drop_packet;
        }
        B43_WARN_ON(skb_shinfo(skb)->nr_frags);
        if (unlikely(!dev))
-               return NETDEV_TX_BUSY;
+               goto drop_packet;
 
        /* Transmissions on seperate queues can run concurrently. */
        read_lock_irqsave(&wl->tx_lock, flags);
@@ -2904,7 +2903,12 @@ static int b43_op_tx(struct ieee80211_hw *hw,
        read_unlock_irqrestore(&wl->tx_lock, flags);
 
        if (unlikely(err))
-               return NETDEV_TX_BUSY;
+               goto drop_packet;
+       return NETDEV_TX_OK;
+
+drop_packet:
+       /* We can not transmit this packet. Drop it. */
+       dev_kfree_skb_any(skb);
        return NETDEV_TX_OK;
 }
 
index c990f87b107acff6603a24a70b8f402144f64d9c..93ddc1cbcc8b2bb7453e8040288a1a2771c1d01b 100644 (file)
@@ -876,6 +876,7 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev,
        if (!ring)
                goto out;
        ring->type = type;
+       ring->dev = dev;
 
        nr_slots = B43legacy_RXRING_SLOTS;
        if (for_tx)
@@ -922,7 +923,6 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev,
                                 DMA_TO_DEVICE);
        }
 
-       ring->dev = dev;
        ring->nr_slots = nr_slots;
        ring->mmio_base = b43legacy_dmacontroller_base(type, controller_index);
        ring->index = controller_index;
index 204077c13870c05b619f781154bcc942eb1cdf1d..3e612d0a13e8fc927c766c09507067a0d009a988 100644 (file)
@@ -2378,8 +2378,10 @@ static int b43legacy_op_tx(struct ieee80211_hw *hw,
        } else
                err = b43legacy_dma_tx(dev, skb, ctl);
 out:
-       if (unlikely(err))
-               return NETDEV_TX_BUSY;
+       if (unlikely(err)) {
+               /* Drop the packet. */
+               dev_kfree_skb_any(skb);
+       }
        return NETDEV_TX_OK;
 }
 
index 4fd73809602e7e8af816a30570b7da7306af71e3..020f450e9dba9cd7f903e7c5b380a5f0600d1c04 100644 (file)
@@ -64,7 +64,7 @@ int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
        int hdrlen, phdrlen, head_need, tail_need;
        u16 fc;
        int prism_header, ret;
-       struct ieee80211_hdr_4addr *hdr;
+       struct ieee80211_hdr_4addr *fhdr;
 
        iface = netdev_priv(dev);
        local = iface->local;
@@ -83,8 +83,8 @@ int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
                phdrlen = 0;
        }
 
-       hdr = (struct ieee80211_hdr_4addr *) skb->data;
-       fc = le16_to_cpu(hdr->frame_ctl);
+       fhdr = (struct ieee80211_hdr_4addr *) skb->data;
+       fc = le16_to_cpu(fhdr->frame_ctl);
 
        if (type == PRISM2_RX_MGMT && (fc & IEEE80211_FCTL_VERS)) {
                printk(KERN_DEBUG "%s: dropped management frame with header "
@@ -551,7 +551,7 @@ hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr_4addr *hdr,
             hdr->addr1[2] != 0xff || hdr->addr1[3] != 0xff ||
             hdr->addr1[4] != 0xff || hdr->addr1[5] != 0xff)) {
                /* RA (or BSSID) is not ours - drop */
-               PDEBUG(DEBUG_EXTRA, "%s: received WDS frame with "
+               PDEBUG(DEBUG_EXTRA2, "%s: received WDS frame with "
                       "not own or broadcast %s=%s\n",
                       local->dev->name,
                       fc & IEEE80211_FCTL_FROMDS ? "RA" : "BSSID",
index 0acd9589c48c0f36277f6b1351a559bbb1988f14..ab981afd481d6ea5a3cc199dcac224b015f6c5bd 100644 (file)
@@ -1930,7 +1930,7 @@ static void handle_pspoll(local_info_t *local,
                PDEBUG(DEBUG_PS, "   PSPOLL and AID[15:14] not set\n");
                return;
        }
-       aid &= ~BIT(15) & ~BIT(14);
+       aid &= ~(BIT(15) | BIT(14));
        if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
                PDEBUG(DEBUG_PS, "   invalid aid=%d\n", aid);
                return;
index ed4317a17cbb03beafb276e9f870dece124b24e8..80039a0ae0276c6514978dd2d945bfc284520447 100644 (file)
@@ -533,10 +533,10 @@ static void prism2_detach(struct pcmcia_device *link)
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
 #define CFG_CHECK2(fn, retf) \
-do { int ret = (retf); \
-if (ret != 0) { \
-       PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \
-       cs_error(link, fn, ret); \
+do { int _ret = (retf); \
+if (_ret != 0) { \
+       PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", _ret); \
+       cs_error(link, fn, _ret); \
        goto next_entry; \
 } \
 } while (0)
index cdf90c40f11b872c60fc293e5caef3a1d82756b9..936f52e3d95c4040a18515e2f949027a95442638 100644 (file)
@@ -2835,7 +2835,7 @@ static void hostap_passive_scan(unsigned long data)
 {
        local_info_t *local = (local_info_t *) data;
        struct net_device *dev = local->dev;
-       u16 channel;
+       u16 chan;
 
        if (local->passive_scan_interval <= 0)
                return;
@@ -2872,11 +2872,11 @@ static void hostap_passive_scan(unsigned long data)
 
                printk(KERN_DEBUG "%s: passive scan channel %d\n",
                       dev->name, local->passive_scan_channel);
-               channel = local->passive_scan_channel;
+               chan = local->passive_scan_channel;
                local->passive_scan_state = PASSIVE_SCAN_WAIT;
                local->passive_scan_timer.expires = jiffies + HZ / 10;
        } else {
-               channel = local->channel;
+               chan = local->channel;
                local->passive_scan_state = PASSIVE_SCAN_LISTEN;
                local->passive_scan_timer.expires = jiffies +
                        local->passive_scan_interval * HZ;
@@ -2884,9 +2884,9 @@ static void hostap_passive_scan(unsigned long data)
 
        if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_TEST |
                                 (HFA384X_TEST_CHANGE_CHANNEL << 8),
-                                channel, NULL, 0))
+                                chan, NULL, 0))
                printk(KERN_ERR "%s: passive scan channel set %d "
-                      "failed\n", dev->name, channel);
+                      "failed\n", dev->name, chan);
 
        add_timer(&local->passive_scan_timer);
 }
index f7aec9309d0412c86dd0bc3fd111ff9c37ef7d5c..a38e85f334df2991e7d086085250d7fd092d2080 100644 (file)
@@ -594,7 +594,8 @@ void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx)
 }
 
 
-int hostap_80211_header_parse(const struct sk_buff *skb, unsigned char *haddr)
+static int hostap_80211_header_parse(const struct sk_buff *skb,
+                                    unsigned char *haddr)
 {
        struct hostap_interface *iface = netdev_priv(skb->dev);
        local_info_t *local = iface->local;
@@ -857,7 +858,6 @@ const struct header_ops hostap_80211_ops = {
        .rebuild        = eth_rebuild_header,
        .cache          = eth_header_cache,
        .cache_update   = eth_header_cache_update,
-
        .parse          = hostap_80211_header_parse,
 };
 EXPORT_SYMBOL(hostap_80211_ops);
@@ -1150,7 +1150,6 @@ EXPORT_SYMBOL(hostap_set_roaming);
 EXPORT_SYMBOL(hostap_set_auth_algs);
 EXPORT_SYMBOL(hostap_dump_rx_header);
 EXPORT_SYMBOL(hostap_dump_tx_header);
-EXPORT_SYMBOL(hostap_80211_header_parse);
 EXPORT_SYMBOL(hostap_80211_get_hdrlen);
 EXPORT_SYMBOL(hostap_get_stats);
 EXPORT_SYMBOL(hostap_setup_dev);
index 13925b627e3b5569f5ebaf1399f121dea3d489d2..b1b3c523185de39a2e5f38670cda26cf1aba6b17 100644 (file)
@@ -2227,7 +2227,10 @@ static int iwl3945_scan_initiate(struct iwl3945_priv *priv)
        }
 
        IWL_DEBUG_INFO("Starting scan...\n");
-       priv->scan_bands = 2;
+       if (priv->cfg->sku & IWL_SKU_G)
+               priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
+       if (priv->cfg->sku & IWL_SKU_A)
+               priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
        set_bit(STATUS_SCANNING, &priv->status);
        priv->scan_start = jiffies;
        priv->scan_pass_start = priv->scan_start;
@@ -3352,13 +3355,18 @@ static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv *priv,
        cancel_delayed_work(&priv->scan_check);
 
        IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
-                      (priv->scan_bands == 2) ? "2.4" : "5.2",
+                      (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
+                                                       "2.4" : "5.2",
                       jiffies_to_msecs(elapsed_jiffies
                                        (priv->scan_pass_start, jiffies)));
 
-       /* Remove this scanned band from the list
-        * of pending bands to scan */
-       priv->scan_bands--;
+       /* Remove this scanned band from the list of pending
+        * bands to scan, band G precedes A in order of scanning
+        * as seen in iwl3945_bg_request_scan */
+       if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
+               priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
+       else if (priv->scan_bands &  BIT(IEEE80211_BAND_5GHZ))
+               priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
 
        /* If a request to abort was given, or the scan did not succeed
         * then we reset the scan state machine and terminate,
@@ -4972,7 +4980,7 @@ static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv,
 
                ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel);
                if (!is_channel_valid(ch_info)) {
-                       IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
+                       IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
                                       scan_ch->channel);
                        continue;
                }
@@ -6315,21 +6323,16 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
 
        /* flags + rate selection */
 
-       switch (priv->scan_bands) {
-       case 2:
+       if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
                scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
                scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
                scan->good_CRC_th = 0;
                band = IEEE80211_BAND_2GHZ;
-               break;
-
-       case 1:
+       } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
                scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
                scan->good_CRC_th = IWL_GOOD_CRC_TH;
                band = IEEE80211_BAND_5GHZ;
-               break;
-
-       default:
+       } else {
                IWL_WARNING("Invalid scan band count\n");
                goto done;
        }
@@ -6770,7 +6773,7 @@ static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
        ch_info = iwl3945_get_channel_info(priv, conf->channel->band,
                                           conf->channel->hw_value);
        if (!is_channel_valid(ch_info)) {
-               IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
+               IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n",
                               conf->channel->hw_value, conf->channel->band);
                IWL_DEBUG_MAC80211("leave - invalid channel\n");
                spin_unlock_irqrestore(&priv->lock, flags);
index 883b42f7e9989dff95e085cf6afb6577eb9f7f1a..5ed16ce784689b9c1439d4fe96a98bd032a03e3f 100644 (file)
@@ -1774,7 +1774,10 @@ static int iwl4965_scan_initiate(struct iwl_priv *priv)
        }
 
        IWL_DEBUG_INFO("Starting scan...\n");
-       priv->scan_bands = 2;
+       if (priv->cfg->sku & IWL_SKU_G)
+               priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
+       if (priv->cfg->sku & IWL_SKU_A)
+               priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
        set_bit(STATUS_SCANNING, &priv->status);
        priv->scan_start = jiffies;
        priv->scan_pass_start = priv->scan_start;
@@ -3023,8 +3026,9 @@ static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
 
        IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
        if (index != -1) {
-               int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
 #ifdef CONFIG_IWL4965_HT
+               int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
+
                if (tid != MAX_TID_COUNT)
                        priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
                if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
@@ -3276,13 +3280,18 @@ static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv,
        cancel_delayed_work(&priv->scan_check);
 
        IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
-                      (priv->scan_bands == 2) ? "2.4" : "5.2",
+                      (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
+                                               "2.4" : "5.2",
                       jiffies_to_msecs(elapsed_jiffies
                                        (priv->scan_pass_start, jiffies)));
 
-       /* Remove this scanned band from the list
-        * of pending bands to scan */
-       priv->scan_bands--;
+       /* Remove this scanned band from the list of pending
+        * bands to scan, band G precedes A in order of scanning
+        * as seen in iwl_bg_request_scan */
+       if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
+               priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
+       else if (priv->scan_bands &  BIT(IEEE80211_BAND_5GHZ))
+               priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
 
        /* If a request to abort was given, or the scan did not succeed
         * then we reset the scan state machine and terminate,
@@ -3292,7 +3301,7 @@ static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv,
                clear_bit(STATUS_SCAN_ABORTING, &priv->status);
        } else {
                /* If there are more bands on this scan pass reschedule */
-               if (priv->scan_bands > 0)
+               if (priv->scan_bands)
                        goto reschedule;
        }
 
@@ -4635,10 +4644,9 @@ static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
 
                scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
 
-               ch_info = iwl_get_channel_info(priv, band,
-                                        scan_ch->channel);
+               ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
                if (!is_channel_valid(ch_info)) {
-                       IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
+                       IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
                                       scan_ch->channel);
                        continue;
                }
@@ -5830,8 +5838,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
        scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
 
 
-       switch (priv->scan_bands) {
-       case 2:
+       if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
                scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
                scan->tx_cmd.rate_n_flags =
                                iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
@@ -5839,17 +5846,13 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
 
                scan->good_CRC_th = 0;
                band = IEEE80211_BAND_2GHZ;
-               break;
-
-       case 1:
+       } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
                scan->tx_cmd.rate_n_flags =
                                iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
                                RATE_MCS_ANT_B_MSK);
                scan->good_CRC_th = IWL_GOOD_CRC_TH;
                band = IEEE80211_BAND_5GHZ;
-               break;
-
-       default:
+       } else {
                IWL_WARNING("Invalid scan band count\n");
                goto done;
        }
index 762e85bef55dcef657ded932a53f911b051ae4b9..e43bae97ed8f66a6bc9ccb9eeb86a66a6db0302c 100644 (file)
@@ -290,7 +290,7 @@ islpci_monitor_rx(islpci_private *priv, struct sk_buff **skb)
 
                avs->version = cpu_to_be32(P80211CAPTURE_VERSION);
                avs->length = cpu_to_be32(sizeof (struct avs_80211_1_header));
-               avs->mactime = cpu_to_be64(le64_to_cpu(clock));
+               avs->mactime = cpu_to_be64(clock);
                avs->hosttime = cpu_to_be64(jiffies);
                avs->phytype = cpu_to_be32(6);  /*OFDM: 6 for (g), 8 for (a) */
                avs->channel = cpu_to_be32(channel_of_freq(freq));
index fdbd0ef2be4bceef492431262796e6466a11e0b8..61e59c17a60aa09ae477d4df6f70a988ff47ad24 100644 (file)
@@ -138,11 +138,8 @@ static void rt2500usb_bbp_write(struct rt2x00_dev *rt2x00dev,
         * Wait until the BBP becomes ready.
         */
        reg = rt2500usb_bbp_check(rt2x00dev);
-       if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
-               ERROR(rt2x00dev, "PHY_CSR8 register busy. Write failed.\n");
-               mutex_unlock(&rt2x00dev->usb_cache_mutex);
-               return;
-       }
+       if (rt2x00_get_field16(reg, PHY_CSR8_BUSY))
+               goto exit_fail;
 
        /*
         * Write the data into the BBP.
@@ -155,6 +152,13 @@ static void rt2500usb_bbp_write(struct rt2x00_dev *rt2x00dev,
        rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
 
        mutex_unlock(&rt2x00dev->usb_cache_mutex);
+
+       return;
+
+exit_fail:
+       mutex_unlock(&rt2x00dev->usb_cache_mutex);
+
+       ERROR(rt2x00dev, "PHY_CSR8 register busy. Write failed.\n");
 }
 
 static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev,
@@ -168,10 +172,8 @@ static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev,
         * Wait until the BBP becomes ready.
         */
        reg = rt2500usb_bbp_check(rt2x00dev);
-       if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
-               ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n");
-               return;
-       }
+       if (rt2x00_get_field16(reg, PHY_CSR8_BUSY))
+               goto exit_fail;
 
        /*
         * Write the request into the BBP.
@@ -186,17 +188,21 @@ static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev,
         * Wait until the BBP becomes ready.
         */
        reg = rt2500usb_bbp_check(rt2x00dev);
-       if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
-               ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n");
-               *value = 0xff;
-               mutex_unlock(&rt2x00dev->usb_cache_mutex);
-               return;
-       }
+       if (rt2x00_get_field16(reg, PHY_CSR8_BUSY))
+               goto exit_fail;
 
        rt2500usb_register_read_lock(rt2x00dev, PHY_CSR7, &reg);
        *value = rt2x00_get_field16(reg, PHY_CSR7_DATA);
 
        mutex_unlock(&rt2x00dev->usb_cache_mutex);
+
+       return;
+
+exit_fail:
+       mutex_unlock(&rt2x00dev->usb_cache_mutex);
+
+       ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n");
+       *value = 0xff;
 }
 
 static void rt2500usb_rf_write(struct rt2x00_dev *rt2x00dev,
index 611d98320593869dc9c26faf2c64218c8c32e3ec..b4bf1e09cf9a906447ed8a5770e9e0cdfec52626 100644 (file)
@@ -821,6 +821,7 @@ struct rt2x00_dev {
        /*
         * Scheduled work.
         */
+       struct workqueue_struct *workqueue;
        struct work_struct intf_work;
        struct work_struct filter_work;
 
index 2673d568bcac286dc9f3cbdb8da9d3c5051ff7cc..c997d4f28ab39bd31e7e8b25adad8ea278b1c198 100644 (file)
@@ -75,7 +75,7 @@ static void rt2x00lib_start_link_tuner(struct rt2x00_dev *rt2x00dev)
 
        rt2x00lib_reset_link_tuner(rt2x00dev);
 
-       queue_delayed_work(rt2x00dev->hw->workqueue,
+       queue_delayed_work(rt2x00dev->workqueue,
                           &rt2x00dev->link.work, LINK_TUNE_INTERVAL);
 }
 
@@ -136,14 +136,6 @@ void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev)
        if (!__test_and_clear_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
                return;
 
-       /*
-        * Stop all scheduled work.
-        */
-       if (work_pending(&rt2x00dev->intf_work))
-               cancel_work_sync(&rt2x00dev->intf_work);
-       if (work_pending(&rt2x00dev->filter_work))
-               cancel_work_sync(&rt2x00dev->filter_work);
-
        /*
         * Stop the TX queues.
         */
@@ -398,8 +390,8 @@ static void rt2x00lib_link_tuner(struct work_struct *work)
         * Increase tuner counter, and reschedule the next link tuner run.
         */
        rt2x00dev->link.count++;
-       queue_delayed_work(rt2x00dev->hw->workqueue, &rt2x00dev->link.work,
-                          LINK_TUNE_INTERVAL);
+       queue_delayed_work(rt2x00dev->workqueue,
+                          &rt2x00dev->link.work, LINK_TUNE_INTERVAL);
 }
 
 static void rt2x00lib_packetfilter_scheduled(struct work_struct *work)
@@ -433,6 +425,15 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
 
        spin_unlock(&intf->lock);
 
+       /*
+        * It is possible the radio was disabled while the work had been
+        * scheduled. If that happens we should return here immediately,
+        * note that in the spinlock protected area above the delayed_flags
+        * have been cleared correctly.
+        */
+       if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
+               return;
+
        if (delayed_flags & DELAYED_UPDATE_BEACON) {
                skb = ieee80211_beacon_get(rt2x00dev->hw, vif, &control);
                if (skb && rt2x00dev->ops->hw->beacon_update(rt2x00dev->hw,
@@ -441,7 +442,7 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac,
        }
 
        if (delayed_flags & DELAYED_CONFIG_ERP)
-               rt2x00lib_config_erp(rt2x00dev, intf, &intf->conf);
+               rt2x00lib_config_erp(rt2x00dev, intf, &conf);
 
        if (delayed_flags & DELAYED_LED_ASSOC)
                rt2x00leds_led_assoc(rt2x00dev, !!rt2x00dev->intf_associated);
@@ -487,7 +488,7 @@ void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev)
                                                   rt2x00lib_beacondone_iter,
                                                   rt2x00dev);
 
-       queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->intf_work);
+       queue_work(rt2x00dev->workqueue, &rt2x00dev->intf_work);
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_beacondone);
 
@@ -1130,6 +1131,10 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
        /*
         * Initialize configuration work.
         */
+       rt2x00dev->workqueue = create_singlethread_workqueue("rt2x00lib");
+       if (!rt2x00dev->workqueue)
+               goto exit;
+
        INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled);
        INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled);
        INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00lib_link_tuner);
@@ -1189,6 +1194,13 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
        rt2x00rfkill_free(rt2x00dev);
        rt2x00leds_unregister(rt2x00dev);
 
+       /*
+        * Stop all queued work. Note that most tasks will already be halted
+        * during rt2x00lib_disable_radio() and rt2x00lib_uninitialize().
+        */
+       flush_workqueue(rt2x00dev->workqueue);
+       destroy_workqueue(rt2x00dev->workqueue);
+
        /*
         * Free ieee80211_hw memory.
         */
index 87e280a21971faf5dbb8e5f15186ec8d41c21ec2..9cb023edd2e9bf7eaad394c5a205c2af3a6e9076 100644 (file)
@@ -428,7 +428,7 @@ void rt2x00mac_configure_filter(struct ieee80211_hw *hw,
        if (!test_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags))
                rt2x00dev->ops->lib->config_filter(rt2x00dev, *total_flags);
        else
-               queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->filter_work);
+               queue_work(rt2x00dev->workqueue, &rt2x00dev->filter_work);
 }
 EXPORT_SYMBOL_GPL(rt2x00mac_configure_filter);
 
@@ -509,7 +509,7 @@ void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
        memcpy(&intf->conf, bss_conf, sizeof(*bss_conf));
        if (delayed) {
                intf->delayed_flags |= delayed;
-               queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->intf_work);
+               queue_work(rt2x00dev->workqueue, &rt2x00dev->intf_work);
        }
        spin_unlock(&intf->lock);
 }
index fff8386e816ba289045ff8955575b7377a98b60b..83cc0147f6986570a00d39daa3cdf5a4381b2993 100644 (file)
@@ -134,11 +134,8 @@ static void rt73usb_bbp_write(struct rt2x00_dev *rt2x00dev,
         * Wait until the BBP becomes ready.
         */
        reg = rt73usb_bbp_check(rt2x00dev);
-       if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
-               ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n");
-               mutex_unlock(&rt2x00dev->usb_cache_mutex);
-               return;
-       }
+       if (rt2x00_get_field32(reg, PHY_CSR3_BUSY))
+               goto exit_fail;
 
        /*
         * Write the data into the BBP.
@@ -151,6 +148,13 @@ static void rt73usb_bbp_write(struct rt2x00_dev *rt2x00dev,
 
        rt73usb_register_write_lock(rt2x00dev, PHY_CSR3, reg);
        mutex_unlock(&rt2x00dev->usb_cache_mutex);
+
+       return;
+
+exit_fail:
+       mutex_unlock(&rt2x00dev->usb_cache_mutex);
+
+       ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n");
 }
 
 static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev,
@@ -164,11 +168,8 @@ static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev,
         * Wait until the BBP becomes ready.
         */
        reg = rt73usb_bbp_check(rt2x00dev);
-       if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
-               ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
-               mutex_unlock(&rt2x00dev->usb_cache_mutex);
-               return;
-       }
+       if (rt2x00_get_field32(reg, PHY_CSR3_BUSY))
+               goto exit_fail;
 
        /*
         * Write the request into the BBP.
@@ -184,14 +185,19 @@ static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev,
         * Wait until the BBP becomes ready.
         */
        reg = rt73usb_bbp_check(rt2x00dev);
-       if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
-               ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
-               *value = 0xff;
-               return;
-       }
+       if (rt2x00_get_field32(reg, PHY_CSR3_BUSY))
+               goto exit_fail;
 
        *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE);
        mutex_unlock(&rt2x00dev->usb_cache_mutex);
+
+       return;
+
+exit_fail:
+       mutex_unlock(&rt2x00dev->usb_cache_mutex);
+
+       ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
+       *value = 0xff;
 }
 
 static void rt73usb_rf_write(struct rt2x00_dev *rt2x00dev,
index ec8f7002b09d3423a8f5c80d94ed48f001e9d4b4..39bb96b413ef1b696eae53d6239c2d3a29bbd20e 100644 (file)
@@ -178,8 +178,7 @@ static int pci_vpd_pci22_read(struct pci_dev *dev, int pos, int size,
        int ret;
        int begin, end, i;
 
-       if (pos < 0 || pos > PCI_VPD_PCI22_SIZE ||
-           size > PCI_VPD_PCI22_SIZE  - pos)
+       if (pos < 0 || pos > vpd->base.len || size > vpd->base.len  - pos)
                return -EINVAL;
        if (size == 0)
                return 0;
@@ -223,8 +222,8 @@ static int pci_vpd_pci22_write(struct pci_dev *dev, int pos, int size,
        u32 val;
        int ret;
 
-       if (pos < 0 || pos > PCI_VPD_PCI22_SIZE || pos & 3 ||
-           size > PCI_VPD_PCI22_SIZE - pos || size < 4)
+       if (pos < 0 || pos > vpd->base.len || pos & 3 ||
+           size > vpd->base.len - pos || size < 4)
                return -EINVAL;
 
        val = (u8) *buf++;
@@ -255,11 +254,6 @@ out:
        return 4;
 }
 
-static int pci_vpd_pci22_get_size(struct pci_dev *dev)
-{
-       return PCI_VPD_PCI22_SIZE;
-}
-
 static void pci_vpd_pci22_release(struct pci_dev *dev)
 {
        kfree(container_of(dev->vpd, struct pci_vpd_pci22, base));
@@ -268,7 +262,6 @@ static void pci_vpd_pci22_release(struct pci_dev *dev)
 static struct pci_vpd_ops pci_vpd_pci22_ops = {
        .read = pci_vpd_pci22_read,
        .write = pci_vpd_pci22_write,
-       .get_size = pci_vpd_pci22_get_size,
        .release = pci_vpd_pci22_release,
 };
 
@@ -284,6 +277,7 @@ int pci_vpd_pci22_init(struct pci_dev *dev)
        if (!vpd)
                return -ENOMEM;
 
+       vpd->base.len = PCI_VPD_PCI22_SIZE;
        vpd->base.ops = &pci_vpd_pci22_ops;
        spin_lock_init(&vpd->lock);
        vpd->cap = cap;
index 648596d469f66bf3005c57b355fd3911d733ae8b..91156f85a9267371c1c9354646bdcc6975e206af 100644 (file)
@@ -700,9 +700,10 @@ cleanup_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
        acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
                                cleanup_p2p_bridge, NULL, NULL);
 
-       if (!(bridge = acpiphp_handle_to_bridge(handle)))
-               return AE_OK;
-       cleanup_bridge(bridge);
+       bridge = acpiphp_handle_to_bridge(handle);
+       if (bridge)
+               cleanup_bridge(bridge);
+
        return AE_OK;
 }
 
@@ -715,9 +716,19 @@ static void remove_bridge(acpi_handle handle)
        acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
                                (u32)1, cleanup_p2p_bridge, NULL, NULL);
 
+       /*
+        * On root bridges with hotplug slots directly underneath (ie,
+        * no p2p bridge inbetween), we call cleanup_bridge(). 
+        *
+        * The else clause cleans up root bridges that either had no
+        * hotplug slots at all, or had a p2p bridge underneath.
+        */
        bridge = acpiphp_handle_to_bridge(handle);
        if (bridge)
                cleanup_bridge(bridge);
+       else
+               acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
+                                          handle_hotplug_event_bridge);
 }
 
 static struct pci_dev * get_apic_pci_info(acpi_handle handle)
index 6f3c7446c329f3dfedc9dd60ee50497184062a63..9c718583a237f4f6082e7dcc5e84e23e85ee651c 100644 (file)
@@ -736,9 +736,9 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
                attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
                if (attr) {
                        pdev->vpd->attr = attr;
-                       attr->size = pdev->vpd->ops->get_size(pdev);
+                       attr->size = pdev->vpd->len;
                        attr->attr.name = "vpd";
-                       attr->attr.mode = S_IRUGO | S_IWUSR;
+                       attr->attr.mode = S_IRUSR | S_IWUSR;
                        attr->read = pci_read_vpd;
                        attr->write = pci_write_vpd;
                        retval = sysfs_create_bin_file(&pdev->dev.kobj, attr);
index 0a497c1b4227c0b80df7be89f56dcc8c5aba55f6..00408c97e5fc8cc2e38f52b408c70fdab9d133a8 100644 (file)
@@ -21,11 +21,11 @@ extern int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
 struct pci_vpd_ops {
        int (*read)(struct pci_dev *dev, int pos, int size, char *buf);
        int (*write)(struct pci_dev *dev, int pos, int size, const char *buf);
-       int (*get_size)(struct pci_dev *dev);
        void (*release)(struct pci_dev *dev);
 };
 
 struct pci_vpd {
+       unsigned int len;
        struct pci_vpd_ops *ops;
        struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
 };
index dabb563f51d9466e4379f9095c85d2ce04545925..338a3f94b4d43bdf3d44dd0548e018199a49774a 100644 (file)
@@ -1670,6 +1670,48 @@ static void __devinit quirk_via_cx700_pci_parking_caching(struct pci_dev *dev)
 }
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_VIA, 0x324e, quirk_via_cx700_pci_parking_caching);
 
+/*
+ * For Broadcom 5706, 5708, 5709 rev. A nics, any read beyond the
+ * VPD end tag will hang the device.  This problem was initially
+ * observed when a vpd entry was created in sysfs
+ * ('/sys/bus/pci/devices/<id>/vpd').   A read to this sysfs entry
+ * will dump 32k of data.  Reading a full 32k will cause an access
+ * beyond the VPD end tag causing the device to hang.  Once the device
+ * is hung, the bnx2 driver will not be able to reset the device.
+ * We believe that it is legal to read beyond the end tag and
+ * therefore the solution is to limit the read/write length.
+ */
+static void __devinit quirk_brcm_570x_limit_vpd(struct pci_dev *dev)
+{
+       /*  Only disable the VPD capability for 5706, 5708, and 5709 rev. A */
+       if ((dev->device == PCI_DEVICE_ID_NX2_5706) ||
+           (dev->device == PCI_DEVICE_ID_NX2_5708) ||
+           ((dev->device == PCI_DEVICE_ID_NX2_5709) &&
+            (dev->revision & 0xf0) == 0x0)) {
+               if (dev->vpd)
+                       dev->vpd->len = 0x80;
+       }
+}
+
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
+                        PCI_DEVICE_ID_NX2_5706,
+                        quirk_brcm_570x_limit_vpd);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
+                        PCI_DEVICE_ID_NX2_5706S,
+                        quirk_brcm_570x_limit_vpd);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
+                        PCI_DEVICE_ID_NX2_5708,
+                        quirk_brcm_570x_limit_vpd);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
+                        PCI_DEVICE_ID_NX2_5708S,
+                        quirk_brcm_570x_limit_vpd);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
+                        PCI_DEVICE_ID_NX2_5709,
+                        quirk_brcm_570x_limit_vpd);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
+                        PCI_DEVICE_ID_NX2_5709S,
+                        quirk_brcm_570x_limit_vpd);
+
 #ifdef CONFIG_PCI_MSI
 /* Some chipsets do not support MSI. We cannot easily rely on setting
  * PCI_BUS_FLAGS_NO_MSI in its bus flags because there are actually
@@ -1685,6 +1727,7 @@ static void __init quirk_disable_all_msi(struct pci_dev *dev)
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_GCNB_LE, quirk_disable_all_msi);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS400_200, quirk_disable_all_msi);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS480, quirk_disable_all_msi);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3336, quirk_disable_all_msi);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3351, quirk_disable_all_msi);
 
 /* Disable MSI on chipsets that are known to not support it */
index 7e3ad4f3b3432aa89c8a7d9a4d9902453f9adbbf..58b7336640ff7a1559263798f46e9d7912f09088 100644 (file)
@@ -126,12 +126,25 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
        int err;
        struct rtc_time before, now;
        int first_time = 1;
+       unsigned long t_now, t_alm;
+       enum { none, day, month, year } missing = none;
+       unsigned days;
 
-       /* The lower level RTC driver may not be capable of filling
-        * in all fields of the rtc_time struct (eg. rtc-cmos),
-        * and so might instead return -1 in some fields.
-        * We deal with that here by grabbing a current RTC timestamp
-        * and using values from that for any missing (-1) values.
+       /* The lower level RTC driver may return -1 in some fields,
+        * creating invalid alarm->time values, for reasons like:
+        *
+        *   - The hardware may not be capable of filling them in;
+        *     many alarms match only on time-of-day fields, not
+        *     day/month/year calendar data.
+        *
+        *   - Some hardware uses illegal values as "wildcard" match
+        *     values, which non-Linux firmware (like a BIOS) may try
+        *     to set up as e.g. "alarm 15 minutes after each hour".
+        *     Linux uses only oneshot alarms.
+        *
+        * When we see that here, we deal with it by using values from
+        * a current RTC timestamp for any missing (-1) values.  The
+        * RTC driver prevents "periodic alarm" modes.
         *
         * But this can be racey, because some fields of the RTC timestamp
         * may have wrapped in the interval since we read the RTC alarm,
@@ -174,6 +187,10 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
                if (!alarm->enabled)
                        return 0;
 
+               /* full-function RTCs won't have such missing fields */
+               if (rtc_valid_tm(&alarm->time) == 0)
+                       return 0;
+
                /* get the "after" timestamp, to detect wrapped fields */
                err = rtc_read_time(rtc, &now);
                if (err < 0)
@@ -183,22 +200,85 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
        } while (   before.tm_min   != now.tm_min
                 || before.tm_hour  != now.tm_hour
                 || before.tm_mon   != now.tm_mon
-                || before.tm_year  != now.tm_year
-                || before.tm_isdst != now.tm_isdst);
+                || before.tm_year  != now.tm_year);
 
-       /* Fill in any missing alarm fields using the timestamp */
+       /* Fill in the missing alarm fields using the timestamp; we
+        * know there's at least one since alarm->time is invalid.
+        */
        if (alarm->time.tm_sec == -1)
                alarm->time.tm_sec = now.tm_sec;
        if (alarm->time.tm_min == -1)
                alarm->time.tm_min = now.tm_min;
        if (alarm->time.tm_hour == -1)
                alarm->time.tm_hour = now.tm_hour;
-       if (alarm->time.tm_mday == -1)
+
+       /* For simplicity, only support date rollover for now */
+       if (alarm->time.tm_mday == -1) {
                alarm->time.tm_mday = now.tm_mday;
-       if (alarm->time.tm_mon == -1)
+               missing = day;
+       }
+       if (alarm->time.tm_mon == -1) {
                alarm->time.tm_mon = now.tm_mon;
-       if (alarm->time.tm_year == -1)
+               if (missing == none)
+                       missing = month;
+       }
+       if (alarm->time.tm_year == -1) {
                alarm->time.tm_year = now.tm_year;
+               if (missing == none)
+                       missing = year;
+       }
+
+       /* with luck, no rollover is needed */
+       rtc_tm_to_time(&now, &t_now);
+       rtc_tm_to_time(&alarm->time, &t_alm);
+       if (t_now < t_alm)
+               goto done;
+
+       switch (missing) {
+
+       /* 24 hour rollover ... if it's now 10am Monday, an alarm that
+        * that will trigger at 5am will do so at 5am Tuesday, which
+        * could also be in the next month or year.  This is a common
+        * case, especially for PCs.
+        */
+       case day:
+               dev_dbg(&rtc->dev, "alarm rollover: %s\n", "day");
+               t_alm += 24 * 60 * 60;
+               rtc_time_to_tm(t_alm, &alarm->time);
+               break;
+
+       /* Month rollover ... if it's the 31th, an alarm on the 3rd will
+        * be next month.  An alarm matching on the 30th, 29th, or 28th
+        * may end up in the month after that!  Many newer PCs support
+        * this type of alarm.
+        */
+       case month:
+               dev_dbg(&rtc->dev, "alarm rollover: %s\n", "month");
+               do {
+                       if (alarm->time.tm_mon < 11)
+                               alarm->time.tm_mon++;
+                       else {
+                               alarm->time.tm_mon = 0;
+                               alarm->time.tm_year++;
+                       }
+                       days = rtc_month_days(alarm->time.tm_mon,
+                                       alarm->time.tm_year);
+               } while (days < alarm->time.tm_mday);
+               break;
+
+       /* Year rollover ... easy except for leap years! */
+       case year:
+               dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year");
+               do {
+                       alarm->time.tm_year++;
+               } while (!rtc_valid_tm(&alarm->time));
+               break;
+
+       default:
+               dev_warn(&rtc->dev, "alarm rollover not handled\n");
+       }
+
+done:
        return 0;
 }
 EXPORT_SYMBOL_GPL(rtc_read_alarm);
index 82f62d25f92180e01caecd6c4467a7fdbf92aa7e..67421b0d3a7b33ff7e2b87d641a5e3e499e5fa98 100644 (file)
@@ -331,14 +331,14 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
                RCNR = 0;
        }
 
+       device_init_wakeup(&pdev->dev, 1);
+
        rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops,
                                THIS_MODULE);
 
        if (IS_ERR(rtc))
                return PTR_ERR(rtc);
 
-       device_init_wakeup(&pdev->dev, 1);
-
        platform_set_drvdata(pdev, rtc);
 
        return 0;
index eaf55945f21bbf860318a082b24463caa8648ebc..7dcfba1bbfe131539af2aba38d361e53d036280e 100644 (file)
@@ -71,6 +71,7 @@
 #define X1205_SR_RTCF          0x01    /* Clock failure */
 #define X1205_SR_WEL           0x02    /* Write Enable Latch */
 #define X1205_SR_RWEL          0x04    /* Register Write Enable */
+#define X1205_SR_AL0           0x20    /* Alarm 0 match */
 
 #define X1205_DTR_DTR0         0x01
 #define X1205_DTR_DTR1         0x02
@@ -78,6 +79,8 @@
 
 #define X1205_HR_MIL           0x80    /* Set in ccr.hour for 24 hr mode */
 
+#define X1205_INT_AL0E         0x20    /* Alarm 0 enable */
+
 static struct i2c_driver x1205_driver;
 
 /*
@@ -89,8 +92,8 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
                                unsigned char reg_base)
 {
        unsigned char dt_addr[2] = { 0, reg_base };
-
        unsigned char buf[8];
+       int i;
 
        struct i2c_msg msgs[] = {
                { client->addr, 0, 2, dt_addr },        /* setup read ptr */
@@ -98,7 +101,7 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
        };
 
        /* read date registers */
-       if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
+       if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) {
                dev_err(&client->dev, "%s: read error\n", __func__);
                return -EIO;
        }
@@ -110,6 +113,11 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
                buf[0], buf[1], buf[2], buf[3],
                buf[4], buf[5], buf[6], buf[7]);
 
+       /* Mask out the enable bits if these are alarm registers */
+       if (reg_base < X1205_CCR_BASE)
+               for (i = 0; i <= 4; i++)
+                       buf[i] &= 0x7F;
+
        tm->tm_sec = BCD2BIN(buf[CCR_SEC]);
        tm->tm_min = BCD2BIN(buf[CCR_MIN]);
        tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */
@@ -138,7 +146,7 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr)
        };
 
        /* read status register */
-       if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
+       if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) {
                dev_err(&client->dev, "%s: read error\n", __func__);
                return -EIO;
        }
@@ -147,10 +155,11 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr)
 }
 
 static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
-                               int datetoo, u8 reg_base)
+                       int datetoo, u8 reg_base, unsigned char alm_enable)
 {
-       int i, xfer;
+       int i, xfer, nbytes;
        unsigned char buf[8];
+       unsigned char rdata[10] = { 0, reg_base };
 
        static const unsigned char wel[3] = { 0, X1205_REG_SR,
                                                X1205_SR_WEL };
@@ -189,6 +198,11 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
                buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100);
        }
 
+       /* If writing alarm registers, set compare bits on registers 0-4 */
+       if (reg_base < X1205_CCR_BASE)
+               for (i = 0; i <= 4; i++)
+                       buf[i] |= 0x80;
+
        /* this sequence is required to unlock the chip */
        if ((xfer = i2c_master_send(client, wel, 3)) != 3) {
                dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer);
@@ -200,19 +214,57 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
                return -EIO;
        }
 
+
        /* write register's data */
-       for (i = 0; i < (datetoo ? 8 : 3); i++) {
-               unsigned char rdata[3] = { 0, reg_base + i, buf[i] };
+       if (datetoo)
+               nbytes = 8;
+       else
+               nbytes = 3;
+       for (i = 0; i < nbytes; i++)
+               rdata[2+i] = buf[i];
+
+       xfer = i2c_master_send(client, rdata, nbytes+2);
+       if (xfer != nbytes+2) {
+               dev_err(&client->dev,
+                       "%s: result=%d addr=%02x, data=%02x\n",
+                       __func__,
+                        xfer, rdata[1], rdata[2]);
+               return -EIO;
+       }
+
+       /* If we wrote to the nonvolatile region, wait 10msec for write cycle*/
+       if (reg_base < X1205_CCR_BASE) {
+               unsigned char al0e[3] = { 0, X1205_REG_INT, 0 };
+
+               msleep(10);
 
-               xfer = i2c_master_send(client, rdata, 3);
+               /* ...and set or clear the AL0E bit in the INT register */
+
+               /* Need to set RWEL again as the write has cleared it */
+               xfer = i2c_master_send(client, rwel, 3);
                if (xfer != 3) {
                        dev_err(&client->dev,
-                               "%s: xfer=%d addr=%02x, data=%02x\n",
+                               "%s: aloe rwel - %d\n",
                                __func__,
-                                xfer, rdata[1], rdata[2]);
+                               xfer);
+                       return -EIO;
+               }
+
+               if (alm_enable)
+                       al0e[2] = X1205_INT_AL0E;
+
+               xfer = i2c_master_send(client, al0e, 3);
+               if (xfer != 3) {
+                       dev_err(&client->dev,
+                               "%s: al0e - %d\n",
+                               __func__,
+                               xfer);
                        return -EIO;
                }
-       };
+
+               /* and wait 10msec again for this write to complete */
+               msleep(10);
+       }
 
        /* disable further writes */
        if ((xfer = i2c_master_send(client, diswe, 3)) != 3) {
@@ -230,9 +282,9 @@ static int x1205_fix_osc(struct i2c_client *client)
 
        tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
 
-       if ((err = x1205_set_datetime(client, &tm, 0, X1205_CCR_BASE)) < 0)
-               dev_err(&client->dev,
-                       "unable to restart the oscillator\n");
+       err = x1205_set_datetime(client, &tm, 0, X1205_CCR_BASE, 0);
+       if (err < 0)
+               dev_err(&client->dev, "unable to restart the oscillator\n");
 
        return err;
 }
@@ -248,7 +300,7 @@ static int x1205_get_dtrim(struct i2c_client *client, int *trim)
        };
 
        /* read dtr register */
-       if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
+       if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) {
                dev_err(&client->dev, "%s: read error\n", __func__);
                return -EIO;
        }
@@ -280,7 +332,7 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim)
        };
 
        /* read atr register */
-       if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
+       if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) {
                dev_err(&client->dev, "%s: read error\n", __func__);
                return -EIO;
        }
@@ -403,14 +455,33 @@ static int x1205_validate_client(struct i2c_client *client)
 
 static int x1205_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
-       return x1205_get_datetime(to_i2c_client(dev),
-               &alrm->time, X1205_ALM0_BASE);
+       int err;
+       unsigned char intreg, status;
+       static unsigned char int_addr[2] = { 0, X1205_REG_INT };
+       struct i2c_client *client = to_i2c_client(dev);
+       struct i2c_msg msgs[] = {
+               { client->addr, 0, 2, int_addr },        /* setup read ptr */
+               { client->addr, I2C_M_RD, 1, &intreg },  /* read INT register */
+       };
+
+       /* read interrupt register and status register */
+       if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) {
+               dev_err(&client->dev, "%s: read error\n", __func__);
+               return -EIO;
+       }
+       err = x1205_get_status(client, &status);
+       if (err == 0) {
+               alrm->pending = (status & X1205_SR_AL0) ? 1 : 0;
+               alrm->enabled = (intreg & X1205_INT_AL0E) ? 1 : 0;
+               err = x1205_get_datetime(client, &alrm->time, X1205_ALM0_BASE);
+       }
+       return err;
 }
 
 static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
        return x1205_set_datetime(to_i2c_client(dev),
-               &alrm->time, 1, X1205_ALM0_BASE);
+               &alrm->time, 1, X1205_ALM0_BASE, alrm->enabled);
 }
 
 static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm)
@@ -422,7 +493,7 @@ static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm)
 static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm)
 {
        return x1205_set_datetime(to_i2c_client(dev),
-               tm, 1, X1205_CCR_BASE);
+               tm, 1, X1205_CCR_BASE, 0);
 }
 
 static int x1205_rtc_proc(struct device *dev, struct seq_file *seq)
index a0b6d414953dda3128acc7477827a7dcfbdd429b..59fbef08d690763920af4b7fac52752f30be0570 100644 (file)
@@ -2359,6 +2359,24 @@ void scsi_esp_unregister(struct esp *esp)
 }
 EXPORT_SYMBOL(scsi_esp_unregister);
 
+static int esp_target_alloc(struct scsi_target *starget)
+{
+       struct esp *esp = shost_priv(dev_to_shost(&starget->dev));
+       struct esp_target_data *tp = &esp->target[starget->id];
+
+       tp->starget = starget;
+
+       return 0;
+}
+
+static void esp_target_destroy(struct scsi_target *starget)
+{
+       struct esp *esp = shost_priv(dev_to_shost(&starget->dev));
+       struct esp_target_data *tp = &esp->target[starget->id];
+
+       tp->starget = NULL;
+}
+
 static int esp_slave_alloc(struct scsi_device *dev)
 {
        struct esp *esp = shost_priv(dev->host);
@@ -2370,8 +2388,6 @@ static int esp_slave_alloc(struct scsi_device *dev)
                return -ENOMEM;
        dev->hostdata = lp;
 
-       tp->starget = dev->sdev_target;
-
        spi_min_period(tp->starget) = esp->min_period;
        spi_max_offset(tp->starget) = 15;
 
@@ -2608,6 +2624,8 @@ struct scsi_host_template scsi_esp_template = {
        .name                   = "esp",
        .info                   = esp_info,
        .queuecommand           = esp_queuecommand,
+       .target_alloc           = esp_target_alloc,
+       .target_destroy         = esp_target_destroy,
        .slave_alloc            = esp_slave_alloc,
        .slave_configure        = esp_slave_configure,
        .slave_destroy          = esp_slave_destroy,
index 45df83b9d847122abac77e2d7a9d5a59eb2cfb95..0fe031f003e7e8e5082dc91469204e53b35067b5 100644 (file)
@@ -61,7 +61,7 @@ static int ses_probe(struct device *dev)
        return err;
 }
 
-#define SES_TIMEOUT 30
+#define SES_TIMEOUT (30 * HZ)
 #define SES_RETRIES 3
 
 static int ses_recv_diag(struct scsi_device *sdev, int page_code,
index c9b64e73c9879d10d7bd7e7e4055bd257c083e73..42d2e108b67968406ebc1da8ac8b316d532f578a 100644 (file)
@@ -1991,7 +1991,9 @@ struct uart_match {
 static int serial_match_port(struct device *dev, void *data)
 {
        struct uart_match *match = data;
-       dev_t devt = MKDEV(match->driver->major, match->driver->minor) + match->port->line;
+       struct tty_driver *tty_drv = match->driver->tty_driver;
+       dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) +
+               match->port->line;
 
        return dev->devt == devt; /* Actually, only one tty per port */
 }
index 799337f7fde1b5a5971ff11c6378121e20cc5451..f5b60c70389b771bc752be6178ed38cfed2730f9 100644 (file)
@@ -167,14 +167,14 @@ spidev_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
 
        mutex_lock(&spidev->buf_lock);
        status = spidev_sync_read(spidev, count);
-       if (status == 0) {
+       if (status > 0) {
                unsigned long   missing;
 
-               missing = copy_to_user(buf, spidev->buffer, count);
-               if (count && missing == count)
+               missing = copy_to_user(buf, spidev->buffer, status);
+               if (missing == status)
                        status = -EFAULT;
                else
-                       status = count - missing;
+                       status = status - missing;
        }
        mutex_unlock(&spidev->buf_lock);
 
@@ -200,8 +200,6 @@ spidev_write(struct file *filp, const char __user *buf,
        missing = copy_from_user(spidev->buffer, buf, count);
        if (missing == 0) {
                status = spidev_sync_write(spidev, count);
-               if (status == 0)
-                       status = count;
        } else
                status = -EFAULT;
        mutex_unlock(&spidev->buf_lock);
index 4b628526df097562a94004a653a9ba16eed9dd18..a86e952ed4ca4de05891b19d54ef185802048bfc 100644 (file)
@@ -12,3 +12,12 @@ menuconfig THERMAL
          cooling devices.
          All platforms with ACPI thermal support can use this driver.
          If you want this support, you should say Y or M here.
+
+config THERMAL_HWMON
+       bool "Hardware monitoring support"
+       depends on HWMON=y || HWMON=THERMAL
+       help
+         The generic thermal sysfs driver's hardware monitoring support
+         requires a 2.10.7/3.0.2 or later lm-sensors userspace.
+
+         Say Y if your user-space is new enough.
index 6098787341f3d6ada67a195b7ee59d307b6a9c34..fe07462d5947fec44a4eb559a552670e84744a08 100644 (file)
@@ -295,8 +295,8 @@ thermal_cooling_device_trip_point_show(struct device *dev,
 
 /* Device management */
 
-#if defined(CONFIG_HWMON) ||   \
-       (defined(CONFIG_HWMON_MODULE) && defined(CONFIG_THERMAL_MODULE))
+#if defined(CONFIG_THERMAL_HWMON)
+
 /* hwmon sys I/F */
 #include <linux/hwmon.h>
 static LIST_HEAD(thermal_hwmon_list);
index 63c34043b4d91e0bfb2864672704be838f518fef..c3201affa0b6f99c17ff6d28c71e3cd08adb58c6 100644 (file)
@@ -1125,9 +1125,6 @@ static void stop_data_traffic(struct acm *acm)
        for (i = 0; i < acm->rx_buflimit; i++)
                usb_kill_urb(acm->ru[i].urb);
 
-       INIT_LIST_HEAD(&acm->filled_read_bufs);
-       INIT_LIST_HEAD(&acm->spare_read_bufs);
-
        tasklet_enable(&acm->urb_task);
 
        cancel_work_sync(&acm->work);
index 09a53e7f33278ad58f555b15792c7b89c676a458..7158dbb6e4b4d74863fa4d4bb78ad94d0fbcd8ec 100644 (file)
@@ -1684,19 +1684,30 @@ EXPORT_SYMBOL_GPL(usb_bus_start_enum);
 irqreturn_t usb_hcd_irq (int irq, void *__hcd)
 {
        struct usb_hcd          *hcd = __hcd;
-       int                     start = hcd->state;
+       unsigned long           flags;
+       irqreturn_t             rc;
 
-       if (unlikely(start == HC_STATE_HALT ||
-           !test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
-               return IRQ_NONE;
-       if (hcd->driver->irq (hcd) == IRQ_NONE)
-               return IRQ_NONE;
+       /* IRQF_DISABLED doesn't work correctly with shared IRQs
+        * when the first handler doesn't use it.  So let's just
+        * assume it's never used.
+        */
+       local_irq_save(flags);
 
-       set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
+       if (unlikely(hcd->state == HC_STATE_HALT ||
+                    !test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) {
+               rc = IRQ_NONE;
+       } else if (hcd->driver->irq(hcd) == IRQ_NONE) {
+               rc = IRQ_NONE;
+       } else {
+               set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
 
-       if (unlikely(hcd->state == HC_STATE_HALT))
-               usb_hc_died (hcd);
-       return IRQ_HANDLED;
+               if (unlikely(hcd->state == HC_STATE_HALT))
+                       usb_hc_died(hcd);
+               rc = IRQ_HANDLED;
+       }
+
+       local_irq_restore(flags);
+       return rc;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -1860,6 +1871,13 @@ int usb_add_hcd(struct usb_hcd *hcd,
 
        /* enable irqs just before we start the controller */
        if (hcd->driver->irq) {
+
+               /* IRQF_DISABLED doesn't work as advertised when used together
+                * with IRQF_SHARED. As usb_hcd_irq() will always disable
+                * interrupts we can remove it here.
+                */
+               irqflags &= ~IRQF_DISABLED;
+
                snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
                                hcd->driver->description, hcd->self.busnum);
                if ((retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
index 94789be54ca3a8c66bfd0e4b5e21c9b9112b5ab9..512d2d57d41e5e15761bb36cc8c2ee87727acd41 100644 (file)
@@ -713,18 +713,11 @@ static void hub_restart(struct usb_hub *hub, int type)
                }
 
                /* Was the power session lost while we were suspended? */
-               switch (type) {
-               case HUB_RESET_RESUME:
-                       portstatus = 0;
-                       portchange = USB_PORT_STAT_C_CONNECTION;
-                       break;
+               status = hub_port_status(hub, port1, &portstatus, &portchange);
 
-               case HUB_RESET:
-               case HUB_RESUME:
-                       status = hub_port_status(hub, port1,
-                                       &portstatus, &portchange);
-                       break;
-               }
+               /* If the device is gone, khubd will handle it later */
+               if (status == 0 && !(portstatus & USB_PORT_STAT_CONNECTION))
+                       continue;
 
                /* For "USB_PERSIST"-enabled children we must
                 * mark the child device for reset-resume and
index 35a03095757ea3b2ae225e203bab757abb4aceb6..90245fd8bac4dd234390ec96e636570ef4e98c73 100644 (file)
@@ -177,6 +177,15 @@ timer_action_done (struct ehci_hcd *ehci, enum ehci_timer_action action)
 static inline void
 timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
 {
+       /* Don't override timeouts which shrink or (later) disable
+        * the async ring; just the I/O watchdog.  Note that if a
+        * SHRINK were pending, OFF would never be requested.
+        */
+       if (timer_pending(&ehci->watchdog)
+                       && ((BIT(TIMER_ASYNC_SHRINK) | BIT(TIMER_ASYNC_OFF))
+                               & ehci->actions))
+               return;
+
        if (!test_and_set_bit (action, &ehci->actions)) {
                unsigned long t;
 
@@ -192,15 +201,7 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
                        t = EHCI_SHRINK_JIFFIES;
                        break;
                }
-               t += jiffies;
-               // all timings except IAA watchdog can be overridden.
-               // async queue SHRINK often precedes IAA.  while it's ready
-               // to go OFF neither can matter, and afterwards the IO
-               // watchdog stops unless there's still periodic traffic.
-               if (time_before_eq(t, ehci->watchdog.expires)
-                               && timer_pending (&ehci->watchdog))
-                       return;
-               mod_timer (&ehci->watchdog, t);
+               mod_timer(&ehci->watchdog, t + jiffies);
        }
 }
 
index 33f1c1c32edf75ecc5a93e4a171c0afa2806a123..a8160d65f32be3f3be08fc4f2813f7b2c5b3def6 100644 (file)
@@ -1054,7 +1054,7 @@ MODULE_LICENSE ("GPL");
 
 #ifdef CONFIG_MFD_SM501
 #include "ohci-sm501.c"
-#define PLATFORM_DRIVER                ohci_hcd_sm501_driver
+#define SM501_OHCI_DRIVER      ohci_hcd_sm501_driver
 #endif
 
 #if    !defined(PCI_DRIVER) &&         \
@@ -1062,6 +1062,7 @@ MODULE_LICENSE ("GPL");
        !defined(OF_PLATFORM_DRIVER) && \
        !defined(SA1111_DRIVER) &&      \
        !defined(PS3_SYSTEM_BUS_DRIVER) && \
+       !defined(SM501_OHCI_DRIVER) && \
        !defined(SSB_OHCI_DRIVER)
 #error "missing bus glue for ohci-hcd"
 #endif
@@ -1121,9 +1122,18 @@ static int __init ohci_hcd_mod_init(void)
                goto error_ssb;
 #endif
 
+#ifdef SM501_OHCI_DRIVER
+       retval = platform_driver_register(&SM501_OHCI_DRIVER);
+       if (retval < 0)
+               goto error_sm501;
+#endif
+
        return retval;
 
        /* Error path */
+#ifdef SM501_OHCI_DRIVER
+ error_sm501:
+#endif
 #ifdef SSB_OHCI_DRIVER
  error_ssb:
 #endif
@@ -1159,6 +1169,9 @@ module_init(ohci_hcd_mod_init);
 
 static void __exit ohci_hcd_mod_exit(void)
 {
+#ifdef SM501_OHCI_DRIVER
+       platform_driver_unregister(&SM501_OHCI_DRIVER);
+#endif
 #ifdef SSB_OHCI_DRIVER
        ssb_driver_unregister(&SSB_OHCI_DRIVER);
 #endif
index 9c9f3b59186f6c65d3d33cbfa16dced198de10eb..9b547407c9342fd41b02700adda126c0382cd74e 100644 (file)
@@ -952,6 +952,7 @@ rescan_this:
                        struct urb      *urb;
                        urb_priv_t      *urb_priv;
                        __hc32          savebits;
+                       u32             tdINFO;
 
                        td = list_entry (entry, struct td, td_list);
                        urb = td->urb;
@@ -966,6 +967,17 @@ rescan_this:
                        savebits = *prev & ~cpu_to_hc32 (ohci, TD_MASK);
                        *prev = td->hwNextTD | savebits;
 
+                       /* If this was unlinked, the TD may not have been
+                        * retired ... so manually save the data toggle.
+                        * The controller ignores the value we save for
+                        * control and ISO endpoints.
+                        */
+                       tdINFO = hc32_to_cpup(ohci, &td->hwINFO);
+                       if ((tdINFO & TD_T) == TD_T_DATA0)
+                               ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_C);
+                       else if ((tdINFO & TD_T) == TD_T_DATA1)
+                               ed->hwHeadP |= cpu_to_hc32(ohci, ED_C);
+
                        /* HC may have partly processed this TD */
                        td_done (ohci, urb, td);
                        urb_priv->td_cnt++;
index cb7fa0eaf3ae9e264bc4fea418a6e70afe979021..33182f4c2267ad69ddab0106e76cf39e2bff8436 100644 (file)
@@ -3264,8 +3264,6 @@ static void sisusb_disconnect(struct usb_interface *intf)
 
        /* decrement our usage count */
        kref_put(&sisusb->kref, sisusb_delete);
-
-       dev_info(&sisusb->sisusb_dev->dev, "Disconnected\n");
 }
 
 static struct usb_device_id sisusb_table [] = {
index 5234e7a3bd2c715278d4afabdd54ca9a8957d17e..0ff4a3971e45a95ce0e7047a0e6bb7411646c493 100644 (file)
@@ -637,6 +637,7 @@ static struct usb_device_id id_table_combined [] = {
        { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID),
                .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
        { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) },
+       { USB_DEVICE(FTDI_VID, FTDI_REU_TINY_PID) },
        { },                                    /* Optional parameter entry */
        { }                                     /* Terminating entry */
 };
index 06e0ecabb3eb7d90e31003e008c27e36675241d4..8302eca893ea334f61c5d0d64c2b3a0ccfad91fa 100644 (file)
 /* Propox devices */
 #define FTDI_PROPOX_JTAGCABLEII_PID    0xD738
 
+/* Rig Expert Ukraine devices */
+#define FTDI_REU_TINY_PID              0xED22  /* RigExpert Tiny */
+
 /* Commands */
 #define FTDI_SIO_RESET                 0 /* Reset the port */
 #define FTDI_SIO_MODEM_CTRL    1 /* Set the modem control register */
index ea924dc48496de2b8ca7341c5de69217c3ad8a7e..d9fb3768a2d7b1ba869e4275bcc6ec9d29d1ed2c 100644 (file)
@@ -570,7 +570,12 @@ static struct usb_serial_driver ipaq_device = {
        .description =          "PocketPC PDA",
        .usb_driver =           &ipaq_driver,
        .id_table =             ipaq_id_table,
-       .num_ports =            2,
+       /*
+        * some devices have an extra endpoint, which
+        * must be ignored as it would make the core
+        * create a second port which oopses when used
+        */
+       .num_ports =            1,
        .open =                 ipaq_open,
        .close =                ipaq_close,
        .attach =               ipaq_startup,
index 43cfde83a93b96e24c680a47b783cb829359df49..a73420dd052a511846be7466050355380d0b970d 100644 (file)
@@ -306,6 +306,7 @@ static struct usb_device_id option_ids[] = {
        { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_C100_1) },
        { USB_DEVICE(BANDRICH_VENDOR_ID, BANDRICH_PRODUCT_C100_2) },
        { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_PRODUCT_KPC680) },
+       { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6000)}, /* ZTE AC8700 */
        { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */
        { USB_DEVICE(MAXON_VENDOR_ID, 0x6280) }, /* BP3-USB & BP3-EXT HSDPA */
        { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) },
index 103195abd41710c39133344d8668bab283003819..2a0dd1b50dc43b8dc884f0964c4f6624bfac1921 100644 (file)
@@ -57,6 +57,7 @@ static struct usb_device_id id_table [] = {
        { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_PHAROS) },
        { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ALDIGA) },
        { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MMX) },
+       { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GPRS) },
        { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
        { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) },
        { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) },
index cff160abb13045d555893c325a8eced36bda15db..6ac3bbcf7a22903b392d2281e2627f5db92e93fc 100644 (file)
@@ -15,6 +15,7 @@
 #define PL2303_PRODUCT_ID_RSAQ3                0xaaa2
 #define PL2303_PRODUCT_ID_ALDIGA       0x0611
 #define PL2303_PRODUCT_ID_MMX          0x0612
+#define PL2303_PRODUCT_ID_GPRS         0x0609
 
 #define ATEN_VENDOR_ID         0x0557
 #define ATEN_VENDOR_ID2                0x0547
index 45fe3663fa7f7c320f47f805ddfa73441efdcbb5..39a7c11795c49bbce9a320eff2189de7cc63eb07 100644 (file)
@@ -402,11 +402,19 @@ UNUSUAL_DEV(  0x04a5, 0x3010, 0x0100, 0x0100,
                US_FL_IGNORE_RESIDUE ),
 
 #ifdef CONFIG_USB_STORAGE_CYPRESS_ATACB
+/* CY7C68300 : support atacb */
 UNUSUAL_DEV(  0x04b4, 0x6830, 0x0000, 0x9999,
                "Cypress",
                "Cypress AT2LP",
                US_SC_CYP_ATACB, US_PR_DEVICE, NULL,
                0),
+
+/* CY7C68310 : support atacb and atacb2 */
+UNUSUAL_DEV(  0x04b4, 0x6831, 0x0000, 0x9999,
+               "Cypress",
+               "Cypress ISD-300LP",
+               US_SC_CYP_ATACB, US_PR_DEVICE, NULL,
+               0),
 #endif
 
 /* Reported by Simon Levitt <simon@whattf.com>
index 002b61b4f0f6d9fba9c48a9f3216068f816b9ce4..e0c5f96b273d150bbca242222b6aee9869d716ba 100644 (file)
@@ -1825,12 +1825,13 @@ config FB_FSL_DIU
 
 config FB_W100
        tristate "W100 frame buffer support"
-       depends on FB && PXA_SHARPSL
+       depends on FB && ARCH_PXA
        select FB_CFB_FILLRECT
        select FB_CFB_COPYAREA
        select FB_CFB_IMAGEBLIT
        ---help---
          Frame buffer driver for the w100 as found on the Sharp SL-Cxx series.
+         It can also drive the w3220 chip found on iPAQ hx4700.
 
          This driver is also available as a module ( = code which can be
          inserted and removed from the running kernel whenever you want). The
index 0a2785361ca3541681fead9c9a5b1838f784178c..712dabc6269f8317f7754bd1e9e68b4c256fe705 100644 (file)
@@ -286,7 +286,7 @@ static struct diu_pool pool;
  *     rheap and make the furture large allocation fail.
  */
 
-void *fsl_diu_alloc(unsigned long size, phys_addr_t *phys)
+static void *fsl_diu_alloc(unsigned long size, phys_addr_t *phys)
 {
        void *virt;
 
@@ -311,12 +311,12 @@ void *fsl_diu_alloc(unsigned long size, phys_addr_t *phys)
                memset(virt, 0, size);
        }
 
-       pr_debug("rh virt=%p phys=%lx\n", virt, *phys);
+       pr_debug("rh virt=%p phys=%llx\n", virt, (unsigned long long)*phys);
 
        return virt;
 }
 
-void fsl_diu_free(void *p, unsigned long size)
+static void fsl_diu_free(void *p, unsigned long size)
 {
        pr_debug("p=%p size=%lu\n", p, size);
 
@@ -770,7 +770,7 @@ static int map_video_memory(struct fb_info *info)
        info->fix.smem_len = info->fix.line_length * info->var.yres_virtual;
        pr_debug("MAP_VIDEO_MEMORY: smem_len = %d\n", info->fix.smem_len);
        info->screen_base = fsl_diu_alloc(info->fix.smem_len, &phys);
-       if (info->screen_base == 0) {
+       if (info->screen_base == NULL) {
                printk(KERN_ERR "Unable to allocate fb memory\n");
                return -ENOMEM;
        }
@@ -788,7 +788,7 @@ static int map_video_memory(struct fb_info *info)
 static void unmap_video_memory(struct fb_info *info)
 {
        fsl_diu_free(info->screen_base, info->fix.smem_len);
-       info->screen_base = 0;
+       info->screen_base = NULL;
        info->fix.smem_start = 0;
        info->fix.smem_len = 0;
 }
@@ -1158,7 +1158,7 @@ static int init_fbinfo(struct fb_info *info)
        return 0;
 }
 
-static int install_fb(struct fb_info *info)
+static int __devinit install_fb(struct fb_info *info)
 {
        int rc;
        struct mfb_info *mfbi = info->par;
@@ -1233,7 +1233,7 @@ static int install_fb(struct fb_info *info)
        return 0;
 }
 
-static void __exit uninstall_fb(struct fb_info *info)
+static void uninstall_fb(struct fb_info *info)
 {
        struct mfb_info *mfbi = info->par;
 
@@ -1287,7 +1287,7 @@ static int request_irq_local(int irq)
        /* Read to clear the status */
        status = in_be32(&hw->int_status);
 
-       ret = request_irq(irq, fsl_diu_isr, 0, "diu", 0);
+       ret = request_irq(irq, fsl_diu_isr, 0, "diu", NULL);
        if (ret)
                pr_info("Request diu IRQ failed.\n");
        else {
@@ -1312,7 +1312,7 @@ static void free_irq_local(int irq)
        /* Disable all LCDC interrupt */
        out_be32(&hw->int_mask, 0x1f);
 
-       free_irq(irq, 0);
+       free_irq(irq, NULL);
 }
 
 #ifdef CONFIG_PM
@@ -1324,7 +1324,7 @@ static int fsl_diu_suspend(struct of_device *ofdev, pm_message_t state)
 {
        struct fsl_diu_data *machine_data;
 
-       machine_data = dev_get_drvdata(&ofdev->dev);
+       machine_data = dev_get_drvdata(&dev->dev);
        disable_lcdc(machine_data->fsl_diu_info[0]);
 
        return 0;
@@ -1334,7 +1334,7 @@ static int fsl_diu_resume(struct of_device *ofdev)
 {
        struct fsl_diu_data *machine_data;
 
-       machine_data = dev_get_drvdata(&ofdev->dev);
+       machine_data = dev_get_drvdata(&dev->dev);
        enable_lcdc(machine_data->fsl_diu_info[0]);
 
        return 0;
@@ -1353,7 +1353,8 @@ static int allocate_buf(struct diu_addr *buf, u32 size, u32 bytes_align)
        dma_addr_t paddr = 0;
 
        ssize = size + bytes_align;
-       buf->vaddr = dma_alloc_coherent(0, ssize, &paddr, GFP_DMA | __GFP_ZERO);
+       buf->vaddr = dma_alloc_coherent(NULL, ssize, &paddr, GFP_DMA |
+                                                            __GFP_ZERO);
        if (!buf->vaddr)
                return -ENOMEM;
 
@@ -1371,7 +1372,7 @@ static int allocate_buf(struct diu_addr *buf, u32 size, u32 bytes_align)
 
 static void free_buf(struct diu_addr *buf, u32 size, u32 bytes_align)
 {
-       dma_free_coherent(0, size + bytes_align,
+       dma_free_coherent(NULL, size + bytes_align,
                                buf->vaddr, (buf->paddr - buf->offset));
        return;
 }
@@ -1411,7 +1412,7 @@ static ssize_t show_monitor(struct device *device,
        return diu_ops.show_monitor_port(machine_data->monitor_port, buf);
 }
 
-static int fsl_diu_probe(struct of_device *ofdev,
+static int __devinit fsl_diu_probe(struct of_device *ofdev,
        const struct of_device_id *match)
 {
        struct device_node *np = ofdev->node;
index 7dcda187d9ba363e777f060c757b7c1c05bc7db4..fafe7db20d6d2d1652f6e6655039c704e14096dd 100644 (file)
@@ -1246,7 +1246,7 @@ static int pxafb_resume(struct platform_device *dev)
  *      cache.  Once this area is remapped, all virtual memory
  *      access to the video memory should occur at the new region.
  */
-static int __init pxafb_map_video_memory(struct pxafb_info *fbi)
+static int __devinit pxafb_map_video_memory(struct pxafb_info *fbi)
 {
        /*
         * We reserve one page for the palette, plus the size
@@ -1348,7 +1348,7 @@ decode_mode:
        pxafb_decode_mode_info(fbi, inf->modes, inf->num_modes);
 }
 
-static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
+static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev)
 {
        struct pxafb_info *fbi;
        void *addr;
@@ -1410,7 +1410,7 @@ static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
 }
 
 #ifdef CONFIG_FB_PXA_PARAMETERS
-static int __init parse_opt_mode(struct device *dev, const char *this_opt)
+static int __devinit parse_opt_mode(struct device *dev, const char *this_opt)
 {
        struct pxafb_mach_info *inf = dev->platform_data;
 
@@ -1469,7 +1469,7 @@ done:
        return 0;
 }
 
-static int __init parse_opt(struct device *dev, char *this_opt)
+static int __devinit parse_opt(struct device *dev, char *this_opt)
 {
        struct pxafb_mach_info *inf = dev->platform_data;
        struct pxafb_mode_info *mode = &inf->modes[0];
@@ -1567,7 +1567,7 @@ static int __init parse_opt(struct device *dev, char *this_opt)
        return 0;
 }
 
-static int __init pxafb_parse_options(struct device *dev, char *options)
+static int __devinit pxafb_parse_options(struct device *dev, char *options)
 {
        char *this_opt;
        int ret;
@@ -1588,8 +1588,8 @@ static int __init pxafb_parse_options(struct device *dev, char *options)
 
 static char g_options[256] __devinitdata = "";
 
-#ifndef CONFIG_MODULES
-static int __devinit pxafb_setup_options(void)
+#ifndef MODULE
+static int __init pxafb_setup_options(void)
 {
        char *options = NULL;
 
@@ -1613,7 +1613,7 @@ MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
 #define pxafb_setup_options()          (0)
 #endif
 
-static int __init pxafb_probe(struct platform_device *dev)
+static int __devinit pxafb_probe(struct platform_device *dev)
 {
        struct pxafb_info *fbi;
        struct pxafb_mach_info *inf;
@@ -1685,14 +1685,14 @@ static int __init pxafb_probe(struct platform_device *dev)
        if (r == NULL) {
                dev_err(&dev->dev, "no I/O memory resource defined\n");
                ret = -ENODEV;
-               goto failed;
+               goto failed_fbi;
        }
 
        r = request_mem_region(r->start, r->end - r->start + 1, dev->name);
        if (r == NULL) {
                dev_err(&dev->dev, "failed to request I/O memory\n");
                ret = -EBUSY;
-               goto failed;
+               goto failed_fbi;
        }
 
        fbi->mmio_base = ioremap(r->start, r->end - r->start + 1);
@@ -1735,8 +1735,17 @@ static int __init pxafb_probe(struct platform_device *dev)
         * This makes sure that our colour bitfield
         * descriptors are correctly initialised.
         */
-       pxafb_check_var(&fbi->fb.var, &fbi->fb);
-       pxafb_set_par(&fbi->fb);
+       ret = pxafb_check_var(&fbi->fb.var, &fbi->fb);
+       if (ret) {
+               dev_err(&dev->dev, "failed to get suitable mode\n");
+               goto failed_free_irq;
+       }
+
+       ret = pxafb_set_par(&fbi->fb);
+       if (ret) {
+               dev_err(&dev->dev, "Failed to set parameters\n");
+               goto failed_free_irq;
+       }
 
        platform_set_drvdata(dev, fbi);
 
@@ -1744,7 +1753,7 @@ static int __init pxafb_probe(struct platform_device *dev)
        if (ret < 0) {
                dev_err(&dev->dev,
                        "Failed to register framebuffer device: %d\n", ret);
-               goto failed_free_irq;
+               goto failed_free_cmap;
        }
 
 #ifdef CONFIG_CPU_FREQ
@@ -1763,18 +1772,23 @@ static int __init pxafb_probe(struct platform_device *dev)
 
        return 0;
 
+failed_free_cmap:
+       if (fbi->fb.cmap.len)
+               fb_dealloc_cmap(&fbi->fb.cmap);
 failed_free_irq:
        free_irq(irq, fbi);
-failed_free_res:
-       release_mem_region(r->start, r->end - r->start + 1);
-failed_free_io:
-       iounmap(fbi->mmio_base);
 failed_free_mem:
        dma_free_writecombine(&dev->dev, fbi->map_size,
                        fbi->map_cpu, fbi->map_dma);
-failed:
+failed_free_io:
+       iounmap(fbi->mmio_base);
+failed_free_res:
+       release_mem_region(r->start, r->end - r->start + 1);
+failed_fbi:
+       clk_put(fbi->clk);
        platform_set_drvdata(dev, NULL);
        kfree(fbi);
+failed:
        return ret;
 }
 
@@ -1787,7 +1801,7 @@ static struct platform_driver pxafb_driver = {
        },
 };
 
-static int __devinit pxafb_init(void)
+static int __init pxafb_init(void)
 {
        if (pxafb_setup_options())
                return -EINVAL;
index 30469bf906e54b51a6688918624fd030ab6f25cf..d0674f1e3f10820e95a8e9db42160fe871908498 100644 (file)
@@ -1003,6 +1003,7 @@ static struct w100_pll_info xtal_14318000[] = {
 static struct w100_pll_info xtal_16000000[] = {
        /*freq     M   N_int    N_fac  tfgoal  lock_time */
        { 72,      1,   8,       0,     0xe0,        48}, /* tfgoal guessed */
+       { 80,      1,   9,       0,     0xe0,        13}, /* tfgoal guessed */
        { 95,      1,   10,      7,     0xe0,        38}, /* tfgoal guessed */
        { 96,      1,   11,      0,     0xe0,        36}, /* tfgoal guessed */
        {  0,      0,   0,       0,        0,         0},
index fd01d90cada545edcdcac367b17da4add13b08f1..57997fa14e69d4260fc5b9a990e030355a321963 100644 (file)
@@ -51,4 +51,4 @@ int v9fs_dir_release(struct inode *inode, struct file *filp);
 int v9fs_file_open(struct inode *inode, struct file *file);
 void v9fs_inode2stat(struct inode *inode, struct p9_stat *stat);
 void v9fs_dentry_release(struct dentry *);
-int v9fs_uflags2omode(int uflags);
+int v9fs_uflags2omode(int uflags, int extended);
index 0d55affe37d4452124471365797ffb472e1ebe52..52944d2249a49a1e05c7fdc05d63919180dc3a29 100644 (file)
@@ -59,7 +59,7 @@ int v9fs_file_open(struct inode *inode, struct file *file)
 
        P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p \n", inode, file);
        v9ses = v9fs_inode2v9ses(inode);
-       omode = v9fs_uflags2omode(file->f_flags);
+       omode = v9fs_uflags2omode(file->f_flags, v9fs_extended(v9ses));
        fid = file->private_data;
        if (!fid) {
                fid = v9fs_fid_clone(file->f_path.dentry);
@@ -75,6 +75,8 @@ int v9fs_file_open(struct inode *inode, struct file *file)
                        inode->i_size = 0;
                        inode->i_blocks = 0;
                }
+               if ((file->f_flags & O_APPEND) && (!v9fs_extended(v9ses)))
+                       generic_file_llseek(file, 0, SEEK_END);
        }
 
        file->private_data = fid;
index 40fa807bd92928793ff2c66eb82024ea274e4899..c95295c65045a3540959b0ddb9c227e1366472f3 100644 (file)
@@ -132,10 +132,10 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
 /**
  * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits
  * @uflags: flags to convert
- *
+ * @extended: if .u extensions are active
  */
 
-int v9fs_uflags2omode(int uflags)
+int v9fs_uflags2omode(int uflags, int extended)
 {
        int ret;
 
@@ -155,14 +155,16 @@ int v9fs_uflags2omode(int uflags)
                break;
        }
 
-       if (uflags & O_EXCL)
-               ret |= P9_OEXCL;
-
        if (uflags & O_TRUNC)
                ret |= P9_OTRUNC;
 
-       if (uflags & O_APPEND)
-               ret |= P9_OAPPEND;
+       if (extended) {
+               if (uflags & O_EXCL)
+                       ret |= P9_OEXCL;
+
+               if (uflags & O_APPEND)
+                       ret |= P9_OAPPEND;
+       }
 
        return ret;
 }
@@ -506,7 +508,7 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
                flags = O_RDWR;
 
        fid = v9fs_create(v9ses, dir, dentry, NULL, perm,
-                                               v9fs_uflags2omode(flags));
+                               v9fs_uflags2omode(flags, v9fs_extended(v9ses)));
        if (IS_ERR(fid)) {
                err = PTR_ERR(fid);
                fid = NULL;
index cf12c403b8c753b4e8a431ab0c56cb89b5ac588a..2694648cbd1b6e7d235bc6dbb46cffa62482294d 100644 (file)
@@ -830,7 +830,7 @@ config NTFS_FS
          from the project web site.
 
          For more information see <file:Documentation/filesystems/ntfs.txt>
-         and <http://linux-ntfs.sourceforge.net/>.
+         and <http://www.linux-ntfs.org/>.
 
          To compile this file system support as a module, choose M here: the
          module will be called ntfs.
index 470c10ceb0fb3a33dc8f28e7e8b2d3535042075b..10d8a0aa871a096eb3d8577b01d285aa9c1fa433 100644 (file)
@@ -931,8 +931,16 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
        struct gendisk *disk;
        int ret;
        int part;
+       int perm = 0;
 
-       ret = devcgroup_inode_permission(bdev->bd_inode, file->f_mode);
+       if (file->f_mode & FMODE_READ)
+               perm |= MAY_READ;
+       if (file->f_mode & FMODE_WRITE)
+               perm |= MAY_WRITE;
+       /*
+        * hooks: /n/, see "layering violations".
+        */
+       ret = devcgroup_inode_permission(bdev->bd_inode, perm);
        if (ret != 0)
                return ret;
 
index a073f3f4f013c5c349afede7edb715672bfd4928..0f51c0f7c266ee7ebf940d94f869081a4d80b084 100644 (file)
@@ -821,7 +821,7 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list)
                                 * contents - it is a noop if I/O is still in
                                 * flight on potentially older contents.
                                 */
-                               ll_rw_block(SWRITE, 1, &bh);
+                               ll_rw_block(SWRITE_SYNC, 1, &bh);
                                brelse(bh);
                                spin_lock(lock);
                        }
@@ -2940,16 +2940,19 @@ void ll_rw_block(int rw, int nr, struct buffer_head *bhs[])
        for (i = 0; i < nr; i++) {
                struct buffer_head *bh = bhs[i];
 
-               if (rw == SWRITE)
+               if (rw == SWRITE || rw == SWRITE_SYNC)
                        lock_buffer(bh);
                else if (test_set_buffer_locked(bh))
                        continue;
 
-               if (rw == WRITE || rw == SWRITE) {
+               if (rw == WRITE || rw == SWRITE || rw == SWRITE_SYNC) {
                        if (test_clear_buffer_dirty(bh)) {
                                bh->b_end_io = end_buffer_write_sync;
                                get_bh(bh);
-                               submit_bh(WRITE, bh);
+                               if (rw == SWRITE_SYNC)
+                                       submit_bh(WRITE_SYNC, bh);
+                               else
+                                       submit_bh(WRITE, bh);
                                continue;
                        }
                } else {
@@ -2978,7 +2981,7 @@ int sync_dirty_buffer(struct buffer_head *bh)
        if (test_clear_buffer_dirty(bh)) {
                get_bh(bh);
                bh->b_end_io = end_buffer_write_sync;
-               ret = submit_bh(WRITE, bh);
+               ret = submit_bh(WRITE_SYNC, bh);
                wait_on_buffer(bh);
                if (buffer_eopnotsupp(bh)) {
                        clear_buffer_eopnotsupp(bh);
index 3ee588d5f585b54d7aa50358648521b64423b3f8..6068c25b393ca21f5faf8c9ca1fdf8d6051fc836 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/syscalls.h>
 #include <linux/string.h>
 #include <linux/mm.h>
+#include <linux/fdtable.h>
 #include <linux/fs.h>
 #include <linux/fsnotify.h>
 #include <linux/slab.h>
@@ -106,9 +107,10 @@ static void dentry_lru_remove(struct dentry *dentry)
 /*
  * Release the dentry's inode, using the filesystem
  * d_iput() operation if defined.
- * Called with dcache_lock and per dentry lock held, drops both.
  */
 static void dentry_iput(struct dentry * dentry)
+       __releases(dentry->d_lock)
+       __releases(dcache_lock)
 {
        struct inode *inode = dentry->d_inode;
        if (inode) {
@@ -132,12 +134,13 @@ static void dentry_iput(struct dentry * dentry)
  * d_kill - kill dentry and return parent
  * @dentry: dentry to kill
  *
- * Called with dcache_lock and d_lock, releases both.  The dentry must
- * already be unhashed and removed from the LRU.
+ * The dentry must already be unhashed and removed from the LRU.
  *
  * If this is the root of the dentry tree, return NULL.
  */
 static struct dentry *d_kill(struct dentry *dentry)
+       __releases(dentry->d_lock)
+       __releases(dcache_lock)
 {
        struct dentry *parent;
 
@@ -383,11 +386,11 @@ restart:
  * Try to prune ancestors as well.  This is necessary to prevent
  * quadratic behavior of shrink_dcache_parent(), but is also expected
  * to be beneficial in reducing dentry cache fragmentation.
- *
- * Called with dcache_lock, drops it and then regains.
- * Called with dentry->d_lock held, drops it.
  */
 static void prune_one_dentry(struct dentry * dentry)
+       __releases(dentry->d_lock)
+       __releases(dcache_lock)
+       __acquires(dcache_lock)
 {
        __d_drop(dentry);
        dentry = d_kill(dentry);
@@ -1604,10 +1607,9 @@ static int d_isparent(struct dentry *p1, struct dentry *p2)
  *
  * Note: If ever the locking in lock_rename() changes, then please
  * remember to update this too...
- *
- * On return, dcache_lock will have been unlocked.
  */
 static struct dentry *__d_unalias(struct dentry *dentry, struct dentry *alias)
+       __releases(dcache_lock)
 {
        struct mutex *m1 = NULL, *m2 = NULL;
        struct dentry *ret;
@@ -1743,11 +1745,9 @@ out_nolock:
 shouldnt_be_hashed:
        spin_unlock(&dcache_lock);
        BUG();
-       goto shouldnt_be_hashed;
 }
 
-static int prepend(char **buffer, int *buflen, const char *str,
-                         int namelen)
+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
 {
        *buflen -= namelen;
        if (*buflen < 0)
@@ -1757,8 +1757,13 @@ static int prepend(char **buffer, int *buflen, const char *str,
        return 0;
 }
 
+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
+{
+       return prepend(buffer, buflen, name->name, name->len);
+}
+
 /**
- * d_path - return the path of a dentry
+ * __d_path - return the path of a dentry
  * @path: the dentry/vfsmount to report
  * @root: root vfsmnt/dentry (may be modified by this function)
  * @buffer: buffer to return value in
@@ -1779,9 +1784,10 @@ char *__d_path(const struct path *path, struct path *root,
 {
        struct dentry *dentry = path->dentry;
        struct vfsmount *vfsmnt = path->mnt;
-       char * end = buffer+buflen;
-       char * retval;
+       char *end = buffer + buflen;
+       char *retval;
 
+       spin_lock(&vfsmount_lock);
        prepend(&end, &buflen, "\0", 1);
        if (!IS_ROOT(dentry) && d_unhashed(dentry) &&
                (prepend(&end, &buflen, " (deleted)", 10) != 0))
@@ -1800,38 +1806,37 @@ char *__d_path(const struct path *path, struct path *root,
                        break;
                if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
                        /* Global root? */
-                       spin_lock(&vfsmount_lock);
                        if (vfsmnt->mnt_parent == vfsmnt) {
-                               spin_unlock(&vfsmount_lock);
                                goto global_root;
                        }
                        dentry = vfsmnt->mnt_mountpoint;
                        vfsmnt = vfsmnt->mnt_parent;
-                       spin_unlock(&vfsmount_lock);
                        continue;
                }
                parent = dentry->d_parent;
                prefetch(parent);
-               if ((prepend(&end, &buflen, dentry->d_name.name,
-                               dentry->d_name.len) != 0) ||
+               if ((prepend_name(&end, &buflen, &dentry->d_name) != 0) ||
                    (prepend(&end, &buflen, "/", 1) != 0))
                        goto Elong;
                retval = end;
                dentry = parent;
        }
 
+out:
+       spin_unlock(&vfsmount_lock);
        return retval;
 
 global_root:
        retval += 1;    /* hit the slash */
-       if (prepend(&retval, &buflen, dentry->d_name.name,
-                   dentry->d_name.len) != 0)
+       if (prepend_name(&retval, &buflen, &dentry->d_name) != 0)
                goto Elong;
        root->mnt = vfsmnt;
        root->dentry = dentry;
-       return retval;
+       goto out;
+
 Elong:
-       return ERR_PTR(-ENAMETOOLONG);
+       retval = ERR_PTR(-ENAMETOOLONG);
+       goto out;
 }
 
 /**
@@ -1845,9 +1850,9 @@ Elong:
  *
  * Returns the buffer or an error code if the path was too long.
  *
- * "buflen" should be positive. Caller holds the dcache_lock.
+ * "buflen" should be positive.
  */
-char *d_path(struct path *path, char *buf, int buflen)
+char *d_path(const struct path *path, char *buf, int buflen)
 {
        char *res;
        struct path root;
@@ -1915,16 +1920,11 @@ char *dentry_path(struct dentry *dentry, char *buf, int buflen)
        retval = end-1;
        *retval = '/';
 
-       for (;;) {
-               struct dentry *parent;
-               if (IS_ROOT(dentry))
-                       break;
+       while (!IS_ROOT(dentry)) {
+               struct dentry *parent = dentry->d_parent;
 
-               parent = dentry->d_parent;
                prefetch(parent);
-
-               if ((prepend(&end, &buflen, dentry->d_name.name,
-                               dentry->d_name.len) != 0) ||
+               if ((prepend_name(&end, &buflen, &dentry->d_name) != 0) ||
                    (prepend(&end, &buflen, "/", 1) != 0))
                        goto Elong;
 
@@ -1975,7 +1975,7 @@ asmlinkage long sys_getcwd(char __user *buf, unsigned long size)
        error = -ENOENT;
        /* Has the current directory has been unlinked? */
        spin_lock(&dcache_lock);
-       if (pwd.dentry->d_parent == pwd.dentry || !d_unhashed(pwd.dentry)) {
+       if (IS_ROOT(pwd.dentry) || !d_unhashed(pwd.dentry)) {
                unsigned long len;
                struct path tmp = root;
                char * cwd;
index 50c994a249a5d7183d729564227a891fd4fb65a5..09a4522f65e6c26311bd896b515b20faf516a025 100644 (file)
@@ -575,13 +575,11 @@ int ecryptfs_init_ecryptfs_miscdev(void)
        int rc;
 
        atomic_set(&ecryptfs_num_miscdev_opens, 0);
-       mutex_lock(&ecryptfs_daemon_hash_mux);
        rc = misc_register(&ecryptfs_miscdev);
        if (rc)
                printk(KERN_ERR "%s: Failed to register miscellaneous device "
                       "for communications with userspace daemons; rc = [%d]\n",
                       __func__, rc);
-       mutex_unlock(&ecryptfs_daemon_hash_mux);
        return rc;
 }
 
index fe3119a71adacb65172cdc6be3c390f55e234679..2845425077e857c85ac7413a9613786d0dd0ac25 100644 (file)
@@ -2875,8 +2875,10 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
                blk++;
        }
 out:
-       if (len == towrite)
+       if (len == towrite) {
+               mutex_unlock(&inode->i_mutex);
                return err;
+       }
        if (inode->i_size < off+len-towrite) {
                i_size_write(inode, off+len-towrite);
                EXT3_I(inode)->i_disksize = inode->i_size;
index cb96f127c36684eab7ddff36e97a64b3d1be0d2c..02bf2434397981e223d62fbcb4cd73a03667049e 100644 (file)
@@ -3337,8 +3337,10 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
                blk++;
        }
 out:
-       if (len == towrite)
+       if (len == towrite) {
+               mutex_unlock(&inode->i_mutex);
                return err;
+       }
        if (inode->i_size < off+len-towrite) {
                i_size_write(inode, off+len-towrite);
                EXT4_I(inode)->i_disksize = inode->i_size;
index 892d41cb3382842a8c1a4b205f6a67fbd38c888b..baeb71ee1cde7a0c372c134e83bf43ef5b32c098 100644 (file)
@@ -512,6 +512,20 @@ void simple_release_fs(struct vfsmount **mount, int *count)
        mntput(mnt);
 }
 
+/**
+ * simple_read_from_buffer - copy data from the buffer to user space
+ * @to: the user space buffer to read to
+ * @count: the maximum number of bytes to read
+ * @ppos: the current position in the buffer
+ * @from: the buffer to read from
+ * @available: the size of the buffer
+ *
+ * The simple_read_from_buffer() function reads up to @count bytes from the
+ * buffer @from at offset @ppos into the user space address starting at @to.
+ *
+ * On success, the number of bytes read is returned and the offset @ppos is
+ * advanced by this number, or negative value is returned on error.
+ **/
 ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos,
                                const void *from, size_t available)
 {
@@ -528,6 +542,20 @@ ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos,
        return count;
 }
 
+/**
+ * memory_read_from_buffer - copy data from the buffer
+ * @to: the kernel space buffer to read to
+ * @count: the maximum number of bytes to read
+ * @ppos: the current position in the buffer
+ * @from: the buffer to read from
+ * @available: the size of the buffer
+ *
+ * The memory_read_from_buffer() function reads up to @count bytes from the
+ * buffer @from at offset @ppos into the kernel space address starting at @to.
+ *
+ * On success, the number of bytes read is returned and the offset @ppos is
+ * advanced by this number, or negative value is returned on error.
+ **/
 ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
                                const void *from, size_t available)
 {
index 11dbf08651b70861d31530ef73436dc2e3beffc1..dce8c747371c77e618ee387158c37451daf63c97 100644 (file)
@@ -561,9 +561,6 @@ static void locks_insert_lock(struct file_lock **pos, struct file_lock *fl)
        /* insert into file's list */
        fl->fl_next = *pos;
        *pos = fl;
-
-       if (fl->fl_ops && fl->fl_ops->fl_insert)
-               fl->fl_ops->fl_insert(fl);
 }
 
 /*
@@ -586,9 +583,6 @@ static void locks_delete_lock(struct file_lock **thisfl_p)
                fl->fl_fasync = NULL;
        }
 
-       if (fl->fl_ops && fl->fl_ops->fl_remove)
-               fl->fl_ops->fl_remove(fl);
-
        if (fl->fl_nspid) {
                put_pid(fl->fl_nspid);
                fl->fl_nspid = NULL;
index c7e43536c49ad06433c5963c446ce936e0f94e9f..01e67dddcc3d2033a2038c37f9f791ba0921a781 100644 (file)
@@ -581,15 +581,13 @@ static __always_inline int link_path_walk(const char *name, struct nameidata *nd
        int result;
 
        /* make sure the stuff we saved doesn't go away */
-       dget(save.dentry);
-       mntget(save.mnt);
+       path_get(&save);
 
        result = __link_path_walk(name, nd);
        if (result == -ESTALE) {
                /* nd->path had been dropped */
                nd->path = save;
-               dget(nd->path.dentry);
-               mntget(nd->path.mnt);
+               path_get(&nd->path);
                nd->flags |= LOOKUP_REVAL;
                result = __link_path_walk(name, nd);
        }
@@ -1216,8 +1214,9 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
        nd->flags = flags;
        nd->depth = 0;
 
-       nd->path.mnt = mntget(mnt);
-       nd->path.dentry = dget(dentry);
+       nd->path.dentry = dentry;
+       nd->path.mnt = mnt;
+       path_get(&nd->path);
 
        retval = path_walk(name, nd);
        if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry &&
@@ -2857,16 +2856,17 @@ int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
 {
        struct nameidata nd;
        void *cookie;
+       int res;
 
        nd.depth = 0;
        cookie = dentry->d_inode->i_op->follow_link(dentry, &nd);
-       if (!IS_ERR(cookie)) {
-               int res = vfs_readlink(dentry, buffer, buflen, nd_get_link(&nd));
-               if (dentry->d_inode->i_op->put_link)
-                       dentry->d_inode->i_op->put_link(dentry, &nd, cookie);
-               cookie = ERR_PTR(res);
-       }
-       return PTR_ERR(cookie);
+       if (IS_ERR(cookie))
+               return PTR_ERR(cookie);
+
+       res = vfs_readlink(dentry, buffer, buflen, nd_get_link(&nd));
+       if (dentry->d_inode->i_op->put_link)
+               dentry->d_inode->i_op->put_link(dentry, &nd, cookie);
+       return res;
 }
 
 int vfs_follow_link(struct nameidata *nd, const char *link)
index a1450086e92f87e64007351ab673bf6274037e70..a99ad09c3197a1f60e4332f86520183cffa50bbd 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -16,6 +16,7 @@
 #include <linux/namei.h>
 #include <linux/backing-dev.h>
 #include <linux/capability.h>
+#include <linux/securebits.h>
 #include <linux/security.h>
 #include <linux/mount.h>
 #include <linux/vfs.h>
@@ -425,7 +426,7 @@ asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode)
 {
        struct nameidata nd;
        int old_fsuid, old_fsgid;
-       kernel_cap_t old_cap;
+       kernel_cap_t uninitialized_var(old_cap);  /* !SECURE_NO_SETUID_FIXUP */
        int res;
 
        if (mode & ~S_IRWXO)    /* where's F_OK, X_OK, W_OK, R_OK? */
@@ -433,23 +434,27 @@ asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode)
 
        old_fsuid = current->fsuid;
        old_fsgid = current->fsgid;
-       old_cap = current->cap_effective;
 
        current->fsuid = current->uid;
        current->fsgid = current->gid;
 
-       /*
-        * Clear the capabilities if we switch to a non-root user
-        *
-        * FIXME: There is a race here against sys_capset.  The
-        * capabilities can change yet we will restore the old
-        * value below.  We should hold task_capabilities_lock,
-        * but we cannot because user_path_walk can sleep.
-        */
-       if (current->uid)
-               cap_clear(current->cap_effective);
-       else
-               current->cap_effective = current->cap_permitted;
+       if (!issecure(SECURE_NO_SETUID_FIXUP)) {
+               /*
+                * Clear the capabilities if we switch to a non-root user
+                */
+#ifndef CONFIG_SECURITY_FILE_CAPABILITIES
+               /*
+                * FIXME: There is a race here against sys_capset.  The
+                * capabilities can change yet we will restore the old
+                * value below.  We should hold task_capabilities_lock,
+                * but we cannot because user_path_walk can sleep.
+                */
+#endif /* ndef CONFIG_SECURITY_FILE_CAPABILITIES */
+               if (current->uid)
+                       old_cap = cap_set_effective(__cap_empty_set);
+               else
+                       old_cap = cap_set_effective(current->cap_permitted);
+       }
 
        res = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW|LOOKUP_ACCESS, &nd);
        if (res)
@@ -478,7 +483,9 @@ out_path_release:
 out:
        current->fsuid = old_fsuid;
        current->fsgid = old_fsgid;
-       current->cap_effective = old_cap;
+
+       if (!issecure(SECURE_NO_SETUID_FIXUP))
+               cap_set_effective(old_cap);
 
        return res;
 }
index ec228bc9f8824128ea99c5cb24abc743063e00bb..700f4e0d9572170a4de51527bc1698768a848afe 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1003,8 +1003,7 @@ struct file *create_write_pipe(void)
 void free_write_pipe(struct file *f)
 {
        free_pipe_info(f->f_dentry->d_inode);
-       dput(f->f_path.dentry);
-       mntput(f->f_path.mnt);
+       path_put(&f->f_path);
        put_filp(f);
 }
 
@@ -1015,8 +1014,8 @@ struct file *create_read_pipe(struct file *wrf)
                return ERR_PTR(-ENFILE);
 
        /* Grab pipe from the writer */
-       f->f_path.mnt = mntget(wrf->f_path.mnt);
-       f->f_path.dentry = dget(wrf->f_path.dentry);
+       f->f_path = wrf->f_path;
+       path_get(&wrf->f_path);
        f->f_mapping = wrf->f_path.dentry->d_inode->i_mapping;
 
        f->f_pos = 0;
@@ -1068,8 +1067,7 @@ int do_pipe(int *fd)
  err_fdr:
        put_unused_fd(fdr);
  err_read_pipe:
-       dput(fr->f_dentry);
-       mntput(fr->f_vfsmnt);
+       path_put(&fr->f_path);
        put_filp(fr);
  err_write_pipe:
        free_write_pipe(fw);
index ab8ccc9d14ff6df10abdd715076d870dafb32a85..c492449f3b45057cba171121e7e2b08b934adbfc 100644 (file)
@@ -476,10 +476,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
                return -ESRCH;
        mm = get_task_mm(task);
        if (mm) {
-               static struct mm_walk clear_refs_walk;
-               memset(&clear_refs_walk, 0, sizeof(clear_refs_walk));
-               clear_refs_walk.pmd_entry = clear_refs_pte_range;
-               clear_refs_walk.mm = mm;
+               struct mm_walk clear_refs_walk = {
+                       .pmd_entry = clear_refs_pte_range,
+                       .mm = mm,
+               };
                down_read(&mm->mmap_sem);
                for (vma = mm->mmap; vma; vma = vma->vm_next) {
                        clear_refs_walk.private = vma;
@@ -602,11 +602,6 @@ static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
        return err;
 }
 
-static struct mm_walk pagemap_walk = {
-       .pmd_entry = pagemap_pte_range,
-       .pte_hole = pagemap_pte_hole
-};
-
 /*
  * /proc/pid/pagemap - an array mapping virtual pages to pfns
  *
@@ -641,6 +636,11 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
        struct pagemapread pm;
        int pagecount;
        int ret = -ESRCH;
+       struct mm_walk pagemap_walk;
+       unsigned long src;
+       unsigned long svpfn;
+       unsigned long start_vaddr;
+       unsigned long end_vaddr;
 
        if (!task)
                goto out;
@@ -659,11 +659,15 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
        if (!mm)
                goto out_task;
 
-       ret = -ENOMEM;
+
        uaddr = (unsigned long)buf & PAGE_MASK;
        uend = (unsigned long)(buf + count);
        pagecount = (PAGE_ALIGN(uend) - uaddr) / PAGE_SIZE;
-       pages = kmalloc(pagecount * sizeof(struct page *), GFP_KERNEL);
+       ret = 0;
+       if (pagecount == 0)
+               goto out_mm;
+       pages = kcalloc(pagecount, sizeof(struct page *), GFP_KERNEL);
+       ret = -ENOMEM;
        if (!pages)
                goto out_mm;
 
@@ -684,33 +688,33 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
        pm.out = (u64 *)buf;
        pm.end = (u64 *)(buf + count);
 
-       if (!ptrace_may_attach(task)) {
-               ret = -EIO;
-       } else {
-               unsigned long src = *ppos;
-               unsigned long svpfn = src / PM_ENTRY_BYTES;
-               unsigned long start_vaddr = svpfn << PAGE_SHIFT;
-               unsigned long end_vaddr = TASK_SIZE_OF(task);
-
-               /* watch out for wraparound */
-               if (svpfn > TASK_SIZE_OF(task) >> PAGE_SHIFT)
-                       start_vaddr = end_vaddr;
-
-               /*
-                * The odds are that this will stop walking way
-                * before end_vaddr, because the length of the
-                * user buffer is tracked in "pm", and the walk
-                * will stop when we hit the end of the buffer.
-                */
-               ret = walk_page_range(start_vaddr, end_vaddr,
-                                       &pagemap_walk);
-               if (ret == PM_END_OF_BUFFER)
-                       ret = 0;
-               /* don't need mmap_sem for these, but this looks cleaner */
-               *ppos += (char *)pm.out - buf;
-               if (!ret)
-                       ret = (char *)pm.out - buf;
-       }
+       pagemap_walk.pmd_entry = pagemap_pte_range;
+       pagemap_walk.pte_hole = pagemap_pte_hole;
+       pagemap_walk.mm = mm;
+       pagemap_walk.private = &pm;
+
+       src = *ppos;
+       svpfn = src / PM_ENTRY_BYTES;
+       start_vaddr = svpfn << PAGE_SHIFT;
+       end_vaddr = TASK_SIZE_OF(task);
+
+       /* watch out for wraparound */
+       if (svpfn > TASK_SIZE_OF(task) >> PAGE_SHIFT)
+               start_vaddr = end_vaddr;
+
+       /*
+        * The odds are that this will stop walking way
+        * before end_vaddr, because the length of the
+        * user buffer is tracked in "pm", and the walk
+        * will stop when we hit the end of the buffer.
+        */
+       ret = walk_page_range(start_vaddr, end_vaddr, &pagemap_walk);
+       if (ret == PM_END_OF_BUFFER)
+               ret = 0;
+       /* don't need mmap_sem for these, but this looks cleaner */
+       *ppos += (char *)pm.out - buf;
+       if (!ret)
+               ret = (char *)pm.out - buf;
 
 out_pages:
        for (; pagecount; pagecount--) {
index ed424d708e6987777b4a2085f88d81df651c86a8..1d40f2bd197081284dce1ff34c6d1f828082304f 100644 (file)
@@ -2165,8 +2165,10 @@ static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
                blk++;
        }
 out:
-       if (len == towrite)
+       if (len == towrite) {
+               mutex_unlock(&inode->i_mutex);
                return err;
+       }
        if (inode->i_size < off + len - towrite)
                i_size_write(inode, off + len - towrite);
        inode->i_version++;
index 7a5f69be6ac2127de968661bd6d5e134712940b3..44cc702f96cc994919170bbee7621c841347b0ea 100644 (file)
@@ -682,38 +682,26 @@ static int udf_vrs(struct super_block *sb, int silent)
 /*
  * Check whether there is an anchor block in the given block
  */
-static int udf_check_anchor_block(struct super_block *sb, sector_t block,
-                                       bool varconv)
+static int udf_check_anchor_block(struct super_block *sb, sector_t block)
 {
-       struct buffer_head *bh = NULL;
-       tag *t;
+       struct buffer_head *bh;
        uint16_t ident;
-       uint32_t location;
 
-       if (varconv) {
-               if (udf_fixed_to_variable(block) >=
-                   sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits)
-                       return 0;
-               bh = sb_bread(sb, udf_fixed_to_variable(block));
-       }
-       else
-               bh = sb_bread(sb, block);
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
+           udf_fixed_to_variable(block) >=
+           sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits)
+               return 0;
 
+       bh = udf_read_tagged(sb, block, block, &ident);
        if (!bh)
                return 0;
-
-       t = (tag *)bh->b_data;
-       ident = le16_to_cpu(t->tagIdent);
-       location = le32_to_cpu(t->tagLocation);
        brelse(bh);
-       if (ident != TAG_IDENT_AVDP)
-               return 0;
-       return location == block;
+
+       return ident == TAG_IDENT_AVDP;
 }
 
 /* Search for an anchor volume descriptor pointer */
-static sector_t udf_scan_anchors(struct super_block *sb, bool varconv,
-                                       sector_t lastblock)
+static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock)
 {
        sector_t last[6];
        int i;
@@ -739,7 +727,7 @@ static sector_t udf_scan_anchors(struct super_block *sb, bool varconv,
                                sb->s_blocksize_bits)
                        continue;
 
-               if (udf_check_anchor_block(sb, last[i], varconv)) {
+               if (udf_check_anchor_block(sb, last[i])) {
                        sbi->s_anchor[0] = last[i];
                        sbi->s_anchor[1] = last[i] - 256;
                        return last[i];
@@ -748,17 +736,17 @@ static sector_t udf_scan_anchors(struct super_block *sb, bool varconv,
                if (last[i] < 256)
                        continue;
 
-               if (udf_check_anchor_block(sb, last[i] - 256, varconv)) {
+               if (udf_check_anchor_block(sb, last[i] - 256)) {
                        sbi->s_anchor[1] = last[i] - 256;
                        return last[i];
                }
        }
 
-       if (udf_check_anchor_block(sb, sbi->s_session + 256, varconv)) {
+       if (udf_check_anchor_block(sb, sbi->s_session + 256)) {
                sbi->s_anchor[0] = sbi->s_session + 256;
                return last[0];
        }
-       if (udf_check_anchor_block(sb, sbi->s_session + 512, varconv)) {
+       if (udf_check_anchor_block(sb, sbi->s_session + 512)) {
                sbi->s_anchor[0] = sbi->s_session + 512;
                return last[0];
        }
@@ -780,23 +768,24 @@ static void udf_find_anchor(struct super_block *sb)
        int i;
        struct udf_sb_info *sbi = UDF_SB(sb);
 
-       lastblock = udf_scan_anchors(sb, 0, sbi->s_last_block);
+       lastblock = udf_scan_anchors(sb, sbi->s_last_block);
        if (lastblock)
                goto check_anchor;
 
        /* No anchor found? Try VARCONV conversion of block numbers */
+       UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
        /* Firstly, we try to not convert number of the last block */
-       lastblock = udf_scan_anchors(sb, 1,
+       lastblock = udf_scan_anchors(sb,
                                udf_variable_to_fixed(sbi->s_last_block));
-       if (lastblock) {
-               UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
+       if (lastblock)
                goto check_anchor;
-       }
 
        /* Secondly, we try with converted number of the last block */
-       lastblock = udf_scan_anchors(sb, 1, sbi->s_last_block);
-       if (lastblock)
-               UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
+       lastblock = udf_scan_anchors(sb, sbi->s_last_block);
+       if (!lastblock) {
+               /* VARCONV didn't help. Clear it. */
+               UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV);
+       }
 
 check_anchor:
        /*
index af059d5cb485df8289eda123380f4937c0c7b77c..b6b664e7145ec7e0debea47c041b7c3faa9a0aee 100644 (file)
@@ -40,14 +40,9 @@ asmlinkage long sys_utime(char __user *filename, struct utimbuf __user *times)
 
 #endif
 
-static bool nsec_special(long nsec)
-{
-       return nsec == UTIME_OMIT || nsec == UTIME_NOW;
-}
-
 static bool nsec_valid(long nsec)
 {
-       if (nsec_special(nsec))
+       if (nsec == UTIME_OMIT || nsec == UTIME_NOW)
                return true;
 
        return nsec >= 0 && nsec <= 999999999;
@@ -102,7 +97,11 @@ long do_utimes(int dfd, char __user *filename, struct timespec *times, int flags
        if (error)
                goto dput_and_out;
 
-       /* Don't worry, the checks are done in inode_change_ok() */
+       if (times && times[0].tv_nsec == UTIME_NOW &&
+                    times[1].tv_nsec == UTIME_NOW)
+               times = NULL;
+
+       /* In most cases, the checks are done in inode_change_ok() */
        newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
        if (times) {
                error = -EPERM;
@@ -124,28 +123,34 @@ long do_utimes(int dfd, char __user *filename, struct timespec *times, int flags
                        newattrs.ia_mtime.tv_nsec = times[1].tv_nsec;
                        newattrs.ia_valid |= ATTR_MTIME_SET;
                }
-       }
 
-       /*
-        * If times is NULL or both times are either UTIME_OMIT or
-        * UTIME_NOW, then need to check permissions, because
-        * inode_change_ok() won't do it.
-        */
-       if (!times || (nsec_special(times[0].tv_nsec) &&
-                      nsec_special(times[1].tv_nsec))) {
+               /*
+                * For the UTIME_OMIT/UTIME_NOW and UTIME_NOW/UTIME_OMIT
+                * cases, we need to make an extra check that is not done by
+                * inode_change_ok().
+                */
+               if (((times[0].tv_nsec == UTIME_NOW &&
+                           times[1].tv_nsec == UTIME_OMIT)
+                    ||
+                    (times[0].tv_nsec == UTIME_OMIT &&
+                           times[1].tv_nsec == UTIME_NOW))
+                   && !is_owner_or_cap(inode))
+                       goto mnt_drop_write_and_out;
+       } else {
+
+               /*
+                * If times is NULL (or both times are UTIME_NOW),
+                * then we need to check permissions, because
+                * inode_change_ok() won't do it.
+                */
                error = -EACCES;
                 if (IS_IMMUTABLE(inode))
                        goto mnt_drop_write_and_out;
 
                if (!is_owner_or_cap(inode)) {
-                       if (f) {
-                               if (!(f->f_mode & FMODE_WRITE))
-                                       goto mnt_drop_write_and_out;
-                       } else {
-                               error = vfs_permission(&nd, MAY_WRITE);
-                               if (error)
-                                       goto mnt_drop_write_and_out;
-                       }
+                       error = permission(inode, MAY_WRITE, NULL);
+                       if (error)
+                               goto mnt_drop_write_and_out;
                }
        }
        mutex_lock(&inode->i_mutex);
@@ -169,14 +174,6 @@ asmlinkage long sys_utimensat(int dfd, char __user *filename, struct timespec __
        if (utimes) {
                if (copy_from_user(&tstimes, utimes, sizeof(tstimes)))
                        return -EFAULT;
-               if ((tstimes[0].tv_nsec == UTIME_OMIT ||
-                    tstimes[0].tv_nsec == UTIME_NOW) &&
-                   tstimes[0].tv_sec != 0)
-                       return -EINVAL;
-               if ((tstimes[1].tv_nsec == UTIME_OMIT ||
-                    tstimes[1].tv_nsec == UTIME_NOW) &&
-                   tstimes[1].tv_sec != 0)
-                       return -EINVAL;
 
                /* Nothing to do, we must not even check the path.  */
                if (tstimes[0].tv_nsec == UTIME_OMIT &&
index 92a6d91d0c1adb1d6974c0fb863917d77c396ed6..7cd25b8e7c9a4b891fcf00fd60b3985e5d48c59e 100644 (file)
@@ -1,6 +1,6 @@
 header-y  += kvm.h
 
-ifeq ($(wildcard include/asm-$(SRCARCH)/a.out.h),include/asm-$(SRCARCH)/a.out.h)
+ifneq ($(wildcard $(srctree)/include/asm-$(SRCARCH)/a.out.h),)
 unifdef-y += a.out.h
 endif
 unifdef-y += auxvec.h
index 85fd0aa27a8cd3f48a8ee9a9b47646316ddbed15..4ec0a296bdec8413394dbecedbf779bb19bfcf4b 100644 (file)
@@ -2,7 +2,7 @@
 #define _ASM_GENERIC_ATOMIC_H
 /*
  * Copyright (C) 2005 Silicon Graphics, Inc.
- *     Christoph Lameter <clameter@sgi.com>
+ *     Christoph Lameter
  *
  * Allows to provide arch independent atomic definitions without the need to
  * edit all arch specific atomic.h files.
index a798d6299a7927ee22d706e9a46c10f4ed9a73a0..1232be3885b01caa879576f3a9a1fd6dc91c8dbc 100644 (file)
@@ -283,10 +283,10 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
                "       beqz    %0, 2f                                  \n"
                "        subu   %0, %1, %3                              \n"
                "       .set    reorder                                 \n"
-               "1:                                                     \n"
                "       .subsection 2                                   \n"
                "2:     b       1b                                      \n"
                "       .previous                                       \n"
+               "1:                                                     \n"
                "       .set    mips0                                   \n"
                : "=&r" (result), "=&r" (temp), "=m" (v->counter)
                : "Ir" (i), "m" (v->counter)
@@ -664,10 +664,10 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
                "       beqz    %0, 2f                                  \n"
                "        dsubu  %0, %1, %3                              \n"
                "       .set    reorder                                 \n"
-               "1:                                                     \n"
                "       .subsection 2                                   \n"
                "2:     b       1b                                      \n"
                "       .previous                                       \n"
+               "1:                                                     \n"
                "       .set    mips0                                   \n"
                : "=&r" (result), "=&r" (temp), "=m" (v->counter)
                : "Ir" (i), "m" (v->counter)
index 7381916dfcbb298a8e1e6e66628b5b6c5a2de6fa..bca352e033c39ff78c2adf71c6f1038e3620eaaf 100644 (file)
@@ -1,6 +1,5 @@
 include include/asm-generic/Kbuild.asm
 
-header-y += a.out.h
 header-y += auxvec.h
 header-y += ioctls.h
 header-y += mman.h
index 3707650a169b5704a6ffedce7ce3226effc8a7f8..2b5f2c91db25ce8b3879c6673fa2514cee80b8ce 100644 (file)
@@ -18,7 +18,7 @@ static inline unsigned long long native_read_tscp(unsigned int *aux)
        unsigned long low, high;
        asm volatile(".byte 0x0f,0x01,0xf9"
                     : "=a" (low), "=d" (high), "=c" (*aux));
-       return low | ((u64)high >> 32);
+       return low | ((u64)high << 32);
 }
 
 /*
index b6fbb2573e8872a6496fdd1c75ee65a864a9395f..71d70d1fbce280585d575ba3f131847c0da19cd8 100644 (file)
@@ -166,7 +166,7 @@ unifdef-y += acct.h
 unifdef-y += adb.h
 unifdef-y += adfs_fs.h
 unifdef-y += agpgart.h
-ifeq ($(wildcard include/asm-$(SRCARCH)/a.out.h),include/asm-$(SRCARCH)/a.out.h)
+ifneq ($(wildcard $(srctree)/include/asm-$(SRCARCH)/a.out.h),)
 unifdef-y += a.out.h
 endif
 unifdef-y += apm_bios.h
index 63c3bb98558f6b3e2d07cd9040621273966c1eec..8b82974bdc125b561bf156a1dbfa58d3a51e3751 100644 (file)
@@ -571,7 +571,7 @@ extern void             audit_log_lost(const char *message);
 extern int                 audit_update_lsm_rules(void);
 
                                /* Private API (for audit.c only) */
-extern int audit_filter_user(struct netlink_skb_parms *cb, int type);
+extern int audit_filter_user(struct netlink_skb_parms *cb);
 extern int audit_filter_type(int type);
 extern int  audit_receive_filter(int type, int pid, int uid, int seq,
                                void *data, size_t datasz, uid_t loginuid,
index fa830f8de0328d6cea2e73c7f66352e9ab6f8871..02673846d20539b25949c3e10356ae09e9be762b 100644 (file)
@@ -501,6 +501,8 @@ extern const kernel_cap_t __cap_empty_set;
 extern const kernel_cap_t __cap_full_set;
 extern const kernel_cap_t __cap_init_eff_set;
 
+kernel_cap_t cap_set_effective(const kernel_cap_t pE_new);
+
 int capable(int cap);
 int __capable(struct task_struct *t, int cap);
 
index 1605dd8aa6463a3edef46cc6bb1ff7216bdb825c..6f9f19d665910e86a4732e2c581fee53b016cc96 100644 (file)
@@ -4,7 +4,7 @@
  * Description: cfag12864b LCD driver header
  *     License: GPLv2
  *
- *      Author: Copyright (C) Miguel Ojeda Sandonis <maxextreme@gmail.com>
+ *      Author: Copyright (C) Miguel Ojeda Sandonis
  *        Date: 2006-10-12
  *
  *  This program is free software; you can redistribute it and/or modify
index 5df3db58fcc65620fe5daf05752252c59048a21c..c24875bd9c5b0ef1b6347f61a87716c5e8673914 100644 (file)
@@ -353,6 +353,10 @@ static inline void __cpus_fold(cpumask_t *dstp, const cpumask_t *origp,
        for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
 #endif /* NR_CPUS */
 
+#define next_cpu_nr(n, src)            next_cpu(n, src)
+#define cpus_weight_nr(cpumask)                cpus_weight(cpumask)
+#define for_each_cpu_mask_nr(cpu, mask)        for_each_cpu_mask(cpu, mask)
+
 /*
  * The following particular system cpumasks and operations manage
  * possible, present and online cpus.  Each of them is a fixed size
index 2a6639407c8037581ce7baa58e95c8c936a26245..d982eb89c77d324a7875c1486ac421d7ecdfdae7 100644 (file)
@@ -300,7 +300,7 @@ extern int d_validate(struct dentry *, struct dentry *);
 extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
 
 extern char *__d_path(const struct path *path, struct path *root, char *, int);
-extern char *d_path(struct path *, char *, int);
+extern char *d_path(const struct path *, char *, int);
 extern char *dentry_path(struct dentry *, char *, int);
 
 /* Allocation counts.. */
index f4a5871767f534ef6b8a2a950c70372ef7c27ca7..4aaa4afb1cb99f849bb345a8189153e65e94cbcd 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __LINUX_DEBUG_LOCKING_H
 #define __LINUX_DEBUG_LOCKING_H
 
+#include <linux/kernel.h>
+
 struct task_struct;
 
 extern int debug_locks;
@@ -11,14 +13,6 @@ extern int debug_locks_silent;
  */
 extern int debug_locks_off(void);
 
-/*
- * In the debug case we carry the caller's instruction pointer into
- * other functions, but we dont want the function argument overhead
- * in the nondebug case - hence these macros:
- */
-#define _RET_IP_               (unsigned long)__builtin_return_address(0)
-#define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
-
 #define DEBUG_LOCKS_WARN_ON(c)                                         \
 ({                                                                     \
        int __ret = 0;                                                  \
index 4d10c7328d2dabafcee9cf285bf263ba6988b3cd..6c7eff2ebada88cf3bb5e543a5bd36da0f7237cd 100644 (file)
@@ -13,7 +13,7 @@ struct firmware {
 
 struct device;
 
-#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
+#if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE))
 int request_firmware(const struct firmware **fw, const char *name,
                     struct device *device);
 int request_firmware_nowait(
index d490779f18d946e52d443148cb8501649aad9030..d8e2762ed14df21bb05c50fde55158d6ec42bd5e 100644 (file)
@@ -83,6 +83,7 @@ extern int dir_notify_enable;
 #define READ_SYNC      (READ | (1 << BIO_RW_SYNC))
 #define READ_META      (READ | (1 << BIO_RW_META))
 #define WRITE_SYNC     (WRITE | (1 << BIO_RW_SYNC))
+#define SWRITE_SYNC    (SWRITE | (1 << BIO_RW_SYNC))
 #define WRITE_BARRIER  ((1 << BIO_RW) | (1 << BIO_RW_BARRIER))
 
 #define SEL_IN         1
@@ -894,8 +895,6 @@ static inline int file_check_writeable(struct file *filp)
 typedef struct files_struct *fl_owner_t;
 
 struct file_lock_operations {
-       void (*fl_insert)(struct file_lock *);  /* lock insertion callback */
-       void (*fl_remove)(struct file_lock *);  /* lock removal callback */
        void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
        void (*fl_release_private)(struct file_lock *);
 };
index fb9af6a0fe9cb0bf275c706129c4589d4ee8fb30..8dc7301321926f6f4a6e9454dcd50d9aa9d1722f 100644 (file)
@@ -171,7 +171,7 @@ struct i2c_client {
        struct i2c_adapter *adapter;    /* the adapter we sit on        */
        struct i2c_driver *driver;      /* and our access routines      */
        struct device dev;              /* the device structure         */
-       int irq;                        /* irq issued by device (or -1) */
+       int irq;                        /* irq issued by device         */
        struct list_head list;          /* DEPRECATED */
        struct completion released;
 };
index 80335b7d77c5bea2d9f64320c46fb19dfcb60cc2..c4335faebb63eba7eb9771dc8f937b1fa82103ac 100644 (file)
@@ -84,7 +84,11 @@ struct net_lro_mgr {
                                    from received packets and eth protocol
                                    is still ETH_P_8021Q */
 
-       u32 ip_summed;      /* Set in non generated SKBs in page mode */
+       /*
+        * Set for generated SKBs that are not added to
+        * the frag list in fragmented mode
+        */
+       u32 ip_summed;
        u32 ip_summed_aggr; /* Set in aggregated SKBs: CHECKSUM_UNNECESSARY
                             * or CHECKSUM_NONE */
 
index e075c4b762fb367e0a3ad07227c440cb7500629e..d150c57e5f0af8653fc2ab96d3b1e3c3a17ec5b5 100644 (file)
@@ -534,8 +534,8 @@ struct input_absinfo {
 
 #define KEY_FRAMEBACK          0x1b4   /* Consumer - transport controls */
 #define KEY_FRAMEFORWARD       0x1b5
-
 #define KEY_CONTEXT_MENU       0x1b6   /* GenDesc - system context menu */
+#define KEY_MEDIA_REPEAT       0x1b7   /* Consumer - transport control */
 
 #define KEY_DEL_EOL            0x1c0
 #define KEY_DEL_EOS            0x1c1
index 792bf0aa779b50d3e6aee9edaff9efe69569848f..2e70006c7fa8876d84e4d7f7c3a3803a721914e4 100644 (file)
@@ -46,6 +46,9 @@ extern const char linux_proc_banner[];
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
 
+#define _RET_IP_               (unsigned long)__builtin_return_address(0)
+#define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
+
 #ifdef CONFIG_LBD
 # include <asm/div64.h>
 # define sector_div(a, b) do_div(a, b)
index a2c54acceb4e9da1b21ab6e5dea9dc8c7e5fd362..cb311798e0bc642dc01eba7ebf9e73e997723b74 100644 (file)
@@ -4,7 +4,7 @@
  * Description: ks0108 LCD Controller driver header
  *     License: GPLv2
  *
- *      Author: Copyright (C) Miguel Ojeda Sandonis <maxextreme@gmail.com>
+ *      Author: Copyright (C) Miguel Ojeda Sandonis
  *        Date: 2006-10-31
  *
  *  This program is free software; you can redistribute it and/or modify
index f27fd2009334922325866c69d2abe42bb45bfd67..25f87102ab663e149e10043c9c399a8d8ca3bd96 100644 (file)
@@ -88,6 +88,8 @@ struct wireless_dev;
 #define NETDEV_TX_BUSY 1       /* driver tx path was busy*/
 #define NETDEV_TX_LOCKED -1    /* driver tx lock was already taken */
 
+#ifdef  __KERNEL__
+
 /*
  *     Compute the worst case header length according to the protocols
  *     used.
@@ -114,6 +116,8 @@ struct wireless_dev;
 #define MAX_HEADER (LL_MAX_HEADER + 48)
 #endif
 
+#endif  /*  __KERNEL__  */
+
 struct net_device_subqueue
 {
        /* Give a control state for each queue.  This struct may contain
index eafc9d6d2b35183dab63c8293ad8eba9b2c2111b..65953822c9cb752fb94d3fd0daa26f2c162544ae 100644 (file)
 #define PCI_DEVICE_ID_MARVELL_GT64260  0x6430
 #define PCI_DEVICE_ID_MARVELL_MV64360  0x6460
 #define PCI_DEVICE_ID_MARVELL_MV64460  0x6480
+#define PCI_DEVICE_ID_MARVELL_CAFE_SD  0x4101
 
 #define PCI_VENDOR_ID_V3               0x11b0
 #define PCI_DEVICE_ID_V3_V960          0x0001
index 78bfdea24a8ecd3f2465a031a7956fd8ba43f63a..e98900671ca91d7a4f76ae91ac7393f6613bd5ee 100644 (file)
@@ -221,6 +221,7 @@ struct bitmap {
        unsigned long syncchunk;
 
        __u64   events_cleared;
+       int need_sync;
 
        /* bitmap spinlock */
        spinlock_t lock;
index b7386ae9d288551b979a42a94ae59726563a035b..dc0e3fcb9f281b15bc9d0f040ce38a42191a4ea5 100644 (file)
@@ -95,7 +95,7 @@ extern int sync_page_io(struct block_device *bdev, sector_t sector, int size,
                        struct page *page, int rw);
 extern void md_do_sync(mddev_t *mddev);
 extern void md_new_event(mddev_t *mddev);
-extern void md_allow_write(mddev_t *mddev);
+extern int md_allow_write(mddev_t *mddev);
 extern void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev);
 
 #endif /* CONFIG_MD */
index 3dea9f545c8f337c516b1713a39e06f59ec767d3..df30c439587592eb380ca9cf5c207a27dddfc111 100644 (file)
@@ -87,6 +87,9 @@ struct mdk_rdev_s
 #define Blocked                8               /* An error occured on an externally
                                         * managed array, don't allow writes
                                         * until it is cleared */
+#define StateChanged   9               /* Faulty or Blocked has changed during
+                                        * interrupt, so it needs to be
+                                        * notified by the thread */
        wait_queue_head_t blocked_wait;
 
        int desc_nr;                    /* descriptor index in the superblock */
@@ -188,6 +191,7 @@ struct mddev_s
         * NEEDED:   we might need to start a resync/recover
         * RUNNING:  a thread is running, or about to be started
         * SYNC:     actually doing a resync, not a recovery
+        * RECOVER:  doing recovery, or need to try it.
         * INTR:     resync needs to be aborted for some reason
         * DONE:     thread is done and is waiting to be reaped
         * REQUEST:  user-space has requested a sync (used with SYNC)
@@ -198,6 +202,7 @@ struct mddev_s
         */
 #define        MD_RECOVERY_RUNNING     0
 #define        MD_RECOVERY_SYNC        1
+#define        MD_RECOVERY_RECOVER     2
 #define        MD_RECOVERY_INTR        3
 #define        MD_RECOVERY_DONE        4
 #define        MD_RECOVERY_NEEDED      5
@@ -227,6 +232,8 @@ struct mddev_s
        atomic_t                        recovery_active; /* blocks scheduled, but not written */
        wait_queue_head_t               recovery_wait;
        sector_t                        recovery_cp;
+       sector_t                        resync_min;     /* user requested sync
+                                                        * starts here */
        sector_t                        resync_max;     /* resync should pause
                                                         * when it gets here */
 
index f0827d31ae6fab718158499c10aaa50979527b17..3b2672792457ff08b991acb78e619f3daa3dab6e 100644 (file)
  *    the compute block completes.
  */
 
+/*
+ * Operations state - intermediate states that are visible outside of sh->lock
+ * In general _idle indicates nothing is running, _run indicates a data
+ * processing operation is active, and _result means the data processing result
+ * is stable and can be acted upon.  For simple operations like biofill and
+ * compute that only have an _idle and _run state they are indicated with
+ * sh->state flags (STRIPE_BIOFILL_RUN and STRIPE_COMPUTE_RUN)
+ */
+/**
+ * enum check_states - handles syncing / repairing a stripe
+ * @check_state_idle - check operations are quiesced
+ * @check_state_run - check operation is running
+ * @check_state_result - set outside lock when check result is valid
+ * @check_state_compute_run - check failed and we are repairing
+ * @check_state_compute_result - set outside lock when compute result is valid
+ */
+enum check_states {
+       check_state_idle = 0,
+       check_state_run, /* parity check */
+       check_state_check_result,
+       check_state_compute_run, /* parity repair */
+       check_state_compute_result,
+};
+
+/**
+ * enum reconstruct_states - handles writing or expanding a stripe
+ */
+enum reconstruct_states {
+       reconstruct_state_idle = 0,
+       reconstruct_state_prexor_drain_run,     /* prexor-write */
+       reconstruct_state_drain_run,            /* write */
+       reconstruct_state_run,                  /* expand */
+       reconstruct_state_prexor_drain_result,
+       reconstruct_state_drain_result,
+       reconstruct_state_result,
+};
+
 struct stripe_head {
        struct hlist_node       hash;
        struct list_head        lru;                    /* inactive_list or handle_list */
@@ -169,19 +206,13 @@ struct stripe_head {
        spinlock_t              lock;
        int                     bm_seq; /* sequence number for bitmap flushes */
        int                     disks;                  /* disks in stripe */
+       enum check_states       check_state;
+       enum reconstruct_states reconstruct_state;
        /* stripe_operations
-        * @pending - pending ops flags (set for request->issue->complete)
-        * @ack - submitted ops flags (set for issue->complete)
-        * @complete - completed ops flags (set for complete)
         * @target - STRIPE_OP_COMPUTE_BLK target
-        * @count - raid5_runs_ops is set to run when this is non-zero
         */
        struct stripe_operations {
-               unsigned long      pending;
-               unsigned long      ack;
-               unsigned long      complete;
                int                target;
-               int                count;
                u32                zero_sum_result;
        } ops;
        struct r5dev {
@@ -202,6 +233,7 @@ struct stripe_head_state {
        int locked, uptodate, to_read, to_write, failed, written;
        int to_fill, compute, req_compute, non_overwrite;
        int failed_num;
+       unsigned long ops_request;
 };
 
 /* r6_state - extra state data only relevant to r6 */
@@ -228,9 +260,7 @@ struct r6_state {
 #define        R5_Wantfill     12 /* dev->toread contains a bio that needs
                                    * filling
                                    */
-#define        R5_Wantprexor   13 /* distinguish blocks ready for rmw from
-                                   * other "towrites"
-                                   */
+#define R5_Wantdrain   13 /* dev->towrite needs to be drained */
 /*
  * Write method
  */
@@ -254,8 +284,10 @@ struct r6_state {
 #define        STRIPE_EXPAND_READY     11
 #define        STRIPE_IO_STARTED       12 /* do not count towards 'bypass_count' */
 #define        STRIPE_FULL_WRITE       13 /* all blocks are set to be overwritten */
+#define        STRIPE_BIOFILL_RUN      14
+#define        STRIPE_COMPUTE_RUN      15
 /*
- * Operations flags (in issue order)
+ * Operation request flags
  */
 #define STRIPE_OP_BIOFILL      0
 #define STRIPE_OP_COMPUTE_BLK  1
@@ -263,14 +295,6 @@ struct r6_state {
 #define STRIPE_OP_BIODRAIN     3
 #define STRIPE_OP_POSTXOR      4
 #define STRIPE_OP_CHECK        5
-#define STRIPE_OP_IO           6
-
-/* modifiers to the base operations
- * STRIPE_OP_MOD_REPAIR_PD - compute the parity block and write it back
- * STRIPE_OP_MOD_DMA_CHECK - parity is not corrupted by the check
- */
-#define STRIPE_OP_MOD_REPAIR_PD 7
-#define STRIPE_OP_MOD_DMA_CHECK 8
 
 /*
  * Plugging:
diff --git a/include/linux/rculist.h b/include/linux/rculist.h
new file mode 100644 (file)
index 0000000..bde4586
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef _LINUX_RCULIST_H
+#define _LINUX_RCULIST_H
+
+#include <linux/list.h>
+
+#endif /* _LINUX_RCULIST_H */
index c1f19dbceb0566f8a4e1342e4f4c1291d0f29349..92f09bdf11752dcbbe579f1e9f239dfb70036266 100644 (file)
@@ -7,14 +7,15 @@
    inheritance of root-permissions and suid-root executable under
    compatibility mode. We raise the effective and inheritable bitmasks
    *of the executable file* if the effective uid of the new process is
-   0. If the real uid is 0, we raise the inheritable bitmask of the
+   0. If the real uid is 0, we raise the effective (legacy) bit of the
    executable file. */
 #define SECURE_NOROOT                  0
 #define SECURE_NOROOT_LOCKED           1  /* make bit-0 immutable */
 
-/* When set, setuid to/from uid 0 does not trigger capability-"fixes"
-   to be compatible with old programs relying on set*uid to loose
-   privileges. When unset, setuid doesn't change privileges. */
+/* When set, setuid to/from uid 0 does not trigger capability-"fixup".
+   When unset, to provide compatiblility with old programs relying on
+   set*uid to gain/lose privilege, transitions to/from uid 0 cause
+   capabilities to be gained/lost. */
 #define SECURE_NO_SETUID_FIXUP         2
 #define SECURE_NO_SETUID_FIXUP_LOCKED  3  /* make bit-2 immutable */
 
 #define SECURE_KEEP_CAPS               4
 #define SECURE_KEEP_CAPS_LOCKED                5  /* make bit-4 immutable */
 
-/* Each securesetting is implemented using two bits. One bit specify
+/* Each securesetting is implemented using two bits. One bit specifies
    whether the setting is on or off. The other bit specify whether the
-   setting is fixed or not. A setting which is fixed cannot be changed
-   from user-level. */
+   setting is locked or not. A setting which is locked cannot be
+   changed from user-level. */
 #define issecure_mask(X)       (1 << (X))
 #define issecure(X)            (issecure_mask(X) & current->securebits)
 
index c2ad35016599ba11b6ce9b947963bc4975c23a21..9aa90a6f20e02e920e883f17e7393aa0e0046400 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Written by Mark Hemment, 1996 (markhe@nextd.demon.co.uk).
  *
- * (C) SGI 2006, Christoph Lameter <clameter@sgi.com>
+ * (C) SGI 2006, Christoph Lameter
  *     Cleaned up and restructured to ease the addition of alternative
  *     implementations of SLAB allocators.
  */
index 71e43a12ebbbc62521498155d6bace9b2b0e0585..d117ea2825a9187b44e37a12602b5538ec175839 100644 (file)
@@ -4,7 +4,7 @@
 /*
  * SLUB : A Slab allocator without object queues.
  *
- * (C) 2007 SGI, Christoph Lameter <clameter@sgi.com>
+ * (C) 2007 SGI, Christoph Lameter
  */
 #include <linux/types.h>
 #include <linux/gfp.h>
@@ -137,10 +137,12 @@ static __always_inline int kmalloc_index(size_t size)
        if (size <= KMALLOC_MIN_SIZE)
                return KMALLOC_SHIFT_LOW;
 
+#if KMALLOC_MIN_SIZE <= 64
        if (size > 64 && size <= 96)
                return 1;
        if (size > 128 && size <= 192)
                return 2;
+#endif
        if (size <=          8) return 3;
        if (size <=         16) return 4;
        if (size <=         32) return 5;
index 06d3e6eb9ca84ddb19b85e862ab51bafbaf0ce4b..917707e6151d7d2c5e4e5c3e6bd2b4310f86d971 100644 (file)
@@ -66,8 +66,7 @@ struct thermal_cooling_device {
                                ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
 #define CELSIUS_TO_KELVIN(t)   ((t)*10+2732)
 
-#if defined(CONFIG_HWMON) ||   \
-       (defined(CONFIG_HWMON_MODULE) && defined(CONFIG_THERMAL_MODULE))
+#if defined(CONFIG_THERMAL_HWMON)
 /* thermal zone devices with the same type share one hwmon device */
 struct thermal_hwmon_device {
        char type[THERMAL_NAME_LENGTH];
@@ -94,8 +93,7 @@ struct thermal_zone_device {
        struct idr idr;
        struct mutex lock;      /* protect cooling devices list */
        struct list_head node;
-#if defined(CONFIG_HWMON) ||   \
-       (defined(CONFIG_HWMON_MODULE) && defined(CONFIG_THERMAL_MODULE))
+#if defined(CONFIG_THERMAL_HWMON)
        struct list_head hwmon_node;
        struct thermal_hwmon_device *hwmon;
        struct thermal_hwmon_attr temp_input;   /* hwmon sys attr */
index cd599ad29fb2114b2b7e26ab46e613c8ea5ccff5..db431d513f2f01ce27cb9d150ed85f62f61d7195 100644 (file)
@@ -32,12 +32,16 @@ enum cx25840_video_input {
        CX25840_COMPOSITE7,
        CX25840_COMPOSITE8,
 
-       /* S-Video inputs consist of one luma input (In1-In4) ORed with one
+       /* S-Video inputs consist of one luma input (In1-In8) ORed with one
           chroma input (In5-In8) */
        CX25840_SVIDEO_LUMA1 = 0x10,
        CX25840_SVIDEO_LUMA2 = 0x20,
        CX25840_SVIDEO_LUMA3 = 0x30,
        CX25840_SVIDEO_LUMA4 = 0x40,
+       CX25840_SVIDEO_LUMA5 = 0x50,
+       CX25840_SVIDEO_LUMA6 = 0x60,
+       CX25840_SVIDEO_LUMA7 = 0x70,
+       CX25840_SVIDEO_LUMA8 = 0x80,
        CX25840_SVIDEO_CHROMA4 = 0x400,
        CX25840_SVIDEO_CHROMA5 = 0x500,
        CX25840_SVIDEO_CHROMA6 = 0x600,
index bfee8be5d63fb6b69765535a8384e928017b8b40..b8e8aa91905a4450bf3ff9c431e2ba7168092f1a 100644 (file)
@@ -146,6 +146,7 @@ extern IR_KEYTAB_TYPE ir_codes_behold_columbus[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_pinnacle_pctv_hd[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_genius_tvgo_a11mce[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_powercolor_real_angel[IR_KEYTAB_SIZE];
+extern IR_KEYTAB_TYPE ir_codes_avermedia_a16d[IR_KEYTAB_SIZE];
 
 #endif
 
index 33f01ae08f767da78c532c257332391bfb48b88c..859f7a6f6f67ab0c5073deb703c928de9f614d2f 100644 (file)
@@ -40,9 +40,9 @@
 #define VFL_TYPE_VTX           3
 
 /*  Video standard functions  */
-extern char *v4l2_norm_to_name(v4l2_std_id id);
+extern const char *v4l2_norm_to_name(v4l2_std_id id);
 extern int v4l2_video_std_construct(struct v4l2_standard *vs,
-                                   int id, char *name);
+                                   int id, const char *name);
 /* Prints the ioctl in a human-readable format */
 extern void v4l_printk_ioctl(unsigned int cmd);
 
index dae3f9ec11549b240ae07be19dc4f58a2389ce62..bcd1623245cbfc09e879776beceeafeeee229fdc 100644 (file)
@@ -595,6 +595,15 @@ enum ieee80211_key_alg {
        ALG_CCMP,
 };
 
+/**
+ * enum ieee80211_key_len - key length
+ * @WEP40: WEP 5 byte long key
+ * @WEP104: WEP 13 byte long key
+ */
+enum ieee80211_key_len {
+       LEN_WEP40 = 5,
+       LEN_WEP104 = 13,
+};
 
 /**
  * enum ieee80211_key_flags - key flags
index ab502ec1c61c3752b022b24ce49f833235b8621c..a87fc0312edc1a724560771980b06ac1a497daf3 100644 (file)
@@ -178,7 +178,7 @@ extern struct Qdisc *qdisc_alloc(struct net_device *dev, struct Qdisc_ops *ops);
 extern struct Qdisc *qdisc_create_dflt(struct net_device *dev,
                                       struct Qdisc_ops *ops, u32 parentid);
 extern void tcf_destroy(struct tcf_proto *tp);
-extern void tcf_destroy_chain(struct tcf_proto *fl);
+extern void tcf_destroy_chain(struct tcf_proto **fl);
 
 static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch,
                                       struct sk_buff_head *list)
index e8692a5748c24d2bd841ea7a81eaa09ae992bb04..e092f1c0ce3030916d9ad4c3af2b90fd64082f15 100644 (file)
@@ -738,7 +738,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
                if (!audit_enabled && msg_type != AUDIT_USER_AVC)
                        return 0;
 
-               err = audit_filter_user(&NETLINK_CB(skb), msg_type);
+               err = audit_filter_user(&NETLINK_CB(skb));
                if (err == 1) {
                        err = 0;
                        if (msg_type == AUDIT_USER_TTY) {
@@ -779,7 +779,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
                }
                /* fallthrough */
        case AUDIT_LIST:
-               err = audit_receive_filter(nlh->nlmsg_type, NETLINK_CB(skb).pid,
+               err = audit_receive_filter(msg_type, NETLINK_CB(skb).pid,
                                           uid, seq, data, nlmsg_len(nlh),
                                           loginuid, sessionid, sid);
                break;
@@ -798,7 +798,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
                }
                /* fallthrough */
        case AUDIT_LIST_RULES:
-               err = audit_receive_filter(nlh->nlmsg_type, NETLINK_CB(skb).pid,
+               err = audit_receive_filter(msg_type, NETLINK_CB(skb).pid,
                                           uid, seq, data, nlmsg_len(nlh),
                                           loginuid, sessionid, sid);
                break;
index 0e0bd27e65129ec94e087753ba398c42f92acc7e..98c50cc671bb85525f8534cc422bc692dbef5dc9 100644 (file)
@@ -1544,6 +1544,7 @@ static void audit_log_rule_change(uid_t loginuid, u32 sessionid, u32 sid,
  * @data: payload data
  * @datasz: size of payload data
  * @loginuid: loginuid of sender
+ * @sessionid: sessionid for netlink audit message
  * @sid: SE Linux Security ID of sender
  */
 int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
@@ -1720,7 +1721,7 @@ static int audit_filter_user_rules(struct netlink_skb_parms *cb,
        return 1;
 }
 
-int audit_filter_user(struct netlink_skb_parms *cb, int type)
+int audit_filter_user(struct netlink_skb_parms *cb)
 {
        enum audit_state state = AUDIT_DISABLED;
        struct audit_entry *e;
index cfbe44299488c18187d80acbe06d9e03c5dc8a83..901e0fdc3fffa3b32fca26e0aa4e1985b244bd10 100644 (file)
@@ -121,6 +121,27 @@ static int cap_validate_magic(cap_user_header_t header, unsigned *tocopy)
  * uninteresting and/or not to be changed.
  */
 
+/*
+ * Atomically modify the effective capabilities returning the original
+ * value. No permission check is performed here - it is assumed that the
+ * caller is permitted to set the desired effective capabilities.
+ */
+kernel_cap_t cap_set_effective(const kernel_cap_t pE_new)
+{
+       kernel_cap_t pE_old;
+
+       spin_lock(&task_capability_lock);
+
+       pE_old = current->cap_effective;
+       current->cap_effective = pE_new;
+
+       spin_unlock(&task_capability_lock);
+
+       return pE_old;
+}
+
+EXPORT_SYMBOL(cap_set_effective);
+
 /**
  * sys_capget - get the capabilities of a given process.
  * @header: pointer to struct that contains capability version and
index 421be5fe5cc78f5d2be0eabd3ba2367fe1b15b3e..ab80515008f4740fd980b1089d922811978ccff4 100644 (file)
@@ -1003,10 +1003,18 @@ hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
         */
        raise = timer->state == HRTIMER_STATE_PENDING;
 
+       /*
+        * We use preempt_disable to prevent this task from migrating after
+        * setting up the softirq and raising it. Otherwise, if me migrate
+        * we will raise the softirq on the wrong CPU.
+        */
+       preempt_disable();
+
        unlock_hrtimer_base(timer, &flags);
 
        if (raise)
                hrtimer_raise_softirq();
+       preempt_enable();
 
        return ret;
 }
index f4ffbd0f306f57c63afbe502c235df1b5e8548ed..a38895a5b8e2eeb1da28a829bebfe4a963c97561 100644 (file)
@@ -89,8 +89,22 @@ static void force_quiescent_state(struct rcu_data *rdp,
                /*
                 * Don't send IPI to itself. With irqs disabled,
                 * rdp->cpu is the current cpu.
+                *
+                * cpu_online_map is updated by the _cpu_down()
+                * using stop_machine_run(). Since we're in irqs disabled
+                * section, stop_machine_run() is not exectuting, hence
+                * the cpu_online_map is stable.
+                *
+                * However,  a cpu might have been offlined _just_ before
+                * we disabled irqs while entering here.
+                * And rcu subsystem might not yet have handled the CPU_DEAD
+                * notification, leading to the offlined cpu's bit
+                * being set in the rcp->cpumask.
+                *
+                * Hence cpumask = (rcp->cpumask & cpu_online_map) to prevent
+                * sending smp_reschedule() to an offlined CPU.
                 */
-               cpumask = rcp->cpumask;
+               cpus_and(cpumask, rcp->cpumask, cpu_online_map);
                cpu_clear(rdp->cpu, cpumask);
                for_each_cpu_mask(cpu, cpumask)
                        smp_send_reschedule(cpu);
index 3aaa5c8cb4214586bd283eedc2375baa3dc739c0..94ead43eda62bf8ebb9e054d9cad2a5838fe8f90 100644 (file)
@@ -5887,6 +5887,7 @@ static void migrate_dead_tasks(unsigned int dead_cpu)
                next = pick_next_task(rq, rq->curr);
                if (!next)
                        break;
+               next->sched_class->put_prev_task(rq, next);
                migrate_dead(dead_cpu, next);
 
        }
@@ -8501,6 +8502,9 @@ int sched_group_set_rt_period(struct task_group *tg, long rt_period_us)
        rt_period = (u64)rt_period_us * NSEC_PER_USEC;
        rt_runtime = tg->rt_bandwidth.rt_runtime;
 
+       if (rt_period == 0)
+               return -EINVAL;
+
        return tg_set_bandwidth(tg, rt_period, rt_runtime);
 }
 
index c828c2339cc9e8a8992df52f31756f8894c7f6b1..a272d78185eb5901449b0e8765f33a3f5723df28 100644 (file)
@@ -120,6 +120,7 @@ void softlockup_tick(void)
        printk(KERN_ERR "BUG: soft lockup - CPU#%d stuck for %lus! [%s:%d]\n",
                        this_cpu, now - touch_timestamp,
                        current->comm, task_pid_nr(current));
+       print_modules();
        if (regs)
                show_regs(regs);
        else
index 29fc39f1029cec92528b0cb66380028670b9eee1..ce7799540c91d28d3109e0e31fc53e623859ed1e 100644 (file)
@@ -13,7 +13,7 @@
  *   Kai Petzke <wpp@marie.physik.tu-berlin.de>
  *   Theodore Ts'o <tytso@mit.edu>
  *
- * Made to use alloc_percpu by Christoph Lameter <clameter@sgi.com>.
+ * Made to use alloc_percpu by Christoph Lameter.
  */
 
 #include <linux/module.h>
index 530f38f55787ec8703375c7706ae49fc7f529f7b..bfeafd60ee9fce4ba8e643c2beb5d8e66cff74e3 100644 (file)
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -37,6 +37,7 @@
  */
 #include <linux/list.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
 #include <linux/bug.h>
 #include <linux/sched.h>
 
@@ -149,6 +150,7 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
                               (void *)bugaddr);
 
                show_regs(regs);
+               add_taint(TAINT_WARN);
                return BUG_TRAP_TYPE_WARN;
        }
 
index a76a5e122ae134dabd283073c6404aac51501243..85b18d79be89acee07e25004eac991df799f0b8a 100644 (file)
@@ -68,6 +68,7 @@ static int fill_pool(void)
 {
        gfp_t gfp = GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN;
        struct debug_obj *new;
+       unsigned long flags;
 
        if (likely(obj_pool_free >= ODEBUG_POOL_MIN_LEVEL))
                return obj_pool_free;
@@ -81,10 +82,10 @@ static int fill_pool(void)
                if (!new)
                        return obj_pool_free;
 
-               spin_lock(&pool_lock);
+               spin_lock_irqsave(&pool_lock, flags);
                hlist_add_head(&new->node, &obj_pool);
                obj_pool_free++;
-               spin_unlock(&pool_lock);
+               spin_unlock_irqrestore(&pool_lock, flags);
        }
        return obj_pool_free;
 }
@@ -110,16 +111,13 @@ static struct debug_obj *lookup_object(void *addr, struct debug_bucket *b)
 }
 
 /*
- * Allocate a new object. If the pool is empty and no refill possible,
- * switch off the debugger.
+ * Allocate a new object. If the pool is empty, switch off the debugger.
  */
 static struct debug_obj *
 alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr)
 {
        struct debug_obj *obj = NULL;
-       int retry = 0;
 
-repeat:
        spin_lock(&pool_lock);
        if (obj_pool.first) {
                obj         = hlist_entry(obj_pool.first, typeof(*obj), node);
@@ -141,9 +139,6 @@ repeat:
        }
        spin_unlock(&pool_lock);
 
-       if (fill_pool() && !obj && !retry++)
-               goto repeat;
-
        return obj;
 }
 
@@ -261,6 +256,8 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
        struct debug_obj *obj;
        unsigned long flags;
 
+       fill_pool();
+
        db = get_bucket((unsigned long) addr);
 
        spin_lock_irqsave(&db->lock, flags);
index 169a2f8dabcc901f185faec5ff26da0d7194cdff..56ec21a7f73dc09fb64dc395ee4297b04907d649 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2001 Momchil Velikov
  * Portions Copyright (C) 2001 Christoph Hellwig
- * Copyright (C) 2005 SGI, Christoph Lameter <clameter@sgi.com>
+ * Copyright (C) 2005 SGI, Christoph Lameter
  * Copyright (C) 2006 Nick Piggin
  *
  * This program is free software; you can redistribute it and/or
index d90822c378a48af52878f41e5db18858496fddb9..4a7fce72898ed40f13d58bca7cc1d97293d8bba0 100644 (file)
@@ -63,7 +63,7 @@ static unsigned int bm_find(struct ts_config *conf, struct ts_state *state)
        struct ts_bm *bm = ts_config_priv(conf);
        unsigned int i, text_len, consumed = state->offset;
        const u8 *text;
-       int shift = bm->patlen, bs;
+       int shift = bm->patlen - 1, bs;
 
        for (;;) {
                text_len = conf->get_next_block(consumed, &text, conf, state);
index f4026bae6eedadb9e077e3500480fc47feb25624..05f2b4009cccd4c249ccfbd50aa8bc3237d4cb59 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * linux/mm/allocpercpu.c
  *
- * Separated from slab.c August 11, 2006 Christoph Lameter <clameter@sgi.com>
+ * Separated from slab.c August 11, 2006 Christoph Lameter
  */
 #include <linux/mm.h>
 #include <linux/module.h>
index d14b251a25a638dec1b5327a6261a67660ba67d5..2302d228fe04f3926f8c52bf65965623f1caff05 100644 (file)
@@ -1151,7 +1151,7 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
                         * be processed until returning to user space.
                         */
                        if (unlikely(test_tsk_thread_flag(tsk, TIF_MEMDIE)))
-                               return -ENOMEM;
+                               return i ? i : -ENOMEM;
 
                        if (write)
                                foll_flags |= FOLL_WRITE;
@@ -1697,8 +1697,19 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
        struct page *dirty_page = NULL;
 
        old_page = vm_normal_page(vma, address, orig_pte);
-       if (!old_page)
+       if (!old_page) {
+               /*
+                * VM_MIXEDMAP !pfn_valid() case
+                *
+                * We should not cow pages in a shared writeable mapping.
+                * Just mark the pages writable as we can't do any dirty
+                * accounting on raw pfn maps.
+                */
+               if ((vma->vm_flags & (VM_WRITE|VM_SHARED)) ==
+                                    (VM_WRITE|VM_SHARED))
+                       goto reuse;
                goto gotten;
+       }
 
        /*
         * Take out anonymous pages first, anonymous shared vmas are
@@ -1751,6 +1762,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
        }
 
        if (reuse) {
+reuse:
                flush_cache_page(vma, address, pte_pfn(orig_pte));
                entry = pte_mkyoung(orig_pte);
                entry = maybe_mkwrite(pte_mkdirty(entry), vma);
index a37a5034f63dda824f15b5ffb89156fea43fb4a3..c94e58b192c3c9913f4f4ab57860b6ac9469f839 100644 (file)
@@ -729,7 +729,11 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask,
        } else {
                *policy = pol == &default_policy ? MPOL_DEFAULT :
                                                pol->mode;
-               *policy |= pol->flags;
+               /*
+                * Internal mempolicy flags must be masked off before exposing
+                * the policy to userspace.
+                */
+               *policy |= (pol->flags & MPOL_MODE_FLAGS);
        }
 
        if (vma) {
index 112bcaeaa1046076af8618b7f06b2cfbc32faf8a..55bd355d170d055907c407f0c93d98dcb6e9e555 100644 (file)
@@ -9,7 +9,7 @@
  * IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
  * Hirokazu Takahashi <taka@valinux.co.jp>
  * Dave Hansen <haveblue@us.ibm.com>
- * Christoph Lameter <clameter@sgi.com>
+ * Christoph Lameter
  */
 
 #include <linux/migrate.h>
index 2f552955a02fbade92fb28c7e7338df46e8244e0..f32fae3121f07461f846911ee6963ce679828780 100644 (file)
@@ -2328,7 +2328,6 @@ static void build_zonelists(pg_data_t *pgdat)
 static void build_zonelist_cache(pg_data_t *pgdat)
 {
        pgdat->node_zonelists[0].zlcache_ptr = NULL;
-       pgdat->node_zonelists[1].zlcache_ptr = NULL;
 }
 
 #endif /* CONFIG_NUMA */
index 0987d1cd943cc88d626a7d1b1097ba1f83243591..1a427c0ae83be3d4ac58509680f38fba9948dc5d 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5,7 +5,7 @@
  * The allocator synchronizes using per slab locks and only
  * uses a centralized lock to manage a pool of partial slabs.
  *
- * (C) 2007 SGI, Christoph Lameter <clameter@sgi.com>
+ * (C) 2007 SGI, Christoph Lameter
  */
 
 #include <linux/mm.h>
@@ -2995,8 +2995,6 @@ void __init kmem_cache_init(void)
                create_kmalloc_cache(&kmalloc_caches[1],
                                "kmalloc-96", 96, GFP_KERNEL);
                caches++;
-       }
-       if (KMALLOC_MIN_SIZE <= 128) {
                create_kmalloc_cache(&kmalloc_caches[2],
                                "kmalloc-192", 192, GFP_KERNEL);
                caches++;
@@ -3026,6 +3024,16 @@ void __init kmem_cache_init(void)
        for (i = 8; i < KMALLOC_MIN_SIZE; i += 8)
                size_index[(i - 1) / 8] = KMALLOC_SHIFT_LOW;
 
+       if (KMALLOC_MIN_SIZE == 128) {
+               /*
+                * The 192 byte sized cache is not used if the alignment
+                * is 128 byte. Redirect kmalloc to use the 256 byte cache
+                * instead.
+                */
+               for (i = 128 + 8; i <= 192; i += 8)
+                       size_index[(i - 1) / 8] = 8;
+       }
+
        slab_state = UP;
 
        /* Provide the correct kmalloc names now that the caches are up */
index 99c4f36eb8a33def3c713937cecb9cc51256359a..a91b5f8fcaf61e6dc50bfe0526e5b488c3c967c7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Virtual Memory Map support
  *
- * (C) 2007 sgi. Christoph Lameter <clameter@sgi.com>.
+ * (C) 2007 sgi. Christoph Lameter.
  *
  * Virtual memory maps allow VM primitives pfn_to_page, page_to_pfn,
  * virt_to_page, page_address() to be implemented as a base offset
index c421a1f8f0b94cc23d8193d254fcf97d06ed6a1b..fca23a3bf12c1b5b14d6430ff07abbecbd749cc4 100644 (file)
@@ -454,7 +454,7 @@ static int netdev_boot_setup_add(char *name, struct ifmap *map)
        for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
                if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
                        memset(s[i].name, 0, sizeof(s[i].name));
-                       strcpy(s[i].name, name);
+                       strlcpy(s[i].name, name, IFNAMSIZ);
                        memcpy(&s[i].map, map, sizeof(s[i].map));
                        break;
                }
@@ -479,7 +479,7 @@ int netdev_boot_setup_check(struct net_device *dev)
 
        for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
                if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
-                   !strncmp(dev->name, s[i].name, strlen(s[i].name))) {
+                   !strcmp(dev->name, s[i].name)) {
                        dev->irq        = s[i].map.irq;
                        dev->base_addr  = s[i].map.base_addr;
                        dev->mem_start  = s[i].map.mem_start;
@@ -2973,7 +2973,7 @@ EXPORT_SYMBOL(dev_unicast_delete);
 /**
  *     dev_unicast_add         - add a secondary unicast address
  *     @dev: device
- *     @addr: address to delete
+ *     @addr: address to add
  *     @alen: length of @addr
  *
  *     Add a secondary unicast address to the device or increase
index e3e9ab0f74e33caf9e0df3a8d0829359f86eefe7..277a2302eb3abb666574a5b3b7dc2714f45ef7c4 100644 (file)
@@ -226,7 +226,7 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
 
        ops = lookup_rules_ops(net, frh->family);
        if (ops == NULL) {
-               err = EAFNOSUPPORT;
+               err = -EAFNOSUPPORT;
                goto errout;
        }
 
@@ -365,7 +365,7 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
 
        ops = lookup_rules_ops(net, frh->family);
        if (ops == NULL) {
-               err = EAFNOSUPPORT;
+               err = -EAFNOSUPPORT;
                goto errout;
        }
 
index 4f8369729a4e8d15347a00cfeac2b56aea40b112..df37443558395a01780f725e744a920fb1664872 100644 (file)
@@ -68,7 +68,6 @@ static inline void *load_pointer(struct sk_buff *skb, int k,
  *     sk_filter - run a packet through a socket filter
  *     @sk: sock associated with &sk_buff
  *     @skb: buffer to filter
- *     @needlock: set to 1 if the sock is not locked by caller.
  *
  * Run the filter code and then cut skb->data to correct size returned by
  * sk_run_filter. If pkt_len is 0 we toss packet. If skb->len is smaller
index 1e556d31211742d41acb39cbc2c1cd8460e2d3b0..366621610e76d5a91ae72522d38d0b60e3df45d9 100644 (file)
@@ -1292,12 +1292,14 @@ static int __skb_splice_bits(struct sk_buff *skb, unsigned int *offset,
 {
        unsigned int nr_pages = spd->nr_pages;
        unsigned int poff, plen, len, toff, tlen;
-       int headlen, seg;
+       int headlen, seg, error = 0;
 
        toff = *offset;
        tlen = *total_len;
-       if (!tlen)
+       if (!tlen) {
+               error = 1;
                goto err;
+       }
 
        /*
         * if the offset is greater than the linear part, go directly to
@@ -1339,7 +1341,8 @@ static int __skb_splice_bits(struct sk_buff *skb, unsigned int *offset,
                 * just jump directly to update and return, no point
                 * in going over fragments when the output is full.
                 */
-               if (spd_fill_page(spd, virt_to_page(p), plen, poff, skb))
+               error = spd_fill_page(spd, virt_to_page(p), plen, poff, skb);
+               if (error)
                        goto done;
 
                tlen -= plen;
@@ -1369,7 +1372,8 @@ map_frag:
                if (!plen)
                        break;
 
-               if (spd_fill_page(spd, f->page, plen, poff, skb))
+               error = spd_fill_page(spd, f->page, plen, poff, skb);
+               if (error)
                        break;
 
                tlen -= plen;
@@ -1382,7 +1386,10 @@ done:
                return 0;
        }
 err:
-       return 1;
+       /* update the offset to reflect the linear part skip, if any */
+       if (!error)
+               *offset = toff;
+       return error;
 }
 
 /*
index 4ed429bd5951542401130f16e3a4f0341ded3920..0546a0bc97ea37bdc1b9bef0c22d6b82ec190abf 100644 (file)
@@ -192,14 +192,21 @@ EXPORT_SYMBOL(inet_frag_evictor);
 
 static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
                struct inet_frag_queue *qp_in, struct inet_frags *f,
-               unsigned int hash, void *arg)
+               void *arg)
 {
        struct inet_frag_queue *qp;
 #ifdef CONFIG_SMP
        struct hlist_node *n;
 #endif
+       unsigned int hash;
 
        write_lock(&f->lock);
+       /*
+        * While we stayed w/o the lock other CPU could update
+        * the rnd seed, so we need to re-calculate the hash
+        * chain. Fortunatelly the qp_in can be used to get one.
+        */
+       hash = f->hashfn(qp_in);
 #ifdef CONFIG_SMP
        /* With SMP race we have to recheck hash table, because
         * such entry could be created on other cpu, while we
@@ -247,7 +254,7 @@ static struct inet_frag_queue *inet_frag_alloc(struct netns_frags *nf,
 }
 
 static struct inet_frag_queue *inet_frag_create(struct netns_frags *nf,
-               struct inet_frags *f, void *arg, unsigned int hash)
+               struct inet_frags *f, void *arg)
 {
        struct inet_frag_queue *q;
 
@@ -255,7 +262,7 @@ static struct inet_frag_queue *inet_frag_create(struct netns_frags *nf,
        if (q == NULL)
                return NULL;
 
-       return inet_frag_intern(nf, q, f, hash, arg);
+       return inet_frag_intern(nf, q, f, arg);
 }
 
 struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
@@ -264,7 +271,6 @@ struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
        struct inet_frag_queue *q;
        struct hlist_node *n;
 
-       read_lock(&f->lock);
        hlist_for_each_entry(q, n, &f->hash[hash], list) {
                if (q->net == nf && f->match(q, key)) {
                        atomic_inc(&q->refcnt);
@@ -274,6 +280,6 @@ struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
        }
        read_unlock(&f->lock);
 
-       return inet_frag_create(nf, f, key, hash);
+       return inet_frag_create(nf, f, key);
 }
 EXPORT_SYMBOL(inet_frag_find);
index 4a4d49fca1f2518a12eebbfbae02211eace06a19..cfd034a2b96ed7926f5139aeb161a58ba1820b2f 100644 (file)
@@ -383,8 +383,7 @@ static int __lro_proc_skb(struct net_lro_mgr *lro_mgr, struct sk_buff *skb,
 out2: /* send aggregated SKBs to stack */
        lro_flush(lro_mgr, lro_desc);
 
-out:  /* Original SKB has to be posted to stack */
-       skb->ip_summed = lro_mgr->ip_summed;
+out:
        return 1;
 }
 
index cd6ce6ac635843e4598e5332c32256bb0ff93926..37221f65915960a8a5173b4862fcace1591fdec9 100644 (file)
@@ -229,6 +229,8 @@ static inline struct ipq *ip_find(struct net *net, struct iphdr *iph, u32 user)
 
        arg.iph = iph;
        arg.user = user;
+
+       read_lock(&ip4_frags.lock);
        hash = ipqhashfn(iph->id, iph->saddr, iph->daddr, iph->protocol);
 
        q = inet_frag_find(&net->ipv4.frags, &ip4_frags, &arg, hash);
index fc54a48fde1e6a6b07a157b1cc551427d226099b..850825dc86e6dc55ea72ce8b669c4bf16f3ee876 100644 (file)
 #include <linux/socket.h>
 #include <linux/random.h>
 #include <linux/bootmem.h>
+#include <linux/highmem.h>
+#include <linux/swap.h>
 #include <linux/cache.h>
 #include <linux/err.h>
 #include <linux/crypto.h>
@@ -2620,7 +2622,7 @@ __setup("thash_entries=", set_thash_entries);
 void __init tcp_init(void)
 {
        struct sk_buff *skb = NULL;
-       unsigned long limit;
+       unsigned long nr_pages, limit;
        int order, i, max_share;
 
        BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb));
@@ -2689,8 +2691,9 @@ void __init tcp_init(void)
         * is up to 1/2 at 256 MB, decreasing toward zero with the amount of
         * memory, with a floor of 128 pages.
         */
-       limit = min(nr_all_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT);
-       limit = (limit * (nr_all_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11);
+       nr_pages = totalram_pages - totalhigh_pages;
+       limit = min(nr_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT);
+       limit = (limit * (nr_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11);
        limit = max(limit, 128UL);
        sysctl_tcp_mem[0] = limit / 4 * 3;
        sysctl_tcp_mem[1] = limit;
index 12695be2c255a2ac4baeb5aa049dd16f41fb7bf9..ffe869ac1bcf15b51abd801b3b3b4533da0b530e 100644 (file)
@@ -2291,7 +2291,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
        }
 
        seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
-                       "%08X %5d %8d %lu %d %p %u %u %u %u %d%n",
+                       "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
                i, src, srcp, dest, destp, sk->sk_state,
                tp->write_seq - tp->snd_una,
                sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
@@ -2303,8 +2303,8 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
                icsk->icsk_probes_out,
                sock_i_ino(sk),
                atomic_read(&sk->sk_refcnt), sk,
-               icsk->icsk_rto,
-               icsk->icsk_ack.ato,
+               jiffies_to_clock_t(icsk->icsk_rto),
+               jiffies_to_clock_t(icsk->icsk_ack.ato),
                (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
                tp->snd_cwnd,
                tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh,
index 27a5e8b48d93a27fababd4d79fb998903d039422..f405cea21a8b89687558c83deb094d7c1940631e 100644 (file)
@@ -129,7 +129,7 @@ static struct nf_hook_ops ip6t_ops[] __read_mostly = {
                .priority       = NF_IP6_PRI_MANGLE,
        },
        {
-               .hook           = ip6t_local_hook,
+               .hook           = ip6t_route_hook,
                .owner          = THIS_MODULE,
                .pf             = PF_INET6,
                .hooknum        = NF_INET_LOCAL_IN,
index e65e26e210ee3a66873f6d472fdca708559fb0a2..cf20bc4fd60db346eab94b35ec3b84ee255dd265 100644 (file)
@@ -207,9 +207,10 @@ fq_find(__be32 id, struct in6_addr *src, struct in6_addr *dst)
        arg.id = id;
        arg.src = src;
        arg.dst = dst;
+
+       read_lock_bh(&nf_frags.lock);
        hash = ip6qhashfn(id, src, dst);
 
-       local_bh_disable();
        q = inet_frag_find(&nf_init_frags, &nf_frags, &arg, hash);
        local_bh_enable();
        if (q == NULL)
index 798cabc7535b747d9193ce20e1dce1907e18eb8f..a60d7d1297137880de4294999966f3cb487ec16c 100644 (file)
@@ -247,6 +247,8 @@ fq_find(struct net *net, __be32 id, struct in6_addr *src, struct in6_addr *dst,
        arg.id = id;
        arg.src = src;
        arg.dst = dst;
+
+       read_lock(&ip6_frags.lock);
        hash = ip6qhashfn(id, src, dst);
 
        q = inet_frag_find(&net->ipv6.frags, &ip6_frags, &arg, hash);
index d1f3e19b06c79ade99a6b34eb385ee15753c6c77..7ff687020fa9ee780042ddeeb080e3ebb20f8199 100644 (file)
@@ -240,7 +240,7 @@ static inline int rt6_need_strict(struct in6_addr *daddr)
 static inline struct rt6_info *rt6_device_match(struct net *net,
                                                    struct rt6_info *rt,
                                                    int oif,
-                                                   int strict)
+                                                   int flags)
 {
        struct rt6_info *local = NULL;
        struct rt6_info *sprt;
@@ -253,7 +253,7 @@ static inline struct rt6_info *rt6_device_match(struct net *net,
                        if (dev->flags & IFF_LOOPBACK) {
                                if (sprt->rt6i_idev == NULL ||
                                    sprt->rt6i_idev->dev->ifindex != oif) {
-                                       if (strict && oif)
+                                       if (flags & RT6_LOOKUP_F_IFACE && oif)
                                                continue;
                                        if (local && (!oif ||
                                                      local->rt6i_idev->dev->ifindex == oif))
@@ -266,7 +266,7 @@ static inline struct rt6_info *rt6_device_match(struct net *net,
                if (local)
                        return local;
 
-               if (strict)
+               if (flags & RT6_LOOKUP_F_IFACE)
                        return net->ipv6.ip6_null_entry;
        }
        return rt;
index cb46749d4c326a3e7133537b70ed3cccce82eb9d..40ea9c36d24bff0426a807a9f200b0de08362c39 100644 (file)
@@ -2036,7 +2036,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
 
        seq_printf(seq,
                   "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
-                  "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %u %u %u %u %d\n",
+                  "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %lu %lu %u %u %d\n",
                   i,
                   src->s6_addr32[0], src->s6_addr32[1],
                   src->s6_addr32[2], src->s6_addr32[3], srcp,
@@ -2052,8 +2052,8 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
                   icsk->icsk_probes_out,
                   sock_i_ino(sp),
                   atomic_read(&sp->sk_refcnt), sp,
-                  icsk->icsk_rto,
-                  icsk->icsk_ack.ato,
+                  jiffies_to_clock_t(icsk->icsk_rto),
+                  jiffies_to_clock_t(icsk->icsk_ack.ato),
                   (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
                   tp->snd_cwnd, tp->snd_ssthresh>=0xFFFF?-1:tp->snd_ssthresh
                   );
index 150d66dbda9d22de6ca0b94c48eab7e70c3f733f..220e83be3ef4a3dad7331f451bb95021d7c04701 100644 (file)
@@ -380,6 +380,15 @@ void ieee80211_key_free(struct ieee80211_key *key)
        if (!key)
                return;
 
+       if (!key->sdata) {
+               /* The key has not been linked yet, simply free it
+                * and don't Oops */
+               if (key->conf.alg == ALG_CCMP)
+                       ieee80211_aes_key_free(key->u.ccmp.tfm);
+               kfree(key);
+               return;
+       }
+
        spin_lock_irqsave(&key->sdata->local->key_lock, flags);
        __ieee80211_key_free(key);
        spin_unlock_irqrestore(&key->sdata->local->key_lock, flags);
index 6106cb79060c928f65e7d5a5d2154f280b55bf5f..e8404212ad57ecdfda2df597a9725c73278627b4 100644 (file)
@@ -95,6 +95,13 @@ static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
                        }
                }
 
+               if (alg == ALG_WEP &&
+                       key_len != LEN_WEP40 && key_len != LEN_WEP104) {
+                       ieee80211_key_free(key);
+                       err = -EINVAL;
+                       goto out_unlock;
+               }
+
                ieee80211_key_link(key, sdata, sta);
 
                if (set_tx_key || (!sta && !sdata->default_key && key))
index 635b996c8c350c52c5f9cef6747c3408e3e40711..5d09e8698b57584cb66bbc83e96295955c68c360 100644 (file)
@@ -323,8 +323,7 @@ static void wme_qdiscop_destroy(struct Qdisc* qd)
        struct ieee80211_hw *hw = &local->hw;
        int queue;
 
-       tcf_destroy_chain(q->filter_list);
-       q->filter_list = NULL;
+       tcf_destroy_chain(&q->filter_list);
 
        for (queue=0; queue < hw->queues; queue++) {
                skb_queue_purge(&q->requeued[queue]);
index ba94004fe323182b6a527507548a1e54e1099321..271cd01d57aed49192d94dc7a98a066d884a9a7b 100644 (file)
@@ -331,12 +331,13 @@ static unsigned int get_conntrack_index(const struct tcphdr *tcph)
 
    I.   Upper bound for valid data:    seq <= sender.td_maxend
    II.  Lower bound for valid data:    seq + len >= sender.td_end - receiver.td_maxwin
-   III.        Upper bound for valid ack:      sack <= receiver.td_end
-   IV. Lower bound for valid ack:      ack >= receiver.td_end - MAXACKWINDOW
+   III.        Upper bound for valid (s)ack:   sack <= receiver.td_end
+   IV. Lower bound for valid (s)ack:   sack >= receiver.td_end - MAXACKWINDOW
 
-   where sack is the highest right edge of sack block found in the packet.
+   where sack is the highest right edge of sack block found in the packet
+   or ack in the case of packet without SACK option.
 
-   The upper bound limit for a valid ack is not ignored -
+   The upper bound limit for a valid (s)ack is not ignored -
    we doesn't have to deal with fragments.
 */
 
@@ -606,12 +607,12 @@ static bool tcp_in_window(const struct nf_conn *ct,
                 before(seq, sender->td_maxend + 1),
                 after(end, sender->td_end - receiver->td_maxwin - 1),
                 before(sack, receiver->td_end + 1),
-                after(ack, receiver->td_end - MAXACKWINDOW(sender)));
+                after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1));
 
        if (before(seq, sender->td_maxend + 1) &&
            after(end, sender->td_end - receiver->td_maxwin - 1) &&
            before(sack, receiver->td_end + 1) &&
-           after(ack, receiver->td_end - MAXACKWINDOW(sender))) {
+           after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)) {
                /*
                 * Take into account window scaling (RFC 1323).
                 */
index 0099da5b2591e5295429b7578688fa6949db3db1..52b2611a6eb6625f8d1d329bea03d03e7ad460ac 100644 (file)
@@ -1534,7 +1534,7 @@ static int netlbl_unlabel_staticlistdef(struct sk_buff *skb,
                }
        }
        list_for_each_entry_rcu(addr6, &iface->addr6_list, list) {
-               if (addr6->valid || iter_addr6++ < skip_addr6)
+               if (!addr6->valid || iter_addr6++ < skip_addr6)
                        continue;
                if (netlbl_unlabel_staticlist_gen(NLBL_UNLABEL_C_STATICLISTDEF,
                                           iface,
index 9b97f8006c9c6edfd0dea0dde522b6a7e64c171f..349aba189558669c9ddd8ac82ad585d1fb23d557 100644 (file)
@@ -886,7 +886,7 @@ retry:
                return netlink_unicast_kernel(sk, skb);
 
        if (sk_filter(sk, skb)) {
-               int err = skb->len;
+               err = skb->len;
                kfree_skb(skb);
                sock_put(sk);
                return err;
index 47bbf45ae5d7905e05487955d77832e03915f215..2d106cfe1d276bf5e234195753eb091cba7b7f1e 100644 (file)
@@ -132,6 +132,7 @@ errout:
  * @maxtype: maximum attribute type to be expected
  * @head: head of attribute stream
  * @len: length of attribute stream
+ * @policy: validation policy
  *
  * Parses a stream of attributes and stores a pointer to each attribute in
  * the tb array accessable via the attribute type. Attributes with a type
@@ -194,7 +195,7 @@ struct nlattr *nla_find(struct nlattr *head, int len, int attrtype)
 /**
  * nla_strlcpy - Copy string attribute payload into a sized buffer
  * @dst: where to copy the string to
- * @src: attribute to copy the string from
+ * @nla: attribute to copy the string from
  * @dstsize: size of destination buffer
  *
  * Copies at most dstsize - 1 bytes into the destination buffer.
@@ -340,9 +341,9 @@ struct nlattr *nla_reserve(struct sk_buff *skb, int attrtype, int attrlen)
 }
 
 /**
- * nla_reserve - reserve room for attribute without header
+ * nla_reserve_nohdr - reserve room for attribute without header
  * @skb: socket buffer to reserve room on
- * @len: length of attribute payload
+ * @attrlen: length of attribute payload
  *
  * Reserves room for attribute payload without a header.
  *
index 82adfe6447d7db004c7108731e0ad4c7b87f8657..9437b27ff84de101b88b3cbe08675f002e562238 100644 (file)
@@ -106,17 +106,6 @@ config NET_SCH_PRIO
          To compile this code as a module, choose M here: the
          module will be called sch_prio.
 
-config NET_SCH_RR
-       tristate "Multi Band Round Robin Queuing (RR)"
-       select NET_SCH_PRIO
-       ---help---
-         Say Y here if you want to use an n-band round robin packet
-         scheduler.
-
-         The module uses sch_prio for its framework and is aliased as
-         sch_rr, so it will load sch_prio, although it is referred
-         to using sch_rr.
-
 config NET_SCH_RED
        tristate "Random Early Detection (RED)"
        ---help---
index c40773cdbe45466c8bead7bfd58c0fde73fc6c76..10f01ad043800589f9d2eebd994c7f8de86ce19b 100644 (file)
@@ -1252,12 +1252,12 @@ void tcf_destroy(struct tcf_proto *tp)
        kfree(tp);
 }
 
-void tcf_destroy_chain(struct tcf_proto *fl)
+void tcf_destroy_chain(struct tcf_proto **fl)
 {
        struct tcf_proto *tp;
 
-       while ((tp = fl) != NULL) {
-               fl = tp->next;
+       while ((tp = *fl) != NULL) {
+               *fl = tp->next;
                tcf_destroy(tp);
        }
 }
index 33527341638427c3bf9e97385a7f7d5ba37f07d8..db0e23ae85f8fb048c81e654ecbe8524fbf08f43 100644 (file)
@@ -160,7 +160,7 @@ static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
        *prev = flow->next;
        pr_debug("atm_tc_put: qdisc %p\n", flow->q);
        qdisc_destroy(flow->q);
-       tcf_destroy_chain(flow->filter_list);
+       tcf_destroy_chain(&flow->filter_list);
        if (flow->sock) {
                pr_debug("atm_tc_put: f_count %d\n",
                        file_count(flow->sock->file));
@@ -586,10 +586,11 @@ static void atm_tc_destroy(struct Qdisc *sch)
        struct atm_flow_data *flow;
 
        pr_debug("atm_tc_destroy(sch %p,[qdisc %p])\n", sch, p);
+       for (flow = p->flows; flow; flow = flow->next)
+               tcf_destroy_chain(&flow->filter_list);
+
        /* races ? */
        while ((flow = p->flows)) {
-               tcf_destroy_chain(flow->filter_list);
-               flow->filter_list = NULL;
                if (flow->ref > 1)
                        printk(KERN_ERR "atm_destroy: %p->ref = %d\n", flow,
                               flow->ref);
index 09969c1fbc08f287cb8b6bbc749e8a360fb9ea26..2a3c97f7dc630a7a44864f3af7b0c15d0186791b 100644 (file)
@@ -1704,7 +1704,7 @@ static void cbq_destroy_class(struct Qdisc *sch, struct cbq_class *cl)
 
        BUG_TRAP(!cl->filters);
 
-       tcf_destroy_chain(cl->filter_list);
+       tcf_destroy_chain(&cl->filter_list);
        qdisc_destroy(cl->q);
        qdisc_put_rtab(cl->R_tab);
        gen_kill_estimator(&cl->bstats, &cl->rate_est);
@@ -1728,10 +1728,8 @@ cbq_destroy(struct Qdisc* sch)
         * be bound to classes which have been destroyed already. --TGR '04
         */
        for (h = 0; h < 16; h++) {
-               for (cl = q->classes[h]; cl; cl = cl->next) {
-                       tcf_destroy_chain(cl->filter_list);
-                       cl->filter_list = NULL;
-               }
+               for (cl = q->classes[h]; cl; cl = cl->next)
+                       tcf_destroy_chain(&cl->filter_list);
        }
        for (h = 0; h < 16; h++) {
                struct cbq_class *next;
index 64465bacbe79e62c9515150b4baa44fa2d6bcff3..c4c1317cd47db91c56310db02bf933f3b521e722 100644 (file)
@@ -416,7 +416,7 @@ static void dsmark_destroy(struct Qdisc *sch)
 
        pr_debug("dsmark_destroy(sch %p,[qdisc %p])\n", sch, p);
 
-       tcf_destroy_chain(p->filter_list);
+       tcf_destroy_chain(&p->filter_list);
        qdisc_destroy(p->q);
        kfree(p->mask);
 }
index d355e5e47fe3a71aca1d151db1ce72429a069297..13afa7214392a74998ebbad3576ae4bb7a6d4638 100644 (file)
@@ -468,7 +468,7 @@ struct Qdisc *qdisc_alloc(struct net_device *dev, struct Qdisc_ops *ops)
 
        return sch;
 errout:
-       return ERR_PTR(-err);
+       return ERR_PTR(err);
 }
 
 struct Qdisc * qdisc_create_dflt(struct net_device *dev, struct Qdisc_ops *ops,
index fdfaa3fcc16d861ed2b14dc3511bea66cf206611..e817aa00441d4a7b5a647450405e202f485bdc88 100644 (file)
@@ -1123,7 +1123,7 @@ hfsc_destroy_class(struct Qdisc *sch, struct hfsc_class *cl)
 {
        struct hfsc_sched *q = qdisc_priv(sch);
 
-       tcf_destroy_chain(cl->filter_list);
+       tcf_destroy_chain(&cl->filter_list);
        qdisc_destroy(cl->qdisc);
        gen_kill_estimator(&cl->bstats, &cl->rate_est);
        if (cl != &q->root)
@@ -1540,6 +1540,10 @@ hfsc_destroy_qdisc(struct Qdisc *sch)
        struct hfsc_class *cl, *next;
        unsigned int i;
 
+       for (i = 0; i < HFSC_HSIZE; i++) {
+               list_for_each_entry(cl, &q->clhash[i], hlist)
+                       tcf_destroy_chain(&cl->filter_list);
+       }
        for (i = 0; i < HFSC_HSIZE; i++) {
                list_for_each_entry_safe(cl, next, &q->clhash[i], hlist)
                        hfsc_destroy_class(sch, cl);
index 6807c97985a54adac52ceb42d4b3847e0beebdd2..3fb58f428f724ca9a8fd8c6cd9a41450df567c4d 100644 (file)
@@ -1238,7 +1238,7 @@ static void htb_destroy_class(struct Qdisc *sch, struct htb_class *cl)
        qdisc_put_rtab(cl->rate);
        qdisc_put_rtab(cl->ceil);
 
-       tcf_destroy_chain(cl->filter_list);
+       tcf_destroy_chain(&cl->filter_list);
 
        while (!list_empty(&cl->children))
                htb_destroy_class(sch, list_entry(cl->children.next,
@@ -1267,7 +1267,7 @@ static void htb_destroy(struct Qdisc *sch)
           and surprisingly it worked in 2.4. But it must precede it
           because filter need its target class alive to be able to call
           unbind_filter on it (without Oops). */
-       tcf_destroy_chain(q->filter_list);
+       tcf_destroy_chain(&q->filter_list);
 
        while (!list_empty(&q->root))
                htb_destroy_class(sch, list_entry(q->root.next,
index 274b1ddb160c3956da169dd1bbc7da5e5f482637..956c80ad59654caa20fe7a805418f02992209465 100644 (file)
@@ -104,7 +104,7 @@ static void ingress_destroy(struct Qdisc *sch)
 {
        struct ingress_qdisc_data *p = qdisc_priv(sch);
 
-       tcf_destroy_chain(p->filter_list);
+       tcf_destroy_chain(&p->filter_list);
 }
 
 static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
index 4aa2b45dad0a80232ed1d1d1c2fbabf33b19ec8f..5532f1031ab52fd3276f37b383967986de070ea9 100644 (file)
@@ -219,7 +219,7 @@ prio_destroy(struct Qdisc* sch)
        int prio;
        struct prio_sched_data *q = qdisc_priv(sch);
 
-       tcf_destroy_chain(q->filter_list);
+       tcf_destroy_chain(&q->filter_list);
        for (prio=0; prio<q->bands; prio++)
                qdisc_destroy(q->queues[prio]);
 }
index f0463d757a98489f5b12138c0026d1b91742fd9d..6a97afbfb95245cc019f371606f36884e4e63b25 100644 (file)
@@ -520,7 +520,7 @@ static void sfq_destroy(struct Qdisc *sch)
 {
        struct sfq_sched_data *q = qdisc_priv(sch);
 
-       tcf_destroy_chain(q->filter_list);
+       tcf_destroy_chain(&q->filter_list);
        q->perturb_period = 0;
        del_timer_sync(&q->perturb_timer);
 }
index 5905d56737d6052a6ea10afbe975e9349a8530d0..81ae3d62a0cc9010d4cc1b6e5de130ae64ca2a57 100644 (file)
@@ -1144,20 +1144,20 @@ svcauth_gss_accept(struct svc_rqst *rqstp, __be32 *authp)
                case RPC_GSS_SVC_NONE:
                        break;
                case RPC_GSS_SVC_INTEGRITY:
+                       /* placeholders for length and seq. number: */
+                       svc_putnl(resv, 0);
+                       svc_putnl(resv, 0);
                        if (unwrap_integ_data(&rqstp->rq_arg,
                                        gc->gc_seq, rsci->mechctx))
                                goto garbage_args;
+                       break;
+               case RPC_GSS_SVC_PRIVACY:
                        /* placeholders for length and seq. number: */
                        svc_putnl(resv, 0);
                        svc_putnl(resv, 0);
-                       break;
-               case RPC_GSS_SVC_PRIVACY:
                        if (unwrap_priv_data(rqstp, &rqstp->rq_arg,
                                        gc->gc_seq, rsci->mechctx))
                                goto garbage_args;
-                       /* placeholders for length and seq. number: */
-                       svc_putnl(resv, 0);
-                       svc_putnl(resv, 0);
                        break;
                default:
                        goto auth_err;
@@ -1170,8 +1170,6 @@ svcauth_gss_accept(struct svc_rqst *rqstp, __be32 *authp)
                goto out;
        }
 garbage_args:
-       /* Restore write pointer to its original value: */
-       xdr_ressize_check(rqstp, reject_stat);
        ret = SVC_GARBAGE;
        goto out;
 auth_err:
index 657835f227d342a2eadc4498c6076b7c435839ac..783317dacd3090f7d602b3c56e82859f3cc22a46 100644 (file)
@@ -487,8 +487,8 @@ static int unix_socketpair(struct socket *, struct socket *);
 static int unix_accept(struct socket *, struct socket *, int);
 static int unix_getname(struct socket *, struct sockaddr *, int *, int);
 static unsigned int unix_poll(struct file *, struct socket *, poll_table *);
-static unsigned int unix_datagram_poll(struct file *, struct socket *,
-                                      poll_table *);
+static unsigned int unix_dgram_poll(struct file *, struct socket *,
+                                   poll_table *);
 static int unix_ioctl(struct socket *, unsigned int, unsigned long);
 static int unix_shutdown(struct socket *, int);
 static int unix_stream_sendmsg(struct kiocb *, struct socket *,
@@ -534,7 +534,7 @@ static const struct proto_ops unix_dgram_ops = {
        .socketpair =   unix_socketpair,
        .accept =       sock_no_accept,
        .getname =      unix_getname,
-       .poll =         unix_datagram_poll,
+       .poll =         unix_dgram_poll,
        .ioctl =        unix_ioctl,
        .listen =       sock_no_listen,
        .shutdown =     unix_shutdown,
@@ -555,7 +555,7 @@ static const struct proto_ops unix_seqpacket_ops = {
        .socketpair =   unix_socketpair,
        .accept =       unix_accept,
        .getname =      unix_getname,
-       .poll =         unix_datagram_poll,
+       .poll =         unix_dgram_poll,
        .ioctl =        unix_ioctl,
        .listen =       unix_listen,
        .shutdown =     unix_shutdown,
@@ -1994,29 +1994,13 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl
        return mask;
 }
 
-static unsigned int unix_datagram_poll(struct file *file, struct socket *sock,
-                                      poll_table *wait)
+static unsigned int unix_dgram_poll(struct file *file, struct socket *sock,
+                                   poll_table *wait)
 {
-       struct sock *sk = sock->sk, *peer;
-       unsigned int mask;
+       struct sock *sk = sock->sk, *other;
+       unsigned int mask, writable;
 
        poll_wait(file, sk->sk_sleep, wait);
-
-       peer = unix_peer_get(sk);
-       if (peer) {
-               if (peer != sk) {
-                       /*
-                        * Writability of a connected socket additionally
-                        * depends on the state of the receive queue of the
-                        * peer.
-                        */
-                       poll_wait(file, &unix_sk(peer)->peer_wait, wait);
-               } else {
-                       sock_put(peer);
-                       peer = NULL;
-               }
-       }
-
        mask = 0;
 
        /* exceptional events? */
@@ -2042,14 +2026,26 @@ static unsigned int unix_datagram_poll(struct file *file, struct socket *sock,
        }
 
        /* writable? */
-       if (unix_writable(sk) && !(peer && unix_recvq_full(peer)))
+       writable = unix_writable(sk);
+       if (writable) {
+               other = unix_peer_get(sk);
+               if (other) {
+                       if (unix_peer(other) != sk) {
+                               poll_wait(file, &unix_sk(other)->peer_wait,
+                                         wait);
+                               if (unix_recvq_full(other))
+                                       writable = 0;
+                       }
+
+                       sock_put(other);
+               }
+       }
+
+       if (writable)
                mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
        else
                set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
 
-       if (peer)
-               sock_put(peer);
-
        return mask;
 }
 
index 185488da246647c06bd85261f856a71fed182c34..855bff4b3250a0eb04b094b5fca6c5512ecb35b1 100644 (file)
@@ -80,6 +80,23 @@ static const struct ieee80211_channel_range ieee80211_JP_channels[] = {
                                     IEEE80211_CHAN_RADAR),
 };
 
+static const struct ieee80211_channel_range ieee80211_EU_channels[] = {
+       /* IEEE 802.11b/g, channels 1..13 */
+       RANGE_PWR(2412, 2472, 20, 6, 0),
+       /* IEEE 802.11a, channel 36*/
+       RANGE_PWR(5180, 5180, 23, 6, IEEE80211_CHAN_PASSIVE_SCAN),
+       /* IEEE 802.11a, channel 40*/
+       RANGE_PWR(5200, 5200, 23, 6, IEEE80211_CHAN_PASSIVE_SCAN),
+       /* IEEE 802.11a, channel 44*/
+       RANGE_PWR(5220, 5220, 23, 6, IEEE80211_CHAN_PASSIVE_SCAN),
+       /* IEEE 802.11a, channels 48..64 */
+       RANGE_PWR(5240, 5320, 23, 6, IEEE80211_CHAN_NO_IBSS |
+                                    IEEE80211_CHAN_RADAR),
+       /* IEEE 802.11a, channels 100..140 */
+       RANGE_PWR(5500, 5700, 30, 6, IEEE80211_CHAN_NO_IBSS |
+                                    IEEE80211_CHAN_RADAR),
+};
+
 #define REGDOM(_code)                                                  \
        {                                                               \
                .code = __stringify(_code),                             \
@@ -90,6 +107,7 @@ static const struct ieee80211_channel_range ieee80211_JP_channels[] = {
 static const struct ieee80211_regdomain ieee80211_regdoms[] = {
        REGDOM(US),
        REGDOM(JP),
+       REGDOM(EU),
 };
 
 
index 5edabc7542ae00c46e568456285f9bf5f369f2e6..33d34330841344f7329e1b1f313cc531c65aa7a9 100644 (file)
@@ -103,10 +103,16 @@ static inline int cap_inh_is_capped(void)
        return (cap_capable(current, CAP_SETPCAP) != 0);
 }
 
+static inline int cap_limit_ptraced_target(void) { return 1; }
+
 #else /* ie., ndef CONFIG_SECURITY_FILE_CAPABILITIES */
 
 static inline int cap_block_setpcap(struct task_struct *t) { return 0; }
 static inline int cap_inh_is_capped(void) { return 1; }
+static inline int cap_limit_ptraced_target(void)
+{
+       return !capable(CAP_SETPCAP);
+}
 
 #endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */
 
@@ -342,9 +348,10 @@ void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
                                bprm->e_uid = current->uid;
                                bprm->e_gid = current->gid;
                        }
-                       if (!capable (CAP_SETPCAP)) {
-                               new_permitted = cap_intersect (new_permitted,
-                                                       current->cap_permitted);
+                       if (cap_limit_ptraced_target()) {
+                               new_permitted =
+                                       cap_intersect(new_permitted,
+                                                     current->cap_permitted);
                        }
                }
        }
index baf348834b66c003758246427a98907d38f78c14..fd764a0858d0d5f1f60f1b671cbcc41c04be77dd 100644 (file)
@@ -382,6 +382,8 @@ static ssize_t devcgroup_access_write(struct cgroup *cgroup, struct cftype *cft,
        case 'a':
                wh.type = DEV_ALL;
                wh.access = ACC_MASK;
+               wh.major = ~0;
+               wh.minor = ~0;
                goto handle;
        case 'b':
                wh.type = DEV_BLOCK;