diff options
123 files changed, 7557 insertions, 342 deletions
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients index ee75cbace28d..d4cd4126d1ad 100644 --- a/Documentation/i2c/writing-clients +++ b/Documentation/i2c/writing-clients | |||
| @@ -25,12 +25,23 @@ routines, and should be zero-initialized except for fields with data you | |||
| 25 | provide. A client structure holds device-specific information like the | 25 | provide. A client structure holds device-specific information like the |
| 26 | driver model device node, and its I2C address. | 26 | driver model device node, and its I2C address. |
| 27 | 27 | ||
| 28 | /* iff driver uses driver model ("new style") binding model: */ | ||
| 29 | |||
| 30 | static struct i2c_device_id foo_idtable[] = { | ||
| 31 | { "foo", my_id_for_foo }, | ||
| 32 | { "bar", my_id_for_bar }, | ||
| 33 | { } | ||
| 34 | }; | ||
| 35 | |||
| 36 | MODULE_DEVICE_TABLE(i2c, foo_idtable); | ||
| 37 | |||
| 28 | static struct i2c_driver foo_driver = { | 38 | static struct i2c_driver foo_driver = { |
| 29 | .driver = { | 39 | .driver = { |
| 30 | .name = "foo", | 40 | .name = "foo", |
| 31 | }, | 41 | }, |
| 32 | 42 | ||
| 33 | /* iff driver uses driver model ("new style") binding model: */ | 43 | /* iff driver uses driver model ("new style") binding model: */ |
| 44 | .id_table = foo_ids, | ||
| 34 | .probe = foo_probe, | 45 | .probe = foo_probe, |
| 35 | .remove = foo_remove, | 46 | .remove = foo_remove, |
| 36 | 47 | ||
| @@ -173,10 +184,9 @@ handle may be used during foo_probe(). If foo_probe() reports success | |||
| 173 | (zero not a negative status code) it may save the handle and use it until | 184 | (zero not a negative status code) it may save the handle and use it until |
| 174 | foo_remove() returns. That binding model is used by most Linux drivers. | 185 | foo_remove() returns. That binding model is used by most Linux drivers. |
| 175 | 186 | ||
| 176 | Drivers match devices when i2c_client.driver_name and the driver name are | 187 | The probe function is called when an entry in the id_table name field |
| 177 | the same; this approach is used in several other busses that don't have | 188 | matches the device's name. It is passed the entry that was matched so |
| 178 | device typing support in the hardware. The driver and module name should | 189 | the driver knows which one in the table matched. |
| 179 | match, so hotplug/coldplug mechanisms will modprobe the driver. | ||
| 180 | 190 | ||
| 181 | 191 | ||
| 182 | Device Creation (Standard driver model) | 192 | Device Creation (Standard driver model) |
diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt index 17a6e46fbd43..17f1f91af35c 100644 --- a/Documentation/networking/ip-sysctl.txt +++ b/Documentation/networking/ip-sysctl.txt | |||
| @@ -81,23 +81,23 @@ inet_peer_minttl - INTEGER | |||
| 81 | Minimum time-to-live of entries. Should be enough to cover fragment | 81 | Minimum time-to-live of entries. Should be enough to cover fragment |
| 82 | time-to-live on the reassembling side. This minimum time-to-live is | 82 | time-to-live on the reassembling side. This minimum time-to-live is |
| 83 | guaranteed if the pool size is less than inet_peer_threshold. | 83 | guaranteed if the pool size is less than inet_peer_threshold. |
| 84 | Measured in jiffies(1). | 84 | Measured in seconds. |
| 85 | 85 | ||
| 86 | inet_peer_maxttl - INTEGER | 86 | inet_peer_maxttl - INTEGER |
| 87 | Maximum time-to-live of entries. Unused entries will expire after | 87 | Maximum time-to-live of entries. Unused entries will expire after |
| 88 | this period of time if there is no memory pressure on the pool (i.e. | 88 | this period of time if there is no memory pressure on the pool (i.e. |
| 89 | when the number of entries in the pool is very small). | 89 | when the number of entries in the pool is very small). |
| 90 | Measured in jiffies(1). | 90 | Measured in seconds. |
| 91 | 91 | ||
| 92 | inet_peer_gc_mintime - INTEGER | 92 | inet_peer_gc_mintime - INTEGER |
| 93 | Minimum interval between garbage collection passes. This interval is | 93 | Minimum interval between garbage collection passes. This interval is |
| 94 | in effect under high memory pressure on the pool. | 94 | in effect under high memory pressure on the pool. |
| 95 | Measured in jiffies(1). | 95 | Measured in seconds. |
| 96 | 96 | ||
| 97 | inet_peer_gc_maxtime - INTEGER | 97 | inet_peer_gc_maxtime - INTEGER |
| 98 | Minimum interval between garbage collection passes. This interval is | 98 | Minimum interval between garbage collection passes. This interval is |
| 99 | in effect under low (or absent) memory pressure on the pool. | 99 | in effect under low (or absent) memory pressure on the pool. |
| 100 | Measured in jiffies(1). | 100 | Measured in seconds. |
| 101 | 101 | ||
| 102 | TCP variables: | 102 | TCP variables: |
| 103 | 103 | ||
| @@ -794,10 +794,6 @@ tag - INTEGER | |||
| 794 | Allows you to write a number, which can be used as required. | 794 | Allows you to write a number, which can be used as required. |
| 795 | Default value is 0. | 795 | Default value is 0. |
| 796 | 796 | ||
| 797 | (1) Jiffie: internal timeunit for the kernel. On the i386 1/100s, on the | ||
| 798 | Alpha 1/1024s. See the HZ define in /usr/include/asm/param.h for the exact | ||
| 799 | value on your system. | ||
| 800 | |||
| 801 | Alexey Kuznetsov. | 797 | Alexey Kuznetsov. |
| 802 | kuznet@ms2.inr.ac.ru | 798 | kuznet@ms2.inr.ac.ru |
| 803 | 799 | ||
diff --git a/Documentation/networking/s2io.txt b/Documentation/networking/s2io.txt index 4bde53e85f3f..1e28e2ddb90a 100644 --- a/Documentation/networking/s2io.txt +++ b/Documentation/networking/s2io.txt | |||
| @@ -83,9 +83,9 @@ Valid range: Limited by memory on system | |||
| 83 | Default: 30 | 83 | Default: 30 |
| 84 | 84 | ||
| 85 | e. intr_type | 85 | e. intr_type |
| 86 | Specifies interrupt type. Possible values 1(INTA), 2(MSI), 3(MSI-X) | 86 | Specifies interrupt type. Possible values 0(INTA), 2(MSI-X) |
| 87 | Valid range: 1-3 | 87 | Valid values: 0, 2 |
| 88 | Default: 1 | 88 | Default: 2 |
| 89 | 89 | ||
| 90 | 5. Performance suggestions | 90 | 5. Performance suggestions |
| 91 | General: | 91 | General: |
diff --git a/MAINTAINERS b/MAINTAINERS index 8f0ec46a7096..e6c06fa3290e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -4314,6 +4314,14 @@ L: netdev@vger.kernel.org | |||
| 4314 | W: http://www.linux-usb.org/usbnet | 4314 | W: http://www.linux-usb.org/usbnet |
| 4315 | S: Maintained | 4315 | S: Maintained |
| 4316 | 4316 | ||
| 4317 | USB VIDEO CLASS | ||
| 4318 | P: Laurent Pinchart | ||
| 4319 | M: laurent.pinchart@skynet.be | ||
| 4320 | L: linx-uvc-devel@berlios.de | ||
| 4321 | L: video4linux-list@redhat.com | ||
| 4322 | W: http://linux-uvc.berlios.de | ||
| 4323 | S: Maintained | ||
| 4324 | |||
| 4317 | USB W996[87]CF DRIVER | 4325 | USB W996[87]CF DRIVER |
| 4318 | P: Luca Risolia | 4326 | P: Luca Risolia |
| 4319 | M: luca.risolia@studio.unibo.it | 4327 | M: luca.risolia@studio.unibo.it |
diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c index 52fc6a883281..2744673314b4 100644 --- a/arch/arm/common/dmabounce.c +++ b/arch/arm/common/dmabounce.c | |||
| @@ -650,7 +650,8 @@ EXPORT_SYMBOL(dma_map_sg); | |||
| 650 | EXPORT_SYMBOL(dma_unmap_sg); | 650 | EXPORT_SYMBOL(dma_unmap_sg); |
| 651 | EXPORT_SYMBOL(dma_sync_single_for_cpu); | 651 | EXPORT_SYMBOL(dma_sync_single_for_cpu); |
| 652 | EXPORT_SYMBOL(dma_sync_single_for_device); | 652 | EXPORT_SYMBOL(dma_sync_single_for_device); |
| 653 | EXPORT_SYMBOL(dma_sync_sg); | 653 | EXPORT_SYMBOL(dma_sync_sg_for_cpu); |
| 654 | EXPORT_SYMBOL(dma_sync_sg_for_device); | ||
| 654 | EXPORT_SYMBOL(dmabounce_register_dev); | 655 | EXPORT_SYMBOL(dmabounce_register_dev); |
| 655 | EXPORT_SYMBOL(dmabounce_unregister_dev); | 656 | EXPORT_SYMBOL(dmabounce_unregister_dev); |
| 656 | 657 | ||
diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c index 02cede295e89..dbf68dc50ae2 100644 --- a/arch/arm/mach-omap2/gpmc.c +++ b/arch/arm/mach-omap2/gpmc.c | |||
| @@ -42,7 +42,7 @@ | |||
| 42 | #define GPMC_STATUS 0x54 | 42 | #define GPMC_STATUS 0x54 |
| 43 | #define GPMC_PREFETCH_CONFIG1 0x1e0 | 43 | #define GPMC_PREFETCH_CONFIG1 0x1e0 |
| 44 | #define GPMC_PREFETCH_CONFIG2 0x1e4 | 44 | #define GPMC_PREFETCH_CONFIG2 0x1e4 |
| 45 | #define GPMC_PREFETCH_CONTROL 0x1e8 | 45 | #define GPMC_PREFETCH_CONTROL 0x1ec |
| 46 | #define GPMC_PREFETCH_STATUS 0x1f0 | 46 | #define GPMC_PREFETCH_STATUS 0x1f0 |
| 47 | #define GPMC_ECC_CONFIG 0x1f4 | 47 | #define GPMC_ECC_CONFIG 0x1f4 |
| 48 | #define GPMC_ECC_CONTROL 0x1f8 | 48 | #define GPMC_ECC_CONTROL 0x1f8 |
diff --git a/arch/arm/mach-realview/platsmp.c b/arch/arm/mach-realview/platsmp.c index 3e57428affee..8e813ed57519 100644 --- a/arch/arm/mach-realview/platsmp.c +++ b/arch/arm/mach-realview/platsmp.c | |||
| @@ -74,6 +74,8 @@ static DEFINE_SPINLOCK(boot_lock); | |||
| 74 | 74 | ||
| 75 | void __cpuinit platform_secondary_init(unsigned int cpu) | 75 | void __cpuinit platform_secondary_init(unsigned int cpu) |
| 76 | { | 76 | { |
| 77 | trace_hardirqs_off(); | ||
| 78 | |||
| 77 | /* | 79 | /* |
| 78 | * the primary core may have used a "cross call" soft interrupt | 80 | * the primary core may have used a "cross call" soft interrupt |
| 79 | * to get this processor out of WFI in the BootMonitor - make | 81 | * to get this processor out of WFI in the BootMonitor - make |
diff --git a/arch/arm/plat-omap/dma.c b/arch/arm/plat-omap/dma.c index c00eda588cd8..39c637b0ffea 100644 --- a/arch/arm/plat-omap/dma.c +++ b/arch/arm/plat-omap/dma.c | |||
| @@ -501,8 +501,6 @@ static inline void omap_enable_channel_irq(int lch) | |||
| 501 | 501 | ||
| 502 | /* Enable some nice interrupts. */ | 502 | /* Enable some nice interrupts. */ |
| 503 | OMAP_DMA_CICR_REG(lch) = dma_chan[lch].enabled_irqs; | 503 | OMAP_DMA_CICR_REG(lch) = dma_chan[lch].enabled_irqs; |
| 504 | |||
| 505 | dma_chan[lch].flags |= OMAP_DMA_ACTIVE; | ||
| 506 | } | 504 | } |
| 507 | 505 | ||
| 508 | static void omap_disable_channel_irq(int lch) | 506 | static void omap_disable_channel_irq(int lch) |
diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c index 4ae15c8c2488..632cda8f2e76 100644 --- a/arch/ia64/kernel/setup.c +++ b/arch/ia64/kernel/setup.c | |||
| @@ -547,7 +547,8 @@ setup_arch (char **cmdline_p) | |||
| 547 | # ifdef CONFIG_ACPI_NUMA | 547 | # ifdef CONFIG_ACPI_NUMA |
| 548 | acpi_numa_init(); | 548 | acpi_numa_init(); |
| 549 | per_cpu_scan_finalize((cpus_weight(early_cpu_possible_map) == 0 ? | 549 | per_cpu_scan_finalize((cpus_weight(early_cpu_possible_map) == 0 ? |
| 550 | 32 : cpus_weight(early_cpu_possible_map)), additional_cpus); | 550 | 32 : cpus_weight(early_cpu_possible_map)), |
| 551 | additional_cpus > 0 ? additional_cpus : 0); | ||
| 551 | # endif | 552 | # endif |
| 552 | #else | 553 | #else |
| 553 | # ifdef CONFIG_SMP | 554 | # ifdef CONFIG_SMP |
diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c index 8c73643f2d66..aad1b7b1fff9 100644 --- a/arch/ia64/kernel/time.c +++ b/arch/ia64/kernel/time.c | |||
| @@ -117,6 +117,7 @@ void account_system_vtime(struct task_struct *tsk) | |||
| 117 | 117 | ||
| 118 | local_irq_restore(flags); | 118 | local_irq_restore(flags); |
| 119 | } | 119 | } |
| 120 | EXPORT_SYMBOL_GPL(account_system_vtime); | ||
| 120 | 121 | ||
| 121 | /* | 122 | /* |
| 122 | * Called from the timer interrupt handler to charge accumulated user time | 123 | * Called from the timer interrupt handler to charge accumulated user time |
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile index 1cee2f9fdf06..095e04db1c0e 100644 --- a/arch/powerpc/boot/Makefile +++ b/arch/powerpc/boot/Makefile | |||
| @@ -273,7 +273,8 @@ endif | |||
| 273 | initrd- := $(patsubst zImage%, zImage.initrd%, $(image-n) $(image-)) | 273 | initrd- := $(patsubst zImage%, zImage.initrd%, $(image-n) $(image-)) |
| 274 | initrd-y := $(patsubst zImage%, zImage.initrd%, \ | 274 | initrd-y := $(patsubst zImage%, zImage.initrd%, \ |
| 275 | $(patsubst dtbImage%, dtbImage.initrd%, \ | 275 | $(patsubst dtbImage%, dtbImage.initrd%, \ |
| 276 | $(patsubst treeImage%, treeImage.initrd%, $(image-y)))) | 276 | $(patsubst simpleImage%, simpleImage.initrd%, \ |
| 277 | $(patsubst treeImage%, treeImage.initrd%, $(image-y))))) | ||
| 277 | initrd-y := $(filter-out $(image-y), $(initrd-y)) | 278 | initrd-y := $(filter-out $(image-y), $(initrd-y)) |
| 278 | targets += $(image-y) $(initrd-y) | 279 | targets += $(image-y) $(initrd-y) |
| 279 | 280 | ||
diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c index 61dd17449ddc..cf37f5ca4b71 100644 --- a/arch/powerpc/kernel/legacy_serial.c +++ b/arch/powerpc/kernel/legacy_serial.c | |||
| @@ -136,6 +136,11 @@ static int __init add_legacy_soc_port(struct device_node *np, | |||
| 136 | if (of_get_property(np, "clock-frequency", NULL) == NULL) | 136 | if (of_get_property(np, "clock-frequency", NULL) == NULL) |
| 137 | return -1; | 137 | return -1; |
| 138 | 138 | ||
| 139 | /* if reg-shift or offset, don't try to use it */ | ||
| 140 | if ((of_get_property(np, "reg-shift", NULL) != NULL) || | ||
| 141 | (of_get_property(np, "reg-offset", NULL) != NULL)) | ||
| 142 | return -1; | ||
| 143 | |||
| 139 | /* if rtas uses this device, don't try to use it as well */ | 144 | /* if rtas uses this device, don't try to use it as well */ |
| 140 | if (of_get_property(np, "used-by-rtas", NULL) != NULL) | 145 | if (of_get_property(np, "used-by-rtas", NULL) != NULL) |
| 141 | return -1; | 146 | return -1; |
diff --git a/arch/powerpc/platforms/52xx/lite5200_pm.c b/arch/powerpc/platforms/52xx/lite5200_pm.c index 41c7fd91e99e..fe92e65103ed 100644 --- a/arch/powerpc/platforms/52xx/lite5200_pm.c +++ b/arch/powerpc/platforms/52xx/lite5200_pm.c | |||
| @@ -14,6 +14,7 @@ static struct mpc52xx_sdma __iomem *bes; | |||
| 14 | static struct mpc52xx_xlb __iomem *xlb; | 14 | static struct mpc52xx_xlb __iomem *xlb; |
| 15 | static struct mpc52xx_gpio __iomem *gps; | 15 | static struct mpc52xx_gpio __iomem *gps; |
| 16 | static struct mpc52xx_gpio_wkup __iomem *gpw; | 16 | static struct mpc52xx_gpio_wkup __iomem *gpw; |
| 17 | static void __iomem *pci; | ||
| 17 | static void __iomem *sram; | 18 | static void __iomem *sram; |
| 18 | static const int sram_size = 0x4000; /* 16 kBytes */ | 19 | static const int sram_size = 0x4000; /* 16 kBytes */ |
| 19 | static void __iomem *mbar; | 20 | static void __iomem *mbar; |
| @@ -50,6 +51,8 @@ static int lite5200_pm_prepare(void) | |||
| 50 | { .type = "builtin", .compatible = "mpc5200", }, /* efika */ | 51 | { .type = "builtin", .compatible = "mpc5200", }, /* efika */ |
| 51 | {} | 52 | {} |
| 52 | }; | 53 | }; |
| 54 | u64 regaddr64 = 0; | ||
| 55 | const u32 *regaddr_p; | ||
| 53 | 56 | ||
| 54 | /* deep sleep? let mpc52xx code handle that */ | 57 | /* deep sleep? let mpc52xx code handle that */ |
| 55 | if (lite5200_pm_target_state == PM_SUSPEND_STANDBY) | 58 | if (lite5200_pm_target_state == PM_SUSPEND_STANDBY) |
| @@ -60,8 +63,12 @@ static int lite5200_pm_prepare(void) | |||
| 60 | 63 | ||
| 61 | /* map registers */ | 64 | /* map registers */ |
| 62 | np = of_find_matching_node(NULL, immr_ids); | 65 | np = of_find_matching_node(NULL, immr_ids); |
| 63 | mbar = of_iomap(np, 0); | 66 | regaddr_p = of_get_address(np, 0, NULL, NULL); |
| 67 | if (regaddr_p) | ||
| 68 | regaddr64 = of_translate_address(np, regaddr_p); | ||
| 64 | of_node_put(np); | 69 | of_node_put(np); |
| 70 | |||
| 71 | mbar = ioremap((u32) regaddr64, 0xC000); | ||
| 65 | if (!mbar) { | 72 | if (!mbar) { |
| 66 | printk(KERN_ERR "%s:%i Error mapping registers\n", __func__, __LINE__); | 73 | printk(KERN_ERR "%s:%i Error mapping registers\n", __func__, __LINE__); |
| 67 | return -ENOSYS; | 74 | return -ENOSYS; |
| @@ -71,6 +78,7 @@ static int lite5200_pm_prepare(void) | |||
| 71 | pic = mbar + 0x500; | 78 | pic = mbar + 0x500; |
| 72 | gps = mbar + 0xb00; | 79 | gps = mbar + 0xb00; |
| 73 | gpw = mbar + 0xc00; | 80 | gpw = mbar + 0xc00; |
| 81 | pci = mbar + 0xd00; | ||
| 74 | bes = mbar + 0x1200; | 82 | bes = mbar + 0x1200; |
| 75 | xlb = mbar + 0x1f00; | 83 | xlb = mbar + 0x1f00; |
| 76 | sram = mbar + 0x8000; | 84 | sram = mbar + 0x8000; |
| @@ -85,6 +93,7 @@ static struct mpc52xx_sdma sbes; | |||
| 85 | static struct mpc52xx_xlb sxlb; | 93 | static struct mpc52xx_xlb sxlb; |
| 86 | static struct mpc52xx_gpio sgps; | 94 | static struct mpc52xx_gpio sgps; |
| 87 | static struct mpc52xx_gpio_wkup sgpw; | 95 | static struct mpc52xx_gpio_wkup sgpw; |
| 96 | static char spci[0x200]; | ||
| 88 | 97 | ||
| 89 | static void lite5200_save_regs(void) | 98 | static void lite5200_save_regs(void) |
| 90 | { | 99 | { |
| @@ -94,6 +103,7 @@ static void lite5200_save_regs(void) | |||
| 94 | _memcpy_fromio(&sxlb, xlb, sizeof(*xlb)); | 103 | _memcpy_fromio(&sxlb, xlb, sizeof(*xlb)); |
| 95 | _memcpy_fromio(&sgps, gps, sizeof(*gps)); | 104 | _memcpy_fromio(&sgps, gps, sizeof(*gps)); |
| 96 | _memcpy_fromio(&sgpw, gpw, sizeof(*gpw)); | 105 | _memcpy_fromio(&sgpw, gpw, sizeof(*gpw)); |
| 106 | _memcpy_fromio(spci, pci, 0x200); | ||
| 97 | 107 | ||
| 98 | _memcpy_fromio(saved_sram, sram, sram_size); | 108 | _memcpy_fromio(saved_sram, sram, sram_size); |
| 99 | } | 109 | } |
| @@ -103,6 +113,8 @@ static void lite5200_restore_regs(void) | |||
| 103 | int i; | 113 | int i; |
| 104 | _memcpy_toio(sram, saved_sram, sram_size); | 114 | _memcpy_toio(sram, saved_sram, sram_size); |
| 105 | 115 | ||
| 116 | /* PCI Configuration */ | ||
| 117 | _memcpy_toio(pci, spci, 0x200); | ||
| 106 | 118 | ||
| 107 | /* | 119 | /* |
| 108 | * GPIOs. Interrupt Master Enable has higher address then other | 120 | * GPIOs. Interrupt Master Enable has higher address then other |
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index e0edaaa6920a..bf07b6f50fa1 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
| @@ -966,8 +966,8 @@ config NUMA_EMU | |||
| 966 | number of nodes. This is only useful for debugging. | 966 | number of nodes. This is only useful for debugging. |
| 967 | 967 | ||
| 968 | config NODES_SHIFT | 968 | config NODES_SHIFT |
| 969 | int "Max num nodes shift(1-15)" | 969 | int "Max num nodes shift(1-9)" |
| 970 | range 1 15 if X86_64 | 970 | range 1 9 if X86_64 |
| 971 | default "6" if X86_64 | 971 | default "6" if X86_64 |
| 972 | default "4" if X86_NUMAQ | 972 | default "4" if X86_NUMAQ |
| 973 | default "3" | 973 | default "3" |
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c index eb9ddd8efb82..95e80e5033c3 100644 --- a/arch/x86/kernel/i387.c +++ b/arch/x86/kernel/i387.c | |||
| @@ -162,7 +162,7 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset, | |||
| 162 | int ret; | 162 | int ret; |
| 163 | 163 | ||
| 164 | if (!cpu_has_fxsr) | 164 | if (!cpu_has_fxsr) |
| 165 | return -ENODEV; | 165 | return -EIO; |
| 166 | 166 | ||
| 167 | ret = init_fpu(target); | 167 | ret = init_fpu(target); |
| 168 | if (ret) | 168 | if (ret) |
| @@ -179,7 +179,7 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset, | |||
| 179 | int ret; | 179 | int ret; |
| 180 | 180 | ||
| 181 | if (!cpu_has_fxsr) | 181 | if (!cpu_has_fxsr) |
| 182 | return -ENODEV; | 182 | return -EIO; |
| 183 | 183 | ||
| 184 | ret = init_fpu(target); | 184 | ret = init_fpu(target); |
| 185 | if (ret) | 185 | if (ret) |
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 56078d61c793..3e1cecedde42 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c | |||
| @@ -996,7 +996,6 @@ do_rest: | |||
| 996 | #endif | 996 | #endif |
| 997 | cpu_clear(cpu, cpu_callout_map); /* was set by do_boot_cpu() */ | 997 | cpu_clear(cpu, cpu_callout_map); /* was set by do_boot_cpu() */ |
| 998 | cpu_clear(cpu, cpu_initialized); /* was set by cpu_init() */ | 998 | cpu_clear(cpu, cpu_initialized); /* was set by cpu_init() */ |
| 999 | cpu_clear(cpu, cpu_possible_map); | ||
| 1000 | cpu_clear(cpu, cpu_present_map); | 999 | cpu_clear(cpu, cpu_present_map); |
| 1001 | per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID; | 1000 | per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID; |
| 1002 | } | 1001 | } |
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 156e6d7b0e32..f6d20be7a8f4 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c | |||
| @@ -135,7 +135,7 @@ static __init void *spp_getpage(void) | |||
| 135 | return ptr; | 135 | return ptr; |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | static void | 138 | static __init void |
| 139 | set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot) | 139 | set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot) |
| 140 | { | 140 | { |
| 141 | pgd_t *pgd; | 141 | pgd_t *pgd; |
| @@ -214,7 +214,7 @@ void __init cleanup_highmap(void) | |||
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | /* NOTE: this is meant to be run only at boot */ | 216 | /* NOTE: this is meant to be run only at boot */ |
| 217 | void __set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t prot) | 217 | void __init __set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t prot) |
| 218 | { | 218 | { |
| 219 | unsigned long address = __fix_to_virt(idx); | 219 | unsigned long address = __fix_to_virt(idx); |
| 220 | 220 | ||
| @@ -506,7 +506,7 @@ early_param("memtest", parse_memtest); | |||
| 506 | 506 | ||
| 507 | static void __init early_memtest(unsigned long start, unsigned long end) | 507 | static void __init early_memtest(unsigned long start, unsigned long end) |
| 508 | { | 508 | { |
| 509 | u64 t_start, t_size; | 509 | unsigned long t_start, t_size; |
| 510 | unsigned pattern; | 510 | unsigned pattern; |
| 511 | 511 | ||
| 512 | if (!memtest_pattern) | 512 | if (!memtest_pattern) |
| @@ -525,7 +525,7 @@ static void __init early_memtest(unsigned long start, unsigned long end) | |||
| 525 | if (t_start + t_size > end) | 525 | if (t_start + t_size > end) |
| 526 | t_size = end - t_start; | 526 | t_size = end - t_start; |
| 527 | 527 | ||
| 528 | printk(KERN_CONT "\n %016llx - %016llx pattern %d", | 528 | printk(KERN_CONT "\n %016lx - %016lx pattern %d", |
| 529 | t_start, t_start + t_size, pattern); | 529 | t_start, t_start + t_size, pattern); |
| 530 | 530 | ||
| 531 | memtest(t_start, t_size, pattern); | 531 | memtest(t_start, t_size, pattern); |
diff --git a/drivers/char/drm/i915_irq.c b/drivers/char/drm/i915_irq.c index f7f16e7a8bf3..df036118b8b1 100644 --- a/drivers/char/drm/i915_irq.c +++ b/drivers/char/drm/i915_irq.c | |||
| @@ -62,11 +62,11 @@ static void i915_vblank_tasklet(struct drm_device *dev) | |||
| 62 | u32 ropcpp = (0xcc << 16) | ((cpp - 1) << 24); | 62 | u32 ropcpp = (0xcc << 16) | ((cpp - 1) << 24); |
| 63 | RING_LOCALS; | 63 | RING_LOCALS; |
| 64 | 64 | ||
| 65 | if (sarea_priv->front_tiled) { | 65 | if (IS_I965G(dev) && sarea_priv->front_tiled) { |
| 66 | cmd |= XY_SRC_COPY_BLT_DST_TILED; | 66 | cmd |= XY_SRC_COPY_BLT_DST_TILED; |
| 67 | dst_pitch >>= 2; | 67 | dst_pitch >>= 2; |
| 68 | } | 68 | } |
| 69 | if (sarea_priv->back_tiled) { | 69 | if (IS_I965G(dev) && sarea_priv->back_tiled) { |
| 70 | cmd |= XY_SRC_COPY_BLT_SRC_TILED; | 70 | cmd |= XY_SRC_COPY_BLT_SRC_TILED; |
| 71 | src_pitch >>= 2; | 71 | src_pitch >>= 2; |
| 72 | } | 72 | } |
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index e94bee032314..750131010af0 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
| @@ -3322,7 +3322,7 @@ static int send_break(struct tty_struct *tty, unsigned int duration) | |||
| 3322 | msleep_interruptible(duration); | 3322 | msleep_interruptible(duration); |
| 3323 | tty->ops->break_ctl(tty, 0); | 3323 | tty->ops->break_ctl(tty, 0); |
| 3324 | tty_write_unlock(tty); | 3324 | tty_write_unlock(tty); |
| 3325 | if (!signal_pending(current)) | 3325 | if (signal_pending(current)) |
| 3326 | return -EINTR; | 3326 | return -EINTR; |
| 3327 | return 0; | 3327 | return 0; |
| 3328 | } | 3328 | } |
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c index 85e2ba7fcfba..bf4830082a13 100644 --- a/drivers/connector/connector.c +++ b/drivers/connector/connector.c | |||
| @@ -27,6 +27,8 @@ | |||
| 27 | #include <linux/moduleparam.h> | 27 | #include <linux/moduleparam.h> |
| 28 | #include <linux/connector.h> | 28 | #include <linux/connector.h> |
| 29 | #include <linux/mutex.h> | 29 | #include <linux/mutex.h> |
| 30 | #include <linux/proc_fs.h> | ||
| 31 | #include <linux/spinlock.h> | ||
| 30 | 32 | ||
| 31 | #include <net/sock.h> | 33 | #include <net/sock.h> |
| 32 | 34 | ||
| @@ -403,6 +405,40 @@ static void cn_callback(void *data) | |||
| 403 | mutex_unlock(¬ify_lock); | 405 | mutex_unlock(¬ify_lock); |
| 404 | } | 406 | } |
| 405 | 407 | ||
| 408 | static int cn_proc_show(struct seq_file *m, void *v) | ||
| 409 | { | ||
| 410 | struct cn_queue_dev *dev = cdev.cbdev; | ||
| 411 | struct cn_callback_entry *cbq; | ||
| 412 | |||
| 413 | seq_printf(m, "Name ID\n"); | ||
| 414 | |||
| 415 | spin_lock_bh(&dev->queue_lock); | ||
| 416 | |||
| 417 | list_for_each_entry(cbq, &dev->queue_list, callback_entry) { | ||
| 418 | seq_printf(m, "%-15s %u:%u\n", | ||
| 419 | cbq->id.name, | ||
| 420 | cbq->id.id.idx, | ||
| 421 | cbq->id.id.val); | ||
| 422 | } | ||
| 423 | |||
| 424 | spin_unlock_bh(&dev->queue_lock); | ||
| 425 | |||
| 426 | return 0; | ||
| 427 | } | ||
| 428 | |||
| 429 | static int cn_proc_open(struct inode *inode, struct file *file) | ||
| 430 | { | ||
| 431 | return single_open(file, cn_proc_show, NULL); | ||
| 432 | } | ||
| 433 | |||
| 434 | static const struct file_operations cn_file_ops = { | ||
| 435 | .owner = THIS_MODULE, | ||
| 436 | .open = cn_proc_open, | ||
| 437 | .read = seq_read, | ||
| 438 | .llseek = seq_lseek, | ||
| 439 | .release = single_release | ||
| 440 | }; | ||
| 441 | |||
| 406 | static int __devinit cn_init(void) | 442 | static int __devinit cn_init(void) |
| 407 | { | 443 | { |
| 408 | struct cn_dev *dev = &cdev; | 444 | struct cn_dev *dev = &cdev; |
| @@ -434,6 +470,8 @@ static int __devinit cn_init(void) | |||
| 434 | return -EINVAL; | 470 | return -EINVAL; |
| 435 | } | 471 | } |
| 436 | 472 | ||
| 473 | proc_net_fops_create(&init_net, "connector", S_IRUGO, &cn_file_ops); | ||
| 474 | |||
| 437 | return 0; | 475 | return 0; |
| 438 | } | 476 | } |
| 439 | 477 | ||
| @@ -443,6 +481,8 @@ static void __devexit cn_fini(void) | |||
| 443 | 481 | ||
| 444 | cn_already_initialized = 0; | 482 | cn_already_initialized = 0; |
| 445 | 483 | ||
| 484 | proc_net_remove(&init_net, "connector"); | ||
| 485 | |||
| 446 | cn_del_callback(&dev->id); | 486 | cn_del_callback(&dev->id); |
| 447 | cn_queue_free_dev(dev->cbdev); | 487 | cn_queue_free_dev(dev->cbdev); |
| 448 | netlink_kernel_release(dev->nls); | 488 | netlink_kernel_release(dev->nls); |
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig index 8e07de23d220..1607536ff5fb 100644 --- a/drivers/ide/Kconfig +++ b/drivers/ide/Kconfig | |||
| @@ -823,6 +823,13 @@ config BLK_DEV_IDE_RAPIDE | |||
| 823 | Say Y here if you want to support the Yellowstone RapIDE controller | 823 | Say Y here if you want to support the Yellowstone RapIDE controller |
| 824 | manufactured for use with Acorn computers. | 824 | manufactured for use with Acorn computers. |
| 825 | 825 | ||
| 826 | config BLK_DEV_IDE_BAST | ||
| 827 | tristate "Simtec BAST / Thorcom VR1000 IDE support" | ||
| 828 | depends on ARM && (ARCH_BAST || MACH_VR1000) | ||
| 829 | help | ||
| 830 | Say Y here if you want to support the onboard IDE channels on the | ||
| 831 | Simtec BAST or the Thorcom VR1000 | ||
| 832 | |||
| 826 | config IDE_H8300 | 833 | config IDE_H8300 |
| 827 | tristate "H8300 IDE support" | 834 | tristate "H8300 IDE support" |
| 828 | depends on H8300 | 835 | depends on H8300 |
diff --git a/drivers/ide/arm/Makefile b/drivers/ide/arm/Makefile index 5bc26053afa6..936e7b0237f5 100644 --- a/drivers/ide/arm/Makefile +++ b/drivers/ide/arm/Makefile | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | 1 | ||
| 2 | obj-$(CONFIG_BLK_DEV_IDE_ICSIDE) += icside.o | 2 | obj-$(CONFIG_BLK_DEV_IDE_ICSIDE) += icside.o |
| 3 | obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapide.o | 3 | obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapide.o |
| 4 | obj-$(CONFIG_BLK_DEV_IDE_BAST) += bast-ide.o | ||
| 4 | obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710) += palm_bk3710.o | 5 | obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710) += palm_bk3710.o |
| 5 | 6 | ||
| 6 | ifeq ($(CONFIG_IDE_ARM), m) | 7 | 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 index 000000000000..8e8c28104b45 --- /dev/null +++ b/drivers/ide/arm/bast-ide.c | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2003-2004 Simtec Electronics | ||
| 3 | * Ben Dooks <ben@simtec.co.uk> | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License version 2 as | ||
| 7 | * published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/module.h> | ||
| 12 | #include <linux/errno.h> | ||
| 13 | #include <linux/ide.h> | ||
| 14 | #include <linux/init.h> | ||
| 15 | |||
| 16 | #include <asm/mach-types.h> | ||
| 17 | |||
| 18 | #include <asm/io.h> | ||
| 19 | #include <asm/irq.h> | ||
| 20 | #include <asm/arch/map.h> | ||
| 21 | #include <asm/arch/bast-map.h> | ||
| 22 | #include <asm/arch/bast-irq.h> | ||
| 23 | |||
| 24 | #define DRV_NAME "bast-ide" | ||
| 25 | |||
| 26 | static int __init bastide_register(unsigned int base, unsigned int aux, int irq) | ||
| 27 | { | ||
| 28 | ide_hwif_t *hwif; | ||
| 29 | hw_regs_t hw; | ||
| 30 | int i; | ||
| 31 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | ||
| 32 | |||
| 33 | memset(&hw, 0, sizeof(hw)); | ||
| 34 | |||
| 35 | base += BAST_IDE_CS; | ||
| 36 | aux += BAST_IDE_CS; | ||
| 37 | |||
| 38 | for (i = 0; i <= 7; i++) { | ||
| 39 | hw.io_ports_array[i] = (unsigned long)base; | ||
| 40 | base += 0x20; | ||
| 41 | } | ||
| 42 | |||
| 43 | hw.io_ports.ctl_addr = aux + (6 * 0x20); | ||
| 44 | hw.irq = irq; | ||
| 45 | hw.chipset = ide_generic; | ||
| 46 | |||
| 47 | hwif = ide_find_port(); | ||
| 48 | if (hwif == NULL) | ||
| 49 | goto out; | ||
| 50 | |||
| 51 | i = hwif->index; | ||
| 52 | |||
| 53 | ide_init_port_data(hwif, i); | ||
| 54 | ide_init_port_hw(hwif, &hw); | ||
| 55 | hwif->port_ops = NULL; | ||
| 56 | |||
| 57 | idx[0] = i; | ||
| 58 | |||
| 59 | ide_device_add(idx, NULL); | ||
| 60 | out: | ||
| 61 | return 0; | ||
| 62 | } | ||
| 63 | |||
| 64 | static int __init bastide_init(void) | ||
| 65 | { | ||
| 66 | unsigned long base = BAST_VA_IDEPRI + BAST_IDE_CS; | ||
| 67 | |||
| 68 | /* we can treat the VR1000 and the BAST the same */ | ||
| 69 | |||
| 70 | if (!(machine_is_bast() || machine_is_vr1000())) | ||
| 71 | return 0; | ||
| 72 | |||
| 73 | printk("BAST: IDE driver, (c) 2003-2004 Simtec Electronics\n"); | ||
| 74 | |||
| 75 | if (!request_mem_region(base, 0x400000, DRV_NAME)) { | ||
| 76 | printk(KERN_ERR "%s: resources busy\n", DRV_NAME); | ||
| 77 | return -EBUSY; | ||
| 78 | } | ||
| 79 | |||
| 80 | bastide_register(BAST_VA_IDEPRI, BAST_VA_IDEPRIAUX, IRQ_IDE0); | ||
| 81 | bastide_register(BAST_VA_IDESEC, BAST_VA_IDESECAUX, IRQ_IDE1); | ||
| 82 | |||
| 83 | return 0; | ||
| 84 | } | ||
| 85 | |||
| 86 | module_init(bastide_init); | ||
| 87 | |||
| 88 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); | ||
| 89 | MODULE_LICENSE("GPL"); | ||
| 90 | MODULE_DESCRIPTION("Simtec BAST / Thorcom VR1000 IDE driver"); | ||
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c index 55ec7f798772..8af88bf0969b 100644 --- a/drivers/ide/ide-proc.c +++ b/drivers/ide/ide-proc.c | |||
| @@ -76,7 +76,7 @@ static int proc_ide_read_mate | |||
| 76 | ide_hwif_t *hwif = (ide_hwif_t *) data; | 76 | ide_hwif_t *hwif = (ide_hwif_t *) data; |
| 77 | int len; | 77 | int len; |
| 78 | 78 | ||
| 79 | if (hwif && hwif->mate && hwif->mate->present) | 79 | if (hwif && hwif->mate) |
| 80 | len = sprintf(page, "%s\n", hwif->mate->name); | 80 | len = sprintf(page, "%s\n", hwif->mate->name); |
| 81 | else | 81 | else |
| 82 | len = sprintf(page, "(none)\n"); | 82 | len = sprintf(page, "(none)\n"); |
diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c index eebc72465fc9..72c63e5dd630 100644 --- a/drivers/input/ff-core.c +++ b/drivers/input/ff-core.c | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | #include <linux/input.h> | 28 | #include <linux/input.h> |
| 29 | #include <linux/module.h> | 29 | #include <linux/module.h> |
| 30 | #include <linux/mutex.h> | 30 | #include <linux/mutex.h> |
| 31 | #include <linux/sched.h> | ||
| 31 | 32 | ||
| 32 | /* | 33 | /* |
| 33 | * Check that the effect_id is a valid effect and whether the user | 34 | * 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, | |||
| 166 | if (ret) | 167 | if (ret) |
| 167 | goto out; | 168 | goto out; |
| 168 | 169 | ||
| 170 | spin_lock_irq(&dev->event_lock); | ||
| 169 | ff->effects[id] = *effect; | 171 | ff->effects[id] = *effect; |
| 170 | ff->effect_owners[id] = file; | 172 | ff->effect_owners[id] = file; |
| 173 | spin_unlock_irq(&dev->event_lock); | ||
| 171 | 174 | ||
| 172 | out: | 175 | out: |
| 173 | mutex_unlock(&ff->mutex); | 176 | mutex_unlock(&ff->mutex); |
| @@ -189,16 +192,22 @@ static int erase_effect(struct input_dev *dev, int effect_id, | |||
| 189 | if (error) | 192 | if (error) |
| 190 | return error; | 193 | return error; |
| 191 | 194 | ||
| 195 | spin_lock_irq(&dev->event_lock); | ||
| 192 | ff->playback(dev, effect_id, 0); | 196 | ff->playback(dev, effect_id, 0); |
| 197 | ff->effect_owners[effect_id] = NULL; | ||
| 198 | spin_unlock_irq(&dev->event_lock); | ||
| 193 | 199 | ||
| 194 | if (ff->erase) { | 200 | if (ff->erase) { |
| 195 | error = ff->erase(dev, effect_id); | 201 | error = ff->erase(dev, effect_id); |
| 196 | if (error) | 202 | if (error) { |
| 203 | spin_lock_irq(&dev->event_lock); | ||
| 204 | ff->effect_owners[effect_id] = file; | ||
| 205 | spin_unlock_irq(&dev->event_lock); | ||
| 206 | |||
| 197 | return error; | 207 | return error; |
| 208 | } | ||
| 198 | } | 209 | } |
| 199 | 210 | ||
| 200 | ff->effect_owners[effect_id] = NULL; | ||
| 201 | |||
| 202 | return 0; | 211 | return 0; |
| 203 | } | 212 | } |
| 204 | 213 | ||
| @@ -263,8 +272,6 @@ int input_ff_event(struct input_dev *dev, unsigned int type, | |||
| 263 | if (type != EV_FF) | 272 | if (type != EV_FF) |
| 264 | return 0; | 273 | return 0; |
| 265 | 274 | ||
| 266 | mutex_lock(&ff->mutex); | ||
| 267 | |||
| 268 | switch (code) { | 275 | switch (code) { |
| 269 | case FF_GAIN: | 276 | case FF_GAIN: |
| 270 | if (!test_bit(FF_GAIN, dev->ffbit) || value > 0xffff) | 277 | if (!test_bit(FF_GAIN, dev->ffbit) || value > 0xffff) |
| @@ -286,7 +293,6 @@ int input_ff_event(struct input_dev *dev, unsigned int type, | |||
| 286 | break; | 293 | break; |
| 287 | } | 294 | } |
| 288 | 295 | ||
| 289 | mutex_unlock(&ff->mutex); | ||
| 290 | return 0; | 296 | return 0; |
| 291 | } | 297 | } |
| 292 | EXPORT_SYMBOL_GPL(input_ff_event); | 298 | EXPORT_SYMBOL_GPL(input_ff_event); |
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 835def11419d..ab6a61db63ce 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c | |||
| @@ -432,6 +432,7 @@ static int crypt_convert(struct crypt_config *cc, | |||
| 432 | case 0: | 432 | case 0: |
| 433 | atomic_dec(&ctx->pending); | 433 | atomic_dec(&ctx->pending); |
| 434 | ctx->sector++; | 434 | ctx->sector++; |
| 435 | cond_resched(); | ||
| 435 | continue; | 436 | continue; |
| 436 | 437 | ||
| 437 | /* error */ | 438 | /* error */ |
diff --git a/drivers/md/md.c b/drivers/md/md.c index 7cf512a34ccf..2580ac1b9b0f 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c | |||
| @@ -3897,8 +3897,10 @@ static void autorun_devices(int part) | |||
| 3897 | 3897 | ||
| 3898 | md_probe(dev, NULL, NULL); | 3898 | md_probe(dev, NULL, NULL); |
| 3899 | mddev = mddev_find(dev); | 3899 | mddev = mddev_find(dev); |
| 3900 | if (!mddev) { | 3900 | if (!mddev || !mddev->gendisk) { |
| 3901 | printk(KERN_ERR | 3901 | if (mddev) |
| 3902 | mddev_put(mddev); | ||
| 3903 | printk(KERN_ERR | ||
| 3902 | "md: cannot allocate memory for md drive.\n"); | 3904 | "md: cannot allocate memory for md drive.\n"); |
| 3903 | break; | 3905 | break; |
| 3904 | } | 3906 | } |
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 1de17da34a95..a71277b640ab 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c | |||
| @@ -2137,6 +2137,8 @@ static int run(mddev_t *mddev) | |||
| 2137 | !test_bit(In_sync, &disk->rdev->flags)) { | 2137 | !test_bit(In_sync, &disk->rdev->flags)) { |
| 2138 | disk->head_position = 0; | 2138 | disk->head_position = 0; |
| 2139 | mddev->degraded++; | 2139 | mddev->degraded++; |
| 2140 | if (disk->rdev) | ||
| 2141 | conf->fullsync = 1; | ||
| 2140 | } | 2142 | } |
| 2141 | } | 2143 | } |
| 2142 | 2144 | ||
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index c37e256b1176..54c8ee28fcc4 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c | |||
| @@ -2898,6 +2898,8 @@ static void handle_stripe5(struct stripe_head *sh) | |||
| 2898 | 2898 | ||
| 2899 | for (i = conf->raid_disks; i--; ) { | 2899 | for (i = conf->raid_disks; i--; ) { |
| 2900 | set_bit(R5_Wantwrite, &sh->dev[i].flags); | 2900 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
| 2901 | set_bit(R5_LOCKED, &dev->flags); | ||
| 2902 | s.locked++; | ||
| 2901 | if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending)) | 2903 | if (!test_and_set_bit(STRIPE_OP_IO, &sh->ops.pending)) |
| 2902 | sh->ops.count++; | 2904 | sh->ops.count++; |
| 2903 | } | 2905 | } |
| @@ -2911,6 +2913,7 @@ static void handle_stripe5(struct stripe_head *sh) | |||
| 2911 | conf->raid_disks); | 2913 | conf->raid_disks); |
| 2912 | s.locked += handle_write_operations5(sh, 1, 1); | 2914 | s.locked += handle_write_operations5(sh, 1, 1); |
| 2913 | } else if (s.expanded && | 2915 | } else if (s.expanded && |
| 2916 | s.locked == 0 && | ||
| 2914 | !test_bit(STRIPE_OP_POSTXOR, &sh->ops.pending)) { | 2917 | !test_bit(STRIPE_OP_POSTXOR, &sh->ops.pending)) { |
| 2915 | clear_bit(STRIPE_EXPAND_READY, &sh->state); | 2918 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
| 2916 | atomic_dec(&conf->reshape_stripes); | 2919 | atomic_dec(&conf->reshape_stripes); |
| @@ -4305,7 +4308,9 @@ static int run(mddev_t *mddev) | |||
| 4305 | " disk %d\n", bdevname(rdev->bdev,b), | 4308 | " disk %d\n", bdevname(rdev->bdev,b), |
| 4306 | raid_disk); | 4309 | raid_disk); |
| 4307 | working_disks++; | 4310 | working_disks++; |
| 4308 | } | 4311 | } else |
| 4312 | /* Cannot rely on bitmap to complete recovery */ | ||
| 4313 | conf->fullsync = 1; | ||
| 4309 | } | 4314 | } |
| 4310 | 4315 | ||
| 4311 | /* | 4316 | /* |
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index 3b26fbd3e558..5ccb0aeca8cc 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig | |||
| @@ -793,6 +793,14 @@ menuconfig V4L_USB_DRIVERS | |||
| 793 | 793 | ||
| 794 | if V4L_USB_DRIVERS && USB | 794 | if V4L_USB_DRIVERS && USB |
| 795 | 795 | ||
| 796 | config USB_VIDEO_CLASS | ||
| 797 | tristate "USB Video Class (UVC)" | ||
| 798 | ---help--- | ||
| 799 | Support for the USB Video Class (UVC). Currently only video | ||
| 800 | input devices, such as webcams, are supported. | ||
| 801 | |||
| 802 | For more information see: <http://linux-uvc.berlios.de/> | ||
| 803 | |||
| 796 | source "drivers/media/video/pvrusb2/Kconfig" | 804 | source "drivers/media/video/pvrusb2/Kconfig" |
| 797 | 805 | ||
| 798 | source "drivers/media/video/em28xx/Kconfig" | 806 | source "drivers/media/video/em28xx/Kconfig" |
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index dff0d6abe917..ecbbfaab24d5 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile | |||
| @@ -136,6 +136,8 @@ obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o | |||
| 136 | 136 | ||
| 137 | obj-$(CONFIG_VIDEO_AU0828) += au0828/ | 137 | obj-$(CONFIG_VIDEO_AU0828) += au0828/ |
| 138 | 138 | ||
| 139 | obj-$(CONFIG_USB_VIDEO_CLASS) += uvc/ | ||
| 140 | |||
| 139 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core | 141 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core |
| 140 | EXTRA_CFLAGS += -Idrivers/media/dvb/frontends | 142 | EXTRA_CFLAGS += -Idrivers/media/dvb/frontends |
| 141 | EXTRA_CFLAGS += -Idrivers/media/common/tuners | 143 | EXTRA_CFLAGS += -Idrivers/media/common/tuners |
diff --git a/drivers/media/video/uvc/Makefile b/drivers/media/video/uvc/Makefile new file mode 100644 index 000000000000..968c1994eda0 --- /dev/null +++ b/drivers/media/video/uvc/Makefile | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | uvcvideo-objs := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o \ | ||
| 2 | uvc_status.o uvc_isight.o | ||
| 3 | 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 index 000000000000..f0ee46d15540 --- /dev/null +++ b/drivers/media/video/uvc/uvc_ctrl.c | |||
| @@ -0,0 +1,1256 @@ | |||
| 1 | /* | ||
| 2 | * uvc_ctrl.c -- USB Video Class driver - Controls | ||
| 3 | * | ||
| 4 | * Copyright (C) 2005-2008 | ||
| 5 | * Laurent Pinchart (laurent.pinchart@skynet.be) | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/version.h> | ||
| 16 | #include <linux/list.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/uaccess.h> | ||
| 19 | #include <linux/usb.h> | ||
| 20 | #include <linux/videodev2.h> | ||
| 21 | #include <linux/vmalloc.h> | ||
| 22 | #include <linux/wait.h> | ||
| 23 | #include <asm/atomic.h> | ||
| 24 | |||
| 25 | #include "uvcvideo.h" | ||
| 26 | |||
| 27 | #define UVC_CTRL_NDATA 2 | ||
| 28 | #define UVC_CTRL_DATA_CURRENT 0 | ||
| 29 | #define UVC_CTRL_DATA_BACKUP 1 | ||
| 30 | |||
| 31 | /* ------------------------------------------------------------------------ | ||
| 32 | * Control, formats, ... | ||
| 33 | */ | ||
| 34 | |||
| 35 | static struct uvc_control_info uvc_ctrls[] = { | ||
| 36 | { | ||
| 37 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 38 | .selector = PU_BRIGHTNESS_CONTROL, | ||
| 39 | .index = 0, | ||
| 40 | .size = 2, | ||
| 41 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 42 | | UVC_CONTROL_RESTORE, | ||
| 43 | }, | ||
| 44 | { | ||
| 45 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 46 | .selector = PU_CONTRAST_CONTROL, | ||
| 47 | .index = 1, | ||
| 48 | .size = 2, | ||
| 49 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 50 | | UVC_CONTROL_RESTORE, | ||
| 51 | }, | ||
| 52 | { | ||
| 53 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 54 | .selector = PU_HUE_CONTROL, | ||
| 55 | .index = 2, | ||
| 56 | .size = 2, | ||
| 57 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 58 | | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE, | ||
| 59 | }, | ||
| 60 | { | ||
| 61 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 62 | .selector = PU_SATURATION_CONTROL, | ||
| 63 | .index = 3, | ||
| 64 | .size = 2, | ||
| 65 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 66 | | UVC_CONTROL_RESTORE, | ||
| 67 | }, | ||
| 68 | { | ||
| 69 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 70 | .selector = PU_SHARPNESS_CONTROL, | ||
| 71 | .index = 4, | ||
| 72 | .size = 2, | ||
| 73 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 74 | | UVC_CONTROL_RESTORE, | ||
| 75 | }, | ||
| 76 | { | ||
| 77 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 78 | .selector = PU_GAMMA_CONTROL, | ||
| 79 | .index = 5, | ||
| 80 | .size = 2, | ||
| 81 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 82 | | UVC_CONTROL_RESTORE, | ||
| 83 | }, | ||
| 84 | { | ||
| 85 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 86 | .selector = PU_BACKLIGHT_COMPENSATION_CONTROL, | ||
| 87 | .index = 8, | ||
| 88 | .size = 2, | ||
| 89 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 90 | | UVC_CONTROL_RESTORE, | ||
| 91 | }, | ||
| 92 | { | ||
| 93 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 94 | .selector = PU_GAIN_CONTROL, | ||
| 95 | .index = 9, | ||
| 96 | .size = 2, | ||
| 97 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 98 | | UVC_CONTROL_RESTORE, | ||
| 99 | }, | ||
| 100 | { | ||
| 101 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 102 | .selector = PU_POWER_LINE_FREQUENCY_CONTROL, | ||
| 103 | .index = 10, | ||
| 104 | .size = 1, | ||
| 105 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 106 | | UVC_CONTROL_RESTORE, | ||
| 107 | }, | ||
| 108 | { | ||
| 109 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 110 | .selector = PU_HUE_AUTO_CONTROL, | ||
| 111 | .index = 11, | ||
| 112 | .size = 1, | ||
| 113 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR | ||
| 114 | | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE, | ||
| 115 | }, | ||
| 116 | { | ||
| 117 | .entity = UVC_GUID_UVC_CAMERA, | ||
| 118 | .selector = CT_AE_MODE_CONTROL, | ||
| 119 | .index = 1, | ||
| 120 | .size = 1, | ||
| 121 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR | ||
| 122 | | UVC_CONTROL_GET_DEF | UVC_CONTROL_GET_RES | ||
| 123 | | UVC_CONTROL_RESTORE, | ||
| 124 | }, | ||
| 125 | { | ||
| 126 | .entity = UVC_GUID_UVC_CAMERA, | ||
| 127 | .selector = CT_AE_PRIORITY_CONTROL, | ||
| 128 | .index = 2, | ||
| 129 | .size = 1, | ||
| 130 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR | ||
| 131 | | UVC_CONTROL_RESTORE, | ||
| 132 | }, | ||
| 133 | { | ||
| 134 | .entity = UVC_GUID_UVC_CAMERA, | ||
| 135 | .selector = CT_EXPOSURE_TIME_ABSOLUTE_CONTROL, | ||
| 136 | .index = 3, | ||
| 137 | .size = 4, | ||
| 138 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 139 | | UVC_CONTROL_RESTORE, | ||
| 140 | }, | ||
| 141 | { | ||
| 142 | .entity = UVC_GUID_UVC_CAMERA, | ||
| 143 | .selector = CT_FOCUS_ABSOLUTE_CONTROL, | ||
| 144 | .index = 5, | ||
| 145 | .size = 2, | ||
| 146 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 147 | | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE, | ||
| 148 | }, | ||
| 149 | { | ||
| 150 | .entity = UVC_GUID_UVC_CAMERA, | ||
| 151 | .selector = CT_FOCUS_AUTO_CONTROL, | ||
| 152 | .index = 17, | ||
| 153 | .size = 1, | ||
| 154 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR | ||
| 155 | | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE, | ||
| 156 | }, | ||
| 157 | { | ||
| 158 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 159 | .selector = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, | ||
| 160 | .index = 12, | ||
| 161 | .size = 1, | ||
| 162 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR | ||
| 163 | | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE, | ||
| 164 | }, | ||
| 165 | { | ||
| 166 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 167 | .selector = PU_WHITE_BALANCE_TEMPERATURE_CONTROL, | ||
| 168 | .index = 6, | ||
| 169 | .size = 2, | ||
| 170 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 171 | | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE, | ||
| 172 | }, | ||
| 173 | { | ||
| 174 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 175 | .selector = PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL, | ||
| 176 | .index = 13, | ||
| 177 | .size = 1, | ||
| 178 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR | ||
| 179 | | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE, | ||
| 180 | }, | ||
| 181 | { | ||
| 182 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 183 | .selector = PU_WHITE_BALANCE_COMPONENT_CONTROL, | ||
| 184 | .index = 7, | ||
| 185 | .size = 4, | ||
| 186 | .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE | ||
| 187 | | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE, | ||
| 188 | }, | ||
| 189 | }; | ||
| 190 | |||
| 191 | static struct uvc_menu_info power_line_frequency_controls[] = { | ||
| 192 | { 0, "Disabled" }, | ||
| 193 | { 1, "50 Hz" }, | ||
| 194 | { 2, "60 Hz" }, | ||
| 195 | }; | ||
| 196 | |||
| 197 | static struct uvc_menu_info exposure_auto_controls[] = { | ||
| 198 | { 1, "Manual Mode" }, | ||
| 199 | { 2, "Auto Mode" }, | ||
| 200 | { 4, "Shutter Priority Mode" }, | ||
| 201 | { 8, "Aperture Priority Mode" }, | ||
| 202 | }; | ||
| 203 | |||
| 204 | static struct uvc_control_mapping uvc_ctrl_mappings[] = { | ||
| 205 | { | ||
| 206 | .id = V4L2_CID_BRIGHTNESS, | ||
| 207 | .name = "Brightness", | ||
| 208 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 209 | .selector = PU_BRIGHTNESS_CONTROL, | ||
| 210 | .size = 16, | ||
| 211 | .offset = 0, | ||
| 212 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 213 | .data_type = UVC_CTRL_DATA_TYPE_SIGNED, | ||
| 214 | }, | ||
| 215 | { | ||
| 216 | .id = V4L2_CID_CONTRAST, | ||
| 217 | .name = "Contrast", | ||
| 218 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 219 | .selector = PU_CONTRAST_CONTROL, | ||
| 220 | .size = 16, | ||
| 221 | .offset = 0, | ||
| 222 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 223 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, | ||
| 224 | }, | ||
| 225 | { | ||
| 226 | .id = V4L2_CID_HUE, | ||
| 227 | .name = "Hue", | ||
| 228 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 229 | .selector = PU_HUE_CONTROL, | ||
| 230 | .size = 16, | ||
| 231 | .offset = 0, | ||
| 232 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 233 | .data_type = UVC_CTRL_DATA_TYPE_SIGNED, | ||
| 234 | }, | ||
| 235 | { | ||
| 236 | .id = V4L2_CID_SATURATION, | ||
| 237 | .name = "Saturation", | ||
| 238 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 239 | .selector = PU_SATURATION_CONTROL, | ||
| 240 | .size = 16, | ||
| 241 | .offset = 0, | ||
| 242 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 243 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, | ||
| 244 | }, | ||
| 245 | { | ||
| 246 | .id = V4L2_CID_SHARPNESS, | ||
| 247 | .name = "Sharpness", | ||
| 248 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 249 | .selector = PU_SHARPNESS_CONTROL, | ||
| 250 | .size = 16, | ||
| 251 | .offset = 0, | ||
| 252 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 253 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, | ||
| 254 | }, | ||
| 255 | { | ||
| 256 | .id = V4L2_CID_GAMMA, | ||
| 257 | .name = "Gamma", | ||
| 258 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 259 | .selector = PU_GAMMA_CONTROL, | ||
| 260 | .size = 16, | ||
| 261 | .offset = 0, | ||
| 262 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 263 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, | ||
| 264 | }, | ||
| 265 | { | ||
| 266 | .id = V4L2_CID_BACKLIGHT_COMPENSATION, | ||
| 267 | .name = "Backlight Compensation", | ||
| 268 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 269 | .selector = PU_BACKLIGHT_COMPENSATION_CONTROL, | ||
| 270 | .size = 16, | ||
| 271 | .offset = 0, | ||
| 272 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 273 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, | ||
| 274 | }, | ||
| 275 | { | ||
| 276 | .id = V4L2_CID_GAIN, | ||
| 277 | .name = "Gain", | ||
| 278 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 279 | .selector = PU_GAIN_CONTROL, | ||
| 280 | .size = 16, | ||
| 281 | .offset = 0, | ||
| 282 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 283 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, | ||
| 284 | }, | ||
| 285 | { | ||
| 286 | .id = V4L2_CID_POWER_LINE_FREQUENCY, | ||
| 287 | .name = "Power Line Frequency", | ||
| 288 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 289 | .selector = PU_POWER_LINE_FREQUENCY_CONTROL, | ||
| 290 | .size = 2, | ||
| 291 | .offset = 0, | ||
| 292 | .v4l2_type = V4L2_CTRL_TYPE_MENU, | ||
| 293 | .data_type = UVC_CTRL_DATA_TYPE_ENUM, | ||
| 294 | .menu_info = power_line_frequency_controls, | ||
| 295 | .menu_count = ARRAY_SIZE(power_line_frequency_controls), | ||
| 296 | }, | ||
| 297 | { | ||
| 298 | .id = V4L2_CID_HUE_AUTO, | ||
| 299 | .name = "Hue, Auto", | ||
| 300 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 301 | .selector = PU_HUE_AUTO_CONTROL, | ||
| 302 | .size = 1, | ||
| 303 | .offset = 0, | ||
| 304 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, | ||
| 305 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, | ||
| 306 | }, | ||
| 307 | { | ||
| 308 | .id = V4L2_CID_EXPOSURE_AUTO, | ||
| 309 | .name = "Exposure, Auto", | ||
| 310 | .entity = UVC_GUID_UVC_CAMERA, | ||
| 311 | .selector = CT_AE_MODE_CONTROL, | ||
| 312 | .size = 4, | ||
| 313 | .offset = 0, | ||
| 314 | .v4l2_type = V4L2_CTRL_TYPE_MENU, | ||
| 315 | .data_type = UVC_CTRL_DATA_TYPE_BITMASK, | ||
| 316 | .menu_info = exposure_auto_controls, | ||
| 317 | .menu_count = ARRAY_SIZE(exposure_auto_controls), | ||
| 318 | }, | ||
| 319 | { | ||
| 320 | .id = V4L2_CID_EXPOSURE_AUTO_PRIORITY, | ||
| 321 | .name = "Exposure, Auto Priority", | ||
| 322 | .entity = UVC_GUID_UVC_CAMERA, | ||
| 323 | .selector = CT_AE_PRIORITY_CONTROL, | ||
| 324 | .size = 1, | ||
| 325 | .offset = 0, | ||
| 326 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, | ||
| 327 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, | ||
| 328 | }, | ||
| 329 | { | ||
| 330 | .id = V4L2_CID_EXPOSURE_ABSOLUTE, | ||
| 331 | .name = "Exposure (Absolute)", | ||
| 332 | .entity = UVC_GUID_UVC_CAMERA, | ||
| 333 | .selector = CT_EXPOSURE_TIME_ABSOLUTE_CONTROL, | ||
| 334 | .size = 32, | ||
| 335 | .offset = 0, | ||
| 336 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 337 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, | ||
| 338 | }, | ||
| 339 | { | ||
| 340 | .id = V4L2_CID_AUTO_WHITE_BALANCE, | ||
| 341 | .name = "White Balance Temperature, Auto", | ||
| 342 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 343 | .selector = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, | ||
| 344 | .size = 1, | ||
| 345 | .offset = 0, | ||
| 346 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, | ||
| 347 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, | ||
| 348 | }, | ||
| 349 | { | ||
| 350 | .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE, | ||
| 351 | .name = "White Balance Temperature", | ||
| 352 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 353 | .selector = PU_WHITE_BALANCE_TEMPERATURE_CONTROL, | ||
| 354 | .size = 16, | ||
| 355 | .offset = 0, | ||
| 356 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 357 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, | ||
| 358 | }, | ||
| 359 | { | ||
| 360 | .id = V4L2_CID_AUTO_WHITE_BALANCE, | ||
| 361 | .name = "White Balance Component, Auto", | ||
| 362 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 363 | .selector = PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL, | ||
| 364 | .size = 1, | ||
| 365 | .offset = 0, | ||
| 366 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, | ||
| 367 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, | ||
| 368 | }, | ||
| 369 | { | ||
| 370 | .id = V4L2_CID_BLUE_BALANCE, | ||
| 371 | .name = "White Balance Blue Component", | ||
| 372 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 373 | .selector = PU_WHITE_BALANCE_COMPONENT_CONTROL, | ||
| 374 | .size = 16, | ||
| 375 | .offset = 0, | ||
| 376 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 377 | .data_type = UVC_CTRL_DATA_TYPE_SIGNED, | ||
| 378 | }, | ||
| 379 | { | ||
| 380 | .id = V4L2_CID_RED_BALANCE, | ||
| 381 | .name = "White Balance Red Component", | ||
| 382 | .entity = UVC_GUID_UVC_PROCESSING, | ||
| 383 | .selector = PU_WHITE_BALANCE_COMPONENT_CONTROL, | ||
| 384 | .size = 16, | ||
| 385 | .offset = 16, | ||
| 386 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 387 | .data_type = UVC_CTRL_DATA_TYPE_SIGNED, | ||
| 388 | }, | ||
| 389 | { | ||
| 390 | .id = V4L2_CID_FOCUS_ABSOLUTE, | ||
| 391 | .name = "Focus (absolute)", | ||
| 392 | .entity = UVC_GUID_UVC_CAMERA, | ||
| 393 | .selector = CT_FOCUS_ABSOLUTE_CONTROL, | ||
| 394 | .size = 16, | ||
| 395 | .offset = 0, | ||
| 396 | .v4l2_type = V4L2_CTRL_TYPE_INTEGER, | ||
| 397 | .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, | ||
| 398 | }, | ||
| 399 | { | ||
| 400 | .id = V4L2_CID_FOCUS_AUTO, | ||
| 401 | .name = "Focus, Auto", | ||
| 402 | .entity = UVC_GUID_UVC_CAMERA, | ||
| 403 | .selector = CT_FOCUS_AUTO_CONTROL, | ||
| 404 | .size = 1, | ||
| 405 | .offset = 0, | ||
| 406 | .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, | ||
| 407 | .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, | ||
| 408 | }, | ||
| 409 | }; | ||
| 410 | |||
| 411 | /* ------------------------------------------------------------------------ | ||
| 412 | * Utility functions | ||
| 413 | */ | ||
| 414 | |||
| 415 | static inline __u8 *uvc_ctrl_data(struct uvc_control *ctrl, int id) | ||
| 416 | { | ||
| 417 | return ctrl->data + id * ctrl->info->size; | ||
| 418 | } | ||
| 419 | |||
| 420 | static inline int uvc_get_bit(const __u8 *data, int bit) | ||
| 421 | { | ||
| 422 | return (data[bit >> 3] >> (bit & 7)) & 1; | ||
| 423 | } | ||
| 424 | |||
| 425 | /* Extract the bit string specified by mapping->offset and mapping->size | ||
| 426 | * from the little-endian data stored at 'data' and return the result as | ||
| 427 | * a signed 32bit integer. Sign extension will be performed if the mapping | ||
| 428 | * references a signed data type. | ||
| 429 | */ | ||
| 430 | static __s32 uvc_get_le_value(const __u8 *data, | ||
| 431 | struct uvc_control_mapping *mapping) | ||
| 432 | { | ||
| 433 | int bits = mapping->size; | ||
| 434 | int offset = mapping->offset; | ||
| 435 | __s32 value = 0; | ||
| 436 | __u8 mask; | ||
| 437 | |||
| 438 | data += offset / 8; | ||
| 439 | offset &= 7; | ||
| 440 | mask = ((1LL << bits) - 1) << offset; | ||
| 441 | |||
| 442 | for (; bits > 0; data++) { | ||
| 443 | __u8 byte = *data & mask; | ||
| 444 | value |= offset > 0 ? (byte >> offset) : (byte << (-offset)); | ||
| 445 | bits -= 8 - (offset > 0 ? offset : 0); | ||
| 446 | offset -= 8; | ||
| 447 | mask = (1 << bits) - 1; | ||
| 448 | } | ||
| 449 | |||
| 450 | /* Sign-extend the value if needed */ | ||
| 451 | if (mapping->data_type == UVC_CTRL_DATA_TYPE_SIGNED) | ||
| 452 | value |= -(value & (1 << (mapping->size - 1))); | ||
| 453 | |||
| 454 | return value; | ||
| 455 | } | ||
| 456 | |||
| 457 | /* Set the bit string specified by mapping->offset and mapping->size | ||
| 458 | * in the little-endian data stored at 'data' to the value 'value'. | ||
| 459 | */ | ||
| 460 | static void uvc_set_le_value(__s32 value, __u8 *data, | ||
| 461 | struct uvc_control_mapping *mapping) | ||
| 462 | { | ||
| 463 | int bits = mapping->size; | ||
| 464 | int offset = mapping->offset; | ||
| 465 | __u8 mask; | ||
| 466 | |||
| 467 | data += offset / 8; | ||
| 468 | offset &= 7; | ||
| 469 | |||
| 470 | for (; bits > 0; data++) { | ||
| 471 | mask = ((1LL << bits) - 1) << offset; | ||
| 472 | *data = (*data & ~mask) | ((value << offset) & mask); | ||
| 473 | value >>= offset ? offset : 8; | ||
| 474 | bits -= 8 - offset; | ||
| 475 | offset = 0; | ||
| 476 | } | ||
| 477 | } | ||
| 478 | |||
| 479 | /* ------------------------------------------------------------------------ | ||
| 480 | * Terminal and unit management | ||
| 481 | */ | ||
| 482 | |||
| 483 | static const __u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; | ||
| 484 | static const __u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA; | ||
| 485 | static const __u8 uvc_media_transport_input_guid[16] = | ||
| 486 | UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; | ||
| 487 | |||
| 488 | static int uvc_entity_match_guid(struct uvc_entity *entity, __u8 guid[16]) | ||
| 489 | { | ||
| 490 | switch (UVC_ENTITY_TYPE(entity)) { | ||
| 491 | case ITT_CAMERA: | ||
| 492 | return memcmp(uvc_camera_guid, guid, 16) == 0; | ||
| 493 | |||
| 494 | case ITT_MEDIA_TRANSPORT_INPUT: | ||
| 495 | return memcmp(uvc_media_transport_input_guid, guid, 16) == 0; | ||
| 496 | |||
| 497 | case VC_PROCESSING_UNIT: | ||
| 498 | return memcmp(uvc_processing_guid, guid, 16) == 0; | ||
| 499 | |||
| 500 | case VC_EXTENSION_UNIT: | ||
| 501 | return memcmp(entity->extension.guidExtensionCode, | ||
| 502 | guid, 16) == 0; | ||
| 503 | |||
| 504 | default: | ||
| 505 | return 0; | ||
| 506 | } | ||
| 507 | } | ||
| 508 | |||
| 509 | /* ------------------------------------------------------------------------ | ||
| 510 | * UVC Controls | ||
| 511 | */ | ||
| 512 | |||
| 513 | static void __uvc_find_control(struct uvc_entity *entity, __u32 v4l2_id, | ||
| 514 | struct uvc_control_mapping **mapping, struct uvc_control **control, | ||
| 515 | int next) | ||
| 516 | { | ||
| 517 | struct uvc_control *ctrl; | ||
| 518 | struct uvc_control_mapping *map; | ||
| 519 | unsigned int i; | ||
| 520 | |||
| 521 | if (entity == NULL) | ||
| 522 | return; | ||
| 523 | |||
| 524 | for (i = 0; i < entity->ncontrols; ++i) { | ||
| 525 | ctrl = &entity->controls[i]; | ||
| 526 | if (ctrl->info == NULL) | ||
| 527 | continue; | ||
| 528 | |||
| 529 | list_for_each_entry(map, &ctrl->info->mappings, list) { | ||
| 530 | if ((map->id == v4l2_id) && !next) { | ||
| 531 | *control = ctrl; | ||
| 532 | *mapping = map; | ||
| 533 | return; | ||
| 534 | } | ||
| 535 | |||
| 536 | if ((*mapping == NULL || (*mapping)->id > map->id) && | ||
| 537 | (map->id > v4l2_id) && next) { | ||
| 538 | *control = ctrl; | ||
| 539 | *mapping = map; | ||
| 540 | } | ||
| 541 | } | ||
| 542 | } | ||
| 543 | } | ||
| 544 | |||
| 545 | struct uvc_control *uvc_find_control(struct uvc_video_device *video, | ||
| 546 | __u32 v4l2_id, struct uvc_control_mapping **mapping) | ||
| 547 | { | ||
| 548 | struct uvc_control *ctrl = NULL; | ||
| 549 | struct uvc_entity *entity; | ||
| 550 | int next = v4l2_id & V4L2_CTRL_FLAG_NEXT_CTRL; | ||
| 551 | |||
| 552 | *mapping = NULL; | ||
| 553 | |||
| 554 | /* Mask the query flags. */ | ||
| 555 | v4l2_id &= V4L2_CTRL_ID_MASK; | ||
| 556 | |||
| 557 | /* Find the control. */ | ||
| 558 | __uvc_find_control(video->processing, v4l2_id, mapping, &ctrl, next); | ||
| 559 | if (ctrl && !next) | ||
| 560 | return ctrl; | ||
| 561 | |||
| 562 | list_for_each_entry(entity, &video->iterms, chain) { | ||
| 563 | __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next); | ||
| 564 | if (ctrl && !next) | ||
| 565 | return ctrl; | ||
| 566 | } | ||
| 567 | |||
| 568 | list_for_each_entry(entity, &video->extensions, chain) { | ||
| 569 | __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next); | ||
| 570 | if (ctrl && !next) | ||
| 571 | return ctrl; | ||
| 572 | } | ||
| 573 | |||
| 574 | if (ctrl == NULL && !next) | ||
| 575 | uvc_trace(UVC_TRACE_CONTROL, "Control 0x%08x not found.\n", | ||
| 576 | v4l2_id); | ||
| 577 | |||
| 578 | return ctrl; | ||
| 579 | } | ||
| 580 | |||
| 581 | int uvc_query_v4l2_ctrl(struct uvc_video_device *video, | ||
| 582 | struct v4l2_queryctrl *v4l2_ctrl) | ||
| 583 | { | ||
| 584 | struct uvc_control *ctrl; | ||
| 585 | struct uvc_control_mapping *mapping; | ||
| 586 | struct uvc_menu_info *menu; | ||
| 587 | unsigned int i; | ||
| 588 | __u8 data[8]; | ||
| 589 | int ret; | ||
| 590 | |||
| 591 | ctrl = uvc_find_control(video, v4l2_ctrl->id, &mapping); | ||
| 592 | if (ctrl == NULL) | ||
| 593 | return -EINVAL; | ||
| 594 | |||
| 595 | v4l2_ctrl->id = mapping->id; | ||
| 596 | v4l2_ctrl->type = mapping->v4l2_type; | ||
| 597 | strncpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name); | ||
| 598 | v4l2_ctrl->flags = 0; | ||
| 599 | |||
| 600 | if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR)) | ||
| 601 | v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; | ||
| 602 | |||
| 603 | if (ctrl->info->flags & UVC_CONTROL_GET_DEF) { | ||
| 604 | if ((ret = uvc_query_ctrl(video->dev, GET_DEF, ctrl->entity->id, | ||
| 605 | video->dev->intfnum, ctrl->info->selector, | ||
| 606 | &data, ctrl->info->size)) < 0) | ||
| 607 | return ret; | ||
| 608 | v4l2_ctrl->default_value = uvc_get_le_value(data, mapping); | ||
| 609 | } | ||
| 610 | |||
| 611 | if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) { | ||
| 612 | v4l2_ctrl->minimum = 0; | ||
| 613 | v4l2_ctrl->maximum = mapping->menu_count - 1; | ||
| 614 | v4l2_ctrl->step = 1; | ||
| 615 | |||
| 616 | menu = mapping->menu_info; | ||
| 617 | for (i = 0; i < mapping->menu_count; ++i, ++menu) { | ||
| 618 | if (menu->value == v4l2_ctrl->default_value) { | ||
| 619 | v4l2_ctrl->default_value = i; | ||
| 620 | break; | ||
| 621 | } | ||
| 622 | } | ||
| 623 | |||
| 624 | return 0; | ||
| 625 | } | ||
| 626 | |||
| 627 | if (ctrl->info->flags & UVC_CONTROL_GET_MIN) { | ||
| 628 | if ((ret = uvc_query_ctrl(video->dev, GET_MIN, ctrl->entity->id, | ||
| 629 | video->dev->intfnum, ctrl->info->selector, | ||
| 630 | &data, ctrl->info->size)) < 0) | ||
| 631 | return ret; | ||
| 632 | v4l2_ctrl->minimum = uvc_get_le_value(data, mapping); | ||
| 633 | } | ||
| 634 | if (ctrl->info->flags & UVC_CONTROL_GET_MAX) { | ||
| 635 | if ((ret = uvc_query_ctrl(video->dev, GET_MAX, ctrl->entity->id, | ||
| 636 | video->dev->intfnum, ctrl->info->selector, | ||
| 637 | &data, ctrl->info->size)) < 0) | ||
| 638 | return ret; | ||
| 639 | v4l2_ctrl->maximum = uvc_get_le_value(data, mapping); | ||
| 640 | } | ||
| 641 | if (ctrl->info->flags & UVC_CONTROL_GET_RES) { | ||
| 642 | if ((ret = uvc_query_ctrl(video->dev, GET_RES, ctrl->entity->id, | ||
| 643 | video->dev->intfnum, ctrl->info->selector, | ||
| 644 | &data, ctrl->info->size)) < 0) | ||
| 645 | return ret; | ||
| 646 | v4l2_ctrl->step = uvc_get_le_value(data, mapping); | ||
| 647 | } | ||
| 648 | |||
| 649 | return 0; | ||
| 650 | } | ||
| 651 | |||
| 652 | |||
| 653 | /* -------------------------------------------------------------------------- | ||
| 654 | * Control transactions | ||
| 655 | * | ||
| 656 | * To make extended set operations as atomic as the hardware allows, controls | ||
| 657 | * are handled using begin/commit/rollback operations. | ||
| 658 | * | ||
| 659 | * At the beginning of a set request, uvc_ctrl_begin should be called to | ||
| 660 | * initialize the request. This function acquires the control lock. | ||
| 661 | * | ||
| 662 | * When setting a control, the new value is stored in the control data field | ||
| 663 | * at position UVC_CTRL_DATA_CURRENT. The control is then marked as dirty for | ||
| 664 | * later processing. If the UVC and V4L2 control sizes differ, the current | ||
| 665 | * value is loaded from the hardware before storing the new value in the data | ||
| 666 | * field. | ||
| 667 | * | ||
| 668 | * After processing all controls in the transaction, uvc_ctrl_commit or | ||
| 669 | * uvc_ctrl_rollback must be called to apply the pending changes to the | ||
| 670 | * hardware or revert them. When applying changes, all controls marked as | ||
| 671 | * dirty will be modified in the UVC device, and the dirty flag will be | ||
| 672 | * cleared. When reverting controls, the control data field | ||
| 673 | * UVC_CTRL_DATA_CURRENT is reverted to its previous value | ||
| 674 | * (UVC_CTRL_DATA_BACKUP) for all dirty controls. Both functions release the | ||
| 675 | * control lock. | ||
| 676 | */ | ||
| 677 | int uvc_ctrl_begin(struct uvc_video_device *video) | ||
| 678 | { | ||
| 679 | return mutex_lock_interruptible(&video->ctrl_mutex) ? -ERESTARTSYS : 0; | ||
| 680 | } | ||
| 681 | |||
| 682 | static int uvc_ctrl_commit_entity(struct uvc_device *dev, | ||
| 683 | struct uvc_entity *entity, int rollback) | ||
| 684 | { | ||
| 685 | struct uvc_control *ctrl; | ||
| 686 | unsigned int i; | ||
| 687 | int ret; | ||
| 688 | |||
| 689 | if (entity == NULL) | ||
| 690 | return 0; | ||
| 691 | |||
| 692 | for (i = 0; i < entity->ncontrols; ++i) { | ||
| 693 | ctrl = &entity->controls[i]; | ||
| 694 | if (ctrl->info == NULL || !ctrl->dirty) | ||
| 695 | continue; | ||
| 696 | |||
| 697 | if (!rollback) | ||
| 698 | ret = uvc_query_ctrl(dev, SET_CUR, ctrl->entity->id, | ||
| 699 | dev->intfnum, ctrl->info->selector, | ||
| 700 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), | ||
| 701 | ctrl->info->size); | ||
| 702 | else | ||
| 703 | ret = 0; | ||
| 704 | |||
| 705 | if (rollback || ret < 0) | ||
| 706 | memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), | ||
| 707 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), | ||
| 708 | ctrl->info->size); | ||
| 709 | |||
| 710 | if ((ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0) | ||
| 711 | ctrl->loaded = 0; | ||
| 712 | |||
| 713 | ctrl->dirty = 0; | ||
| 714 | |||
| 715 | if (ret < 0) | ||
| 716 | return ret; | ||
| 717 | } | ||
| 718 | |||
| 719 | return 0; | ||
| 720 | } | ||
| 721 | |||
| 722 | int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback) | ||
| 723 | { | ||
| 724 | struct uvc_entity *entity; | ||
| 725 | int ret = 0; | ||
| 726 | |||
| 727 | /* Find the control. */ | ||
| 728 | ret = uvc_ctrl_commit_entity(video->dev, video->processing, rollback); | ||
| 729 | if (ret < 0) | ||
| 730 | goto done; | ||
| 731 | |||
| 732 | list_for_each_entry(entity, &video->iterms, chain) { | ||
| 733 | ret = uvc_ctrl_commit_entity(video->dev, entity, rollback); | ||
| 734 | if (ret < 0) | ||
| 735 | goto done; | ||
| 736 | } | ||
| 737 | |||
| 738 | list_for_each_entry(entity, &video->extensions, chain) { | ||
| 739 | ret = uvc_ctrl_commit_entity(video->dev, entity, rollback); | ||
| 740 | if (ret < 0) | ||
| 741 | goto done; | ||
| 742 | } | ||
| 743 | |||
| 744 | done: | ||
| 745 | mutex_unlock(&video->ctrl_mutex); | ||
| 746 | return ret; | ||
| 747 | } | ||
| 748 | |||
| 749 | int uvc_ctrl_get(struct uvc_video_device *video, | ||
| 750 | struct v4l2_ext_control *xctrl) | ||
| 751 | { | ||
| 752 | struct uvc_control *ctrl; | ||
| 753 | struct uvc_control_mapping *mapping; | ||
| 754 | struct uvc_menu_info *menu; | ||
| 755 | unsigned int i; | ||
| 756 | int ret; | ||
| 757 | |||
| 758 | ctrl = uvc_find_control(video, xctrl->id, &mapping); | ||
| 759 | if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0) | ||
| 760 | return -EINVAL; | ||
| 761 | |||
| 762 | if (!ctrl->loaded) { | ||
| 763 | ret = uvc_query_ctrl(video->dev, GET_CUR, ctrl->entity->id, | ||
| 764 | video->dev->intfnum, ctrl->info->selector, | ||
| 765 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), | ||
| 766 | ctrl->info->size); | ||
| 767 | if (ret < 0) | ||
| 768 | return ret; | ||
| 769 | |||
| 770 | if ((ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE) == 0) | ||
| 771 | ctrl->loaded = 1; | ||
| 772 | } | ||
| 773 | |||
| 774 | xctrl->value = uvc_get_le_value( | ||
| 775 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), mapping); | ||
| 776 | |||
| 777 | if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) { | ||
| 778 | menu = mapping->menu_info; | ||
| 779 | for (i = 0; i < mapping->menu_count; ++i, ++menu) { | ||
| 780 | if (menu->value == xctrl->value) { | ||
| 781 | xctrl->value = i; | ||
| 782 | break; | ||
| 783 | } | ||
| 784 | } | ||
| 785 | } | ||
| 786 | |||
| 787 | return 0; | ||
| 788 | } | ||
| 789 | |||
| 790 | int uvc_ctrl_set(struct uvc_video_device *video, | ||
| 791 | struct v4l2_ext_control *xctrl) | ||
| 792 | { | ||
| 793 | struct uvc_control *ctrl; | ||
| 794 | struct uvc_control_mapping *mapping; | ||
| 795 | s32 value = xctrl->value; | ||
| 796 | int ret; | ||
| 797 | |||
| 798 | ctrl = uvc_find_control(video, xctrl->id, &mapping); | ||
| 799 | if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_SET_CUR) == 0) | ||
| 800 | return -EINVAL; | ||
| 801 | |||
| 802 | if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) { | ||
| 803 | if (value < 0 || value >= mapping->menu_count) | ||
| 804 | return -EINVAL; | ||
| 805 | value = mapping->menu_info[value].value; | ||
| 806 | } | ||
| 807 | |||
| 808 | if (!ctrl->loaded && (ctrl->info->size * 8) != mapping->size) { | ||
| 809 | if ((ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0) { | ||
| 810 | memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), | ||
| 811 | 0, ctrl->info->size); | ||
| 812 | } else { | ||
| 813 | ret = uvc_query_ctrl(video->dev, GET_CUR, | ||
| 814 | ctrl->entity->id, video->dev->intfnum, | ||
| 815 | ctrl->info->selector, | ||
| 816 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), | ||
| 817 | ctrl->info->size); | ||
| 818 | if (ret < 0) | ||
| 819 | return ret; | ||
| 820 | } | ||
| 821 | |||
| 822 | if ((ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE) == 0) | ||
| 823 | ctrl->loaded = 1; | ||
| 824 | } | ||
| 825 | |||
| 826 | if (!ctrl->dirty) { | ||
| 827 | memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), | ||
| 828 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), | ||
| 829 | ctrl->info->size); | ||
| 830 | } | ||
| 831 | |||
| 832 | uvc_set_le_value(value, | ||
| 833 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), mapping); | ||
| 834 | |||
| 835 | ctrl->dirty = 1; | ||
| 836 | ctrl->modified = 1; | ||
| 837 | return 0; | ||
| 838 | } | ||
| 839 | |||
| 840 | /* -------------------------------------------------------------------------- | ||
| 841 | * Dynamic controls | ||
| 842 | */ | ||
| 843 | |||
| 844 | int uvc_xu_ctrl_query(struct uvc_video_device *video, | ||
| 845 | struct uvc_xu_control *xctrl, int set) | ||
| 846 | { | ||
| 847 | struct uvc_entity *entity; | ||
| 848 | struct uvc_control *ctrl = NULL; | ||
| 849 | unsigned int i, found = 0; | ||
| 850 | __u8 *data; | ||
| 851 | int ret; | ||
| 852 | |||
| 853 | /* Find the extension unit. */ | ||
| 854 | list_for_each_entry(entity, &video->extensions, chain) { | ||
| 855 | if (entity->id == xctrl->unit) | ||
| 856 | break; | ||
| 857 | } | ||
| 858 | |||
| 859 | if (entity->id != xctrl->unit) { | ||
| 860 | uvc_trace(UVC_TRACE_CONTROL, "Extension unit %u not found.\n", | ||
| 861 | xctrl->unit); | ||
| 862 | return -EINVAL; | ||
| 863 | } | ||
| 864 | |||
| 865 | /* Find the control. */ | ||
| 866 | for (i = 0; i < entity->ncontrols; ++i) { | ||
| 867 | ctrl = &entity->controls[i]; | ||
| 868 | if (ctrl->info == NULL) | ||
| 869 | continue; | ||
| 870 | |||
| 871 | if (ctrl->info->selector == xctrl->selector) { | ||
| 872 | found = 1; | ||
| 873 | break; | ||
| 874 | } | ||
| 875 | } | ||
| 876 | |||
| 877 | if (!found) { | ||
| 878 | uvc_trace(UVC_TRACE_CONTROL, | ||
| 879 | "Control " UVC_GUID_FORMAT "/%u not found.\n", | ||
| 880 | UVC_GUID_ARGS(entity->extension.guidExtensionCode), | ||
| 881 | xctrl->selector); | ||
| 882 | return -EINVAL; | ||
| 883 | } | ||
| 884 | |||
| 885 | /* Validate control data size. */ | ||
| 886 | if (ctrl->info->size != xctrl->size) | ||
| 887 | return -EINVAL; | ||
| 888 | |||
| 889 | if ((set && !(ctrl->info->flags & UVC_CONTROL_SET_CUR)) || | ||
| 890 | (!set && !(ctrl->info->flags & UVC_CONTROL_GET_CUR))) | ||
| 891 | return -EINVAL; | ||
| 892 | |||
| 893 | if (mutex_lock_interruptible(&video->ctrl_mutex)) | ||
| 894 | return -ERESTARTSYS; | ||
| 895 | |||
| 896 | memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), | ||
| 897 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), | ||
| 898 | xctrl->size); | ||
| 899 | data = uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT); | ||
| 900 | |||
| 901 | if (set && copy_from_user(data, xctrl->data, xctrl->size)) { | ||
| 902 | ret = -EFAULT; | ||
| 903 | goto out; | ||
| 904 | } | ||
| 905 | |||
| 906 | ret = uvc_query_ctrl(video->dev, set ? SET_CUR : GET_CUR, xctrl->unit, | ||
| 907 | video->dev->intfnum, xctrl->selector, data, | ||
| 908 | xctrl->size); | ||
| 909 | if (ret < 0) | ||
| 910 | goto out; | ||
| 911 | |||
| 912 | if (!set && copy_to_user(xctrl->data, data, xctrl->size)) { | ||
| 913 | ret = -EFAULT; | ||
| 914 | goto out; | ||
| 915 | } | ||
| 916 | |||
| 917 | out: | ||
| 918 | if (ret) | ||
| 919 | memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), | ||
| 920 | uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), | ||
| 921 | xctrl->size); | ||
| 922 | |||
| 923 | mutex_unlock(&video->ctrl_mutex); | ||
| 924 | return ret; | ||
| 925 | } | ||
| 926 | |||
| 927 | /* -------------------------------------------------------------------------- | ||
| 928 | * Suspend/resume | ||
| 929 | */ | ||
| 930 | |||
| 931 | /* | ||
| 932 | * Restore control values after resume, skipping controls that haven't been | ||
| 933 | * changed. | ||
| 934 | * | ||
| 935 | * TODO | ||
| 936 | * - Don't restore modified controls that are back to their default value. | ||
| 937 | * - Handle restore order (Auto-Exposure Mode should be restored before | ||
| 938 | * Exposure Time). | ||
| 939 | */ | ||
| 940 | int uvc_ctrl_resume_device(struct uvc_device *dev) | ||
| 941 | { | ||
| 942 | struct uvc_control *ctrl; | ||
| 943 | struct uvc_entity *entity; | ||
| 944 | unsigned int i; | ||
| 945 | int ret; | ||
| 946 | |||
| 947 | /* Walk the entities list and restore controls when possible. */ | ||
| 948 | list_for_each_entry(entity, &dev->entities, list) { | ||
| 949 | |||
| 950 | for (i = 0; i < entity->ncontrols; ++i) { | ||
| 951 | ctrl = &entity->controls[i]; | ||
| 952 | |||
| 953 | if (ctrl->info == NULL || !ctrl->modified || | ||
| 954 | (ctrl->info->flags & UVC_CONTROL_RESTORE) == 0) | ||
| 955 | continue; | ||
| 956 | |||
| 957 | printk(KERN_INFO "restoring control " UVC_GUID_FORMAT | ||
| 958 | "/%u/%u\n", UVC_GUID_ARGS(ctrl->info->entity), | ||
| 959 | ctrl->info->index, ctrl->info->selector); | ||
| 960 | ctrl->dirty = 1; | ||
| 961 | } | ||
| 962 | |||
| 963 | ret = uvc_ctrl_commit_entity(dev, entity, 0); | ||
| 964 | if (ret < 0) | ||
| 965 | return ret; | ||
| 966 | } | ||
| 967 | |||
| 968 | return 0; | ||
| 969 | } | ||
| 970 | |||
| 971 | /* -------------------------------------------------------------------------- | ||
| 972 | * Control and mapping handling | ||
| 973 | */ | ||
| 974 | |||
| 975 | static void uvc_ctrl_add_ctrl(struct uvc_device *dev, | ||
| 976 | struct uvc_control_info *info) | ||
| 977 | { | ||
| 978 | struct uvc_entity *entity; | ||
| 979 | struct uvc_control *ctrl = NULL; | ||
| 980 | int ret, found = 0; | ||
| 981 | unsigned int i; | ||
| 982 | |||
| 983 | list_for_each_entry(entity, &dev->entities, list) { | ||
| 984 | if (!uvc_entity_match_guid(entity, info->entity)) | ||
| 985 | continue; | ||
| 986 | |||
| 987 | for (i = 0; i < entity->ncontrols; ++i) { | ||
| 988 | ctrl = &entity->controls[i]; | ||
| 989 | if (ctrl->index == info->index) { | ||
| 990 | found = 1; | ||
| 991 | break; | ||
| 992 | } | ||
| 993 | } | ||
| 994 | |||
| 995 | if (found) | ||
| 996 | break; | ||
| 997 | } | ||
| 998 | |||
| 999 | if (!found) | ||
| 1000 | return; | ||
| 1001 | |||
| 1002 | if (UVC_ENTITY_TYPE(entity) == VC_EXTENSION_UNIT) { | ||
| 1003 | /* Check if the device control information and length match | ||
| 1004 | * the user supplied information. | ||
| 1005 | */ | ||
| 1006 | __u32 flags; | ||
| 1007 | __le16 size; | ||
| 1008 | __u8 inf; | ||
| 1009 | |||
| 1010 | if ((ret = uvc_query_ctrl(dev, GET_LEN, ctrl->entity->id, | ||
| 1011 | dev->intfnum, info->selector, (__u8 *)&size, 2)) < 0) { | ||
| 1012 | uvc_trace(UVC_TRACE_CONTROL, "GET_LEN failed on " | ||
| 1013 | "control " UVC_GUID_FORMAT "/%u (%d).\n", | ||
| 1014 | UVC_GUID_ARGS(info->entity), info->selector, | ||
| 1015 | ret); | ||
| 1016 | return; | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | if (info->size != le16_to_cpu(size)) { | ||
| 1020 | uvc_trace(UVC_TRACE_CONTROL, "Control " UVC_GUID_FORMAT | ||
| 1021 | "/%u size doesn't match user supplied " | ||
| 1022 | "value.\n", UVC_GUID_ARGS(info->entity), | ||
| 1023 | info->selector); | ||
| 1024 | return; | ||
| 1025 | } | ||
| 1026 | |||
| 1027 | if ((ret = uvc_query_ctrl(dev, GET_INFO, ctrl->entity->id, | ||
| 1028 | dev->intfnum, info->selector, &inf, 1)) < 0) { | ||
| 1029 | uvc_trace(UVC_TRACE_CONTROL, "GET_INFO failed on " | ||
| 1030 | "control " UVC_GUID_FORMAT "/%u (%d).\n", | ||
| 1031 | UVC_GUID_ARGS(info->entity), info->selector, | ||
| 1032 | ret); | ||
| 1033 | return; | ||
| 1034 | } | ||
| 1035 | |||
| 1036 | flags = info->flags; | ||
| 1037 | if (((flags & UVC_CONTROL_GET_CUR) && !(inf & (1 << 0))) || | ||
| 1038 | ((flags & UVC_CONTROL_SET_CUR) && !(inf & (1 << 1)))) { | ||
| 1039 | uvc_trace(UVC_TRACE_CONTROL, "Control " | ||
| 1040 | UVC_GUID_FORMAT "/%u flags don't match " | ||
| 1041 | "supported operations.\n", | ||
| 1042 | UVC_GUID_ARGS(info->entity), info->selector); | ||
| 1043 | return; | ||
| 1044 | } | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | ctrl->info = info; | ||
| 1048 | ctrl->data = kmalloc(ctrl->info->size * UVC_CTRL_NDATA, GFP_KERNEL); | ||
| 1049 | uvc_trace(UVC_TRACE_CONTROL, "Added control " UVC_GUID_FORMAT "/%u " | ||
| 1050 | "to device %s entity %u\n", UVC_GUID_ARGS(ctrl->info->entity), | ||
| 1051 | ctrl->info->selector, dev->udev->devpath, entity->id); | ||
| 1052 | } | ||
| 1053 | |||
| 1054 | /* | ||
| 1055 | * Add an item to the UVC control information list, and instantiate a control | ||
| 1056 | * structure for each device that supports the control. | ||
| 1057 | */ | ||
| 1058 | int uvc_ctrl_add_info(struct uvc_control_info *info) | ||
| 1059 | { | ||
| 1060 | struct uvc_control_info *ctrl; | ||
| 1061 | struct uvc_device *dev; | ||
| 1062 | int ret = 0; | ||
| 1063 | |||
| 1064 | /* Find matching controls by walking the devices, entities and | ||
| 1065 | * controls list. | ||
| 1066 | */ | ||
| 1067 | mutex_lock(&uvc_driver.ctrl_mutex); | ||
| 1068 | |||
| 1069 | /* First check if the list contains a control matching the new one. | ||
| 1070 | * Bail out if it does. | ||
| 1071 | */ | ||
| 1072 | list_for_each_entry(ctrl, &uvc_driver.controls, list) { | ||
| 1073 | if (memcmp(ctrl->entity, info->entity, 16)) | ||
| 1074 | continue; | ||
| 1075 | |||
| 1076 | if (ctrl->selector == info->selector) { | ||
| 1077 | uvc_trace(UVC_TRACE_CONTROL, "Control " | ||
| 1078 | UVC_GUID_FORMAT "/%u is already defined.\n", | ||
| 1079 | UVC_GUID_ARGS(info->entity), info->selector); | ||
| 1080 | ret = -EEXIST; | ||
| 1081 | goto end; | ||
| 1082 | } | ||
| 1083 | if (ctrl->index == info->index) { | ||
| 1084 | uvc_trace(UVC_TRACE_CONTROL, "Control " | ||
| 1085 | UVC_GUID_FORMAT "/%u would overwrite index " | ||
| 1086 | "%d.\n", UVC_GUID_ARGS(info->entity), | ||
| 1087 | info->selector, info->index); | ||
| 1088 | ret = -EEXIST; | ||
| 1089 | goto end; | ||
| 1090 | } | ||
| 1091 | } | ||
| 1092 | |||
| 1093 | list_for_each_entry(dev, &uvc_driver.devices, list) | ||
| 1094 | uvc_ctrl_add_ctrl(dev, info); | ||
| 1095 | |||
| 1096 | INIT_LIST_HEAD(&info->mappings); | ||
| 1097 | list_add_tail(&info->list, &uvc_driver.controls); | ||
| 1098 | end: | ||
| 1099 | mutex_unlock(&uvc_driver.ctrl_mutex); | ||
| 1100 | return ret; | ||
| 1101 | } | ||
| 1102 | |||
| 1103 | int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping) | ||
| 1104 | { | ||
| 1105 | struct uvc_control_info *info; | ||
| 1106 | struct uvc_control_mapping *map; | ||
| 1107 | int ret = -EINVAL; | ||
| 1108 | |||
| 1109 | if (mapping->id & ~V4L2_CTRL_ID_MASK) { | ||
| 1110 | uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s' with " | ||
| 1111 | "invalid control id 0x%08x\n", mapping->name, | ||
| 1112 | mapping->id); | ||
| 1113 | return -EINVAL; | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | mutex_lock(&uvc_driver.ctrl_mutex); | ||
| 1117 | list_for_each_entry(info, &uvc_driver.controls, list) { | ||
| 1118 | if (memcmp(info->entity, mapping->entity, 16) || | ||
| 1119 | info->selector != mapping->selector) | ||
| 1120 | continue; | ||
| 1121 | |||
| 1122 | if (info->size * 8 < mapping->size + mapping->offset) { | ||
| 1123 | uvc_trace(UVC_TRACE_CONTROL, "Mapping '%s' would " | ||
| 1124 | "overflow control " UVC_GUID_FORMAT "/%u\n", | ||
| 1125 | mapping->name, UVC_GUID_ARGS(info->entity), | ||
| 1126 | info->selector); | ||
| 1127 | ret = -EOVERFLOW; | ||
| 1128 | goto end; | ||
| 1129 | } | ||
| 1130 | |||
| 1131 | /* Check if the list contains a mapping matching the new one. | ||
| 1132 | * Bail out if it does. | ||
| 1133 | */ | ||
| 1134 | list_for_each_entry(map, &info->mappings, list) { | ||
| 1135 | if (map->id == mapping->id) { | ||
| 1136 | uvc_trace(UVC_TRACE_CONTROL, "Mapping '%s' is " | ||
| 1137 | "already defined.\n", mapping->name); | ||
| 1138 | ret = -EEXIST; | ||
| 1139 | goto end; | ||
| 1140 | } | ||
| 1141 | } | ||
| 1142 | |||
| 1143 | mapping->ctrl = info; | ||
| 1144 | list_add_tail(&mapping->list, &info->mappings); | ||
| 1145 | uvc_trace(UVC_TRACE_CONTROL, "Adding mapping %s to control " | ||
| 1146 | UVC_GUID_FORMAT "/%u.\n", mapping->name, | ||
| 1147 | UVC_GUID_ARGS(info->entity), info->selector); | ||
| 1148 | |||
| 1149 | ret = 0; | ||
| 1150 | break; | ||
| 1151 | } | ||
| 1152 | end: | ||
| 1153 | mutex_unlock(&uvc_driver.ctrl_mutex); | ||
| 1154 | return ret; | ||
| 1155 | } | ||
| 1156 | |||
| 1157 | /* | ||
| 1158 | * Initialize device controls. | ||
| 1159 | */ | ||
| 1160 | int uvc_ctrl_init_device(struct uvc_device *dev) | ||
| 1161 | { | ||
| 1162 | struct uvc_control_info *info; | ||
| 1163 | struct uvc_control *ctrl; | ||
| 1164 | struct uvc_entity *entity; | ||
| 1165 | unsigned int i; | ||
| 1166 | |||
| 1167 | /* Walk the entities list and instantiate controls */ | ||
| 1168 | list_for_each_entry(entity, &dev->entities, list) { | ||
| 1169 | unsigned int bControlSize = 0, ncontrols = 0; | ||
| 1170 | __u8 *bmControls = NULL; | ||
| 1171 | |||
| 1172 | if (UVC_ENTITY_TYPE(entity) == VC_EXTENSION_UNIT) { | ||
| 1173 | bmControls = entity->extension.bmControls; | ||
| 1174 | bControlSize = entity->extension.bControlSize; | ||
| 1175 | } else if (UVC_ENTITY_TYPE(entity) == VC_PROCESSING_UNIT) { | ||
| 1176 | bmControls = entity->processing.bmControls; | ||
| 1177 | bControlSize = entity->processing.bControlSize; | ||
| 1178 | } else if (UVC_ENTITY_TYPE(entity) == ITT_CAMERA) { | ||
| 1179 | bmControls = entity->camera.bmControls; | ||
| 1180 | bControlSize = entity->camera.bControlSize; | ||
| 1181 | } | ||
| 1182 | |||
| 1183 | for (i = 0; i < bControlSize; ++i) | ||
| 1184 | ncontrols += hweight8(bmControls[i]); | ||
| 1185 | |||
| 1186 | if (ncontrols == 0) | ||
| 1187 | continue; | ||
| 1188 | |||
| 1189 | entity->controls = kzalloc(ncontrols*sizeof *ctrl, GFP_KERNEL); | ||
| 1190 | if (entity->controls == NULL) | ||
| 1191 | return -ENOMEM; | ||
| 1192 | |||
| 1193 | entity->ncontrols = ncontrols; | ||
| 1194 | |||
| 1195 | ctrl = entity->controls; | ||
| 1196 | for (i = 0; i < bControlSize * 8; ++i) { | ||
| 1197 | if (uvc_get_bit(bmControls, i) == 0) | ||
| 1198 | continue; | ||
| 1199 | |||
| 1200 | ctrl->entity = entity; | ||
| 1201 | ctrl->index = i; | ||
| 1202 | ctrl++; | ||
| 1203 | } | ||
| 1204 | } | ||
| 1205 | |||
| 1206 | /* Walk the controls info list and associate them with the device | ||
| 1207 | * controls, then add the device to the global device list. This has | ||
| 1208 | * to be done while holding the controls lock, to make sure | ||
| 1209 | * uvc_ctrl_add_info() will not get called in-between. | ||
| 1210 | */ | ||
| 1211 | mutex_lock(&uvc_driver.ctrl_mutex); | ||
| 1212 | list_for_each_entry(info, &uvc_driver.controls, list) | ||
| 1213 | uvc_ctrl_add_ctrl(dev, info); | ||
| 1214 | |||
| 1215 | list_add_tail(&dev->list, &uvc_driver.devices); | ||
| 1216 | mutex_unlock(&uvc_driver.ctrl_mutex); | ||
| 1217 | |||
| 1218 | return 0; | ||
| 1219 | } | ||
| 1220 | |||
| 1221 | /* | ||
| 1222 | * Cleanup device controls. | ||
| 1223 | */ | ||
| 1224 | void uvc_ctrl_cleanup_device(struct uvc_device *dev) | ||
| 1225 | { | ||
| 1226 | struct uvc_entity *entity; | ||
| 1227 | unsigned int i; | ||
| 1228 | |||
| 1229 | /* Remove the device from the global devices list */ | ||
| 1230 | mutex_lock(&uvc_driver.ctrl_mutex); | ||
| 1231 | if (dev->list.next != NULL) | ||
| 1232 | list_del(&dev->list); | ||
| 1233 | mutex_unlock(&uvc_driver.ctrl_mutex); | ||
| 1234 | |||
| 1235 | list_for_each_entry(entity, &dev->entities, list) { | ||
| 1236 | for (i = 0; i < entity->ncontrols; ++i) | ||
| 1237 | kfree(entity->controls[i].data); | ||
| 1238 | |||
| 1239 | kfree(entity->controls); | ||
| 1240 | } | ||
| 1241 | } | ||
| 1242 | |||
| 1243 | void uvc_ctrl_init(void) | ||
| 1244 | { | ||
| 1245 | struct uvc_control_info *ctrl = uvc_ctrls; | ||
| 1246 | struct uvc_control_info *cend = ctrl + ARRAY_SIZE(uvc_ctrls); | ||
| 1247 | struct uvc_control_mapping *mapping = uvc_ctrl_mappings; | ||
| 1248 | struct uvc_control_mapping *mend = | ||
| 1249 | mapping + ARRAY_SIZE(uvc_ctrl_mappings); | ||
| 1250 | |||
| 1251 | for (; ctrl < cend; ++ctrl) | ||
| 1252 | uvc_ctrl_add_info(ctrl); | ||
| 1253 | |||
| 1254 | for (; mapping < mend; ++mapping) | ||
| 1255 | uvc_ctrl_add_mapping(mapping); | ||
| 1256 | } | ||
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c new file mode 100644 index 000000000000..60ced589f898 --- /dev/null +++ b/drivers/media/video/uvc/uvc_driver.c | |||
| @@ -0,0 +1,1955 @@ | |||
| 1 | /* | ||
| 2 | * uvc_driver.c -- USB Video Class driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2005-2008 | ||
| 5 | * Laurent Pinchart (laurent.pinchart@skynet.be) | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | /* | ||
| 15 | * This driver aims to support video input devices compliant with the 'USB | ||
| 16 | * Video Class' specification. | ||
| 17 | * | ||
| 18 | * The driver doesn't support the deprecated v4l1 interface. It implements the | ||
| 19 | * mmap capture method only, and doesn't do any image format conversion in | ||
| 20 | * software. If your user-space application doesn't support YUYV or MJPEG, fix | ||
| 21 | * it :-). Please note that the MJPEG data have been stripped from their | ||
| 22 | * Huffman tables (DHT marker), you will need to add it back if your JPEG | ||
| 23 | * codec can't handle MJPEG data. | ||
| 24 | */ | ||
| 25 | |||
| 26 | #include <linux/kernel.h> | ||
| 27 | #include <linux/version.h> | ||
| 28 | #include <linux/list.h> | ||
| 29 | #include <linux/module.h> | ||
| 30 | #include <linux/usb.h> | ||
| 31 | #include <linux/videodev2.h> | ||
| 32 | #include <linux/vmalloc.h> | ||
| 33 | #include <linux/wait.h> | ||
| 34 | #include <asm/atomic.h> | ||
| 35 | |||
| 36 | #include <media/v4l2-common.h> | ||
| 37 | |||
| 38 | #include "uvcvideo.h" | ||
| 39 | |||
| 40 | #define DRIVER_AUTHOR "Laurent Pinchart <laurent.pinchart@skynet.be>" | ||
| 41 | #define DRIVER_DESC "USB Video Class driver" | ||
| 42 | #ifndef DRIVER_VERSION | ||
| 43 | #define DRIVER_VERSION "v0.1.0" | ||
| 44 | #endif | ||
| 45 | |||
| 46 | static unsigned int uvc_quirks_param; | ||
| 47 | unsigned int uvc_trace_param; | ||
| 48 | |||
| 49 | /* ------------------------------------------------------------------------ | ||
| 50 | * Control, formats, ... | ||
| 51 | */ | ||
| 52 | |||
| 53 | static struct uvc_format_desc uvc_fmts[] = { | ||
| 54 | { | ||
| 55 | .name = "YUV 4:2:2 (YUYV)", | ||
| 56 | .guid = UVC_GUID_FORMAT_YUY2, | ||
| 57 | .fcc = V4L2_PIX_FMT_YUYV, | ||
| 58 | }, | ||
| 59 | { | ||
| 60 | .name = "YUV 4:2:0 (NV12)", | ||
| 61 | .guid = UVC_GUID_FORMAT_NV12, | ||
| 62 | .fcc = V4L2_PIX_FMT_NV12, | ||
| 63 | }, | ||
| 64 | { | ||
| 65 | .name = "MJPEG", | ||
| 66 | .guid = UVC_GUID_FORMAT_MJPEG, | ||
| 67 | .fcc = V4L2_PIX_FMT_MJPEG, | ||
| 68 | }, | ||
| 69 | { | ||
| 70 | .name = "YVU 4:2:0 (YV12)", | ||
| 71 | .guid = UVC_GUID_FORMAT_YV12, | ||
| 72 | .fcc = V4L2_PIX_FMT_YVU420, | ||
| 73 | }, | ||
| 74 | { | ||
| 75 | .name = "YUV 4:2:0 (I420)", | ||
| 76 | .guid = UVC_GUID_FORMAT_I420, | ||
| 77 | .fcc = V4L2_PIX_FMT_YUV420, | ||
| 78 | }, | ||
| 79 | { | ||
| 80 | .name = "YUV 4:2:2 (UYVY)", | ||
| 81 | .guid = UVC_GUID_FORMAT_UYVY, | ||
| 82 | .fcc = V4L2_PIX_FMT_UYVY, | ||
| 83 | }, | ||
| 84 | { | ||
| 85 | .name = "Greyscale", | ||
| 86 | .guid = UVC_GUID_FORMAT_Y800, | ||
| 87 | .fcc = V4L2_PIX_FMT_GREY, | ||
| 88 | }, | ||
| 89 | { | ||
| 90 | .name = "RGB Bayer", | ||
| 91 | .guid = UVC_GUID_FORMAT_BY8, | ||
| 92 | .fcc = V4L2_PIX_FMT_SBGGR8, | ||
| 93 | }, | ||
| 94 | }; | ||
| 95 | |||
| 96 | /* ------------------------------------------------------------------------ | ||
| 97 | * Utility functions | ||
| 98 | */ | ||
| 99 | |||
| 100 | struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts, | ||
| 101 | __u8 epaddr) | ||
| 102 | { | ||
| 103 | struct usb_host_endpoint *ep; | ||
| 104 | unsigned int i; | ||
| 105 | |||
| 106 | for (i = 0; i < alts->desc.bNumEndpoints; ++i) { | ||
| 107 | ep = &alts->endpoint[i]; | ||
| 108 | if (ep->desc.bEndpointAddress == epaddr) | ||
| 109 | return ep; | ||
| 110 | } | ||
| 111 | |||
| 112 | return NULL; | ||
| 113 | } | ||
| 114 | |||
| 115 | static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16]) | ||
| 116 | { | ||
| 117 | unsigned int len = ARRAY_SIZE(uvc_fmts); | ||
| 118 | unsigned int i; | ||
| 119 | |||
| 120 | for (i = 0; i < len; ++i) { | ||
| 121 | if (memcmp(guid, uvc_fmts[i].guid, 16) == 0) | ||
| 122 | return &uvc_fmts[i]; | ||
| 123 | } | ||
| 124 | |||
| 125 | return NULL; | ||
| 126 | } | ||
| 127 | |||
| 128 | static __u32 uvc_colorspace(const __u8 primaries) | ||
| 129 | { | ||
| 130 | static const __u8 colorprimaries[] = { | ||
| 131 | 0, | ||
| 132 | V4L2_COLORSPACE_SRGB, | ||
| 133 | V4L2_COLORSPACE_470_SYSTEM_M, | ||
| 134 | V4L2_COLORSPACE_470_SYSTEM_BG, | ||
| 135 | V4L2_COLORSPACE_SMPTE170M, | ||
| 136 | V4L2_COLORSPACE_SMPTE240M, | ||
| 137 | }; | ||
| 138 | |||
| 139 | if (primaries < ARRAY_SIZE(colorprimaries)) | ||
| 140 | return colorprimaries[primaries]; | ||
| 141 | |||
| 142 | return 0; | ||
| 143 | } | ||
| 144 | |||
| 145 | /* Simplify a fraction using a simple continued fraction decomposition. The | ||
| 146 | * idea here is to convert fractions such as 333333/10000000 to 1/30 using | ||
| 147 | * 32 bit arithmetic only. The algorithm is not perfect and relies upon two | ||
| 148 | * arbitrary parameters to remove non-significative terms from the simple | ||
| 149 | * continued fraction decomposition. Using 8 and 333 for n_terms and threshold | ||
| 150 | * respectively seems to give nice results. | ||
| 151 | */ | ||
| 152 | void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator, | ||
| 153 | unsigned int n_terms, unsigned int threshold) | ||
| 154 | { | ||
| 155 | uint32_t *an; | ||
| 156 | uint32_t x, y, r; | ||
| 157 | unsigned int i, n; | ||
| 158 | |||
| 159 | an = kmalloc(n_terms * sizeof *an, GFP_KERNEL); | ||
| 160 | if (an == NULL) | ||
| 161 | return; | ||
| 162 | |||
| 163 | /* Convert the fraction to a simple continued fraction. See | ||
| 164 | * http://mathforum.org/dr.math/faq/faq.fractions.html | ||
| 165 | * Stop if the current term is bigger than or equal to the given | ||
| 166 | * threshold. | ||
| 167 | */ | ||
| 168 | x = *numerator; | ||
| 169 | y = *denominator; | ||
| 170 | |||
| 171 | for (n = 0; n < n_terms && y != 0; ++n) { | ||
| 172 | an[n] = x / y; | ||
| 173 | if (an[n] >= threshold) { | ||
| 174 | if (n < 2) | ||
| 175 | n++; | ||
| 176 | break; | ||
| 177 | } | ||
| 178 | |||
| 179 | r = x - an[n] * y; | ||
| 180 | x = y; | ||
| 181 | y = r; | ||
| 182 | } | ||
| 183 | |||
| 184 | /* Expand the simple continued fraction back to an integer fraction. */ | ||
| 185 | x = 0; | ||
| 186 | y = 1; | ||
| 187 | |||
| 188 | for (i = n; i > 0; --i) { | ||
| 189 | r = y; | ||
| 190 | y = an[i-1] * y + x; | ||
| 191 | x = r; | ||
| 192 | } | ||
| 193 | |||
| 194 | *numerator = y; | ||
| 195 | *denominator = x; | ||
| 196 | kfree(an); | ||
| 197 | } | ||
| 198 | |||
| 199 | /* Convert a fraction to a frame interval in 100ns multiples. The idea here is | ||
| 200 | * to compute numerator / denominator * 10000000 using 32 bit fixed point | ||
| 201 | * arithmetic only. | ||
| 202 | */ | ||
| 203 | uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator) | ||
| 204 | { | ||
| 205 | uint32_t multiplier; | ||
| 206 | |||
| 207 | /* Saturate the result if the operation would overflow. */ | ||
| 208 | if (denominator == 0 || | ||
| 209 | numerator/denominator >= ((uint32_t)-1)/10000000) | ||
| 210 | return (uint32_t)-1; | ||
| 211 | |||
| 212 | /* Divide both the denominator and the multiplier by two until | ||
| 213 | * numerator * multiplier doesn't overflow. If anyone knows a better | ||
| 214 | * algorithm please let me know. | ||
| 215 | */ | ||
| 216 | multiplier = 10000000; | ||
| 217 | while (numerator > ((uint32_t)-1)/multiplier) { | ||
| 218 | multiplier /= 2; | ||
| 219 | denominator /= 2; | ||
| 220 | } | ||
| 221 | |||
| 222 | return denominator ? numerator * multiplier / denominator : 0; | ||
| 223 | } | ||
| 224 | |||
| 225 | /* ------------------------------------------------------------------------ | ||
| 226 | * Terminal and unit management | ||
| 227 | */ | ||
| 228 | |||
| 229 | static struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id) | ||
| 230 | { | ||
| 231 | struct uvc_entity *entity; | ||
| 232 | |||
| 233 | list_for_each_entry(entity, &dev->entities, list) { | ||
| 234 | if (entity->id == id) | ||
| 235 | return entity; | ||
| 236 | } | ||
| 237 | |||
| 238 | return NULL; | ||
| 239 | } | ||
| 240 | |||
| 241 | static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev, | ||
| 242 | int id, struct uvc_entity *entity) | ||
| 243 | { | ||
| 244 | unsigned int i; | ||
| 245 | |||
| 246 | if (entity == NULL) | ||
| 247 | entity = list_entry(&dev->entities, struct uvc_entity, list); | ||
| 248 | |||
| 249 | list_for_each_entry_continue(entity, &dev->entities, list) { | ||
| 250 | switch (UVC_ENTITY_TYPE(entity)) { | ||
| 251 | case TT_STREAMING: | ||
| 252 | if (entity->output.bSourceID == id) | ||
| 253 | return entity; | ||
| 254 | break; | ||
| 255 | |||
| 256 | case VC_PROCESSING_UNIT: | ||
| 257 | if (entity->processing.bSourceID == id) | ||
| 258 | return entity; | ||
| 259 | break; | ||
| 260 | |||
| 261 | case VC_SELECTOR_UNIT: | ||
| 262 | for (i = 0; i < entity->selector.bNrInPins; ++i) | ||
| 263 | if (entity->selector.baSourceID[i] == id) | ||
| 264 | return entity; | ||
| 265 | break; | ||
| 266 | |||
| 267 | case VC_EXTENSION_UNIT: | ||
| 268 | for (i = 0; i < entity->extension.bNrInPins; ++i) | ||
| 269 | if (entity->extension.baSourceID[i] == id) | ||
| 270 | return entity; | ||
| 271 | break; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | |||
| 275 | return NULL; | ||
| 276 | } | ||
| 277 | |||
| 278 | /* ------------------------------------------------------------------------ | ||
| 279 | * Descriptors handling | ||
| 280 | */ | ||
| 281 | |||
| 282 | static int uvc_parse_format(struct uvc_device *dev, | ||
| 283 | struct uvc_streaming *streaming, struct uvc_format *format, | ||
| 284 | __u32 **intervals, unsigned char *buffer, int buflen) | ||
| 285 | { | ||
| 286 | struct usb_interface *intf = streaming->intf; | ||
| 287 | struct usb_host_interface *alts = intf->cur_altsetting; | ||
| 288 | struct uvc_format_desc *fmtdesc; | ||
| 289 | struct uvc_frame *frame; | ||
| 290 | const unsigned char *start = buffer; | ||
| 291 | unsigned int interval; | ||
| 292 | unsigned int i, n; | ||
| 293 | __u8 ftype; | ||
| 294 | |||
| 295 | format->type = buffer[2]; | ||
| 296 | format->index = buffer[3]; | ||
| 297 | |||
| 298 | switch (buffer[2]) { | ||
| 299 | case VS_FORMAT_UNCOMPRESSED: | ||
| 300 | case VS_FORMAT_FRAME_BASED: | ||
| 301 | if (buflen < 27) { | ||
| 302 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming" | ||
| 303 | "interface %d FORMAT error\n", | ||
| 304 | dev->udev->devnum, | ||
| 305 | alts->desc.bInterfaceNumber); | ||
| 306 | return -EINVAL; | ||
| 307 | } | ||
| 308 | |||
| 309 | /* Find the format descriptor from its GUID. */ | ||
| 310 | fmtdesc = uvc_format_by_guid(&buffer[5]); | ||
| 311 | |||
| 312 | if (fmtdesc != NULL) { | ||
| 313 | strncpy(format->name, fmtdesc->name, | ||
| 314 | sizeof format->name); | ||
| 315 | format->fcc = fmtdesc->fcc; | ||
| 316 | } else { | ||
| 317 | uvc_printk(KERN_INFO, "Unknown video format " | ||
| 318 | UVC_GUID_FORMAT "\n", | ||
| 319 | UVC_GUID_ARGS(&buffer[5])); | ||
| 320 | snprintf(format->name, sizeof format->name, | ||
| 321 | UVC_GUID_FORMAT, UVC_GUID_ARGS(&buffer[5])); | ||
| 322 | format->fcc = 0; | ||
| 323 | } | ||
| 324 | |||
| 325 | format->bpp = buffer[21]; | ||
| 326 | if (buffer[2] == VS_FORMAT_UNCOMPRESSED) { | ||
| 327 | ftype = VS_FRAME_UNCOMPRESSED; | ||
| 328 | } else { | ||
| 329 | ftype = VS_FRAME_FRAME_BASED; | ||
| 330 | if (buffer[27]) | ||
| 331 | format->flags = UVC_FMT_FLAG_COMPRESSED; | ||
| 332 | } | ||
| 333 | break; | ||
| 334 | |||
| 335 | case VS_FORMAT_MJPEG: | ||
| 336 | if (buflen < 11) { | ||
| 337 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming" | ||
| 338 | "interface %d FORMAT error\n", | ||
| 339 | dev->udev->devnum, | ||
| 340 | alts->desc.bInterfaceNumber); | ||
| 341 | return -EINVAL; | ||
| 342 | } | ||
| 343 | |||
| 344 | strncpy(format->name, "MJPEG", sizeof format->name); | ||
| 345 | format->fcc = V4L2_PIX_FMT_MJPEG; | ||
| 346 | format->flags = UVC_FMT_FLAG_COMPRESSED; | ||
| 347 | format->bpp = 0; | ||
| 348 | ftype = VS_FRAME_MJPEG; | ||
| 349 | break; | ||
| 350 | |||
| 351 | case VS_FORMAT_DV: | ||
| 352 | if (buflen < 9) { | ||
| 353 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming" | ||
| 354 | "interface %d FORMAT error\n", | ||
| 355 | dev->udev->devnum, | ||
| 356 | alts->desc.bInterfaceNumber); | ||
| 357 | return -EINVAL; | ||
| 358 | } | ||
| 359 | |||
| 360 | switch (buffer[8] & 0x7f) { | ||
| 361 | case 0: | ||
| 362 | strncpy(format->name, "SD-DV", sizeof format->name); | ||
| 363 | break; | ||
| 364 | case 1: | ||
| 365 | strncpy(format->name, "SDL-DV", sizeof format->name); | ||
| 366 | break; | ||
| 367 | case 2: | ||
| 368 | strncpy(format->name, "HD-DV", sizeof format->name); | ||
| 369 | break; | ||
| 370 | default: | ||
| 371 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming" | ||
| 372 | "interface %d: unknown DV format %u\n", | ||
| 373 | dev->udev->devnum, | ||
| 374 | alts->desc.bInterfaceNumber, buffer[8]); | ||
| 375 | return -EINVAL; | ||
| 376 | } | ||
| 377 | |||
| 378 | strncat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz", | ||
| 379 | sizeof format->name); | ||
| 380 | |||
| 381 | format->fcc = V4L2_PIX_FMT_DV; | ||
| 382 | format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM; | ||
| 383 | format->bpp = 0; | ||
| 384 | ftype = 0; | ||
| 385 | |||
| 386 | /* Create a dummy frame descriptor. */ | ||
| 387 | frame = &format->frame[0]; | ||
| 388 | memset(&format->frame[0], 0, sizeof format->frame[0]); | ||
| 389 | frame->bFrameIntervalType = 1; | ||
| 390 | frame->dwDefaultFrameInterval = 1; | ||
| 391 | frame->dwFrameInterval = *intervals; | ||
| 392 | *(*intervals)++ = 1; | ||
| 393 | format->nframes = 1; | ||
| 394 | break; | ||
| 395 | |||
| 396 | case VS_FORMAT_MPEG2TS: | ||
| 397 | case VS_FORMAT_STREAM_BASED: | ||
| 398 | /* Not supported yet. */ | ||
| 399 | default: | ||
| 400 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming" | ||
| 401 | "interface %d unsupported format %u\n", | ||
| 402 | dev->udev->devnum, alts->desc.bInterfaceNumber, | ||
| 403 | buffer[2]); | ||
| 404 | return -EINVAL; | ||
| 405 | } | ||
| 406 | |||
| 407 | uvc_trace(UVC_TRACE_DESCR, "Found format %s.\n", format->name); | ||
| 408 | |||
| 409 | buflen -= buffer[0]; | ||
| 410 | buffer += buffer[0]; | ||
| 411 | |||
| 412 | /* Parse the frame descriptors. Only uncompressed, MJPEG and frame | ||
| 413 | * based formats have frame descriptors. | ||
| 414 | */ | ||
| 415 | while (buflen > 2 && buffer[2] == ftype) { | ||
| 416 | frame = &format->frame[format->nframes]; | ||
| 417 | |||
| 418 | if (ftype != VS_FRAME_FRAME_BASED) | ||
| 419 | n = buflen > 25 ? buffer[25] : 0; | ||
| 420 | else | ||
| 421 | n = buflen > 21 ? buffer[21] : 0; | ||
| 422 | |||
| 423 | n = n ? n : 3; | ||
| 424 | |||
| 425 | if (buflen < 26 + 4*n) { | ||
| 426 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming" | ||
| 427 | "interface %d FRAME error\n", dev->udev->devnum, | ||
| 428 | alts->desc.bInterfaceNumber); | ||
| 429 | return -EINVAL; | ||
| 430 | } | ||
| 431 | |||
| 432 | frame->bFrameIndex = buffer[3]; | ||
| 433 | frame->bmCapabilities = buffer[4]; | ||
| 434 | frame->wWidth = le16_to_cpup((__le16 *)&buffer[5]); | ||
| 435 | frame->wHeight = le16_to_cpup((__le16 *)&buffer[7]); | ||
| 436 | frame->dwMinBitRate = le32_to_cpup((__le32 *)&buffer[9]); | ||
| 437 | frame->dwMaxBitRate = le32_to_cpup((__le32 *)&buffer[13]); | ||
| 438 | if (ftype != VS_FRAME_FRAME_BASED) { | ||
| 439 | frame->dwMaxVideoFrameBufferSize = | ||
| 440 | le32_to_cpup((__le32 *)&buffer[17]); | ||
| 441 | frame->dwDefaultFrameInterval = | ||
| 442 | le32_to_cpup((__le32 *)&buffer[21]); | ||
| 443 | frame->bFrameIntervalType = buffer[25]; | ||
| 444 | } else { | ||
| 445 | frame->dwMaxVideoFrameBufferSize = 0; | ||
| 446 | frame->dwDefaultFrameInterval = | ||
| 447 | le32_to_cpup((__le32 *)&buffer[17]); | ||
| 448 | frame->bFrameIntervalType = buffer[21]; | ||
| 449 | } | ||
| 450 | frame->dwFrameInterval = *intervals; | ||
| 451 | |||
| 452 | /* Several UVC chipsets screw up dwMaxVideoFrameBufferSize | ||
| 453 | * completely. Observed behaviours range from setting the | ||
| 454 | * value to 1.1x the actual frame size of hardwiring the | ||
| 455 | * 16 low bits to 0. This results in a higher than necessary | ||
| 456 | * memory usage as well as a wrong image size information. For | ||
| 457 | * uncompressed formats this can be fixed by computing the | ||
| 458 | * value from the frame size. | ||
| 459 | */ | ||
| 460 | if (!(format->flags & UVC_FMT_FLAG_COMPRESSED)) | ||
| 461 | frame->dwMaxVideoFrameBufferSize = format->bpp | ||
| 462 | * frame->wWidth * frame->wHeight / 8; | ||
| 463 | |||
| 464 | /* Some bogus devices report dwMinFrameInterval equal to | ||
| 465 | * dwMaxFrameInterval and have dwFrameIntervalStep set to | ||
| 466 | * zero. Setting all null intervals to 1 fixes the problem and | ||
| 467 | * some other divisions by zero which could happen. | ||
| 468 | */ | ||
| 469 | for (i = 0; i < n; ++i) { | ||
| 470 | interval = le32_to_cpup((__le32 *)&buffer[26+4*i]); | ||
| 471 | *(*intervals)++ = interval ? interval : 1; | ||
| 472 | } | ||
| 473 | |||
| 474 | /* Make sure that the default frame interval stays between | ||
| 475 | * the boundaries. | ||
| 476 | */ | ||
| 477 | n -= frame->bFrameIntervalType ? 1 : 2; | ||
| 478 | frame->dwDefaultFrameInterval = | ||
| 479 | min(frame->dwFrameInterval[n], | ||
| 480 | max(frame->dwFrameInterval[0], | ||
| 481 | frame->dwDefaultFrameInterval)); | ||
| 482 | |||
| 483 | uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n", | ||
| 484 | frame->wWidth, frame->wHeight, | ||
| 485 | 10000000/frame->dwDefaultFrameInterval, | ||
| 486 | (100000000/frame->dwDefaultFrameInterval)%10); | ||
| 487 | |||
| 488 | format->nframes++; | ||
| 489 | buflen -= buffer[0]; | ||
| 490 | buffer += buffer[0]; | ||
| 491 | } | ||
| 492 | |||
| 493 | if (buflen > 2 && buffer[2] == VS_STILL_IMAGE_FRAME) { | ||
| 494 | buflen -= buffer[0]; | ||
| 495 | buffer += buffer[0]; | ||
| 496 | } | ||
| 497 | |||
| 498 | if (buflen > 2 && buffer[2] == VS_COLORFORMAT) { | ||
| 499 | if (buflen < 6) { | ||
| 500 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming" | ||
| 501 | "interface %d COLORFORMAT error\n", | ||
| 502 | dev->udev->devnum, | ||
| 503 | alts->desc.bInterfaceNumber); | ||
| 504 | return -EINVAL; | ||
| 505 | } | ||
| 506 | |||
| 507 | format->colorspace = uvc_colorspace(buffer[3]); | ||
| 508 | |||
| 509 | buflen -= buffer[0]; | ||
| 510 | buffer += buffer[0]; | ||
| 511 | } | ||
| 512 | |||
| 513 | return buffer - start; | ||
| 514 | } | ||
| 515 | |||
| 516 | static int uvc_parse_streaming(struct uvc_device *dev, | ||
| 517 | struct usb_interface *intf) | ||
| 518 | { | ||
| 519 | struct uvc_streaming *streaming = NULL; | ||
| 520 | struct uvc_format *format; | ||
| 521 | struct uvc_frame *frame; | ||
| 522 | struct usb_host_interface *alts = &intf->altsetting[0]; | ||
| 523 | unsigned char *_buffer, *buffer = alts->extra; | ||
| 524 | int _buflen, buflen = alts->extralen; | ||
| 525 | unsigned int nformats = 0, nframes = 0, nintervals = 0; | ||
| 526 | unsigned int size, i, n, p; | ||
| 527 | __u32 *interval; | ||
| 528 | __u16 psize; | ||
| 529 | int ret = -EINVAL; | ||
| 530 | |||
| 531 | if (intf->cur_altsetting->desc.bInterfaceSubClass | ||
| 532 | != SC_VIDEOSTREAMING) { | ||
| 533 | uvc_trace(UVC_TRACE_DESCR, "device %d interface %d isn't a " | ||
| 534 | "video streaming interface\n", dev->udev->devnum, | ||
| 535 | intf->altsetting[0].desc.bInterfaceNumber); | ||
| 536 | return -EINVAL; | ||
| 537 | } | ||
| 538 | |||
| 539 | if (usb_driver_claim_interface(&uvc_driver.driver, intf, dev)) { | ||
| 540 | uvc_trace(UVC_TRACE_DESCR, "device %d interface %d is already " | ||
| 541 | "claimed\n", dev->udev->devnum, | ||
| 542 | intf->altsetting[0].desc.bInterfaceNumber); | ||
| 543 | return -EINVAL; | ||
| 544 | } | ||
| 545 | |||
| 546 | streaming = kzalloc(sizeof *streaming, GFP_KERNEL); | ||
| 547 | if (streaming == NULL) { | ||
| 548 | usb_driver_release_interface(&uvc_driver.driver, intf); | ||
| 549 | return -EINVAL; | ||
| 550 | } | ||
| 551 | |||
| 552 | mutex_init(&streaming->mutex); | ||
| 553 | streaming->intf = usb_get_intf(intf); | ||
| 554 | streaming->intfnum = intf->cur_altsetting->desc.bInterfaceNumber; | ||
| 555 | |||
| 556 | /* The Pico iMage webcam has its class-specific interface descriptors | ||
| 557 | * after the endpoint descriptors. | ||
| 558 | */ | ||
| 559 | if (buflen == 0) { | ||
| 560 | for (i = 0; i < alts->desc.bNumEndpoints; ++i) { | ||
| 561 | struct usb_host_endpoint *ep = &alts->endpoint[i]; | ||
| 562 | |||
| 563 | if (ep->extralen == 0) | ||
| 564 | continue; | ||
| 565 | |||
| 566 | if (ep->extralen > 2 && | ||
| 567 | ep->extra[1] == USB_DT_CS_INTERFACE) { | ||
| 568 | uvc_trace(UVC_TRACE_DESCR, "trying extra data " | ||
| 569 | "from endpoint %u.\n", i); | ||
| 570 | buffer = alts->endpoint[i].extra; | ||
| 571 | buflen = alts->endpoint[i].extralen; | ||
| 572 | break; | ||
| 573 | } | ||
| 574 | } | ||
| 575 | } | ||
| 576 | |||
| 577 | /* Skip the standard interface descriptors. */ | ||
| 578 | while (buflen > 2 && buffer[1] != USB_DT_CS_INTERFACE) { | ||
| 579 | buflen -= buffer[0]; | ||
| 580 | buffer += buffer[0]; | ||
| 581 | } | ||
| 582 | |||
| 583 | if (buflen <= 2) { | ||
| 584 | uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming " | ||
| 585 | "interface descriptors found.\n"); | ||
| 586 | goto error; | ||
| 587 | } | ||
| 588 | |||
| 589 | /* Parse the header descriptor. */ | ||
| 590 | if (buffer[2] == VS_OUTPUT_HEADER) { | ||
| 591 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface " | ||
| 592 | "%d OUTPUT HEADER descriptor is not supported.\n", | ||
| 593 | dev->udev->devnum, alts->desc.bInterfaceNumber); | ||
| 594 | goto error; | ||
| 595 | } else if (buffer[2] == VS_INPUT_HEADER) { | ||
| 596 | p = buflen >= 5 ? buffer[3] : 0; | ||
| 597 | n = buflen >= 12 ? buffer[12] : 0; | ||
| 598 | |||
| 599 | if (buflen < 13 + p*n || buffer[2] != VS_INPUT_HEADER) { | ||
| 600 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " | ||
| 601 | "interface %d INPUT HEADER descriptor is " | ||
| 602 | "invalid.\n", dev->udev->devnum, | ||
| 603 | alts->desc.bInterfaceNumber); | ||
| 604 | goto error; | ||
| 605 | } | ||
| 606 | |||
| 607 | streaming->header.bNumFormats = p; | ||
| 608 | streaming->header.bEndpointAddress = buffer[6]; | ||
| 609 | streaming->header.bmInfo = buffer[7]; | ||
| 610 | streaming->header.bTerminalLink = buffer[8]; | ||
| 611 | streaming->header.bStillCaptureMethod = buffer[9]; | ||
| 612 | streaming->header.bTriggerSupport = buffer[10]; | ||
| 613 | streaming->header.bTriggerUsage = buffer[11]; | ||
| 614 | streaming->header.bControlSize = n; | ||
| 615 | |||
| 616 | streaming->header.bmaControls = kmalloc(p*n, GFP_KERNEL); | ||
| 617 | if (streaming->header.bmaControls == NULL) { | ||
| 618 | ret = -ENOMEM; | ||
| 619 | goto error; | ||
| 620 | } | ||
| 621 | |||
| 622 | memcpy(streaming->header.bmaControls, &buffer[13], p*n); | ||
| 623 | } else { | ||
| 624 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface " | ||
| 625 | "%d HEADER descriptor not found.\n", dev->udev->devnum, | ||
| 626 | alts->desc.bInterfaceNumber); | ||
| 627 | goto error; | ||
| 628 | } | ||
| 629 | |||
| 630 | buflen -= buffer[0]; | ||
| 631 | buffer += buffer[0]; | ||
| 632 | |||
| 633 | _buffer = buffer; | ||
| 634 | _buflen = buflen; | ||
| 635 | |||
| 636 | /* Count the format and frame descriptors. */ | ||
| 637 | while (_buflen > 2) { | ||
| 638 | switch (_buffer[2]) { | ||
| 639 | case VS_FORMAT_UNCOMPRESSED: | ||
| 640 | case VS_FORMAT_MJPEG: | ||
| 641 | case VS_FORMAT_FRAME_BASED: | ||
| 642 | nformats++; | ||
| 643 | break; | ||
| 644 | |||
| 645 | case VS_FORMAT_DV: | ||
| 646 | /* DV format has no frame descriptor. We will create a | ||
| 647 | * dummy frame descriptor with a dummy frame interval. | ||
| 648 | */ | ||
| 649 | nformats++; | ||
| 650 | nframes++; | ||
| 651 | nintervals++; | ||
| 652 | break; | ||
| 653 | |||
| 654 | case VS_FORMAT_MPEG2TS: | ||
| 655 | case VS_FORMAT_STREAM_BASED: | ||
| 656 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " | ||
| 657 | "interface %d FORMAT %u is not supported.\n", | ||
| 658 | dev->udev->devnum, | ||
| 659 | alts->desc.bInterfaceNumber, _buffer[2]); | ||
| 660 | break; | ||
| 661 | |||
| 662 | case VS_FRAME_UNCOMPRESSED: | ||
| 663 | case VS_FRAME_MJPEG: | ||
| 664 | nframes++; | ||
| 665 | if (_buflen > 25) | ||
| 666 | nintervals += _buffer[25] ? _buffer[25] : 3; | ||
| 667 | break; | ||
| 668 | |||
| 669 | case VS_FRAME_FRAME_BASED: | ||
| 670 | nframes++; | ||
| 671 | if (_buflen > 21) | ||
| 672 | nintervals += _buffer[21] ? _buffer[21] : 3; | ||
| 673 | break; | ||
| 674 | } | ||
| 675 | |||
| 676 | _buflen -= _buffer[0]; | ||
| 677 | _buffer += _buffer[0]; | ||
| 678 | } | ||
| 679 | |||
| 680 | if (nformats == 0) { | ||
| 681 | uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface " | ||
| 682 | "%d has no supported formats defined.\n", | ||
| 683 | dev->udev->devnum, alts->desc.bInterfaceNumber); | ||
| 684 | goto error; | ||
| 685 | } | ||
| 686 | |||
| 687 | size = nformats * sizeof *format + nframes * sizeof *frame | ||
| 688 | + nintervals * sizeof *interval; | ||
| 689 | format = kzalloc(size, GFP_KERNEL); | ||
| 690 | if (format == NULL) { | ||
| 691 | ret = -ENOMEM; | ||
| 692 | goto error; | ||
| 693 | } | ||
| 694 | |||
| 695 | frame = (struct uvc_frame *)&format[nformats]; | ||
| 696 | interval = (__u32 *)&frame[nframes]; | ||
| 697 | |||
| 698 | streaming->format = format; | ||
| 699 | streaming->nformats = nformats; | ||
| 700 | |||
| 701 | /* Parse the format descriptors. */ | ||
| 702 | while (buflen > 2) { | ||
| 703 | switch (buffer[2]) { | ||
| 704 | case VS_FORMAT_UNCOMPRESSED: | ||
| 705 | case VS_FORMAT_MJPEG: | ||
| 706 | case VS_FORMAT_DV: | ||
| 707 | case VS_FORMAT_FRAME_BASED: | ||
| 708 | format->frame = frame; | ||
| 709 | ret = uvc_parse_format(dev, streaming, format, | ||
| 710 | &interval, buffer, buflen); | ||
| 711 | if (ret < 0) | ||
| 712 | goto error; | ||
| 713 | |||
| 714 | frame += format->nframes; | ||
| 715 | format++; | ||
| 716 | |||
| 717 | buflen -= ret; | ||
| 718 | buffer += ret; | ||
| 719 | continue; | ||
| 720 | |||
| 721 | default: | ||
| 722 | break; | ||
| 723 | } | ||
| 724 | |||
| 725 | buflen -= buffer[0]; | ||
| 726 | buffer += buffer[0]; | ||
| 727 | } | ||
| 728 | |||
| 729 | /* Parse the alternate settings to find the maximum bandwidth. */ | ||
| 730 | for (i = 0; i < intf->num_altsetting; ++i) { | ||
| 731 | struct usb_host_endpoint *ep; | ||
| 732 | alts = &intf->altsetting[i]; | ||
| 733 | ep = uvc_find_endpoint(alts, | ||
| 734 | streaming->header.bEndpointAddress); | ||
| 735 | if (ep == NULL) | ||
| 736 | continue; | ||
| 737 | |||
| 738 | psize = le16_to_cpu(ep->desc.wMaxPacketSize); | ||
| 739 | psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); | ||
| 740 | if (psize > streaming->maxpsize) | ||
| 741 | streaming->maxpsize = psize; | ||
| 742 | } | ||
| 743 | |||
| 744 | list_add_tail(&streaming->list, &dev->streaming); | ||
| 745 | return 0; | ||
| 746 | |||
| 747 | error: | ||
| 748 | usb_driver_release_interface(&uvc_driver.driver, intf); | ||
| 749 | usb_put_intf(intf); | ||
| 750 | kfree(streaming->format); | ||
| 751 | kfree(streaming->header.bmaControls); | ||
| 752 | kfree(streaming); | ||
| 753 | return ret; | ||
| 754 | } | ||
| 755 | |||
| 756 | /* Parse vendor-specific extensions. */ | ||
| 757 | static int uvc_parse_vendor_control(struct uvc_device *dev, | ||
| 758 | const unsigned char *buffer, int buflen) | ||
| 759 | { | ||
| 760 | struct usb_device *udev = dev->udev; | ||
| 761 | struct usb_host_interface *alts = dev->intf->cur_altsetting; | ||
| 762 | struct uvc_entity *unit; | ||
| 763 | unsigned int n, p; | ||
| 764 | int handled = 0; | ||
| 765 | |||
| 766 | switch (le16_to_cpu(dev->udev->descriptor.idVendor)) { | ||
| 767 | case 0x046d: /* Logitech */ | ||
| 768 | if (buffer[1] != 0x41 || buffer[2] != 0x01) | ||
| 769 | break; | ||
| 770 | |||
| 771 | /* Logitech implements several vendor specific functions | ||
| 772 | * through vendor specific extension units (LXU). | ||
| 773 | * | ||
| 774 | * The LXU descriptors are similar to XU descriptors | ||
| 775 | * (see "USB Device Video Class for Video Devices", section | ||
| 776 | * 3.7.2.6 "Extension Unit Descriptor") with the following | ||
| 777 | * differences: | ||
| 778 | * | ||
| 779 | * ---------------------------------------------------------- | ||
| 780 | * 0 bLength 1 Number | ||
| 781 | * Size of this descriptor, in bytes: 24+p+n*2 | ||
| 782 | * ---------------------------------------------------------- | ||
| 783 | * 23+p+n bmControlsType N Bitmap | ||
| 784 | * Individual bits in the set are defined: | ||
| 785 | * 0: Absolute | ||
| 786 | * 1: Relative | ||
| 787 | * | ||
| 788 | * This bitset is mapped exactly the same as bmControls. | ||
| 789 | * ---------------------------------------------------------- | ||
| 790 | * 23+p+n*2 bReserved 1 Boolean | ||
| 791 | * ---------------------------------------------------------- | ||
| 792 | * 24+p+n*2 iExtension 1 Index | ||
| 793 | * Index of a string descriptor that describes this | ||
| 794 | * extension unit. | ||
| 795 | * ---------------------------------------------------------- | ||
| 796 | */ | ||
| 797 | p = buflen >= 22 ? buffer[21] : 0; | ||
| 798 | n = buflen >= 25 + p ? buffer[22+p] : 0; | ||
| 799 | |||
| 800 | if (buflen < 25 + p + 2*n) { | ||
| 801 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | ||
| 802 | "interface %d EXTENSION_UNIT error\n", | ||
| 803 | udev->devnum, alts->desc.bInterfaceNumber); | ||
| 804 | break; | ||
| 805 | } | ||
| 806 | |||
| 807 | unit = kzalloc(sizeof *unit + p + 2*n, GFP_KERNEL); | ||
| 808 | if (unit == NULL) | ||
| 809 | return -ENOMEM; | ||
| 810 | |||
| 811 | unit->id = buffer[3]; | ||
| 812 | unit->type = VC_EXTENSION_UNIT; | ||
| 813 | memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); | ||
| 814 | unit->extension.bNumControls = buffer[20]; | ||
| 815 | unit->extension.bNrInPins = | ||
| 816 | le16_to_cpup((__le16 *)&buffer[21]); | ||
| 817 | unit->extension.baSourceID = (__u8 *)unit + sizeof *unit; | ||
| 818 | memcpy(unit->extension.baSourceID, &buffer[22], p); | ||
| 819 | unit->extension.bControlSize = buffer[22+p]; | ||
| 820 | unit->extension.bmControls = (__u8 *)unit + sizeof *unit + p; | ||
| 821 | unit->extension.bmControlsType = (__u8 *)unit + sizeof *unit | ||
| 822 | + p + n; | ||
| 823 | memcpy(unit->extension.bmControls, &buffer[23+p], 2*n); | ||
| 824 | |||
| 825 | if (buffer[24+p+2*n] != 0) | ||
| 826 | usb_string(udev, buffer[24+p+2*n], unit->name, | ||
| 827 | sizeof unit->name); | ||
| 828 | else | ||
| 829 | sprintf(unit->name, "Extension %u", buffer[3]); | ||
| 830 | |||
| 831 | list_add_tail(&unit->list, &dev->entities); | ||
| 832 | handled = 1; | ||
| 833 | break; | ||
| 834 | } | ||
| 835 | |||
| 836 | return handled; | ||
| 837 | } | ||
| 838 | |||
| 839 | static int uvc_parse_standard_control(struct uvc_device *dev, | ||
| 840 | const unsigned char *buffer, int buflen) | ||
| 841 | { | ||
| 842 | struct usb_device *udev = dev->udev; | ||
| 843 | struct uvc_entity *unit, *term; | ||
| 844 | struct usb_interface *intf; | ||
| 845 | struct usb_host_interface *alts = dev->intf->cur_altsetting; | ||
| 846 | unsigned int i, n, p, len; | ||
| 847 | __u16 type; | ||
| 848 | |||
| 849 | switch (buffer[2]) { | ||
| 850 | case VC_HEADER: | ||
| 851 | n = buflen >= 12 ? buffer[11] : 0; | ||
| 852 | |||
| 853 | if (buflen < 12 || buflen < 12 + n) { | ||
| 854 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | ||
| 855 | "interface %d HEADER error\n", udev->devnum, | ||
| 856 | alts->desc.bInterfaceNumber); | ||
| 857 | return -EINVAL; | ||
| 858 | } | ||
| 859 | |||
| 860 | dev->uvc_version = le16_to_cpup((__le16 *)&buffer[3]); | ||
| 861 | dev->clock_frequency = le32_to_cpup((__le32 *)&buffer[7]); | ||
| 862 | |||
| 863 | /* Parse all USB Video Streaming interfaces. */ | ||
| 864 | for (i = 0; i < n; ++i) { | ||
| 865 | intf = usb_ifnum_to_if(udev, buffer[12+i]); | ||
| 866 | if (intf == NULL) { | ||
| 867 | uvc_trace(UVC_TRACE_DESCR, "device %d " | ||
| 868 | "interface %d doesn't exists\n", | ||
| 869 | udev->devnum, i); | ||
| 870 | continue; | ||
| 871 | } | ||
| 872 | |||
| 873 | uvc_parse_streaming(dev, intf); | ||
| 874 | } | ||
| 875 | break; | ||
| 876 | |||
| 877 | case VC_INPUT_TERMINAL: | ||
| 878 | if (buflen < 8) { | ||
| 879 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | ||
| 880 | "interface %d INPUT_TERMINAL error\n", | ||
| 881 | udev->devnum, alts->desc.bInterfaceNumber); | ||
| 882 | return -EINVAL; | ||
| 883 | } | ||
| 884 | |||
| 885 | /* Make sure the terminal type MSB is not null, otherwise it | ||
| 886 | * could be confused with a unit. | ||
| 887 | */ | ||
| 888 | type = le16_to_cpup((__le16 *)&buffer[4]); | ||
| 889 | if ((type & 0xff00) == 0) { | ||
| 890 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | ||
| 891 | "interface %d INPUT_TERMINAL %d has invalid " | ||
| 892 | "type 0x%04x, skipping\n", udev->devnum, | ||
| 893 | alts->desc.bInterfaceNumber, | ||
| 894 | buffer[3], type); | ||
| 895 | return 0; | ||
| 896 | } | ||
| 897 | |||
| 898 | n = 0; | ||
| 899 | p = 0; | ||
| 900 | len = 8; | ||
| 901 | |||
| 902 | if (type == ITT_CAMERA) { | ||
| 903 | n = buflen >= 15 ? buffer[14] : 0; | ||
| 904 | len = 15; | ||
| 905 | |||
| 906 | } else if (type == ITT_MEDIA_TRANSPORT_INPUT) { | ||
| 907 | n = buflen >= 9 ? buffer[8] : 0; | ||
| 908 | p = buflen >= 10 + n ? buffer[9+n] : 0; | ||
| 909 | len = 10; | ||
| 910 | } | ||
| 911 | |||
| 912 | if (buflen < len + n + p) { | ||
| 913 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | ||
| 914 | "interface %d INPUT_TERMINAL error\n", | ||
| 915 | udev->devnum, alts->desc.bInterfaceNumber); | ||
| 916 | return -EINVAL; | ||
| 917 | } | ||
| 918 | |||
| 919 | term = kzalloc(sizeof *term + n + p, GFP_KERNEL); | ||
| 920 | if (term == NULL) | ||
| 921 | return -ENOMEM; | ||
| 922 | |||
| 923 | term->id = buffer[3]; | ||
| 924 | term->type = type | UVC_TERM_INPUT; | ||
| 925 | |||
| 926 | if (UVC_ENTITY_TYPE(term) == ITT_CAMERA) { | ||
| 927 | term->camera.bControlSize = n; | ||
| 928 | term->camera.bmControls = (__u8 *)term + sizeof *term; | ||
| 929 | term->camera.wObjectiveFocalLengthMin = | ||
| 930 | le16_to_cpup((__le16 *)&buffer[8]); | ||
| 931 | term->camera.wObjectiveFocalLengthMax = | ||
| 932 | le16_to_cpup((__le16 *)&buffer[10]); | ||
| 933 | term->camera.wOcularFocalLength = | ||
| 934 | le16_to_cpup((__le16 *)&buffer[12]); | ||
| 935 | memcpy(term->camera.bmControls, &buffer[15], n); | ||
| 936 | } else if (UVC_ENTITY_TYPE(term) == ITT_MEDIA_TRANSPORT_INPUT) { | ||
| 937 | term->media.bControlSize = n; | ||
| 938 | term->media.bmControls = (__u8 *)term + sizeof *term; | ||
| 939 | term->media.bTransportModeSize = p; | ||
| 940 | term->media.bmTransportModes = (__u8 *)term | ||
| 941 | + sizeof *term + n; | ||
| 942 | memcpy(term->media.bmControls, &buffer[9], n); | ||
| 943 | memcpy(term->media.bmTransportModes, &buffer[10+n], p); | ||
| 944 | } | ||
| 945 | |||
| 946 | if (buffer[7] != 0) | ||
| 947 | usb_string(udev, buffer[7], term->name, | ||
| 948 | sizeof term->name); | ||
| 949 | else if (UVC_ENTITY_TYPE(term) == ITT_CAMERA) | ||
| 950 | sprintf(term->name, "Camera %u", buffer[3]); | ||
| 951 | else if (UVC_ENTITY_TYPE(term) == ITT_MEDIA_TRANSPORT_INPUT) | ||
| 952 | sprintf(term->name, "Media %u", buffer[3]); | ||
| 953 | else | ||
| 954 | sprintf(term->name, "Input %u", buffer[3]); | ||
| 955 | |||
| 956 | list_add_tail(&term->list, &dev->entities); | ||
| 957 | break; | ||
| 958 | |||
| 959 | case VC_OUTPUT_TERMINAL: | ||
| 960 | if (buflen < 9) { | ||
| 961 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | ||
| 962 | "interface %d OUTPUT_TERMINAL error\n", | ||
| 963 | udev->devnum, alts->desc.bInterfaceNumber); | ||
| 964 | return -EINVAL; | ||
| 965 | } | ||
| 966 | |||
| 967 | /* Make sure the terminal type MSB is not null, otherwise it | ||
| 968 | * could be confused with a unit. | ||
| 969 | */ | ||
| 970 | type = le16_to_cpup((__le16 *)&buffer[4]); | ||
| 971 | if ((type & 0xff00) == 0) { | ||
| 972 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | ||
| 973 | "interface %d OUTPUT_TERMINAL %d has invalid " | ||
| 974 | "type 0x%04x, skipping\n", udev->devnum, | ||
| 975 | alts->desc.bInterfaceNumber, buffer[3], type); | ||
| 976 | return 0; | ||
| 977 | } | ||
| 978 | |||
| 979 | term = kzalloc(sizeof *term, GFP_KERNEL); | ||
| 980 | if (term == NULL) | ||
| 981 | return -ENOMEM; | ||
| 982 | |||
| 983 | term->id = buffer[3]; | ||
| 984 | term->type = type | UVC_TERM_OUTPUT; | ||
| 985 | term->output.bSourceID = buffer[7]; | ||
| 986 | |||
| 987 | if (buffer[8] != 0) | ||
| 988 | usb_string(udev, buffer[8], term->name, | ||
| 989 | sizeof term->name); | ||
| 990 | else | ||
| 991 | sprintf(term->name, "Output %u", buffer[3]); | ||
| 992 | |||
| 993 | list_add_tail(&term->list, &dev->entities); | ||
| 994 | break; | ||
| 995 | |||
| 996 | case VC_SELECTOR_UNIT: | ||
| 997 | p = buflen >= 5 ? buffer[4] : 0; | ||
| 998 | |||
| 999 | if (buflen < 5 || buflen < 6 + p) { | ||
| 1000 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | ||
| 1001 | "interface %d SELECTOR_UNIT error\n", | ||
| 1002 | udev->devnum, alts->desc.bInterfaceNumber); | ||
| 1003 | return -EINVAL; | ||
| 1004 | } | ||
| 1005 | |||
| 1006 | unit = kzalloc(sizeof *unit + p, GFP_KERNEL); | ||
| 1007 | if (unit == NULL) | ||
| 1008 | return -ENOMEM; | ||
| 1009 | |||
| 1010 | unit->id = buffer[3]; | ||
| 1011 | unit->type = buffer[2]; | ||
| 1012 | unit->selector.bNrInPins = buffer[4]; | ||
| 1013 | unit->selector.baSourceID = (__u8 *)unit + sizeof *unit; | ||
| 1014 | memcpy(unit->selector.baSourceID, &buffer[5], p); | ||
| 1015 | |||
| 1016 | if (buffer[5+p] != 0) | ||
| 1017 | usb_string(udev, buffer[5+p], unit->name, | ||
| 1018 | sizeof unit->name); | ||
| 1019 | else | ||
| 1020 | sprintf(unit->name, "Selector %u", buffer[3]); | ||
| 1021 | |||
| 1022 | list_add_tail(&unit->list, &dev->entities); | ||
| 1023 | break; | ||
| 1024 | |||
| 1025 | case VC_PROCESSING_UNIT: | ||
| 1026 | n = buflen >= 8 ? buffer[7] : 0; | ||
| 1027 | p = dev->uvc_version >= 0x0110 ? 10 : 9; | ||
| 1028 | |||
| 1029 | if (buflen < p + n) { | ||
| 1030 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | ||
| 1031 | "interface %d PROCESSING_UNIT error\n", | ||
| 1032 | udev->devnum, alts->desc.bInterfaceNumber); | ||
| 1033 | return -EINVAL; | ||
| 1034 | } | ||
| 1035 | |||
| 1036 | unit = kzalloc(sizeof *unit + n, GFP_KERNEL); | ||
| 1037 | if (unit == NULL) | ||
| 1038 | return -ENOMEM; | ||
| 1039 | |||
| 1040 | unit->id = buffer[3]; | ||
| 1041 | unit->type = buffer[2]; | ||
| 1042 | unit->processing.bSourceID = buffer[4]; | ||
| 1043 | unit->processing.wMaxMultiplier = | ||
| 1044 | le16_to_cpup((__le16 *)&buffer[5]); | ||
| 1045 | unit->processing.bControlSize = buffer[7]; | ||
| 1046 | unit->processing.bmControls = (__u8 *)unit + sizeof *unit; | ||
| 1047 | memcpy(unit->processing.bmControls, &buffer[8], n); | ||
| 1048 | if (dev->uvc_version >= 0x0110) | ||
| 1049 | unit->processing.bmVideoStandards = buffer[9+n]; | ||
| 1050 | |||
| 1051 | if (buffer[8+n] != 0) | ||
| 1052 | usb_string(udev, buffer[8+n], unit->name, | ||
| 1053 | sizeof unit->name); | ||
| 1054 | else | ||
| 1055 | sprintf(unit->name, "Processing %u", buffer[3]); | ||
| 1056 | |||
| 1057 | list_add_tail(&unit->list, &dev->entities); | ||
| 1058 | break; | ||
| 1059 | |||
| 1060 | case VC_EXTENSION_UNIT: | ||
| 1061 | p = buflen >= 22 ? buffer[21] : 0; | ||
| 1062 | n = buflen >= 24 + p ? buffer[22+p] : 0; | ||
| 1063 | |||
| 1064 | if (buflen < 24 + p + n) { | ||
| 1065 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | ||
| 1066 | "interface %d EXTENSION_UNIT error\n", | ||
| 1067 | udev->devnum, alts->desc.bInterfaceNumber); | ||
| 1068 | return -EINVAL; | ||
| 1069 | } | ||
| 1070 | |||
| 1071 | unit = kzalloc(sizeof *unit + p + n, GFP_KERNEL); | ||
| 1072 | if (unit == NULL) | ||
| 1073 | return -ENOMEM; | ||
| 1074 | |||
| 1075 | unit->id = buffer[3]; | ||
| 1076 | unit->type = buffer[2]; | ||
| 1077 | memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); | ||
| 1078 | unit->extension.bNumControls = buffer[20]; | ||
| 1079 | unit->extension.bNrInPins = | ||
| 1080 | le16_to_cpup((__le16 *)&buffer[21]); | ||
| 1081 | unit->extension.baSourceID = (__u8 *)unit + sizeof *unit; | ||
| 1082 | memcpy(unit->extension.baSourceID, &buffer[22], p); | ||
| 1083 | unit->extension.bControlSize = buffer[22+p]; | ||
| 1084 | unit->extension.bmControls = (__u8 *)unit + sizeof *unit + p; | ||
| 1085 | memcpy(unit->extension.bmControls, &buffer[23+p], n); | ||
| 1086 | |||
| 1087 | if (buffer[23+p+n] != 0) | ||
| 1088 | usb_string(udev, buffer[23+p+n], unit->name, | ||
| 1089 | sizeof unit->name); | ||
| 1090 | else | ||
| 1091 | sprintf(unit->name, "Extension %u", buffer[3]); | ||
| 1092 | |||
| 1093 | list_add_tail(&unit->list, &dev->entities); | ||
| 1094 | break; | ||
| 1095 | |||
| 1096 | default: | ||
| 1097 | uvc_trace(UVC_TRACE_DESCR, "Found an unknown CS_INTERFACE " | ||
| 1098 | "descriptor (%u)\n", buffer[2]); | ||
| 1099 | break; | ||
| 1100 | } | ||
| 1101 | |||
| 1102 | return 0; | ||
| 1103 | } | ||
| 1104 | |||
| 1105 | static int uvc_parse_control(struct uvc_device *dev) | ||
| 1106 | { | ||
| 1107 | struct usb_host_interface *alts = dev->intf->cur_altsetting; | ||
| 1108 | unsigned char *buffer = alts->extra; | ||
| 1109 | int buflen = alts->extralen; | ||
| 1110 | int ret; | ||
| 1111 | |||
| 1112 | /* Parse the default alternate setting only, as the UVC specification | ||
| 1113 | * defines a single alternate setting, the default alternate setting | ||
| 1114 | * zero. | ||
| 1115 | */ | ||
| 1116 | |||
| 1117 | while (buflen > 2) { | ||
| 1118 | if (uvc_parse_vendor_control(dev, buffer, buflen) || | ||
| 1119 | buffer[1] != USB_DT_CS_INTERFACE) | ||
| 1120 | goto next_descriptor; | ||
| 1121 | |||
| 1122 | if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0) | ||
| 1123 | return ret; | ||
| 1124 | |||
| 1125 | next_descriptor: | ||
| 1126 | buflen -= buffer[0]; | ||
| 1127 | buffer += buffer[0]; | ||
| 1128 | } | ||
| 1129 | |||
| 1130 | /* Check if the optional status endpoint is present. */ | ||
| 1131 | if (alts->desc.bNumEndpoints == 1) { | ||
| 1132 | struct usb_host_endpoint *ep = &alts->endpoint[0]; | ||
| 1133 | struct usb_endpoint_descriptor *desc = &ep->desc; | ||
| 1134 | |||
| 1135 | if (usb_endpoint_is_int_in(desc) && | ||
| 1136 | le16_to_cpu(desc->wMaxPacketSize) >= 8 && | ||
| 1137 | desc->bInterval != 0) { | ||
| 1138 | uvc_trace(UVC_TRACE_DESCR, "Found a Status endpoint " | ||
| 1139 | "(addr %02x).\n", desc->bEndpointAddress); | ||
| 1140 | dev->int_ep = ep; | ||
| 1141 | } | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | return 0; | ||
| 1145 | } | ||
| 1146 | |||
| 1147 | /* ------------------------------------------------------------------------ | ||
| 1148 | * USB probe and disconnect | ||
| 1149 | */ | ||
| 1150 | |||
| 1151 | /* | ||
| 1152 | * Unregister the video devices. | ||
| 1153 | */ | ||
| 1154 | static void uvc_unregister_video(struct uvc_device *dev) | ||
| 1155 | { | ||
| 1156 | if (dev->video.vdev) { | ||
| 1157 | if (dev->video.vdev->minor == -1) | ||
| 1158 | video_device_release(dev->video.vdev); | ||
| 1159 | else | ||
| 1160 | video_unregister_device(dev->video.vdev); | ||
| 1161 | dev->video.vdev = NULL; | ||
| 1162 | } | ||
| 1163 | } | ||
| 1164 | |||
| 1165 | /* | ||
| 1166 | * Scan the UVC descriptors to locate a chain starting at an Output Terminal | ||
| 1167 | * and containing the following units: | ||
| 1168 | * | ||
| 1169 | * - a USB Streaming Output Terminal | ||
| 1170 | * - zero or one Processing Unit | ||
| 1171 | * - zero, one or mode single-input Selector Units | ||
| 1172 | * - zero or one multiple-input Selector Units, provided all inputs are | ||
| 1173 | * connected to input terminals | ||
| 1174 | * - zero, one or mode single-input Extension Units | ||
| 1175 | * - one Camera Input Terminal, or one or more External terminals. | ||
| 1176 | * | ||
| 1177 | * A side forward scan is made on each detected entity to check for additional | ||
| 1178 | * extension units. | ||
| 1179 | */ | ||
| 1180 | static int uvc_scan_chain_entity(struct uvc_video_device *video, | ||
| 1181 | struct uvc_entity *entity) | ||
| 1182 | { | ||
| 1183 | switch (UVC_ENTITY_TYPE(entity)) { | ||
| 1184 | case VC_EXTENSION_UNIT: | ||
| 1185 | if (uvc_trace_param & UVC_TRACE_PROBE) | ||
| 1186 | printk(" <- XU %d", entity->id); | ||
| 1187 | |||
| 1188 | if (entity->extension.bNrInPins != 1) { | ||
| 1189 | uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more " | ||
| 1190 | "than 1 input pin.\n", entity->id); | ||
| 1191 | return -1; | ||
| 1192 | } | ||
| 1193 | |||
| 1194 | list_add_tail(&entity->chain, &video->extensions); | ||
| 1195 | break; | ||
| 1196 | |||
| 1197 | case VC_PROCESSING_UNIT: | ||
| 1198 | if (uvc_trace_param & UVC_TRACE_PROBE) | ||
| 1199 | printk(" <- PU %d", entity->id); | ||
| 1200 | |||
| 1201 | if (video->processing != NULL) { | ||
| 1202 | uvc_trace(UVC_TRACE_DESCR, "Found multiple " | ||
| 1203 | "Processing Units in chain.\n"); | ||
| 1204 | return -1; | ||
| 1205 | } | ||
| 1206 | |||
| 1207 | video->processing = entity; | ||
| 1208 | break; | ||
| 1209 | |||
| 1210 | case VC_SELECTOR_UNIT: | ||
| 1211 | if (uvc_trace_param & UVC_TRACE_PROBE) | ||
| 1212 | printk(" <- SU %d", entity->id); | ||
| 1213 | |||
| 1214 | /* Single-input selector units are ignored. */ | ||
| 1215 | if (entity->selector.bNrInPins == 1) | ||
| 1216 | break; | ||
| 1217 | |||
| 1218 | if (video->selector != NULL) { | ||
| 1219 | uvc_trace(UVC_TRACE_DESCR, "Found multiple Selector " | ||
| 1220 | "Units in chain.\n"); | ||
| 1221 | return -1; | ||
| 1222 | } | ||
| 1223 | |||
| 1224 | video->selector = entity; | ||
| 1225 | break; | ||
| 1226 | |||
| 1227 | case ITT_VENDOR_SPECIFIC: | ||
| 1228 | case ITT_CAMERA: | ||
| 1229 | case ITT_MEDIA_TRANSPORT_INPUT: | ||
| 1230 | if (uvc_trace_param & UVC_TRACE_PROBE) | ||
| 1231 | printk(" <- IT %d\n", entity->id); | ||
| 1232 | |||
| 1233 | list_add_tail(&entity->chain, &video->iterms); | ||
| 1234 | break; | ||
| 1235 | |||
| 1236 | default: | ||
| 1237 | uvc_trace(UVC_TRACE_DESCR, "Unsupported entity type " | ||
| 1238 | "0x%04x found in chain.\n", UVC_ENTITY_TYPE(entity)); | ||
| 1239 | return -1; | ||
| 1240 | } | ||
| 1241 | |||
| 1242 | return 0; | ||
| 1243 | } | ||
| 1244 | |||
| 1245 | static int uvc_scan_chain_forward(struct uvc_video_device *video, | ||
| 1246 | struct uvc_entity *entity, struct uvc_entity *prev) | ||
| 1247 | { | ||
| 1248 | struct uvc_entity *forward; | ||
| 1249 | int found; | ||
| 1250 | |||
| 1251 | /* Forward scan */ | ||
| 1252 | forward = NULL; | ||
| 1253 | found = 0; | ||
| 1254 | |||
| 1255 | while (1) { | ||
| 1256 | forward = uvc_entity_by_reference(video->dev, entity->id, | ||
| 1257 | forward); | ||
| 1258 | if (forward == NULL) | ||
| 1259 | break; | ||
| 1260 | |||
| 1261 | if (UVC_ENTITY_TYPE(forward) != VC_EXTENSION_UNIT || | ||
| 1262 | forward == prev) | ||
| 1263 | continue; | ||
| 1264 | |||
| 1265 | if (forward->extension.bNrInPins != 1) { | ||
| 1266 | uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has" | ||
| 1267 | "more than 1 input pin.\n", entity->id); | ||
| 1268 | return -1; | ||
| 1269 | } | ||
| 1270 | |||
| 1271 | list_add_tail(&forward->chain, &video->extensions); | ||
| 1272 | if (uvc_trace_param & UVC_TRACE_PROBE) { | ||
| 1273 | if (!found) | ||
| 1274 | printk(" (-> XU"); | ||
| 1275 | |||
| 1276 | printk(" %d", forward->id); | ||
| 1277 | found = 1; | ||
| 1278 | } | ||
| 1279 | } | ||
| 1280 | if (found) | ||
| 1281 | printk(")"); | ||
| 1282 | |||
| 1283 | return 0; | ||
| 1284 | } | ||
| 1285 | |||
| 1286 | static int uvc_scan_chain_backward(struct uvc_video_device *video, | ||
| 1287 | struct uvc_entity *entity) | ||
| 1288 | { | ||
| 1289 | struct uvc_entity *term; | ||
| 1290 | int id = -1, i; | ||
| 1291 | |||
| 1292 | switch (UVC_ENTITY_TYPE(entity)) { | ||
| 1293 | case VC_EXTENSION_UNIT: | ||
| 1294 | id = entity->extension.baSourceID[0]; | ||
| 1295 | break; | ||
| 1296 | |||
| 1297 | case VC_PROCESSING_UNIT: | ||
| 1298 | id = entity->processing.bSourceID; | ||
| 1299 | break; | ||
| 1300 | |||
| 1301 | case VC_SELECTOR_UNIT: | ||
| 1302 | /* Single-input selector units are ignored. */ | ||
| 1303 | if (entity->selector.bNrInPins == 1) { | ||
| 1304 | id = entity->selector.baSourceID[0]; | ||
| 1305 | break; | ||
| 1306 | } | ||
| 1307 | |||
| 1308 | if (uvc_trace_param & UVC_TRACE_PROBE) | ||
| 1309 | printk(" <- IT"); | ||
| 1310 | |||
| 1311 | video->selector = entity; | ||
| 1312 | for (i = 0; i < entity->selector.bNrInPins; ++i) { | ||
| 1313 | id = entity->selector.baSourceID[i]; | ||
| 1314 | term = uvc_entity_by_id(video->dev, id); | ||
| 1315 | if (term == NULL || !UVC_ENTITY_IS_ITERM(term)) { | ||
| 1316 | uvc_trace(UVC_TRACE_DESCR, "Selector unit %d " | ||
| 1317 | "input %d isn't connected to an " | ||
| 1318 | "input terminal\n", entity->id, i); | ||
| 1319 | return -1; | ||
| 1320 | } | ||
| 1321 | |||
| 1322 | if (uvc_trace_param & UVC_TRACE_PROBE) | ||
| 1323 | printk(" %d", term->id); | ||
| 1324 | |||
| 1325 | list_add_tail(&term->chain, &video->iterms); | ||
| 1326 | uvc_scan_chain_forward(video, term, entity); | ||
| 1327 | } | ||
| 1328 | |||
| 1329 | if (uvc_trace_param & UVC_TRACE_PROBE) | ||
| 1330 | printk("\n"); | ||
| 1331 | |||
| 1332 | id = 0; | ||
| 1333 | break; | ||
| 1334 | } | ||
| 1335 | |||
| 1336 | return id; | ||
| 1337 | } | ||
| 1338 | |||
| 1339 | static int uvc_scan_chain(struct uvc_video_device *video) | ||
| 1340 | { | ||
| 1341 | struct uvc_entity *entity, *prev; | ||
| 1342 | int id; | ||
| 1343 | |||
| 1344 | entity = video->oterm; | ||
| 1345 | uvc_trace(UVC_TRACE_PROBE, "Scanning UVC chain: OT %d", entity->id); | ||
| 1346 | id = entity->output.bSourceID; | ||
| 1347 | while (id != 0) { | ||
| 1348 | prev = entity; | ||
| 1349 | entity = uvc_entity_by_id(video->dev, id); | ||
| 1350 | if (entity == NULL) { | ||
| 1351 | uvc_trace(UVC_TRACE_DESCR, "Found reference to " | ||
| 1352 | "unknown entity %d.\n", id); | ||
| 1353 | return -1; | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | /* Process entity */ | ||
| 1357 | if (uvc_scan_chain_entity(video, entity) < 0) | ||
| 1358 | return -1; | ||
| 1359 | |||
| 1360 | /* Forward scan */ | ||
| 1361 | if (uvc_scan_chain_forward(video, entity, prev) < 0) | ||
| 1362 | return -1; | ||
| 1363 | |||
| 1364 | /* Stop when a terminal is found. */ | ||
| 1365 | if (!UVC_ENTITY_IS_UNIT(entity)) | ||
| 1366 | break; | ||
| 1367 | |||
| 1368 | /* Backward scan */ | ||
| 1369 | id = uvc_scan_chain_backward(video, entity); | ||
| 1370 | if (id < 0) | ||
| 1371 | return id; | ||
| 1372 | } | ||
| 1373 | |||
| 1374 | /* Initialize the video buffers queue. */ | ||
| 1375 | uvc_queue_init(&video->queue); | ||
| 1376 | |||
| 1377 | return 0; | ||
| 1378 | } | ||
| 1379 | |||
| 1380 | /* | ||
| 1381 | * Register the video devices. | ||
| 1382 | * | ||
| 1383 | * The driver currently supports a single video device per control interface | ||
| 1384 | * only. The terminal and units must match the following structure: | ||
| 1385 | * | ||
| 1386 | * ITT_CAMERA -> VC_PROCESSING_UNIT -> VC_EXTENSION_UNIT{0,n} -> TT_STREAMING | ||
| 1387 | * | ||
| 1388 | * The Extension Units, if present, must have a single input pin. The | ||
| 1389 | * Processing Unit and Extension Units can be in any order. Additional | ||
| 1390 | * Extension Units connected to the main chain as single-unit branches are | ||
| 1391 | * also supported. | ||
| 1392 | */ | ||
| 1393 | static int uvc_register_video(struct uvc_device *dev) | ||
| 1394 | { | ||
| 1395 | struct video_device *vdev; | ||
| 1396 | struct uvc_entity *term; | ||
| 1397 | int found = 0, ret; | ||
| 1398 | |||
| 1399 | /* Check if the control interface matches the structure we expect. */ | ||
| 1400 | list_for_each_entry(term, &dev->entities, list) { | ||
| 1401 | struct uvc_streaming *streaming; | ||
| 1402 | |||
| 1403 | if (UVC_ENTITY_TYPE(term) != TT_STREAMING) | ||
| 1404 | continue; | ||
| 1405 | |||
| 1406 | memset(&dev->video, 0, sizeof dev->video); | ||
| 1407 | mutex_init(&dev->video.ctrl_mutex); | ||
| 1408 | INIT_LIST_HEAD(&dev->video.iterms); | ||
| 1409 | INIT_LIST_HEAD(&dev->video.extensions); | ||
| 1410 | dev->video.oterm = term; | ||
| 1411 | dev->video.dev = dev; | ||
| 1412 | if (uvc_scan_chain(&dev->video) < 0) | ||
| 1413 | continue; | ||
| 1414 | |||
| 1415 | list_for_each_entry(streaming, &dev->streaming, list) { | ||
| 1416 | if (streaming->header.bTerminalLink == term->id) { | ||
| 1417 | dev->video.streaming = streaming; | ||
| 1418 | found = 1; | ||
| 1419 | break; | ||
| 1420 | } | ||
| 1421 | } | ||
| 1422 | |||
| 1423 | if (found) | ||
| 1424 | break; | ||
| 1425 | } | ||
| 1426 | |||
| 1427 | if (!found) { | ||
| 1428 | uvc_printk(KERN_INFO, "No valid video chain found.\n"); | ||
| 1429 | return -1; | ||
| 1430 | } | ||
| 1431 | |||
| 1432 | if (uvc_trace_param & UVC_TRACE_PROBE) { | ||
| 1433 | uvc_printk(KERN_INFO, "Found a valid video chain ("); | ||
| 1434 | list_for_each_entry(term, &dev->video.iterms, chain) { | ||
| 1435 | printk("%d", term->id); | ||
| 1436 | if (term->chain.next != &dev->video.iterms) | ||
| 1437 | printk(","); | ||
| 1438 | } | ||
| 1439 | printk(" -> %d).\n", dev->video.oterm->id); | ||
| 1440 | } | ||
| 1441 | |||
| 1442 | /* Initialize the streaming interface with default streaming | ||
| 1443 | * parameters. | ||
| 1444 | */ | ||
| 1445 | if ((ret = uvc_video_init(&dev->video)) < 0) { | ||
| 1446 | uvc_printk(KERN_ERR, "Failed to initialize the device " | ||
| 1447 | "(%d).\n", ret); | ||
| 1448 | return ret; | ||
| 1449 | } | ||
| 1450 | |||
| 1451 | /* Register the device with V4L. */ | ||
| 1452 | vdev = video_device_alloc(); | ||
| 1453 | if (vdev == NULL) | ||
| 1454 | return -1; | ||
| 1455 | |||
| 1456 | /* We already hold a reference to dev->udev. The video device will be | ||
| 1457 | * unregistered before the reference is released, so we don't need to | ||
| 1458 | * get another one. | ||
| 1459 | */ | ||
| 1460 | vdev->dev = &dev->intf->dev; | ||
| 1461 | vdev->type = 0; | ||
| 1462 | vdev->type2 = 0; | ||
| 1463 | vdev->minor = -1; | ||
| 1464 | vdev->fops = &uvc_fops; | ||
| 1465 | vdev->release = video_device_release; | ||
| 1466 | strncpy(vdev->name, dev->name, sizeof vdev->name); | ||
| 1467 | |||
| 1468 | /* Set the driver data before calling video_register_device, otherwise | ||
| 1469 | * uvc_v4l2_open might race us. | ||
| 1470 | * | ||
| 1471 | * FIXME: usb_set_intfdata hasn't been called so far. Is that a | ||
| 1472 | * problem ? Does any function which could be called here get | ||
| 1473 | * a pointer to the usb_interface ? | ||
| 1474 | */ | ||
| 1475 | dev->video.vdev = vdev; | ||
| 1476 | video_set_drvdata(vdev, &dev->video); | ||
| 1477 | |||
| 1478 | if (video_register_device(vdev, VFL_TYPE_GRABBER, -1) < 0) { | ||
| 1479 | dev->video.vdev = NULL; | ||
| 1480 | video_device_release(vdev); | ||
| 1481 | return -1; | ||
| 1482 | } | ||
| 1483 | |||
| 1484 | return 0; | ||
| 1485 | } | ||
| 1486 | |||
| 1487 | /* | ||
| 1488 | * Delete the UVC device. | ||
| 1489 | * | ||
| 1490 | * Called by the kernel when the last reference to the uvc_device structure | ||
| 1491 | * is released. | ||
| 1492 | * | ||
| 1493 | * Unregistering the video devices is done here because every opened instance | ||
| 1494 | * must be closed before the device can be unregistered. An alternative would | ||
| 1495 | * have been to use another reference count for uvc_v4l2_open/uvc_release, and | ||
| 1496 | * unregister the video devices on disconnect when that reference count drops | ||
| 1497 | * to zero. | ||
| 1498 | * | ||
| 1499 | * As this function is called after or during disconnect(), all URBs have | ||
| 1500 | * already been canceled by the USB core. There is no need to kill the | ||
| 1501 | * interrupt URB manually. | ||
| 1502 | */ | ||
| 1503 | void uvc_delete(struct kref *kref) | ||
| 1504 | { | ||
| 1505 | struct uvc_device *dev = container_of(kref, struct uvc_device, kref); | ||
| 1506 | struct list_head *p, *n; | ||
| 1507 | |||
| 1508 | /* Unregister the video device */ | ||
| 1509 | uvc_unregister_video(dev); | ||
| 1510 | usb_put_intf(dev->intf); | ||
| 1511 | usb_put_dev(dev->udev); | ||
| 1512 | |||
| 1513 | uvc_status_cleanup(dev); | ||
| 1514 | uvc_ctrl_cleanup_device(dev); | ||
| 1515 | |||
| 1516 | list_for_each_safe(p, n, &dev->entities) { | ||
| 1517 | struct uvc_entity *entity; | ||
| 1518 | entity = list_entry(p, struct uvc_entity, list); | ||
| 1519 | kfree(entity); | ||
| 1520 | } | ||
| 1521 | |||
| 1522 | list_for_each_safe(p, n, &dev->streaming) { | ||
| 1523 | struct uvc_streaming *streaming; | ||
| 1524 | streaming = list_entry(p, struct uvc_streaming, list); | ||
| 1525 | usb_driver_release_interface(&uvc_driver.driver, | ||
| 1526 | streaming->intf); | ||
| 1527 | usb_put_intf(streaming->intf); | ||
| 1528 | kfree(streaming->format); | ||
| 1529 | kfree(streaming->header.bmaControls); | ||
| 1530 | kfree(streaming); | ||
| 1531 | } | ||
| 1532 | |||
| 1533 | kfree(dev); | ||
| 1534 | } | ||
| 1535 | |||
| 1536 | static int uvc_probe(struct usb_interface *intf, | ||
| 1537 | const struct usb_device_id *id) | ||
| 1538 | { | ||
| 1539 | struct usb_device *udev = interface_to_usbdev(intf); | ||
| 1540 | struct uvc_device *dev; | ||
| 1541 | int ret; | ||
| 1542 | |||
| 1543 | if (id->idVendor && id->idProduct) | ||
| 1544 | uvc_trace(UVC_TRACE_PROBE, "Probing known UVC device %s " | ||
| 1545 | "(%04x:%04x)\n", udev->devpath, id->idVendor, | ||
| 1546 | id->idProduct); | ||
| 1547 | else | ||
| 1548 | uvc_trace(UVC_TRACE_PROBE, "Probing generic UVC device %s\n", | ||
| 1549 | udev->devpath); | ||
| 1550 | |||
| 1551 | /* Allocate memory for the device and initialize it */ | ||
| 1552 | if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL) | ||
| 1553 | return -ENOMEM; | ||
| 1554 | |||
| 1555 | INIT_LIST_HEAD(&dev->entities); | ||
| 1556 | INIT_LIST_HEAD(&dev->streaming); | ||
| 1557 | kref_init(&dev->kref); | ||
| 1558 | |||
| 1559 | dev->udev = usb_get_dev(udev); | ||
| 1560 | dev->intf = usb_get_intf(intf); | ||
| 1561 | dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber; | ||
| 1562 | dev->quirks = id->driver_info | uvc_quirks_param; | ||
| 1563 | |||
| 1564 | if (udev->product != NULL) | ||
| 1565 | strncpy(dev->name, udev->product, sizeof dev->name); | ||
| 1566 | else | ||
| 1567 | snprintf(dev->name, sizeof dev->name, | ||
| 1568 | "UVC Camera (%04x:%04x)", | ||
| 1569 | le16_to_cpu(udev->descriptor.idVendor), | ||
| 1570 | le16_to_cpu(udev->descriptor.idProduct)); | ||
| 1571 | |||
| 1572 | /* Parse the Video Class control descriptor */ | ||
| 1573 | if (uvc_parse_control(dev) < 0) { | ||
| 1574 | uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC " | ||
| 1575 | "descriptors.\n"); | ||
| 1576 | goto error; | ||
| 1577 | } | ||
| 1578 | |||
| 1579 | uvc_printk(KERN_INFO, "Found UVC %u.%02u device %s (%04x:%04x)\n", | ||
| 1580 | dev->uvc_version >> 8, dev->uvc_version & 0xff, | ||
| 1581 | udev->product ? udev->product : "<unnamed>", | ||
| 1582 | le16_to_cpu(udev->descriptor.idVendor), | ||
| 1583 | le16_to_cpu(udev->descriptor.idProduct)); | ||
| 1584 | |||
| 1585 | if (uvc_quirks_param != 0) { | ||
| 1586 | uvc_printk(KERN_INFO, "Forcing device quirks 0x%x by module " | ||
| 1587 | "parameter for testing purpose.\n", uvc_quirks_param); | ||
| 1588 | uvc_printk(KERN_INFO, "Please report required quirks to the " | ||
| 1589 | "linux-uvc-devel mailing list.\n"); | ||
| 1590 | } | ||
| 1591 | |||
| 1592 | /* Initialize controls */ | ||
| 1593 | if (uvc_ctrl_init_device(dev) < 0) | ||
| 1594 | goto error; | ||
| 1595 | |||
| 1596 | /* Register the video devices */ | ||
| 1597 | if (uvc_register_video(dev) < 0) | ||
| 1598 | goto error; | ||
| 1599 | |||
| 1600 | /* Save our data pointer in the interface data */ | ||
| 1601 | usb_set_intfdata(intf, dev); | ||
| 1602 | |||
| 1603 | /* Initialize the interrupt URB */ | ||
| 1604 | if ((ret = uvc_status_init(dev)) < 0) { | ||
| 1605 | uvc_printk(KERN_INFO, "Unable to initialize the status " | ||
| 1606 | "endpoint (%d), status interrupt will not be " | ||
| 1607 | "supported.\n", ret); | ||
| 1608 | } | ||
| 1609 | |||
| 1610 | uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n"); | ||
| 1611 | return 0; | ||
| 1612 | |||
| 1613 | error: | ||
| 1614 | kref_put(&dev->kref, uvc_delete); | ||
| 1615 | return -ENODEV; | ||
| 1616 | } | ||
| 1617 | |||
| 1618 | static void uvc_disconnect(struct usb_interface *intf) | ||
| 1619 | { | ||
| 1620 | struct uvc_device *dev = usb_get_intfdata(intf); | ||
| 1621 | |||
| 1622 | /* Set the USB interface data to NULL. This can be done outside the | ||
| 1623 | * lock, as there's no other reader. | ||
| 1624 | */ | ||
| 1625 | usb_set_intfdata(intf, NULL); | ||
| 1626 | |||
| 1627 | if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOSTREAMING) | ||
| 1628 | return; | ||
| 1629 | |||
| 1630 | /* uvc_v4l2_open() might race uvc_disconnect(). A static driver-wide | ||
| 1631 | * lock is needed to prevent uvc_disconnect from releasing its | ||
| 1632 | * reference to the uvc_device instance after uvc_v4l2_open() received | ||
| 1633 | * the pointer to the device (video_devdata) but before it got the | ||
| 1634 | * chance to increase the reference count (kref_get). | ||
| 1635 | */ | ||
| 1636 | mutex_lock(&uvc_driver.open_mutex); | ||
| 1637 | |||
| 1638 | dev->state |= UVC_DEV_DISCONNECTED; | ||
| 1639 | kref_put(&dev->kref, uvc_delete); | ||
| 1640 | |||
| 1641 | mutex_unlock(&uvc_driver.open_mutex); | ||
| 1642 | } | ||
| 1643 | |||
| 1644 | static int uvc_suspend(struct usb_interface *intf, pm_message_t message) | ||
| 1645 | { | ||
| 1646 | struct uvc_device *dev = usb_get_intfdata(intf); | ||
| 1647 | |||
| 1648 | uvc_trace(UVC_TRACE_SUSPEND, "Suspending interface %u\n", | ||
| 1649 | intf->cur_altsetting->desc.bInterfaceNumber); | ||
| 1650 | |||
| 1651 | /* Controls are cached on the fly so they don't need to be saved. */ | ||
| 1652 | if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOCONTROL) | ||
| 1653 | return uvc_status_suspend(dev); | ||
| 1654 | |||
| 1655 | if (dev->video.streaming->intf != intf) { | ||
| 1656 | uvc_trace(UVC_TRACE_SUSPEND, "Suspend: video streaming USB " | ||
| 1657 | "interface mismatch.\n"); | ||
| 1658 | return -EINVAL; | ||
| 1659 | } | ||
| 1660 | |||
| 1661 | return uvc_video_suspend(&dev->video); | ||
| 1662 | } | ||
| 1663 | |||
| 1664 | static int uvc_resume(struct usb_interface *intf) | ||
| 1665 | { | ||
| 1666 | struct uvc_device *dev = usb_get_intfdata(intf); | ||
| 1667 | int ret; | ||
| 1668 | |||
| 1669 | uvc_trace(UVC_TRACE_SUSPEND, "Resuming interface %u\n", | ||
| 1670 | intf->cur_altsetting->desc.bInterfaceNumber); | ||
| 1671 | |||
| 1672 | if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOCONTROL) { | ||
| 1673 | if ((ret = uvc_ctrl_resume_device(dev)) < 0) | ||
| 1674 | return ret; | ||
| 1675 | |||
| 1676 | return uvc_status_resume(dev); | ||
| 1677 | } | ||
| 1678 | |||
| 1679 | if (dev->video.streaming->intf != intf) { | ||
| 1680 | uvc_trace(UVC_TRACE_SUSPEND, "Resume: video streaming USB " | ||
| 1681 | "interface mismatch.\n"); | ||
| 1682 | return -EINVAL; | ||
| 1683 | } | ||
| 1684 | |||
| 1685 | return uvc_video_resume(&dev->video); | ||
| 1686 | } | ||
| 1687 | |||
| 1688 | /* ------------------------------------------------------------------------ | ||
| 1689 | * Driver initialization and cleanup | ||
| 1690 | */ | ||
| 1691 | |||
| 1692 | /* | ||
| 1693 | * The Logitech cameras listed below have their interface class set to | ||
| 1694 | * VENDOR_SPEC because they don't announce themselves as UVC devices, even | ||
| 1695 | * though they are compliant. | ||
| 1696 | */ | ||
| 1697 | static struct usb_device_id uvc_ids[] = { | ||
| 1698 | /* ALi M5606 (Clevo M540SR) */ | ||
| 1699 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1700 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1701 | .idVendor = 0x0402, | ||
| 1702 | .idProduct = 0x5606, | ||
| 1703 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1704 | .bInterfaceSubClass = 1, | ||
| 1705 | .bInterfaceProtocol = 0, | ||
| 1706 | .driver_info = UVC_QUIRK_PROBE_MINMAX }, | ||
| 1707 | /* Creative Live! Optia */ | ||
| 1708 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1709 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1710 | .idVendor = 0x041e, | ||
| 1711 | .idProduct = 0x4057, | ||
| 1712 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1713 | .bInterfaceSubClass = 1, | ||
| 1714 | .bInterfaceProtocol = 0, | ||
| 1715 | .driver_info = UVC_QUIRK_PROBE_MINMAX }, | ||
| 1716 | /* Microsoft Lifecam NX-6000 */ | ||
| 1717 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1718 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1719 | .idVendor = 0x045e, | ||
| 1720 | .idProduct = 0x00f8, | ||
| 1721 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1722 | .bInterfaceSubClass = 1, | ||
| 1723 | .bInterfaceProtocol = 0, | ||
| 1724 | .driver_info = UVC_QUIRK_PROBE_MINMAX }, | ||
| 1725 | /* Microsoft Lifecam VX-7000 */ | ||
| 1726 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1727 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1728 | .idVendor = 0x045e, | ||
| 1729 | .idProduct = 0x0723, | ||
| 1730 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1731 | .bInterfaceSubClass = 1, | ||
| 1732 | .bInterfaceProtocol = 0, | ||
| 1733 | .driver_info = UVC_QUIRK_PROBE_MINMAX }, | ||
| 1734 | /* Logitech Quickcam Fusion */ | ||
| 1735 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1736 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1737 | .idVendor = 0x046d, | ||
| 1738 | .idProduct = 0x08c1, | ||
| 1739 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, | ||
| 1740 | .bInterfaceSubClass = 1, | ||
| 1741 | .bInterfaceProtocol = 0 }, | ||
| 1742 | /* Logitech Quickcam Orbit MP */ | ||
| 1743 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1744 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1745 | .idVendor = 0x046d, | ||
| 1746 | .idProduct = 0x08c2, | ||
| 1747 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, | ||
| 1748 | .bInterfaceSubClass = 1, | ||
| 1749 | .bInterfaceProtocol = 0 }, | ||
| 1750 | /* Logitech Quickcam Pro for Notebook */ | ||
| 1751 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1752 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1753 | .idVendor = 0x046d, | ||
| 1754 | .idProduct = 0x08c3, | ||
| 1755 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, | ||
| 1756 | .bInterfaceSubClass = 1, | ||
| 1757 | .bInterfaceProtocol = 0 }, | ||
| 1758 | /* Logitech Quickcam Pro 5000 */ | ||
| 1759 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1760 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1761 | .idVendor = 0x046d, | ||
| 1762 | .idProduct = 0x08c5, | ||
| 1763 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, | ||
| 1764 | .bInterfaceSubClass = 1, | ||
| 1765 | .bInterfaceProtocol = 0 }, | ||
| 1766 | /* Logitech Quickcam OEM Dell Notebook */ | ||
| 1767 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1768 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1769 | .idVendor = 0x046d, | ||
| 1770 | .idProduct = 0x08c6, | ||
| 1771 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, | ||
| 1772 | .bInterfaceSubClass = 1, | ||
| 1773 | .bInterfaceProtocol = 0 }, | ||
| 1774 | /* Logitech Quickcam OEM Cisco VT Camera II */ | ||
| 1775 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1776 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1777 | .idVendor = 0x046d, | ||
| 1778 | .idProduct = 0x08c7, | ||
| 1779 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, | ||
| 1780 | .bInterfaceSubClass = 1, | ||
| 1781 | .bInterfaceProtocol = 0 }, | ||
| 1782 | /* Apple Built-In iSight */ | ||
| 1783 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1784 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1785 | .idVendor = 0x05ac, | ||
| 1786 | .idProduct = 0x8501, | ||
| 1787 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1788 | .bInterfaceSubClass = 1, | ||
| 1789 | .bInterfaceProtocol = 0, | ||
| 1790 | .driver_info = UVC_QUIRK_PROBE_MINMAX | ||
| 1791 | | UVC_QUIRK_BUILTIN_ISIGHT }, | ||
| 1792 | /* Genesys Logic USB 2.0 PC Camera */ | ||
| 1793 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1794 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1795 | .idVendor = 0x05e3, | ||
| 1796 | .idProduct = 0x0505, | ||
| 1797 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1798 | .bInterfaceSubClass = 1, | ||
| 1799 | .bInterfaceProtocol = 0, | ||
| 1800 | .driver_info = UVC_QUIRK_STREAM_NO_FID }, | ||
| 1801 | /* Silicon Motion SM371 */ | ||
| 1802 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1803 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1804 | .idVendor = 0x090c, | ||
| 1805 | .idProduct = 0xb371, | ||
| 1806 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1807 | .bInterfaceSubClass = 1, | ||
| 1808 | .bInterfaceProtocol = 0, | ||
| 1809 | .driver_info = UVC_QUIRK_PROBE_MINMAX }, | ||
| 1810 | /* MT6227 */ | ||
| 1811 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1812 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1813 | .idVendor = 0x0e8d, | ||
| 1814 | .idProduct = 0x0004, | ||
| 1815 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1816 | .bInterfaceSubClass = 1, | ||
| 1817 | .bInterfaceProtocol = 0, | ||
| 1818 | .driver_info = UVC_QUIRK_PROBE_MINMAX }, | ||
| 1819 | /* Syntek (HP Spartan) */ | ||
| 1820 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1821 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1822 | .idVendor = 0x174f, | ||
| 1823 | .idProduct = 0x5212, | ||
| 1824 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1825 | .bInterfaceSubClass = 1, | ||
| 1826 | .bInterfaceProtocol = 0, | ||
| 1827 | .driver_info = UVC_QUIRK_STREAM_NO_FID }, | ||
| 1828 | /* Syntek (Asus U3S) */ | ||
| 1829 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1830 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1831 | .idVendor = 0x174f, | ||
| 1832 | .idProduct = 0x8a33, | ||
| 1833 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1834 | .bInterfaceSubClass = 1, | ||
| 1835 | .bInterfaceProtocol = 0, | ||
| 1836 | .driver_info = UVC_QUIRK_STREAM_NO_FID }, | ||
| 1837 | /* Ecamm Pico iMage */ | ||
| 1838 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1839 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1840 | .idVendor = 0x18cd, | ||
| 1841 | .idProduct = 0xcafe, | ||
| 1842 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1843 | .bInterfaceSubClass = 1, | ||
| 1844 | .bInterfaceProtocol = 0, | ||
| 1845 | .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS }, | ||
| 1846 | /* Bodelin ProScopeHR */ | ||
| 1847 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1848 | | USB_DEVICE_ID_MATCH_DEV_HI | ||
| 1849 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1850 | .idVendor = 0x19ab, | ||
| 1851 | .idProduct = 0x1000, | ||
| 1852 | .bcdDevice_hi = 0x0126, | ||
| 1853 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1854 | .bInterfaceSubClass = 1, | ||
| 1855 | .bInterfaceProtocol = 0, | ||
| 1856 | .driver_info = UVC_QUIRK_STATUS_INTERVAL }, | ||
| 1857 | /* SiGma Micro USB Web Camera */ | ||
| 1858 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1859 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1860 | .idVendor = 0x1c4f, | ||
| 1861 | .idProduct = 0x3000, | ||
| 1862 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1863 | .bInterfaceSubClass = 1, | ||
| 1864 | .bInterfaceProtocol = 0, | ||
| 1865 | .driver_info = UVC_QUIRK_PROBE_MINMAX | ||
| 1866 | | UVC_QUIRK_IGNORE_SELECTOR_UNIT}, | ||
| 1867 | /* Acer OEM Webcam - Unknown vendor */ | ||
| 1868 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1869 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1870 | .idVendor = 0x5986, | ||
| 1871 | .idProduct = 0x0100, | ||
| 1872 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1873 | .bInterfaceSubClass = 1, | ||
| 1874 | .bInterfaceProtocol = 0, | ||
| 1875 | .driver_info = UVC_QUIRK_PROBE_MINMAX }, | ||
| 1876 | /* Packard Bell OEM Webcam */ | ||
| 1877 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1878 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1879 | .idVendor = 0x5986, | ||
| 1880 | .idProduct = 0x0101, | ||
| 1881 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1882 | .bInterfaceSubClass = 1, | ||
| 1883 | .bInterfaceProtocol = 0, | ||
| 1884 | .driver_info = UVC_QUIRK_PROBE_MINMAX }, | ||
| 1885 | /* Acer Crystal Eye webcam */ | ||
| 1886 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1887 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1888 | .idVendor = 0x5986, | ||
| 1889 | .idProduct = 0x0102, | ||
| 1890 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1891 | .bInterfaceSubClass = 1, | ||
| 1892 | .bInterfaceProtocol = 0, | ||
| 1893 | .driver_info = UVC_QUIRK_PROBE_MINMAX }, | ||
| 1894 | /* Acer OrbiCam - Unknown vendor */ | ||
| 1895 | { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | ||
| 1896 | | USB_DEVICE_ID_MATCH_INT_INFO, | ||
| 1897 | .idVendor = 0x5986, | ||
| 1898 | .idProduct = 0x0200, | ||
| 1899 | .bInterfaceClass = USB_CLASS_VIDEO, | ||
| 1900 | .bInterfaceSubClass = 1, | ||
| 1901 | .bInterfaceProtocol = 0, | ||
| 1902 | .driver_info = UVC_QUIRK_PROBE_MINMAX }, | ||
| 1903 | /* Generic USB Video Class */ | ||
| 1904 | { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) }, | ||
| 1905 | {} | ||
| 1906 | }; | ||
| 1907 | |||
| 1908 | MODULE_DEVICE_TABLE(usb, uvc_ids); | ||
| 1909 | |||
| 1910 | struct uvc_driver uvc_driver = { | ||
| 1911 | .driver = { | ||
| 1912 | .name = "uvcvideo", | ||
| 1913 | .probe = uvc_probe, | ||
| 1914 | .disconnect = uvc_disconnect, | ||
| 1915 | .suspend = uvc_suspend, | ||
| 1916 | .resume = uvc_resume, | ||
| 1917 | .id_table = uvc_ids, | ||
| 1918 | .supports_autosuspend = 1, | ||
| 1919 | }, | ||
| 1920 | }; | ||
| 1921 | |||
| 1922 | static int __init uvc_init(void) | ||
| 1923 | { | ||
| 1924 | int result; | ||
| 1925 | |||
| 1926 | INIT_LIST_HEAD(&uvc_driver.devices); | ||
| 1927 | INIT_LIST_HEAD(&uvc_driver.controls); | ||
| 1928 | mutex_init(&uvc_driver.open_mutex); | ||
| 1929 | mutex_init(&uvc_driver.ctrl_mutex); | ||
| 1930 | |||
| 1931 | uvc_ctrl_init(); | ||
| 1932 | |||
| 1933 | result = usb_register(&uvc_driver.driver); | ||
| 1934 | if (result == 0) | ||
| 1935 | printk(KERN_INFO DRIVER_DESC " (" DRIVER_VERSION ")\n"); | ||
| 1936 | return result; | ||
| 1937 | } | ||
| 1938 | |||
| 1939 | static void __exit uvc_cleanup(void) | ||
| 1940 | { | ||
| 1941 | usb_deregister(&uvc_driver.driver); | ||
| 1942 | } | ||
| 1943 | |||
| 1944 | module_init(uvc_init); | ||
| 1945 | module_exit(uvc_cleanup); | ||
| 1946 | |||
| 1947 | module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR); | ||
| 1948 | MODULE_PARM_DESC(quirks, "Forced device quirks"); | ||
| 1949 | module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR); | ||
| 1950 | MODULE_PARM_DESC(trace, "Trace level bitmask"); | ||
| 1951 | |||
| 1952 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
| 1953 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
| 1954 | MODULE_LICENSE("GPL"); | ||
| 1955 | 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 index 000000000000..37bdefdbead5 --- /dev/null +++ b/drivers/media/video/uvc/uvc_isight.c | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | /* | ||
| 2 | * uvc_isight.c -- USB Video Class driver - iSight support | ||
| 3 | * | ||
| 4 | * Copyright (C) 2006-2007 | ||
| 5 | * Ivan N. Zlatev <contact@i-nz.net> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/usb.h> | ||
| 15 | #include <linux/kernel.h> | ||
| 16 | #include <linux/mm.h> | ||
| 17 | |||
| 18 | #include "uvcvideo.h" | ||
| 19 | |||
| 20 | /* Built-in iSight webcams implements most of UVC 1.0 except a | ||
| 21 | * different packet format. Instead of sending a header at the | ||
| 22 | * beginning of each isochronous transfer payload, the webcam sends a | ||
| 23 | * single header per image (on its own in a packet), followed by | ||
| 24 | * packets containing data only. | ||
| 25 | * | ||
| 26 | * Offset Size (bytes) Description | ||
| 27 | * ------------------------------------------------------------------ | ||
| 28 | * 0x00 1 Header length | ||
| 29 | * 0x01 1 Flags (UVC-compliant) | ||
| 30 | * 0x02 4 Always equal to '11223344' | ||
| 31 | * 0x06 8 Always equal to 'deadbeefdeadface' | ||
| 32 | * 0x0e 16 Unknown | ||
| 33 | * | ||
| 34 | * The header can be prefixed by an optional, unknown-purpose byte. | ||
| 35 | */ | ||
| 36 | |||
| 37 | static int isight_decode(struct uvc_video_queue *queue, struct uvc_buffer *buf, | ||
| 38 | const __u8 *data, unsigned int len) | ||
| 39 | { | ||
| 40 | static const __u8 hdr[] = { | ||
| 41 | 0x11, 0x22, 0x33, 0x44, | ||
| 42 | 0xde, 0xad, 0xbe, 0xef, | ||
| 43 | 0xde, 0xad, 0xfa, 0xce | ||
| 44 | }; | ||
| 45 | |||
| 46 | unsigned int maxlen, nbytes; | ||
| 47 | __u8 *mem; | ||
| 48 | int is_header = 0; | ||
| 49 | |||
| 50 | if (buf == NULL) | ||
| 51 | return 0; | ||
| 52 | |||
| 53 | if ((len >= 14 && memcmp(&data[2], hdr, 12) == 0) || | ||
| 54 | (len >= 15 && memcmp(&data[3], hdr, 12) == 0)) { | ||
| 55 | uvc_trace(UVC_TRACE_FRAME, "iSight header found\n"); | ||
| 56 | is_header = 1; | ||
| 57 | } | ||
| 58 | |||
| 59 | /* Synchronize to the input stream by waiting for a header packet. */ | ||
| 60 | if (buf->state != UVC_BUF_STATE_ACTIVE) { | ||
| 61 | if (!is_header) { | ||
| 62 | uvc_trace(UVC_TRACE_FRAME, "Dropping packet (out of " | ||
| 63 | "sync).\n"); | ||
| 64 | return 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | buf->state = UVC_BUF_STATE_ACTIVE; | ||
| 68 | } | ||
| 69 | |||
| 70 | /* Mark the buffer as done if we're at the beginning of a new frame. | ||
| 71 | * | ||
| 72 | * Empty buffers (bytesused == 0) don't trigger end of frame detection | ||
| 73 | * as it doesn't make sense to return an empty buffer. | ||
| 74 | */ | ||
| 75 | if (is_header && buf->buf.bytesused != 0) { | ||
| 76 | buf->state = UVC_BUF_STATE_DONE; | ||
| 77 | return -EAGAIN; | ||
| 78 | } | ||
| 79 | |||
| 80 | /* Copy the video data to the buffer. Skip header packets, as they | ||
| 81 | * contain no data. | ||
| 82 | */ | ||
| 83 | if (!is_header) { | ||
| 84 | maxlen = buf->buf.length - buf->buf.bytesused; | ||
| 85 | mem = queue->mem + buf->buf.m.offset + buf->buf.bytesused; | ||
| 86 | nbytes = min(len, maxlen); | ||
| 87 | memcpy(mem, data, nbytes); | ||
| 88 | buf->buf.bytesused += nbytes; | ||
| 89 | |||
| 90 | if (len > maxlen || buf->buf.bytesused == buf->buf.length) { | ||
| 91 | uvc_trace(UVC_TRACE_FRAME, "Frame complete " | ||
| 92 | "(overflow).\n"); | ||
| 93 | buf->state = UVC_BUF_STATE_DONE; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | return 0; | ||
| 98 | } | ||
| 99 | |||
| 100 | void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video, | ||
| 101 | struct uvc_buffer *buf) | ||
| 102 | { | ||
| 103 | int ret, i; | ||
| 104 | |||
| 105 | for (i = 0; i < urb->number_of_packets; ++i) { | ||
| 106 | if (urb->iso_frame_desc[i].status < 0) { | ||
| 107 | uvc_trace(UVC_TRACE_FRAME, "USB isochronous frame " | ||
| 108 | "lost (%d).\n", | ||
| 109 | urb->iso_frame_desc[i].status); | ||
| 110 | } | ||
| 111 | |||
| 112 | /* Decode the payload packet. | ||
| 113 | * uvc_video_decode is entered twice when a frame transition | ||
| 114 | * has been detected because the end of frame can only be | ||
| 115 | * reliably detected when the first packet of the new frame | ||
| 116 | * is processed. The first pass detects the transition and | ||
| 117 | * closes the previous frame's buffer, the second pass | ||
| 118 | * processes the data of the first payload of the new frame. | ||
| 119 | */ | ||
| 120 | do { | ||
| 121 | ret = isight_decode(&video->queue, buf, | ||
| 122 | urb->transfer_buffer + | ||
| 123 | urb->iso_frame_desc[i].offset, | ||
| 124 | urb->iso_frame_desc[i].actual_length); | ||
| 125 | |||
| 126 | if (buf == NULL) | ||
| 127 | break; | ||
| 128 | |||
| 129 | if (buf->state == UVC_BUF_STATE_DONE || | ||
| 130 | buf->state == UVC_BUF_STATE_ERROR) | ||
| 131 | buf = uvc_queue_next_buffer(&video->queue, buf); | ||
| 132 | } while (ret == -EAGAIN); | ||
| 133 | } | ||
| 134 | } | ||
diff --git a/drivers/media/video/uvc/uvc_queue.c b/drivers/media/video/uvc/uvc_queue.c new file mode 100644 index 000000000000..0923f0e3b3d4 --- /dev/null +++ b/drivers/media/video/uvc/uvc_queue.c | |||
| @@ -0,0 +1,477 @@ | |||
| 1 | /* | ||
| 2 | * uvc_queue.c -- USB Video Class driver - Buffers management | ||
| 3 | * | ||
| 4 | * Copyright (C) 2005-2008 | ||
| 5 | * Laurent Pinchart (laurent.pinchart@skynet.be) | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/version.h> | ||
| 16 | #include <linux/list.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/usb.h> | ||
| 19 | #include <linux/videodev2.h> | ||
| 20 | #include <linux/vmalloc.h> | ||
| 21 | #include <linux/wait.h> | ||
| 22 | #include <asm/atomic.h> | ||
| 23 | |||
| 24 | #include "uvcvideo.h" | ||
| 25 | |||
| 26 | /* ------------------------------------------------------------------------ | ||
| 27 | * Video buffers queue management. | ||
| 28 | * | ||
| 29 | * Video queues is initialized by uvc_queue_init(). The function performs | ||
| 30 | * basic initialization of the uvc_video_queue struct and never fails. | ||
| 31 | * | ||
| 32 | * Video buffer allocation and freeing are performed by uvc_alloc_buffers and | ||
| 33 | * uvc_free_buffers respectively. The former acquires the video queue lock, | ||
| 34 | * while the later must be called with the lock held (so that allocation can | ||
| 35 | * free previously allocated buffers). Trying to free buffers that are mapped | ||
| 36 | * to user space will return -EBUSY. | ||
| 37 | * | ||
| 38 | * Video buffers are managed using two queues. However, unlike most USB video | ||
| 39 | * drivers which use an in queue and an out queue, we use a main queue which | ||
| 40 | * holds all queued buffers (both 'empty' and 'done' buffers), and an irq | ||
| 41 | * queue which holds empty buffers. This design (copied from video-buf) | ||
| 42 | * minimizes locking in interrupt, as only one queue is shared between | ||
| 43 | * interrupt and user contexts. | ||
| 44 | * | ||
| 45 | * Use cases | ||
| 46 | * --------- | ||
| 47 | * | ||
| 48 | * Unless stated otherwise, all operations which modify the irq buffers queue | ||
| 49 | * are protected by the irq spinlock. | ||
| 50 | * | ||
| 51 | * 1. The user queues the buffers, starts streaming and dequeues a buffer. | ||
| 52 | * | ||
| 53 | * The buffers are added to the main and irq queues. Both operations are | ||
| 54 | * protected by the queue lock, and the latert is protected by the irq | ||
| 55 | * spinlock as well. | ||
| 56 | * | ||
| 57 | * The completion handler fetches a buffer from the irq queue and fills it | ||
| 58 | * with video data. If no buffer is available (irq queue empty), the handler | ||
| 59 | * returns immediately. | ||
| 60 | * | ||
| 61 | * When the buffer is full, the completion handler removes it from the irq | ||
| 62 | * queue, marks it as ready (UVC_BUF_STATE_DONE) and wake its wait queue. | ||
| 63 | * At that point, any process waiting on the buffer will be woken up. If a | ||
| 64 | * process tries to dequeue a buffer after it has been marked ready, the | ||
| 65 | * dequeing will succeed immediately. | ||
| 66 | * | ||
| 67 | * 2. Buffers are queued, user is waiting on a buffer and the device gets | ||
| 68 | * disconnected. | ||
| 69 | * | ||
| 70 | * When the device is disconnected, the kernel calls the completion handler | ||
| 71 | * with an appropriate status code. The handler marks all buffers in the | ||
| 72 | * irq queue as being erroneous (UVC_BUF_STATE_ERROR) and wakes them up so | ||
| 73 | * that any process waiting on a buffer gets woken up. | ||
| 74 | * | ||
| 75 | * Waking up up the first buffer on the irq list is not enough, as the | ||
| 76 | * process waiting on the buffer might restart the dequeue operation | ||
| 77 | * immediately. | ||
| 78 | * | ||
| 79 | */ | ||
| 80 | |||
| 81 | void uvc_queue_init(struct uvc_video_queue *queue) | ||
| 82 | { | ||
| 83 | mutex_init(&queue->mutex); | ||
| 84 | spin_lock_init(&queue->irqlock); | ||
| 85 | INIT_LIST_HEAD(&queue->mainqueue); | ||
| 86 | INIT_LIST_HEAD(&queue->irqqueue); | ||
| 87 | } | ||
| 88 | |||
| 89 | /* | ||
| 90 | * Allocate the video buffers. | ||
| 91 | * | ||
| 92 | * Pages are reserved to make sure they will not be swaped, as they will be | ||
| 93 | * filled in URB completion handler. | ||
| 94 | * | ||
| 95 | * Buffers will be individually mapped, so they must all be page aligned. | ||
| 96 | */ | ||
| 97 | int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers, | ||
| 98 | unsigned int buflength) | ||
| 99 | { | ||
| 100 | unsigned int bufsize = PAGE_ALIGN(buflength); | ||
| 101 | unsigned int i; | ||
| 102 | void *mem = NULL; | ||
| 103 | int ret; | ||
| 104 | |||
| 105 | if (nbuffers > UVC_MAX_VIDEO_BUFFERS) | ||
| 106 | nbuffers = UVC_MAX_VIDEO_BUFFERS; | ||
| 107 | |||
| 108 | mutex_lock(&queue->mutex); | ||
| 109 | |||
| 110 | if ((ret = uvc_free_buffers(queue)) < 0) | ||
| 111 | goto done; | ||
| 112 | |||
| 113 | /* Bail out if no buffers should be allocated. */ | ||
| 114 | if (nbuffers == 0) | ||
| 115 | goto done; | ||
| 116 | |||
| 117 | /* Decrement the number of buffers until allocation succeeds. */ | ||
| 118 | for (; nbuffers > 0; --nbuffers) { | ||
| 119 | mem = vmalloc_32(nbuffers * bufsize); | ||
| 120 | if (mem != NULL) | ||
| 121 | break; | ||
| 122 | } | ||
| 123 | |||
| 124 | if (mem == NULL) { | ||
| 125 | ret = -ENOMEM; | ||
| 126 | goto done; | ||
| 127 | } | ||
| 128 | |||
| 129 | for (i = 0; i < nbuffers; ++i) { | ||
| 130 | memset(&queue->buffer[i], 0, sizeof queue->buffer[i]); | ||
| 131 | queue->buffer[i].buf.index = i; | ||
| 132 | queue->buffer[i].buf.m.offset = i * bufsize; | ||
| 133 | queue->buffer[i].buf.length = buflength; | ||
| 134 | queue->buffer[i].buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | ||
| 135 | queue->buffer[i].buf.sequence = 0; | ||
| 136 | queue->buffer[i].buf.field = V4L2_FIELD_NONE; | ||
| 137 | queue->buffer[i].buf.memory = V4L2_MEMORY_MMAP; | ||
| 138 | queue->buffer[i].buf.flags = 0; | ||
| 139 | init_waitqueue_head(&queue->buffer[i].wait); | ||
| 140 | } | ||
| 141 | |||
| 142 | queue->mem = mem; | ||
| 143 | queue->count = nbuffers; | ||
| 144 | queue->buf_size = bufsize; | ||
| 145 | ret = nbuffers; | ||
| 146 | |||
| 147 | done: | ||
| 148 | mutex_unlock(&queue->mutex); | ||
| 149 | return ret; | ||
| 150 | } | ||
| 151 | |||
| 152 | /* | ||
| 153 | * Free the video buffers. | ||
| 154 | * | ||
| 155 | * This function must be called with the queue lock held. | ||
| 156 | */ | ||
| 157 | int uvc_free_buffers(struct uvc_video_queue *queue) | ||
| 158 | { | ||
| 159 | unsigned int i; | ||
| 160 | |||
| 161 | for (i = 0; i < queue->count; ++i) { | ||
| 162 | if (queue->buffer[i].vma_use_count != 0) | ||
| 163 | return -EBUSY; | ||
| 164 | } | ||
| 165 | |||
| 166 | if (queue->count) { | ||
| 167 | vfree(queue->mem); | ||
| 168 | queue->count = 0; | ||
| 169 | } | ||
| 170 | |||
| 171 | return 0; | ||
| 172 | } | ||
| 173 | |||
| 174 | static void __uvc_query_buffer(struct uvc_buffer *buf, | ||
| 175 | struct v4l2_buffer *v4l2_buf) | ||
| 176 | { | ||
| 177 | memcpy(v4l2_buf, &buf->buf, sizeof *v4l2_buf); | ||
| 178 | |||
| 179 | if (buf->vma_use_count) | ||
| 180 | v4l2_buf->flags |= V4L2_BUF_FLAG_MAPPED; | ||
| 181 | |||
| 182 | switch (buf->state) { | ||
| 183 | case UVC_BUF_STATE_ERROR: | ||
| 184 | case UVC_BUF_STATE_DONE: | ||
| 185 | v4l2_buf->flags |= V4L2_BUF_FLAG_DONE; | ||
| 186 | break; | ||
| 187 | case UVC_BUF_STATE_QUEUED: | ||
| 188 | case UVC_BUF_STATE_ACTIVE: | ||
| 189 | v4l2_buf->flags |= V4L2_BUF_FLAG_QUEUED; | ||
| 190 | break; | ||
| 191 | case UVC_BUF_STATE_IDLE: | ||
| 192 | default: | ||
| 193 | break; | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | int uvc_query_buffer(struct uvc_video_queue *queue, | ||
| 198 | struct v4l2_buffer *v4l2_buf) | ||
| 199 | { | ||
| 200 | int ret = 0; | ||
| 201 | |||
| 202 | mutex_lock(&queue->mutex); | ||
| 203 | if (v4l2_buf->index >= queue->count) { | ||
| 204 | ret = -EINVAL; | ||
| 205 | goto done; | ||
| 206 | } | ||
| 207 | |||
| 208 | __uvc_query_buffer(&queue->buffer[v4l2_buf->index], v4l2_buf); | ||
| 209 | |||
| 210 | done: | ||
| 211 | mutex_unlock(&queue->mutex); | ||
| 212 | return ret; | ||
| 213 | } | ||
| 214 | |||
| 215 | /* | ||
| 216 | * Queue a video buffer. Attempting to queue a buffer that has already been | ||
| 217 | * queued will return -EINVAL. | ||
| 218 | */ | ||
| 219 | int uvc_queue_buffer(struct uvc_video_queue *queue, | ||
| 220 | struct v4l2_buffer *v4l2_buf) | ||
| 221 | { | ||
| 222 | struct uvc_buffer *buf; | ||
| 223 | unsigned long flags; | ||
| 224 | int ret = 0; | ||
| 225 | |||
| 226 | uvc_trace(UVC_TRACE_CAPTURE, "Queuing buffer %u.\n", v4l2_buf->index); | ||
| 227 | |||
| 228 | if (v4l2_buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | ||
| 229 | v4l2_buf->memory != V4L2_MEMORY_MMAP) { | ||
| 230 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) " | ||
| 231 | "and/or memory (%u).\n", v4l2_buf->type, | ||
| 232 | v4l2_buf->memory); | ||
| 233 | return -EINVAL; | ||
| 234 | } | ||
| 235 | |||
| 236 | mutex_lock(&queue->mutex); | ||
| 237 | if (v4l2_buf->index >= queue->count) { | ||
| 238 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Out of range index.\n"); | ||
| 239 | ret = -EINVAL; | ||
| 240 | goto done; | ||
| 241 | } | ||
| 242 | |||
| 243 | buf = &queue->buffer[v4l2_buf->index]; | ||
| 244 | if (buf->state != UVC_BUF_STATE_IDLE) { | ||
| 245 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state " | ||
| 246 | "(%u).\n", buf->state); | ||
| 247 | ret = -EINVAL; | ||
| 248 | goto done; | ||
| 249 | } | ||
| 250 | |||
| 251 | spin_lock_irqsave(&queue->irqlock, flags); | ||
| 252 | if (queue->flags & UVC_QUEUE_DISCONNECTED) { | ||
| 253 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
| 254 | ret = -ENODEV; | ||
| 255 | goto done; | ||
| 256 | } | ||
| 257 | buf->state = UVC_BUF_STATE_QUEUED; | ||
| 258 | buf->buf.bytesused = 0; | ||
| 259 | list_add_tail(&buf->stream, &queue->mainqueue); | ||
| 260 | list_add_tail(&buf->queue, &queue->irqqueue); | ||
| 261 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
| 262 | |||
| 263 | done: | ||
| 264 | mutex_unlock(&queue->mutex); | ||
| 265 | return ret; | ||
| 266 | } | ||
| 267 | |||
| 268 | static int uvc_queue_waiton(struct uvc_buffer *buf, int nonblocking) | ||
| 269 | { | ||
| 270 | if (nonblocking) { | ||
| 271 | return (buf->state != UVC_BUF_STATE_QUEUED && | ||
| 272 | buf->state != UVC_BUF_STATE_ACTIVE) | ||
| 273 | ? 0 : -EAGAIN; | ||
| 274 | } | ||
| 275 | |||
| 276 | return wait_event_interruptible(buf->wait, | ||
| 277 | buf->state != UVC_BUF_STATE_QUEUED && | ||
| 278 | buf->state != UVC_BUF_STATE_ACTIVE); | ||
| 279 | } | ||
| 280 | |||
| 281 | /* | ||
| 282 | * Dequeue a video buffer. If nonblocking is false, block until a buffer is | ||
| 283 | * available. | ||
| 284 | */ | ||
| 285 | int uvc_dequeue_buffer(struct uvc_video_queue *queue, | ||
| 286 | struct v4l2_buffer *v4l2_buf, int nonblocking) | ||
| 287 | { | ||
| 288 | struct uvc_buffer *buf; | ||
| 289 | int ret = 0; | ||
| 290 | |||
| 291 | if (v4l2_buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | ||
| 292 | v4l2_buf->memory != V4L2_MEMORY_MMAP) { | ||
| 293 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) " | ||
| 294 | "and/or memory (%u).\n", v4l2_buf->type, | ||
| 295 | v4l2_buf->memory); | ||
| 296 | return -EINVAL; | ||
| 297 | } | ||
| 298 | |||
| 299 | mutex_lock(&queue->mutex); | ||
| 300 | if (list_empty(&queue->mainqueue)) { | ||
| 301 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Empty buffer queue.\n"); | ||
| 302 | ret = -EINVAL; | ||
| 303 | goto done; | ||
| 304 | } | ||
| 305 | |||
| 306 | buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream); | ||
| 307 | if ((ret = uvc_queue_waiton(buf, nonblocking)) < 0) | ||
| 308 | goto done; | ||
| 309 | |||
| 310 | uvc_trace(UVC_TRACE_CAPTURE, "Dequeuing buffer %u (%u, %u bytes).\n", | ||
| 311 | buf->buf.index, buf->state, buf->buf.bytesused); | ||
| 312 | |||
| 313 | switch (buf->state) { | ||
| 314 | case UVC_BUF_STATE_ERROR: | ||
| 315 | uvc_trace(UVC_TRACE_CAPTURE, "[W] Corrupted data " | ||
| 316 | "(transmission error).\n"); | ||
| 317 | ret = -EIO; | ||
| 318 | case UVC_BUF_STATE_DONE: | ||
| 319 | buf->state = UVC_BUF_STATE_IDLE; | ||
| 320 | break; | ||
| 321 | |||
| 322 | case UVC_BUF_STATE_IDLE: | ||
| 323 | case UVC_BUF_STATE_QUEUED: | ||
| 324 | case UVC_BUF_STATE_ACTIVE: | ||
| 325 | default: | ||
| 326 | uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state %u " | ||
| 327 | "(driver bug?).\n", buf->state); | ||
| 328 | ret = -EINVAL; | ||
| 329 | goto done; | ||
| 330 | } | ||
| 331 | |||
| 332 | list_del(&buf->stream); | ||
| 333 | __uvc_query_buffer(buf, v4l2_buf); | ||
| 334 | |||
| 335 | done: | ||
| 336 | mutex_unlock(&queue->mutex); | ||
| 337 | return ret; | ||
| 338 | } | ||
| 339 | |||
| 340 | /* | ||
| 341 | * Poll the video queue. | ||
| 342 | * | ||
| 343 | * This function implements video queue polling and is intended to be used by | ||
| 344 | * the device poll handler. | ||
| 345 | */ | ||
| 346 | unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, | ||
| 347 | poll_table *wait) | ||
| 348 | { | ||
| 349 | struct uvc_buffer *buf; | ||
| 350 | unsigned int mask = 0; | ||
| 351 | |||
| 352 | mutex_lock(&queue->mutex); | ||
| 353 | if (list_empty(&queue->mainqueue)) { | ||
| 354 | mask |= POLLERR; | ||
| 355 | goto done; | ||
| 356 | } | ||
| 357 | buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream); | ||
| 358 | |||
| 359 | poll_wait(file, &buf->wait, wait); | ||
| 360 | if (buf->state == UVC_BUF_STATE_DONE || | ||
| 361 | buf->state == UVC_BUF_STATE_ERROR) | ||
| 362 | mask |= POLLIN | POLLRDNORM; | ||
| 363 | |||
| 364 | done: | ||
| 365 | mutex_unlock(&queue->mutex); | ||
| 366 | return mask; | ||
| 367 | } | ||
| 368 | |||
| 369 | /* | ||
| 370 | * Enable or disable the video buffers queue. | ||
| 371 | * | ||
| 372 | * The queue must be enabled before starting video acquisition and must be | ||
| 373 | * disabled after stopping it. This ensures that the video buffers queue | ||
| 374 | * state can be properly initialized before buffers are accessed from the | ||
| 375 | * interrupt handler. | ||
| 376 | * | ||
| 377 | * Enabling the video queue initializes parameters (such as sequence number, | ||
| 378 | * sync pattern, ...). If the queue is already enabled, return -EBUSY. | ||
| 379 | * | ||
| 380 | * Disabling the video queue cancels the queue and removes all buffers from | ||
| 381 | * the main queue. | ||
| 382 | * | ||
| 383 | * This function can't be called from interrupt context. Use | ||
| 384 | * uvc_queue_cancel() instead. | ||
| 385 | */ | ||
| 386 | int uvc_queue_enable(struct uvc_video_queue *queue, int enable) | ||
| 387 | { | ||
| 388 | unsigned int i; | ||
| 389 | int ret = 0; | ||
| 390 | |||
| 391 | mutex_lock(&queue->mutex); | ||
| 392 | if (enable) { | ||
| 393 | if (uvc_queue_streaming(queue)) { | ||
| 394 | ret = -EBUSY; | ||
| 395 | goto done; | ||
| 396 | } | ||
| 397 | queue->sequence = 0; | ||
| 398 | queue->flags |= UVC_QUEUE_STREAMING; | ||
| 399 | } else { | ||
| 400 | uvc_queue_cancel(queue, 0); | ||
| 401 | INIT_LIST_HEAD(&queue->mainqueue); | ||
| 402 | |||
| 403 | for (i = 0; i < queue->count; ++i) | ||
| 404 | queue->buffer[i].state = UVC_BUF_STATE_IDLE; | ||
| 405 | |||
| 406 | queue->flags &= ~UVC_QUEUE_STREAMING; | ||
| 407 | } | ||
| 408 | |||
| 409 | done: | ||
| 410 | mutex_unlock(&queue->mutex); | ||
| 411 | return ret; | ||
| 412 | } | ||
| 413 | |||
| 414 | /* | ||
| 415 | * Cancel the video buffers queue. | ||
| 416 | * | ||
| 417 | * Cancelling the queue marks all buffers on the irq queue as erroneous, | ||
| 418 | * wakes them up and remove them from the queue. | ||
| 419 | * | ||
| 420 | * If the disconnect parameter is set, further calls to uvc_queue_buffer will | ||
| 421 | * fail with -ENODEV. | ||
| 422 | * | ||
| 423 | * This function acquires the irq spinlock and can be called from interrupt | ||
| 424 | * context. | ||
| 425 | */ | ||
| 426 | void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) | ||
| 427 | { | ||
| 428 | struct uvc_buffer *buf; | ||
| 429 | unsigned long flags; | ||
| 430 | |||
| 431 | spin_lock_irqsave(&queue->irqlock, flags); | ||
| 432 | while (!list_empty(&queue->irqqueue)) { | ||
| 433 | buf = list_first_entry(&queue->irqqueue, struct uvc_buffer, | ||
| 434 | queue); | ||
| 435 | list_del(&buf->queue); | ||
| 436 | buf->state = UVC_BUF_STATE_ERROR; | ||
| 437 | wake_up(&buf->wait); | ||
| 438 | } | ||
| 439 | /* This must be protected by the irqlock spinlock to avoid race | ||
| 440 | * conditions between uvc_queue_buffer and the disconnection event that | ||
| 441 | * could result in an interruptible wait in uvc_dequeue_buffer. Do not | ||
| 442 | * blindly replace this logic by checking for the UVC_DEV_DISCONNECTED | ||
| 443 | * state outside the queue code. | ||
| 444 | */ | ||
| 445 | if (disconnect) | ||
| 446 | queue->flags |= UVC_QUEUE_DISCONNECTED; | ||
| 447 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
| 448 | } | ||
| 449 | |||
| 450 | struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | ||
| 451 | struct uvc_buffer *buf) | ||
| 452 | { | ||
| 453 | struct uvc_buffer *nextbuf; | ||
| 454 | unsigned long flags; | ||
| 455 | |||
| 456 | if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) && | ||
| 457 | buf->buf.length != buf->buf.bytesused) { | ||
| 458 | buf->state = UVC_BUF_STATE_QUEUED; | ||
| 459 | buf->buf.bytesused = 0; | ||
| 460 | return buf; | ||
| 461 | } | ||
| 462 | |||
| 463 | spin_lock_irqsave(&queue->irqlock, flags); | ||
| 464 | list_del(&buf->queue); | ||
| 465 | if (!list_empty(&queue->irqqueue)) | ||
| 466 | nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer, | ||
| 467 | queue); | ||
| 468 | else | ||
| 469 | nextbuf = NULL; | ||
| 470 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
| 471 | |||
| 472 | buf->buf.sequence = queue->sequence++; | ||
| 473 | do_gettimeofday(&buf->buf.timestamp); | ||
| 474 | |||
| 475 | wake_up(&buf->wait); | ||
| 476 | return nextbuf; | ||
| 477 | } | ||
diff --git a/drivers/media/video/uvc/uvc_status.c b/drivers/media/video/uvc/uvc_status.c new file mode 100644 index 000000000000..be9084e5eace --- /dev/null +++ b/drivers/media/video/uvc/uvc_status.c | |||
| @@ -0,0 +1,207 @@ | |||
| 1 | /* | ||
| 2 | * uvc_status.c -- USB Video Class driver - Status endpoint | ||
| 3 | * | ||
| 4 | * Copyright (C) 2007-2008 | ||
| 5 | * Laurent Pinchart (laurent.pinchart@skynet.be) | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/version.h> | ||
| 16 | #include <linux/input.h> | ||
| 17 | #include <linux/usb.h> | ||
| 18 | #include <linux/usb/input.h> | ||
| 19 | |||
| 20 | #include "uvcvideo.h" | ||
| 21 | |||
| 22 | /* -------------------------------------------------------------------------- | ||
| 23 | * Input device | ||
| 24 | */ | ||
| 25 | static int uvc_input_init(struct uvc_device *dev) | ||
| 26 | { | ||
| 27 | struct usb_device *udev = dev->udev; | ||
| 28 | struct input_dev *input; | ||
| 29 | char *phys = NULL; | ||
| 30 | int ret; | ||
| 31 | |||
| 32 | input = input_allocate_device(); | ||
| 33 | if (input == NULL) | ||
| 34 | return -ENOMEM; | ||
| 35 | |||
| 36 | phys = kmalloc(6 + strlen(udev->bus->bus_name) + strlen(udev->devpath), | ||
| 37 | GFP_KERNEL); | ||
| 38 | if (phys == NULL) { | ||
| 39 | ret = -ENOMEM; | ||
| 40 | goto error; | ||
| 41 | } | ||
| 42 | sprintf(phys, "usb-%s-%s", udev->bus->bus_name, udev->devpath); | ||
| 43 | |||
| 44 | input->name = dev->name; | ||
| 45 | input->phys = phys; | ||
| 46 | usb_to_input_id(udev, &input->id); | ||
| 47 | input->dev.parent = &dev->intf->dev; | ||
| 48 | |||
| 49 | set_bit(EV_KEY, input->evbit); | ||
| 50 | set_bit(BTN_0, input->keybit); | ||
| 51 | |||
| 52 | if ((ret = input_register_device(input)) < 0) | ||
| 53 | goto error; | ||
| 54 | |||
| 55 | dev->input = input; | ||
| 56 | return 0; | ||
| 57 | |||
| 58 | error: | ||
| 59 | input_free_device(input); | ||
| 60 | kfree(phys); | ||
| 61 | return ret; | ||
| 62 | } | ||
| 63 | |||
| 64 | static void uvc_input_cleanup(struct uvc_device *dev) | ||
| 65 | { | ||
| 66 | if (dev->input) | ||
| 67 | input_unregister_device(dev->input); | ||
| 68 | } | ||
| 69 | |||
| 70 | /* -------------------------------------------------------------------------- | ||
| 71 | * Status interrupt endpoint | ||
| 72 | */ | ||
| 73 | static void uvc_event_streaming(struct uvc_device *dev, __u8 *data, int len) | ||
| 74 | { | ||
| 75 | if (len < 3) { | ||
| 76 | uvc_trace(UVC_TRACE_STATUS, "Invalid streaming status event " | ||
| 77 | "received.\n"); | ||
| 78 | return; | ||
| 79 | } | ||
| 80 | |||
| 81 | if (data[2] == 0) { | ||
| 82 | if (len < 4) | ||
| 83 | return; | ||
| 84 | uvc_trace(UVC_TRACE_STATUS, "Button (intf %u) %s len %d\n", | ||
| 85 | data[1], data[3] ? "pressed" : "released", len); | ||
| 86 | if (dev->input) | ||
| 87 | input_report_key(dev->input, BTN_0, data[3]); | ||
| 88 | } else { | ||
| 89 | uvc_trace(UVC_TRACE_STATUS, "Stream %u error event %02x %02x " | ||
| 90 | "len %d.\n", data[1], data[2], data[3], len); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | static void uvc_event_control(struct uvc_device *dev, __u8 *data, int len) | ||
| 95 | { | ||
| 96 | char *attrs[3] = { "value", "info", "failure" }; | ||
| 97 | |||
| 98 | if (len < 6 || data[2] != 0 || data[4] > 2) { | ||
| 99 | uvc_trace(UVC_TRACE_STATUS, "Invalid control status event " | ||
| 100 | "received.\n"); | ||
| 101 | return; | ||
| 102 | } | ||
| 103 | |||
| 104 | uvc_trace(UVC_TRACE_STATUS, "Control %u/%u %s change len %d.\n", | ||
| 105 | data[1], data[3], attrs[data[4]], len); | ||
| 106 | } | ||
| 107 | |||
| 108 | static void uvc_status_complete(struct urb *urb) | ||
| 109 | { | ||
| 110 | struct uvc_device *dev = urb->context; | ||
| 111 | int len, ret; | ||
| 112 | |||
| 113 | switch (urb->status) { | ||
| 114 | case 0: | ||
| 115 | break; | ||
| 116 | |||
| 117 | case -ENOENT: /* usb_kill_urb() called. */ | ||
| 118 | case -ECONNRESET: /* usb_unlink_urb() called. */ | ||
| 119 | case -ESHUTDOWN: /* The endpoint is being disabled. */ | ||
| 120 | case -EPROTO: /* Device is disconnected (reported by some | ||
| 121 | * host controller). */ | ||
| 122 | return; | ||
| 123 | |||
| 124 | default: | ||
| 125 | uvc_printk(KERN_WARNING, "Non-zero status (%d) in status " | ||
| 126 | "completion handler.\n", urb->status); | ||
| 127 | return; | ||
| 128 | } | ||
| 129 | |||
| 130 | len = urb->actual_length; | ||
| 131 | if (len > 0) { | ||
| 132 | switch (dev->status[0] & 0x0f) { | ||
| 133 | case UVC_STATUS_TYPE_CONTROL: | ||
| 134 | uvc_event_control(dev, dev->status, len); | ||
| 135 | break; | ||
| 136 | |||
| 137 | case UVC_STATUS_TYPE_STREAMING: | ||
| 138 | uvc_event_streaming(dev, dev->status, len); | ||
| 139 | break; | ||
| 140 | |||
| 141 | default: | ||
| 142 | uvc_printk(KERN_INFO, "unknown event type %u.\n", | ||
| 143 | dev->status[0]); | ||
| 144 | break; | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | /* Resubmit the URB. */ | ||
| 149 | urb->interval = dev->int_ep->desc.bInterval; | ||
| 150 | if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
| 151 | uvc_printk(KERN_ERR, "Failed to resubmit status URB (%d).\n", | ||
| 152 | ret); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | int uvc_status_init(struct uvc_device *dev) | ||
| 157 | { | ||
| 158 | struct usb_host_endpoint *ep = dev->int_ep; | ||
| 159 | unsigned int pipe; | ||
| 160 | int interval; | ||
| 161 | |||
| 162 | if (ep == NULL) | ||
| 163 | return 0; | ||
| 164 | |||
| 165 | uvc_input_init(dev); | ||
| 166 | |||
| 167 | dev->int_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
| 168 | if (dev->int_urb == NULL) | ||
| 169 | return -ENOMEM; | ||
| 170 | |||
| 171 | pipe = usb_rcvintpipe(dev->udev, ep->desc.bEndpointAddress); | ||
| 172 | |||
| 173 | /* For high-speed interrupt endpoints, the bInterval value is used as | ||
| 174 | * an exponent of two. Some developers forgot about it. | ||
| 175 | */ | ||
| 176 | interval = ep->desc.bInterval; | ||
| 177 | if (interval > 16 && dev->udev->speed == USB_SPEED_HIGH && | ||
| 178 | (dev->quirks & UVC_QUIRK_STATUS_INTERVAL)) | ||
| 179 | interval = fls(interval) - 1; | ||
| 180 | |||
| 181 | usb_fill_int_urb(dev->int_urb, dev->udev, pipe, | ||
| 182 | dev->status, sizeof dev->status, uvc_status_complete, | ||
| 183 | dev, interval); | ||
| 184 | |||
| 185 | return usb_submit_urb(dev->int_urb, GFP_KERNEL); | ||
| 186 | } | ||
| 187 | |||
| 188 | void uvc_status_cleanup(struct uvc_device *dev) | ||
| 189 | { | ||
| 190 | usb_kill_urb(dev->int_urb); | ||
| 191 | usb_free_urb(dev->int_urb); | ||
| 192 | uvc_input_cleanup(dev); | ||
| 193 | } | ||
| 194 | |||
| 195 | int uvc_status_suspend(struct uvc_device *dev) | ||
| 196 | { | ||
| 197 | usb_kill_urb(dev->int_urb); | ||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | |||
| 201 | int uvc_status_resume(struct uvc_device *dev) | ||
| 202 | { | ||
| 203 | if (dev->int_urb == NULL) | ||
| 204 | return 0; | ||
| 205 | |||
| 206 | return usb_submit_urb(dev->int_urb, GFP_KERNEL); | ||
| 207 | } | ||
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c new file mode 100644 index 000000000000..2e0a66575bb4 --- /dev/null +++ b/drivers/media/video/uvc/uvc_v4l2.c | |||
| @@ -0,0 +1,1105 @@ | |||
| 1 | /* | ||
| 2 | * uvc_v4l2.c -- USB Video Class driver - V4L2 API | ||
| 3 | * | ||
| 4 | * Copyright (C) 2005-2008 | ||
| 5 | * Laurent Pinchart (laurent.pinchart@skynet.be) | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/version.h> | ||
| 16 | #include <linux/list.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/usb.h> | ||
| 19 | #include <linux/videodev2.h> | ||
| 20 | #include <linux/vmalloc.h> | ||
| 21 | #include <linux/mm.h> | ||
| 22 | #include <linux/wait.h> | ||
| 23 | #include <asm/atomic.h> | ||
| 24 | |||
| 25 | #include <media/v4l2-common.h> | ||
| 26 | |||
| 27 | #include "uvcvideo.h" | ||
| 28 | |||
| 29 | /* ------------------------------------------------------------------------ | ||
| 30 | * V4L2 interface | ||
| 31 | */ | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Mapping V4L2 controls to UVC controls can be straighforward if done well. | ||
| 35 | * Most of the UVC controls exist in V4L2, and can be mapped directly. Some | ||
| 36 | * must be grouped (for instance the Red Balance, Blue Balance and Do White | ||
| 37 | * Balance V4L2 controls use the White Balance Component UVC control) or | ||
| 38 | * otherwise translated. The approach we take here is to use a translation | ||
| 39 | * table for the controls which can be mapped directly, and handle the others | ||
| 40 | * manually. | ||
| 41 | */ | ||
| 42 | static int uvc_v4l2_query_menu(struct uvc_video_device *video, | ||
| 43 | struct v4l2_querymenu *query_menu) | ||
| 44 | { | ||
| 45 | struct uvc_menu_info *menu_info; | ||
| 46 | struct uvc_control_mapping *mapping; | ||
| 47 | struct uvc_control *ctrl; | ||
| 48 | |||
| 49 | ctrl = uvc_find_control(video, query_menu->id, &mapping); | ||
| 50 | if (ctrl == NULL || mapping->v4l2_type != V4L2_CTRL_TYPE_MENU) | ||
| 51 | return -EINVAL; | ||
| 52 | |||
| 53 | if (query_menu->index >= mapping->menu_count) | ||
| 54 | return -EINVAL; | ||
| 55 | |||
| 56 | menu_info = &mapping->menu_info[query_menu->index]; | ||
| 57 | strncpy(query_menu->name, menu_info->name, 32); | ||
| 58 | return 0; | ||
| 59 | } | ||
| 60 | |||
| 61 | /* | ||
| 62 | * Find the frame interval closest to the requested frame interval for the | ||
| 63 | * given frame format and size. This should be done by the device as part of | ||
| 64 | * the Video Probe and Commit negotiation, but some hardware don't implement | ||
| 65 | * that feature. | ||
| 66 | */ | ||
| 67 | static __u32 uvc_try_frame_interval(struct uvc_frame *frame, __u32 interval) | ||
| 68 | { | ||
| 69 | unsigned int i; | ||
| 70 | |||
| 71 | if (frame->bFrameIntervalType) { | ||
| 72 | __u32 best = -1, dist; | ||
| 73 | |||
| 74 | for (i = 0; i < frame->bFrameIntervalType; ++i) { | ||
| 75 | dist = interval > frame->dwFrameInterval[i] | ||
| 76 | ? interval - frame->dwFrameInterval[i] | ||
| 77 | : frame->dwFrameInterval[i] - interval; | ||
| 78 | |||
| 79 | if (dist > best) | ||
| 80 | break; | ||
| 81 | |||
| 82 | best = dist; | ||
| 83 | } | ||
| 84 | |||
| 85 | interval = frame->dwFrameInterval[i-1]; | ||
| 86 | } else { | ||
| 87 | const __u32 min = frame->dwFrameInterval[0]; | ||
| 88 | const __u32 max = frame->dwFrameInterval[1]; | ||
| 89 | const __u32 step = frame->dwFrameInterval[2]; | ||
| 90 | |||
| 91 | interval = min + (interval - min + step/2) / step * step; | ||
| 92 | if (interval > max) | ||
| 93 | interval = max; | ||
| 94 | } | ||
| 95 | |||
| 96 | return interval; | ||
| 97 | } | ||
| 98 | |||
| 99 | static int uvc_v4l2_try_format(struct uvc_video_device *video, | ||
| 100 | struct v4l2_format *fmt, struct uvc_streaming_control *probe, | ||
| 101 | struct uvc_format **uvc_format, struct uvc_frame **uvc_frame) | ||
| 102 | { | ||
| 103 | struct uvc_format *format = NULL; | ||
| 104 | struct uvc_frame *frame = NULL; | ||
| 105 | __u16 rw, rh; | ||
| 106 | unsigned int d, maxd; | ||
| 107 | unsigned int i; | ||
| 108 | __u32 interval; | ||
| 109 | int ret = 0; | ||
| 110 | __u8 *fcc; | ||
| 111 | |||
| 112 | if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 113 | return -EINVAL; | ||
| 114 | |||
| 115 | fcc = (__u8 *)&fmt->fmt.pix.pixelformat; | ||
| 116 | uvc_trace(UVC_TRACE_FORMAT, "Trying format 0x%08x (%c%c%c%c): %ux%u.\n", | ||
| 117 | fmt->fmt.pix.pixelformat, | ||
| 118 | fcc[0], fcc[1], fcc[2], fcc[3], | ||
| 119 | fmt->fmt.pix.width, fmt->fmt.pix.height); | ||
| 120 | |||
| 121 | /* Check if the hardware supports the requested format. */ | ||
| 122 | for (i = 0; i < video->streaming->nformats; ++i) { | ||
| 123 | format = &video->streaming->format[i]; | ||
| 124 | if (format->fcc == fmt->fmt.pix.pixelformat) | ||
| 125 | break; | ||
| 126 | } | ||
| 127 | |||
| 128 | if (format == NULL || format->fcc != fmt->fmt.pix.pixelformat) { | ||
| 129 | uvc_trace(UVC_TRACE_FORMAT, "Unsupported format 0x%08x.\n", | ||
| 130 | fmt->fmt.pix.pixelformat); | ||
| 131 | return -EINVAL; | ||
| 132 | } | ||
| 133 | |||
| 134 | /* Find the closest image size. The distance between image sizes is | ||
| 135 | * the size in pixels of the non-overlapping regions between the | ||
| 136 | * requested size and the frame-specified size. | ||
| 137 | */ | ||
| 138 | rw = fmt->fmt.pix.width; | ||
| 139 | rh = fmt->fmt.pix.height; | ||
| 140 | maxd = (unsigned int)-1; | ||
| 141 | |||
| 142 | for (i = 0; i < format->nframes; ++i) { | ||
| 143 | __u16 w = format->frame[i].wWidth; | ||
| 144 | __u16 h = format->frame[i].wHeight; | ||
| 145 | |||
| 146 | d = min(w, rw) * min(h, rh); | ||
| 147 | d = w*h + rw*rh - 2*d; | ||
| 148 | if (d < maxd) { | ||
| 149 | maxd = d; | ||
| 150 | frame = &format->frame[i]; | ||
| 151 | } | ||
| 152 | |||
| 153 | if (maxd == 0) | ||
| 154 | break; | ||
| 155 | } | ||
| 156 | |||
| 157 | if (frame == NULL) { | ||
| 158 | uvc_trace(UVC_TRACE_FORMAT, "Unsupported size %ux%u.\n", | ||
| 159 | fmt->fmt.pix.width, fmt->fmt.pix.height); | ||
| 160 | return -EINVAL; | ||
| 161 | } | ||
| 162 | |||
| 163 | /* Use the default frame interval. */ | ||
| 164 | interval = frame->dwDefaultFrameInterval; | ||
| 165 | uvc_trace(UVC_TRACE_FORMAT, "Using default frame interval %u.%u us " | ||
| 166 | "(%u.%u fps).\n", interval/10, interval%10, 10000000/interval, | ||
| 167 | (100000000/interval)%10); | ||
| 168 | |||
| 169 | /* Set the format index, frame index and frame interval. */ | ||
| 170 | memset(probe, 0, sizeof *probe); | ||
| 171 | probe->bmHint = 1; /* dwFrameInterval */ | ||
| 172 | probe->bFormatIndex = format->index; | ||
| 173 | probe->bFrameIndex = frame->bFrameIndex; | ||
| 174 | probe->dwFrameInterval = uvc_try_frame_interval(frame, interval); | ||
| 175 | /* Some webcams stall the probe control set request when the | ||
| 176 | * dwMaxVideoFrameSize field is set to zero. The UVC specification | ||
| 177 | * clearly states that the field is read-only from the host, so this | ||
| 178 | * is a webcam bug. Set dwMaxVideoFrameSize to the value reported by | ||
| 179 | * the webcam to work around the problem. | ||
| 180 | * | ||
| 181 | * The workaround could probably be enabled for all webcams, so the | ||
| 182 | * quirk can be removed if needed. It's currently useful to detect | ||
| 183 | * webcam bugs and fix them before they hit the market (providing | ||
| 184 | * developers test their webcams with the Linux driver as well as with | ||
| 185 | * the Windows driver). | ||
| 186 | */ | ||
| 187 | if (video->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS) | ||
| 188 | probe->dwMaxVideoFrameSize = | ||
| 189 | video->streaming->ctrl.dwMaxVideoFrameSize; | ||
| 190 | |||
| 191 | /* Probe the device */ | ||
| 192 | if ((ret = uvc_probe_video(video, probe)) < 0) | ||
| 193 | goto done; | ||
| 194 | |||
| 195 | fmt->fmt.pix.width = frame->wWidth; | ||
| 196 | fmt->fmt.pix.height = frame->wHeight; | ||
| 197 | fmt->fmt.pix.field = V4L2_FIELD_NONE; | ||
| 198 | fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8; | ||
| 199 | fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize; | ||
| 200 | fmt->fmt.pix.colorspace = format->colorspace; | ||
| 201 | fmt->fmt.pix.priv = 0; | ||
| 202 | |||
| 203 | if (uvc_format != NULL) | ||
| 204 | *uvc_format = format; | ||
| 205 | if (uvc_frame != NULL) | ||
| 206 | *uvc_frame = frame; | ||
| 207 | |||
| 208 | done: | ||
| 209 | return ret; | ||
| 210 | } | ||
| 211 | |||
| 212 | static int uvc_v4l2_get_format(struct uvc_video_device *video, | ||
| 213 | struct v4l2_format *fmt) | ||
| 214 | { | ||
| 215 | struct uvc_format *format = video->streaming->cur_format; | ||
| 216 | struct uvc_frame *frame = video->streaming->cur_frame; | ||
| 217 | |||
| 218 | if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 219 | return -EINVAL; | ||
| 220 | |||
| 221 | if (format == NULL || frame == NULL) | ||
| 222 | return -EINVAL; | ||
| 223 | |||
| 224 | fmt->fmt.pix.pixelformat = format->fcc; | ||
| 225 | fmt->fmt.pix.width = frame->wWidth; | ||
| 226 | fmt->fmt.pix.height = frame->wHeight; | ||
| 227 | fmt->fmt.pix.field = V4L2_FIELD_NONE; | ||
| 228 | fmt->fmt.pix.bytesperline = format->bpp * frame->wWidth / 8; | ||
| 229 | fmt->fmt.pix.sizeimage = video->streaming->ctrl.dwMaxVideoFrameSize; | ||
| 230 | fmt->fmt.pix.colorspace = format->colorspace; | ||
| 231 | fmt->fmt.pix.priv = 0; | ||
| 232 | |||
| 233 | return 0; | ||
| 234 | } | ||
| 235 | |||
| 236 | static int uvc_v4l2_set_format(struct uvc_video_device *video, | ||
| 237 | struct v4l2_format *fmt) | ||
| 238 | { | ||
| 239 | struct uvc_streaming_control probe; | ||
| 240 | struct uvc_format *format; | ||
| 241 | struct uvc_frame *frame; | ||
| 242 | int ret; | ||
| 243 | |||
| 244 | if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 245 | return -EINVAL; | ||
| 246 | |||
| 247 | if (uvc_queue_streaming(&video->queue)) | ||
| 248 | return -EBUSY; | ||
| 249 | |||
| 250 | ret = uvc_v4l2_try_format(video, fmt, &probe, &format, &frame); | ||
| 251 | if (ret < 0) | ||
| 252 | return ret; | ||
| 253 | |||
| 254 | if ((ret = uvc_set_video_ctrl(video, &probe, 0)) < 0) | ||
| 255 | return ret; | ||
| 256 | |||
| 257 | memcpy(&video->streaming->ctrl, &probe, sizeof probe); | ||
| 258 | video->streaming->cur_format = format; | ||
| 259 | video->streaming->cur_frame = frame; | ||
| 260 | |||
| 261 | return 0; | ||
| 262 | } | ||
| 263 | |||
| 264 | static int uvc_v4l2_get_streamparm(struct uvc_video_device *video, | ||
| 265 | struct v4l2_streamparm *parm) | ||
| 266 | { | ||
| 267 | uint32_t numerator, denominator; | ||
| 268 | |||
| 269 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 270 | return -EINVAL; | ||
| 271 | |||
| 272 | numerator = video->streaming->ctrl.dwFrameInterval; | ||
| 273 | denominator = 10000000; | ||
| 274 | uvc_simplify_fraction(&numerator, &denominator, 8, 333); | ||
| 275 | |||
| 276 | memset(parm, 0, sizeof *parm); | ||
| 277 | parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | ||
| 278 | parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; | ||
| 279 | parm->parm.capture.capturemode = 0; | ||
| 280 | parm->parm.capture.timeperframe.numerator = numerator; | ||
| 281 | parm->parm.capture.timeperframe.denominator = denominator; | ||
| 282 | parm->parm.capture.extendedmode = 0; | ||
| 283 | parm->parm.capture.readbuffers = 0; | ||
| 284 | |||
| 285 | return 0; | ||
| 286 | } | ||
| 287 | |||
| 288 | static int uvc_v4l2_set_streamparm(struct uvc_video_device *video, | ||
| 289 | struct v4l2_streamparm *parm) | ||
| 290 | { | ||
| 291 | struct uvc_frame *frame = video->streaming->cur_frame; | ||
| 292 | struct uvc_streaming_control probe; | ||
| 293 | uint32_t interval; | ||
| 294 | int ret; | ||
| 295 | |||
| 296 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 297 | return -EINVAL; | ||
| 298 | |||
| 299 | if (uvc_queue_streaming(&video->queue)) | ||
| 300 | return -EBUSY; | ||
| 301 | |||
| 302 | memcpy(&probe, &video->streaming->ctrl, sizeof probe); | ||
| 303 | interval = uvc_fraction_to_interval( | ||
| 304 | parm->parm.capture.timeperframe.numerator, | ||
| 305 | parm->parm.capture.timeperframe.denominator); | ||
| 306 | |||
| 307 | uvc_trace(UVC_TRACE_FORMAT, "Setting frame interval to %u/%u (%u).\n", | ||
| 308 | parm->parm.capture.timeperframe.numerator, | ||
| 309 | parm->parm.capture.timeperframe.denominator, | ||
| 310 | interval); | ||
| 311 | probe.dwFrameInterval = uvc_try_frame_interval(frame, interval); | ||
| 312 | |||
| 313 | /* Probe the device with the new settings. */ | ||
| 314 | if ((ret = uvc_probe_video(video, &probe)) < 0) | ||
| 315 | return ret; | ||
| 316 | |||
| 317 | /* Commit the new settings. */ | ||
| 318 | if ((ret = uvc_set_video_ctrl(video, &probe, 0)) < 0) | ||
| 319 | return ret; | ||
| 320 | |||
| 321 | memcpy(&video->streaming->ctrl, &probe, sizeof probe); | ||
| 322 | |||
| 323 | /* Return the actual frame period. */ | ||
| 324 | parm->parm.capture.timeperframe.numerator = probe.dwFrameInterval; | ||
| 325 | parm->parm.capture.timeperframe.denominator = 10000000; | ||
| 326 | uvc_simplify_fraction(&parm->parm.capture.timeperframe.numerator, | ||
| 327 | &parm->parm.capture.timeperframe.denominator, | ||
| 328 | 8, 333); | ||
| 329 | |||
| 330 | return 0; | ||
| 331 | } | ||
| 332 | |||
| 333 | /* ------------------------------------------------------------------------ | ||
| 334 | * Privilege management | ||
| 335 | */ | ||
| 336 | |||
| 337 | /* | ||
| 338 | * Privilege management is the multiple-open implementation basis. The current | ||
| 339 | * implementation is completely transparent for the end-user and doesn't | ||
| 340 | * require explicit use of the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioctls. | ||
| 341 | * Those ioctls enable finer control on the device (by making possible for a | ||
| 342 | * user to request exclusive access to a device), but are not mature yet. | ||
| 343 | * Switching to the V4L2 priority mechanism might be considered in the future | ||
| 344 | * if this situation changes. | ||
| 345 | * | ||
| 346 | * Each open instance of a UVC device can either be in a privileged or | ||
| 347 | * unprivileged state. Only a single instance can be in a privileged state at | ||
| 348 | * a given time. Trying to perform an operation which requires privileges will | ||
| 349 | * automatically acquire the required privileges if possible, or return -EBUSY | ||
| 350 | * otherwise. Privileges are dismissed when closing the instance. | ||
| 351 | * | ||
| 352 | * Operations which require privileges are: | ||
| 353 | * | ||
| 354 | * - VIDIOC_S_INPUT | ||
| 355 | * - VIDIOC_S_PARM | ||
| 356 | * - VIDIOC_S_FMT | ||
| 357 | * - VIDIOC_TRY_FMT | ||
| 358 | * - VIDIOC_REQBUFS | ||
| 359 | */ | ||
| 360 | static int uvc_acquire_privileges(struct uvc_fh *handle) | ||
| 361 | { | ||
| 362 | int ret = 0; | ||
| 363 | |||
| 364 | /* Always succeed if the handle is already privileged. */ | ||
| 365 | if (handle->state == UVC_HANDLE_ACTIVE) | ||
| 366 | return 0; | ||
| 367 | |||
| 368 | /* Check if the device already has a privileged handle. */ | ||
| 369 | mutex_lock(&uvc_driver.open_mutex); | ||
| 370 | if (atomic_inc_return(&handle->device->active) != 1) { | ||
| 371 | atomic_dec(&handle->device->active); | ||
| 372 | ret = -EBUSY; | ||
| 373 | goto done; | ||
| 374 | } | ||
| 375 | |||
| 376 | handle->state = UVC_HANDLE_ACTIVE; | ||
| 377 | |||
| 378 | done: | ||
| 379 | mutex_unlock(&uvc_driver.open_mutex); | ||
| 380 | return ret; | ||
| 381 | } | ||
| 382 | |||
| 383 | static void uvc_dismiss_privileges(struct uvc_fh *handle) | ||
| 384 | { | ||
| 385 | if (handle->state == UVC_HANDLE_ACTIVE) | ||
| 386 | atomic_dec(&handle->device->active); | ||
| 387 | |||
| 388 | handle->state = UVC_HANDLE_PASSIVE; | ||
| 389 | } | ||
| 390 | |||
| 391 | static int uvc_has_privileges(struct uvc_fh *handle) | ||
| 392 | { | ||
| 393 | return handle->state == UVC_HANDLE_ACTIVE; | ||
| 394 | } | ||
| 395 | |||
| 396 | /* ------------------------------------------------------------------------ | ||
| 397 | * V4L2 file operations | ||
| 398 | */ | ||
| 399 | |||
| 400 | static int uvc_v4l2_open(struct inode *inode, struct file *file) | ||
| 401 | { | ||
| 402 | struct video_device *vdev; | ||
| 403 | struct uvc_video_device *video; | ||
| 404 | struct uvc_fh *handle; | ||
| 405 | int ret = 0; | ||
| 406 | |||
| 407 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n"); | ||
| 408 | mutex_lock(&uvc_driver.open_mutex); | ||
| 409 | vdev = video_devdata(file); | ||
| 410 | video = video_get_drvdata(vdev); | ||
| 411 | |||
| 412 | if (video->dev->state & UVC_DEV_DISCONNECTED) { | ||
| 413 | ret = -ENODEV; | ||
| 414 | goto done; | ||
| 415 | } | ||
| 416 | |||
| 417 | ret = usb_autopm_get_interface(video->dev->intf); | ||
| 418 | if (ret < 0) | ||
| 419 | goto done; | ||
| 420 | |||
| 421 | /* Create the device handle. */ | ||
| 422 | handle = kzalloc(sizeof *handle, GFP_KERNEL); | ||
| 423 | if (handle == NULL) { | ||
| 424 | usb_autopm_put_interface(video->dev->intf); | ||
| 425 | ret = -ENOMEM; | ||
| 426 | goto done; | ||
| 427 | } | ||
| 428 | |||
| 429 | handle->device = video; | ||
| 430 | handle->state = UVC_HANDLE_PASSIVE; | ||
| 431 | file->private_data = handle; | ||
| 432 | |||
| 433 | kref_get(&video->dev->kref); | ||
| 434 | |||
| 435 | done: | ||
| 436 | mutex_unlock(&uvc_driver.open_mutex); | ||
| 437 | return ret; | ||
| 438 | } | ||
| 439 | |||
| 440 | static int uvc_v4l2_release(struct inode *inode, struct file *file) | ||
| 441 | { | ||
| 442 | struct video_device *vdev = video_devdata(file); | ||
| 443 | struct uvc_video_device *video = video_get_drvdata(vdev); | ||
| 444 | struct uvc_fh *handle = (struct uvc_fh *)file->private_data; | ||
| 445 | |||
| 446 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n"); | ||
| 447 | |||
| 448 | /* Only free resources if this is a privileged handle. */ | ||
| 449 | if (uvc_has_privileges(handle)) { | ||
| 450 | uvc_video_enable(video, 0); | ||
| 451 | |||
| 452 | mutex_lock(&video->queue.mutex); | ||
| 453 | if (uvc_free_buffers(&video->queue) < 0) | ||
| 454 | uvc_printk(KERN_ERR, "uvc_v4l2_release: Unable to " | ||
| 455 | "free buffers.\n"); | ||
| 456 | mutex_unlock(&video->queue.mutex); | ||
| 457 | } | ||
| 458 | |||
| 459 | /* Release the file handle. */ | ||
| 460 | uvc_dismiss_privileges(handle); | ||
| 461 | kfree(handle); | ||
| 462 | file->private_data = NULL; | ||
| 463 | |||
| 464 | usb_autopm_put_interface(video->dev->intf); | ||
| 465 | kref_put(&video->dev->kref, uvc_delete); | ||
| 466 | return 0; | ||
| 467 | } | ||
| 468 | |||
| 469 | static int uvc_v4l2_do_ioctl(struct inode *inode, struct file *file, | ||
| 470 | unsigned int cmd, void *arg) | ||
| 471 | { | ||
| 472 | struct video_device *vdev = video_devdata(file); | ||
| 473 | struct uvc_video_device *video = video_get_drvdata(vdev); | ||
| 474 | struct uvc_fh *handle = (struct uvc_fh *)file->private_data; | ||
| 475 | int ret = 0; | ||
| 476 | |||
| 477 | if (uvc_trace_param & UVC_TRACE_IOCTL) | ||
| 478 | v4l_printk_ioctl(cmd); | ||
| 479 | |||
| 480 | switch (cmd) { | ||
| 481 | /* Query capabilities */ | ||
| 482 | case VIDIOC_QUERYCAP: | ||
| 483 | { | ||
| 484 | struct v4l2_capability *cap = arg; | ||
| 485 | |||
| 486 | memset(cap, 0, sizeof *cap); | ||
| 487 | strncpy(cap->driver, "uvcvideo", sizeof cap->driver); | ||
| 488 | strncpy(cap->card, vdev->name, 32); | ||
| 489 | strncpy(cap->bus_info, video->dev->udev->bus->bus_name, | ||
| 490 | sizeof cap->bus_info); | ||
| 491 | cap->version = DRIVER_VERSION_NUMBER; | ||
| 492 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | ||
| 493 | | V4L2_CAP_STREAMING; | ||
| 494 | break; | ||
| 495 | } | ||
| 496 | |||
| 497 | /* Get, Set & Query control */ | ||
| 498 | case VIDIOC_QUERYCTRL: | ||
| 499 | return uvc_query_v4l2_ctrl(video, arg); | ||
| 500 | |||
| 501 | case VIDIOC_G_CTRL: | ||
| 502 | { | ||
| 503 | struct v4l2_control *ctrl = arg; | ||
| 504 | struct v4l2_ext_control xctrl; | ||
| 505 | |||
| 506 | memset(&xctrl, 0, sizeof xctrl); | ||
| 507 | xctrl.id = ctrl->id; | ||
| 508 | |||
| 509 | uvc_ctrl_begin(video); | ||
| 510 | ret = uvc_ctrl_get(video, &xctrl); | ||
| 511 | uvc_ctrl_rollback(video); | ||
| 512 | if (ret >= 0) | ||
| 513 | ctrl->value = xctrl.value; | ||
| 514 | break; | ||
| 515 | } | ||
| 516 | |||
| 517 | case VIDIOC_S_CTRL: | ||
| 518 | { | ||
| 519 | struct v4l2_control *ctrl = arg; | ||
| 520 | struct v4l2_ext_control xctrl; | ||
| 521 | |||
| 522 | memset(&xctrl, 0, sizeof xctrl); | ||
| 523 | xctrl.id = ctrl->id; | ||
| 524 | xctrl.value = ctrl->value; | ||
| 525 | |||
| 526 | uvc_ctrl_begin(video); | ||
| 527 | ret = uvc_ctrl_set(video, &xctrl); | ||
| 528 | if (ret < 0) { | ||
| 529 | uvc_ctrl_rollback(video); | ||
| 530 | return ret; | ||
| 531 | } | ||
| 532 | ret = uvc_ctrl_commit(video); | ||
| 533 | break; | ||
| 534 | } | ||
| 535 | |||
| 536 | case VIDIOC_QUERYMENU: | ||
| 537 | return uvc_v4l2_query_menu(video, arg); | ||
| 538 | |||
| 539 | case VIDIOC_G_EXT_CTRLS: | ||
| 540 | { | ||
| 541 | struct v4l2_ext_controls *ctrls = arg; | ||
| 542 | struct v4l2_ext_control *ctrl = ctrls->controls; | ||
| 543 | unsigned int i; | ||
| 544 | |||
| 545 | uvc_ctrl_begin(video); | ||
| 546 | for (i = 0; i < ctrls->count; ++ctrl, ++i) { | ||
| 547 | ret = uvc_ctrl_get(video, ctrl); | ||
| 548 | if (ret < 0) { | ||
| 549 | uvc_ctrl_rollback(video); | ||
| 550 | ctrls->error_idx = i; | ||
| 551 | return ret; | ||
| 552 | } | ||
| 553 | } | ||
| 554 | ctrls->error_idx = 0; | ||
| 555 | ret = uvc_ctrl_rollback(video); | ||
| 556 | break; | ||
| 557 | } | ||
| 558 | |||
| 559 | case VIDIOC_S_EXT_CTRLS: | ||
| 560 | case VIDIOC_TRY_EXT_CTRLS: | ||
| 561 | { | ||
| 562 | struct v4l2_ext_controls *ctrls = arg; | ||
| 563 | struct v4l2_ext_control *ctrl = ctrls->controls; | ||
| 564 | unsigned int i; | ||
| 565 | |||
| 566 | ret = uvc_ctrl_begin(video); | ||
| 567 | if (ret < 0) | ||
| 568 | return ret; | ||
| 569 | |||
| 570 | for (i = 0; i < ctrls->count; ++ctrl, ++i) { | ||
| 571 | ret = uvc_ctrl_set(video, ctrl); | ||
| 572 | if (ret < 0) { | ||
| 573 | uvc_ctrl_rollback(video); | ||
| 574 | ctrls->error_idx = i; | ||
| 575 | return ret; | ||
| 576 | } | ||
| 577 | } | ||
| 578 | |||
| 579 | ctrls->error_idx = 0; | ||
| 580 | |||
| 581 | if (cmd == VIDIOC_S_EXT_CTRLS) | ||
| 582 | ret = uvc_ctrl_commit(video); | ||
| 583 | else | ||
| 584 | ret = uvc_ctrl_rollback(video); | ||
| 585 | break; | ||
| 586 | } | ||
| 587 | |||
| 588 | /* Get, Set & Enum input */ | ||
| 589 | case VIDIOC_ENUMINPUT: | ||
| 590 | { | ||
| 591 | const struct uvc_entity *selector = video->selector; | ||
| 592 | struct v4l2_input *input = arg; | ||
| 593 | struct uvc_entity *iterm = NULL; | ||
| 594 | u32 index = input->index; | ||
| 595 | int pin = 0; | ||
| 596 | |||
| 597 | if (selector == NULL || | ||
| 598 | (video->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { | ||
| 599 | if (index != 0) | ||
| 600 | return -EINVAL; | ||
| 601 | iterm = list_first_entry(&video->iterms, | ||
| 602 | struct uvc_entity, chain); | ||
| 603 | pin = iterm->id; | ||
| 604 | } else if (pin < selector->selector.bNrInPins) { | ||
| 605 | pin = selector->selector.baSourceID[index]; | ||
| 606 | list_for_each_entry(iterm, video->iterms.next, chain) { | ||
| 607 | if (iterm->id == pin) | ||
| 608 | break; | ||
| 609 | } | ||
| 610 | } | ||
| 611 | |||
| 612 | if (iterm == NULL || iterm->id != pin) | ||
| 613 | return -EINVAL; | ||
| 614 | |||
| 615 | memset(input, 0, sizeof *input); | ||
| 616 | input->index = index; | ||
| 617 | strncpy(input->name, iterm->name, sizeof input->name); | ||
| 618 | if (UVC_ENTITY_TYPE(iterm) == ITT_CAMERA) | ||
| 619 | input->type = V4L2_INPUT_TYPE_CAMERA; | ||
| 620 | break; | ||
| 621 | } | ||
| 622 | |||
| 623 | case VIDIOC_G_INPUT: | ||
| 624 | { | ||
| 625 | u8 input; | ||
| 626 | |||
| 627 | if (video->selector == NULL || | ||
| 628 | (video->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { | ||
| 629 | *(int *)arg = 0; | ||
| 630 | break; | ||
| 631 | } | ||
| 632 | |||
| 633 | ret = uvc_query_ctrl(video->dev, GET_CUR, video->selector->id, | ||
| 634 | video->dev->intfnum, SU_INPUT_SELECT_CONTROL, | ||
| 635 | &input, 1); | ||
| 636 | if (ret < 0) | ||
| 637 | return ret; | ||
| 638 | |||
| 639 | *(int *)arg = input - 1; | ||
| 640 | break; | ||
| 641 | } | ||
| 642 | |||
| 643 | case VIDIOC_S_INPUT: | ||
| 644 | { | ||
| 645 | u8 input = *(u32 *)arg + 1; | ||
| 646 | |||
| 647 | if ((ret = uvc_acquire_privileges(handle)) < 0) | ||
| 648 | return ret; | ||
| 649 | |||
| 650 | if (video->selector == NULL || | ||
| 651 | (video->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { | ||
| 652 | if (input != 1) | ||
| 653 | return -EINVAL; | ||
| 654 | break; | ||
| 655 | } | ||
| 656 | |||
| 657 | if (input > video->selector->selector.bNrInPins) | ||
| 658 | return -EINVAL; | ||
| 659 | |||
| 660 | return uvc_query_ctrl(video->dev, SET_CUR, video->selector->id, | ||
| 661 | video->dev->intfnum, SU_INPUT_SELECT_CONTROL, | ||
| 662 | &input, 1); | ||
| 663 | } | ||
| 664 | |||
| 665 | /* Try, Get, Set & Enum format */ | ||
| 666 | case VIDIOC_ENUM_FMT: | ||
| 667 | { | ||
| 668 | struct v4l2_fmtdesc *fmt = arg; | ||
| 669 | struct uvc_format *format; | ||
| 670 | |||
| 671 | if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | ||
| 672 | fmt->index >= video->streaming->nformats) | ||
| 673 | return -EINVAL; | ||
| 674 | |||
| 675 | format = &video->streaming->format[fmt->index]; | ||
| 676 | fmt->flags = 0; | ||
| 677 | if (format->flags & UVC_FMT_FLAG_COMPRESSED) | ||
| 678 | fmt->flags |= V4L2_FMT_FLAG_COMPRESSED; | ||
| 679 | strncpy(fmt->description, format->name, | ||
| 680 | sizeof fmt->description); | ||
| 681 | fmt->description[sizeof fmt->description - 1] = 0; | ||
| 682 | fmt->pixelformat = format->fcc; | ||
| 683 | break; | ||
| 684 | } | ||
| 685 | |||
| 686 | case VIDIOC_TRY_FMT: | ||
| 687 | { | ||
| 688 | struct uvc_streaming_control probe; | ||
| 689 | |||
| 690 | if ((ret = uvc_acquire_privileges(handle)) < 0) | ||
| 691 | return ret; | ||
| 692 | |||
| 693 | return uvc_v4l2_try_format(video, arg, &probe, NULL, NULL); | ||
| 694 | } | ||
| 695 | |||
| 696 | case VIDIOC_S_FMT: | ||
| 697 | if ((ret = uvc_acquire_privileges(handle)) < 0) | ||
| 698 | return ret; | ||
| 699 | |||
| 700 | return uvc_v4l2_set_format(video, arg); | ||
| 701 | |||
| 702 | case VIDIOC_G_FMT: | ||
| 703 | return uvc_v4l2_get_format(video, arg); | ||
| 704 | |||
| 705 | /* Frame size enumeration */ | ||
| 706 | case VIDIOC_ENUM_FRAMESIZES: | ||
| 707 | { | ||
| 708 | struct v4l2_frmsizeenum *fsize = arg; | ||
| 709 | struct uvc_format *format = NULL; | ||
| 710 | struct uvc_frame *frame; | ||
| 711 | int i; | ||
| 712 | |||
| 713 | /* Look for the given pixel format */ | ||
| 714 | for (i = 0; i < video->streaming->nformats; i++) { | ||
| 715 | if (video->streaming->format[i].fcc == | ||
| 716 | fsize->pixel_format) { | ||
| 717 | format = &video->streaming->format[i]; | ||
| 718 | break; | ||
| 719 | } | ||
| 720 | } | ||
| 721 | if (format == NULL) | ||
| 722 | return -EINVAL; | ||
| 723 | |||
| 724 | if (fsize->index >= format->nframes) | ||
| 725 | return -EINVAL; | ||
| 726 | |||
| 727 | frame = &format->frame[fsize->index]; | ||
| 728 | fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; | ||
| 729 | fsize->discrete.width = frame->wWidth; | ||
| 730 | fsize->discrete.height = frame->wHeight; | ||
| 731 | break; | ||
| 732 | } | ||
| 733 | |||
| 734 | /* Frame interval enumeration */ | ||
| 735 | case VIDIOC_ENUM_FRAMEINTERVALS: | ||
| 736 | { | ||
| 737 | struct v4l2_frmivalenum *fival = arg; | ||
| 738 | struct uvc_format *format = NULL; | ||
| 739 | struct uvc_frame *frame = NULL; | ||
| 740 | int i; | ||
| 741 | |||
| 742 | /* Look for the given pixel format and frame size */ | ||
| 743 | for (i = 0; i < video->streaming->nformats; i++) { | ||
| 744 | if (video->streaming->format[i].fcc == | ||
| 745 | fival->pixel_format) { | ||
| 746 | format = &video->streaming->format[i]; | ||
| 747 | break; | ||
| 748 | } | ||
| 749 | } | ||
| 750 | if (format == NULL) | ||
| 751 | return -EINVAL; | ||
| 752 | |||
| 753 | for (i = 0; i < format->nframes; i++) { | ||
| 754 | if (format->frame[i].wWidth == fival->width && | ||
| 755 | format->frame[i].wHeight == fival->height) { | ||
| 756 | frame = &format->frame[i]; | ||
| 757 | break; | ||
| 758 | } | ||
| 759 | } | ||
| 760 | if (frame == NULL) | ||
| 761 | return -EINVAL; | ||
| 762 | |||
| 763 | if (frame->bFrameIntervalType) { | ||
| 764 | if (fival->index >= frame->bFrameIntervalType) | ||
| 765 | return -EINVAL; | ||
| 766 | |||
| 767 | fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; | ||
| 768 | fival->discrete.numerator = | ||
| 769 | frame->dwFrameInterval[fival->index]; | ||
| 770 | fival->discrete.denominator = 10000000; | ||
| 771 | uvc_simplify_fraction(&fival->discrete.numerator, | ||
| 772 | &fival->discrete.denominator, 8, 333); | ||
| 773 | } else { | ||
| 774 | fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; | ||
| 775 | fival->stepwise.min.numerator = | ||
| 776 | frame->dwFrameInterval[0]; | ||
| 777 | fival->stepwise.min.denominator = 10000000; | ||
| 778 | fival->stepwise.max.numerator = | ||
| 779 | frame->dwFrameInterval[1]; | ||
| 780 | fival->stepwise.max.denominator = 10000000; | ||
| 781 | fival->stepwise.step.numerator = | ||
| 782 | frame->dwFrameInterval[2]; | ||
| 783 | fival->stepwise.step.denominator = 10000000; | ||
| 784 | uvc_simplify_fraction(&fival->stepwise.min.numerator, | ||
| 785 | &fival->stepwise.min.denominator, 8, 333); | ||
| 786 | uvc_simplify_fraction(&fival->stepwise.max.numerator, | ||
| 787 | &fival->stepwise.max.denominator, 8, 333); | ||
| 788 | uvc_simplify_fraction(&fival->stepwise.step.numerator, | ||
| 789 | &fival->stepwise.step.denominator, 8, 333); | ||
| 790 | } | ||
| 791 | break; | ||
| 792 | } | ||
| 793 | |||
| 794 | /* Get & Set streaming parameters */ | ||
| 795 | case VIDIOC_G_PARM: | ||
| 796 | return uvc_v4l2_get_streamparm(video, arg); | ||
| 797 | |||
| 798 | case VIDIOC_S_PARM: | ||
| 799 | if ((ret = uvc_acquire_privileges(handle)) < 0) | ||
| 800 | return ret; | ||
| 801 | |||
| 802 | return uvc_v4l2_set_streamparm(video, arg); | ||
| 803 | |||
| 804 | /* Cropping and scaling */ | ||
| 805 | case VIDIOC_CROPCAP: | ||
| 806 | { | ||
| 807 | struct v4l2_cropcap *ccap = arg; | ||
| 808 | struct uvc_frame *frame = video->streaming->cur_frame; | ||
| 809 | |||
| 810 | if (ccap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 811 | return -EINVAL; | ||
| 812 | |||
| 813 | ccap->bounds.left = 0; | ||
| 814 | ccap->bounds.top = 0; | ||
| 815 | ccap->bounds.width = frame->wWidth; | ||
| 816 | ccap->bounds.height = frame->wHeight; | ||
| 817 | |||
| 818 | ccap->defrect = ccap->bounds; | ||
| 819 | |||
| 820 | ccap->pixelaspect.numerator = 1; | ||
| 821 | ccap->pixelaspect.denominator = 1; | ||
| 822 | break; | ||
| 823 | } | ||
| 824 | |||
| 825 | case VIDIOC_G_CROP: | ||
| 826 | case VIDIOC_S_CROP: | ||
| 827 | return -EINVAL; | ||
| 828 | |||
| 829 | /* Buffers & streaming */ | ||
| 830 | case VIDIOC_REQBUFS: | ||
| 831 | { | ||
| 832 | struct v4l2_requestbuffers *rb = arg; | ||
| 833 | unsigned int bufsize = | ||
| 834 | video->streaming->ctrl.dwMaxVideoFrameSize; | ||
| 835 | |||
| 836 | if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | ||
| 837 | rb->memory != V4L2_MEMORY_MMAP) | ||
| 838 | return -EINVAL; | ||
| 839 | |||
| 840 | if ((ret = uvc_acquire_privileges(handle)) < 0) | ||
| 841 | return ret; | ||
| 842 | |||
| 843 | ret = uvc_alloc_buffers(&video->queue, rb->count, bufsize); | ||
| 844 | if (ret < 0) | ||
| 845 | return ret; | ||
| 846 | |||
| 847 | if (!(video->streaming->cur_format->flags & | ||
| 848 | UVC_FMT_FLAG_COMPRESSED)) | ||
| 849 | video->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE; | ||
| 850 | |||
| 851 | rb->count = ret; | ||
| 852 | ret = 0; | ||
| 853 | break; | ||
| 854 | } | ||
| 855 | |||
| 856 | case VIDIOC_QUERYBUF: | ||
| 857 | { | ||
| 858 | struct v4l2_buffer *buf = arg; | ||
| 859 | |||
| 860 | if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 861 | return -EINVAL; | ||
| 862 | |||
| 863 | if (!uvc_has_privileges(handle)) | ||
| 864 | return -EBUSY; | ||
| 865 | |||
| 866 | return uvc_query_buffer(&video->queue, buf); | ||
| 867 | } | ||
| 868 | |||
| 869 | case VIDIOC_QBUF: | ||
| 870 | if (!uvc_has_privileges(handle)) | ||
| 871 | return -EBUSY; | ||
| 872 | |||
| 873 | return uvc_queue_buffer(&video->queue, arg); | ||
| 874 | |||
| 875 | case VIDIOC_DQBUF: | ||
| 876 | if (!uvc_has_privileges(handle)) | ||
| 877 | return -EBUSY; | ||
| 878 | |||
| 879 | return uvc_dequeue_buffer(&video->queue, arg, | ||
| 880 | file->f_flags & O_NONBLOCK); | ||
| 881 | |||
| 882 | case VIDIOC_STREAMON: | ||
| 883 | { | ||
| 884 | int *type = arg; | ||
| 885 | |||
| 886 | if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 887 | return -EINVAL; | ||
| 888 | |||
| 889 | if (!uvc_has_privileges(handle)) | ||
| 890 | return -EBUSY; | ||
| 891 | |||
| 892 | if ((ret = uvc_video_enable(video, 1)) < 0) | ||
| 893 | return ret; | ||
| 894 | break; | ||
| 895 | } | ||
| 896 | |||
| 897 | case VIDIOC_STREAMOFF: | ||
| 898 | { | ||
| 899 | int *type = arg; | ||
| 900 | |||
| 901 | if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | ||
| 902 | return -EINVAL; | ||
| 903 | |||
| 904 | if (!uvc_has_privileges(handle)) | ||
| 905 | return -EBUSY; | ||
| 906 | |||
| 907 | return uvc_video_enable(video, 0); | ||
| 908 | } | ||
| 909 | |||
| 910 | /* Analog video standards make no sense for digital cameras. */ | ||
| 911 | case VIDIOC_ENUMSTD: | ||
| 912 | case VIDIOC_QUERYSTD: | ||
| 913 | case VIDIOC_G_STD: | ||
| 914 | case VIDIOC_S_STD: | ||
| 915 | |||
| 916 | case VIDIOC_OVERLAY: | ||
| 917 | |||
| 918 | case VIDIOC_ENUMAUDIO: | ||
| 919 | case VIDIOC_ENUMAUDOUT: | ||
| 920 | |||
| 921 | case VIDIOC_ENUMOUTPUT: | ||
| 922 | uvc_trace(UVC_TRACE_IOCTL, "Unsupported ioctl 0x%08x\n", cmd); | ||
| 923 | return -EINVAL; | ||
| 924 | |||
| 925 | /* Dynamic controls. */ | ||
| 926 | case UVCIOC_CTRL_ADD: | ||
| 927 | { | ||
| 928 | struct uvc_xu_control_info *xinfo = arg; | ||
| 929 | struct uvc_control_info *info; | ||
| 930 | |||
| 931 | if (!capable(CAP_SYS_ADMIN)) | ||
| 932 | return -EPERM; | ||
| 933 | |||
| 934 | info = kmalloc(sizeof *info, GFP_KERNEL); | ||
| 935 | if (info == NULL) | ||
| 936 | return -ENOMEM; | ||
| 937 | |||
| 938 | memcpy(info->entity, xinfo->entity, sizeof info->entity); | ||
| 939 | info->index = xinfo->index; | ||
| 940 | info->selector = xinfo->selector; | ||
| 941 | info->size = xinfo->size; | ||
| 942 | info->flags = xinfo->flags; | ||
| 943 | |||
| 944 | info->flags |= UVC_CONTROL_GET_MIN | UVC_CONTROL_GET_MAX | | ||
| 945 | UVC_CONTROL_GET_RES | UVC_CONTROL_GET_DEF; | ||
| 946 | |||
| 947 | ret = uvc_ctrl_add_info(info); | ||
| 948 | if (ret < 0) | ||
| 949 | kfree(info); | ||
| 950 | break; | ||
| 951 | } | ||
| 952 | |||
| 953 | case UVCIOC_CTRL_MAP: | ||
| 954 | { | ||
| 955 | struct uvc_xu_control_mapping *xmap = arg; | ||
| 956 | struct uvc_control_mapping *map; | ||
| 957 | |||
| 958 | if (!capable(CAP_SYS_ADMIN)) | ||
| 959 | return -EPERM; | ||
| 960 | |||
| 961 | map = kmalloc(sizeof *map, GFP_KERNEL); | ||
| 962 | if (map == NULL) | ||
| 963 | return -ENOMEM; | ||
| 964 | |||
| 965 | map->id = xmap->id; | ||
| 966 | memcpy(map->name, xmap->name, sizeof map->name); | ||
| 967 | memcpy(map->entity, xmap->entity, sizeof map->entity); | ||
| 968 | map->selector = xmap->selector; | ||
| 969 | map->size = xmap->size; | ||
| 970 | map->offset = xmap->offset; | ||
| 971 | map->v4l2_type = xmap->v4l2_type; | ||
| 972 | map->data_type = xmap->data_type; | ||
| 973 | |||
| 974 | ret = uvc_ctrl_add_mapping(map); | ||
| 975 | if (ret < 0) | ||
| 976 | kfree(map); | ||
| 977 | break; | ||
| 978 | } | ||
| 979 | |||
| 980 | case UVCIOC_CTRL_GET: | ||
| 981 | return uvc_xu_ctrl_query(video, arg, 0); | ||
| 982 | |||
| 983 | case UVCIOC_CTRL_SET: | ||
| 984 | return uvc_xu_ctrl_query(video, arg, 1); | ||
| 985 | |||
| 986 | default: | ||
| 987 | if ((ret = v4l_compat_translate_ioctl(inode, file, cmd, arg, | ||
| 988 | uvc_v4l2_do_ioctl)) == -ENOIOCTLCMD) | ||
| 989 | uvc_trace(UVC_TRACE_IOCTL, "Unknown ioctl 0x%08x\n", | ||
| 990 | cmd); | ||
| 991 | return ret; | ||
| 992 | } | ||
| 993 | |||
| 994 | return ret; | ||
| 995 | } | ||
| 996 | |||
| 997 | static int uvc_v4l2_ioctl(struct inode *inode, struct file *file, | ||
| 998 | unsigned int cmd, unsigned long arg) | ||
| 999 | { | ||
| 1000 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_ioctl\n"); | ||
| 1001 | return video_usercopy(inode, file, cmd, arg, uvc_v4l2_do_ioctl); | ||
| 1002 | } | ||
| 1003 | |||
| 1004 | static ssize_t uvc_v4l2_read(struct file *file, char __user *data, | ||
| 1005 | size_t count, loff_t *ppos) | ||
| 1006 | { | ||
| 1007 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read: not implemented.\n"); | ||
| 1008 | return -ENODEV; | ||
| 1009 | } | ||
| 1010 | |||
| 1011 | /* | ||
| 1012 | * VMA operations. | ||
| 1013 | */ | ||
| 1014 | static void uvc_vm_open(struct vm_area_struct *vma) | ||
| 1015 | { | ||
| 1016 | struct uvc_buffer *buffer = vma->vm_private_data; | ||
| 1017 | buffer->vma_use_count++; | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | static void uvc_vm_close(struct vm_area_struct *vma) | ||
| 1021 | { | ||
| 1022 | struct uvc_buffer *buffer = vma->vm_private_data; | ||
| 1023 | buffer->vma_use_count--; | ||
| 1024 | } | ||
| 1025 | |||
| 1026 | static struct vm_operations_struct uvc_vm_ops = { | ||
| 1027 | .open = uvc_vm_open, | ||
| 1028 | .close = uvc_vm_close, | ||
| 1029 | }; | ||
| 1030 | |||
| 1031 | static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) | ||
| 1032 | { | ||
| 1033 | struct video_device *vdev = video_devdata(file); | ||
| 1034 | struct uvc_video_device *video = video_get_drvdata(vdev); | ||
| 1035 | struct uvc_buffer *buffer; | ||
| 1036 | struct page *page; | ||
| 1037 | unsigned long addr, start, size; | ||
| 1038 | unsigned int i; | ||
| 1039 | int ret = 0; | ||
| 1040 | |||
| 1041 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_mmap\n"); | ||
| 1042 | |||
| 1043 | start = vma->vm_start; | ||
| 1044 | size = vma->vm_end - vma->vm_start; | ||
| 1045 | |||
| 1046 | mutex_lock(&video->queue.mutex); | ||
| 1047 | |||
| 1048 | for (i = 0; i < video->queue.count; ++i) { | ||
| 1049 | buffer = &video->queue.buffer[i]; | ||
| 1050 | if ((buffer->buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff) | ||
| 1051 | break; | ||
| 1052 | } | ||
| 1053 | |||
| 1054 | if (i == video->queue.count || size != video->queue.buf_size) { | ||
| 1055 | ret = -EINVAL; | ||
| 1056 | goto done; | ||
| 1057 | } | ||
| 1058 | |||
| 1059 | /* | ||
| 1060 | * VM_IO marks the area as being an mmaped region for I/O to a | ||
| 1061 | * device. It also prevents the region from being core dumped. | ||
| 1062 | */ | ||
| 1063 | vma->vm_flags |= VM_IO; | ||
| 1064 | |||
| 1065 | addr = (unsigned long)video->queue.mem + buffer->buf.m.offset; | ||
| 1066 | while (size > 0) { | ||
| 1067 | page = vmalloc_to_page((void *)addr); | ||
| 1068 | if ((ret = vm_insert_page(vma, start, page)) < 0) | ||
| 1069 | goto done; | ||
| 1070 | |||
| 1071 | start += PAGE_SIZE; | ||
| 1072 | addr += PAGE_SIZE; | ||
| 1073 | size -= PAGE_SIZE; | ||
| 1074 | } | ||
| 1075 | |||
| 1076 | vma->vm_ops = &uvc_vm_ops; | ||
| 1077 | vma->vm_private_data = buffer; | ||
| 1078 | uvc_vm_open(vma); | ||
| 1079 | |||
| 1080 | done: | ||
| 1081 | mutex_unlock(&video->queue.mutex); | ||
| 1082 | return ret; | ||
| 1083 | } | ||
| 1084 | |||
| 1085 | static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait) | ||
| 1086 | { | ||
| 1087 | struct video_device *vdev = video_devdata(file); | ||
| 1088 | struct uvc_video_device *video = video_get_drvdata(vdev); | ||
| 1089 | |||
| 1090 | uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n"); | ||
| 1091 | |||
| 1092 | return uvc_queue_poll(&video->queue, file, wait); | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | struct file_operations uvc_fops = { | ||
| 1096 | .owner = THIS_MODULE, | ||
| 1097 | .open = uvc_v4l2_open, | ||
| 1098 | .release = uvc_v4l2_release, | ||
| 1099 | .ioctl = uvc_v4l2_ioctl, | ||
| 1100 | .compat_ioctl = v4l_compat_ioctl32, | ||
| 1101 | .llseek = no_llseek, | ||
| 1102 | .read = uvc_v4l2_read, | ||
| 1103 | .mmap = uvc_v4l2_mmap, | ||
| 1104 | .poll = uvc_v4l2_poll, | ||
| 1105 | }; | ||
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c new file mode 100644 index 000000000000..6faf1fb21614 --- /dev/null +++ b/drivers/media/video/uvc/uvc_video.c | |||
| @@ -0,0 +1,934 @@ | |||
| 1 | /* | ||
| 2 | * uvc_video.c -- USB Video Class driver - Video handling | ||
| 3 | * | ||
| 4 | * Copyright (C) 2005-2008 | ||
| 5 | * Laurent Pinchart (laurent.pinchart@skynet.be) | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/kernel.h> | ||
| 15 | #include <linux/version.h> | ||
| 16 | #include <linux/list.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/usb.h> | ||
| 19 | #include <linux/videodev2.h> | ||
| 20 | #include <linux/vmalloc.h> | ||
| 21 | #include <linux/wait.h> | ||
| 22 | #include <asm/atomic.h> | ||
| 23 | #include <asm/unaligned.h> | ||
| 24 | |||
| 25 | #include <media/v4l2-common.h> | ||
| 26 | |||
| 27 | #include "uvcvideo.h" | ||
| 28 | |||
| 29 | /* ------------------------------------------------------------------------ | ||
| 30 | * UVC Controls | ||
| 31 | */ | ||
| 32 | |||
| 33 | static int __uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, | ||
| 34 | __u8 intfnum, __u8 cs, void *data, __u16 size, | ||
| 35 | int timeout) | ||
| 36 | { | ||
| 37 | __u8 type = USB_TYPE_CLASS | USB_RECIP_INTERFACE; | ||
| 38 | unsigned int pipe; | ||
| 39 | int ret; | ||
| 40 | |||
| 41 | pipe = (query & 0x80) ? usb_rcvctrlpipe(dev->udev, 0) | ||
| 42 | : usb_sndctrlpipe(dev->udev, 0); | ||
| 43 | type |= (query & 0x80) ? USB_DIR_IN : USB_DIR_OUT; | ||
| 44 | |||
| 45 | ret = usb_control_msg(dev->udev, pipe, query, type, cs << 8, | ||
| 46 | unit << 8 | intfnum, data, size, timeout); | ||
| 47 | |||
| 48 | if (ret != size) { | ||
| 49 | uvc_printk(KERN_ERR, "Failed to query (%u) UVC control %u " | ||
| 50 | "(unit %u) : %d (exp. %u).\n", query, cs, unit, ret, | ||
| 51 | size); | ||
| 52 | return -EIO; | ||
| 53 | } | ||
| 54 | |||
| 55 | return 0; | ||
| 56 | } | ||
| 57 | |||
| 58 | int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, | ||
| 59 | __u8 intfnum, __u8 cs, void *data, __u16 size) | ||
| 60 | { | ||
| 61 | return __uvc_query_ctrl(dev, query, unit, intfnum, cs, data, size, | ||
| 62 | UVC_CTRL_CONTROL_TIMEOUT); | ||
| 63 | } | ||
| 64 | |||
| 65 | static void uvc_fixup_buffer_size(struct uvc_video_device *video, | ||
| 66 | struct uvc_streaming_control *ctrl) | ||
| 67 | { | ||
| 68 | struct uvc_format *format; | ||
| 69 | struct uvc_frame *frame; | ||
| 70 | |||
| 71 | if (ctrl->bFormatIndex <= 0 || | ||
| 72 | ctrl->bFormatIndex > video->streaming->nformats) | ||
| 73 | return; | ||
| 74 | |||
| 75 | format = &video->streaming->format[ctrl->bFormatIndex - 1]; | ||
| 76 | |||
| 77 | if (ctrl->bFrameIndex <= 0 || | ||
| 78 | ctrl->bFrameIndex > format->nframes) | ||
| 79 | return; | ||
| 80 | |||
| 81 | frame = &format->frame[ctrl->bFrameIndex - 1]; | ||
| 82 | |||
| 83 | if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) || | ||
| 84 | (ctrl->dwMaxVideoFrameSize == 0 && | ||
| 85 | video->dev->uvc_version < 0x0110)) | ||
| 86 | ctrl->dwMaxVideoFrameSize = | ||
| 87 | frame->dwMaxVideoFrameBufferSize; | ||
| 88 | } | ||
| 89 | |||
| 90 | static int uvc_get_video_ctrl(struct uvc_video_device *video, | ||
| 91 | struct uvc_streaming_control *ctrl, int probe, __u8 query) | ||
| 92 | { | ||
| 93 | __u8 data[34]; | ||
| 94 | __u8 size; | ||
| 95 | int ret; | ||
| 96 | |||
| 97 | size = video->dev->uvc_version >= 0x0110 ? 34 : 26; | ||
| 98 | ret = __uvc_query_ctrl(video->dev, query, 0, video->streaming->intfnum, | ||
| 99 | probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, &data, size, | ||
| 100 | UVC_CTRL_STREAMING_TIMEOUT); | ||
| 101 | |||
| 102 | if (ret < 0) | ||
| 103 | return ret; | ||
| 104 | |||
| 105 | ctrl->bmHint = le16_to_cpup((__le16 *)&data[0]); | ||
| 106 | ctrl->bFormatIndex = data[2]; | ||
| 107 | ctrl->bFrameIndex = data[3]; | ||
| 108 | ctrl->dwFrameInterval = le32_to_cpup((__le32 *)&data[4]); | ||
| 109 | ctrl->wKeyFrameRate = le16_to_cpup((__le16 *)&data[8]); | ||
| 110 | ctrl->wPFrameRate = le16_to_cpup((__le16 *)&data[10]); | ||
| 111 | ctrl->wCompQuality = le16_to_cpup((__le16 *)&data[12]); | ||
| 112 | ctrl->wCompWindowSize = le16_to_cpup((__le16 *)&data[14]); | ||
| 113 | ctrl->wDelay = le16_to_cpup((__le16 *)&data[16]); | ||
| 114 | ctrl->dwMaxVideoFrameSize = | ||
| 115 | le32_to_cpu(get_unaligned((__le32 *)&data[18])); | ||
| 116 | ctrl->dwMaxPayloadTransferSize = | ||
| 117 | le32_to_cpu(get_unaligned((__le32 *)&data[22])); | ||
| 118 | |||
| 119 | if (size == 34) { | ||
| 120 | ctrl->dwClockFrequency = | ||
| 121 | le32_to_cpu(get_unaligned((__le32 *)&data[26])); | ||
| 122 | ctrl->bmFramingInfo = data[30]; | ||
| 123 | ctrl->bPreferedVersion = data[31]; | ||
| 124 | ctrl->bMinVersion = data[32]; | ||
| 125 | ctrl->bMaxVersion = data[33]; | ||
| 126 | } else { | ||
| 127 | ctrl->dwClockFrequency = video->dev->clock_frequency; | ||
| 128 | ctrl->bmFramingInfo = 0; | ||
| 129 | ctrl->bPreferedVersion = 0; | ||
| 130 | ctrl->bMinVersion = 0; | ||
| 131 | ctrl->bMaxVersion = 0; | ||
| 132 | } | ||
| 133 | |||
| 134 | /* Some broken devices return a null or wrong dwMaxVideoFrameSize. | ||
| 135 | * Try to get the value from the format and frame descriptor. | ||
| 136 | */ | ||
| 137 | uvc_fixup_buffer_size(video, ctrl); | ||
| 138 | |||
| 139 | return 0; | ||
| 140 | } | ||
| 141 | |||
| 142 | int uvc_set_video_ctrl(struct uvc_video_device *video, | ||
| 143 | struct uvc_streaming_control *ctrl, int probe) | ||
| 144 | { | ||
| 145 | __u8 data[34]; | ||
| 146 | __u8 size; | ||
| 147 | |||
| 148 | size = video->dev->uvc_version >= 0x0110 ? 34 : 26; | ||
| 149 | memset(data, 0, sizeof data); | ||
| 150 | |||
| 151 | *(__le16 *)&data[0] = cpu_to_le16(ctrl->bmHint); | ||
| 152 | data[2] = ctrl->bFormatIndex; | ||
| 153 | data[3] = ctrl->bFrameIndex; | ||
| 154 | *(__le32 *)&data[4] = cpu_to_le32(ctrl->dwFrameInterval); | ||
| 155 | *(__le16 *)&data[8] = cpu_to_le16(ctrl->wKeyFrameRate); | ||
| 156 | *(__le16 *)&data[10] = cpu_to_le16(ctrl->wPFrameRate); | ||
| 157 | *(__le16 *)&data[12] = cpu_to_le16(ctrl->wCompQuality); | ||
| 158 | *(__le16 *)&data[14] = cpu_to_le16(ctrl->wCompWindowSize); | ||
| 159 | *(__le16 *)&data[16] = cpu_to_le16(ctrl->wDelay); | ||
| 160 | /* Note: Some of the fields below are not required for IN devices (see | ||
| 161 | * UVC spec, 4.3.1.1), but we still copy them in case support for OUT | ||
| 162 | * devices is added in the future. */ | ||
| 163 | put_unaligned(cpu_to_le32(ctrl->dwMaxVideoFrameSize), | ||
| 164 | (__le32 *)&data[18]); | ||
| 165 | put_unaligned(cpu_to_le32(ctrl->dwMaxPayloadTransferSize), | ||
| 166 | (__le32 *)&data[22]); | ||
| 167 | |||
| 168 | if (size == 34) { | ||
| 169 | put_unaligned(cpu_to_le32(ctrl->dwClockFrequency), | ||
| 170 | (__le32 *)&data[26]); | ||
| 171 | data[30] = ctrl->bmFramingInfo; | ||
| 172 | data[31] = ctrl->bPreferedVersion; | ||
| 173 | data[32] = ctrl->bMinVersion; | ||
| 174 | data[33] = ctrl->bMaxVersion; | ||
| 175 | } | ||
| 176 | |||
| 177 | return __uvc_query_ctrl(video->dev, SET_CUR, 0, | ||
| 178 | video->streaming->intfnum, | ||
| 179 | probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, &data, size, | ||
| 180 | UVC_CTRL_STREAMING_TIMEOUT); | ||
| 181 | } | ||
| 182 | |||
| 183 | int uvc_probe_video(struct uvc_video_device *video, | ||
| 184 | struct uvc_streaming_control *probe) | ||
| 185 | { | ||
| 186 | struct uvc_streaming_control probe_min, probe_max; | ||
| 187 | __u16 bandwidth; | ||
| 188 | unsigned int i; | ||
| 189 | int ret; | ||
| 190 | |||
| 191 | mutex_lock(&video->streaming->mutex); | ||
| 192 | |||
| 193 | /* Perform probing. The device should adjust the requested values | ||
| 194 | * according to its capabilities. However, some devices, namely the | ||
| 195 | * first generation UVC Logitech webcams, don't implement the Video | ||
| 196 | * Probe control properly, and just return the needed bandwidth. For | ||
| 197 | * that reason, if the needed bandwidth exceeds the maximum available | ||
| 198 | * bandwidth, try to lower the quality. | ||
| 199 | */ | ||
| 200 | if ((ret = uvc_set_video_ctrl(video, probe, 1)) < 0) | ||
| 201 | goto done; | ||
| 202 | |||
| 203 | /* Get the minimum and maximum values for compression settings. */ | ||
| 204 | if (!(video->dev->quirks & UVC_QUIRK_PROBE_MINMAX)) { | ||
| 205 | ret = uvc_get_video_ctrl(video, &probe_min, 1, GET_MIN); | ||
| 206 | if (ret < 0) | ||
| 207 | goto done; | ||
| 208 | ret = uvc_get_video_ctrl(video, &probe_max, 1, GET_MAX); | ||
| 209 | if (ret < 0) | ||
| 210 | goto done; | ||
| 211 | |||
| 212 | probe->wCompQuality = probe_max.wCompQuality; | ||
| 213 | } | ||
| 214 | |||
| 215 | for (i = 0; i < 2; ++i) { | ||
| 216 | if ((ret = uvc_set_video_ctrl(video, probe, 1)) < 0 || | ||
| 217 | (ret = uvc_get_video_ctrl(video, probe, 1, GET_CUR)) < 0) | ||
| 218 | goto done; | ||
| 219 | |||
| 220 | if (video->streaming->intf->num_altsetting == 1) | ||
| 221 | break; | ||
| 222 | |||
| 223 | bandwidth = probe->dwMaxPayloadTransferSize; | ||
| 224 | if (bandwidth <= video->streaming->maxpsize) | ||
| 225 | break; | ||
| 226 | |||
| 227 | if (video->dev->quirks & UVC_QUIRK_PROBE_MINMAX) { | ||
| 228 | ret = -ENOSPC; | ||
| 229 | goto done; | ||
| 230 | } | ||
| 231 | |||
| 232 | /* TODO: negotiate compression parameters */ | ||
| 233 | probe->wKeyFrameRate = probe_min.wKeyFrameRate; | ||
| 234 | probe->wPFrameRate = probe_min.wPFrameRate; | ||
| 235 | probe->wCompQuality = probe_max.wCompQuality; | ||
| 236 | probe->wCompWindowSize = probe_min.wCompWindowSize; | ||
| 237 | } | ||
| 238 | |||
| 239 | done: | ||
| 240 | mutex_unlock(&video->streaming->mutex); | ||
| 241 | return ret; | ||
| 242 | } | ||
| 243 | |||
| 244 | /* ------------------------------------------------------------------------ | ||
| 245 | * Video codecs | ||
| 246 | */ | ||
| 247 | |||
| 248 | /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */ | ||
| 249 | #define UVC_STREAM_EOH (1 << 7) | ||
| 250 | #define UVC_STREAM_ERR (1 << 6) | ||
| 251 | #define UVC_STREAM_STI (1 << 5) | ||
| 252 | #define UVC_STREAM_RES (1 << 4) | ||
| 253 | #define UVC_STREAM_SCR (1 << 3) | ||
| 254 | #define UVC_STREAM_PTS (1 << 2) | ||
| 255 | #define UVC_STREAM_EOF (1 << 1) | ||
| 256 | #define UVC_STREAM_FID (1 << 0) | ||
| 257 | |||
| 258 | /* Video payload decoding is handled by uvc_video_decode_start(), | ||
| 259 | * uvc_video_decode_data() and uvc_video_decode_end(). | ||
| 260 | * | ||
| 261 | * uvc_video_decode_start is called with URB data at the start of a bulk or | ||
| 262 | * isochronous payload. It processes header data and returns the header size | ||
| 263 | * in bytes if successful. If an error occurs, it returns a negative error | ||
| 264 | * code. The following error codes have special meanings. | ||
| 265 | * | ||
| 266 | * - EAGAIN informs the caller that the current video buffer should be marked | ||
| 267 | * as done, and that the function should be called again with the same data | ||
| 268 | * and a new video buffer. This is used when end of frame conditions can be | ||
| 269 | * reliably detected at the beginning of the next frame only. | ||
| 270 | * | ||
| 271 | * If an error other than -EAGAIN is returned, the caller will drop the current | ||
| 272 | * payload. No call to uvc_video_decode_data and uvc_video_decode_end will be | ||
| 273 | * made until the next payload. -ENODATA can be used to drop the current | ||
| 274 | * payload if no other error code is appropriate. | ||
| 275 | * | ||
| 276 | * uvc_video_decode_data is called for every URB with URB data. It copies the | ||
| 277 | * data to the video buffer. | ||
| 278 | * | ||
| 279 | * uvc_video_decode_end is called with header data at the end of a bulk or | ||
| 280 | * isochronous payload. It performs any additional header data processing and | ||
| 281 | * returns 0 or a negative error code if an error occured. As header data have | ||
| 282 | * already been processed by uvc_video_decode_start, this functions isn't | ||
| 283 | * required to perform sanity checks a second time. | ||
| 284 | * | ||
| 285 | * For isochronous transfers where a payload is always transfered in a single | ||
| 286 | * URB, the three functions will be called in a row. | ||
| 287 | * | ||
| 288 | * To let the decoder process header data and update its internal state even | ||
| 289 | * when no video buffer is available, uvc_video_decode_start must be prepared | ||
| 290 | * to be called with a NULL buf parameter. uvc_video_decode_data and | ||
| 291 | * uvc_video_decode_end will never be called with a NULL buffer. | ||
| 292 | */ | ||
| 293 | static int uvc_video_decode_start(struct uvc_video_device *video, | ||
| 294 | struct uvc_buffer *buf, const __u8 *data, int len) | ||
| 295 | { | ||
| 296 | __u8 fid; | ||
| 297 | |||
| 298 | /* Sanity checks: | ||
| 299 | * - packet must be at least 2 bytes long | ||
| 300 | * - bHeaderLength value must be at least 2 bytes (see above) | ||
| 301 | * - bHeaderLength value can't be larger than the packet size. | ||
| 302 | */ | ||
| 303 | if (len < 2 || data[0] < 2 || data[0] > len) | ||
| 304 | return -EINVAL; | ||
| 305 | |||
| 306 | /* Skip payloads marked with the error bit ("error frames"). */ | ||
| 307 | if (data[1] & UVC_STREAM_ERR) { | ||
| 308 | uvc_trace(UVC_TRACE_FRAME, "Dropping payload (error bit " | ||
| 309 | "set).\n"); | ||
| 310 | return -ENODATA; | ||
| 311 | } | ||
| 312 | |||
| 313 | fid = data[1] & UVC_STREAM_FID; | ||
| 314 | |||
| 315 | /* Store the payload FID bit and return immediately when the buffer is | ||
| 316 | * NULL. | ||
| 317 | */ | ||
| 318 | if (buf == NULL) { | ||
| 319 | video->last_fid = fid; | ||
| 320 | return -ENODATA; | ||
| 321 | } | ||
| 322 | |||
| 323 | /* Synchronize to the input stream by waiting for the FID bit to be | ||
| 324 | * toggled when the the buffer state is not UVC_BUF_STATE_ACTIVE. | ||
| 325 | * queue->last_fid is initialized to -1, so the first isochronous | ||
| 326 | * frame will always be in sync. | ||
| 327 | * | ||
| 328 | * If the device doesn't toggle the FID bit, invert video->last_fid | ||
| 329 | * when the EOF bit is set to force synchronisation on the next packet. | ||
| 330 | */ | ||
| 331 | if (buf->state != UVC_BUF_STATE_ACTIVE) { | ||
| 332 | if (fid == video->last_fid) { | ||
| 333 | uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of " | ||
| 334 | "sync).\n"); | ||
| 335 | if ((video->dev->quirks & UVC_QUIRK_STREAM_NO_FID) && | ||
| 336 | (data[1] & UVC_STREAM_EOF)) | ||
| 337 | video->last_fid ^= UVC_STREAM_FID; | ||
| 338 | return -ENODATA; | ||
| 339 | } | ||
| 340 | |||
| 341 | /* TODO: Handle PTS and SCR. */ | ||
| 342 | buf->state = UVC_BUF_STATE_ACTIVE; | ||
| 343 | } | ||
| 344 | |||
| 345 | /* Mark the buffer as done if we're at the beginning of a new frame. | ||
| 346 | * End of frame detection is better implemented by checking the EOF | ||
| 347 | * bit (FID bit toggling is delayed by one frame compared to the EOF | ||
| 348 | * bit), but some devices don't set the bit at end of frame (and the | ||
| 349 | * last payload can be lost anyway). We thus must check if the FID has | ||
| 350 | * been toggled. | ||
| 351 | * | ||
| 352 | * queue->last_fid is initialized to -1, so the first isochronous | ||
| 353 | * frame will never trigger an end of frame detection. | ||
| 354 | * | ||
| 355 | * Empty buffers (bytesused == 0) don't trigger end of frame detection | ||
| 356 | * as it doesn't make sense to return an empty buffer. This also | ||
| 357 | * avoids detecting and of frame conditions at FID toggling if the | ||
| 358 | * previous payload had the EOF bit set. | ||
| 359 | */ | ||
| 360 | if (fid != video->last_fid && buf->buf.bytesused != 0) { | ||
| 361 | uvc_trace(UVC_TRACE_FRAME, "Frame complete (FID bit " | ||
| 362 | "toggled).\n"); | ||
| 363 | buf->state = UVC_BUF_STATE_DONE; | ||
| 364 | return -EAGAIN; | ||
| 365 | } | ||
| 366 | |||
| 367 | video->last_fid = fid; | ||
| 368 | |||
| 369 | return data[0]; | ||
| 370 | } | ||
| 371 | |||
| 372 | static void uvc_video_decode_data(struct uvc_video_device *video, | ||
| 373 | struct uvc_buffer *buf, const __u8 *data, int len) | ||
| 374 | { | ||
| 375 | struct uvc_video_queue *queue = &video->queue; | ||
| 376 | unsigned int maxlen, nbytes; | ||
| 377 | void *mem; | ||
| 378 | |||
| 379 | if (len <= 0) | ||
| 380 | return; | ||
| 381 | |||
| 382 | /* Copy the video data to the buffer. */ | ||
| 383 | maxlen = buf->buf.length - buf->buf.bytesused; | ||
| 384 | mem = queue->mem + buf->buf.m.offset + buf->buf.bytesused; | ||
| 385 | nbytes = min((unsigned int)len, maxlen); | ||
| 386 | memcpy(mem, data, nbytes); | ||
| 387 | buf->buf.bytesused += nbytes; | ||
| 388 | |||
| 389 | /* Complete the current frame if the buffer size was exceeded. */ | ||
| 390 | if (len > maxlen) { | ||
| 391 | uvc_trace(UVC_TRACE_FRAME, "Frame complete (overflow).\n"); | ||
| 392 | buf->state = UVC_BUF_STATE_DONE; | ||
| 393 | } | ||
| 394 | } | ||
| 395 | |||
| 396 | static void uvc_video_decode_end(struct uvc_video_device *video, | ||
| 397 | struct uvc_buffer *buf, const __u8 *data, int len) | ||
| 398 | { | ||
| 399 | /* Mark the buffer as done if the EOF marker is set. */ | ||
| 400 | if (data[1] & UVC_STREAM_EOF && buf->buf.bytesused != 0) { | ||
| 401 | uvc_trace(UVC_TRACE_FRAME, "Frame complete (EOF found).\n"); | ||
| 402 | if (data[0] == len) | ||
| 403 | uvc_trace(UVC_TRACE_FRAME, "EOF in empty payload.\n"); | ||
| 404 | buf->state = UVC_BUF_STATE_DONE; | ||
| 405 | if (video->dev->quirks & UVC_QUIRK_STREAM_NO_FID) | ||
| 406 | video->last_fid ^= UVC_STREAM_FID; | ||
| 407 | } | ||
| 408 | } | ||
| 409 | |||
| 410 | /* ------------------------------------------------------------------------ | ||
| 411 | * URB handling | ||
| 412 | */ | ||
| 413 | |||
| 414 | /* | ||
| 415 | * Completion handler for video URBs. | ||
| 416 | */ | ||
| 417 | static void uvc_video_decode_isoc(struct urb *urb, | ||
| 418 | struct uvc_video_device *video, struct uvc_buffer *buf) | ||
| 419 | { | ||
| 420 | u8 *mem; | ||
| 421 | int ret, i; | ||
| 422 | |||
| 423 | for (i = 0; i < urb->number_of_packets; ++i) { | ||
| 424 | if (urb->iso_frame_desc[i].status < 0) { | ||
| 425 | uvc_trace(UVC_TRACE_FRAME, "USB isochronous frame " | ||
| 426 | "lost (%d).\n", urb->iso_frame_desc[i].status); | ||
| 427 | continue; | ||
| 428 | } | ||
| 429 | |||
| 430 | /* Decode the payload header. */ | ||
| 431 | mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset; | ||
| 432 | do { | ||
| 433 | ret = uvc_video_decode_start(video, buf, mem, | ||
| 434 | urb->iso_frame_desc[i].actual_length); | ||
| 435 | if (ret == -EAGAIN) | ||
| 436 | buf = uvc_queue_next_buffer(&video->queue, buf); | ||
| 437 | } while (ret == -EAGAIN); | ||
| 438 | |||
| 439 | if (ret < 0) | ||
| 440 | continue; | ||
| 441 | |||
| 442 | /* Decode the payload data. */ | ||
| 443 | uvc_video_decode_data(video, buf, mem + ret, | ||
| 444 | urb->iso_frame_desc[i].actual_length - ret); | ||
| 445 | |||
| 446 | /* Process the header again. */ | ||
| 447 | uvc_video_decode_end(video, buf, mem, ret); | ||
| 448 | |||
| 449 | if (buf->state == UVC_BUF_STATE_DONE || | ||
| 450 | buf->state == UVC_BUF_STATE_ERROR) | ||
| 451 | buf = uvc_queue_next_buffer(&video->queue, buf); | ||
| 452 | } | ||
| 453 | } | ||
| 454 | |||
| 455 | static void uvc_video_decode_bulk(struct urb *urb, | ||
| 456 | struct uvc_video_device *video, struct uvc_buffer *buf) | ||
| 457 | { | ||
| 458 | u8 *mem; | ||
| 459 | int len, ret; | ||
| 460 | |||
| 461 | mem = urb->transfer_buffer; | ||
| 462 | len = urb->actual_length; | ||
| 463 | video->bulk.payload_size += len; | ||
| 464 | |||
| 465 | /* If the URB is the first of its payload, decode and save the | ||
| 466 | * header. | ||
| 467 | */ | ||
| 468 | if (video->bulk.header_size == 0) { | ||
| 469 | do { | ||
| 470 | ret = uvc_video_decode_start(video, buf, mem, len); | ||
| 471 | if (ret == -EAGAIN) | ||
| 472 | buf = uvc_queue_next_buffer(&video->queue, buf); | ||
| 473 | } while (ret == -EAGAIN); | ||
| 474 | |||
| 475 | /* If an error occured skip the rest of the payload. */ | ||
| 476 | if (ret < 0 || buf == NULL) { | ||
| 477 | video->bulk.skip_payload = 1; | ||
| 478 | return; | ||
| 479 | } | ||
| 480 | |||
| 481 | video->bulk.header_size = ret; | ||
| 482 | memcpy(video->bulk.header, mem, video->bulk.header_size); | ||
| 483 | |||
| 484 | mem += ret; | ||
| 485 | len -= ret; | ||
| 486 | } | ||
| 487 | |||
| 488 | /* The buffer queue might have been cancelled while a bulk transfer | ||
| 489 | * was in progress, so we can reach here with buf equal to NULL. Make | ||
| 490 | * sure buf is never dereferenced if NULL. | ||
| 491 | */ | ||
| 492 | |||
| 493 | /* Process video data. */ | ||
| 494 | if (!video->bulk.skip_payload && buf != NULL) | ||
| 495 | uvc_video_decode_data(video, buf, mem, len); | ||
| 496 | |||
| 497 | /* Detect the payload end by a URB smaller than the maximum size (or | ||
| 498 | * a payload size equal to the maximum) and process the header again. | ||
| 499 | */ | ||
| 500 | if (urb->actual_length < urb->transfer_buffer_length || | ||
| 501 | video->bulk.payload_size >= video->bulk.max_payload_size) { | ||
| 502 | if (!video->bulk.skip_payload && buf != NULL) { | ||
| 503 | uvc_video_decode_end(video, buf, video->bulk.header, | ||
| 504 | video->bulk.header_size); | ||
| 505 | if (buf->state == UVC_BUF_STATE_DONE || | ||
| 506 | buf->state == UVC_BUF_STATE_ERROR) | ||
| 507 | buf = uvc_queue_next_buffer(&video->queue, buf); | ||
| 508 | } | ||
| 509 | |||
| 510 | video->bulk.header_size = 0; | ||
| 511 | video->bulk.skip_payload = 0; | ||
| 512 | video->bulk.payload_size = 0; | ||
| 513 | } | ||
| 514 | } | ||
| 515 | |||
| 516 | static void uvc_video_complete(struct urb *urb) | ||
| 517 | { | ||
| 518 | struct uvc_video_device *video = urb->context; | ||
| 519 | struct uvc_video_queue *queue = &video->queue; | ||
| 520 | struct uvc_buffer *buf = NULL; | ||
| 521 | unsigned long flags; | ||
| 522 | int ret; | ||
| 523 | |||
| 524 | switch (urb->status) { | ||
| 525 | case 0: | ||
| 526 | break; | ||
| 527 | |||
| 528 | default: | ||
| 529 | uvc_printk(KERN_WARNING, "Non-zero status (%d) in video " | ||
| 530 | "completion handler.\n", urb->status); | ||
| 531 | |||
| 532 | case -ENOENT: /* usb_kill_urb() called. */ | ||
| 533 | if (video->frozen) | ||
| 534 | return; | ||
| 535 | |||
| 536 | case -ECONNRESET: /* usb_unlink_urb() called. */ | ||
| 537 | case -ESHUTDOWN: /* The endpoint is being disabled. */ | ||
| 538 | uvc_queue_cancel(queue, urb->status == -ESHUTDOWN); | ||
| 539 | return; | ||
| 540 | } | ||
| 541 | |||
| 542 | spin_lock_irqsave(&queue->irqlock, flags); | ||
| 543 | if (!list_empty(&queue->irqqueue)) | ||
| 544 | buf = list_first_entry(&queue->irqqueue, struct uvc_buffer, | ||
| 545 | queue); | ||
| 546 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
| 547 | |||
| 548 | video->decode(urb, video, buf); | ||
| 549 | |||
| 550 | if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
| 551 | uvc_printk(KERN_ERR, "Failed to resubmit video URB (%d).\n", | ||
| 552 | ret); | ||
| 553 | } | ||
| 554 | } | ||
| 555 | |||
| 556 | /* | ||
| 557 | * Uninitialize isochronous/bulk URBs and free transfer buffers. | ||
| 558 | */ | ||
| 559 | static void uvc_uninit_video(struct uvc_video_device *video) | ||
| 560 | { | ||
| 561 | struct urb *urb; | ||
| 562 | unsigned int i; | ||
| 563 | |||
| 564 | for (i = 0; i < UVC_URBS; ++i) { | ||
| 565 | if ((urb = video->urb[i]) == NULL) | ||
| 566 | continue; | ||
| 567 | |||
| 568 | usb_kill_urb(urb); | ||
| 569 | /* urb->transfer_buffer_length is not touched by USB core, so | ||
| 570 | * we can use it here as the buffer length. | ||
| 571 | */ | ||
| 572 | if (video->urb_buffer[i]) { | ||
| 573 | usb_buffer_free(video->dev->udev, | ||
| 574 | urb->transfer_buffer_length, | ||
| 575 | video->urb_buffer[i], urb->transfer_dma); | ||
| 576 | video->urb_buffer[i] = NULL; | ||
| 577 | } | ||
| 578 | |||
| 579 | usb_free_urb(urb); | ||
| 580 | video->urb[i] = NULL; | ||
| 581 | } | ||
| 582 | } | ||
| 583 | |||
| 584 | /* | ||
| 585 | * Initialize isochronous URBs and allocate transfer buffers. The packet size | ||
| 586 | * is given by the endpoint. | ||
| 587 | */ | ||
| 588 | static int uvc_init_video_isoc(struct uvc_video_device *video, | ||
| 589 | struct usb_host_endpoint *ep) | ||
| 590 | { | ||
| 591 | struct urb *urb; | ||
| 592 | unsigned int npackets, i, j; | ||
| 593 | __u16 psize; | ||
| 594 | __u32 size; | ||
| 595 | |||
| 596 | /* Compute the number of isochronous packets to allocate by dividing | ||
| 597 | * the maximum video frame size by the packet size. Limit the result | ||
| 598 | * to UVC_MAX_ISO_PACKETS. | ||
| 599 | */ | ||
| 600 | psize = le16_to_cpu(ep->desc.wMaxPacketSize); | ||
| 601 | psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); | ||
| 602 | |||
| 603 | size = video->streaming->ctrl.dwMaxVideoFrameSize; | ||
| 604 | if (size > UVC_MAX_FRAME_SIZE) | ||
| 605 | return -EINVAL; | ||
| 606 | |||
| 607 | npackets = (size + psize - 1) / psize; | ||
| 608 | if (npackets > UVC_MAX_ISO_PACKETS) | ||
| 609 | npackets = UVC_MAX_ISO_PACKETS; | ||
| 610 | |||
| 611 | size = npackets * psize; | ||
| 612 | |||
| 613 | for (i = 0; i < UVC_URBS; ++i) { | ||
| 614 | urb = usb_alloc_urb(npackets, GFP_KERNEL); | ||
| 615 | if (urb == NULL) { | ||
| 616 | uvc_uninit_video(video); | ||
| 617 | return -ENOMEM; | ||
| 618 | } | ||
| 619 | |||
| 620 | video->urb_buffer[i] = usb_buffer_alloc(video->dev->udev, | ||
| 621 | size, GFP_KERNEL, &urb->transfer_dma); | ||
| 622 | if (video->urb_buffer[i] == NULL) { | ||
| 623 | usb_free_urb(urb); | ||
| 624 | uvc_uninit_video(video); | ||
| 625 | return -ENOMEM; | ||
| 626 | } | ||
| 627 | |||
| 628 | urb->dev = video->dev->udev; | ||
| 629 | urb->context = video; | ||
| 630 | urb->pipe = usb_rcvisocpipe(video->dev->udev, | ||
| 631 | ep->desc.bEndpointAddress); | ||
| 632 | urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; | ||
| 633 | urb->interval = ep->desc.bInterval; | ||
| 634 | urb->transfer_buffer = video->urb_buffer[i]; | ||
| 635 | urb->complete = uvc_video_complete; | ||
| 636 | urb->number_of_packets = npackets; | ||
| 637 | urb->transfer_buffer_length = size; | ||
| 638 | |||
| 639 | for (j = 0; j < npackets; ++j) { | ||
| 640 | urb->iso_frame_desc[j].offset = j * psize; | ||
| 641 | urb->iso_frame_desc[j].length = psize; | ||
| 642 | } | ||
| 643 | |||
| 644 | video->urb[i] = urb; | ||
| 645 | } | ||
| 646 | |||
| 647 | return 0; | ||
| 648 | } | ||
| 649 | |||
| 650 | /* | ||
| 651 | * Initialize bulk URBs and allocate transfer buffers. The packet size is | ||
| 652 | * given by the endpoint. | ||
| 653 | */ | ||
| 654 | static int uvc_init_video_bulk(struct uvc_video_device *video, | ||
| 655 | struct usb_host_endpoint *ep) | ||
| 656 | { | ||
| 657 | struct urb *urb; | ||
| 658 | unsigned int pipe, i; | ||
| 659 | __u16 psize; | ||
| 660 | __u32 size; | ||
| 661 | |||
| 662 | /* Compute the bulk URB size. Some devices set the maximum payload | ||
| 663 | * size to a value too high for memory-constrained devices. We must | ||
| 664 | * then transfer the payload accross multiple URBs. To be consistant | ||
| 665 | * with isochronous mode, allocate maximum UVC_MAX_ISO_PACKETS per bulk | ||
| 666 | * URB. | ||
| 667 | */ | ||
| 668 | psize = le16_to_cpu(ep->desc.wMaxPacketSize) & 0x07ff; | ||
| 669 | size = video->streaming->ctrl.dwMaxPayloadTransferSize; | ||
| 670 | video->bulk.max_payload_size = size; | ||
| 671 | if (size > psize * UVC_MAX_ISO_PACKETS) | ||
| 672 | size = psize * UVC_MAX_ISO_PACKETS; | ||
| 673 | |||
| 674 | pipe = usb_rcvbulkpipe(video->dev->udev, ep->desc.bEndpointAddress); | ||
| 675 | |||
| 676 | for (i = 0; i < UVC_URBS; ++i) { | ||
| 677 | urb = usb_alloc_urb(0, GFP_KERNEL); | ||
| 678 | if (urb == NULL) { | ||
| 679 | uvc_uninit_video(video); | ||
| 680 | return -ENOMEM; | ||
| 681 | } | ||
| 682 | |||
| 683 | video->urb_buffer[i] = usb_buffer_alloc(video->dev->udev, | ||
| 684 | size, GFP_KERNEL, &urb->transfer_dma); | ||
| 685 | if (video->urb_buffer[i] == NULL) { | ||
| 686 | usb_free_urb(urb); | ||
| 687 | uvc_uninit_video(video); | ||
| 688 | return -ENOMEM; | ||
| 689 | } | ||
| 690 | |||
| 691 | usb_fill_bulk_urb(urb, video->dev->udev, pipe, | ||
| 692 | video->urb_buffer[i], size, uvc_video_complete, | ||
| 693 | video); | ||
| 694 | urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; | ||
| 695 | |||
| 696 | video->urb[i] = urb; | ||
| 697 | } | ||
| 698 | |||
| 699 | return 0; | ||
| 700 | } | ||
| 701 | |||
| 702 | /* | ||
| 703 | * Initialize isochronous/bulk URBs and allocate transfer buffers. | ||
| 704 | */ | ||
| 705 | static int uvc_init_video(struct uvc_video_device *video) | ||
| 706 | { | ||
| 707 | struct usb_interface *intf = video->streaming->intf; | ||
| 708 | struct usb_host_interface *alts; | ||
| 709 | struct usb_host_endpoint *ep = NULL; | ||
| 710 | int intfnum = video->streaming->intfnum; | ||
| 711 | unsigned int bandwidth, psize, i; | ||
| 712 | int ret; | ||
| 713 | |||
| 714 | video->last_fid = -1; | ||
| 715 | video->bulk.header_size = 0; | ||
| 716 | video->bulk.skip_payload = 0; | ||
| 717 | video->bulk.payload_size = 0; | ||
| 718 | |||
| 719 | if (intf->num_altsetting > 1) { | ||
| 720 | /* Isochronous endpoint, select the alternate setting. */ | ||
| 721 | bandwidth = video->streaming->ctrl.dwMaxPayloadTransferSize; | ||
| 722 | |||
| 723 | if (bandwidth == 0) { | ||
| 724 | uvc_printk(KERN_WARNING, "device %s requested null " | ||
| 725 | "bandwidth, defaulting to lowest.\n", | ||
| 726 | video->vdev->name); | ||
| 727 | bandwidth = 1; | ||
| 728 | } | ||
| 729 | |||
| 730 | for (i = 0; i < intf->num_altsetting; ++i) { | ||
| 731 | alts = &intf->altsetting[i]; | ||
| 732 | ep = uvc_find_endpoint(alts, | ||
| 733 | video->streaming->header.bEndpointAddress); | ||
| 734 | if (ep == NULL) | ||
| 735 | continue; | ||
| 736 | |||
| 737 | /* Check if the bandwidth is high enough. */ | ||
| 738 | psize = le16_to_cpu(ep->desc.wMaxPacketSize); | ||
| 739 | psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); | ||
| 740 | if (psize >= bandwidth) | ||
| 741 | break; | ||
| 742 | } | ||
| 743 | |||
| 744 | if (i >= intf->num_altsetting) | ||
| 745 | return -EIO; | ||
| 746 | |||
| 747 | if ((ret = usb_set_interface(video->dev->udev, intfnum, i)) < 0) | ||
| 748 | return ret; | ||
| 749 | |||
| 750 | ret = uvc_init_video_isoc(video, ep); | ||
| 751 | } else { | ||
| 752 | /* Bulk endpoint, proceed to URB initialization. */ | ||
| 753 | ep = uvc_find_endpoint(&intf->altsetting[0], | ||
| 754 | video->streaming->header.bEndpointAddress); | ||
| 755 | if (ep == NULL) | ||
| 756 | return -EIO; | ||
| 757 | |||
| 758 | ret = uvc_init_video_bulk(video, ep); | ||
| 759 | } | ||
| 760 | |||
| 761 | if (ret < 0) | ||
| 762 | return ret; | ||
| 763 | |||
| 764 | /* Submit the URBs. */ | ||
| 765 | for (i = 0; i < UVC_URBS; ++i) { | ||
| 766 | if ((ret = usb_submit_urb(video->urb[i], GFP_KERNEL)) < 0) { | ||
| 767 | uvc_printk(KERN_ERR, "Failed to submit URB %u " | ||
| 768 | "(%d).\n", i, ret); | ||
| 769 | uvc_uninit_video(video); | ||
| 770 | return ret; | ||
| 771 | } | ||
| 772 | } | ||
| 773 | |||
| 774 | return 0; | ||
| 775 | } | ||
| 776 | |||
| 777 | /* -------------------------------------------------------------------------- | ||
| 778 | * Suspend/resume | ||
| 779 | */ | ||
| 780 | |||
| 781 | /* | ||
| 782 | * Stop streaming without disabling the video queue. | ||
| 783 | * | ||
| 784 | * To let userspace applications resume without trouble, we must not touch the | ||
| 785 | * video buffers in any way. We mark the device as frozen to make sure the URB | ||
| 786 | * completion handler won't try to cancel the queue when we kill the URBs. | ||
| 787 | */ | ||
| 788 | int uvc_video_suspend(struct uvc_video_device *video) | ||
| 789 | { | ||
| 790 | if (!uvc_queue_streaming(&video->queue)) | ||
| 791 | return 0; | ||
| 792 | |||
| 793 | video->frozen = 1; | ||
| 794 | uvc_uninit_video(video); | ||
| 795 | usb_set_interface(video->dev->udev, video->streaming->intfnum, 0); | ||
| 796 | return 0; | ||
| 797 | } | ||
| 798 | |||
| 799 | /* | ||
| 800 | * Reconfigure the video interface and restart streaming if it was enable | ||
| 801 | * before suspend. | ||
| 802 | * | ||
| 803 | * If an error occurs, disable the video queue. This will wake all pending | ||
| 804 | * buffers, making sure userspace applications are notified of the problem | ||
| 805 | * instead of waiting forever. | ||
| 806 | */ | ||
| 807 | int uvc_video_resume(struct uvc_video_device *video) | ||
| 808 | { | ||
| 809 | int ret; | ||
| 810 | |||
| 811 | video->frozen = 0; | ||
| 812 | |||
| 813 | if ((ret = uvc_set_video_ctrl(video, &video->streaming->ctrl, 0)) < 0) { | ||
| 814 | uvc_queue_enable(&video->queue, 0); | ||
| 815 | return ret; | ||
| 816 | } | ||
| 817 | |||
| 818 | if (!uvc_queue_streaming(&video->queue)) | ||
| 819 | return 0; | ||
| 820 | |||
| 821 | if ((ret = uvc_init_video(video)) < 0) | ||
| 822 | uvc_queue_enable(&video->queue, 0); | ||
| 823 | |||
| 824 | return ret; | ||
| 825 | } | ||
| 826 | |||
| 827 | /* ------------------------------------------------------------------------ | ||
| 828 | * Video device | ||
| 829 | */ | ||
| 830 | |||
| 831 | /* | ||
| 832 | * Initialize the UVC video device by retrieving the default format and | ||
| 833 | * committing it. | ||
| 834 | * | ||
| 835 | * Some cameras (namely the Fuji Finepix) set the format and frame | ||
| 836 | * indexes to zero. The UVC standard doesn't clearly make this a spec | ||
| 837 | * violation, so try to silently fix the values if possible. | ||
| 838 | * | ||
| 839 | * This function is called before registering the device with V4L. | ||
| 840 | */ | ||
| 841 | int uvc_video_init(struct uvc_video_device *video) | ||
| 842 | { | ||
| 843 | struct uvc_streaming_control *probe = &video->streaming->ctrl; | ||
| 844 | struct uvc_format *format = NULL; | ||
| 845 | struct uvc_frame *frame = NULL; | ||
| 846 | unsigned int i; | ||
| 847 | int ret; | ||
| 848 | |||
| 849 | if (video->streaming->nformats == 0) { | ||
| 850 | uvc_printk(KERN_INFO, "No supported video formats found.\n"); | ||
| 851 | return -EINVAL; | ||
| 852 | } | ||
| 853 | |||
| 854 | /* Alternate setting 0 should be the default, yet the XBox Live Vision | ||
| 855 | * Cam (and possibly other devices) crash or otherwise misbehave if | ||
| 856 | * they don't receive a SET_INTERFACE request before any other video | ||
| 857 | * control request. | ||
| 858 | */ | ||
| 859 | usb_set_interface(video->dev->udev, video->streaming->intfnum, 0); | ||
| 860 | |||
| 861 | /* Some webcams don't suport GET_DEF request on the probe control. We | ||
| 862 | * fall back to GET_CUR if GET_DEF fails. | ||
| 863 | */ | ||
| 864 | if ((ret = uvc_get_video_ctrl(video, probe, 1, GET_DEF)) < 0 && | ||
| 865 | (ret = uvc_get_video_ctrl(video, probe, 1, GET_CUR)) < 0) | ||
| 866 | return ret; | ||
| 867 | |||
| 868 | /* Check if the default format descriptor exists. Use the first | ||
| 869 | * available format otherwise. | ||
| 870 | */ | ||
| 871 | for (i = video->streaming->nformats; i > 0; --i) { | ||
| 872 | format = &video->streaming->format[i-1]; | ||
| 873 | if (format->index == probe->bFormatIndex) | ||
| 874 | break; | ||
| 875 | } | ||
| 876 | |||
| 877 | if (format->nframes == 0) { | ||
| 878 | uvc_printk(KERN_INFO, "No frame descriptor found for the " | ||
| 879 | "default format.\n"); | ||
| 880 | return -EINVAL; | ||
| 881 | } | ||
| 882 | |||
| 883 | /* Zero bFrameIndex might be correct. Stream-based formats (including | ||
| 884 | * MPEG-2 TS and DV) do not support frames but have a dummy frame | ||
| 885 | * descriptor with bFrameIndex set to zero. If the default frame | ||
| 886 | * descriptor is not found, use the first avalable frame. | ||
| 887 | */ | ||
| 888 | for (i = format->nframes; i > 0; --i) { | ||
| 889 | frame = &format->frame[i-1]; | ||
| 890 | if (frame->bFrameIndex == probe->bFrameIndex) | ||
| 891 | break; | ||
| 892 | } | ||
| 893 | |||
| 894 | /* Commit the default settings. */ | ||
| 895 | probe->bFormatIndex = format->index; | ||
| 896 | probe->bFrameIndex = frame->bFrameIndex; | ||
| 897 | if ((ret = uvc_set_video_ctrl(video, probe, 0)) < 0) | ||
| 898 | return ret; | ||
| 899 | |||
| 900 | video->streaming->cur_format = format; | ||
| 901 | video->streaming->cur_frame = frame; | ||
| 902 | atomic_set(&video->active, 0); | ||
| 903 | |||
| 904 | /* Select the video decoding function */ | ||
| 905 | if (video->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT) | ||
| 906 | video->decode = uvc_video_decode_isight; | ||
| 907 | else if (video->streaming->intf->num_altsetting > 1) | ||
| 908 | video->decode = uvc_video_decode_isoc; | ||
| 909 | else | ||
| 910 | video->decode = uvc_video_decode_bulk; | ||
| 911 | |||
| 912 | return 0; | ||
| 913 | } | ||
| 914 | |||
| 915 | /* | ||
| 916 | * Enable or disable the video stream. | ||
| 917 | */ | ||
| 918 | int uvc_video_enable(struct uvc_video_device *video, int enable) | ||
| 919 | { | ||
| 920 | int ret; | ||
| 921 | |||
| 922 | if (!enable) { | ||
| 923 | uvc_uninit_video(video); | ||
| 924 | usb_set_interface(video->dev->udev, | ||
| 925 | video->streaming->intfnum, 0); | ||
| 926 | uvc_queue_enable(&video->queue, 0); | ||
| 927 | return 0; | ||
| 928 | } | ||
| 929 | |||
| 930 | if ((ret = uvc_queue_enable(&video->queue, 1)) < 0) | ||
| 931 | return ret; | ||
| 932 | |||
| 933 | return uvc_init_video(video); | ||
| 934 | } | ||
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h new file mode 100644 index 000000000000..a995a780db1c --- /dev/null +++ b/drivers/media/video/uvc/uvcvideo.h | |||
| @@ -0,0 +1,796 @@ | |||
| 1 | #ifndef _USB_VIDEO_H_ | ||
| 2 | #define _USB_VIDEO_H_ | ||
| 3 | |||
| 4 | #include <linux/kernel.h> | ||
| 5 | #include <linux/videodev2.h> | ||
| 6 | |||
| 7 | |||
| 8 | /* | ||
| 9 | * Dynamic controls | ||
| 10 | */ | ||
| 11 | |||
| 12 | /* Data types for UVC control data */ | ||
| 13 | #define UVC_CTRL_DATA_TYPE_RAW 0 | ||
| 14 | #define UVC_CTRL_DATA_TYPE_SIGNED 1 | ||
| 15 | #define UVC_CTRL_DATA_TYPE_UNSIGNED 2 | ||
| 16 | #define UVC_CTRL_DATA_TYPE_BOOLEAN 3 | ||
| 17 | #define UVC_CTRL_DATA_TYPE_ENUM 4 | ||
| 18 | #define UVC_CTRL_DATA_TYPE_BITMASK 5 | ||
| 19 | |||
| 20 | /* Control flags */ | ||
| 21 | #define UVC_CONTROL_SET_CUR (1 << 0) | ||
| 22 | #define UVC_CONTROL_GET_CUR (1 << 1) | ||
| 23 | #define UVC_CONTROL_GET_MIN (1 << 2) | ||
| 24 | #define UVC_CONTROL_GET_MAX (1 << 3) | ||
| 25 | #define UVC_CONTROL_GET_RES (1 << 4) | ||
| 26 | #define UVC_CONTROL_GET_DEF (1 << 5) | ||
| 27 | /* Control should be saved at suspend and restored at resume. */ | ||
| 28 | #define UVC_CONTROL_RESTORE (1 << 6) | ||
| 29 | /* Control can be updated by the camera. */ | ||
| 30 | #define UVC_CONTROL_AUTO_UPDATE (1 << 7) | ||
| 31 | |||
| 32 | #define UVC_CONTROL_GET_RANGE (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \ | ||
| 33 | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \ | ||
| 34 | UVC_CONTROL_GET_DEF) | ||
| 35 | |||
| 36 | struct uvc_xu_control_info { | ||
| 37 | __u8 entity[16]; | ||
| 38 | __u8 index; | ||
| 39 | __u8 selector; | ||
| 40 | __u16 size; | ||
| 41 | __u32 flags; | ||
| 42 | }; | ||
| 43 | |||
| 44 | struct uvc_xu_control_mapping { | ||
| 45 | __u32 id; | ||
| 46 | __u8 name[32]; | ||
| 47 | __u8 entity[16]; | ||
| 48 | __u8 selector; | ||
| 49 | |||
| 50 | __u8 size; | ||
| 51 | __u8 offset; | ||
| 52 | enum v4l2_ctrl_type v4l2_type; | ||
| 53 | __u32 data_type; | ||
| 54 | }; | ||
| 55 | |||
| 56 | struct uvc_xu_control { | ||
| 57 | __u8 unit; | ||
| 58 | __u8 selector; | ||
| 59 | __u16 size; | ||
| 60 | __u8 __user *data; | ||
| 61 | }; | ||
| 62 | |||
| 63 | #define UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info) | ||
| 64 | #define UVCIOC_CTRL_MAP _IOWR('U', 2, struct uvc_xu_control_mapping) | ||
| 65 | #define UVCIOC_CTRL_GET _IOWR('U', 3, struct uvc_xu_control) | ||
| 66 | #define UVCIOC_CTRL_SET _IOW('U', 4, struct uvc_xu_control) | ||
| 67 | |||
| 68 | #ifdef __KERNEL__ | ||
| 69 | |||
| 70 | #include <linux/poll.h> | ||
| 71 | |||
| 72 | /* -------------------------------------------------------------------------- | ||
| 73 | * UVC constants | ||
| 74 | */ | ||
| 75 | |||
| 76 | #define SC_UNDEFINED 0x00 | ||
| 77 | #define SC_VIDEOCONTROL 0x01 | ||
| 78 | #define SC_VIDEOSTREAMING 0x02 | ||
| 79 | #define SC_VIDEO_INTERFACE_COLLECTION 0x03 | ||
| 80 | |||
| 81 | #define PC_PROTOCOL_UNDEFINED 0x00 | ||
| 82 | |||
| 83 | #define CS_UNDEFINED 0x20 | ||
| 84 | #define CS_DEVICE 0x21 | ||
| 85 | #define CS_CONFIGURATION 0x22 | ||
| 86 | #define CS_STRING 0x23 | ||
| 87 | #define CS_INTERFACE 0x24 | ||
| 88 | #define CS_ENDPOINT 0x25 | ||
| 89 | |||
| 90 | /* VideoControl class specific interface descriptor */ | ||
| 91 | #define VC_DESCRIPTOR_UNDEFINED 0x00 | ||
| 92 | #define VC_HEADER 0x01 | ||
| 93 | #define VC_INPUT_TERMINAL 0x02 | ||
| 94 | #define VC_OUTPUT_TERMINAL 0x03 | ||
| 95 | #define VC_SELECTOR_UNIT 0x04 | ||
| 96 | #define VC_PROCESSING_UNIT 0x05 | ||
| 97 | #define VC_EXTENSION_UNIT 0x06 | ||
| 98 | |||
| 99 | /* VideoStreaming class specific interface descriptor */ | ||
| 100 | #define VS_UNDEFINED 0x00 | ||
| 101 | #define VS_INPUT_HEADER 0x01 | ||
| 102 | #define VS_OUTPUT_HEADER 0x02 | ||
| 103 | #define VS_STILL_IMAGE_FRAME 0x03 | ||
| 104 | #define VS_FORMAT_UNCOMPRESSED 0x04 | ||
| 105 | #define VS_FRAME_UNCOMPRESSED 0x05 | ||
| 106 | #define VS_FORMAT_MJPEG 0x06 | ||
| 107 | #define VS_FRAME_MJPEG 0x07 | ||
| 108 | #define VS_FORMAT_MPEG2TS 0x0a | ||
| 109 | #define VS_FORMAT_DV 0x0c | ||
| 110 | #define VS_COLORFORMAT 0x0d | ||
| 111 | #define VS_FORMAT_FRAME_BASED 0x10 | ||
| 112 | #define VS_FRAME_FRAME_BASED 0x11 | ||
| 113 | #define VS_FORMAT_STREAM_BASED 0x12 | ||
| 114 | |||
| 115 | /* Endpoint type */ | ||
| 116 | #define EP_UNDEFINED 0x00 | ||
| 117 | #define EP_GENERAL 0x01 | ||
| 118 | #define EP_ENDPOINT 0x02 | ||
| 119 | #define EP_INTERRUPT 0x03 | ||
| 120 | |||
| 121 | /* Request codes */ | ||
| 122 | #define RC_UNDEFINED 0x00 | ||
| 123 | #define SET_CUR 0x01 | ||
| 124 | #define GET_CUR 0x81 | ||
| 125 | #define GET_MIN 0x82 | ||
| 126 | #define GET_MAX 0x83 | ||
| 127 | #define GET_RES 0x84 | ||
| 128 | #define GET_LEN 0x85 | ||
| 129 | #define GET_INFO 0x86 | ||
| 130 | #define GET_DEF 0x87 | ||
| 131 | |||
| 132 | /* VideoControl interface controls */ | ||
| 133 | #define VC_CONTROL_UNDEFINED 0x00 | ||
| 134 | #define VC_VIDEO_POWER_MODE_CONTROL 0x01 | ||
| 135 | #define VC_REQUEST_ERROR_CODE_CONTROL 0x02 | ||
| 136 | |||
| 137 | /* Terminal controls */ | ||
| 138 | #define TE_CONTROL_UNDEFINED 0x00 | ||
| 139 | |||
| 140 | /* Selector Unit controls */ | ||
| 141 | #define SU_CONTROL_UNDEFINED 0x00 | ||
| 142 | #define SU_INPUT_SELECT_CONTROL 0x01 | ||
| 143 | |||
| 144 | /* Camera Terminal controls */ | ||
| 145 | #define CT_CONTROL_UNDEFINED 0x00 | ||
| 146 | #define CT_SCANNING_MODE_CONTROL 0x01 | ||
| 147 | #define CT_AE_MODE_CONTROL 0x02 | ||
| 148 | #define CT_AE_PRIORITY_CONTROL 0x03 | ||
| 149 | #define CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x04 | ||
| 150 | #define CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x05 | ||
| 151 | #define CT_FOCUS_ABSOLUTE_CONTROL 0x06 | ||
| 152 | #define CT_FOCUS_RELATIVE_CONTROL 0x07 | ||
| 153 | #define CT_FOCUS_AUTO_CONTROL 0x08 | ||
| 154 | #define CT_IRIS_ABSOLUTE_CONTROL 0x09 | ||
| 155 | #define CT_IRIS_RELATIVE_CONTROL 0x0a | ||
| 156 | #define CT_ZOOM_ABSOLUTE_CONTROL 0x0b | ||
| 157 | #define CT_ZOOM_RELATIVE_CONTROL 0x0c | ||
| 158 | #define CT_PANTILT_ABSOLUTE_CONTROL 0x0d | ||
| 159 | #define CT_PANTILT_RELATIVE_CONTROL 0x0e | ||
| 160 | #define CT_ROLL_ABSOLUTE_CONTROL 0x0f | ||
| 161 | #define CT_ROLL_RELATIVE_CONTROL 0x10 | ||
| 162 | #define CT_PRIVACY_CONTROL 0x11 | ||
| 163 | |||
| 164 | /* Processing Unit controls */ | ||
| 165 | #define PU_CONTROL_UNDEFINED 0x00 | ||
| 166 | #define PU_BACKLIGHT_COMPENSATION_CONTROL 0x01 | ||
| 167 | #define PU_BRIGHTNESS_CONTROL 0x02 | ||
| 168 | #define PU_CONTRAST_CONTROL 0x03 | ||
| 169 | #define PU_GAIN_CONTROL 0x04 | ||
| 170 | #define PU_POWER_LINE_FREQUENCY_CONTROL 0x05 | ||
| 171 | #define PU_HUE_CONTROL 0x06 | ||
| 172 | #define PU_SATURATION_CONTROL 0x07 | ||
| 173 | #define PU_SHARPNESS_CONTROL 0x08 | ||
| 174 | #define PU_GAMMA_CONTROL 0x09 | ||
| 175 | #define PU_WHITE_BALANCE_TEMPERATURE_CONTROL 0x0a | ||
| 176 | #define PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL 0x0b | ||
| 177 | #define PU_WHITE_BALANCE_COMPONENT_CONTROL 0x0c | ||
| 178 | #define PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL 0x0d | ||
| 179 | #define PU_DIGITAL_MULTIPLIER_CONTROL 0x0e | ||
| 180 | #define PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL 0x0f | ||
| 181 | #define PU_HUE_AUTO_CONTROL 0x10 | ||
| 182 | #define PU_ANALOG_VIDEO_STANDARD_CONTROL 0x11 | ||
| 183 | #define PU_ANALOG_LOCK_STATUS_CONTROL 0x12 | ||
| 184 | |||
| 185 | #define LXU_MOTOR_PANTILT_RELATIVE_CONTROL 0x01 | ||
| 186 | #define LXU_MOTOR_PANTILT_RESET_CONTROL 0x02 | ||
| 187 | #define LXU_MOTOR_FOCUS_MOTOR_CONTROL 0x03 | ||
| 188 | |||
| 189 | /* VideoStreaming interface controls */ | ||
| 190 | #define VS_CONTROL_UNDEFINED 0x00 | ||
| 191 | #define VS_PROBE_CONTROL 0x01 | ||
| 192 | #define VS_COMMIT_CONTROL 0x02 | ||
| 193 | #define VS_STILL_PROBE_CONTROL 0x03 | ||
| 194 | #define VS_STILL_COMMIT_CONTROL 0x04 | ||
| 195 | #define VS_STILL_IMAGE_TRIGGER_CONTROL 0x05 | ||
| 196 | #define VS_STREAM_ERROR_CODE_CONTROL 0x06 | ||
| 197 | #define VS_GENERATE_KEY_FRAME_CONTROL 0x07 | ||
| 198 | #define VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08 | ||
| 199 | #define VS_SYNC_DELAY_CONTROL 0x09 | ||
| 200 | |||
| 201 | #define TT_VENDOR_SPECIFIC 0x0100 | ||
| 202 | #define TT_STREAMING 0x0101 | ||
| 203 | |||
| 204 | /* Input Terminal types */ | ||
| 205 | #define ITT_VENDOR_SPECIFIC 0x0200 | ||
| 206 | #define ITT_CAMERA 0x0201 | ||
| 207 | #define ITT_MEDIA_TRANSPORT_INPUT 0x0202 | ||
| 208 | |||
| 209 | /* Output Terminal types */ | ||
| 210 | #define OTT_VENDOR_SPECIFIC 0x0300 | ||
| 211 | #define OTT_DISPLAY 0x0301 | ||
| 212 | #define OTT_MEDIA_TRANSPORT_OUTPUT 0x0302 | ||
| 213 | |||
| 214 | /* External Terminal types */ | ||
| 215 | #define EXTERNAL_VENDOR_SPECIFIC 0x0400 | ||
| 216 | #define COMPOSITE_CONNECTOR 0x0401 | ||
| 217 | #define SVIDEO_CONNECTOR 0x0402 | ||
| 218 | #define COMPONENT_CONNECTOR 0x0403 | ||
| 219 | |||
| 220 | #define UVC_TERM_INPUT 0x0000 | ||
| 221 | #define UVC_TERM_OUTPUT 0x8000 | ||
| 222 | |||
| 223 | #define UVC_ENTITY_TYPE(entity) ((entity)->type & 0x7fff) | ||
| 224 | #define UVC_ENTITY_IS_UNIT(entity) (((entity)->type & 0xff00) == 0) | ||
| 225 | #define UVC_ENTITY_IS_TERM(entity) (((entity)->type & 0xff00) != 0) | ||
| 226 | #define UVC_ENTITY_IS_ITERM(entity) \ | ||
| 227 | (((entity)->type & 0x8000) == UVC_TERM_INPUT) | ||
| 228 | #define UVC_ENTITY_IS_OTERM(entity) \ | ||
| 229 | (((entity)->type & 0x8000) == UVC_TERM_OUTPUT) | ||
| 230 | |||
| 231 | #define UVC_STATUS_TYPE_CONTROL 1 | ||
| 232 | #define UVC_STATUS_TYPE_STREAMING 2 | ||
| 233 | |||
| 234 | /* ------------------------------------------------------------------------ | ||
| 235 | * GUIDs | ||
| 236 | */ | ||
| 237 | #define UVC_GUID_UVC_CAMERA \ | ||
| 238 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ | ||
| 239 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} | ||
| 240 | #define UVC_GUID_UVC_OUTPUT \ | ||
| 241 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ | ||
| 242 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02} | ||
| 243 | #define UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT \ | ||
| 244 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ | ||
| 245 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03} | ||
| 246 | #define UVC_GUID_UVC_PROCESSING \ | ||
| 247 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ | ||
| 248 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01} | ||
| 249 | #define UVC_GUID_UVC_SELECTOR \ | ||
| 250 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ | ||
| 251 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} | ||
| 252 | |||
| 253 | #define UVC_GUID_LOGITECH_DEV_INFO \ | ||
| 254 | {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ | ||
| 255 | 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1e} | ||
| 256 | #define UVC_GUID_LOGITECH_USER_HW \ | ||
| 257 | {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ | ||
| 258 | 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1f} | ||
| 259 | #define UVC_GUID_LOGITECH_VIDEO \ | ||
| 260 | {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ | ||
| 261 | 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x50} | ||
| 262 | #define UVC_GUID_LOGITECH_MOTOR \ | ||
| 263 | {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ | ||
| 264 | 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x56} | ||
| 265 | |||
| 266 | #define UVC_GUID_FORMAT_MJPEG \ | ||
| 267 | { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ | ||
| 268 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | ||
| 269 | #define UVC_GUID_FORMAT_YUY2 \ | ||
| 270 | { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ | ||
| 271 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | ||
| 272 | #define UVC_GUID_FORMAT_NV12 \ | ||
| 273 | { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ | ||
| 274 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | ||
| 275 | #define UVC_GUID_FORMAT_YV12 \ | ||
| 276 | { 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ | ||
| 277 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | ||
| 278 | #define UVC_GUID_FORMAT_I420 \ | ||
| 279 | { 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ | ||
| 280 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | ||
| 281 | #define UVC_GUID_FORMAT_UYVY \ | ||
| 282 | { 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \ | ||
| 283 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | ||
| 284 | #define UVC_GUID_FORMAT_Y800 \ | ||
| 285 | { 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \ | ||
| 286 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | ||
| 287 | #define UVC_GUID_FORMAT_BY8 \ | ||
| 288 | { 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \ | ||
| 289 | 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} | ||
| 290 | |||
| 291 | |||
| 292 | /* ------------------------------------------------------------------------ | ||
| 293 | * Driver specific constants. | ||
| 294 | */ | ||
| 295 | |||
| 296 | #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0) | ||
| 297 | |||
| 298 | /* Number of isochronous URBs. */ | ||
| 299 | #define UVC_URBS 5 | ||
| 300 | /* Maximum number of packets per isochronous URB. */ | ||
| 301 | #define UVC_MAX_ISO_PACKETS 40 | ||
| 302 | /* Maximum frame size in bytes, for sanity checking. */ | ||
| 303 | #define UVC_MAX_FRAME_SIZE (16*1024*1024) | ||
| 304 | /* Maximum number of video buffers. */ | ||
| 305 | #define UVC_MAX_VIDEO_BUFFERS 32 | ||
| 306 | |||
| 307 | #define UVC_CTRL_CONTROL_TIMEOUT 300 | ||
| 308 | #define UVC_CTRL_STREAMING_TIMEOUT 1000 | ||
| 309 | |||
| 310 | /* Devices quirks */ | ||
| 311 | #define UVC_QUIRK_STATUS_INTERVAL 0x00000001 | ||
| 312 | #define UVC_QUIRK_PROBE_MINMAX 0x00000002 | ||
| 313 | #define UVC_QUIRK_PROBE_EXTRAFIELDS 0x00000004 | ||
| 314 | #define UVC_QUIRK_BUILTIN_ISIGHT 0x00000008 | ||
| 315 | #define UVC_QUIRK_STREAM_NO_FID 0x00000010 | ||
| 316 | #define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020 | ||
| 317 | |||
| 318 | /* Format flags */ | ||
| 319 | #define UVC_FMT_FLAG_COMPRESSED 0x00000001 | ||
| 320 | #define UVC_FMT_FLAG_STREAM 0x00000002 | ||
| 321 | |||
| 322 | /* ------------------------------------------------------------------------ | ||
| 323 | * Structures. | ||
| 324 | */ | ||
| 325 | |||
| 326 | struct uvc_device; | ||
| 327 | |||
| 328 | /* TODO: Put the most frequently accessed fields at the beginning of | ||
| 329 | * structures to maximize cache efficiency. | ||
| 330 | */ | ||
| 331 | struct uvc_streaming_control { | ||
| 332 | __u16 bmHint; | ||
| 333 | __u8 bFormatIndex; | ||
| 334 | __u8 bFrameIndex; | ||
| 335 | __u32 dwFrameInterval; | ||
| 336 | __u16 wKeyFrameRate; | ||
| 337 | __u16 wPFrameRate; | ||
| 338 | __u16 wCompQuality; | ||
| 339 | __u16 wCompWindowSize; | ||
| 340 | __u16 wDelay; | ||
| 341 | __u32 dwMaxVideoFrameSize; | ||
| 342 | __u32 dwMaxPayloadTransferSize; | ||
| 343 | __u32 dwClockFrequency; | ||
| 344 | __u8 bmFramingInfo; | ||
| 345 | __u8 bPreferedVersion; | ||
| 346 | __u8 bMinVersion; | ||
| 347 | __u8 bMaxVersion; | ||
| 348 | }; | ||
| 349 | |||
| 350 | struct uvc_menu_info { | ||
| 351 | __u32 value; | ||
| 352 | __u8 name[32]; | ||
| 353 | }; | ||
| 354 | |||
| 355 | struct uvc_control_info { | ||
| 356 | struct list_head list; | ||
| 357 | struct list_head mappings; | ||
| 358 | |||
| 359 | __u8 entity[16]; | ||
| 360 | __u8 index; | ||
| 361 | __u8 selector; | ||
| 362 | |||
| 363 | __u16 size; | ||
| 364 | __u32 flags; | ||
| 365 | }; | ||
| 366 | |||
| 367 | struct uvc_control_mapping { | ||
| 368 | struct list_head list; | ||
| 369 | |||
| 370 | struct uvc_control_info *ctrl; | ||
| 371 | |||
| 372 | __u32 id; | ||
| 373 | __u8 name[32]; | ||
| 374 | __u8 entity[16]; | ||
| 375 | __u8 selector; | ||
| 376 | |||
| 377 | __u8 size; | ||
| 378 | __u8 offset; | ||
| 379 | enum v4l2_ctrl_type v4l2_type; | ||
| 380 | __u32 data_type; | ||
| 381 | |||
| 382 | struct uvc_menu_info *menu_info; | ||
| 383 | __u32 menu_count; | ||
| 384 | }; | ||
| 385 | |||
| 386 | struct uvc_control { | ||
| 387 | struct uvc_entity *entity; | ||
| 388 | struct uvc_control_info *info; | ||
| 389 | |||
| 390 | __u8 index; /* Used to match the uvc_control entry with a | ||
| 391 | uvc_control_info. */ | ||
| 392 | __u8 dirty : 1, | ||
| 393 | loaded : 1, | ||
| 394 | modified : 1; | ||
| 395 | |||
| 396 | __u8 *data; | ||
| 397 | }; | ||
| 398 | |||
| 399 | struct uvc_format_desc { | ||
| 400 | char *name; | ||
| 401 | __u8 guid[16]; | ||
| 402 | __u32 fcc; | ||
| 403 | }; | ||
| 404 | |||
| 405 | /* The term 'entity' refers to both UVC units and UVC terminals. | ||
| 406 | * | ||
| 407 | * The type field is either the terminal type (wTerminalType in the terminal | ||
| 408 | * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor). | ||
| 409 | * As the bDescriptorSubtype field is one byte long, the type value will | ||
| 410 | * always have a null MSB for units. All terminal types defined by the UVC | ||
| 411 | * specification have a non-null MSB, so it is safe to use the MSB to | ||
| 412 | * differentiate between units and terminals as long as the descriptor parsing | ||
| 413 | * code makes sure terminal types have a non-null MSB. | ||
| 414 | * | ||
| 415 | * For terminals, the type's most significant bit stores the terminal | ||
| 416 | * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should | ||
| 417 | * always be accessed with the UVC_ENTITY_* macros and never directly. | ||
| 418 | */ | ||
| 419 | |||
| 420 | struct uvc_entity { | ||
| 421 | struct list_head list; /* Entity as part of a UVC device. */ | ||
| 422 | struct list_head chain; /* Entity as part of a video device | ||
| 423 | * chain. */ | ||
| 424 | __u8 id; | ||
| 425 | __u16 type; | ||
| 426 | char name[64]; | ||
| 427 | |||
| 428 | union { | ||
| 429 | struct { | ||
| 430 | __u16 wObjectiveFocalLengthMin; | ||
| 431 | __u16 wObjectiveFocalLengthMax; | ||
| 432 | __u16 wOcularFocalLength; | ||
| 433 | __u8 bControlSize; | ||
| 434 | __u8 *bmControls; | ||
| 435 | } camera; | ||
| 436 | |||
| 437 | struct { | ||
| 438 | __u8 bControlSize; | ||
| 439 | __u8 *bmControls; | ||
| 440 | __u8 bTransportModeSize; | ||
| 441 | __u8 *bmTransportModes; | ||
| 442 | } media; | ||
| 443 | |||
| 444 | struct { | ||
| 445 | __u8 bSourceID; | ||
| 446 | } output; | ||
| 447 | |||
| 448 | struct { | ||
| 449 | __u8 bSourceID; | ||
| 450 | __u16 wMaxMultiplier; | ||
| 451 | __u8 bControlSize; | ||
| 452 | __u8 *bmControls; | ||
| 453 | __u8 bmVideoStandards; | ||
| 454 | } processing; | ||
| 455 | |||
| 456 | struct { | ||
| 457 | __u8 bNrInPins; | ||
| 458 | __u8 *baSourceID; | ||
| 459 | } selector; | ||
| 460 | |||
| 461 | struct { | ||
| 462 | __u8 guidExtensionCode[16]; | ||
| 463 | __u8 bNumControls; | ||
| 464 | __u8 bNrInPins; | ||
| 465 | __u8 *baSourceID; | ||
| 466 | __u8 bControlSize; | ||
| 467 | __u8 *bmControls; | ||
| 468 | __u8 *bmControlsType; | ||
| 469 | } extension; | ||
| 470 | }; | ||
| 471 | |||
| 472 | unsigned int ncontrols; | ||
| 473 | struct uvc_control *controls; | ||
| 474 | }; | ||
| 475 | |||
| 476 | struct uvc_frame { | ||
| 477 | __u8 bFrameIndex; | ||
| 478 | __u8 bmCapabilities; | ||
| 479 | __u16 wWidth; | ||
| 480 | __u16 wHeight; | ||
| 481 | __u32 dwMinBitRate; | ||
| 482 | __u32 dwMaxBitRate; | ||
| 483 | __u32 dwMaxVideoFrameBufferSize; | ||
| 484 | __u8 bFrameIntervalType; | ||
| 485 | __u32 dwDefaultFrameInterval; | ||
| 486 | __u32 *dwFrameInterval; | ||
| 487 | }; | ||
| 488 | |||
| 489 | struct uvc_format { | ||
| 490 | __u8 type; | ||
| 491 | __u8 index; | ||
| 492 | __u8 bpp; | ||
| 493 | __u8 colorspace; | ||
| 494 | __u32 fcc; | ||
| 495 | __u32 flags; | ||
| 496 | |||
| 497 | char name[32]; | ||
| 498 | |||
| 499 | unsigned int nframes; | ||
| 500 | struct uvc_frame *frame; | ||
| 501 | }; | ||
| 502 | |||
| 503 | struct uvc_streaming_header { | ||
| 504 | __u8 bNumFormats; | ||
| 505 | __u8 bEndpointAddress; | ||
| 506 | __u8 bTerminalLink; | ||
| 507 | __u8 bControlSize; | ||
| 508 | __u8 *bmaControls; | ||
| 509 | /* The following fields are used by input headers only. */ | ||
| 510 | __u8 bmInfo; | ||
| 511 | __u8 bStillCaptureMethod; | ||
| 512 | __u8 bTriggerSupport; | ||
| 513 | __u8 bTriggerUsage; | ||
| 514 | }; | ||
| 515 | |||
| 516 | struct uvc_streaming { | ||
| 517 | struct list_head list; | ||
| 518 | |||
| 519 | struct usb_interface *intf; | ||
| 520 | int intfnum; | ||
| 521 | __u16 maxpsize; | ||
| 522 | |||
| 523 | struct uvc_streaming_header header; | ||
| 524 | |||
| 525 | unsigned int nformats; | ||
| 526 | struct uvc_format *format; | ||
| 527 | |||
| 528 | struct uvc_streaming_control ctrl; | ||
| 529 | struct uvc_format *cur_format; | ||
| 530 | struct uvc_frame *cur_frame; | ||
| 531 | |||
| 532 | struct mutex mutex; | ||
| 533 | }; | ||
| 534 | |||
| 535 | enum uvc_buffer_state { | ||
| 536 | UVC_BUF_STATE_IDLE = 0, | ||
| 537 | UVC_BUF_STATE_QUEUED = 1, | ||
| 538 | UVC_BUF_STATE_ACTIVE = 2, | ||
| 539 | UVC_BUF_STATE_DONE = 3, | ||
| 540 | UVC_BUF_STATE_ERROR = 4, | ||
| 541 | }; | ||
| 542 | |||
| 543 | struct uvc_buffer { | ||
| 544 | unsigned long vma_use_count; | ||
| 545 | struct list_head stream; | ||
| 546 | |||
| 547 | /* Touched by interrupt handler. */ | ||
| 548 | struct v4l2_buffer buf; | ||
| 549 | struct list_head queue; | ||
| 550 | wait_queue_head_t wait; | ||
| 551 | enum uvc_buffer_state state; | ||
| 552 | }; | ||
| 553 | |||
| 554 | #define UVC_QUEUE_STREAMING (1 << 0) | ||
| 555 | #define UVC_QUEUE_DISCONNECTED (1 << 1) | ||
| 556 | #define UVC_QUEUE_DROP_INCOMPLETE (1 << 2) | ||
| 557 | |||
| 558 | struct uvc_video_queue { | ||
| 559 | void *mem; | ||
| 560 | unsigned int flags; | ||
| 561 | __u32 sequence; | ||
| 562 | |||
| 563 | unsigned int count; | ||
| 564 | unsigned int buf_size; | ||
| 565 | struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS]; | ||
| 566 | struct mutex mutex; /* protects buffers and mainqueue */ | ||
| 567 | spinlock_t irqlock; /* protects irqqueue */ | ||
| 568 | |||
| 569 | struct list_head mainqueue; | ||
| 570 | struct list_head irqqueue; | ||
| 571 | }; | ||
| 572 | |||
| 573 | struct uvc_video_device { | ||
| 574 | struct uvc_device *dev; | ||
| 575 | struct video_device *vdev; | ||
| 576 | atomic_t active; | ||
| 577 | unsigned int frozen : 1; | ||
| 578 | |||
| 579 | struct list_head iterms; | ||
| 580 | struct uvc_entity *oterm; | ||
| 581 | struct uvc_entity *processing; | ||
| 582 | struct uvc_entity *selector; | ||
| 583 | struct list_head extensions; | ||
| 584 | struct mutex ctrl_mutex; | ||
| 585 | |||
| 586 | struct uvc_video_queue queue; | ||
| 587 | |||
| 588 | /* Video streaming object, must always be non-NULL. */ | ||
| 589 | struct uvc_streaming *streaming; | ||
| 590 | |||
| 591 | void (*decode) (struct urb *urb, struct uvc_video_device *video, | ||
| 592 | struct uvc_buffer *buf); | ||
| 593 | |||
| 594 | /* Context data used by the bulk completion handler. */ | ||
| 595 | struct { | ||
| 596 | __u8 header[256]; | ||
| 597 | unsigned int header_size; | ||
| 598 | int skip_payload; | ||
| 599 | __u32 payload_size; | ||
| 600 | __u32 max_payload_size; | ||
| 601 | } bulk; | ||
| 602 | |||
| 603 | struct urb *urb[UVC_URBS]; | ||
| 604 | char *urb_buffer[UVC_URBS]; | ||
| 605 | |||
| 606 | __u8 last_fid; | ||
| 607 | }; | ||
| 608 | |||
| 609 | enum uvc_device_state { | ||
| 610 | UVC_DEV_DISCONNECTED = 1, | ||
| 611 | }; | ||
| 612 | |||
| 613 | struct uvc_device { | ||
| 614 | struct usb_device *udev; | ||
| 615 | struct usb_interface *intf; | ||
| 616 | __u32 quirks; | ||
| 617 | int intfnum; | ||
| 618 | char name[32]; | ||
| 619 | |||
| 620 | enum uvc_device_state state; | ||
| 621 | struct kref kref; | ||
| 622 | struct list_head list; | ||
| 623 | |||
| 624 | /* Video control interface */ | ||
| 625 | __u16 uvc_version; | ||
| 626 | __u32 clock_frequency; | ||
| 627 | |||
| 628 | struct list_head entities; | ||
| 629 | |||
| 630 | struct uvc_video_device video; | ||
| 631 | |||
| 632 | /* Status Interrupt Endpoint */ | ||
| 633 | struct usb_host_endpoint *int_ep; | ||
| 634 | struct urb *int_urb; | ||
| 635 | __u8 status[16]; | ||
| 636 | struct input_dev *input; | ||
| 637 | |||
| 638 | /* Video Streaming interfaces */ | ||
| 639 | struct list_head streaming; | ||
| 640 | }; | ||
| 641 | |||
| 642 | enum uvc_handle_state { | ||
| 643 | UVC_HANDLE_PASSIVE = 0, | ||
| 644 | UVC_HANDLE_ACTIVE = 1, | ||
| 645 | }; | ||
| 646 | |||
| 647 | struct uvc_fh { | ||
| 648 | struct uvc_video_device *device; | ||
| 649 | enum uvc_handle_state state; | ||
| 650 | }; | ||
| 651 | |||
| 652 | struct uvc_driver { | ||
| 653 | struct usb_driver driver; | ||
| 654 | |||
| 655 | struct mutex open_mutex; /* protects from open/disconnect race */ | ||
| 656 | |||
| 657 | struct list_head devices; /* struct uvc_device list */ | ||
| 658 | struct list_head controls; /* struct uvc_control_info list */ | ||
| 659 | struct mutex ctrl_mutex; /* protects controls and devices | ||
| 660 | lists */ | ||
| 661 | }; | ||
| 662 | |||
| 663 | /* ------------------------------------------------------------------------ | ||
| 664 | * Debugging, printing and logging | ||
| 665 | */ | ||
| 666 | |||
| 667 | #define UVC_TRACE_PROBE (1 << 0) | ||
| 668 | #define UVC_TRACE_DESCR (1 << 1) | ||
| 669 | #define UVC_TRACE_CONTROL (1 << 2) | ||
| 670 | #define UVC_TRACE_FORMAT (1 << 3) | ||
| 671 | #define UVC_TRACE_CAPTURE (1 << 4) | ||
| 672 | #define UVC_TRACE_CALLS (1 << 5) | ||
| 673 | #define UVC_TRACE_IOCTL (1 << 6) | ||
| 674 | #define UVC_TRACE_FRAME (1 << 7) | ||
| 675 | #define UVC_TRACE_SUSPEND (1 << 8) | ||
| 676 | #define UVC_TRACE_STATUS (1 << 9) | ||
| 677 | |||
| 678 | extern unsigned int uvc_trace_param; | ||
| 679 | |||
| 680 | #define uvc_trace(flag, msg...) \ | ||
| 681 | do { \ | ||
| 682 | if (uvc_trace_param & flag) \ | ||
| 683 | printk(KERN_DEBUG "uvcvideo: " msg); \ | ||
| 684 | } while (0) | ||
| 685 | |||
| 686 | #define uvc_printk(level, msg...) \ | ||
| 687 | printk(level "uvcvideo: " msg) | ||
| 688 | |||
| 689 | #define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \ | ||
| 690 | "%02x%02x%02x%02x%02x%02x" | ||
| 691 | #define UVC_GUID_ARGS(guid) \ | ||
| 692 | (guid)[3], (guid)[2], (guid)[1], (guid)[0], \ | ||
| 693 | (guid)[5], (guid)[4], \ | ||
| 694 | (guid)[7], (guid)[6], \ | ||
| 695 | (guid)[8], (guid)[9], \ | ||
| 696 | (guid)[10], (guid)[11], (guid)[12], \ | ||
| 697 | (guid)[13], (guid)[14], (guid)[15] | ||
| 698 | |||
| 699 | /* -------------------------------------------------------------------------- | ||
| 700 | * Internal functions. | ||
| 701 | */ | ||
| 702 | |||
| 703 | /* Core driver */ | ||
| 704 | extern struct uvc_driver uvc_driver; | ||
| 705 | extern void uvc_delete(struct kref *kref); | ||
| 706 | |||
| 707 | /* Video buffers queue management. */ | ||
| 708 | extern void uvc_queue_init(struct uvc_video_queue *queue); | ||
| 709 | extern int uvc_alloc_buffers(struct uvc_video_queue *queue, | ||
| 710 | unsigned int nbuffers, unsigned int buflength); | ||
| 711 | extern int uvc_free_buffers(struct uvc_video_queue *queue); | ||
| 712 | extern int uvc_query_buffer(struct uvc_video_queue *queue, | ||
| 713 | struct v4l2_buffer *v4l2_buf); | ||
| 714 | extern int uvc_queue_buffer(struct uvc_video_queue *queue, | ||
| 715 | struct v4l2_buffer *v4l2_buf); | ||
| 716 | extern int uvc_dequeue_buffer(struct uvc_video_queue *queue, | ||
| 717 | struct v4l2_buffer *v4l2_buf, int nonblocking); | ||
| 718 | extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable); | ||
| 719 | extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); | ||
| 720 | extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | ||
| 721 | struct uvc_buffer *buf); | ||
| 722 | extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, | ||
| 723 | struct file *file, poll_table *wait); | ||
| 724 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) | ||
| 725 | { | ||
| 726 | return queue->flags & UVC_QUEUE_STREAMING; | ||
| 727 | } | ||
| 728 | |||
| 729 | /* V4L2 interface */ | ||
| 730 | extern struct file_operations uvc_fops; | ||
| 731 | |||
| 732 | /* Video */ | ||
| 733 | extern int uvc_video_init(struct uvc_video_device *video); | ||
| 734 | extern int uvc_video_suspend(struct uvc_video_device *video); | ||
| 735 | extern int uvc_video_resume(struct uvc_video_device *video); | ||
| 736 | extern int uvc_video_enable(struct uvc_video_device *video, int enable); | ||
| 737 | extern int uvc_probe_video(struct uvc_video_device *video, | ||
| 738 | struct uvc_streaming_control *probe); | ||
| 739 | extern int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, | ||
| 740 | __u8 intfnum, __u8 cs, void *data, __u16 size); | ||
| 741 | extern int uvc_set_video_ctrl(struct uvc_video_device *video, | ||
| 742 | struct uvc_streaming_control *ctrl, int probe); | ||
| 743 | |||
| 744 | /* Status */ | ||
| 745 | extern int uvc_status_init(struct uvc_device *dev); | ||
| 746 | extern void uvc_status_cleanup(struct uvc_device *dev); | ||
| 747 | extern int uvc_status_suspend(struct uvc_device *dev); | ||
| 748 | extern int uvc_status_resume(struct uvc_device *dev); | ||
| 749 | |||
| 750 | /* Controls */ | ||
| 751 | extern struct uvc_control *uvc_find_control(struct uvc_video_device *video, | ||
| 752 | __u32 v4l2_id, struct uvc_control_mapping **mapping); | ||
| 753 | extern int uvc_query_v4l2_ctrl(struct uvc_video_device *video, | ||
| 754 | struct v4l2_queryctrl *v4l2_ctrl); | ||
| 755 | |||
| 756 | extern int uvc_ctrl_add_info(struct uvc_control_info *info); | ||
| 757 | extern int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping); | ||
| 758 | extern int uvc_ctrl_init_device(struct uvc_device *dev); | ||
| 759 | extern void uvc_ctrl_cleanup_device(struct uvc_device *dev); | ||
| 760 | extern int uvc_ctrl_resume_device(struct uvc_device *dev); | ||
| 761 | extern void uvc_ctrl_init(void); | ||
| 762 | |||
| 763 | extern int uvc_ctrl_begin(struct uvc_video_device *video); | ||
| 764 | extern int __uvc_ctrl_commit(struct uvc_video_device *video, int rollback); | ||
| 765 | static inline int uvc_ctrl_commit(struct uvc_video_device *video) | ||
| 766 | { | ||
| 767 | return __uvc_ctrl_commit(video, 0); | ||
| 768 | } | ||
| 769 | static inline int uvc_ctrl_rollback(struct uvc_video_device *video) | ||
| 770 | { | ||
| 771 | return __uvc_ctrl_commit(video, 1); | ||
| 772 | } | ||
| 773 | |||
| 774 | extern int uvc_ctrl_get(struct uvc_video_device *video, | ||
| 775 | struct v4l2_ext_control *xctrl); | ||
| 776 | extern int uvc_ctrl_set(struct uvc_video_device *video, | ||
| 777 | struct v4l2_ext_control *xctrl); | ||
| 778 | |||
| 779 | extern int uvc_xu_ctrl_query(struct uvc_video_device *video, | ||
| 780 | struct uvc_xu_control *ctrl, int set); | ||
| 781 | |||
| 782 | /* Utility functions */ | ||
| 783 | extern void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator, | ||
| 784 | unsigned int n_terms, unsigned int threshold); | ||
| 785 | extern uint32_t uvc_fraction_to_interval(uint32_t numerator, | ||
| 786 | uint32_t denominator); | ||
| 787 | extern struct usb_host_endpoint *uvc_find_endpoint( | ||
| 788 | struct usb_host_interface *alts, __u8 epaddr); | ||
| 789 | |||
| 790 | /* Quirks support */ | ||
| 791 | void uvc_video_decode_isight(struct urb *urb, struct uvc_video_device *video, | ||
| 792 | struct uvc_buffer *buf); | ||
| 793 | |||
| 794 | #endif /* __KERNEL__ */ | ||
| 795 | |||
| 796 | #endif | ||
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c index 2edda8cc7f99..aabad8ce7458 100644 --- a/drivers/net/3c59x.c +++ b/drivers/net/3c59x.c | |||
| @@ -1768,9 +1768,10 @@ vortex_timer(unsigned long data) | |||
| 1768 | case XCVR_MII: case XCVR_NWAY: | 1768 | case XCVR_MII: case XCVR_NWAY: |
| 1769 | { | 1769 | { |
| 1770 | ok = 1; | 1770 | ok = 1; |
| 1771 | spin_lock_bh(&vp->lock); | 1771 | /* Interrupts are already disabled */ |
| 1772 | spin_lock(&vp->lock); | ||
| 1772 | vortex_check_media(dev, 0); | 1773 | vortex_check_media(dev, 0); |
| 1773 | spin_unlock_bh(&vp->lock); | 1774 | spin_unlock(&vp->lock); |
| 1774 | } | 1775 | } |
| 1775 | break; | 1776 | break; |
| 1776 | default: /* Other media types handled by Tx timeouts. */ | 1777 | default: /* Other media types handled by Tx timeouts. */ |
diff --git a/drivers/net/e100.c b/drivers/net/e100.c index f3cba5e24ec5..1037b1332312 100644 --- a/drivers/net/e100.c +++ b/drivers/net/e100.c | |||
| @@ -1803,6 +1803,8 @@ static int e100_rx_alloc_skb(struct nic *nic, struct rx *rx) | |||
| 1803 | if (rx->prev->skb) { | 1803 | if (rx->prev->skb) { |
| 1804 | struct rfd *prev_rfd = (struct rfd *)rx->prev->skb->data; | 1804 | struct rfd *prev_rfd = (struct rfd *)rx->prev->skb->data; |
| 1805 | put_unaligned_le32(rx->dma_addr, &prev_rfd->link); | 1805 | put_unaligned_le32(rx->dma_addr, &prev_rfd->link); |
| 1806 | pci_dma_sync_single_for_device(nic->pdev, rx->prev->dma_addr, | ||
| 1807 | sizeof(struct rfd), PCI_DMA_TODEVICE); | ||
| 1806 | } | 1808 | } |
| 1807 | 1809 | ||
| 1808 | return 0; | 1810 | return 0; |
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c index 701531e72e7b..a3f6a9c72ec8 100644 --- a/drivers/net/e1000/e1000_ethtool.c +++ b/drivers/net/e1000/e1000_ethtool.c | |||
| @@ -347,7 +347,7 @@ e1000_set_tso(struct net_device *netdev, u32 data) | |||
| 347 | else | 347 | else |
| 348 | netdev->features &= ~NETIF_F_TSO; | 348 | netdev->features &= ~NETIF_F_TSO; |
| 349 | 349 | ||
| 350 | if (data) | 350 | if (data && (adapter->hw.mac_type > e1000_82547_rev_2)) |
| 351 | netdev->features |= NETIF_F_TSO6; | 351 | netdev->features |= NETIF_F_TSO6; |
| 352 | else | 352 | else |
| 353 | netdev->features &= ~NETIF_F_TSO6; | 353 | netdev->features &= ~NETIF_F_TSO6; |
diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c index cab1835173cd..648a87bbf467 100644 --- a/drivers/net/e1000e/netdev.c +++ b/drivers/net/e1000e/netdev.c | |||
| @@ -2535,7 +2535,8 @@ void e1000e_down(struct e1000_adapter *adapter) | |||
| 2535 | adapter->link_speed = 0; | 2535 | adapter->link_speed = 0; |
| 2536 | adapter->link_duplex = 0; | 2536 | adapter->link_duplex = 0; |
| 2537 | 2537 | ||
| 2538 | e1000e_reset(adapter); | 2538 | if (!pci_channel_offline(adapter->pdev)) |
| 2539 | e1000e_reset(adapter); | ||
| 2539 | e1000_clean_tx_ring(adapter); | 2540 | e1000_clean_tx_ring(adapter); |
| 2540 | e1000_clean_rx_ring(adapter); | 2541 | e1000_clean_rx_ring(adapter); |
| 2541 | 2542 | ||
diff --git a/drivers/net/hamradio/dmascc.c b/drivers/net/hamradio/dmascc.c index 0b94833e23f7..e8cfadefa4b6 100644 --- a/drivers/net/hamradio/dmascc.c +++ b/drivers/net/hamradio/dmascc.c | |||
| @@ -1077,8 +1077,6 @@ static inline void rx_off(struct scc_priv *priv) | |||
| 1077 | 1077 | ||
| 1078 | static void start_timer(struct scc_priv *priv, int t, int r15) | 1078 | static void start_timer(struct scc_priv *priv, int t, int r15) |
| 1079 | { | 1079 | { |
| 1080 | unsigned long flags; | ||
| 1081 | |||
| 1082 | outb(priv->tmr_mode, priv->tmr_ctrl); | 1080 | outb(priv->tmr_mode, priv->tmr_ctrl); |
| 1083 | if (t == 0) { | 1081 | if (t == 0) { |
| 1084 | tm_isr(priv); | 1082 | tm_isr(priv); |
diff --git a/drivers/net/igb/igb_main.c b/drivers/net/igb/igb_main.c index ae398f04c7b4..e79a26a886c8 100644 --- a/drivers/net/igb/igb_main.c +++ b/drivers/net/igb/igb_main.c | |||
| @@ -718,7 +718,8 @@ void igb_down(struct igb_adapter *adapter) | |||
| 718 | adapter->link_speed = 0; | 718 | adapter->link_speed = 0; |
| 719 | adapter->link_duplex = 0; | 719 | adapter->link_duplex = 0; |
| 720 | 720 | ||
| 721 | igb_reset(adapter); | 721 | if (!pci_channel_offline(adapter->pdev)) |
| 722 | igb_reset(adapter); | ||
| 722 | igb_clean_all_tx_rings(adapter); | 723 | igb_clean_all_tx_rings(adapter); |
| 723 | igb_clean_all_rx_rings(adapter); | 724 | igb_clean_all_rx_rings(adapter); |
| 724 | } | 725 | } |
diff --git a/drivers/net/ipg.c b/drivers/net/ipg.c index 679a0826780e..2c03f4e2ccc4 100644 --- a/drivers/net/ipg.c +++ b/drivers/net/ipg.c | |||
| @@ -1271,7 +1271,7 @@ static void ipg_nic_rx_with_end(struct net_device *dev, | |||
| 1271 | 1271 | ||
| 1272 | framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN; | 1272 | framelen = le64_to_cpu(rxfd->rfs) & IPG_RFS_RXFRAMELEN; |
| 1273 | 1273 | ||
| 1274 | endframeLen = framelen - jumbo->current_size; | 1274 | endframelen = framelen - jumbo->current_size; |
| 1275 | /* | 1275 | /* |
| 1276 | if (framelen > IPG_RXFRAG_SIZE) | 1276 | if (framelen > IPG_RXFRAG_SIZE) |
| 1277 | framelen=IPG_RXFRAG_SIZE; | 1277 | framelen=IPG_RXFRAG_SIZE; |
| @@ -1279,8 +1279,8 @@ static void ipg_nic_rx_with_end(struct net_device *dev, | |||
| 1279 | if (framelen > IPG_RXSUPPORT_SIZE) | 1279 | if (framelen > IPG_RXSUPPORT_SIZE) |
| 1280 | dev_kfree_skb_irq(jumbo->skb); | 1280 | dev_kfree_skb_irq(jumbo->skb); |
| 1281 | else { | 1281 | else { |
| 1282 | memcpy(skb_put(jumbo->skb, endframeLen), | 1282 | memcpy(skb_put(jumbo->skb, endframelen), |
| 1283 | skb->data, endframeLen); | 1283 | skb->data, endframelen); |
| 1284 | 1284 | ||
| 1285 | jumbo->skb->protocol = | 1285 | jumbo->skb->protocol = |
| 1286 | eth_type_trans(jumbo->skb, dev); | 1286 | eth_type_trans(jumbo->skb, dev); |
| @@ -1352,16 +1352,16 @@ static int ipg_nic_rx(struct net_device *dev) | |||
| 1352 | 1352 | ||
| 1353 | switch (ipg_nic_rx_check_frame_type(dev)) { | 1353 | switch (ipg_nic_rx_check_frame_type(dev)) { |
| 1354 | case FRAME_WITH_START_WITH_END: | 1354 | case FRAME_WITH_START_WITH_END: |
| 1355 | ipg_nic_rx_with_start_and_end(dev, tp, rxfd, entry); | 1355 | ipg_nic_rx_with_start_and_end(dev, sp, rxfd, entry); |
| 1356 | break; | 1356 | break; |
| 1357 | case FRAME_WITH_START: | 1357 | case FRAME_WITH_START: |
| 1358 | ipg_nic_rx_with_start(dev, tp, rxfd, entry); | 1358 | ipg_nic_rx_with_start(dev, sp, rxfd, entry); |
| 1359 | break; | 1359 | break; |
| 1360 | case FRAME_WITH_END: | 1360 | case FRAME_WITH_END: |
| 1361 | ipg_nic_rx_with_end(dev, tp, rxfd, entry); | 1361 | ipg_nic_rx_with_end(dev, sp, rxfd, entry); |
| 1362 | break; | 1362 | break; |
| 1363 | case FRAME_NO_START_NO_END: | 1363 | case FRAME_NO_START_NO_END: |
| 1364 | ipg_nic_rx_no_start_no_end(dev, tp, rxfd, entry); | 1364 | ipg_nic_rx_no_start_no_end(dev, sp, rxfd, entry); |
| 1365 | break; | 1365 | break; |
| 1366 | } | 1366 | } |
| 1367 | } | 1367 | } |
| @@ -1808,7 +1808,7 @@ static int ipg_nic_open(struct net_device *dev) | |||
| 1808 | /* initialize JUMBO Frame control variable */ | 1808 | /* initialize JUMBO Frame control variable */ |
| 1809 | sp->jumbo.found_start = 0; | 1809 | sp->jumbo.found_start = 0; |
| 1810 | sp->jumbo.current_size = 0; | 1810 | sp->jumbo.current_size = 0; |
| 1811 | sp->jumbo.skb = 0; | 1811 | sp->jumbo.skb = NULL; |
| 1812 | dev->mtu = IPG_TXFRAG_SIZE; | 1812 | dev->mtu = IPG_TXFRAG_SIZE; |
| 1813 | #endif | 1813 | #endif |
| 1814 | 1814 | ||
diff --git a/drivers/net/ixgbe/ixgbe_main.c b/drivers/net/ixgbe/ixgbe_main.c index 7b859220c255..8f0460901153 100644 --- a/drivers/net/ixgbe/ixgbe_main.c +++ b/drivers/net/ixgbe/ixgbe_main.c | |||
| @@ -1969,7 +1969,8 @@ void ixgbe_down(struct ixgbe_adapter *adapter) | |||
| 1969 | netif_carrier_off(netdev); | 1969 | netif_carrier_off(netdev); |
| 1970 | netif_stop_queue(netdev); | 1970 | netif_stop_queue(netdev); |
| 1971 | 1971 | ||
| 1972 | ixgbe_reset(adapter); | 1972 | if (!pci_channel_offline(adapter->pdev)) |
| 1973 | ixgbe_reset(adapter); | ||
| 1973 | ixgbe_clean_all_tx_rings(adapter); | 1974 | ixgbe_clean_all_tx_rings(adapter); |
| 1974 | ixgbe_clean_all_rx_rings(adapter); | 1975 | ixgbe_clean_all_rx_rings(adapter); |
| 1975 | 1976 | ||
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c index 6797ed069f1f..63cd67b931e7 100644 --- a/drivers/net/netxen/netxen_nic_main.c +++ b/drivers/net/netxen/netxen_nic_main.c | |||
| @@ -71,14 +71,18 @@ static irqreturn_t netxen_intr(int irq, void *data); | |||
| 71 | static irqreturn_t netxen_msi_intr(int irq, void *data); | 71 | static irqreturn_t netxen_msi_intr(int irq, void *data); |
| 72 | 72 | ||
| 73 | /* PCI Device ID Table */ | 73 | /* PCI Device ID Table */ |
| 74 | #define ENTRY(device) \ | ||
| 75 | {PCI_DEVICE(0x4040, (device)), \ | ||
| 76 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} | ||
| 77 | |||
| 74 | static struct pci_device_id netxen_pci_tbl[] __devinitdata = { | 78 | static struct pci_device_id netxen_pci_tbl[] __devinitdata = { |
| 75 | {PCI_DEVICE(0x4040, 0x0001), PCI_DEVICE_CLASS(0x020000, ~0)}, | 79 | ENTRY(0x0001), |
| 76 | {PCI_DEVICE(0x4040, 0x0002), PCI_DEVICE_CLASS(0x020000, ~0)}, | 80 | ENTRY(0x0002), |
| 77 | {PCI_DEVICE(0x4040, 0x0003), PCI_DEVICE_CLASS(0x020000, ~0)}, | 81 | ENTRY(0x0003), |
| 78 | {PCI_DEVICE(0x4040, 0x0004), PCI_DEVICE_CLASS(0x020000, ~0)}, | 82 | ENTRY(0x0004), |
| 79 | {PCI_DEVICE(0x4040, 0x0005), PCI_DEVICE_CLASS(0x020000, ~0)}, | 83 | ENTRY(0x0005), |
| 80 | {PCI_DEVICE(0x4040, 0x0024), PCI_DEVICE_CLASS(0x020000, ~0)}, | 84 | ENTRY(0x0024), |
| 81 | {PCI_DEVICE(0x4040, 0x0025), PCI_DEVICE_CLASS(0x020000, ~0)}, | 85 | ENTRY(0x0025), |
| 82 | {0,} | 86 | {0,} |
| 83 | }; | 87 | }; |
| 84 | 88 | ||
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c index ce95c5d168fe..70d012e90dcf 100644 --- a/drivers/net/pcmcia/axnet_cs.c +++ b/drivers/net/pcmcia/axnet_cs.c | |||
| @@ -525,12 +525,14 @@ static int axnet_open(struct net_device *dev) | |||
| 525 | int ret; | 525 | int ret; |
| 526 | axnet_dev_t *info = PRIV(dev); | 526 | axnet_dev_t *info = PRIV(dev); |
| 527 | struct pcmcia_device *link = info->p_dev; | 527 | struct pcmcia_device *link = info->p_dev; |
| 528 | unsigned int nic_base = dev->base_addr; | ||
| 528 | 529 | ||
| 529 | DEBUG(2, "axnet_open('%s')\n", dev->name); | 530 | DEBUG(2, "axnet_open('%s')\n", dev->name); |
| 530 | 531 | ||
| 531 | if (!pcmcia_dev_present(link)) | 532 | if (!pcmcia_dev_present(link)) |
| 532 | return -ENODEV; | 533 | return -ENODEV; |
| 533 | 534 | ||
| 535 | outb_p(0xFF, nic_base + EN0_ISR); /* Clear bogus intr. */ | ||
| 534 | ret = request_irq(dev->irq, ei_irq_wrapper, IRQF_SHARED, "axnet_cs", dev); | 536 | ret = request_irq(dev->irq, ei_irq_wrapper, IRQF_SHARED, "axnet_cs", dev); |
| 535 | if (ret) | 537 | if (ret) |
| 536 | return ret; | 538 | return ret; |
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c index fd8158a86f64..2d4c4ad89b8d 100644 --- a/drivers/net/pcmcia/pcnet_cs.c +++ b/drivers/net/pcmcia/pcnet_cs.c | |||
| @@ -969,6 +969,7 @@ static int pcnet_open(struct net_device *dev) | |||
| 969 | int ret; | 969 | int ret; |
| 970 | pcnet_dev_t *info = PRIV(dev); | 970 | pcnet_dev_t *info = PRIV(dev); |
| 971 | struct pcmcia_device *link = info->p_dev; | 971 | struct pcmcia_device *link = info->p_dev; |
| 972 | unsigned int nic_base = dev->base_addr; | ||
| 972 | 973 | ||
| 973 | DEBUG(2, "pcnet_open('%s')\n", dev->name); | 974 | DEBUG(2, "pcnet_open('%s')\n", dev->name); |
| 974 | 975 | ||
| @@ -976,6 +977,8 @@ static int pcnet_open(struct net_device *dev) | |||
| 976 | return -ENODEV; | 977 | return -ENODEV; |
| 977 | 978 | ||
| 978 | set_misc_reg(dev); | 979 | set_misc_reg(dev); |
| 980 | |||
| 981 | outb_p(0xFF, nic_base + EN0_ISR); /* Clear bogus intr. */ | ||
| 979 | ret = request_irq(dev->irq, ei_irq_wrapper, IRQF_SHARED, dev_info, dev); | 982 | ret = request_irq(dev->irq, ei_irq_wrapper, IRQF_SHARED, dev_info, dev); |
| 980 | if (ret) | 983 | if (ret) |
| 981 | return ret; | 984 | return ret; |
diff --git a/drivers/net/qla3xxx.c b/drivers/net/qla3xxx.c index b7f7b2227d56..bccee68bd48a 100644 --- a/drivers/net/qla3xxx.c +++ b/drivers/net/qla3xxx.c | |||
| @@ -3701,7 +3701,9 @@ static int ql_cycle_adapter(struct ql3_adapter *qdev, int reset) | |||
| 3701 | printk(KERN_ERR PFX | 3701 | printk(KERN_ERR PFX |
| 3702 | "%s: Driver up/down cycle failed, " | 3702 | "%s: Driver up/down cycle failed, " |
| 3703 | "closing device\n",qdev->ndev->name); | 3703 | "closing device\n",qdev->ndev->name); |
| 3704 | rtnl_lock(); | ||
| 3704 | dev_close(qdev->ndev); | 3705 | dev_close(qdev->ndev); |
| 3706 | rtnl_unlock(); | ||
| 3705 | return -1; | 3707 | return -1; |
| 3706 | } | 3708 | } |
| 3707 | return 0; | 3709 | return 0; |
diff --git a/drivers/net/r6040.c b/drivers/net/r6040.c index 858b191517b3..504a48ff73c8 100644 --- a/drivers/net/r6040.c +++ b/drivers/net/r6040.c | |||
| @@ -273,7 +273,7 @@ static void r6040_init_ring_desc(struct r6040_descriptor *desc_ring, | |||
| 273 | dma_addr_t mapping = desc_dma; | 273 | dma_addr_t mapping = desc_dma; |
| 274 | 274 | ||
| 275 | while (size-- > 0) { | 275 | while (size-- > 0) { |
| 276 | mapping += sizeof(sizeof(*desc)); | 276 | mapping += sizeof(*desc); |
| 277 | desc->ndesc = cpu_to_le32(mapping); | 277 | desc->ndesc = cpu_to_le32(mapping); |
| 278 | desc->vndescp = desc + 1; | 278 | desc->vndescp = desc + 1; |
| 279 | desc++; | 279 | desc++; |
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c index b5c1e663417d..ae7b697456b4 100644 --- a/drivers/net/s2io.c +++ b/drivers/net/s2io.c | |||
| @@ -2625,9 +2625,7 @@ static int fill_rx_buffers(struct ring_info *ring) | |||
| 2625 | rxdp1->Buffer0_ptr = pci_map_single | 2625 | rxdp1->Buffer0_ptr = pci_map_single |
| 2626 | (ring->pdev, skb->data, size - NET_IP_ALIGN, | 2626 | (ring->pdev, skb->data, size - NET_IP_ALIGN, |
| 2627 | PCI_DMA_FROMDEVICE); | 2627 | PCI_DMA_FROMDEVICE); |
| 2628 | if( (rxdp1->Buffer0_ptr == 0) || | 2628 | if(pci_dma_mapping_error(rxdp1->Buffer0_ptr)) |
| 2629 | (rxdp1->Buffer0_ptr == | ||
| 2630 | DMA_ERROR_CODE)) | ||
| 2631 | goto pci_map_failed; | 2629 | goto pci_map_failed; |
| 2632 | 2630 | ||
| 2633 | rxdp->Control_2 = | 2631 | rxdp->Control_2 = |
| @@ -2657,6 +2655,7 @@ static int fill_rx_buffers(struct ring_info *ring) | |||
| 2657 | skb->data = (void *) (unsigned long)tmp; | 2655 | skb->data = (void *) (unsigned long)tmp; |
| 2658 | skb_reset_tail_pointer(skb); | 2656 | skb_reset_tail_pointer(skb); |
| 2659 | 2657 | ||
| 2658 | /* AK: check is wrong. 0 can be valid dma address */ | ||
| 2660 | if (!(rxdp3->Buffer0_ptr)) | 2659 | if (!(rxdp3->Buffer0_ptr)) |
| 2661 | rxdp3->Buffer0_ptr = | 2660 | rxdp3->Buffer0_ptr = |
| 2662 | pci_map_single(ring->pdev, ba->ba_0, | 2661 | pci_map_single(ring->pdev, ba->ba_0, |
| @@ -2665,8 +2664,7 @@ static int fill_rx_buffers(struct ring_info *ring) | |||
| 2665 | pci_dma_sync_single_for_device(ring->pdev, | 2664 | pci_dma_sync_single_for_device(ring->pdev, |
| 2666 | (dma_addr_t) rxdp3->Buffer0_ptr, | 2665 | (dma_addr_t) rxdp3->Buffer0_ptr, |
| 2667 | BUF0_LEN, PCI_DMA_FROMDEVICE); | 2666 | BUF0_LEN, PCI_DMA_FROMDEVICE); |
| 2668 | if( (rxdp3->Buffer0_ptr == 0) || | 2667 | if (pci_dma_mapping_error(rxdp3->Buffer0_ptr)) |
| 2669 | (rxdp3->Buffer0_ptr == DMA_ERROR_CODE)) | ||
| 2670 | goto pci_map_failed; | 2668 | goto pci_map_failed; |
| 2671 | 2669 | ||
| 2672 | rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN); | 2670 | rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN); |
| @@ -2681,18 +2679,17 @@ static int fill_rx_buffers(struct ring_info *ring) | |||
| 2681 | (ring->pdev, skb->data, ring->mtu + 4, | 2679 | (ring->pdev, skb->data, ring->mtu + 4, |
| 2682 | PCI_DMA_FROMDEVICE); | 2680 | PCI_DMA_FROMDEVICE); |
| 2683 | 2681 | ||
| 2684 | if( (rxdp3->Buffer2_ptr == 0) || | 2682 | if (pci_dma_mapping_error(rxdp3->Buffer2_ptr)) |
| 2685 | (rxdp3->Buffer2_ptr == DMA_ERROR_CODE)) | ||
| 2686 | goto pci_map_failed; | 2683 | goto pci_map_failed; |
| 2687 | 2684 | ||
| 2685 | /* AK: check is wrong */ | ||
| 2688 | if (!rxdp3->Buffer1_ptr) | 2686 | if (!rxdp3->Buffer1_ptr) |
| 2689 | rxdp3->Buffer1_ptr = | 2687 | rxdp3->Buffer1_ptr = |
| 2690 | pci_map_single(ring->pdev, | 2688 | pci_map_single(ring->pdev, |
| 2691 | ba->ba_1, BUF1_LEN, | 2689 | ba->ba_1, BUF1_LEN, |
| 2692 | PCI_DMA_FROMDEVICE); | 2690 | PCI_DMA_FROMDEVICE); |
| 2693 | 2691 | ||
| 2694 | if( (rxdp3->Buffer1_ptr == 0) || | 2692 | if (pci_dma_mapping_error(rxdp3->Buffer1_ptr)) { |
| 2695 | (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) { | ||
| 2696 | pci_unmap_single | 2693 | pci_unmap_single |
| 2697 | (ring->pdev, | 2694 | (ring->pdev, |
| 2698 | (dma_addr_t)(unsigned long) | 2695 | (dma_addr_t)(unsigned long) |
| @@ -4264,16 +4261,14 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 4264 | txdp->Buffer_Pointer = pci_map_single(sp->pdev, | 4261 | txdp->Buffer_Pointer = pci_map_single(sp->pdev, |
| 4265 | fifo->ufo_in_band_v, | 4262 | fifo->ufo_in_band_v, |
| 4266 | sizeof(u64), PCI_DMA_TODEVICE); | 4263 | sizeof(u64), PCI_DMA_TODEVICE); |
| 4267 | if((txdp->Buffer_Pointer == 0) || | 4264 | if (pci_dma_mapping_error(txdp->Buffer_Pointer)) |
| 4268 | (txdp->Buffer_Pointer == DMA_ERROR_CODE)) | ||
| 4269 | goto pci_map_failed; | 4265 | goto pci_map_failed; |
| 4270 | txdp++; | 4266 | txdp++; |
| 4271 | } | 4267 | } |
| 4272 | 4268 | ||
| 4273 | txdp->Buffer_Pointer = pci_map_single | 4269 | txdp->Buffer_Pointer = pci_map_single |
| 4274 | (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE); | 4270 | (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE); |
| 4275 | if((txdp->Buffer_Pointer == 0) || | 4271 | if (pci_dma_mapping_error(txdp->Buffer_Pointer)) |
| 4276 | (txdp->Buffer_Pointer == DMA_ERROR_CODE)) | ||
| 4277 | goto pci_map_failed; | 4272 | goto pci_map_failed; |
| 4278 | 4273 | ||
| 4279 | txdp->Host_Control = (unsigned long) skb; | 4274 | txdp->Host_Control = (unsigned long) skb; |
| @@ -6884,10 +6879,8 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp, | |||
| 6884 | pci_map_single( sp->pdev, (*skb)->data, | 6879 | pci_map_single( sp->pdev, (*skb)->data, |
| 6885 | size - NET_IP_ALIGN, | 6880 | size - NET_IP_ALIGN, |
| 6886 | PCI_DMA_FROMDEVICE); | 6881 | PCI_DMA_FROMDEVICE); |
| 6887 | if( (rxdp1->Buffer0_ptr == 0) || | 6882 | if (pci_dma_mapping_error(rxdp1->Buffer0_ptr)) |
| 6888 | (rxdp1->Buffer0_ptr == DMA_ERROR_CODE)) { | ||
| 6889 | goto memalloc_failed; | 6883 | goto memalloc_failed; |
| 6890 | } | ||
| 6891 | rxdp->Host_Control = (unsigned long) (*skb); | 6884 | rxdp->Host_Control = (unsigned long) (*skb); |
| 6892 | } | 6885 | } |
| 6893 | } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) { | 6886 | } 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, | |||
| 6913 | pci_map_single(sp->pdev, (*skb)->data, | 6906 | pci_map_single(sp->pdev, (*skb)->data, |
| 6914 | dev->mtu + 4, | 6907 | dev->mtu + 4, |
| 6915 | PCI_DMA_FROMDEVICE); | 6908 | PCI_DMA_FROMDEVICE); |
| 6916 | if( (rxdp3->Buffer2_ptr == 0) || | 6909 | if (pci_dma_mapping_error(rxdp3->Buffer2_ptr)) |
| 6917 | (rxdp3->Buffer2_ptr == DMA_ERROR_CODE)) { | ||
| 6918 | goto memalloc_failed; | 6910 | goto memalloc_failed; |
| 6919 | } | ||
| 6920 | rxdp3->Buffer0_ptr = *temp0 = | 6911 | rxdp3->Buffer0_ptr = *temp0 = |
| 6921 | pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN, | 6912 | pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN, |
| 6922 | PCI_DMA_FROMDEVICE); | 6913 | PCI_DMA_FROMDEVICE); |
| 6923 | if( (rxdp3->Buffer0_ptr == 0) || | 6914 | if (pci_dma_mapping_error(rxdp3->Buffer0_ptr)) { |
| 6924 | (rxdp3->Buffer0_ptr == DMA_ERROR_CODE)) { | ||
| 6925 | pci_unmap_single (sp->pdev, | 6915 | pci_unmap_single (sp->pdev, |
| 6926 | (dma_addr_t)rxdp3->Buffer2_ptr, | 6916 | (dma_addr_t)rxdp3->Buffer2_ptr, |
| 6927 | dev->mtu + 4, PCI_DMA_FROMDEVICE); | 6917 | dev->mtu + 4, PCI_DMA_FROMDEVICE); |
| @@ -6933,8 +6923,7 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp, | |||
| 6933 | rxdp3->Buffer1_ptr = *temp1 = | 6923 | rxdp3->Buffer1_ptr = *temp1 = |
| 6934 | pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN, | 6924 | pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN, |
| 6935 | PCI_DMA_FROMDEVICE); | 6925 | PCI_DMA_FROMDEVICE); |
| 6936 | if( (rxdp3->Buffer1_ptr == 0) || | 6926 | if (pci_dma_mapping_error(rxdp3->Buffer1_ptr)) { |
| 6937 | (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) { | ||
| 6938 | pci_unmap_single (sp->pdev, | 6927 | pci_unmap_single (sp->pdev, |
| 6939 | (dma_addr_t)rxdp3->Buffer0_ptr, | 6928 | (dma_addr_t)rxdp3->Buffer0_ptr, |
| 6940 | BUF0_LEN, PCI_DMA_FROMDEVICE); | 6929 | BUF0_LEN, PCI_DMA_FROMDEVICE); |
diff --git a/drivers/net/s2io.h b/drivers/net/s2io.h index 4706f7f9acb6..1827b6686c98 100644 --- a/drivers/net/s2io.h +++ b/drivers/net/s2io.h | |||
| @@ -75,10 +75,6 @@ static int debug_level = ERR_DBG; | |||
| 75 | /* DEBUG message print. */ | 75 | /* DEBUG message print. */ |
| 76 | #define DBG_PRINT(dbg_level, args...) if(!(debug_level<dbg_level)) printk(args) | 76 | #define DBG_PRINT(dbg_level, args...) if(!(debug_level<dbg_level)) printk(args) |
| 77 | 77 | ||
| 78 | #ifndef DMA_ERROR_CODE | ||
| 79 | #define DMA_ERROR_CODE (~(dma_addr_t)0x0) | ||
| 80 | #endif | ||
| 81 | |||
| 82 | /* Protocol assist features of the NIC */ | 78 | /* Protocol assist features of the NIC */ |
| 83 | #define L3_CKSUM_OK 0xFFFF | 79 | #define L3_CKSUM_OK 0xFFFF |
| 84 | #define L4_CKSUM_OK 0xFFFF | 80 | #define L4_CKSUM_OK 0xFFFF |
diff --git a/drivers/net/tc35815.c b/drivers/net/tc35815.c index 10e4e85da3fc..b07b8cbadeaf 100644 --- a/drivers/net/tc35815.c +++ b/drivers/net/tc35815.c | |||
| @@ -1394,6 +1394,7 @@ tc35815_open(struct net_device *dev) | |||
| 1394 | tc35815_chip_init(dev); | 1394 | tc35815_chip_init(dev); |
| 1395 | spin_unlock_irq(&lp->lock); | 1395 | spin_unlock_irq(&lp->lock); |
| 1396 | 1396 | ||
| 1397 | netif_carrier_off(dev); | ||
| 1397 | /* schedule a link state check */ | 1398 | /* schedule a link state check */ |
| 1398 | phy_start(lp->phy_dev); | 1399 | phy_start(lp->phy_dev); |
| 1399 | 1400 | ||
| @@ -1735,7 +1736,6 @@ tc35815_rx(struct net_device *dev) | |||
| 1735 | skb = lp->rx_skbs[cur_bd].skb; | 1736 | skb = lp->rx_skbs[cur_bd].skb; |
| 1736 | prefetch(skb->data); | 1737 | prefetch(skb->data); |
| 1737 | lp->rx_skbs[cur_bd].skb = NULL; | 1738 | lp->rx_skbs[cur_bd].skb = NULL; |
| 1738 | lp->fbl_count--; | ||
| 1739 | pci_unmap_single(lp->pci_dev, | 1739 | pci_unmap_single(lp->pci_dev, |
| 1740 | lp->rx_skbs[cur_bd].skb_dma, | 1740 | lp->rx_skbs[cur_bd].skb_dma, |
| 1741 | RX_BUF_SIZE, PCI_DMA_FROMDEVICE); | 1741 | RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| @@ -1791,6 +1791,7 @@ tc35815_rx(struct net_device *dev) | |||
| 1791 | #ifdef TC35815_USE_PACKEDBUFFER | 1791 | #ifdef TC35815_USE_PACKEDBUFFER |
| 1792 | while (lp->fbl_curid != id) | 1792 | while (lp->fbl_curid != id) |
| 1793 | #else | 1793 | #else |
| 1794 | lp->fbl_count--; | ||
| 1794 | while (lp->fbl_count < RX_BUF_NUM) | 1795 | while (lp->fbl_count < RX_BUF_NUM) |
| 1795 | #endif | 1796 | #endif |
| 1796 | { | 1797 | { |
| @@ -2453,6 +2454,7 @@ static int tc35815_resume(struct pci_dev *pdev) | |||
| 2453 | return 0; | 2454 | return 0; |
| 2454 | pci_set_power_state(pdev, PCI_D0); | 2455 | pci_set_power_state(pdev, PCI_D0); |
| 2455 | tc35815_restart(dev); | 2456 | tc35815_restart(dev); |
| 2457 | netif_carrier_off(dev); | ||
| 2456 | if (lp->phy_dev) | 2458 | if (lp->phy_dev) |
| 2457 | phy_start(lp->phy_dev); | 2459 | phy_start(lp->phy_dev); |
| 2458 | netif_device_attach(dev); | 2460 | netif_device_attach(dev); |
diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c index 249e18053d5f..069f8bb0a99f 100644 --- a/drivers/net/wan/x25_asy.c +++ b/drivers/net/wan/x25_asy.c | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #include <linux/x25.h> | 32 | #include <linux/x25.h> |
| 33 | #include <linux/lapb.h> | 33 | #include <linux/lapb.h> |
| 34 | #include <linux/init.h> | 34 | #include <linux/init.h> |
| 35 | #include <linux/rtnetlink.h> | ||
| 35 | #include "x25_asy.h" | 36 | #include "x25_asy.h" |
| 36 | 37 | ||
| 37 | #include <net/x25device.h> | 38 | #include <net/x25device.h> |
| @@ -601,8 +602,10 @@ static void x25_asy_close_tty(struct tty_struct *tty) | |||
| 601 | if (!sl || sl->magic != X25_ASY_MAGIC) | 602 | if (!sl || sl->magic != X25_ASY_MAGIC) |
| 602 | return; | 603 | return; |
| 603 | 604 | ||
| 605 | rtnl_lock(); | ||
| 604 | if (sl->dev->flags & IFF_UP) | 606 | if (sl->dev->flags & IFF_UP) |
| 605 | dev_close(sl->dev); | 607 | dev_close(sl->dev); |
| 608 | rtnl_unlock(); | ||
| 606 | 609 | ||
| 607 | tty->disc_data = NULL; | 610 | tty->disc_data = NULL; |
| 608 | sl->tty = NULL; | 611 | sl->tty = NULL; |
diff --git a/drivers/net/wireless/b43/leds.c b/drivers/net/wireless/b43/leds.c index 36a9c42df835..76f4c7bad8b8 100644 --- a/drivers/net/wireless/b43/leds.c +++ b/drivers/net/wireless/b43/leds.c | |||
| @@ -72,6 +72,9 @@ static void b43_led_brightness_set(struct led_classdev *led_dev, | |||
| 72 | struct b43_wldev *dev = led->dev; | 72 | struct b43_wldev *dev = led->dev; |
| 73 | bool radio_enabled; | 73 | bool radio_enabled; |
| 74 | 74 | ||
| 75 | if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) | ||
| 76 | return; | ||
| 77 | |||
| 75 | /* Checking the radio-enabled status here is slightly racy, | 78 | /* Checking the radio-enabled status here is slightly racy, |
| 76 | * but we want to avoid the locking overhead and we don't care | 79 | * but we want to avoid the locking overhead and we don't care |
| 77 | * whether the LED has the wrong state for a second. */ | 80 | * whether the LED has the wrong state for a second. */ |
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c index fa4b0d8b74a2..a70827793086 100644 --- a/drivers/net/wireless/b43/main.c +++ b/drivers/net/wireless/b43/main.c | |||
| @@ -2883,12 +2883,11 @@ static int b43_op_tx(struct ieee80211_hw *hw, | |||
| 2883 | 2883 | ||
| 2884 | if (unlikely(skb->len < 2 + 2 + 6)) { | 2884 | if (unlikely(skb->len < 2 + 2 + 6)) { |
| 2885 | /* Too short, this can't be a valid frame. */ | 2885 | /* Too short, this can't be a valid frame. */ |
| 2886 | dev_kfree_skb_any(skb); | 2886 | goto drop_packet; |
| 2887 | return NETDEV_TX_OK; | ||
| 2888 | } | 2887 | } |
| 2889 | B43_WARN_ON(skb_shinfo(skb)->nr_frags); | 2888 | B43_WARN_ON(skb_shinfo(skb)->nr_frags); |
| 2890 | if (unlikely(!dev)) | 2889 | if (unlikely(!dev)) |
| 2891 | return NETDEV_TX_BUSY; | 2890 | goto drop_packet; |
| 2892 | 2891 | ||
| 2893 | /* Transmissions on seperate queues can run concurrently. */ | 2892 | /* Transmissions on seperate queues can run concurrently. */ |
| 2894 | read_lock_irqsave(&wl->tx_lock, flags); | 2893 | read_lock_irqsave(&wl->tx_lock, flags); |
| @@ -2904,7 +2903,12 @@ static int b43_op_tx(struct ieee80211_hw *hw, | |||
| 2904 | read_unlock_irqrestore(&wl->tx_lock, flags); | 2903 | read_unlock_irqrestore(&wl->tx_lock, flags); |
| 2905 | 2904 | ||
| 2906 | if (unlikely(err)) | 2905 | if (unlikely(err)) |
| 2907 | return NETDEV_TX_BUSY; | 2906 | goto drop_packet; |
| 2907 | return NETDEV_TX_OK; | ||
| 2908 | |||
| 2909 | drop_packet: | ||
| 2910 | /* We can not transmit this packet. Drop it. */ | ||
| 2911 | dev_kfree_skb_any(skb); | ||
| 2908 | return NETDEV_TX_OK; | 2912 | return NETDEV_TX_OK; |
| 2909 | } | 2913 | } |
| 2910 | 2914 | ||
diff --git a/drivers/net/wireless/b43legacy/dma.c b/drivers/net/wireless/b43legacy/dma.c index c990f87b107a..93ddc1cbcc8b 100644 --- a/drivers/net/wireless/b43legacy/dma.c +++ b/drivers/net/wireless/b43legacy/dma.c | |||
| @@ -876,6 +876,7 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev, | |||
| 876 | if (!ring) | 876 | if (!ring) |
| 877 | goto out; | 877 | goto out; |
| 878 | ring->type = type; | 878 | ring->type = type; |
| 879 | ring->dev = dev; | ||
| 879 | 880 | ||
| 880 | nr_slots = B43legacy_RXRING_SLOTS; | 881 | nr_slots = B43legacy_RXRING_SLOTS; |
| 881 | if (for_tx) | 882 | if (for_tx) |
| @@ -922,7 +923,6 @@ struct b43legacy_dmaring *b43legacy_setup_dmaring(struct b43legacy_wldev *dev, | |||
| 922 | DMA_TO_DEVICE); | 923 | DMA_TO_DEVICE); |
| 923 | } | 924 | } |
| 924 | 925 | ||
| 925 | ring->dev = dev; | ||
| 926 | ring->nr_slots = nr_slots; | 926 | ring->nr_slots = nr_slots; |
| 927 | ring->mmio_base = b43legacy_dmacontroller_base(type, controller_index); | 927 | ring->mmio_base = b43legacy_dmacontroller_base(type, controller_index); |
| 928 | ring->index = controller_index; | 928 | ring->index = controller_index; |
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c index 204077c13870..3e612d0a13e8 100644 --- a/drivers/net/wireless/b43legacy/main.c +++ b/drivers/net/wireless/b43legacy/main.c | |||
| @@ -2378,8 +2378,10 @@ static int b43legacy_op_tx(struct ieee80211_hw *hw, | |||
| 2378 | } else | 2378 | } else |
| 2379 | err = b43legacy_dma_tx(dev, skb, ctl); | 2379 | err = b43legacy_dma_tx(dev, skb, ctl); |
| 2380 | out: | 2380 | out: |
| 2381 | if (unlikely(err)) | 2381 | if (unlikely(err)) { |
| 2382 | return NETDEV_TX_BUSY; | 2382 | /* Drop the packet. */ |
| 2383 | dev_kfree_skb_any(skb); | ||
| 2384 | } | ||
| 2383 | return NETDEV_TX_OK; | 2385 | return NETDEV_TX_OK; |
| 2384 | } | 2386 | } |
| 2385 | 2387 | ||
diff --git a/drivers/net/wireless/hostap/hostap_80211_rx.c b/drivers/net/wireless/hostap/hostap_80211_rx.c index 4fd73809602e..020f450e9dba 100644 --- a/drivers/net/wireless/hostap/hostap_80211_rx.c +++ b/drivers/net/wireless/hostap/hostap_80211_rx.c | |||
| @@ -64,7 +64,7 @@ int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb, | |||
| 64 | int hdrlen, phdrlen, head_need, tail_need; | 64 | int hdrlen, phdrlen, head_need, tail_need; |
| 65 | u16 fc; | 65 | u16 fc; |
| 66 | int prism_header, ret; | 66 | int prism_header, ret; |
| 67 | struct ieee80211_hdr_4addr *hdr; | 67 | struct ieee80211_hdr_4addr *fhdr; |
| 68 | 68 | ||
| 69 | iface = netdev_priv(dev); | 69 | iface = netdev_priv(dev); |
| 70 | local = iface->local; | 70 | local = iface->local; |
| @@ -83,8 +83,8 @@ int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb, | |||
| 83 | phdrlen = 0; | 83 | phdrlen = 0; |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | hdr = (struct ieee80211_hdr_4addr *) skb->data; | 86 | fhdr = (struct ieee80211_hdr_4addr *) skb->data; |
| 87 | fc = le16_to_cpu(hdr->frame_ctl); | 87 | fc = le16_to_cpu(fhdr->frame_ctl); |
| 88 | 88 | ||
| 89 | if (type == PRISM2_RX_MGMT && (fc & IEEE80211_FCTL_VERS)) { | 89 | if (type == PRISM2_RX_MGMT && (fc & IEEE80211_FCTL_VERS)) { |
| 90 | printk(KERN_DEBUG "%s: dropped management frame with header " | 90 | 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, | |||
| 551 | hdr->addr1[2] != 0xff || hdr->addr1[3] != 0xff || | 551 | hdr->addr1[2] != 0xff || hdr->addr1[3] != 0xff || |
| 552 | hdr->addr1[4] != 0xff || hdr->addr1[5] != 0xff)) { | 552 | hdr->addr1[4] != 0xff || hdr->addr1[5] != 0xff)) { |
| 553 | /* RA (or BSSID) is not ours - drop */ | 553 | /* RA (or BSSID) is not ours - drop */ |
| 554 | PDEBUG(DEBUG_EXTRA, "%s: received WDS frame with " | 554 | PDEBUG(DEBUG_EXTRA2, "%s: received WDS frame with " |
| 555 | "not own or broadcast %s=%s\n", | 555 | "not own or broadcast %s=%s\n", |
| 556 | local->dev->name, | 556 | local->dev->name, |
| 557 | fc & IEEE80211_FCTL_FROMDS ? "RA" : "BSSID", | 557 | fc & IEEE80211_FCTL_FROMDS ? "RA" : "BSSID", |
diff --git a/drivers/net/wireless/hostap/hostap_ap.c b/drivers/net/wireless/hostap/hostap_ap.c index 0acd9589c48c..ab981afd481d 100644 --- a/drivers/net/wireless/hostap/hostap_ap.c +++ b/drivers/net/wireless/hostap/hostap_ap.c | |||
| @@ -1930,7 +1930,7 @@ static void handle_pspoll(local_info_t *local, | |||
| 1930 | PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n"); | 1930 | PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n"); |
| 1931 | return; | 1931 | return; |
| 1932 | } | 1932 | } |
| 1933 | aid &= ~BIT(15) & ~BIT(14); | 1933 | aid &= ~(BIT(15) | BIT(14)); |
| 1934 | if (aid == 0 || aid > MAX_AID_TABLE_SIZE) { | 1934 | if (aid == 0 || aid > MAX_AID_TABLE_SIZE) { |
| 1935 | PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid); | 1935 | PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid); |
| 1936 | return; | 1936 | return; |
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c index ed4317a17cbb..80039a0ae027 100644 --- a/drivers/net/wireless/hostap/hostap_cs.c +++ b/drivers/net/wireless/hostap/hostap_cs.c | |||
| @@ -533,10 +533,10 @@ static void prism2_detach(struct pcmcia_device *link) | |||
| 533 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) | 533 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) |
| 534 | 534 | ||
| 535 | #define CFG_CHECK2(fn, retf) \ | 535 | #define CFG_CHECK2(fn, retf) \ |
| 536 | do { int ret = (retf); \ | 536 | do { int _ret = (retf); \ |
| 537 | if (ret != 0) { \ | 537 | if (_ret != 0) { \ |
| 538 | PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \ | 538 | PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", _ret); \ |
| 539 | cs_error(link, fn, ret); \ | 539 | cs_error(link, fn, _ret); \ |
| 540 | goto next_entry; \ | 540 | goto next_entry; \ |
| 541 | } \ | 541 | } \ |
| 542 | } while (0) | 542 | } while (0) |
diff --git a/drivers/net/wireless/hostap/hostap_hw.c b/drivers/net/wireless/hostap/hostap_hw.c index cdf90c40f11b..936f52e3d95c 100644 --- a/drivers/net/wireless/hostap/hostap_hw.c +++ b/drivers/net/wireless/hostap/hostap_hw.c | |||
| @@ -2835,7 +2835,7 @@ static void hostap_passive_scan(unsigned long data) | |||
| 2835 | { | 2835 | { |
| 2836 | local_info_t *local = (local_info_t *) data; | 2836 | local_info_t *local = (local_info_t *) data; |
| 2837 | struct net_device *dev = local->dev; | 2837 | struct net_device *dev = local->dev; |
| 2838 | u16 channel; | 2838 | u16 chan; |
| 2839 | 2839 | ||
| 2840 | if (local->passive_scan_interval <= 0) | 2840 | if (local->passive_scan_interval <= 0) |
| 2841 | return; | 2841 | return; |
| @@ -2872,11 +2872,11 @@ static void hostap_passive_scan(unsigned long data) | |||
| 2872 | 2872 | ||
| 2873 | printk(KERN_DEBUG "%s: passive scan channel %d\n", | 2873 | printk(KERN_DEBUG "%s: passive scan channel %d\n", |
| 2874 | dev->name, local->passive_scan_channel); | 2874 | dev->name, local->passive_scan_channel); |
| 2875 | channel = local->passive_scan_channel; | 2875 | chan = local->passive_scan_channel; |
| 2876 | local->passive_scan_state = PASSIVE_SCAN_WAIT; | 2876 | local->passive_scan_state = PASSIVE_SCAN_WAIT; |
| 2877 | local->passive_scan_timer.expires = jiffies + HZ / 10; | 2877 | local->passive_scan_timer.expires = jiffies + HZ / 10; |
| 2878 | } else { | 2878 | } else { |
| 2879 | channel = local->channel; | 2879 | chan = local->channel; |
| 2880 | local->passive_scan_state = PASSIVE_SCAN_LISTEN; | 2880 | local->passive_scan_state = PASSIVE_SCAN_LISTEN; |
| 2881 | local->passive_scan_timer.expires = jiffies + | 2881 | local->passive_scan_timer.expires = jiffies + |
| 2882 | local->passive_scan_interval * HZ; | 2882 | local->passive_scan_interval * HZ; |
| @@ -2884,9 +2884,9 @@ static void hostap_passive_scan(unsigned long data) | |||
| 2884 | 2884 | ||
| 2885 | if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_TEST | | 2885 | if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_TEST | |
| 2886 | (HFA384X_TEST_CHANGE_CHANNEL << 8), | 2886 | (HFA384X_TEST_CHANGE_CHANNEL << 8), |
| 2887 | channel, NULL, 0)) | 2887 | chan, NULL, 0)) |
| 2888 | printk(KERN_ERR "%s: passive scan channel set %d " | 2888 | printk(KERN_ERR "%s: passive scan channel set %d " |
| 2889 | "failed\n", dev->name, channel); | 2889 | "failed\n", dev->name, chan); |
| 2890 | 2890 | ||
| 2891 | add_timer(&local->passive_scan_timer); | 2891 | add_timer(&local->passive_scan_timer); |
| 2892 | } | 2892 | } |
diff --git a/drivers/net/wireless/hostap/hostap_main.c b/drivers/net/wireless/hostap/hostap_main.c index f7aec9309d04..a38e85f334df 100644 --- a/drivers/net/wireless/hostap/hostap_main.c +++ b/drivers/net/wireless/hostap/hostap_main.c | |||
| @@ -594,7 +594,8 @@ void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx) | |||
| 594 | } | 594 | } |
| 595 | 595 | ||
| 596 | 596 | ||
| 597 | int hostap_80211_header_parse(const struct sk_buff *skb, unsigned char *haddr) | 597 | static int hostap_80211_header_parse(const struct sk_buff *skb, |
| 598 | unsigned char *haddr) | ||
| 598 | { | 599 | { |
| 599 | struct hostap_interface *iface = netdev_priv(skb->dev); | 600 | struct hostap_interface *iface = netdev_priv(skb->dev); |
| 600 | local_info_t *local = iface->local; | 601 | local_info_t *local = iface->local; |
| @@ -857,7 +858,6 @@ const struct header_ops hostap_80211_ops = { | |||
| 857 | .rebuild = eth_rebuild_header, | 858 | .rebuild = eth_rebuild_header, |
| 858 | .cache = eth_header_cache, | 859 | .cache = eth_header_cache, |
| 859 | .cache_update = eth_header_cache_update, | 860 | .cache_update = eth_header_cache_update, |
| 860 | |||
| 861 | .parse = hostap_80211_header_parse, | 861 | .parse = hostap_80211_header_parse, |
| 862 | }; | 862 | }; |
| 863 | EXPORT_SYMBOL(hostap_80211_ops); | 863 | EXPORT_SYMBOL(hostap_80211_ops); |
| @@ -1150,7 +1150,6 @@ EXPORT_SYMBOL(hostap_set_roaming); | |||
| 1150 | EXPORT_SYMBOL(hostap_set_auth_algs); | 1150 | EXPORT_SYMBOL(hostap_set_auth_algs); |
| 1151 | EXPORT_SYMBOL(hostap_dump_rx_header); | 1151 | EXPORT_SYMBOL(hostap_dump_rx_header); |
| 1152 | EXPORT_SYMBOL(hostap_dump_tx_header); | 1152 | EXPORT_SYMBOL(hostap_dump_tx_header); |
| 1153 | EXPORT_SYMBOL(hostap_80211_header_parse); | ||
| 1154 | EXPORT_SYMBOL(hostap_80211_get_hdrlen); | 1153 | EXPORT_SYMBOL(hostap_80211_get_hdrlen); |
| 1155 | EXPORT_SYMBOL(hostap_get_stats); | 1154 | EXPORT_SYMBOL(hostap_get_stats); |
| 1156 | EXPORT_SYMBOL(hostap_setup_dev); | 1155 | EXPORT_SYMBOL(hostap_setup_dev); |
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c index 13925b627e3b..b1b3c523185d 100644 --- a/drivers/net/wireless/iwlwifi/iwl3945-base.c +++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c | |||
| @@ -2227,7 +2227,10 @@ static int iwl3945_scan_initiate(struct iwl3945_priv *priv) | |||
| 2227 | } | 2227 | } |
| 2228 | 2228 | ||
| 2229 | IWL_DEBUG_INFO("Starting scan...\n"); | 2229 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 2230 | priv->scan_bands = 2; | 2230 | if (priv->cfg->sku & IWL_SKU_G) |
| 2231 | priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ); | ||
| 2232 | if (priv->cfg->sku & IWL_SKU_A) | ||
| 2233 | priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ); | ||
| 2231 | set_bit(STATUS_SCANNING, &priv->status); | 2234 | set_bit(STATUS_SCANNING, &priv->status); |
| 2232 | priv->scan_start = jiffies; | 2235 | priv->scan_start = jiffies; |
| 2233 | priv->scan_pass_start = priv->scan_start; | 2236 | priv->scan_pass_start = priv->scan_start; |
| @@ -3352,13 +3355,18 @@ static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv *priv, | |||
| 3352 | cancel_delayed_work(&priv->scan_check); | 3355 | cancel_delayed_work(&priv->scan_check); |
| 3353 | 3356 | ||
| 3354 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", | 3357 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 3355 | (priv->scan_bands == 2) ? "2.4" : "5.2", | 3358 | (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ? |
| 3359 | "2.4" : "5.2", | ||
| 3356 | jiffies_to_msecs(elapsed_jiffies | 3360 | jiffies_to_msecs(elapsed_jiffies |
| 3357 | (priv->scan_pass_start, jiffies))); | 3361 | (priv->scan_pass_start, jiffies))); |
| 3358 | 3362 | ||
| 3359 | /* Remove this scanned band from the list | 3363 | /* Remove this scanned band from the list of pending |
| 3360 | * of pending bands to scan */ | 3364 | * bands to scan, band G precedes A in order of scanning |
| 3361 | priv->scan_bands--; | 3365 | * as seen in iwl3945_bg_request_scan */ |
| 3366 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) | ||
| 3367 | priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ); | ||
| 3368 | else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) | ||
| 3369 | priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ); | ||
| 3362 | 3370 | ||
| 3363 | /* If a request to abort was given, or the scan did not succeed | 3371 | /* If a request to abort was given, or the scan did not succeed |
| 3364 | * then we reset the scan state machine and terminate, | 3372 | * then we reset the scan state machine and terminate, |
| @@ -4972,7 +4980,7 @@ static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, | |||
| 4972 | 4980 | ||
| 4973 | ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel); | 4981 | ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel); |
| 4974 | if (!is_channel_valid(ch_info)) { | 4982 | if (!is_channel_valid(ch_info)) { |
| 4975 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", | 4983 | IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n", |
| 4976 | scan_ch->channel); | 4984 | scan_ch->channel); |
| 4977 | continue; | 4985 | continue; |
| 4978 | } | 4986 | } |
| @@ -6315,21 +6323,16 @@ static void iwl3945_bg_request_scan(struct work_struct *data) | |||
| 6315 | 6323 | ||
| 6316 | /* flags + rate selection */ | 6324 | /* flags + rate selection */ |
| 6317 | 6325 | ||
| 6318 | switch (priv->scan_bands) { | 6326 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) { |
| 6319 | case 2: | ||
| 6320 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; | 6327 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 6321 | scan->tx_cmd.rate = IWL_RATE_1M_PLCP; | 6328 | scan->tx_cmd.rate = IWL_RATE_1M_PLCP; |
| 6322 | scan->good_CRC_th = 0; | 6329 | scan->good_CRC_th = 0; |
| 6323 | band = IEEE80211_BAND_2GHZ; | 6330 | band = IEEE80211_BAND_2GHZ; |
| 6324 | break; | 6331 | } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { |
| 6325 | |||
| 6326 | case 1: | ||
| 6327 | scan->tx_cmd.rate = IWL_RATE_6M_PLCP; | 6332 | scan->tx_cmd.rate = IWL_RATE_6M_PLCP; |
| 6328 | scan->good_CRC_th = IWL_GOOD_CRC_TH; | 6333 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
| 6329 | band = IEEE80211_BAND_5GHZ; | 6334 | band = IEEE80211_BAND_5GHZ; |
| 6330 | break; | 6335 | } else { |
| 6331 | |||
| 6332 | default: | ||
| 6333 | IWL_WARNING("Invalid scan band count\n"); | 6336 | IWL_WARNING("Invalid scan band count\n"); |
| 6334 | goto done; | 6337 | goto done; |
| 6335 | } | 6338 | } |
| @@ -6770,7 +6773,7 @@ static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co | |||
| 6770 | ch_info = iwl3945_get_channel_info(priv, conf->channel->band, | 6773 | ch_info = iwl3945_get_channel_info(priv, conf->channel->band, |
| 6771 | conf->channel->hw_value); | 6774 | conf->channel->hw_value); |
| 6772 | if (!is_channel_valid(ch_info)) { | 6775 | if (!is_channel_valid(ch_info)) { |
| 6773 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n", | 6776 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n", |
| 6774 | conf->channel->hw_value, conf->channel->band); | 6777 | conf->channel->hw_value, conf->channel->band); |
| 6775 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); | 6778 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 6776 | spin_unlock_irqrestore(&priv->lock, flags); | 6779 | spin_unlock_irqrestore(&priv->lock, flags); |
diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c index 883b42f7e998..5ed16ce78468 100644 --- a/drivers/net/wireless/iwlwifi/iwl4965-base.c +++ b/drivers/net/wireless/iwlwifi/iwl4965-base.c | |||
| @@ -1774,7 +1774,10 @@ static int iwl4965_scan_initiate(struct iwl_priv *priv) | |||
| 1774 | } | 1774 | } |
| 1775 | 1775 | ||
| 1776 | IWL_DEBUG_INFO("Starting scan...\n"); | 1776 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 1777 | priv->scan_bands = 2; | 1777 | if (priv->cfg->sku & IWL_SKU_G) |
| 1778 | priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ); | ||
| 1779 | if (priv->cfg->sku & IWL_SKU_A) | ||
| 1780 | priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ); | ||
| 1778 | set_bit(STATUS_SCANNING, &priv->status); | 1781 | set_bit(STATUS_SCANNING, &priv->status); |
| 1779 | priv->scan_start = jiffies; | 1782 | priv->scan_start = jiffies; |
| 1780 | priv->scan_pass_start = priv->scan_start; | 1783 | priv->scan_pass_start = priv->scan_start; |
| @@ -3023,8 +3026,9 @@ static void iwl4965_rx_reply_tx(struct iwl_priv *priv, | |||
| 3023 | 3026 | ||
| 3024 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); | 3027 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
| 3025 | if (index != -1) { | 3028 | if (index != -1) { |
| 3026 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); | ||
| 3027 | #ifdef CONFIG_IWL4965_HT | 3029 | #ifdef CONFIG_IWL4965_HT |
| 3030 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); | ||
| 3031 | |||
| 3028 | if (tid != MAX_TID_COUNT) | 3032 | if (tid != MAX_TID_COUNT) |
| 3029 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; | 3033 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 3030 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && | 3034 | 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, | |||
| 3276 | cancel_delayed_work(&priv->scan_check); | 3280 | cancel_delayed_work(&priv->scan_check); |
| 3277 | 3281 | ||
| 3278 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", | 3282 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 3279 | (priv->scan_bands == 2) ? "2.4" : "5.2", | 3283 | (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ? |
| 3284 | "2.4" : "5.2", | ||
| 3280 | jiffies_to_msecs(elapsed_jiffies | 3285 | jiffies_to_msecs(elapsed_jiffies |
| 3281 | (priv->scan_pass_start, jiffies))); | 3286 | (priv->scan_pass_start, jiffies))); |
| 3282 | 3287 | ||
| 3283 | /* Remove this scanned band from the list | 3288 | /* Remove this scanned band from the list of pending |
| 3284 | * of pending bands to scan */ | 3289 | * bands to scan, band G precedes A in order of scanning |
| 3285 | priv->scan_bands--; | 3290 | * as seen in iwl_bg_request_scan */ |
| 3291 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) | ||
| 3292 | priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ); | ||
| 3293 | else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) | ||
| 3294 | priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ); | ||
| 3286 | 3295 | ||
| 3287 | /* If a request to abort was given, or the scan did not succeed | 3296 | /* If a request to abort was given, or the scan did not succeed |
| 3288 | * then we reset the scan state machine and terminate, | 3297 | * then we reset the scan state machine and terminate, |
| @@ -3292,7 +3301,7 @@ static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, | |||
| 3292 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); | 3301 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 3293 | } else { | 3302 | } else { |
| 3294 | /* If there are more bands on this scan pass reschedule */ | 3303 | /* If there are more bands on this scan pass reschedule */ |
| 3295 | if (priv->scan_bands > 0) | 3304 | if (priv->scan_bands) |
| 3296 | goto reschedule; | 3305 | goto reschedule; |
| 3297 | } | 3306 | } |
| 3298 | 3307 | ||
| @@ -4635,10 +4644,9 @@ static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, | |||
| 4635 | 4644 | ||
| 4636 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); | 4645 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
| 4637 | 4646 | ||
| 4638 | ch_info = iwl_get_channel_info(priv, band, | 4647 | ch_info = iwl_get_channel_info(priv, band, scan_ch->channel); |
| 4639 | scan_ch->channel); | ||
| 4640 | if (!is_channel_valid(ch_info)) { | 4648 | if (!is_channel_valid(ch_info)) { |
| 4641 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", | 4649 | IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n", |
| 4642 | scan_ch->channel); | 4650 | scan_ch->channel); |
| 4643 | continue; | 4651 | continue; |
| 4644 | } | 4652 | } |
| @@ -5830,8 +5838,7 @@ static void iwl4965_bg_request_scan(struct work_struct *data) | |||
| 5830 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; | 5838 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 5831 | 5839 | ||
| 5832 | 5840 | ||
| 5833 | switch (priv->scan_bands) { | 5841 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) { |
| 5834 | case 2: | ||
| 5835 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; | 5842 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 5836 | scan->tx_cmd.rate_n_flags = | 5843 | scan->tx_cmd.rate_n_flags = |
| 5837 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, | 5844 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
| @@ -5839,17 +5846,13 @@ static void iwl4965_bg_request_scan(struct work_struct *data) | |||
| 5839 | 5846 | ||
| 5840 | scan->good_CRC_th = 0; | 5847 | scan->good_CRC_th = 0; |
| 5841 | band = IEEE80211_BAND_2GHZ; | 5848 | band = IEEE80211_BAND_2GHZ; |
| 5842 | break; | 5849 | } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { |
| 5843 | |||
| 5844 | case 1: | ||
| 5845 | scan->tx_cmd.rate_n_flags = | 5850 | scan->tx_cmd.rate_n_flags = |
| 5846 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, | 5851 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
| 5847 | RATE_MCS_ANT_B_MSK); | 5852 | RATE_MCS_ANT_B_MSK); |
| 5848 | scan->good_CRC_th = IWL_GOOD_CRC_TH; | 5853 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
| 5849 | band = IEEE80211_BAND_5GHZ; | 5854 | band = IEEE80211_BAND_5GHZ; |
| 5850 | break; | 5855 | } else { |
| 5851 | |||
| 5852 | default: | ||
| 5853 | IWL_WARNING("Invalid scan band count\n"); | 5856 | IWL_WARNING("Invalid scan band count\n"); |
| 5854 | goto done; | 5857 | goto done; |
| 5855 | } | 5858 | } |
diff --git a/drivers/net/wireless/prism54/islpci_eth.c b/drivers/net/wireless/prism54/islpci_eth.c index 762e85bef55d..e43bae97ed8f 100644 --- a/drivers/net/wireless/prism54/islpci_eth.c +++ b/drivers/net/wireless/prism54/islpci_eth.c | |||
| @@ -290,7 +290,7 @@ islpci_monitor_rx(islpci_private *priv, struct sk_buff **skb) | |||
| 290 | 290 | ||
| 291 | avs->version = cpu_to_be32(P80211CAPTURE_VERSION); | 291 | avs->version = cpu_to_be32(P80211CAPTURE_VERSION); |
| 292 | avs->length = cpu_to_be32(sizeof (struct avs_80211_1_header)); | 292 | avs->length = cpu_to_be32(sizeof (struct avs_80211_1_header)); |
| 293 | avs->mactime = cpu_to_be64(le64_to_cpu(clock)); | 293 | avs->mactime = cpu_to_be64(clock); |
| 294 | avs->hosttime = cpu_to_be64(jiffies); | 294 | avs->hosttime = cpu_to_be64(jiffies); |
| 295 | avs->phytype = cpu_to_be32(6); /*OFDM: 6 for (g), 8 for (a) */ | 295 | avs->phytype = cpu_to_be32(6); /*OFDM: 6 for (g), 8 for (a) */ |
| 296 | avs->channel = cpu_to_be32(channel_of_freq(freq)); | 296 | avs->channel = cpu_to_be32(channel_of_freq(freq)); |
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c index fdbd0ef2be4b..61e59c17a60a 100644 --- a/drivers/net/wireless/rt2x00/rt2500usb.c +++ b/drivers/net/wireless/rt2x00/rt2500usb.c | |||
| @@ -138,11 +138,8 @@ static void rt2500usb_bbp_write(struct rt2x00_dev *rt2x00dev, | |||
| 138 | * Wait until the BBP becomes ready. | 138 | * Wait until the BBP becomes ready. |
| 139 | */ | 139 | */ |
| 140 | reg = rt2500usb_bbp_check(rt2x00dev); | 140 | reg = rt2500usb_bbp_check(rt2x00dev); |
| 141 | if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) { | 141 | if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) |
| 142 | ERROR(rt2x00dev, "PHY_CSR8 register busy. Write failed.\n"); | 142 | goto exit_fail; |
| 143 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | ||
| 144 | return; | ||
| 145 | } | ||
| 146 | 143 | ||
| 147 | /* | 144 | /* |
| 148 | * Write the data into the BBP. | 145 | * Write the data into the BBP. |
| @@ -155,6 +152,13 @@ static void rt2500usb_bbp_write(struct rt2x00_dev *rt2x00dev, | |||
| 155 | rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg); | 152 | rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg); |
| 156 | 153 | ||
| 157 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | 154 | mutex_unlock(&rt2x00dev->usb_cache_mutex); |
| 155 | |||
| 156 | return; | ||
| 157 | |||
| 158 | exit_fail: | ||
| 159 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | ||
| 160 | |||
| 161 | ERROR(rt2x00dev, "PHY_CSR8 register busy. Write failed.\n"); | ||
| 158 | } | 162 | } |
| 159 | 163 | ||
| 160 | static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev, | 164 | static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev, |
| @@ -168,10 +172,8 @@ static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev, | |||
| 168 | * Wait until the BBP becomes ready. | 172 | * Wait until the BBP becomes ready. |
| 169 | */ | 173 | */ |
| 170 | reg = rt2500usb_bbp_check(rt2x00dev); | 174 | reg = rt2500usb_bbp_check(rt2x00dev); |
| 171 | if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) { | 175 | if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) |
| 172 | ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n"); | 176 | goto exit_fail; |
| 173 | return; | ||
| 174 | } | ||
| 175 | 177 | ||
| 176 | /* | 178 | /* |
| 177 | * Write the request into the BBP. | 179 | * Write the request into the BBP. |
| @@ -186,17 +188,21 @@ static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev, | |||
| 186 | * Wait until the BBP becomes ready. | 188 | * Wait until the BBP becomes ready. |
| 187 | */ | 189 | */ |
| 188 | reg = rt2500usb_bbp_check(rt2x00dev); | 190 | reg = rt2500usb_bbp_check(rt2x00dev); |
| 189 | if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) { | 191 | if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) |
| 190 | ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n"); | 192 | goto exit_fail; |
| 191 | *value = 0xff; | ||
| 192 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | ||
| 193 | return; | ||
| 194 | } | ||
| 195 | 193 | ||
| 196 | rt2500usb_register_read_lock(rt2x00dev, PHY_CSR7, ®); | 194 | rt2500usb_register_read_lock(rt2x00dev, PHY_CSR7, ®); |
| 197 | *value = rt2x00_get_field16(reg, PHY_CSR7_DATA); | 195 | *value = rt2x00_get_field16(reg, PHY_CSR7_DATA); |
| 198 | 196 | ||
| 199 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | 197 | mutex_unlock(&rt2x00dev->usb_cache_mutex); |
| 198 | |||
| 199 | return; | ||
| 200 | |||
| 201 | exit_fail: | ||
| 202 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | ||
| 203 | |||
| 204 | ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n"); | ||
| 205 | *value = 0xff; | ||
| 200 | } | 206 | } |
| 201 | 207 | ||
| 202 | static void rt2500usb_rf_write(struct rt2x00_dev *rt2x00dev, | 208 | static void rt2500usb_rf_write(struct rt2x00_dev *rt2x00dev, |
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h index 611d98320593..b4bf1e09cf9a 100644 --- a/drivers/net/wireless/rt2x00/rt2x00.h +++ b/drivers/net/wireless/rt2x00/rt2x00.h | |||
| @@ -821,6 +821,7 @@ struct rt2x00_dev { | |||
| 821 | /* | 821 | /* |
| 822 | * Scheduled work. | 822 | * Scheduled work. |
| 823 | */ | 823 | */ |
| 824 | struct workqueue_struct *workqueue; | ||
| 824 | struct work_struct intf_work; | 825 | struct work_struct intf_work; |
| 825 | struct work_struct filter_work; | 826 | struct work_struct filter_work; |
| 826 | 827 | ||
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c index 2673d568bcac..c997d4f28ab3 100644 --- a/drivers/net/wireless/rt2x00/rt2x00dev.c +++ b/drivers/net/wireless/rt2x00/rt2x00dev.c | |||
| @@ -75,7 +75,7 @@ static void rt2x00lib_start_link_tuner(struct rt2x00_dev *rt2x00dev) | |||
| 75 | 75 | ||
| 76 | rt2x00lib_reset_link_tuner(rt2x00dev); | 76 | rt2x00lib_reset_link_tuner(rt2x00dev); |
| 77 | 77 | ||
| 78 | queue_delayed_work(rt2x00dev->hw->workqueue, | 78 | queue_delayed_work(rt2x00dev->workqueue, |
| 79 | &rt2x00dev->link.work, LINK_TUNE_INTERVAL); | 79 | &rt2x00dev->link.work, LINK_TUNE_INTERVAL); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| @@ -137,14 +137,6 @@ void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev) | |||
| 137 | return; | 137 | return; |
| 138 | 138 | ||
| 139 | /* | 139 | /* |
| 140 | * Stop all scheduled work. | ||
| 141 | */ | ||
| 142 | if (work_pending(&rt2x00dev->intf_work)) | ||
| 143 | cancel_work_sync(&rt2x00dev->intf_work); | ||
| 144 | if (work_pending(&rt2x00dev->filter_work)) | ||
| 145 | cancel_work_sync(&rt2x00dev->filter_work); | ||
| 146 | |||
| 147 | /* | ||
| 148 | * Stop the TX queues. | 140 | * Stop the TX queues. |
| 149 | */ | 141 | */ |
| 150 | ieee80211_stop_queues(rt2x00dev->hw); | 142 | ieee80211_stop_queues(rt2x00dev->hw); |
| @@ -398,8 +390,8 @@ static void rt2x00lib_link_tuner(struct work_struct *work) | |||
| 398 | * Increase tuner counter, and reschedule the next link tuner run. | 390 | * Increase tuner counter, and reschedule the next link tuner run. |
| 399 | */ | 391 | */ |
| 400 | rt2x00dev->link.count++; | 392 | rt2x00dev->link.count++; |
| 401 | queue_delayed_work(rt2x00dev->hw->workqueue, &rt2x00dev->link.work, | 393 | queue_delayed_work(rt2x00dev->workqueue, |
| 402 | LINK_TUNE_INTERVAL); | 394 | &rt2x00dev->link.work, LINK_TUNE_INTERVAL); |
| 403 | } | 395 | } |
| 404 | 396 | ||
| 405 | static void rt2x00lib_packetfilter_scheduled(struct work_struct *work) | 397 | static void rt2x00lib_packetfilter_scheduled(struct work_struct *work) |
| @@ -433,6 +425,15 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac, | |||
| 433 | 425 | ||
| 434 | spin_unlock(&intf->lock); | 426 | spin_unlock(&intf->lock); |
| 435 | 427 | ||
| 428 | /* | ||
| 429 | * It is possible the radio was disabled while the work had been | ||
| 430 | * scheduled. If that happens we should return here immediately, | ||
| 431 | * note that in the spinlock protected area above the delayed_flags | ||
| 432 | * have been cleared correctly. | ||
| 433 | */ | ||
| 434 | if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags)) | ||
| 435 | return; | ||
| 436 | |||
| 436 | if (delayed_flags & DELAYED_UPDATE_BEACON) { | 437 | if (delayed_flags & DELAYED_UPDATE_BEACON) { |
| 437 | skb = ieee80211_beacon_get(rt2x00dev->hw, vif, &control); | 438 | skb = ieee80211_beacon_get(rt2x00dev->hw, vif, &control); |
| 438 | if (skb && rt2x00dev->ops->hw->beacon_update(rt2x00dev->hw, | 439 | if (skb && rt2x00dev->ops->hw->beacon_update(rt2x00dev->hw, |
| @@ -441,7 +442,7 @@ static void rt2x00lib_intf_scheduled_iter(void *data, u8 *mac, | |||
| 441 | } | 442 | } |
| 442 | 443 | ||
| 443 | if (delayed_flags & DELAYED_CONFIG_ERP) | 444 | if (delayed_flags & DELAYED_CONFIG_ERP) |
| 444 | rt2x00lib_config_erp(rt2x00dev, intf, &intf->conf); | 445 | rt2x00lib_config_erp(rt2x00dev, intf, &conf); |
| 445 | 446 | ||
| 446 | if (delayed_flags & DELAYED_LED_ASSOC) | 447 | if (delayed_flags & DELAYED_LED_ASSOC) |
| 447 | rt2x00leds_led_assoc(rt2x00dev, !!rt2x00dev->intf_associated); | 448 | rt2x00leds_led_assoc(rt2x00dev, !!rt2x00dev->intf_associated); |
| @@ -487,7 +488,7 @@ void rt2x00lib_beacondone(struct rt2x00_dev *rt2x00dev) | |||
| 487 | rt2x00lib_beacondone_iter, | 488 | rt2x00lib_beacondone_iter, |
| 488 | rt2x00dev); | 489 | rt2x00dev); |
| 489 | 490 | ||
| 490 | queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->intf_work); | 491 | queue_work(rt2x00dev->workqueue, &rt2x00dev->intf_work); |
| 491 | } | 492 | } |
| 492 | EXPORT_SYMBOL_GPL(rt2x00lib_beacondone); | 493 | EXPORT_SYMBOL_GPL(rt2x00lib_beacondone); |
| 493 | 494 | ||
| @@ -1130,6 +1131,10 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev) | |||
| 1130 | /* | 1131 | /* |
| 1131 | * Initialize configuration work. | 1132 | * Initialize configuration work. |
| 1132 | */ | 1133 | */ |
| 1134 | rt2x00dev->workqueue = create_singlethread_workqueue("rt2x00lib"); | ||
| 1135 | if (!rt2x00dev->workqueue) | ||
| 1136 | goto exit; | ||
| 1137 | |||
| 1133 | INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled); | 1138 | INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled); |
| 1134 | INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled); | 1139 | INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled); |
| 1135 | INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00lib_link_tuner); | 1140 | INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00lib_link_tuner); |
| @@ -1190,6 +1195,13 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev) | |||
| 1190 | rt2x00leds_unregister(rt2x00dev); | 1195 | rt2x00leds_unregister(rt2x00dev); |
| 1191 | 1196 | ||
| 1192 | /* | 1197 | /* |
| 1198 | * Stop all queued work. Note that most tasks will already be halted | ||
| 1199 | * during rt2x00lib_disable_radio() and rt2x00lib_uninitialize(). | ||
| 1200 | */ | ||
| 1201 | flush_workqueue(rt2x00dev->workqueue); | ||
| 1202 | destroy_workqueue(rt2x00dev->workqueue); | ||
| 1203 | |||
| 1204 | /* | ||
| 1193 | * Free ieee80211_hw memory. | 1205 | * Free ieee80211_hw memory. |
| 1194 | */ | 1206 | */ |
| 1195 | rt2x00lib_remove_hw(rt2x00dev); | 1207 | rt2x00lib_remove_hw(rt2x00dev); |
diff --git a/drivers/net/wireless/rt2x00/rt2x00mac.c b/drivers/net/wireless/rt2x00/rt2x00mac.c index 87e280a21971..9cb023edd2e9 100644 --- a/drivers/net/wireless/rt2x00/rt2x00mac.c +++ b/drivers/net/wireless/rt2x00/rt2x00mac.c | |||
| @@ -428,7 +428,7 @@ void rt2x00mac_configure_filter(struct ieee80211_hw *hw, | |||
| 428 | if (!test_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags)) | 428 | if (!test_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags)) |
| 429 | rt2x00dev->ops->lib->config_filter(rt2x00dev, *total_flags); | 429 | rt2x00dev->ops->lib->config_filter(rt2x00dev, *total_flags); |
| 430 | else | 430 | else |
| 431 | queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->filter_work); | 431 | queue_work(rt2x00dev->workqueue, &rt2x00dev->filter_work); |
| 432 | } | 432 | } |
| 433 | EXPORT_SYMBOL_GPL(rt2x00mac_configure_filter); | 433 | EXPORT_SYMBOL_GPL(rt2x00mac_configure_filter); |
| 434 | 434 | ||
| @@ -509,7 +509,7 @@ void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw, | |||
| 509 | memcpy(&intf->conf, bss_conf, sizeof(*bss_conf)); | 509 | memcpy(&intf->conf, bss_conf, sizeof(*bss_conf)); |
| 510 | if (delayed) { | 510 | if (delayed) { |
| 511 | intf->delayed_flags |= delayed; | 511 | intf->delayed_flags |= delayed; |
| 512 | queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->intf_work); | 512 | queue_work(rt2x00dev->workqueue, &rt2x00dev->intf_work); |
| 513 | } | 513 | } |
| 514 | spin_unlock(&intf->lock); | 514 | spin_unlock(&intf->lock); |
| 515 | } | 515 | } |
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c index fff8386e816b..83cc0147f698 100644 --- a/drivers/net/wireless/rt2x00/rt73usb.c +++ b/drivers/net/wireless/rt2x00/rt73usb.c | |||
| @@ -134,11 +134,8 @@ static void rt73usb_bbp_write(struct rt2x00_dev *rt2x00dev, | |||
| 134 | * Wait until the BBP becomes ready. | 134 | * Wait until the BBP becomes ready. |
| 135 | */ | 135 | */ |
| 136 | reg = rt73usb_bbp_check(rt2x00dev); | 136 | reg = rt73usb_bbp_check(rt2x00dev); |
| 137 | if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) { | 137 | if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) |
| 138 | ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n"); | 138 | goto exit_fail; |
| 139 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | ||
| 140 | return; | ||
| 141 | } | ||
| 142 | 139 | ||
| 143 | /* | 140 | /* |
| 144 | * Write the data into the BBP. | 141 | * Write the data into the BBP. |
| @@ -151,6 +148,13 @@ static void rt73usb_bbp_write(struct rt2x00_dev *rt2x00dev, | |||
| 151 | 148 | ||
| 152 | rt73usb_register_write_lock(rt2x00dev, PHY_CSR3, reg); | 149 | rt73usb_register_write_lock(rt2x00dev, PHY_CSR3, reg); |
| 153 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | 150 | mutex_unlock(&rt2x00dev->usb_cache_mutex); |
| 151 | |||
| 152 | return; | ||
| 153 | |||
| 154 | exit_fail: | ||
| 155 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | ||
| 156 | |||
| 157 | ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n"); | ||
| 154 | } | 158 | } |
| 155 | 159 | ||
| 156 | static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev, | 160 | static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev, |
| @@ -164,11 +168,8 @@ static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev, | |||
| 164 | * Wait until the BBP becomes ready. | 168 | * Wait until the BBP becomes ready. |
| 165 | */ | 169 | */ |
| 166 | reg = rt73usb_bbp_check(rt2x00dev); | 170 | reg = rt73usb_bbp_check(rt2x00dev); |
| 167 | if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) { | 171 | if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) |
| 168 | ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n"); | 172 | goto exit_fail; |
| 169 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | ||
| 170 | return; | ||
| 171 | } | ||
| 172 | 173 | ||
| 173 | /* | 174 | /* |
| 174 | * Write the request into the BBP. | 175 | * Write the request into the BBP. |
| @@ -184,14 +185,19 @@ static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev, | |||
| 184 | * Wait until the BBP becomes ready. | 185 | * Wait until the BBP becomes ready. |
| 185 | */ | 186 | */ |
| 186 | reg = rt73usb_bbp_check(rt2x00dev); | 187 | reg = rt73usb_bbp_check(rt2x00dev); |
| 187 | if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) { | 188 | if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) |
| 188 | ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n"); | 189 | goto exit_fail; |
| 189 | *value = 0xff; | ||
| 190 | return; | ||
| 191 | } | ||
| 192 | 190 | ||
| 193 | *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE); | 191 | *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE); |
| 194 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | 192 | mutex_unlock(&rt2x00dev->usb_cache_mutex); |
| 193 | |||
| 194 | return; | ||
| 195 | |||
| 196 | exit_fail: | ||
| 197 | mutex_unlock(&rt2x00dev->usb_cache_mutex); | ||
| 198 | |||
| 199 | ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n"); | ||
| 200 | *value = 0xff; | ||
| 195 | } | 201 | } |
| 196 | 202 | ||
| 197 | static void rt73usb_rf_write(struct rt2x00_dev *rt2x00dev, | 203 | static void rt73usb_rf_write(struct rt2x00_dev *rt2x00dev, |
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c index 82f62d25f921..67421b0d3a7b 100644 --- a/drivers/rtc/rtc-sa1100.c +++ b/drivers/rtc/rtc-sa1100.c | |||
| @@ -331,14 +331,14 @@ static int sa1100_rtc_probe(struct platform_device *pdev) | |||
| 331 | RCNR = 0; | 331 | RCNR = 0; |
| 332 | } | 332 | } |
| 333 | 333 | ||
| 334 | device_init_wakeup(&pdev->dev, 1); | ||
| 335 | |||
| 334 | rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, | 336 | rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, |
| 335 | THIS_MODULE); | 337 | THIS_MODULE); |
| 336 | 338 | ||
| 337 | if (IS_ERR(rtc)) | 339 | if (IS_ERR(rtc)) |
| 338 | return PTR_ERR(rtc); | 340 | return PTR_ERR(rtc); |
| 339 | 341 | ||
| 340 | device_init_wakeup(&pdev->dev, 1); | ||
| 341 | |||
| 342 | platform_set_drvdata(pdev, rtc); | 342 | platform_set_drvdata(pdev, rtc); |
| 343 | 343 | ||
| 344 | return 0; | 344 | return 0; |
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c index a0b6d414953d..59fbef08d690 100644 --- a/drivers/scsi/esp_scsi.c +++ b/drivers/scsi/esp_scsi.c | |||
| @@ -2359,6 +2359,24 @@ void scsi_esp_unregister(struct esp *esp) | |||
| 2359 | } | 2359 | } |
| 2360 | EXPORT_SYMBOL(scsi_esp_unregister); | 2360 | EXPORT_SYMBOL(scsi_esp_unregister); |
| 2361 | 2361 | ||
| 2362 | static int esp_target_alloc(struct scsi_target *starget) | ||
| 2363 | { | ||
| 2364 | struct esp *esp = shost_priv(dev_to_shost(&starget->dev)); | ||
| 2365 | struct esp_target_data *tp = &esp->target[starget->id]; | ||
| 2366 | |||
| 2367 | tp->starget = starget; | ||
| 2368 | |||
| 2369 | return 0; | ||
| 2370 | } | ||
| 2371 | |||
| 2372 | static void esp_target_destroy(struct scsi_target *starget) | ||
| 2373 | { | ||
| 2374 | struct esp *esp = shost_priv(dev_to_shost(&starget->dev)); | ||
| 2375 | struct esp_target_data *tp = &esp->target[starget->id]; | ||
| 2376 | |||
| 2377 | tp->starget = NULL; | ||
| 2378 | } | ||
| 2379 | |||
| 2362 | static int esp_slave_alloc(struct scsi_device *dev) | 2380 | static int esp_slave_alloc(struct scsi_device *dev) |
| 2363 | { | 2381 | { |
| 2364 | struct esp *esp = shost_priv(dev->host); | 2382 | struct esp *esp = shost_priv(dev->host); |
| @@ -2370,8 +2388,6 @@ static int esp_slave_alloc(struct scsi_device *dev) | |||
| 2370 | return -ENOMEM; | 2388 | return -ENOMEM; |
| 2371 | dev->hostdata = lp; | 2389 | dev->hostdata = lp; |
| 2372 | 2390 | ||
| 2373 | tp->starget = dev->sdev_target; | ||
| 2374 | |||
| 2375 | spi_min_period(tp->starget) = esp->min_period; | 2391 | spi_min_period(tp->starget) = esp->min_period; |
| 2376 | spi_max_offset(tp->starget) = 15; | 2392 | spi_max_offset(tp->starget) = 15; |
| 2377 | 2393 | ||
| @@ -2608,6 +2624,8 @@ struct scsi_host_template scsi_esp_template = { | |||
| 2608 | .name = "esp", | 2624 | .name = "esp", |
| 2609 | .info = esp_info, | 2625 | .info = esp_info, |
| 2610 | .queuecommand = esp_queuecommand, | 2626 | .queuecommand = esp_queuecommand, |
| 2627 | .target_alloc = esp_target_alloc, | ||
| 2628 | .target_destroy = esp_target_destroy, | ||
| 2611 | .slave_alloc = esp_slave_alloc, | 2629 | .slave_alloc = esp_slave_alloc, |
| 2612 | .slave_configure = esp_slave_configure, | 2630 | .slave_configure = esp_slave_configure, |
| 2613 | .slave_destroy = esp_slave_destroy, | 2631 | .slave_destroy = esp_slave_destroy, |
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c index 45df83b9d847..0fe031f003e7 100644 --- a/drivers/scsi/ses.c +++ b/drivers/scsi/ses.c | |||
| @@ -61,7 +61,7 @@ static int ses_probe(struct device *dev) | |||
| 61 | return err; | 61 | return err; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | #define SES_TIMEOUT 30 | 64 | #define SES_TIMEOUT (30 * HZ) |
| 65 | #define SES_RETRIES 3 | 65 | #define SES_RETRIES 3 |
| 66 | 66 | ||
| 67 | static int ses_recv_diag(struct scsi_device *sdev, int page_code, | 67 | static int ses_recv_diag(struct scsi_device *sdev, int page_code, |
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c index 7dcda187d9ba..fafe7db20d6d 100644 --- a/drivers/video/pxafb.c +++ b/drivers/video/pxafb.c | |||
| @@ -1246,7 +1246,7 @@ static int pxafb_resume(struct platform_device *dev) | |||
| 1246 | * cache. Once this area is remapped, all virtual memory | 1246 | * cache. Once this area is remapped, all virtual memory |
| 1247 | * access to the video memory should occur at the new region. | 1247 | * access to the video memory should occur at the new region. |
| 1248 | */ | 1248 | */ |
| 1249 | static int __init pxafb_map_video_memory(struct pxafb_info *fbi) | 1249 | static int __devinit pxafb_map_video_memory(struct pxafb_info *fbi) |
| 1250 | { | 1250 | { |
| 1251 | /* | 1251 | /* |
| 1252 | * We reserve one page for the palette, plus the size | 1252 | * We reserve one page for the palette, plus the size |
| @@ -1348,7 +1348,7 @@ decode_mode: | |||
| 1348 | pxafb_decode_mode_info(fbi, inf->modes, inf->num_modes); | 1348 | pxafb_decode_mode_info(fbi, inf->modes, inf->num_modes); |
| 1349 | } | 1349 | } |
| 1350 | 1350 | ||
| 1351 | static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev) | 1351 | static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev) |
| 1352 | { | 1352 | { |
| 1353 | struct pxafb_info *fbi; | 1353 | struct pxafb_info *fbi; |
| 1354 | void *addr; | 1354 | void *addr; |
| @@ -1410,7 +1410,7 @@ static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev) | |||
| 1410 | } | 1410 | } |
| 1411 | 1411 | ||
| 1412 | #ifdef CONFIG_FB_PXA_PARAMETERS | 1412 | #ifdef CONFIG_FB_PXA_PARAMETERS |
| 1413 | static int __init parse_opt_mode(struct device *dev, const char *this_opt) | 1413 | static int __devinit parse_opt_mode(struct device *dev, const char *this_opt) |
| 1414 | { | 1414 | { |
| 1415 | struct pxafb_mach_info *inf = dev->platform_data; | 1415 | struct pxafb_mach_info *inf = dev->platform_data; |
| 1416 | 1416 | ||
| @@ -1469,7 +1469,7 @@ done: | |||
| 1469 | return 0; | 1469 | return 0; |
| 1470 | } | 1470 | } |
| 1471 | 1471 | ||
| 1472 | static int __init parse_opt(struct device *dev, char *this_opt) | 1472 | static int __devinit parse_opt(struct device *dev, char *this_opt) |
| 1473 | { | 1473 | { |
| 1474 | struct pxafb_mach_info *inf = dev->platform_data; | 1474 | struct pxafb_mach_info *inf = dev->platform_data; |
| 1475 | struct pxafb_mode_info *mode = &inf->modes[0]; | 1475 | struct pxafb_mode_info *mode = &inf->modes[0]; |
| @@ -1567,7 +1567,7 @@ static int __init parse_opt(struct device *dev, char *this_opt) | |||
| 1567 | return 0; | 1567 | return 0; |
| 1568 | } | 1568 | } |
| 1569 | 1569 | ||
| 1570 | static int __init pxafb_parse_options(struct device *dev, char *options) | 1570 | static int __devinit pxafb_parse_options(struct device *dev, char *options) |
| 1571 | { | 1571 | { |
| 1572 | char *this_opt; | 1572 | char *this_opt; |
| 1573 | int ret; | 1573 | int ret; |
| @@ -1588,8 +1588,8 @@ static int __init pxafb_parse_options(struct device *dev, char *options) | |||
| 1588 | 1588 | ||
| 1589 | static char g_options[256] __devinitdata = ""; | 1589 | static char g_options[256] __devinitdata = ""; |
| 1590 | 1590 | ||
| 1591 | #ifndef CONFIG_MODULES | 1591 | #ifndef MODULE |
| 1592 | static int __devinit pxafb_setup_options(void) | 1592 | static int __init pxafb_setup_options(void) |
| 1593 | { | 1593 | { |
| 1594 | char *options = NULL; | 1594 | char *options = NULL; |
| 1595 | 1595 | ||
| @@ -1613,7 +1613,7 @@ MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)"); | |||
| 1613 | #define pxafb_setup_options() (0) | 1613 | #define pxafb_setup_options() (0) |
| 1614 | #endif | 1614 | #endif |
| 1615 | 1615 | ||
| 1616 | static int __init pxafb_probe(struct platform_device *dev) | 1616 | static int __devinit pxafb_probe(struct platform_device *dev) |
| 1617 | { | 1617 | { |
| 1618 | struct pxafb_info *fbi; | 1618 | struct pxafb_info *fbi; |
| 1619 | struct pxafb_mach_info *inf; | 1619 | struct pxafb_mach_info *inf; |
| @@ -1685,14 +1685,14 @@ static int __init pxafb_probe(struct platform_device *dev) | |||
| 1685 | if (r == NULL) { | 1685 | if (r == NULL) { |
| 1686 | dev_err(&dev->dev, "no I/O memory resource defined\n"); | 1686 | dev_err(&dev->dev, "no I/O memory resource defined\n"); |
| 1687 | ret = -ENODEV; | 1687 | ret = -ENODEV; |
| 1688 | goto failed; | 1688 | goto failed_fbi; |
| 1689 | } | 1689 | } |
| 1690 | 1690 | ||
| 1691 | r = request_mem_region(r->start, r->end - r->start + 1, dev->name); | 1691 | r = request_mem_region(r->start, r->end - r->start + 1, dev->name); |
| 1692 | if (r == NULL) { | 1692 | if (r == NULL) { |
| 1693 | dev_err(&dev->dev, "failed to request I/O memory\n"); | 1693 | dev_err(&dev->dev, "failed to request I/O memory\n"); |
| 1694 | ret = -EBUSY; | 1694 | ret = -EBUSY; |
| 1695 | goto failed; | 1695 | goto failed_fbi; |
| 1696 | } | 1696 | } |
| 1697 | 1697 | ||
| 1698 | fbi->mmio_base = ioremap(r->start, r->end - r->start + 1); | 1698 | fbi->mmio_base = ioremap(r->start, r->end - r->start + 1); |
| @@ -1735,8 +1735,17 @@ static int __init pxafb_probe(struct platform_device *dev) | |||
| 1735 | * This makes sure that our colour bitfield | 1735 | * This makes sure that our colour bitfield |
| 1736 | * descriptors are correctly initialised. | 1736 | * descriptors are correctly initialised. |
| 1737 | */ | 1737 | */ |
| 1738 | pxafb_check_var(&fbi->fb.var, &fbi->fb); | 1738 | ret = pxafb_check_var(&fbi->fb.var, &fbi->fb); |
| 1739 | pxafb_set_par(&fbi->fb); | 1739 | if (ret) { |
| 1740 | dev_err(&dev->dev, "failed to get suitable mode\n"); | ||
| 1741 | goto failed_free_irq; | ||
| 1742 | } | ||
| 1743 | |||
| 1744 | ret = pxafb_set_par(&fbi->fb); | ||
| 1745 | if (ret) { | ||
| 1746 | dev_err(&dev->dev, "Failed to set parameters\n"); | ||
| 1747 | goto failed_free_irq; | ||
| 1748 | } | ||
| 1740 | 1749 | ||
| 1741 | platform_set_drvdata(dev, fbi); | 1750 | platform_set_drvdata(dev, fbi); |
| 1742 | 1751 | ||
| @@ -1744,7 +1753,7 @@ static int __init pxafb_probe(struct platform_device *dev) | |||
| 1744 | if (ret < 0) { | 1753 | if (ret < 0) { |
| 1745 | dev_err(&dev->dev, | 1754 | dev_err(&dev->dev, |
| 1746 | "Failed to register framebuffer device: %d\n", ret); | 1755 | "Failed to register framebuffer device: %d\n", ret); |
| 1747 | goto failed_free_irq; | 1756 | goto failed_free_cmap; |
| 1748 | } | 1757 | } |
| 1749 | 1758 | ||
| 1750 | #ifdef CONFIG_CPU_FREQ | 1759 | #ifdef CONFIG_CPU_FREQ |
| @@ -1763,18 +1772,23 @@ static int __init pxafb_probe(struct platform_device *dev) | |||
| 1763 | 1772 | ||
| 1764 | return 0; | 1773 | return 0; |
| 1765 | 1774 | ||
| 1775 | failed_free_cmap: | ||
| 1776 | if (fbi->fb.cmap.len) | ||
| 1777 | fb_dealloc_cmap(&fbi->fb.cmap); | ||
| 1766 | failed_free_irq: | 1778 | failed_free_irq: |
| 1767 | free_irq(irq, fbi); | 1779 | free_irq(irq, fbi); |
| 1768 | failed_free_res: | ||
| 1769 | release_mem_region(r->start, r->end - r->start + 1); | ||
| 1770 | failed_free_io: | ||
| 1771 | iounmap(fbi->mmio_base); | ||
| 1772 | failed_free_mem: | 1780 | failed_free_mem: |
| 1773 | dma_free_writecombine(&dev->dev, fbi->map_size, | 1781 | dma_free_writecombine(&dev->dev, fbi->map_size, |
| 1774 | fbi->map_cpu, fbi->map_dma); | 1782 | fbi->map_cpu, fbi->map_dma); |
| 1775 | failed: | 1783 | failed_free_io: |
| 1784 | iounmap(fbi->mmio_base); | ||
| 1785 | failed_free_res: | ||
| 1786 | release_mem_region(r->start, r->end - r->start + 1); | ||
| 1787 | failed_fbi: | ||
| 1788 | clk_put(fbi->clk); | ||
| 1776 | platform_set_drvdata(dev, NULL); | 1789 | platform_set_drvdata(dev, NULL); |
| 1777 | kfree(fbi); | 1790 | kfree(fbi); |
| 1791 | failed: | ||
| 1778 | return ret; | 1792 | return ret; |
| 1779 | } | 1793 | } |
| 1780 | 1794 | ||
| @@ -1787,7 +1801,7 @@ static struct platform_driver pxafb_driver = { | |||
| 1787 | }, | 1801 | }, |
| 1788 | }; | 1802 | }; |
| 1789 | 1803 | ||
| 1790 | static int __devinit pxafb_init(void) | 1804 | static int __init pxafb_init(void) |
| 1791 | { | 1805 | { |
| 1792 | if (pxafb_setup_options()) | 1806 | if (pxafb_setup_options()) |
| 1793 | return -EINVAL; | 1807 | return -EINVAL; |
diff --git a/include/asm-x86/msr.h b/include/asm-x86/msr.h index 3707650a169b..2b5f2c91db25 100644 --- a/include/asm-x86/msr.h +++ b/include/asm-x86/msr.h | |||
| @@ -18,7 +18,7 @@ static inline unsigned long long native_read_tscp(unsigned int *aux) | |||
| 18 | unsigned long low, high; | 18 | unsigned long low, high; |
| 19 | asm volatile(".byte 0x0f,0x01,0xf9" | 19 | asm volatile(".byte 0x0f,0x01,0xf9" |
| 20 | : "=a" (low), "=d" (high), "=c" (*aux)); | 20 | : "=a" (low), "=d" (high), "=c" (*aux)); |
| 21 | return low | ((u64)high >> 32); | 21 | return low | ((u64)high << 32); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | /* | 24 | /* |
diff --git a/include/linux/i2c.h b/include/linux/i2c.h index fb9af6a0fe9c..8dc730132192 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h | |||
| @@ -171,7 +171,7 @@ struct i2c_client { | |||
| 171 | struct i2c_adapter *adapter; /* the adapter we sit on */ | 171 | struct i2c_adapter *adapter; /* the adapter we sit on */ |
| 172 | struct i2c_driver *driver; /* and our access routines */ | 172 | struct i2c_driver *driver; /* and our access routines */ |
| 173 | struct device dev; /* the device structure */ | 173 | struct device dev; /* the device structure */ |
| 174 | int irq; /* irq issued by device (or -1) */ | 174 | int irq; /* irq issued by device */ |
| 175 | struct list_head list; /* DEPRECATED */ | 175 | struct list_head list; /* DEPRECATED */ |
| 176 | struct completion released; | 176 | struct completion released; |
| 177 | }; | 177 | }; |
diff --git a/include/linux/inet_lro.h b/include/linux/inet_lro.h index 80335b7d77c5..c4335faebb63 100644 --- a/include/linux/inet_lro.h +++ b/include/linux/inet_lro.h | |||
| @@ -84,7 +84,11 @@ struct net_lro_mgr { | |||
| 84 | from received packets and eth protocol | 84 | from received packets and eth protocol |
| 85 | is still ETH_P_8021Q */ | 85 | is still ETH_P_8021Q */ |
| 86 | 86 | ||
| 87 | u32 ip_summed; /* Set in non generated SKBs in page mode */ | 87 | /* |
| 88 | * Set for generated SKBs that are not added to | ||
| 89 | * the frag list in fragmented mode | ||
| 90 | */ | ||
| 91 | u32 ip_summed; | ||
| 88 | u32 ip_summed_aggr; /* Set in aggregated SKBs: CHECKSUM_UNNECESSARY | 92 | u32 ip_summed_aggr; /* Set in aggregated SKBs: CHECKSUM_UNNECESSARY |
| 89 | * or CHECKSUM_NONE */ | 93 | * or CHECKSUM_NONE */ |
| 90 | 94 | ||
diff --git a/include/linux/input.h b/include/linux/input.h index e075c4b762fb..d150c57e5f0a 100644 --- a/include/linux/input.h +++ b/include/linux/input.h | |||
| @@ -534,8 +534,8 @@ struct input_absinfo { | |||
| 534 | 534 | ||
| 535 | #define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */ | 535 | #define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */ |
| 536 | #define KEY_FRAMEFORWARD 0x1b5 | 536 | #define KEY_FRAMEFORWARD 0x1b5 |
| 537 | |||
| 538 | #define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */ | 537 | #define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */ |
| 538 | #define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */ | ||
| 539 | 539 | ||
| 540 | #define KEY_DEL_EOL 0x1c0 | 540 | #define KEY_DEL_EOL 0x1c0 |
| 541 | #define KEY_DEL_EOS 0x1c1 | 541 | #define KEY_DEL_EOS 0x1c1 |
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index f27fd2009334..25f87102ab66 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h | |||
| @@ -88,6 +88,8 @@ struct wireless_dev; | |||
| 88 | #define NETDEV_TX_BUSY 1 /* driver tx path was busy*/ | 88 | #define NETDEV_TX_BUSY 1 /* driver tx path was busy*/ |
| 89 | #define NETDEV_TX_LOCKED -1 /* driver tx lock was already taken */ | 89 | #define NETDEV_TX_LOCKED -1 /* driver tx lock was already taken */ |
| 90 | 90 | ||
| 91 | #ifdef __KERNEL__ | ||
| 92 | |||
| 91 | /* | 93 | /* |
| 92 | * Compute the worst case header length according to the protocols | 94 | * Compute the worst case header length according to the protocols |
| 93 | * used. | 95 | * used. |
| @@ -114,6 +116,8 @@ struct wireless_dev; | |||
| 114 | #define MAX_HEADER (LL_MAX_HEADER + 48) | 116 | #define MAX_HEADER (LL_MAX_HEADER + 48) |
| 115 | #endif | 117 | #endif |
| 116 | 118 | ||
| 119 | #endif /* __KERNEL__ */ | ||
| 120 | |||
| 117 | struct net_device_subqueue | 121 | struct net_device_subqueue |
| 118 | { | 122 | { |
| 119 | /* Give a control state for each queue. This struct may contain | 123 | /* Give a control state for each queue. This struct may contain |
diff --git a/include/net/mac80211.h b/include/net/mac80211.h index dae3f9ec1154..bcd1623245cb 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h | |||
| @@ -595,6 +595,15 @@ enum ieee80211_key_alg { | |||
| 595 | ALG_CCMP, | 595 | ALG_CCMP, |
| 596 | }; | 596 | }; |
| 597 | 597 | ||
| 598 | /** | ||
| 599 | * enum ieee80211_key_len - key length | ||
| 600 | * @WEP40: WEP 5 byte long key | ||
| 601 | * @WEP104: WEP 13 byte long key | ||
| 602 | */ | ||
| 603 | enum ieee80211_key_len { | ||
| 604 | LEN_WEP40 = 5, | ||
| 605 | LEN_WEP104 = 13, | ||
| 606 | }; | ||
| 598 | 607 | ||
| 599 | /** | 608 | /** |
| 600 | * enum ieee80211_key_flags - key flags | 609 | * enum ieee80211_key_flags - key flags |
diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index ab502ec1c61c..a87fc0312edc 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h | |||
| @@ -178,7 +178,7 @@ extern struct Qdisc *qdisc_alloc(struct net_device *dev, struct Qdisc_ops *ops); | |||
| 178 | extern struct Qdisc *qdisc_create_dflt(struct net_device *dev, | 178 | extern struct Qdisc *qdisc_create_dflt(struct net_device *dev, |
| 179 | struct Qdisc_ops *ops, u32 parentid); | 179 | struct Qdisc_ops *ops, u32 parentid); |
| 180 | extern void tcf_destroy(struct tcf_proto *tp); | 180 | extern void tcf_destroy(struct tcf_proto *tp); |
| 181 | extern void tcf_destroy_chain(struct tcf_proto *fl); | 181 | extern void tcf_destroy_chain(struct tcf_proto **fl); |
| 182 | 182 | ||
| 183 | static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch, | 183 | static inline int __qdisc_enqueue_tail(struct sk_buff *skb, struct Qdisc *sch, |
| 184 | struct sk_buff_head *list) | 184 | struct sk_buff_head *list) |
diff --git a/kernel/rcuclassic.c b/kernel/rcuclassic.c index f4ffbd0f306f..a38895a5b8e2 100644 --- a/kernel/rcuclassic.c +++ b/kernel/rcuclassic.c | |||
| @@ -89,8 +89,22 @@ static void force_quiescent_state(struct rcu_data *rdp, | |||
| 89 | /* | 89 | /* |
| 90 | * Don't send IPI to itself. With irqs disabled, | 90 | * Don't send IPI to itself. With irqs disabled, |
| 91 | * rdp->cpu is the current cpu. | 91 | * rdp->cpu is the current cpu. |
| 92 | * | ||
| 93 | * cpu_online_map is updated by the _cpu_down() | ||
| 94 | * using stop_machine_run(). Since we're in irqs disabled | ||
| 95 | * section, stop_machine_run() is not exectuting, hence | ||
| 96 | * the cpu_online_map is stable. | ||
| 97 | * | ||
| 98 | * However, a cpu might have been offlined _just_ before | ||
| 99 | * we disabled irqs while entering here. | ||
| 100 | * And rcu subsystem might not yet have handled the CPU_DEAD | ||
| 101 | * notification, leading to the offlined cpu's bit | ||
| 102 | * being set in the rcp->cpumask. | ||
| 103 | * | ||
| 104 | * Hence cpumask = (rcp->cpumask & cpu_online_map) to prevent | ||
| 105 | * sending smp_reschedule() to an offlined CPU. | ||
| 92 | */ | 106 | */ |
| 93 | cpumask = rcp->cpumask; | 107 | cpus_and(cpumask, rcp->cpumask, cpu_online_map); |
| 94 | cpu_clear(rdp->cpu, cpumask); | 108 | cpu_clear(rdp->cpu, cpumask); |
| 95 | for_each_cpu_mask(cpu, cpumask) | 109 | for_each_cpu_mask(cpu, cpumask) |
| 96 | smp_send_reschedule(cpu); | 110 | smp_send_reschedule(cpu); |
diff --git a/kernel/sched.c b/kernel/sched.c index 3aaa5c8cb421..94ead43eda62 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
| @@ -5887,6 +5887,7 @@ static void migrate_dead_tasks(unsigned int dead_cpu) | |||
| 5887 | next = pick_next_task(rq, rq->curr); | 5887 | next = pick_next_task(rq, rq->curr); |
| 5888 | if (!next) | 5888 | if (!next) |
| 5889 | break; | 5889 | break; |
| 5890 | next->sched_class->put_prev_task(rq, next); | ||
| 5890 | migrate_dead(dead_cpu, next); | 5891 | migrate_dead(dead_cpu, next); |
| 5891 | 5892 | ||
| 5892 | } | 5893 | } |
| @@ -8501,6 +8502,9 @@ int sched_group_set_rt_period(struct task_group *tg, long rt_period_us) | |||
| 8501 | rt_period = (u64)rt_period_us * NSEC_PER_USEC; | 8502 | rt_period = (u64)rt_period_us * NSEC_PER_USEC; |
| 8502 | rt_runtime = tg->rt_bandwidth.rt_runtime; | 8503 | rt_runtime = tg->rt_bandwidth.rt_runtime; |
| 8503 | 8504 | ||
| 8505 | if (rt_period == 0) | ||
| 8506 | return -EINVAL; | ||
| 8507 | |||
| 8504 | return tg_set_bandwidth(tg, rt_period, rt_runtime); | 8508 | return tg_set_bandwidth(tg, rt_period, rt_runtime); |
| 8505 | } | 8509 | } |
| 8506 | 8510 | ||
diff --git a/lib/debugobjects.c b/lib/debugobjects.c index a76a5e122ae1..85b18d79be89 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c | |||
| @@ -68,6 +68,7 @@ static int fill_pool(void) | |||
| 68 | { | 68 | { |
| 69 | gfp_t gfp = GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN; | 69 | gfp_t gfp = GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN; |
| 70 | struct debug_obj *new; | 70 | struct debug_obj *new; |
| 71 | unsigned long flags; | ||
| 71 | 72 | ||
| 72 | if (likely(obj_pool_free >= ODEBUG_POOL_MIN_LEVEL)) | 73 | if (likely(obj_pool_free >= ODEBUG_POOL_MIN_LEVEL)) |
| 73 | return obj_pool_free; | 74 | return obj_pool_free; |
| @@ -81,10 +82,10 @@ static int fill_pool(void) | |||
| 81 | if (!new) | 82 | if (!new) |
| 82 | return obj_pool_free; | 83 | return obj_pool_free; |
| 83 | 84 | ||
| 84 | spin_lock(&pool_lock); | 85 | spin_lock_irqsave(&pool_lock, flags); |
| 85 | hlist_add_head(&new->node, &obj_pool); | 86 | hlist_add_head(&new->node, &obj_pool); |
| 86 | obj_pool_free++; | 87 | obj_pool_free++; |
| 87 | spin_unlock(&pool_lock); | 88 | spin_unlock_irqrestore(&pool_lock, flags); |
| 88 | } | 89 | } |
| 89 | return obj_pool_free; | 90 | return obj_pool_free; |
| 90 | } | 91 | } |
| @@ -110,16 +111,13 @@ static struct debug_obj *lookup_object(void *addr, struct debug_bucket *b) | |||
| 110 | } | 111 | } |
| 111 | 112 | ||
| 112 | /* | 113 | /* |
| 113 | * Allocate a new object. If the pool is empty and no refill possible, | 114 | * Allocate a new object. If the pool is empty, switch off the debugger. |
| 114 | * switch off the debugger. | ||
| 115 | */ | 115 | */ |
| 116 | static struct debug_obj * | 116 | static struct debug_obj * |
| 117 | alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr) | 117 | alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr) |
| 118 | { | 118 | { |
| 119 | struct debug_obj *obj = NULL; | 119 | struct debug_obj *obj = NULL; |
| 120 | int retry = 0; | ||
| 121 | 120 | ||
| 122 | repeat: | ||
| 123 | spin_lock(&pool_lock); | 121 | spin_lock(&pool_lock); |
| 124 | if (obj_pool.first) { | 122 | if (obj_pool.first) { |
| 125 | obj = hlist_entry(obj_pool.first, typeof(*obj), node); | 123 | obj = hlist_entry(obj_pool.first, typeof(*obj), node); |
| @@ -141,9 +139,6 @@ repeat: | |||
| 141 | } | 139 | } |
| 142 | spin_unlock(&pool_lock); | 140 | spin_unlock(&pool_lock); |
| 143 | 141 | ||
| 144 | if (fill_pool() && !obj && !retry++) | ||
| 145 | goto repeat; | ||
| 146 | |||
| 147 | return obj; | 142 | return obj; |
| 148 | } | 143 | } |
| 149 | 144 | ||
| @@ -261,6 +256,8 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack) | |||
| 261 | struct debug_obj *obj; | 256 | struct debug_obj *obj; |
| 262 | unsigned long flags; | 257 | unsigned long flags; |
| 263 | 258 | ||
| 259 | fill_pool(); | ||
| 260 | |||
| 264 | db = get_bucket((unsigned long) addr); | 261 | db = get_bucket((unsigned long) addr); |
| 265 | 262 | ||
| 266 | spin_lock_irqsave(&db->lock, flags); | 263 | spin_lock_irqsave(&db->lock, flags); |
diff --git a/lib/ts_bm.c b/lib/ts_bm.c index d90822c378a4..4a7fce72898e 100644 --- a/lib/ts_bm.c +++ b/lib/ts_bm.c | |||
| @@ -63,7 +63,7 @@ static unsigned int bm_find(struct ts_config *conf, struct ts_state *state) | |||
| 63 | struct ts_bm *bm = ts_config_priv(conf); | 63 | struct ts_bm *bm = ts_config_priv(conf); |
| 64 | unsigned int i, text_len, consumed = state->offset; | 64 | unsigned int i, text_len, consumed = state->offset; |
| 65 | const u8 *text; | 65 | const u8 *text; |
| 66 | int shift = bm->patlen, bs; | 66 | int shift = bm->patlen - 1, bs; |
| 67 | 67 | ||
| 68 | for (;;) { | 68 | for (;;) { |
| 69 | text_len = conf->get_next_block(consumed, &text, conf, state); | 69 | text_len = conf->get_next_block(consumed, &text, conf, state); |
diff --git a/net/core/dev.c b/net/core/dev.c index c421a1f8f0b9..fca23a3bf12c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
| @@ -454,7 +454,7 @@ static int netdev_boot_setup_add(char *name, struct ifmap *map) | |||
| 454 | for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { | 454 | for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { |
| 455 | if (s[i].name[0] == '\0' || s[i].name[0] == ' ') { | 455 | if (s[i].name[0] == '\0' || s[i].name[0] == ' ') { |
| 456 | memset(s[i].name, 0, sizeof(s[i].name)); | 456 | memset(s[i].name, 0, sizeof(s[i].name)); |
| 457 | strcpy(s[i].name, name); | 457 | strlcpy(s[i].name, name, IFNAMSIZ); |
| 458 | memcpy(&s[i].map, map, sizeof(s[i].map)); | 458 | memcpy(&s[i].map, map, sizeof(s[i].map)); |
| 459 | break; | 459 | break; |
| 460 | } | 460 | } |
| @@ -479,7 +479,7 @@ int netdev_boot_setup_check(struct net_device *dev) | |||
| 479 | 479 | ||
| 480 | for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { | 480 | for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { |
| 481 | if (s[i].name[0] != '\0' && s[i].name[0] != ' ' && | 481 | if (s[i].name[0] != '\0' && s[i].name[0] != ' ' && |
| 482 | !strncmp(dev->name, s[i].name, strlen(s[i].name))) { | 482 | !strcmp(dev->name, s[i].name)) { |
| 483 | dev->irq = s[i].map.irq; | 483 | dev->irq = s[i].map.irq; |
| 484 | dev->base_addr = s[i].map.base_addr; | 484 | dev->base_addr = s[i].map.base_addr; |
| 485 | dev->mem_start = s[i].map.mem_start; | 485 | dev->mem_start = s[i].map.mem_start; |
| @@ -2973,7 +2973,7 @@ EXPORT_SYMBOL(dev_unicast_delete); | |||
| 2973 | /** | 2973 | /** |
| 2974 | * dev_unicast_add - add a secondary unicast address | 2974 | * dev_unicast_add - add a secondary unicast address |
| 2975 | * @dev: device | 2975 | * @dev: device |
| 2976 | * @addr: address to delete | 2976 | * @addr: address to add |
| 2977 | * @alen: length of @addr | 2977 | * @alen: length of @addr |
| 2978 | * | 2978 | * |
| 2979 | * Add a secondary unicast address to the device or increase | 2979 | * Add a secondary unicast address to the device or increase |
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index e3e9ab0f74e3..277a2302eb3a 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c | |||
| @@ -226,7 +226,7 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) | |||
| 226 | 226 | ||
| 227 | ops = lookup_rules_ops(net, frh->family); | 227 | ops = lookup_rules_ops(net, frh->family); |
| 228 | if (ops == NULL) { | 228 | if (ops == NULL) { |
| 229 | err = EAFNOSUPPORT; | 229 | err = -EAFNOSUPPORT; |
| 230 | goto errout; | 230 | goto errout; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| @@ -365,7 +365,7 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) | |||
| 365 | 365 | ||
| 366 | ops = lookup_rules_ops(net, frh->family); | 366 | ops = lookup_rules_ops(net, frh->family); |
| 367 | if (ops == NULL) { | 367 | if (ops == NULL) { |
| 368 | err = EAFNOSUPPORT; | 368 | err = -EAFNOSUPPORT; |
| 369 | goto errout; | 369 | goto errout; |
| 370 | } | 370 | } |
| 371 | 371 | ||
diff --git a/net/core/filter.c b/net/core/filter.c index 4f8369729a4e..df3744355839 100644 --- a/net/core/filter.c +++ b/net/core/filter.c | |||
| @@ -68,7 +68,6 @@ static inline void *load_pointer(struct sk_buff *skb, int k, | |||
| 68 | * sk_filter - run a packet through a socket filter | 68 | * sk_filter - run a packet through a socket filter |
| 69 | * @sk: sock associated with &sk_buff | 69 | * @sk: sock associated with &sk_buff |
| 70 | * @skb: buffer to filter | 70 | * @skb: buffer to filter |
| 71 | * @needlock: set to 1 if the sock is not locked by caller. | ||
| 72 | * | 71 | * |
| 73 | * Run the filter code and then cut skb->data to correct size returned by | 72 | * Run the filter code and then cut skb->data to correct size returned by |
| 74 | * sk_run_filter. If pkt_len is 0 we toss packet. If skb->len is smaller | 73 | * sk_run_filter. If pkt_len is 0 we toss packet. If skb->len is smaller |
diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 1e556d312117..366621610e76 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c | |||
| @@ -1292,12 +1292,14 @@ static int __skb_splice_bits(struct sk_buff *skb, unsigned int *offset, | |||
| 1292 | { | 1292 | { |
| 1293 | unsigned int nr_pages = spd->nr_pages; | 1293 | unsigned int nr_pages = spd->nr_pages; |
| 1294 | unsigned int poff, plen, len, toff, tlen; | 1294 | unsigned int poff, plen, len, toff, tlen; |
| 1295 | int headlen, seg; | 1295 | int headlen, seg, error = 0; |
| 1296 | 1296 | ||
| 1297 | toff = *offset; | 1297 | toff = *offset; |
| 1298 | tlen = *total_len; | 1298 | tlen = *total_len; |
| 1299 | if (!tlen) | 1299 | if (!tlen) { |
| 1300 | error = 1; | ||
| 1300 | goto err; | 1301 | goto err; |
| 1302 | } | ||
| 1301 | 1303 | ||
| 1302 | /* | 1304 | /* |
| 1303 | * if the offset is greater than the linear part, go directly to | 1305 | * 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, | |||
| 1339 | * just jump directly to update and return, no point | 1341 | * just jump directly to update and return, no point |
| 1340 | * in going over fragments when the output is full. | 1342 | * in going over fragments when the output is full. |
| 1341 | */ | 1343 | */ |
| 1342 | if (spd_fill_page(spd, virt_to_page(p), plen, poff, skb)) | 1344 | error = spd_fill_page(spd, virt_to_page(p), plen, poff, skb); |
| 1345 | if (error) | ||
| 1343 | goto done; | 1346 | goto done; |
| 1344 | 1347 | ||
| 1345 | tlen -= plen; | 1348 | tlen -= plen; |
| @@ -1369,7 +1372,8 @@ map_frag: | |||
| 1369 | if (!plen) | 1372 | if (!plen) |
| 1370 | break; | 1373 | break; |
| 1371 | 1374 | ||
| 1372 | if (spd_fill_page(spd, f->page, plen, poff, skb)) | 1375 | error = spd_fill_page(spd, f->page, plen, poff, skb); |
| 1376 | if (error) | ||
| 1373 | break; | 1377 | break; |
| 1374 | 1378 | ||
| 1375 | tlen -= plen; | 1379 | tlen -= plen; |
| @@ -1382,7 +1386,10 @@ done: | |||
| 1382 | return 0; | 1386 | return 0; |
| 1383 | } | 1387 | } |
| 1384 | err: | 1388 | err: |
| 1385 | return 1; | 1389 | /* update the offset to reflect the linear part skip, if any */ |
| 1390 | if (!error) | ||
| 1391 | *offset = toff; | ||
| 1392 | return error; | ||
| 1386 | } | 1393 | } |
| 1387 | 1394 | ||
| 1388 | /* | 1395 | /* |
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c index 4ed429bd5951..0546a0bc97ea 100644 --- a/net/ipv4/inet_fragment.c +++ b/net/ipv4/inet_fragment.c | |||
| @@ -192,14 +192,21 @@ EXPORT_SYMBOL(inet_frag_evictor); | |||
| 192 | 192 | ||
| 193 | static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf, | 193 | static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf, |
| 194 | struct inet_frag_queue *qp_in, struct inet_frags *f, | 194 | struct inet_frag_queue *qp_in, struct inet_frags *f, |
| 195 | unsigned int hash, void *arg) | 195 | void *arg) |
| 196 | { | 196 | { |
| 197 | struct inet_frag_queue *qp; | 197 | struct inet_frag_queue *qp; |
| 198 | #ifdef CONFIG_SMP | 198 | #ifdef CONFIG_SMP |
| 199 | struct hlist_node *n; | 199 | struct hlist_node *n; |
| 200 | #endif | 200 | #endif |
| 201 | unsigned int hash; | ||
| 201 | 202 | ||
| 202 | write_lock(&f->lock); | 203 | write_lock(&f->lock); |
| 204 | /* | ||
| 205 | * While we stayed w/o the lock other CPU could update | ||
| 206 | * the rnd seed, so we need to re-calculate the hash | ||
| 207 | * chain. Fortunatelly the qp_in can be used to get one. | ||
| 208 | */ | ||
| 209 | hash = f->hashfn(qp_in); | ||
| 203 | #ifdef CONFIG_SMP | 210 | #ifdef CONFIG_SMP |
| 204 | /* With SMP race we have to recheck hash table, because | 211 | /* With SMP race we have to recheck hash table, because |
| 205 | * such entry could be created on other cpu, while we | 212 | * 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, | |||
| 247 | } | 254 | } |
| 248 | 255 | ||
| 249 | static struct inet_frag_queue *inet_frag_create(struct netns_frags *nf, | 256 | static struct inet_frag_queue *inet_frag_create(struct netns_frags *nf, |
| 250 | struct inet_frags *f, void *arg, unsigned int hash) | 257 | struct inet_frags *f, void *arg) |
| 251 | { | 258 | { |
| 252 | struct inet_frag_queue *q; | 259 | struct inet_frag_queue *q; |
| 253 | 260 | ||
| @@ -255,7 +262,7 @@ static struct inet_frag_queue *inet_frag_create(struct netns_frags *nf, | |||
| 255 | if (q == NULL) | 262 | if (q == NULL) |
| 256 | return NULL; | 263 | return NULL; |
| 257 | 264 | ||
| 258 | return inet_frag_intern(nf, q, f, hash, arg); | 265 | return inet_frag_intern(nf, q, f, arg); |
| 259 | } | 266 | } |
| 260 | 267 | ||
| 261 | struct inet_frag_queue *inet_frag_find(struct netns_frags *nf, | 268 | 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, | |||
| 264 | struct inet_frag_queue *q; | 271 | struct inet_frag_queue *q; |
| 265 | struct hlist_node *n; | 272 | struct hlist_node *n; |
| 266 | 273 | ||
| 267 | read_lock(&f->lock); | ||
| 268 | hlist_for_each_entry(q, n, &f->hash[hash], list) { | 274 | hlist_for_each_entry(q, n, &f->hash[hash], list) { |
| 269 | if (q->net == nf && f->match(q, key)) { | 275 | if (q->net == nf && f->match(q, key)) { |
| 270 | atomic_inc(&q->refcnt); | 276 | atomic_inc(&q->refcnt); |
| @@ -274,6 +280,6 @@ struct inet_frag_queue *inet_frag_find(struct netns_frags *nf, | |||
| 274 | } | 280 | } |
| 275 | read_unlock(&f->lock); | 281 | read_unlock(&f->lock); |
| 276 | 282 | ||
| 277 | return inet_frag_create(nf, f, key, hash); | 283 | return inet_frag_create(nf, f, key); |
| 278 | } | 284 | } |
| 279 | EXPORT_SYMBOL(inet_frag_find); | 285 | EXPORT_SYMBOL(inet_frag_find); |
diff --git a/net/ipv4/inet_lro.c b/net/ipv4/inet_lro.c index 4a4d49fca1f2..cfd034a2b96e 100644 --- a/net/ipv4/inet_lro.c +++ b/net/ipv4/inet_lro.c | |||
| @@ -383,8 +383,7 @@ static int __lro_proc_skb(struct net_lro_mgr *lro_mgr, struct sk_buff *skb, | |||
| 383 | out2: /* send aggregated SKBs to stack */ | 383 | out2: /* send aggregated SKBs to stack */ |
| 384 | lro_flush(lro_mgr, lro_desc); | 384 | lro_flush(lro_mgr, lro_desc); |
| 385 | 385 | ||
| 386 | out: /* Original SKB has to be posted to stack */ | 386 | out: |
| 387 | skb->ip_summed = lro_mgr->ip_summed; | ||
| 388 | return 1; | 387 | return 1; |
| 389 | } | 388 | } |
| 390 | 389 | ||
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index cd6ce6ac6358..37221f659159 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c | |||
| @@ -229,6 +229,8 @@ static inline struct ipq *ip_find(struct net *net, struct iphdr *iph, u32 user) | |||
| 229 | 229 | ||
| 230 | arg.iph = iph; | 230 | arg.iph = iph; |
| 231 | arg.user = user; | 231 | arg.user = user; |
| 232 | |||
| 233 | read_lock(&ip4_frags.lock); | ||
| 232 | hash = ipqhashfn(iph->id, iph->saddr, iph->daddr, iph->protocol); | 234 | hash = ipqhashfn(iph->id, iph->saddr, iph->daddr, iph->protocol); |
| 233 | 235 | ||
| 234 | q = inet_frag_find(&net->ipv4.frags, &ip4_frags, &arg, hash); | 236 | q = inet_frag_find(&net->ipv4.frags, &ip4_frags, &arg, hash); |
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index fc54a48fde1e..850825dc86e6 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
| @@ -260,6 +260,8 @@ | |||
| 260 | #include <linux/socket.h> | 260 | #include <linux/socket.h> |
| 261 | #include <linux/random.h> | 261 | #include <linux/random.h> |
| 262 | #include <linux/bootmem.h> | 262 | #include <linux/bootmem.h> |
| 263 | #include <linux/highmem.h> | ||
| 264 | #include <linux/swap.h> | ||
| 263 | #include <linux/cache.h> | 265 | #include <linux/cache.h> |
| 264 | #include <linux/err.h> | 266 | #include <linux/err.h> |
| 265 | #include <linux/crypto.h> | 267 | #include <linux/crypto.h> |
| @@ -2620,7 +2622,7 @@ __setup("thash_entries=", set_thash_entries); | |||
| 2620 | void __init tcp_init(void) | 2622 | void __init tcp_init(void) |
| 2621 | { | 2623 | { |
| 2622 | struct sk_buff *skb = NULL; | 2624 | struct sk_buff *skb = NULL; |
| 2623 | unsigned long limit; | 2625 | unsigned long nr_pages, limit; |
| 2624 | int order, i, max_share; | 2626 | int order, i, max_share; |
| 2625 | 2627 | ||
| 2626 | BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb)); | 2628 | BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb)); |
| @@ -2689,8 +2691,9 @@ void __init tcp_init(void) | |||
| 2689 | * is up to 1/2 at 256 MB, decreasing toward zero with the amount of | 2691 | * is up to 1/2 at 256 MB, decreasing toward zero with the amount of |
| 2690 | * memory, with a floor of 128 pages. | 2692 | * memory, with a floor of 128 pages. |
| 2691 | */ | 2693 | */ |
| 2692 | limit = min(nr_all_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT); | 2694 | nr_pages = totalram_pages - totalhigh_pages; |
| 2693 | limit = (limit * (nr_all_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11); | 2695 | limit = min(nr_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT); |
| 2696 | limit = (limit * (nr_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11); | ||
| 2694 | limit = max(limit, 128UL); | 2697 | limit = max(limit, 128UL); |
| 2695 | sysctl_tcp_mem[0] = limit / 4 * 3; | 2698 | sysctl_tcp_mem[0] = limit / 4 * 3; |
| 2696 | sysctl_tcp_mem[1] = limit; | 2699 | sysctl_tcp_mem[1] = limit; |
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 12695be2c255..ffe869ac1bcf 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
| @@ -2291,7 +2291,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len) | |||
| 2291 | } | 2291 | } |
| 2292 | 2292 | ||
| 2293 | seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX " | 2293 | seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX " |
| 2294 | "%08X %5d %8d %lu %d %p %u %u %u %u %d%n", | 2294 | "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n", |
| 2295 | i, src, srcp, dest, destp, sk->sk_state, | 2295 | i, src, srcp, dest, destp, sk->sk_state, |
| 2296 | tp->write_seq - tp->snd_una, | 2296 | tp->write_seq - tp->snd_una, |
| 2297 | sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog : | 2297 | 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) | |||
| 2303 | icsk->icsk_probes_out, | 2303 | icsk->icsk_probes_out, |
| 2304 | sock_i_ino(sk), | 2304 | sock_i_ino(sk), |
| 2305 | atomic_read(&sk->sk_refcnt), sk, | 2305 | atomic_read(&sk->sk_refcnt), sk, |
| 2306 | icsk->icsk_rto, | 2306 | jiffies_to_clock_t(icsk->icsk_rto), |
| 2307 | icsk->icsk_ack.ato, | 2307 | jiffies_to_clock_t(icsk->icsk_ack.ato), |
| 2308 | (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, | 2308 | (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, |
| 2309 | tp->snd_cwnd, | 2309 | tp->snd_cwnd, |
| 2310 | tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh, | 2310 | tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh, |
diff --git a/net/ipv6/netfilter/ip6table_mangle.c b/net/ipv6/netfilter/ip6table_mangle.c index 27a5e8b48d93..f405cea21a8b 100644 --- a/net/ipv6/netfilter/ip6table_mangle.c +++ b/net/ipv6/netfilter/ip6table_mangle.c | |||
| @@ -129,7 +129,7 @@ static struct nf_hook_ops ip6t_ops[] __read_mostly = { | |||
| 129 | .priority = NF_IP6_PRI_MANGLE, | 129 | .priority = NF_IP6_PRI_MANGLE, |
| 130 | }, | 130 | }, |
| 131 | { | 131 | { |
| 132 | .hook = ip6t_local_hook, | 132 | .hook = ip6t_route_hook, |
| 133 | .owner = THIS_MODULE, | 133 | .owner = THIS_MODULE, |
| 134 | .pf = PF_INET6, | 134 | .pf = PF_INET6, |
| 135 | .hooknum = NF_INET_LOCAL_IN, | 135 | .hooknum = NF_INET_LOCAL_IN, |
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c index e65e26e210ee..cf20bc4fd60d 100644 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c | |||
| @@ -207,9 +207,10 @@ fq_find(__be32 id, struct in6_addr *src, struct in6_addr *dst) | |||
| 207 | arg.id = id; | 207 | arg.id = id; |
| 208 | arg.src = src; | 208 | arg.src = src; |
| 209 | arg.dst = dst; | 209 | arg.dst = dst; |
| 210 | |||
| 211 | read_lock_bh(&nf_frags.lock); | ||
| 210 | hash = ip6qhashfn(id, src, dst); | 212 | hash = ip6qhashfn(id, src, dst); |
| 211 | 213 | ||
| 212 | local_bh_disable(); | ||
| 213 | q = inet_frag_find(&nf_init_frags, &nf_frags, &arg, hash); | 214 | q = inet_frag_find(&nf_init_frags, &nf_frags, &arg, hash); |
| 214 | local_bh_enable(); | 215 | local_bh_enable(); |
| 215 | if (q == NULL) | 216 | if (q == NULL) |
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c index 798cabc7535b..a60d7d129713 100644 --- a/net/ipv6/reassembly.c +++ b/net/ipv6/reassembly.c | |||
| @@ -247,6 +247,8 @@ fq_find(struct net *net, __be32 id, struct in6_addr *src, struct in6_addr *dst, | |||
| 247 | arg.id = id; | 247 | arg.id = id; |
| 248 | arg.src = src; | 248 | arg.src = src; |
| 249 | arg.dst = dst; | 249 | arg.dst = dst; |
| 250 | |||
| 251 | read_lock(&ip6_frags.lock); | ||
| 250 | hash = ip6qhashfn(id, src, dst); | 252 | hash = ip6qhashfn(id, src, dst); |
| 251 | 253 | ||
| 252 | q = inet_frag_find(&net->ipv6.frags, &ip6_frags, &arg, hash); | 254 | q = inet_frag_find(&net->ipv6.frags, &ip6_frags, &arg, hash); |
diff --git a/net/ipv6/route.c b/net/ipv6/route.c index d1f3e19b06c7..7ff687020fa9 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c | |||
| @@ -240,7 +240,7 @@ static inline int rt6_need_strict(struct in6_addr *daddr) | |||
| 240 | static inline struct rt6_info *rt6_device_match(struct net *net, | 240 | static inline struct rt6_info *rt6_device_match(struct net *net, |
| 241 | struct rt6_info *rt, | 241 | struct rt6_info *rt, |
| 242 | int oif, | 242 | int oif, |
| 243 | int strict) | 243 | int flags) |
| 244 | { | 244 | { |
| 245 | struct rt6_info *local = NULL; | 245 | struct rt6_info *local = NULL; |
| 246 | struct rt6_info *sprt; | 246 | struct rt6_info *sprt; |
| @@ -253,7 +253,7 @@ static inline struct rt6_info *rt6_device_match(struct net *net, | |||
| 253 | if (dev->flags & IFF_LOOPBACK) { | 253 | if (dev->flags & IFF_LOOPBACK) { |
| 254 | if (sprt->rt6i_idev == NULL || | 254 | if (sprt->rt6i_idev == NULL || |
| 255 | sprt->rt6i_idev->dev->ifindex != oif) { | 255 | sprt->rt6i_idev->dev->ifindex != oif) { |
| 256 | if (strict && oif) | 256 | if (flags & RT6_LOOKUP_F_IFACE && oif) |
| 257 | continue; | 257 | continue; |
| 258 | if (local && (!oif || | 258 | if (local && (!oif || |
| 259 | local->rt6i_idev->dev->ifindex == oif)) | 259 | local->rt6i_idev->dev->ifindex == oif)) |
| @@ -266,7 +266,7 @@ static inline struct rt6_info *rt6_device_match(struct net *net, | |||
| 266 | if (local) | 266 | if (local) |
| 267 | return local; | 267 | return local; |
| 268 | 268 | ||
| 269 | if (strict) | 269 | if (flags & RT6_LOOKUP_F_IFACE) |
| 270 | return net->ipv6.ip6_null_entry; | 270 | return net->ipv6.ip6_null_entry; |
| 271 | } | 271 | } |
| 272 | return rt; | 272 | return rt; |
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index cb46749d4c32..40ea9c36d24b 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c | |||
| @@ -2036,7 +2036,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i) | |||
| 2036 | 2036 | ||
| 2037 | seq_printf(seq, | 2037 | seq_printf(seq, |
| 2038 | "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " | 2038 | "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " |
| 2039 | "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %u %u %u %u %d\n", | 2039 | "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %lu %lu %u %u %d\n", |
| 2040 | i, | 2040 | i, |
| 2041 | src->s6_addr32[0], src->s6_addr32[1], | 2041 | src->s6_addr32[0], src->s6_addr32[1], |
| 2042 | src->s6_addr32[2], src->s6_addr32[3], srcp, | 2042 | 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) | |||
| 2052 | icsk->icsk_probes_out, | 2052 | icsk->icsk_probes_out, |
| 2053 | sock_i_ino(sp), | 2053 | sock_i_ino(sp), |
| 2054 | atomic_read(&sp->sk_refcnt), sp, | 2054 | atomic_read(&sp->sk_refcnt), sp, |
| 2055 | icsk->icsk_rto, | 2055 | jiffies_to_clock_t(icsk->icsk_rto), |
| 2056 | icsk->icsk_ack.ato, | 2056 | jiffies_to_clock_t(icsk->icsk_ack.ato), |
| 2057 | (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong, | 2057 | (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong, |
| 2058 | tp->snd_cwnd, tp->snd_ssthresh>=0xFFFF?-1:tp->snd_ssthresh | 2058 | tp->snd_cwnd, tp->snd_ssthresh>=0xFFFF?-1:tp->snd_ssthresh |
| 2059 | ); | 2059 | ); |
diff --git a/net/mac80211/key.c b/net/mac80211/key.c index 150d66dbda9d..220e83be3ef4 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c | |||
| @@ -380,6 +380,15 @@ void ieee80211_key_free(struct ieee80211_key *key) | |||
| 380 | if (!key) | 380 | if (!key) |
| 381 | return; | 381 | return; |
| 382 | 382 | ||
| 383 | if (!key->sdata) { | ||
| 384 | /* The key has not been linked yet, simply free it | ||
| 385 | * and don't Oops */ | ||
| 386 | if (key->conf.alg == ALG_CCMP) | ||
| 387 | ieee80211_aes_key_free(key->u.ccmp.tfm); | ||
| 388 | kfree(key); | ||
| 389 | return; | ||
| 390 | } | ||
| 391 | |||
| 383 | spin_lock_irqsave(&key->sdata->local->key_lock, flags); | 392 | spin_lock_irqsave(&key->sdata->local->key_lock, flags); |
| 384 | __ieee80211_key_free(key); | 393 | __ieee80211_key_free(key); |
| 385 | spin_unlock_irqrestore(&key->sdata->local->key_lock, flags); | 394 | spin_unlock_irqrestore(&key->sdata->local->key_lock, flags); |
diff --git a/net/mac80211/wext.c b/net/mac80211/wext.c index 6106cb79060c..e8404212ad57 100644 --- a/net/mac80211/wext.c +++ b/net/mac80211/wext.c | |||
| @@ -95,6 +95,13 @@ static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr, | |||
| 95 | } | 95 | } |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | if (alg == ALG_WEP && | ||
| 99 | key_len != LEN_WEP40 && key_len != LEN_WEP104) { | ||
| 100 | ieee80211_key_free(key); | ||
| 101 | err = -EINVAL; | ||
| 102 | goto out_unlock; | ||
| 103 | } | ||
| 104 | |||
| 98 | ieee80211_key_link(key, sdata, sta); | 105 | ieee80211_key_link(key, sdata, sta); |
| 99 | 106 | ||
| 100 | if (set_tx_key || (!sta && !sdata->default_key && key)) | 107 | if (set_tx_key || (!sta && !sdata->default_key && key)) |
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c index 635b996c8c35..5d09e8698b57 100644 --- a/net/mac80211/wme.c +++ b/net/mac80211/wme.c | |||
| @@ -323,8 +323,7 @@ static void wme_qdiscop_destroy(struct Qdisc* qd) | |||
| 323 | struct ieee80211_hw *hw = &local->hw; | 323 | struct ieee80211_hw *hw = &local->hw; |
| 324 | int queue; | 324 | int queue; |
| 325 | 325 | ||
| 326 | tcf_destroy_chain(q->filter_list); | 326 | tcf_destroy_chain(&q->filter_list); |
| 327 | q->filter_list = NULL; | ||
| 328 | 327 | ||
| 329 | for (queue=0; queue < hw->queues; queue++) { | 328 | for (queue=0; queue < hw->queues; queue++) { |
| 330 | skb_queue_purge(&q->requeued[queue]); | 329 | skb_queue_purge(&q->requeued[queue]); |
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c index ba94004fe323..271cd01d57ae 100644 --- a/net/netfilter/nf_conntrack_proto_tcp.c +++ b/net/netfilter/nf_conntrack_proto_tcp.c | |||
| @@ -331,12 +331,13 @@ static unsigned int get_conntrack_index(const struct tcphdr *tcph) | |||
| 331 | 331 | ||
| 332 | I. Upper bound for valid data: seq <= sender.td_maxend | 332 | I. Upper bound for valid data: seq <= sender.td_maxend |
| 333 | II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin | 333 | II. Lower bound for valid data: seq + len >= sender.td_end - receiver.td_maxwin |
| 334 | III. Upper bound for valid ack: sack <= receiver.td_end | 334 | III. Upper bound for valid (s)ack: sack <= receiver.td_end |
| 335 | IV. Lower bound for valid ack: ack >= receiver.td_end - MAXACKWINDOW | 335 | IV. Lower bound for valid (s)ack: sack >= receiver.td_end - MAXACKWINDOW |
| 336 | 336 | ||
| 337 | where sack is the highest right edge of sack block found in the packet. | 337 | where sack is the highest right edge of sack block found in the packet |
| 338 | or ack in the case of packet without SACK option. | ||
| 338 | 339 | ||
| 339 | The upper bound limit for a valid ack is not ignored - | 340 | The upper bound limit for a valid (s)ack is not ignored - |
| 340 | we doesn't have to deal with fragments. | 341 | we doesn't have to deal with fragments. |
| 341 | */ | 342 | */ |
| 342 | 343 | ||
| @@ -606,12 +607,12 @@ static bool tcp_in_window(const struct nf_conn *ct, | |||
| 606 | before(seq, sender->td_maxend + 1), | 607 | before(seq, sender->td_maxend + 1), |
| 607 | after(end, sender->td_end - receiver->td_maxwin - 1), | 608 | after(end, sender->td_end - receiver->td_maxwin - 1), |
| 608 | before(sack, receiver->td_end + 1), | 609 | before(sack, receiver->td_end + 1), |
| 609 | after(ack, receiver->td_end - MAXACKWINDOW(sender))); | 610 | after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)); |
| 610 | 611 | ||
| 611 | if (before(seq, sender->td_maxend + 1) && | 612 | if (before(seq, sender->td_maxend + 1) && |
| 612 | after(end, sender->td_end - receiver->td_maxwin - 1) && | 613 | after(end, sender->td_end - receiver->td_maxwin - 1) && |
| 613 | before(sack, receiver->td_end + 1) && | 614 | before(sack, receiver->td_end + 1) && |
| 614 | after(ack, receiver->td_end - MAXACKWINDOW(sender))) { | 615 | after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)) { |
| 615 | /* | 616 | /* |
| 616 | * Take into account window scaling (RFC 1323). | 617 | * Take into account window scaling (RFC 1323). |
| 617 | */ | 618 | */ |
diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index 0099da5b2591..52b2611a6eb6 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c | |||
| @@ -1534,7 +1534,7 @@ static int netlbl_unlabel_staticlistdef(struct sk_buff *skb, | |||
| 1534 | } | 1534 | } |
| 1535 | } | 1535 | } |
| 1536 | list_for_each_entry_rcu(addr6, &iface->addr6_list, list) { | 1536 | list_for_each_entry_rcu(addr6, &iface->addr6_list, list) { |
| 1537 | if (addr6->valid || iter_addr6++ < skip_addr6) | 1537 | if (!addr6->valid || iter_addr6++ < skip_addr6) |
| 1538 | continue; | 1538 | continue; |
| 1539 | if (netlbl_unlabel_staticlist_gen(NLBL_UNLABEL_C_STATICLISTDEF, | 1539 | if (netlbl_unlabel_staticlist_gen(NLBL_UNLABEL_C_STATICLISTDEF, |
| 1540 | iface, | 1540 | iface, |
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 9b97f8006c9c..349aba189558 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c | |||
| @@ -886,7 +886,7 @@ retry: | |||
| 886 | return netlink_unicast_kernel(sk, skb); | 886 | return netlink_unicast_kernel(sk, skb); |
| 887 | 887 | ||
| 888 | if (sk_filter(sk, skb)) { | 888 | if (sk_filter(sk, skb)) { |
| 889 | int err = skb->len; | 889 | err = skb->len; |
| 890 | kfree_skb(skb); | 890 | kfree_skb(skb); |
| 891 | sock_put(sk); | 891 | sock_put(sk); |
| 892 | return err; | 892 | return err; |
diff --git a/net/netlink/attr.c b/net/netlink/attr.c index 47bbf45ae5d7..2d106cfe1d27 100644 --- a/net/netlink/attr.c +++ b/net/netlink/attr.c | |||
| @@ -132,6 +132,7 @@ errout: | |||
| 132 | * @maxtype: maximum attribute type to be expected | 132 | * @maxtype: maximum attribute type to be expected |
| 133 | * @head: head of attribute stream | 133 | * @head: head of attribute stream |
| 134 | * @len: length of attribute stream | 134 | * @len: length of attribute stream |
| 135 | * @policy: validation policy | ||
| 135 | * | 136 | * |
| 136 | * Parses a stream of attributes and stores a pointer to each attribute in | 137 | * Parses a stream of attributes and stores a pointer to each attribute in |
| 137 | * the tb array accessable via the attribute type. Attributes with a type | 138 | * 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) | |||
| 194 | /** | 195 | /** |
| 195 | * nla_strlcpy - Copy string attribute payload into a sized buffer | 196 | * nla_strlcpy - Copy string attribute payload into a sized buffer |
| 196 | * @dst: where to copy the string to | 197 | * @dst: where to copy the string to |
| 197 | * @src: attribute to copy the string from | 198 | * @nla: attribute to copy the string from |
| 198 | * @dstsize: size of destination buffer | 199 | * @dstsize: size of destination buffer |
| 199 | * | 200 | * |
| 200 | * Copies at most dstsize - 1 bytes into the destination buffer. | 201 | * 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) | |||
| 340 | } | 341 | } |
| 341 | 342 | ||
| 342 | /** | 343 | /** |
| 343 | * nla_reserve - reserve room for attribute without header | 344 | * nla_reserve_nohdr - reserve room for attribute without header |
| 344 | * @skb: socket buffer to reserve room on | 345 | * @skb: socket buffer to reserve room on |
| 345 | * @len: length of attribute payload | 346 | * @attrlen: length of attribute payload |
| 346 | * | 347 | * |
| 347 | * Reserves room for attribute payload without a header. | 348 | * Reserves room for attribute payload without a header. |
| 348 | * | 349 | * |
diff --git a/net/sched/Kconfig b/net/sched/Kconfig index 82adfe6447d7..9437b27ff84d 100644 --- a/net/sched/Kconfig +++ b/net/sched/Kconfig | |||
| @@ -106,17 +106,6 @@ config NET_SCH_PRIO | |||
| 106 | To compile this code as a module, choose M here: the | 106 | To compile this code as a module, choose M here: the |
| 107 | module will be called sch_prio. | 107 | module will be called sch_prio. |
| 108 | 108 | ||
| 109 | config NET_SCH_RR | ||
| 110 | tristate "Multi Band Round Robin Queuing (RR)" | ||
| 111 | select NET_SCH_PRIO | ||
| 112 | ---help--- | ||
| 113 | Say Y here if you want to use an n-band round robin packet | ||
| 114 | scheduler. | ||
| 115 | |||
| 116 | The module uses sch_prio for its framework and is aliased as | ||
| 117 | sch_rr, so it will load sch_prio, although it is referred | ||
| 118 | to using sch_rr. | ||
| 119 | |||
| 120 | config NET_SCH_RED | 109 | config NET_SCH_RED |
| 121 | tristate "Random Early Detection (RED)" | 110 | tristate "Random Early Detection (RED)" |
| 122 | ---help--- | 111 | ---help--- |
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index c40773cdbe45..10f01ad04380 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c | |||
| @@ -1252,12 +1252,12 @@ void tcf_destroy(struct tcf_proto *tp) | |||
| 1252 | kfree(tp); | 1252 | kfree(tp); |
| 1253 | } | 1253 | } |
| 1254 | 1254 | ||
| 1255 | void tcf_destroy_chain(struct tcf_proto *fl) | 1255 | void tcf_destroy_chain(struct tcf_proto **fl) |
| 1256 | { | 1256 | { |
| 1257 | struct tcf_proto *tp; | 1257 | struct tcf_proto *tp; |
| 1258 | 1258 | ||
| 1259 | while ((tp = fl) != NULL) { | 1259 | while ((tp = *fl) != NULL) { |
| 1260 | fl = tp->next; | 1260 | *fl = tp->next; |
| 1261 | tcf_destroy(tp); | 1261 | tcf_destroy(tp); |
| 1262 | } | 1262 | } |
| 1263 | } | 1263 | } |
diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c index 335273416384..db0e23ae85f8 100644 --- a/net/sched/sch_atm.c +++ b/net/sched/sch_atm.c | |||
| @@ -160,7 +160,7 @@ static void atm_tc_put(struct Qdisc *sch, unsigned long cl) | |||
| 160 | *prev = flow->next; | 160 | *prev = flow->next; |
| 161 | pr_debug("atm_tc_put: qdisc %p\n", flow->q); | 161 | pr_debug("atm_tc_put: qdisc %p\n", flow->q); |
| 162 | qdisc_destroy(flow->q); | 162 | qdisc_destroy(flow->q); |
| 163 | tcf_destroy_chain(flow->filter_list); | 163 | tcf_destroy_chain(&flow->filter_list); |
| 164 | if (flow->sock) { | 164 | if (flow->sock) { |
| 165 | pr_debug("atm_tc_put: f_count %d\n", | 165 | pr_debug("atm_tc_put: f_count %d\n", |
| 166 | file_count(flow->sock->file)); | 166 | file_count(flow->sock->file)); |
| @@ -586,10 +586,11 @@ static void atm_tc_destroy(struct Qdisc *sch) | |||
| 586 | struct atm_flow_data *flow; | 586 | struct atm_flow_data *flow; |
| 587 | 587 | ||
| 588 | pr_debug("atm_tc_destroy(sch %p,[qdisc %p])\n", sch, p); | 588 | pr_debug("atm_tc_destroy(sch %p,[qdisc %p])\n", sch, p); |
| 589 | for (flow = p->flows; flow; flow = flow->next) | ||
| 590 | tcf_destroy_chain(&flow->filter_list); | ||
| 591 | |||
| 589 | /* races ? */ | 592 | /* races ? */ |
| 590 | while ((flow = p->flows)) { | 593 | while ((flow = p->flows)) { |
| 591 | tcf_destroy_chain(flow->filter_list); | ||
| 592 | flow->filter_list = NULL; | ||
| 593 | if (flow->ref > 1) | 594 | if (flow->ref > 1) |
| 594 | printk(KERN_ERR "atm_destroy: %p->ref = %d\n", flow, | 595 | printk(KERN_ERR "atm_destroy: %p->ref = %d\n", flow, |
| 595 | flow->ref); | 596 | flow->ref); |
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c index 09969c1fbc08..2a3c97f7dc63 100644 --- a/net/sched/sch_cbq.c +++ b/net/sched/sch_cbq.c | |||
| @@ -1704,7 +1704,7 @@ static void cbq_destroy_class(struct Qdisc *sch, struct cbq_class *cl) | |||
| 1704 | 1704 | ||
| 1705 | BUG_TRAP(!cl->filters); | 1705 | BUG_TRAP(!cl->filters); |
| 1706 | 1706 | ||
| 1707 | tcf_destroy_chain(cl->filter_list); | 1707 | tcf_destroy_chain(&cl->filter_list); |
| 1708 | qdisc_destroy(cl->q); | 1708 | qdisc_destroy(cl->q); |
| 1709 | qdisc_put_rtab(cl->R_tab); | 1709 | qdisc_put_rtab(cl->R_tab); |
| 1710 | gen_kill_estimator(&cl->bstats, &cl->rate_est); | 1710 | gen_kill_estimator(&cl->bstats, &cl->rate_est); |
| @@ -1728,10 +1728,8 @@ cbq_destroy(struct Qdisc* sch) | |||
| 1728 | * be bound to classes which have been destroyed already. --TGR '04 | 1728 | * be bound to classes which have been destroyed already. --TGR '04 |
| 1729 | */ | 1729 | */ |
| 1730 | for (h = 0; h < 16; h++) { | 1730 | for (h = 0; h < 16; h++) { |
| 1731 | for (cl = q->classes[h]; cl; cl = cl->next) { | 1731 | for (cl = q->classes[h]; cl; cl = cl->next) |
| 1732 | tcf_destroy_chain(cl->filter_list); | 1732 | tcf_destroy_chain(&cl->filter_list); |
| 1733 | cl->filter_list = NULL; | ||
| 1734 | } | ||
| 1735 | } | 1733 | } |
| 1736 | for (h = 0; h < 16; h++) { | 1734 | for (h = 0; h < 16; h++) { |
| 1737 | struct cbq_class *next; | 1735 | struct cbq_class *next; |
diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c index 64465bacbe79..c4c1317cd47d 100644 --- a/net/sched/sch_dsmark.c +++ b/net/sched/sch_dsmark.c | |||
| @@ -416,7 +416,7 @@ static void dsmark_destroy(struct Qdisc *sch) | |||
| 416 | 416 | ||
| 417 | pr_debug("dsmark_destroy(sch %p,[qdisc %p])\n", sch, p); | 417 | pr_debug("dsmark_destroy(sch %p,[qdisc %p])\n", sch, p); |
| 418 | 418 | ||
| 419 | tcf_destroy_chain(p->filter_list); | 419 | tcf_destroy_chain(&p->filter_list); |
| 420 | qdisc_destroy(p->q); | 420 | qdisc_destroy(p->q); |
| 421 | kfree(p->mask); | 421 | kfree(p->mask); |
| 422 | } | 422 | } |
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index d355e5e47fe3..13afa7214392 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c | |||
| @@ -468,7 +468,7 @@ struct Qdisc *qdisc_alloc(struct net_device *dev, struct Qdisc_ops *ops) | |||
| 468 | 468 | ||
| 469 | return sch; | 469 | return sch; |
| 470 | errout: | 470 | errout: |
| 471 | return ERR_PTR(-err); | 471 | return ERR_PTR(err); |
| 472 | } | 472 | } |
| 473 | 473 | ||
| 474 | struct Qdisc * qdisc_create_dflt(struct net_device *dev, struct Qdisc_ops *ops, | 474 | struct Qdisc * qdisc_create_dflt(struct net_device *dev, struct Qdisc_ops *ops, |
diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c index fdfaa3fcc16d..e817aa00441d 100644 --- a/net/sched/sch_hfsc.c +++ b/net/sched/sch_hfsc.c | |||
| @@ -1123,7 +1123,7 @@ hfsc_destroy_class(struct Qdisc *sch, struct hfsc_class *cl) | |||
| 1123 | { | 1123 | { |
| 1124 | struct hfsc_sched *q = qdisc_priv(sch); | 1124 | struct hfsc_sched *q = qdisc_priv(sch); |
| 1125 | 1125 | ||
| 1126 | tcf_destroy_chain(cl->filter_list); | 1126 | tcf_destroy_chain(&cl->filter_list); |
| 1127 | qdisc_destroy(cl->qdisc); | 1127 | qdisc_destroy(cl->qdisc); |
| 1128 | gen_kill_estimator(&cl->bstats, &cl->rate_est); | 1128 | gen_kill_estimator(&cl->bstats, &cl->rate_est); |
| 1129 | if (cl != &q->root) | 1129 | if (cl != &q->root) |
| @@ -1541,6 +1541,10 @@ hfsc_destroy_qdisc(struct Qdisc *sch) | |||
| 1541 | unsigned int i; | 1541 | unsigned int i; |
| 1542 | 1542 | ||
| 1543 | for (i = 0; i < HFSC_HSIZE; i++) { | 1543 | for (i = 0; i < HFSC_HSIZE; i++) { |
| 1544 | list_for_each_entry(cl, &q->clhash[i], hlist) | ||
| 1545 | tcf_destroy_chain(&cl->filter_list); | ||
| 1546 | } | ||
| 1547 | for (i = 0; i < HFSC_HSIZE; i++) { | ||
| 1544 | list_for_each_entry_safe(cl, next, &q->clhash[i], hlist) | 1548 | list_for_each_entry_safe(cl, next, &q->clhash[i], hlist) |
| 1545 | hfsc_destroy_class(sch, cl); | 1549 | hfsc_destroy_class(sch, cl); |
| 1546 | } | 1550 | } |
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 6807c97985a5..3fb58f428f72 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c | |||
| @@ -1238,7 +1238,7 @@ static void htb_destroy_class(struct Qdisc *sch, struct htb_class *cl) | |||
| 1238 | qdisc_put_rtab(cl->rate); | 1238 | qdisc_put_rtab(cl->rate); |
| 1239 | qdisc_put_rtab(cl->ceil); | 1239 | qdisc_put_rtab(cl->ceil); |
| 1240 | 1240 | ||
| 1241 | tcf_destroy_chain(cl->filter_list); | 1241 | tcf_destroy_chain(&cl->filter_list); |
| 1242 | 1242 | ||
| 1243 | while (!list_empty(&cl->children)) | 1243 | while (!list_empty(&cl->children)) |
| 1244 | htb_destroy_class(sch, list_entry(cl->children.next, | 1244 | htb_destroy_class(sch, list_entry(cl->children.next, |
| @@ -1267,7 +1267,7 @@ static void htb_destroy(struct Qdisc *sch) | |||
| 1267 | and surprisingly it worked in 2.4. But it must precede it | 1267 | and surprisingly it worked in 2.4. But it must precede it |
| 1268 | because filter need its target class alive to be able to call | 1268 | because filter need its target class alive to be able to call |
| 1269 | unbind_filter on it (without Oops). */ | 1269 | unbind_filter on it (without Oops). */ |
| 1270 | tcf_destroy_chain(q->filter_list); | 1270 | tcf_destroy_chain(&q->filter_list); |
| 1271 | 1271 | ||
| 1272 | while (!list_empty(&q->root)) | 1272 | while (!list_empty(&q->root)) |
| 1273 | htb_destroy_class(sch, list_entry(q->root.next, | 1273 | htb_destroy_class(sch, list_entry(q->root.next, |
diff --git a/net/sched/sch_ingress.c b/net/sched/sch_ingress.c index 274b1ddb160c..956c80ad5965 100644 --- a/net/sched/sch_ingress.c +++ b/net/sched/sch_ingress.c | |||
| @@ -104,7 +104,7 @@ static void ingress_destroy(struct Qdisc *sch) | |||
| 104 | { | 104 | { |
| 105 | struct ingress_qdisc_data *p = qdisc_priv(sch); | 105 | struct ingress_qdisc_data *p = qdisc_priv(sch); |
| 106 | 106 | ||
| 107 | tcf_destroy_chain(p->filter_list); | 107 | tcf_destroy_chain(&p->filter_list); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb) | 110 | static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb) |
diff --git a/net/sched/sch_prio.c b/net/sched/sch_prio.c index 4aa2b45dad0a..5532f1031ab5 100644 --- a/net/sched/sch_prio.c +++ b/net/sched/sch_prio.c | |||
| @@ -219,7 +219,7 @@ prio_destroy(struct Qdisc* sch) | |||
| 219 | int prio; | 219 | int prio; |
| 220 | struct prio_sched_data *q = qdisc_priv(sch); | 220 | struct prio_sched_data *q = qdisc_priv(sch); |
| 221 | 221 | ||
| 222 | tcf_destroy_chain(q->filter_list); | 222 | tcf_destroy_chain(&q->filter_list); |
| 223 | for (prio=0; prio<q->bands; prio++) | 223 | for (prio=0; prio<q->bands; prio++) |
| 224 | qdisc_destroy(q->queues[prio]); | 224 | qdisc_destroy(q->queues[prio]); |
| 225 | } | 225 | } |
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c index f0463d757a98..6a97afbfb952 100644 --- a/net/sched/sch_sfq.c +++ b/net/sched/sch_sfq.c | |||
| @@ -520,7 +520,7 @@ static void sfq_destroy(struct Qdisc *sch) | |||
| 520 | { | 520 | { |
| 521 | struct sfq_sched_data *q = qdisc_priv(sch); | 521 | struct sfq_sched_data *q = qdisc_priv(sch); |
| 522 | 522 | ||
| 523 | tcf_destroy_chain(q->filter_list); | 523 | tcf_destroy_chain(&q->filter_list); |
| 524 | q->perturb_period = 0; | 524 | q->perturb_period = 0; |
| 525 | del_timer_sync(&q->perturb_timer); | 525 | del_timer_sync(&q->perturb_timer); |
| 526 | } | 526 | } |
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 657835f227d3..783317dacd30 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
| @@ -487,8 +487,8 @@ static int unix_socketpair(struct socket *, struct socket *); | |||
| 487 | static int unix_accept(struct socket *, struct socket *, int); | 487 | static int unix_accept(struct socket *, struct socket *, int); |
| 488 | static int unix_getname(struct socket *, struct sockaddr *, int *, int); | 488 | static int unix_getname(struct socket *, struct sockaddr *, int *, int); |
| 489 | static unsigned int unix_poll(struct file *, struct socket *, poll_table *); | 489 | static unsigned int unix_poll(struct file *, struct socket *, poll_table *); |
| 490 | static unsigned int unix_datagram_poll(struct file *, struct socket *, | 490 | static unsigned int unix_dgram_poll(struct file *, struct socket *, |
| 491 | poll_table *); | 491 | poll_table *); |
| 492 | static int unix_ioctl(struct socket *, unsigned int, unsigned long); | 492 | static int unix_ioctl(struct socket *, unsigned int, unsigned long); |
| 493 | static int unix_shutdown(struct socket *, int); | 493 | static int unix_shutdown(struct socket *, int); |
| 494 | static int unix_stream_sendmsg(struct kiocb *, struct socket *, | 494 | static int unix_stream_sendmsg(struct kiocb *, struct socket *, |
| @@ -534,7 +534,7 @@ static const struct proto_ops unix_dgram_ops = { | |||
| 534 | .socketpair = unix_socketpair, | 534 | .socketpair = unix_socketpair, |
| 535 | .accept = sock_no_accept, | 535 | .accept = sock_no_accept, |
| 536 | .getname = unix_getname, | 536 | .getname = unix_getname, |
| 537 | .poll = unix_datagram_poll, | 537 | .poll = unix_dgram_poll, |
| 538 | .ioctl = unix_ioctl, | 538 | .ioctl = unix_ioctl, |
| 539 | .listen = sock_no_listen, | 539 | .listen = sock_no_listen, |
| 540 | .shutdown = unix_shutdown, | 540 | .shutdown = unix_shutdown, |
| @@ -555,7 +555,7 @@ static const struct proto_ops unix_seqpacket_ops = { | |||
| 555 | .socketpair = unix_socketpair, | 555 | .socketpair = unix_socketpair, |
| 556 | .accept = unix_accept, | 556 | .accept = unix_accept, |
| 557 | .getname = unix_getname, | 557 | .getname = unix_getname, |
| 558 | .poll = unix_datagram_poll, | 558 | .poll = unix_dgram_poll, |
| 559 | .ioctl = unix_ioctl, | 559 | .ioctl = unix_ioctl, |
| 560 | .listen = unix_listen, | 560 | .listen = unix_listen, |
| 561 | .shutdown = unix_shutdown, | 561 | .shutdown = unix_shutdown, |
| @@ -1994,29 +1994,13 @@ static unsigned int unix_poll(struct file * file, struct socket *sock, poll_tabl | |||
| 1994 | return mask; | 1994 | return mask; |
| 1995 | } | 1995 | } |
| 1996 | 1996 | ||
| 1997 | static unsigned int unix_datagram_poll(struct file *file, struct socket *sock, | 1997 | static unsigned int unix_dgram_poll(struct file *file, struct socket *sock, |
| 1998 | poll_table *wait) | 1998 | poll_table *wait) |
| 1999 | { | 1999 | { |
| 2000 | struct sock *sk = sock->sk, *peer; | 2000 | struct sock *sk = sock->sk, *other; |
| 2001 | unsigned int mask; | 2001 | unsigned int mask, writable; |
| 2002 | 2002 | ||
| 2003 | poll_wait(file, sk->sk_sleep, wait); | 2003 | poll_wait(file, sk->sk_sleep, wait); |
| 2004 | |||
| 2005 | peer = unix_peer_get(sk); | ||
| 2006 | if (peer) { | ||
| 2007 | if (peer != sk) { | ||
| 2008 | /* | ||
| 2009 | * Writability of a connected socket additionally | ||
| 2010 | * depends on the state of the receive queue of the | ||
| 2011 | * peer. | ||
| 2012 | */ | ||
| 2013 | poll_wait(file, &unix_sk(peer)->peer_wait, wait); | ||
| 2014 | } else { | ||
| 2015 | sock_put(peer); | ||
| 2016 | peer = NULL; | ||
| 2017 | } | ||
| 2018 | } | ||
| 2019 | |||
| 2020 | mask = 0; | 2004 | mask = 0; |
| 2021 | 2005 | ||
| 2022 | /* exceptional events? */ | 2006 | /* exceptional events? */ |
| @@ -2042,14 +2026,26 @@ static unsigned int unix_datagram_poll(struct file *file, struct socket *sock, | |||
| 2042 | } | 2026 | } |
| 2043 | 2027 | ||
| 2044 | /* writable? */ | 2028 | /* writable? */ |
| 2045 | if (unix_writable(sk) && !(peer && unix_recvq_full(peer))) | 2029 | writable = unix_writable(sk); |
| 2030 | if (writable) { | ||
| 2031 | other = unix_peer_get(sk); | ||
| 2032 | if (other) { | ||
| 2033 | if (unix_peer(other) != sk) { | ||
| 2034 | poll_wait(file, &unix_sk(other)->peer_wait, | ||
| 2035 | wait); | ||
| 2036 | if (unix_recvq_full(other)) | ||
| 2037 | writable = 0; | ||
| 2038 | } | ||
| 2039 | |||
| 2040 | sock_put(other); | ||
| 2041 | } | ||
| 2042 | } | ||
| 2043 | |||
| 2044 | if (writable) | ||
| 2046 | mask |= POLLOUT | POLLWRNORM | POLLWRBAND; | 2045 | mask |= POLLOUT | POLLWRNORM | POLLWRBAND; |
| 2047 | else | 2046 | else |
| 2048 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); | 2047 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); |
| 2049 | 2048 | ||
| 2050 | if (peer) | ||
| 2051 | sock_put(peer); | ||
| 2052 | |||
| 2053 | return mask; | 2049 | return mask; |
| 2054 | } | 2050 | } |
| 2055 | 2051 | ||
diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 185488da2466..855bff4b3250 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c | |||
| @@ -80,6 +80,23 @@ static const struct ieee80211_channel_range ieee80211_JP_channels[] = { | |||
| 80 | IEEE80211_CHAN_RADAR), | 80 | IEEE80211_CHAN_RADAR), |
| 81 | }; | 81 | }; |
| 82 | 82 | ||
| 83 | static const struct ieee80211_channel_range ieee80211_EU_channels[] = { | ||
| 84 | /* IEEE 802.11b/g, channels 1..13 */ | ||
| 85 | RANGE_PWR(2412, 2472, 20, 6, 0), | ||
| 86 | /* IEEE 802.11a, channel 36*/ | ||
| 87 | RANGE_PWR(5180, 5180, 23, 6, IEEE80211_CHAN_PASSIVE_SCAN), | ||
| 88 | /* IEEE 802.11a, channel 40*/ | ||
| 89 | RANGE_PWR(5200, 5200, 23, 6, IEEE80211_CHAN_PASSIVE_SCAN), | ||
| 90 | /* IEEE 802.11a, channel 44*/ | ||
| 91 | RANGE_PWR(5220, 5220, 23, 6, IEEE80211_CHAN_PASSIVE_SCAN), | ||
| 92 | /* IEEE 802.11a, channels 48..64 */ | ||
| 93 | RANGE_PWR(5240, 5320, 23, 6, IEEE80211_CHAN_NO_IBSS | | ||
| 94 | IEEE80211_CHAN_RADAR), | ||
| 95 | /* IEEE 802.11a, channels 100..140 */ | ||
| 96 | RANGE_PWR(5500, 5700, 30, 6, IEEE80211_CHAN_NO_IBSS | | ||
| 97 | IEEE80211_CHAN_RADAR), | ||
| 98 | }; | ||
| 99 | |||
| 83 | #define REGDOM(_code) \ | 100 | #define REGDOM(_code) \ |
| 84 | { \ | 101 | { \ |
| 85 | .code = __stringify(_code), \ | 102 | .code = __stringify(_code), \ |
| @@ -90,6 +107,7 @@ static const struct ieee80211_channel_range ieee80211_JP_channels[] = { | |||
| 90 | static const struct ieee80211_regdomain ieee80211_regdoms[] = { | 107 | static const struct ieee80211_regdomain ieee80211_regdoms[] = { |
| 91 | REGDOM(US), | 108 | REGDOM(US), |
| 92 | REGDOM(JP), | 109 | REGDOM(JP), |
| 110 | REGDOM(EU), | ||
| 93 | }; | 111 | }; |
| 94 | 112 | ||
| 95 | 113 | ||
