aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Documentation/block/data-integrity.txt4
-rw-r--r--Documentation/cgroups/cpusets.txt12
-rw-r--r--Documentation/gcov.txt25
-rw-r--r--Documentation/kernel-parameters.txt14
-rw-r--r--Documentation/kmemleak.txt23
-rw-r--r--Documentation/leds-lp3944.txt50
-rw-r--r--Documentation/powerpc/booting-without-of.txt1168
-rw-r--r--Documentation/powerpc/dts-bindings/4xx/emac.txt148
-rw-r--r--Documentation/powerpc/dts-bindings/gpio/gpio.txt50
-rw-r--r--Documentation/powerpc/dts-bindings/gpio/led.txt17
-rw-r--r--Documentation/powerpc/dts-bindings/gpio/mdio.txt19
-rw-r--r--Documentation/powerpc/dts-bindings/marvell.txt521
-rw-r--r--Documentation/powerpc/dts-bindings/phy.txt25
-rw-r--r--Documentation/powerpc/dts-bindings/spi-bus.txt57
-rw-r--r--Documentation/powerpc/dts-bindings/usb-ehci.txt25
-rw-r--r--Documentation/powerpc/dts-bindings/xilinx.txt295
-rw-r--r--Documentation/sound/alsa/HD-Audio-Models.txt1
-rw-r--r--Documentation/spi/spidev_test.c10
-rw-r--r--MAINTAINERS60
-rw-r--r--Makefile9
-rw-r--r--arch/alpha/include/asm/percpu.h6
-rw-r--r--arch/arm/Kconfig.debug8
-rw-r--r--arch/arm/configs/s3c2410_defconfig2
-rw-r--r--arch/arm/configs/s3c6400_defconfig1
-rw-r--r--arch/arm/configs/tct_hammer_defconfig1
-rw-r--r--arch/arm/include/asm/page.h2
-rw-r--r--arch/arm/kernel/irq.c24
-rw-r--r--arch/arm/kernel/vmlinux.lds.S15
-rw-r--r--arch/arm/mach-at91/board-sam9g20ek.c54
-rw-r--r--arch/arm/mach-at91/board-sam9rlek.c6
-rw-r--r--arch/arm/mach-omap1/board-nokia770.c3
-rw-r--r--arch/arm/mach-omap1/mailbox.c2
-rw-r--r--arch/arm/mach-omap2/board-rx51-peripherals.c1
-rw-r--r--arch/arm/mach-omap2/gpmc-onenand.c21
-rw-r--r--arch/arm/mach-omap2/id.c22
-rw-r--r--arch/arm/mach-omap2/mailbox.c6
-rw-r--r--arch/arm/mach-omap2/mmc-twl4030.c13
-rw-r--r--arch/arm/mach-s3c2440/mach-mini2440.c3
-rw-r--r--arch/arm/mach-s3c2442/mach-gta02.c3
-rw-r--r--arch/arm/plat-omap/dma.c13
-rw-r--r--arch/arm/plat-omap/gpio.c1
-rw-r--r--arch/arm/plat-omap/include/mach/cpu.h22
-rw-r--r--arch/arm/plat-omap/include/mach/dma.h15
-rw-r--r--arch/arm/plat-omap/include/mach/io.h2
-rw-r--r--arch/arm/plat-omap/iommu.c2
-rw-r--r--arch/arm/plat-omap/sram.c7
-rw-r--r--arch/arm/plat-s3c/Makefile2
-rw-r--r--arch/arm/plat-s3c/include/plat/devs.h1
-rw-r--r--arch/arm/plat-s3c24xx/Makefile2
-rw-r--r--arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c3
-rw-r--r--arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c3
-rw-r--r--arch/frv/Kconfig1
-rw-r--r--arch/frv/include/asm/atomic.h68
-rw-r--r--arch/frv/include/asm/perf_counter.h17
-rw-r--r--arch/frv/include/asm/system.h2
-rw-r--r--arch/frv/include/asm/unistd.h4
-rw-r--r--arch/frv/kernel/entry.S2
-rw-r--r--arch/frv/kernel/frv_ksyms.c4
-rw-r--r--arch/frv/lib/Makefile4
-rw-r--r--arch/frv/lib/atomic-ops.S3
-rw-r--r--arch/frv/lib/atomic64-ops.S162
-rw-r--r--arch/frv/lib/perf_counter.c19
-rw-r--r--arch/ia64/hp/sim/simeth.c2
-rw-r--r--arch/ia64/kernel/esi.c2
-rw-r--r--arch/ia64/kernel/perfmon.c2
-rw-r--r--arch/ia64/kernel/salinfo.c2
-rw-r--r--arch/ia64/kvm/kvm_lib.c6
-rw-r--r--arch/ia64/kvm/process.c6
-rw-r--r--arch/ia64/kvm/vcpu.c2
-rw-r--r--arch/ia64/kvm/vtlb.c4
-rw-r--r--arch/ia64/sn/kernel/io_common.c3
-rw-r--r--arch/mips/Kconfig29
-rw-r--r--arch/mips/Makefile7
-rw-r--r--arch/mips/ar7/Makefile10
-rw-r--r--arch/mips/ar7/clock.c440
-rw-r--r--arch/mips/ar7/gpio.c48
-rw-r--r--arch/mips/ar7/irq.c176
-rw-r--r--arch/mips/ar7/memory.c72
-rw-r--r--arch/mips/ar7/platform.c555
-rw-r--r--arch/mips/ar7/prom.c297
-rw-r--r--arch/mips/ar7/setup.c94
-rw-r--r--arch/mips/ar7/time.c30
-rw-r--r--arch/mips/cavium-octeon/Makefile4
-rw-r--r--arch/mips/cavium-octeon/dma-octeon.c2
-rw-r--r--arch/mips/cavium-octeon/pci-common.c137
-rw-r--r--arch/mips/cobalt/buttons.c2
-rw-r--r--arch/mips/cobalt/lcd.c2
-rw-r--r--arch/mips/cobalt/led.c2
-rw-r--r--arch/mips/cobalt/mtd.c2
-rw-r--r--arch/mips/cobalt/rtc.c2
-rw-r--r--arch/mips/cobalt/serial.c2
-rw-r--r--arch/mips/cobalt/time.c2
-rw-r--r--arch/mips/configs/ar7_defconfig1182
-rw-r--r--arch/mips/gt64120/wrppmc/serial.c2
-rw-r--r--arch/mips/include/asm/amon.h7
-rw-r--r--arch/mips/include/asm/ds1287.h2
-rw-r--r--arch/mips/include/asm/elf.h4
-rw-r--r--arch/mips/include/asm/gcmpregs.h2
-rw-r--r--arch/mips/include/asm/gic.h6
-rw-r--r--arch/mips/include/asm/irq_gt641xx.h2
-rw-r--r--arch/mips/include/asm/mach-ar7/ar7.h178
-rw-r--r--arch/mips/include/asm/mach-ar7/gpio.h110
-rw-r--r--arch/mips/include/asm/mach-ar7/irq.h16
-rw-r--r--arch/mips/include/asm/mach-ar7/prom.h25
-rw-r--r--arch/mips/include/asm/mach-ar7/spaces.h22
-rw-r--r--arch/mips/include/asm/mach-ar7/war.h25
-rw-r--r--arch/mips/include/asm/mach-cobalt/irq.h2
-rw-r--r--arch/mips/include/asm/mach-cobalt/mach-gt64120.h2
-rw-r--r--arch/mips/include/asm/octeon/pci-octeon.h (renamed from arch/mips/cavium-octeon/pci-common.h)30
-rw-r--r--arch/mips/include/asm/page.h9
-rw-r--r--arch/mips/include/asm/reg.h2
-rw-r--r--arch/mips/include/asm/swab.h8
-rw-r--r--arch/mips/include/asm/unistd.h18
-rw-r--r--arch/mips/include/asm/vr41xx/capcella.h2
-rw-r--r--arch/mips/include/asm/vr41xx/giu.h22
-rw-r--r--arch/mips/include/asm/vr41xx/irq.h2
-rw-r--r--arch/mips/include/asm/vr41xx/mpc30x.h2
-rw-r--r--arch/mips/include/asm/vr41xx/pci.h2
-rw-r--r--arch/mips/include/asm/vr41xx/siu.h2
-rw-r--r--arch/mips/include/asm/vr41xx/tb0219.h2
-rw-r--r--arch/mips/include/asm/vr41xx/tb0226.h2
-rw-r--r--arch/mips/include/asm/vr41xx/vr41xx.h2
-rw-r--r--arch/mips/kernel/binfmt_elfo32.c20
-rw-r--r--arch/mips/kernel/cevt-ds1287.c2
-rw-r--r--arch/mips/kernel/cevt-gt641xx.c2
-rw-r--r--arch/mips/kernel/csrc-ioasic.c2
-rw-r--r--arch/mips/kernel/irq-gic.c19
-rw-r--r--arch/mips/kernel/irq-gt641xx.c2
-rw-r--r--arch/mips/kernel/scall32-o32.S2
-rw-r--r--arch/mips/kernel/scall64-64.S2
-rw-r--r--arch/mips/kernel/scall64-n32.S4
-rw-r--r--arch/mips/kernel/scall64-o32.S6
-rw-r--r--arch/mips/kernel/smp-cmp.c66
-rw-r--r--arch/mips/kernel/sync-r4k.c31
-rw-r--r--arch/mips/kernel/vpe.c2
-rw-r--r--arch/mips/mti-malta/malta-init.c14
-rw-r--r--arch/mips/mti-malta/malta-int.c89
-rw-r--r--arch/mips/mti-malta/malta-reset.c3
-rw-r--r--arch/mips/pci/Makefile5
-rw-r--r--arch/mips/pci/fixup-capcella.c2
-rw-r--r--arch/mips/pci/fixup-mpc30x.c2
-rw-r--r--arch/mips/pci/fixup-tb0219.c2
-rw-r--r--arch/mips/pci/fixup-tb0226.c2
-rw-r--r--arch/mips/pci/fixup-tb0287.c2
-rw-r--r--arch/mips/pci/msi-octeon.c (renamed from arch/mips/cavium-octeon/msi.c)56
-rw-r--r--arch/mips/pci/ops-vr41xx.c6
-rw-r--r--arch/mips/pci/pci-octeon.c (renamed from arch/mips/cavium-octeon/pci.c)147
-rw-r--r--arch/mips/pci/pci-vr41xx.c6
-rw-r--r--arch/mips/pci/pci-vr41xx.h4
-rw-r--r--arch/mips/pci/pcie-octeon.c (renamed from arch/mips/cavium-octeon/pcie.c)37
-rw-r--r--arch/mips/vr41xx/casio-e55/setup.c2
-rw-r--r--arch/mips/vr41xx/common/bcu.c8
-rw-r--r--arch/mips/vr41xx/common/cmu.c8
-rw-r--r--arch/mips/vr41xx/common/giu.c2
-rw-r--r--arch/mips/vr41xx/common/icu.c8
-rw-r--r--arch/mips/vr41xx/common/init.c2
-rw-r--r--arch/mips/vr41xx/common/irq.c2
-rw-r--r--arch/mips/vr41xx/common/pmu.c2
-rw-r--r--arch/mips/vr41xx/common/rtc.c2
-rw-r--r--arch/mips/vr41xx/common/siu.c2
-rw-r--r--arch/mips/vr41xx/common/type.c2
-rw-r--r--arch/mips/vr41xx/ibm-workpad/setup.c2
-rw-r--r--arch/mn10300/include/asm/unistd.h4
-rw-r--r--arch/mn10300/kernel/entry.S2
-rw-r--r--arch/mn10300/kernel/vmlinux.lds.S2
-rw-r--r--arch/parisc/Kconfig2
-rw-r--r--arch/parisc/include/asm/atomic.h14
-rw-r--r--arch/parisc/include/asm/dma.h3
-rw-r--r--arch/parisc/include/asm/perf_counter.h7
-rw-r--r--arch/parisc/include/asm/processor.h3
-rw-r--r--arch/parisc/include/asm/system.h4
-rw-r--r--arch/parisc/include/asm/tlbflush.h14
-rw-r--r--arch/parisc/include/asm/unistd.h6
-rw-r--r--arch/parisc/kernel/cache.c26
-rw-r--r--arch/parisc/kernel/inventory.c41
-rw-r--r--arch/parisc/kernel/irq.c10
-rw-r--r--arch/parisc/kernel/pci-dma.c12
-rw-r--r--arch/parisc/kernel/pci.c3
-rw-r--r--arch/parisc/kernel/processor.c19
-rw-r--r--arch/parisc/kernel/setup.c3
-rw-r--r--arch/parisc/kernel/sys_parisc32.c62
-rw-r--r--arch/parisc/kernel/syscall_table.S4
-rw-r--r--arch/parisc/kernel/time.c90
-rw-r--r--arch/parisc/lib/checksum.c2
-rw-r--r--arch/parisc/lib/memcpy.c2
-rw-r--r--arch/parisc/math-emu/decode_exc.c2
-rw-r--r--arch/parisc/mm/fault.c3
-rw-r--r--arch/parisc/mm/init.c29
-rw-r--r--arch/powerpc/Kconfig1
-rw-r--r--arch/powerpc/boot/.gitignore10
-rw-r--r--arch/powerpc/boot/dts/amigaone.dts4
-rw-r--r--arch/powerpc/boot/dts/mpc8569mds.dts1
-rw-r--r--arch/powerpc/include/asm/cpm1.h2
-rw-r--r--arch/powerpc/include/asm/dma-mapping.h24
-rw-r--r--arch/powerpc/include/asm/highmem.h57
-rw-r--r--arch/powerpc/include/asm/hw_irq.h20
-rw-r--r--arch/powerpc/include/asm/perf_counter.h2
-rw-r--r--arch/powerpc/include/asm/pte-hash64-64k.h3
-rw-r--r--arch/powerpc/include/asm/rtas.h5
-rw-r--r--arch/powerpc/kernel/entry_32.S127
-rw-r--r--arch/powerpc/kernel/head_32.S17
-rw-r--r--arch/powerpc/kernel/of_device.c2
-rw-r--r--arch/powerpc/kernel/process.c2
-rw-r--r--arch/powerpc/kernel/rtas.c69
-rw-r--r--arch/powerpc/kernel/setup_32.c2
-rw-r--r--arch/powerpc/kernel/smp.c3
-rw-r--r--arch/powerpc/kernel/udbg_16550.c2
-rw-r--r--arch/powerpc/mm/Makefile1
-rw-r--r--arch/powerpc/mm/highmem.c77
-rw-r--r--arch/powerpc/platforms/44x/warp.c44
-rw-r--r--arch/powerpc/platforms/85xx/mpc85xx_mds.c1
-rw-r--r--arch/powerpc/platforms/85xx/smp.c9
-rw-r--r--arch/powerpc/platforms/85xx/socrates.c6
-rw-r--r--arch/powerpc/platforms/85xx/xes_mpc85xx.c1
-rw-r--r--arch/powerpc/platforms/cell/smp.c30
-rw-r--r--arch/powerpc/platforms/chrp/smp.c33
-rw-r--r--arch/powerpc/platforms/pasemi/setup.c15
-rw-r--r--arch/powerpc/platforms/powermac/setup.c41
-rw-r--r--arch/powerpc/platforms/powermac/smp.c166
-rw-r--r--arch/powerpc/platforms/pseries/smp.c30
-rw-r--r--arch/powerpc/sysdev/mpic.c34
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe.c9
-rw-r--r--arch/s390/include/asm/kvm_host.h4
-rw-r--r--arch/s390/kvm/kvm-s390.c23
-rw-r--r--arch/s390/kvm/priv.c2
-rw-r--r--arch/sh/Kconfig.debug4
-rw-r--r--arch/sh/boards/mach-se/7206/io.c2
-rw-r--r--arch/sh/boards/mach-se/7724/setup.c110
-rw-r--r--arch/sh/configs/migor_defconfig53
-rw-r--r--arch/sh/configs/se7724_defconfig25
-rw-r--r--arch/sh/include/asm/perf_counter.h2
-rw-r--r--arch/sh/include/asm/syscall_32.h1
-rw-r--r--arch/sh/include/mach-se/mach/se7724.h5
-rw-r--r--arch/sh/mm/fault_32.c61
-rw-r--r--arch/sh/mm/tlbflush_64.c15
-rw-r--r--arch/sparc/boot/Makefile6
-rw-r--r--arch/sparc/boot/piggyback_32.c4
-rw-r--r--arch/sparc/boot/piggyback_64.c1
-rw-r--r--arch/sparc/kernel/irq_64.c45
-rw-r--r--arch/sparc/kernel/sys32.S2
-rw-r--r--arch/um/drivers/net_kern.c2
-rw-r--r--arch/um/drivers/slip_kern.c1
-rw-r--r--arch/um/drivers/slirp_kern.c1
-rw-r--r--arch/um/include/asm/dma-mapping.h4
-rw-r--r--arch/x86/Kconfig15
-rw-r--r--arch/x86/include/asm/boot.h6
-rw-r--r--arch/x86/include/asm/pci.h2
-rw-r--r--arch/x86/include/asm/percpu.h10
-rw-r--r--arch/x86/include/asm/perf_counter.h3
-rw-r--r--arch/x86/include/asm/proto.h11
-rw-r--r--arch/x86/kernel/cpu/amd.c4
-rw-r--r--arch/x86/kernel/cpu/common.c3
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce.c4
-rw-r--r--arch/x86/kernel/cpu/perf_counter.c22
-rw-r--r--arch/x86/kernel/dumpstack.c1
-rw-r--r--arch/x86/kernel/e820.c16
-rw-r--r--arch/x86/kernel/pci-dma.c2
-rw-r--r--arch/x86/kernel/setup.c16
-rw-r--r--arch/x86/kernel/setup_percpu.c219
-rw-r--r--arch/x86/kernel/tlb_uv.c9
-rw-r--r--arch/x86/kernel/traps.c3
-rw-r--r--arch/x86/kvm/mmu.c6
-rw-r--r--arch/x86/kvm/paging_tmpl.h2
-rw-r--r--arch/x86/kvm/vmx.c15
-rw-r--r--arch/x86/kvm/x86.c1
-rw-r--r--arch/x86/kvm/x86_emulate.c2
-rw-r--r--arch/x86/lib/delay.c3
-rw-r--r--arch/x86/mm/init.c17
-rw-r--r--arch/x86/mm/init_64.c2
-rw-r--r--arch/x86/mm/pageattr.c65
-rw-r--r--arch/x86/power/cpu.c2
-rw-r--r--arch/xtensa/platforms/iss/network.c2
-rw-r--r--block/Makefile2
-rw-r--r--block/blk-core.c14
-rw-r--r--block/blk-merge.c6
-rw-r--r--block/bsg.c2
-rw-r--r--block/cfq-iosched.c176
-rw-r--r--block/cmd-filter.c233
-rw-r--r--block/elevator.c8
-rw-r--r--block/scsi_ioctl.c43
-rw-r--r--drivers/acpi/pci_root.c2
-rw-r--r--drivers/block/cciss.c15
-rw-r--r--drivers/block/cciss_cmd.h1
-rw-r--r--drivers/block/floppy.c5
-rw-r--r--drivers/char/Kconfig4
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/bsr.c42
-rw-r--r--drivers/char/tb0219.c4
-rw-r--r--drivers/char/tty_ldisc.c15
-rw-r--r--drivers/char/vr41xx_giu.c680
-rw-r--r--drivers/clocksource/sh_tmu.c2
-rw-r--r--drivers/edac/amd64_edac.c25
-rw-r--r--drivers/edac/amd64_edac.h2
-rw-r--r--drivers/edac/edac_core.h4
-rw-r--r--drivers/edac/edac_mc_sysfs.c4
-rw-r--r--drivers/edac/mpc85xx_edac.c6
-rw-r--r--drivers/edac/mpc85xx_edac.h1
-rw-r--r--drivers/gpio/Kconfig6
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/pl061.c20
-rw-r--r--drivers/gpio/vr41xx_giu.c586
-rw-r--r--drivers/gpu/drm/Kconfig1
-rw-r--r--drivers/gpu/drm/Makefile2
-rw-r--r--drivers/gpu/drm/drm_edid.c12
-rw-r--r--drivers/gpu/drm/i915/Makefile2
-rw-r--r--drivers/gpu/drm/i915/dvo.h4
-rw-r--r--drivers/gpu/drm/i915/dvo_ch7017.c20
-rw-r--r--drivers/gpu/drm/i915/dvo_ch7xxx.c25
-rw-r--r--drivers/gpu/drm/i915/dvo_ivch.c21
-rw-r--r--drivers/gpu/drm/i915/dvo_sil164.c25
-rw-r--r--drivers/gpu/drm/i915/dvo_tfp410.c25
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c4
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h12
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c19
-rw-r--r--drivers/gpu/drm/i915/i915_gem_debug.c6
-rw-r--r--drivers/gpu/drm/i915/i915_gem_tiling.c2
-rw-r--r--drivers/gpu/drm/i915/i915_irq.c12
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h29
-rw-r--r--drivers/gpu/drm/i915/i915_suspend.c34
-rw-r--r--drivers/gpu/drm/i915/intel_bios.c12
-rw-r--r--drivers/gpu/drm/i915/intel_display.c199
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c1153
-rw-r--r--drivers/gpu/drm/i915/intel_dp.h144
-rw-r--r--drivers/gpu/drm/i915/intel_dp_i2c.c272
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h17
-rw-r--r--drivers/gpu/drm/i915/intel_dvo.c16
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c35
-rw-r--r--drivers/gpu/drm/i915/intel_i2c.c16
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c344
-rw-r--r--drivers/gpu/drm/i915/intel_modes.c14
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c72
-rw-r--r--drivers/gpu/drm/i915/intel_tv.c53
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c22
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_fb.c33
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.c30
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_util.c1
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_vm.c1
-rw-r--r--drivers/gpu/drm/ttm/ttm_tt.c1
-rw-r--r--drivers/i2c/busses/Kconfig1
-rw-r--r--drivers/ide/cs5520.c1
-rw-r--r--drivers/ide/ide-acpi.c37
-rw-r--r--drivers/ide/ide-cd.c24
-rw-r--r--drivers/ide/ide-devsets.c2
-rw-r--r--drivers/ide/ide-dma.c21
-rw-r--r--drivers/ide/ide-eh.c2
-rw-r--r--drivers/ide/ide-floppy.c2
-rw-r--r--drivers/ide/ide-io.c68
-rw-r--r--drivers/ide/ide-ioctls.c3
-rw-r--r--drivers/ide/ide-iops.c4
-rw-r--r--drivers/ide/ide-pm.c30
-rw-r--r--drivers/ide/ide-probe.c23
-rw-r--r--drivers/ieee802154/fakehard.c2
-rw-r--r--drivers/input/misc/cobalt_btns.c4
-rw-r--r--drivers/isdn/hysdn/hysdn_net.c2
-rw-r--r--drivers/isdn/i4l/isdn_net.c16
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c6
-rw-r--r--drivers/leds/Kconfig14
-rw-r--r--drivers/leds/Makefile1
-rw-r--r--drivers/leds/leds-alix2.c7
-rw-r--r--drivers/leds/leds-bd2802.c96
-rw-r--r--drivers/leds/leds-cobalt-raq.c2
-rw-r--r--drivers/leds/leds-gpio.c22
-rw-r--r--drivers/leds/leds-lp3944.c466
-rw-r--r--drivers/leds/leds-pca9532.c58
-rw-r--r--drivers/lguest/lg.h2
-rw-r--r--drivers/lguest/lguest_user.c4
-rw-r--r--drivers/macintosh/macio_asic.c11
-rw-r--r--drivers/md/dm-exception-store.c9
-rw-r--r--drivers/md/dm-table.c2
-rw-r--r--drivers/md/dm.c4
-rw-r--r--drivers/md/linear.c4
-rw-r--r--drivers/md/md.c56
-rw-r--r--drivers/md/multipath.c7
-rw-r--r--drivers/md/raid0.c9
-rw-r--r--drivers/md/raid1.c9
-rw-r--r--drivers/md/raid10.c19
-rw-r--r--drivers/md/raid5.c28
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c2
-rw-r--r--drivers/message/fusion/mptlan.c2
-rw-r--r--drivers/mfd/ezx-pcap.c4
-rw-r--r--drivers/mfd/sm501.c3
-rw-r--r--drivers/misc/sgi-xp/xpnet.c4
-rw-r--r--drivers/mmc/host/mmc_spi.c6
-rw-r--r--drivers/mtd/cmdlinepart.c2
-rw-r--r--drivers/mtd/devices/m25p80.c2
-rw-r--r--drivers/mtd/inftlcore.c11
-rw-r--r--drivers/mtd/maps/integrator-flash.c22
-rw-r--r--drivers/mtd/nand/atmel_nand.c2
-rw-r--r--drivers/mtd/nand/omap2.c7
-rw-r--r--drivers/mtd/nftlcore.c16
-rw-r--r--drivers/net/3c501.c2
-rw-r--r--drivers/net/3c505.c2
-rw-r--r--drivers/net/3c507.c2
-rw-r--r--drivers/net/3c509.c2
-rw-r--r--drivers/net/3c515.c4
-rw-r--r--drivers/net/3c523.c2
-rw-r--r--drivers/net/3c527.c4
-rw-r--r--drivers/net/3c59x.c4
-rw-r--r--drivers/net/7990.c2
-rw-r--r--drivers/net/8139cp.c2
-rw-r--r--drivers/net/8139too.c4
-rw-r--r--drivers/net/82596.c4
-rw-r--r--drivers/net/a2065.c4
-rw-r--r--drivers/net/amd8111e.c2
-rw-r--r--drivers/net/appletalk/cops.c2
-rw-r--r--drivers/net/appletalk/ipddp.c4
-rw-r--r--drivers/net/appletalk/ltpc.c2
-rw-r--r--drivers/net/ariadne.c4
-rw-r--r--drivers/net/arm/am79c961a.c2
-rw-r--r--drivers/net/arm/at91_ether.c2
-rw-r--r--drivers/net/arm/ether1.c2
-rw-r--r--drivers/net/arm/ether3.c4
-rw-r--r--drivers/net/at1700.c2
-rw-r--r--drivers/net/atarilance.c4
-rw-r--r--drivers/net/atp.c2
-rw-r--r--drivers/net/au1000_eth.c2
-rw-r--r--drivers/net/bfin_mac.c2
-rw-r--r--drivers/net/bmac.c2
-rw-r--r--drivers/net/bonding/bond_3ad.c5
-rw-r--r--drivers/net/bonding/bond_alb.c2
-rw-r--r--drivers/net/bonding/bond_main.c8
-rw-r--r--drivers/net/can/sja1000/sja1000.c2
-rw-r--r--drivers/net/cassini.c4
-rw-r--r--drivers/net/cris/eth_v10.c2
-rw-r--r--drivers/net/cs89x0.c4
-rw-r--r--drivers/net/cxgb3/adapter.h10
-rw-r--r--drivers/net/cxgb3/ael1002.c1193
-rw-r--r--drivers/net/cxgb3/aq100x.c7
-rw-r--r--drivers/net/cxgb3/common.h10
-rw-r--r--drivers/net/cxgb3/cxgb3_main.c99
-rw-r--r--drivers/net/cxgb3/t3_hw.c2
-rw-r--r--drivers/net/cxgb3/xgmac.c11
-rw-r--r--drivers/net/de600.c2
-rw-r--r--drivers/net/de620.c2
-rw-r--r--drivers/net/declance.c4
-rw-r--r--drivers/net/defxx.c6
-rw-r--r--drivers/net/depca.c2
-rw-r--r--drivers/net/dm9000.c109
-rw-r--r--drivers/net/dm9000.h18
-rw-r--r--drivers/net/dnet.c2
-rw-r--r--drivers/net/dummy.c2
-rw-r--r--drivers/net/e100.c2
-rw-r--r--drivers/net/e1000/e1000.h7
-rw-r--r--drivers/net/e1000/e1000_ethtool.c51
-rw-r--r--drivers/net/e1000/e1000_hw.c2
-rw-r--r--drivers/net/e1000/e1000_hw.h3
-rw-r--r--drivers/net/e1000/e1000_main.c483
-rw-r--r--drivers/net/eepro.c4
-rw-r--r--drivers/net/eexpress.c4
-rw-r--r--drivers/net/enc28j60.c2
-rw-r--r--drivers/net/epic100.c4
-rw-r--r--drivers/net/eql.c2
-rw-r--r--drivers/net/eth16i.c4
-rw-r--r--drivers/net/ewrk3.c2
-rw-r--r--drivers/net/fealnx.c2
-rw-r--r--drivers/net/fec.c2
-rw-r--r--drivers/net/gianfar.c1
-rw-r--r--drivers/net/hamachi.c2
-rw-r--r--drivers/net/hamradio/6pack.c2
-rw-r--r--drivers/net/hamradio/baycom_epp.c6
-rw-r--r--drivers/net/hamradio/bpqether.c2
-rw-r--r--drivers/net/hamradio/dmascc.c2
-rw-r--r--drivers/net/hamradio/hdlcdrv.c4
-rw-r--r--drivers/net/hamradio/mkiss.c2
-rw-r--r--drivers/net/hamradio/scc.c6
-rw-r--r--drivers/net/hamradio/yam.c2
-rw-r--r--drivers/net/hp100.c6
-rw-r--r--drivers/net/ibm_newemac/core.c2
-rw-r--r--drivers/net/ibmveth.c2
-rw-r--r--drivers/net/ifb.c2
-rw-r--r--drivers/net/ioc3-eth.c2
-rw-r--r--drivers/net/irda/ali-ircc.c12
-rw-r--r--drivers/net/irda/au1k_ir.c4
-rw-r--r--drivers/net/irda/donauboe.c8
-rw-r--r--drivers/net/irda/irda-usb.c2
-rw-r--r--drivers/net/irda/nsc-ircc.c10
-rw-r--r--drivers/net/irda/pxaficp_ir.c4
-rw-r--r--drivers/net/irda/sa1100_ir.c4
-rw-r--r--drivers/net/irda/sir_dev.c6
-rw-r--r--drivers/net/irda/smsc-ircc2.c16
-rw-r--r--drivers/net/irda/stir4200.c2
-rw-r--r--drivers/net/irda/via-ircc.c12
-rw-r--r--drivers/net/irda/vlsi_ir.c6
-rw-r--r--drivers/net/irda/w83977af_ir.c4
-rw-r--r--drivers/net/isa-skeleton.c2
-rw-r--r--drivers/net/iseries_veth.c4
-rw-r--r--drivers/net/ixgb/ixgb_main.c2
-rw-r--r--drivers/net/ixp2000/ixpdev.c4
-rw-r--r--drivers/net/jme.c189
-rw-r--r--drivers/net/jme.h21
-rw-r--r--drivers/net/lance.c2
-rw-r--r--drivers/net/lib82596.c4
-rw-r--r--drivers/net/lib8390.c2
-rw-r--r--drivers/net/ll_temac_main.c2
-rw-r--r--drivers/net/loopback.c2
-rw-r--r--drivers/net/lp486e.c4
-rw-r--r--drivers/net/mac89x0.c2
-rw-r--r--drivers/net/macb.c2
-rw-r--r--drivers/net/mace.c2
-rw-r--r--drivers/net/meth.c2
-rw-r--r--drivers/net/mipsnet.c2
-rw-r--r--drivers/net/mlx4/en_tx.c2
-rw-r--r--drivers/net/myri10ge/myri10ge.c10
-rw-r--r--drivers/net/myri_sbus.c2
-rw-r--r--drivers/net/natsemi.c2
-rw-r--r--drivers/net/netx-eth.c2
-rw-r--r--drivers/net/ni5010.c2
-rw-r--r--drivers/net/ni52.c4
-rw-r--r--drivers/net/ni65.c2
-rw-r--r--drivers/net/pci-skeleton.c2
-rw-r--r--drivers/net/pcmcia/3c574_cs.c2
-rw-r--r--drivers/net/pcmcia/3c589_cs.c2
-rw-r--r--drivers/net/pcmcia/axnet_cs.c2
-rw-r--r--drivers/net/pcmcia/fmvj18x_cs.c4
-rw-r--r--drivers/net/pcmcia/nmclan_cs.c2
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c6
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c4
-rw-r--r--drivers/net/pcnet32.c2
-rw-r--r--drivers/net/phy/Kconfig6
-rw-r--r--drivers/net/phy/Makefile1
-rw-r--r--drivers/net/phy/bcm63xx.c132
-rw-r--r--drivers/net/plip.c2
-rw-r--r--drivers/net/ppp_generic.c4
-rw-r--r--drivers/net/r6040.c4
-rw-r--r--drivers/net/rionet.c7
-rw-r--r--drivers/net/rrunner.c2
-rw-r--r--drivers/net/s2io.c10
-rw-r--r--drivers/net/sb1000.c2
-rw-r--r--drivers/net/sb1250-mac.c2
-rw-r--r--drivers/net/seeq8005.c4
-rw-r--r--drivers/net/sgiseeq.c4
-rw-r--r--drivers/net/sh_eth.c2
-rw-r--r--drivers/net/sis900.c2
-rw-r--r--drivers/net/skfp/skfddi.c4
-rw-r--r--drivers/net/slip.c6
-rw-r--r--drivers/net/smc911x.c6
-rw-r--r--drivers/net/smc9194.c8
-rw-r--r--drivers/net/smc91x.c4
-rw-r--r--drivers/net/sonic.c4
-rw-r--r--drivers/net/starfire.c2
-rw-r--r--drivers/net/sun3_82586.c4
-rw-r--r--drivers/net/sun3lance.c4
-rw-r--r--drivers/net/sunbmac.c2
-rw-r--r--drivers/net/sundance.c2
-rw-r--r--drivers/net/sunhme.c2
-rw-r--r--drivers/net/sunlance.c2
-rw-r--r--drivers/net/sunqe.c2
-rw-r--r--drivers/net/tc35815.c2
-rw-r--r--drivers/net/tlan.c6
-rw-r--r--drivers/net/tokenring/3c359.c2
-rw-r--r--drivers/net/tokenring/ibmtr.c2
-rw-r--r--drivers/net/tokenring/lanstreamer.c2
-rw-r--r--drivers/net/tokenring/olympic.c2
-rw-r--r--drivers/net/tokenring/smctr.c2
-rw-r--r--drivers/net/tokenring/tms380tr.c2
-rw-r--r--drivers/net/tulip/de2104x.c2
-rw-r--r--drivers/net/tulip/dmfe.c4
-rw-r--r--drivers/net/tulip/tulip_core.c2
-rw-r--r--drivers/net/tulip/uli526x.c4
-rw-r--r--drivers/net/tulip/winbond-840.c2
-rw-r--r--drivers/net/tulip/xircom_cb.c2
-rw-r--r--drivers/net/tun.c5
-rw-r--r--drivers/net/typhoon.c2
-rw-r--r--drivers/net/ucc_geth.c42
-rw-r--r--drivers/net/ucc_geth.h2
-rw-r--r--drivers/net/usb/catc.c2
-rw-r--r--drivers/net/usb/hso.c2
-rw-r--r--drivers/net/usb/kaweth.c4
-rw-r--r--drivers/net/usb/pegasus.c2
-rw-r--r--drivers/net/usb/rtl8150.c2
-rw-r--r--drivers/net/usb/usbnet.c14
-rw-r--r--drivers/net/veth.c6
-rw-r--r--drivers/net/via-rhine.c6
-rw-r--r--drivers/net/via-velocity.c2
-rw-r--r--drivers/net/vxge/vxge-config.c10
-rw-r--r--drivers/net/vxge/vxge-config.h10
-rw-r--r--drivers/net/vxge/vxge-main.c100
-rw-r--r--drivers/net/vxge/vxge-main.h4
-rw-r--r--drivers/net/vxge/vxge-reg.h9
-rw-r--r--drivers/net/vxge/vxge-traffic.h2
-rw-r--r--drivers/net/vxge/vxge-version.h2
-rw-r--r--drivers/net/wan/cycx_x25.c2
-rw-r--r--drivers/net/wan/dlci.c4
-rw-r--r--drivers/net/wan/dscc4.c2
-rw-r--r--drivers/net/wan/farsync.c27
-rw-r--r--drivers/net/wan/hdlc_fr.c6
-rw-r--r--drivers/net/wan/lmc/lmc_main.c2
-rw-r--r--drivers/net/wan/sbni.c4
-rw-r--r--drivers/net/wan/wanxl.c2
-rw-r--r--drivers/net/wan/x25_asy.c10
-rw-r--r--drivers/net/wireless/adm8211.c3
-rw-r--r--drivers/net/wireless/airo.c14
-rw-r--r--drivers/net/wireless/arlan-main.c2
-rw-r--r--drivers/net/wireless/at76c50x-usb.c3
-rw-r--r--drivers/net/wireless/ath/ar9170/main.c6
-rw-r--r--drivers/net/wireless/ath/ar9170/usb.c2
-rw-r--r--drivers/net/wireless/ath/ath5k/ath5k.h21
-rw-r--r--drivers/net/wireless/ath/ath5k/attach.c3
-rw-r--r--drivers/net/wireless/ath/ath5k/base.c130
-rw-r--r--drivers/net/wireless/ath/ath5k/base.h10
-rw-r--r--drivers/net/wireless/ath/ath5k/debug.c8
-rw-r--r--drivers/net/wireless/ath/ath5k/phy.c7
-rw-r--r--drivers/net/wireless/ath/ath5k/qcu.c1
-rw-r--r--drivers/net/wireless/ath/ath5k/reset.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h2
-rw-r--r--drivers/net/wireless/ath/ath9k/beacon.c15
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c62
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c67
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c33
-rw-r--r--drivers/net/wireless/ath/regd.c2
-rw-r--r--drivers/net/wireless/atmel.c6
-rw-r--r--drivers/net/wireless/b43/xmit.c3
-rw-r--r--drivers/net/wireless/b43legacy/xmit.c3
-rw-r--r--drivers/net/wireless/hostap/hostap_80211_tx.c42
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2200.c10
-rw-r--r--drivers/net/wireless/ipw2x00/libipw_tx.c4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c29
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c74
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-calib.c7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c63
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h3
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debug.h6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rx.c5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-scan.c31
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c88
-rw-r--r--drivers/net/wireless/iwmc3200wifi/cfg80211.c235
-rw-r--r--drivers/net/wireless/iwmc3200wifi/commands.c116
-rw-r--r--drivers/net/wireless/iwmc3200wifi/commands.h7
-rw-r--r--drivers/net/wireless/iwmc3200wifi/eeprom.c4
-rw-r--r--drivers/net/wireless/iwmc3200wifi/fw.c21
-rw-r--r--drivers/net/wireless/iwmc3200wifi/iwm.h32
-rw-r--r--drivers/net/wireless/iwmc3200wifi/lmac.h4
-rw-r--r--drivers/net/wireless/iwmc3200wifi/main.c38
-rw-r--r--drivers/net/wireless/iwmc3200wifi/netdev.c27
-rw-r--r--drivers/net/wireless/iwmc3200wifi/rx.c36
-rw-r--r--drivers/net/wireless/iwmc3200wifi/sdio.c6
-rw-r--r--drivers/net/wireless/iwmc3200wifi/umac.h2
-rw-r--r--drivers/net/wireless/iwmc3200wifi/wext.c352
-rw-r--r--drivers/net/wireless/libertas/assoc.c6
-rw-r--r--drivers/net/wireless/libertas/dev.h1
-rw-r--r--drivers/net/wireless/libertas/if_cs.c3
-rw-r--r--drivers/net/wireless/libertas/if_sdio.c5
-rw-r--r--drivers/net/wireless/libertas/if_spi.c8
-rw-r--r--drivers/net/wireless/libertas/if_usb.c3
-rw-r--r--drivers/net/wireless/libertas/wext.c2
-rw-r--r--drivers/net/wireless/libertas_tf/main.c3
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c83
-rw-r--r--drivers/net/wireless/mwl8k.c3
-rw-r--r--drivers/net/wireless/netwave_cs.c2
-rw-r--r--drivers/net/wireless/orinoco/Kconfig1
-rw-r--r--drivers/net/wireless/orinoco/Makefile2
-rw-r--r--drivers/net/wireless/orinoco/airport.c98
-rw-r--r--drivers/net/wireless/orinoco/cfg.c162
-rw-r--r--drivers/net/wireless/orinoco/cfg.h15
-rw-r--r--drivers/net/wireless/orinoco/fw.c41
-rw-r--r--drivers/net/wireless/orinoco/hermes.c2
-rw-r--r--drivers/net/wireless/orinoco/hermes.h2
-rw-r--r--drivers/net/wireless/orinoco/hermes_dld.c50
-rw-r--r--drivers/net/wireless/orinoco/hw.c668
-rw-r--r--drivers/net/wireless/orinoco/hw.h11
-rw-r--r--drivers/net/wireless/orinoco/main.c1132
-rw-r--r--drivers/net/wireless/orinoco/main.h3
-rw-r--r--drivers/net/wireless/orinoco/orinoco.h49
-rw-r--r--drivers/net/wireless/orinoco/orinoco_cs.c96
-rw-r--r--drivers/net/wireless/orinoco/orinoco_nortel.c38
-rw-r--r--drivers/net/wireless/orinoco/orinoco_pci.c38
-rw-r--r--drivers/net/wireless/orinoco/orinoco_pci.h57
-rw-r--r--drivers/net/wireless/orinoco/orinoco_plx.c38
-rw-r--r--drivers/net/wireless/orinoco/orinoco_tmd.c38
-rw-r--r--drivers/net/wireless/orinoco/scan.c291
-rw-r--r--drivers/net/wireless/orinoco/scan.h21
-rw-r--r--drivers/net/wireless/orinoco/spectrum_cs.c96
-rw-r--r--drivers/net/wireless/orinoco/wext.c878
-rw-r--r--drivers/net/wireless/p54/Makefile3
-rw-r--r--drivers/net/wireless/p54/eeprom.c564
-rw-r--r--drivers/net/wireless/p54/eeprom.h226
-rw-r--r--drivers/net/wireless/p54/fwio.c698
-rw-r--r--drivers/net/wireless/p54/led.c163
-rw-r--r--drivers/net/wireless/p54/lmac.h551
-rw-r--r--drivers/net/wireless/p54/main.c607
-rw-r--r--drivers/net/wireless/p54/p54.h148
-rw-r--r--drivers/net/wireless/p54/p54common.c2688
-rw-r--r--drivers/net/wireless/p54/p54common.h644
-rw-r--r--drivers/net/wireless/p54/p54pci.c9
-rw-r--r--drivers/net/wireless/p54/p54spi.c50
-rw-r--r--drivers/net/wireless/p54/p54usb.c42
-rw-r--r--drivers/net/wireless/p54/txrx.c826
-rw-r--r--drivers/net/wireless/prism54/islpci_eth.c2
-rw-r--r--drivers/net/wireless/prism54/islpci_hotplug.c4
-rw-r--r--drivers/net/wireless/ray_cs.c6
-rw-r--r--drivers/net/wireless/rndis_wlan.c298
-rw-r--r--drivers/net/wireless/rt2x00/Kconfig8
-rw-r--r--drivers/net/wireless/rt2x00/Makefile1
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.c7
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.c7
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c7
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c7
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h13
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00crypto.c6
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c5
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00lib.h21
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00mac.c12
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00rfkill.c127
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c7
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c7
-rw-r--r--drivers/net/wireless/rtl818x/rtl8180_dev.c5
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187_dev.c3
-rw-r--r--drivers/net/wireless/strip.c2
-rw-r--r--drivers/net/wireless/wavelan.c2
-rw-r--r--drivers/net/wireless/wavelan_cs.c4
-rw-r--r--drivers/net/wireless/wl12xx/Kconfig17
-rw-r--r--drivers/net/wireless/wl12xx/Makefile9
-rw-r--r--drivers/net/wireless/wl12xx/acx.c689
-rw-r--r--drivers/net/wireless/wl12xx/cmd.c353
-rw-r--r--drivers/net/wireless/wl12xx/reg.h1
-rw-r--r--drivers/net/wireless/wl12xx/wl1251.h479
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_acx.c840
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_acx.h (renamed from drivers/net/wireless/wl12xx/acx.h)199
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_boot.c (renamed from drivers/net/wireless/wl12xx/boot.c)114
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_boot.h (renamed from drivers/net/wireless/wl12xx/boot.h)12
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_cmd.c428
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_cmd.h (renamed from drivers/net/wireless/wl12xx/cmd.h)194
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_debugfs.c (renamed from drivers/net/wireless/wl12xx/debugfs.c)60
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_debugfs.h (renamed from drivers/net/wireless/wl12xx/debugfs.h)16
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_event.c (renamed from drivers/net/wireless/wl12xx/event.c)54
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_event.h (renamed from drivers/net/wireless/wl12xx/event.h)12
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_init.c (renamed from drivers/net/wireless/wl12xx/init.c)78
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_init.h (renamed from drivers/net/wireless/wl12xx/init.h)27
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_main.c (renamed from drivers/net/wireless/wl12xx/main.c)638
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_netlink.c679
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_netlink.h30
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_ops.c (renamed from drivers/net/wireless/wl12xx/wl1251.c)297
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_ops.h165
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_ps.c (renamed from drivers/net/wireless/wl12xx/ps.c)64
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_ps.h (renamed from drivers/net/wireless/wl12xx/ps.h)18
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_rx.c (renamed from drivers/net/wireless/wl12xx/rx.c)90
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_rx.h (renamed from drivers/net/wireless/wl12xx/rx.h)22
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_spi.c (renamed from drivers/net/wireless/wl12xx/spi.c)179
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_spi.h (renamed from drivers/net/wireless/wl12xx/spi.h)62
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_tx.c (renamed from drivers/net/wireless/wl12xx/tx.c)124
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_tx.h (renamed from drivers/net/wireless/wl12xx/tx.h)21
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx.h409
-rw-r--r--drivers/net/wireless/wl3501_cs.c3
-rw-r--r--drivers/net/wireless/zd1201.c4
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c3
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c73
-rw-r--r--drivers/net/xen-netfront.c4
-rw-r--r--drivers/net/yellowfin.c4
-rw-r--r--drivers/net/znet.c4
-rw-r--r--drivers/parisc/ccio-dma.c7
-rw-r--r--drivers/parisc/dino.c12
-rw-r--r--drivers/parisc/eisa.c2
-rw-r--r--drivers/parisc/gsc.c4
-rw-r--r--drivers/parisc/gsc.h2
-rw-r--r--drivers/parisc/iosapic.c2
-rw-r--r--drivers/parisc/lba_pci.c41
-rw-r--r--drivers/parisc/sba_iommu.c2
-rw-r--r--drivers/parisc/superio.c6
-rw-r--r--drivers/parport/parport_pc.c5
-rw-r--r--drivers/pci/intel-iommu.c704
-rw-r--r--drivers/pci/iova.c26
-rw-r--r--drivers/pcmcia/vrc4171_card.c4
-rw-r--r--drivers/pcmcia/vrc4173_cardu.c4
-rw-r--r--drivers/pcmcia/vrc4173_cardu.h2
-rw-r--r--drivers/platform/x86/Kconfig1
-rw-r--r--drivers/platform/x86/eeepc-laptop.c346
-rw-r--r--drivers/rtc/rtc-bfin.c30
-rw-r--r--drivers/rtc/rtc-vr41xx.c4
-rw-r--r--drivers/s390/net/claw.c2
-rw-r--r--drivers/s390/net/ctcm_main.c10
-rw-r--r--drivers/s390/net/lcs.c8
-rw-r--r--drivers/s390/net/netiucv.c6
-rw-r--r--drivers/s390/net/qeth_l2_main.c1
-rw-r--r--drivers/s390/net/qeth_l3_main.c1
-rw-r--r--drivers/scsi/cxgb3i/Kbuild2
-rw-r--r--drivers/scsi/cxgb3i/cxgb3i_iscsi.c4
-rw-r--r--drivers/scsi/fnic/fnic_main.c8
-rw-r--r--drivers/scsi/fnic/fnic_scsi.c7
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c7
-rw-r--r--drivers/scsi/scsi_transport_fc.c5
-rw-r--r--drivers/scsi/sg.c4
-rw-r--r--drivers/scsi/zalon.c2
-rw-r--r--drivers/serial/8250_pci.c6
-rw-r--r--drivers/serial/vr41xx_siu.c2
-rw-r--r--drivers/spi/omap_uwire.c2
-rw-r--r--drivers/spi/spi_bitbang.c24
-rw-r--r--drivers/spi/spidev.c17
-rw-r--r--drivers/ssb/driver_mipscore.c85
-rw-r--r--drivers/staging/agnx/xmit.c3
-rw-r--r--drivers/staging/at76_usb/at76_usb.c8
-rw-r--r--drivers/staging/epl/VirtualEthernetLinux.c2
-rw-r--r--drivers/staging/otus/usbdrv.c8
-rw-r--r--drivers/staging/otus/wrap_pkt.c3
-rw-r--r--drivers/staging/rt2860/rt_main_dev.c6
-rw-r--r--drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c4
-rw-r--r--drivers/staging/rtl8187se/r8180_core.c4
-rw-r--r--drivers/staging/slicoss/slicoss.c2
-rw-r--r--drivers/staging/stlc45xx/stlc45xx.c3
-rw-r--r--drivers/staging/winbond/wb35rx.c3
-rw-r--r--drivers/staging/wlan-ng/p80211netdev.c2
-rw-r--r--drivers/usb/class/cdc-acm.c4
-rw-r--r--drivers/usb/gadget/f_phonet.c2
-rw-r--r--drivers/usb/gadget/u_ether.c6
-rw-r--r--drivers/usb/serial/usb-serial.c3
-rw-r--r--drivers/video/Kconfig2
-rw-r--r--drivers/video/atafb.c7
-rw-r--r--drivers/video/atmel_lcdfb.c2
-rw-r--r--drivers/video/aty/atyfb.h3
-rw-r--r--drivers/video/aty/atyfb_base.c141
-rw-r--r--drivers/video/aty/mach64_accel.c7
-rw-r--r--drivers/video/backlight/tdo24m.c2
-rw-r--r--drivers/video/cobalt_lcdfb.c2
-rw-r--r--drivers/video/fbmem.c13
-rw-r--r--drivers/video/fsl-diu-fb.c14
-rw-r--r--drivers/video/i810/i810_main.c2
-rw-r--r--drivers/video/matrox/matroxfb_base.c3
-rw-r--r--drivers/video/matrox/matroxfb_crtc2.c5
-rw-r--r--drivers/video/mx3fb.c17
-rw-r--r--drivers/video/omap/omapfb_main.c4
-rw-r--r--drivers/video/platinumfb.c2
-rw-r--r--drivers/video/pxafb.c2
-rw-r--r--drivers/video/sh7760fb.c19
-rw-r--r--drivers/video/sh_mobile_lcdcfb.c53
-rw-r--r--drivers/video/sis/sis_main.c2
-rw-r--r--drivers/video/sm501fb.c23
-rw-r--r--drivers/video/w100fb.c2
-rw-r--r--drivers/watchdog/wdrtas.c8
-rw-r--r--firmware/Makefile5
-rw-r--r--firmware/WHENCE17
-rw-r--r--firmware/cxgb3/ael2005_opt_edc.bin.ihex69
-rw-r--r--firmware/cxgb3/ael2005_twx_edc.bin.ihex93
-rw-r--r--firmware/cxgb3/ael2020_twx_edc.bin.ihex100
-rw-r--r--fs/afs/flock.c1
-rw-r--r--fs/aio.c24
-rw-r--r--fs/binfmt_elf.c9
-rw-r--r--fs/bio-integrity.c170
-rw-r--r--fs/bio.c11
-rw-r--r--fs/btrfs/async-thread.c2
-rw-r--r--fs/btrfs/ctree.h3
-rw-r--r--fs/btrfs/extent-tree.c566
-rw-r--r--fs/btrfs/file.c5
-rw-r--r--fs/btrfs/inode.c25
-rw-r--r--fs/btrfs/ioctl.c6
-rw-r--r--fs/btrfs/relocation.c5
-rw-r--r--fs/btrfs/transaction.c4
-rw-r--r--fs/cifs/CHANGES2
-rw-r--r--fs/cifs/asn1.c55
-rw-r--r--fs/cifs/cifsfs.c157
-rw-r--r--fs/cifs/cifsglob.h2
-rw-r--r--fs/cifs/cifsproto.h2
-rw-r--r--fs/cifs/cifssmb.c4
-rw-r--r--fs/cifs/connect.c39
-rw-r--r--fs/cifs/dir.c6
-rw-r--r--fs/cifs/dns_resolve.c25
-rw-r--r--fs/cifs/file.c34
-rw-r--r--fs/cifs/inode.c15
-rw-r--r--fs/cifs/link.c3
-rw-r--r--fs/cifs/netmisc.c56
-rw-r--r--fs/cifs/sess.c2
-rw-r--r--fs/cifs/xattr.c12
-rw-r--r--fs/dlm/netlink.c2
-rw-r--r--fs/eventfd.c122
-rw-r--r--fs/ext2/namei.c12
-rw-r--r--fs/fuse/dev.c83
-rw-r--r--fs/fuse/dir.c57
-rw-r--r--fs/fuse/file.c2
-rw-r--r--fs/fuse/fuse_i.h27
-rw-r--r--fs/fuse/inode.c68
-rw-r--r--fs/hostfs/hostfs_kern.c1
-rw-r--r--fs/jffs2/scan.c4
-rw-r--r--fs/namei.c7
-rw-r--r--fs/nfsd/vfs.c3
-rw-r--r--fs/notify/inotify/inotify_user.c3
-rw-r--r--include/asm-generic/percpu.h4
-rw-r--r--include/asm-generic/vmlinux.lds.h15
-rw-r--r--include/drm/drm_edid.h38
-rw-r--r--include/linux/aio.h4
-rw-r--r--include/linux/bio.h22
-rw-r--r--include/linux/blkdev.h15
-rw-r--r--include/linux/eventfd.h35
-rw-r--r--include/linux/fb.h1
-rw-r--r--include/linux/fsnotify_backend.h2
-rw-r--r--include/linux/fuse.h36
-rw-r--r--include/linux/hrtimer.h5
-rw-r--r--include/linux/ide.h5
-rw-r--r--include/linux/ieee80211.h4
-rw-r--r--include/linux/ima.h6
-rw-r--r--include/linux/init_task.h3
-rw-r--r--include/linux/kernel.h1
-rw-r--r--include/linux/kvm_host.h1
-rw-r--r--include/linux/leds-lp3944.h53
-rw-r--r--include/linux/leds.h14
-rw-r--r--include/linux/linkage.h9
-rw-r--r--include/linux/mm.h2
-rw-r--r--include/linux/net_dropmon.h1
-rw-r--r--include/linux/netdevice.h4
-rw-r--r--include/linux/nl80211.h96
-rw-r--r--include/linux/pci_ids.h1
-rw-r--r--include/linux/percpu-defs.h3
-rw-r--r--include/linux/perf_counter.h46
-rw-r--r--include/linux/rfkill.h14
-rw-r--r--include/linux/sched.h16
-rw-r--r--include/linux/spi/spi.h6
-rw-r--r--include/linux/spi/spidev.h2
-rw-r--r--include/linux/timer.h4
-rw-r--r--include/linux/tipc.h2
-rw-r--r--include/linux/usb/usbnet.h3
-rw-r--r--include/linux/wireless.h8
-rw-r--r--include/net/cfg80211.h460
-rw-r--r--include/net/genetlink.h66
-rw-r--r--include/net/ipv6.h12
-rw-r--r--include/net/iw_handler.h2
-rw-r--r--include/net/mac80211.h34
-rw-r--r--include/net/net_namespace.h10
-rw-r--r--include/net/netns/x_tables.h3
-rw-r--r--include/net/scm.h2
-rw-r--r--include/net/udp.h3
-rw-r--r--ipc/mqueue.c2
-rw-r--r--kernel/Makefile1
-rw-r--r--kernel/acct.c6
-rw-r--r--kernel/futex.c2
-rw-r--r--kernel/perf_counter.c320
-rw-r--r--kernel/pid.c7
-rw-r--r--kernel/resource.c2
-rw-r--r--kernel/sysctl.c13
-rw-r--r--kernel/taskstats.c10
-rw-r--r--kernel/time/timer_stats.c16
-rw-r--r--kernel/timer.c2
-rw-r--r--kernel/trace/ftrace.c56
-rw-r--r--kernel/trace/ring_buffer.c11
-rw-r--r--kernel/trace/trace.c23
-rw-r--r--kernel/trace/trace.h7
-rw-r--r--kernel/trace/trace_events.c28
-rw-r--r--kernel/trace/trace_functions.c3
-rw-r--r--kernel/trace/trace_printk.c26
-rw-r--r--kernel/trace/trace_stat.c6
-rw-r--r--lib/Kconfig.debug12
-rw-r--r--mm/dmapool.c2
-rw-r--r--mm/kmemleak.c197
-rw-r--r--mm/memory.c26
-rw-r--r--mm/nommu.c33
-rw-r--r--mm/page-writeback.c5
-rw-r--r--mm/page_alloc.c13
-rw-r--r--mm/percpu.c24
-rw-r--r--net/Kconfig20
-rw-r--r--net/Makefile1
-rw-r--r--net/atm/br2684.c4
-rw-r--r--net/atm/clip.c12
-rw-r--r--net/atm/lec.c8
-rw-r--r--net/atm/mpc.c2
-rw-r--r--net/bluetooth/bnep/netdev.c6
-rw-r--r--net/bridge/br_device.c2
-rw-r--r--net/bridge/br_netfilter.c96
-rw-r--r--net/compat.c17
-rw-r--r--net/core/dev.c6
-rw-r--r--net/core/neighbour.c6
-rw-r--r--net/core/net_namespace.c35
-rw-r--r--net/core/netpoll.c6
-rw-r--r--net/core/rtnetlink.c21
-rw-r--r--net/decnet/dn_route.c2
-rw-r--r--net/econet/af_econet.c4
-rw-r--r--net/ipv4/af_inet.c12
-rw-r--r--net/ipv4/ip_gre.c6
-rw-r--r--net/ipv4/ipip.c6
-rw-r--r--net/ipv4/ipmr.c2
-rw-r--r--net/ipv4/udp.c61
-rw-r--r--net/ipv6/af_inet6.c20
-rw-r--r--net/ipv6/ip6_input.c6
-rw-r--r--net/ipv6/ip6_output.c26
-rw-r--r--net/ipv6/ip6_tunnel.c4
-rw-r--r--net/ipv6/ip6mr.c2
-rw-r--r--net/ipv6/sit.c6
-rw-r--r--net/ipv6/udp.c141
-rw-r--r--net/irda/irlan/irlan_eth.c4
-rw-r--r--net/irda/irnetlink.c2
-rw-r--r--net/lapb/lapb_iface.c2
-rw-r--r--net/mac80211/Kconfig16
-rw-r--r--net/mac80211/cfg.c216
-rw-r--r--net/mac80211/debugfs_netdev.c46
-rw-r--r--net/mac80211/debugfs_sta.c98
-rw-r--r--net/mac80211/event.c23
-rw-r--r--net/mac80211/ibss.c6
-rw-r--r--net/mac80211/ieee80211_i.h148
-rw-r--r--net/mac80211/iface.c30
-rw-r--r--net/mac80211/key.c28
-rw-r--r--net/mac80211/main.c5
-rw-r--r--net/mac80211/mesh.c6
-rw-r--r--net/mac80211/mesh.h3
-rw-r--r--net/mac80211/mlme.c1637
-rw-r--r--net/mac80211/rx.c103
-rw-r--r--net/mac80211/scan.c29
-rw-r--r--net/mac80211/sta_info.h17
-rw-r--r--net/mac80211/tx.c12
-rw-r--r--net/mac80211/wep.c52
-rw-r--r--net/mac80211/wep.h4
-rw-r--r--net/mac80211/wext.c450
-rw-r--r--net/mac80211/wpa.c3
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c2
-rw-r--r--net/netlink/af_netlink.c72
-rw-r--r--net/netlink/genetlink.c186
-rw-r--r--net/netrom/nr_dev.c4
-rw-r--r--net/phonet/pep-gprs.c4
-rw-r--r--net/rfkill/core.c10
-rw-r--r--net/rose/rose_dev.c2
-rw-r--r--net/sched/sch_teql.c6
-rw-r--r--net/tipc/netlink.c2
-rw-r--r--net/tipc/socket.c6
-rw-r--r--net/wireless/Kconfig43
-rw-r--r--net/wireless/Makefile4
-rw-r--r--net/wireless/core.c385
-rw-r--r--net/wireless/core.h184
-rw-r--r--net/wireless/debugfs.c14
-rw-r--r--net/wireless/debugfs.h8
-rw-r--r--net/wireless/ibss.c158
-rw-r--r--net/wireless/mlme.c581
-rw-r--r--net/wireless/nl80211.c1124
-rw-r--r--net/wireless/nl80211.h71
-rw-r--r--net/wireless/reg.c48
-rw-r--r--net/wireless/scan.c75
-rw-r--r--net/wireless/sme.c792
-rw-r--r--net/wireless/util.c21
-rw-r--r--net/wireless/wext-compat.c496
-rw-r--r--net/wireless/wext-sme.c380
-rw-r--r--net/wireless/wext.c256
-rw-r--r--scripts/.gitignore1
-rw-r--r--scripts/dtc/.gitignore5
-rwxr-xr-xscripts/kernel-doc4
-rw-r--r--scripts/package/builddeb2
-rw-r--r--scripts/pnmtologo.c4
-rw-r--r--security/integrity/ima/ima_main.c29
-rw-r--r--security/integrity/ima/ima_queue.c3
-rw-r--r--sound/isa/cmi8330.c2
-rw-r--r--sound/oss/kahlua.c2
-rw-r--r--sound/oss/mpu401.c16
-rw-r--r--sound/pci/atiixp.c8
-rw-r--r--sound/pci/atiixp_modem.c4
-rw-r--r--sound/pci/au88x0/au8810.c3
-rw-r--r--sound/pci/au88x0/au8820.c3
-rw-r--r--sound/pci/au88x0/au8830.c3
-rw-r--r--sound/pci/ca0106/ca0106_main.c2
-rw-r--r--sound/pci/cmipci.c10
-rw-r--r--sound/pci/cs4281.c2
-rw-r--r--sound/pci/cs46xx/cs46xx.c6
-rw-r--r--sound/pci/emu10k1/emu10k1.c6
-rw-r--r--sound/pci/emu10k1/emu10k1x.c2
-rw-r--r--sound/pci/ens1370.c8
-rw-r--r--sound/pci/es1938.c2
-rw-r--r--sound/pci/hda/hda_codec.c14
-rw-r--r--sound/pci/hda/hda_intel.c7
-rw-r--r--sound/pci/hda/patch_analog.c156
-rw-r--r--sound/pci/hda/patch_ca0110.c2
-rw-r--r--sound/pci/hda/patch_realtek.c70
-rw-r--r--sound/pci/ice1712/ice1712.c2
-rw-r--r--sound/pci/ice1712/ice1724.c2
-rw-r--r--sound/pci/intel8x0.c46
-rw-r--r--sound/pci/intel8x0m.c34
-rw-r--r--sound/pci/lx6464es/lx6464es.c7
-rw-r--r--sound/pci/mixart/mixart.c2
-rw-r--r--sound/pci/nm256/nm256.c6
-rw-r--r--sound/pci/oxygen/oxygen_mixer.c28
-rw-r--r--sound/pci/oxygen/virtuoso.c2
-rw-r--r--sound/pci/rme32.c9
-rw-r--r--sound/pci/rme96.c12
-rw-r--r--sound/pci/sonicvibes.c2
-rw-r--r--sound/pci/via82xx.c4
-rw-r--r--sound/pci/via82xx_modem.c2
-rw-r--r--sound/pci/ymfpci/ymfpci.c12
-rw-r--r--sound/soc/fsl/Kconfig6
-rw-r--r--sound/soc/omap/omap-pcm.c11
-rw-r--r--sound/soc/pxa/pxa2xx-i2s.c7
-rw-r--r--sound/sound_core.c5
-rw-r--r--sound/usb/caiaq/device.c10
-rw-r--r--sound/usb/usx2y/us122l.c2
-rw-r--r--sound/usb/usx2y/usbusx2y.c2
-rw-r--r--tools/perf/CREDITS30
-rw-r--r--tools/perf/Documentation/perf-report.txt14
-rw-r--r--tools/perf/Documentation/perf-stat.txt6
-rw-r--r--tools/perf/Makefile6
-rw-r--r--tools/perf/builtin-annotate.c8
-rw-r--r--tools/perf/builtin-record.c127
-rw-r--r--tools/perf/builtin-report.c236
-rw-r--r--tools/perf/builtin-stat.c171
-rw-r--r--tools/perf/builtin-top.c11
-rw-r--r--tools/perf/perf.h25
-rw-r--r--tools/perf/util/callchain.c174
-rw-r--r--tools/perf/util/callchain.h33
-rw-r--r--tools/perf/util/header.c242
-rw-r--r--tools/perf/util/header.h37
-rw-r--r--tools/perf/util/help.c15
-rw-r--r--tools/perf/util/pager.c5
-rw-r--r--tools/perf/util/parse-events.c153
-rw-r--r--tools/perf/util/run-command.c95
-rw-r--r--tools/perf/util/run-command.h5
-rw-r--r--tools/perf/util/strbuf.c2
-rw-r--r--tools/perf/util/string.h2
-rw-r--r--tools/perf/util/strlist.c184
-rw-r--r--tools/perf/util/strlist.h32
-rw-r--r--tools/perf/util/symbol.c16
-rw-r--r--tools/perf/util/symbol.h5
-rw-r--r--tools/perf/util/types.h (renamed from tools/perf/types.h)0
-rw-r--r--tools/perf/util/util.h15
-rw-r--r--virt/kvm/kvm_main.c5
1113 files changed, 33998 insertions, 20477 deletions
diff --git a/.gitignore b/.gitignore
index cecb3b040cc1..b93fb7eff942 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,6 +27,7 @@
27*.gz 27*.gz
28*.lzma 28*.lzma
29*.patch 29*.patch
30*.gcno
30 31
31# 32#
32# Top-level generic files 33# Top-level generic files
diff --git a/Documentation/block/data-integrity.txt b/Documentation/block/data-integrity.txt
index e8ca040ba2cf..2d735b0ae383 100644
--- a/Documentation/block/data-integrity.txt
+++ b/Documentation/block/data-integrity.txt
@@ -50,7 +50,7 @@ encouraged them to allow separation of the data and integrity metadata
50scatter-gather lists. 50scatter-gather lists.
51 51
52The controller will interleave the buffers on write and split them on 52The controller will interleave the buffers on write and split them on
53read. This means that the Linux can DMA the data buffers to and from 53read. This means that Linux can DMA the data buffers to and from
54host memory without changes to the page cache. 54host memory without changes to the page cache.
55 55
56Also, the 16-bit CRC checksum mandated by both the SCSI and SATA specs 56Also, the 16-bit CRC checksum mandated by both the SCSI and SATA specs
@@ -66,7 +66,7 @@ software RAID5).
66 66
67The IP checksum is weaker than the CRC in terms of detecting bit 67The IP checksum is weaker than the CRC in terms of detecting bit
68errors. However, the strength is really in the separation of the data 68errors. However, the strength is really in the separation of the data
69buffers and the integrity metadata. These two distinct buffers much 69buffers and the integrity metadata. These two distinct buffers must
70match up for an I/O to complete. 70match up for an I/O to complete.
71 71
72The separation of the data and integrity metadata buffers as well as 72The separation of the data and integrity metadata buffers as well as
diff --git a/Documentation/cgroups/cpusets.txt b/Documentation/cgroups/cpusets.txt
index f9ca389dddf4..1d7e9784439a 100644
--- a/Documentation/cgroups/cpusets.txt
+++ b/Documentation/cgroups/cpusets.txt
@@ -777,6 +777,18 @@ in cpuset directories:
777# /bin/echo 1-4 > cpus -> set cpus list to cpus 1,2,3,4 777# /bin/echo 1-4 > cpus -> set cpus list to cpus 1,2,3,4
778# /bin/echo 1,2,3,4 > cpus -> set cpus list to cpus 1,2,3,4 778# /bin/echo 1,2,3,4 > cpus -> set cpus list to cpus 1,2,3,4
779 779
780To add a CPU to a cpuset, write the new list of CPUs including the
781CPU to be added. To add 6 to the above cpuset:
782
783# /bin/echo 1-4,6 > cpus -> set cpus list to cpus 1,2,3,4,6
784
785Similarly to remove a CPU from a cpuset, write the new list of CPUs
786without the CPU to be removed.
787
788To remove all the CPUs:
789
790# /bin/echo "" > cpus -> clear cpus list
791
7802.3 Setting flags 7922.3 Setting flags
781----------------- 793-----------------
782 794
diff --git a/Documentation/gcov.txt b/Documentation/gcov.txt
index e716aadb3a33..40ec63352760 100644
--- a/Documentation/gcov.txt
+++ b/Documentation/gcov.txt
@@ -188,13 +188,18 @@ Solution: Exclude affected source files from profiling by specifying
188 GCOV_PROFILE := n or GCOV_PROFILE_basename.o := n in the 188 GCOV_PROFILE := n or GCOV_PROFILE_basename.o := n in the
189 corresponding Makefile. 189 corresponding Makefile.
190 190
191Problem: Files copied from sysfs appear empty or incomplete.
192Cause: Due to the way seq_file works, some tools such as cp or tar
193 may not correctly copy files from sysfs.
194Solution: Use 'cat' to read .gcda files and 'cp -d' to copy links.
195 Alternatively use the mechanism shown in Appendix B.
196
191 197
192Appendix A: gather_on_build.sh 198Appendix A: gather_on_build.sh
193============================== 199==============================
194 200
195Sample script to gather coverage meta files on the build machine 201Sample script to gather coverage meta files on the build machine
196(see 6a): 202(see 6a):
197
198#!/bin/bash 203#!/bin/bash
199 204
200KSRC=$1 205KSRC=$1
@@ -226,7 +231,7 @@ Appendix B: gather_on_test.sh
226Sample script to gather coverage data files on the test machine 231Sample script to gather coverage data files on the test machine
227(see 6b): 232(see 6b):
228 233
229#!/bin/bash 234#!/bin/bash -e
230 235
231DEST=$1 236DEST=$1
232GCDA=/sys/kernel/debug/gcov 237GCDA=/sys/kernel/debug/gcov
@@ -236,11 +241,13 @@ if [ -z "$DEST" ] ; then
236 exit 1 241 exit 1
237fi 242fi
238 243
239find $GCDA -name '*.gcno' -o -name '*.gcda' | tar cfz $DEST -T - 244TEMPDIR=$(mktemp -d)
245echo Collecting data..
246find $GCDA -type d -exec mkdir -p $TEMPDIR/\{\} \;
247find $GCDA -name '*.gcda' -exec sh -c 'cat < $0 > '$TEMPDIR'/$0' {} \;
248find $GCDA -name '*.gcno' -exec sh -c 'cp -d $0 '$TEMPDIR'/$0' {} \;
249tar czf $DEST -C $TEMPDIR sys
250rm -rf $TEMPDIR
240 251
241if [ $? -eq 0 ] ; then 252echo "$DEST successfully created, copy to build system and unpack with:"
242 echo "$DEST successfully created, copy to build system and unpack with:" 253echo " tar xfz $DEST"
243 echo " tar xfz $DEST"
244else
245 echo "Could not create file $DEST"
246fi
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index d08759aa0903..9347f4ad4342 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1531,6 +1531,11 @@ and is between 256 and 4096 characters. It is defined in the file
1531 symbolic names: lapic and ioapic 1531 symbolic names: lapic and ioapic
1532 Example: nmi_watchdog=2 or nmi_watchdog=panic,lapic 1532 Example: nmi_watchdog=2 or nmi_watchdog=panic,lapic
1533 1533
1534 netpoll.carrier_timeout=
1535 [NET] Specifies amount of time (in seconds) that
1536 netpoll should wait for a carrier. By default netpoll
1537 waits 4 seconds.
1538
1534 no387 [BUGS=X86-32] Tells the kernel to use the 387 maths 1539 no387 [BUGS=X86-32] Tells the kernel to use the 387 maths
1535 emulation library even if a 387 maths coprocessor 1540 emulation library even if a 387 maths coprocessor
1536 is present. 1541 is present.
@@ -1915,6 +1920,12 @@ and is between 256 and 4096 characters. It is defined in the file
1915 Format: { 0 | 1 } 1920 Format: { 0 | 1 }
1916 See arch/parisc/kernel/pdc_chassis.c 1921 See arch/parisc/kernel/pdc_chassis.c
1917 1922
1923 percpu_alloc= [X86] Select which percpu first chunk allocator to use.
1924 Allowed values are one of "lpage", "embed" and "4k".
1925 See comments in arch/x86/kernel/setup_percpu.c for
1926 details on each allocator. This parameter is primarily
1927 for debugging and performance comparison.
1928
1918 pf. [PARIDE] 1929 pf. [PARIDE]
1919 See Documentation/blockdev/paride.txt. 1930 See Documentation/blockdev/paride.txt.
1920 1931
@@ -2467,7 +2478,8 @@ and is between 256 and 4096 characters. It is defined in the file
2467 2478
2468 tp720= [HW,PS2] 2479 tp720= [HW,PS2]
2469 2480
2470 trace_buf_size=nn[KMG] [ftrace] will set tracing buffer size. 2481 trace_buf_size=nn[KMG]
2482 [FTRACE] will set tracing buffer size.
2471 2483
2472 trix= [HW,OSS] MediaTrix AudioTrix Pro 2484 trix= [HW,OSS] MediaTrix AudioTrix Pro
2473 Format: 2485 Format:
diff --git a/Documentation/kmemleak.txt b/Documentation/kmemleak.txt
index 0112da3b9ab8..89068030b01b 100644
--- a/Documentation/kmemleak.txt
+++ b/Documentation/kmemleak.txt
@@ -16,13 +16,17 @@ Usage
16----- 16-----
17 17
18CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel 18CONFIG_DEBUG_KMEMLEAK in "Kernel hacking" has to be enabled. A kernel
19thread scans the memory every 10 minutes (by default) and prints any new 19thread scans the memory every 10 minutes (by default) and prints the
20unreferenced objects found. To trigger an intermediate scan and display 20number of new unreferenced objects found. To display the details of all
21all the possible memory leaks: 21the possible memory leaks:
22 22
23 # mount -t debugfs nodev /sys/kernel/debug/ 23 # mount -t debugfs nodev /sys/kernel/debug/
24 # cat /sys/kernel/debug/kmemleak 24 # cat /sys/kernel/debug/kmemleak
25 25
26To trigger an intermediate memory scan:
27
28 # echo scan > /sys/kernel/debug/kmemleak
29
26Note that the orphan objects are listed in the order they were allocated 30Note that the orphan objects are listed in the order they were allocated
27and one object at the beginning of the list may cause other subsequent 31and one object at the beginning of the list may cause other subsequent
28objects to be reported as orphan. 32objects to be reported as orphan.
@@ -31,16 +35,21 @@ Memory scanning parameters can be modified at run-time by writing to the
31/sys/kernel/debug/kmemleak file. The following parameters are supported: 35/sys/kernel/debug/kmemleak file. The following parameters are supported:
32 36
33 off - disable kmemleak (irreversible) 37 off - disable kmemleak (irreversible)
34 stack=on - enable the task stacks scanning 38 stack=on - enable the task stacks scanning (default)
35 stack=off - disable the tasks stacks scanning 39 stack=off - disable the tasks stacks scanning
36 scan=on - start the automatic memory scanning thread 40 scan=on - start the automatic memory scanning thread (default)
37 scan=off - stop the automatic memory scanning thread 41 scan=off - stop the automatic memory scanning thread
38 scan=<secs> - set the automatic memory scanning period in seconds (0 42 scan=<secs> - set the automatic memory scanning period in seconds
39 to disable it) 43 (default 600, 0 to stop the automatic scanning)
44 scan - trigger a memory scan
40 45
41Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on 46Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on
42the kernel command line. 47the kernel command line.
43 48
49Memory may be allocated or freed before kmemleak is initialised and
50these actions are stored in an early log buffer. The size of this buffer
51is configured via the CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE option.
52
44Basic Algorithm 53Basic Algorithm
45--------------- 54---------------
46 55
diff --git a/Documentation/leds-lp3944.txt b/Documentation/leds-lp3944.txt
new file mode 100644
index 000000000000..c6eda18b15ef
--- /dev/null
+++ b/Documentation/leds-lp3944.txt
@@ -0,0 +1,50 @@
1Kernel driver lp3944
2====================
3
4 * National Semiconductor LP3944 Fun-light Chip
5 Prefix: 'lp3944'
6 Addresses scanned: None (see the Notes section below)
7 Datasheet: Publicly available at the National Semiconductor website
8 http://www.national.com/pf/LP/LP3944.html
9
10Authors:
11 Antonio Ospite <ospite@studenti.unina.it>
12
13
14Description
15-----------
16The LP3944 is a helper chip that can drive up to 8 leds, with two programmable
17DIM modes; it could even be used as a gpio expander but this driver assumes it
18is used as a led controller.
19
20The DIM modes are used to set _blink_ patterns for leds, the pattern is
21specified supplying two parameters:
22 - period: from 0s to 1.6s
23 - duty cycle: percentage of the period the led is on, from 0 to 100
24
25Setting a led in DIM0 or DIM1 mode makes it blink according to the pattern.
26See the datasheet for details.
27
28LP3944 can be found on Motorola A910 smartphone, where it drives the rgb
29leds, the camera flash light and the lcds power.
30
31
32Notes
33-----
34The chip is used mainly in embedded contexts, so this driver expects it is
35registered using the i2c_board_info mechanism.
36
37To register the chip at address 0x60 on adapter 0, set the platform data
38according to include/linux/leds-lp3944.h, set the i2c board info:
39
40 static struct i2c_board_info __initdata a910_i2c_board_info[] = {
41 {
42 I2C_BOARD_INFO("lp3944", 0x60),
43 .platform_data = &a910_lp3944_leds,
44 },
45 };
46
47and register it in the platform init function
48
49 i2c_register_board_info(0, a910_i2c_board_info,
50 ARRAY_SIZE(a910_i2c_board_info));
diff --git a/Documentation/powerpc/booting-without-of.txt b/Documentation/powerpc/booting-without-of.txt
index 8d999d862d0e..79f533f38c61 100644
--- a/Documentation/powerpc/booting-without-of.txt
+++ b/Documentation/powerpc/booting-without-of.txt
@@ -1238,1122 +1238,7 @@ descriptions for the SOC devices for which new nodes have been
1238defined; this list will expand as more and more SOC-containing 1238defined; this list will expand as more and more SOC-containing
1239platforms are moved over to use the flattened-device-tree model. 1239platforms are moved over to use the flattened-device-tree model.
1240 1240
1241 a) PHY nodes 1241VII - Specifying interrupt information for devices
1242
1243 Required properties:
1244
1245 - device_type : Should be "ethernet-phy"
1246 - interrupts : <a b> where a is the interrupt number and b is a
1247 field that represents an encoding of the sense and level
1248 information for the interrupt. This should be encoded based on
1249 the information in section 2) depending on the type of interrupt
1250 controller you have.
1251 - interrupt-parent : the phandle for the interrupt controller that
1252 services interrupts for this device.
1253 - reg : The ID number for the phy, usually a small integer
1254 - linux,phandle : phandle for this node; likely referenced by an
1255 ethernet controller node.
1256
1257
1258 Example:
1259
1260 ethernet-phy@0 {
1261 linux,phandle = <2452000>
1262 interrupt-parent = <40000>;
1263 interrupts = <35 1>;
1264 reg = <0>;
1265 device_type = "ethernet-phy";
1266 };
1267
1268
1269 b) Interrupt controllers
1270
1271 Some SOC devices contain interrupt controllers that are different
1272 from the standard Open PIC specification. The SOC device nodes for
1273 these types of controllers should be specified just like a standard
1274 OpenPIC controller. Sense and level information should be encoded
1275 as specified in section 2) of this chapter for each device that
1276 specifies an interrupt.
1277
1278 Example :
1279
1280 pic@40000 {
1281 linux,phandle = <40000>;
1282 interrupt-controller;
1283 #address-cells = <0>;
1284 reg = <40000 40000>;
1285 compatible = "chrp,open-pic";
1286 device_type = "open-pic";
1287 };
1288
1289 c) 4xx/Axon EMAC ethernet nodes
1290
1291 The EMAC ethernet controller in IBM and AMCC 4xx chips, and also
1292 the Axon bridge. To operate this needs to interact with a ths
1293 special McMAL DMA controller, and sometimes an RGMII or ZMII
1294 interface. In addition to the nodes and properties described
1295 below, the node for the OPB bus on which the EMAC sits must have a
1296 correct clock-frequency property.
1297
1298 i) The EMAC node itself
1299
1300 Required properties:
1301 - device_type : "network"
1302
1303 - compatible : compatible list, contains 2 entries, first is
1304 "ibm,emac-CHIP" where CHIP is the host ASIC (440gx,
1305 405gp, Axon) and second is either "ibm,emac" or
1306 "ibm,emac4". For Axon, thus, we have: "ibm,emac-axon",
1307 "ibm,emac4"
1308 - interrupts : <interrupt mapping for EMAC IRQ and WOL IRQ>
1309 - interrupt-parent : optional, if needed for interrupt mapping
1310 - reg : <registers mapping>
1311 - local-mac-address : 6 bytes, MAC address
1312 - mal-device : phandle of the associated McMAL node
1313 - mal-tx-channel : 1 cell, index of the tx channel on McMAL associated
1314 with this EMAC
1315 - mal-rx-channel : 1 cell, index of the rx channel on McMAL associated
1316 with this EMAC
1317 - cell-index : 1 cell, hardware index of the EMAC cell on a given
1318 ASIC (typically 0x0 and 0x1 for EMAC0 and EMAC1 on
1319 each Axon chip)
1320 - max-frame-size : 1 cell, maximum frame size supported in bytes
1321 - rx-fifo-size : 1 cell, Rx fifo size in bytes for 10 and 100 Mb/sec
1322 operations.
1323 For Axon, 2048
1324 - tx-fifo-size : 1 cell, Tx fifo size in bytes for 10 and 100 Mb/sec
1325 operations.
1326 For Axon, 2048.
1327 - fifo-entry-size : 1 cell, size of a fifo entry (used to calculate
1328 thresholds).
1329 For Axon, 0x00000010
1330 - mal-burst-size : 1 cell, MAL burst size (used to calculate thresholds)
1331 in bytes.
1332 For Axon, 0x00000100 (I think ...)
1333 - phy-mode : string, mode of operations of the PHY interface.
1334 Supported values are: "mii", "rmii", "smii", "rgmii",
1335 "tbi", "gmii", rtbi", "sgmii".
1336 For Axon on CAB, it is "rgmii"
1337 - mdio-device : 1 cell, required iff using shared MDIO registers
1338 (440EP). phandle of the EMAC to use to drive the
1339 MDIO lines for the PHY used by this EMAC.
1340 - zmii-device : 1 cell, required iff connected to a ZMII. phandle of
1341 the ZMII device node
1342 - zmii-channel : 1 cell, required iff connected to a ZMII. Which ZMII
1343 channel or 0xffffffff if ZMII is only used for MDIO.
1344 - rgmii-device : 1 cell, required iff connected to an RGMII. phandle
1345 of the RGMII device node.
1346 For Axon: phandle of plb5/plb4/opb/rgmii
1347 - rgmii-channel : 1 cell, required iff connected to an RGMII. Which
1348 RGMII channel is used by this EMAC.
1349 Fox Axon: present, whatever value is appropriate for each
1350 EMAC, that is the content of the current (bogus) "phy-port"
1351 property.
1352
1353 Optional properties:
1354 - phy-address : 1 cell, optional, MDIO address of the PHY. If absent,
1355 a search is performed.
1356 - phy-map : 1 cell, optional, bitmap of addresses to probe the PHY
1357 for, used if phy-address is absent. bit 0x00000001 is
1358 MDIO address 0.
1359 For Axon it can be absent, though my current driver
1360 doesn't handle phy-address yet so for now, keep
1361 0x00ffffff in it.
1362 - rx-fifo-size-gige : 1 cell, Rx fifo size in bytes for 1000 Mb/sec
1363 operations (if absent the value is the same as
1364 rx-fifo-size). For Axon, either absent or 2048.
1365 - tx-fifo-size-gige : 1 cell, Tx fifo size in bytes for 1000 Mb/sec
1366 operations (if absent the value is the same as
1367 tx-fifo-size). For Axon, either absent or 2048.
1368 - tah-device : 1 cell, optional. If connected to a TAH engine for
1369 offload, phandle of the TAH device node.
1370 - tah-channel : 1 cell, optional. If appropriate, channel used on the
1371 TAH engine.
1372
1373 Example:
1374
1375 EMAC0: ethernet@40000800 {
1376 device_type = "network";
1377 compatible = "ibm,emac-440gp", "ibm,emac";
1378 interrupt-parent = <&UIC1>;
1379 interrupts = <1c 4 1d 4>;
1380 reg = <40000800 70>;
1381 local-mac-address = [00 04 AC E3 1B 1E];
1382 mal-device = <&MAL0>;
1383 mal-tx-channel = <0 1>;
1384 mal-rx-channel = <0>;
1385 cell-index = <0>;
1386 max-frame-size = <5dc>;
1387 rx-fifo-size = <1000>;
1388 tx-fifo-size = <800>;
1389 phy-mode = "rmii";
1390 phy-map = <00000001>;
1391 zmii-device = <&ZMII0>;
1392 zmii-channel = <0>;
1393 };
1394
1395 ii) McMAL node
1396
1397 Required properties:
1398 - device_type : "dma-controller"
1399 - compatible : compatible list, containing 2 entries, first is
1400 "ibm,mcmal-CHIP" where CHIP is the host ASIC (like
1401 emac) and the second is either "ibm,mcmal" or
1402 "ibm,mcmal2".
1403 For Axon, "ibm,mcmal-axon","ibm,mcmal2"
1404 - interrupts : <interrupt mapping for the MAL interrupts sources:
1405 5 sources: tx_eob, rx_eob, serr, txde, rxde>.
1406 For Axon: This is _different_ from the current
1407 firmware. We use the "delayed" interrupts for txeob
1408 and rxeob. Thus we end up with mapping those 5 MPIC
1409 interrupts, all level positive sensitive: 10, 11, 32,
1410 33, 34 (in decimal)
1411 - dcr-reg : < DCR registers range >
1412 - dcr-parent : if needed for dcr-reg
1413 - num-tx-chans : 1 cell, number of Tx channels
1414 - num-rx-chans : 1 cell, number of Rx channels
1415
1416 iii) ZMII node
1417
1418 Required properties:
1419 - compatible : compatible list, containing 2 entries, first is
1420 "ibm,zmii-CHIP" where CHIP is the host ASIC (like
1421 EMAC) and the second is "ibm,zmii".
1422 For Axon, there is no ZMII node.
1423 - reg : <registers mapping>
1424
1425 iv) RGMII node
1426
1427 Required properties:
1428 - compatible : compatible list, containing 2 entries, first is
1429 "ibm,rgmii-CHIP" where CHIP is the host ASIC (like
1430 EMAC) and the second is "ibm,rgmii".
1431 For Axon, "ibm,rgmii-axon","ibm,rgmii"
1432 - reg : <registers mapping>
1433 - revision : as provided by the RGMII new version register if
1434 available.
1435 For Axon: 0x0000012a
1436
1437 d) Xilinx IP cores
1438
1439 The Xilinx EDK toolchain ships with a set of IP cores (devices) for use
1440 in Xilinx Spartan and Virtex FPGAs. The devices cover the whole range
1441 of standard device types (network, serial, etc.) and miscellaneous
1442 devices (gpio, LCD, spi, etc). Also, since these devices are
1443 implemented within the fpga fabric every instance of the device can be
1444 synthesised with different options that change the behaviour.
1445
1446 Each IP-core has a set of parameters which the FPGA designer can use to
1447 control how the core is synthesized. Historically, the EDK tool would
1448 extract the device parameters relevant to device drivers and copy them
1449 into an 'xparameters.h' in the form of #define symbols. This tells the
1450 device drivers how the IP cores are configured, but it requres the kernel
1451 to be recompiled every time the FPGA bitstream is resynthesized.
1452
1453 The new approach is to export the parameters into the device tree and
1454 generate a new device tree each time the FPGA bitstream changes. The
1455 parameters which used to be exported as #defines will now become
1456 properties of the device node. In general, device nodes for IP-cores
1457 will take the following form:
1458
1459 (name): (generic-name)@(base-address) {
1460 compatible = "xlnx,(ip-core-name)-(HW_VER)"
1461 [, (list of compatible devices), ...];
1462 reg = <(baseaddr) (size)>;
1463 interrupt-parent = <&interrupt-controller-phandle>;
1464 interrupts = < ... >;
1465 xlnx,(parameter1) = "(string-value)";
1466 xlnx,(parameter2) = <(int-value)>;
1467 };
1468
1469 (generic-name): an open firmware-style name that describes the
1470 generic class of device. Preferably, this is one word, such
1471 as 'serial' or 'ethernet'.
1472 (ip-core-name): the name of the ip block (given after the BEGIN
1473 directive in system.mhs). Should be in lowercase
1474 and all underscores '_' converted to dashes '-'.
1475 (name): is derived from the "PARAMETER INSTANCE" value.
1476 (parameter#): C_* parameters from system.mhs. The C_ prefix is
1477 dropped from the parameter name, the name is converted
1478 to lowercase and all underscore '_' characters are
1479 converted to dashes '-'.
1480 (baseaddr): the baseaddr parameter value (often named C_BASEADDR).
1481 (HW_VER): from the HW_VER parameter.
1482 (size): the address range size (often C_HIGHADDR - C_BASEADDR + 1).
1483
1484 Typically, the compatible list will include the exact IP core version
1485 followed by an older IP core version which implements the same
1486 interface or any other device with the same interface.
1487
1488 'reg', 'interrupt-parent' and 'interrupts' are all optional properties.
1489
1490 For example, the following block from system.mhs:
1491
1492 BEGIN opb_uartlite
1493 PARAMETER INSTANCE = opb_uartlite_0
1494 PARAMETER HW_VER = 1.00.b
1495 PARAMETER C_BAUDRATE = 115200
1496 PARAMETER C_DATA_BITS = 8
1497 PARAMETER C_ODD_PARITY = 0
1498 PARAMETER C_USE_PARITY = 0
1499 PARAMETER C_CLK_FREQ = 50000000
1500 PARAMETER C_BASEADDR = 0xEC100000
1501 PARAMETER C_HIGHADDR = 0xEC10FFFF
1502 BUS_INTERFACE SOPB = opb_7
1503 PORT OPB_Clk = CLK_50MHz
1504 PORT Interrupt = opb_uartlite_0_Interrupt
1505 PORT RX = opb_uartlite_0_RX
1506 PORT TX = opb_uartlite_0_TX
1507 PORT OPB_Rst = sys_bus_reset_0
1508 END
1509
1510 becomes the following device tree node:
1511
1512 opb_uartlite_0: serial@ec100000 {
1513 device_type = "serial";
1514 compatible = "xlnx,opb-uartlite-1.00.b";
1515 reg = <ec100000 10000>;
1516 interrupt-parent = <&opb_intc_0>;
1517 interrupts = <1 0>; // got this from the opb_intc parameters
1518 current-speed = <d#115200>; // standard serial device prop
1519 clock-frequency = <d#50000000>; // standard serial device prop
1520 xlnx,data-bits = <8>;
1521 xlnx,odd-parity = <0>;
1522 xlnx,use-parity = <0>;
1523 };
1524
1525 Some IP cores actually implement 2 or more logical devices. In
1526 this case, the device should still describe the whole IP core with
1527 a single node and add a child node for each logical device. The
1528 ranges property can be used to translate from parent IP-core to the
1529 registers of each device. In addition, the parent node should be
1530 compatible with the bus type 'xlnx,compound', and should contain
1531 #address-cells and #size-cells, as with any other bus. (Note: this
1532 makes the assumption that both logical devices have the same bus
1533 binding. If this is not true, then separate nodes should be used
1534 for each logical device). The 'cell-index' property can be used to
1535 enumerate logical devices within an IP core. For example, the
1536 following is the system.mhs entry for the dual ps2 controller found
1537 on the ml403 reference design.
1538
1539 BEGIN opb_ps2_dual_ref
1540 PARAMETER INSTANCE = opb_ps2_dual_ref_0
1541 PARAMETER HW_VER = 1.00.a
1542 PARAMETER C_BASEADDR = 0xA9000000
1543 PARAMETER C_HIGHADDR = 0xA9001FFF
1544 BUS_INTERFACE SOPB = opb_v20_0
1545 PORT Sys_Intr1 = ps2_1_intr
1546 PORT Sys_Intr2 = ps2_2_intr
1547 PORT Clkin1 = ps2_clk_rx_1
1548 PORT Clkin2 = ps2_clk_rx_2
1549 PORT Clkpd1 = ps2_clk_tx_1
1550 PORT Clkpd2 = ps2_clk_tx_2
1551 PORT Rx1 = ps2_d_rx_1
1552 PORT Rx2 = ps2_d_rx_2
1553 PORT Txpd1 = ps2_d_tx_1
1554 PORT Txpd2 = ps2_d_tx_2
1555 END
1556
1557 It would result in the following device tree nodes:
1558
1559 opb_ps2_dual_ref_0: opb-ps2-dual-ref@a9000000 {
1560 #address-cells = <1>;
1561 #size-cells = <1>;
1562 compatible = "xlnx,compound";
1563 ranges = <0 a9000000 2000>;
1564 // If this device had extra parameters, then they would
1565 // go here.
1566 ps2@0 {
1567 compatible = "xlnx,opb-ps2-dual-ref-1.00.a";
1568 reg = <0 40>;
1569 interrupt-parent = <&opb_intc_0>;
1570 interrupts = <3 0>;
1571 cell-index = <0>;
1572 };
1573 ps2@1000 {
1574 compatible = "xlnx,opb-ps2-dual-ref-1.00.a";
1575 reg = <1000 40>;
1576 interrupt-parent = <&opb_intc_0>;
1577 interrupts = <3 0>;
1578 cell-index = <0>;
1579 };
1580 };
1581
1582 Also, the system.mhs file defines bus attachments from the processor
1583 to the devices. The device tree structure should reflect the bus
1584 attachments. Again an example; this system.mhs fragment:
1585
1586 BEGIN ppc405_virtex4
1587 PARAMETER INSTANCE = ppc405_0
1588 PARAMETER HW_VER = 1.01.a
1589 BUS_INTERFACE DPLB = plb_v34_0
1590 BUS_INTERFACE IPLB = plb_v34_0
1591 END
1592
1593 BEGIN opb_intc
1594 PARAMETER INSTANCE = opb_intc_0
1595 PARAMETER HW_VER = 1.00.c
1596 PARAMETER C_BASEADDR = 0xD1000FC0
1597 PARAMETER C_HIGHADDR = 0xD1000FDF
1598 BUS_INTERFACE SOPB = opb_v20_0
1599 END
1600
1601 BEGIN opb_uart16550
1602 PARAMETER INSTANCE = opb_uart16550_0
1603 PARAMETER HW_VER = 1.00.d
1604 PARAMETER C_BASEADDR = 0xa0000000
1605 PARAMETER C_HIGHADDR = 0xa0001FFF
1606 BUS_INTERFACE SOPB = opb_v20_0
1607 END
1608
1609 BEGIN plb_v34
1610 PARAMETER INSTANCE = plb_v34_0
1611 PARAMETER HW_VER = 1.02.a
1612 END
1613
1614 BEGIN plb_bram_if_cntlr
1615 PARAMETER INSTANCE = plb_bram_if_cntlr_0
1616 PARAMETER HW_VER = 1.00.b
1617 PARAMETER C_BASEADDR = 0xFFFF0000
1618 PARAMETER C_HIGHADDR = 0xFFFFFFFF
1619 BUS_INTERFACE SPLB = plb_v34_0
1620 END
1621
1622 BEGIN plb2opb_bridge
1623 PARAMETER INSTANCE = plb2opb_bridge_0
1624 PARAMETER HW_VER = 1.01.a
1625 PARAMETER C_RNG0_BASEADDR = 0x20000000
1626 PARAMETER C_RNG0_HIGHADDR = 0x3FFFFFFF
1627 PARAMETER C_RNG1_BASEADDR = 0x60000000
1628 PARAMETER C_RNG1_HIGHADDR = 0x7FFFFFFF
1629 PARAMETER C_RNG2_BASEADDR = 0x80000000
1630 PARAMETER C_RNG2_HIGHADDR = 0xBFFFFFFF
1631 PARAMETER C_RNG3_BASEADDR = 0xC0000000
1632 PARAMETER C_RNG3_HIGHADDR = 0xDFFFFFFF
1633 BUS_INTERFACE SPLB = plb_v34_0
1634 BUS_INTERFACE MOPB = opb_v20_0
1635 END
1636
1637 Gives this device tree (some properties removed for clarity):
1638
1639 plb@0 {
1640 #address-cells = <1>;
1641 #size-cells = <1>;
1642 compatible = "xlnx,plb-v34-1.02.a";
1643 device_type = "ibm,plb";
1644 ranges; // 1:1 translation
1645
1646 plb_bram_if_cntrl_0: bram@ffff0000 {
1647 reg = <ffff0000 10000>;
1648 }
1649
1650 opb@20000000 {
1651 #address-cells = <1>;
1652 #size-cells = <1>;
1653 ranges = <20000000 20000000 20000000
1654 60000000 60000000 20000000
1655 80000000 80000000 40000000
1656 c0000000 c0000000 20000000>;
1657
1658 opb_uart16550_0: serial@a0000000 {
1659 reg = <a00000000 2000>;
1660 };
1661
1662 opb_intc_0: interrupt-controller@d1000fc0 {
1663 reg = <d1000fc0 20>;
1664 };
1665 };
1666 };
1667
1668 That covers the general approach to binding xilinx IP cores into the
1669 device tree. The following are bindings for specific devices:
1670
1671 i) Xilinx ML300 Framebuffer
1672
1673 Simple framebuffer device from the ML300 reference design (also on the
1674 ML403 reference design as well as others).
1675
1676 Optional properties:
1677 - resolution = <xres yres> : pixel resolution of framebuffer. Some
1678 implementations use a different resolution.
1679 Default is <d#640 d#480>
1680 - virt-resolution = <xvirt yvirt> : Size of framebuffer in memory.
1681 Default is <d#1024 d#480>.
1682 - rotate-display (empty) : rotate display 180 degrees.
1683
1684 ii) Xilinx SystemACE
1685
1686 The Xilinx SystemACE device is used to program FPGAs from an FPGA
1687 bitstream stored on a CF card. It can also be used as a generic CF
1688 interface device.
1689
1690 Optional properties:
1691 - 8-bit (empty) : Set this property for SystemACE in 8 bit mode
1692
1693 iii) Xilinx EMAC and Xilinx TEMAC
1694
1695 Xilinx Ethernet devices. In addition to general xilinx properties
1696 listed above, nodes for these devices should include a phy-handle
1697 property, and may include other common network device properties
1698 like local-mac-address.
1699
1700 iv) Xilinx Uartlite
1701
1702 Xilinx uartlite devices are simple fixed speed serial ports.
1703
1704 Required properties:
1705 - current-speed : Baud rate of uartlite
1706
1707 v) Xilinx hwicap
1708
1709 Xilinx hwicap devices provide access to the configuration logic
1710 of the FPGA through the Internal Configuration Access Port
1711 (ICAP). The ICAP enables partial reconfiguration of the FPGA,
1712 readback of the configuration information, and some control over
1713 'warm boots' of the FPGA fabric.
1714
1715 Required properties:
1716 - xlnx,family : The family of the FPGA, necessary since the
1717 capabilities of the underlying ICAP hardware
1718 differ between different families. May be
1719 'virtex2p', 'virtex4', or 'virtex5'.
1720
1721 vi) Xilinx Uart 16550
1722
1723 Xilinx UART 16550 devices are very similar to the NS16550 but with
1724 different register spacing and an offset from the base address.
1725
1726 Required properties:
1727 - clock-frequency : Frequency of the clock input
1728 - reg-offset : A value of 3 is required
1729 - reg-shift : A value of 2 is required
1730
1731 e) USB EHCI controllers
1732
1733 Required properties:
1734 - compatible : should be "usb-ehci".
1735 - reg : should contain at least address and length of the standard EHCI
1736 register set for the device. Optional platform-dependent registers
1737 (debug-port or other) can be also specified here, but only after
1738 definition of standard EHCI registers.
1739 - interrupts : one EHCI interrupt should be described here.
1740 If device registers are implemented in big endian mode, the device
1741 node should have "big-endian-regs" property.
1742 If controller implementation operates with big endian descriptors,
1743 "big-endian-desc" property should be specified.
1744 If both big endian registers and descriptors are used by the controller
1745 implementation, "big-endian" property can be specified instead of having
1746 both "big-endian-regs" and "big-endian-desc".
1747
1748 Example (Sequoia 440EPx):
1749 ehci@e0000300 {
1750 compatible = "ibm,usb-ehci-440epx", "usb-ehci";
1751 interrupt-parent = <&UIC0>;
1752 interrupts = <1a 4>;
1753 reg = <0 e0000300 90 0 e0000390 70>;
1754 big-endian;
1755 };
1756
1757 f) MDIO on GPIOs
1758
1759 Currently defined compatibles:
1760 - virtual,gpio-mdio
1761
1762 MDC and MDIO lines connected to GPIO controllers are listed in the
1763 gpios property as described in section VIII.1 in the following order:
1764
1765 MDC, MDIO.
1766
1767 Example:
1768
1769 mdio {
1770 compatible = "virtual,mdio-gpio";
1771 #address-cells = <1>;
1772 #size-cells = <0>;
1773 gpios = <&qe_pio_a 11
1774 &qe_pio_c 6>;
1775 };
1776
1777 g) SPI (Serial Peripheral Interface) busses
1778
1779 SPI busses can be described with a node for the SPI master device
1780 and a set of child nodes for each SPI slave on the bus. For this
1781 discussion, it is assumed that the system's SPI controller is in
1782 SPI master mode. This binding does not describe SPI controllers
1783 in slave mode.
1784
1785 The SPI master node requires the following properties:
1786 - #address-cells - number of cells required to define a chip select
1787 address on the SPI bus.
1788 - #size-cells - should be zero.
1789 - compatible - name of SPI bus controller following generic names
1790 recommended practice.
1791 No other properties are required in the SPI bus node. It is assumed
1792 that a driver for an SPI bus device will understand that it is an SPI bus.
1793 However, the binding does not attempt to define the specific method for
1794 assigning chip select numbers. Since SPI chip select configuration is
1795 flexible and non-standardized, it is left out of this binding with the
1796 assumption that board specific platform code will be used to manage
1797 chip selects. Individual drivers can define additional properties to
1798 support describing the chip select layout.
1799
1800 SPI slave nodes must be children of the SPI master node and can
1801 contain the following properties.
1802 - reg - (required) chip select address of device.
1803 - compatible - (required) name of SPI device following generic names
1804 recommended practice
1805 - spi-max-frequency - (required) Maximum SPI clocking speed of device in Hz
1806 - spi-cpol - (optional) Empty property indicating device requires
1807 inverse clock polarity (CPOL) mode
1808 - spi-cpha - (optional) Empty property indicating device requires
1809 shifted clock phase (CPHA) mode
1810 - spi-cs-high - (optional) Empty property indicating device requires
1811 chip select active high
1812
1813 SPI example for an MPC5200 SPI bus:
1814 spi@f00 {
1815 #address-cells = <1>;
1816 #size-cells = <0>;
1817 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
1818 reg = <0xf00 0x20>;
1819 interrupts = <2 13 0 2 14 0>;
1820 interrupt-parent = <&mpc5200_pic>;
1821
1822 ethernet-switch@0 {
1823 compatible = "micrel,ks8995m";
1824 spi-max-frequency = <1000000>;
1825 reg = <0>;
1826 };
1827
1828 codec@1 {
1829 compatible = "ti,tlv320aic26";
1830 spi-max-frequency = <100000>;
1831 reg = <1>;
1832 };
1833 };
1834
1835VII - Marvell Discovery mv64[345]6x System Controller chips
1836===========================================================
1837
1838The Marvell mv64[345]60 series of system controller chips contain
1839many of the peripherals needed to implement a complete computer
1840system. In this section, we define device tree nodes to describe
1841the system controller chip itself and each of the peripherals
1842which it contains. Compatible string values for each node are
1843prefixed with the string "marvell,", for Marvell Technology Group Ltd.
1844
18451) The /system-controller node
1846
1847 This node is used to represent the system-controller and must be
1848 present when the system uses a system controller chip. The top-level
1849 system-controller node contains information that is global to all
1850 devices within the system controller chip. The node name begins
1851 with "system-controller" followed by the unit address, which is
1852 the base address of the memory-mapped register set for the system
1853 controller chip.
1854
1855 Required properties:
1856
1857 - ranges : Describes the translation of system controller addresses
1858 for memory mapped registers.
1859 - clock-frequency: Contains the main clock frequency for the system
1860 controller chip.
1861 - reg : This property defines the address and size of the
1862 memory-mapped registers contained within the system controller
1863 chip. The address specified in the "reg" property should match
1864 the unit address of the system-controller node.
1865 - #address-cells : Address representation for system controller
1866 devices. This field represents the number of cells needed to
1867 represent the address of the memory-mapped registers of devices
1868 within the system controller chip.
1869 - #size-cells : Size representation for for the memory-mapped
1870 registers within the system controller chip.
1871 - #interrupt-cells : Defines the width of cells used to represent
1872 interrupts.
1873
1874 Optional properties:
1875
1876 - model : The specific model of the system controller chip. Such
1877 as, "mv64360", "mv64460", or "mv64560".
1878 - compatible : A string identifying the compatibility identifiers
1879 of the system controller chip.
1880
1881 The system-controller node contains child nodes for each system
1882 controller device that the platform uses. Nodes should not be created
1883 for devices which exist on the system controller chip but are not used
1884
1885 Example Marvell Discovery mv64360 system-controller node:
1886
1887 system-controller@f1000000 { /* Marvell Discovery mv64360 */
1888 #address-cells = <1>;
1889 #size-cells = <1>;
1890 model = "mv64360"; /* Default */
1891 compatible = "marvell,mv64360";
1892 clock-frequency = <133333333>;
1893 reg = <0xf1000000 0x10000>;
1894 virtual-reg = <0xf1000000>;
1895 ranges = <0x88000000 0x88000000 0x1000000 /* PCI 0 I/O Space */
1896 0x80000000 0x80000000 0x8000000 /* PCI 0 MEM Space */
1897 0xa0000000 0xa0000000 0x4000000 /* User FLASH */
1898 0x00000000 0xf1000000 0x0010000 /* Bridge's regs */
1899 0xf2000000 0xf2000000 0x0040000>;/* Integrated SRAM */
1900
1901 [ child node definitions... ]
1902 }
1903
19042) Child nodes of /system-controller
1905
1906 a) Marvell Discovery MDIO bus
1907
1908 The MDIO is a bus to which the PHY devices are connected. For each
1909 device that exists on this bus, a child node should be created. See
1910 the definition of the PHY node below for an example of how to define
1911 a PHY.
1912
1913 Required properties:
1914 - #address-cells : Should be <1>
1915 - #size-cells : Should be <0>
1916 - device_type : Should be "mdio"
1917 - compatible : Should be "marvell,mv64360-mdio"
1918
1919 Example:
1920
1921 mdio {
1922 #address-cells = <1>;
1923 #size-cells = <0>;
1924 device_type = "mdio";
1925 compatible = "marvell,mv64360-mdio";
1926
1927 ethernet-phy@0 {
1928 ......
1929 };
1930 };
1931
1932
1933 b) Marvell Discovery ethernet controller
1934
1935 The Discover ethernet controller is described with two levels
1936 of nodes. The first level describes an ethernet silicon block
1937 and the second level describes up to 3 ethernet nodes within
1938 that block. The reason for the multiple levels is that the
1939 registers for the node are interleaved within a single set
1940 of registers. The "ethernet-block" level describes the
1941 shared register set, and the "ethernet" nodes describe ethernet
1942 port-specific properties.
1943
1944 Ethernet block node
1945
1946 Required properties:
1947 - #address-cells : <1>
1948 - #size-cells : <0>
1949 - compatible : "marvell,mv64360-eth-block"
1950 - reg : Offset and length of the register set for this block
1951
1952 Example Discovery Ethernet block node:
1953 ethernet-block@2000 {
1954 #address-cells = <1>;
1955 #size-cells = <0>;
1956 compatible = "marvell,mv64360-eth-block";
1957 reg = <0x2000 0x2000>;
1958 ethernet@0 {
1959 .......
1960 };
1961 };
1962
1963 Ethernet port node
1964
1965 Required properties:
1966 - device_type : Should be "network".
1967 - compatible : Should be "marvell,mv64360-eth".
1968 - reg : Should be <0>, <1>, or <2>, according to which registers
1969 within the silicon block the device uses.
1970 - interrupts : <a> where a is the interrupt number for the port.
1971 - interrupt-parent : the phandle for the interrupt controller
1972 that services interrupts for this device.
1973 - phy : the phandle for the PHY connected to this ethernet
1974 controller.
1975 - local-mac-address : 6 bytes, MAC address
1976
1977 Example Discovery Ethernet port node:
1978 ethernet@0 {
1979 device_type = "network";
1980 compatible = "marvell,mv64360-eth";
1981 reg = <0>;
1982 interrupts = <32>;
1983 interrupt-parent = <&PIC>;
1984 phy = <&PHY0>;
1985 local-mac-address = [ 00 00 00 00 00 00 ];
1986 };
1987
1988
1989
1990 c) Marvell Discovery PHY nodes
1991
1992 Required properties:
1993 - device_type : Should be "ethernet-phy"
1994 - interrupts : <a> where a is the interrupt number for this phy.
1995 - interrupt-parent : the phandle for the interrupt controller that
1996 services interrupts for this device.
1997 - reg : The ID number for the phy, usually a small integer
1998
1999 Example Discovery PHY node:
2000 ethernet-phy@1 {
2001 device_type = "ethernet-phy";
2002 compatible = "broadcom,bcm5421";
2003 interrupts = <76>; /* GPP 12 */
2004 interrupt-parent = <&PIC>;
2005 reg = <1>;
2006 };
2007
2008
2009 d) Marvell Discovery SDMA nodes
2010
2011 Represent DMA hardware associated with the MPSC (multiprotocol
2012 serial controllers).
2013
2014 Required properties:
2015 - compatible : "marvell,mv64360-sdma"
2016 - reg : Offset and length of the register set for this device
2017 - interrupts : <a> where a is the interrupt number for the DMA
2018 device.
2019 - interrupt-parent : the phandle for the interrupt controller
2020 that services interrupts for this device.
2021
2022 Example Discovery SDMA node:
2023 sdma@4000 {
2024 compatible = "marvell,mv64360-sdma";
2025 reg = <0x4000 0xc18>;
2026 virtual-reg = <0xf1004000>;
2027 interrupts = <36>;
2028 interrupt-parent = <&PIC>;
2029 };
2030
2031
2032 e) Marvell Discovery BRG nodes
2033
2034 Represent baud rate generator hardware associated with the MPSC
2035 (multiprotocol serial controllers).
2036
2037 Required properties:
2038 - compatible : "marvell,mv64360-brg"
2039 - reg : Offset and length of the register set for this device
2040 - clock-src : A value from 0 to 15 which selects the clock
2041 source for the baud rate generator. This value corresponds
2042 to the CLKS value in the BRGx configuration register. See
2043 the mv64x60 User's Manual.
2044 - clock-frequence : The frequency (in Hz) of the baud rate
2045 generator's input clock.
2046 - current-speed : The current speed setting (presumably by
2047 firmware) of the baud rate generator.
2048
2049 Example Discovery BRG node:
2050 brg@b200 {
2051 compatible = "marvell,mv64360-brg";
2052 reg = <0xb200 0x8>;
2053 clock-src = <8>;
2054 clock-frequency = <133333333>;
2055 current-speed = <9600>;
2056 };
2057
2058
2059 f) Marvell Discovery CUNIT nodes
2060
2061 Represent the Serial Communications Unit device hardware.
2062
2063 Required properties:
2064 - reg : Offset and length of the register set for this device
2065
2066 Example Discovery CUNIT node:
2067 cunit@f200 {
2068 reg = <0xf200 0x200>;
2069 };
2070
2071
2072 g) Marvell Discovery MPSCROUTING nodes
2073
2074 Represent the Discovery's MPSC routing hardware
2075
2076 Required properties:
2077 - reg : Offset and length of the register set for this device
2078
2079 Example Discovery CUNIT node:
2080 mpscrouting@b500 {
2081 reg = <0xb400 0xc>;
2082 };
2083
2084
2085 h) Marvell Discovery MPSCINTR nodes
2086
2087 Represent the Discovery's MPSC DMA interrupt hardware registers
2088 (SDMA cause and mask registers).
2089
2090 Required properties:
2091 - reg : Offset and length of the register set for this device
2092
2093 Example Discovery MPSCINTR node:
2094 mpsintr@b800 {
2095 reg = <0xb800 0x100>;
2096 };
2097
2098
2099 i) Marvell Discovery MPSC nodes
2100
2101 Represent the Discovery's MPSC (Multiprotocol Serial Controller)
2102 serial port.
2103
2104 Required properties:
2105 - device_type : "serial"
2106 - compatible : "marvell,mv64360-mpsc"
2107 - reg : Offset and length of the register set for this device
2108 - sdma : the phandle for the SDMA node used by this port
2109 - brg : the phandle for the BRG node used by this port
2110 - cunit : the phandle for the CUNIT node used by this port
2111 - mpscrouting : the phandle for the MPSCROUTING node used by this port
2112 - mpscintr : the phandle for the MPSCINTR node used by this port
2113 - cell-index : the hardware index of this cell in the MPSC core
2114 - max_idle : value needed for MPSC CHR3 (Maximum Frame Length)
2115 register
2116 - interrupts : <a> where a is the interrupt number for the MPSC.
2117 - interrupt-parent : the phandle for the interrupt controller
2118 that services interrupts for this device.
2119
2120 Example Discovery MPSCINTR node:
2121 mpsc@8000 {
2122 device_type = "serial";
2123 compatible = "marvell,mv64360-mpsc";
2124 reg = <0x8000 0x38>;
2125 virtual-reg = <0xf1008000>;
2126 sdma = <&SDMA0>;
2127 brg = <&BRG0>;
2128 cunit = <&CUNIT>;
2129 mpscrouting = <&MPSCROUTING>;
2130 mpscintr = <&MPSCINTR>;
2131 cell-index = <0>;
2132 max_idle = <40>;
2133 interrupts = <40>;
2134 interrupt-parent = <&PIC>;
2135 };
2136
2137
2138 j) Marvell Discovery Watch Dog Timer nodes
2139
2140 Represent the Discovery's watchdog timer hardware
2141
2142 Required properties:
2143 - compatible : "marvell,mv64360-wdt"
2144 - reg : Offset and length of the register set for this device
2145
2146 Example Discovery Watch Dog Timer node:
2147 wdt@b410 {
2148 compatible = "marvell,mv64360-wdt";
2149 reg = <0xb410 0x8>;
2150 };
2151
2152
2153 k) Marvell Discovery I2C nodes
2154
2155 Represent the Discovery's I2C hardware
2156
2157 Required properties:
2158 - device_type : "i2c"
2159 - compatible : "marvell,mv64360-i2c"
2160 - reg : Offset and length of the register set for this device
2161 - interrupts : <a> where a is the interrupt number for the I2C.
2162 - interrupt-parent : the phandle for the interrupt controller
2163 that services interrupts for this device.
2164
2165 Example Discovery I2C node:
2166 compatible = "marvell,mv64360-i2c";
2167 reg = <0xc000 0x20>;
2168 virtual-reg = <0xf100c000>;
2169 interrupts = <37>;
2170 interrupt-parent = <&PIC>;
2171 };
2172
2173
2174 l) Marvell Discovery PIC (Programmable Interrupt Controller) nodes
2175
2176 Represent the Discovery's PIC hardware
2177
2178 Required properties:
2179 - #interrupt-cells : <1>
2180 - #address-cells : <0>
2181 - compatible : "marvell,mv64360-pic"
2182 - reg : Offset and length of the register set for this device
2183 - interrupt-controller
2184
2185 Example Discovery PIC node:
2186 pic {
2187 #interrupt-cells = <1>;
2188 #address-cells = <0>;
2189 compatible = "marvell,mv64360-pic";
2190 reg = <0x0 0x88>;
2191 interrupt-controller;
2192 };
2193
2194
2195 m) Marvell Discovery MPP (Multipurpose Pins) multiplexing nodes
2196
2197 Represent the Discovery's MPP hardware
2198
2199 Required properties:
2200 - compatible : "marvell,mv64360-mpp"
2201 - reg : Offset and length of the register set for this device
2202
2203 Example Discovery MPP node:
2204 mpp@f000 {
2205 compatible = "marvell,mv64360-mpp";
2206 reg = <0xf000 0x10>;
2207 };
2208
2209
2210 n) Marvell Discovery GPP (General Purpose Pins) nodes
2211
2212 Represent the Discovery's GPP hardware
2213
2214 Required properties:
2215 - compatible : "marvell,mv64360-gpp"
2216 - reg : Offset and length of the register set for this device
2217
2218 Example Discovery GPP node:
2219 gpp@f000 {
2220 compatible = "marvell,mv64360-gpp";
2221 reg = <0xf100 0x20>;
2222 };
2223
2224
2225 o) Marvell Discovery PCI host bridge node
2226
2227 Represents the Discovery's PCI host bridge device. The properties
2228 for this node conform to Rev 2.1 of the PCI Bus Binding to IEEE
2229 1275-1994. A typical value for the compatible property is
2230 "marvell,mv64360-pci".
2231
2232 Example Discovery PCI host bridge node
2233 pci@80000000 {
2234 #address-cells = <3>;
2235 #size-cells = <2>;
2236 #interrupt-cells = <1>;
2237 device_type = "pci";
2238 compatible = "marvell,mv64360-pci";
2239 reg = <0xcf8 0x8>;
2240 ranges = <0x01000000 0x0 0x0
2241 0x88000000 0x0 0x01000000
2242 0x02000000 0x0 0x80000000
2243 0x80000000 0x0 0x08000000>;
2244 bus-range = <0 255>;
2245 clock-frequency = <66000000>;
2246 interrupt-parent = <&PIC>;
2247 interrupt-map-mask = <0xf800 0x0 0x0 0x7>;
2248 interrupt-map = <
2249 /* IDSEL 0x0a */
2250 0x5000 0 0 1 &PIC 80
2251 0x5000 0 0 2 &PIC 81
2252 0x5000 0 0 3 &PIC 91
2253 0x5000 0 0 4 &PIC 93
2254
2255 /* IDSEL 0x0b */
2256 0x5800 0 0 1 &PIC 91
2257 0x5800 0 0 2 &PIC 93
2258 0x5800 0 0 3 &PIC 80
2259 0x5800 0 0 4 &PIC 81
2260
2261 /* IDSEL 0x0c */
2262 0x6000 0 0 1 &PIC 91
2263 0x6000 0 0 2 &PIC 93
2264 0x6000 0 0 3 &PIC 80
2265 0x6000 0 0 4 &PIC 81
2266
2267 /* IDSEL 0x0d */
2268 0x6800 0 0 1 &PIC 93
2269 0x6800 0 0 2 &PIC 80
2270 0x6800 0 0 3 &PIC 81
2271 0x6800 0 0 4 &PIC 91
2272 >;
2273 };
2274
2275
2276 p) Marvell Discovery CPU Error nodes
2277
2278 Represent the Discovery's CPU error handler device.
2279
2280 Required properties:
2281 - compatible : "marvell,mv64360-cpu-error"
2282 - reg : Offset and length of the register set for this device
2283 - interrupts : the interrupt number for this device
2284 - interrupt-parent : the phandle for the interrupt controller
2285 that services interrupts for this device.
2286
2287 Example Discovery CPU Error node:
2288 cpu-error@0070 {
2289 compatible = "marvell,mv64360-cpu-error";
2290 reg = <0x70 0x10 0x128 0x28>;
2291 interrupts = <3>;
2292 interrupt-parent = <&PIC>;
2293 };
2294
2295
2296 q) Marvell Discovery SRAM Controller nodes
2297
2298 Represent the Discovery's SRAM controller device.
2299
2300 Required properties:
2301 - compatible : "marvell,mv64360-sram-ctrl"
2302 - reg : Offset and length of the register set for this device
2303 - interrupts : the interrupt number for this device
2304 - interrupt-parent : the phandle for the interrupt controller
2305 that services interrupts for this device.
2306
2307 Example Discovery SRAM Controller node:
2308 sram-ctrl@0380 {
2309 compatible = "marvell,mv64360-sram-ctrl";
2310 reg = <0x380 0x80>;
2311 interrupts = <13>;
2312 interrupt-parent = <&PIC>;
2313 };
2314
2315
2316 r) Marvell Discovery PCI Error Handler nodes
2317
2318 Represent the Discovery's PCI error handler device.
2319
2320 Required properties:
2321 - compatible : "marvell,mv64360-pci-error"
2322 - reg : Offset and length of the register set for this device
2323 - interrupts : the interrupt number for this device
2324 - interrupt-parent : the phandle for the interrupt controller
2325 that services interrupts for this device.
2326
2327 Example Discovery PCI Error Handler node:
2328 pci-error@1d40 {
2329 compatible = "marvell,mv64360-pci-error";
2330 reg = <0x1d40 0x40 0xc28 0x4>;
2331 interrupts = <12>;
2332 interrupt-parent = <&PIC>;
2333 };
2334
2335
2336 s) Marvell Discovery Memory Controller nodes
2337
2338 Represent the Discovery's memory controller device.
2339
2340 Required properties:
2341 - compatible : "marvell,mv64360-mem-ctrl"
2342 - reg : Offset and length of the register set for this device
2343 - interrupts : the interrupt number for this device
2344 - interrupt-parent : the phandle for the interrupt controller
2345 that services interrupts for this device.
2346
2347 Example Discovery Memory Controller node:
2348 mem-ctrl@1400 {
2349 compatible = "marvell,mv64360-mem-ctrl";
2350 reg = <0x1400 0x60>;
2351 interrupts = <17>;
2352 interrupt-parent = <&PIC>;
2353 };
2354
2355
2356VIII - Specifying interrupt information for devices
2357=================================================== 1242===================================================
2358 1243
2359The device tree represents the busses and devices of a hardware 1244The device tree represents the busses and devices of a hardware
@@ -2439,56 +1324,7 @@ encodings listed below:
2439 2 = high to low edge sensitive type enabled 1324 2 = high to low edge sensitive type enabled
2440 3 = low to high edge sensitive type enabled 1325 3 = low to high edge sensitive type enabled
2441 1326
2442IX - Specifying GPIO information for devices 1327VIII - Specifying Device Power Management Information (sleep property)
2443============================================
2444
24451) gpios property
2446-----------------
2447
2448Nodes that makes use of GPIOs should define them using `gpios' property,
2449format of which is: <&gpio-controller1-phandle gpio1-specifier
2450 &gpio-controller2-phandle gpio2-specifier
2451 0 /* holes are permitted, means no GPIO 3 */
2452 &gpio-controller4-phandle gpio4-specifier
2453 ...>;
2454
2455Note that gpio-specifier length is controller dependent.
2456
2457gpio-specifier may encode: bank, pin position inside the bank,
2458whether pin is open-drain and whether pin is logically inverted.
2459
2460Example of the node using GPIOs:
2461
2462 node {
2463 gpios = <&qe_pio_e 18 0>;
2464 };
2465
2466In this example gpio-specifier is "18 0" and encodes GPIO pin number,
2467and empty GPIO flags as accepted by the "qe_pio_e" gpio-controller.
2468
24692) gpio-controller nodes
2470------------------------
2471
2472Every GPIO controller node must have #gpio-cells property defined,
2473this information will be used to translate gpio-specifiers.
2474
2475Example of two SOC GPIO banks defined as gpio-controller nodes:
2476
2477 qe_pio_a: gpio-controller@1400 {
2478 #gpio-cells = <2>;
2479 compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank";
2480 reg = <0x1400 0x18>;
2481 gpio-controller;
2482 };
2483
2484 qe_pio_e: gpio-controller@1460 {
2485 #gpio-cells = <2>;
2486 compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
2487 reg = <0x1460 0x18>;
2488 gpio-controller;
2489 };
2490
2491X - Specifying Device Power Management Information (sleep property)
2492=================================================================== 1328===================================================================
2493 1329
2494Devices on SOCs often have mechanisms for placing devices into low-power 1330Devices on SOCs often have mechanisms for placing devices into low-power
diff --git a/Documentation/powerpc/dts-bindings/4xx/emac.txt b/Documentation/powerpc/dts-bindings/4xx/emac.txt
new file mode 100644
index 000000000000..2161334a7ca5
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/4xx/emac.txt
@@ -0,0 +1,148 @@
1 4xx/Axon EMAC ethernet nodes
2
3 The EMAC ethernet controller in IBM and AMCC 4xx chips, and also
4 the Axon bridge. To operate this needs to interact with a ths
5 special McMAL DMA controller, and sometimes an RGMII or ZMII
6 interface. In addition to the nodes and properties described
7 below, the node for the OPB bus on which the EMAC sits must have a
8 correct clock-frequency property.
9
10 i) The EMAC node itself
11
12 Required properties:
13 - device_type : "network"
14
15 - compatible : compatible list, contains 2 entries, first is
16 "ibm,emac-CHIP" where CHIP is the host ASIC (440gx,
17 405gp, Axon) and second is either "ibm,emac" or
18 "ibm,emac4". For Axon, thus, we have: "ibm,emac-axon",
19 "ibm,emac4"
20 - interrupts : <interrupt mapping for EMAC IRQ and WOL IRQ>
21 - interrupt-parent : optional, if needed for interrupt mapping
22 - reg : <registers mapping>
23 - local-mac-address : 6 bytes, MAC address
24 - mal-device : phandle of the associated McMAL node
25 - mal-tx-channel : 1 cell, index of the tx channel on McMAL associated
26 with this EMAC
27 - mal-rx-channel : 1 cell, index of the rx channel on McMAL associated
28 with this EMAC
29 - cell-index : 1 cell, hardware index of the EMAC cell on a given
30 ASIC (typically 0x0 and 0x1 for EMAC0 and EMAC1 on
31 each Axon chip)
32 - max-frame-size : 1 cell, maximum frame size supported in bytes
33 - rx-fifo-size : 1 cell, Rx fifo size in bytes for 10 and 100 Mb/sec
34 operations.
35 For Axon, 2048
36 - tx-fifo-size : 1 cell, Tx fifo size in bytes for 10 and 100 Mb/sec
37 operations.
38 For Axon, 2048.
39 - fifo-entry-size : 1 cell, size of a fifo entry (used to calculate
40 thresholds).
41 For Axon, 0x00000010
42 - mal-burst-size : 1 cell, MAL burst size (used to calculate thresholds)
43 in bytes.
44 For Axon, 0x00000100 (I think ...)
45 - phy-mode : string, mode of operations of the PHY interface.
46 Supported values are: "mii", "rmii", "smii", "rgmii",
47 "tbi", "gmii", rtbi", "sgmii".
48 For Axon on CAB, it is "rgmii"
49 - mdio-device : 1 cell, required iff using shared MDIO registers
50 (440EP). phandle of the EMAC to use to drive the
51 MDIO lines for the PHY used by this EMAC.
52 - zmii-device : 1 cell, required iff connected to a ZMII. phandle of
53 the ZMII device node
54 - zmii-channel : 1 cell, required iff connected to a ZMII. Which ZMII
55 channel or 0xffffffff if ZMII is only used for MDIO.
56 - rgmii-device : 1 cell, required iff connected to an RGMII. phandle
57 of the RGMII device node.
58 For Axon: phandle of plb5/plb4/opb/rgmii
59 - rgmii-channel : 1 cell, required iff connected to an RGMII. Which
60 RGMII channel is used by this EMAC.
61 Fox Axon: present, whatever value is appropriate for each
62 EMAC, that is the content of the current (bogus) "phy-port"
63 property.
64
65 Optional properties:
66 - phy-address : 1 cell, optional, MDIO address of the PHY. If absent,
67 a search is performed.
68 - phy-map : 1 cell, optional, bitmap of addresses to probe the PHY
69 for, used if phy-address is absent. bit 0x00000001 is
70 MDIO address 0.
71 For Axon it can be absent, though my current driver
72 doesn't handle phy-address yet so for now, keep
73 0x00ffffff in it.
74 - rx-fifo-size-gige : 1 cell, Rx fifo size in bytes for 1000 Mb/sec
75 operations (if absent the value is the same as
76 rx-fifo-size). For Axon, either absent or 2048.
77 - tx-fifo-size-gige : 1 cell, Tx fifo size in bytes for 1000 Mb/sec
78 operations (if absent the value is the same as
79 tx-fifo-size). For Axon, either absent or 2048.
80 - tah-device : 1 cell, optional. If connected to a TAH engine for
81 offload, phandle of the TAH device node.
82 - tah-channel : 1 cell, optional. If appropriate, channel used on the
83 TAH engine.
84
85 Example:
86
87 EMAC0: ethernet@40000800 {
88 device_type = "network";
89 compatible = "ibm,emac-440gp", "ibm,emac";
90 interrupt-parent = <&UIC1>;
91 interrupts = <1c 4 1d 4>;
92 reg = <40000800 70>;
93 local-mac-address = [00 04 AC E3 1B 1E];
94 mal-device = <&MAL0>;
95 mal-tx-channel = <0 1>;
96 mal-rx-channel = <0>;
97 cell-index = <0>;
98 max-frame-size = <5dc>;
99 rx-fifo-size = <1000>;
100 tx-fifo-size = <800>;
101 phy-mode = "rmii";
102 phy-map = <00000001>;
103 zmii-device = <&ZMII0>;
104 zmii-channel = <0>;
105 };
106
107 ii) McMAL node
108
109 Required properties:
110 - device_type : "dma-controller"
111 - compatible : compatible list, containing 2 entries, first is
112 "ibm,mcmal-CHIP" where CHIP is the host ASIC (like
113 emac) and the second is either "ibm,mcmal" or
114 "ibm,mcmal2".
115 For Axon, "ibm,mcmal-axon","ibm,mcmal2"
116 - interrupts : <interrupt mapping for the MAL interrupts sources:
117 5 sources: tx_eob, rx_eob, serr, txde, rxde>.
118 For Axon: This is _different_ from the current
119 firmware. We use the "delayed" interrupts for txeob
120 and rxeob. Thus we end up with mapping those 5 MPIC
121 interrupts, all level positive sensitive: 10, 11, 32,
122 33, 34 (in decimal)
123 - dcr-reg : < DCR registers range >
124 - dcr-parent : if needed for dcr-reg
125 - num-tx-chans : 1 cell, number of Tx channels
126 - num-rx-chans : 1 cell, number of Rx channels
127
128 iii) ZMII node
129
130 Required properties:
131 - compatible : compatible list, containing 2 entries, first is
132 "ibm,zmii-CHIP" where CHIP is the host ASIC (like
133 EMAC) and the second is "ibm,zmii".
134 For Axon, there is no ZMII node.
135 - reg : <registers mapping>
136
137 iv) RGMII node
138
139 Required properties:
140 - compatible : compatible list, containing 2 entries, first is
141 "ibm,rgmii-CHIP" where CHIP is the host ASIC (like
142 EMAC) and the second is "ibm,rgmii".
143 For Axon, "ibm,rgmii-axon","ibm,rgmii"
144 - reg : <registers mapping>
145 - revision : as provided by the RGMII new version register if
146 available.
147 For Axon: 0x0000012a
148
diff --git a/Documentation/powerpc/dts-bindings/gpio/gpio.txt b/Documentation/powerpc/dts-bindings/gpio/gpio.txt
new file mode 100644
index 000000000000..edaa84d288a1
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/gpio/gpio.txt
@@ -0,0 +1,50 @@
1Specifying GPIO information for devices
2============================================
3
41) gpios property
5-----------------
6
7Nodes that makes use of GPIOs should define them using `gpios' property,
8format of which is: <&gpio-controller1-phandle gpio1-specifier
9 &gpio-controller2-phandle gpio2-specifier
10 0 /* holes are permitted, means no GPIO 3 */
11 &gpio-controller4-phandle gpio4-specifier
12 ...>;
13
14Note that gpio-specifier length is controller dependent.
15
16gpio-specifier may encode: bank, pin position inside the bank,
17whether pin is open-drain and whether pin is logically inverted.
18
19Example of the node using GPIOs:
20
21 node {
22 gpios = <&qe_pio_e 18 0>;
23 };
24
25In this example gpio-specifier is "18 0" and encodes GPIO pin number,
26and empty GPIO flags as accepted by the "qe_pio_e" gpio-controller.
27
282) gpio-controller nodes
29------------------------
30
31Every GPIO controller node must have #gpio-cells property defined,
32this information will be used to translate gpio-specifiers.
33
34Example of two SOC GPIO banks defined as gpio-controller nodes:
35
36 qe_pio_a: gpio-controller@1400 {
37 #gpio-cells = <2>;
38 compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank";
39 reg = <0x1400 0x18>;
40 gpio-controller;
41 };
42
43 qe_pio_e: gpio-controller@1460 {
44 #gpio-cells = <2>;
45 compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank";
46 reg = <0x1460 0x18>;
47 gpio-controller;
48 };
49
50
diff --git a/Documentation/powerpc/dts-bindings/gpio/led.txt b/Documentation/powerpc/dts-bindings/gpio/led.txt
index 4fe14deedc0a..064db928c3c1 100644
--- a/Documentation/powerpc/dts-bindings/gpio/led.txt
+++ b/Documentation/powerpc/dts-bindings/gpio/led.txt
@@ -16,10 +16,17 @@ LED sub-node properties:
16 string defining the trigger assigned to the LED. Current triggers are: 16 string defining the trigger assigned to the LED. Current triggers are:
17 "backlight" - LED will act as a back-light, controlled by the framebuffer 17 "backlight" - LED will act as a back-light, controlled by the framebuffer
18 system 18 system
19 "default-on" - LED will turn on 19 "default-on" - LED will turn on, but see "default-state" below
20 "heartbeat" - LED "double" flashes at a load average based rate 20 "heartbeat" - LED "double" flashes at a load average based rate
21 "ide-disk" - LED indicates disk activity 21 "ide-disk" - LED indicates disk activity
22 "timer" - LED flashes at a fixed, configurable rate 22 "timer" - LED flashes at a fixed, configurable rate
23- default-state: (optional) The initial state of the LED. Valid
24 values are "on", "off", and "keep". If the LED is already on or off
25 and the default-state property is set the to same value, then no
26 glitch should be produced where the LED momentarily turns off (or
27 on). The "keep" setting will keep the LED at whatever its current
28 state is, without producing a glitch. The default is off if this
29 property is not present.
23 30
24Examples: 31Examples:
25 32
@@ -30,14 +37,22 @@ leds {
30 gpios = <&mcu_pio 0 1>; /* Active low */ 37 gpios = <&mcu_pio 0 1>; /* Active low */
31 linux,default-trigger = "ide-disk"; 38 linux,default-trigger = "ide-disk";
32 }; 39 };
40
41 fault {
42 gpios = <&mcu_pio 1 0>;
43 /* Keep LED on if BIOS detected hardware fault */
44 default-state = "keep";
45 };
33}; 46};
34 47
35run-control { 48run-control {
36 compatible = "gpio-leds"; 49 compatible = "gpio-leds";
37 red { 50 red {
38 gpios = <&mpc8572 6 0>; 51 gpios = <&mpc8572 6 0>;
52 default-state = "off";
39 }; 53 };
40 green { 54 green {
41 gpios = <&mpc8572 7 0>; 55 gpios = <&mpc8572 7 0>;
56 default-state = "on";
42 }; 57 };
43} 58}
diff --git a/Documentation/powerpc/dts-bindings/gpio/mdio.txt b/Documentation/powerpc/dts-bindings/gpio/mdio.txt
new file mode 100644
index 000000000000..bc9549529014
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/gpio/mdio.txt
@@ -0,0 +1,19 @@
1MDIO on GPIOs
2
3Currently defined compatibles:
4- virtual,gpio-mdio
5
6MDC and MDIO lines connected to GPIO controllers are listed in the
7gpios property as described in section VIII.1 in the following order:
8
9MDC, MDIO.
10
11Example:
12
13mdio {
14 compatible = "virtual,mdio-gpio";
15 #address-cells = <1>;
16 #size-cells = <0>;
17 gpios = <&qe_pio_a 11
18 &qe_pio_c 6>;
19};
diff --git a/Documentation/powerpc/dts-bindings/marvell.txt b/Documentation/powerpc/dts-bindings/marvell.txt
new file mode 100644
index 000000000000..3708a2fd4747
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/marvell.txt
@@ -0,0 +1,521 @@
1Marvell Discovery mv64[345]6x System Controller chips
2===========================================================
3
4The Marvell mv64[345]60 series of system controller chips contain
5many of the peripherals needed to implement a complete computer
6system. In this section, we define device tree nodes to describe
7the system controller chip itself and each of the peripherals
8which it contains. Compatible string values for each node are
9prefixed with the string "marvell,", for Marvell Technology Group Ltd.
10
111) The /system-controller node
12
13 This node is used to represent the system-controller and must be
14 present when the system uses a system controller chip. The top-level
15 system-controller node contains information that is global to all
16 devices within the system controller chip. The node name begins
17 with "system-controller" followed by the unit address, which is
18 the base address of the memory-mapped register set for the system
19 controller chip.
20
21 Required properties:
22
23 - ranges : Describes the translation of system controller addresses
24 for memory mapped registers.
25 - clock-frequency: Contains the main clock frequency for the system
26 controller chip.
27 - reg : This property defines the address and size of the
28 memory-mapped registers contained within the system controller
29 chip. The address specified in the "reg" property should match
30 the unit address of the system-controller node.
31 - #address-cells : Address representation for system controller
32 devices. This field represents the number of cells needed to
33 represent the address of the memory-mapped registers of devices
34 within the system controller chip.
35 - #size-cells : Size representation for for the memory-mapped
36 registers within the system controller chip.
37 - #interrupt-cells : Defines the width of cells used to represent
38 interrupts.
39
40 Optional properties:
41
42 - model : The specific model of the system controller chip. Such
43 as, "mv64360", "mv64460", or "mv64560".
44 - compatible : A string identifying the compatibility identifiers
45 of the system controller chip.
46
47 The system-controller node contains child nodes for each system
48 controller device that the platform uses. Nodes should not be created
49 for devices which exist on the system controller chip but are not used
50
51 Example Marvell Discovery mv64360 system-controller node:
52
53 system-controller@f1000000 { /* Marvell Discovery mv64360 */
54 #address-cells = <1>;
55 #size-cells = <1>;
56 model = "mv64360"; /* Default */
57 compatible = "marvell,mv64360";
58 clock-frequency = <133333333>;
59 reg = <0xf1000000 0x10000>;
60 virtual-reg = <0xf1000000>;
61 ranges = <0x88000000 0x88000000 0x1000000 /* PCI 0 I/O Space */
62 0x80000000 0x80000000 0x8000000 /* PCI 0 MEM Space */
63 0xa0000000 0xa0000000 0x4000000 /* User FLASH */
64 0x00000000 0xf1000000 0x0010000 /* Bridge's regs */
65 0xf2000000 0xf2000000 0x0040000>;/* Integrated SRAM */
66
67 [ child node definitions... ]
68 }
69
702) Child nodes of /system-controller
71
72 a) Marvell Discovery MDIO bus
73
74 The MDIO is a bus to which the PHY devices are connected. For each
75 device that exists on this bus, a child node should be created. See
76 the definition of the PHY node below for an example of how to define
77 a PHY.
78
79 Required properties:
80 - #address-cells : Should be <1>
81 - #size-cells : Should be <0>
82 - device_type : Should be "mdio"
83 - compatible : Should be "marvell,mv64360-mdio"
84
85 Example:
86
87 mdio {
88 #address-cells = <1>;
89 #size-cells = <0>;
90 device_type = "mdio";
91 compatible = "marvell,mv64360-mdio";
92
93 ethernet-phy@0 {
94 ......
95 };
96 };
97
98
99 b) Marvell Discovery ethernet controller
100
101 The Discover ethernet controller is described with two levels
102 of nodes. The first level describes an ethernet silicon block
103 and the second level describes up to 3 ethernet nodes within
104 that block. The reason for the multiple levels is that the
105 registers for the node are interleaved within a single set
106 of registers. The "ethernet-block" level describes the
107 shared register set, and the "ethernet" nodes describe ethernet
108 port-specific properties.
109
110 Ethernet block node
111
112 Required properties:
113 - #address-cells : <1>
114 - #size-cells : <0>
115 - compatible : "marvell,mv64360-eth-block"
116 - reg : Offset and length of the register set for this block
117
118 Example Discovery Ethernet block node:
119 ethernet-block@2000 {
120 #address-cells = <1>;
121 #size-cells = <0>;
122 compatible = "marvell,mv64360-eth-block";
123 reg = <0x2000 0x2000>;
124 ethernet@0 {
125 .......
126 };
127 };
128
129 Ethernet port node
130
131 Required properties:
132 - device_type : Should be "network".
133 - compatible : Should be "marvell,mv64360-eth".
134 - reg : Should be <0>, <1>, or <2>, according to which registers
135 within the silicon block the device uses.
136 - interrupts : <a> where a is the interrupt number for the port.
137 - interrupt-parent : the phandle for the interrupt controller
138 that services interrupts for this device.
139 - phy : the phandle for the PHY connected to this ethernet
140 controller.
141 - local-mac-address : 6 bytes, MAC address
142
143 Example Discovery Ethernet port node:
144 ethernet@0 {
145 device_type = "network";
146 compatible = "marvell,mv64360-eth";
147 reg = <0>;
148 interrupts = <32>;
149 interrupt-parent = <&PIC>;
150 phy = <&PHY0>;
151 local-mac-address = [ 00 00 00 00 00 00 ];
152 };
153
154
155
156 c) Marvell Discovery PHY nodes
157
158 Required properties:
159 - device_type : Should be "ethernet-phy"
160 - interrupts : <a> where a is the interrupt number for this phy.
161 - interrupt-parent : the phandle for the interrupt controller that
162 services interrupts for this device.
163 - reg : The ID number for the phy, usually a small integer
164
165 Example Discovery PHY node:
166 ethernet-phy@1 {
167 device_type = "ethernet-phy";
168 compatible = "broadcom,bcm5421";
169 interrupts = <76>; /* GPP 12 */
170 interrupt-parent = <&PIC>;
171 reg = <1>;
172 };
173
174
175 d) Marvell Discovery SDMA nodes
176
177 Represent DMA hardware associated with the MPSC (multiprotocol
178 serial controllers).
179
180 Required properties:
181 - compatible : "marvell,mv64360-sdma"
182 - reg : Offset and length of the register set for this device
183 - interrupts : <a> where a is the interrupt number for the DMA
184 device.
185 - interrupt-parent : the phandle for the interrupt controller
186 that services interrupts for this device.
187
188 Example Discovery SDMA node:
189 sdma@4000 {
190 compatible = "marvell,mv64360-sdma";
191 reg = <0x4000 0xc18>;
192 virtual-reg = <0xf1004000>;
193 interrupts = <36>;
194 interrupt-parent = <&PIC>;
195 };
196
197
198 e) Marvell Discovery BRG nodes
199
200 Represent baud rate generator hardware associated with the MPSC
201 (multiprotocol serial controllers).
202
203 Required properties:
204 - compatible : "marvell,mv64360-brg"
205 - reg : Offset and length of the register set for this device
206 - clock-src : A value from 0 to 15 which selects the clock
207 source for the baud rate generator. This value corresponds
208 to the CLKS value in the BRGx configuration register. See
209 the mv64x60 User's Manual.
210 - clock-frequence : The frequency (in Hz) of the baud rate
211 generator's input clock.
212 - current-speed : The current speed setting (presumably by
213 firmware) of the baud rate generator.
214
215 Example Discovery BRG node:
216 brg@b200 {
217 compatible = "marvell,mv64360-brg";
218 reg = <0xb200 0x8>;
219 clock-src = <8>;
220 clock-frequency = <133333333>;
221 current-speed = <9600>;
222 };
223
224
225 f) Marvell Discovery CUNIT nodes
226
227 Represent the Serial Communications Unit device hardware.
228
229 Required properties:
230 - reg : Offset and length of the register set for this device
231
232 Example Discovery CUNIT node:
233 cunit@f200 {
234 reg = <0xf200 0x200>;
235 };
236
237
238 g) Marvell Discovery MPSCROUTING nodes
239
240 Represent the Discovery's MPSC routing hardware
241
242 Required properties:
243 - reg : Offset and length of the register set for this device
244
245 Example Discovery CUNIT node:
246 mpscrouting@b500 {
247 reg = <0xb400 0xc>;
248 };
249
250
251 h) Marvell Discovery MPSCINTR nodes
252
253 Represent the Discovery's MPSC DMA interrupt hardware registers
254 (SDMA cause and mask registers).
255
256 Required properties:
257 - reg : Offset and length of the register set for this device
258
259 Example Discovery MPSCINTR node:
260 mpsintr@b800 {
261 reg = <0xb800 0x100>;
262 };
263
264
265 i) Marvell Discovery MPSC nodes
266
267 Represent the Discovery's MPSC (Multiprotocol Serial Controller)
268 serial port.
269
270 Required properties:
271 - device_type : "serial"
272 - compatible : "marvell,mv64360-mpsc"
273 - reg : Offset and length of the register set for this device
274 - sdma : the phandle for the SDMA node used by this port
275 - brg : the phandle for the BRG node used by this port
276 - cunit : the phandle for the CUNIT node used by this port
277 - mpscrouting : the phandle for the MPSCROUTING node used by this port
278 - mpscintr : the phandle for the MPSCINTR node used by this port
279 - cell-index : the hardware index of this cell in the MPSC core
280 - max_idle : value needed for MPSC CHR3 (Maximum Frame Length)
281 register
282 - interrupts : <a> where a is the interrupt number for the MPSC.
283 - interrupt-parent : the phandle for the interrupt controller
284 that services interrupts for this device.
285
286 Example Discovery MPSCINTR node:
287 mpsc@8000 {
288 device_type = "serial";
289 compatible = "marvell,mv64360-mpsc";
290 reg = <0x8000 0x38>;
291 virtual-reg = <0xf1008000>;
292 sdma = <&SDMA0>;
293 brg = <&BRG0>;
294 cunit = <&CUNIT>;
295 mpscrouting = <&MPSCROUTING>;
296 mpscintr = <&MPSCINTR>;
297 cell-index = <0>;
298 max_idle = <40>;
299 interrupts = <40>;
300 interrupt-parent = <&PIC>;
301 };
302
303
304 j) Marvell Discovery Watch Dog Timer nodes
305
306 Represent the Discovery's watchdog timer hardware
307
308 Required properties:
309 - compatible : "marvell,mv64360-wdt"
310 - reg : Offset and length of the register set for this device
311
312 Example Discovery Watch Dog Timer node:
313 wdt@b410 {
314 compatible = "marvell,mv64360-wdt";
315 reg = <0xb410 0x8>;
316 };
317
318
319 k) Marvell Discovery I2C nodes
320
321 Represent the Discovery's I2C hardware
322
323 Required properties:
324 - device_type : "i2c"
325 - compatible : "marvell,mv64360-i2c"
326 - reg : Offset and length of the register set for this device
327 - interrupts : <a> where a is the interrupt number for the I2C.
328 - interrupt-parent : the phandle for the interrupt controller
329 that services interrupts for this device.
330
331 Example Discovery I2C node:
332 compatible = "marvell,mv64360-i2c";
333 reg = <0xc000 0x20>;
334 virtual-reg = <0xf100c000>;
335 interrupts = <37>;
336 interrupt-parent = <&PIC>;
337 };
338
339
340 l) Marvell Discovery PIC (Programmable Interrupt Controller) nodes
341
342 Represent the Discovery's PIC hardware
343
344 Required properties:
345 - #interrupt-cells : <1>
346 - #address-cells : <0>
347 - compatible : "marvell,mv64360-pic"
348 - reg : Offset and length of the register set for this device
349 - interrupt-controller
350
351 Example Discovery PIC node:
352 pic {
353 #interrupt-cells = <1>;
354 #address-cells = <0>;
355 compatible = "marvell,mv64360-pic";
356 reg = <0x0 0x88>;
357 interrupt-controller;
358 };
359
360
361 m) Marvell Discovery MPP (Multipurpose Pins) multiplexing nodes
362
363 Represent the Discovery's MPP hardware
364
365 Required properties:
366 - compatible : "marvell,mv64360-mpp"
367 - reg : Offset and length of the register set for this device
368
369 Example Discovery MPP node:
370 mpp@f000 {
371 compatible = "marvell,mv64360-mpp";
372 reg = <0xf000 0x10>;
373 };
374
375
376 n) Marvell Discovery GPP (General Purpose Pins) nodes
377
378 Represent the Discovery's GPP hardware
379
380 Required properties:
381 - compatible : "marvell,mv64360-gpp"
382 - reg : Offset and length of the register set for this device
383
384 Example Discovery GPP node:
385 gpp@f000 {
386 compatible = "marvell,mv64360-gpp";
387 reg = <0xf100 0x20>;
388 };
389
390
391 o) Marvell Discovery PCI host bridge node
392
393 Represents the Discovery's PCI host bridge device. The properties
394 for this node conform to Rev 2.1 of the PCI Bus Binding to IEEE
395 1275-1994. A typical value for the compatible property is
396 "marvell,mv64360-pci".
397
398 Example Discovery PCI host bridge node
399 pci@80000000 {
400 #address-cells = <3>;
401 #size-cells = <2>;
402 #interrupt-cells = <1>;
403 device_type = "pci";
404 compatible = "marvell,mv64360-pci";
405 reg = <0xcf8 0x8>;
406 ranges = <0x01000000 0x0 0x0
407 0x88000000 0x0 0x01000000
408 0x02000000 0x0 0x80000000
409 0x80000000 0x0 0x08000000>;
410 bus-range = <0 255>;
411 clock-frequency = <66000000>;
412 interrupt-parent = <&PIC>;
413 interrupt-map-mask = <0xf800 0x0 0x0 0x7>;
414 interrupt-map = <
415 /* IDSEL 0x0a */
416 0x5000 0 0 1 &PIC 80
417 0x5000 0 0 2 &PIC 81
418 0x5000 0 0 3 &PIC 91
419 0x5000 0 0 4 &PIC 93
420
421 /* IDSEL 0x0b */
422 0x5800 0 0 1 &PIC 91
423 0x5800 0 0 2 &PIC 93
424 0x5800 0 0 3 &PIC 80
425 0x5800 0 0 4 &PIC 81
426
427 /* IDSEL 0x0c */
428 0x6000 0 0 1 &PIC 91
429 0x6000 0 0 2 &PIC 93
430 0x6000 0 0 3 &PIC 80
431 0x6000 0 0 4 &PIC 81
432
433 /* IDSEL 0x0d */
434 0x6800 0 0 1 &PIC 93
435 0x6800 0 0 2 &PIC 80
436 0x6800 0 0 3 &PIC 81
437 0x6800 0 0 4 &PIC 91
438 >;
439 };
440
441
442 p) Marvell Discovery CPU Error nodes
443
444 Represent the Discovery's CPU error handler device.
445
446 Required properties:
447 - compatible : "marvell,mv64360-cpu-error"
448 - reg : Offset and length of the register set for this device
449 - interrupts : the interrupt number for this device
450 - interrupt-parent : the phandle for the interrupt controller
451 that services interrupts for this device.
452
453 Example Discovery CPU Error node:
454 cpu-error@0070 {
455 compatible = "marvell,mv64360-cpu-error";
456 reg = <0x70 0x10 0x128 0x28>;
457 interrupts = <3>;
458 interrupt-parent = <&PIC>;
459 };
460
461
462 q) Marvell Discovery SRAM Controller nodes
463
464 Represent the Discovery's SRAM controller device.
465
466 Required properties:
467 - compatible : "marvell,mv64360-sram-ctrl"
468 - reg : Offset and length of the register set for this device
469 - interrupts : the interrupt number for this device
470 - interrupt-parent : the phandle for the interrupt controller
471 that services interrupts for this device.
472
473 Example Discovery SRAM Controller node:
474 sram-ctrl@0380 {
475 compatible = "marvell,mv64360-sram-ctrl";
476 reg = <0x380 0x80>;
477 interrupts = <13>;
478 interrupt-parent = <&PIC>;
479 };
480
481
482 r) Marvell Discovery PCI Error Handler nodes
483
484 Represent the Discovery's PCI error handler device.
485
486 Required properties:
487 - compatible : "marvell,mv64360-pci-error"
488 - reg : Offset and length of the register set for this device
489 - interrupts : the interrupt number for this device
490 - interrupt-parent : the phandle for the interrupt controller
491 that services interrupts for this device.
492
493 Example Discovery PCI Error Handler node:
494 pci-error@1d40 {
495 compatible = "marvell,mv64360-pci-error";
496 reg = <0x1d40 0x40 0xc28 0x4>;
497 interrupts = <12>;
498 interrupt-parent = <&PIC>;
499 };
500
501
502 s) Marvell Discovery Memory Controller nodes
503
504 Represent the Discovery's memory controller device.
505
506 Required properties:
507 - compatible : "marvell,mv64360-mem-ctrl"
508 - reg : Offset and length of the register set for this device
509 - interrupts : the interrupt number for this device
510 - interrupt-parent : the phandle for the interrupt controller
511 that services interrupts for this device.
512
513 Example Discovery Memory Controller node:
514 mem-ctrl@1400 {
515 compatible = "marvell,mv64360-mem-ctrl";
516 reg = <0x1400 0x60>;
517 interrupts = <17>;
518 interrupt-parent = <&PIC>;
519 };
520
521
diff --git a/Documentation/powerpc/dts-bindings/phy.txt b/Documentation/powerpc/dts-bindings/phy.txt
new file mode 100644
index 000000000000..bb8c742eb8c5
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/phy.txt
@@ -0,0 +1,25 @@
1PHY nodes
2
3Required properties:
4
5 - device_type : Should be "ethernet-phy"
6 - interrupts : <a b> where a is the interrupt number and b is a
7 field that represents an encoding of the sense and level
8 information for the interrupt. This should be encoded based on
9 the information in section 2) depending on the type of interrupt
10 controller you have.
11 - interrupt-parent : the phandle for the interrupt controller that
12 services interrupts for this device.
13 - reg : The ID number for the phy, usually a small integer
14 - linux,phandle : phandle for this node; likely referenced by an
15 ethernet controller node.
16
17Example:
18
19ethernet-phy@0 {
20 linux,phandle = <2452000>
21 interrupt-parent = <40000>;
22 interrupts = <35 1>;
23 reg = <0>;
24 device_type = "ethernet-phy";
25};
diff --git a/Documentation/powerpc/dts-bindings/spi-bus.txt b/Documentation/powerpc/dts-bindings/spi-bus.txt
new file mode 100644
index 000000000000..e782add2e457
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/spi-bus.txt
@@ -0,0 +1,57 @@
1SPI (Serial Peripheral Interface) busses
2
3SPI busses can be described with a node for the SPI master device
4and a set of child nodes for each SPI slave on the bus. For this
5discussion, it is assumed that the system's SPI controller is in
6SPI master mode. This binding does not describe SPI controllers
7in slave mode.
8
9The SPI master node requires the following properties:
10- #address-cells - number of cells required to define a chip select
11 address on the SPI bus.
12- #size-cells - should be zero.
13- compatible - name of SPI bus controller following generic names
14 recommended practice.
15No other properties are required in the SPI bus node. It is assumed
16that a driver for an SPI bus device will understand that it is an SPI bus.
17However, the binding does not attempt to define the specific method for
18assigning chip select numbers. Since SPI chip select configuration is
19flexible and non-standardized, it is left out of this binding with the
20assumption that board specific platform code will be used to manage
21chip selects. Individual drivers can define additional properties to
22support describing the chip select layout.
23
24SPI slave nodes must be children of the SPI master node and can
25contain the following properties.
26- reg - (required) chip select address of device.
27- compatible - (required) name of SPI device following generic names
28 recommended practice
29- spi-max-frequency - (required) Maximum SPI clocking speed of device in Hz
30- spi-cpol - (optional) Empty property indicating device requires
31 inverse clock polarity (CPOL) mode
32- spi-cpha - (optional) Empty property indicating device requires
33 shifted clock phase (CPHA) mode
34- spi-cs-high - (optional) Empty property indicating device requires
35 chip select active high
36
37SPI example for an MPC5200 SPI bus:
38 spi@f00 {
39 #address-cells = <1>;
40 #size-cells = <0>;
41 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
42 reg = <0xf00 0x20>;
43 interrupts = <2 13 0 2 14 0>;
44 interrupt-parent = <&mpc5200_pic>;
45
46 ethernet-switch@0 {
47 compatible = "micrel,ks8995m";
48 spi-max-frequency = <1000000>;
49 reg = <0>;
50 };
51
52 codec@1 {
53 compatible = "ti,tlv320aic26";
54 spi-max-frequency = <100000>;
55 reg = <1>;
56 };
57 };
diff --git a/Documentation/powerpc/dts-bindings/usb-ehci.txt b/Documentation/powerpc/dts-bindings/usb-ehci.txt
new file mode 100644
index 000000000000..fa18612f757b
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/usb-ehci.txt
@@ -0,0 +1,25 @@
1USB EHCI controllers
2
3Required properties:
4 - compatible : should be "usb-ehci".
5 - reg : should contain at least address and length of the standard EHCI
6 register set for the device. Optional platform-dependent registers
7 (debug-port or other) can be also specified here, but only after
8 definition of standard EHCI registers.
9 - interrupts : one EHCI interrupt should be described here.
10If device registers are implemented in big endian mode, the device
11node should have "big-endian-regs" property.
12If controller implementation operates with big endian descriptors,
13"big-endian-desc" property should be specified.
14If both big endian registers and descriptors are used by the controller
15implementation, "big-endian" property can be specified instead of having
16both "big-endian-regs" and "big-endian-desc".
17
18Example (Sequoia 440EPx):
19 ehci@e0000300 {
20 compatible = "ibm,usb-ehci-440epx", "usb-ehci";
21 interrupt-parent = <&UIC0>;
22 interrupts = <1a 4>;
23 reg = <0 e0000300 90 0 e0000390 70>;
24 big-endian;
25 };
diff --git a/Documentation/powerpc/dts-bindings/xilinx.txt b/Documentation/powerpc/dts-bindings/xilinx.txt
new file mode 100644
index 000000000000..80339fe4300b
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/xilinx.txt
@@ -0,0 +1,295 @@
1 d) Xilinx IP cores
2
3 The Xilinx EDK toolchain ships with a set of IP cores (devices) for use
4 in Xilinx Spartan and Virtex FPGAs. The devices cover the whole range
5 of standard device types (network, serial, etc.) and miscellaneous
6 devices (gpio, LCD, spi, etc). Also, since these devices are
7 implemented within the fpga fabric every instance of the device can be
8 synthesised with different options that change the behaviour.
9
10 Each IP-core has a set of parameters which the FPGA designer can use to
11 control how the core is synthesized. Historically, the EDK tool would
12 extract the device parameters relevant to device drivers and copy them
13 into an 'xparameters.h' in the form of #define symbols. This tells the
14 device drivers how the IP cores are configured, but it requres the kernel
15 to be recompiled every time the FPGA bitstream is resynthesized.
16
17 The new approach is to export the parameters into the device tree and
18 generate a new device tree each time the FPGA bitstream changes. The
19 parameters which used to be exported as #defines will now become
20 properties of the device node. In general, device nodes for IP-cores
21 will take the following form:
22
23 (name): (generic-name)@(base-address) {
24 compatible = "xlnx,(ip-core-name)-(HW_VER)"
25 [, (list of compatible devices), ...];
26 reg = <(baseaddr) (size)>;
27 interrupt-parent = <&interrupt-controller-phandle>;
28 interrupts = < ... >;
29 xlnx,(parameter1) = "(string-value)";
30 xlnx,(parameter2) = <(int-value)>;
31 };
32
33 (generic-name): an open firmware-style name that describes the
34 generic class of device. Preferably, this is one word, such
35 as 'serial' or 'ethernet'.
36 (ip-core-name): the name of the ip block (given after the BEGIN
37 directive in system.mhs). Should be in lowercase
38 and all underscores '_' converted to dashes '-'.
39 (name): is derived from the "PARAMETER INSTANCE" value.
40 (parameter#): C_* parameters from system.mhs. The C_ prefix is
41 dropped from the parameter name, the name is converted
42 to lowercase and all underscore '_' characters are
43 converted to dashes '-'.
44 (baseaddr): the baseaddr parameter value (often named C_BASEADDR).
45 (HW_VER): from the HW_VER parameter.
46 (size): the address range size (often C_HIGHADDR - C_BASEADDR + 1).
47
48 Typically, the compatible list will include the exact IP core version
49 followed by an older IP core version which implements the same
50 interface or any other device with the same interface.
51
52 'reg', 'interrupt-parent' and 'interrupts' are all optional properties.
53
54 For example, the following block from system.mhs:
55
56 BEGIN opb_uartlite
57 PARAMETER INSTANCE = opb_uartlite_0
58 PARAMETER HW_VER = 1.00.b
59 PARAMETER C_BAUDRATE = 115200
60 PARAMETER C_DATA_BITS = 8
61 PARAMETER C_ODD_PARITY = 0
62 PARAMETER C_USE_PARITY = 0
63 PARAMETER C_CLK_FREQ = 50000000
64 PARAMETER C_BASEADDR = 0xEC100000
65 PARAMETER C_HIGHADDR = 0xEC10FFFF
66 BUS_INTERFACE SOPB = opb_7
67 PORT OPB_Clk = CLK_50MHz
68 PORT Interrupt = opb_uartlite_0_Interrupt
69 PORT RX = opb_uartlite_0_RX
70 PORT TX = opb_uartlite_0_TX
71 PORT OPB_Rst = sys_bus_reset_0
72 END
73
74 becomes the following device tree node:
75
76 opb_uartlite_0: serial@ec100000 {
77 device_type = "serial";
78 compatible = "xlnx,opb-uartlite-1.00.b";
79 reg = <ec100000 10000>;
80 interrupt-parent = <&opb_intc_0>;
81 interrupts = <1 0>; // got this from the opb_intc parameters
82 current-speed = <d#115200>; // standard serial device prop
83 clock-frequency = <d#50000000>; // standard serial device prop
84 xlnx,data-bits = <8>;
85 xlnx,odd-parity = <0>;
86 xlnx,use-parity = <0>;
87 };
88
89 Some IP cores actually implement 2 or more logical devices. In
90 this case, the device should still describe the whole IP core with
91 a single node and add a child node for each logical device. The
92 ranges property can be used to translate from parent IP-core to the
93 registers of each device. In addition, the parent node should be
94 compatible with the bus type 'xlnx,compound', and should contain
95 #address-cells and #size-cells, as with any other bus. (Note: this
96 makes the assumption that both logical devices have the same bus
97 binding. If this is not true, then separate nodes should be used
98 for each logical device). The 'cell-index' property can be used to
99 enumerate logical devices within an IP core. For example, the
100 following is the system.mhs entry for the dual ps2 controller found
101 on the ml403 reference design.
102
103 BEGIN opb_ps2_dual_ref
104 PARAMETER INSTANCE = opb_ps2_dual_ref_0
105 PARAMETER HW_VER = 1.00.a
106 PARAMETER C_BASEADDR = 0xA9000000
107 PARAMETER C_HIGHADDR = 0xA9001FFF
108 BUS_INTERFACE SOPB = opb_v20_0
109 PORT Sys_Intr1 = ps2_1_intr
110 PORT Sys_Intr2 = ps2_2_intr
111 PORT Clkin1 = ps2_clk_rx_1
112 PORT Clkin2 = ps2_clk_rx_2
113 PORT Clkpd1 = ps2_clk_tx_1
114 PORT Clkpd2 = ps2_clk_tx_2
115 PORT Rx1 = ps2_d_rx_1
116 PORT Rx2 = ps2_d_rx_2
117 PORT Txpd1 = ps2_d_tx_1
118 PORT Txpd2 = ps2_d_tx_2
119 END
120
121 It would result in the following device tree nodes:
122
123 opb_ps2_dual_ref_0: opb-ps2-dual-ref@a9000000 {
124 #address-cells = <1>;
125 #size-cells = <1>;
126 compatible = "xlnx,compound";
127 ranges = <0 a9000000 2000>;
128 // If this device had extra parameters, then they would
129 // go here.
130 ps2@0 {
131 compatible = "xlnx,opb-ps2-dual-ref-1.00.a";
132 reg = <0 40>;
133 interrupt-parent = <&opb_intc_0>;
134 interrupts = <3 0>;
135 cell-index = <0>;
136 };
137 ps2@1000 {
138 compatible = "xlnx,opb-ps2-dual-ref-1.00.a";
139 reg = <1000 40>;
140 interrupt-parent = <&opb_intc_0>;
141 interrupts = <3 0>;
142 cell-index = <0>;
143 };
144 };
145
146 Also, the system.mhs file defines bus attachments from the processor
147 to the devices. The device tree structure should reflect the bus
148 attachments. Again an example; this system.mhs fragment:
149
150 BEGIN ppc405_virtex4
151 PARAMETER INSTANCE = ppc405_0
152 PARAMETER HW_VER = 1.01.a
153 BUS_INTERFACE DPLB = plb_v34_0
154 BUS_INTERFACE IPLB = plb_v34_0
155 END
156
157 BEGIN opb_intc
158 PARAMETER INSTANCE = opb_intc_0
159 PARAMETER HW_VER = 1.00.c
160 PARAMETER C_BASEADDR = 0xD1000FC0
161 PARAMETER C_HIGHADDR = 0xD1000FDF
162 BUS_INTERFACE SOPB = opb_v20_0
163 END
164
165 BEGIN opb_uart16550
166 PARAMETER INSTANCE = opb_uart16550_0
167 PARAMETER HW_VER = 1.00.d
168 PARAMETER C_BASEADDR = 0xa0000000
169 PARAMETER C_HIGHADDR = 0xa0001FFF
170 BUS_INTERFACE SOPB = opb_v20_0
171 END
172
173 BEGIN plb_v34
174 PARAMETER INSTANCE = plb_v34_0
175 PARAMETER HW_VER = 1.02.a
176 END
177
178 BEGIN plb_bram_if_cntlr
179 PARAMETER INSTANCE = plb_bram_if_cntlr_0
180 PARAMETER HW_VER = 1.00.b
181 PARAMETER C_BASEADDR = 0xFFFF0000
182 PARAMETER C_HIGHADDR = 0xFFFFFFFF
183 BUS_INTERFACE SPLB = plb_v34_0
184 END
185
186 BEGIN plb2opb_bridge
187 PARAMETER INSTANCE = plb2opb_bridge_0
188 PARAMETER HW_VER = 1.01.a
189 PARAMETER C_RNG0_BASEADDR = 0x20000000
190 PARAMETER C_RNG0_HIGHADDR = 0x3FFFFFFF
191 PARAMETER C_RNG1_BASEADDR = 0x60000000
192 PARAMETER C_RNG1_HIGHADDR = 0x7FFFFFFF
193 PARAMETER C_RNG2_BASEADDR = 0x80000000
194 PARAMETER C_RNG2_HIGHADDR = 0xBFFFFFFF
195 PARAMETER C_RNG3_BASEADDR = 0xC0000000
196 PARAMETER C_RNG3_HIGHADDR = 0xDFFFFFFF
197 BUS_INTERFACE SPLB = plb_v34_0
198 BUS_INTERFACE MOPB = opb_v20_0
199 END
200
201 Gives this device tree (some properties removed for clarity):
202
203 plb@0 {
204 #address-cells = <1>;
205 #size-cells = <1>;
206 compatible = "xlnx,plb-v34-1.02.a";
207 device_type = "ibm,plb";
208 ranges; // 1:1 translation
209
210 plb_bram_if_cntrl_0: bram@ffff0000 {
211 reg = <ffff0000 10000>;
212 }
213
214 opb@20000000 {
215 #address-cells = <1>;
216 #size-cells = <1>;
217 ranges = <20000000 20000000 20000000
218 60000000 60000000 20000000
219 80000000 80000000 40000000
220 c0000000 c0000000 20000000>;
221
222 opb_uart16550_0: serial@a0000000 {
223 reg = <a00000000 2000>;
224 };
225
226 opb_intc_0: interrupt-controller@d1000fc0 {
227 reg = <d1000fc0 20>;
228 };
229 };
230 };
231
232 That covers the general approach to binding xilinx IP cores into the
233 device tree. The following are bindings for specific devices:
234
235 i) Xilinx ML300 Framebuffer
236
237 Simple framebuffer device from the ML300 reference design (also on the
238 ML403 reference design as well as others).
239
240 Optional properties:
241 - resolution = <xres yres> : pixel resolution of framebuffer. Some
242 implementations use a different resolution.
243 Default is <d#640 d#480>
244 - virt-resolution = <xvirt yvirt> : Size of framebuffer in memory.
245 Default is <d#1024 d#480>.
246 - rotate-display (empty) : rotate display 180 degrees.
247
248 ii) Xilinx SystemACE
249
250 The Xilinx SystemACE device is used to program FPGAs from an FPGA
251 bitstream stored on a CF card. It can also be used as a generic CF
252 interface device.
253
254 Optional properties:
255 - 8-bit (empty) : Set this property for SystemACE in 8 bit mode
256
257 iii) Xilinx EMAC and Xilinx TEMAC
258
259 Xilinx Ethernet devices. In addition to general xilinx properties
260 listed above, nodes for these devices should include a phy-handle
261 property, and may include other common network device properties
262 like local-mac-address.
263
264 iv) Xilinx Uartlite
265
266 Xilinx uartlite devices are simple fixed speed serial ports.
267
268 Required properties:
269 - current-speed : Baud rate of uartlite
270
271 v) Xilinx hwicap
272
273 Xilinx hwicap devices provide access to the configuration logic
274 of the FPGA through the Internal Configuration Access Port
275 (ICAP). The ICAP enables partial reconfiguration of the FPGA,
276 readback of the configuration information, and some control over
277 'warm boots' of the FPGA fabric.
278
279 Required properties:
280 - xlnx,family : The family of the FPGA, necessary since the
281 capabilities of the underlying ICAP hardware
282 differ between different families. May be
283 'virtex2p', 'virtex4', or 'virtex5'.
284
285 vi) Xilinx Uart 16550
286
287 Xilinx UART 16550 devices are very similar to the NS16550 but with
288 different register spacing and an offset from the base address.
289
290 Required properties:
291 - clock-frequency : Frequency of the clock input
292 - reg-offset : A value of 3 is required
293 - reg-shift : A value of 2 is required
294
295
diff --git a/Documentation/sound/alsa/HD-Audio-Models.txt b/Documentation/sound/alsa/HD-Audio-Models.txt
index 0d8d23581c44..939a3dd58148 100644
--- a/Documentation/sound/alsa/HD-Audio-Models.txt
+++ b/Documentation/sound/alsa/HD-Audio-Models.txt
@@ -240,6 +240,7 @@ AD1986A
240 laptop-automute 2-channel with EAPD and HP-automute (Lenovo N100) 240 laptop-automute 2-channel with EAPD and HP-automute (Lenovo N100)
241 ultra 2-channel with EAPD (Samsung Ultra tablet PC) 241 ultra 2-channel with EAPD (Samsung Ultra tablet PC)
242 samsung 2-channel with EAPD (Samsung R65) 242 samsung 2-channel with EAPD (Samsung R65)
243 samsung-p50 2-channel with HP-automute (Samsung P50)
243 244
244AD1988/AD1988B/AD1989A/AD1989B 245AD1988/AD1988B/AD1989A/AD1989B
245============================== 246==============================
diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c
index cf0e3ce0d526..c1a5aad3c75a 100644
--- a/Documentation/spi/spidev_test.c
+++ b/Documentation/spi/spidev_test.c
@@ -99,11 +99,13 @@ void parse_opts(int argc, char *argv[])
99 { "lsb", 0, 0, 'L' }, 99 { "lsb", 0, 0, 'L' },
100 { "cs-high", 0, 0, 'C' }, 100 { "cs-high", 0, 0, 'C' },
101 { "3wire", 0, 0, '3' }, 101 { "3wire", 0, 0, '3' },
102 { "no-cs", 0, 0, 'N' },
103 { "ready", 0, 0, 'R' },
102 { NULL, 0, 0, 0 }, 104 { NULL, 0, 0, 0 },
103 }; 105 };
104 int c; 106 int c;
105 107
106 c = getopt_long(argc, argv, "D:s:d:b:lHOLC3", lopts, NULL); 108 c = getopt_long(argc, argv, "D:s:d:b:lHOLC3NR", lopts, NULL);
107 109
108 if (c == -1) 110 if (c == -1)
109 break; 111 break;
@@ -139,6 +141,12 @@ void parse_opts(int argc, char *argv[])
139 case '3': 141 case '3':
140 mode |= SPI_3WIRE; 142 mode |= SPI_3WIRE;
141 break; 143 break;
144 case 'N':
145 mode |= SPI_NO_CS;
146 break;
147 case 'R':
148 mode |= SPI_READY;
149 break;
142 default: 150 default:
143 print_usage(argv[0]); 151 print_usage(argv[0]);
144 break; 152 break;
diff --git a/MAINTAINERS b/MAINTAINERS
index f608e1debdd9..57ea97973349 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -867,12 +867,22 @@ M: alex@shark-linux.de
867W: http://www.shark-linux.de/shark.html 867W: http://www.shark-linux.de/shark.html
868S: Maintained 868S: Maintained
869 869
870ARM/SAMSUNG ARM ARCHITECTURES
871P: Ben Dooks
872M: ben-linux@fluff.org
873L: linux-arm-kernel@lists.arm.linux.org.uk (subscribers-only)
874W: http://www.fluff.org/ben/linux/
875S: Maintained
876F: arch/arm/plat-s3c/
877F: arch/arm/plat-s3c24xx/
878
870ARM/S3C2410 ARM ARCHITECTURE 879ARM/S3C2410 ARM ARCHITECTURE
871P: Ben Dooks 880P: Ben Dooks
872M: ben-linux@fluff.org 881M: ben-linux@fluff.org
873L: linux-arm-kernel@lists.arm.linux.org.uk (subscribers-only) 882L: linux-arm-kernel@lists.arm.linux.org.uk (subscribers-only)
874W: http://www.fluff.org/ben/linux/ 883W: http://www.fluff.org/ben/linux/
875S: Maintained 884S: Maintained
885F: arch/arm/mach-s3c2410/
876 886
877ARM/S3C2440 ARM ARCHITECTURE 887ARM/S3C2440 ARM ARCHITECTURE
878P: Ben Dooks 888P: Ben Dooks
@@ -880,6 +890,39 @@ M: ben-linux@fluff.org
880L: linux-arm-kernel@lists.arm.linux.org.uk (subscribers-only) 890L: linux-arm-kernel@lists.arm.linux.org.uk (subscribers-only)
881W: http://www.fluff.org/ben/linux/ 891W: http://www.fluff.org/ben/linux/
882S: Maintained 892S: Maintained
893F: arch/arm/mach-s3c2440/
894
895ARM/S3C2442 ARM ARCHITECTURE
896P: Ben Dooks
897M: ben-linux@fluff.org
898L: linux-arm-kernel@lists.arm.linux.org.uk (subscribers-only)
899W: http://www.fluff.org/ben/linux/
900S: Maintained
901F: arch/arm/mach-s3c2442/
902
903ARM/S3C2443 ARM ARCHITECTURE
904P: Ben Dooks
905M: ben-linux@fluff.org
906L: linux-arm-kernel@lists.arm.linux.org.uk (subscribers-only)
907W: http://www.fluff.org/ben/linux/
908S: Maintained
909F: arch/arm/mach-s3c2443/
910
911ARM/S3C6400 ARM ARCHITECTURE
912P: Ben Dooks
913M: ben-linux@fluff.org
914L: linux-arm-kernel@lists.arm.linux.org.uk (subscribers-only)
915W: http://www.fluff.org/ben/linux/
916S: Maintained
917F: arch/arm/mach-s3c6400/
918
919ARM/S3C6410 ARM ARCHITECTURE
920P: Ben Dooks
921M: ben-linux@fluff.org
922L: linux-arm-kernel@lists.arm.linux.org.uk (subscribers-only)
923W: http://www.fluff.org/ben/linux/
924S: Maintained
925F: arch/arm/mach-s3c6410/
883 926
884ARM/TECHNOLOGIC SYSTEMS TS7250 MACHINE SUPPORT 927ARM/TECHNOLOGIC SYSTEMS TS7250 MACHINE SUPPORT
885P: Lennert Buytenhek 928P: Lennert Buytenhek
@@ -2087,9 +2130,9 @@ F: drivers/edac/i5400_edac.c
2087 2130
2088EDAC-I82975X 2131EDAC-I82975X
2089P: Ranganathan Desikan 2132P: Ranganathan Desikan
2090M: rdesikan@jetzbroadband.com 2133M: ravi@jetztechnologies.com
2091P: Arvind R. 2134P: Arvind R.
2092M: arvind@acarlab.com 2135M: arvind@jetztechnologies.com
2093L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers) 2136L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers)
2094W: bluesmoke.sourceforge.net 2137W: bluesmoke.sourceforge.net
2095S: Maintained 2138S: Maintained
@@ -2808,7 +2851,9 @@ S: Maintained
2808 2851
2809IA64 (Itanium) PLATFORM 2852IA64 (Itanium) PLATFORM
2810P: Tony Luck 2853P: Tony Luck
2854P: Fenghua Yu
2811M: tony.luck@intel.com 2855M: tony.luck@intel.com
2856M: fenghua.yu@intel.com
2812L: linux-ia64@vger.kernel.org 2857L: linux-ia64@vger.kernel.org
2813W: http://www.ia64-linux.org/ 2858W: http://www.ia64-linux.org/
2814T: git git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6.git 2859T: git git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6.git
@@ -5534,8 +5579,8 @@ F: drivers/staging/
5534 5579
5535STARFIRE/DURALAN NETWORK DRIVER 5580STARFIRE/DURALAN NETWORK DRIVER
5536P: Ion Badulescu 5581P: Ion Badulescu
5537M: ionut@cs.columbia.edu 5582M: ionut@badula.org
5538S: Maintained 5583S: Odd Fixes
5539F: drivers/net/starfire* 5584F: drivers/net/starfire*
5540 5585
5541STARMODE RADIO IP (STRIP) PROTOCOL DRIVER 5586STARMODE RADIO IP (STRIP) PROTOCOL DRIVER
@@ -5669,6 +5714,13 @@ F: drivers/misc/tifm*
5669F: drivers/mmc/host/tifm_sd.c 5714F: drivers/mmc/host/tifm_sd.c
5670F: include/linux/tifm.h 5715F: include/linux/tifm.h
5671 5716
5717TI TWL4030 SERIES SOC CODEC DRIVER
5718P: Peter Ujfalusi
5719M: peter.ujfalusi@nokia.com
5720L: alsa-devel@alsa-project.org (moderated for non-subscribers)
5721S: Maintained
5722F: sound/soc/codecs/twl4030*
5723
5672TIPC NETWORK LAYER 5724TIPC NETWORK LAYER
5673P: Per Liden 5725P: Per Liden
5674M: per.liden@ericsson.com 5726M: per.liden@ericsson.com
diff --git a/Makefile b/Makefile
index d1216fea0c92..0aeec59c1f0a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 2 1VERSION = 2
2PATCHLEVEL = 6 2PATCHLEVEL = 6
3SUBLEVEL = 31 3SUBLEVEL = 31
4EXTRAVERSION = -rc1 4EXTRAVERSION = -rc2
5NAME = Man-Eating Seals of Antiquity 5NAME = Man-Eating Seals of Antiquity
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
@@ -140,15 +140,13 @@ _all: modules
140endif 140endif
141 141
142srctree := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR)) 142srctree := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
143TOPDIR := $(srctree)
144# FIXME - TOPDIR is obsolete, use srctree/objtree
145objtree := $(CURDIR) 143objtree := $(CURDIR)
146src := $(srctree) 144src := $(srctree)
147obj := $(objtree) 145obj := $(objtree)
148 146
149VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD)) 147VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
150 148
151export srctree objtree VPATH TOPDIR 149export srctree objtree VPATH
152 150
153 151
154# SUBARCH tells the usermode build what the underlying arch is. That is set 152# SUBARCH tells the usermode build what the underlying arch is. That is set
@@ -344,7 +342,8 @@ KBUILD_CPPFLAGS := -D__KERNEL__
344 342
345KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ 343KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
346 -fno-strict-aliasing -fno-common \ 344 -fno-strict-aliasing -fno-common \
347 -Werror-implicit-function-declaration 345 -Werror-implicit-function-declaration \
346 -Wno-format-security
348KBUILD_AFLAGS := -D__ASSEMBLY__ 347KBUILD_AFLAGS := -D__ASSEMBLY__
349 348
350# Read KERNELRELEASE from include/config/kernel.release (if it exists) 349# Read KERNELRELEASE from include/config/kernel.release (if it exists)
diff --git a/arch/alpha/include/asm/percpu.h b/arch/alpha/include/asm/percpu.h
index 06c5c7a4afd3..b663f1f10b6a 100644
--- a/arch/alpha/include/asm/percpu.h
+++ b/arch/alpha/include/asm/percpu.h
@@ -30,7 +30,7 @@ extern unsigned long __per_cpu_offset[NR_CPUS];
30 30
31#ifndef MODULE 31#ifndef MODULE
32#define SHIFT_PERCPU_PTR(var, offset) RELOC_HIDE(&per_cpu_var(var), (offset)) 32#define SHIFT_PERCPU_PTR(var, offset) RELOC_HIDE(&per_cpu_var(var), (offset))
33#define PER_CPU_ATTRIBUTES 33#define PER_CPU_DEF_ATTRIBUTES
34#else 34#else
35/* 35/*
36 * To calculate addresses of locally defined variables, GCC uses 32-bit 36 * To calculate addresses of locally defined variables, GCC uses 32-bit
@@ -49,7 +49,7 @@ extern unsigned long __per_cpu_offset[NR_CPUS];
49 : "=&r"(__ptr), "=&r"(tmp_gp)); \ 49 : "=&r"(__ptr), "=&r"(tmp_gp)); \
50 (typeof(&per_cpu_var(var)))(__ptr + (offset)); }) 50 (typeof(&per_cpu_var(var)))(__ptr + (offset)); })
51 51
52#define PER_CPU_ATTRIBUTES __used 52#define PER_CPU_DEF_ATTRIBUTES __used
53 53
54#endif /* MODULE */ 54#endif /* MODULE */
55 55
@@ -71,7 +71,7 @@ extern unsigned long __per_cpu_offset[NR_CPUS];
71#define __get_cpu_var(var) per_cpu_var(var) 71#define __get_cpu_var(var) per_cpu_var(var)
72#define __raw_get_cpu_var(var) per_cpu_var(var) 72#define __raw_get_cpu_var(var) per_cpu_var(var)
73 73
74#define PER_CPU_ATTRIBUTES 74#define PER_CPU_DEF_ATTRIBUTES
75 75
76#endif /* SMP */ 76#endif /* SMP */
77 77
diff --git a/arch/arm/Kconfig.debug b/arch/arm/Kconfig.debug
index a71fd941ade7..a89e4734b8f0 100644
--- a/arch/arm/Kconfig.debug
+++ b/arch/arm/Kconfig.debug
@@ -99,14 +99,6 @@ config DEBUG_CLPS711X_UART2
99 output to the second serial port on these devices. Saying N will 99 output to the second serial port on these devices. Saying N will
100 cause the debug messages to appear on the first serial port. 100 cause the debug messages to appear on the first serial port.
101 101
102config DEBUG_S3C_PORT
103 depends on DEBUG_LL && PLAT_S3C
104 bool "Kernel low-level debugging messages via S3C UART"
105 help
106 Say Y here if you want debug print routines to go to one of the
107 S3C internal UARTs. The chosen UART must have been configured
108 before it is used.
109
110config DEBUG_S3C_UART 102config DEBUG_S3C_UART
111 depends on PLAT_S3C 103 depends on PLAT_S3C
112 int "S3C UART to use for low-level debug" 104 int "S3C UART to use for low-level debug"
diff --git a/arch/arm/configs/s3c2410_defconfig b/arch/arm/configs/s3c2410_defconfig
index 2d58b8fe59be..b49810461e41 100644
--- a/arch/arm/configs/s3c2410_defconfig
+++ b/arch/arm/configs/s3c2410_defconfig
@@ -260,6 +260,7 @@ CONFIG_MACH_NEXCODER_2440=y
260CONFIG_SMDK2440_CPU2440=y 260CONFIG_SMDK2440_CPU2440=y
261CONFIG_MACH_AT2440EVB=y 261CONFIG_MACH_AT2440EVB=y
262CONFIG_CPU_S3C2442=y 262CONFIG_CPU_S3C2442=y
263CONFIG_MACH_MINI2440=y
263 264
264# 265#
265# S3C2442 Machines 266# S3C2442 Machines
@@ -2298,7 +2299,6 @@ CONFIG_DEBUG_ERRORS=y
2298# CONFIG_DEBUG_STACK_USAGE is not set 2299# CONFIG_DEBUG_STACK_USAGE is not set
2299CONFIG_DEBUG_LL=y 2300CONFIG_DEBUG_LL=y
2300# CONFIG_DEBUG_ICEDCC is not set 2301# CONFIG_DEBUG_ICEDCC is not set
2301CONFIG_DEBUG_S3C_PORT=y
2302CONFIG_DEBUG_S3C_UART=0 2302CONFIG_DEBUG_S3C_UART=0
2303 2303
2304# 2304#
diff --git a/arch/arm/configs/s3c6400_defconfig b/arch/arm/configs/s3c6400_defconfig
index 2e8fa50e9a09..32860609e057 100644
--- a/arch/arm/configs/s3c6400_defconfig
+++ b/arch/arm/configs/s3c6400_defconfig
@@ -816,7 +816,6 @@ CONFIG_DEBUG_ERRORS=y
816# CONFIG_DEBUG_STACK_USAGE is not set 816# CONFIG_DEBUG_STACK_USAGE is not set
817CONFIG_DEBUG_LL=y 817CONFIG_DEBUG_LL=y
818# CONFIG_DEBUG_ICEDCC is not set 818# CONFIG_DEBUG_ICEDCC is not set
819CONFIG_DEBUG_S3C_PORT=y
820CONFIG_DEBUG_S3C_UART=0 819CONFIG_DEBUG_S3C_UART=0
821 820
822# 821#
diff --git a/arch/arm/configs/tct_hammer_defconfig b/arch/arm/configs/tct_hammer_defconfig
index 07dfb98df4f0..9d32faef05f6 100644
--- a/arch/arm/configs/tct_hammer_defconfig
+++ b/arch/arm/configs/tct_hammer_defconfig
@@ -857,7 +857,6 @@ CONFIG_DEBUG_ERRORS=y
857# CONFIG_DEBUG_STACK_USAGE is not set 857# CONFIG_DEBUG_STACK_USAGE is not set
858CONFIG_DEBUG_LL=y 858CONFIG_DEBUG_LL=y
859# CONFIG_DEBUG_ICEDCC is not set 859# CONFIG_DEBUG_ICEDCC is not set
860# CONFIG_DEBUG_S3C_PORT is not set
861CONFIG_DEBUG_S3C_UART=0 860CONFIG_DEBUG_S3C_UART=0
862 861
863# 862#
diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
index be962c1349c4..9c746af1bf6e 100644
--- a/arch/arm/include/asm/page.h
+++ b/arch/arm/include/asm/page.h
@@ -12,7 +12,7 @@
12 12
13/* PAGE_SHIFT determines the page size */ 13/* PAGE_SHIFT determines the page size */
14#define PAGE_SHIFT 12 14#define PAGE_SHIFT 12
15#define PAGE_SIZE (1UL << PAGE_SHIFT) 15#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
16#define PAGE_MASK (~(PAGE_SIZE-1)) 16#define PAGE_MASK (~(PAGE_SIZE-1))
17 17
18#ifndef __ASSEMBLY__ 18#ifndef __ASSEMBLY__
diff --git a/arch/arm/kernel/irq.c b/arch/arm/kernel/irq.c
index 096f600dc8d8..b7c3490eaa24 100644
--- a/arch/arm/kernel/irq.c
+++ b/arch/arm/kernel/irq.c
@@ -98,17 +98,6 @@ unlock:
98 return 0; 98 return 0;
99} 99}
100 100
101/* Handle bad interrupts */
102static struct irq_desc bad_irq_desc = {
103 .handle_irq = handle_bad_irq,
104 .lock = __SPIN_LOCK_UNLOCKED(bad_irq_desc.lock),
105};
106
107#ifdef CONFIG_CPUMASK_OFFSTACK
108/* We are not allocating bad_irq_desc.affinity or .pending_mask */
109#error "ARM architecture does not support CONFIG_CPUMASK_OFFSTACK."
110#endif
111
112/* 101/*
113 * do_IRQ handles all hardware IRQ's. Decoded IRQs should not 102 * do_IRQ handles all hardware IRQ's. Decoded IRQs should not
114 * come via this function. Instead, they should provide their 103 * come via this function. Instead, they should provide their
@@ -124,10 +113,13 @@ asmlinkage void __exception asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
124 * Some hardware gives randomly wrong interrupts. Rather 113 * Some hardware gives randomly wrong interrupts. Rather
125 * than crashing, do something sensible. 114 * than crashing, do something sensible.
126 */ 115 */
127 if (irq >= NR_IRQS) 116 if (unlikely(irq >= NR_IRQS)) {
128 handle_bad_irq(irq, &bad_irq_desc); 117 if (printk_ratelimit())
129 else 118 printk(KERN_WARNING "Bad IRQ%u\n", irq);
119 ack_bad_irq(irq);
120 } else {
130 generic_handle_irq(irq); 121 generic_handle_irq(irq);
122 }
131 123
132 /* AT91 specific workaround */ 124 /* AT91 specific workaround */
133 irq_finish(irq); 125 irq_finish(irq);
@@ -165,10 +157,6 @@ void __init init_IRQ(void)
165 for (irq = 0; irq < NR_IRQS; irq++) 157 for (irq = 0; irq < NR_IRQS; irq++)
166 irq_desc[irq].status |= IRQ_NOREQUEST | IRQ_NOPROBE; 158 irq_desc[irq].status |= IRQ_NOREQUEST | IRQ_NOPROBE;
167 159
168#ifdef CONFIG_SMP
169 cpumask_setall(bad_irq_desc.affinity);
170 bad_irq_desc.node = smp_processor_id();
171#endif
172 init_arch_irq(); 160 init_arch_irq();
173} 161}
174 162
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index 4340bf3d2c84..69371028a202 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -6,6 +6,7 @@
6#include <asm-generic/vmlinux.lds.h> 6#include <asm-generic/vmlinux.lds.h>
7#include <asm/thread_info.h> 7#include <asm/thread_info.h>
8#include <asm/memory.h> 8#include <asm/memory.h>
9#include <asm/page.h>
9 10
10OUTPUT_ARCH(arm) 11OUTPUT_ARCH(arm)
11ENTRY(stext) 12ENTRY(stext)
@@ -63,7 +64,7 @@ SECTIONS
63 usr/built-in.o(.init.ramfs) 64 usr/built-in.o(.init.ramfs)
64 __initramfs_end = .; 65 __initramfs_end = .;
65#endif 66#endif
66 . = ALIGN(4096); 67 . = ALIGN(PAGE_SIZE);
67 __per_cpu_load = .; 68 __per_cpu_load = .;
68 __per_cpu_start = .; 69 __per_cpu_start = .;
69 *(.data.percpu.page_aligned) 70 *(.data.percpu.page_aligned)
@@ -73,7 +74,7 @@ SECTIONS
73#ifndef CONFIG_XIP_KERNEL 74#ifndef CONFIG_XIP_KERNEL
74 __init_begin = _stext; 75 __init_begin = _stext;
75 INIT_DATA 76 INIT_DATA
76 . = ALIGN(4096); 77 . = ALIGN(PAGE_SIZE);
77 __init_end = .; 78 __init_end = .;
78#endif 79#endif
79 } 80 }
@@ -118,7 +119,7 @@ SECTIONS
118 *(.got) /* Global offset table */ 119 *(.got) /* Global offset table */
119 } 120 }
120 121
121 RODATA 122 RO_DATA(PAGE_SIZE)
122 123
123 _etext = .; /* End of text and rodata section */ 124 _etext = .; /* End of text and rodata section */
124 125
@@ -158,17 +159,17 @@ SECTIONS
158 *(.data.init_task) 159 *(.data.init_task)
159 160
160#ifdef CONFIG_XIP_KERNEL 161#ifdef CONFIG_XIP_KERNEL
161 . = ALIGN(4096); 162 . = ALIGN(PAGE_SIZE);
162 __init_begin = .; 163 __init_begin = .;
163 INIT_DATA 164 INIT_DATA
164 . = ALIGN(4096); 165 . = ALIGN(PAGE_SIZE);
165 __init_end = .; 166 __init_end = .;
166#endif 167#endif
167 168
168 . = ALIGN(4096); 169 . = ALIGN(PAGE_SIZE);
169 __nosave_begin = .; 170 __nosave_begin = .;
170 *(.data.nosave) 171 *(.data.nosave)
171 . = ALIGN(4096); 172 . = ALIGN(PAGE_SIZE);
172 __nosave_end = .; 173 __nosave_end = .;
173 174
174 /* 175 /*
diff --git a/arch/arm/mach-at91/board-sam9g20ek.c b/arch/arm/mach-at91/board-sam9g20ek.c
index cc270beadd5d..a55398ed1211 100644
--- a/arch/arm/mach-at91/board-sam9g20ek.c
+++ b/arch/arm/mach-at91/board-sam9g20ek.c
@@ -24,6 +24,8 @@
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
26#include <linux/spi/at73c213.h> 26#include <linux/spi/at73c213.h>
27#include <linux/gpio_keys.h>
28#include <linux/input.h>
27#include <linux/clk.h> 29#include <linux/clk.h>
28 30
29#include <mach/hardware.h> 31#include <mach/hardware.h>
@@ -218,6 +220,56 @@ static struct gpio_led ek_leds[] = {
218 } 220 }
219}; 221};
220 222
223
224/*
225 * GPIO Buttons
226 */
227#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
228static struct gpio_keys_button ek_buttons[] = {
229 {
230 .gpio = AT91_PIN_PA30,
231 .code = BTN_3,
232 .desc = "Button 3",
233 .active_low = 1,
234 .wakeup = 1,
235 },
236 {
237 .gpio = AT91_PIN_PA31,
238 .code = BTN_4,
239 .desc = "Button 4",
240 .active_low = 1,
241 .wakeup = 1,
242 }
243};
244
245static struct gpio_keys_platform_data ek_button_data = {
246 .buttons = ek_buttons,
247 .nbuttons = ARRAY_SIZE(ek_buttons),
248};
249
250static struct platform_device ek_button_device = {
251 .name = "gpio-keys",
252 .id = -1,
253 .num_resources = 0,
254 .dev = {
255 .platform_data = &ek_button_data,
256 }
257};
258
259static void __init ek_add_device_buttons(void)
260{
261 at91_set_gpio_input(AT91_PIN_PA30, 1); /* btn3 */
262 at91_set_deglitch(AT91_PIN_PA30, 1);
263 at91_set_gpio_input(AT91_PIN_PA31, 1); /* btn4 */
264 at91_set_deglitch(AT91_PIN_PA31, 1);
265
266 platform_device_register(&ek_button_device);
267}
268#else
269static void __init ek_add_device_buttons(void) {}
270#endif
271
272
221static struct i2c_board_info __initdata ek_i2c_devices[] = { 273static struct i2c_board_info __initdata ek_i2c_devices[] = {
222 { 274 {
223 I2C_BOARD_INFO("24c512", 0x50), 275 I2C_BOARD_INFO("24c512", 0x50),
@@ -245,6 +297,8 @@ static void __init ek_board_init(void)
245 at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices)); 297 at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
246 /* LEDs */ 298 /* LEDs */
247 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds)); 299 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
300 /* Push Buttons */
301 ek_add_device_buttons();
248 /* PCK0 provides MCLK to the WM8731 */ 302 /* PCK0 provides MCLK to the WM8731 */
249 at91_set_B_periph(AT91_PIN_PC1, 0); 303 at91_set_B_periph(AT91_PIN_PC1, 0);
250 /* SSC (for WM8731) */ 304 /* SSC (for WM8731) */
diff --git a/arch/arm/mach-at91/board-sam9rlek.c b/arch/arm/mach-at91/board-sam9rlek.c
index 35e12a49d1a6..f6b5672cabd6 100644
--- a/arch/arm/mach-at91/board-sam9rlek.c
+++ b/arch/arm/mach-at91/board-sam9rlek.c
@@ -186,19 +186,21 @@ static struct fb_monspecs at91fb_default_monspecs = {
186static void at91_lcdc_power_control(int on) 186static void at91_lcdc_power_control(int on)
187{ 187{
188 if (on) 188 if (on)
189 at91_set_gpio_value(AT91_PIN_PA30, 0); /* power up */ 189 at91_set_gpio_value(AT91_PIN_PC1, 0); /* power up */
190 else 190 else
191 at91_set_gpio_value(AT91_PIN_PA30, 1); /* power down */ 191 at91_set_gpio_value(AT91_PIN_PC1, 1); /* power down */
192} 192}
193 193
194/* Driver datas */ 194/* Driver datas */
195static struct atmel_lcdfb_info __initdata ek_lcdc_data = { 195static struct atmel_lcdfb_info __initdata ek_lcdc_data = {
196 .lcdcon_is_backlight = true,
196 .default_bpp = 16, 197 .default_bpp = 16,
197 .default_dmacon = ATMEL_LCDC_DMAEN, 198 .default_dmacon = ATMEL_LCDC_DMAEN,
198 .default_lcdcon2 = AT91SAM9RL_DEFAULT_LCDCON2, 199 .default_lcdcon2 = AT91SAM9RL_DEFAULT_LCDCON2,
199 .default_monspecs = &at91fb_default_monspecs, 200 .default_monspecs = &at91fb_default_monspecs,
200 .atmel_lcdfb_power_control = at91_lcdc_power_control, 201 .atmel_lcdfb_power_control = at91_lcdc_power_control,
201 .guard_time = 1, 202 .guard_time = 1,
203 .lcd_wiring_mode = ATMEL_LCDC_WIRING_RGB,
202}; 204};
203 205
204#else 206#else
diff --git a/arch/arm/mach-omap1/board-nokia770.c b/arch/arm/mach-omap1/board-nokia770.c
index e70fc7c66bbb..ed2a48a9ce74 100644
--- a/arch/arm/mach-omap1/board-nokia770.c
+++ b/arch/arm/mach-omap1/board-nokia770.c
@@ -36,7 +36,6 @@
36#include <mach/hwa742.h> 36#include <mach/hwa742.h>
37#include <mach/lcd_mipid.h> 37#include <mach/lcd_mipid.h>
38#include <mach/mmc.h> 38#include <mach/mmc.h>
39#include <mach/usb.h>
40#include <mach/clock.h> 39#include <mach/clock.h>
41 40
42#define ADS7846_PENDOWN_GPIO 15 41#define ADS7846_PENDOWN_GPIO 15
@@ -205,9 +204,11 @@ static int nokia770_mmc_get_cover_state(struct device *dev, int slot)
205static struct omap_mmc_platform_data nokia770_mmc2_data = { 204static struct omap_mmc_platform_data nokia770_mmc2_data = {
206 .nr_slots = 1, 205 .nr_slots = 1,
207 .dma_mask = 0xffffffff, 206 .dma_mask = 0xffffffff,
207 .max_freq = 12000000,
208 .slots[0] = { 208 .slots[0] = {
209 .set_power = nokia770_mmc_set_power, 209 .set_power = nokia770_mmc_set_power,
210 .get_cover_state = nokia770_mmc_get_cover_state, 210 .get_cover_state = nokia770_mmc_get_cover_state,
211 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
211 .name = "mmcblk", 212 .name = "mmcblk",
212 }, 213 },
213}; 214};
diff --git a/arch/arm/mach-omap1/mailbox.c b/arch/arm/mach-omap1/mailbox.c
index 0af4d6c85b47..6810b4aeb02c 100644
--- a/arch/arm/mach-omap1/mailbox.c
+++ b/arch/arm/mach-omap1/mailbox.c
@@ -203,5 +203,5 @@ module_exit(omap1_mbox_exit);
203 203
204MODULE_LICENSE("GPL v2"); 204MODULE_LICENSE("GPL v2");
205MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions"); 205MODULE_DESCRIPTION("omap mailbox: omap1 architecture specific functions");
206MODULE_AUTHOR("Hiroshi DOYU" <Hiroshi.DOYU@nokia.com>); 206MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
207MODULE_ALIAS("platform:omap1-mailbox"); 207MODULE_ALIAS("platform:omap1-mailbox");
diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c
index da93b86234ed..9a0bf6744a05 100644
--- a/arch/arm/mach-omap2/board-rx51-peripherals.c
+++ b/arch/arm/mach-omap2/board-rx51-peripherals.c
@@ -362,6 +362,7 @@ static struct omap_onenand_platform_data board_onenand_data = {
362 .gpio_irq = 65, 362 .gpio_irq = 65,
363 .parts = onenand_partitions, 363 .parts = onenand_partitions,
364 .nr_parts = ARRAY_SIZE(onenand_partitions), 364 .nr_parts = ARRAY_SIZE(onenand_partitions),
365 .flags = ONENAND_SYNC_READWRITE,
365}; 366};
366 367
367static void __init board_onenand_init(void) 368static void __init board_onenand_init(void)
diff --git a/arch/arm/mach-omap2/gpmc-onenand.c b/arch/arm/mach-omap2/gpmc-onenand.c
index 2fd22f9c5f0e..54fec53a48e7 100644
--- a/arch/arm/mach-omap2/gpmc-onenand.c
+++ b/arch/arm/mach-omap2/gpmc-onenand.c
@@ -31,6 +31,8 @@ static struct platform_device gpmc_onenand_device = {
31static int omap2_onenand_set_async_mode(int cs, void __iomem *onenand_base) 31static int omap2_onenand_set_async_mode(int cs, void __iomem *onenand_base)
32{ 32{
33 struct gpmc_timings t; 33 struct gpmc_timings t;
34 u32 reg;
35 int err;
34 36
35 const int t_cer = 15; 37 const int t_cer = 15;
36 const int t_avdp = 12; 38 const int t_avdp = 12;
@@ -43,6 +45,11 @@ static int omap2_onenand_set_async_mode(int cs, void __iomem *onenand_base)
43 const int t_wpl = 40; 45 const int t_wpl = 40;
44 const int t_wph = 30; 46 const int t_wph = 30;
45 47
48 /* Ensure sync read and sync write are disabled */
49 reg = readw(onenand_base + ONENAND_REG_SYS_CFG1);
50 reg &= ~ONENAND_SYS_CFG1_SYNC_READ & ~ONENAND_SYS_CFG1_SYNC_WRITE;
51 writew(reg, onenand_base + ONENAND_REG_SYS_CFG1);
52
46 memset(&t, 0, sizeof(t)); 53 memset(&t, 0, sizeof(t));
47 t.sync_clk = 0; 54 t.sync_clk = 0;
48 t.cs_on = 0; 55 t.cs_on = 0;
@@ -74,7 +81,16 @@ static int omap2_onenand_set_async_mode(int cs, void __iomem *onenand_base)
74 GPMC_CONFIG1_DEVICESIZE_16 | 81 GPMC_CONFIG1_DEVICESIZE_16 |
75 GPMC_CONFIG1_MUXADDDATA); 82 GPMC_CONFIG1_MUXADDDATA);
76 83
77 return gpmc_cs_set_timings(cs, &t); 84 err = gpmc_cs_set_timings(cs, &t);
85 if (err)
86 return err;
87
88 /* Ensure sync read and sync write are disabled */
89 reg = readw(onenand_base + ONENAND_REG_SYS_CFG1);
90 reg &= ~ONENAND_SYS_CFG1_SYNC_READ & ~ONENAND_SYS_CFG1_SYNC_WRITE;
91 writew(reg, onenand_base + ONENAND_REG_SYS_CFG1);
92
93 return 0;
78} 94}
79 95
80static void set_onenand_cfg(void __iomem *onenand_base, int latency, 96static void set_onenand_cfg(void __iomem *onenand_base, int latency,
@@ -124,7 +140,8 @@ static int omap2_onenand_set_sync_mode(struct omap_onenand_platform_data *cfg,
124 } else if (cfg->flags & ONENAND_SYNC_READWRITE) { 140 } else if (cfg->flags & ONENAND_SYNC_READWRITE) {
125 sync_read = 1; 141 sync_read = 1;
126 sync_write = 1; 142 sync_write = 1;
127 } 143 } else
144 return omap2_onenand_set_async_mode(cs, onenand_base);
128 145
129 if (!freq) { 146 if (!freq) {
130 /* Very first call freq is not known */ 147 /* Very first call freq is not known */
diff --git a/arch/arm/mach-omap2/id.c b/arch/arm/mach-omap2/id.c
index 458990e20c60..a98201cc265c 100644
--- a/arch/arm/mach-omap2/id.c
+++ b/arch/arm/mach-omap2/id.c
@@ -48,6 +48,28 @@ int omap_chip_is(struct omap_chip_id oci)
48} 48}
49EXPORT_SYMBOL(omap_chip_is); 49EXPORT_SYMBOL(omap_chip_is);
50 50
51int omap_type(void)
52{
53 u32 val = 0;
54
55 if (cpu_is_omap24xx())
56 val = omap_ctrl_readl(OMAP24XX_CONTROL_STATUS);
57 else if (cpu_is_omap34xx())
58 val = omap_ctrl_readl(OMAP343X_CONTROL_STATUS);
59 else {
60 pr_err("Cannot detect omap type!\n");
61 goto out;
62 }
63
64 val &= OMAP2_DEVICETYPE_MASK;
65 val >>= 8;
66
67out:
68 return val;
69}
70EXPORT_SYMBOL(omap_type);
71
72
51/*----------------------------------------------------------------------------*/ 73/*----------------------------------------------------------------------------*/
52 74
53#define OMAP_TAP_IDCODE 0x0204 75#define OMAP_TAP_IDCODE 0x0204
diff --git a/arch/arm/mach-omap2/mailbox.c b/arch/arm/mach-omap2/mailbox.c
index fd5b8a5925cc..6f71f3730c97 100644
--- a/arch/arm/mach-omap2/mailbox.c
+++ b/arch/arm/mach-omap2/mailbox.c
@@ -282,12 +282,12 @@ static int __devinit omap2_mbox_probe(struct platform_device *pdev)
282 return -ENOMEM; 282 return -ENOMEM;
283 283
284 /* DSP or IVA2 IRQ */ 284 /* DSP or IVA2 IRQ */
285 mbox_dsp_info.irq = platform_get_irq(pdev, 0); 285 ret = platform_get_irq(pdev, 0);
286 if (mbox_dsp_info.irq < 0) { 286 if (ret < 0) {
287 dev_err(&pdev->dev, "invalid irq resource\n"); 287 dev_err(&pdev->dev, "invalid irq resource\n");
288 ret = -ENODEV;
289 goto err_dsp; 288 goto err_dsp;
290 } 289 }
290 mbox_dsp_info.irq = ret;
291 291
292 ret = omap_mbox_register(&pdev->dev, &mbox_dsp_info); 292 ret = omap_mbox_register(&pdev->dev, &mbox_dsp_info);
293 if (ret) 293 if (ret)
diff --git a/arch/arm/mach-omap2/mmc-twl4030.c b/arch/arm/mach-omap2/mmc-twl4030.c
index 9756a878fd90..1541fd4c8d0f 100644
--- a/arch/arm/mach-omap2/mmc-twl4030.c
+++ b/arch/arm/mach-omap2/mmc-twl4030.c
@@ -263,8 +263,19 @@ static int twl_mmc1_set_power(struct device *dev, int slot, int power_on,
263static int twl_mmc23_set_power(struct device *dev, int slot, int power_on, int vdd) 263static int twl_mmc23_set_power(struct device *dev, int slot, int power_on, int vdd)
264{ 264{
265 int ret = 0; 265 int ret = 0;
266 struct twl_mmc_controller *c = &hsmmc[1]; 266 struct twl_mmc_controller *c = NULL;
267 struct omap_mmc_platform_data *mmc = dev->platform_data; 267 struct omap_mmc_platform_data *mmc = dev->platform_data;
268 int i;
269
270 for (i = 1; i < ARRAY_SIZE(hsmmc); i++) {
271 if (mmc == hsmmc[i].mmc) {
272 c = &hsmmc[i];
273 break;
274 }
275 }
276
277 if (c == NULL)
278 return -ENODEV;
268 279
269 /* If we don't see a Vcc regulator, assume it's a fixed 280 /* If we don't see a Vcc regulator, assume it's a fixed
270 * voltage always-on regulator. 281 * voltage always-on regulator.
diff --git a/arch/arm/mach-s3c2440/mach-mini2440.c b/arch/arm/mach-s3c2440/mach-mini2440.c
index 6a5bc3021bdb..ec71a6965786 100644
--- a/arch/arm/mach-s3c2440/mach-mini2440.c
+++ b/arch/arm/mach-s3c2440/mach-mini2440.c
@@ -48,8 +48,6 @@
48#include <plat/mci.h> 48#include <plat/mci.h>
49#include <plat/udc.h> 49#include <plat/udc.h>
50 50
51#include <plat/regs-serial.h>
52
53#include <linux/mtd/mtd.h> 51#include <linux/mtd/mtd.h>
54#include <linux/mtd/nand.h> 52#include <linux/mtd/nand.h>
55#include <linux/mtd/nand_ecc.h> 53#include <linux/mtd/nand_ecc.h>
@@ -275,6 +273,7 @@ static struct s3c2410_nand_set mini2440_nand_sets[] __initdata = {
275 .nr_chips = 1, 273 .nr_chips = 1,
276 .nr_partitions = ARRAY_SIZE(mini2440_default_nand_part), 274 .nr_partitions = ARRAY_SIZE(mini2440_default_nand_part),
277 .partitions = mini2440_default_nand_part, 275 .partitions = mini2440_default_nand_part,
276 .flash_bbt = 1, /* we use u-boot to create a BBT */
278 }, 277 },
279}; 278};
280 279
diff --git a/arch/arm/mach-s3c2442/mach-gta02.c b/arch/arm/mach-s3c2442/mach-gta02.c
index e23b581aa0e1..0fb385bd9cd9 100644
--- a/arch/arm/mach-s3c2442/mach-gta02.c
+++ b/arch/arm/mach-s3c2442/mach-gta02.c
@@ -433,8 +433,7 @@ static struct s3c2410_nand_set gta02_nand_sets[] = {
433 */ 433 */
434 .name = "neo1973-nand", 434 .name = "neo1973-nand",
435 .nr_chips = 1, 435 .nr_chips = 1,
436 .use_bbt = 1, 436 .flash_bbt = 1,
437 .force_soft_ecc = 1,
438 }, 437 },
439}; 438};
440 439
diff --git a/arch/arm/plat-omap/dma.c b/arch/arm/plat-omap/dma.c
index def14ec265b3..7677a4a1cef2 100644
--- a/arch/arm/plat-omap/dma.c
+++ b/arch/arm/plat-omap/dma.c
@@ -2457,6 +2457,19 @@ static int __init omap_init_dma(void)
2457 setup_irq(irq, &omap24xx_dma_irq); 2457 setup_irq(irq, &omap24xx_dma_irq);
2458 } 2458 }
2459 2459
2460 /* Enable smartidle idlemodes and autoidle */
2461 if (cpu_is_omap34xx()) {
2462 u32 v = dma_read(OCP_SYSCONFIG);
2463 v &= ~(DMA_SYSCONFIG_MIDLEMODE_MASK |
2464 DMA_SYSCONFIG_SIDLEMODE_MASK |
2465 DMA_SYSCONFIG_AUTOIDLE);
2466 v |= (DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_SMARTIDLE) |
2467 DMA_SYSCONFIG_SIDLEMODE(DMA_IDLEMODE_SMARTIDLE) |
2468 DMA_SYSCONFIG_AUTOIDLE);
2469 dma_write(v , OCP_SYSCONFIG);
2470 }
2471
2472
2460 /* FIXME: Update LCD DMA to work on 24xx */ 2473 /* FIXME: Update LCD DMA to work on 24xx */
2461 if (cpu_class_is_omap1()) { 2474 if (cpu_class_is_omap1()) {
2462 r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0, 2475 r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0,
diff --git a/arch/arm/plat-omap/gpio.c b/arch/arm/plat-omap/gpio.c
index 7fd89ba8d3b5..26b387c12423 100644
--- a/arch/arm/plat-omap/gpio.c
+++ b/arch/arm/plat-omap/gpio.c
@@ -1585,6 +1585,7 @@ static int __init _omap_gpio_init(void)
1585 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1); 1585 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
1586 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1); 1586 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
1587 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG); 1587 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
1588 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_DEBOUNCE_EN);
1588 1589
1589 /* Initialize interface clock ungated, module enabled */ 1590 /* Initialize interface clock ungated, module enabled */
1590 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL); 1591 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
diff --git a/arch/arm/plat-omap/include/mach/cpu.h b/arch/arm/plat-omap/include/mach/cpu.h
index fc60c4ebcc28..285eaa3a8275 100644
--- a/arch/arm/plat-omap/include/mach/cpu.h
+++ b/arch/arm/plat-omap/include/mach/cpu.h
@@ -30,6 +30,17 @@
30#ifndef __ASM_ARCH_OMAP_CPU_H 30#ifndef __ASM_ARCH_OMAP_CPU_H
31#define __ASM_ARCH_OMAP_CPU_H 31#define __ASM_ARCH_OMAP_CPU_H
32 32
33/*
34 * Omap device type i.e. EMU/HS/TST/GP/BAD
35 */
36#define OMAP2_DEVICE_TYPE_TEST 0
37#define OMAP2_DEVICE_TYPE_EMU 1
38#define OMAP2_DEVICE_TYPE_SEC 2
39#define OMAP2_DEVICE_TYPE_GP 3
40#define OMAP2_DEVICE_TYPE_BAD 4
41
42int omap_type(void);
43
33struct omap_chip_id { 44struct omap_chip_id {
34 u8 oc; 45 u8 oc;
35 u8 type; 46 u8 type;
@@ -424,17 +435,6 @@ IS_OMAP_TYPE(3430, 0x3430)
424 435
425 436
426int omap_chip_is(struct omap_chip_id oci); 437int omap_chip_is(struct omap_chip_id oci);
427int omap_type(void);
428
429/*
430 * Macro to detect device type i.e. EMU/HS/TST/GP/BAD
431 */
432#define OMAP2_DEVICE_TYPE_TEST 0
433#define OMAP2_DEVICE_TYPE_EMU 1
434#define OMAP2_DEVICE_TYPE_SEC 2
435#define OMAP2_DEVICE_TYPE_GP 3
436#define OMAP2_DEVICE_TYPE_BAD 4
437
438void omap2_check_revision(void); 438void omap2_check_revision(void);
439 439
440#endif /* defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) */ 440#endif /* defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) */
diff --git a/arch/arm/plat-omap/include/mach/dma.h b/arch/arm/plat-omap/include/mach/dma.h
index 8c1eae88737e..7b939cc01962 100644
--- a/arch/arm/plat-omap/include/mach/dma.h
+++ b/arch/arm/plat-omap/include/mach/dma.h
@@ -389,6 +389,21 @@
389#define DMA_THREAD_FIFO_25 (0x02 << 14) 389#define DMA_THREAD_FIFO_25 (0x02 << 14)
390#define DMA_THREAD_FIFO_50 (0x03 << 14) 390#define DMA_THREAD_FIFO_50 (0x03 << 14)
391 391
392/* DMA4_OCP_SYSCONFIG bits */
393#define DMA_SYSCONFIG_MIDLEMODE_MASK (3 << 12)
394#define DMA_SYSCONFIG_CLOCKACTIVITY_MASK (3 << 8)
395#define DMA_SYSCONFIG_EMUFREE (1 << 5)
396#define DMA_SYSCONFIG_SIDLEMODE_MASK (3 << 3)
397#define DMA_SYSCONFIG_SOFTRESET (1 << 2)
398#define DMA_SYSCONFIG_AUTOIDLE (1 << 0)
399
400#define DMA_SYSCONFIG_MIDLEMODE(n) ((n) << 12)
401#define DMA_SYSCONFIG_SIDLEMODE(n) ((n) << 3)
402
403#define DMA_IDLEMODE_SMARTIDLE 0x2
404#define DMA_IDLEMODE_NO_IDLE 0x1
405#define DMA_IDLEMODE_FORCE_IDLE 0x0
406
392/* Chaining modes*/ 407/* Chaining modes*/
393#ifndef CONFIG_ARCH_OMAP1 408#ifndef CONFIG_ARCH_OMAP1
394#define OMAP_DMA_STATIC_CHAIN 0x1 409#define OMAP_DMA_STATIC_CHAIN 0x1
diff --git a/arch/arm/plat-omap/include/mach/io.h b/arch/arm/plat-omap/include/mach/io.h
index 3b2814720569..73f483d56ca6 100644
--- a/arch/arm/plat-omap/include/mach/io.h
+++ b/arch/arm/plat-omap/include/mach/io.h
@@ -201,7 +201,7 @@
201#define OMAP2_IO_ADDRESS(pa) IOMEM(__OMAP2_IO_ADDRESS(pa)) 201#define OMAP2_IO_ADDRESS(pa) IOMEM(__OMAP2_IO_ADDRESS(pa))
202 202
203#ifdef __ASSEMBLER__ 203#ifdef __ASSEMBLER__
204#define IOMEM(x) x 204#define IOMEM(x) (x)
205#else 205#else
206#define IOMEM(x) ((void __force __iomem *)(x)) 206#define IOMEM(x) ((void __force __iomem *)(x))
207 207
diff --git a/arch/arm/plat-omap/iommu.c b/arch/arm/plat-omap/iommu.c
index 4cf449fa2cb5..4a0301399013 100644
--- a/arch/arm/plat-omap/iommu.c
+++ b/arch/arm/plat-omap/iommu.c
@@ -298,7 +298,7 @@ void flush_iotlb_page(struct iommu *obj, u32 da)
298 if ((start <= da) && (da < start + bytes)) { 298 if ((start <= da) && (da < start + bytes)) {
299 dev_dbg(obj->dev, "%s: %08x<=%08x(%x)\n", 299 dev_dbg(obj->dev, "%s: %08x<=%08x(%x)\n",
300 __func__, start, da, bytes); 300 __func__, start, da, bytes);
301 301 iotlb_load_cr(obj, &cr);
302 iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY); 302 iommu_write_reg(obj, 1, MMU_FLUSH_ENTRY);
303 } 303 }
304 } 304 }
diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
index 65006df3f1b7..4ea73804d21e 100644
--- a/arch/arm/plat-omap/sram.c
+++ b/arch/arm/plat-omap/sram.c
@@ -133,7 +133,12 @@ void __init omap_detect_sram(void)
133 if (cpu_is_omap34xx()) { 133 if (cpu_is_omap34xx()) {
134 omap_sram_base = OMAP3_SRAM_PUB_VA; 134 omap_sram_base = OMAP3_SRAM_PUB_VA;
135 omap_sram_start = OMAP3_SRAM_PUB_PA; 135 omap_sram_start = OMAP3_SRAM_PUB_PA;
136 omap_sram_size = 0x8000; /* 32K */ 136 if ((omap_type() == OMAP2_DEVICE_TYPE_EMU) ||
137 (omap_type() == OMAP2_DEVICE_TYPE_SEC)) {
138 omap_sram_size = 0x7000; /* 28K */
139 } else {
140 omap_sram_size = 0x8000; /* 32K */
141 }
137 } else { 142 } else {
138 omap_sram_base = OMAP2_SRAM_PUB_VA; 143 omap_sram_base = OMAP2_SRAM_PUB_VA;
139 omap_sram_start = OMAP2_SRAM_PUB_PA; 144 omap_sram_start = OMAP2_SRAM_PUB_PA;
diff --git a/arch/arm/plat-s3c/Makefile b/arch/arm/plat-s3c/Makefile
index 74bb7cb5da49..0761766b1833 100644
--- a/arch/arm/plat-s3c/Makefile
+++ b/arch/arm/plat-s3c/Makefile
@@ -34,7 +34,7 @@ obj-$(CONFIG_S3C_DEV_HSMMC) += dev-hsmmc.o
34obj-$(CONFIG_S3C_DEV_HSMMC1) += dev-hsmmc1.o 34obj-$(CONFIG_S3C_DEV_HSMMC1) += dev-hsmmc1.o
35obj-y += dev-i2c0.o 35obj-y += dev-i2c0.o
36obj-$(CONFIG_S3C_DEV_I2C1) += dev-i2c1.o 36obj-$(CONFIG_S3C_DEV_I2C1) += dev-i2c1.o
37obj-$(CONFIG_SND_S3C24XX_SOC) += dev-audio.o 37obj-$(CONFIG_SND_S3C64XX_SOC_I2S) += dev-audio.o
38obj-$(CONFIG_S3C_DEV_FB) += dev-fb.o 38obj-$(CONFIG_S3C_DEV_FB) += dev-fb.o
39obj-$(CONFIG_S3C_DEV_USB_HOST) += dev-usb.o 39obj-$(CONFIG_S3C_DEV_USB_HOST) += dev-usb.o
40obj-$(CONFIG_S3C_DEV_USB_HSOTG) += dev-usb-hsotg.o 40obj-$(CONFIG_S3C_DEV_USB_HSOTG) += dev-usb-hsotg.o
diff --git a/arch/arm/plat-s3c/include/plat/devs.h b/arch/arm/plat-s3c/include/plat/devs.h
index b5b9c4d46e9a..2e170827e0b0 100644
--- a/arch/arm/plat-s3c/include/plat/devs.h
+++ b/arch/arm/plat-s3c/include/plat/devs.h
@@ -37,6 +37,7 @@ extern struct platform_device s3c_device_i2c1;
37extern struct platform_device s3c_device_rtc; 37extern struct platform_device s3c_device_rtc;
38extern struct platform_device s3c_device_adc; 38extern struct platform_device s3c_device_adc;
39extern struct platform_device s3c_device_sdi; 39extern struct platform_device s3c_device_sdi;
40extern struct platform_device s3c_device_iis;
40extern struct platform_device s3c_device_hwmon; 41extern struct platform_device s3c_device_hwmon;
41extern struct platform_device s3c_device_hsmmc0; 42extern struct platform_device s3c_device_hsmmc0;
42extern struct platform_device s3c_device_hsmmc1; 43extern struct platform_device s3c_device_hsmmc1;
diff --git a/arch/arm/plat-s3c24xx/Makefile b/arch/arm/plat-s3c24xx/Makefile
index 636cb12711df..579a165c2827 100644
--- a/arch/arm/plat-s3c24xx/Makefile
+++ b/arch/arm/plat-s3c24xx/Makefile
@@ -29,7 +29,7 @@ obj-$(CONFIG_PM_SIMTEC) += pm-simtec.o
29obj-$(CONFIG_PM) += pm.o 29obj-$(CONFIG_PM) += pm.o
30obj-$(CONFIG_PM) += irq-pm.o 30obj-$(CONFIG_PM) += irq-pm.o
31obj-$(CONFIG_PM) += sleep.o 31obj-$(CONFIG_PM) += sleep.o
32obj-$(CONFIG_HAVE_PWM) += pwm.o 32obj-$(CONFIG_S3C24XX_PWM) += pwm.o
33obj-$(CONFIG_S3C2410_CLOCK) += s3c2410-clock.o 33obj-$(CONFIG_S3C2410_CLOCK) += s3c2410-clock.o
34obj-$(CONFIG_S3C2410_DMA) += dma.o 34obj-$(CONFIG_S3C2410_DMA) += dma.o
35obj-$(CONFIG_S3C24XX_ADC) += adc.o 35obj-$(CONFIG_S3C24XX_ADC) += adc.o
diff --git a/arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c b/arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c
index 9edf7894eedd..da7a61728c18 100644
--- a/arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c
+++ b/arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c
@@ -12,8 +12,7 @@
12*/ 12*/
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15 15#include <linux/gpio.h>
16#include <mach/hardware.h>
17 16
18#include <mach/spi.h> 17#include <mach/spi.h>
19#include <mach/regs-gpio.h> 18#include <mach/regs-gpio.h>
diff --git a/arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c b/arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c
index f34d0fc69ad8..86b9edc67413 100644
--- a/arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c
+++ b/arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c
@@ -12,8 +12,7 @@
12*/ 12*/
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15 15#include <linux/gpio.h>
16#include <mach/hardware.h>
17 16
18#include <mach/spi.h> 17#include <mach/spi.h>
19#include <mach/regs-gpio.h> 18#include <mach/regs-gpio.h>
diff --git a/arch/frv/Kconfig b/arch/frv/Kconfig
index 8a5bd7a9c6f5..b86e19c9b5b0 100644
--- a/arch/frv/Kconfig
+++ b/arch/frv/Kconfig
@@ -7,6 +7,7 @@ config FRV
7 default y 7 default y
8 select HAVE_IDE 8 select HAVE_IDE
9 select HAVE_ARCH_TRACEHOOK 9 select HAVE_ARCH_TRACEHOOK
10 select HAVE_PERF_COUNTERS
10 11
11config ZONE_DMA 12config ZONE_DMA
12 bool 13 bool
diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
index 0409d981fd39..00a57af79afc 100644
--- a/arch/frv/include/asm/atomic.h
+++ b/arch/frv/include/asm/atomic.h
@@ -121,10 +121,72 @@ static inline void atomic_dec(atomic_t *v)
121#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0) 121#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
122#define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0) 122#define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0)
123 123
124/*
125 * 64-bit atomic ops
126 */
127typedef struct {
128 volatile long long counter;
129} atomic64_t;
130
131#define ATOMIC64_INIT(i) { (i) }
132
133static inline long long atomic64_read(atomic64_t *v)
134{
135 long long counter;
136
137 asm("ldd%I1 %M1,%0"
138 : "=e"(counter)
139 : "m"(v->counter));
140 return counter;
141}
142
143static inline void atomic64_set(atomic64_t *v, long long i)
144{
145 asm volatile("std%I0 %1,%M0"
146 : "=m"(v->counter)
147 : "e"(i));
148}
149
150extern long long atomic64_inc_return(atomic64_t *v);
151extern long long atomic64_dec_return(atomic64_t *v);
152extern long long atomic64_add_return(long long i, atomic64_t *v);
153extern long long atomic64_sub_return(long long i, atomic64_t *v);
154
155static inline long long atomic64_add_negative(long long i, atomic64_t *v)
156{
157 return atomic64_add_return(i, v) < 0;
158}
159
160static inline void atomic64_add(long long i, atomic64_t *v)
161{
162 atomic64_add_return(i, v);
163}
164
165static inline void atomic64_sub(long long i, atomic64_t *v)
166{
167 atomic64_sub_return(i, v);
168}
169
170static inline void atomic64_inc(atomic64_t *v)
171{
172 atomic64_inc_return(v);
173}
174
175static inline void atomic64_dec(atomic64_t *v)
176{
177 atomic64_dec_return(v);
178}
179
180#define atomic64_sub_and_test(i,v) (atomic64_sub_return((i), (v)) == 0)
181#define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
182#define atomic64_inc_and_test(v) (atomic64_inc_return((v)) == 0)
183
124/*****************************************************************************/ 184/*****************************************************************************/
125/* 185/*
126 * exchange value with memory 186 * exchange value with memory
127 */ 187 */
188extern uint64_t __xchg_64(uint64_t i, volatile void *v);
189
128#ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS 190#ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS
129 191
130#define xchg(ptr, x) \ 192#define xchg(ptr, x) \
@@ -174,8 +236,10 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
174 236
175#define tas(ptr) (xchg((ptr), 1)) 237#define tas(ptr) (xchg((ptr), 1))
176 238
177#define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new)) 239#define atomic_cmpxchg(v, old, new) (cmpxchg(&(v)->counter, old, new))
178#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) 240#define atomic_xchg(v, new) (xchg(&(v)->counter, new))
241#define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
242#define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
179 243
180static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) 244static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
181{ 245{
diff --git a/arch/frv/include/asm/perf_counter.h b/arch/frv/include/asm/perf_counter.h
new file mode 100644
index 000000000000..ccf726e61b2e
--- /dev/null
+++ b/arch/frv/include/asm/perf_counter.h
@@ -0,0 +1,17 @@
1/* FRV performance counter support
2 *
3 * Copyright (C) 2009 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11
12#ifndef _ASM_PERF_COUNTER_H
13#define _ASM_PERF_COUNTER_H
14
15#define PERF_COUNTER_INDEX_OFFSET 0
16
17#endif /* _ASM_PERF_COUNTER_H */
diff --git a/arch/frv/include/asm/system.h b/arch/frv/include/asm/system.h
index 7742ec000cc4..efd22d9077ac 100644
--- a/arch/frv/include/asm/system.h
+++ b/arch/frv/include/asm/system.h
@@ -208,6 +208,8 @@ extern void free_initmem(void);
208 * - if (*ptr == test) then orig = *ptr; *ptr = test; 208 * - if (*ptr == test) then orig = *ptr; *ptr = test;
209 * - if (*ptr != test) then orig = *ptr; 209 * - if (*ptr != test) then orig = *ptr;
210 */ 210 */
211extern uint64_t __cmpxchg_64(uint64_t test, uint64_t new, volatile uint64_t *v);
212
211#ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS 213#ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS
212 214
213#define cmpxchg(ptr, test, new) \ 215#define cmpxchg(ptr, test, new) \
diff --git a/arch/frv/include/asm/unistd.h b/arch/frv/include/asm/unistd.h
index 96d78d5d2c41..4a8fb427ce0a 100644
--- a/arch/frv/include/asm/unistd.h
+++ b/arch/frv/include/asm/unistd.h
@@ -341,10 +341,12 @@
341#define __NR_inotify_init1 332 341#define __NR_inotify_init1 332
342#define __NR_preadv 333 342#define __NR_preadv 333
343#define __NR_pwritev 334 343#define __NR_pwritev 334
344#define __NR_rt_tgsigqueueinfo 335
345#define __NR_perf_counter_open 336
344 346
345#ifdef __KERNEL__ 347#ifdef __KERNEL__
346 348
347#define NR_syscalls 335 349#define NR_syscalls 337
348 350
349#define __ARCH_WANT_IPC_PARSE_VERSION 351#define __ARCH_WANT_IPC_PARSE_VERSION
350/* #define __ARCH_WANT_OLD_READDIR */ 352/* #define __ARCH_WANT_OLD_READDIR */
diff --git a/arch/frv/kernel/entry.S b/arch/frv/kernel/entry.S
index 356e0e327a89..fde1e446b440 100644
--- a/arch/frv/kernel/entry.S
+++ b/arch/frv/kernel/entry.S
@@ -1524,5 +1524,7 @@ sys_call_table:
1524 .long sys_inotify_init1 1524 .long sys_inotify_init1
1525 .long sys_preadv 1525 .long sys_preadv
1526 .long sys_pwritev 1526 .long sys_pwritev
1527 .long sys_rt_tgsigqueueinfo /* 335 */
1528 .long sys_perf_counter_open
1527 1529
1528syscall_table_size = (. - sys_call_table) 1530syscall_table_size = (. - sys_call_table)
diff --git a/arch/frv/kernel/frv_ksyms.c b/arch/frv/kernel/frv_ksyms.c
index 0316b3c50eff..a89803b58b9a 100644
--- a/arch/frv/kernel/frv_ksyms.c
+++ b/arch/frv/kernel/frv_ksyms.c
@@ -67,6 +67,10 @@ EXPORT_SYMBOL(atomic_sub_return);
67EXPORT_SYMBOL(__xchg_32); 67EXPORT_SYMBOL(__xchg_32);
68EXPORT_SYMBOL(__cmpxchg_32); 68EXPORT_SYMBOL(__cmpxchg_32);
69#endif 69#endif
70EXPORT_SYMBOL(atomic64_add_return);
71EXPORT_SYMBOL(atomic64_sub_return);
72EXPORT_SYMBOL(__xchg_64);
73EXPORT_SYMBOL(__cmpxchg_64);
70 74
71EXPORT_SYMBOL(__debug_bug_printk); 75EXPORT_SYMBOL(__debug_bug_printk);
72EXPORT_SYMBOL(__delay_loops_MHz); 76EXPORT_SYMBOL(__delay_loops_MHz);
diff --git a/arch/frv/lib/Makefile b/arch/frv/lib/Makefile
index 08be305c9f44..0a377210c89b 100644
--- a/arch/frv/lib/Makefile
+++ b/arch/frv/lib/Makefile
@@ -4,5 +4,5 @@
4 4
5lib-y := \ 5lib-y := \
6 __ashldi3.o __lshrdi3.o __muldi3.o __ashrdi3.o __negdi2.o __ucmpdi2.o \ 6 __ashldi3.o __lshrdi3.o __muldi3.o __ashrdi3.o __negdi2.o __ucmpdi2.o \
7 checksum.o memcpy.o memset.o atomic-ops.o \ 7 checksum.o memcpy.o memset.o atomic-ops.o atomic64-ops.o \
8 outsl_ns.o outsl_sw.o insl_ns.o insl_sw.o cache.o 8 outsl_ns.o outsl_sw.o insl_ns.o insl_sw.o cache.o perf_counter.o
diff --git a/arch/frv/lib/atomic-ops.S b/arch/frv/lib/atomic-ops.S
index ee0ac905fb08..5e9e6ab5dd0e 100644
--- a/arch/frv/lib/atomic-ops.S
+++ b/arch/frv/lib/atomic-ops.S
@@ -163,11 +163,10 @@ __cmpxchg_32:
163 ld.p @(gr11,gr0),gr8 163 ld.p @(gr11,gr0),gr8
164 orcr cc7,cc7,cc3 164 orcr cc7,cc7,cc3
165 subcc gr8,gr9,gr7,icc0 165 subcc gr8,gr9,gr7,icc0
166 bne icc0,#0,1f 166 bnelr icc0,#0
167 cst.p gr10,@(gr11,gr0) ,cc3,#1 167 cst.p gr10,@(gr11,gr0) ,cc3,#1
168 corcc gr29,gr29,gr0 ,cc3,#1 168 corcc gr29,gr29,gr0 ,cc3,#1
169 beq icc3,#0,0b 169 beq icc3,#0,0b
1701:
171 bralr 170 bralr
172 171
173 .size __cmpxchg_32, .-__cmpxchg_32 172 .size __cmpxchg_32, .-__cmpxchg_32
diff --git a/arch/frv/lib/atomic64-ops.S b/arch/frv/lib/atomic64-ops.S
new file mode 100644
index 000000000000..b6194eeac127
--- /dev/null
+++ b/arch/frv/lib/atomic64-ops.S
@@ -0,0 +1,162 @@
1/* kernel atomic64 operations
2 *
3 * For an explanation of how atomic ops work in this arch, see:
4 * Documentation/frv/atomic-ops.txt
5 *
6 * Copyright (C) 2009 Red Hat, Inc. All Rights Reserved.
7 * Written by David Howells (dhowells@redhat.com)
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 */
14
15#include <asm/spr-regs.h>
16
17 .text
18 .balign 4
19
20
21###############################################################################
22#
23# long long atomic64_inc_return(atomic64_t *v)
24#
25###############################################################################
26 .globl atomic64_inc_return
27 .type atomic64_inc_return,@function
28atomic64_inc_return:
29 or.p gr8,gr8,gr10
300:
31 orcc gr0,gr0,gr0,icc3 /* set ICC3.Z */
32 ckeq icc3,cc7
33 ldd.p @(gr10,gr0),gr8 /* LDD.P/ORCR must be atomic */
34 orcr cc7,cc7,cc3 /* set CC3 to true */
35 addicc gr9,#1,gr9,icc0
36 addxi gr8,#0,gr8,icc0
37 cstd.p gr8,@(gr10,gr0) ,cc3,#1
38 corcc gr29,gr29,gr0 ,cc3,#1 /* clear ICC3.Z if store happens */
39 beq icc3,#0,0b
40 bralr
41
42 .size atomic64_inc_return, .-atomic64_inc_return
43
44###############################################################################
45#
46# long long atomic64_dec_return(atomic64_t *v)
47#
48###############################################################################
49 .globl atomic64_dec_return
50 .type atomic64_dec_return,@function
51atomic64_dec_return:
52 or.p gr8,gr8,gr10
530:
54 orcc gr0,gr0,gr0,icc3 /* set ICC3.Z */
55 ckeq icc3,cc7
56 ldd.p @(gr10,gr0),gr8 /* LDD.P/ORCR must be atomic */
57 orcr cc7,cc7,cc3 /* set CC3 to true */
58 subicc gr9,#1,gr9,icc0
59 subxi gr8,#0,gr8,icc0
60 cstd.p gr8,@(gr10,gr0) ,cc3,#1
61 corcc gr29,gr29,gr0 ,cc3,#1 /* clear ICC3.Z if store happens */
62 beq icc3,#0,0b
63 bralr
64
65 .size atomic64_dec_return, .-atomic64_dec_return
66
67###############################################################################
68#
69# long long atomic64_add_return(long long i, atomic64_t *v)
70#
71###############################################################################
72 .globl atomic64_add_return
73 .type atomic64_add_return,@function
74atomic64_add_return:
75 or.p gr8,gr8,gr4
76 or gr9,gr9,gr5
770:
78 orcc gr0,gr0,gr0,icc3 /* set ICC3.Z */
79 ckeq icc3,cc7
80 ldd.p @(gr10,gr0),gr8 /* LDD.P/ORCR must be atomic */
81 orcr cc7,cc7,cc3 /* set CC3 to true */
82 addcc gr9,gr5,gr9,icc0
83 addx gr8,gr4,gr8,icc0
84 cstd.p gr8,@(gr10,gr0) ,cc3,#1
85 corcc gr29,gr29,gr0 ,cc3,#1 /* clear ICC3.Z if store happens */
86 beq icc3,#0,0b
87 bralr
88
89 .size atomic64_add_return, .-atomic64_add_return
90
91###############################################################################
92#
93# long long atomic64_sub_return(long long i, atomic64_t *v)
94#
95###############################################################################
96 .globl atomic64_sub_return
97 .type atomic64_sub_return,@function
98atomic64_sub_return:
99 or.p gr8,gr8,gr4
100 or gr9,gr9,gr5
1010:
102 orcc gr0,gr0,gr0,icc3 /* set ICC3.Z */
103 ckeq icc3,cc7
104 ldd.p @(gr10,gr0),gr8 /* LDD.P/ORCR must be atomic */
105 orcr cc7,cc7,cc3 /* set CC3 to true */
106 subcc gr9,gr5,gr9,icc0
107 subx gr8,gr4,gr8,icc0
108 cstd.p gr8,@(gr10,gr0) ,cc3,#1
109 corcc gr29,gr29,gr0 ,cc3,#1 /* clear ICC3.Z if store happens */
110 beq icc3,#0,0b
111 bralr
112
113 .size atomic64_sub_return, .-atomic64_sub_return
114
115###############################################################################
116#
117# uint64_t __xchg_64(uint64_t i, uint64_t *v)
118#
119###############################################################################
120 .globl __xchg_64
121 .type __xchg_64,@function
122__xchg_64:
123 or.p gr8,gr8,gr4
124 or gr9,gr9,gr5
1250:
126 orcc gr0,gr0,gr0,icc3 /* set ICC3.Z */
127 ckeq icc3,cc7
128 ldd.p @(gr10,gr0),gr8 /* LDD.P/ORCR must be atomic */
129 orcr cc7,cc7,cc3 /* set CC3 to true */
130 cstd.p gr4,@(gr10,gr0) ,cc3,#1
131 corcc gr29,gr29,gr0 ,cc3,#1 /* clear ICC3.Z if store happens */
132 beq icc3,#0,0b
133 bralr
134
135 .size __xchg_64, .-__xchg_64
136
137###############################################################################
138#
139# uint64_t __cmpxchg_64(uint64_t test, uint64_t new, uint64_t *v)
140#
141###############################################################################
142 .globl __cmpxchg_64
143 .type __cmpxchg_64,@function
144__cmpxchg_64:
145 or.p gr8,gr8,gr4
146 or gr9,gr9,gr5
1470:
148 orcc gr0,gr0,gr0,icc3 /* set ICC3.Z */
149 ckeq icc3,cc7
150 ldd.p @(gr12,gr0),gr8 /* LDD.P/ORCR must be atomic */
151 orcr cc7,cc7,cc3
152 subcc gr8,gr4,gr0,icc0
153 subcc.p gr9,gr5,gr0,icc1
154 bnelr icc0,#0
155 bnelr icc1,#0
156 cstd.p gr10,@(gr12,gr0) ,cc3,#1
157 corcc gr29,gr29,gr0 ,cc3,#1 /* clear ICC3.Z if store happens */
158 beq icc3,#0,0b
159 bralr
160
161 .size __cmpxchg_64, .-__cmpxchg_64
162
diff --git a/arch/frv/lib/perf_counter.c b/arch/frv/lib/perf_counter.c
new file mode 100644
index 000000000000..2000feecd571
--- /dev/null
+++ b/arch/frv/lib/perf_counter.c
@@ -0,0 +1,19 @@
1/* Performance counter handling
2 *
3 * Copyright (C) 2009 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11
12#include <linux/perf_counter.h>
13
14/*
15 * mark the performance counter as pending
16 */
17void set_perf_counter_pending(void)
18{
19}
diff --git a/arch/ia64/hp/sim/simeth.c b/arch/ia64/hp/sim/simeth.c
index e4d8fde68103..7e81966ce481 100644
--- a/arch/ia64/hp/sim/simeth.c
+++ b/arch/ia64/hp/sim/simeth.c
@@ -412,7 +412,7 @@ simeth_tx(struct sk_buff *skb, struct net_device *dev)
412 */ 412 */
413 413
414 dev_kfree_skb(skb); 414 dev_kfree_skb(skb);
415 return 0; 415 return NETDEV_TX_OK;
416} 416}
417 417
418static inline struct sk_buff * 418static inline struct sk_buff *
diff --git a/arch/ia64/kernel/esi.c b/arch/ia64/kernel/esi.c
index ebf4e988e78c..d5764a3d74af 100644
--- a/arch/ia64/kernel/esi.c
+++ b/arch/ia64/kernel/esi.c
@@ -65,7 +65,7 @@ static int __init esi_init (void)
65 } 65 }
66 66
67 if (!esi) 67 if (!esi)
68 return -ENODEV;; 68 return -ENODEV;
69 69
70 systab = __va(esi); 70 systab = __va(esi);
71 71
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index abce2468a40b..f1782705b1f7 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -5603,7 +5603,7 @@ pfm_interrupt_handler(int irq, void *arg)
5603 * /proc/perfmon interface, for debug only 5603 * /proc/perfmon interface, for debug only
5604 */ 5604 */
5605 5605
5606#define PFM_PROC_SHOW_HEADER ((void *)nr_cpu_ids+1) 5606#define PFM_PROC_SHOW_HEADER ((void *)(long)nr_cpu_ids+1)
5607 5607
5608static void * 5608static void *
5609pfm_proc_start(struct seq_file *m, loff_t *pos) 5609pfm_proc_start(struct seq_file *m, loff_t *pos)
diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
index 7053c55b7649..e6676fca4828 100644
--- a/arch/ia64/kernel/salinfo.c
+++ b/arch/ia64/kernel/salinfo.c
@@ -192,7 +192,7 @@ struct salinfo_platform_oemdata_parms {
192static void 192static void
193salinfo_work_to_do(struct salinfo_data *data) 193salinfo_work_to_do(struct salinfo_data *data)
194{ 194{
195 down_trylock(&data->mutex); 195 (void)(down_trylock(&data->mutex) ?: 0);
196 up(&data->mutex); 196 up(&data->mutex);
197} 197}
198 198
diff --git a/arch/ia64/kvm/kvm_lib.c b/arch/ia64/kvm/kvm_lib.c
index a85cb611ecd7..f1268b8e6f9e 100644
--- a/arch/ia64/kvm/kvm_lib.c
+++ b/arch/ia64/kvm/kvm_lib.c
@@ -11,5 +11,11 @@
11 * 11 *
12 */ 12 */
13#undef CONFIG_MODULES 13#undef CONFIG_MODULES
14#include <linux/module.h>
15#undef CONFIG_KALLSYMS
16#undef EXPORT_SYMBOL
17#undef EXPORT_SYMBOL_GPL
18#define EXPORT_SYMBOL(sym)
19#define EXPORT_SYMBOL_GPL(sym)
14#include "../../../lib/vsprintf.c" 20#include "../../../lib/vsprintf.c"
15#include "../../../lib/ctype.c" 21#include "../../../lib/ctype.c"
diff --git a/arch/ia64/kvm/process.c b/arch/ia64/kvm/process.c
index a8f84da04b49..bb862fb224f2 100644
--- a/arch/ia64/kvm/process.c
+++ b/arch/ia64/kvm/process.c
@@ -130,7 +130,7 @@ static void collect_interruption(struct kvm_vcpu *vcpu)
130 if (vdcr & IA64_DCR_PP) { 130 if (vdcr & IA64_DCR_PP) {
131 vpsr |= IA64_PSR_PP; 131 vpsr |= IA64_PSR_PP;
132 } else { 132 } else {
133 vpsr &= ~IA64_PSR_PP;; 133 vpsr &= ~IA64_PSR_PP;
134 } 134 }
135 135
136 vcpu_set_psr(vcpu, vpsr); 136 vcpu_set_psr(vcpu, vpsr);
@@ -594,11 +594,11 @@ static void set_pal_call_data(struct kvm_vcpu *vcpu)
594 p->u.pal_data.gr30 = vcpu_get_gr(vcpu, 30); 594 p->u.pal_data.gr30 = vcpu_get_gr(vcpu, 30);
595 break; 595 break;
596 case PAL_BRAND_INFO: 596 case PAL_BRAND_INFO:
597 p->u.pal_data.gr29 = gr29;; 597 p->u.pal_data.gr29 = gr29;
598 p->u.pal_data.gr30 = kvm_trans_pal_call_args(vcpu, gr30); 598 p->u.pal_data.gr30 = kvm_trans_pal_call_args(vcpu, gr30);
599 break; 599 break;
600 default: 600 default:
601 p->u.pal_data.gr29 = gr29;; 601 p->u.pal_data.gr29 = gr29;
602 p->u.pal_data.gr30 = vcpu_get_gr(vcpu, 30); 602 p->u.pal_data.gr30 = vcpu_get_gr(vcpu, 30);
603 } 603 }
604 p->u.pal_data.gr28 = gr28; 604 p->u.pal_data.gr28 = gr28;
diff --git a/arch/ia64/kvm/vcpu.c b/arch/ia64/kvm/vcpu.c
index a2c6c15e4761..46b02cbcc874 100644
--- a/arch/ia64/kvm/vcpu.c
+++ b/arch/ia64/kvm/vcpu.c
@@ -406,7 +406,7 @@ void getreg(unsigned long regnum, unsigned long *val,
406 * Now look at registers in [0-31] range and init correct UNAT 406 * Now look at registers in [0-31] range and init correct UNAT
407 */ 407 */
408 addr = (unsigned long)regs; 408 addr = (unsigned long)regs;
409 unat = &regs->eml_unat;; 409 unat = &regs->eml_unat;
410 410
411 addr += gr_info[regnum]; 411 addr += gr_info[regnum];
412 412
diff --git a/arch/ia64/kvm/vtlb.c b/arch/ia64/kvm/vtlb.c
index 4290a429bf7c..20b3852f7a6e 100644
--- a/arch/ia64/kvm/vtlb.c
+++ b/arch/ia64/kvm/vtlb.c
@@ -135,7 +135,7 @@ struct thash_data *__vtr_lookup(struct kvm_vcpu *vcpu, u64 va, int type)
135 u64 rid; 135 u64 rid;
136 136
137 rid = vcpu_get_rr(vcpu, va); 137 rid = vcpu_get_rr(vcpu, va);
138 rid = rid & RR_RID_MASK;; 138 rid = rid & RR_RID_MASK;
139 if (type == D_TLB) { 139 if (type == D_TLB) {
140 if (vcpu_quick_region_check(vcpu->arch.dtr_regions, va)) { 140 if (vcpu_quick_region_check(vcpu->arch.dtr_regions, va)) {
141 for (trp = (struct thash_data *)&vcpu->arch.dtrs, i = 0; 141 for (trp = (struct thash_data *)&vcpu->arch.dtrs, i = 0;
@@ -518,7 +518,7 @@ struct thash_data *vtlb_lookup(struct kvm_vcpu *v, u64 va, int is_data)
518 518
519 struct thash_cb *hcb = &v->arch.vtlb; 519 struct thash_cb *hcb = &v->arch.vtlb;
520 520
521 cch = __vtr_lookup(v, va, is_data);; 521 cch = __vtr_lookup(v, va, is_data);
522 if (cch) 522 if (cch)
523 return cch; 523 return cch;
524 524
diff --git a/arch/ia64/sn/kernel/io_common.c b/arch/ia64/sn/kernel/io_common.c
index 76645cf6ac5d..25831c47c579 100644
--- a/arch/ia64/sn/kernel/io_common.c
+++ b/arch/ia64/sn/kernel/io_common.c
@@ -435,7 +435,8 @@ void sn_generate_path(struct pci_bus *pci_bus, char *address)
435 bricktype = MODULE_GET_BTYPE(moduleid); 435 bricktype = MODULE_GET_BTYPE(moduleid);
436 if ((bricktype == L1_BRICKTYPE_191010) || 436 if ((bricktype == L1_BRICKTYPE_191010) ||
437 (bricktype == L1_BRICKTYPE_1932)) 437 (bricktype == L1_BRICKTYPE_1932))
438 sprintf(address, "%s^%d", address, geo_slot(geoid)); 438 sprintf(address + strlen(address), "^%d",
439 geo_slot(geoid));
439} 440}
440 441
441void __devinit 442void __devinit
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 8c4be1f301cf..3ca0fe1a9123 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -22,6 +22,26 @@ choice
22config MACH_ALCHEMY 22config MACH_ALCHEMY
23 bool "Alchemy processor based machines" 23 bool "Alchemy processor based machines"
24 24
25config AR7
26 bool "Texas Instruments AR7"
27 select BOOT_ELF32
28 select DMA_NONCOHERENT
29 select CEVT_R4K
30 select CSRC_R4K
31 select IRQ_CPU
32 select NO_EXCEPT_FILL
33 select SWAP_IO_SPACE
34 select SYS_HAS_CPU_MIPS32_R1
35 select SYS_HAS_EARLY_PRINTK
36 select SYS_SUPPORTS_32BIT_KERNEL
37 select SYS_SUPPORTS_LITTLE_ENDIAN
38 select GENERIC_GPIO
39 select GCD
40 select VLYNQ
41 help
42 Support for the Texas Instruments AR7 System-on-a-Chip
43 family: TNETD7100, 7200 and 7300.
44
25config BASLER_EXCITE 45config BASLER_EXCITE
26 bool "Basler eXcite smart camera" 46 bool "Basler eXcite smart camera"
27 select CEVT_R4K 47 select CEVT_R4K
@@ -209,7 +229,7 @@ config MIPS_MALTA
209 select SYS_SUPPORTS_64BIT_KERNEL 229 select SYS_SUPPORTS_64BIT_KERNEL
210 select SYS_SUPPORTS_BIG_ENDIAN 230 select SYS_SUPPORTS_BIG_ENDIAN
211 select SYS_SUPPORTS_LITTLE_ENDIAN 231 select SYS_SUPPORTS_LITTLE_ENDIAN
212 select SYS_SUPPORTS_MIPS_CMP if BROKEN # because SYNC_R4K is broken 232 select SYS_SUPPORTS_MIPS_CMP
213 select SYS_SUPPORTS_MULTITHREADING 233 select SYS_SUPPORTS_MULTITHREADING
214 select SYS_SUPPORTS_SMARTMIPS 234 select SYS_SUPPORTS_SMARTMIPS
215 help 235 help
@@ -247,6 +267,7 @@ config MACH_VR41XX
247 select CEVT_R4K 267 select CEVT_R4K
248 select CSRC_R4K 268 select CSRC_R4K
249 select SYS_HAS_CPU_VR41XX 269 select SYS_HAS_CPU_VR41XX
270 select ARCH_REQUIRE_GPIOLIB
250 271
251config NXP_STB220 272config NXP_STB220
252 bool "NXP STB220 board" 273 bool "NXP STB220 board"
@@ -1635,7 +1656,7 @@ config MIPS_APSP_KSPD
1635config MIPS_CMP 1656config MIPS_CMP
1636 bool "MIPS CMP framework support" 1657 bool "MIPS CMP framework support"
1637 depends on SYS_SUPPORTS_MIPS_CMP 1658 depends on SYS_SUPPORTS_MIPS_CMP
1638 select SYNC_R4K if BROKEN 1659 select SYNC_R4K
1639 select SYS_SUPPORTS_SMP 1660 select SYS_SUPPORTS_SMP
1640 select SYS_SUPPORTS_SCHED_SMT if SMP 1661 select SYS_SUPPORTS_SCHED_SMT if SMP
1641 select WEAK_ORDERING 1662 select WEAK_ORDERING
@@ -2147,11 +2168,11 @@ menu "Power management options"
2147 2168
2148config ARCH_HIBERNATION_POSSIBLE 2169config ARCH_HIBERNATION_POSSIBLE
2149 def_bool y 2170 def_bool y
2150 depends on SYS_SUPPORTS_HOTPLUG_CPU 2171 depends on SYS_SUPPORTS_HOTPLUG_CPU || !SMP
2151 2172
2152config ARCH_SUSPEND_POSSIBLE 2173config ARCH_SUSPEND_POSSIBLE
2153 def_bool y 2174 def_bool y
2154 depends on SYS_SUPPORTS_HOTPLUG_CPU 2175 depends on SYS_SUPPORTS_HOTPLUG_CPU || !SMP
2155 2176
2156source "kernel/power/Kconfig" 2177source "kernel/power/Kconfig"
2157 2178
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 807572a6a4d2..861da514a468 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -173,6 +173,13 @@ libs-y += arch/mips/fw/lib/
173# 173#
174 174
175# 175#
176# Texas Instruments AR7
177#
178core-$(CONFIG_AR7) += arch/mips/ar7/
179cflags-$(CONFIG_AR7) += -I$(srctree)/arch/mips/include/asm/mach-ar7
180load-$(CONFIG_AR7) += 0xffffffff94100000
181
182#
176# Acer PICA 61, Mips Magnum 4000 and Olivetti M700. 183# Acer PICA 61, Mips Magnum 4000 and Olivetti M700.
177# 184#
178core-$(CONFIG_MACH_JAZZ) += arch/mips/jazz/ 185core-$(CONFIG_MACH_JAZZ) += arch/mips/jazz/
diff --git a/arch/mips/ar7/Makefile b/arch/mips/ar7/Makefile
new file mode 100644
index 000000000000..7435e44b3964
--- /dev/null
+++ b/arch/mips/ar7/Makefile
@@ -0,0 +1,10 @@
1
2obj-y := \
3 prom.o \
4 setup.o \
5 memory.o \
6 irq.o \
7 time.o \
8 platform.o \
9 gpio.o \
10 clock.o
diff --git a/arch/mips/ar7/clock.c b/arch/mips/ar7/clock.c
new file mode 100644
index 000000000000..27dc6663f2fa
--- /dev/null
+++ b/arch/mips/ar7/clock.c
@@ -0,0 +1,440 @@
1/*
2 * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org>
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 as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/types.h>
23#include <linux/module.h>
24#include <linux/delay.h>
25#include <linux/gcd.h>
26#include <linux/io.h>
27
28#include <asm/addrspace.h>
29#include <asm/mach-ar7/ar7.h>
30
31#define BOOT_PLL_SOURCE_MASK 0x3
32#define CPU_PLL_SOURCE_SHIFT 16
33#define BUS_PLL_SOURCE_SHIFT 14
34#define USB_PLL_SOURCE_SHIFT 18
35#define DSP_PLL_SOURCE_SHIFT 22
36#define BOOT_PLL_SOURCE_AFE 0
37#define BOOT_PLL_SOURCE_BUS 0
38#define BOOT_PLL_SOURCE_REF 1
39#define BOOT_PLL_SOURCE_XTAL 2
40#define BOOT_PLL_SOURCE_CPU 3
41#define BOOT_PLL_BYPASS 0x00000020
42#define BOOT_PLL_ASYNC_MODE 0x02000000
43#define BOOT_PLL_2TO1_MODE 0x00008000
44
45#define TNETD7200_CLOCK_ID_CPU 0
46#define TNETD7200_CLOCK_ID_DSP 1
47#define TNETD7200_CLOCK_ID_USB 2
48
49#define TNETD7200_DEF_CPU_CLK 211000000
50#define TNETD7200_DEF_DSP_CLK 125000000
51#define TNETD7200_DEF_USB_CLK 48000000
52
53struct tnetd7300_clock {
54 u32 ctrl;
55#define PREDIV_MASK 0x001f0000
56#define PREDIV_SHIFT 16
57#define POSTDIV_MASK 0x0000001f
58 u32 unused1[3];
59 u32 pll;
60#define MUL_MASK 0x0000f000
61#define MUL_SHIFT 12
62#define PLL_MODE_MASK 0x00000001
63#define PLL_NDIV 0x00000800
64#define PLL_DIV 0x00000002
65#define PLL_STATUS 0x00000001
66 u32 unused2[3];
67};
68
69struct tnetd7300_clocks {
70 struct tnetd7300_clock bus;
71 struct tnetd7300_clock cpu;
72 struct tnetd7300_clock usb;
73 struct tnetd7300_clock dsp;
74};
75
76struct tnetd7200_clock {
77 u32 ctrl;
78 u32 unused1[3];
79#define DIVISOR_ENABLE_MASK 0x00008000
80 u32 mul;
81 u32 prediv;
82 u32 postdiv;
83 u32 postdiv2;
84 u32 unused2[6];
85 u32 cmd;
86 u32 status;
87 u32 cmden;
88 u32 padding[15];
89};
90
91struct tnetd7200_clocks {
92 struct tnetd7200_clock cpu;
93 struct tnetd7200_clock dsp;
94 struct tnetd7200_clock usb;
95};
96
97int ar7_cpu_clock = 150000000;
98EXPORT_SYMBOL(ar7_cpu_clock);
99int ar7_bus_clock = 125000000;
100EXPORT_SYMBOL(ar7_bus_clock);
101int ar7_dsp_clock;
102EXPORT_SYMBOL(ar7_dsp_clock);
103
104static void approximate(int base, int target, int *prediv,
105 int *postdiv, int *mul)
106{
107 int i, j, k, freq, res = target;
108 for (i = 1; i <= 16; i++)
109 for (j = 1; j <= 32; j++)
110 for (k = 1; k <= 32; k++) {
111 freq = abs(base / j * i / k - target);
112 if (freq < res) {
113 res = freq;
114 *mul = i;
115 *prediv = j;
116 *postdiv = k;
117 }
118 }
119}
120
121static void calculate(int base, int target, int *prediv, int *postdiv,
122 int *mul)
123{
124 int tmp_gcd, tmp_base, tmp_freq;
125
126 for (*prediv = 1; *prediv <= 32; (*prediv)++) {
127 tmp_base = base / *prediv;
128 tmp_gcd = gcd(target, tmp_base);
129 *mul = target / tmp_gcd;
130 *postdiv = tmp_base / tmp_gcd;
131 if ((*mul < 1) || (*mul >= 16))
132 continue;
133 if ((*postdiv > 0) & (*postdiv <= 32))
134 break;
135 }
136
137 if (base / *prediv * *mul / *postdiv != target) {
138 approximate(base, target, prediv, postdiv, mul);
139 tmp_freq = base / *prediv * *mul / *postdiv;
140 printk(KERN_WARNING
141 "Adjusted requested frequency %d to %d\n",
142 target, tmp_freq);
143 }
144
145 printk(KERN_DEBUG "Clocks: prediv: %d, postdiv: %d, mul: %d\n",
146 *prediv, *postdiv, *mul);
147}
148
149static int tnetd7300_dsp_clock(void)
150{
151 u32 didr1, didr2;
152 u8 rev = ar7_chip_rev();
153 didr1 = readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x18));
154 didr2 = readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x1c));
155 if (didr2 & (1 << 23))
156 return 0;
157 if ((rev >= 0x23) && (rev != 0x57))
158 return 250000000;
159 if ((((didr2 & 0x1fff) << 10) | ((didr1 & 0xffc00000) >> 22))
160 > 4208000)
161 return 250000000;
162 return 0;
163}
164
165static int tnetd7300_get_clock(u32 shift, struct tnetd7300_clock *clock,
166 u32 *bootcr, u32 bus_clock)
167{
168 int product;
169 int base_clock = AR7_REF_CLOCK;
170 u32 ctrl = readl(&clock->ctrl);
171 u32 pll = readl(&clock->pll);
172 int prediv = ((ctrl & PREDIV_MASK) >> PREDIV_SHIFT) + 1;
173 int postdiv = (ctrl & POSTDIV_MASK) + 1;
174 int divisor = prediv * postdiv;
175 int mul = ((pll & MUL_MASK) >> MUL_SHIFT) + 1;
176
177 switch ((*bootcr & (BOOT_PLL_SOURCE_MASK << shift)) >> shift) {
178 case BOOT_PLL_SOURCE_BUS:
179 base_clock = bus_clock;
180 break;
181 case BOOT_PLL_SOURCE_REF:
182 base_clock = AR7_REF_CLOCK;
183 break;
184 case BOOT_PLL_SOURCE_XTAL:
185 base_clock = AR7_XTAL_CLOCK;
186 break;
187 case BOOT_PLL_SOURCE_CPU:
188 base_clock = ar7_cpu_clock;
189 break;
190 }
191
192 if (*bootcr & BOOT_PLL_BYPASS)
193 return base_clock / divisor;
194
195 if ((pll & PLL_MODE_MASK) == 0)
196 return (base_clock >> (mul / 16 + 1)) / divisor;
197
198 if ((pll & (PLL_NDIV | PLL_DIV)) == (PLL_NDIV | PLL_DIV)) {
199 product = (mul & 1) ?
200 (base_clock * mul) >> 1 :
201 (base_clock * (mul - 1)) >> 2;
202 return product / divisor;
203 }
204
205 if (mul == 16)
206 return base_clock / divisor;
207
208 return base_clock * mul / divisor;
209}
210
211static void tnetd7300_set_clock(u32 shift, struct tnetd7300_clock *clock,
212 u32 *bootcr, u32 frequency)
213{
214 int prediv, postdiv, mul;
215 int base_clock = ar7_bus_clock;
216
217 switch ((*bootcr & (BOOT_PLL_SOURCE_MASK << shift)) >> shift) {
218 case BOOT_PLL_SOURCE_BUS:
219 base_clock = ar7_bus_clock;
220 break;
221 case BOOT_PLL_SOURCE_REF:
222 base_clock = AR7_REF_CLOCK;
223 break;
224 case BOOT_PLL_SOURCE_XTAL:
225 base_clock = AR7_XTAL_CLOCK;
226 break;
227 case BOOT_PLL_SOURCE_CPU:
228 base_clock = ar7_cpu_clock;
229 break;
230 }
231
232 calculate(base_clock, frequency, &prediv, &postdiv, &mul);
233
234 writel(((prediv - 1) << PREDIV_SHIFT) | (postdiv - 1), &clock->ctrl);
235 msleep(1);
236 writel(4, &clock->pll);
237 while (readl(&clock->pll) & PLL_STATUS)
238 ;
239 writel(((mul - 1) << MUL_SHIFT) | (0xff << 3) | 0x0e, &clock->pll);
240 msleep(75);
241}
242
243static void __init tnetd7300_init_clocks(void)
244{
245 u32 *bootcr = (u32 *)ioremap_nocache(AR7_REGS_DCL, 4);
246 struct tnetd7300_clocks *clocks =
247 ioremap_nocache(UR8_REGS_CLOCKS,
248 sizeof(struct tnetd7300_clocks));
249
250 ar7_bus_clock = tnetd7300_get_clock(BUS_PLL_SOURCE_SHIFT,
251 &clocks->bus, bootcr, AR7_AFE_CLOCK);
252
253 if (*bootcr & BOOT_PLL_ASYNC_MODE)
254 ar7_cpu_clock = tnetd7300_get_clock(CPU_PLL_SOURCE_SHIFT,
255 &clocks->cpu, bootcr, AR7_AFE_CLOCK);
256 else
257 ar7_cpu_clock = ar7_bus_clock;
258
259 if (ar7_dsp_clock == 250000000)
260 tnetd7300_set_clock(DSP_PLL_SOURCE_SHIFT, &clocks->dsp,
261 bootcr, ar7_dsp_clock);
262
263 iounmap(clocks);
264 iounmap(bootcr);
265}
266
267static int tnetd7200_get_clock(int base, struct tnetd7200_clock *clock,
268 u32 *bootcr, u32 bus_clock)
269{
270 int divisor = ((readl(&clock->prediv) & 0x1f) + 1) *
271 ((readl(&clock->postdiv) & 0x1f) + 1);
272
273 if (*bootcr & BOOT_PLL_BYPASS)
274 return base / divisor;
275
276 return base * ((readl(&clock->mul) & 0xf) + 1) / divisor;
277}
278
279
280static void tnetd7200_set_clock(int base, struct tnetd7200_clock *clock,
281 int prediv, int postdiv, int postdiv2, int mul, u32 frequency)
282{
283 printk(KERN_INFO
284 "Clocks: base = %d, frequency = %u, prediv = %d, "
285 "postdiv = %d, postdiv2 = %d, mul = %d\n",
286 base, frequency, prediv, postdiv, postdiv2, mul);
287
288 writel(0, &clock->ctrl);
289 writel(DIVISOR_ENABLE_MASK | ((prediv - 1) & 0x1F), &clock->prediv);
290 writel((mul - 1) & 0xF, &clock->mul);
291
292 while (readl(&clock->status) & 0x1)
293 ; /* nop */
294
295 writel(DIVISOR_ENABLE_MASK | ((postdiv - 1) & 0x1F), &clock->postdiv);
296
297 writel(readl(&clock->cmden) | 1, &clock->cmden);
298 writel(readl(&clock->cmd) | 1, &clock->cmd);
299
300 while (readl(&clock->status) & 0x1)
301 ; /* nop */
302
303 writel(DIVISOR_ENABLE_MASK | ((postdiv2 - 1) & 0x1F), &clock->postdiv2);
304
305 writel(readl(&clock->cmden) | 1, &clock->cmden);
306 writel(readl(&clock->cmd) | 1, &clock->cmd);
307
308 while (readl(&clock->status) & 0x1)
309 ; /* nop */
310
311 writel(readl(&clock->ctrl) | 1, &clock->ctrl);
312}
313
314static int tnetd7200_get_clock_base(int clock_id, u32 *bootcr)
315{
316 if (*bootcr & BOOT_PLL_ASYNC_MODE)
317 /* Async */
318 switch (clock_id) {
319 case TNETD7200_CLOCK_ID_DSP:
320 return AR7_REF_CLOCK;
321 default:
322 return AR7_AFE_CLOCK;
323 }
324 else
325 /* Sync */
326 if (*bootcr & BOOT_PLL_2TO1_MODE)
327 /* 2:1 */
328 switch (clock_id) {
329 case TNETD7200_CLOCK_ID_DSP:
330 return AR7_REF_CLOCK;
331 default:
332 return AR7_AFE_CLOCK;
333 }
334 else
335 /* 1:1 */
336 return AR7_REF_CLOCK;
337}
338
339
340static void __init tnetd7200_init_clocks(void)
341{
342 u32 *bootcr = (u32 *)ioremap_nocache(AR7_REGS_DCL, 4);
343 struct tnetd7200_clocks *clocks =
344 ioremap_nocache(AR7_REGS_CLOCKS,
345 sizeof(struct tnetd7200_clocks));
346 int cpu_base, cpu_mul, cpu_prediv, cpu_postdiv;
347 int dsp_base, dsp_mul, dsp_prediv, dsp_postdiv;
348 int usb_base, usb_mul, usb_prediv, usb_postdiv;
349
350 cpu_base = tnetd7200_get_clock_base(TNETD7200_CLOCK_ID_CPU, bootcr);
351 dsp_base = tnetd7200_get_clock_base(TNETD7200_CLOCK_ID_DSP, bootcr);
352
353 if (*bootcr & BOOT_PLL_ASYNC_MODE) {
354 printk(KERN_INFO "Clocks: Async mode\n");
355
356 printk(KERN_INFO "Clocks: Setting DSP clock\n");
357 calculate(dsp_base, TNETD7200_DEF_DSP_CLK,
358 &dsp_prediv, &dsp_postdiv, &dsp_mul);
359 ar7_bus_clock =
360 ((dsp_base / dsp_prediv) * dsp_mul) / dsp_postdiv;
361 tnetd7200_set_clock(dsp_base, &clocks->dsp,
362 dsp_prediv, dsp_postdiv * 2, dsp_postdiv, dsp_mul * 2,
363 ar7_bus_clock);
364
365 printk(KERN_INFO "Clocks: Setting CPU clock\n");
366 calculate(cpu_base, TNETD7200_DEF_CPU_CLK, &cpu_prediv,
367 &cpu_postdiv, &cpu_mul);
368 ar7_cpu_clock =
369 ((cpu_base / cpu_prediv) * cpu_mul) / cpu_postdiv;
370 tnetd7200_set_clock(cpu_base, &clocks->cpu,
371 cpu_prediv, cpu_postdiv, -1, cpu_mul,
372 ar7_cpu_clock);
373
374 } else
375 if (*bootcr & BOOT_PLL_2TO1_MODE) {
376 printk(KERN_INFO "Clocks: Sync 2:1 mode\n");
377
378 printk(KERN_INFO "Clocks: Setting CPU clock\n");
379 calculate(cpu_base, TNETD7200_DEF_CPU_CLK, &cpu_prediv,
380 &cpu_postdiv, &cpu_mul);
381 ar7_cpu_clock = ((cpu_base / cpu_prediv) * cpu_mul)
382 / cpu_postdiv;
383 tnetd7200_set_clock(cpu_base, &clocks->cpu,
384 cpu_prediv, cpu_postdiv, -1, cpu_mul,
385 ar7_cpu_clock);
386
387 printk(KERN_INFO "Clocks: Setting DSP clock\n");
388 calculate(dsp_base, TNETD7200_DEF_DSP_CLK, &dsp_prediv,
389 &dsp_postdiv, &dsp_mul);
390 ar7_bus_clock = ar7_cpu_clock / 2;
391 tnetd7200_set_clock(dsp_base, &clocks->dsp,
392 dsp_prediv, dsp_postdiv * 2, dsp_postdiv,
393 dsp_mul * 2, ar7_bus_clock);
394 } else {
395 printk(KERN_INFO "Clocks: Sync 1:1 mode\n");
396
397 printk(KERN_INFO "Clocks: Setting DSP clock\n");
398 calculate(dsp_base, TNETD7200_DEF_DSP_CLK, &dsp_prediv,
399 &dsp_postdiv, &dsp_mul);
400 ar7_bus_clock = ((dsp_base / dsp_prediv) * dsp_mul)
401 / dsp_postdiv;
402 tnetd7200_set_clock(dsp_base, &clocks->dsp,
403 dsp_prediv, dsp_postdiv * 2, dsp_postdiv,
404 dsp_mul * 2, ar7_bus_clock);
405
406 ar7_cpu_clock = ar7_bus_clock;
407 }
408
409 printk(KERN_INFO "Clocks: Setting USB clock\n");
410 usb_base = ar7_bus_clock;
411 calculate(usb_base, TNETD7200_DEF_USB_CLK, &usb_prediv,
412 &usb_postdiv, &usb_mul);
413 tnetd7200_set_clock(usb_base, &clocks->usb,
414 usb_prediv, usb_postdiv, -1, usb_mul,
415 TNETD7200_DEF_USB_CLK);
416
417 ar7_dsp_clock = ar7_cpu_clock;
418
419 iounmap(clocks);
420 iounmap(bootcr);
421}
422
423int __init ar7_init_clocks(void)
424{
425 switch (ar7_chip_id()) {
426 case AR7_CHIP_7100:
427 case AR7_CHIP_7200:
428 tnetd7200_init_clocks();
429 break;
430 case AR7_CHIP_7300:
431 ar7_dsp_clock = tnetd7300_dsp_clock();
432 tnetd7300_init_clocks();
433 break;
434 default:
435 break;
436 }
437
438 return 0;
439}
440arch_initcall(ar7_init_clocks);
diff --git a/arch/mips/ar7/gpio.c b/arch/mips/ar7/gpio.c
new file mode 100644
index 000000000000..74e14a3dbf4a
--- /dev/null
+++ b/arch/mips/ar7/gpio.c
@@ -0,0 +1,48 @@
1/*
2 * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org>
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 as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <linux/module.h>
21
22#include <asm/mach-ar7/gpio.h>
23
24static const char *ar7_gpio_list[AR7_GPIO_MAX];
25
26int gpio_request(unsigned gpio, const char *label)
27{
28 if (gpio >= AR7_GPIO_MAX)
29 return -EINVAL;
30
31 if (ar7_gpio_list[gpio])
32 return -EBUSY;
33
34 if (label)
35 ar7_gpio_list[gpio] = label;
36 else
37 ar7_gpio_list[gpio] = "busy";
38
39 return 0;
40}
41EXPORT_SYMBOL(gpio_request);
42
43void gpio_free(unsigned gpio)
44{
45 BUG_ON(!ar7_gpio_list[gpio]);
46 ar7_gpio_list[gpio] = NULL;
47}
48EXPORT_SYMBOL(gpio_free);
diff --git a/arch/mips/ar7/irq.c b/arch/mips/ar7/irq.c
new file mode 100644
index 000000000000..c781556c44e4
--- /dev/null
+++ b/arch/mips/ar7/irq.c
@@ -0,0 +1,176 @@
1/*
2 * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
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 as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <linux/interrupt.h>
21#include <linux/io.h>
22
23#include <asm/irq_cpu.h>
24#include <asm/mipsregs.h>
25#include <asm/mach-ar7/ar7.h>
26
27#define EXCEPT_OFFSET 0x80
28#define PACE_OFFSET 0xA0
29#define CHNLS_OFFSET 0x200
30
31#define REG_OFFSET(irq, reg) ((irq) / 32 * 0x4 + reg * 0x10)
32#define SEC_REG_OFFSET(reg) (EXCEPT_OFFSET + reg * 0x8)
33#define SEC_SR_OFFSET (SEC_REG_OFFSET(0)) /* 0x80 */
34#define CR_OFFSET(irq) (REG_OFFSET(irq, 1)) /* 0x10 */
35#define SEC_CR_OFFSET (SEC_REG_OFFSET(1)) /* 0x88 */
36#define ESR_OFFSET(irq) (REG_OFFSET(irq, 2)) /* 0x20 */
37#define SEC_ESR_OFFSET (SEC_REG_OFFSET(2)) /* 0x90 */
38#define ECR_OFFSET(irq) (REG_OFFSET(irq, 3)) /* 0x30 */
39#define SEC_ECR_OFFSET (SEC_REG_OFFSET(3)) /* 0x98 */
40#define PIR_OFFSET (0x40)
41#define MSR_OFFSET (0x44)
42#define PM_OFFSET(irq) (REG_OFFSET(irq, 5)) /* 0x50 */
43#define TM_OFFSET(irq) (REG_OFFSET(irq, 6)) /* 0x60 */
44
45#define REG(addr) ((u32 *)(KSEG1ADDR(AR7_REGS_IRQ) + addr))
46
47#define CHNL_OFFSET(chnl) (CHNLS_OFFSET + (chnl * 4))
48
49static int ar7_irq_base;
50
51static void ar7_unmask_irq(unsigned int irq)
52{
53 writel(1 << ((irq - ar7_irq_base) % 32),
54 REG(ESR_OFFSET(irq - ar7_irq_base)));
55}
56
57static void ar7_mask_irq(unsigned int irq)
58{
59 writel(1 << ((irq - ar7_irq_base) % 32),
60 REG(ECR_OFFSET(irq - ar7_irq_base)));
61}
62
63static void ar7_ack_irq(unsigned int irq)
64{
65 writel(1 << ((irq - ar7_irq_base) % 32),
66 REG(CR_OFFSET(irq - ar7_irq_base)));
67}
68
69static void ar7_unmask_sec_irq(unsigned int irq)
70{
71 writel(1 << (irq - ar7_irq_base - 40), REG(SEC_ESR_OFFSET));
72}
73
74static void ar7_mask_sec_irq(unsigned int irq)
75{
76 writel(1 << (irq - ar7_irq_base - 40), REG(SEC_ECR_OFFSET));
77}
78
79static void ar7_ack_sec_irq(unsigned int irq)
80{
81 writel(1 << (irq - ar7_irq_base - 40), REG(SEC_CR_OFFSET));
82}
83
84static struct irq_chip ar7_irq_type = {
85 .name = "AR7",
86 .unmask = ar7_unmask_irq,
87 .mask = ar7_mask_irq,
88 .ack = ar7_ack_irq
89};
90
91static struct irq_chip ar7_sec_irq_type = {
92 .name = "AR7",
93 .unmask = ar7_unmask_sec_irq,
94 .mask = ar7_mask_sec_irq,
95 .ack = ar7_ack_sec_irq,
96};
97
98static struct irqaction ar7_cascade_action = {
99 .handler = no_action,
100 .name = "AR7 cascade interrupt"
101};
102
103static void __init ar7_irq_init(int base)
104{
105 int i;
106 /*
107 * Disable interrupts and clear pending
108 */
109 writel(0xffffffff, REG(ECR_OFFSET(0)));
110 writel(0xff, REG(ECR_OFFSET(32)));
111 writel(0xffffffff, REG(SEC_ECR_OFFSET));
112 writel(0xffffffff, REG(CR_OFFSET(0)));
113 writel(0xff, REG(CR_OFFSET(32)));
114 writel(0xffffffff, REG(SEC_CR_OFFSET));
115
116 ar7_irq_base = base;
117
118 for (i = 0; i < 40; i++) {
119 writel(i, REG(CHNL_OFFSET(i)));
120 /* Primary IRQ's */
121 set_irq_chip_and_handler(base + i, &ar7_irq_type,
122 handle_level_irq);
123 /* Secondary IRQ's */
124 if (i < 32)
125 set_irq_chip_and_handler(base + i + 40,
126 &ar7_sec_irq_type,
127 handle_level_irq);
128 }
129
130 setup_irq(2, &ar7_cascade_action);
131 setup_irq(ar7_irq_base, &ar7_cascade_action);
132 set_c0_status(IE_IRQ0);
133}
134
135void __init arch_init_irq(void)
136{
137 mips_cpu_irq_init();
138 ar7_irq_init(8);
139}
140
141static void ar7_cascade(void)
142{
143 u32 status;
144 int i, irq;
145
146 /* Primary IRQ's */
147 irq = readl(REG(PIR_OFFSET)) & 0x3f;
148 if (irq) {
149 do_IRQ(ar7_irq_base + irq);
150 return;
151 }
152
153 /* Secondary IRQ's are cascaded through primary '0' */
154 writel(1, REG(CR_OFFSET(irq)));
155 status = readl(REG(SEC_SR_OFFSET));
156 for (i = 0; i < 32; i++) {
157 if (status & 1) {
158 do_IRQ(ar7_irq_base + i + 40);
159 return;
160 }
161 status >>= 1;
162 }
163
164 spurious_interrupt();
165}
166
167asmlinkage void plat_irq_dispatch(void)
168{
169 unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
170 if (pending & STATUSF_IP7) /* cpu timer */
171 do_IRQ(7);
172 else if (pending & STATUSF_IP2) /* int0 hardware line */
173 ar7_cascade();
174 else
175 spurious_interrupt();
176}
diff --git a/arch/mips/ar7/memory.c b/arch/mips/ar7/memory.c
new file mode 100644
index 000000000000..46fed44825a6
--- /dev/null
+++ b/arch/mips/ar7/memory.c
@@ -0,0 +1,72 @@
1/*
2 * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org>
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 as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19#include <linux/bootmem.h>
20#include <linux/init.h>
21#include <linux/mm.h>
22#include <linux/module.h>
23#include <linux/pfn.h>
24#include <linux/proc_fs.h>
25#include <linux/string.h>
26#include <linux/swap.h>
27
28#include <asm/bootinfo.h>
29#include <asm/page.h>
30#include <asm/sections.h>
31
32#include <asm/mach-ar7/ar7.h>
33#include <asm/mips-boards/prom.h>
34
35static int __init memsize(void)
36{
37 u32 size = (64 << 20);
38 u32 *addr = (u32 *)KSEG1ADDR(AR7_SDRAM_BASE + size - 4);
39 u32 *kernel_end = (u32 *)KSEG1ADDR(CPHYSADDR((u32)&_end));
40 u32 *tmpaddr = addr;
41
42 while (tmpaddr > kernel_end) {
43 *tmpaddr = (u32)tmpaddr;
44 size >>= 1;
45 tmpaddr -= size >> 2;
46 }
47
48 do {
49 tmpaddr += size >> 2;
50 if (*tmpaddr != (u32)tmpaddr)
51 break;
52 size <<= 1;
53 } while (size < (64 << 20));
54
55 writel(tmpaddr, &addr);
56
57 return size;
58}
59
60void __init prom_meminit(void)
61{
62 unsigned long pages;
63
64 pages = memsize() >> PAGE_SHIFT;
65 add_memory_region(PHYS_OFFSET, pages << PAGE_SHIFT,
66 BOOT_MEM_RAM);
67}
68
69void __init prom_free_prom_memory(void)
70{
71 /* Nothing to free */
72}
diff --git a/arch/mips/ar7/platform.c b/arch/mips/ar7/platform.c
new file mode 100644
index 000000000000..542244961780
--- /dev/null
+++ b/arch/mips/ar7/platform.c
@@ -0,0 +1,555 @@
1/*
2 * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
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 as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <linux/init.h>
21#include <linux/types.h>
22#include <linux/module.h>
23#include <linux/delay.h>
24#include <linux/dma-mapping.h>
25#include <linux/platform_device.h>
26#include <linux/mtd/physmap.h>
27#include <linux/serial.h>
28#include <linux/serial_8250.h>
29#include <linux/ioport.h>
30#include <linux/io.h>
31#include <linux/version.h>
32#include <linux/vlynq.h>
33#include <linux/leds.h>
34#include <linux/string.h>
35#include <linux/etherdevice.h>
36
37#include <asm/addrspace.h>
38#include <asm/mach-ar7/ar7.h>
39#include <asm/mach-ar7/gpio.h>
40#include <asm/mach-ar7/prom.h>
41
42struct plat_vlynq_data {
43 struct plat_vlynq_ops ops;
44 int gpio_bit;
45 int reset_bit;
46};
47
48
49static int vlynq_on(struct vlynq_device *dev)
50{
51 int result;
52 struct plat_vlynq_data *pdata = dev->dev.platform_data;
53
54 result = gpio_request(pdata->gpio_bit, "vlynq");
55 if (result)
56 goto out;
57
58 ar7_device_reset(pdata->reset_bit);
59
60 result = ar7_gpio_disable(pdata->gpio_bit);
61 if (result)
62 goto out_enabled;
63
64 result = ar7_gpio_enable(pdata->gpio_bit);
65 if (result)
66 goto out_enabled;
67
68 result = gpio_direction_output(pdata->gpio_bit, 0);
69 if (result)
70 goto out_gpio_enabled;
71
72 msleep(50);
73
74 gpio_set_value(pdata->gpio_bit, 1);
75 msleep(50);
76
77 return 0;
78
79out_gpio_enabled:
80 ar7_gpio_disable(pdata->gpio_bit);
81out_enabled:
82 ar7_device_disable(pdata->reset_bit);
83 gpio_free(pdata->gpio_bit);
84out:
85 return result;
86}
87
88static void vlynq_off(struct vlynq_device *dev)
89{
90 struct plat_vlynq_data *pdata = dev->dev.platform_data;
91 ar7_gpio_disable(pdata->gpio_bit);
92 gpio_free(pdata->gpio_bit);
93 ar7_device_disable(pdata->reset_bit);
94}
95
96static struct resource physmap_flash_resource = {
97 .name = "mem",
98 .flags = IORESOURCE_MEM,
99 .start = 0x10000000,
100 .end = 0x107fffff,
101};
102
103static struct resource cpmac_low_res[] = {
104 {
105 .name = "regs",
106 .flags = IORESOURCE_MEM,
107 .start = AR7_REGS_MAC0,
108 .end = AR7_REGS_MAC0 + 0x7ff,
109 },
110 {
111 .name = "irq",
112 .flags = IORESOURCE_IRQ,
113 .start = 27,
114 .end = 27,
115 },
116};
117
118static struct resource cpmac_high_res[] = {
119 {
120 .name = "regs",
121 .flags = IORESOURCE_MEM,
122 .start = AR7_REGS_MAC1,
123 .end = AR7_REGS_MAC1 + 0x7ff,
124 },
125 {
126 .name = "irq",
127 .flags = IORESOURCE_IRQ,
128 .start = 41,
129 .end = 41,
130 },
131};
132
133static struct resource vlynq_low_res[] = {
134 {
135 .name = "regs",
136 .flags = IORESOURCE_MEM,
137 .start = AR7_REGS_VLYNQ0,
138 .end = AR7_REGS_VLYNQ0 + 0xff,
139 },
140 {
141 .name = "irq",
142 .flags = IORESOURCE_IRQ,
143 .start = 29,
144 .end = 29,
145 },
146 {
147 .name = "mem",
148 .flags = IORESOURCE_MEM,
149 .start = 0x04000000,
150 .end = 0x04ffffff,
151 },
152 {
153 .name = "devirq",
154 .flags = IORESOURCE_IRQ,
155 .start = 80,
156 .end = 111,
157 },
158};
159
160static struct resource vlynq_high_res[] = {
161 {
162 .name = "regs",
163 .flags = IORESOURCE_MEM,
164 .start = AR7_REGS_VLYNQ1,
165 .end = AR7_REGS_VLYNQ1 + 0xff,
166 },
167 {
168 .name = "irq",
169 .flags = IORESOURCE_IRQ,
170 .start = 33,
171 .end = 33,
172 },
173 {
174 .name = "mem",
175 .flags = IORESOURCE_MEM,
176 .start = 0x0c000000,
177 .end = 0x0cffffff,
178 },
179 {
180 .name = "devirq",
181 .flags = IORESOURCE_IRQ,
182 .start = 112,
183 .end = 143,
184 },
185};
186
187static struct resource usb_res[] = {
188 {
189 .name = "regs",
190 .flags = IORESOURCE_MEM,
191 .start = AR7_REGS_USB,
192 .end = AR7_REGS_USB + 0xff,
193 },
194 {
195 .name = "irq",
196 .flags = IORESOURCE_IRQ,
197 .start = 32,
198 .end = 32,
199 },
200 {
201 .name = "mem",
202 .flags = IORESOURCE_MEM,
203 .start = 0x03400000,
204 .end = 0x034001fff,
205 },
206};
207
208static struct physmap_flash_data physmap_flash_data = {
209 .width = 2,
210};
211
212static struct plat_cpmac_data cpmac_low_data = {
213 .reset_bit = 17,
214 .power_bit = 20,
215 .phy_mask = 0x80000000,
216};
217
218static struct plat_cpmac_data cpmac_high_data = {
219 .reset_bit = 21,
220 .power_bit = 22,
221 .phy_mask = 0x7fffffff,
222};
223
224static struct plat_vlynq_data vlynq_low_data = {
225 .ops.on = vlynq_on,
226 .ops.off = vlynq_off,
227 .reset_bit = 20,
228 .gpio_bit = 18,
229};
230
231static struct plat_vlynq_data vlynq_high_data = {
232 .ops.on = vlynq_on,
233 .ops.off = vlynq_off,
234 .reset_bit = 16,
235 .gpio_bit = 19,
236};
237
238static struct platform_device physmap_flash = {
239 .id = 0,
240 .name = "physmap-flash",
241 .dev.platform_data = &physmap_flash_data,
242 .resource = &physmap_flash_resource,
243 .num_resources = 1,
244};
245
246static u64 cpmac_dma_mask = DMA_32BIT_MASK;
247static struct platform_device cpmac_low = {
248 .id = 0,
249 .name = "cpmac",
250 .dev = {
251 .dma_mask = &cpmac_dma_mask,
252 .coherent_dma_mask = DMA_32BIT_MASK,
253 .platform_data = &cpmac_low_data,
254 },
255 .resource = cpmac_low_res,
256 .num_resources = ARRAY_SIZE(cpmac_low_res),
257};
258
259static struct platform_device cpmac_high = {
260 .id = 1,
261 .name = "cpmac",
262 .dev = {
263 .dma_mask = &cpmac_dma_mask,
264 .coherent_dma_mask = DMA_32BIT_MASK,
265 .platform_data = &cpmac_high_data,
266 },
267 .resource = cpmac_high_res,
268 .num_resources = ARRAY_SIZE(cpmac_high_res),
269};
270
271static struct platform_device vlynq_low = {
272 .id = 0,
273 .name = "vlynq",
274 .dev.platform_data = &vlynq_low_data,
275 .resource = vlynq_low_res,
276 .num_resources = ARRAY_SIZE(vlynq_low_res),
277};
278
279static struct platform_device vlynq_high = {
280 .id = 1,
281 .name = "vlynq",
282 .dev.platform_data = &vlynq_high_data,
283 .resource = vlynq_high_res,
284 .num_resources = ARRAY_SIZE(vlynq_high_res),
285};
286
287
288static struct gpio_led default_leds[] = {
289 {
290 .name = "status",
291 .gpio = 8,
292 .active_low = 1,
293 },
294};
295
296static struct gpio_led dsl502t_leds[] = {
297 {
298 .name = "status",
299 .gpio = 9,
300 .active_low = 1,
301 },
302 {
303 .name = "ethernet",
304 .gpio = 7,
305 .active_low = 1,
306 },
307 {
308 .name = "usb",
309 .gpio = 12,
310 .active_low = 1,
311 },
312};
313
314static struct gpio_led dg834g_leds[] = {
315 {
316 .name = "ppp",
317 .gpio = 6,
318 .active_low = 1,
319 },
320 {
321 .name = "status",
322 .gpio = 7,
323 .active_low = 1,
324 },
325 {
326 .name = "adsl",
327 .gpio = 8,
328 .active_low = 1,
329 },
330 {
331 .name = "wifi",
332 .gpio = 12,
333 .active_low = 1,
334 },
335 {
336 .name = "power",
337 .gpio = 14,
338 .active_low = 1,
339 .default_trigger = "default-on",
340 },
341};
342
343static struct gpio_led fb_sl_leds[] = {
344 {
345 .name = "1",
346 .gpio = 7,
347 },
348 {
349 .name = "2",
350 .gpio = 13,
351 .active_low = 1,
352 },
353 {
354 .name = "3",
355 .gpio = 10,
356 .active_low = 1,
357 },
358 {
359 .name = "4",
360 .gpio = 12,
361 .active_low = 1,
362 },
363 {
364 .name = "5",
365 .gpio = 9,
366 .active_low = 1,
367 },
368};
369
370static struct gpio_led fb_fon_leds[] = {
371 {
372 .name = "1",
373 .gpio = 8,
374 },
375 {
376 .name = "2",
377 .gpio = 3,
378 .active_low = 1,
379 },
380 {
381 .name = "3",
382 .gpio = 5,
383 },
384 {
385 .name = "4",
386 .gpio = 4,
387 .active_low = 1,
388 },
389 {
390 .name = "5",
391 .gpio = 11,
392 .active_low = 1,
393 },
394};
395
396static struct gpio_led_platform_data ar7_led_data;
397
398static struct platform_device ar7_gpio_leds = {
399 .name = "leds-gpio",
400 .id = -1,
401 .dev = {
402 .platform_data = &ar7_led_data,
403 }
404};
405
406static struct platform_device ar7_udc = {
407 .id = -1,
408 .name = "ar7_udc",
409 .resource = usb_res,
410 .num_resources = ARRAY_SIZE(usb_res),
411};
412
413static inline unsigned char char2hex(char h)
414{
415 switch (h) {
416 case '0': case '1': case '2': case '3': case '4':
417 case '5': case '6': case '7': case '8': case '9':
418 return h - '0';
419 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
420 return h - 'A' + 10;
421 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
422 return h - 'a' + 10;
423 default:
424 return 0;
425 }
426}
427
428static void cpmac_get_mac(int instance, unsigned char *dev_addr)
429{
430 int i;
431 char name[5], default_mac[ETH_ALEN], *mac;
432
433 mac = NULL;
434 sprintf(name, "mac%c", 'a' + instance);
435 mac = prom_getenv(name);
436 if (!mac) {
437 sprintf(name, "mac%c", 'a');
438 mac = prom_getenv(name);
439 }
440 if (!mac) {
441 random_ether_addr(default_mac);
442 mac = default_mac;
443 }
444 for (i = 0; i < 6; i++)
445 dev_addr[i] = (char2hex(mac[i * 3]) << 4) +
446 char2hex(mac[i * 3 + 1]);
447}
448
449static void __init detect_leds(void)
450{
451 char *prid, *usb_prod;
452
453 /* Default LEDs */
454 ar7_led_data.num_leds = ARRAY_SIZE(default_leds);
455 ar7_led_data.leds = default_leds;
456
457 /* FIXME: the whole thing is unreliable */
458 prid = prom_getenv("ProductID");
459 usb_prod = prom_getenv("usb_prod");
460
461 /* If we can't get the product id from PROM, use the default LEDs */
462 if (!prid)
463 return;
464
465 if (strstr(prid, "Fritz_Box_FON")) {
466 ar7_led_data.num_leds = ARRAY_SIZE(fb_fon_leds);
467 ar7_led_data.leds = fb_fon_leds;
468 } else if (strstr(prid, "Fritz_Box_")) {
469 ar7_led_data.num_leds = ARRAY_SIZE(fb_sl_leds);
470 ar7_led_data.leds = fb_sl_leds;
471 } else if ((!strcmp(prid, "AR7RD") || !strcmp(prid, "AR7DB"))
472 && usb_prod != NULL && strstr(usb_prod, "DSL-502T")) {
473 ar7_led_data.num_leds = ARRAY_SIZE(dsl502t_leds);
474 ar7_led_data.leds = dsl502t_leds;
475 } else if (strstr(prid, "DG834")) {
476 ar7_led_data.num_leds = ARRAY_SIZE(dg834g_leds);
477 ar7_led_data.leds = dg834g_leds;
478 }
479}
480
481static int __init ar7_register_devices(void)
482{
483 int res;
484 static struct uart_port uart_port[2];
485
486 memset(uart_port, 0, sizeof(struct uart_port) * 2);
487
488 uart_port[0].type = PORT_16550A;
489 uart_port[0].line = 0;
490 uart_port[0].irq = AR7_IRQ_UART0;
491 uart_port[0].uartclk = ar7_bus_freq() / 2;
492 uart_port[0].iotype = UPIO_MEM32;
493 uart_port[0].mapbase = AR7_REGS_UART0;
494 uart_port[0].membase = ioremap(uart_port[0].mapbase, 256);
495 uart_port[0].regshift = 2;
496 res = early_serial_setup(&uart_port[0]);
497 if (res)
498 return res;
499
500
501 /* Only TNETD73xx have a second serial port */
502 if (ar7_has_second_uart()) {
503 uart_port[1].type = PORT_16550A;
504 uart_port[1].line = 1;
505 uart_port[1].irq = AR7_IRQ_UART1;
506 uart_port[1].uartclk = ar7_bus_freq() / 2;
507 uart_port[1].iotype = UPIO_MEM32;
508 uart_port[1].mapbase = UR8_REGS_UART1;
509 uart_port[1].membase = ioremap(uart_port[1].mapbase, 256);
510 uart_port[1].regshift = 2;
511 res = early_serial_setup(&uart_port[1]);
512 if (res)
513 return res;
514 }
515
516 res = platform_device_register(&physmap_flash);
517 if (res)
518 return res;
519
520 ar7_device_disable(vlynq_low_data.reset_bit);
521 res = platform_device_register(&vlynq_low);
522 if (res)
523 return res;
524
525 if (ar7_has_high_vlynq()) {
526 ar7_device_disable(vlynq_high_data.reset_bit);
527 res = platform_device_register(&vlynq_high);
528 if (res)
529 return res;
530 }
531
532 if (ar7_has_high_cpmac()) {
533 cpmac_get_mac(1, cpmac_high_data.dev_addr);
534 res = platform_device_register(&cpmac_high);
535 if (res)
536 return res;
537 } else {
538 cpmac_low_data.phy_mask = 0xffffffff;
539 }
540
541 cpmac_get_mac(0, cpmac_low_data.dev_addr);
542 res = platform_device_register(&cpmac_low);
543 if (res)
544 return res;
545
546 detect_leds();
547 res = platform_device_register(&ar7_gpio_leds);
548 if (res)
549 return res;
550
551 res = platform_device_register(&ar7_udc);
552
553 return res;
554}
555arch_initcall(ar7_register_devices);
diff --git a/arch/mips/ar7/prom.c b/arch/mips/ar7/prom.c
new file mode 100644
index 000000000000..a320bceb2f9d
--- /dev/null
+++ b/arch/mips/ar7/prom.c
@@ -0,0 +1,297 @@
1/*
2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
4 *
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17 *
18 * Putting things on the screen/serial line using YAMONs facilities.
19 */
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/serial_reg.h>
23#include <linux/spinlock.h>
24#include <linux/module.h>
25#include <linux/string.h>
26#include <linux/io.h>
27#include <asm/bootinfo.h>
28
29#include <asm/mach-ar7/ar7.h>
30#include <asm/mach-ar7/prom.h>
31
32#define MAX_ENTRY 80
33
34struct env_var {
35 char *name;
36 char *value;
37};
38
39static struct env_var adam2_env[MAX_ENTRY];
40
41char *prom_getenv(const char *name)
42{
43 int i;
44 for (i = 0; (i < MAX_ENTRY) && adam2_env[i].name; i++)
45 if (!strcmp(name, adam2_env[i].name))
46 return adam2_env[i].value;
47
48 return NULL;
49}
50EXPORT_SYMBOL(prom_getenv);
51
52char * __init prom_getcmdline(void)
53{
54 return &(arcs_cmdline[0]);
55}
56
57static void __init ar7_init_cmdline(int argc, char *argv[])
58{
59 char *cp;
60 int actr;
61
62 actr = 1; /* Always ignore argv[0] */
63
64 cp = &(arcs_cmdline[0]);
65 while (actr < argc) {
66 strcpy(cp, argv[actr]);
67 cp += strlen(argv[actr]);
68 *cp++ = ' ';
69 actr++;
70 }
71 if (cp != &(arcs_cmdline[0])) {
72 /* get rid of trailing space */
73 --cp;
74 *cp = '\0';
75 }
76}
77
78struct psbl_rec {
79 u32 psbl_size;
80 u32 env_base;
81 u32 env_size;
82 u32 ffs_base;
83 u32 ffs_size;
84};
85
86static __initdata char psp_env_version[] = "TIENV0.8";
87
88struct psp_env_chunk {
89 u8 num;
90 u8 ctrl;
91 u16 csum;
92 u8 len;
93 char data[11];
94} __attribute__ ((packed));
95
96struct psp_var_map_entry {
97 u8 num;
98 char *value;
99};
100
101static struct psp_var_map_entry psp_var_map[] = {
102 { 1, "cpufrequency" },
103 { 2, "memsize" },
104 { 3, "flashsize" },
105 { 4, "modetty0" },
106 { 5, "modetty1" },
107 { 8, "maca" },
108 { 9, "macb" },
109 { 28, "sysfrequency" },
110 { 38, "mipsfrequency" },
111};
112
113/*
114
115Well-known variable (num is looked up in table above for matching variable name)
116Example: cpufrequency=211968000
117+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
118| 01 |CTRL|CHECKSUM | 01 | _2 | _1 | _1 | _9 | _6 | _8 | _0 | _0 | _0 | \0 | FF
119+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
120
121Name=Value pair in a single chunk
122Example: NAME=VALUE
123+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
124| 00 |CTRL|CHECKSUM | 01 | _N | _A | _M | _E | _0 | _V | _A | _L | _U | _E | \0
125+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
126
127Name=Value pair in 2 chunks (len is the number of chunks)
128Example: bootloaderVersion=1.3.7.15
129+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
130| 00 |CTRL|CHECKSUM | 02 | _b | _o | _o | _t | _l | _o | _a | _d | _e | _r | _V
131+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
132| _e | _r | _s | _i | _o | _n | \0 | _1 | _. | _3 | _. | _7 | _. | _1 | _5 | \0
133+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+---
134
135Data is padded with 0xFF
136
137*/
138
139#define PSP_ENV_SIZE 4096
140
141static char psp_env_data[PSP_ENV_SIZE] = { 0, };
142
143static char * __init lookup_psp_var_map(u8 num)
144{
145 int i;
146
147 for (i = 0; i < sizeof(psp_var_map); i++)
148 if (psp_var_map[i].num == num)
149 return psp_var_map[i].value;
150
151 return NULL;
152}
153
154static void __init add_adam2_var(char *name, char *value)
155{
156 int i;
157 for (i = 0; i < MAX_ENTRY; i++) {
158 if (!adam2_env[i].name) {
159 adam2_env[i].name = name;
160 adam2_env[i].value = value;
161 return;
162 } else if (!strcmp(adam2_env[i].name, name)) {
163 adam2_env[i].value = value;
164 return;
165 }
166 }
167}
168
169static int __init parse_psp_env(void *psp_env_base)
170{
171 int i, n;
172 char *name, *value;
173 struct psp_env_chunk *chunks = (struct psp_env_chunk *)psp_env_data;
174
175 memcpy_fromio(chunks, psp_env_base, PSP_ENV_SIZE);
176
177 i = 1;
178 n = PSP_ENV_SIZE / sizeof(struct psp_env_chunk);
179 while (i < n) {
180 if ((chunks[i].num == 0xff) || ((i + chunks[i].len) > n))
181 break;
182 value = chunks[i].data;
183 if (chunks[i].num) {
184 name = lookup_psp_var_map(chunks[i].num);
185 } else {
186 name = value;
187 value += strlen(name) + 1;
188 }
189 if (name)
190 add_adam2_var(name, value);
191 i += chunks[i].len;
192 }
193 return 0;
194}
195
196static void __init ar7_init_env(struct env_var *env)
197{
198 int i;
199 struct psbl_rec *psbl = (struct psbl_rec *)(KSEG1ADDR(0x14000300));
200 void *psp_env = (void *)KSEG1ADDR(psbl->env_base);
201
202 if (strcmp(psp_env, psp_env_version) == 0) {
203 parse_psp_env(psp_env);
204 } else {
205 for (i = 0; i < MAX_ENTRY; i++, env++)
206 if (env->name)
207 add_adam2_var(env->name, env->value);
208 }
209}
210
211static void __init console_config(void)
212{
213#ifdef CONFIG_SERIAL_8250_CONSOLE
214 char console_string[40];
215 int baud = 0;
216 char parity = '\0', bits = '\0', flow = '\0';
217 char *s, *p;
218
219 if (strstr(prom_getcmdline(), "console="))
220 return;
221
222#ifdef CONFIG_KGDB
223 if (!strstr(prom_getcmdline(), "nokgdb")) {
224 strcat(prom_getcmdline(), " console=kgdb");
225 kgdb_enabled = 1;
226 return;
227 }
228#endif
229
230 s = prom_getenv("modetty0");
231 if (s) {
232 baud = simple_strtoul(s, &p, 10);
233 s = p;
234 if (*s == ',')
235 s++;
236 if (*s)
237 parity = *s++;
238 if (*s == ',')
239 s++;
240 if (*s)
241 bits = *s++;
242 if (*s == ',')
243 s++;
244 if (*s == 'h')
245 flow = 'r';
246 }
247
248 if (baud == 0)
249 baud = 38400;
250 if (parity != 'n' && parity != 'o' && parity != 'e')
251 parity = 'n';
252 if (bits != '7' && bits != '8')
253 bits = '8';
254
255 if (flow == 'r')
256 sprintf(console_string, " console=ttyS0,%d%c%c%c", baud,
257 parity, bits, flow);
258 else
259 sprintf(console_string, " console=ttyS0,%d%c%c", baud, parity,
260 bits);
261 strcat(prom_getcmdline(), console_string);
262#endif
263}
264
265void __init prom_init(void)
266{
267 ar7_init_cmdline(fw_arg0, (char **)fw_arg1);
268 ar7_init_env((struct env_var *)fw_arg2);
269 console_config();
270}
271
272#define PORT(offset) (KSEG1ADDR(AR7_REGS_UART0 + (offset * 4)))
273static inline unsigned int serial_in(int offset)
274{
275 return readl((void *)PORT(offset));
276}
277
278static inline void serial_out(int offset, int value)
279{
280 writel(value, (void *)PORT(offset));
281}
282
283char prom_getchar(void)
284{
285 while (!(serial_in(UART_LSR) & UART_LSR_DR))
286 ;
287 return serial_in(UART_RX);
288}
289
290int prom_putchar(char c)
291{
292 while ((serial_in(UART_LSR) & UART_LSR_TEMT) == 0)
293 ;
294 serial_out(UART_TX, c);
295 return 1;
296}
297
diff --git a/arch/mips/ar7/setup.c b/arch/mips/ar7/setup.c
new file mode 100644
index 000000000000..6ebb5f16d967
--- /dev/null
+++ b/arch/mips/ar7/setup.c
@@ -0,0 +1,94 @@
1/*
2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
4 *
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17 */
18#include <linux/version.h>
19#include <linux/init.h>
20#include <linux/ioport.h>
21#include <linux/pm.h>
22#include <linux/time.h>
23
24#include <asm/reboot.h>
25#include <asm/mach-ar7/ar7.h>
26#include <asm/mach-ar7/prom.h>
27
28static void ar7_machine_restart(char *command)
29{
30 u32 *softres_reg = ioremap(AR7_REGS_RESET +
31 AR7_RESET_SOFTWARE, 1);
32 writel(1, softres_reg);
33}
34
35static void ar7_machine_halt(void)
36{
37 while (1)
38 ;
39}
40
41static void ar7_machine_power_off(void)
42{
43 u32 *power_reg = (u32 *)ioremap(AR7_REGS_POWER, 1);
44 u32 power_state = readl(power_reg) | (3 << 30);
45 writel(power_state, power_reg);
46 ar7_machine_halt();
47}
48
49const char *get_system_type(void)
50{
51 u16 chip_id = ar7_chip_id();
52 switch (chip_id) {
53 case AR7_CHIP_7300:
54 return "TI AR7 (TNETD7300)";
55 case AR7_CHIP_7100:
56 return "TI AR7 (TNETD7100)";
57 case AR7_CHIP_7200:
58 return "TI AR7 (TNETD7200)";
59 default:
60 return "TI AR7 (Unknown)";
61 }
62}
63
64static int __init ar7_init_console(void)
65{
66 return 0;
67}
68console_initcall(ar7_init_console);
69
70/*
71 * Initializes basic routines and structures pointers, memory size (as
72 * given by the bios and saves the command line.
73 */
74
75void __init plat_mem_setup(void)
76{
77 unsigned long io_base;
78
79 _machine_restart = ar7_machine_restart;
80 _machine_halt = ar7_machine_halt;
81 pm_power_off = ar7_machine_power_off;
82 panic_timeout = 3;
83
84 io_base = (unsigned long)ioremap(AR7_REGS_BASE, 0x10000);
85 if (!io_base)
86 panic("Can't remap IO base!\n");
87 set_io_port_base(io_base);
88
89 prom_meminit();
90
91 printk(KERN_INFO "%s, ID: 0x%04x, Revision: 0x%02x\n",
92 get_system_type(),
93 ar7_chip_id(), ar7_chip_rev());
94}
diff --git a/arch/mips/ar7/time.c b/arch/mips/ar7/time.c
new file mode 100644
index 000000000000..a1fba894daa2
--- /dev/null
+++ b/arch/mips/ar7/time.c
@@ -0,0 +1,30 @@
1/*
2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
4 *
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17 *
18 * Setting up the clock on the MIPS boards.
19 */
20
21#include <linux/init.h>
22#include <linux/time.h>
23
24#include <asm/time.h>
25#include <asm/mach-ar7/ar7.h>
26
27void __init plat_time_init(void)
28{
29 mips_hpt_frequency = ar7_cpu_freq() / 2;
30}
diff --git a/arch/mips/cavium-octeon/Makefile b/arch/mips/cavium-octeon/Makefile
index 7c0528b0e34c..d6903c3f3d51 100644
--- a/arch/mips/cavium-octeon/Makefile
+++ b/arch/mips/cavium-octeon/Makefile
@@ -14,9 +14,5 @@ obj-y += dma-octeon.o flash_setup.o
14obj-y += octeon-memcpy.o 14obj-y += octeon-memcpy.o
15 15
16obj-$(CONFIG_SMP) += smp.o 16obj-$(CONFIG_SMP) += smp.o
17obj-$(CONFIG_PCI) += pci-common.o
18obj-$(CONFIG_PCI) += pci.o
19obj-$(CONFIG_PCI) += pcie.o
20obj-$(CONFIG_PCI_MSI) += msi.o
21 17
22EXTRA_CFLAGS += -Werror 18EXTRA_CFLAGS += -Werror
diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index 627c162a6159..4b92bfc662db 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -29,7 +29,7 @@
29#include <dma-coherence.h> 29#include <dma-coherence.h>
30 30
31#ifdef CONFIG_PCI 31#ifdef CONFIG_PCI
32#include "pci-common.h" 32#include <asm/octeon/pci-octeon.h>
33#endif 33#endif
34 34
35#define BAR2_PCI_ADDRESS 0x8000000000ul 35#define BAR2_PCI_ADDRESS 0x8000000000ul
diff --git a/arch/mips/cavium-octeon/pci-common.c b/arch/mips/cavium-octeon/pci-common.c
deleted file mode 100644
index cd029f88da7f..000000000000
--- a/arch/mips/cavium-octeon/pci-common.c
+++ /dev/null
@@ -1,137 +0,0 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2005-2007 Cavium Networks
7 */
8#include <linux/kernel.h>
9#include <linux/init.h>
10#include <linux/pci.h>
11#include <linux/interrupt.h>
12#include <linux/time.h>
13#include <linux/delay.h>
14#include "pci-common.h"
15
16typeof(pcibios_map_irq) *octeon_pcibios_map_irq;
17enum octeon_dma_bar_type octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_INVALID;
18
19/**
20 * Map a PCI device to the appropriate interrupt line
21 *
22 * @param dev The Linux PCI device structure for the device to map
23 * @param slot The slot number for this device on __BUS 0__. Linux
24 * enumerates through all the bridges and figures out the
25 * slot on Bus 0 where this device eventually hooks to.
26 * @param pin The PCI interrupt pin read from the device, then swizzled
27 * as it goes through each bridge.
28 * @return Interrupt number for the device
29 */
30int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
31{
32 if (octeon_pcibios_map_irq)
33 return octeon_pcibios_map_irq(dev, slot, pin);
34 else
35 panic("octeon_pcibios_map_irq doesn't point to a "
36 "pcibios_map_irq() function");
37}
38
39
40/**
41 * Called to perform platform specific PCI setup
42 *
43 * @param dev
44 * @return
45 */
46int pcibios_plat_dev_init(struct pci_dev *dev)
47{
48 uint16_t config;
49 uint32_t dconfig;
50 int pos;
51 /*
52 * Force the Cache line setting to 64 bytes. The standard
53 * Linux bus scan doesn't seem to set it. Octeon really has
54 * 128 byte lines, but Intel bridges get really upset if you
55 * try and set values above 64 bytes. Value is specified in
56 * 32bit words.
57 */
58 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 64 / 4);
59 /* Set latency timers for all devices */
60 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 48);
61
62 /* Enable reporting System errors and parity errors on all devices */
63 /* Enable parity checking and error reporting */
64 pci_read_config_word(dev, PCI_COMMAND, &config);
65 config |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
66 pci_write_config_word(dev, PCI_COMMAND, config);
67
68 if (dev->subordinate) {
69 /* Set latency timers on sub bridges */
70 pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 48);
71 /* More bridge error detection */
72 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &config);
73 config |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR;
74 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, config);
75 }
76
77 /* Enable the PCIe normal error reporting */
78 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
79 if (pos) {
80 /* Update Device Control */
81 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &config);
82 /* Correctable Error Reporting */
83 config |= PCI_EXP_DEVCTL_CERE;
84 /* Non-Fatal Error Reporting */
85 config |= PCI_EXP_DEVCTL_NFERE;
86 /* Fatal Error Reporting */
87 config |= PCI_EXP_DEVCTL_FERE;
88 /* Unsupported Request */
89 config |= PCI_EXP_DEVCTL_URRE;
90 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, config);
91 }
92
93 /* Find the Advanced Error Reporting capability */
94 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
95 if (pos) {
96 /* Clear Uncorrectable Error Status */
97 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
98 &dconfig);
99 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
100 dconfig);
101 /* Enable reporting of all uncorrectable errors */
102 /* Uncorrectable Error Mask - turned on bits disable errors */
103 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, 0);
104 /*
105 * Leave severity at HW default. This only controls if
106 * errors are reported as uncorrectable or
107 * correctable, not if the error is reported.
108 */
109 /* PCI_ERR_UNCOR_SEVER - Uncorrectable Error Severity */
110 /* Clear Correctable Error Status */
111 pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &dconfig);
112 pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, dconfig);
113 /* Enable reporting of all correctable errors */
114 /* Correctable Error Mask - turned on bits disable errors */
115 pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, 0);
116 /* Advanced Error Capabilities */
117 pci_read_config_dword(dev, pos + PCI_ERR_CAP, &dconfig);
118 /* ECRC Generation Enable */
119 if (config & PCI_ERR_CAP_ECRC_GENC)
120 config |= PCI_ERR_CAP_ECRC_GENE;
121 /* ECRC Check Enable */
122 if (config & PCI_ERR_CAP_ECRC_CHKC)
123 config |= PCI_ERR_CAP_ECRC_CHKE;
124 pci_write_config_dword(dev, pos + PCI_ERR_CAP, dconfig);
125 /* PCI_ERR_HEADER_LOG - Header Log Register (16 bytes) */
126 /* Report all errors to the root complex */
127 pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND,
128 PCI_ERR_ROOT_CMD_COR_EN |
129 PCI_ERR_ROOT_CMD_NONFATAL_EN |
130 PCI_ERR_ROOT_CMD_FATAL_EN);
131 /* Clear the Root status register */
132 pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &dconfig);
133 pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, dconfig);
134 }
135
136 return 0;
137}
diff --git a/arch/mips/cobalt/buttons.c b/arch/mips/cobalt/buttons.c
index 9e143989c7b8..4eaec8b46e0c 100644
--- a/arch/mips/cobalt/buttons.c
+++ b/arch/mips/cobalt/buttons.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Cobalt buttons platform device. 2 * Cobalt buttons platform device.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/cobalt/lcd.c b/arch/mips/cobalt/lcd.c
index 0720e4fae311..0f1cd90f37ed 100644
--- a/arch/mips/cobalt/lcd.c
+++ b/arch/mips/cobalt/lcd.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Registration of Cobalt LCD platform device. 2 * Registration of Cobalt LCD platform device.
3 * 3 *
4 * Copyright (C) 2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/cobalt/led.c b/arch/mips/cobalt/led.c
index 1c6ebd468b07..d3ce6fa1dc74 100644
--- a/arch/mips/cobalt/led.c
+++ b/arch/mips/cobalt/led.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Registration of Cobalt LED platform device. 2 * Registration of Cobalt LED platform device.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/cobalt/mtd.c b/arch/mips/cobalt/mtd.c
index 2b088ef3839a..691d620b6766 100644
--- a/arch/mips/cobalt/mtd.c
+++ b/arch/mips/cobalt/mtd.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Registration of Cobalt MTD device. 2 * Registration of Cobalt MTD device.
3 * 3 *
4 * Copyright (C) 2006 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2006 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/cobalt/rtc.c b/arch/mips/cobalt/rtc.c
index e70794b8bcba..3ab39898b4e4 100644
--- a/arch/mips/cobalt/rtc.c
+++ b/arch/mips/cobalt/rtc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Registration of Cobalt RTC platform device. 2 * Registration of Cobalt RTC platform device.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/cobalt/serial.c b/arch/mips/cobalt/serial.c
index 53b8d0d6da90..7cb51f57275e 100644
--- a/arch/mips/cobalt/serial.c
+++ b/arch/mips/cobalt/serial.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Registration of Cobalt UART platform device. 2 * Registration of Cobalt UART platform device.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/cobalt/time.c b/arch/mips/cobalt/time.c
index 4a570e7145fe..0162f9edc693 100644
--- a/arch/mips/cobalt/time.c
+++ b/arch/mips/cobalt/time.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Cobalt time initialization. 2 * Cobalt time initialization.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/configs/ar7_defconfig b/arch/mips/configs/ar7_defconfig
new file mode 100644
index 000000000000..dad5b6769d74
--- /dev/null
+++ b/arch/mips/configs/ar7_defconfig
@@ -0,0 +1,1182 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.30
4# Wed Jun 24 14:08:59 2009
5#
6CONFIG_MIPS=y
7
8#
9# Machine selection
10#
11# CONFIG_MACH_ALCHEMY is not set
12CONFIG_AR7=y
13# CONFIG_BASLER_EXCITE is not set
14# CONFIG_BCM47XX is not set
15# CONFIG_MIPS_COBALT is not set
16# CONFIG_MACH_DECSTATION is not set
17# CONFIG_MACH_JAZZ is not set
18# CONFIG_LASAT is not set
19# CONFIG_LEMOTE_FULONG is not set
20# CONFIG_MIPS_MALTA is not set
21# CONFIG_MIPS_SIM is not set
22# CONFIG_NEC_MARKEINS is not set
23# CONFIG_MACH_VR41XX is not set
24# CONFIG_NXP_STB220 is not set
25# CONFIG_NXP_STB225 is not set
26# CONFIG_PNX8550_JBS is not set
27# CONFIG_PNX8550_STB810 is not set
28# CONFIG_PMC_MSP is not set
29# CONFIG_PMC_YOSEMITE is not set
30# CONFIG_SGI_IP22 is not set
31# CONFIG_SGI_IP27 is not set
32# CONFIG_SGI_IP28 is not set
33# CONFIG_SGI_IP32 is not set
34# CONFIG_SIBYTE_CRHINE is not set
35# CONFIG_SIBYTE_CARMEL is not set
36# CONFIG_SIBYTE_CRHONE is not set
37# CONFIG_SIBYTE_RHONE is not set
38# CONFIG_SIBYTE_SWARM is not set
39# CONFIG_SIBYTE_LITTLESUR is not set
40# CONFIG_SIBYTE_SENTOSA is not set
41# CONFIG_SIBYTE_BIGSUR is not set
42# CONFIG_SNI_RM is not set
43# CONFIG_MACH_TX39XX is not set
44# CONFIG_MACH_TX49XX is not set
45# CONFIG_MIKROTIK_RB532 is not set
46# CONFIG_WR_PPMC is not set
47# CONFIG_CAVIUM_OCTEON_SIMULATOR is not set
48# CONFIG_CAVIUM_OCTEON_REFERENCE_BOARD is not set
49# CONFIG_ALCHEMY_GPIO_INDIRECT is not set
50CONFIG_RWSEM_GENERIC_SPINLOCK=y
51# CONFIG_ARCH_HAS_ILOG2_U32 is not set
52# CONFIG_ARCH_HAS_ILOG2_U64 is not set
53CONFIG_ARCH_SUPPORTS_OPROFILE=y
54CONFIG_GENERIC_FIND_NEXT_BIT=y
55CONFIG_GENERIC_HWEIGHT=y
56CONFIG_GENERIC_CALIBRATE_DELAY=y
57CONFIG_GENERIC_CLOCKEVENTS=y
58CONFIG_GENERIC_TIME=y
59CONFIG_GENERIC_CMOS_UPDATE=y
60CONFIG_SCHED_OMIT_FRAME_POINTER=y
61CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
62CONFIG_CEVT_R4K_LIB=y
63CONFIG_CEVT_R4K=y
64CONFIG_CSRC_R4K_LIB=y
65CONFIG_CSRC_R4K=y
66CONFIG_DMA_NONCOHERENT=y
67CONFIG_DMA_NEED_PCI_MAP_STATE=y
68CONFIG_EARLY_PRINTK=y
69CONFIG_SYS_HAS_EARLY_PRINTK=y
70# CONFIG_HOTPLUG_CPU is not set
71# CONFIG_NO_IOPORT is not set
72CONFIG_GENERIC_GPIO=y
73# CONFIG_CPU_BIG_ENDIAN is not set
74CONFIG_CPU_LITTLE_ENDIAN=y
75CONFIG_SYS_SUPPORTS_LITTLE_ENDIAN=y
76CONFIG_IRQ_CPU=y
77CONFIG_NO_EXCEPT_FILL=y
78CONFIG_SWAP_IO_SPACE=y
79CONFIG_BOOT_ELF32=y
80CONFIG_MIPS_L1_CACHE_SHIFT=5
81
82#
83# CPU selection
84#
85# CONFIG_CPU_LOONGSON2 is not set
86CONFIG_CPU_MIPS32_R1=y
87# CONFIG_CPU_MIPS32_R2 is not set
88# CONFIG_CPU_MIPS64_R1 is not set
89# CONFIG_CPU_MIPS64_R2 is not set
90# CONFIG_CPU_R3000 is not set
91# CONFIG_CPU_TX39XX is not set
92# CONFIG_CPU_VR41XX is not set
93# CONFIG_CPU_R4300 is not set
94# CONFIG_CPU_R4X00 is not set
95# CONFIG_CPU_TX49XX is not set
96# CONFIG_CPU_R5000 is not set
97# CONFIG_CPU_R5432 is not set
98# CONFIG_CPU_R5500 is not set
99# CONFIG_CPU_R6000 is not set
100# CONFIG_CPU_NEVADA is not set
101# CONFIG_CPU_R8000 is not set
102# CONFIG_CPU_R10000 is not set
103# CONFIG_CPU_RM7000 is not set
104# CONFIG_CPU_RM9000 is not set
105# CONFIG_CPU_SB1 is not set
106# CONFIG_CPU_CAVIUM_OCTEON is not set
107CONFIG_SYS_HAS_CPU_MIPS32_R1=y
108CONFIG_CPU_MIPS32=y
109CONFIG_CPU_MIPSR1=y
110CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
111CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
112CONFIG_HARDWARE_WATCHPOINTS=y
113
114#
115# Kernel type
116#
117CONFIG_32BIT=y
118# CONFIG_64BIT is not set
119CONFIG_PAGE_SIZE_4KB=y
120# CONFIG_PAGE_SIZE_8KB is not set
121# CONFIG_PAGE_SIZE_16KB is not set
122# CONFIG_PAGE_SIZE_32KB is not set
123# CONFIG_PAGE_SIZE_64KB is not set
124CONFIG_CPU_HAS_PREFETCH=y
125CONFIG_MIPS_MT_DISABLED=y
126# CONFIG_MIPS_MT_SMP is not set
127# CONFIG_MIPS_MT_SMTC is not set
128CONFIG_CPU_HAS_LLSC=y
129CONFIG_CPU_HAS_SYNC=y
130CONFIG_GENERIC_HARDIRQS=y
131CONFIG_GENERIC_IRQ_PROBE=y
132CONFIG_CPU_SUPPORTS_HIGHMEM=y
133CONFIG_ARCH_FLATMEM_ENABLE=y
134CONFIG_ARCH_POPULATES_NODE_MAP=y
135CONFIG_SELECT_MEMORY_MODEL=y
136CONFIG_FLATMEM_MANUAL=y
137# CONFIG_DISCONTIGMEM_MANUAL is not set
138# CONFIG_SPARSEMEM_MANUAL is not set
139CONFIG_FLATMEM=y
140CONFIG_FLAT_NODE_MEM_MAP=y
141CONFIG_PAGEFLAGS_EXTENDED=y
142CONFIG_SPLIT_PTLOCK_CPUS=4
143# CONFIG_PHYS_ADDR_T_64BIT is not set
144CONFIG_ZONE_DMA_FLAG=0
145CONFIG_VIRT_TO_BUS=y
146CONFIG_HAVE_MLOCK=y
147CONFIG_HAVE_MLOCKED_PAGE_BIT=y
148CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
149CONFIG_TICK_ONESHOT=y
150# CONFIG_NO_HZ is not set
151CONFIG_HIGH_RES_TIMERS=y
152CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
153# CONFIG_HZ_48 is not set
154CONFIG_HZ_100=y
155# CONFIG_HZ_128 is not set
156# CONFIG_HZ_250 is not set
157# CONFIG_HZ_256 is not set
158# CONFIG_HZ_1000 is not set
159# CONFIG_HZ_1024 is not set
160CONFIG_SYS_SUPPORTS_ARBIT_HZ=y
161CONFIG_HZ=100
162CONFIG_PREEMPT_NONE=y
163# CONFIG_PREEMPT_VOLUNTARY is not set
164# CONFIG_PREEMPT is not set
165CONFIG_KEXEC=y
166# CONFIG_SECCOMP is not set
167CONFIG_LOCKDEP_SUPPORT=y
168CONFIG_STACKTRACE_SUPPORT=y
169CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
170
171#
172# General setup
173#
174CONFIG_EXPERIMENTAL=y
175CONFIG_BROKEN_ON_SMP=y
176CONFIG_INIT_ENV_ARG_LIMIT=32
177CONFIG_LOCALVERSION=""
178# CONFIG_LOCALVERSION_AUTO is not set
179CONFIG_SWAP=y
180CONFIG_SYSVIPC=y
181CONFIG_SYSVIPC_SYSCTL=y
182# CONFIG_POSIX_MQUEUE is not set
183CONFIG_BSD_PROCESS_ACCT=y
184# CONFIG_BSD_PROCESS_ACCT_V3 is not set
185# CONFIG_TASKSTATS is not set
186# CONFIG_AUDIT is not set
187
188#
189# RCU Subsystem
190#
191CONFIG_CLASSIC_RCU=y
192# CONFIG_TREE_RCU is not set
193# CONFIG_PREEMPT_RCU is not set
194# CONFIG_TREE_RCU_TRACE is not set
195# CONFIG_PREEMPT_RCU_TRACE is not set
196# CONFIG_IKCONFIG is not set
197CONFIG_LOG_BUF_SHIFT=14
198# CONFIG_GROUP_SCHED is not set
199# CONFIG_CGROUPS is not set
200CONFIG_SYSFS_DEPRECATED=y
201CONFIG_SYSFS_DEPRECATED_V2=y
202CONFIG_RELAY=y
203# CONFIG_NAMESPACES is not set
204CONFIG_BLK_DEV_INITRD=y
205CONFIG_INITRAMFS_SOURCE=""
206CONFIG_RD_GZIP=y
207# CONFIG_RD_BZIP2 is not set
208CONFIG_RD_LZMA=y
209CONFIG_CC_OPTIMIZE_FOR_SIZE=y
210CONFIG_SYSCTL=y
211CONFIG_ANON_INODES=y
212CONFIG_EMBEDDED=y
213CONFIG_SYSCTL_SYSCALL=y
214# CONFIG_KALLSYMS is not set
215CONFIG_HOTPLUG=y
216CONFIG_PRINTK=y
217CONFIG_BUG=y
218# CONFIG_ELF_CORE is not set
219# CONFIG_PCSPKR_PLATFORM is not set
220CONFIG_BASE_FULL=y
221CONFIG_FUTEX=y
222CONFIG_EPOLL=y
223CONFIG_SIGNALFD=y
224CONFIG_TIMERFD=y
225CONFIG_EVENTFD=y
226CONFIG_SHMEM=y
227CONFIG_AIO=y
228
229#
230# Performance Counters
231#
232# CONFIG_VM_EVENT_COUNTERS is not set
233CONFIG_STRIP_ASM_SYMS=y
234# CONFIG_COMPAT_BRK is not set
235CONFIG_SLAB=y
236# CONFIG_SLUB is not set
237# CONFIG_SLOB is not set
238# CONFIG_PROFILING is not set
239# CONFIG_MARKERS is not set
240CONFIG_HAVE_OPROFILE=y
241# CONFIG_SLOW_WORK is not set
242# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
243CONFIG_SLABINFO=y
244CONFIG_RT_MUTEXES=y
245CONFIG_BASE_SMALL=0
246CONFIG_MODULES=y
247# CONFIG_MODULE_FORCE_LOAD is not set
248CONFIG_MODULE_UNLOAD=y
249# CONFIG_MODULE_FORCE_UNLOAD is not set
250# CONFIG_MODVERSIONS is not set
251# CONFIG_MODULE_SRCVERSION_ALL is not set
252CONFIG_BLOCK=y
253# CONFIG_LBD is not set
254# CONFIG_BLK_DEV_BSG is not set
255# CONFIG_BLK_DEV_INTEGRITY is not set
256
257#
258# IO Schedulers
259#
260CONFIG_IOSCHED_NOOP=y
261# CONFIG_IOSCHED_AS is not set
262CONFIG_IOSCHED_DEADLINE=y
263# CONFIG_IOSCHED_CFQ is not set
264# CONFIG_DEFAULT_AS is not set
265CONFIG_DEFAULT_DEADLINE=y
266# CONFIG_DEFAULT_CFQ is not set
267# CONFIG_DEFAULT_NOOP is not set
268CONFIG_DEFAULT_IOSCHED="deadline"
269CONFIG_PROBE_INITRD_HEADER=y
270# CONFIG_FREEZER is not set
271
272#
273# Bus options (PCI, PCMCIA, EISA, ISA, TC)
274#
275# CONFIG_ARCH_SUPPORTS_MSI is not set
276CONFIG_MMU=y
277# CONFIG_PCCARD is not set
278
279#
280# Executable file formats
281#
282CONFIG_BINFMT_ELF=y
283# CONFIG_HAVE_AOUT is not set
284# CONFIG_BINFMT_MISC is not set
285CONFIG_TRAD_SIGNALS=y
286
287#
288# Power management options
289#
290CONFIG_ARCH_HIBERNATION_POSSIBLE=y
291CONFIG_ARCH_SUSPEND_POSSIBLE=y
292# CONFIG_PM is not set
293CONFIG_NET=y
294
295#
296# Networking options
297#
298CONFIG_PACKET=y
299CONFIG_PACKET_MMAP=y
300CONFIG_UNIX=y
301# CONFIG_NET_KEY is not set
302CONFIG_INET=y
303CONFIG_IP_MULTICAST=y
304CONFIG_IP_ADVANCED_ROUTER=y
305CONFIG_ASK_IP_FIB_HASH=y
306# CONFIG_IP_FIB_TRIE is not set
307CONFIG_IP_FIB_HASH=y
308CONFIG_IP_MULTIPLE_TABLES=y
309CONFIG_IP_ROUTE_MULTIPATH=y
310CONFIG_IP_ROUTE_VERBOSE=y
311# CONFIG_IP_PNP is not set
312# CONFIG_NET_IPIP is not set
313# CONFIG_NET_IPGRE is not set
314CONFIG_IP_MROUTE=y
315# CONFIG_IP_PIMSM_V1 is not set
316# CONFIG_IP_PIMSM_V2 is not set
317CONFIG_ARPD=y
318CONFIG_SYN_COOKIES=y
319# CONFIG_INET_AH is not set
320# CONFIG_INET_ESP is not set
321# CONFIG_INET_IPCOMP is not set
322# CONFIG_INET_XFRM_TUNNEL is not set
323# CONFIG_INET_TUNNEL is not set
324# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
325# CONFIG_INET_XFRM_MODE_TUNNEL is not set
326# CONFIG_INET_XFRM_MODE_BEET is not set
327# CONFIG_INET_LRO is not set
328# CONFIG_INET_DIAG is not set
329CONFIG_TCP_CONG_ADVANCED=y
330# CONFIG_TCP_CONG_BIC is not set
331# CONFIG_TCP_CONG_CUBIC is not set
332CONFIG_TCP_CONG_WESTWOOD=y
333# CONFIG_TCP_CONG_HTCP is not set
334# CONFIG_TCP_CONG_HSTCP is not set
335# CONFIG_TCP_CONG_HYBLA is not set
336# CONFIG_TCP_CONG_VEGAS is not set
337# CONFIG_TCP_CONG_SCALABLE is not set
338# CONFIG_TCP_CONG_LP is not set
339# CONFIG_TCP_CONG_VENO is not set
340# CONFIG_TCP_CONG_YEAH is not set
341# CONFIG_TCP_CONG_ILLINOIS is not set
342# CONFIG_DEFAULT_BIC is not set
343# CONFIG_DEFAULT_CUBIC is not set
344# CONFIG_DEFAULT_HTCP is not set
345# CONFIG_DEFAULT_VEGAS is not set
346CONFIG_DEFAULT_WESTWOOD=y
347# CONFIG_DEFAULT_RENO is not set
348CONFIG_DEFAULT_TCP_CONG="westwood"
349# CONFIG_TCP_MD5SIG is not set
350# CONFIG_IPV6 is not set
351# CONFIG_NETWORK_SECMARK is not set
352CONFIG_NETFILTER=y
353# CONFIG_NETFILTER_DEBUG is not set
354CONFIG_NETFILTER_ADVANCED=y
355# CONFIG_BRIDGE_NETFILTER is not set
356
357#
358# Core Netfilter Configuration
359#
360# CONFIG_NETFILTER_NETLINK_QUEUE is not set
361# CONFIG_NETFILTER_NETLINK_LOG is not set
362CONFIG_NF_CONNTRACK=m
363# CONFIG_NF_CT_ACCT is not set
364CONFIG_NF_CONNTRACK_MARK=y
365# CONFIG_NF_CONNTRACK_EVENTS is not set
366# CONFIG_NF_CT_PROTO_DCCP is not set
367# CONFIG_NF_CT_PROTO_SCTP is not set
368# CONFIG_NF_CT_PROTO_UDPLITE is not set
369# CONFIG_NF_CONNTRACK_AMANDA is not set
370CONFIG_NF_CONNTRACK_FTP=m
371# CONFIG_NF_CONNTRACK_H323 is not set
372CONFIG_NF_CONNTRACK_IRC=m
373# CONFIG_NF_CONNTRACK_NETBIOS_NS is not set
374# CONFIG_NF_CONNTRACK_PPTP is not set
375# CONFIG_NF_CONNTRACK_SANE is not set
376# CONFIG_NF_CONNTRACK_SIP is not set
377CONFIG_NF_CONNTRACK_TFTP=m
378# CONFIG_NF_CT_NETLINK is not set
379# CONFIG_NETFILTER_TPROXY is not set
380CONFIG_NETFILTER_XTABLES=m
381# CONFIG_NETFILTER_XT_TARGET_CLASSIFY is not set
382# CONFIG_NETFILTER_XT_TARGET_CONNMARK is not set
383# CONFIG_NETFILTER_XT_TARGET_DSCP is not set
384# CONFIG_NETFILTER_XT_TARGET_HL is not set
385# CONFIG_NETFILTER_XT_TARGET_LED is not set
386# CONFIG_NETFILTER_XT_TARGET_MARK is not set
387# CONFIG_NETFILTER_XT_TARGET_NFLOG is not set
388# CONFIG_NETFILTER_XT_TARGET_NFQUEUE is not set
389CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
390# CONFIG_NETFILTER_XT_TARGET_RATEEST is not set
391# CONFIG_NETFILTER_XT_TARGET_TRACE is not set
392CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
393# CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP is not set
394# CONFIG_NETFILTER_XT_MATCH_CLUSTER is not set
395# CONFIG_NETFILTER_XT_MATCH_COMMENT is not set
396# CONFIG_NETFILTER_XT_MATCH_CONNBYTES is not set
397# CONFIG_NETFILTER_XT_MATCH_CONNLIMIT is not set
398# CONFIG_NETFILTER_XT_MATCH_CONNMARK is not set
399# CONFIG_NETFILTER_XT_MATCH_CONNTRACK is not set
400# CONFIG_NETFILTER_XT_MATCH_DCCP is not set
401# CONFIG_NETFILTER_XT_MATCH_DSCP is not set
402# CONFIG_NETFILTER_XT_MATCH_ESP is not set
403# CONFIG_NETFILTER_XT_MATCH_HASHLIMIT is not set
404# CONFIG_NETFILTER_XT_MATCH_HELPER is not set
405# CONFIG_NETFILTER_XT_MATCH_HL is not set
406# CONFIG_NETFILTER_XT_MATCH_IPRANGE is not set
407# CONFIG_NETFILTER_XT_MATCH_LENGTH is not set
408CONFIG_NETFILTER_XT_MATCH_LIMIT=m
409CONFIG_NETFILTER_XT_MATCH_MAC=m
410# CONFIG_NETFILTER_XT_MATCH_MARK is not set
411CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
412# CONFIG_NETFILTER_XT_MATCH_OWNER is not set
413# CONFIG_NETFILTER_XT_MATCH_PKTTYPE is not set
414# CONFIG_NETFILTER_XT_MATCH_QUOTA is not set
415# CONFIG_NETFILTER_XT_MATCH_RATEEST is not set
416# CONFIG_NETFILTER_XT_MATCH_REALM is not set
417# CONFIG_NETFILTER_XT_MATCH_RECENT is not set
418# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
419CONFIG_NETFILTER_XT_MATCH_STATE=m
420# CONFIG_NETFILTER_XT_MATCH_STATISTIC is not set
421# CONFIG_NETFILTER_XT_MATCH_STRING is not set
422# CONFIG_NETFILTER_XT_MATCH_TCPMSS is not set
423# CONFIG_NETFILTER_XT_MATCH_TIME is not set
424# CONFIG_NETFILTER_XT_MATCH_U32 is not set
425# CONFIG_IP_VS is not set
426
427#
428# IP: Netfilter Configuration
429#
430CONFIG_NF_DEFRAG_IPV4=m
431CONFIG_NF_CONNTRACK_IPV4=m
432CONFIG_NF_CONNTRACK_PROC_COMPAT=y
433# CONFIG_IP_NF_QUEUE is not set
434CONFIG_IP_NF_IPTABLES=m
435# CONFIG_IP_NF_MATCH_ADDRTYPE is not set
436# CONFIG_IP_NF_MATCH_AH is not set
437# CONFIG_IP_NF_MATCH_ECN is not set
438# CONFIG_IP_NF_MATCH_TTL is not set
439CONFIG_IP_NF_FILTER=m
440CONFIG_IP_NF_TARGET_REJECT=m
441CONFIG_IP_NF_TARGET_LOG=m
442# CONFIG_IP_NF_TARGET_ULOG is not set
443CONFIG_NF_NAT=m
444CONFIG_NF_NAT_NEEDED=y
445CONFIG_IP_NF_TARGET_MASQUERADE=m
446# CONFIG_IP_NF_TARGET_NETMAP is not set
447# CONFIG_IP_NF_TARGET_REDIRECT is not set
448# CONFIG_NF_NAT_SNMP_BASIC is not set
449CONFIG_NF_NAT_FTP=m
450CONFIG_NF_NAT_IRC=m
451CONFIG_NF_NAT_TFTP=m
452# CONFIG_NF_NAT_AMANDA is not set
453# CONFIG_NF_NAT_PPTP is not set
454# CONFIG_NF_NAT_H323 is not set
455# CONFIG_NF_NAT_SIP is not set
456CONFIG_IP_NF_MANGLE=m
457# CONFIG_IP_NF_TARGET_CLUSTERIP is not set
458# CONFIG_IP_NF_TARGET_ECN is not set
459# CONFIG_IP_NF_TARGET_TTL is not set
460CONFIG_IP_NF_RAW=m
461# CONFIG_IP_NF_ARPTABLES is not set
462# CONFIG_IP_DCCP is not set
463# CONFIG_IP_SCTP is not set
464# CONFIG_TIPC is not set
465CONFIG_ATM=m
466# CONFIG_ATM_CLIP is not set
467# CONFIG_ATM_LANE is not set
468CONFIG_ATM_BR2684=m
469CONFIG_ATM_BR2684_IPFILTER=y
470CONFIG_STP=y
471CONFIG_BRIDGE=y
472# CONFIG_NET_DSA is not set
473CONFIG_VLAN_8021Q=y
474# CONFIG_VLAN_8021Q_GVRP is not set
475# CONFIG_DECNET is not set
476CONFIG_LLC=y
477# CONFIG_LLC2 is not set
478# CONFIG_IPX is not set
479# CONFIG_ATALK is not set
480# CONFIG_X25 is not set
481# CONFIG_LAPB is not set
482# CONFIG_ECONET is not set
483# CONFIG_WAN_ROUTER is not set
484# CONFIG_PHONET is not set
485# CONFIG_IEEE802154 is not set
486CONFIG_NET_SCHED=y
487
488#
489# Queueing/Scheduling
490#
491# CONFIG_NET_SCH_CBQ is not set
492# CONFIG_NET_SCH_HTB is not set
493# CONFIG_NET_SCH_HFSC is not set
494# CONFIG_NET_SCH_ATM is not set
495# CONFIG_NET_SCH_PRIO is not set
496# CONFIG_NET_SCH_MULTIQ is not set
497# CONFIG_NET_SCH_RED is not set
498# CONFIG_NET_SCH_SFQ is not set
499# CONFIG_NET_SCH_TEQL is not set
500# CONFIG_NET_SCH_TBF is not set
501# CONFIG_NET_SCH_GRED is not set
502# CONFIG_NET_SCH_DSMARK is not set
503# CONFIG_NET_SCH_NETEM is not set
504# CONFIG_NET_SCH_DRR is not set
505# CONFIG_NET_SCH_INGRESS is not set
506
507#
508# Classification
509#
510# CONFIG_NET_CLS_BASIC is not set
511# CONFIG_NET_CLS_TCINDEX is not set
512# CONFIG_NET_CLS_ROUTE4 is not set
513# CONFIG_NET_CLS_FW is not set
514# CONFIG_NET_CLS_U32 is not set
515# CONFIG_NET_CLS_RSVP is not set
516# CONFIG_NET_CLS_RSVP6 is not set
517# CONFIG_NET_CLS_FLOW is not set
518# CONFIG_NET_EMATCH is not set
519CONFIG_NET_CLS_ACT=y
520CONFIG_NET_ACT_POLICE=y
521# CONFIG_NET_ACT_GACT is not set
522# CONFIG_NET_ACT_MIRRED is not set
523# CONFIG_NET_ACT_IPT is not set
524# CONFIG_NET_ACT_NAT is not set
525# CONFIG_NET_ACT_PEDIT is not set
526# CONFIG_NET_ACT_SIMP is not set
527# CONFIG_NET_ACT_SKBEDIT is not set
528CONFIG_NET_SCH_FIFO=y
529# CONFIG_DCB is not set
530
531#
532# Network testing
533#
534# CONFIG_NET_PKTGEN is not set
535CONFIG_HAMRADIO=y
536
537#
538# Packet Radio protocols
539#
540# CONFIG_AX25 is not set
541# CONFIG_CAN is not set
542# CONFIG_IRDA is not set
543# CONFIG_BT is not set
544# CONFIG_AF_RXRPC is not set
545CONFIG_FIB_RULES=y
546CONFIG_WIRELESS=y
547CONFIG_CFG80211=m
548# CONFIG_CFG80211_REG_DEBUG is not set
549# CONFIG_CFG80211_DEBUGFS is not set
550# CONFIG_WIRELESS_OLD_REGULATORY is not set
551CONFIG_WIRELESS_EXT=y
552CONFIG_WIRELESS_EXT_SYSFS=y
553# CONFIG_LIB80211 is not set
554CONFIG_MAC80211=m
555CONFIG_MAC80211_DEFAULT_PS=y
556CONFIG_MAC80211_DEFAULT_PS_VALUE=1
557
558#
559# Rate control algorithm selection
560#
561CONFIG_MAC80211_RC_PID=y
562CONFIG_MAC80211_RC_MINSTREL=y
563CONFIG_MAC80211_RC_DEFAULT_PID=y
564# CONFIG_MAC80211_RC_DEFAULT_MINSTREL is not set
565CONFIG_MAC80211_RC_DEFAULT="pid"
566# CONFIG_MAC80211_MESH is not set
567# CONFIG_MAC80211_LEDS is not set
568# CONFIG_MAC80211_DEBUGFS is not set
569# CONFIG_MAC80211_DEBUG_MENU is not set
570# CONFIG_WIMAX is not set
571# CONFIG_RFKILL is not set
572# CONFIG_NET_9P is not set
573
574#
575# Device Drivers
576#
577
578#
579# Generic Driver Options
580#
581CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
582CONFIG_STANDALONE=y
583CONFIG_PREVENT_FIRMWARE_BUILD=y
584CONFIG_FW_LOADER=y
585# CONFIG_FIRMWARE_IN_KERNEL is not set
586CONFIG_EXTRA_FIRMWARE=""
587# CONFIG_SYS_HYPERVISOR is not set
588# CONFIG_CONNECTOR is not set
589CONFIG_MTD=y
590# CONFIG_MTD_DEBUG is not set
591# CONFIG_MTD_CONCAT is not set
592CONFIG_MTD_PARTITIONS=y
593# CONFIG_MTD_TESTS is not set
594# CONFIG_MTD_REDBOOT_PARTS is not set
595# CONFIG_MTD_CMDLINE_PARTS is not set
596# CONFIG_MTD_AR7_PARTS is not set
597
598#
599# User Modules And Translation Layers
600#
601CONFIG_MTD_CHAR=y
602CONFIG_MTD_BLKDEVS=y
603CONFIG_MTD_BLOCK=y
604# CONFIG_FTL is not set
605# CONFIG_NFTL is not set
606# CONFIG_INFTL is not set
607# CONFIG_RFD_FTL is not set
608# CONFIG_SSFDC is not set
609# CONFIG_MTD_OOPS is not set
610
611#
612# RAM/ROM/Flash chip drivers
613#
614CONFIG_MTD_CFI=y
615# CONFIG_MTD_JEDECPROBE is not set
616CONFIG_MTD_GEN_PROBE=y
617# CONFIG_MTD_CFI_ADV_OPTIONS is not set
618CONFIG_MTD_MAP_BANK_WIDTH_1=y
619CONFIG_MTD_MAP_BANK_WIDTH_2=y
620CONFIG_MTD_MAP_BANK_WIDTH_4=y
621# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
622# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
623# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
624CONFIG_MTD_CFI_I1=y
625CONFIG_MTD_CFI_I2=y
626# CONFIG_MTD_CFI_I4 is not set
627# CONFIG_MTD_CFI_I8 is not set
628CONFIG_MTD_CFI_INTELEXT=y
629CONFIG_MTD_CFI_AMDSTD=y
630CONFIG_MTD_CFI_STAA=y
631CONFIG_MTD_CFI_UTIL=y
632# CONFIG_MTD_RAM is not set
633# CONFIG_MTD_ROM is not set
634# CONFIG_MTD_ABSENT is not set
635
636#
637# Mapping drivers for chip access
638#
639CONFIG_MTD_COMPLEX_MAPPINGS=y
640CONFIG_MTD_PHYSMAP=y
641# CONFIG_MTD_PHYSMAP_COMPAT is not set
642# CONFIG_MTD_PLATRAM is not set
643
644#
645# Self-contained MTD device drivers
646#
647# CONFIG_MTD_SLRAM is not set
648# CONFIG_MTD_PHRAM is not set
649# CONFIG_MTD_MTDRAM is not set
650# CONFIG_MTD_BLOCK2MTD is not set
651
652#
653# Disk-On-Chip Device Drivers
654#
655# CONFIG_MTD_DOC2000 is not set
656# CONFIG_MTD_DOC2001 is not set
657# CONFIG_MTD_DOC2001PLUS is not set
658# CONFIG_MTD_NAND is not set
659# CONFIG_MTD_ONENAND is not set
660
661#
662# LPDDR flash memory drivers
663#
664# CONFIG_MTD_LPDDR is not set
665
666#
667# UBI - Unsorted block images
668#
669# CONFIG_MTD_UBI is not set
670# CONFIG_PARPORT is not set
671CONFIG_BLK_DEV=y
672# CONFIG_BLK_DEV_COW_COMMON is not set
673# CONFIG_BLK_DEV_LOOP is not set
674# CONFIG_BLK_DEV_NBD is not set
675# CONFIG_BLK_DEV_RAM is not set
676# CONFIG_CDROM_PKTCDVD is not set
677# CONFIG_ATA_OVER_ETH is not set
678# CONFIG_BLK_DEV_HD is not set
679CONFIG_MISC_DEVICES=y
680# CONFIG_ENCLOSURE_SERVICES is not set
681# CONFIG_C2PORT is not set
682
683#
684# EEPROM support
685#
686# CONFIG_EEPROM_93CX6 is not set
687CONFIG_HAVE_IDE=y
688# CONFIG_IDE is not set
689
690#
691# SCSI device support
692#
693# CONFIG_RAID_ATTRS is not set
694# CONFIG_SCSI is not set
695# CONFIG_SCSI_DMA is not set
696# CONFIG_SCSI_NETLINK is not set
697# CONFIG_ATA is not set
698# CONFIG_MD is not set
699CONFIG_NETDEVICES=y
700# CONFIG_IFB is not set
701# CONFIG_DUMMY is not set
702# CONFIG_BONDING is not set
703# CONFIG_MACVLAN is not set
704# CONFIG_EQUALIZER is not set
705# CONFIG_TUN is not set
706# CONFIG_VETH is not set
707CONFIG_PHYLIB=y
708
709#
710# MII PHY device drivers
711#
712# CONFIG_MARVELL_PHY is not set
713# CONFIG_DAVICOM_PHY is not set
714# CONFIG_QSEMI_PHY is not set
715# CONFIG_LXT_PHY is not set
716# CONFIG_CICADA_PHY is not set
717# CONFIG_VITESSE_PHY is not set
718# CONFIG_SMSC_PHY is not set
719# CONFIG_BROADCOM_PHY is not set
720# CONFIG_ICPLUS_PHY is not set
721# CONFIG_REALTEK_PHY is not set
722# CONFIG_NATIONAL_PHY is not set
723# CONFIG_STE10XP is not set
724# CONFIG_LSI_ET1011C_PHY is not set
725CONFIG_FIXED_PHY=y
726# CONFIG_MDIO_BITBANG is not set
727CONFIG_NET_ETHERNET=y
728CONFIG_MII=y
729# CONFIG_AX88796 is not set
730# CONFIG_SMC91X is not set
731# CONFIG_DM9000 is not set
732# CONFIG_ETHOC is not set
733# CONFIG_DNET is not set
734# CONFIG_IBM_NEW_EMAC_ZMII is not set
735# CONFIG_IBM_NEW_EMAC_RGMII is not set
736# CONFIG_IBM_NEW_EMAC_TAH is not set
737# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
738# CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL is not set
739# CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT is not set
740# CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR is not set
741# CONFIG_B44 is not set
742# CONFIG_KS8842 is not set
743CONFIG_CPMAC=y
744# CONFIG_NETDEV_1000 is not set
745# CONFIG_NETDEV_10000 is not set
746
747#
748# Wireless LAN
749#
750# CONFIG_WLAN_PRE80211 is not set
751CONFIG_WLAN_80211=y
752# CONFIG_LIBERTAS is not set
753# CONFIG_LIBERTAS_THINFIRM is not set
754# CONFIG_MAC80211_HWSIM is not set
755# CONFIG_P54_COMMON is not set
756# CONFIG_HOSTAP is not set
757# CONFIG_B43 is not set
758# CONFIG_B43LEGACY is not set
759# CONFIG_RT2X00 is not set
760
761#
762# Enable WiMAX (Networking options) to see the WiMAX drivers
763#
764# CONFIG_WAN is not set
765CONFIG_ATM_DRIVERS=y
766# CONFIG_ATM_DUMMY is not set
767# CONFIG_ATM_TCP is not set
768CONFIG_PPP=m
769CONFIG_PPP_MULTILINK=y
770CONFIG_PPP_FILTER=y
771CONFIG_PPP_ASYNC=m
772# CONFIG_PPP_SYNC_TTY is not set
773# CONFIG_PPP_DEFLATE is not set
774# CONFIG_PPP_BSDCOMP is not set
775# CONFIG_PPP_MPPE is not set
776CONFIG_PPPOE=m
777CONFIG_PPPOATM=m
778# CONFIG_PPPOL2TP is not set
779# CONFIG_SLIP is not set
780CONFIG_SLHC=m
781# CONFIG_NETCONSOLE is not set
782# CONFIG_NETPOLL is not set
783# CONFIG_NET_POLL_CONTROLLER is not set
784# CONFIG_ISDN is not set
785# CONFIG_PHONE is not set
786
787#
788# Input device support
789#
790# CONFIG_INPUT is not set
791
792#
793# Hardware I/O ports
794#
795# CONFIG_SERIO is not set
796# CONFIG_GAMEPORT is not set
797
798#
799# Character devices
800#
801# CONFIG_VT is not set
802# CONFIG_DEVKMEM is not set
803# CONFIG_SERIAL_NONSTANDARD is not set
804
805#
806# Serial drivers
807#
808CONFIG_SERIAL_8250=y
809CONFIG_SERIAL_8250_CONSOLE=y
810CONFIG_SERIAL_8250_NR_UARTS=2
811CONFIG_SERIAL_8250_RUNTIME_UARTS=2
812# CONFIG_SERIAL_8250_EXTENDED is not set
813
814#
815# Non-8250 serial port support
816#
817CONFIG_SERIAL_CORE=y
818CONFIG_SERIAL_CORE_CONSOLE=y
819CONFIG_UNIX98_PTYS=y
820# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
821# CONFIG_LEGACY_PTYS is not set
822# CONFIG_IPMI_HANDLER is not set
823CONFIG_HW_RANDOM=y
824# CONFIG_HW_RANDOM_TIMERIOMEM is not set
825# CONFIG_R3964 is not set
826# CONFIG_RAW_DRIVER is not set
827# CONFIG_TCG_TPM is not set
828# CONFIG_I2C is not set
829# CONFIG_SPI is not set
830# CONFIG_W1 is not set
831# CONFIG_POWER_SUPPLY is not set
832# CONFIG_HWMON is not set
833# CONFIG_THERMAL is not set
834# CONFIG_THERMAL_HWMON is not set
835CONFIG_WATCHDOG=y
836# CONFIG_WATCHDOG_NOWAYOUT is not set
837
838#
839# Watchdog Device Drivers
840#
841# CONFIG_SOFT_WATCHDOG is not set
842CONFIG_AR7_WDT=y
843CONFIG_SSB_POSSIBLE=y
844
845#
846# Sonics Silicon Backplane
847#
848CONFIG_SSB=y
849# CONFIG_SSB_SILENT is not set
850# CONFIG_SSB_DEBUG is not set
851CONFIG_SSB_SERIAL=y
852CONFIG_SSB_DRIVER_MIPS=y
853CONFIG_SSB_EMBEDDED=y
854CONFIG_SSB_DRIVER_EXTIF=y
855
856#
857# Multifunction device drivers
858#
859# CONFIG_MFD_CORE is not set
860# CONFIG_MFD_SM501 is not set
861# CONFIG_HTC_PASIC3 is not set
862# CONFIG_MFD_TMIO is not set
863# CONFIG_REGULATOR is not set
864# CONFIG_MEDIA_SUPPORT is not set
865
866#
867# Graphics support
868#
869# CONFIG_VGASTATE is not set
870# CONFIG_VIDEO_OUTPUT_CONTROL is not set
871# CONFIG_FB is not set
872# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
873
874#
875# Display device support
876#
877# CONFIG_DISPLAY_SUPPORT is not set
878# CONFIG_SOUND is not set
879# CONFIG_USB_SUPPORT is not set
880# CONFIG_MMC is not set
881# CONFIG_MEMSTICK is not set
882CONFIG_NEW_LEDS=y
883CONFIG_LEDS_CLASS=y
884
885#
886# LED drivers
887#
888# CONFIG_LEDS_GPIO is not set
889
890#
891# LED Triggers
892#
893CONFIG_LEDS_TRIGGERS=y
894CONFIG_LEDS_TRIGGER_TIMER=y
895CONFIG_LEDS_TRIGGER_HEARTBEAT=y
896# CONFIG_LEDS_TRIGGER_BACKLIGHT is not set
897CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
898
899#
900# iptables trigger is under Netfilter config (LED target)
901#
902# CONFIG_ACCESSIBILITY is not set
903CONFIG_RTC_LIB=y
904# CONFIG_RTC_CLASS is not set
905# CONFIG_DMADEVICES is not set
906# CONFIG_AUXDISPLAY is not set
907# CONFIG_UIO is not set
908
909#
910# TI VLYNQ
911#
912CONFIG_VLYNQ=y
913# CONFIG_STAGING is not set
914
915#
916# File systems
917#
918# CONFIG_EXT2_FS is not set
919# CONFIG_EXT3_FS is not set
920# CONFIG_EXT4_FS is not set
921# CONFIG_REISERFS_FS is not set
922# CONFIG_JFS_FS is not set
923# CONFIG_FS_POSIX_ACL is not set
924# CONFIG_XFS_FS is not set
925# CONFIG_OCFS2_FS is not set
926# CONFIG_BTRFS_FS is not set
927CONFIG_FILE_LOCKING=y
928CONFIG_FSNOTIFY=y
929# CONFIG_DNOTIFY is not set
930# CONFIG_INOTIFY is not set
931CONFIG_INOTIFY_USER=y
932# CONFIG_QUOTA is not set
933# CONFIG_AUTOFS_FS is not set
934# CONFIG_AUTOFS4_FS is not set
935# CONFIG_FUSE_FS is not set
936
937#
938# Caches
939#
940# CONFIG_FSCACHE is not set
941
942#
943# CD-ROM/DVD Filesystems
944#
945# CONFIG_ISO9660_FS is not set
946# CONFIG_UDF_FS is not set
947
948#
949# DOS/FAT/NT Filesystems
950#
951# CONFIG_MSDOS_FS is not set
952# CONFIG_VFAT_FS is not set
953# CONFIG_NTFS_FS is not set
954
955#
956# Pseudo filesystems
957#
958CONFIG_PROC_FS=y
959CONFIG_PROC_KCORE=y
960CONFIG_PROC_SYSCTL=y
961# CONFIG_PROC_PAGE_MONITOR is not set
962CONFIG_SYSFS=y
963CONFIG_TMPFS=y
964# CONFIG_TMPFS_POSIX_ACL is not set
965# CONFIG_HUGETLB_PAGE is not set
966# CONFIG_CONFIGFS_FS is not set
967CONFIG_MISC_FILESYSTEMS=y
968# CONFIG_ADFS_FS is not set
969# CONFIG_AFFS_FS is not set
970# CONFIG_HFS_FS is not set
971# CONFIG_HFSPLUS_FS is not set
972# CONFIG_BEFS_FS is not set
973# CONFIG_BFS_FS is not set
974# CONFIG_EFS_FS is not set
975CONFIG_JFFS2_FS=y
976CONFIG_JFFS2_FS_DEBUG=0
977CONFIG_JFFS2_FS_WRITEBUFFER=y
978# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
979CONFIG_JFFS2_SUMMARY=y
980# CONFIG_JFFS2_FS_XATTR is not set
981CONFIG_JFFS2_COMPRESSION_OPTIONS=y
982CONFIG_JFFS2_ZLIB=y
983# CONFIG_JFFS2_LZO is not set
984CONFIG_JFFS2_RTIME=y
985# CONFIG_JFFS2_RUBIN is not set
986# CONFIG_JFFS2_CMODE_NONE is not set
987CONFIG_JFFS2_CMODE_PRIORITY=y
988# CONFIG_JFFS2_CMODE_SIZE is not set
989# CONFIG_JFFS2_CMODE_FAVOURLZO is not set
990# CONFIG_CRAMFS is not set
991CONFIG_SQUASHFS=y
992# CONFIG_SQUASHFS_EMBEDDED is not set
993CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3
994# CONFIG_VXFS_FS is not set
995# CONFIG_MINIX_FS is not set
996# CONFIG_OMFS_FS is not set
997# CONFIG_HPFS_FS is not set
998# CONFIG_QNX4FS_FS is not set
999# CONFIG_ROMFS_FS is not set
1000# CONFIG_SYSV_FS is not set
1001# CONFIG_UFS_FS is not set
1002# CONFIG_NILFS2_FS is not set
1003CONFIG_NETWORK_FILESYSTEMS=y
1004# CONFIG_NFS_FS is not set
1005# CONFIG_NFSD is not set
1006# CONFIG_SMB_FS is not set
1007# CONFIG_CIFS is not set
1008# CONFIG_NCP_FS is not set
1009# CONFIG_CODA_FS is not set
1010# CONFIG_AFS_FS is not set
1011
1012#
1013# Partition Types
1014#
1015CONFIG_PARTITION_ADVANCED=y
1016# CONFIG_ACORN_PARTITION is not set
1017# CONFIG_OSF_PARTITION is not set
1018# CONFIG_AMIGA_PARTITION is not set
1019# CONFIG_ATARI_PARTITION is not set
1020# CONFIG_MAC_PARTITION is not set
1021CONFIG_MSDOS_PARTITION=y
1022CONFIG_BSD_DISKLABEL=y
1023# CONFIG_MINIX_SUBPARTITION is not set
1024# CONFIG_SOLARIS_X86_PARTITION is not set
1025# CONFIG_UNIXWARE_DISKLABEL is not set
1026# CONFIG_LDM_PARTITION is not set
1027# CONFIG_SGI_PARTITION is not set
1028# CONFIG_ULTRIX_PARTITION is not set
1029# CONFIG_SUN_PARTITION is not set
1030# CONFIG_KARMA_PARTITION is not set
1031# CONFIG_EFI_PARTITION is not set
1032# CONFIG_SYSV68_PARTITION is not set
1033# CONFIG_NLS is not set
1034# CONFIG_DLM is not set
1035
1036#
1037# Kernel hacking
1038#
1039CONFIG_TRACE_IRQFLAGS_SUPPORT=y
1040# CONFIG_PRINTK_TIME is not set
1041CONFIG_ENABLE_WARN_DEPRECATED=y
1042# CONFIG_ENABLE_MUST_CHECK is not set
1043CONFIG_FRAME_WARN=1024
1044# CONFIG_MAGIC_SYSRQ is not set
1045# CONFIG_UNUSED_SYMBOLS is not set
1046CONFIG_DEBUG_FS=y
1047# CONFIG_HEADERS_CHECK is not set
1048# CONFIG_DEBUG_KERNEL is not set
1049# CONFIG_DEBUG_MEMORY_INIT is not set
1050# CONFIG_RCU_CPU_STALL_DETECTOR is not set
1051CONFIG_SYSCTL_SYSCALL_CHECK=y
1052CONFIG_TRACING_SUPPORT=y
1053# CONFIG_FTRACE is not set
1054# CONFIG_DYNAMIC_DEBUG is not set
1055# CONFIG_SAMPLES is not set
1056CONFIG_HAVE_ARCH_KGDB=y
1057CONFIG_CMDLINE="rootfstype=squashfs,jffs2"
1058
1059#
1060# Security options
1061#
1062# CONFIG_KEYS is not set
1063# CONFIG_SECURITY is not set
1064# CONFIG_SECURITYFS is not set
1065# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1066CONFIG_CRYPTO=y
1067
1068#
1069# Crypto core or helper
1070#
1071# CONFIG_CRYPTO_FIPS is not set
1072CONFIG_CRYPTO_ALGAPI=m
1073CONFIG_CRYPTO_ALGAPI2=m
1074CONFIG_CRYPTO_AEAD2=m
1075CONFIG_CRYPTO_BLKCIPHER=m
1076CONFIG_CRYPTO_BLKCIPHER2=m
1077CONFIG_CRYPTO_HASH2=m
1078CONFIG_CRYPTO_RNG2=m
1079CONFIG_CRYPTO_PCOMP=m
1080CONFIG_CRYPTO_MANAGER=m
1081CONFIG_CRYPTO_MANAGER2=m
1082# CONFIG_CRYPTO_GF128MUL is not set
1083# CONFIG_CRYPTO_NULL is not set
1084CONFIG_CRYPTO_WORKQUEUE=m
1085# CONFIG_CRYPTO_CRYPTD is not set
1086# CONFIG_CRYPTO_AUTHENC is not set
1087# CONFIG_CRYPTO_TEST is not set
1088
1089#
1090# Authenticated Encryption with Associated Data
1091#
1092# CONFIG_CRYPTO_CCM is not set
1093# CONFIG_CRYPTO_GCM is not set
1094# CONFIG_CRYPTO_SEQIV is not set
1095
1096#
1097# Block modes
1098#
1099# CONFIG_CRYPTO_CBC is not set
1100# CONFIG_CRYPTO_CTR is not set
1101# CONFIG_CRYPTO_CTS is not set
1102CONFIG_CRYPTO_ECB=m
1103# CONFIG_CRYPTO_LRW is not set
1104# CONFIG_CRYPTO_PCBC is not set
1105# CONFIG_CRYPTO_XTS is not set
1106
1107#
1108# Hash modes
1109#
1110# CONFIG_CRYPTO_HMAC is not set
1111# CONFIG_CRYPTO_XCBC is not set
1112
1113#
1114# Digest
1115#
1116# CONFIG_CRYPTO_CRC32C is not set
1117# CONFIG_CRYPTO_MD4 is not set
1118# CONFIG_CRYPTO_MD5 is not set
1119# CONFIG_CRYPTO_MICHAEL_MIC is not set
1120# CONFIG_CRYPTO_RMD128 is not set
1121# CONFIG_CRYPTO_RMD160 is not set
1122# CONFIG_CRYPTO_RMD256 is not set
1123# CONFIG_CRYPTO_RMD320 is not set
1124# CONFIG_CRYPTO_SHA1 is not set
1125# CONFIG_CRYPTO_SHA256 is not set
1126# CONFIG_CRYPTO_SHA512 is not set
1127# CONFIG_CRYPTO_TGR192 is not set
1128# CONFIG_CRYPTO_WP512 is not set
1129
1130#
1131# Ciphers
1132#
1133CONFIG_CRYPTO_AES=m
1134# CONFIG_CRYPTO_ANUBIS is not set
1135CONFIG_CRYPTO_ARC4=m
1136# CONFIG_CRYPTO_BLOWFISH is not set
1137# CONFIG_CRYPTO_CAMELLIA is not set
1138# CONFIG_CRYPTO_CAST5 is not set
1139# CONFIG_CRYPTO_CAST6 is not set
1140# CONFIG_CRYPTO_DES is not set
1141# CONFIG_CRYPTO_FCRYPT is not set
1142# CONFIG_CRYPTO_KHAZAD is not set
1143# CONFIG_CRYPTO_SALSA20 is not set
1144# CONFIG_CRYPTO_SEED is not set
1145# CONFIG_CRYPTO_SERPENT is not set
1146# CONFIG_CRYPTO_TEA is not set
1147# CONFIG_CRYPTO_TWOFISH is not set
1148
1149#
1150# Compression
1151#
1152# CONFIG_CRYPTO_DEFLATE is not set
1153# CONFIG_CRYPTO_ZLIB is not set
1154# CONFIG_CRYPTO_LZO is not set
1155
1156#
1157# Random Number Generation
1158#
1159# CONFIG_CRYPTO_ANSI_CPRNG is not set
1160# CONFIG_CRYPTO_HW is not set
1161# CONFIG_BINARY_PRINTF is not set
1162
1163#
1164# Library routines
1165#
1166CONFIG_BITREVERSE=y
1167CONFIG_GENERIC_FIND_LAST_BIT=y
1168CONFIG_CRC_CCITT=m
1169# CONFIG_CRC16 is not set
1170# CONFIG_CRC_T10DIF is not set
1171# CONFIG_CRC_ITU_T is not set
1172CONFIG_CRC32=y
1173# CONFIG_CRC7 is not set
1174# CONFIG_LIBCRC32C is not set
1175CONFIG_ZLIB_INFLATE=y
1176CONFIG_ZLIB_DEFLATE=y
1177CONFIG_DECOMPRESS_GZIP=y
1178CONFIG_DECOMPRESS_LZMA=y
1179CONFIG_HAS_IOMEM=y
1180CONFIG_HAS_IOPORT=y
1181CONFIG_HAS_DMA=y
1182CONFIG_NLATTR=y
diff --git a/arch/mips/gt64120/wrppmc/serial.c b/arch/mips/gt64120/wrppmc/serial.c
index 5ec1c2ffd3a5..6f9d0858f596 100644
--- a/arch/mips/gt64120/wrppmc/serial.c
+++ b/arch/mips/gt64120/wrppmc/serial.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Registration of WRPPMC UART platform device. 2 * Registration of WRPPMC UART platform device.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/include/asm/amon.h b/arch/mips/include/asm/amon.h
new file mode 100644
index 000000000000..c3dc1a68dd8d
--- /dev/null
+++ b/arch/mips/include/asm/amon.h
@@ -0,0 +1,7 @@
1/*
2 * Amon support
3 */
4
5int amon_cpu_avail(int);
6void amon_cpu_start(int, unsigned long, unsigned long,
7 unsigned long, unsigned long);
diff --git a/arch/mips/include/asm/ds1287.h b/arch/mips/include/asm/ds1287.h
index ba1702e86931..3af0b8fb3b8c 100644
--- a/arch/mips/include/asm/ds1287.h
+++ b/arch/mips/include/asm/ds1287.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * DS1287 timer functions. 2 * DS1287 timer functions.
3 * 3 *
4 * Copyright (C) 2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
index d58f128aa747..7990694cda22 100644
--- a/arch/mips/include/asm/elf.h
+++ b/arch/mips/include/asm/elf.h
@@ -316,9 +316,13 @@ extern void elf_dump_regs(elf_greg_t *, struct pt_regs *regs);
316extern int dump_task_regs(struct task_struct *, elf_gregset_t *); 316extern int dump_task_regs(struct task_struct *, elf_gregset_t *);
317extern int dump_task_fpu(struct task_struct *, elf_fpregset_t *); 317extern int dump_task_fpu(struct task_struct *, elf_fpregset_t *);
318 318
319#ifndef ELF_CORE_COPY_REGS
319#define ELF_CORE_COPY_REGS(elf_regs, regs) \ 320#define ELF_CORE_COPY_REGS(elf_regs, regs) \
320 elf_dump_regs((elf_greg_t *)&(elf_regs), regs); 321 elf_dump_regs((elf_greg_t *)&(elf_regs), regs);
322#endif
323#ifndef ELF_CORE_COPY_TASK_REGS
321#define ELF_CORE_COPY_TASK_REGS(tsk, elf_regs) dump_task_regs(tsk, elf_regs) 324#define ELF_CORE_COPY_TASK_REGS(tsk, elf_regs) dump_task_regs(tsk, elf_regs)
325#endif
322#define ELF_CORE_COPY_FPREGS(tsk, elf_fpregs) \ 326#define ELF_CORE_COPY_FPREGS(tsk, elf_fpregs) \
323 dump_task_fpu(tsk, elf_fpregs) 327 dump_task_fpu(tsk, elf_fpregs)
324 328
diff --git a/arch/mips/include/asm/gcmpregs.h b/arch/mips/include/asm/gcmpregs.h
index d74a8a4ca861..36fd969d64d6 100644
--- a/arch/mips/include/asm/gcmpregs.h
+++ b/arch/mips/include/asm/gcmpregs.h
@@ -114,4 +114,6 @@
114#define GCMP_CCB_DINTGROUP_OFS 0x0030 /* DINT Group Participate */ 114#define GCMP_CCB_DINTGROUP_OFS 0x0030 /* DINT Group Participate */
115#define GCMP_CCB_DBGGROUP_OFS 0x0100 /* DebugBreak Group */ 115#define GCMP_CCB_DBGGROUP_OFS 0x0100 /* DebugBreak Group */
116 116
117extern int __init gcmp_probe(unsigned long, unsigned long);
118
117#endif /* _ASM_GCMPREGS_H */ 119#endif /* _ASM_GCMPREGS_H */
diff --git a/arch/mips/include/asm/gic.h b/arch/mips/include/asm/gic.h
index 954807d9d66a..10292e37c1f7 100644
--- a/arch/mips/include/asm/gic.h
+++ b/arch/mips/include/asm/gic.h
@@ -20,7 +20,11 @@
20#define GIC_TRIG_EDGE 1 20#define GIC_TRIG_EDGE 1
21#define GIC_TRIG_LEVEL 0 21#define GIC_TRIG_LEVEL 0
22 22
23#if CONFIG_SMP
24#define GIC_NUM_INTRS (24 + NR_CPUS * 2)
25#else
23#define GIC_NUM_INTRS 32 26#define GIC_NUM_INTRS 32
27#endif
24 28
25#define MSK(n) ((1 << (n)) - 1) 29#define MSK(n) ((1 << (n)) - 1)
26#define REG32(addr) (*(volatile unsigned int *) (addr)) 30#define REG32(addr) (*(volatile unsigned int *) (addr))
@@ -483,5 +487,7 @@ extern void gic_init(unsigned long gic_base_addr,
483 487
484extern unsigned int gic_get_int(void); 488extern unsigned int gic_get_int(void);
485extern void gic_send_ipi(unsigned int intr); 489extern void gic_send_ipi(unsigned int intr);
490extern unsigned int plat_ipi_call_int_xlate(unsigned int);
491extern unsigned int plat_ipi_resched_int_xlate(unsigned int);
486 492
487#endif /* _ASM_GICREGS_H */ 493#endif /* _ASM_GICREGS_H */
diff --git a/arch/mips/include/asm/irq_gt641xx.h b/arch/mips/include/asm/irq_gt641xx.h
index f9a7c3ac2e66..250a2407b599 100644
--- a/arch/mips/include/asm/irq_gt641xx.h
+++ b/arch/mips/include/asm/irq_gt641xx.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Galileo/Marvell GT641xx IRQ definitions. 2 * Galileo/Marvell GT641xx IRQ definitions.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/include/asm/mach-ar7/ar7.h b/arch/mips/include/asm/mach-ar7/ar7.h
new file mode 100644
index 000000000000..de71694614de
--- /dev/null
+++ b/arch/mips/include/asm/mach-ar7/ar7.h
@@ -0,0 +1,178 @@
1/*
2 * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
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 as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef __AR7_H__
21#define __AR7_H__
22
23#include <linux/delay.h>
24#include <linux/io.h>
25#include <linux/errno.h>
26
27#include <asm/addrspace.h>
28
29#define AR7_SDRAM_BASE 0x14000000
30
31#define AR7_REGS_BASE 0x08610000
32
33#define AR7_REGS_MAC0 (AR7_REGS_BASE + 0x0000)
34#define AR7_REGS_GPIO (AR7_REGS_BASE + 0x0900)
35/* 0x08610A00 - 0x08610BFF (512 bytes, 128 bytes / clock) */
36#define AR7_REGS_POWER (AR7_REGS_BASE + 0x0a00)
37#define AR7_REGS_CLOCKS (AR7_REGS_POWER + 0x80)
38#define UR8_REGS_CLOCKS (AR7_REGS_POWER + 0x20)
39#define AR7_REGS_UART0 (AR7_REGS_BASE + 0x0e00)
40#define AR7_REGS_USB (AR7_REGS_BASE + 0x1200)
41#define AR7_REGS_RESET (AR7_REGS_BASE + 0x1600)
42#define AR7_REGS_VLYNQ0 (AR7_REGS_BASE + 0x1800)
43#define AR7_REGS_DCL (AR7_REGS_BASE + 0x1a00)
44#define AR7_REGS_VLYNQ1 (AR7_REGS_BASE + 0x1c00)
45#define AR7_REGS_MDIO (AR7_REGS_BASE + 0x1e00)
46#define AR7_REGS_IRQ (AR7_REGS_BASE + 0x2400)
47#define AR7_REGS_MAC1 (AR7_REGS_BASE + 0x2800)
48
49#define AR7_REGS_WDT (AR7_REGS_BASE + 0x1f00)
50#define UR8_REGS_WDT (AR7_REGS_BASE + 0x0b00)
51#define UR8_REGS_UART1 (AR7_REGS_BASE + 0x0f00)
52
53#define AR7_RESET_PEREPHERIAL 0x0
54#define AR7_RESET_SOFTWARE 0x4
55#define AR7_RESET_STATUS 0x8
56
57#define AR7_RESET_BIT_CPMAC_LO 17
58#define AR7_RESET_BIT_CPMAC_HI 21
59#define AR7_RESET_BIT_MDIO 22
60#define AR7_RESET_BIT_EPHY 26
61
62/* GPIO control registers */
63#define AR7_GPIO_INPUT 0x0
64#define AR7_GPIO_OUTPUT 0x4
65#define AR7_GPIO_DIR 0x8
66#define AR7_GPIO_ENABLE 0xc
67
68#define AR7_CHIP_7100 0x18
69#define AR7_CHIP_7200 0x2b
70#define AR7_CHIP_7300 0x05
71
72/* Interrupts */
73#define AR7_IRQ_UART0 15
74#define AR7_IRQ_UART1 16
75
76/* Clocks */
77#define AR7_AFE_CLOCK 35328000
78#define AR7_REF_CLOCK 25000000
79#define AR7_XTAL_CLOCK 24000000
80
81struct plat_cpmac_data {
82 int reset_bit;
83 int power_bit;
84 u32 phy_mask;
85 char dev_addr[6];
86};
87
88struct plat_dsl_data {
89 int reset_bit_dsl;
90 int reset_bit_sar;
91};
92
93extern int ar7_cpu_clock, ar7_bus_clock, ar7_dsp_clock;
94
95static inline u16 ar7_chip_id(void)
96{
97 return readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x14)) & 0xffff;
98}
99
100static inline u8 ar7_chip_rev(void)
101{
102 return (readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x14)) >> 16) & 0xff;
103}
104
105static inline int ar7_cpu_freq(void)
106{
107 return ar7_cpu_clock;
108}
109
110static inline int ar7_bus_freq(void)
111{
112 return ar7_bus_clock;
113}
114
115static inline int ar7_vbus_freq(void)
116{
117 return ar7_bus_clock / 2;
118}
119#define ar7_cpmac_freq ar7_vbus_freq
120
121static inline int ar7_dsp_freq(void)
122{
123 return ar7_dsp_clock;
124}
125
126static inline int ar7_has_high_cpmac(void)
127{
128 u16 chip_id = ar7_chip_id();
129 switch (chip_id) {
130 case AR7_CHIP_7100:
131 case AR7_CHIP_7200:
132 return 0;
133 case AR7_CHIP_7300:
134 return 1;
135 default:
136 return -ENXIO;
137 }
138}
139#define ar7_has_high_vlynq ar7_has_high_cpmac
140#define ar7_has_second_uart ar7_has_high_cpmac
141
142static inline void ar7_device_enable(u32 bit)
143{
144 void *reset_reg =
145 (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PEREPHERIAL);
146 writel(readl(reset_reg) | (1 << bit), reset_reg);
147 msleep(20);
148}
149
150static inline void ar7_device_disable(u32 bit)
151{
152 void *reset_reg =
153 (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PEREPHERIAL);
154 writel(readl(reset_reg) & ~(1 << bit), reset_reg);
155 msleep(20);
156}
157
158static inline void ar7_device_reset(u32 bit)
159{
160 ar7_device_disable(bit);
161 ar7_device_enable(bit);
162}
163
164static inline void ar7_device_on(u32 bit)
165{
166 void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
167 writel(readl(power_reg) | (1 << bit), power_reg);
168 msleep(20);
169}
170
171static inline void ar7_device_off(u32 bit)
172{
173 void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
174 writel(readl(power_reg) & ~(1 << bit), power_reg);
175 msleep(20);
176}
177
178#endif /* __AR7_H__ */
diff --git a/arch/mips/include/asm/mach-ar7/gpio.h b/arch/mips/include/asm/mach-ar7/gpio.h
new file mode 100644
index 000000000000..cbe9c4f126df
--- /dev/null
+++ b/arch/mips/include/asm/mach-ar7/gpio.h
@@ -0,0 +1,110 @@
1/*
2 * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef __AR7_GPIO_H__
20#define __AR7_GPIO_H__
21
22#include <asm/mach-ar7/ar7.h>
23
24#define AR7_GPIO_MAX 32
25
26extern int gpio_request(unsigned gpio, const char *label);
27extern void gpio_free(unsigned gpio);
28
29/* Common GPIO layer */
30static inline int gpio_get_value(unsigned gpio)
31{
32 void __iomem *gpio_in =
33 (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_INPUT);
34
35 return readl(gpio_in) & (1 << gpio);
36}
37
38static inline void gpio_set_value(unsigned gpio, int value)
39{
40 void __iomem *gpio_out =
41 (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_OUTPUT);
42 unsigned tmp;
43
44 tmp = readl(gpio_out) & ~(1 << gpio);
45 if (value)
46 tmp |= 1 << gpio;
47 writel(tmp, gpio_out);
48}
49
50static inline int gpio_direction_input(unsigned gpio)
51{
52 void __iomem *gpio_dir =
53 (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
54
55 if (gpio >= AR7_GPIO_MAX)
56 return -EINVAL;
57
58 writel(readl(gpio_dir) | (1 << gpio), gpio_dir);
59
60 return 0;
61}
62
63static inline int gpio_direction_output(unsigned gpio, int value)
64{
65 void __iomem *gpio_dir =
66 (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_DIR);
67
68 if (gpio >= AR7_GPIO_MAX)
69 return -EINVAL;
70
71 gpio_set_value(gpio, value);
72 writel(readl(gpio_dir) & ~(1 << gpio), gpio_dir);
73
74 return 0;
75}
76
77static inline int gpio_to_irq(unsigned gpio)
78{
79 return -EINVAL;
80}
81
82static inline int irq_to_gpio(unsigned irq)
83{
84 return -EINVAL;
85}
86
87/* Board specific GPIO functions */
88static inline int ar7_gpio_enable(unsigned gpio)
89{
90 void __iomem *gpio_en =
91 (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
92
93 writel(readl(gpio_en) | (1 << gpio), gpio_en);
94
95 return 0;
96}
97
98static inline int ar7_gpio_disable(unsigned gpio)
99{
100 void __iomem *gpio_en =
101 (void __iomem *)KSEG1ADDR(AR7_REGS_GPIO + AR7_GPIO_ENABLE);
102
103 writel(readl(gpio_en) & ~(1 << gpio), gpio_en);
104
105 return 0;
106}
107
108#include <asm-generic/gpio.h>
109
110#endif
diff --git a/arch/mips/include/asm/mach-ar7/irq.h b/arch/mips/include/asm/mach-ar7/irq.h
new file mode 100644
index 000000000000..39e9757e3d93
--- /dev/null
+++ b/arch/mips/include/asm/mach-ar7/irq.h
@@ -0,0 +1,16 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Shamelessly copied from asm-mips/mach-emma2rh/
7 * Copyright (C) 2003 by Ralf Baechle
8 */
9#ifndef __ASM_AR7_IRQ_H
10#define __ASM_AR7_IRQ_H
11
12#define NR_IRQS 256
13
14#include_next <irq.h>
15
16#endif /* __ASM_AR7_IRQ_H */
diff --git a/arch/mips/include/asm/mach-ar7/prom.h b/arch/mips/include/asm/mach-ar7/prom.h
new file mode 100644
index 000000000000..088f61fe85ea
--- /dev/null
+++ b/arch/mips/include/asm/mach-ar7/prom.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2006, 2007 Florian Fainelli <florian@openwrt.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef __PROM_H__
20#define __PROM_H__
21
22extern char *prom_getenv(const char *name);
23extern void prom_meminit(void);
24
25#endif /* __PROM_H__ */
diff --git a/arch/mips/include/asm/mach-ar7/spaces.h b/arch/mips/include/asm/mach-ar7/spaces.h
new file mode 100644
index 000000000000..ac28f273449c
--- /dev/null
+++ b/arch/mips/include/asm/mach-ar7/spaces.h
@@ -0,0 +1,22 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1994 - 1999, 2000, 03, 04 Ralf Baechle
7 * Copyright (C) 2000, 2002 Maciej W. Rozycki
8 * Copyright (C) 1990, 1999, 2000 Silicon Graphics, Inc.
9 */
10#ifndef _ASM_AR7_SPACES_H
11#define _ASM_AR7_SPACES_H
12
13/*
14 * This handles the memory map.
15 * We handle pages at KSEG0 for kernels with 32 bit address space.
16 */
17#define PAGE_OFFSET 0x94000000UL
18#define PHYS_OFFSET 0x14000000UL
19
20#include <asm/mach-generic/spaces.h>
21
22#endif /* __ASM_AR7_SPACES_H */
diff --git a/arch/mips/include/asm/mach-ar7/war.h b/arch/mips/include/asm/mach-ar7/war.h
new file mode 100644
index 000000000000..f4862b563080
--- /dev/null
+++ b/arch/mips/include/asm/mach-ar7/war.h
@@ -0,0 +1,25 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2002, 2004, 2007 by Ralf Baechle <ralf@linux-mips.org>
7 */
8#ifndef __ASM_MIPS_MACH_AR7_WAR_H
9#define __ASM_MIPS_MACH_AR7_WAR_H
10
11#define R4600_V1_INDEX_ICACHEOP_WAR 0
12#define R4600_V1_HIT_CACHEOP_WAR 0
13#define R4600_V2_HIT_CACHEOP_WAR 0
14#define R5432_CP0_INTERRUPT_WAR 0
15#define BCM1250_M3_WAR 0
16#define SIBYTE_1956_WAR 0
17#define MIPS4K_ICACHE_REFILL_WAR 0
18#define MIPS_CACHE_SYNC_WAR 0
19#define TX49XX_ICACHE_INDEX_INV_WAR 0
20#define RM9000_CDEX_SMP_WAR 0
21#define ICACHE_REFILLS_WORKAROUND_WAR 0
22#define R10000_LLSC_WAR 0
23#define MIPS34K_MISSED_ITLB_WAR 0
24
25#endif /* __ASM_MIPS_MACH_AR7_WAR_H */
diff --git a/arch/mips/include/asm/mach-cobalt/irq.h b/arch/mips/include/asm/mach-cobalt/irq.h
index 57c8c9ac5851..9da9acf5dcba 100644
--- a/arch/mips/include/asm/mach-cobalt/irq.h
+++ b/arch/mips/include/asm/mach-cobalt/irq.h
@@ -8,7 +8,7 @@
8 * Copyright (C) 1997 Cobalt Microserver 8 * Copyright (C) 1997 Cobalt Microserver
9 * Copyright (C) 1997, 2003 Ralf Baechle 9 * Copyright (C) 1997, 2003 Ralf Baechle
10 * Copyright (C) 2001-2003 Liam Davies (ldavies@agile.tv) 10 * Copyright (C) 2001-2003 Liam Davies (ldavies@agile.tv)
11 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 11 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
12 */ 12 */
13#ifndef _ASM_COBALT_IRQ_H 13#ifndef _ASM_COBALT_IRQ_H
14#define _ASM_COBALT_IRQ_H 14#define _ASM_COBALT_IRQ_H
diff --git a/arch/mips/include/asm/mach-cobalt/mach-gt64120.h b/arch/mips/include/asm/mach-cobalt/mach-gt64120.h
index ae9c5523c7ef..f8afec3f2943 100644
--- a/arch/mips/include/asm/mach-cobalt/mach-gt64120.h
+++ b/arch/mips/include/asm/mach-cobalt/mach-gt64120.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 2 * Copyright (C) 2006 Yoichi Yuasa <yuasa@linux-mips.org>
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/cavium-octeon/pci-common.h b/arch/mips/include/asm/octeon/pci-octeon.h
index 74ae79991e45..6ac5d3e3398e 100644
--- a/arch/mips/cavium-octeon/pci-common.h
+++ b/arch/mips/include/asm/octeon/pci-octeon.h
@@ -3,23 +3,29 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (C) 2005-2007 Cavium Networks 6 * Copyright (C) 2005-2009 Cavium Networks
7 */ 7 */
8#ifndef __OCTEON_PCI_COMMON_H__ 8
9#define __OCTEON_PCI_COMMON_H__ 9#ifndef __PCI_OCTEON_H__
10#define __PCI_OCTEON_H__
10 11
11#include <linux/pci.h> 12#include <linux/pci.h>
12 13
13/* Some PCI cards require delays when accessing config space. */ 14/* Some PCI cards require delays when accessing config space. */
14#define PCI_CONFIG_SPACE_DELAY 10000 15#define PCI_CONFIG_SPACE_DELAY 10000
15 16
16/* pcibios_map_irq() is defined inside pci-common.c. All it does is call the 17/*
17 Octeon specific version pointed to by this variable. This function needs to 18 * pcibios_map_irq() is defined inside pci-octeon.c. All it does is
18 change for PCI or PCIe based hosts */ 19 * call the Octeon specific version pointed to by this variable. This
19extern typeof(pcibios_map_irq) *octeon_pcibios_map_irq; 20 * function needs to change for PCI or PCIe based hosts.
21 */
22extern int (*octeon_pcibios_map_irq)(const struct pci_dev *dev,
23 u8 slot, u8 pin);
20 24
21/* The following defines are only used when octeon_dma_bar_type = 25/*
22 OCTEON_DMA_BAR_TYPE_BIG */ 26 * The following defines are used when octeon_dma_bar_type =
27 * OCTEON_DMA_BAR_TYPE_BIG
28 */
23#define OCTEON_PCI_BAR1_HOLE_BITS 5 29#define OCTEON_PCI_BAR1_HOLE_BITS 5
24#define OCTEON_PCI_BAR1_HOLE_SIZE (1ul<<(OCTEON_PCI_BAR1_HOLE_BITS+3)) 30#define OCTEON_PCI_BAR1_HOLE_SIZE (1ul<<(OCTEON_PCI_BAR1_HOLE_BITS+3))
25 31
@@ -30,9 +36,9 @@ enum octeon_dma_bar_type {
30 OCTEON_DMA_BAR_TYPE_PCIE 36 OCTEON_DMA_BAR_TYPE_PCIE
31}; 37};
32 38
33/** 39/*
34 * This is a variable to tell the DMA mapping system in dma-octeon.c 40 * This tells the DMA mapping system in dma-octeon.c how to map PCI
35 * how to map PCI DMA addresses. 41 * DMA addresses.
36 */ 42 */
37extern enum octeon_dma_bar_type octeon_dma_bar_type; 43extern enum octeon_dma_bar_type octeon_dma_bar_type;
38 44
diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
index dc0eaa731281..96a14a426a7c 100644
--- a/arch/mips/include/asm/page.h
+++ b/arch/mips/include/asm/page.h
@@ -165,7 +165,14 @@ typedef struct { unsigned long pgprot; } pgprot_t;
165 165
166#ifdef CONFIG_FLATMEM 166#ifdef CONFIG_FLATMEM
167 167
168#define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && (pfn) < max_mapnr) 168#define pfn_valid(pfn) \
169({ \
170 unsigned long __pfn = (pfn); \
171 /* avoid <linux/bootmem.h> include hell */ \
172 extern unsigned long min_low_pfn; \
173 \
174 __pfn >= min_low_pfn && __pfn < max_mapnr; \
175})
169 176
170#elif defined(CONFIG_SPARSEMEM) 177#elif defined(CONFIG_SPARSEMEM)
171 178
diff --git a/arch/mips/include/asm/reg.h b/arch/mips/include/asm/reg.h
index 634b55d7e7f6..910e71a12466 100644
--- a/arch/mips/include/asm/reg.h
+++ b/arch/mips/include/asm/reg.h
@@ -69,7 +69,7 @@
69 69
70#endif 70#endif
71 71
72#ifdef CONFIG_64BIT 72#if defined(CONFIG_64BIT) && !defined(WANT_COMPAT_REG_H)
73 73
74#define EF_R0 0 74#define EF_R0 0
75#define EF_R1 1 75#define EF_R1 1
diff --git a/arch/mips/include/asm/swab.h b/arch/mips/include/asm/swab.h
index 99993c0d6c12..97c2f81b4b43 100644
--- a/arch/mips/include/asm/swab.h
+++ b/arch/mips/include/asm/swab.h
@@ -38,7 +38,11 @@ static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
38} 38}
39#define __arch_swab32 __arch_swab32 39#define __arch_swab32 __arch_swab32
40 40
41#ifdef CONFIG_CPU_MIPS64_R2 41/*
42 * Having already checked for CONFIG_CPU_MIPSR2, enable the
43 * optimized version for 64-bit kernel on r2 CPUs.
44 */
45#ifdef CONFIG_64BIT
42static inline __attribute_const__ __u64 __arch_swab64(__u64 x) 46static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
43{ 47{
44 __asm__( 48 __asm__(
@@ -50,6 +54,6 @@ static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
50 return x; 54 return x;
51} 55}
52#define __arch_swab64 __arch_swab64 56#define __arch_swab64 __arch_swab64
53#endif /* CONFIG_CPU_MIPS64_R2 */ 57#endif /* CONFIG_64BIT */
54#endif /* CONFIG_CPU_MIPSR2 */ 58#endif /* CONFIG_CPU_MIPSR2 */
55#endif /* _ASM_SWAB_H */ 59#endif /* _ASM_SWAB_H */
diff --git a/arch/mips/include/asm/unistd.h b/arch/mips/include/asm/unistd.h
index 40005010827c..b70c49fdda26 100644
--- a/arch/mips/include/asm/unistd.h
+++ b/arch/mips/include/asm/unistd.h
@@ -352,16 +352,18 @@
352#define __NR_inotify_init1 (__NR_Linux + 329) 352#define __NR_inotify_init1 (__NR_Linux + 329)
353#define __NR_preadv (__NR_Linux + 330) 353#define __NR_preadv (__NR_Linux + 330)
354#define __NR_pwritev (__NR_Linux + 331) 354#define __NR_pwritev (__NR_Linux + 331)
355#define __NR_rt_tgsigqueueinfo (__NR_Linux + 332)
356#define __NR_perf_counter_open (__NR_Linux + 333)
355 357
356/* 358/*
357 * Offset of the last Linux o32 flavoured syscall 359 * Offset of the last Linux o32 flavoured syscall
358 */ 360 */
359#define __NR_Linux_syscalls 331 361#define __NR_Linux_syscalls 333
360 362
361#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */ 363#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */
362 364
363#define __NR_O32_Linux 4000 365#define __NR_O32_Linux 4000
364#define __NR_O32_Linux_syscalls 331 366#define __NR_O32_Linux_syscalls 333
365 367
366#if _MIPS_SIM == _MIPS_SIM_ABI64 368#if _MIPS_SIM == _MIPS_SIM_ABI64
367 369
@@ -660,16 +662,18 @@
660#define __NR_inotify_init1 (__NR_Linux + 288) 662#define __NR_inotify_init1 (__NR_Linux + 288)
661#define __NR_preadv (__NR_Linux + 289) 663#define __NR_preadv (__NR_Linux + 289)
662#define __NR_pwritev (__NR_Linux + 290) 664#define __NR_pwritev (__NR_Linux + 290)
665#define __NR_rt_tgsigqueueinfo (__NR_Linux + 291)
666#define __NR_perf_counter_open (__NR_Linux + 292)
663 667
664/* 668/*
665 * Offset of the last Linux 64-bit flavoured syscall 669 * Offset of the last Linux 64-bit flavoured syscall
666 */ 670 */
667#define __NR_Linux_syscalls 290 671#define __NR_Linux_syscalls 292
668 672
669#endif /* _MIPS_SIM == _MIPS_SIM_ABI64 */ 673#endif /* _MIPS_SIM == _MIPS_SIM_ABI64 */
670 674
671#define __NR_64_Linux 5000 675#define __NR_64_Linux 5000
672#define __NR_64_Linux_syscalls 290 676#define __NR_64_Linux_syscalls 292
673 677
674#if _MIPS_SIM == _MIPS_SIM_NABI32 678#if _MIPS_SIM == _MIPS_SIM_NABI32
675 679
@@ -972,16 +976,18 @@
972#define __NR_inotify_init1 (__NR_Linux + 292) 976#define __NR_inotify_init1 (__NR_Linux + 292)
973#define __NR_preadv (__NR_Linux + 293) 977#define __NR_preadv (__NR_Linux + 293)
974#define __NR_pwritev (__NR_Linux + 294) 978#define __NR_pwritev (__NR_Linux + 294)
979#define __NR_rt_tgsigqueueinfo (__NR_Linux + 295)
980#define __NR_perf_counter_open (__NR_Linux + 296)
975 981
976/* 982/*
977 * Offset of the last N32 flavoured syscall 983 * Offset of the last N32 flavoured syscall
978 */ 984 */
979#define __NR_Linux_syscalls 294 985#define __NR_Linux_syscalls 296
980 986
981#endif /* _MIPS_SIM == _MIPS_SIM_NABI32 */ 987#endif /* _MIPS_SIM == _MIPS_SIM_NABI32 */
982 988
983#define __NR_N32_Linux 6000 989#define __NR_N32_Linux 6000
984#define __NR_N32_Linux_syscalls 294 990#define __NR_N32_Linux_syscalls 296
985 991
986#ifdef __KERNEL__ 992#ifdef __KERNEL__
987 993
diff --git a/arch/mips/include/asm/vr41xx/capcella.h b/arch/mips/include/asm/vr41xx/capcella.h
index e0ee05a3dfcc..fcc6569414fa 100644
--- a/arch/mips/include/asm/vr41xx/capcella.h
+++ b/arch/mips/include/asm/vr41xx/capcella.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * capcella.h, Include file for ZAO Networks Capcella. 2 * capcella.h, Include file for ZAO Networks Capcella.
3 * 3 *
4 * Copyright (C) 2002-2004 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2002-2004 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/include/asm/vr41xx/giu.h b/arch/mips/include/asm/vr41xx/giu.h
index 0bcdd3a5c256..6a90bc1d916b 100644
--- a/arch/mips/include/asm/vr41xx/giu.h
+++ b/arch/mips/include/asm/vr41xx/giu.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Include file for NEC VR4100 series General-purpose I/O Unit. 2 * Include file for NEC VR4100 series General-purpose I/O Unit.
3 * 3 *
4 * Copyright (C) 2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2005-2009 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -41,7 +41,8 @@ typedef enum {
41 IRQ_SIGNAL_HOLD, 41 IRQ_SIGNAL_HOLD,
42} irq_signal_t; 42} irq_signal_t;
43 43
44extern void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger, irq_signal_t signal); 44extern void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger,
45 irq_signal_t signal);
45 46
46typedef enum { 47typedef enum {
47 IRQ_LEVEL_LOW, 48 IRQ_LEVEL_LOW,
@@ -51,23 +52,6 @@ typedef enum {
51extern void vr41xx_set_irq_level(unsigned int pin, irq_level_t level); 52extern void vr41xx_set_irq_level(unsigned int pin, irq_level_t level);
52 53
53typedef enum { 54typedef enum {
54 GPIO_DATA_LOW,
55 GPIO_DATA_HIGH,
56 GPIO_DATA_INVAL,
57} gpio_data_t;
58
59extern gpio_data_t vr41xx_gpio_get_pin(unsigned int pin);
60extern int vr41xx_gpio_set_pin(unsigned int pin, gpio_data_t data);
61
62typedef enum {
63 GPIO_INPUT,
64 GPIO_OUTPUT,
65 GPIO_OUTPUT_DISABLE,
66} gpio_direction_t;
67
68extern int vr41xx_gpio_set_direction(unsigned int pin, gpio_direction_t dir);
69
70typedef enum {
71 GPIO_PULL_DOWN, 55 GPIO_PULL_DOWN,
72 GPIO_PULL_UP, 56 GPIO_PULL_UP,
73 GPIO_PULL_DISABLE, 57 GPIO_PULL_DISABLE,
diff --git a/arch/mips/include/asm/vr41xx/irq.h b/arch/mips/include/asm/vr41xx/irq.h
index d315dfbc08f2..b07f7321751d 100644
--- a/arch/mips/include/asm/vr41xx/irq.h
+++ b/arch/mips/include/asm/vr41xx/irq.h
@@ -7,7 +7,7 @@
7 * Copyright (C) 2001, 2002 Paul Mundt 7 * Copyright (C) 2001, 2002 Paul Mundt
8 * Copyright (C) 2002 MontaVista Software, Inc. 8 * Copyright (C) 2002 MontaVista Software, Inc.
9 * Copyright (C) 2002 TimeSys Corp. 9 * Copyright (C) 2002 TimeSys Corp.
10 * Copyright (C) 2003-2006 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 10 * Copyright (C) 2003-2006 Yoichi Yuasa <yuasa@linux-mips.org>
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify it 12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the 13 * under the terms of the GNU General Public License as published by the
diff --git a/arch/mips/include/asm/vr41xx/mpc30x.h b/arch/mips/include/asm/vr41xx/mpc30x.h
index 1d67df843dc3..130d09d8c8cb 100644
--- a/arch/mips/include/asm/vr41xx/mpc30x.h
+++ b/arch/mips/include/asm/vr41xx/mpc30x.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * mpc30x.h, Include file for Victor MP-C303/304. 2 * mpc30x.h, Include file for Victor MP-C303/304.
3 * 3 *
4 * Copyright (C) 2002-2004 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2002-2004 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/include/asm/vr41xx/pci.h b/arch/mips/include/asm/vr41xx/pci.h
index 6fc01ce19777..c231a3d6cfd8 100644
--- a/arch/mips/include/asm/vr41xx/pci.h
+++ b/arch/mips/include/asm/vr41xx/pci.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Include file for NEC VR4100 series PCI Control Unit. 2 * Include file for NEC VR4100 series PCI Control Unit.
3 * 3 *
4 * Copyright (C) 2004-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2004-2005 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/include/asm/vr41xx/siu.h b/arch/mips/include/asm/vr41xx/siu.h
index da9f6e373409..ca806bc4ddc8 100644
--- a/arch/mips/include/asm/vr41xx/siu.h
+++ b/arch/mips/include/asm/vr41xx/siu.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Include file for NEC VR4100 series Serial Interface Unit. 2 * Include file for NEC VR4100 series Serial Interface Unit.
3 * 3 *
4 * Copyright (C) 2005-2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2005-2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/include/asm/vr41xx/tb0219.h b/arch/mips/include/asm/vr41xx/tb0219.h
index dc981b4be0a4..c78e8243b447 100644
--- a/arch/mips/include/asm/vr41xx/tb0219.h
+++ b/arch/mips/include/asm/vr41xx/tb0219.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * tb0219.h, Include file for TANBAC TB0219. 2 * tb0219.h, Include file for TANBAC TB0219.
3 * 3 *
4 * Copyright (C) 2002-2004 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2002-2004 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * Modified for TANBAC TB0219: 6 * Modified for TANBAC TB0219:
7 * Copyright (C) 2003 Megasolution Inc. <matsu@megasolution.jp> 7 * Copyright (C) 2003 Megasolution Inc. <matsu@megasolution.jp>
diff --git a/arch/mips/include/asm/vr41xx/tb0226.h b/arch/mips/include/asm/vr41xx/tb0226.h
index de527dcfa5f3..36f5f798e416 100644
--- a/arch/mips/include/asm/vr41xx/tb0226.h
+++ b/arch/mips/include/asm/vr41xx/tb0226.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * tb0226.h, Include file for TANBAC TB0226. 2 * tb0226.h, Include file for TANBAC TB0226.
3 * 3 *
4 * Copyright (C) 2002-2004 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2002-2004 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/include/asm/vr41xx/vr41xx.h b/arch/mips/include/asm/vr41xx/vr41xx.h
index 22be64971cc6..7b96a43b72ba 100644
--- a/arch/mips/include/asm/vr41xx/vr41xx.h
+++ b/arch/mips/include/asm/vr41xx/vr41xx.h
@@ -7,7 +7,7 @@
7 * Copyright (C) 2001, 2002 Paul Mundt 7 * Copyright (C) 2001, 2002 Paul Mundt
8 * Copyright (C) 2002 MontaVista Software, Inc. 8 * Copyright (C) 2002 MontaVista Software, Inc.
9 * Copyright (C) 2002 TimeSys Corp. 9 * Copyright (C) 2002 TimeSys Corp.
10 * Copyright (C) 2003-2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 10 * Copyright (C) 2003-2008 Yoichi Yuasa <yuasa@linux-mips.org>
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify it 12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the 13 * under the terms of the GNU General Public License as published by the
diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
index e1333d7319e2..ff448233dab5 100644
--- a/arch/mips/kernel/binfmt_elfo32.c
+++ b/arch/mips/kernel/binfmt_elfo32.c
@@ -53,6 +53,23 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
53#define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2) 53#define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
54 54
55#include <asm/processor.h> 55#include <asm/processor.h>
56
57/*
58 * When this file is selected, we are definitely running a 64bit kernel.
59 * So using the right regs define in asm/reg.h
60 */
61#define WANT_COMPAT_REG_H
62
63/* These MUST be defined before elf.h gets included */
64extern void elf32_core_copy_regs(elf_gregset_t grp, struct pt_regs *regs);
65#define ELF_CORE_COPY_REGS(_dest, _regs) elf32_core_copy_regs(_dest, _regs);
66#define ELF_CORE_COPY_TASK_REGS(_tsk, _dest) \
67({ \
68 int __res = 1; \
69 elf32_core_copy_regs(*(_dest), task_pt_regs(_tsk)); \
70 __res; \
71})
72
56#include <linux/module.h> 73#include <linux/module.h>
57#include <linux/elfcore.h> 74#include <linux/elfcore.h>
58#include <linux/compat.h> 75#include <linux/compat.h>
@@ -110,9 +127,6 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
110 value->tv_usec = rem / NSEC_PER_USEC; 127 value->tv_usec = rem / NSEC_PER_USEC;
111} 128}
112 129
113#undef ELF_CORE_COPY_REGS
114#define ELF_CORE_COPY_REGS(_dest, _regs) elf32_core_copy_regs(_dest, _regs);
115
116void elf32_core_copy_regs(elf_gregset_t grp, struct pt_regs *regs) 130void elf32_core_copy_regs(elf_gregset_t grp, struct pt_regs *regs)
117{ 131{
118 int i; 132 int i;
diff --git a/arch/mips/kernel/cevt-ds1287.c b/arch/mips/kernel/cevt-ds1287.c
index 1ada45ea0700..6996da4d74a2 100644
--- a/arch/mips/kernel/cevt-ds1287.c
+++ b/arch/mips/kernel/cevt-ds1287.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * DS1287 clockevent driver 2 * DS1287 clockevent driver
3 * 3 *
4 * Copyright (C) 2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/kernel/cevt-gt641xx.c b/arch/mips/kernel/cevt-gt641xx.c
index e9b787feedcb..92351e00ae0e 100644
--- a/arch/mips/kernel/cevt-gt641xx.c
+++ b/arch/mips/kernel/cevt-gt641xx.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * GT641xx clockevent routines. 2 * GT641xx clockevent routines.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/kernel/csrc-ioasic.c b/arch/mips/kernel/csrc-ioasic.c
index b551f48d3a07..23da108506b0 100644
--- a/arch/mips/kernel/csrc-ioasic.c
+++ b/arch/mips/kernel/csrc-ioasic.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * DEC I/O ASIC's counter clocksource 2 * DEC I/O ASIC's counter clocksource
3 * 3 *
4 * Copyright (C) 2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/kernel/irq-gic.c b/arch/mips/kernel/irq-gic.c
index 39000f103f2c..d2072cd38592 100644
--- a/arch/mips/kernel/irq-gic.c
+++ b/arch/mips/kernel/irq-gic.c
@@ -107,9 +107,7 @@ static unsigned int gic_irq_startup(unsigned int irq)
107{ 107{
108 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__, irq); 108 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__, irq);
109 irq -= _irqbase; 109 irq -= _irqbase;
110 /* FIXME: this is wrong for !GICISWORDLITTLEENDIAN */ 110 GIC_SET_INTR_MASK(irq, 1);
111 GICWRITE(GIC_REG_ADDR(SHARED, (GIC_SH_SMASK_31_0_OFS + (irq / 32))),
112 1 << (irq % 32));
113 return 0; 111 return 0;
114} 112}
115 113
@@ -120,8 +118,7 @@ static void gic_irq_ack(unsigned int irq)
120#endif 118#endif
121 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__, irq); 119 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__, irq);
122 irq -= _irqbase; 120 irq -= _irqbase;
123 GICWRITE(GIC_REG_ADDR(SHARED, (GIC_SH_RMASK_31_0_OFS + (irq / 32))), 121 GIC_CLR_INTR_MASK(irq, 1);
124 1 << (irq % 32));
125 122
126 if (_intrmap[irq].trigtype == GIC_TRIG_EDGE) { 123 if (_intrmap[irq].trigtype == GIC_TRIG_EDGE) {
127 if (!gic_wedgeb2bok) 124 if (!gic_wedgeb2bok)
@@ -138,18 +135,14 @@ static void gic_mask_irq(unsigned int irq)
138{ 135{
139 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__, irq); 136 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__, irq);
140 irq -= _irqbase; 137 irq -= _irqbase;
141 /* FIXME: this is wrong for !GICISWORDLITTLEENDIAN */ 138 GIC_CLR_INTR_MASK(irq, 1);
142 GICWRITE(GIC_REG_ADDR(SHARED, (GIC_SH_RMASK_31_0_OFS + (irq / 32))),
143 1 << (irq % 32));
144} 139}
145 140
146static void gic_unmask_irq(unsigned int irq) 141static void gic_unmask_irq(unsigned int irq)
147{ 142{
148 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__, irq); 143 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__, irq);
149 irq -= _irqbase; 144 irq -= _irqbase;
150 /* FIXME: this is wrong for !GICISWORDLITTLEENDIAN */ 145 GIC_SET_INTR_MASK(irq, 1);
151 GICWRITE(GIC_REG_ADDR(SHARED, (GIC_SH_SMASK_31_0_OFS + (irq / 32))),
152 1 << (irq % 32));
153} 146}
154 147
155#ifdef CONFIG_SMP 148#ifdef CONFIG_SMP
@@ -254,6 +247,10 @@ static void __init gic_basic_init(void)
254 if (cpu == X) 247 if (cpu == X)
255 continue; 248 continue;
256 249
250 if (cpu == 0 && i != 0 && _intrmap[i].intrnum == 0 &&
251 _intrmap[i].ipiflag == 0)
252 continue;
253
257 setup_intr(_intrmap[i].intrnum, 254 setup_intr(_intrmap[i].intrnum,
258 _intrmap[i].cpunum, 255 _intrmap[i].cpunum,
259 _intrmap[i].pin, 256 _intrmap[i].pin,
diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
index 1b81b131f43c..ebcc5f7ad9c2 100644
--- a/arch/mips/kernel/irq-gt641xx.c
+++ b/arch/mips/kernel/irq-gt641xx.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * GT641xx IRQ routines. 2 * GT641xx IRQ routines.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
index 0b31b9bda048..20a86e08fd58 100644
--- a/arch/mips/kernel/scall32-o32.S
+++ b/arch/mips/kernel/scall32-o32.S
@@ -652,6 +652,8 @@ einval: li v0, -ENOSYS
652 sys sys_inotify_init1 1 652 sys sys_inotify_init1 1
653 sys sys_preadv 6 /* 4330 */ 653 sys sys_preadv 6 /* 4330 */
654 sys sys_pwritev 6 654 sys sys_pwritev 6
655 sys sys_rt_tgsigqueueinfo 4
656 sys sys_perf_counter_open 5
655 .endm 657 .endm
656 658
657 /* We pre-compute the number of _instruction_ bytes needed to 659 /* We pre-compute the number of _instruction_ bytes needed to
diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
index c647fd6e722f..b046130d4c5d 100644
--- a/arch/mips/kernel/scall64-64.S
+++ b/arch/mips/kernel/scall64-64.S
@@ -489,4 +489,6 @@ sys_call_table:
489 PTR sys_inotify_init1 489 PTR sys_inotify_init1
490 PTR sys_preadv 490 PTR sys_preadv
491 PTR sys_pwritev /* 5390 */ 491 PTR sys_pwritev /* 5390 */
492 PTR sys_rt_tgsigqueueinfo
493 PTR sys_perf_counter_open
492 .size sys_call_table,.-sys_call_table 494 .size sys_call_table,.-sys_call_table
diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
index 93cc672f4522..7c4a94f43706 100644
--- a/arch/mips/kernel/scall64-n32.S
+++ b/arch/mips/kernel/scall64-n32.S
@@ -164,7 +164,7 @@ EXPORT(sysn32_call_table)
164 PTR sys_connect 164 PTR sys_connect
165 PTR sys_accept 165 PTR sys_accept
166 PTR sys_sendto 166 PTR sys_sendto
167 PTR sys_recvfrom 167 PTR compat_sys_recvfrom
168 PTR compat_sys_sendmsg /* 6045 */ 168 PTR compat_sys_sendmsg /* 6045 */
169 PTR compat_sys_recvmsg 169 PTR compat_sys_recvmsg
170 PTR sys_shutdown 170 PTR sys_shutdown
@@ -415,4 +415,6 @@ EXPORT(sysn32_call_table)
415 PTR sys_inotify_init1 415 PTR sys_inotify_init1
416 PTR sys_preadv 416 PTR sys_preadv
417 PTR sys_pwritev 417 PTR sys_pwritev
418 PTR compat_sys_rt_tgsigqueueinfo /* 5295 */
419 PTR sys_perf_counter_open
418 .size sysn32_call_table,.-sysn32_call_table 420 .size sysn32_call_table,.-sysn32_call_table
diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
index a5598b2339dd..821fc978673d 100644
--- a/arch/mips/kernel/scall64-o32.S
+++ b/arch/mips/kernel/scall64-o32.S
@@ -378,8 +378,8 @@ sys_call_table:
378 PTR sys_getsockname 378 PTR sys_getsockname
379 PTR sys_getsockopt 379 PTR sys_getsockopt
380 PTR sys_listen 380 PTR sys_listen
381 PTR sys_recv /* 4175 */ 381 PTR compat_sys_recv /* 4175 */
382 PTR sys_recvfrom 382 PTR compat_sys_recvfrom
383 PTR compat_sys_recvmsg 383 PTR compat_sys_recvmsg
384 PTR sys_send 384 PTR sys_send
385 PTR compat_sys_sendmsg 385 PTR compat_sys_sendmsg
@@ -535,4 +535,6 @@ sys_call_table:
535 PTR sys_inotify_init1 535 PTR sys_inotify_init1
536 PTR compat_sys_preadv /* 4330 */ 536 PTR compat_sys_preadv /* 4330 */
537 PTR compat_sys_pwritev 537 PTR compat_sys_pwritev
538 PTR compat_sys_rt_tgsigqueueinfo
539 PTR sys_perf_counter_open
538 .size sys_call_table,.-sys_call_table 540 .size sys_call_table,.-sys_call_table
diff --git a/arch/mips/kernel/smp-cmp.c b/arch/mips/kernel/smp-cmp.c
index 653be061b9ec..ad0ff5dc4d59 100644
--- a/arch/mips/kernel/smp-cmp.c
+++ b/arch/mips/kernel/smp-cmp.c
@@ -37,80 +37,24 @@
37#include <asm/mipsregs.h> 37#include <asm/mipsregs.h>
38#include <asm/mipsmtregs.h> 38#include <asm/mipsmtregs.h>
39#include <asm/mips_mt.h> 39#include <asm/mips_mt.h>
40 40#include <asm/amon.h>
41/* 41#include <asm/gic.h>
42 * Crude manipulation of the CPU masks to control which
43 * which CPU's are brought online during initialisation
44 *
45 * Beware... this needs to be called after CPU discovery
46 * but before CPU bringup
47 */
48static int __init allowcpus(char *str)
49{
50 cpumask_t cpu_allow_map;
51 char buf[256];
52 int len;
53
54 cpus_clear(cpu_allow_map);
55 if (cpulist_parse(str, &cpu_allow_map) == 0) {
56 cpu_set(0, cpu_allow_map);
57 cpus_and(cpu_possible_map, cpu_possible_map, cpu_allow_map);
58 len = cpulist_scnprintf(buf, sizeof(buf)-1, &cpu_possible_map);
59 buf[len] = '\0';
60 pr_debug("Allowable CPUs: %s\n", buf);
61 return 1;
62 } else
63 return 0;
64}
65__setup("allowcpus=", allowcpus);
66 42
67static void ipi_call_function(unsigned int cpu) 43static void ipi_call_function(unsigned int cpu)
68{ 44{
69 unsigned int action = 0;
70
71 pr_debug("CPU%d: %s cpu %d status %08x\n", 45 pr_debug("CPU%d: %s cpu %d status %08x\n",
72 smp_processor_id(), __func__, cpu, read_c0_status()); 46 smp_processor_id(), __func__, cpu, read_c0_status());
73 47
74 switch (cpu) { 48 gic_send_ipi(plat_ipi_call_int_xlate(cpu));
75 case 0:
76 action = GIC_IPI_EXT_INTR_CALLFNC_VPE0;
77 break;
78 case 1:
79 action = GIC_IPI_EXT_INTR_CALLFNC_VPE1;
80 break;
81 case 2:
82 action = GIC_IPI_EXT_INTR_CALLFNC_VPE2;
83 break;
84 case 3:
85 action = GIC_IPI_EXT_INTR_CALLFNC_VPE3;
86 break;
87 }
88 gic_send_ipi(action);
89} 49}
90 50
91 51
92static void ipi_resched(unsigned int cpu) 52static void ipi_resched(unsigned int cpu)
93{ 53{
94 unsigned int action = 0;
95
96 pr_debug("CPU%d: %s cpu %d status %08x\n", 54 pr_debug("CPU%d: %s cpu %d status %08x\n",
97 smp_processor_id(), __func__, cpu, read_c0_status()); 55 smp_processor_id(), __func__, cpu, read_c0_status());
98 56
99 switch (cpu) { 57 gic_send_ipi(plat_ipi_resched_int_xlate(cpu));
100 case 0:
101 action = GIC_IPI_EXT_INTR_RESCHED_VPE0;
102 break;
103 case 1:
104 action = GIC_IPI_EXT_INTR_RESCHED_VPE1;
105 break;
106 case 2:
107 action = GIC_IPI_EXT_INTR_RESCHED_VPE2;
108 break;
109 case 3:
110 action = GIC_IPI_EXT_INTR_RESCHED_VPE3;
111 break;
112 }
113 gic_send_ipi(action);
114} 58}
115 59
116/* 60/*
@@ -206,7 +150,7 @@ static void cmp_boot_secondary(int cpu, struct task_struct *idle)
206 (unsigned long)(gp + sizeof(struct thread_info))); 150 (unsigned long)(gp + sizeof(struct thread_info)));
207#endif 151#endif
208 152
209 amon_cpu_start(cpu, pc, sp, gp, a0); 153 amon_cpu_start(cpu, pc, sp, (unsigned long)gp, a0);
210} 154}
211 155
212/* 156/*
diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
index 9021108eb9c1..05dd170a83f7 100644
--- a/arch/mips/kernel/sync-r4k.c
+++ b/arch/mips/kernel/sync-r4k.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Count register synchronisation. 2 * Count register synchronisation.
3 * 3 *
4 * All CPUs will have their count registers synchronised to the CPU0 expirelo 4 * All CPUs will have their count registers synchronised to the CPU0 next time
5 * value. This can cause a small timewarp for CPU0. All other CPU's should 5 * value. This can cause a small timewarp for CPU0. All other CPU's should
6 * not have done anything significant (but they may have had interrupts 6 * not have done anything significant (but they may have had interrupts
7 * enabled briefly - prom_smp_finish() should not be responsible for enabling 7 * enabled briefly - prom_smp_finish() should not be responsible for enabling
@@ -13,21 +13,22 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/irqflags.h> 15#include <linux/irqflags.h>
16#include <linux/r4k-timer.h> 16#include <linux/cpumask.h>
17 17
18#include <asm/r4k-timer.h>
18#include <asm/atomic.h> 19#include <asm/atomic.h>
19#include <asm/barrier.h> 20#include <asm/barrier.h>
20#include <asm/cpumask.h>
21#include <asm/mipsregs.h> 21#include <asm/mipsregs.h>
22 22
23static atomic_t __initdata count_start_flag = ATOMIC_INIT(0); 23static atomic_t __cpuinitdata count_start_flag = ATOMIC_INIT(0);
24static atomic_t __initdata count_count_start = ATOMIC_INIT(0); 24static atomic_t __cpuinitdata count_count_start = ATOMIC_INIT(0);
25static atomic_t __initdata count_count_stop = ATOMIC_INIT(0); 25static atomic_t __cpuinitdata count_count_stop = ATOMIC_INIT(0);
26static atomic_t __cpuinitdata count_reference = ATOMIC_INIT(0);
26 27
27#define COUNTON 100 28#define COUNTON 100
28#define NR_LOOPS 5 29#define NR_LOOPS 5
29 30
30void __init synchronise_count_master(void) 31void __cpuinit synchronise_count_master(void)
31{ 32{
32 int i; 33 int i;
33 unsigned long flags; 34 unsigned long flags;
@@ -42,19 +43,20 @@ void __init synchronise_count_master(void)
42 return; 43 return;
43#endif 44#endif
44 45
45 pr_info("Checking COUNT synchronization across %u CPUs: ", 46 printk(KERN_INFO "Synchronize counters across %u CPUs: ",
46 num_online_cpus()); 47 num_online_cpus());
47 48
48 local_irq_save(flags); 49 local_irq_save(flags);
49 50
50 /* 51 /*
51 * Notify the slaves that it's time to start 52 * Notify the slaves that it's time to start
52 */ 53 */
54 atomic_set(&count_reference, read_c0_count());
53 atomic_set(&count_start_flag, 1); 55 atomic_set(&count_start_flag, 1);
54 smp_wmb(); 56 smp_wmb();
55 57
56 /* Count will be initialised to expirelo for all CPU's */ 58 /* Count will be initialised to current timer for all CPU's */
57 initcount = expirelo; 59 initcount = read_c0_count();
58 60
59 /* 61 /*
60 * We loop a few times to get a primed instruction cache, 62 * We loop a few times to get a primed instruction cache,
@@ -106,7 +108,7 @@ void __init synchronise_count_master(void)
106 printk("done.\n"); 108 printk("done.\n");
107} 109}
108 110
109void __init synchronise_count_slave(void) 111void __cpuinit synchronise_count_slave(void)
110{ 112{
111 int i; 113 int i;
112 unsigned long flags; 114 unsigned long flags;
@@ -131,8 +133,8 @@ void __init synchronise_count_slave(void)
131 while (!atomic_read(&count_start_flag)) 133 while (!atomic_read(&count_start_flag))
132 mb(); 134 mb();
133 135
134 /* Count will be initialised to expirelo for all CPU's */ 136 /* Count will be initialised to next expire for all CPU's */
135 initcount = expirelo; 137 initcount = atomic_read(&count_reference);
136 138
137 ncpus = num_online_cpus(); 139 ncpus = num_online_cpus();
138 for (i = 0; i < NR_LOOPS; i++) { 140 for (i = 0; i < NR_LOOPS; i++) {
@@ -156,4 +158,3 @@ void __init synchronise_count_slave(void)
156 local_irq_restore(flags); 158 local_irq_restore(flags);
157} 159}
158#undef NR_LOOPS 160#undef NR_LOOPS
159#endif
diff --git a/arch/mips/kernel/vpe.c b/arch/mips/kernel/vpe.c
index 3ca5f42e819d..07b9ec2c6e3d 100644
--- a/arch/mips/kernel/vpe.c
+++ b/arch/mips/kernel/vpe.c
@@ -1387,7 +1387,7 @@ static ssize_t store_ntcs(struct device *dev, struct device_attribute *attr,
1387 return len; 1387 return len;
1388 1388
1389out_einval: 1389out_einval:
1390 return -EINVAL;; 1390 return -EINVAL;
1391} 1391}
1392 1392
1393static struct device_attribute vpe_class_attributes[] = { 1393static struct device_attribute vpe_class_attributes[] = {
diff --git a/arch/mips/mti-malta/malta-init.c b/arch/mips/mti-malta/malta-init.c
index 475038a141a6..27c807b67fea 100644
--- a/arch/mips/mti-malta/malta-init.c
+++ b/arch/mips/mti-malta/malta-init.c
@@ -30,6 +30,7 @@
30#include <asm/cacheflush.h> 30#include <asm/cacheflush.h>
31#include <asm/traps.h> 31#include <asm/traps.h>
32 32
33#include <asm/gcmpregs.h>
33#include <asm/mips-boards/prom.h> 34#include <asm/mips-boards/prom.h>
34#include <asm/mips-boards/generic.h> 35#include <asm/mips-boards/generic.h>
35#include <asm/mips-boards/bonito64.h> 36#include <asm/mips-boards/bonito64.h>
@@ -192,6 +193,8 @@ extern struct plat_smp_ops msmtc_smp_ops;
192 193
193void __init prom_init(void) 194void __init prom_init(void)
194{ 195{
196 int result;
197
195 prom_argc = fw_arg0; 198 prom_argc = fw_arg0;
196 _prom_argv = (int *) fw_arg1; 199 _prom_argv = (int *) fw_arg1;
197 _prom_envp = (int *) fw_arg2; 200 _prom_envp = (int *) fw_arg2;
@@ -358,12 +361,21 @@ void __init prom_init(void)
358#ifdef CONFIG_SERIAL_8250_CONSOLE 361#ifdef CONFIG_SERIAL_8250_CONSOLE
359 console_config(); 362 console_config();
360#endif 363#endif
364 /* Early detection of CMP support */
365 result = gcmp_probe(GCMP_BASE_ADDR, GCMP_ADDRSPACE_SZ);
366
361#ifdef CONFIG_MIPS_CMP 367#ifdef CONFIG_MIPS_CMP
362 register_smp_ops(&cmp_smp_ops); 368 if (result)
369 register_smp_ops(&cmp_smp_ops);
363#endif 370#endif
364#ifdef CONFIG_MIPS_MT_SMP 371#ifdef CONFIG_MIPS_MT_SMP
372#ifdef CONFIG_MIPS_CMP
373 if (!result)
374 register_smp_ops(&vsmp_smp_ops);
375#else
365 register_smp_ops(&vsmp_smp_ops); 376 register_smp_ops(&vsmp_smp_ops);
366#endif 377#endif
378#endif
367#ifdef CONFIG_MIPS_MT_SMTC 379#ifdef CONFIG_MIPS_MT_SMTC
368 register_smp_ops(&msmtc_smp_ops); 380 register_smp_ops(&msmtc_smp_ops);
369#endif 381#endif
diff --git a/arch/mips/mti-malta/malta-int.c b/arch/mips/mti-malta/malta-int.c
index b4eaf137e4a7..a8756f82c31b 100644
--- a/arch/mips/mti-malta/malta-int.c
+++ b/arch/mips/mti-malta/malta-int.c
@@ -331,6 +331,21 @@ static struct irqaction irq_call = {
331 .flags = IRQF_DISABLED|IRQF_PERCPU, 331 .flags = IRQF_DISABLED|IRQF_PERCPU,
332 .name = "IPI_call" 332 .name = "IPI_call"
333}; 333};
334
335static int gic_resched_int_base;
336static int gic_call_int_base;
337#define GIC_RESCHED_INT(cpu) (gic_resched_int_base+(cpu))
338#define GIC_CALL_INT(cpu) (gic_call_int_base+(cpu))
339
340unsigned int plat_ipi_call_int_xlate(unsigned int cpu)
341{
342 return GIC_CALL_INT(cpu);
343}
344
345unsigned int plat_ipi_resched_int_xlate(unsigned int cpu)
346{
347 return GIC_RESCHED_INT(cpu);
348}
334#endif /* CONFIG_MIPS_MT_SMP */ 349#endif /* CONFIG_MIPS_MT_SMP */
335 350
336static struct irqaction i8259irq = { 351static struct irqaction i8259irq = {
@@ -370,7 +385,7 @@ static int __initdata msc_nr_eicirqs = ARRAY_SIZE(msc_eicirqmap);
370 * Interrupts and CPUs/Core Interrupts. The nature of the External 385 * Interrupts and CPUs/Core Interrupts. The nature of the External
371 * Interrupts is also defined here - polarity/trigger. 386 * Interrupts is also defined here - polarity/trigger.
372 */ 387 */
373static struct gic_intr_map gic_intr_map[] = { 388static struct gic_intr_map gic_intr_map[GIC_NUM_INTRS] = {
374 { GIC_EXT_INTR(0), X, X, X, X, 0 }, 389 { GIC_EXT_INTR(0), X, X, X, X, 0 },
375 { GIC_EXT_INTR(1), X, X, X, X, 0 }, 390 { GIC_EXT_INTR(1), X, X, X, X, 0 },
376 { GIC_EXT_INTR(2), X, X, X, X, 0 }, 391 { GIC_EXT_INTR(2), X, X, X, X, 0 },
@@ -387,21 +402,14 @@ static struct gic_intr_map gic_intr_map[] = {
387 { GIC_EXT_INTR(13), 0, GIC_MAP_TO_NMI_MSK, GIC_POL_POS, GIC_TRIG_LEVEL, 0 }, 402 { GIC_EXT_INTR(13), 0, GIC_MAP_TO_NMI_MSK, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
388 { GIC_EXT_INTR(14), 0, GIC_MAP_TO_NMI_MSK, GIC_POL_POS, GIC_TRIG_LEVEL, 0 }, 403 { GIC_EXT_INTR(14), 0, GIC_MAP_TO_NMI_MSK, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
389 { GIC_EXT_INTR(15), X, X, X, X, 0 }, 404 { GIC_EXT_INTR(15), X, X, X, X, 0 },
390 { GIC_EXT_INTR(16), 0, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, 1 }, 405/* This is the end of the general interrupts now we do IPI ones */
391 { GIC_EXT_INTR(17), 0, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
392 { GIC_EXT_INTR(18), 1, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
393 { GIC_EXT_INTR(19), 1, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
394 { GIC_EXT_INTR(20), 2, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
395 { GIC_EXT_INTR(21), 2, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
396 { GIC_EXT_INTR(22), 3, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
397 { GIC_EXT_INTR(23), 3, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
398}; 406};
399#endif 407#endif
400 408
401/* 409/*
402 * GCMP needs to be detected before any SMP initialisation 410 * GCMP needs to be detected before any SMP initialisation
403 */ 411 */
404static int __init gcmp_probe(unsigned long addr, unsigned long size) 412int __init gcmp_probe(unsigned long addr, unsigned long size)
405{ 413{
406 if (gcmp_present >= 0) 414 if (gcmp_present >= 0)
407 return gcmp_present; 415 return gcmp_present;
@@ -416,28 +424,36 @@ static int __init gcmp_probe(unsigned long addr, unsigned long size)
416} 424}
417 425
418#if defined(CONFIG_MIPS_MT_SMP) 426#if defined(CONFIG_MIPS_MT_SMP)
427static void __init fill_ipi_map1(int baseintr, int cpu, int cpupin)
428{
429 int intr = baseintr + cpu;
430 gic_intr_map[intr].intrnum = GIC_EXT_INTR(intr);
431 gic_intr_map[intr].cpunum = cpu;
432 gic_intr_map[intr].pin = cpupin;
433 gic_intr_map[intr].polarity = GIC_POL_POS;
434 gic_intr_map[intr].trigtype = GIC_TRIG_EDGE;
435 gic_intr_map[intr].ipiflag = 1;
436 ipi_map[cpu] |= (1 << (cpupin + 2));
437}
438
419static void __init fill_ipi_map(void) 439static void __init fill_ipi_map(void)
420{ 440{
421 int i; 441 int cpu;
422 442
423 for (i = 0; i < ARRAY_SIZE(gic_intr_map); i++) { 443 for (cpu = 0; cpu < NR_CPUS; cpu++) {
424 if (gic_intr_map[i].ipiflag && (gic_intr_map[i].cpunum != X)) 444 fill_ipi_map1(gic_resched_int_base, cpu, GIC_CPU_INT1);
425 ipi_map[gic_intr_map[i].cpunum] |= 445 fill_ipi_map1(gic_call_int_base, cpu, GIC_CPU_INT2);
426 (1 << (gic_intr_map[i].pin + 2));
427 } 446 }
428} 447}
429#endif 448#endif
430 449
431void __init arch_init_irq(void) 450void __init arch_init_irq(void)
432{ 451{
433 int gic_present, gcmp_present;
434
435 init_i8259_irqs(); 452 init_i8259_irqs();
436 453
437 if (!cpu_has_veic) 454 if (!cpu_has_veic)
438 mips_cpu_irq_init(); 455 mips_cpu_irq_init();
439 456
440 gcmp_present = gcmp_probe(GCMP_BASE_ADDR, GCMP_ADDRSPACE_SZ);
441 if (gcmp_present) { 457 if (gcmp_present) {
442 GCMPGCB(GICBA) = GIC_BASE_ADDR | GCMP_GCB_GICBA_EN_MSK; 458 GCMPGCB(GICBA) = GIC_BASE_ADDR | GCMP_GCB_GICBA_EN_MSK;
443 gic_present = 1; 459 gic_present = 1;
@@ -514,24 +530,10 @@ void __init arch_init_irq(void)
514 if (gic_present) { 530 if (gic_present) {
515 /* FIXME */ 531 /* FIXME */
516 int i; 532 int i;
517 struct { 533
518 unsigned int resched; 534 gic_call_int_base = GIC_NUM_INTRS - NR_CPUS;
519 unsigned int call; 535 gic_resched_int_base = gic_call_int_base - NR_CPUS;
520 } ipiirq[] = { 536
521 {
522 .resched = GIC_IPI_EXT_INTR_RESCHED_VPE0,
523 .call = GIC_IPI_EXT_INTR_CALLFNC_VPE0},
524 {
525 .resched = GIC_IPI_EXT_INTR_RESCHED_VPE1,
526 .call = GIC_IPI_EXT_INTR_CALLFNC_VPE1
527 }, {
528 .resched = GIC_IPI_EXT_INTR_RESCHED_VPE2,
529 .call = GIC_IPI_EXT_INTR_CALLFNC_VPE2
530 }, {
531 .resched = GIC_IPI_EXT_INTR_RESCHED_VPE3,
532 .call = GIC_IPI_EXT_INTR_CALLFNC_VPE3
533 }
534 };
535 fill_ipi_map(); 537 fill_ipi_map();
536 gic_init(GIC_BASE_ADDR, GIC_ADDRSPACE_SZ, gic_intr_map, ARRAY_SIZE(gic_intr_map), MIPS_GIC_IRQ_BASE); 538 gic_init(GIC_BASE_ADDR, GIC_ADDRSPACE_SZ, gic_intr_map, ARRAY_SIZE(gic_intr_map), MIPS_GIC_IRQ_BASE);
537 if (!gcmp_present) { 539 if (!gcmp_present) {
@@ -553,12 +555,15 @@ void __init arch_init_irq(void)
553 printk("CPU%d: status register now %08x\n", smp_processor_id(), read_c0_status()); 555 printk("CPU%d: status register now %08x\n", smp_processor_id(), read_c0_status());
554 write_c0_status(0x1100dc00); 556 write_c0_status(0x1100dc00);
555 printk("CPU%d: status register frc %08x\n", smp_processor_id(), read_c0_status()); 557 printk("CPU%d: status register frc %08x\n", smp_processor_id(), read_c0_status());
556 for (i = 0; i < ARRAY_SIZE(ipiirq); i++) { 558 for (i = 0; i < NR_CPUS; i++) {
557 setup_irq(MIPS_GIC_IRQ_BASE + ipiirq[i].resched, &irq_resched); 559 setup_irq(MIPS_GIC_IRQ_BASE +
558 setup_irq(MIPS_GIC_IRQ_BASE + ipiirq[i].call, &irq_call); 560 GIC_RESCHED_INT(i), &irq_resched);
559 561 setup_irq(MIPS_GIC_IRQ_BASE +
560 set_irq_handler(MIPS_GIC_IRQ_BASE + ipiirq[i].resched, handle_percpu_irq); 562 GIC_CALL_INT(i), &irq_call);
561 set_irq_handler(MIPS_GIC_IRQ_BASE + ipiirq[i].call, handle_percpu_irq); 563 set_irq_handler(MIPS_GIC_IRQ_BASE +
564 GIC_RESCHED_INT(i), handle_percpu_irq);
565 set_irq_handler(MIPS_GIC_IRQ_BASE +
566 GIC_CALL_INT(i), handle_percpu_irq);
562 } 567 }
563 } else { 568 } else {
564 /* set up ipi interrupts */ 569 /* set up ipi interrupts */
diff --git a/arch/mips/mti-malta/malta-reset.c b/arch/mips/mti-malta/malta-reset.c
index 42dee4da37ba..f48d60e84290 100644
--- a/arch/mips/mti-malta/malta-reset.c
+++ b/arch/mips/mti-malta/malta-reset.c
@@ -28,9 +28,6 @@
28#include <asm/reboot.h> 28#include <asm/reboot.h>
29#include <asm/mips-boards/generic.h> 29#include <asm/mips-boards/generic.h>
30 30
31static void mips_machine_restart(char *command);
32static void mips_machine_halt(void);
33
34static void mips_machine_restart(char *command) 31static void mips_machine_restart(char *command)
35{ 32{
36 unsigned int __iomem *softres_reg = 33 unsigned int __iomem *softres_reg =
diff --git a/arch/mips/pci/Makefile b/arch/mips/pci/Makefile
index e8a97f59e066..63d8a297c58d 100644
--- a/arch/mips/pci/Makefile
+++ b/arch/mips/pci/Makefile
@@ -52,3 +52,8 @@ obj-$(CONFIG_VICTOR_MPC30X) += fixup-mpc30x.o
52obj-$(CONFIG_ZAO_CAPCELLA) += fixup-capcella.o 52obj-$(CONFIG_ZAO_CAPCELLA) += fixup-capcella.o
53obj-$(CONFIG_WR_PPMC) += fixup-wrppmc.o 53obj-$(CONFIG_WR_PPMC) += fixup-wrppmc.o
54obj-$(CONFIG_MIKROTIK_RB532) += pci-rc32434.o ops-rc32434.o fixup-rc32434.o 54obj-$(CONFIG_MIKROTIK_RB532) += pci-rc32434.o ops-rc32434.o fixup-rc32434.o
55obj-$(CONFIG_CPU_CAVIUM_OCTEON) += pci-octeon.o pcie-octeon.o
56
57ifdef CONFIG_PCI_MSI
58obj-$(CONFIG_CPU_CAVIUM_OCTEON) += msi-octeon.o
59endif
diff --git a/arch/mips/pci/fixup-capcella.c b/arch/mips/pci/fixup-capcella.c
index 1416bca6d1a3..1c02f5737367 100644
--- a/arch/mips/pci/fixup-capcella.c
+++ b/arch/mips/pci/fixup-capcella.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * fixup-cappcela.c, The ZAO Networks Capcella specific PCI fixups. 2 * fixup-cappcela.c, The ZAO Networks Capcella specific PCI fixups.
3 * 3 *
4 * Copyright (C) 2002,2004 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2002,2004 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/pci/fixup-mpc30x.c b/arch/mips/pci/fixup-mpc30x.c
index 591159625722..e08f49cb6875 100644
--- a/arch/mips/pci/fixup-mpc30x.c
+++ b/arch/mips/pci/fixup-mpc30x.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * fixup-mpc30x.c, The Victor MP-C303/304 specific PCI fixups. 2 * fixup-mpc30x.c, The Victor MP-C303/304 specific PCI fixups.
3 * 3 *
4 * Copyright (C) 2002,2004 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2002,2004 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/pci/fixup-tb0219.c b/arch/mips/pci/fixup-tb0219.c
index ed87733f6796..8084b17d4406 100644
--- a/arch/mips/pci/fixup-tb0219.c
+++ b/arch/mips/pci/fixup-tb0219.c
@@ -2,7 +2,7 @@
2 * fixup-tb0219.c, The TANBAC TB0219 specific PCI fixups. 2 * fixup-tb0219.c, The TANBAC TB0219 specific PCI fixups.
3 * 3 *
4 * Copyright (C) 2003 Megasolution Inc. <matsu@megasolution.jp> 4 * Copyright (C) 2003 Megasolution Inc. <matsu@megasolution.jp>
5 * Copyright (C) 2004-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 5 * Copyright (C) 2004-2005 Yoichi Yuasa <yuasa@linux-mips.org>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/pci/fixup-tb0226.c b/arch/mips/pci/fixup-tb0226.c
index e3eedf4bf9bd..4196ccf3ea3d 100644
--- a/arch/mips/pci/fixup-tb0226.c
+++ b/arch/mips/pci/fixup-tb0226.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * fixup-tb0226.c, The TANBAC TB0226 specific PCI fixups. 2 * fixup-tb0226.c, The TANBAC TB0226 specific PCI fixups.
3 * 3 *
4 * Copyright (C) 2002-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2002-2005 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/pci/fixup-tb0287.c b/arch/mips/pci/fixup-tb0287.c
index 267ab3dc3d42..2fe29db43725 100644
--- a/arch/mips/pci/fixup-tb0287.c
+++ b/arch/mips/pci/fixup-tb0287.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * fixup-tb0287.c, The TANBAC TB0287 specific PCI fixups. 2 * fixup-tb0287.c, The TANBAC TB0287 specific PCI fixups.
3 * 3 *
4 * Copyright (C) 2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2005 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/cavium-octeon/msi.c b/arch/mips/pci/msi-octeon.c
index 964b03b75a8f..03742e647657 100644
--- a/arch/mips/cavium-octeon/msi.c
+++ b/arch/mips/pci/msi-octeon.c
@@ -3,7 +3,7 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (C) 2005-2007 Cavium Networks 6 * Copyright (C) 2005-2009 Cavium Networks
7 */ 7 */
8#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/init.h> 9#include <linux/init.h>
@@ -16,8 +16,7 @@
16#include <asm/octeon/cvmx-pci-defs.h> 16#include <asm/octeon/cvmx-pci-defs.h>
17#include <asm/octeon/cvmx-npei-defs.h> 17#include <asm/octeon/cvmx-npei-defs.h>
18#include <asm/octeon/cvmx-pexp-defs.h> 18#include <asm/octeon/cvmx-pexp-defs.h>
19 19#include <asm/octeon/pci-octeon.h>
20#include "pci-common.h"
21 20
22/* 21/*
23 * Each bit in msi_free_irq_bitmask represents a MSI interrupt that is 22 * Each bit in msi_free_irq_bitmask represents a MSI interrupt that is
@@ -47,8 +46,8 @@ static DEFINE_SPINLOCK(msi_free_irq_bitmask_lock);
47 * programming the MSI control bits [6:4] before calling 46 * programming the MSI control bits [6:4] before calling
48 * pci_enable_msi(). 47 * pci_enable_msi().
49 * 48 *
50 * @param dev Device requesting MSI interrupts 49 * @dev: Device requesting MSI interrupts
51 * @param desc MSI descriptor 50 * @desc: MSI descriptor
52 * 51 *
53 * Returns 0 on success. 52 * Returns 0 on success.
54 */ 53 */
@@ -213,14 +212,9 @@ void arch_teardown_msi_irq(unsigned int irq)
213} 212}
214 213
215 214
216/** 215/*
217 * Called by the interrupt handling code when an MSI interrupt 216 * Called by the interrupt handling code when an MSI interrupt
218 * occurs. 217 * occurs.
219 *
220 * @param cpl
221 * @param dev_id
222 *
223 * @return
224 */ 218 */
225static irqreturn_t octeon_msi_interrupt(int cpl, void *dev_id) 219static irqreturn_t octeon_msi_interrupt(int cpl, void *dev_id)
226{ 220{
@@ -256,31 +250,37 @@ static irqreturn_t octeon_msi_interrupt(int cpl, void *dev_id)
256} 250}
257 251
258 252
259/** 253/*
260 * Initializes the MSI interrupt handling code 254 * Initializes the MSI interrupt handling code
261 *
262 * @return
263 */ 255 */
264int octeon_msi_initialize(void) 256int octeon_msi_initialize(void)
265{ 257{
266 int r;
267 if (octeon_has_feature(OCTEON_FEATURE_PCIE)) { 258 if (octeon_has_feature(OCTEON_FEATURE_PCIE)) {
268 r = request_irq(OCTEON_IRQ_PCI_MSI0, octeon_msi_interrupt, 259 if (request_irq(OCTEON_IRQ_PCI_MSI0, octeon_msi_interrupt,
269 IRQF_SHARED, 260 IRQF_SHARED,
270 "MSI[0:63]", octeon_msi_interrupt); 261 "MSI[0:63]", octeon_msi_interrupt))
262 panic("request_irq(OCTEON_IRQ_PCI_MSI0) failed");
271 } else if (octeon_is_pci_host()) { 263 } else if (octeon_is_pci_host()) {
272 r = request_irq(OCTEON_IRQ_PCI_MSI0, octeon_msi_interrupt, 264 if (request_irq(OCTEON_IRQ_PCI_MSI0, octeon_msi_interrupt,
273 IRQF_SHARED, 265 IRQF_SHARED,
274 "MSI[0:15]", octeon_msi_interrupt); 266 "MSI[0:15]", octeon_msi_interrupt))
275 r += request_irq(OCTEON_IRQ_PCI_MSI1, octeon_msi_interrupt, 267 panic("request_irq(OCTEON_IRQ_PCI_MSI0) failed");
276 IRQF_SHARED, 268
277 "MSI[16:31]", octeon_msi_interrupt); 269 if (request_irq(OCTEON_IRQ_PCI_MSI1, octeon_msi_interrupt,
278 r += request_irq(OCTEON_IRQ_PCI_MSI2, octeon_msi_interrupt, 270 IRQF_SHARED,
279 IRQF_SHARED, 271 "MSI[16:31]", octeon_msi_interrupt))
280 "MSI[32:47]", octeon_msi_interrupt); 272 panic("request_irq(OCTEON_IRQ_PCI_MSI1) failed");
281 r += request_irq(OCTEON_IRQ_PCI_MSI3, octeon_msi_interrupt, 273
282 IRQF_SHARED, 274 if (request_irq(OCTEON_IRQ_PCI_MSI2, octeon_msi_interrupt,
283 "MSI[48:63]", octeon_msi_interrupt); 275 IRQF_SHARED,
276 "MSI[32:47]", octeon_msi_interrupt))
277 panic("request_irq(OCTEON_IRQ_PCI_MSI2) failed");
278
279 if (request_irq(OCTEON_IRQ_PCI_MSI3, octeon_msi_interrupt,
280 IRQF_SHARED,
281 "MSI[48:63]", octeon_msi_interrupt))
282 panic("request_irq(OCTEON_IRQ_PCI_MSI3) failed");
283
284 } 284 }
285 return 0; 285 return 0;
286} 286}
diff --git a/arch/mips/pci/ops-vr41xx.c b/arch/mips/pci/ops-vr41xx.c
index 900c6b32576c..28962a7c6606 100644
--- a/arch/mips/pci/ops-vr41xx.c
+++ b/arch/mips/pci/ops-vr41xx.c
@@ -2,8 +2,8 @@
2 * ops-vr41xx.c, PCI configuration routines for the PCIU of NEC VR4100 series. 2 * ops-vr41xx.c, PCI configuration routines for the PCIU of NEC VR4100 series.
3 * 3 *
4 * Copyright (C) 2001-2003 MontaVista Software Inc. 4 * Copyright (C) 2001-2003 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com> 5 * Author: Yoichi Yuasa <source@mvista.com>
6 * Copyright (C) 2004-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 6 * Copyright (C) 2004-2005 Yoichi Yuasa <yuasa@linux-mips.org>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
21 */ 21 */
22/* 22/*
23 * Changes: 23 * Changes:
24 * MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com> 24 * MontaVista Software Inc. <source@mvista.com>
25 * - New creation, NEC VR4122 and VR4131 are supported. 25 * - New creation, NEC VR4122 and VR4131 are supported.
26 */ 26 */
27#include <linux/pci.h> 27#include <linux/pci.h>
diff --git a/arch/mips/cavium-octeon/pci.c b/arch/mips/pci/pci-octeon.c
index 67c0ff5e92f1..9cb0c807f564 100644
--- a/arch/mips/cavium-octeon/pci.c
+++ b/arch/mips/pci/pci-octeon.c
@@ -3,7 +3,7 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (C) 2005-2007 Cavium Networks 6 * Copyright (C) 2005-2009 Cavium Networks
7 */ 7 */
8#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/init.h> 9#include <linux/init.h>
@@ -17,8 +17,7 @@
17#include <asm/octeon/octeon.h> 17#include <asm/octeon/octeon.h>
18#include <asm/octeon/cvmx-npi-defs.h> 18#include <asm/octeon/cvmx-npi-defs.h>
19#include <asm/octeon/cvmx-pci-defs.h> 19#include <asm/octeon/cvmx-pci-defs.h>
20 20#include <asm/octeon/pci-octeon.h>
21#include "pci-common.h"
22 21
23#define USE_OCTEON_INTERNAL_ARBITER 22#define USE_OCTEON_INTERNAL_ARBITER
24 23
@@ -54,6 +53,126 @@ union octeon_pci_address {
54 } s; 53 } s;
55}; 54};
56 55
56int __initdata (*octeon_pcibios_map_irq)(const struct pci_dev *dev,
57 u8 slot, u8 pin);
58enum octeon_dma_bar_type octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_INVALID;
59
60/**
61 * Map a PCI device to the appropriate interrupt line
62 *
63 * @dev: The Linux PCI device structure for the device to map
64 * @slot: The slot number for this device on __BUS 0__. Linux
65 * enumerates through all the bridges and figures out the
66 * slot on Bus 0 where this device eventually hooks to.
67 * @pin: The PCI interrupt pin read from the device, then swizzled
68 * as it goes through each bridge.
69 * Returns Interrupt number for the device
70 */
71int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
72{
73 if (octeon_pcibios_map_irq)
74 return octeon_pcibios_map_irq(dev, slot, pin);
75 else
76 panic("octeon_pcibios_map_irq not set.");
77}
78
79
80/*
81 * Called to perform platform specific PCI setup
82 */
83int pcibios_plat_dev_init(struct pci_dev *dev)
84{
85 uint16_t config;
86 uint32_t dconfig;
87 int pos;
88 /*
89 * Force the Cache line setting to 64 bytes. The standard
90 * Linux bus scan doesn't seem to set it. Octeon really has
91 * 128 byte lines, but Intel bridges get really upset if you
92 * try and set values above 64 bytes. Value is specified in
93 * 32bit words.
94 */
95 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 64 / 4);
96 /* Set latency timers for all devices */
97 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 48);
98
99 /* Enable reporting System errors and parity errors on all devices */
100 /* Enable parity checking and error reporting */
101 pci_read_config_word(dev, PCI_COMMAND, &config);
102 config |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
103 pci_write_config_word(dev, PCI_COMMAND, config);
104
105 if (dev->subordinate) {
106 /* Set latency timers on sub bridges */
107 pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 48);
108 /* More bridge error detection */
109 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &config);
110 config |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR;
111 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, config);
112 }
113
114 /* Enable the PCIe normal error reporting */
115 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
116 if (pos) {
117 /* Update Device Control */
118 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &config);
119 /* Correctable Error Reporting */
120 config |= PCI_EXP_DEVCTL_CERE;
121 /* Non-Fatal Error Reporting */
122 config |= PCI_EXP_DEVCTL_NFERE;
123 /* Fatal Error Reporting */
124 config |= PCI_EXP_DEVCTL_FERE;
125 /* Unsupported Request */
126 config |= PCI_EXP_DEVCTL_URRE;
127 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, config);
128 }
129
130 /* Find the Advanced Error Reporting capability */
131 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
132 if (pos) {
133 /* Clear Uncorrectable Error Status */
134 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
135 &dconfig);
136 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
137 dconfig);
138 /* Enable reporting of all uncorrectable errors */
139 /* Uncorrectable Error Mask - turned on bits disable errors */
140 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, 0);
141 /*
142 * Leave severity at HW default. This only controls if
143 * errors are reported as uncorrectable or
144 * correctable, not if the error is reported.
145 */
146 /* PCI_ERR_UNCOR_SEVER - Uncorrectable Error Severity */
147 /* Clear Correctable Error Status */
148 pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &dconfig);
149 pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, dconfig);
150 /* Enable reporting of all correctable errors */
151 /* Correctable Error Mask - turned on bits disable errors */
152 pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, 0);
153 /* Advanced Error Capabilities */
154 pci_read_config_dword(dev, pos + PCI_ERR_CAP, &dconfig);
155 /* ECRC Generation Enable */
156 if (config & PCI_ERR_CAP_ECRC_GENC)
157 config |= PCI_ERR_CAP_ECRC_GENE;
158 /* ECRC Check Enable */
159 if (config & PCI_ERR_CAP_ECRC_CHKC)
160 config |= PCI_ERR_CAP_ECRC_CHKE;
161 pci_write_config_dword(dev, pos + PCI_ERR_CAP, dconfig);
162 /* PCI_ERR_HEADER_LOG - Header Log Register (16 bytes) */
163 /* Report all errors to the root complex */
164 pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND,
165 PCI_ERR_ROOT_CMD_COR_EN |
166 PCI_ERR_ROOT_CMD_NONFATAL_EN |
167 PCI_ERR_ROOT_CMD_FATAL_EN);
168 /* Clear the Root status register */
169 pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &dconfig);
170 pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, dconfig);
171 }
172
173 return 0;
174}
175
57/** 176/**
58 * Return the mapping of PCI device number to IRQ line. Each 177 * Return the mapping of PCI device number to IRQ line. Each
59 * character in the return string represents the interrupt 178 * character in the return string represents the interrupt
@@ -136,9 +255,8 @@ int __init octeon_pci_pcibios_map_irq(const struct pci_dev *dev,
136} 255}
137 256
138 257
139/** 258/*
140 * Read a value from configuration space 259 * Read a value from configuration space
141 *
142 */ 260 */
143static int octeon_read_config(struct pci_bus *bus, unsigned int devfn, 261static int octeon_read_config(struct pci_bus *bus, unsigned int devfn,
144 int reg, int size, u32 *val) 262 int reg, int size, u32 *val)
@@ -174,15 +292,8 @@ static int octeon_read_config(struct pci_bus *bus, unsigned int devfn,
174} 292}
175 293
176 294
177/** 295/*
178 * Write a value to PCI configuration space 296 * Write a value to PCI configuration space
179 *
180 * @bus:
181 * @devfn:
182 * @reg:
183 * @size:
184 * @val:
185 * Returns
186 */ 297 */
187static int octeon_write_config(struct pci_bus *bus, unsigned int devfn, 298static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
188 int reg, int size, u32 val) 299 int reg, int size, u32 val)
@@ -251,10 +362,8 @@ static struct pci_controller octeon_pci_controller = {
251}; 362};
252 363
253 364
254/** 365/*
255 * Low level initialize the Octeon PCI controller 366 * Low level initialize the Octeon PCI controller
256 *
257 * Returns
258 */ 367 */
259static void octeon_pci_initialize(void) 368static void octeon_pci_initialize(void)
260{ 369{
@@ -398,7 +507,7 @@ static void octeon_pci_initialize(void)
398 pci_int_arb_cfg.s.en = 1; /* Internal arbiter enable */ 507 pci_int_arb_cfg.s.en = 1; /* Internal arbiter enable */
399 cvmx_write_csr(CVMX_NPI_PCI_INT_ARB_CFG, pci_int_arb_cfg.u64); 508 cvmx_write_csr(CVMX_NPI_PCI_INT_ARB_CFG, pci_int_arb_cfg.u64);
400 } 509 }
401#endif /* USE_OCTEON_INTERNAL_ARBITER */ 510#endif /* USE_OCTEON_INTERNAL_ARBITER */
402 511
403 /* 512 /*
404 * Preferrably written to 1 to set MLTD. [RDSATI,TRTAE, 513 * Preferrably written to 1 to set MLTD. [RDSATI,TRTAE,
@@ -457,10 +566,8 @@ static void octeon_pci_initialize(void)
457} 566}
458 567
459 568
460/** 569/*
461 * Initialize the Octeon PCI controller 570 * Initialize the Octeon PCI controller
462 *
463 * Returns
464 */ 571 */
465static int __init octeon_pci_setup(void) 572static int __init octeon_pci_setup(void)
466{ 573{
diff --git a/arch/mips/pci/pci-vr41xx.c b/arch/mips/pci/pci-vr41xx.c
index d1e049b55f34..56525711f8b7 100644
--- a/arch/mips/pci/pci-vr41xx.c
+++ b/arch/mips/pci/pci-vr41xx.c
@@ -2,8 +2,8 @@
2 * pci-vr41xx.c, PCI Control Unit routines for the NEC VR4100 series. 2 * pci-vr41xx.c, PCI Control Unit routines for the NEC VR4100 series.
3 * 3 *
4 * Copyright (C) 2001-2003 MontaVista Software Inc. 4 * Copyright (C) 2001-2003 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com> 5 * Author: Yoichi Yuasa <source@mvista.com>
6 * Copyright (C) 2004-2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 6 * Copyright (C) 2004-2008 Yoichi Yuasa <yuasa@linux-mips.org>
7 * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org) 7 * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
@@ -22,7 +22,7 @@
22 */ 22 */
23/* 23/*
24 * Changes: 24 * Changes:
25 * MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com> 25 * MontaVista Software Inc. <source@mvista.com>
26 * - New creation, NEC VR4122 and VR4131 are supported. 26 * - New creation, NEC VR4122 and VR4131 are supported.
27 */ 27 */
28#include <linux/init.h> 28#include <linux/init.h>
diff --git a/arch/mips/pci/pci-vr41xx.h b/arch/mips/pci/pci-vr41xx.h
index 8a35e32b8376..6b1ae2eb1c06 100644
--- a/arch/mips/pci/pci-vr41xx.h
+++ b/arch/mips/pci/pci-vr41xx.h
@@ -2,8 +2,8 @@
2 * pci-vr41xx.h, Include file for PCI Control Unit of the NEC VR4100 series. 2 * pci-vr41xx.h, Include file for PCI Control Unit of the NEC VR4100 series.
3 * 3 *
4 * Copyright (C) 2002 MontaVista Software Inc. 4 * Copyright (C) 2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com> 5 * Author: Yoichi Yuasa <source@mvista.com>
6 * Copyright (C) 2004-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 6 * Copyright (C) 2004-2005 Yoichi Yuasa <yuasa@linux-mips.org>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/cavium-octeon/pcie.c b/arch/mips/pci/pcie-octeon.c
index 49d14081b3b5..75262247f3e4 100644
--- a/arch/mips/cavium-octeon/pcie.c
+++ b/arch/mips/pci/pcie-octeon.c
@@ -18,8 +18,7 @@
18#include <asm/octeon/cvmx-pescx-defs.h> 18#include <asm/octeon/cvmx-pescx-defs.h>
19#include <asm/octeon/cvmx-pexp-defs.h> 19#include <asm/octeon/cvmx-pexp-defs.h>
20#include <asm/octeon/cvmx-helper-errata.h> 20#include <asm/octeon/cvmx-helper-errata.h>
21 21#include <asm/octeon/pci-octeon.h>
22#include "pci-common.h"
23 22
24union cvmx_pcie_address { 23union cvmx_pcie_address {
25 uint64_t u64; 24 uint64_t u64;
@@ -976,13 +975,13 @@ static int cvmx_pcie_rc_initialize(int pcie_port)
976/** 975/**
977 * Map a PCI device to the appropriate interrupt line 976 * Map a PCI device to the appropriate interrupt line
978 * 977 *
979 * @param dev The Linux PCI device structure for the device to map 978 * @dev: The Linux PCI device structure for the device to map
980 * @param slot The slot number for this device on __BUS 0__. Linux 979 * @slot: The slot number for this device on __BUS 0__. Linux
981 * enumerates through all the bridges and figures out the 980 * enumerates through all the bridges and figures out the
982 * slot on Bus 0 where this device eventually hooks to. 981 * slot on Bus 0 where this device eventually hooks to.
983 * @param pin The PCI interrupt pin read from the device, then swizzled 982 * @pin: The PCI interrupt pin read from the device, then swizzled
984 * as it goes through each bridge. 983 * as it goes through each bridge.
985 * @return Interrupt number for the device 984 * Returns Interrupt number for the device
986 */ 985 */
987int __init octeon_pcie_pcibios_map_irq(const struct pci_dev *dev, 986int __init octeon_pcie_pcibios_map_irq(const struct pci_dev *dev,
988 u8 slot, u8 pin) 987 u8 slot, u8 pin)
@@ -1025,12 +1024,12 @@ int __init octeon_pcie_pcibios_map_irq(const struct pci_dev *dev,
1025/** 1024/**
1026 * Read a value from configuration space 1025 * Read a value from configuration space
1027 * 1026 *
1028 * @param bus 1027 * @bus:
1029 * @param devfn 1028 * @devfn:
1030 * @param reg 1029 * @reg:
1031 * @param size 1030 * @size:
1032 * @param val 1031 * @val:
1033 * @return 1032 * Returns
1034 */ 1033 */
1035static inline int octeon_pcie_read_config(int pcie_port, struct pci_bus *bus, 1034static inline int octeon_pcie_read_config(int pcie_port, struct pci_bus *bus,
1036 unsigned int devfn, int reg, int size, 1035 unsigned int devfn, int reg, int size,
@@ -1156,12 +1155,12 @@ static int octeon_pcie1_read_config(struct pci_bus *bus, unsigned int devfn,
1156/** 1155/**
1157 * Write a value to PCI configuration space 1156 * Write a value to PCI configuration space
1158 * 1157 *
1159 * @param bus 1158 * @bus:
1160 * @param devfn 1159 * @devfn:
1161 * @param reg 1160 * @reg:
1162 * @param size 1161 * @size:
1163 * @param val 1162 * @val:
1164 * @return 1163 * Returns
1165 */ 1164 */
1166static inline int octeon_pcie_write_config(int pcie_port, struct pci_bus *bus, 1165static inline int octeon_pcie_write_config(int pcie_port, struct pci_bus *bus,
1167 unsigned int devfn, int reg, 1166 unsigned int devfn, int reg,
@@ -1254,7 +1253,7 @@ static struct pci_controller octeon_pcie1_controller = {
1254/** 1253/**
1255 * Initialize the Octeon PCIe controllers 1254 * Initialize the Octeon PCIe controllers
1256 * 1255 *
1257 * @return 1256 * Returns
1258 */ 1257 */
1259static int __init octeon_pcie_setup(void) 1258static int __init octeon_pcie_setup(void)
1260{ 1259{
diff --git a/arch/mips/vr41xx/casio-e55/setup.c b/arch/mips/vr41xx/casio-e55/setup.c
index 6d9bab890587..719f4a5b9844 100644
--- a/arch/mips/vr41xx/casio-e55/setup.c
+++ b/arch/mips/vr41xx/casio-e55/setup.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * setup.c, Setup for the CASIO CASSIOPEIA E-11/15/55/65. 2 * setup.c, Setup for the CASIO CASSIOPEIA E-11/15/55/65.
3 * 3 *
4 * Copyright (C) 2002-2006 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2002-2006 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/vr41xx/common/bcu.c b/arch/mips/vr41xx/common/bcu.c
index d77c330a0d59..6346c59c9f9d 100644
--- a/arch/mips/vr41xx/common/bcu.c
+++ b/arch/mips/vr41xx/common/bcu.c
@@ -2,8 +2,8 @@
2 * bcu.c, Bus Control Unit routines for the NEC VR4100 series. 2 * bcu.c, Bus Control Unit routines for the NEC VR4100 series.
3 * 3 *
4 * Copyright (C) 2002 MontaVista Software Inc. 4 * Copyright (C) 2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com, or source@mvista.com> 5 * Author: Yoichi Yuasa <source@mvista.com>
6 * Copyright (C) 2003-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 6 * Copyright (C) 2003-2005 Yoichi Yuasa <yuasa@linux-mips.org>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -21,11 +21,11 @@
21 */ 21 */
22/* 22/*
23 * Changes: 23 * Changes:
24 * MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com> 24 * MontaVista Software Inc. <source@mvista.com>
25 * - New creation, NEC VR4122 and VR4131 are supported. 25 * - New creation, NEC VR4122 and VR4131 are supported.
26 * - Added support for NEC VR4111 and VR4121. 26 * - Added support for NEC VR4111 and VR4121.
27 * 27 *
28 * Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 28 * Yoichi Yuasa <yuasa@linux-mips.org>
29 * - Added support for NEC VR4133. 29 * - Added support for NEC VR4133.
30 */ 30 */
31#include <linux/kernel.h> 31#include <linux/kernel.h>
diff --git a/arch/mips/vr41xx/common/cmu.c b/arch/mips/vr41xx/common/cmu.c
index ad0e8e3409d9..8ba7d04a5ec5 100644
--- a/arch/mips/vr41xx/common/cmu.c
+++ b/arch/mips/vr41xx/common/cmu.c
@@ -2,8 +2,8 @@
2 * cmu.c, Clock Mask Unit routines for the NEC VR4100 series. 2 * cmu.c, Clock Mask Unit routines for the NEC VR4100 series.
3 * 3 *
4 * Copyright (C) 2001-2002 MontaVista Software Inc. 4 * Copyright (C) 2001-2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com> 5 * Author: Yoichi Yuasa <source@mvista.com>
6 * Copuright (C) 2003-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 6 * Copuright (C) 2003-2005 Yoichi Yuasa <yuasa@linux-mips.org>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -21,11 +21,11 @@
21 */ 21 */
22/* 22/*
23 * Changes: 23 * Changes:
24 * MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com> 24 * MontaVista Software Inc. <source@mvista.com>
25 * - New creation, NEC VR4122 and VR4131 are supported. 25 * - New creation, NEC VR4122 and VR4131 are supported.
26 * - Added support for NEC VR4111 and VR4121. 26 * - Added support for NEC VR4111 and VR4121.
27 * 27 *
28 * Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 28 * Yoichi Yuasa <yuasa@linux-mips.org>
29 * - Added support for NEC VR4133. 29 * - Added support for NEC VR4133.
30 */ 30 */
31#include <linux/init.h> 31#include <linux/init.h>
diff --git a/arch/mips/vr41xx/common/giu.c b/arch/mips/vr41xx/common/giu.c
index 2b272f1496fe..22cc6f2100a1 100644
--- a/arch/mips/vr41xx/common/giu.c
+++ b/arch/mips/vr41xx/common/giu.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * NEC VR4100 series GIU platform device. 2 * NEC VR4100 series GIU platform device.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
index 3f23d9fda662..6d39e222b170 100644
--- a/arch/mips/vr41xx/common/icu.c
+++ b/arch/mips/vr41xx/common/icu.c
@@ -2,8 +2,8 @@
2 * icu.c, Interrupt Control Unit routines for the NEC VR4100 series. 2 * icu.c, Interrupt Control Unit routines for the NEC VR4100 series.
3 * 3 *
4 * Copyright (C) 2001-2002 MontaVista Software Inc. 4 * Copyright (C) 2001-2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com> 5 * Author: Yoichi Yuasa <source@mvista.com>
6 * Copyright (C) 2003-2006 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 6 * Copyright (C) 2003-2006 Yoichi Yuasa <yuasa@linux-mips.org>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -21,11 +21,11 @@
21 */ 21 */
22/* 22/*
23 * Changes: 23 * Changes:
24 * MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com> 24 * MontaVista Software Inc. <source@mvista.com>
25 * - New creation, NEC VR4122 and VR4131 are supported. 25 * - New creation, NEC VR4122 and VR4131 are supported.
26 * - Added support for NEC VR4111 and VR4121. 26 * - Added support for NEC VR4111 and VR4121.
27 * 27 *
28 * Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 28 * Yoichi Yuasa <yuasa@linux-mips.org>
29 * - Coped with INTASSIGN of NEC VR4133. 29 * - Coped with INTASSIGN of NEC VR4133.
30 */ 30 */
31#include <linux/errno.h> 31#include <linux/errno.h>
diff --git a/arch/mips/vr41xx/common/init.c b/arch/mips/vr41xx/common/init.c
index c64995342ba8..1386e6f081c8 100644
--- a/arch/mips/vr41xx/common/init.c
+++ b/arch/mips/vr41xx/common/init.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * init.c, Common initialization routines for NEC VR4100 series. 2 * init.c, Common initialization routines for NEC VR4100 series.
3 * 3 *
4 * Copyright (C) 2003-2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2003-2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
index 9cc389109b19..bef06872f012 100644
--- a/arch/mips/vr41xx/common/irq.c
+++ b/arch/mips/vr41xx/common/irq.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Interrupt handing routines for NEC VR4100 series. 2 * Interrupt handing routines for NEC VR4100 series.
3 * 3 *
4 * Copyright (C) 2005-2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2005-2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/vr41xx/common/pmu.c b/arch/mips/vr41xx/common/pmu.c
index 028aaf75eb21..692b4e85b7fc 100644
--- a/arch/mips/vr41xx/common/pmu.c
+++ b/arch/mips/vr41xx/common/pmu.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * pmu.c, Power Management Unit routines for NEC VR4100 series. 2 * pmu.c, Power Management Unit routines for NEC VR4100 series.
3 * 3 *
4 * Copyright (C) 2003-2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2003-2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/vr41xx/common/rtc.c b/arch/mips/vr41xx/common/rtc.c
index 9f26c14edcac..ebc5dcf0ed8e 100644
--- a/arch/mips/vr41xx/common/rtc.c
+++ b/arch/mips/vr41xx/common/rtc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * NEC VR4100 series RTC platform device. 2 * NEC VR4100 series RTC platform device.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/vr41xx/common/siu.c b/arch/mips/vr41xx/common/siu.c
index 654dee6208be..54eae56108fb 100644
--- a/arch/mips/vr41xx/common/siu.c
+++ b/arch/mips/vr41xx/common/siu.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * NEC VR4100 series SIU platform device. 2 * NEC VR4100 series SIU platform device.
3 * 3 *
4 * Copyright (C) 2007-2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007-2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/vr41xx/common/type.c b/arch/mips/vr41xx/common/type.c
index e0c1ac5e988e..ff841422b638 100644
--- a/arch/mips/vr41xx/common/type.c
+++ b/arch/mips/vr41xx/common/type.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * type.c, System type for NEC VR4100 series. 2 * type.c, System type for NEC VR4100 series.
3 * 3 *
4 * Copyright (C) 2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2005 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mips/vr41xx/ibm-workpad/setup.c b/arch/mips/vr41xx/ibm-workpad/setup.c
index 9eef297eca1a..3982f378a3e6 100644
--- a/arch/mips/vr41xx/ibm-workpad/setup.c
+++ b/arch/mips/vr41xx/ibm-workpad/setup.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * setup.c, Setup for the IBM WorkPad z50. 2 * setup.c, Setup for the IBM WorkPad z50.
3 * 3 *
4 * Copyright (C) 2002-2006 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2002-2006 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/arch/mn10300/include/asm/unistd.h b/arch/mn10300/include/asm/unistd.h
index fef5b434dadc..fad68616af32 100644
--- a/arch/mn10300/include/asm/unistd.h
+++ b/arch/mn10300/include/asm/unistd.h
@@ -346,10 +346,12 @@
346#define __NR_inotify_init1 333 346#define __NR_inotify_init1 333
347#define __NR_preadv 334 347#define __NR_preadv 334
348#define __NR_pwritev 335 348#define __NR_pwritev 335
349#define __NR_rt_tgsigqueueinfo 336
350#define __NR_perf_counter_open 337
349 351
350#ifdef __KERNEL__ 352#ifdef __KERNEL__
351 353
352#define NR_syscalls 326 354#define NR_syscalls 338
353 355
354/* 356/*
355 * specify the deprecated syscalls we want to support on this arch 357 * specify the deprecated syscalls we want to support on this arch
diff --git a/arch/mn10300/kernel/entry.S b/arch/mn10300/kernel/entry.S
index 7408a27199f3..e0d2563af4f2 100644
--- a/arch/mn10300/kernel/entry.S
+++ b/arch/mn10300/kernel/entry.S
@@ -722,6 +722,8 @@ ENTRY(sys_call_table)
722 .long sys_inotify_init1 722 .long sys_inotify_init1
723 .long sys_preadv 723 .long sys_preadv
724 .long sys_pwritev /* 335 */ 724 .long sys_pwritev /* 335 */
725 .long sys_rt_tgsigqueueinfo
726 .long sys_perf_counter_open
725 727
726 728
727nr_syscalls=(.-sys_call_table)/4 729nr_syscalls=(.-sys_call_table)/4
diff --git a/arch/mn10300/kernel/vmlinux.lds.S b/arch/mn10300/kernel/vmlinux.lds.S
index bcebcefb4ad7..c96ba3da95ac 100644
--- a/arch/mn10300/kernel/vmlinux.lds.S
+++ b/arch/mn10300/kernel/vmlinux.lds.S
@@ -61,7 +61,7 @@ SECTIONS
61 _edata = .; /* End of data section */ 61 _edata = .; /* End of data section */
62 } 62 }
63 63
64 .data.init_task : { INIT_TASK(THREAD_SIZE); } 64 .data.init_task : { INIT_TASK_DATA(THREAD_SIZE); }
65 65
66 /* might get freed after init */ 66 /* might get freed after init */
67 . = ALIGN(PAGE_SIZE); 67 . = ALIGN(PAGE_SIZE);
diff --git a/arch/parisc/Kconfig b/arch/parisc/Kconfig
index 9038f39d9d73..06f8d5b5b0f9 100644
--- a/arch/parisc/Kconfig
+++ b/arch/parisc/Kconfig
@@ -16,6 +16,8 @@ config PARISC
16 select RTC_DRV_GENERIC 16 select RTC_DRV_GENERIC
17 select INIT_ALL_POSSIBLE 17 select INIT_ALL_POSSIBLE
18 select BUG 18 select BUG
19 select HAVE_PERF_COUNTERS
20 select GENERIC_ATOMIC64 if !64BIT
19 help 21 help
20 The PA-RISC microprocessor is designed by Hewlett-Packard and used 22 The PA-RISC microprocessor is designed by Hewlett-Packard and used
21 in many of their workstations & servers (HP9000 700 and 800 series, 23 in many of their workstations & servers (HP9000 700 and 800 series,
diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
index 7eeaff944360..8bc9e96699b2 100644
--- a/arch/parisc/include/asm/atomic.h
+++ b/arch/parisc/include/asm/atomic.h
@@ -222,13 +222,13 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
222 222
223#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) 223#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
224 224
225#define atomic_add(i,v) ((void)(__atomic_add_return( ((int)(i)),(v)))) 225#define atomic_add(i,v) ((void)(__atomic_add_return( (i),(v))))
226#define atomic_sub(i,v) ((void)(__atomic_add_return(-((int)(i)),(v)))) 226#define atomic_sub(i,v) ((void)(__atomic_add_return(-(i),(v))))
227#define atomic_inc(v) ((void)(__atomic_add_return( 1,(v)))) 227#define atomic_inc(v) ((void)(__atomic_add_return( 1,(v))))
228#define atomic_dec(v) ((void)(__atomic_add_return( -1,(v)))) 228#define atomic_dec(v) ((void)(__atomic_add_return( -1,(v))))
229 229
230#define atomic_add_return(i,v) (__atomic_add_return( ((int)(i)),(v))) 230#define atomic_add_return(i,v) (__atomic_add_return( (i),(v)))
231#define atomic_sub_return(i,v) (__atomic_add_return(-((int)(i)),(v))) 231#define atomic_sub_return(i,v) (__atomic_add_return(-(i),(v)))
232#define atomic_inc_return(v) (__atomic_add_return( 1,(v))) 232#define atomic_inc_return(v) (__atomic_add_return( 1,(v)))
233#define atomic_dec_return(v) (__atomic_add_return( -1,(v))) 233#define atomic_dec_return(v) (__atomic_add_return( -1,(v)))
234 234
@@ -336,7 +336,11 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
336 336
337#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) 337#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
338 338
339#endif /* CONFIG_64BIT */ 339#else /* CONFIG_64BIT */
340
341#include <asm-generic/atomic64.h>
342
343#endif /* !CONFIG_64BIT */
340 344
341#include <asm-generic/atomic-long.h> 345#include <asm-generic/atomic-long.h>
342 346
diff --git a/arch/parisc/include/asm/dma.h b/arch/parisc/include/asm/dma.h
index 31ad0f05af3d..f7a18f968703 100644
--- a/arch/parisc/include/asm/dma.h
+++ b/arch/parisc/include/asm/dma.h
@@ -1,5 +1,4 @@
1/* $Id: dma.h,v 1.2 1999/04/27 00:46:18 deller Exp $ 1/* asm/dma.h: Defines for using and allocating dma channels.
2 * linux/include/asm/dma.h: Defines for using and allocating dma channels.
3 * Written by Hennus Bergman, 1992. 2 * Written by Hennus Bergman, 1992.
4 * High DMA channel support & info by Hannu Savolainen 3 * High DMA channel support & info by Hannu Savolainen
5 * and John Boyd, Nov. 1992. 4 * and John Boyd, Nov. 1992.
diff --git a/arch/parisc/include/asm/perf_counter.h b/arch/parisc/include/asm/perf_counter.h
new file mode 100644
index 000000000000..dc9e829f7013
--- /dev/null
+++ b/arch/parisc/include/asm/perf_counter.h
@@ -0,0 +1,7 @@
1#ifndef __ASM_PARISC_PERF_COUNTER_H
2#define __ASM_PARISC_PERF_COUNTER_H
3
4/* parisc only supports software counters through this interface. */
5static inline void set_perf_counter_pending(void) { }
6
7#endif /* __ASM_PARISC_PERF_COUNTER_H */
diff --git a/arch/parisc/include/asm/processor.h b/arch/parisc/include/asm/processor.h
index 9d64df8754ba..9ce66e9d1c2b 100644
--- a/arch/parisc/include/asm/processor.h
+++ b/arch/parisc/include/asm/processor.h
@@ -18,6 +18,7 @@
18#include <asm/types.h> 18#include <asm/types.h>
19#include <asm/system.h> 19#include <asm/system.h>
20#include <asm/percpu.h> 20#include <asm/percpu.h>
21
21#endif /* __ASSEMBLY__ */ 22#endif /* __ASSEMBLY__ */
22 23
23#define KERNEL_STACK_SIZE (4*PAGE_SIZE) 24#define KERNEL_STACK_SIZE (4*PAGE_SIZE)
@@ -127,6 +128,8 @@ struct thread_struct {
127 unsigned long flags; 128 unsigned long flags;
128}; 129};
129 130
131#define task_pt_regs(tsk) ((struct pt_regs *)&((tsk)->thread.regs))
132
130/* Thread struct flags. */ 133/* Thread struct flags. */
131#define PARISC_UAC_NOPRINT (1UL << 0) /* see prctl and unaligned.c */ 134#define PARISC_UAC_NOPRINT (1UL << 0) /* see prctl and unaligned.c */
132#define PARISC_UAC_SIGBUS (1UL << 1) 135#define PARISC_UAC_SIGBUS (1UL << 1)
diff --git a/arch/parisc/include/asm/system.h b/arch/parisc/include/asm/system.h
index ee80c920b464..d91357bca5b4 100644
--- a/arch/parisc/include/asm/system.h
+++ b/arch/parisc/include/asm/system.h
@@ -168,8 +168,8 @@ static inline void set_eiem(unsigned long val)
168/* LDCW, the only atomic read-write operation PA-RISC has. *sigh*. */ 168/* LDCW, the only atomic read-write operation PA-RISC has. *sigh*. */
169#define __ldcw(a) ({ \ 169#define __ldcw(a) ({ \
170 unsigned __ret; \ 170 unsigned __ret; \
171 __asm__ __volatile__(__LDCW " 0(%1),%0" \ 171 __asm__ __volatile__(__LDCW " 0(%2),%0" \
172 : "=r" (__ret) : "r" (a)); \ 172 : "=r" (__ret), "+m" (*(a)) : "r" (a)); \
173 __ret; \ 173 __ret; \
174}) 174})
175 175
diff --git a/arch/parisc/include/asm/tlbflush.h b/arch/parisc/include/asm/tlbflush.h
index 1f6fd4fc05b9..8f1a8100bf2d 100644
--- a/arch/parisc/include/asm/tlbflush.h
+++ b/arch/parisc/include/asm/tlbflush.h
@@ -12,14 +12,12 @@
12 * N class systems, only one PxTLB inter processor broadcast can be 12 * N class systems, only one PxTLB inter processor broadcast can be
13 * active at any one time on the Merced bus. This tlb purge 13 * active at any one time on the Merced bus. This tlb purge
14 * synchronisation is fairly lightweight and harmless so we activate 14 * synchronisation is fairly lightweight and harmless so we activate
15 * it on all SMP systems not just the N class. We also need to have 15 * it on all systems not just the N class.
16 * preemption disabled on uniprocessor machines, and spin_lock does that
17 * nicely.
18 */ 16 */
19extern spinlock_t pa_tlb_lock; 17extern spinlock_t pa_tlb_lock;
20 18
21#define purge_tlb_start(x) spin_lock(&pa_tlb_lock) 19#define purge_tlb_start(flags) spin_lock_irqsave(&pa_tlb_lock, flags)
22#define purge_tlb_end(x) spin_unlock(&pa_tlb_lock) 20#define purge_tlb_end(flags) spin_unlock_irqrestore(&pa_tlb_lock, flags)
23 21
24extern void flush_tlb_all(void); 22extern void flush_tlb_all(void);
25extern void flush_tlb_all_local(void *); 23extern void flush_tlb_all_local(void *);
@@ -63,14 +61,16 @@ static inline void flush_tlb_mm(struct mm_struct *mm)
63static inline void flush_tlb_page(struct vm_area_struct *vma, 61static inline void flush_tlb_page(struct vm_area_struct *vma,
64 unsigned long addr) 62 unsigned long addr)
65{ 63{
64 unsigned long flags;
65
66 /* For one page, it's not worth testing the split_tlb variable */ 66 /* For one page, it's not worth testing the split_tlb variable */
67 67
68 mb(); 68 mb();
69 mtsp(vma->vm_mm->context,1); 69 mtsp(vma->vm_mm->context,1);
70 purge_tlb_start(); 70 purge_tlb_start(flags);
71 pdtlb(addr); 71 pdtlb(addr);
72 pitlb(addr); 72 pitlb(addr);
73 purge_tlb_end(); 73 purge_tlb_end(flags);
74} 74}
75 75
76void __flush_tlb_range(unsigned long sid, 76void __flush_tlb_range(unsigned long sid,
diff --git a/arch/parisc/include/asm/unistd.h b/arch/parisc/include/asm/unistd.h
index ef26b009dc5d..f3d3b8b012c4 100644
--- a/arch/parisc/include/asm/unistd.h
+++ b/arch/parisc/include/asm/unistd.h
@@ -807,8 +807,12 @@
807#define __NR_dup3 (__NR_Linux + 312) 807#define __NR_dup3 (__NR_Linux + 312)
808#define __NR_pipe2 (__NR_Linux + 313) 808#define __NR_pipe2 (__NR_Linux + 313)
809#define __NR_inotify_init1 (__NR_Linux + 314) 809#define __NR_inotify_init1 (__NR_Linux + 314)
810#define __NR_preadv (__NR_Linux + 315)
811#define __NR_pwritev (__NR_Linux + 316)
812#define __NR_rt_tgsigqueueinfo (__NR_Linux + 317)
813#define __NR_perf_counter_open (__NR_Linux + 318)
810 814
811#define __NR_Linux_syscalls (__NR_inotify_init1 + 1) 815#define __NR_Linux_syscalls (__NR_perf_counter_open + 1)
812 816
813 817
814#define __IGNORE_select /* newselect */ 818#define __IGNORE_select /* newselect */
diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c
index 837530ea32e7..b6ed34de14e1 100644
--- a/arch/parisc/kernel/cache.c
+++ b/arch/parisc/kernel/cache.c
@@ -1,5 +1,4 @@
1/* $Id: cache.c,v 1.4 2000/01/25 00:11:38 prumpf Exp $ 1/*
2 *
3 * This file is subject to the terms and conditions of the GNU General Public 2 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
5 * for more details. 4 * for more details.
@@ -398,12 +397,13 @@ EXPORT_SYMBOL(flush_kernel_icache_range_asm);
398 397
399void clear_user_page_asm(void *page, unsigned long vaddr) 398void clear_user_page_asm(void *page, unsigned long vaddr)
400{ 399{
400 unsigned long flags;
401 /* This function is implemented in assembly in pacache.S */ 401 /* This function is implemented in assembly in pacache.S */
402 extern void __clear_user_page_asm(void *page, unsigned long vaddr); 402 extern void __clear_user_page_asm(void *page, unsigned long vaddr);
403 403
404 purge_tlb_start(); 404 purge_tlb_start(flags);
405 __clear_user_page_asm(page, vaddr); 405 __clear_user_page_asm(page, vaddr);
406 purge_tlb_end(); 406 purge_tlb_end(flags);
407} 407}
408 408
409#define FLUSH_THRESHOLD 0x80000 /* 0.5MB */ 409#define FLUSH_THRESHOLD 0x80000 /* 0.5MB */
@@ -444,20 +444,24 @@ extern void clear_user_page_asm(void *page, unsigned long vaddr);
444 444
445void clear_user_page(void *page, unsigned long vaddr, struct page *pg) 445void clear_user_page(void *page, unsigned long vaddr, struct page *pg)
446{ 446{
447 unsigned long flags;
448
447 purge_kernel_dcache_page((unsigned long)page); 449 purge_kernel_dcache_page((unsigned long)page);
448 purge_tlb_start(); 450 purge_tlb_start(flags);
449 pdtlb_kernel(page); 451 pdtlb_kernel(page);
450 purge_tlb_end(); 452 purge_tlb_end(flags);
451 clear_user_page_asm(page, vaddr); 453 clear_user_page_asm(page, vaddr);
452} 454}
453EXPORT_SYMBOL(clear_user_page); 455EXPORT_SYMBOL(clear_user_page);
454 456
455void flush_kernel_dcache_page_addr(void *addr) 457void flush_kernel_dcache_page_addr(void *addr)
456{ 458{
459 unsigned long flags;
460
457 flush_kernel_dcache_page_asm(addr); 461 flush_kernel_dcache_page_asm(addr);
458 purge_tlb_start(); 462 purge_tlb_start(flags);
459 pdtlb_kernel(addr); 463 pdtlb_kernel(addr);
460 purge_tlb_end(); 464 purge_tlb_end(flags);
461} 465}
462EXPORT_SYMBOL(flush_kernel_dcache_page_addr); 466EXPORT_SYMBOL(flush_kernel_dcache_page_addr);
463 467
@@ -490,8 +494,10 @@ void __flush_tlb_range(unsigned long sid, unsigned long start,
490 if (npages >= 512) /* 2MB of space: arbitrary, should be tuned */ 494 if (npages >= 512) /* 2MB of space: arbitrary, should be tuned */
491 flush_tlb_all(); 495 flush_tlb_all();
492 else { 496 else {
497 unsigned long flags;
498
493 mtsp(sid, 1); 499 mtsp(sid, 1);
494 purge_tlb_start(); 500 purge_tlb_start(flags);
495 if (split_tlb) { 501 if (split_tlb) {
496 while (npages--) { 502 while (npages--) {
497 pdtlb(start); 503 pdtlb(start);
@@ -504,7 +510,7 @@ void __flush_tlb_range(unsigned long sid, unsigned long start,
504 start += PAGE_SIZE; 510 start += PAGE_SIZE;
505 } 511 }
506 } 512 }
507 purge_tlb_end(); 513 purge_tlb_end(flags);
508 } 514 }
509} 515}
510 516
diff --git a/arch/parisc/kernel/inventory.c b/arch/parisc/kernel/inventory.c
index bd1f7f1ff74e..d228d8237879 100644
--- a/arch/parisc/kernel/inventory.c
+++ b/arch/parisc/kernel/inventory.c
@@ -170,23 +170,27 @@ static void __init pagezero_memconfig(void)
170static int __init 170static int __init
171pat_query_module(ulong pcell_loc, ulong mod_index) 171pat_query_module(ulong pcell_loc, ulong mod_index)
172{ 172{
173 pdc_pat_cell_mod_maddr_block_t pa_pdc_cell; 173 pdc_pat_cell_mod_maddr_block_t *pa_pdc_cell;
174 unsigned long bytecnt; 174 unsigned long bytecnt;
175 unsigned long temp; /* 64-bit scratch value */ 175 unsigned long temp; /* 64-bit scratch value */
176 long status; /* PDC return value status */ 176 long status; /* PDC return value status */
177 struct parisc_device *dev; 177 struct parisc_device *dev;
178 178
179 pa_pdc_cell = kmalloc(sizeof (*pa_pdc_cell), GFP_KERNEL);
180 if (!pa_pdc_cell)
181 panic("couldn't allocate memory for PDC_PAT_CELL!");
182
179 /* return cell module (PA or Processor view) */ 183 /* return cell module (PA or Processor view) */
180 status = pdc_pat_cell_module(&bytecnt, pcell_loc, mod_index, 184 status = pdc_pat_cell_module(&bytecnt, pcell_loc, mod_index,
181 PA_VIEW, &pa_pdc_cell); 185 PA_VIEW, pa_pdc_cell);
182 186
183 if (status != PDC_OK) { 187 if (status != PDC_OK) {
184 /* no more cell modules or error */ 188 /* no more cell modules or error */
185 return status; 189 return status;
186 } 190 }
187 191
188 temp = pa_pdc_cell.cba; 192 temp = pa_pdc_cell->cba;
189 dev = alloc_pa_dev(PAT_GET_CBA(temp), &pa_pdc_cell.mod_path); 193 dev = alloc_pa_dev(PAT_GET_CBA(temp), &(pa_pdc_cell->mod_path));
190 if (!dev) { 194 if (!dev) {
191 return PDC_OK; 195 return PDC_OK;
192 } 196 }
@@ -203,8 +207,8 @@ pat_query_module(ulong pcell_loc, ulong mod_index)
203 207
204 /* save generic info returned from the call */ 208 /* save generic info returned from the call */
205 /* REVISIT: who is the consumer of this? not sure yet... */ 209 /* REVISIT: who is the consumer of this? not sure yet... */
206 dev->mod_info = pa_pdc_cell.mod_info; /* pass to PAT_GET_ENTITY() */ 210 dev->mod_info = pa_pdc_cell->mod_info; /* pass to PAT_GET_ENTITY() */
207 dev->pmod_loc = pa_pdc_cell.mod_location; 211 dev->pmod_loc = pa_pdc_cell->mod_location;
208 212
209 register_parisc_device(dev); /* advertise device */ 213 register_parisc_device(dev); /* advertise device */
210 214
@@ -216,14 +220,14 @@ pat_query_module(ulong pcell_loc, ulong mod_index)
216 220
217 case PAT_ENTITY_PROC: 221 case PAT_ENTITY_PROC:
218 printk(KERN_DEBUG "PAT_ENTITY_PROC: id_eid 0x%lx\n", 222 printk(KERN_DEBUG "PAT_ENTITY_PROC: id_eid 0x%lx\n",
219 pa_pdc_cell.mod[0]); 223 pa_pdc_cell->mod[0]);
220 break; 224 break;
221 225
222 case PAT_ENTITY_MEM: 226 case PAT_ENTITY_MEM:
223 printk(KERN_DEBUG 227 printk(KERN_DEBUG
224 "PAT_ENTITY_MEM: amount 0x%lx min_gni_base 0x%lx min_gni_len 0x%lx\n", 228 "PAT_ENTITY_MEM: amount 0x%lx min_gni_base 0x%lx min_gni_len 0x%lx\n",
225 pa_pdc_cell.mod[0], pa_pdc_cell.mod[1], 229 pa_pdc_cell->mod[0], pa_pdc_cell->mod[1],
226 pa_pdc_cell.mod[2]); 230 pa_pdc_cell->mod[2]);
227 break; 231 break;
228 case PAT_ENTITY_CA: 232 case PAT_ENTITY_CA:
229 printk(KERN_DEBUG "PAT_ENTITY_CA: %ld\n", pcell_loc); 233 printk(KERN_DEBUG "PAT_ENTITY_CA: %ld\n", pcell_loc);
@@ -243,23 +247,26 @@ pat_query_module(ulong pcell_loc, ulong mod_index)
243 print_ranges: 247 print_ranges:
244 pdc_pat_cell_module(&bytecnt, pcell_loc, mod_index, 248 pdc_pat_cell_module(&bytecnt, pcell_loc, mod_index,
245 IO_VIEW, &io_pdc_cell); 249 IO_VIEW, &io_pdc_cell);
246 printk(KERN_DEBUG "ranges %ld\n", pa_pdc_cell.mod[1]); 250 printk(KERN_DEBUG "ranges %ld\n", pa_pdc_cell->mod[1]);
247 for (i = 0; i < pa_pdc_cell.mod[1]; i++) { 251 for (i = 0; i < pa_pdc_cell->mod[1]; i++) {
248 printk(KERN_DEBUG 252 printk(KERN_DEBUG
249 " PA_VIEW %ld: 0x%016lx 0x%016lx 0x%016lx\n", 253 " PA_VIEW %ld: 0x%016lx 0x%016lx 0x%016lx\n",
250 i, pa_pdc_cell.mod[2 + i * 3], /* type */ 254 i, pa_pdc_cell->mod[2 + i * 3], /* type */
251 pa_pdc_cell.mod[3 + i * 3], /* start */ 255 pa_pdc_cell->mod[3 + i * 3], /* start */
252 pa_pdc_cell.mod[4 + i * 3]); /* finish (ie end) */ 256 pa_pdc_cell->mod[4 + i * 3]); /* finish (ie end) */
253 printk(KERN_DEBUG 257 printk(KERN_DEBUG
254 " IO_VIEW %ld: 0x%016lx 0x%016lx 0x%016lx\n", 258 " IO_VIEW %ld: 0x%016lx 0x%016lx 0x%016lx\n",
255 i, io_pdc_cell.mod[2 + i * 3], /* type */ 259 i, io_pdc_cell->mod[2 + i * 3], /* type */
256 io_pdc_cell.mod[3 + i * 3], /* start */ 260 io_pdc_cell->mod[3 + i * 3], /* start */
257 io_pdc_cell.mod[4 + i * 3]); /* finish (ie end) */ 261 io_pdc_cell->mod[4 + i * 3]); /* finish (ie end) */
258 } 262 }
259 printk(KERN_DEBUG "\n"); 263 printk(KERN_DEBUG "\n");
260 break; 264 break;
261 } 265 }
262#endif /* DEBUG_PAT */ 266#endif /* DEBUG_PAT */
267
268 kfree(pa_pdc_cell);
269
263 return PDC_OK; 270 return PDC_OK;
264} 271}
265 272
diff --git a/arch/parisc/kernel/irq.c b/arch/parisc/kernel/irq.c
index 8007f1e65729..330f536a9324 100644
--- a/arch/parisc/kernel/irq.c
+++ b/arch/parisc/kernel/irq.c
@@ -120,7 +120,7 @@ int cpu_check_affinity(unsigned int irq, const struct cpumask *dest)
120 if (CHECK_IRQ_PER_CPU(irq)) { 120 if (CHECK_IRQ_PER_CPU(irq)) {
121 /* Bad linux design decision. The mask has already 121 /* Bad linux design decision. The mask has already
122 * been set; we must reset it */ 122 * been set; we must reset it */
123 cpumask_setall(&irq_desc[irq].affinity); 123 cpumask_setall(irq_desc[irq].affinity);
124 return -EINVAL; 124 return -EINVAL;
125 } 125 }
126 126
@@ -138,13 +138,13 @@ static int cpu_set_affinity_irq(unsigned int irq, const struct cpumask *dest)
138 if (cpu_dest < 0) 138 if (cpu_dest < 0)
139 return -1; 139 return -1;
140 140
141 cpumask_copy(&irq_desc[irq].affinity, dest); 141 cpumask_copy(irq_desc[irq].affinity, dest);
142 142
143 return 0; 143 return 0;
144} 144}
145#endif 145#endif
146 146
147static struct hw_interrupt_type cpu_interrupt_type = { 147static struct irq_chip cpu_interrupt_type = {
148 .typename = "CPU", 148 .typename = "CPU",
149 .startup = cpu_startup_irq, 149 .startup = cpu_startup_irq,
150 .shutdown = cpu_disable_irq, 150 .shutdown = cpu_disable_irq,
@@ -299,7 +299,7 @@ int txn_alloc_irq(unsigned int bits_wide)
299unsigned long txn_affinity_addr(unsigned int irq, int cpu) 299unsigned long txn_affinity_addr(unsigned int irq, int cpu)
300{ 300{
301#ifdef CONFIG_SMP 301#ifdef CONFIG_SMP
302 cpumask_copy(&irq_desc[irq].affinity, cpumask_of(cpu)); 302 cpumask_copy(irq_desc[irq].affinity, cpumask_of(cpu));
303#endif 303#endif
304 304
305 return per_cpu(cpu_data, cpu).txn_addr; 305 return per_cpu(cpu_data, cpu).txn_addr;
@@ -356,7 +356,7 @@ void do_cpu_irq_mask(struct pt_regs *regs)
356 irq = eirr_to_irq(eirr_val); 356 irq = eirr_to_irq(eirr_val);
357 357
358#ifdef CONFIG_SMP 358#ifdef CONFIG_SMP
359 cpumask_copy(&dest, &irq_desc[irq].affinity); 359 cpumask_copy(&dest, irq_desc[irq].affinity);
360 if (CHECK_IRQ_PER_CPU(irq_desc[irq].status) && 360 if (CHECK_IRQ_PER_CPU(irq_desc[irq].status) &&
361 !cpu_isset(smp_processor_id(), dest)) { 361 !cpu_isset(smp_processor_id(), dest)) {
362 int cpu = first_cpu(dest); 362 int cpu = first_cpu(dest);
diff --git a/arch/parisc/kernel/pci-dma.c b/arch/parisc/kernel/pci-dma.c
index 7d927eac932b..c07f618ff7da 100644
--- a/arch/parisc/kernel/pci-dma.c
+++ b/arch/parisc/kernel/pci-dma.c
@@ -90,12 +90,14 @@ static inline int map_pte_uncached(pte_t * pte,
90 if (end > PMD_SIZE) 90 if (end > PMD_SIZE)
91 end = PMD_SIZE; 91 end = PMD_SIZE;
92 do { 92 do {
93 unsigned long flags;
94
93 if (!pte_none(*pte)) 95 if (!pte_none(*pte))
94 printk(KERN_ERR "map_pte_uncached: page already exists\n"); 96 printk(KERN_ERR "map_pte_uncached: page already exists\n");
95 set_pte(pte, __mk_pte(*paddr_ptr, PAGE_KERNEL_UNC)); 97 set_pte(pte, __mk_pte(*paddr_ptr, PAGE_KERNEL_UNC));
96 purge_tlb_start(); 98 purge_tlb_start(flags);
97 pdtlb_kernel(orig_vaddr); 99 pdtlb_kernel(orig_vaddr);
98 purge_tlb_end(); 100 purge_tlb_end(flags);
99 vaddr += PAGE_SIZE; 101 vaddr += PAGE_SIZE;
100 orig_vaddr += PAGE_SIZE; 102 orig_vaddr += PAGE_SIZE;
101 (*paddr_ptr) += PAGE_SIZE; 103 (*paddr_ptr) += PAGE_SIZE;
@@ -168,11 +170,13 @@ static inline void unmap_uncached_pte(pmd_t * pmd, unsigned long vaddr,
168 if (end > PMD_SIZE) 170 if (end > PMD_SIZE)
169 end = PMD_SIZE; 171 end = PMD_SIZE;
170 do { 172 do {
173 unsigned long flags;
171 pte_t page = *pte; 174 pte_t page = *pte;
175
172 pte_clear(&init_mm, vaddr, pte); 176 pte_clear(&init_mm, vaddr, pte);
173 purge_tlb_start(); 177 purge_tlb_start(flags);
174 pdtlb_kernel(orig_vaddr); 178 pdtlb_kernel(orig_vaddr);
175 purge_tlb_end(); 179 purge_tlb_end(flags);
176 vaddr += PAGE_SIZE; 180 vaddr += PAGE_SIZE;
177 orig_vaddr += PAGE_SIZE; 181 orig_vaddr += PAGE_SIZE;
178 pte++; 182 pte++;
diff --git a/arch/parisc/kernel/pci.c b/arch/parisc/kernel/pci.c
index 6936386c9861..f7064abc3bb6 100644
--- a/arch/parisc/kernel/pci.c
+++ b/arch/parisc/kernel/pci.c
@@ -1,5 +1,4 @@
1/* $Id: pci.c,v 1.6 2000/01/29 00:12:05 grundler Exp $ 1/*
2 *
3 * This file is subject to the terms and conditions of the GNU General Public 2 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
5 * for more details. 4 * for more details.
diff --git a/arch/parisc/kernel/processor.c b/arch/parisc/kernel/processor.c
index e09d0f7fb6b0..c8fb61ed32f4 100644
--- a/arch/parisc/kernel/processor.c
+++ b/arch/parisc/kernel/processor.c
@@ -1,5 +1,4 @@
1/* $Id: processor.c,v 1.1 2002/07/20 16:27:06 rhirst Exp $ 1/*
2 *
3 * Initial setup-routines for HP 9000 based hardware. 2 * Initial setup-routines for HP 9000 based hardware.
4 * 3 *
5 * Copyright (C) 1991, 1992, 1995 Linus Torvalds 4 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
@@ -121,22 +120,28 @@ static int __cpuinit processor_probe(struct parisc_device *dev)
121 if (is_pdc_pat()) { 120 if (is_pdc_pat()) {
122 ulong status; 121 ulong status;
123 unsigned long bytecnt; 122 unsigned long bytecnt;
124 pdc_pat_cell_mod_maddr_block_t pa_pdc_cell; 123 pdc_pat_cell_mod_maddr_block_t *pa_pdc_cell;
125#undef USE_PAT_CPUID 124#undef USE_PAT_CPUID
126#ifdef USE_PAT_CPUID 125#ifdef USE_PAT_CPUID
127 struct pdc_pat_cpu_num cpu_info; 126 struct pdc_pat_cpu_num cpu_info;
128#endif 127#endif
129 128
129 pa_pdc_cell = kmalloc(sizeof (*pa_pdc_cell), GFP_KERNEL);
130 if (!pa_pdc_cell)
131 panic("couldn't allocate memory for PDC_PAT_CELL!");
132
130 status = pdc_pat_cell_module(&bytecnt, dev->pcell_loc, 133 status = pdc_pat_cell_module(&bytecnt, dev->pcell_loc,
131 dev->mod_index, PA_VIEW, &pa_pdc_cell); 134 dev->mod_index, PA_VIEW, pa_pdc_cell);
132 135
133 BUG_ON(PDC_OK != status); 136 BUG_ON(PDC_OK != status);
134 137
135 /* verify it's the same as what do_pat_inventory() found */ 138 /* verify it's the same as what do_pat_inventory() found */
136 BUG_ON(dev->mod_info != pa_pdc_cell.mod_info); 139 BUG_ON(dev->mod_info != pa_pdc_cell->mod_info);
137 BUG_ON(dev->pmod_loc != pa_pdc_cell.mod_location); 140 BUG_ON(dev->pmod_loc != pa_pdc_cell->mod_location);
141
142 txn_addr = pa_pdc_cell->mod[0]; /* id_eid for IO sapic */
138 143
139 txn_addr = pa_pdc_cell.mod[0]; /* id_eid for IO sapic */ 144 kfree(pa_pdc_cell);
140 145
141#ifdef USE_PAT_CPUID 146#ifdef USE_PAT_CPUID
142/* We need contiguous numbers for cpuid. Firmware's notion 147/* We need contiguous numbers for cpuid. Firmware's notion
diff --git a/arch/parisc/kernel/setup.c b/arch/parisc/kernel/setup.c
index 82131ca8e05c..cb71f3dac995 100644
--- a/arch/parisc/kernel/setup.c
+++ b/arch/parisc/kernel/setup.c
@@ -1,5 +1,4 @@
1/* $Id: setup.c,v 1.8 2000/02/02 04:42:38 prumpf Exp $ 1/*
2 *
3 * Initial setup-routines for HP 9000 based hardware. 2 * Initial setup-routines for HP 9000 based hardware.
4 * 3 *
5 * Copyright (C) 1991, 1992, 1995 Linus Torvalds 4 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
diff --git a/arch/parisc/kernel/sys_parisc32.c b/arch/parisc/kernel/sys_parisc32.c
index 1adb40c81669..92a0acaa0d12 100644
--- a/arch/parisc/kernel/sys_parisc32.c
+++ b/arch/parisc/kernel/sys_parisc32.c
@@ -174,68 +174,6 @@ asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
174 return ret; 174 return ret;
175} 175}
176 176
177/*** copied from mips64 ***/
178/*
179 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
180 * 64-bit unsigned longs.
181 */
182
183static inline int
184get_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
185{
186 n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
187 if (ufdset) {
188 unsigned long odd;
189
190 if (!access_ok(VERIFY_WRITE, ufdset, n*sizeof(u32)))
191 return -EFAULT;
192
193 odd = n & 1UL;
194 n &= ~1UL;
195 while (n) {
196 unsigned long h, l;
197 __get_user(l, ufdset);
198 __get_user(h, ufdset+1);
199 ufdset += 2;
200 *fdset++ = h << 32 | l;
201 n -= 2;
202 }
203 if (odd)
204 __get_user(*fdset, ufdset);
205 } else {
206 /* Tricky, must clear full unsigned long in the
207 * kernel fdset at the end, this makes sure that
208 * actually happens.
209 */
210 memset(fdset, 0, ((n + 1) & ~1)*sizeof(u32));
211 }
212 return 0;
213}
214
215static inline void
216set_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
217{
218 unsigned long odd;
219 n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
220
221 if (!ufdset)
222 return;
223
224 odd = n & 1UL;
225 n &= ~1UL;
226 while (n) {
227 unsigned long h, l;
228 l = *fdset++;
229 h = l >> 32;
230 __put_user(l, ufdset);
231 __put_user(h, ufdset+1);
232 ufdset += 2;
233 n -= 2;
234 }
235 if (odd)
236 __put_user(*fdset, ufdset);
237}
238
239struct msgbuf32 { 177struct msgbuf32 {
240 int mtype; 178 int mtype;
241 char mtext[1]; 179 char mtext[1];
diff --git a/arch/parisc/kernel/syscall_table.S b/arch/parisc/kernel/syscall_table.S
index 03b9a01bc16c..cf145eb026b3 100644
--- a/arch/parisc/kernel/syscall_table.S
+++ b/arch/parisc/kernel/syscall_table.S
@@ -413,6 +413,10 @@
413 ENTRY_SAME(dup3) 413 ENTRY_SAME(dup3)
414 ENTRY_SAME(pipe2) 414 ENTRY_SAME(pipe2)
415 ENTRY_SAME(inotify_init1) 415 ENTRY_SAME(inotify_init1)
416 ENTRY_COMP(preadv) /* 315 */
417 ENTRY_COMP(pwritev)
418 ENTRY_COMP(rt_tgsigqueueinfo)
419 ENTRY_SAME(perf_counter_open)
416 420
417 /* Nothing yet */ 421 /* Nothing yet */
418 422
diff --git a/arch/parisc/kernel/time.c b/arch/parisc/kernel/time.c
index d4dd05674c62..a79c6f9e7e2c 100644
--- a/arch/parisc/kernel/time.c
+++ b/arch/parisc/kernel/time.c
@@ -56,9 +56,9 @@ static unsigned long clocktick __read_mostly; /* timer cycles per tick */
56 */ 56 */
57irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id) 57irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id)
58{ 58{
59 unsigned long now; 59 unsigned long now, now2;
60 unsigned long next_tick; 60 unsigned long next_tick;
61 unsigned long cycles_elapsed, ticks_elapsed; 61 unsigned long cycles_elapsed, ticks_elapsed = 1;
62 unsigned long cycles_remainder; 62 unsigned long cycles_remainder;
63 unsigned int cpu = smp_processor_id(); 63 unsigned int cpu = smp_processor_id();
64 struct cpuinfo_parisc *cpuinfo = &per_cpu(cpu_data, cpu); 64 struct cpuinfo_parisc *cpuinfo = &per_cpu(cpu_data, cpu);
@@ -71,44 +71,24 @@ irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id)
71 /* Initialize next_tick to the expected tick time. */ 71 /* Initialize next_tick to the expected tick time. */
72 next_tick = cpuinfo->it_value; 72 next_tick = cpuinfo->it_value;
73 73
74 /* Get current interval timer. 74 /* Get current cycle counter (Control Register 16). */
75 * CR16 reads as 64 bits in CPU wide mode.
76 * CR16 reads as 32 bits in CPU narrow mode.
77 */
78 now = mfctl(16); 75 now = mfctl(16);
79 76
80 cycles_elapsed = now - next_tick; 77 cycles_elapsed = now - next_tick;
81 78
82 if ((cycles_elapsed >> 5) < cpt) { 79 if ((cycles_elapsed >> 6) < cpt) {
83 /* use "cheap" math (add/subtract) instead 80 /* use "cheap" math (add/subtract) instead
84 * of the more expensive div/mul method 81 * of the more expensive div/mul method
85 */ 82 */
86 cycles_remainder = cycles_elapsed; 83 cycles_remainder = cycles_elapsed;
87 ticks_elapsed = 1;
88 while (cycles_remainder > cpt) { 84 while (cycles_remainder > cpt) {
89 cycles_remainder -= cpt; 85 cycles_remainder -= cpt;
90 ticks_elapsed++; 86 ticks_elapsed++;
91 } 87 }
92 } else { 88 } else {
89 /* TODO: Reduce this to one fdiv op */
93 cycles_remainder = cycles_elapsed % cpt; 90 cycles_remainder = cycles_elapsed % cpt;
94 ticks_elapsed = 1 + cycles_elapsed / cpt; 91 ticks_elapsed += cycles_elapsed / cpt;
95 }
96
97 /* Can we differentiate between "early CR16" (aka Scenario 1) and
98 * "long delay" (aka Scenario 3)? I don't think so.
99 *
100 * We expected timer_interrupt to be delivered at least a few hundred
101 * cycles after the IT fires. But it's arbitrary how much time passes
102 * before we call it "late". I've picked one second.
103 */
104 if (unlikely(ticks_elapsed > HZ)) {
105 /* Scenario 3: very long delay? bad in any case */
106 printk (KERN_CRIT "timer_interrupt(CPU %d): delayed!"
107 " cycles %lX rem %lX "
108 " next/now %lX/%lX\n",
109 cpu,
110 cycles_elapsed, cycles_remainder,
111 next_tick, now );
112 } 92 }
113 93
114 /* convert from "division remainder" to "remainder of clock tick" */ 94 /* convert from "division remainder" to "remainder of clock tick" */
@@ -122,18 +102,56 @@ irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id)
122 102
123 cpuinfo->it_value = next_tick; 103 cpuinfo->it_value = next_tick;
124 104
125 /* Skip one clocktick on purpose if we are likely to miss next_tick. 105 /* Program the IT when to deliver the next interrupt.
126 * We want to avoid the new next_tick being less than CR16. 106 * Only bottom 32-bits of next_tick are writable in CR16!
127 * If that happened, itimer wouldn't fire until CR16 wrapped.
128 * We'll catch the tick we missed on the tick after that.
129 */ 107 */
130 if (!(cycles_remainder >> 13))
131 next_tick += cpt;
132
133 /* Program the IT when to deliver the next interrupt. */
134 /* Only bottom 32-bits of next_tick are written to cr16. */
135 mtctl(next_tick, 16); 108 mtctl(next_tick, 16);
136 109
110 /* Skip one clocktick on purpose if we missed next_tick.
111 * The new CR16 must be "later" than current CR16 otherwise
112 * itimer would not fire until CR16 wrapped - e.g 4 seconds
113 * later on a 1Ghz processor. We'll account for the missed
114 * tick on the next timer interrupt.
115 *
116 * "next_tick - now" will always give the difference regardless
117 * if one or the other wrapped. If "now" is "bigger" we'll end up
118 * with a very large unsigned number.
119 */
120 now2 = mfctl(16);
121 if (next_tick - now2 > cpt)
122 mtctl(next_tick+cpt, 16);
123
124#if 1
125/*
126 * GGG: DEBUG code for how many cycles programming CR16 used.
127 */
128 if (unlikely(now2 - now > 0x3000)) /* 12K cycles */
129 printk (KERN_CRIT "timer_interrupt(CPU %d): SLOW! 0x%lx cycles!"
130 " cyc %lX rem %lX "
131 " next/now %lX/%lX\n",
132 cpu, now2 - now, cycles_elapsed, cycles_remainder,
133 next_tick, now );
134#endif
135
136 /* Can we differentiate between "early CR16" (aka Scenario 1) and
137 * "long delay" (aka Scenario 3)? I don't think so.
138 *
139 * Timer_interrupt will be delivered at least a few hundred cycles
140 * after the IT fires. But it's arbitrary how much time passes
141 * before we call it "late". I've picked one second.
142 *
143 * It's important NO printk's are between reading CR16 and
144 * setting up the next value. May introduce huge variance.
145 */
146 if (unlikely(ticks_elapsed > HZ)) {
147 /* Scenario 3: very long delay? bad in any case */
148 printk (KERN_CRIT "timer_interrupt(CPU %d): delayed!"
149 " cycles %lX rem %lX "
150 " next/now %lX/%lX\n",
151 cpu,
152 cycles_elapsed, cycles_remainder,
153 next_tick, now );
154 }
137 155
138 /* Done mucking with unreliable delivery of interrupts. 156 /* Done mucking with unreliable delivery of interrupts.
139 * Go do system house keeping. 157 * Go do system house keeping.
@@ -173,7 +191,7 @@ EXPORT_SYMBOL(profile_pc);
173 191
174/* clock source code */ 192/* clock source code */
175 193
176static cycle_t read_cr16(void) 194static cycle_t read_cr16(struct clocksource *cs)
177{ 195{
178 return get_cycles(); 196 return get_cycles();
179} 197}
diff --git a/arch/parisc/lib/checksum.c b/arch/parisc/lib/checksum.c
index 462696d30d3b..ae66d31f9ecf 100644
--- a/arch/parisc/lib/checksum.c
+++ b/arch/parisc/lib/checksum.c
@@ -13,8 +13,6 @@
13 * modify it under the terms of the GNU General Public License 13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version. 15 * 2 of the License, or (at your option) any later version.
16 *
17 * $Id: checksum.c,v 1.3 1997/12/01 17:57:34 ralf Exp $
18 */ 16 */
19#include <linux/module.h> 17#include <linux/module.h>
20#include <linux/types.h> 18#include <linux/types.h>
diff --git a/arch/parisc/lib/memcpy.c b/arch/parisc/lib/memcpy.c
index bbda909c866e..abf41f4632a9 100644
--- a/arch/parisc/lib/memcpy.c
+++ b/arch/parisc/lib/memcpy.c
@@ -405,7 +405,7 @@ byte_copy:
405 405
406unaligned_copy: 406unaligned_copy:
407 /* possibly we are aligned on a word, but not on a double... */ 407 /* possibly we are aligned on a word, but not on a double... */
408 if (likely(t1 & (sizeof(unsigned int)-1)) == 0) { 408 if (likely((t1 & (sizeof(unsigned int)-1)) == 0)) {
409 t2 = src & (sizeof(unsigned int) - 1); 409 t2 = src & (sizeof(unsigned int) - 1);
410 410
411 if (unlikely(t2 != 0)) { 411 if (unlikely(t2 != 0)) {
diff --git a/arch/parisc/math-emu/decode_exc.c b/arch/parisc/math-emu/decode_exc.c
index 66c8a9f6a27e..3ca1c6149218 100644
--- a/arch/parisc/math-emu/decode_exc.c
+++ b/arch/parisc/math-emu/decode_exc.c
@@ -40,7 +40,7 @@
40 * END_DESC 40 * END_DESC
41*/ 41*/
42 42
43 43#include <linux/kernel.h>
44#include "float.h" 44#include "float.h"
45#include "sgl_float.h" 45#include "sgl_float.h"
46#include "dbl_float.h" 46#include "dbl_float.h"
diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
index bfb6dd6ab380..c6afbfc95770 100644
--- a/arch/parisc/mm/fault.c
+++ b/arch/parisc/mm/fault.c
@@ -1,5 +1,4 @@
1/* $Id: fault.c,v 1.5 2000/01/26 16:20:29 jsm Exp $ 1/*
2 *
3 * This file is subject to the terms and conditions of the GNU General Public 2 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
5 * for more details. 4 * for more details.
diff --git a/arch/parisc/mm/init.c b/arch/parisc/mm/init.c
index 4356ceb1e366..b0831d9e35cb 100644
--- a/arch/parisc/mm/init.c
+++ b/arch/parisc/mm/init.c
@@ -370,34 +370,22 @@ static void __init setup_bootmem(void)
370 370
371void free_initmem(void) 371void free_initmem(void)
372{ 372{
373 unsigned long addr, init_begin, init_end; 373 unsigned long addr;
374 374 unsigned long init_begin = (unsigned long)__init_begin;
375 printk(KERN_INFO "Freeing unused kernel memory: "); 375 unsigned long init_end = (unsigned long)__init_end;
376 376
377#ifdef CONFIG_DEBUG_KERNEL 377#ifdef CONFIG_DEBUG_KERNEL
378 /* Attempt to catch anyone trying to execute code here 378 /* Attempt to catch anyone trying to execute code here
379 * by filling the page with BRK insns. 379 * by filling the page with BRK insns.
380 *
381 * If we disable interrupts for all CPUs, then IPI stops working.
382 * Kinda breaks the global cache flushing.
383 */ 380 */
384 local_irq_disable(); 381 memset((void *)init_begin, 0x00, init_end - init_begin);
385 382 flush_icache_range(init_begin, init_end);
386 memset(__init_begin, 0x00,
387 (unsigned long)__init_end - (unsigned long)__init_begin);
388
389 flush_data_cache();
390 asm volatile("sync" : : );
391 flush_icache_range((unsigned long)__init_begin, (unsigned long)__init_end);
392 asm volatile("sync" : : );
393
394 local_irq_enable();
395#endif 383#endif
396 384
397 /* align __init_begin and __init_end to page size, 385 /* align __init_begin and __init_end to page size,
398 ignoring linker script where we might have tried to save RAM */ 386 ignoring linker script where we might have tried to save RAM */
399 init_begin = PAGE_ALIGN((unsigned long)(__init_begin)); 387 init_begin = PAGE_ALIGN(init_begin);
400 init_end = PAGE_ALIGN((unsigned long)(__init_end)); 388 init_end = PAGE_ALIGN(init_end);
401 for (addr = init_begin; addr < init_end; addr += PAGE_SIZE) { 389 for (addr = init_begin; addr < init_end; addr += PAGE_SIZE) {
402 ClearPageReserved(virt_to_page(addr)); 390 ClearPageReserved(virt_to_page(addr));
403 init_page_count(virt_to_page(addr)); 391 init_page_count(virt_to_page(addr));
@@ -409,7 +397,8 @@ void free_initmem(void)
409 /* set up a new led state on systems shipped LED State panel */ 397 /* set up a new led state on systems shipped LED State panel */
410 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BCOMPLETE); 398 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BCOMPLETE);
411 399
412 printk("%luk freed\n", (init_end - init_begin) >> 10); 400 printk(KERN_INFO "Freeing unused kernel memory: %luk freed\n",
401 (init_end - init_begin) >> 10);
413} 402}
414 403
415 404
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index bf6cedfa05db..d00131ca0835 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -62,7 +62,6 @@ config HAVE_LATENCYTOP_SUPPORT
62 62
63config TRACE_IRQFLAGS_SUPPORT 63config TRACE_IRQFLAGS_SUPPORT
64 bool 64 bool
65 depends on PPC64
66 default y 65 default y
67 66
68config LOCKDEP_SUPPORT 67config LOCKDEP_SUPPORT
diff --git a/arch/powerpc/boot/.gitignore b/arch/powerpc/boot/.gitignore
index 2f50acd11a60..3d80c3e9cf60 100644
--- a/arch/powerpc/boot/.gitignore
+++ b/arch/powerpc/boot/.gitignore
@@ -36,3 +36,13 @@ zImage.pseries
36zconf.h 36zconf.h
37zlib.h 37zlib.h
38zutil.h 38zutil.h
39fdt.c
40fdt.h
41fdt_ro.c
42fdt_rw.c
43fdt_strerror.c
44fdt_sw.c
45fdt_wip.c
46libfdt.h
47libfdt_internal.h
48
diff --git a/arch/powerpc/boot/dts/amigaone.dts b/arch/powerpc/boot/dts/amigaone.dts
index 26549fca2ed4..49ac36b16dd7 100644
--- a/arch/powerpc/boot/dts/amigaone.dts
+++ b/arch/powerpc/boot/dts/amigaone.dts
@@ -70,8 +70,8 @@
70 devsel-speed = <0x00000001>; 70 devsel-speed = <0x00000001>;
71 min-grant = <0>; 71 min-grant = <0>;
72 max-latency = <0>; 72 max-latency = <0>;
73 /* First 64k for I/O at 0x0 on PCI mapped to 0x0 on ISA. */ 73 /* First 4k for I/O at 0x0 on PCI mapped to 0x0 on ISA. */
74 ranges = <0x00000001 0 0x01000000 0 0x00000000 0x00010000>; 74 ranges = <0x00000001 0 0x01000000 0 0x00000000 0x00001000>;
75 interrupt-parent = <&i8259>; 75 interrupt-parent = <&i8259>;
76 #interrupt-cells = <2>; 76 #interrupt-cells = <2>;
77 #address-cells = <2>; 77 #address-cells = <2>;
diff --git a/arch/powerpc/boot/dts/mpc8569mds.dts b/arch/powerpc/boot/dts/mpc8569mds.dts
index a8dcb018c4a5..a680165292f2 100644
--- a/arch/powerpc/boot/dts/mpc8569mds.dts
+++ b/arch/powerpc/boot/dts/mpc8569mds.dts
@@ -253,6 +253,7 @@
253 /* Filled in by U-Boot */ 253 /* Filled in by U-Boot */
254 clock-frequency = <0>; 254 clock-frequency = <0>;
255 status = "disabled"; 255 status = "disabled";
256 sdhci,1-bit-only;
256 }; 257 };
257 258
258 crypto@30000 { 259 crypto@30000 {
diff --git a/arch/powerpc/include/asm/cpm1.h b/arch/powerpc/include/asm/cpm1.h
index 2ff798744c1d..7685ffde8821 100644
--- a/arch/powerpc/include/asm/cpm1.h
+++ b/arch/powerpc/include/asm/cpm1.h
@@ -598,8 +598,6 @@ typedef struct risc_timer_pram {
598#define CICR_IEN ((uint)0x00000080) /* Int. enable */ 598#define CICR_IEN ((uint)0x00000080) /* Int. enable */
599#define CICR_SPS ((uint)0x00000001) /* SCC Spread */ 599#define CICR_SPS ((uint)0x00000001) /* SCC Spread */
600 600
601#define IMAP_ADDR (get_immrbase())
602
603#define CPM_PIN_INPUT 0 601#define CPM_PIN_INPUT 0
604#define CPM_PIN_OUTPUT 1 602#define CPM_PIN_OUTPUT 1
605#define CPM_PIN_PRIMARY 0 603#define CPM_PIN_PRIMARY 0
diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h
index 3d9e887c3c0c..b44aaabdd1a6 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -309,7 +309,9 @@ static inline void dma_sync_single_for_cpu(struct device *dev,
309 struct dma_mapping_ops *dma_ops = get_dma_ops(dev); 309 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
310 310
311 BUG_ON(!dma_ops); 311 BUG_ON(!dma_ops);
312 dma_ops->sync_single_range_for_cpu(dev, dma_handle, 0, 312
313 if (dma_ops->sync_single_range_for_cpu)
314 dma_ops->sync_single_range_for_cpu(dev, dma_handle, 0,
313 size, direction); 315 size, direction);
314} 316}
315 317
@@ -320,7 +322,9 @@ static inline void dma_sync_single_for_device(struct device *dev,
320 struct dma_mapping_ops *dma_ops = get_dma_ops(dev); 322 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
321 323
322 BUG_ON(!dma_ops); 324 BUG_ON(!dma_ops);
323 dma_ops->sync_single_range_for_device(dev, dma_handle, 325
326 if (dma_ops->sync_single_range_for_device)
327 dma_ops->sync_single_range_for_device(dev, dma_handle,
324 0, size, direction); 328 0, size, direction);
325} 329}
326 330
@@ -331,7 +335,9 @@ static inline void dma_sync_sg_for_cpu(struct device *dev,
331 struct dma_mapping_ops *dma_ops = get_dma_ops(dev); 335 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
332 336
333 BUG_ON(!dma_ops); 337 BUG_ON(!dma_ops);
334 dma_ops->sync_sg_for_cpu(dev, sgl, nents, direction); 338
339 if (dma_ops->sync_sg_for_cpu)
340 dma_ops->sync_sg_for_cpu(dev, sgl, nents, direction);
335} 341}
336 342
337static inline void dma_sync_sg_for_device(struct device *dev, 343static inline void dma_sync_sg_for_device(struct device *dev,
@@ -341,7 +347,9 @@ static inline void dma_sync_sg_for_device(struct device *dev,
341 struct dma_mapping_ops *dma_ops = get_dma_ops(dev); 347 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
342 348
343 BUG_ON(!dma_ops); 349 BUG_ON(!dma_ops);
344 dma_ops->sync_sg_for_device(dev, sgl, nents, direction); 350
351 if (dma_ops->sync_sg_for_device)
352 dma_ops->sync_sg_for_device(dev, sgl, nents, direction);
345} 353}
346 354
347static inline void dma_sync_single_range_for_cpu(struct device *dev, 355static inline void dma_sync_single_range_for_cpu(struct device *dev,
@@ -351,7 +359,9 @@ static inline void dma_sync_single_range_for_cpu(struct device *dev,
351 struct dma_mapping_ops *dma_ops = get_dma_ops(dev); 359 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
352 360
353 BUG_ON(!dma_ops); 361 BUG_ON(!dma_ops);
354 dma_ops->sync_single_range_for_cpu(dev, dma_handle, 362
363 if (dma_ops->sync_single_range_for_cpu)
364 dma_ops->sync_single_range_for_cpu(dev, dma_handle,
355 offset, size, direction); 365 offset, size, direction);
356} 366}
357 367
@@ -362,7 +372,9 @@ static inline void dma_sync_single_range_for_device(struct device *dev,
362 struct dma_mapping_ops *dma_ops = get_dma_ops(dev); 372 struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
363 373
364 BUG_ON(!dma_ops); 374 BUG_ON(!dma_ops);
365 dma_ops->sync_single_range_for_device(dev, dma_handle, offset, 375
376 if (dma_ops->sync_single_range_for_device)
377 dma_ops->sync_single_range_for_device(dev, dma_handle, offset,
366 size, direction); 378 size, direction);
367} 379}
368#else /* CONFIG_PPC_NEED_DMA_SYNC_OPS */ 380#else /* CONFIG_PPC_NEED_DMA_SYNC_OPS */
diff --git a/arch/powerpc/include/asm/highmem.h b/arch/powerpc/include/asm/highmem.h
index 684a73f4324f..a74c4ee6c020 100644
--- a/arch/powerpc/include/asm/highmem.h
+++ b/arch/powerpc/include/asm/highmem.h
@@ -22,9 +22,7 @@
22 22
23#ifdef __KERNEL__ 23#ifdef __KERNEL__
24 24
25#include <linux/init.h>
26#include <linux/interrupt.h> 25#include <linux/interrupt.h>
27#include <linux/highmem.h>
28#include <asm/kmap_types.h> 26#include <asm/kmap_types.h>
29#include <asm/tlbflush.h> 27#include <asm/tlbflush.h>
30#include <asm/page.h> 28#include <asm/page.h>
@@ -62,6 +60,9 @@ extern pte_t *pkmap_page_table;
62 60
63extern void *kmap_high(struct page *page); 61extern void *kmap_high(struct page *page);
64extern void kunmap_high(struct page *page); 62extern void kunmap_high(struct page *page);
63extern void *kmap_atomic_prot(struct page *page, enum km_type type,
64 pgprot_t prot);
65extern void kunmap_atomic(void *kvaddr, enum km_type type);
65 66
66static inline void *kmap(struct page *page) 67static inline void *kmap(struct page *page)
67{ 68{
@@ -79,62 +80,11 @@ static inline void kunmap(struct page *page)
79 kunmap_high(page); 80 kunmap_high(page);
80} 81}
81 82
82/*
83 * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
84 * gives a more generic (and caching) interface. But kmap_atomic can
85 * be used in IRQ contexts, so in some (very limited) cases we need
86 * it.
87 */
88static inline void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot)
89{
90 unsigned int idx;
91 unsigned long vaddr;
92
93 /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
94 pagefault_disable();
95 if (!PageHighMem(page))
96 return page_address(page);
97
98 debug_kmap_atomic(type);
99 idx = type + KM_TYPE_NR*smp_processor_id();
100 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
101#ifdef CONFIG_DEBUG_HIGHMEM
102 BUG_ON(!pte_none(*(kmap_pte-idx)));
103#endif
104 __set_pte_at(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot), 1);
105 local_flush_tlb_page(NULL, vaddr);
106
107 return (void*) vaddr;
108}
109
110static inline void *kmap_atomic(struct page *page, enum km_type type) 83static inline void *kmap_atomic(struct page *page, enum km_type type)
111{ 84{
112 return kmap_atomic_prot(page, type, kmap_prot); 85 return kmap_atomic_prot(page, type, kmap_prot);
113} 86}
114 87
115static inline void kunmap_atomic(void *kvaddr, enum km_type type)
116{
117#ifdef CONFIG_DEBUG_HIGHMEM
118 unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
119 enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
120
121 if (vaddr < __fix_to_virt(FIX_KMAP_END)) {
122 pagefault_enable();
123 return;
124 }
125
126 BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
127
128 /*
129 * force other mappings to Oops if they'll try to access
130 * this pte without first remap it
131 */
132 pte_clear(&init_mm, vaddr, kmap_pte-idx);
133 local_flush_tlb_page(NULL, vaddr);
134#endif
135 pagefault_enable();
136}
137
138static inline struct page *kmap_atomic_to_page(void *ptr) 88static inline struct page *kmap_atomic_to_page(void *ptr)
139{ 89{
140 unsigned long idx, vaddr = (unsigned long) ptr; 90 unsigned long idx, vaddr = (unsigned long) ptr;
@@ -148,6 +98,7 @@ static inline struct page *kmap_atomic_to_page(void *ptr)
148 return pte_page(*pte); 98 return pte_page(*pte);
149} 99}
150 100
101
151#define flush_cache_kmaps() flush_cache_all() 102#define flush_cache_kmaps() flush_cache_all()
152 103
153#endif /* __KERNEL__ */ 104#endif /* __KERNEL__ */
diff --git a/arch/powerpc/include/asm/hw_irq.h b/arch/powerpc/include/asm/hw_irq.h
index 867ab8ed69b3..8b505eaaa38a 100644
--- a/arch/powerpc/include/asm/hw_irq.h
+++ b/arch/powerpc/include/asm/hw_irq.h
@@ -68,13 +68,13 @@ static inline int irqs_disabled_flags(unsigned long flags)
68 68
69#if defined(CONFIG_BOOKE) 69#if defined(CONFIG_BOOKE)
70#define SET_MSR_EE(x) mtmsr(x) 70#define SET_MSR_EE(x) mtmsr(x)
71#define local_irq_restore(flags) __asm__ __volatile__("wrtee %0" : : "r" (flags) : "memory") 71#define raw_local_irq_restore(flags) __asm__ __volatile__("wrtee %0" : : "r" (flags) : "memory")
72#else 72#else
73#define SET_MSR_EE(x) mtmsr(x) 73#define SET_MSR_EE(x) mtmsr(x)
74#define local_irq_restore(flags) mtmsr(flags) 74#define raw_local_irq_restore(flags) mtmsr(flags)
75#endif 75#endif
76 76
77static inline void local_irq_disable(void) 77static inline void raw_local_irq_disable(void)
78{ 78{
79#ifdef CONFIG_BOOKE 79#ifdef CONFIG_BOOKE
80 __asm__ __volatile__("wrteei 0": : :"memory"); 80 __asm__ __volatile__("wrteei 0": : :"memory");
@@ -86,7 +86,7 @@ static inline void local_irq_disable(void)
86#endif 86#endif
87} 87}
88 88
89static inline void local_irq_enable(void) 89static inline void raw_local_irq_enable(void)
90{ 90{
91#ifdef CONFIG_BOOKE 91#ifdef CONFIG_BOOKE
92 __asm__ __volatile__("wrteei 1": : :"memory"); 92 __asm__ __volatile__("wrteei 1": : :"memory");
@@ -98,7 +98,7 @@ static inline void local_irq_enable(void)
98#endif 98#endif
99} 99}
100 100
101static inline void local_irq_save_ptr(unsigned long *flags) 101static inline void raw_local_irq_save_ptr(unsigned long *flags)
102{ 102{
103 unsigned long msr; 103 unsigned long msr;
104 msr = mfmsr(); 104 msr = mfmsr();
@@ -110,12 +110,12 @@ static inline void local_irq_save_ptr(unsigned long *flags)
110#endif 110#endif
111} 111}
112 112
113#define local_save_flags(flags) ((flags) = mfmsr()) 113#define raw_local_save_flags(flags) ((flags) = mfmsr())
114#define local_irq_save(flags) local_irq_save_ptr(&flags) 114#define raw_local_irq_save(flags) raw_local_irq_save_ptr(&flags)
115#define irqs_disabled() ((mfmsr() & MSR_EE) == 0) 115#define raw_irqs_disabled() ((mfmsr() & MSR_EE) == 0)
116#define raw_irqs_disabled_flags(flags) (((flags) & MSR_EE) == 0)
116 117
117#define hard_irq_enable() local_irq_enable() 118#define hard_irq_disable() raw_local_irq_disable()
118#define hard_irq_disable() local_irq_disable()
119 119
120static inline int irqs_disabled_flags(unsigned long flags) 120static inline int irqs_disabled_flags(unsigned long flags)
121{ 121{
diff --git a/arch/powerpc/include/asm/perf_counter.h b/arch/powerpc/include/asm/perf_counter.h
index 8ccd4e155768..0ea0639fcf75 100644
--- a/arch/powerpc/include/asm/perf_counter.h
+++ b/arch/powerpc/include/asm/perf_counter.h
@@ -61,6 +61,8 @@ struct pt_regs;
61extern unsigned long perf_misc_flags(struct pt_regs *regs); 61extern unsigned long perf_misc_flags(struct pt_regs *regs);
62extern unsigned long perf_instruction_pointer(struct pt_regs *regs); 62extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
63 63
64#define PERF_COUNTER_INDEX_OFFSET 1
65
64/* 66/*
65 * Only override the default definitions in include/linux/perf_counter.h 67 * Only override the default definitions in include/linux/perf_counter.h
66 * if we have hardware PMU support. 68 * if we have hardware PMU support.
diff --git a/arch/powerpc/include/asm/pte-hash64-64k.h b/arch/powerpc/include/asm/pte-hash64-64k.h
index e05d26fa372f..82b72207c51c 100644
--- a/arch/powerpc/include/asm/pte-hash64-64k.h
+++ b/arch/powerpc/include/asm/pte-hash64-64k.h
@@ -47,7 +47,8 @@
47 * generic accessors and iterators here 47 * generic accessors and iterators here
48 */ 48 */
49#define __real_pte(e,p) ((real_pte_t) { \ 49#define __real_pte(e,p) ((real_pte_t) { \
50 (e), pte_val(*((p) + PTRS_PER_PTE)) }) 50 (e), ((e) & _PAGE_COMBO) ? \
51 (pte_val(*((p) + PTRS_PER_PTE))) : 0 })
51#define __rpte_to_hidx(r,index) ((pte_val((r).pte) & _PAGE_COMBO) ? \ 52#define __rpte_to_hidx(r,index) ((pte_val((r).pte) & _PAGE_COMBO) ? \
52 (((r).hidx >> ((index)<<2)) & 0xf) : ((pte_val((r).pte) >> 12) & 0xf)) 53 (((r).hidx >> ((index)<<2)) & 0xf) : ((pte_val((r).pte) >> 12) & 0xf))
53#define __rpte_to_pte(r) ((r).pte) 54#define __rpte_to_pte(r) ((r).pte)
diff --git a/arch/powerpc/include/asm/rtas.h b/arch/powerpc/include/asm/rtas.h
index 01c12339b304..168fce726201 100644
--- a/arch/powerpc/include/asm/rtas.h
+++ b/arch/powerpc/include/asm/rtas.h
@@ -58,7 +58,7 @@ struct rtas_t {
58 unsigned long entry; /* physical address pointer */ 58 unsigned long entry; /* physical address pointer */
59 unsigned long base; /* physical address pointer */ 59 unsigned long base; /* physical address pointer */
60 unsigned long size; 60 unsigned long size;
61 spinlock_t lock; 61 raw_spinlock_t lock;
62 struct rtas_args args; 62 struct rtas_args args;
63 struct device_node *dev; /* virtual address pointer */ 63 struct device_node *dev; /* virtual address pointer */
64}; 64};
@@ -245,5 +245,8 @@ static inline u32 rtas_config_addr(int busno, int devfn, int reg)
245 (devfn << 8) | (reg & 0xff); 245 (devfn << 8) | (reg & 0xff);
246} 246}
247 247
248extern void __cpuinit rtas_give_timebase(void);
249extern void __cpuinit rtas_take_timebase(void);
250
248#endif /* __KERNEL__ */ 251#endif /* __KERNEL__ */
249#endif /* _POWERPC_RTAS_H */ 252#endif /* _POWERPC_RTAS_H */
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 4dd38f129153..3cadba60a4b6 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -191,11 +191,49 @@ transfer_to_handler_cont:
191 mflr r9 191 mflr r9
192 lwz r11,0(r9) /* virtual address of handler */ 192 lwz r11,0(r9) /* virtual address of handler */
193 lwz r9,4(r9) /* where to go when done */ 193 lwz r9,4(r9) /* where to go when done */
194#ifdef CONFIG_TRACE_IRQFLAGS
195 lis r12,reenable_mmu@h
196 ori r12,r12,reenable_mmu@l
197 mtspr SPRN_SRR0,r12
198 mtspr SPRN_SRR1,r10
199 SYNC
200 RFI
201reenable_mmu: /* re-enable mmu so we can */
202 mfmsr r10
203 lwz r12,_MSR(r1)
204 xor r10,r10,r12
205 andi. r10,r10,MSR_EE /* Did EE change? */
206 beq 1f
207
208 /* Save handler and return address into the 2 unused words
209 * of the STACK_FRAME_OVERHEAD (sneak sneak sneak). Everything
210 * else can be recovered from the pt_regs except r3 which for
211 * normal interrupts has been set to pt_regs and for syscalls
212 * is an argument, so we temporarily use ORIG_GPR3 to save it
213 */
214 stw r9,8(r1)
215 stw r11,12(r1)
216 stw r3,ORIG_GPR3(r1)
217 bl trace_hardirqs_off
218 lwz r0,GPR0(r1)
219 lwz r3,ORIG_GPR3(r1)
220 lwz r4,GPR4(r1)
221 lwz r5,GPR5(r1)
222 lwz r6,GPR6(r1)
223 lwz r7,GPR7(r1)
224 lwz r8,GPR8(r1)
225 lwz r9,8(r1)
226 lwz r11,12(r1)
2271: mtctr r11
228 mtlr r9
229 bctr /* jump to handler */
230#else /* CONFIG_TRACE_IRQFLAGS */
194 mtspr SPRN_SRR0,r11 231 mtspr SPRN_SRR0,r11
195 mtspr SPRN_SRR1,r10 232 mtspr SPRN_SRR1,r10
196 mtlr r9 233 mtlr r9
197 SYNC 234 SYNC
198 RFI /* jump to handler, enable MMU */ 235 RFI /* jump to handler, enable MMU */
236#endif /* CONFIG_TRACE_IRQFLAGS */
199 237
200#if defined (CONFIG_6xx) || defined(CONFIG_E500) 238#if defined (CONFIG_6xx) || defined(CONFIG_E500)
2014: rlwinm r12,r12,0,~_TLF_NAPPING 2394: rlwinm r12,r12,0,~_TLF_NAPPING
@@ -251,6 +289,31 @@ _GLOBAL(DoSyscall)
251#ifdef SHOW_SYSCALLS 289#ifdef SHOW_SYSCALLS
252 bl do_show_syscall 290 bl do_show_syscall
253#endif /* SHOW_SYSCALLS */ 291#endif /* SHOW_SYSCALLS */
292#ifdef CONFIG_TRACE_IRQFLAGS
293 /* Return from syscalls can (and generally will) hard enable
294 * interrupts. You aren't supposed to call a syscall with
295 * interrupts disabled in the first place. However, to ensure
296 * that we get it right vs. lockdep if it happens, we force
297 * that hard enable here with appropriate tracing if we see
298 * that we have been called with interrupts off
299 */
300 mfmsr r11
301 andi. r12,r11,MSR_EE
302 bne+ 1f
303 /* We came in with interrupts disabled, we enable them now */
304 bl trace_hardirqs_on
305 mfmsr r11
306 lwz r0,GPR0(r1)
307 lwz r3,GPR3(r1)
308 lwz r4,GPR4(r1)
309 ori r11,r11,MSR_EE
310 lwz r5,GPR5(r1)
311 lwz r6,GPR6(r1)
312 lwz r7,GPR7(r1)
313 lwz r8,GPR8(r1)
314 mtmsr r11
3151:
316#endif /* CONFIG_TRACE_IRQFLAGS */
254 rlwinm r10,r1,0,0,(31-THREAD_SHIFT) /* current_thread_info() */ 317 rlwinm r10,r1,0,0,(31-THREAD_SHIFT) /* current_thread_info() */
255 lwz r11,TI_FLAGS(r10) 318 lwz r11,TI_FLAGS(r10)
256 andi. r11,r11,_TIF_SYSCALL_T_OR_A 319 andi. r11,r11,_TIF_SYSCALL_T_OR_A
@@ -275,6 +338,7 @@ ret_from_syscall:
275 rlwinm r12,r1,0,0,(31-THREAD_SHIFT) /* current_thread_info() */ 338 rlwinm r12,r1,0,0,(31-THREAD_SHIFT) /* current_thread_info() */
276 /* disable interrupts so current_thread_info()->flags can't change */ 339 /* disable interrupts so current_thread_info()->flags can't change */
277 LOAD_MSR_KERNEL(r10,MSR_KERNEL) /* doesn't include MSR_EE */ 340 LOAD_MSR_KERNEL(r10,MSR_KERNEL) /* doesn't include MSR_EE */
341 /* Note: We don't bother telling lockdep about it */
278 SYNC 342 SYNC
279 MTMSRD(r10) 343 MTMSRD(r10)
280 lwz r9,TI_FLAGS(r12) 344 lwz r9,TI_FLAGS(r12)
@@ -288,6 +352,19 @@ ret_from_syscall:
288 oris r11,r11,0x1000 /* Set SO bit in CR */ 352 oris r11,r11,0x1000 /* Set SO bit in CR */
289 stw r11,_CCR(r1) 353 stw r11,_CCR(r1)
290syscall_exit_cont: 354syscall_exit_cont:
355 lwz r8,_MSR(r1)
356#ifdef CONFIG_TRACE_IRQFLAGS
357 /* If we are going to return from the syscall with interrupts
358 * off, we trace that here. It shouldn't happen though but we
359 * want to catch the bugger if it does right ?
360 */
361 andi. r10,r8,MSR_EE
362 bne+ 1f
363 stw r3,GPR3(r1)
364 bl trace_hardirqs_off
365 lwz r3,GPR3(r1)
3661:
367#endif /* CONFIG_TRACE_IRQFLAGS */
291#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE) 368#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
292 /* If the process has its own DBCR0 value, load it up. The internal 369 /* If the process has its own DBCR0 value, load it up. The internal
293 debug mode bit tells us that dbcr0 should be loaded. */ 370 debug mode bit tells us that dbcr0 should be loaded. */
@@ -311,7 +388,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
311 mtlr r4 388 mtlr r4
312 mtcr r5 389 mtcr r5
313 lwz r7,_NIP(r1) 390 lwz r7,_NIP(r1)
314 lwz r8,_MSR(r1)
315 FIX_SRR1(r8, r0) 391 FIX_SRR1(r8, r0)
316 lwz r2,GPR2(r1) 392 lwz r2,GPR2(r1)
317 lwz r1,GPR1(r1) 393 lwz r1,GPR1(r1)
@@ -394,7 +470,9 @@ syscall_exit_work:
394 andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP) 470 andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP)
395 beq ret_from_except 471 beq ret_from_except
396 472
397 /* Re-enable interrupts */ 473 /* Re-enable interrupts. There is no need to trace that with
474 * lockdep as we are supposed to have IRQs on at this point
475 */
398 ori r10,r10,MSR_EE 476 ori r10,r10,MSR_EE
399 SYNC 477 SYNC
400 MTMSRD(r10) 478 MTMSRD(r10)
@@ -705,6 +783,7 @@ ret_from_except:
705 /* Hard-disable interrupts so that current_thread_info()->flags 783 /* Hard-disable interrupts so that current_thread_info()->flags
706 * can't change between when we test it and when we return 784 * can't change between when we test it and when we return
707 * from the interrupt. */ 785 * from the interrupt. */
786 /* Note: We don't bother telling lockdep about it */
708 LOAD_MSR_KERNEL(r10,MSR_KERNEL) 787 LOAD_MSR_KERNEL(r10,MSR_KERNEL)
709 SYNC /* Some chip revs have problems here... */ 788 SYNC /* Some chip revs have problems here... */
710 MTMSRD(r10) /* disable interrupts */ 789 MTMSRD(r10) /* disable interrupts */
@@ -744,11 +823,24 @@ resume_kernel:
744 beq+ restore 823 beq+ restore
745 andi. r0,r3,MSR_EE /* interrupts off? */ 824 andi. r0,r3,MSR_EE /* interrupts off? */
746 beq restore /* don't schedule if so */ 825 beq restore /* don't schedule if so */
826#ifdef CONFIG_TRACE_IRQFLAGS
827 /* Lockdep thinks irqs are enabled, we need to call
828 * preempt_schedule_irq with IRQs off, so we inform lockdep
829 * now that we -did- turn them off already
830 */
831 bl trace_hardirqs_off
832#endif
7471: bl preempt_schedule_irq 8331: bl preempt_schedule_irq
748 rlwinm r9,r1,0,0,(31-THREAD_SHIFT) 834 rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
749 lwz r3,TI_FLAGS(r9) 835 lwz r3,TI_FLAGS(r9)
750 andi. r0,r3,_TIF_NEED_RESCHED 836 andi. r0,r3,_TIF_NEED_RESCHED
751 bne- 1b 837 bne- 1b
838#ifdef CONFIG_TRACE_IRQFLAGS
839 /* And now, to properly rebalance the above, we tell lockdep they
840 * are being turned back on, which will happen when we return
841 */
842 bl trace_hardirqs_on
843#endif
752#else 844#else
753resume_kernel: 845resume_kernel:
754#endif /* CONFIG_PREEMPT */ 846#endif /* CONFIG_PREEMPT */
@@ -765,6 +857,28 @@ restore:
765 stw r6,icache_44x_need_flush@l(r4) 857 stw r6,icache_44x_need_flush@l(r4)
7661: 8581:
767#endif /* CONFIG_44x */ 859#endif /* CONFIG_44x */
860
861 lwz r9,_MSR(r1)
862#ifdef CONFIG_TRACE_IRQFLAGS
863 /* Lockdep doesn't know about the fact that IRQs are temporarily turned
864 * off in this assembly code while peeking at TI_FLAGS() and such. However
865 * we need to inform it if the exception turned interrupts off, and we
866 * are about to trun them back on.
867 *
868 * The problem here sadly is that we don't know whether the exceptions was
869 * one that turned interrupts off or not. So we always tell lockdep about
870 * turning them on here when we go back to wherever we came from with EE
871 * on, even if that may meen some redudant calls being tracked. Maybe later
872 * we could encode what the exception did somewhere or test the exception
873 * type in the pt_regs but that sounds overkill
874 */
875 andi. r10,r9,MSR_EE
876 beq 1f
877 bl trace_hardirqs_on
878 lwz r9,_MSR(r1)
8791:
880#endif /* CONFIG_TRACE_IRQFLAGS */
881
768 lwz r0,GPR0(r1) 882 lwz r0,GPR0(r1)
769 lwz r2,GPR2(r1) 883 lwz r2,GPR2(r1)
770 REST_4GPRS(3, r1) 884 REST_4GPRS(3, r1)
@@ -782,7 +896,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
782 stwcx. r0,0,r1 /* to clear the reservation */ 896 stwcx. r0,0,r1 /* to clear the reservation */
783 897
784#if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE)) 898#if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
785 lwz r9,_MSR(r1)
786 andi. r10,r9,MSR_RI /* check if this exception occurred */ 899 andi. r10,r9,MSR_RI /* check if this exception occurred */
787 beql nonrecoverable /* at a bad place (MSR:RI = 0) */ 900 beql nonrecoverable /* at a bad place (MSR:RI = 0) */
788 901
@@ -805,7 +918,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
805 MTMSRD(r10) /* clear the RI bit */ 918 MTMSRD(r10) /* clear the RI bit */
806 .globl exc_exit_restart 919 .globl exc_exit_restart
807exc_exit_restart: 920exc_exit_restart:
808 lwz r9,_MSR(r1)
809 lwz r12,_NIP(r1) 921 lwz r12,_NIP(r1)
810 FIX_SRR1(r9,r10) 922 FIX_SRR1(r9,r10)
811 mtspr SPRN_SRR0,r12 923 mtspr SPRN_SRR0,r12
@@ -1035,11 +1147,18 @@ do_work: /* r10 contains MSR_KERNEL here */
1035 beq do_user_signal 1147 beq do_user_signal
1036 1148
1037do_resched: /* r10 contains MSR_KERNEL here */ 1149do_resched: /* r10 contains MSR_KERNEL here */
1150 /* Note: We don't need to inform lockdep that we are enabling
1151 * interrupts here. As far as it knows, they are already enabled
1152 */
1038 ori r10,r10,MSR_EE 1153 ori r10,r10,MSR_EE
1039 SYNC 1154 SYNC
1040 MTMSRD(r10) /* hard-enable interrupts */ 1155 MTMSRD(r10) /* hard-enable interrupts */
1041 bl schedule 1156 bl schedule
1042recheck: 1157recheck:
1158 /* Note: And we don't tell it we are disabling them again
1159 * neither. Those disable/enable cycles used to peek at
1160 * TI_FLAGS aren't advertised.
1161 */
1043 LOAD_MSR_KERNEL(r10,MSR_KERNEL) 1162 LOAD_MSR_KERNEL(r10,MSR_KERNEL)
1044 SYNC 1163 SYNC
1045 MTMSRD(r10) /* disable interrupts */ 1164 MTMSRD(r10) /* disable interrupts */
diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S
index 48469463f89e..fc2132942754 100644
--- a/arch/powerpc/kernel/head_32.S
+++ b/arch/powerpc/kernel/head_32.S
@@ -1124,9 +1124,8 @@ mmu_off:
1124 RFI 1124 RFI
1125 1125
1126/* 1126/*
1127 * Use the first pair of BAT registers to map the 1st 16MB 1127 * On 601, we use 3 BATs to map up to 24M of RAM at _PAGE_OFFSET
1128 * of RAM to PAGE_OFFSET. From this point on we can't safely 1128 * (we keep one for debugging) and on others, we use one 256M BAT.
1129 * call OF any more.
1130 */ 1129 */
1131initial_bats: 1130initial_bats:
1132 lis r11,PAGE_OFFSET@h 1131 lis r11,PAGE_OFFSET@h
@@ -1136,12 +1135,16 @@ initial_bats:
1136 bne 4f 1135 bne 4f
1137 ori r11,r11,4 /* set up BAT registers for 601 */ 1136 ori r11,r11,4 /* set up BAT registers for 601 */
1138 li r8,0x7f /* valid, block length = 8MB */ 1137 li r8,0x7f /* valid, block length = 8MB */
1139 oris r9,r11,0x800000@h /* set up BAT reg for 2nd 8M */
1140 oris r10,r8,0x800000@h /* set up BAT reg for 2nd 8M */
1141 mtspr SPRN_IBAT0U,r11 /* N.B. 601 has valid bit in */ 1138 mtspr SPRN_IBAT0U,r11 /* N.B. 601 has valid bit in */
1142 mtspr SPRN_IBAT0L,r8 /* lower BAT register */ 1139 mtspr SPRN_IBAT0L,r8 /* lower BAT register */
1143 mtspr SPRN_IBAT1U,r9 1140 addis r11,r11,0x800000@h
1144 mtspr SPRN_IBAT1L,r10 1141 addis r8,r8,0x800000@h
1142 mtspr SPRN_IBAT1U,r11
1143 mtspr SPRN_IBAT1L,r8
1144 addis r11,r11,0x800000@h
1145 addis r8,r8,0x800000@h
1146 mtspr SPRN_IBAT2U,r11
1147 mtspr SPRN_IBAT2L,r8
1145 isync 1148 isync
1146 blr 1149 blr
1147 1150
diff --git a/arch/powerpc/kernel/of_device.c b/arch/powerpc/kernel/of_device.c
index fa983a59c4ce..a359cb08e900 100644
--- a/arch/powerpc/kernel/of_device.c
+++ b/arch/powerpc/kernel/of_device.c
@@ -76,7 +76,7 @@ struct of_device *of_device_alloc(struct device_node *np,
76 dev->dev.archdata.of_node = np; 76 dev->dev.archdata.of_node = np;
77 77
78 if (bus_id) 78 if (bus_id)
79 dev_set_name(&dev->dev, bus_id); 79 dev_set_name(&dev->dev, "%s", bus_id);
80 else 80 else
81 of_device_make_bus_id(dev); 81 of_device_make_bus_id(dev);
82 82
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 3e7135bbe40f..892a9f2e6d76 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -528,7 +528,7 @@ void show_regs(struct pt_regs * regs)
528 528
529 for (i = 0; i < 32; i++) { 529 for (i = 0; i < 32; i++) {
530 if ((i % REGS_PER_LINE) == 0) 530 if ((i % REGS_PER_LINE) == 0)
531 printk("\n" KERN_INFO "GPR%02d: ", i); 531 printk("\nGPR%02d: ", i);
532 printk(REG " ", regs->gpr[i]); 532 printk(REG " ", regs->gpr[i]);
533 if (i == LAST_VOLATILE && !FULL_REGS(regs)) 533 if (i == LAST_VOLATILE && !FULL_REGS(regs))
534 break; 534 break;
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index ee4c7609b649..c434823b8c83 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -38,9 +38,10 @@
38#include <asm/syscalls.h> 38#include <asm/syscalls.h>
39#include <asm/smp.h> 39#include <asm/smp.h>
40#include <asm/atomic.h> 40#include <asm/atomic.h>
41#include <asm/time.h>
41 42
42struct rtas_t rtas = { 43struct rtas_t rtas = {
43 .lock = SPIN_LOCK_UNLOCKED 44 .lock = __RAW_SPIN_LOCK_UNLOCKED
44}; 45};
45EXPORT_SYMBOL(rtas); 46EXPORT_SYMBOL(rtas);
46 47
@@ -67,6 +68,28 @@ unsigned long rtas_rmo_buf;
67void (*rtas_flash_term_hook)(int); 68void (*rtas_flash_term_hook)(int);
68EXPORT_SYMBOL(rtas_flash_term_hook); 69EXPORT_SYMBOL(rtas_flash_term_hook);
69 70
71/* RTAS use home made raw locking instead of spin_lock_irqsave
72 * because those can be called from within really nasty contexts
73 * such as having the timebase stopped which would lockup with
74 * normal locks and spinlock debugging enabled
75 */
76static unsigned long lock_rtas(void)
77{
78 unsigned long flags;
79
80 local_irq_save(flags);
81 preempt_disable();
82 __raw_spin_lock_flags(&rtas.lock, flags);
83 return flags;
84}
85
86static void unlock_rtas(unsigned long flags)
87{
88 __raw_spin_unlock(&rtas.lock);
89 local_irq_restore(flags);
90 preempt_enable();
91}
92
70/* 93/*
71 * call_rtas_display_status and call_rtas_display_status_delay 94 * call_rtas_display_status and call_rtas_display_status_delay
72 * are designed only for very early low-level debugging, which 95 * are designed only for very early low-level debugging, which
@@ -79,7 +102,7 @@ static void call_rtas_display_status(char c)
79 102
80 if (!rtas.base) 103 if (!rtas.base)
81 return; 104 return;
82 spin_lock_irqsave(&rtas.lock, s); 105 s = lock_rtas();
83 106
84 args->token = 10; 107 args->token = 10;
85 args->nargs = 1; 108 args->nargs = 1;
@@ -89,7 +112,7 @@ static void call_rtas_display_status(char c)
89 112
90 enter_rtas(__pa(args)); 113 enter_rtas(__pa(args));
91 114
92 spin_unlock_irqrestore(&rtas.lock, s); 115 unlock_rtas(s);
93} 116}
94 117
95static void call_rtas_display_status_delay(char c) 118static void call_rtas_display_status_delay(char c)
@@ -411,8 +434,7 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
411 if (!rtas.entry || token == RTAS_UNKNOWN_SERVICE) 434 if (!rtas.entry || token == RTAS_UNKNOWN_SERVICE)
412 return -1; 435 return -1;
413 436
414 /* Gotta do something different here, use global lock for now... */ 437 s = lock_rtas();
415 spin_lock_irqsave(&rtas.lock, s);
416 rtas_args = &rtas.args; 438 rtas_args = &rtas.args;
417 439
418 rtas_args->token = token; 440 rtas_args->token = token;
@@ -439,8 +461,7 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)
439 outputs[i] = rtas_args->rets[i+1]; 461 outputs[i] = rtas_args->rets[i+1];
440 ret = (nret > 0)? rtas_args->rets[0]: 0; 462 ret = (nret > 0)? rtas_args->rets[0]: 0;
441 463
442 /* Gotta do something different here, use global lock for now... */ 464 unlock_rtas(s);
443 spin_unlock_irqrestore(&rtas.lock, s);
444 465
445 if (buff_copy) { 466 if (buff_copy) {
446 log_error(buff_copy, ERR_TYPE_RTAS_LOG, 0); 467 log_error(buff_copy, ERR_TYPE_RTAS_LOG, 0);
@@ -837,7 +858,7 @@ asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
837 858
838 buff_copy = get_errorlog_buffer(); 859 buff_copy = get_errorlog_buffer();
839 860
840 spin_lock_irqsave(&rtas.lock, flags); 861 flags = lock_rtas();
841 862
842 rtas.args = args; 863 rtas.args = args;
843 enter_rtas(__pa(&rtas.args)); 864 enter_rtas(__pa(&rtas.args));
@@ -848,7 +869,7 @@ asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
848 if (args.rets[0] == -1) 869 if (args.rets[0] == -1)
849 errbuf = __fetch_rtas_last_error(buff_copy); 870 errbuf = __fetch_rtas_last_error(buff_copy);
850 871
851 spin_unlock_irqrestore(&rtas.lock, flags); 872 unlock_rtas(flags);
852 873
853 if (buff_copy) { 874 if (buff_copy) {
854 if (errbuf) 875 if (errbuf)
@@ -951,3 +972,33 @@ int __init early_init_dt_scan_rtas(unsigned long node,
951 /* break now */ 972 /* break now */
952 return 1; 973 return 1;
953} 974}
975
976static raw_spinlock_t timebase_lock;
977static u64 timebase = 0;
978
979void __cpuinit rtas_give_timebase(void)
980{
981 unsigned long flags;
982
983 local_irq_save(flags);
984 hard_irq_disable();
985 __raw_spin_lock(&timebase_lock);
986 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
987 timebase = get_tb();
988 __raw_spin_unlock(&timebase_lock);
989
990 while (timebase)
991 barrier();
992 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
993 local_irq_restore(flags);
994}
995
996void __cpuinit rtas_take_timebase(void)
997{
998 while (!timebase)
999 barrier();
1000 __raw_spin_lock(&timebase_lock);
1001 set_tb(timebase >> 32, timebase & 0xffffffff);
1002 timebase = 0;
1003 __raw_spin_unlock(&timebase_lock);
1004}
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index 1d154248cf40..e1e3059cf34b 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -119,6 +119,8 @@ notrace unsigned long __init early_init(unsigned long dt_ptr)
119 */ 119 */
120notrace void __init machine_init(unsigned long dt_ptr) 120notrace void __init machine_init(unsigned long dt_ptr)
121{ 121{
122 lockdep_init();
123
122 /* Enable early debugging if any specified (see udbg.h) */ 124 /* Enable early debugging if any specified (see udbg.h) */
123 udbg_early_init(); 125 udbg_early_init();
124 126
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 65484b2200b3..0b47de07302d 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -68,7 +68,8 @@ EXPORT_PER_CPU_SYMBOL(cpu_core_map);
68/* SMP operations for this machine */ 68/* SMP operations for this machine */
69struct smp_ops_t *smp_ops; 69struct smp_ops_t *smp_ops;
70 70
71static volatile unsigned int cpu_callin_map[NR_CPUS]; 71/* Can't be static due to PowerMac hackery */
72volatile unsigned int cpu_callin_map[NR_CPUS];
72 73
73int smt_enabled_at_boot = 1; 74int smt_enabled_at_boot = 1;
74 75
diff --git a/arch/powerpc/kernel/udbg_16550.c b/arch/powerpc/kernel/udbg_16550.c
index 0362a891e54e..acb74a17bbbf 100644
--- a/arch/powerpc/kernel/udbg_16550.c
+++ b/arch/powerpc/kernel/udbg_16550.c
@@ -219,7 +219,7 @@ void udbg_init_pas_realmode(void)
219#ifdef CONFIG_PPC_EARLY_DEBUG_44x 219#ifdef CONFIG_PPC_EARLY_DEBUG_44x
220#include <platforms/44x/44x.h> 220#include <platforms/44x/44x.h>
221 221
222static int udbg_44x_as1_flush(void) 222static void udbg_44x_as1_flush(void)
223{ 223{
224 if (udbg_comport) { 224 if (udbg_comport) {
225 while ((as1_readb(&udbg_comport->lsr) & LSR_THRE) == 0) 225 while ((as1_readb(&udbg_comport->lsr) & LSR_THRE) == 0)
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index 2d2192e48de7..3e68363405b7 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -30,3 +30,4 @@ obj-$(CONFIG_PPC_MM_SLICES) += slice.o
30obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o 30obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
31obj-$(CONFIG_PPC_SUBPAGE_PROT) += subpage-prot.o 31obj-$(CONFIG_PPC_SUBPAGE_PROT) += subpage-prot.o
32obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o 32obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
33obj-$(CONFIG_HIGHMEM) += highmem.o
diff --git a/arch/powerpc/mm/highmem.c b/arch/powerpc/mm/highmem.c
new file mode 100644
index 000000000000..c2186c74c85a
--- /dev/null
+++ b/arch/powerpc/mm/highmem.c
@@ -0,0 +1,77 @@
1/*
2 * highmem.c: virtual kernel memory mappings for high memory
3 *
4 * PowerPC version, stolen from the i386 version.
5 *
6 * Used in CONFIG_HIGHMEM systems for memory pages which
7 * are not addressable by direct kernel virtual addresses.
8 *
9 * Copyright (C) 1999 Gerhard Wichert, Siemens AG
10 * Gerhard.Wichert@pdb.siemens.de
11 *
12 *
13 * Redesigned the x86 32-bit VM architecture to deal with
14 * up to 16 Terrabyte physical memory. With current x86 CPUs
15 * we now support up to 64 Gigabytes physical RAM.
16 *
17 * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
18 *
19 * Reworked for PowerPC by various contributors. Moved from
20 * highmem.h by Benjamin Herrenschmidt (c) 2009 IBM Corp.
21 */
22
23#include <linux/highmem.h>
24#include <linux/module.h>
25
26/*
27 * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
28 * gives a more generic (and caching) interface. But kmap_atomic can
29 * be used in IRQ contexts, so in some (very limited) cases we need
30 * it.
31 */
32void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot)
33{
34 unsigned int idx;
35 unsigned long vaddr;
36
37 /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
38 pagefault_disable();
39 if (!PageHighMem(page))
40 return page_address(page);
41
42 debug_kmap_atomic(type);
43 idx = type + KM_TYPE_NR*smp_processor_id();
44 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
45#ifdef CONFIG_DEBUG_HIGHMEM
46 BUG_ON(!pte_none(*(kmap_pte-idx)));
47#endif
48 __set_pte_at(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot), 1);
49 local_flush_tlb_page(NULL, vaddr);
50
51 return (void*) vaddr;
52}
53EXPORT_SYMBOL(kmap_atomic_prot);
54
55void kunmap_atomic(void *kvaddr, enum km_type type)
56{
57#ifdef CONFIG_DEBUG_HIGHMEM
58 unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
59 enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
60
61 if (vaddr < __fix_to_virt(FIX_KMAP_END)) {
62 pagefault_enable();
63 return;
64 }
65
66 BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
67
68 /*
69 * force other mappings to Oops if they'll try to access
70 * this pte without first remap it
71 */
72 pte_clear(&init_mm, vaddr, kmap_pte-idx);
73 local_flush_tlb_page(NULL, vaddr);
74#endif
75 pagefault_enable();
76}
77EXPORT_SYMBOL(kunmap_atomic);
diff --git a/arch/powerpc/platforms/44x/warp.c b/arch/powerpc/platforms/44x/warp.c
index 42e09a9f77e2..0362c88f47d7 100644
--- a/arch/powerpc/platforms/44x/warp.c
+++ b/arch/powerpc/platforms/44x/warp.c
@@ -16,6 +16,7 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/of_gpio.h> 18#include <linux/of_gpio.h>
19#include <linux/of_i2c.h>
19 20
20#include <asm/machdep.h> 21#include <asm/machdep.h>
21#include <asm/prom.h> 22#include <asm/prom.h>
@@ -65,7 +66,6 @@ define_machine(warp) {
65 66
66static u32 post_info; 67static u32 post_info;
67 68
68/* I am not sure this is the best place for this... */
69static int __init warp_post_info(void) 69static int __init warp_post_info(void)
70{ 70{
71 struct device_node *np; 71 struct device_node *np;
@@ -194,9 +194,9 @@ static int pika_setup_leds(void)
194 return 0; 194 return 0;
195} 195}
196 196
197static void pika_setup_critical_temp(struct i2c_client *client) 197static void pika_setup_critical_temp(struct device_node *np,
198 struct i2c_client *client)
198{ 199{
199 struct device_node *np;
200 int irq, rc; 200 int irq, rc;
201 201
202 /* Do this before enabling critical temp interrupt since we 202 /* Do this before enabling critical temp interrupt since we
@@ -208,14 +208,7 @@ static void pika_setup_critical_temp(struct i2c_client *client)
208 i2c_smbus_write_byte_data(client, 2, 65); /* Thigh */ 208 i2c_smbus_write_byte_data(client, 2, 65); /* Thigh */
209 i2c_smbus_write_byte_data(client, 3, 0); /* Tlow */ 209 i2c_smbus_write_byte_data(client, 3, 0); /* Tlow */
210 210
211 np = of_find_compatible_node(NULL, NULL, "adi,ad7414");
212 if (np == NULL) {
213 printk(KERN_ERR __FILE__ ": Unable to find ad7414\n");
214 return;
215 }
216
217 irq = irq_of_parse_and_map(np, 0); 211 irq = irq_of_parse_and_map(np, 0);
218 of_node_put(np);
219 if (irq == NO_IRQ) { 212 if (irq == NO_IRQ) {
220 printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n"); 213 printk(KERN_ERR __FILE__ ": Unable to get ad7414 irq\n");
221 return; 214 return;
@@ -244,32 +237,24 @@ static inline void pika_dtm_check_fan(void __iomem *fpga)
244 237
245static int pika_dtm_thread(void __iomem *fpga) 238static int pika_dtm_thread(void __iomem *fpga)
246{ 239{
247 struct i2c_adapter *adap; 240 struct device_node *np;
248 struct i2c_client *client; 241 struct i2c_client *client;
249 242
250 /* We loop in case either driver was compiled as a module and 243 np = of_find_compatible_node(NULL, NULL, "adi,ad7414");
251 * has not been insmoded yet. 244 if (np == NULL)
252 */ 245 return -ENOENT;
253 while (!(adap = i2c_get_adapter(0))) {
254 set_current_state(TASK_INTERRUPTIBLE);
255 schedule_timeout(HZ);
256 }
257
258 while (1) {
259 list_for_each_entry(client, &adap->clients, list)
260 if (client->addr == 0x4a)
261 goto found_it;
262 246
263 set_current_state(TASK_INTERRUPTIBLE); 247 client = of_find_i2c_device_by_node(np);
264 schedule_timeout(HZ); 248 if (client == NULL) {
249 of_node_put(np);
250 return -ENOENT;
265 } 251 }
266 252
267found_it: 253 pika_setup_critical_temp(np, client);
268 pika_setup_critical_temp(client);
269 254
270 i2c_put_adapter(adap); 255 of_node_put(np);
271 256
272 printk(KERN_INFO "PIKA DTM thread running.\n"); 257 printk(KERN_INFO "Warp DTM thread running.\n");
273 258
274 while (!kthread_should_stop()) { 259 while (!kthread_should_stop()) {
275 int val; 260 int val;
@@ -291,7 +276,6 @@ found_it:
291 return 0; 276 return 0;
292} 277}
293 278
294
295static int __init pika_dtm_start(void) 279static int __init pika_dtm_start(void)
296{ 280{
297 struct task_struct *dtm_thread; 281 struct task_struct *dtm_thread;
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_mds.c b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
index 77f90b356356..60ed9c067b1d 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_mds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
@@ -285,6 +285,7 @@ static struct of_device_id mpc85xx_ids[] = {
285 { .type = "qe", }, 285 { .type = "qe", },
286 { .compatible = "fsl,qe", }, 286 { .compatible = "fsl,qe", },
287 { .compatible = "gianfar", }, 287 { .compatible = "gianfar", },
288 { .compatible = "fsl,rapidio-delta", },
288 {}, 289 {},
289}; 290};
290 291
diff --git a/arch/powerpc/platforms/85xx/smp.c b/arch/powerpc/platforms/85xx/smp.c
index cc0b0db8a6f3..62c592ede641 100644
--- a/arch/powerpc/platforms/85xx/smp.c
+++ b/arch/powerpc/platforms/85xx/smp.c
@@ -52,20 +52,19 @@ smp_85xx_kick_cpu(int nr)
52 52
53 pr_debug("smp_85xx_kick_cpu: kick CPU #%d\n", nr); 53 pr_debug("smp_85xx_kick_cpu: kick CPU #%d\n", nr);
54 54
55 local_irq_save(flags);
56
57 np = of_get_cpu_node(nr, NULL); 55 np = of_get_cpu_node(nr, NULL);
58 cpu_rel_addr = of_get_property(np, "cpu-release-addr", NULL); 56 cpu_rel_addr = of_get_property(np, "cpu-release-addr", NULL);
59 57
60 if (cpu_rel_addr == NULL) { 58 if (cpu_rel_addr == NULL) {
61 printk(KERN_ERR "No cpu-release-addr for cpu %d\n", nr); 59 printk(KERN_ERR "No cpu-release-addr for cpu %d\n", nr);
62 local_irq_restore(flags);
63 return; 60 return;
64 } 61 }
65 62
66 /* Map the spin table */ 63 /* Map the spin table */
67 bptr_vaddr = ioremap(*cpu_rel_addr, SIZE_BOOT_ENTRY); 64 bptr_vaddr = ioremap(*cpu_rel_addr, SIZE_BOOT_ENTRY);
68 65
66 local_irq_save(flags);
67
69 out_be32(bptr_vaddr + BOOT_ENTRY_PIR, nr); 68 out_be32(bptr_vaddr + BOOT_ENTRY_PIR, nr);
70 out_be32(bptr_vaddr + BOOT_ENTRY_ADDR_LOWER, __pa(__early_start)); 69 out_be32(bptr_vaddr + BOOT_ENTRY_ADDR_LOWER, __pa(__early_start));
71 70
@@ -73,10 +72,10 @@ smp_85xx_kick_cpu(int nr)
73 while ((__secondary_hold_acknowledge != nr) && (++n < 1000)) 72 while ((__secondary_hold_acknowledge != nr) && (++n < 1000))
74 mdelay(1); 73 mdelay(1);
75 74
76 iounmap(bptr_vaddr);
77
78 local_irq_restore(flags); 75 local_irq_restore(flags);
79 76
77 iounmap(bptr_vaddr);
78
80 pr_debug("waited %d msecs for CPU #%d.\n", n, nr); 79 pr_debug("waited %d msecs for CPU #%d.\n", n, nr);
81} 80}
82 81
diff --git a/arch/powerpc/platforms/85xx/socrates.c b/arch/powerpc/platforms/85xx/socrates.c
index d0e8443b12c6..747d8fb3ab82 100644
--- a/arch/powerpc/platforms/85xx/socrates.c
+++ b/arch/powerpc/platforms/85xx/socrates.c
@@ -102,10 +102,11 @@ static struct of_device_id __initdata socrates_of_bus_ids[] = {
102 {}, 102 {},
103}; 103};
104 104
105static void __init socrates_init(void) 105static int __init socrates_publish_devices(void)
106{ 106{
107 of_platform_bus_probe(NULL, socrates_of_bus_ids, NULL); 107 return of_platform_bus_probe(NULL, socrates_of_bus_ids, NULL);
108} 108}
109machine_device_initcall(socrates, socrates_publish_devices);
109 110
110/* 111/*
111 * Called very early, device-tree isn't unflattened 112 * Called very early, device-tree isn't unflattened
@@ -124,7 +125,6 @@ define_machine(socrates) {
124 .name = "Socrates", 125 .name = "Socrates",
125 .probe = socrates_probe, 126 .probe = socrates_probe,
126 .setup_arch = socrates_setup_arch, 127 .setup_arch = socrates_setup_arch,
127 .init = socrates_init,
128 .init_IRQ = socrates_pic_init, 128 .init_IRQ = socrates_pic_init,
129 .get_irq = mpic_get_irq, 129 .get_irq = mpic_get_irq,
130 .restart = fsl_rstcr_restart, 130 .restart = fsl_rstcr_restart,
diff --git a/arch/powerpc/platforms/85xx/xes_mpc85xx.c b/arch/powerpc/platforms/85xx/xes_mpc85xx.c
index ee01532786e4..1b426050a2f9 100644
--- a/arch/powerpc/platforms/85xx/xes_mpc85xx.c
+++ b/arch/powerpc/platforms/85xx/xes_mpc85xx.c
@@ -32,7 +32,6 @@
32 32
33#include <sysdev/fsl_soc.h> 33#include <sysdev/fsl_soc.h>
34#include <sysdev/fsl_pci.h> 34#include <sysdev/fsl_pci.h>
35#include <linux/of_platform.h>
36 35
37/* A few bit definitions needed for fixups on some boards */ 36/* A few bit definitions needed for fixups on some boards */
38#define MPC85xx_L2CTL_L2E 0x80000000 /* L2 enable */ 37#define MPC85xx_L2CTL_L2E 0x80000000 /* L2 enable */
diff --git a/arch/powerpc/platforms/cell/smp.c b/arch/powerpc/platforms/cell/smp.c
index 9046803c8276..bc97fada48c6 100644
--- a/arch/powerpc/platforms/cell/smp.c
+++ b/arch/powerpc/platforms/cell/smp.c
@@ -36,7 +36,6 @@
36#include <asm/prom.h> 36#include <asm/prom.h>
37#include <asm/smp.h> 37#include <asm/smp.h>
38#include <asm/paca.h> 38#include <asm/paca.h>
39#include <asm/time.h>
40#include <asm/machdep.h> 39#include <asm/machdep.h>
41#include <asm/cputable.h> 40#include <asm/cputable.h>
42#include <asm/firmware.h> 41#include <asm/firmware.h>
@@ -140,31 +139,6 @@ static void __devinit smp_cell_setup_cpu(int cpu)
140 mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER); 139 mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
141} 140}
142 141
143static DEFINE_SPINLOCK(timebase_lock);
144static unsigned long timebase = 0;
145
146static void __devinit cell_give_timebase(void)
147{
148 spin_lock(&timebase_lock);
149 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
150 timebase = get_tb();
151 spin_unlock(&timebase_lock);
152
153 while (timebase)
154 barrier();
155 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
156}
157
158static void __devinit cell_take_timebase(void)
159{
160 while (!timebase)
161 barrier();
162 spin_lock(&timebase_lock);
163 set_tb(timebase >> 32, timebase & 0xffffffff);
164 timebase = 0;
165 spin_unlock(&timebase_lock);
166}
167
168static void __devinit smp_cell_kick_cpu(int nr) 142static void __devinit smp_cell_kick_cpu(int nr)
169{ 143{
170 BUG_ON(nr < 0 || nr >= NR_CPUS); 144 BUG_ON(nr < 0 || nr >= NR_CPUS);
@@ -224,8 +198,8 @@ void __init smp_init_cell(void)
224 198
225 /* Non-lpar has additional take/give timebase */ 199 /* Non-lpar has additional take/give timebase */
226 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) { 200 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
227 smp_ops->give_timebase = cell_give_timebase; 201 smp_ops->give_timebase = rtas_give_timebase;
228 smp_ops->take_timebase = cell_take_timebase; 202 smp_ops->take_timebase = rtas_take_timebase;
229 } 203 }
230 204
231 DBG(" <- smp_init_cell()\n"); 205 DBG(" <- smp_init_cell()\n");
diff --git a/arch/powerpc/platforms/chrp/smp.c b/arch/powerpc/platforms/chrp/smp.c
index 10a4a4d063b6..02cafecc90e3 100644
--- a/arch/powerpc/platforms/chrp/smp.c
+++ b/arch/powerpc/platforms/chrp/smp.c
@@ -26,7 +26,6 @@
26#include <asm/io.h> 26#include <asm/io.h>
27#include <asm/prom.h> 27#include <asm/prom.h>
28#include <asm/smp.h> 28#include <asm/smp.h>
29#include <asm/time.h>
30#include <asm/machdep.h> 29#include <asm/machdep.h>
31#include <asm/mpic.h> 30#include <asm/mpic.h>
32#include <asm/rtas.h> 31#include <asm/rtas.h>
@@ -42,40 +41,12 @@ static void __devinit smp_chrp_setup_cpu(int cpu_nr)
42 mpic_setup_this_cpu(); 41 mpic_setup_this_cpu();
43} 42}
44 43
45static DEFINE_SPINLOCK(timebase_lock);
46static unsigned int timebase_upper = 0, timebase_lower = 0;
47
48void __devinit smp_chrp_give_timebase(void)
49{
50 spin_lock(&timebase_lock);
51 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
52 timebase_upper = get_tbu();
53 timebase_lower = get_tbl();
54 spin_unlock(&timebase_lock);
55
56 while (timebase_upper || timebase_lower)
57 barrier();
58 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
59}
60
61void __devinit smp_chrp_take_timebase(void)
62{
63 while (!(timebase_upper || timebase_lower))
64 barrier();
65 spin_lock(&timebase_lock);
66 set_tb(timebase_upper, timebase_lower);
67 timebase_upper = 0;
68 timebase_lower = 0;
69 spin_unlock(&timebase_lock);
70 printk("CPU %i taken timebase\n", smp_processor_id());
71}
72
73/* CHRP with openpic */ 44/* CHRP with openpic */
74struct smp_ops_t chrp_smp_ops = { 45struct smp_ops_t chrp_smp_ops = {
75 .message_pass = smp_mpic_message_pass, 46 .message_pass = smp_mpic_message_pass,
76 .probe = smp_mpic_probe, 47 .probe = smp_mpic_probe,
77 .kick_cpu = smp_chrp_kick_cpu, 48 .kick_cpu = smp_chrp_kick_cpu,
78 .setup_cpu = smp_chrp_setup_cpu, 49 .setup_cpu = smp_chrp_setup_cpu,
79 .give_timebase = smp_chrp_give_timebase, 50 .give_timebase = rtas_give_timebase,
80 .take_timebase = smp_chrp_take_timebase, 51 .take_timebase = rtas_take_timebase,
81}; 52};
diff --git a/arch/powerpc/platforms/pasemi/setup.c b/arch/powerpc/platforms/pasemi/setup.c
index 153051eb6d93..a4619347aa7e 100644
--- a/arch/powerpc/platforms/pasemi/setup.c
+++ b/arch/powerpc/platforms/pasemi/setup.c
@@ -71,20 +71,25 @@ static void pas_restart(char *cmd)
71} 71}
72 72
73#ifdef CONFIG_SMP 73#ifdef CONFIG_SMP
74static DEFINE_SPINLOCK(timebase_lock); 74static raw_spinlock_t timebase_lock;
75static unsigned long timebase; 75static unsigned long timebase;
76 76
77static void __devinit pas_give_timebase(void) 77static void __devinit pas_give_timebase(void)
78{ 78{
79 spin_lock(&timebase_lock); 79 unsigned long flags;
80
81 local_irq_save(flags);
82 hard_irq_disable();
83 __raw_spin_lock(&timebase_lock);
80 mtspr(SPRN_TBCTL, TBCTL_FREEZE); 84 mtspr(SPRN_TBCTL, TBCTL_FREEZE);
81 isync(); 85 isync();
82 timebase = get_tb(); 86 timebase = get_tb();
83 spin_unlock(&timebase_lock); 87 __raw_spin_unlock(&timebase_lock);
84 88
85 while (timebase) 89 while (timebase)
86 barrier(); 90 barrier();
87 mtspr(SPRN_TBCTL, TBCTL_RESTART); 91 mtspr(SPRN_TBCTL, TBCTL_RESTART);
92 local_irq_restore(flags);
88} 93}
89 94
90static void __devinit pas_take_timebase(void) 95static void __devinit pas_take_timebase(void)
@@ -92,10 +97,10 @@ static void __devinit pas_take_timebase(void)
92 while (!timebase) 97 while (!timebase)
93 smp_rmb(); 98 smp_rmb();
94 99
95 spin_lock(&timebase_lock); 100 __raw_spin_lock(&timebase_lock);
96 set_tb(timebase >> 32, timebase & 0xffffffff); 101 set_tb(timebase >> 32, timebase & 0xffffffff);
97 timebase = 0; 102 timebase = 0;
98 spin_unlock(&timebase_lock); 103 __raw_spin_unlock(&timebase_lock);
99} 104}
100 105
101struct smp_ops_t pas_smp_ops = { 106struct smp_ops_t pas_smp_ops = {
diff --git a/arch/powerpc/platforms/powermac/setup.c b/arch/powerpc/platforms/powermac/setup.c
index 86f69a4eb49b..c20522656367 100644
--- a/arch/powerpc/platforms/powermac/setup.c
+++ b/arch/powerpc/platforms/powermac/setup.c
@@ -103,11 +103,6 @@ unsigned long smu_cmdbuf_abs;
103EXPORT_SYMBOL(smu_cmdbuf_abs); 103EXPORT_SYMBOL(smu_cmdbuf_abs);
104#endif 104#endif
105 105
106#ifdef CONFIG_SMP
107extern struct smp_ops_t psurge_smp_ops;
108extern struct smp_ops_t core99_smp_ops;
109#endif /* CONFIG_SMP */
110
111static void pmac_show_cpuinfo(struct seq_file *m) 106static void pmac_show_cpuinfo(struct seq_file *m)
112{ 107{
113 struct device_node *np; 108 struct device_node *np;
@@ -341,34 +336,6 @@ static void __init pmac_setup_arch(void)
341 ROOT_DEV = DEFAULT_ROOT_DEVICE; 336 ROOT_DEV = DEFAULT_ROOT_DEVICE;
342#endif 337#endif
343 338
344#ifdef CONFIG_SMP
345 /* Check for Core99 */
346 ic = of_find_node_by_name(NULL, "uni-n");
347 if (!ic)
348 ic = of_find_node_by_name(NULL, "u3");
349 if (!ic)
350 ic = of_find_node_by_name(NULL, "u4");
351 if (ic) {
352 of_node_put(ic);
353 smp_ops = &core99_smp_ops;
354 }
355#ifdef CONFIG_PPC32
356 else {
357 /*
358 * We have to set bits in cpu_possible_map here since the
359 * secondary CPU(s) aren't in the device tree, and
360 * setup_per_cpu_areas only allocates per-cpu data for
361 * CPUs in the cpu_possible_map.
362 */
363 int cpu;
364
365 for (cpu = 1; cpu < 4 && cpu < NR_CPUS; ++cpu)
366 cpu_set(cpu, cpu_possible_map);
367 smp_ops = &psurge_smp_ops;
368 }
369#endif
370#endif /* CONFIG_SMP */
371
372#ifdef CONFIG_ADB 339#ifdef CONFIG_ADB
373 if (strstr(cmd_line, "adb_sync")) { 340 if (strstr(cmd_line, "adb_sync")) {
374 extern int __adb_probe_sync; 341 extern int __adb_probe_sync;
@@ -512,6 +479,14 @@ static void __init pmac_init_early(void)
512#ifdef CONFIG_PPC64 479#ifdef CONFIG_PPC64
513 iommu_init_early_dart(); 480 iommu_init_early_dart();
514#endif 481#endif
482
483 /* SMP Init has to be done early as we need to patch up
484 * cpu_possible_map before interrupt stacks are allocated
485 * or kaboom...
486 */
487#ifdef CONFIG_SMP
488 pmac_setup_smp();
489#endif
515} 490}
516 491
517static int __init pmac_declare_of_platform_devices(void) 492static int __init pmac_declare_of_platform_devices(void)
diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
index cf1dbe758890..6d4da7b46b41 100644
--- a/arch/powerpc/platforms/powermac/smp.c
+++ b/arch/powerpc/platforms/powermac/smp.c
@@ -64,10 +64,11 @@
64extern void __secondary_start_pmac_0(void); 64extern void __secondary_start_pmac_0(void);
65extern int pmac_pfunc_base_install(void); 65extern int pmac_pfunc_base_install(void);
66 66
67#ifdef CONFIG_PPC32 67static void (*pmac_tb_freeze)(int freeze);
68static u64 timebase;
69static int tb_req;
68 70
69/* Sync flag for HW tb sync */ 71#ifdef CONFIG_PPC32
70static volatile int sec_tb_reset = 0;
71 72
72/* 73/*
73 * Powersurge (old powermac SMP) support. 74 * Powersurge (old powermac SMP) support.
@@ -294,6 +295,9 @@ static int __init smp_psurge_probe(void)
294 psurge_quad_init(); 295 psurge_quad_init();
295 /* All released cards using this HW design have 4 CPUs */ 296 /* All released cards using this HW design have 4 CPUs */
296 ncpus = 4; 297 ncpus = 4;
298 /* No sure how timebase sync works on those, let's use SW */
299 smp_ops->give_timebase = smp_generic_give_timebase;
300 smp_ops->take_timebase = smp_generic_take_timebase;
297 } else { 301 } else {
298 iounmap(quad_base); 302 iounmap(quad_base);
299 if ((in_8(hhead_base + HHEAD_CONFIG) & 0x02) == 0) { 303 if ((in_8(hhead_base + HHEAD_CONFIG) & 0x02) == 0) {
@@ -308,18 +312,15 @@ static int __init smp_psurge_probe(void)
308 psurge_start = ioremap(PSURGE_START, 4); 312 psurge_start = ioremap(PSURGE_START, 4);
309 psurge_pri_intr = ioremap(PSURGE_PRI_INTR, 4); 313 psurge_pri_intr = ioremap(PSURGE_PRI_INTR, 4);
310 314
311 /* 315 /* This is necessary because OF doesn't know about the
312 * This is necessary because OF doesn't know about the
313 * secondary cpu(s), and thus there aren't nodes in the 316 * secondary cpu(s), and thus there aren't nodes in the
314 * device tree for them, and smp_setup_cpu_maps hasn't 317 * device tree for them, and smp_setup_cpu_maps hasn't
315 * set their bits in cpu_possible_map and cpu_present_map. 318 * set their bits in cpu_present_map.
316 */ 319 */
317 if (ncpus > NR_CPUS) 320 if (ncpus > NR_CPUS)
318 ncpus = NR_CPUS; 321 ncpus = NR_CPUS;
319 for (i = 1; i < ncpus ; ++i) { 322 for (i = 1; i < ncpus ; ++i)
320 cpu_set(i, cpu_present_map); 323 cpu_set(i, cpu_present_map);
321 set_hard_smp_processor_id(i, i);
322 }
323 324
324 if (ppc_md.progress) ppc_md.progress("smp_psurge_probe - done", 0x352); 325 if (ppc_md.progress) ppc_md.progress("smp_psurge_probe - done", 0x352);
325 326
@@ -329,8 +330,14 @@ static int __init smp_psurge_probe(void)
329static void __init smp_psurge_kick_cpu(int nr) 330static void __init smp_psurge_kick_cpu(int nr)
330{ 331{
331 unsigned long start = __pa(__secondary_start_pmac_0) + nr * 8; 332 unsigned long start = __pa(__secondary_start_pmac_0) + nr * 8;
332 unsigned long a; 333 unsigned long a, flags;
333 int i; 334 int i, j;
335
336 /* Defining this here is evil ... but I prefer hiding that
337 * crap to avoid giving people ideas that they can do the
338 * same.
339 */
340 extern volatile unsigned int cpu_callin_map[NR_CPUS];
334 341
335 /* may need to flush here if secondary bats aren't setup */ 342 /* may need to flush here if secondary bats aren't setup */
336 for (a = KERNELBASE; a < KERNELBASE + 0x800000; a += 32) 343 for (a = KERNELBASE; a < KERNELBASE + 0x800000; a += 32)
@@ -339,47 +346,52 @@ static void __init smp_psurge_kick_cpu(int nr)
339 346
340 if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu", 0x353); 347 if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu", 0x353);
341 348
349 /* This is going to freeze the timeebase, we disable interrupts */
350 local_irq_save(flags);
351
342 out_be32(psurge_start, start); 352 out_be32(psurge_start, start);
343 mb(); 353 mb();
344 354
345 psurge_set_ipi(nr); 355 psurge_set_ipi(nr);
356
346 /* 357 /*
347 * We can't use udelay here because the timebase is now frozen. 358 * We can't use udelay here because the timebase is now frozen.
348 */ 359 */
349 for (i = 0; i < 2000; ++i) 360 for (i = 0; i < 2000; ++i)
350 barrier(); 361 asm volatile("nop" : : : "memory");
351 psurge_clr_ipi(nr); 362 psurge_clr_ipi(nr);
352 363
353 if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu - done", 0x354); 364 /*
354} 365 * Also, because the timebase is frozen, we must not return to the
355 366 * caller which will try to do udelay's etc... Instead, we wait -here-
356/* 367 * for the CPU to callin.
357 * With the dual-cpu powersurge board, the decrementers and timebases 368 */
358 * of both cpus are frozen after the secondary cpu is started up, 369 for (i = 0; i < 100000 && !cpu_callin_map[nr]; ++i) {
359 * until we give the secondary cpu another interrupt. This routine 370 for (j = 1; j < 10000; j++)
360 * uses this to get the timebases synchronized. 371 asm volatile("nop" : : : "memory");
361 * -- paulus. 372 asm volatile("sync" : : : "memory");
362 */ 373 }
363static void __init psurge_dual_sync_tb(int cpu_nr) 374 if (!cpu_callin_map[nr])
364{ 375 goto stuck;
365 int t; 376
366 377 /* And we do the TB sync here too for standard dual CPU cards */
367 set_dec(tb_ticks_per_jiffy); 378 if (psurge_type == PSURGE_DUAL) {
368 /* XXX fixme */ 379 while(!tb_req)
369 set_tb(0, 0); 380 barrier();
370 381 tb_req = 0;
371 if (cpu_nr > 0) { 382 mb();
383 timebase = get_tb();
384 mb();
385 while (timebase)
386 barrier();
372 mb(); 387 mb();
373 sec_tb_reset = 1;
374 return;
375 } 388 }
389 stuck:
390 /* now interrupt the secondary, restarting both TBs */
391 if (psurge_type == PSURGE_DUAL)
392 psurge_set_ipi(1);
376 393
377 /* wait for the secondary to have reset its TB before proceeding */ 394 if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu - done", 0x354);
378 for (t = 10000000; t > 0 && !sec_tb_reset; --t)
379 ;
380
381 /* now interrupt the secondary, starting both TBs */
382 psurge_set_ipi(1);
383} 395}
384 396
385static struct irqaction psurge_irqaction = { 397static struct irqaction psurge_irqaction = {
@@ -390,36 +402,35 @@ static struct irqaction psurge_irqaction = {
390 402
391static void __init smp_psurge_setup_cpu(int cpu_nr) 403static void __init smp_psurge_setup_cpu(int cpu_nr)
392{ 404{
405 if (cpu_nr != 0)
406 return;
393 407
394 if (cpu_nr == 0) { 408 /* reset the entry point so if we get another intr we won't
395 /* If we failed to start the second CPU, we should still 409 * try to startup again */
396 * send it an IPI to start the timebase & DEC or we might 410 out_be32(psurge_start, 0x100);
397 * have them stuck. 411 if (setup_irq(30, &psurge_irqaction))
398 */ 412 printk(KERN_ERR "Couldn't get primary IPI interrupt");
399 if (num_online_cpus() < 2) {
400 if (psurge_type == PSURGE_DUAL)
401 psurge_set_ipi(1);
402 return;
403 }
404 /* reset the entry point so if we get another intr we won't
405 * try to startup again */
406 out_be32(psurge_start, 0x100);
407 if (setup_irq(30, &psurge_irqaction))
408 printk(KERN_ERR "Couldn't get primary IPI interrupt");
409 }
410
411 if (psurge_type == PSURGE_DUAL)
412 psurge_dual_sync_tb(cpu_nr);
413} 413}
414 414
415void __init smp_psurge_take_timebase(void) 415void __init smp_psurge_take_timebase(void)
416{ 416{
417 /* Dummy implementation */ 417 if (psurge_type != PSURGE_DUAL)
418 return;
419
420 tb_req = 1;
421 mb();
422 while (!timebase)
423 barrier();
424 mb();
425 set_tb(timebase >> 32, timebase & 0xffffffff);
426 timebase = 0;
427 mb();
428 set_dec(tb_ticks_per_jiffy/2);
418} 429}
419 430
420void __init smp_psurge_give_timebase(void) 431void __init smp_psurge_give_timebase(void)
421{ 432{
422 /* Dummy implementation */ 433 /* Nothing to do here */
423} 434}
424 435
425/* PowerSurge-style Macs */ 436/* PowerSurge-style Macs */
@@ -437,9 +448,6 @@ struct smp_ops_t psurge_smp_ops = {
437 * Core 99 and later support 448 * Core 99 and later support
438 */ 449 */
439 450
440static void (*pmac_tb_freeze)(int freeze);
441static u64 timebase;
442static int tb_req;
443 451
444static void smp_core99_give_timebase(void) 452static void smp_core99_give_timebase(void)
445{ 453{
@@ -478,7 +486,6 @@ static void __devinit smp_core99_take_timebase(void)
478 set_tb(timebase >> 32, timebase & 0xffffffff); 486 set_tb(timebase >> 32, timebase & 0xffffffff);
479 timebase = 0; 487 timebase = 0;
480 mb(); 488 mb();
481 set_dec(tb_ticks_per_jiffy/2);
482 489
483 local_irq_restore(flags); 490 local_irq_restore(flags);
484} 491}
@@ -920,3 +927,34 @@ struct smp_ops_t core99_smp_ops = {
920# endif 927# endif
921#endif 928#endif
922}; 929};
930
931void __init pmac_setup_smp(void)
932{
933 struct device_node *np;
934
935 /* Check for Core99 */
936 np = of_find_node_by_name(NULL, "uni-n");
937 if (!np)
938 np = of_find_node_by_name(NULL, "u3");
939 if (!np)
940 np = of_find_node_by_name(NULL, "u4");
941 if (np) {
942 of_node_put(np);
943 smp_ops = &core99_smp_ops;
944 }
945#ifdef CONFIG_PPC32
946 else {
947 /* We have to set bits in cpu_possible_map here since the
948 * secondary CPU(s) aren't in the device tree. Various
949 * things won't be initialized for CPUs not in the possible
950 * map, so we really need to fix it up here.
951 */
952 int cpu;
953
954 for (cpu = 1; cpu < 4 && cpu < NR_CPUS; ++cpu)
955 cpu_set(cpu, cpu_possible_map);
956 smp_ops = &psurge_smp_ops;
957 }
958#endif /* CONFIG_PPC32 */
959}
960
diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c
index 1a231c389ba0..1f8f6cfb94f7 100644
--- a/arch/powerpc/platforms/pseries/smp.c
+++ b/arch/powerpc/platforms/pseries/smp.c
@@ -35,7 +35,6 @@
35#include <asm/prom.h> 35#include <asm/prom.h>
36#include <asm/smp.h> 36#include <asm/smp.h>
37#include <asm/paca.h> 37#include <asm/paca.h>
38#include <asm/time.h>
39#include <asm/machdep.h> 38#include <asm/machdep.h>
40#include <asm/cputable.h> 39#include <asm/cputable.h>
41#include <asm/firmware.h> 40#include <asm/firmware.h>
@@ -118,31 +117,6 @@ static void __devinit smp_xics_setup_cpu(int cpu)
118} 117}
119#endif /* CONFIG_XICS */ 118#endif /* CONFIG_XICS */
120 119
121static DEFINE_SPINLOCK(timebase_lock);
122static unsigned long timebase = 0;
123
124static void __devinit pSeries_give_timebase(void)
125{
126 spin_lock(&timebase_lock);
127 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
128 timebase = get_tb();
129 spin_unlock(&timebase_lock);
130
131 while (timebase)
132 barrier();
133 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
134}
135
136static void __devinit pSeries_take_timebase(void)
137{
138 while (!timebase)
139 barrier();
140 spin_lock(&timebase_lock);
141 set_tb(timebase >> 32, timebase & 0xffffffff);
142 timebase = 0;
143 spin_unlock(&timebase_lock);
144}
145
146static void __devinit smp_pSeries_kick_cpu(int nr) 120static void __devinit smp_pSeries_kick_cpu(int nr)
147{ 121{
148 BUG_ON(nr < 0 || nr >= NR_CPUS); 122 BUG_ON(nr < 0 || nr >= NR_CPUS);
@@ -209,8 +183,8 @@ static void __init smp_init_pseries(void)
209 183
210 /* Non-lpar has additional take/give timebase */ 184 /* Non-lpar has additional take/give timebase */
211 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) { 185 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
212 smp_ops->give_timebase = pSeries_give_timebase; 186 smp_ops->give_timebase = rtas_give_timebase;
213 smp_ops->take_timebase = pSeries_take_timebase; 187 smp_ops->take_timebase = rtas_take_timebase;
214 } 188 }
215 189
216 pr_debug(" <- smp_init_pSeries()\n"); 190 pr_debug(" <- smp_init_pSeries()\n");
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index 9c3af5045495..d46de1f0f3ee 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -279,28 +279,29 @@ static void _mpic_map_mmio(struct mpic *mpic, phys_addr_t phys_addr,
279} 279}
280 280
281#ifdef CONFIG_PPC_DCR 281#ifdef CONFIG_PPC_DCR
282static void _mpic_map_dcr(struct mpic *mpic, struct mpic_reg_bank *rb, 282static void _mpic_map_dcr(struct mpic *mpic, struct device_node *node,
283 struct mpic_reg_bank *rb,
283 unsigned int offset, unsigned int size) 284 unsigned int offset, unsigned int size)
284{ 285{
285 const u32 *dbasep; 286 const u32 *dbasep;
286 287
287 dbasep = of_get_property(mpic->irqhost->of_node, "dcr-reg", NULL); 288 dbasep = of_get_property(node, "dcr-reg", NULL);
288 289
289 rb->dhost = dcr_map(mpic->irqhost->of_node, *dbasep + offset, size); 290 rb->dhost = dcr_map(node, *dbasep + offset, size);
290 BUG_ON(!DCR_MAP_OK(rb->dhost)); 291 BUG_ON(!DCR_MAP_OK(rb->dhost));
291} 292}
292 293
293static inline void mpic_map(struct mpic *mpic, phys_addr_t phys_addr, 294static inline void mpic_map(struct mpic *mpic, struct device_node *node,
294 struct mpic_reg_bank *rb, unsigned int offset, 295 phys_addr_t phys_addr, struct mpic_reg_bank *rb,
295 unsigned int size) 296 unsigned int offset, unsigned int size)
296{ 297{
297 if (mpic->flags & MPIC_USES_DCR) 298 if (mpic->flags & MPIC_USES_DCR)
298 _mpic_map_dcr(mpic, rb, offset, size); 299 _mpic_map_dcr(mpic, node, rb, offset, size);
299 else 300 else
300 _mpic_map_mmio(mpic, phys_addr, rb, offset, size); 301 _mpic_map_mmio(mpic, phys_addr, rb, offset, size);
301} 302}
302#else /* CONFIG_PPC_DCR */ 303#else /* CONFIG_PPC_DCR */
303#define mpic_map(m,p,b,o,s) _mpic_map_mmio(m,p,b,o,s) 304#define mpic_map(m,n,p,b,o,s) _mpic_map_mmio(m,p,b,o,s)
304#endif /* !CONFIG_PPC_DCR */ 305#endif /* !CONFIG_PPC_DCR */
305 306
306 307
@@ -1052,11 +1053,10 @@ struct mpic * __init mpic_alloc(struct device_node *node,
1052 int intvec_top; 1053 int intvec_top;
1053 u64 paddr = phys_addr; 1054 u64 paddr = phys_addr;
1054 1055
1055 mpic = alloc_bootmem(sizeof(struct mpic)); 1056 mpic = kzalloc(sizeof(struct mpic), GFP_KERNEL);
1056 if (mpic == NULL) 1057 if (mpic == NULL)
1057 return NULL; 1058 return NULL;
1058 1059
1059 memset(mpic, 0, sizeof(struct mpic));
1060 mpic->name = name; 1060 mpic->name = name;
1061 1061
1062 mpic->hc_irq = mpic_irq_chip; 1062 mpic->hc_irq = mpic_irq_chip;
@@ -1152,8 +1152,8 @@ struct mpic * __init mpic_alloc(struct device_node *node,
1152 } 1152 }
1153 1153
1154 /* Map the global registers */ 1154 /* Map the global registers */
1155 mpic_map(mpic, paddr, &mpic->gregs, MPIC_INFO(GREG_BASE), 0x1000); 1155 mpic_map(mpic, node, paddr, &mpic->gregs, MPIC_INFO(GREG_BASE), 0x1000);
1156 mpic_map(mpic, paddr, &mpic->tmregs, MPIC_INFO(TIMER_BASE), 0x1000); 1156 mpic_map(mpic, node, paddr, &mpic->tmregs, MPIC_INFO(TIMER_BASE), 0x1000);
1157 1157
1158 /* Reset */ 1158 /* Reset */
1159 if (flags & MPIC_WANTS_RESET) { 1159 if (flags & MPIC_WANTS_RESET) {
@@ -1194,7 +1194,7 @@ struct mpic * __init mpic_alloc(struct device_node *node,
1194 1194
1195 /* Map the per-CPU registers */ 1195 /* Map the per-CPU registers */
1196 for (i = 0; i < mpic->num_cpus; i++) { 1196 for (i = 0; i < mpic->num_cpus; i++) {
1197 mpic_map(mpic, paddr, &mpic->cpuregs[i], 1197 mpic_map(mpic, node, paddr, &mpic->cpuregs[i],
1198 MPIC_INFO(CPU_BASE) + i * MPIC_INFO(CPU_STRIDE), 1198 MPIC_INFO(CPU_BASE) + i * MPIC_INFO(CPU_STRIDE),
1199 0x1000); 1199 0x1000);
1200 } 1200 }
@@ -1202,7 +1202,7 @@ struct mpic * __init mpic_alloc(struct device_node *node,
1202 /* Initialize main ISU if none provided */ 1202 /* Initialize main ISU if none provided */
1203 if (mpic->isu_size == 0) { 1203 if (mpic->isu_size == 0) {
1204 mpic->isu_size = mpic->num_sources; 1204 mpic->isu_size = mpic->num_sources;
1205 mpic_map(mpic, paddr, &mpic->isus[0], 1205 mpic_map(mpic, node, paddr, &mpic->isus[0],
1206 MPIC_INFO(IRQ_BASE), MPIC_INFO(IRQ_STRIDE) * mpic->isu_size); 1206 MPIC_INFO(IRQ_BASE), MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
1207 } 1207 }
1208 mpic->isu_shift = 1 + __ilog2(mpic->isu_size - 1); 1208 mpic->isu_shift = 1 + __ilog2(mpic->isu_size - 1);
@@ -1256,8 +1256,10 @@ void __init mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
1256 1256
1257 BUG_ON(isu_num >= MPIC_MAX_ISU); 1257 BUG_ON(isu_num >= MPIC_MAX_ISU);
1258 1258
1259 mpic_map(mpic, paddr, &mpic->isus[isu_num], 0, 1259 mpic_map(mpic, mpic->irqhost->of_node,
1260 paddr, &mpic->isus[isu_num], 0,
1260 MPIC_INFO(IRQ_STRIDE) * mpic->isu_size); 1261 MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
1262
1261 if ((isu_first + mpic->isu_size) > mpic->num_sources) 1263 if ((isu_first + mpic->isu_size) > mpic->num_sources)
1262 mpic->num_sources = isu_first + mpic->isu_size; 1264 mpic->num_sources = isu_first + mpic->isu_size;
1263} 1265}
diff --git a/arch/powerpc/sysdev/qe_lib/qe.c b/arch/powerpc/sysdev/qe_lib/qe.c
index b28b0e512d67..237e3654f48c 100644
--- a/arch/powerpc/sysdev/qe_lib/qe.c
+++ b/arch/powerpc/sysdev/qe_lib/qe.c
@@ -112,6 +112,7 @@ int qe_issue_cmd(u32 cmd, u32 device, u8 mcn_protocol, u32 cmd_input)
112{ 112{
113 unsigned long flags; 113 unsigned long flags;
114 u8 mcn_shift = 0, dev_shift = 0; 114 u8 mcn_shift = 0, dev_shift = 0;
115 u32 ret;
115 116
116 spin_lock_irqsave(&qe_lock, flags); 117 spin_lock_irqsave(&qe_lock, flags);
117 if (cmd == QE_RESET) { 118 if (cmd == QE_RESET) {
@@ -139,11 +140,13 @@ int qe_issue_cmd(u32 cmd, u32 device, u8 mcn_protocol, u32 cmd_input)
139 } 140 }
140 141
141 /* wait for the QE_CR_FLG to clear */ 142 /* wait for the QE_CR_FLG to clear */
142 while(in_be32(&qe_immr->cp.cecr) & QE_CR_FLG) 143 ret = spin_event_timeout((in_be32(&qe_immr->cp.cecr) & QE_CR_FLG) == 0,
143 cpu_relax(); 144 100, 0);
145 /* On timeout (e.g. failure), the expression will be false (ret == 0),
146 otherwise it will be true (ret == 1). */
144 spin_unlock_irqrestore(&qe_lock, flags); 147 spin_unlock_irqrestore(&qe_lock, flags);
145 148
146 return 0; 149 return ret == 1;
147} 150}
148EXPORT_SYMBOL(qe_issue_cmd); 151EXPORT_SYMBOL(qe_issue_cmd);
149 152
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index a27d0d5a6f86..1cd02f6073a0 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -99,7 +99,9 @@ struct kvm_s390_sie_block {
99 __u8 reservedd0[48]; /* 0x00d0 */ 99 __u8 reservedd0[48]; /* 0x00d0 */
100 __u64 gcr[16]; /* 0x0100 */ 100 __u64 gcr[16]; /* 0x0100 */
101 __u64 gbea; /* 0x0180 */ 101 __u64 gbea; /* 0x0180 */
102 __u8 reserved188[120]; /* 0x0188 */ 102 __u8 reserved188[24]; /* 0x0188 */
103 __u32 fac; /* 0x01a0 */
104 __u8 reserved1a4[92]; /* 0x01a4 */
103} __attribute__((packed)); 105} __attribute__((packed));
104 106
105struct kvm_vcpu_stat { 107struct kvm_vcpu_stat {
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index c18b21d6991c..90d9d1ba258b 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -25,6 +25,7 @@
25#include <asm/lowcore.h> 25#include <asm/lowcore.h>
26#include <asm/pgtable.h> 26#include <asm/pgtable.h>
27#include <asm/nmi.h> 27#include <asm/nmi.h>
28#include <asm/system.h>
28#include "kvm-s390.h" 29#include "kvm-s390.h"
29#include "gaccess.h" 30#include "gaccess.h"
30 31
@@ -69,6 +70,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
69 { NULL } 70 { NULL }
70}; 71};
71 72
73static unsigned long long *facilities;
72 74
73/* Section: not file related */ 75/* Section: not file related */
74void kvm_arch_hardware_enable(void *garbage) 76void kvm_arch_hardware_enable(void *garbage)
@@ -288,6 +290,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
288 vcpu->arch.sie_block->gmsor = vcpu->kvm->arch.guest_origin; 290 vcpu->arch.sie_block->gmsor = vcpu->kvm->arch.guest_origin;
289 vcpu->arch.sie_block->ecb = 2; 291 vcpu->arch.sie_block->ecb = 2;
290 vcpu->arch.sie_block->eca = 0xC1002001U; 292 vcpu->arch.sie_block->eca = 0xC1002001U;
293 vcpu->arch.sie_block->fac = (int) (long) facilities;
291 hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); 294 hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
292 tasklet_init(&vcpu->arch.tasklet, kvm_s390_tasklet, 295 tasklet_init(&vcpu->arch.tasklet, kvm_s390_tasklet,
293 (unsigned long) vcpu); 296 (unsigned long) vcpu);
@@ -739,11 +742,29 @@ gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn)
739 742
740static int __init kvm_s390_init(void) 743static int __init kvm_s390_init(void)
741{ 744{
742 return kvm_init(NULL, sizeof(struct kvm_vcpu), THIS_MODULE); 745 int ret;
746 ret = kvm_init(NULL, sizeof(struct kvm_vcpu), THIS_MODULE);
747 if (ret)
748 return ret;
749
750 /*
751 * guests can ask for up to 255+1 double words, we need a full page
752 * to hold the maximum amount of facilites. On the other hand, we
753 * only set facilities that are known to work in KVM.
754 */
755 facilities = (unsigned long long *) get_zeroed_page(GFP_DMA);
756 if (!facilities) {
757 kvm_exit();
758 return -ENOMEM;
759 }
760 stfle(facilities, 1);
761 facilities[0] &= 0xff00fff3f0700000ULL;
762 return 0;
743} 763}
744 764
745static void __exit kvm_s390_exit(void) 765static void __exit kvm_s390_exit(void)
746{ 766{
767 free_page((unsigned long) facilities);
747 kvm_exit(); 768 kvm_exit();
748} 769}
749 770
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 93ecd06e1a74..d426aac8095d 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -158,7 +158,7 @@ static int handle_stfl(struct kvm_vcpu *vcpu)
158 158
159 vcpu->stat.instruction_stfl++; 159 vcpu->stat.instruction_stfl++;
160 /* only pass the facility bits, which we can handle */ 160 /* only pass the facility bits, which we can handle */
161 facility_list &= 0xfe00fff3; 161 facility_list &= 0xff00fff3;
162 162
163 rc = copy_to_guest(vcpu, offsetof(struct _lowcore, stfl_fac_list), 163 rc = copy_to_guest(vcpu, offsetof(struct _lowcore, stfl_fac_list),
164 &facility_list, sizeof(facility_list)); 164 &facility_list, sizeof(facility_list));
diff --git a/arch/sh/Kconfig.debug b/arch/sh/Kconfig.debug
index 8ece0b5bd028..39224b57c6ef 100644
--- a/arch/sh/Kconfig.debug
+++ b/arch/sh/Kconfig.debug
@@ -61,10 +61,6 @@ config EARLY_PRINTK
61 select both the EARLY_SCIF_CONSOLE and SH_STANDARD_BIOS, using 61 select both the EARLY_SCIF_CONSOLE and SH_STANDARD_BIOS, using
62 the kernel command line option to toggle back and forth. 62 the kernel command line option to toggle back and forth.
63 63
64config DEBUG_BOOTMEM
65 depends on DEBUG_KERNEL
66 bool "Debug BOOTMEM initialization"
67
68config DEBUG_STACKOVERFLOW 64config DEBUG_STACKOVERFLOW
69 bool "Check for stack overflows" 65 bool "Check for stack overflows"
70 depends on DEBUG_KERNEL && SUPERH32 66 depends on DEBUG_KERNEL && SUPERH32
diff --git a/arch/sh/boards/mach-se/7206/io.c b/arch/sh/boards/mach-se/7206/io.c
index 9c3a33210d61..180455642a43 100644
--- a/arch/sh/boards/mach-se/7206/io.c
+++ b/arch/sh/boards/mach-se/7206/io.c
@@ -50,7 +50,7 @@ unsigned char se7206_inb_p(unsigned long port)
50 50
51unsigned short se7206_inw(unsigned long port) 51unsigned short se7206_inw(unsigned long port)
52{ 52{
53 return *port2adr(port);; 53 return *port2adr(port);
54} 54}
55 55
56void se7206_outb(unsigned char value, unsigned long port) 56void se7206_outb(unsigned char value, unsigned long port)
diff --git a/arch/sh/boards/mach-se/7724/setup.c b/arch/sh/boards/mach-se/7724/setup.c
index 9cd04bd558b8..c050a8d76dfd 100644
--- a/arch/sh/boards/mach-se/7724/setup.c
+++ b/arch/sh/boards/mach-se/7724/setup.c
@@ -23,6 +23,8 @@
23#include <media/sh_mobile_ceu.h> 23#include <media/sh_mobile_ceu.h>
24#include <asm/io.h> 24#include <asm/io.h>
25#include <asm/heartbeat.h> 25#include <asm/heartbeat.h>
26#include <asm/sh_eth.h>
27#include <asm/clock.h>
26#include <asm/sh_keysc.h> 28#include <asm/sh_keysc.h>
27#include <cpu/sh7724.h> 29#include <cpu/sh7724.h>
28#include <mach-se/mach/se7724.h> 30#include <mach-se/mach/se7724.h>
@@ -272,6 +274,34 @@ static struct platform_device keysc_device = {
272 }, 274 },
273}; 275};
274 276
277/* SH Eth */
278static struct resource sh_eth_resources[] = {
279 [0] = {
280 .start = SH_ETH_ADDR,
281 .end = SH_ETH_ADDR + 0x1FC,
282 .flags = IORESOURCE_MEM,
283 },
284 [1] = {
285 .start = 91,
286 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
287 },
288};
289
290struct sh_eth_plat_data sh_eth_plat = {
291 .phy = 0x1f, /* SMSC LAN8187 */
292 .edmac_endian = EDMAC_LITTLE_ENDIAN,
293};
294
295static struct platform_device sh_eth_device = {
296 .name = "sh-eth",
297 .id = 0,
298 .dev = {
299 .platform_data = &sh_eth_plat,
300 },
301 .num_resources = ARRAY_SIZE(sh_eth_resources),
302 .resource = sh_eth_resources,
303};
304
275static struct platform_device *ms7724se_devices[] __initdata = { 305static struct platform_device *ms7724se_devices[] __initdata = {
276 &heartbeat_device, 306 &heartbeat_device,
277 &smc91x_eth_device, 307 &smc91x_eth_device,
@@ -280,8 +310,57 @@ static struct platform_device *ms7724se_devices[] __initdata = {
280 &ceu0_device, 310 &ceu0_device,
281 &ceu1_device, 311 &ceu1_device,
282 &keysc_device, 312 &keysc_device,
313 &sh_eth_device,
283}; 314};
284 315
316#define EEPROM_OP 0xBA206000
317#define EEPROM_ADR 0xBA206004
318#define EEPROM_DATA 0xBA20600C
319#define EEPROM_STAT 0xBA206010
320#define EEPROM_STRT 0xBA206014
321static int __init sh_eth_is_eeprom_ready(void)
322{
323 int t = 10000;
324
325 while (t--) {
326 if (!ctrl_inw(EEPROM_STAT))
327 return 1;
328 cpu_relax();
329 }
330
331 printk(KERN_ERR "ms7724se can not access to eeprom\n");
332 return 0;
333}
334
335static void __init sh_eth_init(void)
336{
337 int i;
338 u16 mac[3];
339
340 /* check EEPROM status */
341 if (!sh_eth_is_eeprom_ready())
342 return;
343
344 /* read MAC addr from EEPROM */
345 for (i = 0 ; i < 3 ; i++) {
346 ctrl_outw(0x0, EEPROM_OP); /* read */
347 ctrl_outw(i*2, EEPROM_ADR);
348 ctrl_outw(0x1, EEPROM_STRT);
349 if (!sh_eth_is_eeprom_ready())
350 return;
351
352 mac[i] = ctrl_inw(EEPROM_DATA);
353 mac[i] = ((mac[i] & 0xFF) << 8) | (mac[i] >> 8); /* swap */
354 }
355
356 /* reset sh-eth */
357 ctrl_outl(0x1, SH_ETH_ADDR + 0x0);
358
359 /* set MAC addr */
360 ctrl_outl(((mac[0] << 16) | (mac[1])), SH_ETH_MAHR);
361 ctrl_outl((mac[2]), SH_ETH_MALR);
362}
363
285#define SW4140 0xBA201000 364#define SW4140 0xBA201000
286#define FPGA_OUT 0xBA200400 365#define FPGA_OUT 0xBA200400
287#define PORT_HIZA 0xA4050158 366#define PORT_HIZA 0xA4050158
@@ -302,7 +381,8 @@ static int __init devices_setup(void)
302 ctrl_outw(ctrl_inw(FPGA_OUT) & 381 ctrl_outw(ctrl_inw(FPGA_OUT) &
303 ~((1 << 1) | /* LAN */ 382 ~((1 << 1) | /* LAN */
304 (1 << 6) | /* VIDEO DAC */ 383 (1 << 6) | /* VIDEO DAC */
305 (1 << 12)), /* USB0 */ 384 (1 << 12) | /* USB0 */
385 (1 << 14)), /* RMII */
306 FPGA_OUT); 386 FPGA_OUT);
307 387
308 /* enable IRQ 0,1,2 */ 388 /* enable IRQ 0,1,2 */
@@ -374,7 +454,7 @@ static int __init devices_setup(void)
374 gpio_request(GPIO_FN_VIO0_CLK, NULL); 454 gpio_request(GPIO_FN_VIO0_CLK, NULL);
375 gpio_request(GPIO_FN_VIO0_FLD, NULL); 455 gpio_request(GPIO_FN_VIO0_FLD, NULL);
376 gpio_request(GPIO_FN_VIO0_HD, NULL); 456 gpio_request(GPIO_FN_VIO0_HD, NULL);
377 platform_resource_setup_memory(&ceu0_device, "ceu", 4 << 20); 457 platform_resource_setup_memory(&ceu0_device, "ceu0", 4 << 20);
378 458
379 /* enable CEU1 */ 459 /* enable CEU1 */
380 gpio_request(GPIO_FN_VIO1_D7, NULL); 460 gpio_request(GPIO_FN_VIO1_D7, NULL);
@@ -389,7 +469,7 @@ static int __init devices_setup(void)
389 gpio_request(GPIO_FN_VIO1_HD, NULL); 469 gpio_request(GPIO_FN_VIO1_HD, NULL);
390 gpio_request(GPIO_FN_VIO1_VD, NULL); 470 gpio_request(GPIO_FN_VIO1_VD, NULL);
391 gpio_request(GPIO_FN_VIO1_CLK, NULL); 471 gpio_request(GPIO_FN_VIO1_CLK, NULL);
392 platform_resource_setup_memory(&ceu1_device, "ceu", 4 << 20); 472 platform_resource_setup_memory(&ceu1_device, "ceu1", 4 << 20);
393 473
394 /* KEYSC */ 474 /* KEYSC */
395 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL); 475 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
@@ -404,6 +484,28 @@ static int __init devices_setup(void)
404 gpio_request(GPIO_FN_KEYOUT1, NULL); 484 gpio_request(GPIO_FN_KEYOUT1, NULL);
405 gpio_request(GPIO_FN_KEYOUT0, NULL); 485 gpio_request(GPIO_FN_KEYOUT0, NULL);
406 486
487 /*
488 * enable SH-Eth
489 *
490 * please remove J33 pin from your board !!
491 *
492 * ms7724 board should not use GPIO_FN_LNKSTA pin
493 * So, This time PTX5 is set to input pin
494 */
495 gpio_request(GPIO_FN_RMII_RXD0, NULL);
496 gpio_request(GPIO_FN_RMII_RXD1, NULL);
497 gpio_request(GPIO_FN_RMII_TXD0, NULL);
498 gpio_request(GPIO_FN_RMII_TXD1, NULL);
499 gpio_request(GPIO_FN_RMII_REF_CLK, NULL);
500 gpio_request(GPIO_FN_RMII_TX_EN, NULL);
501 gpio_request(GPIO_FN_RMII_RX_ER, NULL);
502 gpio_request(GPIO_FN_RMII_CRS_DV, NULL);
503 gpio_request(GPIO_FN_MDIO, NULL);
504 gpio_request(GPIO_FN_MDC, NULL);
505 gpio_request(GPIO_PTX5, NULL);
506 gpio_direction_input(GPIO_PTX5);
507 sh_eth_init();
508
407 if (sw & SW41_B) { 509 if (sw & SW41_B) {
408 /* SVGA */ 510 /* SVGA */
409 lcdc_info.ch[0].lcd_cfg.xres = 800; 511 lcdc_info.ch[0].lcd_cfg.xres = 800;
@@ -437,7 +539,7 @@ static int __init devices_setup(void)
437 } 539 }
438 540
439 return platform_add_devices(ms7724se_devices, 541 return platform_add_devices(ms7724se_devices,
440 ARRAY_SIZE(ms7724se_devices)); 542 ARRAY_SIZE(ms7724se_devices));
441} 543}
442device_initcall(devices_setup); 544device_initcall(devices_setup);
443 545
diff --git a/arch/sh/configs/migor_defconfig b/arch/sh/configs/migor_defconfig
index da627d22c009..b18cfd39cac6 100644
--- a/arch/sh/configs/migor_defconfig
+++ b/arch/sh/configs/migor_defconfig
@@ -309,7 +309,7 @@ CONFIG_ZERO_PAGE_OFFSET=0x00001000
309CONFIG_BOOT_LINK_OFFSET=0x00800000 309CONFIG_BOOT_LINK_OFFSET=0x00800000
310CONFIG_ENTRY_OFFSET=0x00001000 310CONFIG_ENTRY_OFFSET=0x00001000
311CONFIG_CMDLINE_BOOL=y 311CONFIG_CMDLINE_BOOL=y
312CONFIG_CMDLINE="console=ttySC0,115200 earlyprintk=serial ip=on root=/dev/nfs ip=dhcp" 312CONFIG_CMDLINE="console=tty0 console=ttySC0,115200 earlyprintk=serial ip=on root=/dev/nfs ip=dhcp"
313 313
314# 314#
315# Bus options 315# Bus options
@@ -858,7 +858,35 @@ CONFIG_VIDEO_SH_MOBILE_CEU=y
858# 858#
859# CONFIG_VGASTATE is not set 859# CONFIG_VGASTATE is not set
860# CONFIG_VIDEO_OUTPUT_CONTROL is not set 860# CONFIG_VIDEO_OUTPUT_CONTROL is not set
861# CONFIG_FB is not set 861CONFIG_FB=y
862# CONFIG_FIRMWARE_EDID is not set
863# CONFIG_FB_DDC is not set
864# CONFIG_FB_BOOT_VESA_SUPPORT is not set
865# CONFIG_FB_CFB_FILLRECT is not set
866# CONFIG_FB_CFB_COPYAREA is not set
867# CONFIG_FB_CFB_IMAGEBLIT is not set
868# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
869CONFIG_FB_SYS_FILLRECT=y
870CONFIG_FB_SYS_COPYAREA=y
871CONFIG_FB_SYS_IMAGEBLIT=y
872# CONFIG_FB_FOREIGN_ENDIAN is not set
873CONFIG_FB_SYS_FOPS=y
874CONFIG_FB_DEFERRED_IO=y
875# CONFIG_FB_SVGALIB is not set
876# CONFIG_FB_MACMODES is not set
877# CONFIG_FB_BACKLIGHT is not set
878# CONFIG_FB_MODE_HELPERS is not set
879# CONFIG_FB_TILEBLITTING is not set
880
881#
882# Frame buffer hardware drivers
883#
884# CONFIG_FB_S1D13XXX is not set
885CONFIG_FB_SH_MOBILE_LCDC=y
886# CONFIG_FB_VIRTUAL is not set
887# CONFIG_FB_METRONOME is not set
888# CONFIG_FB_MB862XX is not set
889# CONFIG_FB_BROADSHEET is not set
862# CONFIG_BACKLIGHT_LCD_SUPPORT is not set 890# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
863 891
864# 892#
@@ -870,6 +898,27 @@ CONFIG_VIDEO_SH_MOBILE_CEU=y
870# Console display driver support 898# Console display driver support
871# 899#
872CONFIG_DUMMY_CONSOLE=y 900CONFIG_DUMMY_CONSOLE=y
901CONFIG_FRAMEBUFFER_CONSOLE=y
902CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
903# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
904CONFIG_FONTS=y
905# CONFIG_FONT_8x8 is not set
906# CONFIG_FONT_8x16 is not set
907# CONFIG_FONT_6x11 is not set
908# CONFIG_FONT_7x14 is not set
909# CONFIG_FONT_PEARL_8x8 is not set
910# CONFIG_FONT_ACORN_8x8 is not set
911CONFIG_FONT_MINI_4x6=y
912# CONFIG_FONT_SUN8x16 is not set
913# CONFIG_FONT_SUN12x22 is not set
914# CONFIG_FONT_10x18 is not set
915CONFIG_LOGO=y
916# CONFIG_LOGO_LINUX_MONO is not set
917# CONFIG_LOGO_LINUX_VGA16 is not set
918# CONFIG_LOGO_LINUX_CLUT224 is not set
919# CONFIG_LOGO_SUPERH_MONO is not set
920CONFIG_LOGO_SUPERH_VGA16=y
921# CONFIG_LOGO_SUPERH_CLUT224 is not set
873# CONFIG_SOUND is not set 922# CONFIG_SOUND is not set
874CONFIG_HID_SUPPORT=y 923CONFIG_HID_SUPPORT=y
875CONFIG_HID=y 924CONFIG_HID=y
diff --git a/arch/sh/configs/se7724_defconfig b/arch/sh/configs/se7724_defconfig
index 3840270283e4..3ee783a0a075 100644
--- a/arch/sh/configs/se7724_defconfig
+++ b/arch/sh/configs/se7724_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.30 3# Linux kernel version: 2.6.30
4# Thu Jun 18 16:09:05 2009 4# Mon Jun 29 16:28:43 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
@@ -14,6 +14,7 @@ CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y 14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y 15CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
16CONFIG_GENERIC_IRQ_PROBE=y 16CONFIG_GENERIC_IRQ_PROBE=y
17CONFIG_IRQ_PER_CPU=y
17CONFIG_GENERIC_GPIO=y 18CONFIG_GENERIC_GPIO=y
18CONFIG_GENERIC_TIME=y 19CONFIG_GENERIC_TIME=y
19CONFIG_GENERIC_CLOCKEVENTS=y 20CONFIG_GENERIC_CLOCKEVENTS=y
@@ -28,7 +29,9 @@ CONFIG_HAVE_LATENCYTOP_SUPPORT=y
28# CONFIG_ARCH_HAS_ILOG2_U64 is not set 29# CONFIG_ARCH_HAS_ILOG2_U64 is not set
29CONFIG_ARCH_NO_VIRT_TO_BUS=y 30CONFIG_ARCH_NO_VIRT_TO_BUS=y
30CONFIG_ARCH_HAS_DEFAULT_IDLE=y 31CONFIG_ARCH_HAS_DEFAULT_IDLE=y
32CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
31CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 33CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
34CONFIG_CONSTRUCTORS=y
32 35
33# 36#
34# General setup 37# General setup
@@ -88,10 +91,12 @@ CONFIG_TIMERFD=y
88CONFIG_EVENTFD=y 91CONFIG_EVENTFD=y
89CONFIG_SHMEM=y 92CONFIG_SHMEM=y
90CONFIG_AIO=y 93CONFIG_AIO=y
94CONFIG_HAVE_PERF_COUNTERS=y
91 95
92# 96#
93# Performance Counters 97# Performance Counters
94# 98#
99# CONFIG_PERF_COUNTERS is not set
95CONFIG_VM_EVENT_COUNTERS=y 100CONFIG_VM_EVENT_COUNTERS=y
96# CONFIG_STRIP_ASM_SYMS is not set 101# CONFIG_STRIP_ASM_SYMS is not set
97CONFIG_COMPAT_BRK=y 102CONFIG_COMPAT_BRK=y
@@ -107,6 +112,10 @@ CONFIG_HAVE_KRETPROBES=y
107CONFIG_HAVE_ARCH_TRACEHOOK=y 112CONFIG_HAVE_ARCH_TRACEHOOK=y
108CONFIG_HAVE_CLK=y 113CONFIG_HAVE_CLK=y
109CONFIG_HAVE_DMA_API_DEBUG=y 114CONFIG_HAVE_DMA_API_DEBUG=y
115
116#
117# GCOV-based kernel profiling
118#
110# CONFIG_SLOW_WORK is not set 119# CONFIG_SLOW_WORK is not set
111CONFIG_HAVE_GENERIC_DMA_COHERENT=y 120CONFIG_HAVE_GENERIC_DMA_COHERENT=y
112CONFIG_SLABINFO=y 121CONFIG_SLABINFO=y
@@ -119,7 +128,7 @@ CONFIG_MODULE_UNLOAD=y
119# CONFIG_MODVERSIONS is not set 128# CONFIG_MODVERSIONS is not set
120# CONFIG_MODULE_SRCVERSION_ALL is not set 129# CONFIG_MODULE_SRCVERSION_ALL is not set
121CONFIG_BLOCK=y 130CONFIG_BLOCK=y
122# CONFIG_LBD is not set 131CONFIG_LBDAF=y
123# CONFIG_BLK_DEV_BSG is not set 132# CONFIG_BLK_DEV_BSG is not set
124# CONFIG_BLK_DEV_INTEGRITY is not set 133# CONFIG_BLK_DEV_INTEGRITY is not set
125 134
@@ -584,7 +593,6 @@ CONFIG_SCSI_WAIT_SCAN=m
584# CONFIG_SCSI_SRP_ATTRS is not set 593# CONFIG_SCSI_SRP_ATTRS is not set
585CONFIG_SCSI_LOWLEVEL=y 594CONFIG_SCSI_LOWLEVEL=y
586# CONFIG_ISCSI_TCP is not set 595# CONFIG_ISCSI_TCP is not set
587# CONFIG_SCSI_BNX2_ISCSI is not set
588# CONFIG_LIBFC is not set 596# CONFIG_LIBFC is not set
589# CONFIG_LIBFCOE is not set 597# CONFIG_LIBFCOE is not set
590# CONFIG_SCSI_DEBUG is not set 598# CONFIG_SCSI_DEBUG is not set
@@ -624,7 +632,7 @@ CONFIG_NET_ETHERNET=y
624CONFIG_MII=y 632CONFIG_MII=y
625# CONFIG_AX88796 is not set 633# CONFIG_AX88796 is not set
626# CONFIG_STNIC is not set 634# CONFIG_STNIC is not set
627# CONFIG_SH_ETH is not set 635CONFIG_SH_ETH=y
628CONFIG_SMC91X=y 636CONFIG_SMC91X=y
629# CONFIG_ENC28J60 is not set 637# CONFIG_ENC28J60 is not set
630# CONFIG_ETHOC is not set 638# CONFIG_ETHOC is not set
@@ -801,6 +809,11 @@ CONFIG_SPI_BITBANG=y
801# 809#
802# CONFIG_SPI_SPIDEV is not set 810# CONFIG_SPI_SPIDEV is not set
803# CONFIG_SPI_TLE62X0 is not set 811# CONFIG_SPI_TLE62X0 is not set
812
813#
814# PPS support
815#
816# CONFIG_PPS is not set
804CONFIG_ARCH_REQUIRE_GPIOLIB=y 817CONFIG_ARCH_REQUIRE_GPIOLIB=y
805CONFIG_GPIOLIB=y 818CONFIG_GPIOLIB=y
806# CONFIG_GPIO_SYSFS is not set 819# CONFIG_GPIO_SYSFS is not set
@@ -851,6 +864,8 @@ CONFIG_SSB_POSSIBLE=y
851# CONFIG_MFD_WM8400 is not set 864# CONFIG_MFD_WM8400 is not set
852# CONFIG_MFD_WM8350_I2C is not set 865# CONFIG_MFD_WM8350_I2C is not set
853# CONFIG_MFD_PCF50633 is not set 866# CONFIG_MFD_PCF50633 is not set
867# CONFIG_AB3100_CORE is not set
868# CONFIG_EZX_PCAP is not set
854# CONFIG_REGULATOR is not set 869# CONFIG_REGULATOR is not set
855CONFIG_MEDIA_SUPPORT=y 870CONFIG_MEDIA_SUPPORT=y
856 871
@@ -1196,6 +1211,7 @@ CONFIG_RTC_DRV_PCF8563=y
1196# CONFIG_RTC_DRV_S35390A is not set 1211# CONFIG_RTC_DRV_S35390A is not set
1197# CONFIG_RTC_DRV_FM3130 is not set 1212# CONFIG_RTC_DRV_FM3130 is not set
1198# CONFIG_RTC_DRV_RX8581 is not set 1213# CONFIG_RTC_DRV_RX8581 is not set
1214# CONFIG_RTC_DRV_RX8025 is not set
1199 1215
1200# 1216#
1201# SPI RTC drivers 1217# SPI RTC drivers
@@ -1260,6 +1276,7 @@ CONFIG_FS_MBCACHE=y
1260# CONFIG_JFS_FS is not set 1276# CONFIG_JFS_FS is not set
1261CONFIG_FS_POSIX_ACL=y 1277CONFIG_FS_POSIX_ACL=y
1262# CONFIG_XFS_FS is not set 1278# CONFIG_XFS_FS is not set
1279# CONFIG_GFS2_FS is not set
1263# CONFIG_OCFS2_FS is not set 1280# CONFIG_OCFS2_FS is not set
1264# CONFIG_BTRFS_FS is not set 1281# CONFIG_BTRFS_FS is not set
1265CONFIG_FILE_LOCKING=y 1282CONFIG_FILE_LOCKING=y
diff --git a/arch/sh/include/asm/perf_counter.h b/arch/sh/include/asm/perf_counter.h
index a8153c2aa6fa..61c2b40c802c 100644
--- a/arch/sh/include/asm/perf_counter.h
+++ b/arch/sh/include/asm/perf_counter.h
@@ -2,6 +2,6 @@
2#define __ASM_SH_PERF_COUNTER_H 2#define __ASM_SH_PERF_COUNTER_H
3 3
4/* SH only supports software counters through this interface. */ 4/* SH only supports software counters through this interface. */
5#define set_perf_counter_pending() do { } while (0) 5static inline void set_perf_counter_pending(void) {}
6 6
7#endif /* __ASM_SH_PERF_COUNTER_H */ 7#endif /* __ASM_SH_PERF_COUNTER_H */
diff --git a/arch/sh/include/asm/syscall_32.h b/arch/sh/include/asm/syscall_32.h
index 5bc34681d994..6f83f2cc45c1 100644
--- a/arch/sh/include/asm/syscall_32.h
+++ b/arch/sh/include/asm/syscall_32.h
@@ -3,6 +3,7 @@
3 3
4#include <linux/kernel.h> 4#include <linux/kernel.h>
5#include <linux/sched.h> 5#include <linux/sched.h>
6#include <linux/err.h>
6#include <asm/ptrace.h> 7#include <asm/ptrace.h>
7 8
8/* The system call number is given by the user in R3 */ 9/* The system call number is given by the user in R3 */
diff --git a/arch/sh/include/mach-se/mach/se7724.h b/arch/sh/include/mach-se/mach/se7724.h
index 74164b60d0db..29514a39d0f5 100644
--- a/arch/sh/include/mach-se/mach/se7724.h
+++ b/arch/sh/include/mach-se/mach/se7724.h
@@ -20,6 +20,11 @@
20 */ 20 */
21#include <asm/addrspace.h> 21#include <asm/addrspace.h>
22 22
23/* SH Eth */
24#define SH_ETH_ADDR (0xA4600000)
25#define SH_ETH_MAHR (SH_ETH_ADDR + 0x1C0)
26#define SH_ETH_MALR (SH_ETH_ADDR + 0x1C8)
27
23#define PA_LED (0xba203000) /* 8bit LED */ 28#define PA_LED (0xba203000) /* 8bit LED */
24#define IRQ_MODE (0xba200010) 29#define IRQ_MODE (0xba200010)
25#define IRQ0_SR (0xba200014) 30#define IRQ0_SR (0xba200014)
diff --git a/arch/sh/mm/fault_32.c b/arch/sh/mm/fault_32.c
index cc8ddbdf3d7a..71925946f1e1 100644
--- a/arch/sh/mm/fault_32.c
+++ b/arch/sh/mm/fault_32.c
@@ -15,12 +15,28 @@
15#include <linux/mm.h> 15#include <linux/mm.h>
16#include <linux/hardirq.h> 16#include <linux/hardirq.h>
17#include <linux/kprobes.h> 17#include <linux/kprobes.h>
18#include <linux/marker.h> 18#include <linux/perf_counter.h>
19#include <asm/io_trapped.h> 19#include <asm/io_trapped.h>
20#include <asm/system.h> 20#include <asm/system.h>
21#include <asm/mmu_context.h> 21#include <asm/mmu_context.h>
22#include <asm/tlbflush.h> 22#include <asm/tlbflush.h>
23 23
24static inline int notify_page_fault(struct pt_regs *regs, int trap)
25{
26 int ret = 0;
27
28#ifdef CONFIG_KPROBES
29 if (!user_mode(regs)) {
30 preempt_disable();
31 if (kprobe_running() && kprobe_fault_handler(regs, trap))
32 ret = 1;
33 preempt_enable();
34 }
35#endif
36
37 return ret;
38}
39
24/* 40/*
25 * This routine handles page faults. It determines the address, 41 * This routine handles page faults. It determines the address,
26 * and the problem, and then passes it off to one of the appropriate 42 * and the problem, and then passes it off to one of the appropriate
@@ -87,13 +103,16 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
87 return; 103 return;
88 } 104 }
89 105
106 mm = tsk->mm;
107
108 if (unlikely(notify_page_fault(regs, lookup_exception_vector())))
109 return;
110
90 /* Only enable interrupts if they were on before the fault */ 111 /* Only enable interrupts if they were on before the fault */
91 if ((regs->sr & SR_IMASK) != SR_IMASK) { 112 if ((regs->sr & SR_IMASK) != SR_IMASK)
92 trace_hardirqs_on();
93 local_irq_enable(); 113 local_irq_enable();
94 }
95 114
96 mm = tsk->mm; 115 perf_swcounter_event(PERF_COUNT_SW_PAGE_FAULTS, 1, 0, regs, address);
97 116
98 /* 117 /*
99 * If we're in an interrupt or have no user 118 * If we're in an interrupt or have no user
@@ -141,10 +160,15 @@ survive:
141 goto do_sigbus; 160 goto do_sigbus;
142 BUG(); 161 BUG();
143 } 162 }
144 if (fault & VM_FAULT_MAJOR) 163 if (fault & VM_FAULT_MAJOR) {
145 tsk->maj_flt++; 164 tsk->maj_flt++;
146 else 165 perf_swcounter_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, 0,
166 regs, address);
167 } else {
147 tsk->min_flt++; 168 tsk->min_flt++;
169 perf_swcounter_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, 0,
170 regs, address);
171 }
148 172
149 up_read(&mm->mmap_sem); 173 up_read(&mm->mmap_sem);
150 return; 174 return;
@@ -245,22 +269,6 @@ do_sigbus:
245 goto no_context; 269 goto no_context;
246} 270}
247 271
248static inline int notify_page_fault(struct pt_regs *regs, int trap)
249{
250 int ret = 0;
251
252#ifdef CONFIG_KPROBES
253 if (!user_mode(regs)) {
254 preempt_disable();
255 if (kprobe_running() && kprobe_fault_handler(regs, trap))
256 ret = 1;
257 preempt_enable();
258 }
259#endif
260
261 return ret;
262}
263
264/* 272/*
265 * Called with interrupts disabled. 273 * Called with interrupts disabled.
266 */ 274 */
@@ -273,12 +281,7 @@ asmlinkage int __kprobes __do_page_fault(struct pt_regs *regs,
273 pmd_t *pmd; 281 pmd_t *pmd;
274 pte_t *pte; 282 pte_t *pte;
275 pte_t entry; 283 pte_t entry;
276 int ret = 0; 284 int ret = 1;
277
278 if (notify_page_fault(regs, lookup_exception_vector()))
279 goto out;
280
281 ret = 1;
282 285
283 /* 286 /*
284 * We don't take page faults for P1, P2, and parts of P4, these 287 * We don't take page faults for P1, P2, and parts of P4, these
diff --git a/arch/sh/mm/tlbflush_64.c b/arch/sh/mm/tlbflush_64.c
index fcbb6e135cef..3ce40ea34824 100644
--- a/arch/sh/mm/tlbflush_64.c
+++ b/arch/sh/mm/tlbflush_64.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2000, 2001 Paolo Alberelli 4 * Copyright (C) 2000, 2001 Paolo Alberelli
5 * Copyright (C) 2003 Richard Curnow (/proc/tlb, bug fixes) 5 * Copyright (C) 2003 Richard Curnow (/proc/tlb, bug fixes)
6 * Copyright (C) 2003 Paul Mundt 6 * Copyright (C) 2003 - 2009 Paul Mundt
7 * 7 *
8 * This file is subject to the terms and conditions of the GNU General Public 8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive 9 * License. See the file "COPYING" in the main directory of this archive
@@ -20,6 +20,7 @@
20#include <linux/mman.h> 20#include <linux/mman.h>
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/smp.h> 22#include <linux/smp.h>
23#include <linux/perf_counter.h>
23#include <linux/interrupt.h> 24#include <linux/interrupt.h>
24#include <asm/system.h> 25#include <asm/system.h>
25#include <asm/io.h> 26#include <asm/io.h>
@@ -115,6 +116,8 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long writeaccess,
115 /* Not an IO address, so reenable interrupts */ 116 /* Not an IO address, so reenable interrupts */
116 local_irq_enable(); 117 local_irq_enable();
117 118
119 perf_swcounter_event(PERF_COUNT_SW_PAGE_FAULTS, 1, 0, regs, address);
120
118 /* 121 /*
119 * If we're in an interrupt or have no user 122 * If we're in an interrupt or have no user
120 * context, we must not take the fault.. 123 * context, we must not take the fault..
@@ -195,10 +198,16 @@ survive:
195 goto do_sigbus; 198 goto do_sigbus;
196 BUG(); 199 BUG();
197 } 200 }
198 if (fault & VM_FAULT_MAJOR) 201
202 if (fault & VM_FAULT_MAJOR) {
199 tsk->maj_flt++; 203 tsk->maj_flt++;
200 else 204 perf_swcounter_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, 0,
205 regs, address);
206 } else {
201 tsk->min_flt++; 207 tsk->min_flt++;
208 perf_swcounter_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, 0,
209 regs, address);
210 }
202 211
203 /* If we get here, the page fault has been handled. Do the TLB refill 212 /* If we get here, the page fault has been handled. Do the TLB refill
204 now from the newly-setup PTE, to avoid having to fault again right 213 now from the newly-setup PTE, to avoid having to fault again right
diff --git a/arch/sparc/boot/Makefile b/arch/sparc/boot/Makefile
index 96041a8d39e8..1ff0fd924756 100644
--- a/arch/sparc/boot/Makefile
+++ b/arch/sparc/boot/Makefile
@@ -15,7 +15,7 @@ quiet_cmd_elftoaout = ELFTOAOUT $@
15 15
16ifeq ($(CONFIG_SPARC32),y) 16ifeq ($(CONFIG_SPARC32),y)
17quiet_cmd_piggy = PIGGY $@ 17quiet_cmd_piggy = PIGGY $@
18 cmd_piggy = $(obj)/piggyback_32 $@ $(obj)/System.map $(ROOT_IMG) 18 cmd_piggy = $(obj)/piggyback_32 $@ System.map $(ROOT_IMG)
19quiet_cmd_btfix = BTFIX $@ 19quiet_cmd_btfix = BTFIX $@
20 cmd_btfix = $(OBJDUMP) -x vmlinux | $(obj)/btfixupprep > $@ 20 cmd_btfix = $(OBJDUMP) -x vmlinux | $(obj)/btfixupprep > $@
21quiet_cmd_sysmap = SYSMAP $(obj)/System.map 21quiet_cmd_sysmap = SYSMAP $(obj)/System.map
@@ -58,7 +58,7 @@ $(obj)/image: $(obj)/btfix.o FORCE
58$(obj)/zImage: $(obj)/image 58$(obj)/zImage: $(obj)/image
59 $(call if_changed,strip) 59 $(call if_changed,strip)
60 60
61$(obj)/tftpboot.img: $(obj)/piggyback $(obj)/System.map $(obj)/image FORCE 61$(obj)/tftpboot.img: $(obj)/image $(obj)/piggyback_32 System.map $(ROOT_IMG) FORCE
62 $(call if_changed,elftoaout) 62 $(call if_changed,elftoaout)
63 $(call if_changed,piggy) 63 $(call if_changed,piggy)
64 64
@@ -79,7 +79,7 @@ $(obj)/image: vmlinux FORCE
79 $(call if_changed,strip) 79 $(call if_changed,strip)
80 @echo ' kernel: $@ is ready' 80 @echo ' kernel: $@ is ready'
81 81
82$(obj)/tftpboot.img: vmlinux $(obj)/piggyback_64 System.map $(ROOT_IMG) FORCE 82$(obj)/tftpboot.img: $(obj)/image $(obj)/piggyback_64 System.map $(ROOT_IMG) FORCE
83 $(call if_changed,elftoaout) 83 $(call if_changed,elftoaout)
84 $(call if_changed,piggy) 84 $(call if_changed,piggy)
85 @echo ' kernel: $@ is ready' 85 @echo ' kernel: $@ is ready'
diff --git a/arch/sparc/boot/piggyback_32.c b/arch/sparc/boot/piggyback_32.c
index c9f500c1a8b2..e8dc9adfcd61 100644
--- a/arch/sparc/boot/piggyback_32.c
+++ b/arch/sparc/boot/piggyback_32.c
@@ -70,7 +70,7 @@ void die(char *str)
70int main(int argc,char **argv) 70int main(int argc,char **argv)
71{ 71{
72 static char aout_magic[] = { 0x01, 0x03, 0x01, 0x07 }; 72 static char aout_magic[] = { 0x01, 0x03, 0x01, 0x07 };
73 unsigned char buffer[1024], *q, *r; 73 char buffer[1024], *q, *r;
74 unsigned int i, j, k, start, end, offset; 74 unsigned int i, j, k, start, end, offset;
75 FILE *map; 75 FILE *map;
76 struct stat s; 76 struct stat s;
@@ -84,7 +84,7 @@ int main(int argc,char **argv)
84 while (fgets (buffer, 1024, map)) { 84 while (fgets (buffer, 1024, map)) {
85 if (!strcmp (buffer + 8, " T start\n") || !strcmp (buffer + 16, " T start\n")) 85 if (!strcmp (buffer + 8, " T start\n") || !strcmp (buffer + 16, " T start\n"))
86 start = strtoul (buffer, NULL, 16); 86 start = strtoul (buffer, NULL, 16);
87 else if (!strcmp (buffer + 8, " A end\n") || !strcmp (buffer + 16, " A end\n")) 87 else if (!strcmp (buffer + 8, " A _end\n") || !strcmp (buffer + 16, " A _end\n"))
88 end = strtoul (buffer, NULL, 16); 88 end = strtoul (buffer, NULL, 16);
89 } 89 }
90 fclose (map); 90 fclose (map);
diff --git a/arch/sparc/boot/piggyback_64.c b/arch/sparc/boot/piggyback_64.c
index de364bfed0bb..c63fd1b6bdd4 100644
--- a/arch/sparc/boot/piggyback_64.c
+++ b/arch/sparc/boot/piggyback_64.c
@@ -46,6 +46,7 @@ int main(int argc,char **argv)
46 struct stat s; 46 struct stat s;
47 int image, tail; 47 int image, tail;
48 48
49 start = end = 0;
49 if (stat (argv[3], &s) < 0) die (argv[3]); 50 if (stat (argv[3], &s) < 0) die (argv[3]);
50 map = fopen (argv[2], "r"); 51 map = fopen (argv[2], "r");
51 if (!map) die(argv[2]); 52 if (!map) die(argv[2]);
diff --git a/arch/sparc/kernel/irq_64.c b/arch/sparc/kernel/irq_64.c
index bd075054942b..f0ee79055409 100644
--- a/arch/sparc/kernel/irq_64.c
+++ b/arch/sparc/kernel/irq_64.c
@@ -20,7 +20,6 @@
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/proc_fs.h> 21#include <linux/proc_fs.h>
22#include <linux/seq_file.h> 22#include <linux/seq_file.h>
23#include <linux/bootmem.h>
24#include <linux/irq.h> 23#include <linux/irq.h>
25 24
26#include <asm/ptrace.h> 25#include <asm/ptrace.h>
@@ -914,25 +913,19 @@ void __cpuinit notrace sun4v_register_mondo_queues(int this_cpu)
914 tb->nonresum_qmask); 913 tb->nonresum_qmask);
915} 914}
916 915
917static void __init alloc_one_mondo(unsigned long *pa_ptr, unsigned long qmask) 916/* Each queue region must be a power of 2 multiple of 64 bytes in
918{ 917 * size. The base real address must be aligned to the size of the
919 unsigned long size = PAGE_ALIGN(qmask + 1); 918 * region. Thus, an 8KB queue must be 8KB aligned, for example.
920 void *p = __alloc_bootmem(size, size, 0); 919 */
921 if (!p) { 920static void __init alloc_one_queue(unsigned long *pa_ptr, unsigned long qmask)
922 prom_printf("SUN4V: Error, cannot allocate mondo queue.\n");
923 prom_halt();
924 }
925
926 *pa_ptr = __pa(p);
927}
928
929static void __init alloc_one_kbuf(unsigned long *pa_ptr, unsigned long qmask)
930{ 921{
931 unsigned long size = PAGE_ALIGN(qmask + 1); 922 unsigned long size = PAGE_ALIGN(qmask + 1);
932 void *p = __alloc_bootmem(size, size, 0); 923 unsigned long order = get_order(size);
924 unsigned long p;
933 925
926 p = __get_free_pages(GFP_KERNEL, order);
934 if (!p) { 927 if (!p) {
935 prom_printf("SUN4V: Error, cannot allocate kbuf page.\n"); 928 prom_printf("SUN4V: Error, cannot allocate queue.\n");
936 prom_halt(); 929 prom_halt();
937 } 930 }
938 931
@@ -942,11 +935,11 @@ static void __init alloc_one_kbuf(unsigned long *pa_ptr, unsigned long qmask)
942static void __init init_cpu_send_mondo_info(struct trap_per_cpu *tb) 935static void __init init_cpu_send_mondo_info(struct trap_per_cpu *tb)
943{ 936{
944#ifdef CONFIG_SMP 937#ifdef CONFIG_SMP
945 void *page; 938 unsigned long page;
946 939
947 BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64)); 940 BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
948 941
949 page = alloc_bootmem_pages(PAGE_SIZE); 942 page = get_zeroed_page(GFP_KERNEL);
950 if (!page) { 943 if (!page) {
951 prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n"); 944 prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
952 prom_halt(); 945 prom_halt();
@@ -965,13 +958,13 @@ static void __init sun4v_init_mondo_queues(void)
965 for_each_possible_cpu(cpu) { 958 for_each_possible_cpu(cpu) {
966 struct trap_per_cpu *tb = &trap_block[cpu]; 959 struct trap_per_cpu *tb = &trap_block[cpu];
967 960
968 alloc_one_mondo(&tb->cpu_mondo_pa, tb->cpu_mondo_qmask); 961 alloc_one_queue(&tb->cpu_mondo_pa, tb->cpu_mondo_qmask);
969 alloc_one_mondo(&tb->dev_mondo_pa, tb->dev_mondo_qmask); 962 alloc_one_queue(&tb->dev_mondo_pa, tb->dev_mondo_qmask);
970 alloc_one_mondo(&tb->resum_mondo_pa, tb->resum_qmask); 963 alloc_one_queue(&tb->resum_mondo_pa, tb->resum_qmask);
971 alloc_one_kbuf(&tb->resum_kernel_buf_pa, tb->resum_qmask); 964 alloc_one_queue(&tb->resum_kernel_buf_pa, tb->resum_qmask);
972 alloc_one_mondo(&tb->nonresum_mondo_pa, tb->nonresum_qmask); 965 alloc_one_queue(&tb->nonresum_mondo_pa, tb->nonresum_qmask);
973 alloc_one_kbuf(&tb->nonresum_kernel_buf_pa, 966 alloc_one_queue(&tb->nonresum_kernel_buf_pa,
974 tb->nonresum_qmask); 967 tb->nonresum_qmask);
975 } 968 }
976} 969}
977 970
@@ -999,7 +992,7 @@ void __init init_IRQ(void)
999 kill_prom_timer(); 992 kill_prom_timer();
1000 993
1001 size = sizeof(struct ino_bucket) * NUM_IVECS; 994 size = sizeof(struct ino_bucket) * NUM_IVECS;
1002 ivector_table = alloc_bootmem(size); 995 ivector_table = kzalloc(size, GFP_KERNEL);
1003 if (!ivector_table) { 996 if (!ivector_table) {
1004 prom_printf("Fatal error, cannot allocate ivector_table\n"); 997 prom_printf("Fatal error, cannot allocate ivector_table\n");
1005 prom_halt(); 998 prom_halt();
diff --git a/arch/sparc/kernel/sys32.S b/arch/sparc/kernel/sys32.S
index f061c4dda9ef..3762f6c78944 100644
--- a/arch/sparc/kernel/sys32.S
+++ b/arch/sparc/kernel/sys32.S
@@ -121,7 +121,7 @@ SIGN2(sys32_syslog, sys_syslog, %o0, %o2)
121SIGN1(sys32_umask, sys_umask, %o0) 121SIGN1(sys32_umask, sys_umask, %o0)
122SIGN3(sys32_tgkill, sys_tgkill, %o0, %o1, %o2) 122SIGN3(sys32_tgkill, sys_tgkill, %o0, %o1, %o2)
123SIGN1(sys32_sendto, sys_sendto, %o0) 123SIGN1(sys32_sendto, sys_sendto, %o0)
124SIGN1(sys32_recvfrom, sys_recvfrom, %o0) 124SIGN1(sys32_recvfrom, compat_sys_recvfrom, %o0)
125SIGN3(sys32_socket, sys_socket, %o0, %o1, %o2) 125SIGN3(sys32_socket, sys_socket, %o0, %o1, %o2)
126SIGN2(sys32_connect, sys_connect, %o0, %o2) 126SIGN2(sys32_connect, sys_connect, %o0, %o2)
127SIGN2(sys32_bind, sys_bind, %o0, %o2) 127SIGN2(sys32_bind, sys_bind, %o0, %o2)
diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
index 3b44b47c7e1d..4c75409bc09c 100644
--- a/arch/um/drivers/net_kern.c
+++ b/arch/um/drivers/net_kern.c
@@ -245,7 +245,7 @@ static int uml_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
245 245
246 dev_kfree_skb(skb); 246 dev_kfree_skb(skb);
247 247
248 return 0; 248 return NETDEV_TX_OK;
249} 249}
250 250
251static void uml_net_set_multicast_list(struct net_device *dev) 251static void uml_net_set_multicast_list(struct net_device *dev)
diff --git a/arch/um/drivers/slip_kern.c b/arch/um/drivers/slip_kern.c
index 5ec17563142e..dd2aadc14af0 100644
--- a/arch/um/drivers/slip_kern.c
+++ b/arch/um/drivers/slip_kern.c
@@ -30,7 +30,6 @@ static void slip_init(struct net_device *dev, void *data)
30 30
31 slip_proto_init(&spri->slip); 31 slip_proto_init(&spri->slip);
32 32
33 dev->init = NULL;
34 dev->hard_header_len = 0; 33 dev->hard_header_len = 0;
35 dev->header_ops = NULL; 34 dev->header_ops = NULL;
36 dev->addr_len = 0; 35 dev->addr_len = 0;
diff --git a/arch/um/drivers/slirp_kern.c b/arch/um/drivers/slirp_kern.c
index f15a6e7654f3..e376284f0fb7 100644
--- a/arch/um/drivers/slirp_kern.c
+++ b/arch/um/drivers/slirp_kern.c
@@ -32,7 +32,6 @@ void slirp_init(struct net_device *dev, void *data)
32 32
33 slip_proto_init(&spri->slip); 33 slip_proto_init(&spri->slip);
34 34
35 dev->init = NULL;
36 dev->hard_header_len = 0; 35 dev->hard_header_len = 0;
37 dev->header_ops = NULL; 36 dev->header_ops = NULL;
38 dev->addr_len = 0; 37 dev->addr_len = 0;
diff --git a/arch/um/include/asm/dma-mapping.h b/arch/um/include/asm/dma-mapping.h
index 90fc708b320e..378de4bbf49f 100644
--- a/arch/um/include/asm/dma-mapping.h
+++ b/arch/um/include/asm/dma-mapping.h
@@ -79,14 +79,14 @@ dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
79} 79}
80 80
81static inline void 81static inline void
82dma_sync_single(struct device *dev, dma_addr_t dma_handle, size_t size, 82dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
83 enum dma_data_direction direction) 83 enum dma_data_direction direction)
84{ 84{
85 BUG(); 85 BUG();
86} 86}
87 87
88static inline void 88static inline void
89dma_sync_sg(struct device *dev, struct scatterlist *sg, int nelems, 89dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
90 enum dma_data_direction direction) 90 enum dma_data_direction direction)
91{ 91{
92 BUG(); 92 BUG();
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index d1430ef6b4f9..c07f72205909 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1913,25 +1913,14 @@ config DMAR_DEFAULT_ON
1913 recommended you say N here while the DMAR code remains 1913 recommended you say N here while the DMAR code remains
1914 experimental. 1914 experimental.
1915 1915
1916config DMAR_GFX_WA
1917 def_bool y
1918 prompt "Support for Graphics workaround"
1919 depends on DMAR
1920 ---help---
1921 Current Graphics drivers tend to use physical address
1922 for DMA and avoid using DMA APIs. Setting this config
1923 option permits the IOMMU driver to set a unity map for
1924 all the OS-visible memory. Hence the driver can continue
1925 to use physical addresses for DMA.
1926
1927config DMAR_FLOPPY_WA 1916config DMAR_FLOPPY_WA
1928 def_bool y 1917 def_bool y
1929 depends on DMAR 1918 depends on DMAR
1930 ---help--- 1919 ---help---
1931 Floppy disk drivers are know to bypass DMA API calls 1920 Floppy disk drivers are known to bypass DMA API calls
1932 thereby failing to work when IOMMU is enabled. This 1921 thereby failing to work when IOMMU is enabled. This
1933 workaround will setup a 1:1 mapping for the first 1922 workaround will setup a 1:1 mapping for the first
1934 16M to make floppy (an ISA device) work. 1923 16MiB to make floppy (an ISA device) work.
1935 1924
1936config INTR_REMAP 1925config INTR_REMAP
1937 bool "Support for Interrupt Remapping (EXPERIMENTAL)" 1926 bool "Support for Interrupt Remapping (EXPERIMENTAL)"
diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
index 418e632d4a80..7a1065958ba9 100644
--- a/arch/x86/include/asm/boot.h
+++ b/arch/x86/include/asm/boot.h
@@ -8,7 +8,7 @@
8 8
9#ifdef __KERNEL__ 9#ifdef __KERNEL__
10 10
11#include <asm/page_types.h> 11#include <asm/pgtable_types.h>
12 12
13/* Physical address where kernel should be loaded. */ 13/* Physical address where kernel should be loaded. */
14#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \ 14#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
@@ -16,10 +16,10 @@
16 & ~(CONFIG_PHYSICAL_ALIGN - 1)) 16 & ~(CONFIG_PHYSICAL_ALIGN - 1))
17 17
18/* Minimum kernel alignment, as a power of two */ 18/* Minimum kernel alignment, as a power of two */
19#ifdef CONFIG_x86_64 19#ifdef CONFIG_X86_64
20#define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT 20#define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
21#else 21#else
22#define MIN_KERNEL_ALIGN_LG2 (PAGE_SHIFT+1) 22#define MIN_KERNEL_ALIGN_LG2 (PAGE_SHIFT + THREAD_ORDER)
23#endif 23#endif
24#define MIN_KERNEL_ALIGN (_AC(1, UL) << MIN_KERNEL_ALIGN_LG2) 24#define MIN_KERNEL_ALIGN (_AC(1, UL) << MIN_KERNEL_ALIGN_LG2)
25 25
diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h
index 927958d13c19..1ff685ca221c 100644
--- a/arch/x86/include/asm/pci.h
+++ b/arch/x86/include/asm/pci.h
@@ -91,7 +91,7 @@ extern void pci_iommu_alloc(void);
91 91
92#define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys) 92#define PCI_DMA_BUS_IS_PHYS (dma_ops->is_phys)
93 93
94#if defined(CONFIG_X86_64) || defined(CONFIG_DMA_API_DEBUG) 94#if defined(CONFIG_X86_64) || defined(CONFIG_DMAR) || defined(CONFIG_DMA_API_DEBUG)
95 95
96#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \ 96#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
97 dma_addr_t ADDR_NAME; 97 dma_addr_t ADDR_NAME;
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 02ecb30982a3..103f1ddb0d85 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -42,6 +42,7 @@
42 42
43#else /* ...!ASSEMBLY */ 43#else /* ...!ASSEMBLY */
44 44
45#include <linux/kernel.h>
45#include <linux/stringify.h> 46#include <linux/stringify.h>
46 47
47#ifdef CONFIG_SMP 48#ifdef CONFIG_SMP
@@ -155,6 +156,15 @@ do { \
155/* We can use this directly for local CPU (faster). */ 156/* We can use this directly for local CPU (faster). */
156DECLARE_PER_CPU(unsigned long, this_cpu_off); 157DECLARE_PER_CPU(unsigned long, this_cpu_off);
157 158
159#ifdef CONFIG_NEED_MULTIPLE_NODES
160void *pcpu_lpage_remapped(void *kaddr);
161#else
162static inline void *pcpu_lpage_remapped(void *kaddr)
163{
164 return NULL;
165}
166#endif
167
158#endif /* !__ASSEMBLY__ */ 168#endif /* !__ASSEMBLY__ */
159 169
160#ifdef CONFIG_SMP 170#ifdef CONFIG_SMP
diff --git a/arch/x86/include/asm/perf_counter.h b/arch/x86/include/asm/perf_counter.h
index 5fb33e160ea0..fa64e401589d 100644
--- a/arch/x86/include/asm/perf_counter.h
+++ b/arch/x86/include/asm/perf_counter.h
@@ -87,6 +87,9 @@ union cpuid10_edx {
87#ifdef CONFIG_PERF_COUNTERS 87#ifdef CONFIG_PERF_COUNTERS
88extern void init_hw_perf_counters(void); 88extern void init_hw_perf_counters(void);
89extern void perf_counters_lapic_init(void); 89extern void perf_counters_lapic_init(void);
90
91#define PERF_COUNTER_INDEX_OFFSET 0
92
90#else 93#else
91static inline void init_hw_perf_counters(void) { } 94static inline void init_hw_perf_counters(void) { }
92static inline void perf_counters_lapic_init(void) { } 95static inline void perf_counters_lapic_init(void) { }
diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h
index 49fb3ecf3bb3..621f56d73121 100644
--- a/arch/x86/include/asm/proto.h
+++ b/arch/x86/include/asm/proto.h
@@ -22,7 +22,14 @@ extern int reboot_force;
22 22
23long do_arch_prctl(struct task_struct *task, int code, unsigned long addr); 23long do_arch_prctl(struct task_struct *task, int code, unsigned long addr);
24 24
25#define round_up(x, y) (((x) + (y) - 1) & ~((y) - 1)) 25/*
26#define round_down(x, y) ((x) & ~((y) - 1)) 26 * This looks more complex than it should be. But we need to
27 * get the type for the ~ right in round_down (it needs to be
28 * as wide as the result!), and we want to evaluate the macro
29 * arguments just once each.
30 */
31#define __round_mask(x,y) ((__typeof__(x))((y)-1))
32#define round_up(x,y) ((((x)-1) | __round_mask(x,y))+1)
33#define round_down(x,y) ((x) & ~__round_mask(x,y))
27 34
28#endif /* _ASM_X86_PROTO_H */ 35#endif /* _ASM_X86_PROTO_H */
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index e5b27d8f1b47..28e5f5956042 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -258,13 +258,15 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
258{ 258{
259#ifdef CONFIG_X86_HT 259#ifdef CONFIG_X86_HT
260 unsigned bits; 260 unsigned bits;
261 int cpu = smp_processor_id();
261 262
262 bits = c->x86_coreid_bits; 263 bits = c->x86_coreid_bits;
263
264 /* Low order bits define the core id (index of core in socket) */ 264 /* Low order bits define the core id (index of core in socket) */
265 c->cpu_core_id = c->initial_apicid & ((1 << bits)-1); 265 c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
266 /* Convert the initial APIC ID into the socket ID */ 266 /* Convert the initial APIC ID into the socket ID */
267 c->phys_proc_id = c->initial_apicid >> bits; 267 c->phys_proc_id = c->initial_apicid >> bits;
268 /* use socket ID also for last level cache */
269 per_cpu(cpu_llc_id, cpu) = c->phys_proc_id;
268#endif 270#endif
269} 271}
270 272
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 6b26d4deada0..f1961c07af9a 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -848,9 +848,6 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
848#if defined(CONFIG_NUMA) && defined(CONFIG_X86_64) 848#if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
849 numa_add_cpu(smp_processor_id()); 849 numa_add_cpu(smp_processor_id());
850#endif 850#endif
851
852 /* Cap the iomem address space to what is addressable on all CPUs */
853 iomem_resource.end &= (1ULL << c->x86_phys_bits) - 1;
854} 851}
855 852
856#ifdef CONFIG_X86_64 853#ifdef CONFIG_X86_64
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 284d1de968bc..af425b83202b 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -1117,7 +1117,7 @@ static void mcheck_timer(unsigned long data)
1117 *n = min(*n*2, (int)round_jiffies_relative(check_interval*HZ)); 1117 *n = min(*n*2, (int)round_jiffies_relative(check_interval*HZ));
1118 1118
1119 t->expires = jiffies + *n; 1119 t->expires = jiffies + *n;
1120 add_timer(t); 1120 add_timer_on(t, smp_processor_id());
1121} 1121}
1122 1122
1123static void mce_do_trigger(struct work_struct *work) 1123static void mce_do_trigger(struct work_struct *work)
@@ -1321,7 +1321,7 @@ static void mce_init_timer(void)
1321 return; 1321 return;
1322 setup_timer(t, mcheck_timer, smp_processor_id()); 1322 setup_timer(t, mcheck_timer, smp_processor_id());
1323 t->expires = round_jiffies(jiffies + *n); 1323 t->expires = round_jiffies(jiffies + *n);
1324 add_timer(t); 1324 add_timer_on(t, smp_processor_id());
1325} 1325}
1326 1326
1327/* 1327/*
diff --git a/arch/x86/kernel/cpu/perf_counter.c b/arch/x86/kernel/cpu/perf_counter.c
index 76dfef23f789..d4cf4ce19aac 100644
--- a/arch/x86/kernel/cpu/perf_counter.c
+++ b/arch/x86/kernel/cpu/perf_counter.c
@@ -401,7 +401,7 @@ static const u64 amd_hw_cache_event_ids
401 [ C(RESULT_MISS) ] = 0x0041, /* Data Cache Misses */ 401 [ C(RESULT_MISS) ] = 0x0041, /* Data Cache Misses */
402 }, 402 },
403 [ C(OP_WRITE) ] = { 403 [ C(OP_WRITE) ] = {
404 [ C(RESULT_ACCESS) ] = 0x0042, /* Data Cache Refills from L2 */ 404 [ C(RESULT_ACCESS) ] = 0x0142, /* Data Cache Refills :system */
405 [ C(RESULT_MISS) ] = 0, 405 [ C(RESULT_MISS) ] = 0,
406 }, 406 },
407 [ C(OP_PREFETCH) ] = { 407 [ C(OP_PREFETCH) ] = {
@@ -912,6 +912,8 @@ x86_perf_counter_set_period(struct perf_counter *counter,
912 err = checking_wrmsrl(hwc->counter_base + idx, 912 err = checking_wrmsrl(hwc->counter_base + idx,
913 (u64)(-left) & x86_pmu.counter_mask); 913 (u64)(-left) & x86_pmu.counter_mask);
914 914
915 perf_counter_update_userpage(counter);
916
915 return ret; 917 return ret;
916} 918}
917 919
@@ -969,13 +971,6 @@ fixed_mode_idx(struct perf_counter *counter, struct hw_perf_counter *hwc)
969 if (!x86_pmu.num_counters_fixed) 971 if (!x86_pmu.num_counters_fixed)
970 return -1; 972 return -1;
971 973
972 /*
973 * Quirk, IA32_FIXED_CTRs do not work on current Atom processors:
974 */
975 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
976 boot_cpu_data.x86_model == 28)
977 return -1;
978
979 event = hwc->config & ARCH_PERFMON_EVENT_MASK; 974 event = hwc->config & ARCH_PERFMON_EVENT_MASK;
980 975
981 if (unlikely(event == x86_pmu.event_map(PERF_COUNT_HW_INSTRUCTIONS))) 976 if (unlikely(event == x86_pmu.event_map(PERF_COUNT_HW_INSTRUCTIONS)))
@@ -1041,6 +1036,8 @@ try_generic:
1041 x86_perf_counter_set_period(counter, hwc, idx); 1036 x86_perf_counter_set_period(counter, hwc, idx);
1042 x86_pmu.enable(hwc, idx); 1037 x86_pmu.enable(hwc, idx);
1043 1038
1039 perf_counter_update_userpage(counter);
1040
1044 return 0; 1041 return 0;
1045} 1042}
1046 1043
@@ -1133,6 +1130,8 @@ static void x86_pmu_disable(struct perf_counter *counter)
1133 x86_perf_counter_update(counter, hwc, idx); 1130 x86_perf_counter_update(counter, hwc, idx);
1134 cpuc->counters[idx] = NULL; 1131 cpuc->counters[idx] = NULL;
1135 clear_bit(idx, cpuc->used_mask); 1132 clear_bit(idx, cpuc->used_mask);
1133
1134 perf_counter_update_userpage(counter);
1136} 1135}
1137 1136
1138/* 1137/*
@@ -1428,8 +1427,6 @@ static int intel_pmu_init(void)
1428 */ 1427 */
1429 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3); 1428 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
1430 1429
1431 rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, x86_pmu.intel_ctrl);
1432
1433 /* 1430 /*
1434 * Install the hw-cache-events table: 1431 * Install the hw-cache-events table:
1435 */ 1432 */
@@ -1499,21 +1496,22 @@ void __init init_hw_perf_counters(void)
1499 pr_cont("%s PMU driver.\n", x86_pmu.name); 1496 pr_cont("%s PMU driver.\n", x86_pmu.name);
1500 1497
1501 if (x86_pmu.num_counters > X86_PMC_MAX_GENERIC) { 1498 if (x86_pmu.num_counters > X86_PMC_MAX_GENERIC) {
1502 x86_pmu.num_counters = X86_PMC_MAX_GENERIC;
1503 WARN(1, KERN_ERR "hw perf counters %d > max(%d), clipping!", 1499 WARN(1, KERN_ERR "hw perf counters %d > max(%d), clipping!",
1504 x86_pmu.num_counters, X86_PMC_MAX_GENERIC); 1500 x86_pmu.num_counters, X86_PMC_MAX_GENERIC);
1501 x86_pmu.num_counters = X86_PMC_MAX_GENERIC;
1505 } 1502 }
1506 perf_counter_mask = (1 << x86_pmu.num_counters) - 1; 1503 perf_counter_mask = (1 << x86_pmu.num_counters) - 1;
1507 perf_max_counters = x86_pmu.num_counters; 1504 perf_max_counters = x86_pmu.num_counters;
1508 1505
1509 if (x86_pmu.num_counters_fixed > X86_PMC_MAX_FIXED) { 1506 if (x86_pmu.num_counters_fixed > X86_PMC_MAX_FIXED) {
1510 x86_pmu.num_counters_fixed = X86_PMC_MAX_FIXED;
1511 WARN(1, KERN_ERR "hw perf counters fixed %d > max(%d), clipping!", 1507 WARN(1, KERN_ERR "hw perf counters fixed %d > max(%d), clipping!",
1512 x86_pmu.num_counters_fixed, X86_PMC_MAX_FIXED); 1508 x86_pmu.num_counters_fixed, X86_PMC_MAX_FIXED);
1509 x86_pmu.num_counters_fixed = X86_PMC_MAX_FIXED;
1513 } 1510 }
1514 1511
1515 perf_counter_mask |= 1512 perf_counter_mask |=
1516 ((1LL << x86_pmu.num_counters_fixed)-1) << X86_PMC_IDX_FIXED; 1513 ((1LL << x86_pmu.num_counters_fixed)-1) << X86_PMC_IDX_FIXED;
1514 x86_pmu.intel_ctrl = perf_counter_mask;
1517 1515
1518 perf_counters_lapic_init(); 1516 perf_counters_lapic_init();
1519 register_die_notifier(&perf_counter_nmi_notifier); 1517 register_die_notifier(&perf_counter_nmi_notifier);
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index 95ea5fa7d444..c8405718a4c3 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -22,6 +22,7 @@
22#include "dumpstack.h" 22#include "dumpstack.h"
23 23
24int panic_on_unrecovered_nmi; 24int panic_on_unrecovered_nmi;
25int panic_on_io_nmi;
25unsigned int code_bytes = 64; 26unsigned int code_bytes = 64;
26int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; 27int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE;
27static int die_counter; 28static int die_counter;
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 7271fa33d791..c4ca89d9aaf4 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1383,6 +1383,8 @@ static unsigned long ram_alignment(resource_size_t pos)
1383 return 32*1024*1024; 1383 return 32*1024*1024;
1384} 1384}
1385 1385
1386#define MAX_RESOURCE_SIZE ((resource_size_t)-1)
1387
1386void __init e820_reserve_resources_late(void) 1388void __init e820_reserve_resources_late(void)
1387{ 1389{
1388 int i; 1390 int i;
@@ -1400,17 +1402,19 @@ void __init e820_reserve_resources_late(void)
1400 * avoid stolen RAM: 1402 * avoid stolen RAM:
1401 */ 1403 */
1402 for (i = 0; i < e820.nr_map; i++) { 1404 for (i = 0; i < e820.nr_map; i++) {
1403 struct e820entry *entry = &e820_saved.map[i]; 1405 struct e820entry *entry = &e820.map[i];
1404 resource_size_t start, end; 1406 u64 start, end;
1405 1407
1406 if (entry->type != E820_RAM) 1408 if (entry->type != E820_RAM)
1407 continue; 1409 continue;
1408 start = entry->addr + entry->size; 1410 start = entry->addr + entry->size;
1409 end = round_up(start, ram_alignment(start)); 1411 end = round_up(start, ram_alignment(start)) - 1;
1410 if (start == end) 1412 if (end > MAX_RESOURCE_SIZE)
1413 end = MAX_RESOURCE_SIZE;
1414 if (start >= end)
1411 continue; 1415 continue;
1412 reserve_region_with_split(&iomem_resource, start, 1416 reserve_region_with_split(&iomem_resource, start, end,
1413 end - 1, "RAM buffer"); 1417 "RAM buffer");
1414 } 1418 }
1415} 1419}
1416 1420
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 47630479b067..1a041bcf506b 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -211,11 +211,11 @@ static __init int iommu_setup(char *p)
211#ifdef CONFIG_SWIOTLB 211#ifdef CONFIG_SWIOTLB
212 if (!strncmp(p, "soft", 4)) 212 if (!strncmp(p, "soft", 4))
213 swiotlb = 1; 213 swiotlb = 1;
214#endif
214 if (!strncmp(p, "pt", 2)) { 215 if (!strncmp(p, "pt", 2)) {
215 iommu_pass_through = 1; 216 iommu_pass_through = 1;
216 return 1; 217 return 1;
217 } 218 }
218#endif
219 219
220 gart_parse_options(p); 220 gart_parse_options(p);
221 221
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index be5ae80f897f..de2cab132844 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -289,6 +289,20 @@ void * __init extend_brk(size_t size, size_t align)
289 return ret; 289 return ret;
290} 290}
291 291
292#ifdef CONFIG_X86_64
293static void __init init_gbpages(void)
294{
295 if (direct_gbpages && cpu_has_gbpages)
296 printk(KERN_INFO "Using GB pages for direct mapping\n");
297 else
298 direct_gbpages = 0;
299}
300#else
301static inline void init_gbpages(void)
302{
303}
304#endif
305
292static void __init reserve_brk(void) 306static void __init reserve_brk(void)
293{ 307{
294 if (_brk_end > _brk_start) 308 if (_brk_end > _brk_start)
@@ -871,6 +885,8 @@ void __init setup_arch(char **cmdline_p)
871 885
872 reserve_brk(); 886 reserve_brk();
873 887
888 init_gbpages();
889
874 /* max_pfn_mapped is updated here */ 890 /* max_pfn_mapped is updated here */
875 max_low_pfn_mapped = init_memory_mapping(0, max_low_pfn<<PAGE_SHIFT); 891 max_low_pfn_mapped = init_memory_mapping(0, max_low_pfn<<PAGE_SHIFT);
876 max_pfn_mapped = max_low_pfn_mapped; 892 max_pfn_mapped = max_low_pfn_mapped;
diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
index 9c3f0823e6aa..29a3eef7cf4a 100644
--- a/arch/x86/kernel/setup_percpu.c
+++ b/arch/x86/kernel/setup_percpu.c
@@ -124,7 +124,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
124} 124}
125 125
126/* 126/*
127 * Remap allocator 127 * Large page remap allocator
128 * 128 *
129 * This allocator uses PMD page as unit. A PMD page is allocated for 129 * This allocator uses PMD page as unit. A PMD page is allocated for
130 * each cpu and each is remapped into vmalloc area using PMD mapping. 130 * each cpu and each is remapped into vmalloc area using PMD mapping.
@@ -137,105 +137,185 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
137 * better than only using 4k mappings while still being NUMA friendly. 137 * better than only using 4k mappings while still being NUMA friendly.
138 */ 138 */
139#ifdef CONFIG_NEED_MULTIPLE_NODES 139#ifdef CONFIG_NEED_MULTIPLE_NODES
140static size_t pcpur_size __initdata; 140struct pcpul_ent {
141static void **pcpur_ptrs __initdata; 141 unsigned int cpu;
142 void *ptr;
143};
144
145static size_t pcpul_size;
146static struct pcpul_ent *pcpul_map;
147static struct vm_struct pcpul_vm;
142 148
143static struct page * __init pcpur_get_page(unsigned int cpu, int pageno) 149static struct page * __init pcpul_get_page(unsigned int cpu, int pageno)
144{ 150{
145 size_t off = (size_t)pageno << PAGE_SHIFT; 151 size_t off = (size_t)pageno << PAGE_SHIFT;
146 152
147 if (off >= pcpur_size) 153 if (off >= pcpul_size)
148 return NULL; 154 return NULL;
149 155
150 return virt_to_page(pcpur_ptrs[cpu] + off); 156 return virt_to_page(pcpul_map[cpu].ptr + off);
151} 157}
152 158
153static ssize_t __init setup_pcpu_remap(size_t static_size) 159static ssize_t __init setup_pcpu_lpage(size_t static_size, bool chosen)
154{ 160{
155 static struct vm_struct vm; 161 size_t map_size, dyn_size;
156 size_t ptrs_size, dyn_size;
157 unsigned int cpu; 162 unsigned int cpu;
163 int i, j;
158 ssize_t ret; 164 ssize_t ret;
159 165
160 /* 166 if (!chosen) {
161 * If large page isn't supported, there's no benefit in doing 167 size_t vm_size = VMALLOC_END - VMALLOC_START;
162 * this. Also, on non-NUMA, embedding is better. 168 size_t tot_size = num_possible_cpus() * PMD_SIZE;
163 * 169
164 * NOTE: disabled for now. 170 /* on non-NUMA, embedding is better */
165 */ 171 if (!pcpu_need_numa())
166 if (true || !cpu_has_pse || !pcpu_need_numa()) 172 return -EINVAL;
173
174 /* don't consume more than 20% of vmalloc area */
175 if (tot_size > vm_size / 5) {
176 pr_info("PERCPU: too large chunk size %zuMB for "
177 "large page remap\n", tot_size >> 20);
178 return -EINVAL;
179 }
180 }
181
182 /* need PSE */
183 if (!cpu_has_pse) {
184 pr_warning("PERCPU: lpage allocator requires PSE\n");
167 return -EINVAL; 185 return -EINVAL;
186 }
168 187
169 /* 188 /*
170 * Currently supports only single page. Supporting multiple 189 * Currently supports only single page. Supporting multiple
171 * pages won't be too difficult if it ever becomes necessary. 190 * pages won't be too difficult if it ever becomes necessary.
172 */ 191 */
173 pcpur_size = PFN_ALIGN(static_size + PERCPU_MODULE_RESERVE + 192 pcpul_size = PFN_ALIGN(static_size + PERCPU_MODULE_RESERVE +
174 PERCPU_DYNAMIC_RESERVE); 193 PERCPU_DYNAMIC_RESERVE);
175 if (pcpur_size > PMD_SIZE) { 194 if (pcpul_size > PMD_SIZE) {
176 pr_warning("PERCPU: static data is larger than large page, " 195 pr_warning("PERCPU: static data is larger than large page, "
177 "can't use large page\n"); 196 "can't use large page\n");
178 return -EINVAL; 197 return -EINVAL;
179 } 198 }
180 dyn_size = pcpur_size - static_size - PERCPU_FIRST_CHUNK_RESERVE; 199 dyn_size = pcpul_size - static_size - PERCPU_FIRST_CHUNK_RESERVE;
181 200
182 /* allocate pointer array and alloc large pages */ 201 /* allocate pointer array and alloc large pages */
183 ptrs_size = PFN_ALIGN(num_possible_cpus() * sizeof(pcpur_ptrs[0])); 202 map_size = PFN_ALIGN(num_possible_cpus() * sizeof(pcpul_map[0]));
184 pcpur_ptrs = alloc_bootmem(ptrs_size); 203 pcpul_map = alloc_bootmem(map_size);
185 204
186 for_each_possible_cpu(cpu) { 205 for_each_possible_cpu(cpu) {
187 pcpur_ptrs[cpu] = pcpu_alloc_bootmem(cpu, PMD_SIZE, PMD_SIZE); 206 pcpul_map[cpu].cpu = cpu;
188 if (!pcpur_ptrs[cpu]) 207 pcpul_map[cpu].ptr = pcpu_alloc_bootmem(cpu, PMD_SIZE,
208 PMD_SIZE);
209 if (!pcpul_map[cpu].ptr) {
210 pr_warning("PERCPU: failed to allocate large page "
211 "for cpu%u\n", cpu);
189 goto enomem; 212 goto enomem;
213 }
190 214
191 /* 215 /*
192 * Only use pcpur_size bytes and give back the rest. 216 * Only use pcpul_size bytes and give back the rest.
193 * 217 *
194 * Ingo: The 2MB up-rounding bootmem is needed to make 218 * Ingo: The 2MB up-rounding bootmem is needed to make
195 * sure the partial 2MB page is still fully RAM - it's 219 * sure the partial 2MB page is still fully RAM - it's
196 * not well-specified to have a PAT-incompatible area 220 * not well-specified to have a PAT-incompatible area
197 * (unmapped RAM, device memory, etc.) in that hole. 221 * (unmapped RAM, device memory, etc.) in that hole.
198 */ 222 */
199 free_bootmem(__pa(pcpur_ptrs[cpu] + pcpur_size), 223 free_bootmem(__pa(pcpul_map[cpu].ptr + pcpul_size),
200 PMD_SIZE - pcpur_size); 224 PMD_SIZE - pcpul_size);
201 225
202 memcpy(pcpur_ptrs[cpu], __per_cpu_load, static_size); 226 memcpy(pcpul_map[cpu].ptr, __per_cpu_load, static_size);
203 } 227 }
204 228
205 /* allocate address and map */ 229 /* allocate address and map */
206 vm.flags = VM_ALLOC; 230 pcpul_vm.flags = VM_ALLOC;
207 vm.size = num_possible_cpus() * PMD_SIZE; 231 pcpul_vm.size = num_possible_cpus() * PMD_SIZE;
208 vm_area_register_early(&vm, PMD_SIZE); 232 vm_area_register_early(&pcpul_vm, PMD_SIZE);
209 233
210 for_each_possible_cpu(cpu) { 234 for_each_possible_cpu(cpu) {
211 pmd_t *pmd; 235 pmd_t *pmd, pmd_v;
212 236
213 pmd = populate_extra_pmd((unsigned long)vm.addr 237 pmd = populate_extra_pmd((unsigned long)pcpul_vm.addr +
214 + cpu * PMD_SIZE); 238 cpu * PMD_SIZE);
215 set_pmd(pmd, pfn_pmd(page_to_pfn(virt_to_page(pcpur_ptrs[cpu])), 239 pmd_v = pfn_pmd(page_to_pfn(virt_to_page(pcpul_map[cpu].ptr)),
216 PAGE_KERNEL_LARGE)); 240 PAGE_KERNEL_LARGE);
241 set_pmd(pmd, pmd_v);
217 } 242 }
218 243
219 /* we're ready, commit */ 244 /* we're ready, commit */
220 pr_info("PERCPU: Remapped at %p with large pages, static data " 245 pr_info("PERCPU: Remapped at %p with large pages, static data "
221 "%zu bytes\n", vm.addr, static_size); 246 "%zu bytes\n", pcpul_vm.addr, static_size);
222 247
223 ret = pcpu_setup_first_chunk(pcpur_get_page, static_size, 248 ret = pcpu_setup_first_chunk(pcpul_get_page, static_size,
224 PERCPU_FIRST_CHUNK_RESERVE, dyn_size, 249 PERCPU_FIRST_CHUNK_RESERVE, dyn_size,
225 PMD_SIZE, vm.addr, NULL); 250 PMD_SIZE, pcpul_vm.addr, NULL);
226 goto out_free_ar; 251
252 /* sort pcpul_map array for pcpu_lpage_remapped() */
253 for (i = 0; i < num_possible_cpus() - 1; i++)
254 for (j = i + 1; j < num_possible_cpus(); j++)
255 if (pcpul_map[i].ptr > pcpul_map[j].ptr) {
256 struct pcpul_ent tmp = pcpul_map[i];
257 pcpul_map[i] = pcpul_map[j];
258 pcpul_map[j] = tmp;
259 }
260
261 return ret;
227 262
228enomem: 263enomem:
229 for_each_possible_cpu(cpu) 264 for_each_possible_cpu(cpu)
230 if (pcpur_ptrs[cpu]) 265 if (pcpul_map[cpu].ptr)
231 free_bootmem(__pa(pcpur_ptrs[cpu]), PMD_SIZE); 266 free_bootmem(__pa(pcpul_map[cpu].ptr), pcpul_size);
232 ret = -ENOMEM; 267 free_bootmem(__pa(pcpul_map), map_size);
233out_free_ar: 268 return -ENOMEM;
234 free_bootmem(__pa(pcpur_ptrs), ptrs_size); 269}
235 return ret; 270
271/**
272 * pcpu_lpage_remapped - determine whether a kaddr is in pcpul recycled area
273 * @kaddr: the kernel address in question
274 *
275 * Determine whether @kaddr falls in the pcpul recycled area. This is
276 * used by pageattr to detect VM aliases and break up the pcpu PMD
277 * mapping such that the same physical page is not mapped under
278 * different attributes.
279 *
280 * The recycled area is always at the tail of a partially used PMD
281 * page.
282 *
283 * RETURNS:
284 * Address of corresponding remapped pcpu address if match is found;
285 * otherwise, NULL.
286 */
287void *pcpu_lpage_remapped(void *kaddr)
288{
289 void *pmd_addr = (void *)((unsigned long)kaddr & PMD_MASK);
290 unsigned long offset = (unsigned long)kaddr & ~PMD_MASK;
291 int left = 0, right = num_possible_cpus() - 1;
292 int pos;
293
294 /* pcpul in use at all? */
295 if (!pcpul_map)
296 return NULL;
297
298 /* okay, perform binary search */
299 while (left <= right) {
300 pos = (left + right) / 2;
301
302 if (pcpul_map[pos].ptr < pmd_addr)
303 left = pos + 1;
304 else if (pcpul_map[pos].ptr > pmd_addr)
305 right = pos - 1;
306 else {
307 /* it shouldn't be in the area for the first chunk */
308 WARN_ON(offset < pcpul_size);
309
310 return pcpul_vm.addr +
311 pcpul_map[pos].cpu * PMD_SIZE + offset;
312 }
313 }
314
315 return NULL;
236} 316}
237#else 317#else
238static ssize_t __init setup_pcpu_remap(size_t static_size) 318static ssize_t __init setup_pcpu_lpage(size_t static_size, bool chosen)
239{ 319{
240 return -EINVAL; 320 return -EINVAL;
241} 321}
@@ -249,7 +329,7 @@ static ssize_t __init setup_pcpu_remap(size_t static_size)
249 * mapping so that it can use PMD mapping without additional TLB 329 * mapping so that it can use PMD mapping without additional TLB
250 * pressure. 330 * pressure.
251 */ 331 */
252static ssize_t __init setup_pcpu_embed(size_t static_size) 332static ssize_t __init setup_pcpu_embed(size_t static_size, bool chosen)
253{ 333{
254 size_t reserve = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE; 334 size_t reserve = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE;
255 335
@@ -258,7 +338,7 @@ static ssize_t __init setup_pcpu_embed(size_t static_size)
258 * this. Also, embedding allocation doesn't play well with 338 * this. Also, embedding allocation doesn't play well with
259 * NUMA. 339 * NUMA.
260 */ 340 */
261 if (!cpu_has_pse || pcpu_need_numa()) 341 if (!chosen && (!cpu_has_pse || pcpu_need_numa()))
262 return -EINVAL; 342 return -EINVAL;
263 343
264 return pcpu_embed_first_chunk(static_size, PERCPU_FIRST_CHUNK_RESERVE, 344 return pcpu_embed_first_chunk(static_size, PERCPU_FIRST_CHUNK_RESERVE,
@@ -308,8 +388,11 @@ static ssize_t __init setup_pcpu_4k(size_t static_size)
308 void *ptr; 388 void *ptr;
309 389
310 ptr = pcpu_alloc_bootmem(cpu, PAGE_SIZE, PAGE_SIZE); 390 ptr = pcpu_alloc_bootmem(cpu, PAGE_SIZE, PAGE_SIZE);
311 if (!ptr) 391 if (!ptr) {
392 pr_warning("PERCPU: failed to allocate "
393 "4k page for cpu%u\n", cpu);
312 goto enomem; 394 goto enomem;
395 }
313 396
314 memcpy(ptr, __per_cpu_load + i * PAGE_SIZE, PAGE_SIZE); 397 memcpy(ptr, __per_cpu_load + i * PAGE_SIZE, PAGE_SIZE);
315 pcpu4k_pages[j++] = virt_to_page(ptr); 398 pcpu4k_pages[j++] = virt_to_page(ptr);
@@ -333,6 +416,16 @@ out_free_ar:
333 return ret; 416 return ret;
334} 417}
335 418
419/* for explicit first chunk allocator selection */
420static char pcpu_chosen_alloc[16] __initdata;
421
422static int __init percpu_alloc_setup(char *str)
423{
424 strncpy(pcpu_chosen_alloc, str, sizeof(pcpu_chosen_alloc) - 1);
425 return 0;
426}
427early_param("percpu_alloc", percpu_alloc_setup);
428
336static inline void setup_percpu_segment(int cpu) 429static inline void setup_percpu_segment(int cpu)
337{ 430{
338#ifdef CONFIG_X86_32 431#ifdef CONFIG_X86_32
@@ -346,11 +439,6 @@ static inline void setup_percpu_segment(int cpu)
346#endif 439#endif
347} 440}
348 441
349/*
350 * Great future plan:
351 * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
352 * Always point %gs to its beginning
353 */
354void __init setup_per_cpu_areas(void) 442void __init setup_per_cpu_areas(void)
355{ 443{
356 size_t static_size = __per_cpu_end - __per_cpu_start; 444 size_t static_size = __per_cpu_end - __per_cpu_start;
@@ -367,9 +455,26 @@ void __init setup_per_cpu_areas(void)
367 * of large page mappings. Please read comments on top of 455 * of large page mappings. Please read comments on top of
368 * each allocator for details. 456 * each allocator for details.
369 */ 457 */
370 ret = setup_pcpu_remap(static_size); 458 ret = -EINVAL;
371 if (ret < 0) 459 if (strlen(pcpu_chosen_alloc)) {
372 ret = setup_pcpu_embed(static_size); 460 if (strcmp(pcpu_chosen_alloc, "4k")) {
461 if (!strcmp(pcpu_chosen_alloc, "lpage"))
462 ret = setup_pcpu_lpage(static_size, true);
463 else if (!strcmp(pcpu_chosen_alloc, "embed"))
464 ret = setup_pcpu_embed(static_size, true);
465 else
466 pr_warning("PERCPU: unknown allocator %s "
467 "specified\n", pcpu_chosen_alloc);
468 if (ret < 0)
469 pr_warning("PERCPU: %s allocator failed (%zd), "
470 "falling back to 4k\n",
471 pcpu_chosen_alloc, ret);
472 }
473 } else {
474 ret = setup_pcpu_lpage(static_size, false);
475 if (ret < 0)
476 ret = setup_pcpu_embed(static_size, false);
477 }
373 if (ret < 0) 478 if (ret < 0)
374 ret = setup_pcpu_4k(static_size); 479 ret = setup_pcpu_4k(static_size);
375 if (ret < 0) 480 if (ret < 0)
diff --git a/arch/x86/kernel/tlb_uv.c b/arch/x86/kernel/tlb_uv.c
index 124d40c575df..8ccabb8a2f6a 100644
--- a/arch/x86/kernel/tlb_uv.c
+++ b/arch/x86/kernel/tlb_uv.c
@@ -711,7 +711,6 @@ uv_activation_descriptor_init(int node, int pnode)
711 unsigned long pa; 711 unsigned long pa;
712 unsigned long m; 712 unsigned long m;
713 unsigned long n; 713 unsigned long n;
714 unsigned long mmr_image;
715 struct bau_desc *adp; 714 struct bau_desc *adp;
716 struct bau_desc *ad2; 715 struct bau_desc *ad2;
717 716
@@ -727,12 +726,8 @@ uv_activation_descriptor_init(int node, int pnode)
727 n = pa >> uv_nshift; 726 n = pa >> uv_nshift;
728 m = pa & uv_mmask; 727 m = pa & uv_mmask;
729 728
730 mmr_image = uv_read_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE); 729 uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE,
731 if (mmr_image) { 730 (n << UV_DESC_BASE_PNODE_SHIFT | m));
732 uv_write_global_mmr64(pnode, (unsigned long)
733 UVH_LB_BAU_SB_DESCRIPTOR_BASE,
734 (n << UV_DESC_BASE_PNODE_SHIFT | m));
735 }
736 731
737 /* 732 /*
738 * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each 733 * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index a0f48f5671c0..5204332f475d 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -346,6 +346,9 @@ io_check_error(unsigned char reason, struct pt_regs *regs)
346 printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n"); 346 printk(KERN_EMERG "NMI: IOCK error (debug interrupt?)\n");
347 show_registers(regs); 347 show_registers(regs);
348 348
349 if (panic_on_io_nmi)
350 panic("NMI IOCK error: Not continuing");
351
349 /* Re-enable the IOCK line, wait for a few seconds */ 352 /* Re-enable the IOCK line, wait for a few seconds */
350 reason = (reason & 0xf) | 8; 353 reason = (reason & 0xf) | 8;
351 outb(reason, 0x61); 354 outb(reason, 0x61);
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 5c3d6e81a7dc..7030b5f911bf 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2157,7 +2157,7 @@ static void reset_rsvds_bits_mask(struct kvm_vcpu *vcpu, int level)
2157 else 2157 else
2158 /* 32 bits PSE 4MB page */ 2158 /* 32 bits PSE 4MB page */
2159 context->rsvd_bits_mask[1][1] = rsvd_bits(13, 21); 2159 context->rsvd_bits_mask[1][1] = rsvd_bits(13, 21);
2160 context->rsvd_bits_mask[1][0] = ~0ull; 2160 context->rsvd_bits_mask[1][0] = context->rsvd_bits_mask[1][0];
2161 break; 2161 break;
2162 case PT32E_ROOT_LEVEL: 2162 case PT32E_ROOT_LEVEL:
2163 context->rsvd_bits_mask[0][2] = 2163 context->rsvd_bits_mask[0][2] =
@@ -2170,7 +2170,7 @@ static void reset_rsvds_bits_mask(struct kvm_vcpu *vcpu, int level)
2170 context->rsvd_bits_mask[1][1] = exb_bit_rsvd | 2170 context->rsvd_bits_mask[1][1] = exb_bit_rsvd |
2171 rsvd_bits(maxphyaddr, 62) | 2171 rsvd_bits(maxphyaddr, 62) |
2172 rsvd_bits(13, 20); /* large page */ 2172 rsvd_bits(13, 20); /* large page */
2173 context->rsvd_bits_mask[1][0] = ~0ull; 2173 context->rsvd_bits_mask[1][0] = context->rsvd_bits_mask[1][0];
2174 break; 2174 break;
2175 case PT64_ROOT_LEVEL: 2175 case PT64_ROOT_LEVEL:
2176 context->rsvd_bits_mask[0][3] = exb_bit_rsvd | 2176 context->rsvd_bits_mask[0][3] = exb_bit_rsvd |
@@ -2186,7 +2186,7 @@ static void reset_rsvds_bits_mask(struct kvm_vcpu *vcpu, int level)
2186 context->rsvd_bits_mask[1][1] = exb_bit_rsvd | 2186 context->rsvd_bits_mask[1][1] = exb_bit_rsvd |
2187 rsvd_bits(maxphyaddr, 51) | 2187 rsvd_bits(maxphyaddr, 51) |
2188 rsvd_bits(13, 20); /* large page */ 2188 rsvd_bits(13, 20); /* large page */
2189 context->rsvd_bits_mask[1][0] = ~0ull; 2189 context->rsvd_bits_mask[1][0] = context->rsvd_bits_mask[1][0];
2190 break; 2190 break;
2191 } 2191 }
2192} 2192}
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index 258e4591e1ca..67785f635399 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -281,7 +281,7 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
281{ 281{
282 unsigned access = gw->pt_access; 282 unsigned access = gw->pt_access;
283 struct kvm_mmu_page *shadow_page; 283 struct kvm_mmu_page *shadow_page;
284 u64 spte, *sptep; 284 u64 spte, *sptep = NULL;
285 int direct; 285 int direct;
286 gfn_t table_gfn; 286 gfn_t table_gfn;
287 int r; 287 int r;
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index e770bf349ec4..356a0ce85c68 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3012,6 +3012,12 @@ static int handle_vmcall(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3012 return 1; 3012 return 1;
3013} 3013}
3014 3014
3015static int handle_vmx_insn(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3016{
3017 kvm_queue_exception(vcpu, UD_VECTOR);
3018 return 1;
3019}
3020
3015static int handle_invlpg(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 3021static int handle_invlpg(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3016{ 3022{
3017 unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION); 3023 unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
@@ -3198,6 +3204,15 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu,
3198 [EXIT_REASON_HLT] = handle_halt, 3204 [EXIT_REASON_HLT] = handle_halt,
3199 [EXIT_REASON_INVLPG] = handle_invlpg, 3205 [EXIT_REASON_INVLPG] = handle_invlpg,
3200 [EXIT_REASON_VMCALL] = handle_vmcall, 3206 [EXIT_REASON_VMCALL] = handle_vmcall,
3207 [EXIT_REASON_VMCLEAR] = handle_vmx_insn,
3208 [EXIT_REASON_VMLAUNCH] = handle_vmx_insn,
3209 [EXIT_REASON_VMPTRLD] = handle_vmx_insn,
3210 [EXIT_REASON_VMPTRST] = handle_vmx_insn,
3211 [EXIT_REASON_VMREAD] = handle_vmx_insn,
3212 [EXIT_REASON_VMRESUME] = handle_vmx_insn,
3213 [EXIT_REASON_VMWRITE] = handle_vmx_insn,
3214 [EXIT_REASON_VMOFF] = handle_vmx_insn,
3215 [EXIT_REASON_VMON] = handle_vmx_insn,
3201 [EXIT_REASON_TPR_BELOW_THRESHOLD] = handle_tpr_below_threshold, 3216 [EXIT_REASON_TPR_BELOW_THRESHOLD] = handle_tpr_below_threshold,
3202 [EXIT_REASON_APIC_ACCESS] = handle_apic_access, 3217 [EXIT_REASON_APIC_ACCESS] = handle_apic_access,
3203 [EXIT_REASON_WBINVD] = handle_wbinvd, 3218 [EXIT_REASON_WBINVD] = handle_wbinvd,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 249540f98513..fe5474aec41a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -898,6 +898,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
898 case MSR_VM_HSAVE_PA: 898 case MSR_VM_HSAVE_PA:
899 case MSR_P6_EVNTSEL0: 899 case MSR_P6_EVNTSEL0:
900 case MSR_P6_EVNTSEL1: 900 case MSR_P6_EVNTSEL1:
901 case MSR_K7_EVNTSEL0:
901 data = 0; 902 data = 0;
902 break; 903 break;
903 case MSR_MTRRcap: 904 case MSR_MTRRcap:
diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index c1b6c232e02b..616de4628d60 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -1361,7 +1361,7 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
1361 return 0; 1361 return 0;
1362} 1362}
1363 1363
1364void toggle_interruptibility(struct x86_emulate_ctxt *ctxt, u32 mask) 1364static void toggle_interruptibility(struct x86_emulate_ctxt *ctxt, u32 mask)
1365{ 1365{
1366 u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(ctxt->vcpu, mask); 1366 u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(ctxt->vcpu, mask);
1367 /* 1367 /*
diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
index f4568605d7d5..ff485d361182 100644
--- a/arch/x86/lib/delay.c
+++ b/arch/x86/lib/delay.c
@@ -55,8 +55,10 @@ static void delay_tsc(unsigned long loops)
55 55
56 preempt_disable(); 56 preempt_disable();
57 cpu = smp_processor_id(); 57 cpu = smp_processor_id();
58 rdtsc_barrier();
58 rdtscl(bclock); 59 rdtscl(bclock);
59 for (;;) { 60 for (;;) {
61 rdtsc_barrier();
60 rdtscl(now); 62 rdtscl(now);
61 if ((now - bclock) >= loops) 63 if ((now - bclock) >= loops)
62 break; 64 break;
@@ -78,6 +80,7 @@ static void delay_tsc(unsigned long loops)
78 if (unlikely(cpu != smp_processor_id())) { 80 if (unlikely(cpu != smp_processor_id())) {
79 loops -= (now - bclock); 81 loops -= (now - bclock);
80 cpu = smp_processor_id(); 82 cpu = smp_processor_id();
83 rdtsc_barrier();
81 rdtscl(bclock); 84 rdtscl(bclock);
82 } 85 }
83 } 86 }
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index f53b57e4086f..47ce9a2ce5e7 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -177,20 +177,6 @@ static int __meminit save_mr(struct map_range *mr, int nr_range,
177 return nr_range; 177 return nr_range;
178} 178}
179 179
180#ifdef CONFIG_X86_64
181static void __init init_gbpages(void)
182{
183 if (direct_gbpages && cpu_has_gbpages)
184 printk(KERN_INFO "Using GB pages for direct mapping\n");
185 else
186 direct_gbpages = 0;
187}
188#else
189static inline void init_gbpages(void)
190{
191}
192#endif
193
194/* 180/*
195 * Setup the direct mapping of the physical memory at PAGE_OFFSET. 181 * Setup the direct mapping of the physical memory at PAGE_OFFSET.
196 * This runs before bootmem is initialized and gets pages directly from 182 * This runs before bootmem is initialized and gets pages directly from
@@ -210,9 +196,6 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
210 196
211 printk(KERN_INFO "init_memory_mapping: %016lx-%016lx\n", start, end); 197 printk(KERN_INFO "init_memory_mapping: %016lx-%016lx\n", start, end);
212 198
213 if (!after_bootmem)
214 init_gbpages();
215
216#if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK) 199#if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
217 /* 200 /*
218 * For CONFIG_DEBUG_PAGEALLOC, identity mapping will use small pages. 201 * For CONFIG_DEBUG_PAGEALLOC, identity mapping will use small pages.
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index c4378f4fd4a5..b177652251a4 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -598,6 +598,8 @@ void __init paging_init(void)
598 598
599 sparse_memory_present_with_active_regions(MAX_NUMNODES); 599 sparse_memory_present_with_active_regions(MAX_NUMNODES);
600 sparse_init(); 600 sparse_init();
601 /* clear the default setting with node 0 */
602 nodes_clear(node_states[N_NORMAL_MEMORY]);
601 free_area_init_nodes(max_zone_pfns); 603 free_area_init_nodes(max_zone_pfns);
602} 604}
603 605
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 3cfe9ced8a4c..1b734d7a8966 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -11,6 +11,7 @@
11#include <linux/interrupt.h> 11#include <linux/interrupt.h>
12#include <linux/seq_file.h> 12#include <linux/seq_file.h>
13#include <linux/debugfs.h> 13#include <linux/debugfs.h>
14#include <linux/pfn.h>
14 15
15#include <asm/e820.h> 16#include <asm/e820.h>
16#include <asm/processor.h> 17#include <asm/processor.h>
@@ -681,8 +682,9 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias);
681static int cpa_process_alias(struct cpa_data *cpa) 682static int cpa_process_alias(struct cpa_data *cpa)
682{ 683{
683 struct cpa_data alias_cpa; 684 struct cpa_data alias_cpa;
684 int ret = 0; 685 unsigned long laddr = (unsigned long)__va(cpa->pfn << PAGE_SHIFT);
685 unsigned long temp_cpa_vaddr, vaddr; 686 unsigned long vaddr, remapped;
687 int ret;
686 688
687 if (cpa->pfn >= max_pfn_mapped) 689 if (cpa->pfn >= max_pfn_mapped)
688 return 0; 690 return 0;
@@ -706,42 +708,55 @@ static int cpa_process_alias(struct cpa_data *cpa)
706 PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT)))) { 708 PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT)))) {
707 709
708 alias_cpa = *cpa; 710 alias_cpa = *cpa;
709 temp_cpa_vaddr = (unsigned long) __va(cpa->pfn << PAGE_SHIFT); 711 alias_cpa.vaddr = &laddr;
710 alias_cpa.vaddr = &temp_cpa_vaddr;
711 alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY); 712 alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY);
712 713
713
714 ret = __change_page_attr_set_clr(&alias_cpa, 0); 714 ret = __change_page_attr_set_clr(&alias_cpa, 0);
715 if (ret)
716 return ret;
715 } 717 }
716 718
717#ifdef CONFIG_X86_64 719#ifdef CONFIG_X86_64
718 if (ret)
719 return ret;
720 /* 720 /*
721 * No need to redo, when the primary call touched the high 721 * If the primary call didn't touch the high mapping already
722 * mapping already: 722 * and the physical address is inside the kernel map, we need
723 */
724 if (within(vaddr, (unsigned long) _text, _brk_end))
725 return 0;
726
727 /*
728 * If the physical address is inside the kernel map, we need
729 * to touch the high mapped kernel as well: 723 * to touch the high mapped kernel as well:
730 */ 724 */
731 if (!within(cpa->pfn, highmap_start_pfn(), highmap_end_pfn())) 725 if (!within(vaddr, (unsigned long)_text, _brk_end) &&
732 return 0; 726 within(cpa->pfn, highmap_start_pfn(), highmap_end_pfn())) {
727 unsigned long temp_cpa_vaddr = (cpa->pfn << PAGE_SHIFT) +
728 __START_KERNEL_map - phys_base;
729 alias_cpa = *cpa;
730 alias_cpa.vaddr = &temp_cpa_vaddr;
731 alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY);
733 732
734 alias_cpa = *cpa; 733 /*
735 temp_cpa_vaddr = (cpa->pfn << PAGE_SHIFT) + __START_KERNEL_map - phys_base; 734 * The high mapping range is imprecise, so ignore the
736 alias_cpa.vaddr = &temp_cpa_vaddr; 735 * return value.
737 alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY); 736 */
737 __change_page_attr_set_clr(&alias_cpa, 0);
738 }
739#endif
738 740
739 /* 741 /*
740 * The high mapping range is imprecise, so ignore the return value. 742 * If the PMD page was partially used for per-cpu remapping,
743 * the recycled area needs to be split and modified. Because
744 * the area is always proper subset of a PMD page
745 * cpa->numpages is guaranteed to be 1 for these areas, so
746 * there's no need to loop over and check for further remaps.
741 */ 747 */
742 __change_page_attr_set_clr(&alias_cpa, 0); 748 remapped = (unsigned long)pcpu_lpage_remapped((void *)laddr);
743#endif 749 if (remapped) {
744 return ret; 750 WARN_ON(cpa->numpages > 1);
751 alias_cpa = *cpa;
752 alias_cpa.vaddr = &remapped;
753 alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY);
754 ret = __change_page_attr_set_clr(&alias_cpa, 0);
755 if (ret)
756 return ret;
757 }
758
759 return 0;
745} 760}
746 761
747static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias) 762static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
index d277ef1eea51..b3d20b9cac63 100644
--- a/arch/x86/power/cpu.c
+++ b/arch/x86/power/cpu.c
@@ -244,7 +244,7 @@ static void __restore_processor_state(struct saved_context *ctxt)
244 do_fpu_end(); 244 do_fpu_end();
245 mtrr_ap_init(); 245 mtrr_ap_init();
246 246
247#ifdef CONFIG_X86_32 247#ifdef CONFIG_X86_OLD_MCE
248 mcheck_init(&boot_cpu_data); 248 mcheck_init(&boot_cpu_data);
249#endif 249#endif
250} 250}
diff --git a/arch/xtensa/platforms/iss/network.c b/arch/xtensa/platforms/iss/network.c
index edad4156d89a..2f0b86b37cf9 100644
--- a/arch/xtensa/platforms/iss/network.c
+++ b/arch/xtensa/platforms/iss/network.c
@@ -545,7 +545,7 @@ static int iss_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
545 spin_unlock_irqrestore(&lp->lock, flags); 545 spin_unlock_irqrestore(&lp->lock, flags);
546 546
547 dev_kfree_skb(skb); 547 dev_kfree_skb(skb);
548 return 0; 548 return NETDEV_TX_OK;
549} 549}
550 550
551 551
diff --git a/block/Makefile b/block/Makefile
index e9fa4dd690f2..6c54ed0ff755 100644
--- a/block/Makefile
+++ b/block/Makefile
@@ -5,7 +5,7 @@
5obj-$(CONFIG_BLOCK) := elevator.o blk-core.o blk-tag.o blk-sysfs.o \ 5obj-$(CONFIG_BLOCK) := elevator.o blk-core.o blk-tag.o blk-sysfs.o \
6 blk-barrier.o blk-settings.o blk-ioc.o blk-map.o \ 6 blk-barrier.o blk-settings.o blk-ioc.o blk-map.o \
7 blk-exec.o blk-merge.o blk-softirq.o blk-timeout.o \ 7 blk-exec.o blk-merge.o blk-softirq.o blk-timeout.o \
8 ioctl.o genhd.o scsi_ioctl.o cmd-filter.o 8 ioctl.o genhd.o scsi_ioctl.o
9 9
10obj-$(CONFIG_BLK_DEV_BSG) += bsg.o 10obj-$(CONFIG_BLK_DEV_BSG) += bsg.o
11obj-$(CONFIG_IOSCHED_NOOP) += noop-iosched.o 11obj-$(CONFIG_IOSCHED_NOOP) += noop-iosched.o
diff --git a/block/blk-core.c b/block/blk-core.c
index b06cf5c2a829..4b45435c6eaf 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -595,8 +595,6 @@ blk_init_queue_node(request_fn_proc *rfn, spinlock_t *lock, int node_id)
595 595
596 q->sg_reserved_size = INT_MAX; 596 q->sg_reserved_size = INT_MAX;
597 597
598 blk_set_cmd_filter_defaults(&q->cmd_filter);
599
600 /* 598 /*
601 * all done 599 * all done
602 */ 600 */
@@ -1172,6 +1170,11 @@ static int __make_request(struct request_queue *q, struct bio *bio)
1172 const int unplug = bio_unplug(bio); 1170 const int unplug = bio_unplug(bio);
1173 int rw_flags; 1171 int rw_flags;
1174 1172
1173 if (bio_barrier(bio) && bio_has_data(bio) &&
1174 (q->next_ordered == QUEUE_ORDERED_NONE)) {
1175 bio_endio(bio, -EOPNOTSUPP);
1176 return 0;
1177 }
1175 /* 1178 /*
1176 * low level driver can indicate that it wants pages above a 1179 * low level driver can indicate that it wants pages above a
1177 * certain limit bounced to low memory (ie for highmem, or even 1180 * certain limit bounced to low memory (ie for highmem, or even
@@ -1472,11 +1475,6 @@ static inline void __generic_make_request(struct bio *bio)
1472 err = -EOPNOTSUPP; 1475 err = -EOPNOTSUPP;
1473 goto end_io; 1476 goto end_io;
1474 } 1477 }
1475 if (bio_barrier(bio) && bio_has_data(bio) &&
1476 (q->next_ordered == QUEUE_ORDERED_NONE)) {
1477 err = -EOPNOTSUPP;
1478 goto end_io;
1479 }
1480 1478
1481 ret = q->make_request_fn(q, bio); 1479 ret = q->make_request_fn(q, bio);
1482 } while (ret); 1480 } while (ret);
@@ -2365,7 +2363,7 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
2365 __bio_clone(bio, bio_src); 2363 __bio_clone(bio, bio_src);
2366 2364
2367 if (bio_integrity(bio_src) && 2365 if (bio_integrity(bio_src) &&
2368 bio_integrity_clone(bio, bio_src, gfp_mask)) 2366 bio_integrity_clone(bio, bio_src, gfp_mask, bs))
2369 goto free_and_out; 2367 goto free_and_out;
2370 2368
2371 if (bio_ctr && bio_ctr(bio, bio_src, data)) 2369 if (bio_ctr && bio_ctr(bio, bio_src, data))
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 39ce64432ba6..e1999679a4d5 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -350,6 +350,12 @@ static int attempt_merge(struct request_queue *q, struct request *req,
350 if (blk_integrity_rq(req) != blk_integrity_rq(next)) 350 if (blk_integrity_rq(req) != blk_integrity_rq(next))
351 return 0; 351 return 0;
352 352
353 /* don't merge requests of different failfast settings */
354 if (blk_failfast_dev(req) != blk_failfast_dev(next) ||
355 blk_failfast_transport(req) != blk_failfast_transport(next) ||
356 blk_failfast_driver(req) != blk_failfast_driver(next))
357 return 0;
358
353 /* 359 /*
354 * If we are allowed to merge, then append bio list 360 * If we are allowed to merge, then append bio list
355 * from next to rq and release next. merge_requests_fn 361 * from next to rq and release next. merge_requests_fn
diff --git a/block/bsg.c b/block/bsg.c
index e7d475254248..5f184bb3ff9e 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -186,7 +186,7 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
186 return -EFAULT; 186 return -EFAULT;
187 187
188 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) { 188 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
189 if (blk_verify_command(&q->cmd_filter, rq->cmd, has_write_perm)) 189 if (blk_verify_command(rq->cmd, has_write_perm))
190 return -EPERM; 190 return -EPERM;
191 } else if (!capable(CAP_SYS_RAWIO)) 191 } else if (!capable(CAP_SYS_RAWIO))
192 return -EPERM; 192 return -EPERM;
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 833ec18eaa63..87276eb83f7f 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -71,6 +71,51 @@ struct cfq_rb_root {
71#define CFQ_RB_ROOT (struct cfq_rb_root) { RB_ROOT, NULL, } 71#define CFQ_RB_ROOT (struct cfq_rb_root) { RB_ROOT, NULL, }
72 72
73/* 73/*
74 * Per process-grouping structure
75 */
76struct cfq_queue {
77 /* reference count */
78 atomic_t ref;
79 /* various state flags, see below */
80 unsigned int flags;
81 /* parent cfq_data */
82 struct cfq_data *cfqd;
83 /* service_tree member */
84 struct rb_node rb_node;
85 /* service_tree key */
86 unsigned long rb_key;
87 /* prio tree member */
88 struct rb_node p_node;
89 /* prio tree root we belong to, if any */
90 struct rb_root *p_root;
91 /* sorted list of pending requests */
92 struct rb_root sort_list;
93 /* if fifo isn't expired, next request to serve */
94 struct request *next_rq;
95 /* requests queued in sort_list */
96 int queued[2];
97 /* currently allocated requests */
98 int allocated[2];
99 /* fifo list of requests in sort_list */
100 struct list_head fifo;
101
102 unsigned long slice_end;
103 long slice_resid;
104 unsigned int slice_dispatch;
105
106 /* pending metadata requests */
107 int meta_pending;
108 /* number of requests that are on the dispatch list or inside driver */
109 int dispatched;
110
111 /* io prio of this group */
112 unsigned short ioprio, org_ioprio;
113 unsigned short ioprio_class, org_ioprio_class;
114
115 pid_t pid;
116};
117
118/*
74 * Per block device queue structure 119 * Per block device queue structure
75 */ 120 */
76struct cfq_data { 121struct cfq_data {
@@ -135,51 +180,11 @@ struct cfq_data {
135 unsigned int cfq_slice_idle; 180 unsigned int cfq_slice_idle;
136 181
137 struct list_head cic_list; 182 struct list_head cic_list;
138};
139
140/*
141 * Per process-grouping structure
142 */
143struct cfq_queue {
144 /* reference count */
145 atomic_t ref;
146 /* various state flags, see below */
147 unsigned int flags;
148 /* parent cfq_data */
149 struct cfq_data *cfqd;
150 /* service_tree member */
151 struct rb_node rb_node;
152 /* service_tree key */
153 unsigned long rb_key;
154 /* prio tree member */
155 struct rb_node p_node;
156 /* prio tree root we belong to, if any */
157 struct rb_root *p_root;
158 /* sorted list of pending requests */
159 struct rb_root sort_list;
160 /* if fifo isn't expired, next request to serve */
161 struct request *next_rq;
162 /* requests queued in sort_list */
163 int queued[2];
164 /* currently allocated requests */
165 int allocated[2];
166 /* fifo list of requests in sort_list */
167 struct list_head fifo;
168 183
169 unsigned long slice_end; 184 /*
170 long slice_resid; 185 * Fallback dummy cfqq for extreme OOM conditions
171 unsigned int slice_dispatch; 186 */
172 187 struct cfq_queue oom_cfqq;
173 /* pending metadata requests */
174 int meta_pending;
175 /* number of requests that are on the dispatch list or inside driver */
176 int dispatched;
177
178 /* io prio of this group */
179 unsigned short ioprio, org_ioprio;
180 unsigned short ioprio_class, org_ioprio_class;
181
182 pid_t pid;
183}; 188};
184 189
185enum cfqq_state_flags { 190enum cfqq_state_flags {
@@ -1641,6 +1646,26 @@ static void cfq_ioc_set_ioprio(struct io_context *ioc)
1641 ioc->ioprio_changed = 0; 1646 ioc->ioprio_changed = 0;
1642} 1647}
1643 1648
1649static void cfq_init_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1650 pid_t pid, int is_sync)
1651{
1652 RB_CLEAR_NODE(&cfqq->rb_node);
1653 RB_CLEAR_NODE(&cfqq->p_node);
1654 INIT_LIST_HEAD(&cfqq->fifo);
1655
1656 atomic_set(&cfqq->ref, 0);
1657 cfqq->cfqd = cfqd;
1658
1659 cfq_mark_cfqq_prio_changed(cfqq);
1660
1661 if (is_sync) {
1662 if (!cfq_class_idle(cfqq))
1663 cfq_mark_cfqq_idle_window(cfqq);
1664 cfq_mark_cfqq_sync(cfqq);
1665 }
1666 cfqq->pid = pid;
1667}
1668
1644static struct cfq_queue * 1669static struct cfq_queue *
1645cfq_find_alloc_queue(struct cfq_data *cfqd, int is_sync, 1670cfq_find_alloc_queue(struct cfq_data *cfqd, int is_sync,
1646 struct io_context *ioc, gfp_t gfp_mask) 1671 struct io_context *ioc, gfp_t gfp_mask)
@@ -1653,56 +1678,40 @@ retry:
1653 /* cic always exists here */ 1678 /* cic always exists here */
1654 cfqq = cic_to_cfqq(cic, is_sync); 1679 cfqq = cic_to_cfqq(cic, is_sync);
1655 1680
1656 if (!cfqq) { 1681 /*
1682 * Always try a new alloc if we fell back to the OOM cfqq
1683 * originally, since it should just be a temporary situation.
1684 */
1685 if (!cfqq || cfqq == &cfqd->oom_cfqq) {
1686 cfqq = NULL;
1657 if (new_cfqq) { 1687 if (new_cfqq) {
1658 cfqq = new_cfqq; 1688 cfqq = new_cfqq;
1659 new_cfqq = NULL; 1689 new_cfqq = NULL;
1660 } else if (gfp_mask & __GFP_WAIT) { 1690 } else if (gfp_mask & __GFP_WAIT) {
1661 /*
1662 * Inform the allocator of the fact that we will
1663 * just repeat this allocation if it fails, to allow
1664 * the allocator to do whatever it needs to attempt to
1665 * free memory.
1666 */
1667 spin_unlock_irq(cfqd->queue->queue_lock); 1691 spin_unlock_irq(cfqd->queue->queue_lock);
1668 new_cfqq = kmem_cache_alloc_node(cfq_pool, 1692 new_cfqq = kmem_cache_alloc_node(cfq_pool,
1669 gfp_mask | __GFP_NOFAIL | __GFP_ZERO, 1693 gfp_mask | __GFP_ZERO,
1670 cfqd->queue->node); 1694 cfqd->queue->node);
1671 spin_lock_irq(cfqd->queue->queue_lock); 1695 spin_lock_irq(cfqd->queue->queue_lock);
1672 goto retry; 1696 if (new_cfqq)
1697 goto retry;
1673 } else { 1698 } else {
1674 cfqq = kmem_cache_alloc_node(cfq_pool, 1699 cfqq = kmem_cache_alloc_node(cfq_pool,
1675 gfp_mask | __GFP_ZERO, 1700 gfp_mask | __GFP_ZERO,
1676 cfqd->queue->node); 1701 cfqd->queue->node);
1677 if (!cfqq)
1678 goto out;
1679 } 1702 }
1680 1703
1681 RB_CLEAR_NODE(&cfqq->rb_node); 1704 if (cfqq) {
1682 RB_CLEAR_NODE(&cfqq->p_node); 1705 cfq_init_cfqq(cfqd, cfqq, current->pid, is_sync);
1683 INIT_LIST_HEAD(&cfqq->fifo); 1706 cfq_init_prio_data(cfqq, ioc);
1684 1707 cfq_log_cfqq(cfqd, cfqq, "alloced");
1685 atomic_set(&cfqq->ref, 0); 1708 } else
1686 cfqq->cfqd = cfqd; 1709 cfqq = &cfqd->oom_cfqq;
1687
1688 cfq_mark_cfqq_prio_changed(cfqq);
1689
1690 cfq_init_prio_data(cfqq, ioc);
1691
1692 if (is_sync) {
1693 if (!cfq_class_idle(cfqq))
1694 cfq_mark_cfqq_idle_window(cfqq);
1695 cfq_mark_cfqq_sync(cfqq);
1696 }
1697 cfqq->pid = current->pid;
1698 cfq_log_cfqq(cfqd, cfqq, "alloced");
1699 } 1710 }
1700 1711
1701 if (new_cfqq) 1712 if (new_cfqq)
1702 kmem_cache_free(cfq_pool, new_cfqq); 1713 kmem_cache_free(cfq_pool, new_cfqq);
1703 1714
1704out:
1705 WARN_ON((gfp_mask & __GFP_WAIT) && !cfqq);
1706 return cfqq; 1715 return cfqq;
1707} 1716}
1708 1717
@@ -1735,11 +1744,8 @@ cfq_get_queue(struct cfq_data *cfqd, int is_sync, struct io_context *ioc,
1735 cfqq = *async_cfqq; 1744 cfqq = *async_cfqq;
1736 } 1745 }
1737 1746
1738 if (!cfqq) { 1747 if (!cfqq)
1739 cfqq = cfq_find_alloc_queue(cfqd, is_sync, ioc, gfp_mask); 1748 cfqq = cfq_find_alloc_queue(cfqd, is_sync, ioc, gfp_mask);
1740 if (!cfqq)
1741 return NULL;
1742 }
1743 1749
1744 /* 1750 /*
1745 * pin the queue now that it's allocated, scheduler exit will prune it 1751 * pin the queue now that it's allocated, scheduler exit will prune it
@@ -2307,10 +2313,6 @@ cfq_set_request(struct request_queue *q, struct request *rq, gfp_t gfp_mask)
2307 cfqq = cic_to_cfqq(cic, is_sync); 2313 cfqq = cic_to_cfqq(cic, is_sync);
2308 if (!cfqq) { 2314 if (!cfqq) {
2309 cfqq = cfq_get_queue(cfqd, is_sync, cic->ioc, gfp_mask); 2315 cfqq = cfq_get_queue(cfqd, is_sync, cic->ioc, gfp_mask);
2310
2311 if (!cfqq)
2312 goto queue_fail;
2313
2314 cic_set_cfqq(cic, cfqq, is_sync); 2316 cic_set_cfqq(cic, cfqq, is_sync);
2315 } 2317 }
2316 2318
@@ -2465,6 +2467,14 @@ static void *cfq_init_queue(struct request_queue *q)
2465 for (i = 0; i < CFQ_PRIO_LISTS; i++) 2467 for (i = 0; i < CFQ_PRIO_LISTS; i++)
2466 cfqd->prio_trees[i] = RB_ROOT; 2468 cfqd->prio_trees[i] = RB_ROOT;
2467 2469
2470 /*
2471 * Our fallback cfqq if cfq_find_alloc_queue() runs into OOM issues.
2472 * Grab a permanent reference to it, so that the normal code flow
2473 * will not attempt to free it.
2474 */
2475 cfq_init_cfqq(cfqd, &cfqd->oom_cfqq, 1, 0);
2476 atomic_inc(&cfqd->oom_cfqq.ref);
2477
2468 INIT_LIST_HEAD(&cfqd->cic_list); 2478 INIT_LIST_HEAD(&cfqd->cic_list);
2469 2479
2470 cfqd->queue = q; 2480 cfqd->queue = q;
diff --git a/block/cmd-filter.c b/block/cmd-filter.c
deleted file mode 100644
index 572bbc2f900d..000000000000
--- a/block/cmd-filter.c
+++ /dev/null
@@ -1,233 +0,0 @@
1/*
2 * Copyright 2004 Peter M. Jones <pjones@redhat.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public Licens
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-
17 *
18 */
19
20#include <linux/list.h>
21#include <linux/genhd.h>
22#include <linux/spinlock.h>
23#include <linux/capability.h>
24#include <linux/bitops.h>
25#include <linux/blkdev.h>
26
27#include <scsi/scsi.h>
28#include <linux/cdrom.h>
29
30int blk_verify_command(struct blk_cmd_filter *filter,
31 unsigned char *cmd, fmode_t has_write_perm)
32{
33 /* root can do any command. */
34 if (capable(CAP_SYS_RAWIO))
35 return 0;
36
37 /* if there's no filter set, assume we're filtering everything out */
38 if (!filter)
39 return -EPERM;
40
41 /* Anybody who can open the device can do a read-safe command */
42 if (test_bit(cmd[0], filter->read_ok))
43 return 0;
44
45 /* Write-safe commands require a writable open */
46 if (test_bit(cmd[0], filter->write_ok) && has_write_perm)
47 return 0;
48
49 return -EPERM;
50}
51EXPORT_SYMBOL(blk_verify_command);
52
53#if 0
54/* and now, the sysfs stuff */
55static ssize_t rcf_cmds_show(struct blk_cmd_filter *filter, char *page,
56 int rw)
57{
58 char *npage = page;
59 unsigned long *okbits;
60 int i;
61
62 if (rw == READ)
63 okbits = filter->read_ok;
64 else
65 okbits = filter->write_ok;
66
67 for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {
68 if (test_bit(i, okbits)) {
69 npage += sprintf(npage, "0x%02x", i);
70 if (i < BLK_SCSI_MAX_CMDS - 1)
71 sprintf(npage++, " ");
72 }
73 }
74
75 if (npage != page)
76 npage += sprintf(npage, "\n");
77
78 return npage - page;
79}
80
81static ssize_t rcf_readcmds_show(struct blk_cmd_filter *filter, char *page)
82{
83 return rcf_cmds_show(filter, page, READ);
84}
85
86static ssize_t rcf_writecmds_show(struct blk_cmd_filter *filter,
87 char *page)
88{
89 return rcf_cmds_show(filter, page, WRITE);
90}
91
92static ssize_t rcf_cmds_store(struct blk_cmd_filter *filter,
93 const char *page, size_t count, int rw)
94{
95 unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits;
96 int cmd, set;
97 char *p, *status;
98
99 if (rw == READ) {
100 memcpy(&okbits, filter->read_ok, sizeof(okbits));
101 target_okbits = filter->read_ok;
102 } else {
103 memcpy(&okbits, filter->write_ok, sizeof(okbits));
104 target_okbits = filter->write_ok;
105 }
106
107 while ((p = strsep((char **)&page, " ")) != NULL) {
108 set = 1;
109
110 if (p[0] == '+') {
111 p++;
112 } else if (p[0] == '-') {
113 set = 0;
114 p++;
115 }
116
117 cmd = simple_strtol(p, &status, 16);
118
119 /* either of these cases means invalid input, so do nothing. */
120 if ((status == p) || cmd >= BLK_SCSI_MAX_CMDS)
121 return -EINVAL;
122
123 if (set)
124 __set_bit(cmd, okbits);
125 else
126 __clear_bit(cmd, okbits);
127 }
128
129 memcpy(target_okbits, okbits, sizeof(okbits));
130 return count;
131}
132
133static ssize_t rcf_readcmds_store(struct blk_cmd_filter *filter,
134 const char *page, size_t count)
135{
136 return rcf_cmds_store(filter, page, count, READ);
137}
138
139static ssize_t rcf_writecmds_store(struct blk_cmd_filter *filter,
140 const char *page, size_t count)
141{
142 return rcf_cmds_store(filter, page, count, WRITE);
143}
144
145struct rcf_sysfs_entry {
146 struct attribute attr;
147 ssize_t (*show)(struct blk_cmd_filter *, char *);
148 ssize_t (*store)(struct blk_cmd_filter *, const char *, size_t);
149};
150
151static struct rcf_sysfs_entry rcf_readcmds_entry = {
152 .attr = { .name = "read_table", .mode = S_IRUGO | S_IWUSR },
153 .show = rcf_readcmds_show,
154 .store = rcf_readcmds_store,
155};
156
157static struct rcf_sysfs_entry rcf_writecmds_entry = {
158 .attr = {.name = "write_table", .mode = S_IRUGO | S_IWUSR },
159 .show = rcf_writecmds_show,
160 .store = rcf_writecmds_store,
161};
162
163static struct attribute *default_attrs[] = {
164 &rcf_readcmds_entry.attr,
165 &rcf_writecmds_entry.attr,
166 NULL,
167};
168
169#define to_rcf(atr) container_of((atr), struct rcf_sysfs_entry, attr)
170
171static ssize_t
172rcf_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
173{
174 struct rcf_sysfs_entry *entry = to_rcf(attr);
175 struct blk_cmd_filter *filter;
176
177 filter = container_of(kobj, struct blk_cmd_filter, kobj);
178 if (entry->show)
179 return entry->show(filter, page);
180
181 return 0;
182}
183
184static ssize_t
185rcf_attr_store(struct kobject *kobj, struct attribute *attr,
186 const char *page, size_t length)
187{
188 struct rcf_sysfs_entry *entry = to_rcf(attr);
189 struct blk_cmd_filter *filter;
190
191 if (!capable(CAP_SYS_RAWIO))
192 return -EPERM;
193
194 if (!entry->store)
195 return -EINVAL;
196
197 filter = container_of(kobj, struct blk_cmd_filter, kobj);
198 return entry->store(filter, page, length);
199}
200
201static struct sysfs_ops rcf_sysfs_ops = {
202 .show = rcf_attr_show,
203 .store = rcf_attr_store,
204};
205
206static struct kobj_type rcf_ktype = {
207 .sysfs_ops = &rcf_sysfs_ops,
208 .default_attrs = default_attrs,
209};
210
211int blk_register_filter(struct gendisk *disk)
212{
213 int ret;
214 struct blk_cmd_filter *filter = &disk->queue->cmd_filter;
215
216 ret = kobject_init_and_add(&filter->kobj, &rcf_ktype,
217 &disk_to_dev(disk)->kobj,
218 "%s", "cmd_filter");
219 if (ret < 0)
220 return ret;
221
222 return 0;
223}
224EXPORT_SYMBOL(blk_register_filter);
225
226void blk_unregister_filter(struct gendisk *disk)
227{
228 struct blk_cmd_filter *filter = &disk->queue->cmd_filter;
229
230 kobject_put(&filter->kobj);
231}
232EXPORT_SYMBOL(blk_unregister_filter);
233#endif
diff --git a/block/elevator.c b/block/elevator.c
index ca861927ba41..6f2375339a99 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -100,6 +100,14 @@ int elv_rq_merge_ok(struct request *rq, struct bio *bio)
100 if (bio_integrity(bio) != blk_integrity_rq(rq)) 100 if (bio_integrity(bio) != blk_integrity_rq(rq))
101 return 0; 101 return 0;
102 102
103 /*
104 * Don't merge if failfast settings don't match
105 */
106 if (bio_failfast_dev(bio) != blk_failfast_dev(rq) ||
107 bio_failfast_transport(bio) != blk_failfast_transport(rq) ||
108 bio_failfast_driver(bio) != blk_failfast_driver(rq))
109 return 0;
110
103 if (!elv_iosched_allow_merge(rq, bio)) 111 if (!elv_iosched_allow_merge(rq, bio))
104 return 0; 112 return 0;
105 113
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 5f8e798ede4e..f0e0ce0a607d 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -32,6 +32,11 @@
32#include <scsi/scsi_ioctl.h> 32#include <scsi/scsi_ioctl.h>
33#include <scsi/scsi_cmnd.h> 33#include <scsi/scsi_cmnd.h>
34 34
35struct blk_cmd_filter {
36 unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
37 unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
38} blk_default_cmd_filter;
39
35/* Command group 3 is reserved and should never be used. */ 40/* Command group 3 is reserved and should never be used. */
36const unsigned char scsi_command_size_tbl[8] = 41const unsigned char scsi_command_size_tbl[8] =
37{ 42{
@@ -105,7 +110,7 @@ static int sg_emulated_host(struct request_queue *q, int __user *p)
105 return put_user(1, p); 110 return put_user(1, p);
106} 111}
107 112
108void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter) 113static void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter)
109{ 114{
110 /* Basic read-only commands */ 115 /* Basic read-only commands */
111 __set_bit(TEST_UNIT_READY, filter->read_ok); 116 __set_bit(TEST_UNIT_READY, filter->read_ok);
@@ -187,14 +192,37 @@ void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter)
187 __set_bit(GPCMD_SET_STREAMING, filter->write_ok); 192 __set_bit(GPCMD_SET_STREAMING, filter->write_ok);
188 __set_bit(GPCMD_SET_READ_AHEAD, filter->write_ok); 193 __set_bit(GPCMD_SET_READ_AHEAD, filter->write_ok);
189} 194}
190EXPORT_SYMBOL_GPL(blk_set_cmd_filter_defaults); 195
196int blk_verify_command(unsigned char *cmd, fmode_t has_write_perm)
197{
198 struct blk_cmd_filter *filter = &blk_default_cmd_filter;
199
200 /* root can do any command. */
201 if (capable(CAP_SYS_RAWIO))
202 return 0;
203
204 /* if there's no filter set, assume we're filtering everything out */
205 if (!filter)
206 return -EPERM;
207
208 /* Anybody who can open the device can do a read-safe command */
209 if (test_bit(cmd[0], filter->read_ok))
210 return 0;
211
212 /* Write-safe commands require a writable open */
213 if (test_bit(cmd[0], filter->write_ok) && has_write_perm)
214 return 0;
215
216 return -EPERM;
217}
218EXPORT_SYMBOL(blk_verify_command);
191 219
192static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq, 220static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
193 struct sg_io_hdr *hdr, fmode_t mode) 221 struct sg_io_hdr *hdr, fmode_t mode)
194{ 222{
195 if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len)) 223 if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
196 return -EFAULT; 224 return -EFAULT;
197 if (blk_verify_command(&q->cmd_filter, rq->cmd, mode & FMODE_WRITE)) 225 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
198 return -EPERM; 226 return -EPERM;
199 227
200 /* 228 /*
@@ -427,7 +455,7 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
427 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len)) 455 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
428 goto error; 456 goto error;
429 457
430 err = blk_verify_command(&q->cmd_filter, rq->cmd, mode & FMODE_WRITE); 458 err = blk_verify_command(rq->cmd, mode & FMODE_WRITE);
431 if (err) 459 if (err)
432 goto error; 460 goto error;
433 461
@@ -645,5 +673,10 @@ int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mod
645 blk_put_queue(q); 673 blk_put_queue(q);
646 return err; 674 return err;
647} 675}
648
649EXPORT_SYMBOL(scsi_cmd_ioctl); 676EXPORT_SYMBOL(scsi_cmd_ioctl);
677
678int __init blk_scsi_ioctl_init(void)
679{
680 blk_set_cmd_filter_defaults(&blk_default_cmd_filter);
681 return 0;
682}
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 8a5bf3b356fa..55b5b90c2a44 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -395,7 +395,7 @@ struct pci_dev *acpi_get_pci_dev(acpi_handle handle)
395 fn = adr & 0xffff; 395 fn = adr & 0xffff;
396 396
397 pdev = pci_get_slot(pbus, PCI_DEVFN(dev, fn)); 397 pdev = pci_get_slot(pbus, PCI_DEVFN(dev, fn));
398 if (hnd == handle) 398 if (!pdev || hnd == handle)
399 break; 399 break;
400 400
401 pbus = pdev->subordinate; 401 pbus = pdev->subordinate;
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index c7a527c08a09..65a0655e7fc8 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -226,8 +226,18 @@ static inline void addQ(struct hlist_head *list, CommandList_struct *c)
226 226
227static inline void removeQ(CommandList_struct *c) 227static inline void removeQ(CommandList_struct *c)
228{ 228{
229 if (WARN_ON(hlist_unhashed(&c->list))) 229 /*
230 * After kexec/dump some commands might still
231 * be in flight, which the firmware will try
232 * to complete. Resetting the firmware doesn't work
233 * with old fw revisions, so we have to mark
234 * them off as 'stale' to prevent the driver from
235 * falling over.
236 */
237 if (WARN_ON(hlist_unhashed(&c->list))) {
238 c->cmd_type = CMD_MSG_STALE;
230 return; 239 return;
240 }
231 241
232 hlist_del_init(&c->list); 242 hlist_del_init(&c->list);
233} 243}
@@ -4246,7 +4256,8 @@ static void fail_all_cmds(unsigned long ctlr)
4246 while (!hlist_empty(&h->cmpQ)) { 4256 while (!hlist_empty(&h->cmpQ)) {
4247 c = hlist_entry(h->cmpQ.first, CommandList_struct, list); 4257 c = hlist_entry(h->cmpQ.first, CommandList_struct, list);
4248 removeQ(c); 4258 removeQ(c);
4249 c->err_info->CommandStatus = CMD_HARDWARE_ERR; 4259 if (c->cmd_type != CMD_MSG_STALE)
4260 c->err_info->CommandStatus = CMD_HARDWARE_ERR;
4250 if (c->cmd_type == CMD_RWREQ) { 4261 if (c->cmd_type == CMD_RWREQ) {
4251 complete_command(h, c, 0); 4262 complete_command(h, c, 0);
4252 } else if (c->cmd_type == CMD_IOCTL_PEND) 4263 } else if (c->cmd_type == CMD_IOCTL_PEND)
diff --git a/drivers/block/cciss_cmd.h b/drivers/block/cciss_cmd.h
index cd665b00c7c5..dbaed1ea0da3 100644
--- a/drivers/block/cciss_cmd.h
+++ b/drivers/block/cciss_cmd.h
@@ -274,6 +274,7 @@ typedef struct _ErrorInfo_struct {
274#define CMD_SCSI 0x03 274#define CMD_SCSI 0x03
275#define CMD_MSG_DONE 0x04 275#define CMD_MSG_DONE 0x04
276#define CMD_MSG_TIMEOUT 0x05 276#define CMD_MSG_TIMEOUT 0x05
277#define CMD_MSG_STALE 0xff
277 278
278/* This structure needs to be divisible by 8 for new 279/* This structure needs to be divisible by 8 for new
279 * indexing method. 280 * indexing method.
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 862b40c90181..91b753013780 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3327,7 +3327,10 @@ static inline int set_geometry(unsigned int cmd, struct floppy_struct *g,
3327 if (!capable(CAP_SYS_ADMIN)) 3327 if (!capable(CAP_SYS_ADMIN))
3328 return -EPERM; 3328 return -EPERM;
3329 mutex_lock(&open_lock); 3329 mutex_lock(&open_lock);
3330 LOCK_FDC(drive, 1); 3330 if (lock_fdc(drive, 1)) {
3331 mutex_unlock(&open_lock);
3332 return -EINTR;
3333 }
3331 floppy_type[type] = *g; 3334 floppy_type[type] = *g;
3332 floppy_type[type].name = "user format"; 3335 floppy_type[type].name = "user format";
3333 for (cnt = type << 2; cnt < (type << 2) + 4; cnt++) 3336 for (cnt = type << 2; cnt < (type << 2) + 4; cnt++)
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 0bd01f49cfd8..6a06913b01d3 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -1029,10 +1029,6 @@ config CS5535_GPIO
1029 1029
1030 If compiled as a module, it will be called cs5535_gpio. 1030 If compiled as a module, it will be called cs5535_gpio.
1031 1031
1032config GPIO_VR41XX
1033 tristate "NEC VR4100 series General-purpose I/O Unit support"
1034 depends on CPU_VR41XX
1035
1036config RAW_DRIVER 1032config RAW_DRIVER
1037 tristate "RAW driver (/dev/raw/rawN)" 1033 tristate "RAW driver (/dev/raw/rawN)"
1038 depends on BLOCK 1034 depends on BLOCK
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 189efcff08ce..66f779ad4f4c 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -95,7 +95,6 @@ obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
95obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o 95obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
96obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o 96obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
97obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o 97obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o
98obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o
99obj-$(CONFIG_GPIO_TB0219) += tb0219.o 98obj-$(CONFIG_GPIO_TB0219) += tb0219.o
100obj-$(CONFIG_TELCLOCK) += tlclk.o 99obj-$(CONFIG_TELCLOCK) += tlclk.o
101 100
diff --git a/drivers/char/bsr.c b/drivers/char/bsr.c
index 140ea10ecb88..c02db01f736e 100644
--- a/drivers/char/bsr.c
+++ b/drivers/char/bsr.c
@@ -27,6 +27,7 @@
27#include <linux/cdev.h> 27#include <linux/cdev.h>
28#include <linux/list.h> 28#include <linux/list.h>
29#include <linux/mm.h> 29#include <linux/mm.h>
30#include <asm/pgtable.h>
30#include <asm/io.h> 31#include <asm/io.h>
31 32
32/* 33/*
@@ -75,12 +76,13 @@ static struct class *bsr_class;
75static int bsr_major; 76static int bsr_major;
76 77
77enum { 78enum {
78 BSR_8 = 0, 79 BSR_8 = 0,
79 BSR_16 = 1, 80 BSR_16 = 1,
80 BSR_64 = 2, 81 BSR_64 = 2,
81 BSR_128 = 3, 82 BSR_128 = 3,
82 BSR_UNKNOWN = 4, 83 BSR_4096 = 4,
83 BSR_MAX = 5, 84 BSR_UNKNOWN = 5,
85 BSR_MAX = 6,
84}; 86};
85 87
86static unsigned bsr_types[BSR_MAX]; 88static unsigned bsr_types[BSR_MAX];
@@ -117,15 +119,22 @@ static int bsr_mmap(struct file *filp, struct vm_area_struct *vma)
117{ 119{
118 unsigned long size = vma->vm_end - vma->vm_start; 120 unsigned long size = vma->vm_end - vma->vm_start;
119 struct bsr_dev *dev = filp->private_data; 121 struct bsr_dev *dev = filp->private_data;
122 int ret;
120 123
121 if (size > dev->bsr_len || (size & (PAGE_SIZE-1)))
122 return -EINVAL;
123
124 vma->vm_flags |= (VM_IO | VM_DONTEXPAND);
125 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 124 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
126 125
127 if (io_remap_pfn_range(vma, vma->vm_start, dev->bsr_addr >> PAGE_SHIFT, 126 /* check for the case of a small BSR device and map one 4k page for it*/
128 size, vma->vm_page_prot)) 127 if (dev->bsr_len < PAGE_SIZE && size == PAGE_SIZE)
128 ret = remap_4k_pfn(vma, vma->vm_start, dev->bsr_addr >> 12,
129 vma->vm_page_prot);
130 else if (size <= dev->bsr_len)
131 ret = io_remap_pfn_range(vma, vma->vm_start,
132 dev->bsr_addr >> PAGE_SHIFT,
133 size, vma->vm_page_prot);
134 else
135 return -EINVAL;
136
137 if (ret)
129 return -EAGAIN; 138 return -EAGAIN;
130 139
131 return 0; 140 return 0;
@@ -205,6 +214,11 @@ static int bsr_add_node(struct device_node *bn)
205 cur->bsr_stride = bsr_stride[i]; 214 cur->bsr_stride = bsr_stride[i];
206 cur->bsr_dev = MKDEV(bsr_major, i + total_bsr_devs); 215 cur->bsr_dev = MKDEV(bsr_major, i + total_bsr_devs);
207 216
217 /* if we have a bsr_len of > 4k and less then PAGE_SIZE (64k pages) */
218 /* we can only map 4k of it, so only advertise the 4k in sysfs */
219 if (cur->bsr_len > 4096 && cur->bsr_len < PAGE_SIZE)
220 cur->bsr_len = 4096;
221
208 switch(cur->bsr_bytes) { 222 switch(cur->bsr_bytes) {
209 case 8: 223 case 8:
210 cur->bsr_type = BSR_8; 224 cur->bsr_type = BSR_8;
@@ -218,9 +232,11 @@ static int bsr_add_node(struct device_node *bn)
218 case 128: 232 case 128:
219 cur->bsr_type = BSR_128; 233 cur->bsr_type = BSR_128;
220 break; 234 break;
235 case 4096:
236 cur->bsr_type = BSR_4096;
237 break;
221 default: 238 default:
222 cur->bsr_type = BSR_UNKNOWN; 239 cur->bsr_type = BSR_UNKNOWN;
223 printk(KERN_INFO "unknown BSR size %d\n",cur->bsr_bytes);
224 } 240 }
225 241
226 cur->bsr_num = bsr_types[cur->bsr_type]; 242 cur->bsr_num = bsr_types[cur->bsr_type];
diff --git a/drivers/char/tb0219.c b/drivers/char/tb0219.c
index 6062b62800fd..b3ec9b10e292 100644
--- a/drivers/char/tb0219.c
+++ b/drivers/char/tb0219.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for TANBAC TB0219 base board. 2 * Driver for TANBAC TB0219 base board.
3 * 3 *
4 * Copyright (C) 2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2005 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@
28#include <asm/vr41xx/giu.h> 28#include <asm/vr41xx/giu.h>
29#include <asm/vr41xx/tb0219.h> 29#include <asm/vr41xx/tb0219.h>
30 30
31MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); 31MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
32MODULE_DESCRIPTION("TANBAC TB0219 base board driver"); 32MODULE_DESCRIPTION("TANBAC TB0219 base board driver");
33MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
34 34
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
index a19e935847b0..913aa8d3f1c5 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -867,15 +867,22 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
867 tty_ldisc_wait_idle(tty); 867 tty_ldisc_wait_idle(tty);
868 868
869 /* 869 /*
870 * Shutdown the current line discipline, and reset it to N_TTY. 870 * Now kill off the ldisc
871 *
872 * FIXME: this MUST get fixed for the new reflocking
873 */ 871 */
872 tty_ldisc_close(tty, tty->ldisc);
873 tty_ldisc_put(tty->ldisc);
874 /* Force an oops if we mess this up */
875 tty->ldisc = NULL;
876
877 /* Ensure the next open requests the N_TTY ldisc */
878 tty_set_termios_ldisc(tty, N_TTY);
874 879
875 tty_ldisc_reinit(tty);
876 /* This will need doing differently if we need to lock */ 880 /* This will need doing differently if we need to lock */
877 if (o_tty) 881 if (o_tty)
878 tty_ldisc_release(o_tty, NULL); 882 tty_ldisc_release(o_tty, NULL);
883
884 /* And the memory resources remaining (buffers, termios) will be
885 disposed of when the kref hits zero */
879} 886}
880 887
881/** 888/**
diff --git a/drivers/char/vr41xx_giu.c b/drivers/char/vr41xx_giu.c
index 54c837288d19..e69de29bb2d1 100644
--- a/drivers/char/vr41xx_giu.c
+++ b/drivers/char/vr41xx_giu.c
@@ -1,680 +0,0 @@
1/*
2 * Driver for NEC VR4100 series General-purpose I/O Unit.
3 *
4 * Copyright (C) 2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
6 * Copyright (C) 2003-2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22#include <linux/errno.h>
23#include <linux/fs.h>
24#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/irq.h>
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/platform_device.h>
30#include <linux/smp_lock.h>
31#include <linux/spinlock.h>
32#include <linux/types.h>
33
34#include <asm/io.h>
35#include <asm/vr41xx/giu.h>
36#include <asm/vr41xx/irq.h>
37#include <asm/vr41xx/vr41xx.h>
38
39MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>");
40MODULE_DESCRIPTION("NEC VR4100 series General-purpose I/O Unit driver");
41MODULE_LICENSE("GPL");
42
43static int major; /* default is dynamic major device number */
44module_param(major, int, 0);
45MODULE_PARM_DESC(major, "Major device number");
46
47#define GIUIOSELL 0x00
48#define GIUIOSELH 0x02
49#define GIUPIODL 0x04
50#define GIUPIODH 0x06
51#define GIUINTSTATL 0x08
52#define GIUINTSTATH 0x0a
53#define GIUINTENL 0x0c
54#define GIUINTENH 0x0e
55#define GIUINTTYPL 0x10
56#define GIUINTTYPH 0x12
57#define GIUINTALSELL 0x14
58#define GIUINTALSELH 0x16
59#define GIUINTHTSELL 0x18
60#define GIUINTHTSELH 0x1a
61#define GIUPODATL 0x1c
62#define GIUPODATEN 0x1c
63#define GIUPODATH 0x1e
64 #define PIOEN0 0x0100
65 #define PIOEN1 0x0200
66#define GIUPODAT 0x1e
67#define GIUFEDGEINHL 0x20
68#define GIUFEDGEINHH 0x22
69#define GIUREDGEINHL 0x24
70#define GIUREDGEINHH 0x26
71
72#define GIUUSEUPDN 0x1e0
73#define GIUTERMUPDN 0x1e2
74
75#define GPIO_HAS_PULLUPDOWN_IO 0x0001
76#define GPIO_HAS_OUTPUT_ENABLE 0x0002
77#define GPIO_HAS_INTERRUPT_EDGE_SELECT 0x0100
78
79static spinlock_t giu_lock;
80static unsigned long giu_flags;
81static unsigned int giu_nr_pins;
82
83static void __iomem *giu_base;
84
85#define giu_read(offset) readw(giu_base + (offset))
86#define giu_write(offset, value) writew((value), giu_base + (offset))
87
88#define GPIO_PIN_OF_IRQ(irq) ((irq) - GIU_IRQ_BASE)
89#define GIUINT_HIGH_OFFSET 16
90#define GIUINT_HIGH_MAX 32
91
92static inline uint16_t giu_set(uint16_t offset, uint16_t set)
93{
94 uint16_t data;
95
96 data = giu_read(offset);
97 data |= set;
98 giu_write(offset, data);
99
100 return data;
101}
102
103static inline uint16_t giu_clear(uint16_t offset, uint16_t clear)
104{
105 uint16_t data;
106
107 data = giu_read(offset);
108 data &= ~clear;
109 giu_write(offset, data);
110
111 return data;
112}
113
114static void ack_giuint_low(unsigned int irq)
115{
116 giu_write(GIUINTSTATL, 1 << GPIO_PIN_OF_IRQ(irq));
117}
118
119static void mask_giuint_low(unsigned int irq)
120{
121 giu_clear(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
122}
123
124static void mask_ack_giuint_low(unsigned int irq)
125{
126 unsigned int pin;
127
128 pin = GPIO_PIN_OF_IRQ(irq);
129 giu_clear(GIUINTENL, 1 << pin);
130 giu_write(GIUINTSTATL, 1 << pin);
131}
132
133static void unmask_giuint_low(unsigned int irq)
134{
135 giu_set(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
136}
137
138static struct irq_chip giuint_low_irq_chip = {
139 .name = "GIUINTL",
140 .ack = ack_giuint_low,
141 .mask = mask_giuint_low,
142 .mask_ack = mask_ack_giuint_low,
143 .unmask = unmask_giuint_low,
144};
145
146static void ack_giuint_high(unsigned int irq)
147{
148 giu_write(GIUINTSTATH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
149}
150
151static void mask_giuint_high(unsigned int irq)
152{
153 giu_clear(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
154}
155
156static void mask_ack_giuint_high(unsigned int irq)
157{
158 unsigned int pin;
159
160 pin = GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET;
161 giu_clear(GIUINTENH, 1 << pin);
162 giu_write(GIUINTSTATH, 1 << pin);
163}
164
165static void unmask_giuint_high(unsigned int irq)
166{
167 giu_set(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
168}
169
170static struct irq_chip giuint_high_irq_chip = {
171 .name = "GIUINTH",
172 .ack = ack_giuint_high,
173 .mask = mask_giuint_high,
174 .mask_ack = mask_ack_giuint_high,
175 .unmask = unmask_giuint_high,
176};
177
178static int giu_get_irq(unsigned int irq)
179{
180 uint16_t pendl, pendh, maskl, maskh;
181 int i;
182
183 pendl = giu_read(GIUINTSTATL);
184 pendh = giu_read(GIUINTSTATH);
185 maskl = giu_read(GIUINTENL);
186 maskh = giu_read(GIUINTENH);
187
188 maskl &= pendl;
189 maskh &= pendh;
190
191 if (maskl) {
192 for (i = 0; i < 16; i++) {
193 if (maskl & (1 << i))
194 return GIU_IRQ(i);
195 }
196 } else if (maskh) {
197 for (i = 0; i < 16; i++) {
198 if (maskh & (1 << i))
199 return GIU_IRQ(i + GIUINT_HIGH_OFFSET);
200 }
201 }
202
203 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
204 maskl, pendl, maskh, pendh);
205
206 atomic_inc(&irq_err_count);
207
208 return -EINVAL;
209}
210
211void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger, irq_signal_t signal)
212{
213 uint16_t mask;
214
215 if (pin < GIUINT_HIGH_OFFSET) {
216 mask = 1 << pin;
217 if (trigger != IRQ_TRIGGER_LEVEL) {
218 giu_set(GIUINTTYPL, mask);
219 if (signal == IRQ_SIGNAL_HOLD)
220 giu_set(GIUINTHTSELL, mask);
221 else
222 giu_clear(GIUINTHTSELL, mask);
223 if (giu_flags & GPIO_HAS_INTERRUPT_EDGE_SELECT) {
224 switch (trigger) {
225 case IRQ_TRIGGER_EDGE_FALLING:
226 giu_set(GIUFEDGEINHL, mask);
227 giu_clear(GIUREDGEINHL, mask);
228 break;
229 case IRQ_TRIGGER_EDGE_RISING:
230 giu_clear(GIUFEDGEINHL, mask);
231 giu_set(GIUREDGEINHL, mask);
232 break;
233 default:
234 giu_set(GIUFEDGEINHL, mask);
235 giu_set(GIUREDGEINHL, mask);
236 break;
237 }
238 }
239 set_irq_chip_and_handler(GIU_IRQ(pin),
240 &giuint_low_irq_chip,
241 handle_edge_irq);
242 } else {
243 giu_clear(GIUINTTYPL, mask);
244 giu_clear(GIUINTHTSELL, mask);
245 set_irq_chip_and_handler(GIU_IRQ(pin),
246 &giuint_low_irq_chip,
247 handle_level_irq);
248 }
249 giu_write(GIUINTSTATL, mask);
250 } else if (pin < GIUINT_HIGH_MAX) {
251 mask = 1 << (pin - GIUINT_HIGH_OFFSET);
252 if (trigger != IRQ_TRIGGER_LEVEL) {
253 giu_set(GIUINTTYPH, mask);
254 if (signal == IRQ_SIGNAL_HOLD)
255 giu_set(GIUINTHTSELH, mask);
256 else
257 giu_clear(GIUINTHTSELH, mask);
258 if (giu_flags & GPIO_HAS_INTERRUPT_EDGE_SELECT) {
259 switch (trigger) {
260 case IRQ_TRIGGER_EDGE_FALLING:
261 giu_set(GIUFEDGEINHH, mask);
262 giu_clear(GIUREDGEINHH, mask);
263 break;
264 case IRQ_TRIGGER_EDGE_RISING:
265 giu_clear(GIUFEDGEINHH, mask);
266 giu_set(GIUREDGEINHH, mask);
267 break;
268 default:
269 giu_set(GIUFEDGEINHH, mask);
270 giu_set(GIUREDGEINHH, mask);
271 break;
272 }
273 }
274 set_irq_chip_and_handler(GIU_IRQ(pin),
275 &giuint_high_irq_chip,
276 handle_edge_irq);
277 } else {
278 giu_clear(GIUINTTYPH, mask);
279 giu_clear(GIUINTHTSELH, mask);
280 set_irq_chip_and_handler(GIU_IRQ(pin),
281 &giuint_high_irq_chip,
282 handle_level_irq);
283 }
284 giu_write(GIUINTSTATH, mask);
285 }
286}
287EXPORT_SYMBOL_GPL(vr41xx_set_irq_trigger);
288
289void vr41xx_set_irq_level(unsigned int pin, irq_level_t level)
290{
291 uint16_t mask;
292
293 if (pin < GIUINT_HIGH_OFFSET) {
294 mask = 1 << pin;
295 if (level == IRQ_LEVEL_HIGH)
296 giu_set(GIUINTALSELL, mask);
297 else
298 giu_clear(GIUINTALSELL, mask);
299 giu_write(GIUINTSTATL, mask);
300 } else if (pin < GIUINT_HIGH_MAX) {
301 mask = 1 << (pin - GIUINT_HIGH_OFFSET);
302 if (level == IRQ_LEVEL_HIGH)
303 giu_set(GIUINTALSELH, mask);
304 else
305 giu_clear(GIUINTALSELH, mask);
306 giu_write(GIUINTSTATH, mask);
307 }
308}
309EXPORT_SYMBOL_GPL(vr41xx_set_irq_level);
310
311gpio_data_t vr41xx_gpio_get_pin(unsigned int pin)
312{
313 uint16_t reg, mask;
314
315 if (pin >= giu_nr_pins)
316 return GPIO_DATA_INVAL;
317
318 if (pin < 16) {
319 reg = giu_read(GIUPIODL);
320 mask = (uint16_t)1 << pin;
321 } else if (pin < 32) {
322 reg = giu_read(GIUPIODH);
323 mask = (uint16_t)1 << (pin - 16);
324 } else if (pin < 48) {
325 reg = giu_read(GIUPODATL);
326 mask = (uint16_t)1 << (pin - 32);
327 } else {
328 reg = giu_read(GIUPODATH);
329 mask = (uint16_t)1 << (pin - 48);
330 }
331
332 if (reg & mask)
333 return GPIO_DATA_HIGH;
334
335 return GPIO_DATA_LOW;
336}
337EXPORT_SYMBOL_GPL(vr41xx_gpio_get_pin);
338
339int vr41xx_gpio_set_pin(unsigned int pin, gpio_data_t data)
340{
341 uint16_t offset, mask, reg;
342 unsigned long flags;
343
344 if (pin >= giu_nr_pins)
345 return -EINVAL;
346
347 if (pin < 16) {
348 offset = GIUPIODL;
349 mask = (uint16_t)1 << pin;
350 } else if (pin < 32) {
351 offset = GIUPIODH;
352 mask = (uint16_t)1 << (pin - 16);
353 } else if (pin < 48) {
354 offset = GIUPODATL;
355 mask = (uint16_t)1 << (pin - 32);
356 } else {
357 offset = GIUPODATH;
358 mask = (uint16_t)1 << (pin - 48);
359 }
360
361 spin_lock_irqsave(&giu_lock, flags);
362
363 reg = giu_read(offset);
364 if (data == GPIO_DATA_HIGH)
365 reg |= mask;
366 else
367 reg &= ~mask;
368 giu_write(offset, reg);
369
370 spin_unlock_irqrestore(&giu_lock, flags);
371
372 return 0;
373}
374EXPORT_SYMBOL_GPL(vr41xx_gpio_set_pin);
375
376int vr41xx_gpio_set_direction(unsigned int pin, gpio_direction_t dir)
377{
378 uint16_t offset, mask, reg;
379 unsigned long flags;
380
381 if (pin >= giu_nr_pins)
382 return -EINVAL;
383
384 if (pin < 16) {
385 offset = GIUIOSELL;
386 mask = (uint16_t)1 << pin;
387 } else if (pin < 32) {
388 offset = GIUIOSELH;
389 mask = (uint16_t)1 << (pin - 16);
390 } else {
391 if (giu_flags & GPIO_HAS_OUTPUT_ENABLE) {
392 offset = GIUPODATEN;
393 mask = (uint16_t)1 << (pin - 32);
394 } else {
395 switch (pin) {
396 case 48:
397 offset = GIUPODATH;
398 mask = PIOEN0;
399 break;
400 case 49:
401 offset = GIUPODATH;
402 mask = PIOEN1;
403 break;
404 default:
405 return -EINVAL;
406 }
407 }
408 }
409
410 spin_lock_irqsave(&giu_lock, flags);
411
412 reg = giu_read(offset);
413 if (dir == GPIO_OUTPUT)
414 reg |= mask;
415 else
416 reg &= ~mask;
417 giu_write(offset, reg);
418
419 spin_unlock_irqrestore(&giu_lock, flags);
420
421 return 0;
422}
423EXPORT_SYMBOL_GPL(vr41xx_gpio_set_direction);
424
425int vr41xx_gpio_pullupdown(unsigned int pin, gpio_pull_t pull)
426{
427 uint16_t reg, mask;
428 unsigned long flags;
429
430 if ((giu_flags & GPIO_HAS_PULLUPDOWN_IO) != GPIO_HAS_PULLUPDOWN_IO)
431 return -EPERM;
432
433 if (pin >= 15)
434 return -EINVAL;
435
436 mask = (uint16_t)1 << pin;
437
438 spin_lock_irqsave(&giu_lock, flags);
439
440 if (pull == GPIO_PULL_UP || pull == GPIO_PULL_DOWN) {
441 reg = giu_read(GIUTERMUPDN);
442 if (pull == GPIO_PULL_UP)
443 reg |= mask;
444 else
445 reg &= ~mask;
446 giu_write(GIUTERMUPDN, reg);
447
448 reg = giu_read(GIUUSEUPDN);
449 reg |= mask;
450 giu_write(GIUUSEUPDN, reg);
451 } else {
452 reg = giu_read(GIUUSEUPDN);
453 reg &= ~mask;
454 giu_write(GIUUSEUPDN, reg);
455 }
456
457 spin_unlock_irqrestore(&giu_lock, flags);
458
459 return 0;
460}
461EXPORT_SYMBOL_GPL(vr41xx_gpio_pullupdown);
462
463static ssize_t gpio_read(struct file *file, char __user *buf, size_t len,
464 loff_t *ppos)
465{
466 unsigned int pin;
467 char value = '0';
468
469 pin = iminor(file->f_path.dentry->d_inode);
470 if (pin >= giu_nr_pins)
471 return -EBADF;
472
473 if (vr41xx_gpio_get_pin(pin) == GPIO_DATA_HIGH)
474 value = '1';
475
476 if (len <= 0)
477 return -EFAULT;
478
479 if (put_user(value, buf))
480 return -EFAULT;
481
482 return 1;
483}
484
485static ssize_t gpio_write(struct file *file, const char __user *data,
486 size_t len, loff_t *ppos)
487{
488 unsigned int pin;
489 size_t i;
490 char c;
491 int retval = 0;
492
493 pin = iminor(file->f_path.dentry->d_inode);
494 if (pin >= giu_nr_pins)
495 return -EBADF;
496
497 for (i = 0; i < len; i++) {
498 if (get_user(c, data + i))
499 return -EFAULT;
500
501 switch (c) {
502 case '0':
503 retval = vr41xx_gpio_set_pin(pin, GPIO_DATA_LOW);
504 break;
505 case '1':
506 retval = vr41xx_gpio_set_pin(pin, GPIO_DATA_HIGH);
507 break;
508 case 'D':
509 printk(KERN_INFO "GPIO%d: pull down\n", pin);
510 retval = vr41xx_gpio_pullupdown(pin, GPIO_PULL_DOWN);
511 break;
512 case 'd':
513 printk(KERN_INFO "GPIO%d: pull up/down disable\n", pin);
514 retval = vr41xx_gpio_pullupdown(pin, GPIO_PULL_DISABLE);
515 break;
516 case 'I':
517 printk(KERN_INFO "GPIO%d: input\n", pin);
518 retval = vr41xx_gpio_set_direction(pin, GPIO_INPUT);
519 break;
520 case 'O':
521 printk(KERN_INFO "GPIO%d: output\n", pin);
522 retval = vr41xx_gpio_set_direction(pin, GPIO_OUTPUT);
523 break;
524 case 'o':
525 printk(KERN_INFO "GPIO%d: output disable\n", pin);
526 retval = vr41xx_gpio_set_direction(pin, GPIO_OUTPUT_DISABLE);
527 break;
528 case 'P':
529 printk(KERN_INFO "GPIO%d: pull up\n", pin);
530 retval = vr41xx_gpio_pullupdown(pin, GPIO_PULL_UP);
531 break;
532 case 'p':
533 printk(KERN_INFO "GPIO%d: pull up/down disable\n", pin);
534 retval = vr41xx_gpio_pullupdown(pin, GPIO_PULL_DISABLE);
535 break;
536 default:
537 break;
538 }
539
540 if (retval < 0)
541 break;
542 }
543
544 return i;
545}
546
547static int gpio_open(struct inode *inode, struct file *file)
548{
549 unsigned int pin;
550
551 cycle_kernel_lock();
552 pin = iminor(inode);
553 if (pin >= giu_nr_pins)
554 return -EBADF;
555
556 return nonseekable_open(inode, file);
557}
558
559static int gpio_release(struct inode *inode, struct file *file)
560{
561 unsigned int pin;
562
563 pin = iminor(inode);
564 if (pin >= giu_nr_pins)
565 return -EBADF;
566
567 return 0;
568}
569
570static const struct file_operations gpio_fops = {
571 .owner = THIS_MODULE,
572 .read = gpio_read,
573 .write = gpio_write,
574 .open = gpio_open,
575 .release = gpio_release,
576};
577
578static int __devinit giu_probe(struct platform_device *dev)
579{
580 struct resource *res;
581 unsigned int trigger, i, pin;
582 struct irq_chip *chip;
583 int irq, retval;
584
585 switch (dev->id) {
586 case GPIO_50PINS_PULLUPDOWN:
587 giu_flags = GPIO_HAS_PULLUPDOWN_IO;
588 giu_nr_pins = 50;
589 break;
590 case GPIO_36PINS:
591 giu_nr_pins = 36;
592 break;
593 case GPIO_48PINS_EDGE_SELECT:
594 giu_flags = GPIO_HAS_INTERRUPT_EDGE_SELECT;
595 giu_nr_pins = 48;
596 break;
597 default:
598 printk(KERN_ERR "GIU: unknown ID %d\n", dev->id);
599 return -ENODEV;
600 }
601
602 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
603 if (!res)
604 return -EBUSY;
605
606 giu_base = ioremap(res->start, res->end - res->start + 1);
607 if (!giu_base)
608 return -ENOMEM;
609
610 retval = register_chrdev(major, "GIU", &gpio_fops);
611 if (retval < 0) {
612 iounmap(giu_base);
613 giu_base = NULL;
614 return retval;
615 }
616
617 if (major == 0) {
618 major = retval;
619 printk(KERN_INFO "GIU: major number %d\n", major);
620 }
621
622 spin_lock_init(&giu_lock);
623
624 giu_write(GIUINTENL, 0);
625 giu_write(GIUINTENH, 0);
626
627 trigger = giu_read(GIUINTTYPH) << 16;
628 trigger |= giu_read(GIUINTTYPL);
629 for (i = GIU_IRQ_BASE; i <= GIU_IRQ_LAST; i++) {
630 pin = GPIO_PIN_OF_IRQ(i);
631 if (pin < GIUINT_HIGH_OFFSET)
632 chip = &giuint_low_irq_chip;
633 else
634 chip = &giuint_high_irq_chip;
635
636 if (trigger & (1 << pin))
637 set_irq_chip_and_handler(i, chip, handle_edge_irq);
638 else
639 set_irq_chip_and_handler(i, chip, handle_level_irq);
640
641 }
642
643 irq = platform_get_irq(dev, 0);
644 if (irq < 0 || irq >= nr_irqs)
645 return -EBUSY;
646
647 return cascade_irq(irq, giu_get_irq);
648}
649
650static int __devexit giu_remove(struct platform_device *dev)
651{
652 if (giu_base) {
653 iounmap(giu_base);
654 giu_base = NULL;
655 }
656
657 return 0;
658}
659
660static struct platform_driver giu_device_driver = {
661 .probe = giu_probe,
662 .remove = __devexit_p(giu_remove),
663 .driver = {
664 .name = "GIU",
665 .owner = THIS_MODULE,
666 },
667};
668
669static int __init vr41xx_giu_init(void)
670{
671 return platform_driver_register(&giu_device_driver);
672}
673
674static void __exit vr41xx_giu_exit(void)
675{
676 platform_driver_unregister(&giu_device_driver);
677}
678
679module_init(vr41xx_giu_init);
680module_exit(vr41xx_giu_exit);
diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
index 9ffb05f4095d..93c2322feab7 100644
--- a/drivers/clocksource/sh_tmu.c
+++ b/drivers/clocksource/sh_tmu.c
@@ -161,7 +161,7 @@ static void sh_tmu_set_next(struct sh_tmu_priv *p, unsigned long delta,
161 if (periodic) 161 if (periodic)
162 sh_tmu_write(p, TCOR, delta); 162 sh_tmu_write(p, TCOR, delta);
163 else 163 else
164 sh_tmu_write(p, TCOR, 0); 164 sh_tmu_write(p, TCOR, 0xffffffff);
165 165
166 sh_tmu_write(p, TCNT, delta); 166 sh_tmu_write(p, TCNT, delta);
167 167
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index c36bf40568cf..858fe6037223 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -754,13 +754,13 @@ static void amd64_cpu_display_info(struct amd64_pvt *pvt)
754static enum edac_type amd64_determine_edac_cap(struct amd64_pvt *pvt) 754static enum edac_type amd64_determine_edac_cap(struct amd64_pvt *pvt)
755{ 755{
756 int bit; 756 int bit;
757 enum dev_type edac_cap = EDAC_NONE; 757 enum dev_type edac_cap = EDAC_FLAG_NONE;
758 758
759 bit = (boot_cpu_data.x86 > 0xf || pvt->ext_model >= OPTERON_CPU_REV_F) 759 bit = (boot_cpu_data.x86 > 0xf || pvt->ext_model >= OPTERON_CPU_REV_F)
760 ? 19 760 ? 19
761 : 17; 761 : 17;
762 762
763 if (pvt->dclr0 >> BIT(bit)) 763 if (pvt->dclr0 & BIT(bit))
764 edac_cap = EDAC_FLAG_SECDED; 764 edac_cap = EDAC_FLAG_SECDED;
765 765
766 return edac_cap; 766 return edac_cap;
@@ -1269,7 +1269,7 @@ static int f10_early_channel_count(struct amd64_pvt *pvt)
1269 if (channels == 0) 1269 if (channels == 0)
1270 channels = 1; 1270 channels = 1;
1271 1271
1272 debugf0("DIMM count= %d\n", channels); 1272 debugf0("MCT channel count: %d\n", channels);
1273 1273
1274 return channels; 1274 return channels;
1275 1275
@@ -2966,7 +2966,12 @@ static int amd64_check_ecc_enabled(struct amd64_pvt *pvt)
2966 " Use of the override can cause " 2966 " Use of the override can cause "
2967 "unknown side effects.\n"); 2967 "unknown side effects.\n");
2968 ret = -ENODEV; 2968 ret = -ENODEV;
2969 } 2969 } else
2970 /*
2971 * enable further driver loading if ECC enable is
2972 * overridden.
2973 */
2974 ret = 0;
2970 } else { 2975 } else {
2971 amd64_printk(KERN_INFO, 2976 amd64_printk(KERN_INFO,
2972 "ECC is enabled by BIOS, Proceeding " 2977 "ECC is enabled by BIOS, Proceeding "
@@ -3006,7 +3011,6 @@ static void amd64_setup_mci_misc_attributes(struct mem_ctl_info *mci)
3006 3011
3007 mci->mtype_cap = MEM_FLAG_DDR2 | MEM_FLAG_RDDR2; 3012 mci->mtype_cap = MEM_FLAG_DDR2 | MEM_FLAG_RDDR2;
3008 mci->edac_ctl_cap = EDAC_FLAG_NONE; 3013 mci->edac_ctl_cap = EDAC_FLAG_NONE;
3009 mci->edac_cap = EDAC_FLAG_NONE;
3010 3014
3011 if (pvt->nbcap & K8_NBCAP_SECDED) 3015 if (pvt->nbcap & K8_NBCAP_SECDED)
3012 mci->edac_ctl_cap |= EDAC_FLAG_SECDED; 3016 mci->edac_ctl_cap |= EDAC_FLAG_SECDED;
@@ -3052,7 +3056,7 @@ static int amd64_probe_one_instance(struct pci_dev *dram_f2_ctl,
3052 if (!pvt) 3056 if (!pvt)
3053 goto err_exit; 3057 goto err_exit;
3054 3058
3055 pvt->mc_node_id = get_mc_node_id_from_pdev(dram_f2_ctl); 3059 pvt->mc_node_id = get_node_id(dram_f2_ctl);
3056 3060
3057 pvt->dram_f2_ctl = dram_f2_ctl; 3061 pvt->dram_f2_ctl = dram_f2_ctl;
3058 pvt->ext_model = boot_cpu_data.x86_model >> 4; 3062 pvt->ext_model = boot_cpu_data.x86_model >> 4;
@@ -3179,8 +3183,7 @@ static int __devinit amd64_init_one_instance(struct pci_dev *pdev,
3179{ 3183{
3180 int ret = 0; 3184 int ret = 0;
3181 3185
3182 debugf0("(MC node=%d,mc_type='%s')\n", 3186 debugf0("(MC node=%d,mc_type='%s')\n", get_node_id(pdev),
3183 get_mc_node_id_from_pdev(pdev),
3184 get_amd_family_name(mc_type->driver_data)); 3187 get_amd_family_name(mc_type->driver_data));
3185 3188
3186 ret = pci_enable_device(pdev); 3189 ret = pci_enable_device(pdev);
@@ -3319,15 +3322,17 @@ static int __init amd64_edac_init(void)
3319 3322
3320 err = amd64_init_2nd_stage(pvt_lookup[nb]); 3323 err = amd64_init_2nd_stage(pvt_lookup[nb]);
3321 if (err) 3324 if (err)
3322 goto err_exit; 3325 goto err_2nd_stage;
3323 } 3326 }
3324 3327
3325 amd64_setup_pci_device(); 3328 amd64_setup_pci_device();
3326 3329
3327 return 0; 3330 return 0;
3328 3331
3332err_2nd_stage:
3333 debugf0("2nd stage failed\n");
3334
3329err_exit: 3335err_exit:
3330 debugf0("'finish_setup' stage failed\n");
3331 pci_unregister_driver(&amd64_pci_driver); 3336 pci_unregister_driver(&amd64_pci_driver);
3332 3337
3333 return err; 3338 return err;
diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h
index a159957e167b..ba73015af8e4 100644
--- a/drivers/edac/amd64_edac.h
+++ b/drivers/edac/amd64_edac.h
@@ -444,7 +444,7 @@ enum {
444#define K8_MSR_MC4ADDR 0x0412 444#define K8_MSR_MC4ADDR 0x0412
445 445
446/* AMD sets the first MC device at device ID 0x18. */ 446/* AMD sets the first MC device at device ID 0x18. */
447static inline int get_mc_node_id_from_pdev(struct pci_dev *pdev) 447static inline int get_node_id(struct pci_dev *pdev)
448{ 448{
449 return PCI_SLOT(pdev->devfn) - 0x18; 449 return PCI_SLOT(pdev->devfn) - 0x18;
450} 450}
diff --git a/drivers/edac/edac_core.h b/drivers/edac/edac_core.h
index 3493c6bdb820..871c13b4c148 100644
--- a/drivers/edac/edac_core.h
+++ b/drivers/edac/edac_core.h
@@ -150,6 +150,8 @@ enum mem_type {
150 MEM_FB_DDR2, /* fully buffered DDR2 */ 150 MEM_FB_DDR2, /* fully buffered DDR2 */
151 MEM_RDDR2, /* Registered DDR2 RAM */ 151 MEM_RDDR2, /* Registered DDR2 RAM */
152 MEM_XDR, /* Rambus XDR */ 152 MEM_XDR, /* Rambus XDR */
153 MEM_DDR3, /* DDR3 RAM */
154 MEM_RDDR3, /* Registered DDR3 RAM */
153}; 155};
154 156
155#define MEM_FLAG_EMPTY BIT(MEM_EMPTY) 157#define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
@@ -167,6 +169,8 @@ enum mem_type {
167#define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2) 169#define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
168#define MEM_FLAG_RDDR2 BIT(MEM_RDDR2) 170#define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
169#define MEM_FLAG_XDR BIT(MEM_XDR) 171#define MEM_FLAG_XDR BIT(MEM_XDR)
172#define MEM_FLAG_DDR3 BIT(MEM_DDR3)
173#define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
170 174
171/* chipset Error Detection and Correction capabilities and mode */ 175/* chipset Error Detection and Correction capabilities and mode */
172enum edac_type { 176enum edac_type {
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index ad218fe4942d..e1d4ce083481 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -94,7 +94,9 @@ static const char *mem_types[] = {
94 [MEM_DDR2] = "Unbuffered-DDR2", 94 [MEM_DDR2] = "Unbuffered-DDR2",
95 [MEM_FB_DDR2] = "FullyBuffered-DDR2", 95 [MEM_FB_DDR2] = "FullyBuffered-DDR2",
96 [MEM_RDDR2] = "Registered-DDR2", 96 [MEM_RDDR2] = "Registered-DDR2",
97 [MEM_XDR] = "XDR" 97 [MEM_XDR] = "XDR",
98 [MEM_DDR3] = "Unbuffered-DDR3",
99 [MEM_RDDR3] = "Registered-DDR3"
98}; 100};
99 101
100static const char *dev_types[] = { 102static const char *dev_types[] = {
diff --git a/drivers/edac/mpc85xx_edac.c b/drivers/edac/mpc85xx_edac.c
index 7c8c2d72916f..3f2ccfc6407c 100644
--- a/drivers/edac/mpc85xx_edac.c
+++ b/drivers/edac/mpc85xx_edac.c
@@ -757,6 +757,9 @@ static void __devinit mpc85xx_init_csrows(struct mem_ctl_info *mci)
757 case DSC_SDTYPE_DDR2: 757 case DSC_SDTYPE_DDR2:
758 mtype = MEM_RDDR2; 758 mtype = MEM_RDDR2;
759 break; 759 break;
760 case DSC_SDTYPE_DDR3:
761 mtype = MEM_RDDR3;
762 break;
760 default: 763 default:
761 mtype = MEM_UNKNOWN; 764 mtype = MEM_UNKNOWN;
762 break; 765 break;
@@ -769,6 +772,9 @@ static void __devinit mpc85xx_init_csrows(struct mem_ctl_info *mci)
769 case DSC_SDTYPE_DDR2: 772 case DSC_SDTYPE_DDR2:
770 mtype = MEM_DDR2; 773 mtype = MEM_DDR2;
771 break; 774 break;
775 case DSC_SDTYPE_DDR3:
776 mtype = MEM_DDR3;
777 break;
772 default: 778 default:
773 mtype = MEM_UNKNOWN; 779 mtype = MEM_UNKNOWN;
774 break; 780 break;
diff --git a/drivers/edac/mpc85xx_edac.h b/drivers/edac/mpc85xx_edac.h
index 135b3539a030..52432ee7c4b9 100644
--- a/drivers/edac/mpc85xx_edac.h
+++ b/drivers/edac/mpc85xx_edac.h
@@ -53,6 +53,7 @@
53 53
54#define DSC_SDTYPE_DDR 0x02000000 54#define DSC_SDTYPE_DDR 0x02000000
55#define DSC_SDTYPE_DDR2 0x03000000 55#define DSC_SDTYPE_DDR2 0x03000000
56#define DSC_SDTYPE_DDR3 0x07000000
56#define DSC_X32_EN 0x00000020 57#define DSC_X32_EN 0x00000020
57 58
58/* Err_Int_En */ 59/* Err_Int_En */
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 3582c39f9725..96dda81c9228 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -79,6 +79,12 @@ config GPIO_XILINX
79 help 79 help
80 Say yes here to support the Xilinx FPGA GPIO device 80 Say yes here to support the Xilinx FPGA GPIO device
81 81
82config GPIO_VR41XX
83 tristate "NEC VR4100 series General-purpose I/O Uint support"
84 depends on CPU_VR41XX
85 help
86 Say yes here to support the NEC VR4100 series General-purpose I/O Uint
87
82comment "I2C GPIO expanders:" 88comment "I2C GPIO expanders:"
83 89
84config GPIO_MAX732X 90config GPIO_MAX732X
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index ef90203e8f3c..9244c6fcd8be 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -13,3 +13,4 @@ obj-$(CONFIG_GPIO_PL061) += pl061.o
13obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o 13obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o
14obj-$(CONFIG_GPIO_XILINX) += xilinx_gpio.o 14obj-$(CONFIG_GPIO_XILINX) += xilinx_gpio.o
15obj-$(CONFIG_GPIO_BT8XX) += bt8xxgpio.o 15obj-$(CONFIG_GPIO_BT8XX) += bt8xxgpio.o
16obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o
diff --git a/drivers/gpio/pl061.c b/drivers/gpio/pl061.c
index aa8e7cb020d9..4ee4c8367a3f 100644
--- a/drivers/gpio/pl061.c
+++ b/drivers/gpio/pl061.c
@@ -109,6 +109,16 @@ static void pl061_set_value(struct gpio_chip *gc, unsigned offset, int value)
109 writeb(!!value << offset, chip->base + (1 << (offset + 2))); 109 writeb(!!value << offset, chip->base + (1 << (offset + 2)));
110} 110}
111 111
112static int pl061_to_irq(struct gpio_chip *gc, unsigned offset)
113{
114 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
115
116 if (chip->irq_base == (unsigned) -1)
117 return -EINVAL;
118
119 return chip->irq_base + offset;
120}
121
112/* 122/*
113 * PL061 GPIO IRQ 123 * PL061 GPIO IRQ
114 */ 124 */
@@ -200,7 +210,7 @@ static void pl061_irq_handler(unsigned irq, struct irq_desc *desc)
200 desc->chip->ack(irq); 210 desc->chip->ack(irq);
201 list_for_each(ptr, chip_list) { 211 list_for_each(ptr, chip_list) {
202 unsigned long pending; 212 unsigned long pending;
203 int gpio; 213 int offset;
204 214
205 chip = list_entry(ptr, struct pl061_gpio, list); 215 chip = list_entry(ptr, struct pl061_gpio, list);
206 pending = readb(chip->base + GPIOMIS); 216 pending = readb(chip->base + GPIOMIS);
@@ -209,8 +219,8 @@ static void pl061_irq_handler(unsigned irq, struct irq_desc *desc)
209 if (pending == 0) 219 if (pending == 0)
210 continue; 220 continue;
211 221
212 for_each_bit(gpio, &pending, PL061_GPIO_NR) 222 for_each_bit(offset, &pending, PL061_GPIO_NR)
213 generic_handle_irq(gpio_to_irq(gpio)); 223 generic_handle_irq(pl061_to_irq(&chip->gc, offset));
214 } 224 }
215 desc->chip->unmask(irq); 225 desc->chip->unmask(irq);
216} 226}
@@ -221,7 +231,7 @@ static int __init pl061_probe(struct amba_device *dev, struct amba_id *id)
221 struct pl061_gpio *chip; 231 struct pl061_gpio *chip;
222 struct list_head *chip_list; 232 struct list_head *chip_list;
223 int ret, irq, i; 233 int ret, irq, i;
224 static unsigned long init_irq[BITS_TO_LONGS(NR_IRQS)]; 234 static DECLARE_BITMAP(init_irq, NR_IRQS);
225 235
226 pdata = dev->dev.platform_data; 236 pdata = dev->dev.platform_data;
227 if (pdata == NULL) 237 if (pdata == NULL)
@@ -251,6 +261,7 @@ static int __init pl061_probe(struct amba_device *dev, struct amba_id *id)
251 chip->gc.direction_output = pl061_direction_output; 261 chip->gc.direction_output = pl061_direction_output;
252 chip->gc.get = pl061_get_value; 262 chip->gc.get = pl061_get_value;
253 chip->gc.set = pl061_set_value; 263 chip->gc.set = pl061_set_value;
264 chip->gc.to_irq = pl061_to_irq;
254 chip->gc.base = pdata->gpio_base; 265 chip->gc.base = pdata->gpio_base;
255 chip->gc.ngpio = PL061_GPIO_NR; 266 chip->gc.ngpio = PL061_GPIO_NR;
256 chip->gc.label = dev_name(&dev->dev); 267 chip->gc.label = dev_name(&dev->dev);
@@ -280,6 +291,7 @@ static int __init pl061_probe(struct amba_device *dev, struct amba_id *id)
280 if (!test_and_set_bit(irq, init_irq)) { /* list initialized? */ 291 if (!test_and_set_bit(irq, init_irq)) { /* list initialized? */
281 chip_list = kmalloc(sizeof(*chip_list), GFP_KERNEL); 292 chip_list = kmalloc(sizeof(*chip_list), GFP_KERNEL);
282 if (chip_list == NULL) { 293 if (chip_list == NULL) {
294 clear_bit(irq, init_irq);
283 ret = -ENOMEM; 295 ret = -ENOMEM;
284 goto iounmap; 296 goto iounmap;
285 } 297 }
diff --git a/drivers/gpio/vr41xx_giu.c b/drivers/gpio/vr41xx_giu.c
new file mode 100644
index 000000000000..b70e06133e78
--- /dev/null
+++ b/drivers/gpio/vr41xx_giu.c
@@ -0,0 +1,586 @@
1/*
2 * Driver for NEC VR4100 series General-purpose I/O Unit.
3 *
4 * Copyright (C) 2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <source@mvista.com>
6 * Copyright (C) 2003-2009 Yoichi Yuasa <yuasa@linux-mips.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22#include <linux/errno.h>
23#include <linux/fs.h>
24#include <linux/gpio.h>
25#include <linux/init.h>
26#include <linux/interrupt.h>
27#include <linux/io.h>
28#include <linux/irq.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/platform_device.h>
32#include <linux/smp_lock.h>
33#include <linux/spinlock.h>
34#include <linux/types.h>
35
36#include <asm/vr41xx/giu.h>
37#include <asm/vr41xx/irq.h>
38#include <asm/vr41xx/vr41xx.h>
39
40MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
41MODULE_DESCRIPTION("NEC VR4100 series General-purpose I/O Unit driver");
42MODULE_LICENSE("GPL");
43
44#define GIUIOSELL 0x00
45#define GIUIOSELH 0x02
46#define GIUPIODL 0x04
47#define GIUPIODH 0x06
48#define GIUINTSTATL 0x08
49#define GIUINTSTATH 0x0a
50#define GIUINTENL 0x0c
51#define GIUINTENH 0x0e
52#define GIUINTTYPL 0x10
53#define GIUINTTYPH 0x12
54#define GIUINTALSELL 0x14
55#define GIUINTALSELH 0x16
56#define GIUINTHTSELL 0x18
57#define GIUINTHTSELH 0x1a
58#define GIUPODATL 0x1c
59#define GIUPODATEN 0x1c
60#define GIUPODATH 0x1e
61 #define PIOEN0 0x0100
62 #define PIOEN1 0x0200
63#define GIUPODAT 0x1e
64#define GIUFEDGEINHL 0x20
65#define GIUFEDGEINHH 0x22
66#define GIUREDGEINHL 0x24
67#define GIUREDGEINHH 0x26
68
69#define GIUUSEUPDN 0x1e0
70#define GIUTERMUPDN 0x1e2
71
72#define GPIO_HAS_PULLUPDOWN_IO 0x0001
73#define GPIO_HAS_OUTPUT_ENABLE 0x0002
74#define GPIO_HAS_INTERRUPT_EDGE_SELECT 0x0100
75
76enum {
77 GPIO_INPUT,
78 GPIO_OUTPUT,
79};
80
81static DEFINE_SPINLOCK(giu_lock);
82static unsigned long giu_flags;
83
84static void __iomem *giu_base;
85
86#define giu_read(offset) readw(giu_base + (offset))
87#define giu_write(offset, value) writew((value), giu_base + (offset))
88
89#define GPIO_PIN_OF_IRQ(irq) ((irq) - GIU_IRQ_BASE)
90#define GIUINT_HIGH_OFFSET 16
91#define GIUINT_HIGH_MAX 32
92
93static inline u16 giu_set(u16 offset, u16 set)
94{
95 u16 data;
96
97 data = giu_read(offset);
98 data |= set;
99 giu_write(offset, data);
100
101 return data;
102}
103
104static inline u16 giu_clear(u16 offset, u16 clear)
105{
106 u16 data;
107
108 data = giu_read(offset);
109 data &= ~clear;
110 giu_write(offset, data);
111
112 return data;
113}
114
115static void ack_giuint_low(unsigned int irq)
116{
117 giu_write(GIUINTSTATL, 1 << GPIO_PIN_OF_IRQ(irq));
118}
119
120static void mask_giuint_low(unsigned int irq)
121{
122 giu_clear(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
123}
124
125static void mask_ack_giuint_low(unsigned int irq)
126{
127 unsigned int pin;
128
129 pin = GPIO_PIN_OF_IRQ(irq);
130 giu_clear(GIUINTENL, 1 << pin);
131 giu_write(GIUINTSTATL, 1 << pin);
132}
133
134static void unmask_giuint_low(unsigned int irq)
135{
136 giu_set(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
137}
138
139static struct irq_chip giuint_low_irq_chip = {
140 .name = "GIUINTL",
141 .ack = ack_giuint_low,
142 .mask = mask_giuint_low,
143 .mask_ack = mask_ack_giuint_low,
144 .unmask = unmask_giuint_low,
145};
146
147static void ack_giuint_high(unsigned int irq)
148{
149 giu_write(GIUINTSTATH,
150 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
151}
152
153static void mask_giuint_high(unsigned int irq)
154{
155 giu_clear(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
156}
157
158static void mask_ack_giuint_high(unsigned int irq)
159{
160 unsigned int pin;
161
162 pin = GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET;
163 giu_clear(GIUINTENH, 1 << pin);
164 giu_write(GIUINTSTATH, 1 << pin);
165}
166
167static void unmask_giuint_high(unsigned int irq)
168{
169 giu_set(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
170}
171
172static struct irq_chip giuint_high_irq_chip = {
173 .name = "GIUINTH",
174 .ack = ack_giuint_high,
175 .mask = mask_giuint_high,
176 .mask_ack = mask_ack_giuint_high,
177 .unmask = unmask_giuint_high,
178};
179
180static int giu_get_irq(unsigned int irq)
181{
182 u16 pendl, pendh, maskl, maskh;
183 int i;
184
185 pendl = giu_read(GIUINTSTATL);
186 pendh = giu_read(GIUINTSTATH);
187 maskl = giu_read(GIUINTENL);
188 maskh = giu_read(GIUINTENH);
189
190 maskl &= pendl;
191 maskh &= pendh;
192
193 if (maskl) {
194 for (i = 0; i < 16; i++) {
195 if (maskl & (1 << i))
196 return GIU_IRQ(i);
197 }
198 } else if (maskh) {
199 for (i = 0; i < 16; i++) {
200 if (maskh & (1 << i))
201 return GIU_IRQ(i + GIUINT_HIGH_OFFSET);
202 }
203 }
204
205 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
206 maskl, pendl, maskh, pendh);
207
208 atomic_inc(&irq_err_count);
209
210 return -EINVAL;
211}
212
213void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger,
214 irq_signal_t signal)
215{
216 u16 mask;
217
218 if (pin < GIUINT_HIGH_OFFSET) {
219 mask = 1 << pin;
220 if (trigger != IRQ_TRIGGER_LEVEL) {
221 giu_set(GIUINTTYPL, mask);
222 if (signal == IRQ_SIGNAL_HOLD)
223 giu_set(GIUINTHTSELL, mask);
224 else
225 giu_clear(GIUINTHTSELL, mask);
226 if (giu_flags & GPIO_HAS_INTERRUPT_EDGE_SELECT) {
227 switch (trigger) {
228 case IRQ_TRIGGER_EDGE_FALLING:
229 giu_set(GIUFEDGEINHL, mask);
230 giu_clear(GIUREDGEINHL, mask);
231 break;
232 case IRQ_TRIGGER_EDGE_RISING:
233 giu_clear(GIUFEDGEINHL, mask);
234 giu_set(GIUREDGEINHL, mask);
235 break;
236 default:
237 giu_set(GIUFEDGEINHL, mask);
238 giu_set(GIUREDGEINHL, mask);
239 break;
240 }
241 }
242 set_irq_chip_and_handler(GIU_IRQ(pin),
243 &giuint_low_irq_chip,
244 handle_edge_irq);
245 } else {
246 giu_clear(GIUINTTYPL, mask);
247 giu_clear(GIUINTHTSELL, mask);
248 set_irq_chip_and_handler(GIU_IRQ(pin),
249 &giuint_low_irq_chip,
250 handle_level_irq);
251 }
252 giu_write(GIUINTSTATL, mask);
253 } else if (pin < GIUINT_HIGH_MAX) {
254 mask = 1 << (pin - GIUINT_HIGH_OFFSET);
255 if (trigger != IRQ_TRIGGER_LEVEL) {
256 giu_set(GIUINTTYPH, mask);
257 if (signal == IRQ_SIGNAL_HOLD)
258 giu_set(GIUINTHTSELH, mask);
259 else
260 giu_clear(GIUINTHTSELH, mask);
261 if (giu_flags & GPIO_HAS_INTERRUPT_EDGE_SELECT) {
262 switch (trigger) {
263 case IRQ_TRIGGER_EDGE_FALLING:
264 giu_set(GIUFEDGEINHH, mask);
265 giu_clear(GIUREDGEINHH, mask);
266 break;
267 case IRQ_TRIGGER_EDGE_RISING:
268 giu_clear(GIUFEDGEINHH, mask);
269 giu_set(GIUREDGEINHH, mask);
270 break;
271 default:
272 giu_set(GIUFEDGEINHH, mask);
273 giu_set(GIUREDGEINHH, mask);
274 break;
275 }
276 }
277 set_irq_chip_and_handler(GIU_IRQ(pin),
278 &giuint_high_irq_chip,
279 handle_edge_irq);
280 } else {
281 giu_clear(GIUINTTYPH, mask);
282 giu_clear(GIUINTHTSELH, mask);
283 set_irq_chip_and_handler(GIU_IRQ(pin),
284 &giuint_high_irq_chip,
285 handle_level_irq);
286 }
287 giu_write(GIUINTSTATH, mask);
288 }
289}
290EXPORT_SYMBOL_GPL(vr41xx_set_irq_trigger);
291
292void vr41xx_set_irq_level(unsigned int pin, irq_level_t level)
293{
294 u16 mask;
295
296 if (pin < GIUINT_HIGH_OFFSET) {
297 mask = 1 << pin;
298 if (level == IRQ_LEVEL_HIGH)
299 giu_set(GIUINTALSELL, mask);
300 else
301 giu_clear(GIUINTALSELL, mask);
302 giu_write(GIUINTSTATL, mask);
303 } else if (pin < GIUINT_HIGH_MAX) {
304 mask = 1 << (pin - GIUINT_HIGH_OFFSET);
305 if (level == IRQ_LEVEL_HIGH)
306 giu_set(GIUINTALSELH, mask);
307 else
308 giu_clear(GIUINTALSELH, mask);
309 giu_write(GIUINTSTATH, mask);
310 }
311}
312EXPORT_SYMBOL_GPL(vr41xx_set_irq_level);
313
314static int giu_set_direction(struct gpio_chip *chip, unsigned pin, int dir)
315{
316 u16 offset, mask, reg;
317 unsigned long flags;
318
319 if (pin >= chip->ngpio)
320 return -EINVAL;
321
322 if (pin < 16) {
323 offset = GIUIOSELL;
324 mask = 1 << pin;
325 } else if (pin < 32) {
326 offset = GIUIOSELH;
327 mask = 1 << (pin - 16);
328 } else {
329 if (giu_flags & GPIO_HAS_OUTPUT_ENABLE) {
330 offset = GIUPODATEN;
331 mask = 1 << (pin - 32);
332 } else {
333 switch (pin) {
334 case 48:
335 offset = GIUPODATH;
336 mask = PIOEN0;
337 break;
338 case 49:
339 offset = GIUPODATH;
340 mask = PIOEN1;
341 break;
342 default:
343 return -EINVAL;
344 }
345 }
346 }
347
348 spin_lock_irqsave(&giu_lock, flags);
349
350 reg = giu_read(offset);
351 if (dir == GPIO_OUTPUT)
352 reg |= mask;
353 else
354 reg &= ~mask;
355 giu_write(offset, reg);
356
357 spin_unlock_irqrestore(&giu_lock, flags);
358
359 return 0;
360}
361
362int vr41xx_gpio_pullupdown(unsigned int pin, gpio_pull_t pull)
363{
364 u16 reg, mask;
365 unsigned long flags;
366
367 if ((giu_flags & GPIO_HAS_PULLUPDOWN_IO) != GPIO_HAS_PULLUPDOWN_IO)
368 return -EPERM;
369
370 if (pin >= 15)
371 return -EINVAL;
372
373 mask = 1 << pin;
374
375 spin_lock_irqsave(&giu_lock, flags);
376
377 if (pull == GPIO_PULL_UP || pull == GPIO_PULL_DOWN) {
378 reg = giu_read(GIUTERMUPDN);
379 if (pull == GPIO_PULL_UP)
380 reg |= mask;
381 else
382 reg &= ~mask;
383 giu_write(GIUTERMUPDN, reg);
384
385 reg = giu_read(GIUUSEUPDN);
386 reg |= mask;
387 giu_write(GIUUSEUPDN, reg);
388 } else {
389 reg = giu_read(GIUUSEUPDN);
390 reg &= ~mask;
391 giu_write(GIUUSEUPDN, reg);
392 }
393
394 spin_unlock_irqrestore(&giu_lock, flags);
395
396 return 0;
397}
398EXPORT_SYMBOL_GPL(vr41xx_gpio_pullupdown);
399
400static int vr41xx_gpio_get(struct gpio_chip *chip, unsigned pin)
401{
402 u16 reg, mask;
403
404 if (pin >= chip->ngpio)
405 return -EINVAL;
406
407 if (pin < 16) {
408 reg = giu_read(GIUPIODL);
409 mask = 1 << pin;
410 } else if (pin < 32) {
411 reg = giu_read(GIUPIODH);
412 mask = 1 << (pin - 16);
413 } else if (pin < 48) {
414 reg = giu_read(GIUPODATL);
415 mask = 1 << (pin - 32);
416 } else {
417 reg = giu_read(GIUPODATH);
418 mask = 1 << (pin - 48);
419 }
420
421 if (reg & mask)
422 return 1;
423
424 return 0;
425}
426
427static void vr41xx_gpio_set(struct gpio_chip *chip, unsigned pin,
428 int value)
429{
430 u16 offset, mask, reg;
431 unsigned long flags;
432
433 if (pin >= chip->ngpio)
434 return;
435
436 if (pin < 16) {
437 offset = GIUPIODL;
438 mask = 1 << pin;
439 } else if (pin < 32) {
440 offset = GIUPIODH;
441 mask = 1 << (pin - 16);
442 } else if (pin < 48) {
443 offset = GIUPODATL;
444 mask = 1 << (pin - 32);
445 } else {
446 offset = GIUPODATH;
447 mask = 1 << (pin - 48);
448 }
449
450 spin_lock_irqsave(&giu_lock, flags);
451
452 reg = giu_read(offset);
453 if (value)
454 reg |= mask;
455 else
456 reg &= ~mask;
457 giu_write(offset, reg);
458
459 spin_unlock_irqrestore(&giu_lock, flags);
460}
461
462
463static int vr41xx_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
464{
465 return giu_set_direction(chip, offset, GPIO_INPUT);
466}
467
468static int vr41xx_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
469 int value)
470{
471 vr41xx_gpio_set(chip, offset, value);
472
473 return giu_set_direction(chip, offset, GPIO_OUTPUT);
474}
475
476static int vr41xx_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
477{
478 if (offset >= chip->ngpio)
479 return -EINVAL;
480
481 return GIU_IRQ_BASE + offset;
482}
483
484static struct gpio_chip vr41xx_gpio_chip = {
485 .label = "vr41xx",
486 .owner = THIS_MODULE,
487 .direction_input = vr41xx_gpio_direction_input,
488 .get = vr41xx_gpio_get,
489 .direction_output = vr41xx_gpio_direction_output,
490 .set = vr41xx_gpio_set,
491 .to_irq = vr41xx_gpio_to_irq,
492};
493
494static int __devinit giu_probe(struct platform_device *pdev)
495{
496 struct resource *res;
497 unsigned int trigger, i, pin;
498 struct irq_chip *chip;
499 int irq, retval;
500
501 switch (pdev->id) {
502 case GPIO_50PINS_PULLUPDOWN:
503 giu_flags = GPIO_HAS_PULLUPDOWN_IO;
504 vr41xx_gpio_chip.ngpio = 50;
505 break;
506 case GPIO_36PINS:
507 vr41xx_gpio_chip.ngpio = 36;
508 break;
509 case GPIO_48PINS_EDGE_SELECT:
510 giu_flags = GPIO_HAS_INTERRUPT_EDGE_SELECT;
511 vr41xx_gpio_chip.ngpio = 48;
512 break;
513 default:
514 dev_err(&pdev->dev, "GIU: unknown ID %d\n", pdev->id);
515 return -ENODEV;
516 }
517
518 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
519 if (!res)
520 return -EBUSY;
521
522 giu_base = ioremap(res->start, res->end - res->start + 1);
523 if (!giu_base)
524 return -ENOMEM;
525
526 vr41xx_gpio_chip.dev = &pdev->dev;
527
528 retval = gpiochip_add(&vr41xx_gpio_chip);
529
530 giu_write(GIUINTENL, 0);
531 giu_write(GIUINTENH, 0);
532
533 trigger = giu_read(GIUINTTYPH) << 16;
534 trigger |= giu_read(GIUINTTYPL);
535 for (i = GIU_IRQ_BASE; i <= GIU_IRQ_LAST; i++) {
536 pin = GPIO_PIN_OF_IRQ(i);
537 if (pin < GIUINT_HIGH_OFFSET)
538 chip = &giuint_low_irq_chip;
539 else
540 chip = &giuint_high_irq_chip;
541
542 if (trigger & (1 << pin))
543 set_irq_chip_and_handler(i, chip, handle_edge_irq);
544 else
545 set_irq_chip_and_handler(i, chip, handle_level_irq);
546
547 }
548
549 irq = platform_get_irq(pdev, 0);
550 if (irq < 0 || irq >= nr_irqs)
551 return -EBUSY;
552
553 return cascade_irq(irq, giu_get_irq);
554}
555
556static int __devexit giu_remove(struct platform_device *pdev)
557{
558 if (giu_base) {
559 iounmap(giu_base);
560 giu_base = NULL;
561 }
562
563 return 0;
564}
565
566static struct platform_driver giu_device_driver = {
567 .probe = giu_probe,
568 .remove = __devexit_p(giu_remove),
569 .driver = {
570 .name = "GIU",
571 .owner = THIS_MODULE,
572 },
573};
574
575static int __init vr41xx_giu_init(void)
576{
577 return platform_driver_register(&giu_device_driver);
578}
579
580static void __exit vr41xx_giu_exit(void)
581{
582 platform_driver_unregister(&giu_device_driver);
583}
584
585module_init(vr41xx_giu_init);
586module_exit(vr41xx_giu_exit);
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index c961fe415aef..39b393d38bb3 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -81,6 +81,7 @@ config DRM_I830
81 81
82config DRM_I915 82config DRM_I915
83 tristate "i915 driver" 83 tristate "i915 driver"
84 depends on AGP_INTEL
84 select FB_CFB_FILLRECT 85 select FB_CFB_FILLRECT
85 select FB_CFB_COPYAREA 86 select FB_CFB_COPYAREA
86 select FB_CFB_IMAGEBLIT 87 select FB_CFB_IMAGEBLIT
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 4e89ab08b7b8..fe23f29f7cba 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -16,6 +16,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \
16drm-$(CONFIG_COMPAT) += drm_ioc32.o 16drm-$(CONFIG_COMPAT) += drm_ioc32.o
17 17
18obj-$(CONFIG_DRM) += drm.o 18obj-$(CONFIG_DRM) += drm.o
19obj-$(CONFIG_DRM_TTM) += ttm/
19obj-$(CONFIG_DRM_TDFX) += tdfx/ 20obj-$(CONFIG_DRM_TDFX) += tdfx/
20obj-$(CONFIG_DRM_R128) += r128/ 21obj-$(CONFIG_DRM_R128) += r128/
21obj-$(CONFIG_DRM_RADEON)+= radeon/ 22obj-$(CONFIG_DRM_RADEON)+= radeon/
@@ -26,4 +27,3 @@ obj-$(CONFIG_DRM_I915) += i915/
26obj-$(CONFIG_DRM_SIS) += sis/ 27obj-$(CONFIG_DRM_SIS) += sis/
27obj-$(CONFIG_DRM_SAVAGE)+= savage/ 28obj-$(CONFIG_DRM_SAVAGE)+= savage/
28obj-$(CONFIG_DRM_VIA) +=via/ 29obj-$(CONFIG_DRM_VIA) +=via/
29obj-$(CONFIG_DRM_TTM) += ttm/
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 7d0835226f6e..80cc6d06d61b 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -294,10 +294,10 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
294 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo; 294 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
295 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo; 295 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
296 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo; 296 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
297 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 8 | pt->hsync_offset_lo; 297 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
298 unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) << 6 | pt->hsync_pulse_width_lo; 298 unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
299 unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) | (pt->vsync_offset_pulse_width_lo & 0xf); 299 unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) >> 2 | pt->vsync_offset_pulse_width_lo >> 4;
300 unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) >> 2 | pt->vsync_offset_pulse_width_lo >> 4; 300 unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
301 301
302 /* ignore tiny modes */ 302 /* ignore tiny modes */
303 if (hactive < 64 || vactive < 64) 303 if (hactive < 64 || vactive < 64)
@@ -347,8 +347,8 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
347 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ? 347 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
348 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC; 348 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
349 349
350 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf) << 8; 350 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
351 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4; 351 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
352 352
353 if (quirks & EDID_QUIRK_DETAILED_IN_CM) { 353 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
354 mode->width_mm *= 10; 354 mode->width_mm *= 10;
diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 51c5a050aa73..30d6b99fb302 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -13,6 +13,8 @@ i915-y := i915_drv.o i915_dma.o i915_irq.o i915_mem.o \
13 intel_crt.o \ 13 intel_crt.o \
14 intel_lvds.o \ 14 intel_lvds.o \
15 intel_bios.o \ 15 intel_bios.o \
16 intel_dp.o \
17 intel_dp_i2c.o \
16 intel_hdmi.o \ 18 intel_hdmi.o \
17 intel_sdvo.o \ 19 intel_sdvo.o \
18 intel_modes.o \ 20 intel_modes.o \
diff --git a/drivers/gpu/drm/i915/dvo.h b/drivers/gpu/drm/i915/dvo.h
index e747ac42fe3a..288fc50627e2 100644
--- a/drivers/gpu/drm/i915/dvo.h
+++ b/drivers/gpu/drm/i915/dvo.h
@@ -37,7 +37,7 @@ struct intel_dvo_device {
37 /* GPIO register used for i2c bus to control this device */ 37 /* GPIO register used for i2c bus to control this device */
38 u32 gpio; 38 u32 gpio;
39 int slave_addr; 39 int slave_addr;
40 struct intel_i2c_chan *i2c_bus; 40 struct i2c_adapter *i2c_bus;
41 41
42 const struct intel_dvo_dev_ops *dev_ops; 42 const struct intel_dvo_dev_ops *dev_ops;
43 void *dev_priv; 43 void *dev_priv;
@@ -52,7 +52,7 @@ struct intel_dvo_dev_ops {
52 * Returns NULL if the device does not exist. 52 * Returns NULL if the device does not exist.
53 */ 53 */
54 bool (*init)(struct intel_dvo_device *dvo, 54 bool (*init)(struct intel_dvo_device *dvo,
55 struct intel_i2c_chan *i2cbus); 55 struct i2c_adapter *i2cbus);
56 56
57 /* 57 /*
58 * Called to allow the output a chance to create properties after the 58 * Called to allow the output a chance to create properties after the
diff --git a/drivers/gpu/drm/i915/dvo_ch7017.c b/drivers/gpu/drm/i915/dvo_ch7017.c
index 03d4b4973b02..621815b531db 100644
--- a/drivers/gpu/drm/i915/dvo_ch7017.c
+++ b/drivers/gpu/drm/i915/dvo_ch7017.c
@@ -176,19 +176,20 @@ static void ch7017_dpms(struct intel_dvo_device *dvo, int mode);
176 176
177static bool ch7017_read(struct intel_dvo_device *dvo, int addr, uint8_t *val) 177static bool ch7017_read(struct intel_dvo_device *dvo, int addr, uint8_t *val)
178{ 178{
179 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 179 struct i2c_adapter *adapter = dvo->i2c_bus;
180 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
180 u8 out_buf[2]; 181 u8 out_buf[2];
181 u8 in_buf[2]; 182 u8 in_buf[2];
182 183
183 struct i2c_msg msgs[] = { 184 struct i2c_msg msgs[] = {
184 { 185 {
185 .addr = i2cbus->slave_addr, 186 .addr = dvo->slave_addr,
186 .flags = 0, 187 .flags = 0,
187 .len = 1, 188 .len = 1,
188 .buf = out_buf, 189 .buf = out_buf,
189 }, 190 },
190 { 191 {
191 .addr = i2cbus->slave_addr, 192 .addr = dvo->slave_addr,
192 .flags = I2C_M_RD, 193 .flags = I2C_M_RD,
193 .len = 1, 194 .len = 1,
194 .buf = in_buf, 195 .buf = in_buf,
@@ -208,10 +209,11 @@ static bool ch7017_read(struct intel_dvo_device *dvo, int addr, uint8_t *val)
208 209
209static bool ch7017_write(struct intel_dvo_device *dvo, int addr, uint8_t val) 210static bool ch7017_write(struct intel_dvo_device *dvo, int addr, uint8_t val)
210{ 211{
211 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 212 struct i2c_adapter *adapter = dvo->i2c_bus;
213 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
212 uint8_t out_buf[2]; 214 uint8_t out_buf[2];
213 struct i2c_msg msg = { 215 struct i2c_msg msg = {
214 .addr = i2cbus->slave_addr, 216 .addr = dvo->slave_addr,
215 .flags = 0, 217 .flags = 0,
216 .len = 2, 218 .len = 2,
217 .buf = out_buf, 219 .buf = out_buf,
@@ -228,8 +230,9 @@ static bool ch7017_write(struct intel_dvo_device *dvo, int addr, uint8_t val)
228 230
229/** Probes for a CH7017 on the given bus and slave address. */ 231/** Probes for a CH7017 on the given bus and slave address. */
230static bool ch7017_init(struct intel_dvo_device *dvo, 232static bool ch7017_init(struct intel_dvo_device *dvo,
231 struct intel_i2c_chan *i2cbus) 233 struct i2c_adapter *adapter)
232{ 234{
235 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
233 struct ch7017_priv *priv; 236 struct ch7017_priv *priv;
234 uint8_t val; 237 uint8_t val;
235 238
@@ -237,8 +240,7 @@ static bool ch7017_init(struct intel_dvo_device *dvo,
237 if (priv == NULL) 240 if (priv == NULL)
238 return false; 241 return false;
239 242
240 dvo->i2c_bus = i2cbus; 243 dvo->i2c_bus = adapter;
241 dvo->i2c_bus->slave_addr = dvo->slave_addr;
242 dvo->dev_priv = priv; 244 dvo->dev_priv = priv;
243 245
244 if (!ch7017_read(dvo, CH7017_DEVICE_ID, &val)) 246 if (!ch7017_read(dvo, CH7017_DEVICE_ID, &val))
@@ -248,7 +250,7 @@ static bool ch7017_init(struct intel_dvo_device *dvo,
248 val != CH7018_DEVICE_ID_VALUE && 250 val != CH7018_DEVICE_ID_VALUE &&
249 val != CH7019_DEVICE_ID_VALUE) { 251 val != CH7019_DEVICE_ID_VALUE) {
250 DRM_DEBUG("ch701x not detected, got %d: from %s Slave %d.\n", 252 DRM_DEBUG("ch701x not detected, got %d: from %s Slave %d.\n",
251 val, i2cbus->adapter.name,i2cbus->slave_addr); 253 val, i2cbus->adapter.name,dvo->slave_addr);
252 goto fail; 254 goto fail;
253 } 255 }
254 256
diff --git a/drivers/gpu/drm/i915/dvo_ch7xxx.c b/drivers/gpu/drm/i915/dvo_ch7xxx.c
index d2fd95dbd034..a9b896289680 100644
--- a/drivers/gpu/drm/i915/dvo_ch7xxx.c
+++ b/drivers/gpu/drm/i915/dvo_ch7xxx.c
@@ -123,19 +123,20 @@ static char *ch7xxx_get_id(uint8_t vid)
123static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) 123static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
124{ 124{
125 struct ch7xxx_priv *ch7xxx= dvo->dev_priv; 125 struct ch7xxx_priv *ch7xxx= dvo->dev_priv;
126 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 126 struct i2c_adapter *adapter = dvo->i2c_bus;
127 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
127 u8 out_buf[2]; 128 u8 out_buf[2];
128 u8 in_buf[2]; 129 u8 in_buf[2];
129 130
130 struct i2c_msg msgs[] = { 131 struct i2c_msg msgs[] = {
131 { 132 {
132 .addr = i2cbus->slave_addr, 133 .addr = dvo->slave_addr,
133 .flags = 0, 134 .flags = 0,
134 .len = 1, 135 .len = 1,
135 .buf = out_buf, 136 .buf = out_buf,
136 }, 137 },
137 { 138 {
138 .addr = i2cbus->slave_addr, 139 .addr = dvo->slave_addr,
139 .flags = I2C_M_RD, 140 .flags = I2C_M_RD,
140 .len = 1, 141 .len = 1,
141 .buf = in_buf, 142 .buf = in_buf,
@@ -152,7 +153,7 @@ static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
152 153
153 if (!ch7xxx->quiet) { 154 if (!ch7xxx->quiet) {
154 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n", 155 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n",
155 addr, i2cbus->adapter.name, i2cbus->slave_addr); 156 addr, i2cbus->adapter.name, dvo->slave_addr);
156 } 157 }
157 return false; 158 return false;
158} 159}
@@ -161,10 +162,11 @@ static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
161static bool ch7xxx_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch) 162static bool ch7xxx_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
162{ 163{
163 struct ch7xxx_priv *ch7xxx = dvo->dev_priv; 164 struct ch7xxx_priv *ch7xxx = dvo->dev_priv;
164 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 165 struct i2c_adapter *adapter = dvo->i2c_bus;
166 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
165 uint8_t out_buf[2]; 167 uint8_t out_buf[2];
166 struct i2c_msg msg = { 168 struct i2c_msg msg = {
167 .addr = i2cbus->slave_addr, 169 .addr = dvo->slave_addr,
168 .flags = 0, 170 .flags = 0,
169 .len = 2, 171 .len = 2,
170 .buf = out_buf, 172 .buf = out_buf,
@@ -178,14 +180,14 @@ static bool ch7xxx_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
178 180
179 if (!ch7xxx->quiet) { 181 if (!ch7xxx->quiet) {
180 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n", 182 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n",
181 addr, i2cbus->adapter.name, i2cbus->slave_addr); 183 addr, i2cbus->adapter.name, dvo->slave_addr);
182 } 184 }
183 185
184 return false; 186 return false;
185} 187}
186 188
187static bool ch7xxx_init(struct intel_dvo_device *dvo, 189static bool ch7xxx_init(struct intel_dvo_device *dvo,
188 struct intel_i2c_chan *i2cbus) 190 struct i2c_adapter *adapter)
189{ 191{
190 /* this will detect the CH7xxx chip on the specified i2c bus */ 192 /* this will detect the CH7xxx chip on the specified i2c bus */
191 struct ch7xxx_priv *ch7xxx; 193 struct ch7xxx_priv *ch7xxx;
@@ -196,8 +198,7 @@ static bool ch7xxx_init(struct intel_dvo_device *dvo,
196 if (ch7xxx == NULL) 198 if (ch7xxx == NULL)
197 return false; 199 return false;
198 200
199 dvo->i2c_bus = i2cbus; 201 dvo->i2c_bus = adapter;
200 dvo->i2c_bus->slave_addr = dvo->slave_addr;
201 dvo->dev_priv = ch7xxx; 202 dvo->dev_priv = ch7xxx;
202 ch7xxx->quiet = true; 203 ch7xxx->quiet = true;
203 204
@@ -207,7 +208,7 @@ static bool ch7xxx_init(struct intel_dvo_device *dvo,
207 name = ch7xxx_get_id(vendor); 208 name = ch7xxx_get_id(vendor);
208 if (!name) { 209 if (!name) {
209 DRM_DEBUG("ch7xxx not detected; got 0x%02x from %s slave %d.\n", 210 DRM_DEBUG("ch7xxx not detected; got 0x%02x from %s slave %d.\n",
210 vendor, i2cbus->adapter.name, i2cbus->slave_addr); 211 vendor, adapter->name, dvo->slave_addr);
211 goto out; 212 goto out;
212 } 213 }
213 214
@@ -217,7 +218,7 @@ static bool ch7xxx_init(struct intel_dvo_device *dvo,
217 218
218 if (device != CH7xxx_DID) { 219 if (device != CH7xxx_DID) {
219 DRM_DEBUG("ch7xxx not detected; got 0x%02x from %s slave %d.\n", 220 DRM_DEBUG("ch7xxx not detected; got 0x%02x from %s slave %d.\n",
220 vendor, i2cbus->adapter.name, i2cbus->slave_addr); 221 vendor, adapter->name, dvo->slave_addr);
221 goto out; 222 goto out;
222 } 223 }
223 224
diff --git a/drivers/gpu/drm/i915/dvo_ivch.c b/drivers/gpu/drm/i915/dvo_ivch.c
index 0c8d375e8e37..aa176f9921fe 100644
--- a/drivers/gpu/drm/i915/dvo_ivch.c
+++ b/drivers/gpu/drm/i915/dvo_ivch.c
@@ -169,13 +169,14 @@ static void ivch_dump_regs(struct intel_dvo_device *dvo);
169static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data) 169static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
170{ 170{
171 struct ivch_priv *priv = dvo->dev_priv; 171 struct ivch_priv *priv = dvo->dev_priv;
172 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 172 struct i2c_adapter *adapter = dvo->i2c_bus;
173 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
173 u8 out_buf[1]; 174 u8 out_buf[1];
174 u8 in_buf[2]; 175 u8 in_buf[2];
175 176
176 struct i2c_msg msgs[] = { 177 struct i2c_msg msgs[] = {
177 { 178 {
178 .addr = i2cbus->slave_addr, 179 .addr = dvo->slave_addr,
179 .flags = I2C_M_RD, 180 .flags = I2C_M_RD,
180 .len = 0, 181 .len = 0,
181 }, 182 },
@@ -186,7 +187,7 @@ static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
186 .buf = out_buf, 187 .buf = out_buf,
187 }, 188 },
188 { 189 {
189 .addr = i2cbus->slave_addr, 190 .addr = dvo->slave_addr,
190 .flags = I2C_M_RD | I2C_M_NOSTART, 191 .flags = I2C_M_RD | I2C_M_NOSTART,
191 .len = 2, 192 .len = 2,
192 .buf = in_buf, 193 .buf = in_buf,
@@ -202,7 +203,7 @@ static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
202 203
203 if (!priv->quiet) { 204 if (!priv->quiet) {
204 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n", 205 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n",
205 addr, i2cbus->adapter.name, i2cbus->slave_addr); 206 addr, i2cbus->adapter.name, dvo->slave_addr);
206 } 207 }
207 return false; 208 return false;
208} 209}
@@ -211,10 +212,11 @@ static bool ivch_read(struct intel_dvo_device *dvo, int addr, uint16_t *data)
211static bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data) 212static bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data)
212{ 213{
213 struct ivch_priv *priv = dvo->dev_priv; 214 struct ivch_priv *priv = dvo->dev_priv;
214 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 215 struct i2c_adapter *adapter = dvo->i2c_bus;
216 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
215 u8 out_buf[3]; 217 u8 out_buf[3];
216 struct i2c_msg msg = { 218 struct i2c_msg msg = {
217 .addr = i2cbus->slave_addr, 219 .addr = dvo->slave_addr,
218 .flags = 0, 220 .flags = 0,
219 .len = 3, 221 .len = 3,
220 .buf = out_buf, 222 .buf = out_buf,
@@ -229,7 +231,7 @@ static bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data)
229 231
230 if (!priv->quiet) { 232 if (!priv->quiet) {
231 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n", 233 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n",
232 addr, i2cbus->adapter.name, i2cbus->slave_addr); 234 addr, i2cbus->adapter.name, dvo->slave_addr);
233 } 235 }
234 236
235 return false; 237 return false;
@@ -237,7 +239,7 @@ static bool ivch_write(struct intel_dvo_device *dvo, int addr, uint16_t data)
237 239
238/** Probes the given bus and slave address for an ivch */ 240/** Probes the given bus and slave address for an ivch */
239static bool ivch_init(struct intel_dvo_device *dvo, 241static bool ivch_init(struct intel_dvo_device *dvo,
240 struct intel_i2c_chan *i2cbus) 242 struct i2c_adapter *adapter)
241{ 243{
242 struct ivch_priv *priv; 244 struct ivch_priv *priv;
243 uint16_t temp; 245 uint16_t temp;
@@ -246,8 +248,7 @@ static bool ivch_init(struct intel_dvo_device *dvo,
246 if (priv == NULL) 248 if (priv == NULL)
247 return false; 249 return false;
248 250
249 dvo->i2c_bus = i2cbus; 251 dvo->i2c_bus = adapter;
250 dvo->i2c_bus->slave_addr = dvo->slave_addr;
251 dvo->dev_priv = priv; 252 dvo->dev_priv = priv;
252 priv->quiet = true; 253 priv->quiet = true;
253 254
diff --git a/drivers/gpu/drm/i915/dvo_sil164.c b/drivers/gpu/drm/i915/dvo_sil164.c
index 033a4bb070b2..e1c1f7341e5c 100644
--- a/drivers/gpu/drm/i915/dvo_sil164.c
+++ b/drivers/gpu/drm/i915/dvo_sil164.c
@@ -76,19 +76,20 @@ struct sil164_priv {
76static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) 76static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
77{ 77{
78 struct sil164_priv *sil = dvo->dev_priv; 78 struct sil164_priv *sil = dvo->dev_priv;
79 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 79 struct i2c_adapter *adapter = dvo->i2c_bus;
80 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
80 u8 out_buf[2]; 81 u8 out_buf[2];
81 u8 in_buf[2]; 82 u8 in_buf[2];
82 83
83 struct i2c_msg msgs[] = { 84 struct i2c_msg msgs[] = {
84 { 85 {
85 .addr = i2cbus->slave_addr, 86 .addr = dvo->slave_addr,
86 .flags = 0, 87 .flags = 0,
87 .len = 1, 88 .len = 1,
88 .buf = out_buf, 89 .buf = out_buf,
89 }, 90 },
90 { 91 {
91 .addr = i2cbus->slave_addr, 92 .addr = dvo->slave_addr,
92 .flags = I2C_M_RD, 93 .flags = I2C_M_RD,
93 .len = 1, 94 .len = 1,
94 .buf = in_buf, 95 .buf = in_buf,
@@ -105,7 +106,7 @@ static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
105 106
106 if (!sil->quiet) { 107 if (!sil->quiet) {
107 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n", 108 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n",
108 addr, i2cbus->adapter.name, i2cbus->slave_addr); 109 addr, i2cbus->adapter.name, dvo->slave_addr);
109 } 110 }
110 return false; 111 return false;
111} 112}
@@ -113,10 +114,11 @@ static bool sil164_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
113static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch) 114static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
114{ 115{
115 struct sil164_priv *sil= dvo->dev_priv; 116 struct sil164_priv *sil= dvo->dev_priv;
116 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 117 struct i2c_adapter *adapter = dvo->i2c_bus;
118 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
117 uint8_t out_buf[2]; 119 uint8_t out_buf[2];
118 struct i2c_msg msg = { 120 struct i2c_msg msg = {
119 .addr = i2cbus->slave_addr, 121 .addr = dvo->slave_addr,
120 .flags = 0, 122 .flags = 0,
121 .len = 2, 123 .len = 2,
122 .buf = out_buf, 124 .buf = out_buf,
@@ -130,7 +132,7 @@ static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
130 132
131 if (!sil->quiet) { 133 if (!sil->quiet) {
132 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n", 134 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n",
133 addr, i2cbus->adapter.name, i2cbus->slave_addr); 135 addr, i2cbus->adapter.name, dvo->slave_addr);
134 } 136 }
135 137
136 return false; 138 return false;
@@ -138,7 +140,7 @@ static bool sil164_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
138 140
139/* Silicon Image 164 driver for chip on i2c bus */ 141/* Silicon Image 164 driver for chip on i2c bus */
140static bool sil164_init(struct intel_dvo_device *dvo, 142static bool sil164_init(struct intel_dvo_device *dvo,
141 struct intel_i2c_chan *i2cbus) 143 struct i2c_adapter *adapter)
142{ 144{
143 /* this will detect the SIL164 chip on the specified i2c bus */ 145 /* this will detect the SIL164 chip on the specified i2c bus */
144 struct sil164_priv *sil; 146 struct sil164_priv *sil;
@@ -148,8 +150,7 @@ static bool sil164_init(struct intel_dvo_device *dvo,
148 if (sil == NULL) 150 if (sil == NULL)
149 return false; 151 return false;
150 152
151 dvo->i2c_bus = i2cbus; 153 dvo->i2c_bus = adapter;
152 dvo->i2c_bus->slave_addr = dvo->slave_addr;
153 dvo->dev_priv = sil; 154 dvo->dev_priv = sil;
154 sil->quiet = true; 155 sil->quiet = true;
155 156
@@ -158,7 +159,7 @@ static bool sil164_init(struct intel_dvo_device *dvo,
158 159
159 if (ch != (SIL164_VID & 0xff)) { 160 if (ch != (SIL164_VID & 0xff)) {
160 DRM_DEBUG("sil164 not detected got %d: from %s Slave %d.\n", 161 DRM_DEBUG("sil164 not detected got %d: from %s Slave %d.\n",
161 ch, i2cbus->adapter.name, i2cbus->slave_addr); 162 ch, adapter->name, dvo->slave_addr);
162 goto out; 163 goto out;
163 } 164 }
164 165
@@ -167,7 +168,7 @@ static bool sil164_init(struct intel_dvo_device *dvo,
167 168
168 if (ch != (SIL164_DID & 0xff)) { 169 if (ch != (SIL164_DID & 0xff)) {
169 DRM_DEBUG("sil164 not detected got %d: from %s Slave %d.\n", 170 DRM_DEBUG("sil164 not detected got %d: from %s Slave %d.\n",
170 ch, i2cbus->adapter.name, i2cbus->slave_addr); 171 ch, adapter->name, dvo->slave_addr);
171 goto out; 172 goto out;
172 } 173 }
173 sil->quiet = false; 174 sil->quiet = false;
diff --git a/drivers/gpu/drm/i915/dvo_tfp410.c b/drivers/gpu/drm/i915/dvo_tfp410.c
index 207fda806ebf..9ecc907384ec 100644
--- a/drivers/gpu/drm/i915/dvo_tfp410.c
+++ b/drivers/gpu/drm/i915/dvo_tfp410.c
@@ -101,19 +101,20 @@ struct tfp410_priv {
101static bool tfp410_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) 101static bool tfp410_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
102{ 102{
103 struct tfp410_priv *tfp = dvo->dev_priv; 103 struct tfp410_priv *tfp = dvo->dev_priv;
104 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 104 struct i2c_adapter *adapter = dvo->i2c_bus;
105 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
105 u8 out_buf[2]; 106 u8 out_buf[2];
106 u8 in_buf[2]; 107 u8 in_buf[2];
107 108
108 struct i2c_msg msgs[] = { 109 struct i2c_msg msgs[] = {
109 { 110 {
110 .addr = i2cbus->slave_addr, 111 .addr = dvo->slave_addr,
111 .flags = 0, 112 .flags = 0,
112 .len = 1, 113 .len = 1,
113 .buf = out_buf, 114 .buf = out_buf,
114 }, 115 },
115 { 116 {
116 .addr = i2cbus->slave_addr, 117 .addr = dvo->slave_addr,
117 .flags = I2C_M_RD, 118 .flags = I2C_M_RD,
118 .len = 1, 119 .len = 1,
119 .buf = in_buf, 120 .buf = in_buf,
@@ -130,7 +131,7 @@ static bool tfp410_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
130 131
131 if (!tfp->quiet) { 132 if (!tfp->quiet) {
132 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n", 133 DRM_DEBUG("Unable to read register 0x%02x from %s:%02x.\n",
133 addr, i2cbus->adapter.name, i2cbus->slave_addr); 134 addr, i2cbus->adapter.name, dvo->slave_addr);
134 } 135 }
135 return false; 136 return false;
136} 137}
@@ -138,10 +139,11 @@ static bool tfp410_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch)
138static bool tfp410_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch) 139static bool tfp410_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
139{ 140{
140 struct tfp410_priv *tfp = dvo->dev_priv; 141 struct tfp410_priv *tfp = dvo->dev_priv;
141 struct intel_i2c_chan *i2cbus = dvo->i2c_bus; 142 struct i2c_adapter *adapter = dvo->i2c_bus;
143 struct intel_i2c_chan *i2cbus = container_of(adapter, struct intel_i2c_chan, adapter);
142 uint8_t out_buf[2]; 144 uint8_t out_buf[2];
143 struct i2c_msg msg = { 145 struct i2c_msg msg = {
144 .addr = i2cbus->slave_addr, 146 .addr = dvo->slave_addr,
145 .flags = 0, 147 .flags = 0,
146 .len = 2, 148 .len = 2,
147 .buf = out_buf, 149 .buf = out_buf,
@@ -155,7 +157,7 @@ static bool tfp410_writeb(struct intel_dvo_device *dvo, int addr, uint8_t ch)
155 157
156 if (!tfp->quiet) { 158 if (!tfp->quiet) {
157 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n", 159 DRM_DEBUG("Unable to write register 0x%02x to %s:%d.\n",
158 addr, i2cbus->adapter.name, i2cbus->slave_addr); 160 addr, i2cbus->adapter.name, dvo->slave_addr);
159 } 161 }
160 162
161 return false; 163 return false;
@@ -174,7 +176,7 @@ static int tfp410_getid(struct intel_dvo_device *dvo, int addr)
174 176
175/* Ti TFP410 driver for chip on i2c bus */ 177/* Ti TFP410 driver for chip on i2c bus */
176static bool tfp410_init(struct intel_dvo_device *dvo, 178static bool tfp410_init(struct intel_dvo_device *dvo,
177 struct intel_i2c_chan *i2cbus) 179 struct i2c_adapter *adapter)
178{ 180{
179 /* this will detect the tfp410 chip on the specified i2c bus */ 181 /* this will detect the tfp410 chip on the specified i2c bus */
180 struct tfp410_priv *tfp; 182 struct tfp410_priv *tfp;
@@ -184,20 +186,19 @@ static bool tfp410_init(struct intel_dvo_device *dvo,
184 if (tfp == NULL) 186 if (tfp == NULL)
185 return false; 187 return false;
186 188
187 dvo->i2c_bus = i2cbus; 189 dvo->i2c_bus = adapter;
188 dvo->i2c_bus->slave_addr = dvo->slave_addr;
189 dvo->dev_priv = tfp; 190 dvo->dev_priv = tfp;
190 tfp->quiet = true; 191 tfp->quiet = true;
191 192
192 if ((id = tfp410_getid(dvo, TFP410_VID_LO)) != TFP410_VID) { 193 if ((id = tfp410_getid(dvo, TFP410_VID_LO)) != TFP410_VID) {
193 DRM_DEBUG("tfp410 not detected got VID %X: from %s Slave %d.\n", 194 DRM_DEBUG("tfp410 not detected got VID %X: from %s Slave %d.\n",
194 id, i2cbus->adapter.name, i2cbus->slave_addr); 195 id, adapter->name, dvo->slave_addr);
195 goto out; 196 goto out;
196 } 197 }
197 198
198 if ((id = tfp410_getid(dvo, TFP410_DID_LO)) != TFP410_DID) { 199 if ((id = tfp410_getid(dvo, TFP410_DID_LO)) != TFP410_DID) {
199 DRM_DEBUG("tfp410 not detected got DID %X: from %s Slave %d.\n", 200 DRM_DEBUG("tfp410 not detected got DID %X: from %s Slave %d.\n",
200 id, i2cbus->adapter.name, i2cbus->slave_addr); 201 id, adapter->name, dvo->slave_addr);
201 goto out; 202 goto out;
202 } 203 }
203 tfp->quiet = false; 204 tfp->quiet = false;
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 98560e1e899a..e3cb4025e323 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -67,8 +67,6 @@ static int i915_suspend(struct drm_device *dev, pm_message_t state)
67 67
68 pci_save_state(dev->pdev); 68 pci_save_state(dev->pdev);
69 69
70 i915_save_state(dev);
71
72 /* If KMS is active, we do the leavevt stuff here */ 70 /* If KMS is active, we do the leavevt stuff here */
73 if (drm_core_check_feature(dev, DRIVER_MODESET)) { 71 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
74 if (i915_gem_idle(dev)) 72 if (i915_gem_idle(dev))
@@ -77,6 +75,8 @@ static int i915_suspend(struct drm_device *dev, pm_message_t state)
77 drm_irq_uninstall(dev); 75 drm_irq_uninstall(dev);
78 } 76 }
79 77
78 i915_save_state(dev);
79
80 intel_opregion_free(dev, 1); 80 intel_opregion_free(dev, 1);
81 81
82 if (state.event == PM_EVENT_SUSPEND) { 82 if (state.event == PM_EVENT_SUSPEND) {
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 7a84f04e8439..bb4c2d387b6c 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -306,6 +306,17 @@ typedef struct drm_i915_private {
306 u32 saveCURBPOS; 306 u32 saveCURBPOS;
307 u32 saveCURBBASE; 307 u32 saveCURBBASE;
308 u32 saveCURSIZE; 308 u32 saveCURSIZE;
309 u32 saveDP_B;
310 u32 saveDP_C;
311 u32 saveDP_D;
312 u32 savePIPEA_GMCH_DATA_M;
313 u32 savePIPEB_GMCH_DATA_M;
314 u32 savePIPEA_GMCH_DATA_N;
315 u32 savePIPEB_GMCH_DATA_N;
316 u32 savePIPEA_DP_LINK_M;
317 u32 savePIPEB_DP_LINK_M;
318 u32 savePIPEA_DP_LINK_N;
319 u32 savePIPEB_DP_LINK_N;
309 320
310 struct { 321 struct {
311 struct drm_mm gtt_space; 322 struct drm_mm gtt_space;
@@ -857,6 +868,7 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
857#define HAS_128_BYTE_Y_TILING(dev) (IS_I9XX(dev) && !(IS_I915G(dev) || \ 868#define HAS_128_BYTE_Y_TILING(dev) (IS_I9XX(dev) && !(IS_I915G(dev) || \
858 IS_I915GM(dev))) 869 IS_I915GM(dev)))
859#define SUPPORTS_INTEGRATED_HDMI(dev) (IS_G4X(dev) || IS_IGDNG(dev)) 870#define SUPPORTS_INTEGRATED_HDMI(dev) (IS_G4X(dev) || IS_IGDNG(dev))
871#define SUPPORTS_INTEGRATED_DP(dev) (IS_G4X(dev) || IS_IGDNG(dev))
860#define I915_HAS_HOTPLUG(dev) (IS_I945G(dev) || IS_I945GM(dev) || IS_I965G(dev)) 872#define I915_HAS_HOTPLUG(dev) (IS_I945G(dev) || IS_I945GM(dev) || IS_I965G(dev))
861 873
862#define PRIMARY_RINGBUFFER_SIZE (128*1024) 874#define PRIMARY_RINGBUFFER_SIZE (128*1024)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index fd2b8bdffe3f..876b65cb7629 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1006,7 +1006,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
1006 1006
1007 mutex_lock(&dev->struct_mutex); 1007 mutex_lock(&dev->struct_mutex);
1008#if WATCH_BUF 1008#if WATCH_BUF
1009 DRM_INFO("set_domain_ioctl %p(%d), %08x %08x\n", 1009 DRM_INFO("set_domain_ioctl %p(%zd), %08x %08x\n",
1010 obj, obj->size, read_domains, write_domain); 1010 obj, obj->size, read_domains, write_domain);
1011#endif 1011#endif
1012 if (read_domains & I915_GEM_DOMAIN_GTT) { 1012 if (read_domains & I915_GEM_DOMAIN_GTT) {
@@ -1050,7 +1050,7 @@ i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
1050 } 1050 }
1051 1051
1052#if WATCH_BUF 1052#if WATCH_BUF
1053 DRM_INFO("%s: sw_finish %d (%p %d)\n", 1053 DRM_INFO("%s: sw_finish %d (%p %zd)\n",
1054 __func__, args->handle, obj, obj->size); 1054 __func__, args->handle, obj, obj->size);
1055#endif 1055#endif
1056 obj_priv = obj->driver_private; 1056 obj_priv = obj->driver_private;
@@ -2423,7 +2423,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
2423 } 2423 }
2424 2424
2425#if WATCH_BUF 2425#if WATCH_BUF
2426 DRM_INFO("Binding object of size %d at 0x%08x\n", 2426 DRM_INFO("Binding object of size %zd at 0x%08x\n",
2427 obj->size, obj_priv->gtt_offset); 2427 obj->size, obj_priv->gtt_offset);
2428#endif 2428#endif
2429 ret = i915_gem_object_get_pages(obj); 2429 ret = i915_gem_object_get_pages(obj);
@@ -4227,6 +4227,7 @@ i915_gem_lastclose(struct drm_device *dev)
4227void 4227void
4228i915_gem_load(struct drm_device *dev) 4228i915_gem_load(struct drm_device *dev)
4229{ 4229{
4230 int i;
4230 drm_i915_private_t *dev_priv = dev->dev_private; 4231 drm_i915_private_t *dev_priv = dev->dev_private;
4231 4232
4232 spin_lock_init(&dev_priv->mm.active_list_lock); 4233 spin_lock_init(&dev_priv->mm.active_list_lock);
@@ -4246,6 +4247,18 @@ i915_gem_load(struct drm_device *dev)
4246 else 4247 else
4247 dev_priv->num_fence_regs = 8; 4248 dev_priv->num_fence_regs = 8;
4248 4249
4250 /* Initialize fence registers to zero */
4251 if (IS_I965G(dev)) {
4252 for (i = 0; i < 16; i++)
4253 I915_WRITE64(FENCE_REG_965_0 + (i * 8), 0);
4254 } else {
4255 for (i = 0; i < 8; i++)
4256 I915_WRITE(FENCE_REG_830_0 + (i * 4), 0);
4257 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
4258 for (i = 0; i < 8; i++)
4259 I915_WRITE(FENCE_REG_945_8 + (i * 4), 0);
4260 }
4261
4249 i915_gem_detect_bit_6_swizzle(dev); 4262 i915_gem_detect_bit_6_swizzle(dev);
4250} 4263}
4251 4264
diff --git a/drivers/gpu/drm/i915/i915_gem_debug.c b/drivers/gpu/drm/i915/i915_gem_debug.c
index 8d0b943e2c5a..e602614bd3f8 100644
--- a/drivers/gpu/drm/i915/i915_gem_debug.c
+++ b/drivers/gpu/drm/i915/i915_gem_debug.c
@@ -87,7 +87,7 @@ i915_gem_dump_object(struct drm_gem_object *obj, int len,
87 chunk_len = page_len - chunk; 87 chunk_len = page_len - chunk;
88 if (chunk_len > 128) 88 if (chunk_len > 128)
89 chunk_len = 128; 89 chunk_len = 128;
90 i915_gem_dump_page(obj_priv->page_list[page], 90 i915_gem_dump_page(obj_priv->pages[page],
91 chunk, chunk + chunk_len, 91 chunk, chunk + chunk_len,
92 obj_priv->gtt_offset + 92 obj_priv->gtt_offset +
93 page * PAGE_SIZE, 93 page * PAGE_SIZE,
@@ -143,7 +143,7 @@ i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle)
143 uint32_t *backing_map = NULL; 143 uint32_t *backing_map = NULL;
144 int bad_count = 0; 144 int bad_count = 0;
145 145
146 DRM_INFO("%s: checking coherency of object %p@0x%08x (%d, %dkb):\n", 146 DRM_INFO("%s: checking coherency of object %p@0x%08x (%d, %zdkb):\n",
147 __func__, obj, obj_priv->gtt_offset, handle, 147 __func__, obj, obj_priv->gtt_offset, handle,
148 obj->size / 1024); 148 obj->size / 1024);
149 149
@@ -157,7 +157,7 @@ i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle)
157 for (page = 0; page < obj->size / PAGE_SIZE; page++) { 157 for (page = 0; page < obj->size / PAGE_SIZE; page++) {
158 int i; 158 int i;
159 159
160 backing_map = kmap_atomic(obj_priv->page_list[page], KM_USER0); 160 backing_map = kmap_atomic(obj_priv->pages[page], KM_USER0);
161 161
162 if (backing_map == NULL) { 162 if (backing_map == NULL) {
163 DRM_ERROR("failed to map backing page\n"); 163 DRM_ERROR("failed to map backing page\n");
diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c
index 5c1ceec49f5b..daeae62e1c28 100644
--- a/drivers/gpu/drm/i915/i915_gem_tiling.c
+++ b/drivers/gpu/drm/i915/i915_gem_tiling.c
@@ -114,11 +114,13 @@ intel_alloc_mchbar_resource(struct drm_device *dev)
114 mchbar_addr = ((u64)temp_hi << 32) | temp_lo; 114 mchbar_addr = ((u64)temp_hi << 32) | temp_lo;
115 115
116 /* If ACPI doesn't have it, assume we need to allocate it ourselves */ 116 /* If ACPI doesn't have it, assume we need to allocate it ourselves */
117#ifdef CONFIG_PNP
117 if (mchbar_addr && 118 if (mchbar_addr &&
118 pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE)) { 119 pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE)) {
119 ret = 0; 120 ret = 0;
120 goto out_put; 121 goto out_put;
121 } 122 }
123#endif
122 124
123 /* Get some space for it */ 125 /* Get some space for it */
124 ret = pci_bus_alloc_resource(bridge_dev->bus, &dev_priv->mch_res, 126 ret = pci_bus_alloc_resource(bridge_dev->bus, &dev_priv->mch_res,
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index b86b7b7130c6..228546f6eaa4 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -232,7 +232,17 @@ static void i915_hotplug_work_func(struct work_struct *work)
232 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t, 232 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
233 hotplug_work); 233 hotplug_work);
234 struct drm_device *dev = dev_priv->dev; 234 struct drm_device *dev = dev_priv->dev;
235 235 struct drm_mode_config *mode_config = &dev->mode_config;
236 struct drm_connector *connector;
237
238 if (mode_config->num_connector) {
239 list_for_each_entry(connector, &mode_config->connector_list, head) {
240 struct intel_output *intel_output = to_intel_output(connector);
241
242 if (intel_output->hot_plug)
243 (*intel_output->hot_plug) (intel_output);
244 }
245 }
236 /* Just fire off a uevent and let userspace tell us what to do */ 246 /* Just fire off a uevent and let userspace tell us what to do */
237 drm_sysfs_hotplug_event(dev); 247 drm_sysfs_hotplug_event(dev);
238} 248}
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index f6237a0b1133..88bf7521405f 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -569,6 +569,19 @@
569#define C0DRB3 0x10206 569#define C0DRB3 0x10206
570#define C1DRB3 0x10606 570#define C1DRB3 0x10606
571 571
572/* Clocking configuration register */
573#define CLKCFG 0x10c00
574#define CLKCFG_FSB_400 (0 << 0) /* hrawclk 100 */
575#define CLKCFG_FSB_533 (1 << 0) /* hrawclk 133 */
576#define CLKCFG_FSB_667 (3 << 0) /* hrawclk 166 */
577#define CLKCFG_FSB_800 (2 << 0) /* hrawclk 200 */
578#define CLKCFG_FSB_1067 (6 << 0) /* hrawclk 266 */
579#define CLKCFG_FSB_1333 (7 << 0) /* hrawclk 333 */
580/* this is a guess, could be 5 as well */
581#define CLKCFG_FSB_1600 (4 << 0) /* hrawclk 400 */
582#define CLKCFG_FSB_1600_ALT (5 << 0) /* hrawclk 400 */
583#define CLKCFG_FSB_MASK (7 << 0)
584
572/** GM965 GM45 render standby register */ 585/** GM965 GM45 render standby register */
573#define MCHBAR_RENDER_STANDBY 0x111B8 586#define MCHBAR_RENDER_STANDBY 0x111B8
574 587
@@ -834,9 +847,25 @@
834#define HORIZ_INTERP_MASK (3 << 6) 847#define HORIZ_INTERP_MASK (3 << 6)
835#define HORIZ_AUTO_SCALE (1 << 5) 848#define HORIZ_AUTO_SCALE (1 << 5)
836#define PANEL_8TO6_DITHER_ENABLE (1 << 3) 849#define PANEL_8TO6_DITHER_ENABLE (1 << 3)
850#define PFIT_FILTER_FUZZY (0 << 24)
851#define PFIT_SCALING_AUTO (0 << 26)
852#define PFIT_SCALING_PROGRAMMED (1 << 26)
853#define PFIT_SCALING_PILLAR (2 << 26)
854#define PFIT_SCALING_LETTER (3 << 26)
837#define PFIT_PGM_RATIOS 0x61234 855#define PFIT_PGM_RATIOS 0x61234
838#define PFIT_VERT_SCALE_MASK 0xfff00000 856#define PFIT_VERT_SCALE_MASK 0xfff00000
839#define PFIT_HORIZ_SCALE_MASK 0x0000fff0 857#define PFIT_HORIZ_SCALE_MASK 0x0000fff0
858/* Pre-965 */
859#define PFIT_VERT_SCALE_SHIFT 20
860#define PFIT_VERT_SCALE_MASK 0xfff00000
861#define PFIT_HORIZ_SCALE_SHIFT 4
862#define PFIT_HORIZ_SCALE_MASK 0x0000fff0
863/* 965+ */
864#define PFIT_VERT_SCALE_SHIFT_965 16
865#define PFIT_VERT_SCALE_MASK_965 0x1fff0000
866#define PFIT_HORIZ_SCALE_SHIFT_965 0
867#define PFIT_HORIZ_SCALE_MASK_965 0x00001fff
868
840#define PFIT_AUTO_RATIOS 0x61238 869#define PFIT_AUTO_RATIOS 0x61238
841 870
842/* Backlight control */ 871/* Backlight control */
diff --git a/drivers/gpu/drm/i915/i915_suspend.c b/drivers/gpu/drm/i915/i915_suspend.c
index a98e2831ed31..8d8e083d14ab 100644
--- a/drivers/gpu/drm/i915/i915_suspend.c
+++ b/drivers/gpu/drm/i915/i915_suspend.c
@@ -322,6 +322,20 @@ int i915_save_state(struct drm_device *dev)
322 dev_priv->savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS); 322 dev_priv->savePP_OFF_DELAYS = I915_READ(PP_OFF_DELAYS);
323 dev_priv->savePP_DIVISOR = I915_READ(PP_DIVISOR); 323 dev_priv->savePP_DIVISOR = I915_READ(PP_DIVISOR);
324 324
325 /* Display Port state */
326 if (SUPPORTS_INTEGRATED_DP(dev)) {
327 dev_priv->saveDP_B = I915_READ(DP_B);
328 dev_priv->saveDP_C = I915_READ(DP_C);
329 dev_priv->saveDP_D = I915_READ(DP_D);
330 dev_priv->savePIPEA_GMCH_DATA_M = I915_READ(PIPEA_GMCH_DATA_M);
331 dev_priv->savePIPEB_GMCH_DATA_M = I915_READ(PIPEB_GMCH_DATA_M);
332 dev_priv->savePIPEA_GMCH_DATA_N = I915_READ(PIPEA_GMCH_DATA_N);
333 dev_priv->savePIPEB_GMCH_DATA_N = I915_READ(PIPEB_GMCH_DATA_N);
334 dev_priv->savePIPEA_DP_LINK_M = I915_READ(PIPEA_DP_LINK_M);
335 dev_priv->savePIPEB_DP_LINK_M = I915_READ(PIPEB_DP_LINK_M);
336 dev_priv->savePIPEA_DP_LINK_N = I915_READ(PIPEA_DP_LINK_N);
337 dev_priv->savePIPEB_DP_LINK_N = I915_READ(PIPEB_DP_LINK_N);
338 }
325 /* FIXME: save TV & SDVO state */ 339 /* FIXME: save TV & SDVO state */
326 340
327 /* FBC state */ 341 /* FBC state */
@@ -404,7 +418,19 @@ int i915_restore_state(struct drm_device *dev)
404 for (i = 0; i < 8; i++) 418 for (i = 0; i < 8; i++)
405 I915_WRITE(FENCE_REG_945_8 + (i * 4), dev_priv->saveFENCE[i+8]); 419 I915_WRITE(FENCE_REG_945_8 + (i * 4), dev_priv->saveFENCE[i+8]);
406 } 420 }
407 421
422 /* Display port ratios (must be done before clock is set) */
423 if (SUPPORTS_INTEGRATED_DP(dev)) {
424 I915_WRITE(PIPEA_GMCH_DATA_M, dev_priv->savePIPEA_GMCH_DATA_M);
425 I915_WRITE(PIPEB_GMCH_DATA_M, dev_priv->savePIPEB_GMCH_DATA_M);
426 I915_WRITE(PIPEA_GMCH_DATA_N, dev_priv->savePIPEA_GMCH_DATA_N);
427 I915_WRITE(PIPEB_GMCH_DATA_N, dev_priv->savePIPEB_GMCH_DATA_N);
428 I915_WRITE(PIPEA_DP_LINK_M, dev_priv->savePIPEA_DP_LINK_M);
429 I915_WRITE(PIPEB_DP_LINK_M, dev_priv->savePIPEB_DP_LINK_M);
430 I915_WRITE(PIPEA_DP_LINK_N, dev_priv->savePIPEA_DP_LINK_N);
431 I915_WRITE(PIPEB_DP_LINK_N, dev_priv->savePIPEB_DP_LINK_N);
432 }
433
408 /* Pipe & plane A info */ 434 /* Pipe & plane A info */
409 /* Prime the clock */ 435 /* Prime the clock */
410 if (dev_priv->saveDPLL_A & DPLL_VCO_ENABLE) { 436 if (dev_priv->saveDPLL_A & DPLL_VCO_ENABLE) {
@@ -518,6 +544,12 @@ int i915_restore_state(struct drm_device *dev)
518 I915_WRITE(PP_DIVISOR, dev_priv->savePP_DIVISOR); 544 I915_WRITE(PP_DIVISOR, dev_priv->savePP_DIVISOR);
519 I915_WRITE(PP_CONTROL, dev_priv->savePP_CONTROL); 545 I915_WRITE(PP_CONTROL, dev_priv->savePP_CONTROL);
520 546
547 /* Display Port state */
548 if (SUPPORTS_INTEGRATED_DP(dev)) {
549 I915_WRITE(DP_B, dev_priv->saveDP_B);
550 I915_WRITE(DP_C, dev_priv->saveDP_C);
551 I915_WRITE(DP_D, dev_priv->saveDP_D);
552 }
521 /* FIXME: restore TV & SDVO state */ 553 /* FIXME: restore TV & SDVO state */
522 554
523 /* FBC info */ 555 /* FBC info */
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
index cdd126d068a7..716409a57244 100644
--- a/drivers/gpu/drm/i915/intel_bios.c
+++ b/drivers/gpu/drm/i915/intel_bios.c
@@ -99,9 +99,11 @@ parse_lfp_panel_data(struct drm_i915_private *dev_priv,
99{ 99{
100 struct bdb_lvds_options *lvds_options; 100 struct bdb_lvds_options *lvds_options;
101 struct bdb_lvds_lfp_data *lvds_lfp_data; 101 struct bdb_lvds_lfp_data *lvds_lfp_data;
102 struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
102 struct bdb_lvds_lfp_data_entry *entry; 103 struct bdb_lvds_lfp_data_entry *entry;
103 struct lvds_dvo_timing *dvo_timing; 104 struct lvds_dvo_timing *dvo_timing;
104 struct drm_display_mode *panel_fixed_mode; 105 struct drm_display_mode *panel_fixed_mode;
106 int lfp_data_size;
105 107
106 /* Defaults if we can't find VBT info */ 108 /* Defaults if we can't find VBT info */
107 dev_priv->lvds_dither = 0; 109 dev_priv->lvds_dither = 0;
@@ -119,9 +121,17 @@ parse_lfp_panel_data(struct drm_i915_private *dev_priv,
119 if (!lvds_lfp_data) 121 if (!lvds_lfp_data)
120 return; 122 return;
121 123
124 lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
125 if (!lvds_lfp_data_ptrs)
126 return;
127
122 dev_priv->lvds_vbt = 1; 128 dev_priv->lvds_vbt = 1;
123 129
124 entry = &lvds_lfp_data->data[lvds_options->panel_type]; 130 lfp_data_size = lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
131 lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
132 entry = (struct bdb_lvds_lfp_data_entry *)
133 ((uint8_t *)lvds_lfp_data->data + (lfp_data_size *
134 lvds_options->panel_type));
125 dvo_timing = &entry->dvo_timing; 135 dvo_timing = &entry->dvo_timing;
126 136
127 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL); 137 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 3e1c78162119..73e7b9cecac8 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -29,6 +29,7 @@
29#include "intel_drv.h" 29#include "intel_drv.h"
30#include "i915_drm.h" 30#include "i915_drm.h"
31#include "i915_drv.h" 31#include "i915_drv.h"
32#include "intel_dp.h"
32 33
33#include "drm_crtc_helper.h" 34#include "drm_crtc_helper.h"
34 35
@@ -127,19 +128,6 @@ struct intel_limit {
127#define I9XX_P2_LVDS_FAST 7 128#define I9XX_P2_LVDS_FAST 7
128#define I9XX_P2_LVDS_SLOW_LIMIT 112000 129#define I9XX_P2_LVDS_SLOW_LIMIT 112000
129 130
130#define INTEL_LIMIT_I8XX_DVO_DAC 0
131#define INTEL_LIMIT_I8XX_LVDS 1
132#define INTEL_LIMIT_I9XX_SDVO_DAC 2
133#define INTEL_LIMIT_I9XX_LVDS 3
134#define INTEL_LIMIT_G4X_SDVO 4
135#define INTEL_LIMIT_G4X_HDMI_DAC 5
136#define INTEL_LIMIT_G4X_SINGLE_CHANNEL_LVDS 6
137#define INTEL_LIMIT_G4X_DUAL_CHANNEL_LVDS 7
138#define INTEL_LIMIT_IGD_SDVO_DAC 8
139#define INTEL_LIMIT_IGD_LVDS 9
140#define INTEL_LIMIT_IGDNG_SDVO_DAC 10
141#define INTEL_LIMIT_IGDNG_LVDS 11
142
143/*The parameter is for SDVO on G4x platform*/ 131/*The parameter is for SDVO on G4x platform*/
144#define G4X_DOT_SDVO_MIN 25000 132#define G4X_DOT_SDVO_MIN 25000
145#define G4X_DOT_SDVO_MAX 270000 133#define G4X_DOT_SDVO_MAX 270000
@@ -218,6 +206,25 @@ struct intel_limit {
218#define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7 206#define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7
219#define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0 207#define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0
220 208
209/*The parameter is for DISPLAY PORT on G4x platform*/
210#define G4X_DOT_DISPLAY_PORT_MIN 161670
211#define G4X_DOT_DISPLAY_PORT_MAX 227000
212#define G4X_N_DISPLAY_PORT_MIN 1
213#define G4X_N_DISPLAY_PORT_MAX 2
214#define G4X_M_DISPLAY_PORT_MIN 97
215#define G4X_M_DISPLAY_PORT_MAX 108
216#define G4X_M1_DISPLAY_PORT_MIN 0x10
217#define G4X_M1_DISPLAY_PORT_MAX 0x12
218#define G4X_M2_DISPLAY_PORT_MIN 0x05
219#define G4X_M2_DISPLAY_PORT_MAX 0x06
220#define G4X_P_DISPLAY_PORT_MIN 10
221#define G4X_P_DISPLAY_PORT_MAX 20
222#define G4X_P1_DISPLAY_PORT_MIN 1
223#define G4X_P1_DISPLAY_PORT_MAX 2
224#define G4X_P2_DISPLAY_PORT_SLOW 10
225#define G4X_P2_DISPLAY_PORT_FAST 10
226#define G4X_P2_DISPLAY_PORT_LIMIT 0
227
221/* IGDNG */ 228/* IGDNG */
222/* as we calculate clock using (register_value + 2) for 229/* as we calculate clock using (register_value + 2) for
223 N/M1/M2, so here the range value for them is (actual_value-2). 230 N/M1/M2, so here the range value for them is (actual_value-2).
@@ -256,8 +263,11 @@ static bool
256intel_igdng_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, 263intel_igdng_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
257 int target, int refclk, intel_clock_t *best_clock); 264 int target, int refclk, intel_clock_t *best_clock);
258 265
259static const intel_limit_t intel_limits[] = { 266static bool
260 { /* INTEL_LIMIT_I8XX_DVO_DAC */ 267intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
268 int target, int refclk, intel_clock_t *best_clock);
269
270static const intel_limit_t intel_limits_i8xx_dvo = {
261 .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX }, 271 .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
262 .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX }, 272 .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
263 .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX }, 273 .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
@@ -269,8 +279,9 @@ static const intel_limit_t intel_limits[] = {
269 .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT, 279 .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
270 .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST }, 280 .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST },
271 .find_pll = intel_find_best_PLL, 281 .find_pll = intel_find_best_PLL,
272 }, 282};
273 { /* INTEL_LIMIT_I8XX_LVDS */ 283
284static const intel_limit_t intel_limits_i8xx_lvds = {
274 .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX }, 285 .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
275 .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX }, 286 .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
276 .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX }, 287 .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
@@ -282,8 +293,9 @@ static const intel_limit_t intel_limits[] = {
282 .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT, 293 .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
283 .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST }, 294 .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST },
284 .find_pll = intel_find_best_PLL, 295 .find_pll = intel_find_best_PLL,
285 }, 296};
286 { /* INTEL_LIMIT_I9XX_SDVO_DAC */ 297
298static const intel_limit_t intel_limits_i9xx_sdvo = {
287 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, 299 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
288 .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX }, 300 .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
289 .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX }, 301 .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
@@ -295,8 +307,9 @@ static const intel_limit_t intel_limits[] = {
295 .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT, 307 .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
296 .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST }, 308 .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
297 .find_pll = intel_find_best_PLL, 309 .find_pll = intel_find_best_PLL,
298 }, 310};
299 { /* INTEL_LIMIT_I9XX_LVDS */ 311
312static const intel_limit_t intel_limits_i9xx_lvds = {
300 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, 313 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
301 .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX }, 314 .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
302 .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX }, 315 .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
@@ -311,9 +324,10 @@ static const intel_limit_t intel_limits[] = {
311 .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT, 324 .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
312 .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST }, 325 .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST },
313 .find_pll = intel_find_best_PLL, 326 .find_pll = intel_find_best_PLL,
314 }, 327};
328
315 /* below parameter and function is for G4X Chipset Family*/ 329 /* below parameter and function is for G4X Chipset Family*/
316 { /* INTEL_LIMIT_G4X_SDVO */ 330static const intel_limit_t intel_limits_g4x_sdvo = {
317 .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX }, 331 .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX },
318 .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX}, 332 .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
319 .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX }, 333 .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX },
@@ -327,8 +341,9 @@ static const intel_limit_t intel_limits[] = {
327 .p2_fast = G4X_P2_SDVO_FAST 341 .p2_fast = G4X_P2_SDVO_FAST
328 }, 342 },
329 .find_pll = intel_g4x_find_best_PLL, 343 .find_pll = intel_g4x_find_best_PLL,
330 }, 344};
331 { /* INTEL_LIMIT_G4X_HDMI_DAC */ 345
346static const intel_limit_t intel_limits_g4x_hdmi = {
332 .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX }, 347 .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX },
333 .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX}, 348 .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
334 .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX }, 349 .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX },
@@ -342,8 +357,9 @@ static const intel_limit_t intel_limits[] = {
342 .p2_fast = G4X_P2_HDMI_DAC_FAST 357 .p2_fast = G4X_P2_HDMI_DAC_FAST
343 }, 358 },
344 .find_pll = intel_g4x_find_best_PLL, 359 .find_pll = intel_g4x_find_best_PLL,
345 }, 360};
346 { /* INTEL_LIMIT_G4X_SINGLE_CHANNEL_LVDS */ 361
362static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
347 .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN, 363 .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN,
348 .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX }, 364 .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX },
349 .vco = { .min = G4X_VCO_MIN, 365 .vco = { .min = G4X_VCO_MIN,
@@ -365,8 +381,9 @@ static const intel_limit_t intel_limits[] = {
365 .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST 381 .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST
366 }, 382 },
367 .find_pll = intel_g4x_find_best_PLL, 383 .find_pll = intel_g4x_find_best_PLL,
368 }, 384};
369 { /* INTEL_LIMIT_G4X_DUAL_CHANNEL_LVDS */ 385
386static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
370 .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN, 387 .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN,
371 .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX }, 388 .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX },
372 .vco = { .min = G4X_VCO_MIN, 389 .vco = { .min = G4X_VCO_MIN,
@@ -388,8 +405,32 @@ static const intel_limit_t intel_limits[] = {
388 .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST 405 .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST
389 }, 406 },
390 .find_pll = intel_g4x_find_best_PLL, 407 .find_pll = intel_g4x_find_best_PLL,
391 }, 408};
392 { /* INTEL_LIMIT_IGD_SDVO */ 409
410static const intel_limit_t intel_limits_g4x_display_port = {
411 .dot = { .min = G4X_DOT_DISPLAY_PORT_MIN,
412 .max = G4X_DOT_DISPLAY_PORT_MAX },
413 .vco = { .min = G4X_VCO_MIN,
414 .max = G4X_VCO_MAX},
415 .n = { .min = G4X_N_DISPLAY_PORT_MIN,
416 .max = G4X_N_DISPLAY_PORT_MAX },
417 .m = { .min = G4X_M_DISPLAY_PORT_MIN,
418 .max = G4X_M_DISPLAY_PORT_MAX },
419 .m1 = { .min = G4X_M1_DISPLAY_PORT_MIN,
420 .max = G4X_M1_DISPLAY_PORT_MAX },
421 .m2 = { .min = G4X_M2_DISPLAY_PORT_MIN,
422 .max = G4X_M2_DISPLAY_PORT_MAX },
423 .p = { .min = G4X_P_DISPLAY_PORT_MIN,
424 .max = G4X_P_DISPLAY_PORT_MAX },
425 .p1 = { .min = G4X_P1_DISPLAY_PORT_MIN,
426 .max = G4X_P1_DISPLAY_PORT_MAX},
427 .p2 = { .dot_limit = G4X_P2_DISPLAY_PORT_LIMIT,
428 .p2_slow = G4X_P2_DISPLAY_PORT_SLOW,
429 .p2_fast = G4X_P2_DISPLAY_PORT_FAST },
430 .find_pll = intel_find_pll_g4x_dp,
431};
432
433static const intel_limit_t intel_limits_igd_sdvo = {
393 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX}, 434 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX},
394 .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX }, 435 .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX },
395 .n = { .min = IGD_N_MIN, .max = IGD_N_MAX }, 436 .n = { .min = IGD_N_MIN, .max = IGD_N_MAX },
@@ -401,8 +442,9 @@ static const intel_limit_t intel_limits[] = {
401 .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT, 442 .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
402 .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST }, 443 .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
403 .find_pll = intel_find_best_PLL, 444 .find_pll = intel_find_best_PLL,
404 }, 445};
405 { /* INTEL_LIMIT_IGD_LVDS */ 446
447static const intel_limit_t intel_limits_igd_lvds = {
406 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX }, 448 .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
407 .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX }, 449 .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX },
408 .n = { .min = IGD_N_MIN, .max = IGD_N_MAX }, 450 .n = { .min = IGD_N_MIN, .max = IGD_N_MAX },
@@ -415,8 +457,9 @@ static const intel_limit_t intel_limits[] = {
415 .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT, 457 .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
416 .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW }, 458 .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW },
417 .find_pll = intel_find_best_PLL, 459 .find_pll = intel_find_best_PLL,
418 }, 460};
419 { /* INTEL_LIMIT_IGDNG_SDVO_DAC */ 461
462static const intel_limit_t intel_limits_igdng_sdvo = {
420 .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX }, 463 .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX },
421 .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX }, 464 .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX },
422 .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX }, 465 .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX },
@@ -429,8 +472,9 @@ static const intel_limit_t intel_limits[] = {
429 .p2_slow = IGDNG_P2_SDVO_DAC_SLOW, 472 .p2_slow = IGDNG_P2_SDVO_DAC_SLOW,
430 .p2_fast = IGDNG_P2_SDVO_DAC_FAST }, 473 .p2_fast = IGDNG_P2_SDVO_DAC_FAST },
431 .find_pll = intel_igdng_find_best_PLL, 474 .find_pll = intel_igdng_find_best_PLL,
432 }, 475};
433 { /* INTEL_LIMIT_IGDNG_LVDS */ 476
477static const intel_limit_t intel_limits_igdng_lvds = {
434 .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX }, 478 .dot = { .min = IGDNG_DOT_MIN, .max = IGDNG_DOT_MAX },
435 .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX }, 479 .vco = { .min = IGDNG_VCO_MIN, .max = IGDNG_VCO_MAX },
436 .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX }, 480 .n = { .min = IGDNG_N_MIN, .max = IGDNG_N_MAX },
@@ -443,16 +487,15 @@ static const intel_limit_t intel_limits[] = {
443 .p2_slow = IGDNG_P2_LVDS_SLOW, 487 .p2_slow = IGDNG_P2_LVDS_SLOW,
444 .p2_fast = IGDNG_P2_LVDS_FAST }, 488 .p2_fast = IGDNG_P2_LVDS_FAST },
445 .find_pll = intel_igdng_find_best_PLL, 489 .find_pll = intel_igdng_find_best_PLL,
446 },
447}; 490};
448 491
449static const intel_limit_t *intel_igdng_limit(struct drm_crtc *crtc) 492static const intel_limit_t *intel_igdng_limit(struct drm_crtc *crtc)
450{ 493{
451 const intel_limit_t *limit; 494 const intel_limit_t *limit;
452 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) 495 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
453 limit = &intel_limits[INTEL_LIMIT_IGDNG_LVDS]; 496 limit = &intel_limits_igdng_lvds;
454 else 497 else
455 limit = &intel_limits[INTEL_LIMIT_IGDNG_SDVO_DAC]; 498 limit = &intel_limits_igdng_sdvo;
456 499
457 return limit; 500 return limit;
458} 501}
@@ -467,19 +510,19 @@ static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
467 if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) == 510 if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
468 LVDS_CLKB_POWER_UP) 511 LVDS_CLKB_POWER_UP)
469 /* LVDS with dual channel */ 512 /* LVDS with dual channel */
470 limit = &intel_limits 513 limit = &intel_limits_g4x_dual_channel_lvds;
471 [INTEL_LIMIT_G4X_DUAL_CHANNEL_LVDS];
472 else 514 else
473 /* LVDS with dual channel */ 515 /* LVDS with dual channel */
474 limit = &intel_limits 516 limit = &intel_limits_g4x_single_channel_lvds;
475 [INTEL_LIMIT_G4X_SINGLE_CHANNEL_LVDS];
476 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) || 517 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
477 intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) { 518 intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
478 limit = &intel_limits[INTEL_LIMIT_G4X_HDMI_DAC]; 519 limit = &intel_limits_g4x_hdmi;
479 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) { 520 } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
480 limit = &intel_limits[INTEL_LIMIT_G4X_SDVO]; 521 limit = &intel_limits_g4x_sdvo;
522 } else if (intel_pipe_has_type (crtc, INTEL_OUTPUT_DISPLAYPORT)) {
523 limit = &intel_limits_g4x_display_port;
481 } else /* The option is for other outputs */ 524 } else /* The option is for other outputs */
482 limit = &intel_limits[INTEL_LIMIT_I9XX_SDVO_DAC]; 525 limit = &intel_limits_i9xx_sdvo;
483 526
484 return limit; 527 return limit;
485} 528}
@@ -495,19 +538,19 @@ static const intel_limit_t *intel_limit(struct drm_crtc *crtc)
495 limit = intel_g4x_limit(crtc); 538 limit = intel_g4x_limit(crtc);
496 } else if (IS_I9XX(dev) && !IS_IGD(dev)) { 539 } else if (IS_I9XX(dev) && !IS_IGD(dev)) {
497 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) 540 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
498 limit = &intel_limits[INTEL_LIMIT_I9XX_LVDS]; 541 limit = &intel_limits_i9xx_lvds;
499 else 542 else
500 limit = &intel_limits[INTEL_LIMIT_I9XX_SDVO_DAC]; 543 limit = &intel_limits_i9xx_sdvo;
501 } else if (IS_IGD(dev)) { 544 } else if (IS_IGD(dev)) {
502 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) 545 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
503 limit = &intel_limits[INTEL_LIMIT_IGD_LVDS]; 546 limit = &intel_limits_igd_lvds;
504 else 547 else
505 limit = &intel_limits[INTEL_LIMIT_IGD_SDVO_DAC]; 548 limit = &intel_limits_igd_sdvo;
506 } else { 549 } else {
507 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) 550 if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
508 limit = &intel_limits[INTEL_LIMIT_I8XX_LVDS]; 551 limit = &intel_limits_i8xx_lvds;
509 else 552 else
510 limit = &intel_limits[INTEL_LIMIT_I8XX_DVO_DAC]; 553 limit = &intel_limits_i8xx_dvo;
511 } 554 }
512 return limit; 555 return limit;
513} 556}
@@ -764,6 +807,35 @@ out:
764 return found; 807 return found;
765} 808}
766 809
810/* DisplayPort has only two frequencies, 162MHz and 270MHz */
811static bool
812intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
813 int target, int refclk, intel_clock_t *best_clock)
814{
815 intel_clock_t clock;
816 if (target < 200000) {
817 clock.dot = 161670;
818 clock.p = 20;
819 clock.p1 = 2;
820 clock.p2 = 10;
821 clock.n = 0x01;
822 clock.m = 97;
823 clock.m1 = 0x10;
824 clock.m2 = 0x05;
825 } else {
826 clock.dot = 270000;
827 clock.p = 10;
828 clock.p1 = 1;
829 clock.p2 = 10;
830 clock.n = 0x02;
831 clock.m = 108;
832 clock.m1 = 0x12;
833 clock.m2 = 0x06;
834 }
835 memcpy(best_clock, &clock, sizeof(intel_clock_t));
836 return true;
837}
838
767void 839void
768intel_wait_for_vblank(struct drm_device *dev) 840intel_wait_for_vblank(struct drm_device *dev)
769{ 841{
@@ -1541,7 +1613,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1541 intel_clock_t clock; 1613 intel_clock_t clock;
1542 u32 dpll = 0, fp = 0, dspcntr, pipeconf; 1614 u32 dpll = 0, fp = 0, dspcntr, pipeconf;
1543 bool ok, is_sdvo = false, is_dvo = false; 1615 bool ok, is_sdvo = false, is_dvo = false;
1544 bool is_crt = false, is_lvds = false, is_tv = false; 1616 bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
1545 struct drm_mode_config *mode_config = &dev->mode_config; 1617 struct drm_mode_config *mode_config = &dev->mode_config;
1546 struct drm_connector *connector; 1618 struct drm_connector *connector;
1547 const intel_limit_t *limit; 1619 const intel_limit_t *limit;
@@ -1585,6 +1657,9 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1585 case INTEL_OUTPUT_ANALOG: 1657 case INTEL_OUTPUT_ANALOG:
1586 is_crt = true; 1658 is_crt = true;
1587 break; 1659 break;
1660 case INTEL_OUTPUT_DISPLAYPORT:
1661 is_dp = true;
1662 break;
1588 } 1663 }
1589 1664
1590 num_outputs++; 1665 num_outputs++;
@@ -1600,6 +1675,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1600 } else { 1675 } else {
1601 refclk = 48000; 1676 refclk = 48000;
1602 } 1677 }
1678
1603 1679
1604 /* 1680 /*
1605 * Returns a set of divisors for the desired target clock with the given 1681 * Returns a set of divisors for the desired target clock with the given
@@ -1662,6 +1738,8 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1662 else if (IS_IGDNG(dev)) 1738 else if (IS_IGDNG(dev))
1663 dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; 1739 dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
1664 } 1740 }
1741 if (is_dp)
1742 dpll |= DPLL_DVO_HIGH_SPEED;
1665 1743
1666 /* compute bitmask from p1 value */ 1744 /* compute bitmask from p1 value */
1667 if (IS_IGD(dev)) 1745 if (IS_IGD(dev))
@@ -1809,6 +1887,8 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
1809 I915_WRITE(lvds_reg, lvds); 1887 I915_WRITE(lvds_reg, lvds);
1810 I915_READ(lvds_reg); 1888 I915_READ(lvds_reg);
1811 } 1889 }
1890 if (is_dp)
1891 intel_dp_set_m_n(crtc, mode, adjusted_mode);
1812 1892
1813 I915_WRITE(fp_reg, fp); 1893 I915_WRITE(fp_reg, fp);
1814 I915_WRITE(dpll_reg, dpll); 1894 I915_WRITE(dpll_reg, dpll);
@@ -2475,6 +2555,8 @@ static void intel_setup_outputs(struct drm_device *dev)
2475 found = intel_sdvo_init(dev, SDVOB); 2555 found = intel_sdvo_init(dev, SDVOB);
2476 if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) 2556 if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
2477 intel_hdmi_init(dev, SDVOB); 2557 intel_hdmi_init(dev, SDVOB);
2558 if (!found && SUPPORTS_INTEGRATED_DP(dev))
2559 intel_dp_init(dev, DP_B);
2478 } 2560 }
2479 2561
2480 /* Before G4X SDVOC doesn't have its own detect register */ 2562 /* Before G4X SDVOC doesn't have its own detect register */
@@ -2487,7 +2569,11 @@ static void intel_setup_outputs(struct drm_device *dev)
2487 found = intel_sdvo_init(dev, SDVOC); 2569 found = intel_sdvo_init(dev, SDVOC);
2488 if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) 2570 if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
2489 intel_hdmi_init(dev, SDVOC); 2571 intel_hdmi_init(dev, SDVOC);
2572 if (!found && SUPPORTS_INTEGRATED_DP(dev))
2573 intel_dp_init(dev, DP_C);
2490 } 2574 }
2575 if (SUPPORTS_INTEGRATED_DP(dev) && (I915_READ(DP_D) & DP_DETECTED))
2576 intel_dp_init(dev, DP_D);
2491 } else 2577 } else
2492 intel_dvo_init(dev); 2578 intel_dvo_init(dev);
2493 2579
@@ -2530,6 +2616,11 @@ static void intel_setup_outputs(struct drm_device *dev)
2530 (1 << 1)); 2616 (1 << 1));
2531 clone_mask = (1 << INTEL_OUTPUT_TVOUT); 2617 clone_mask = (1 << INTEL_OUTPUT_TVOUT);
2532 break; 2618 break;
2619 case INTEL_OUTPUT_DISPLAYPORT:
2620 crtc_mask = ((1 << 0) |
2621 (1 << 1));
2622 clone_mask = (1 << INTEL_OUTPUT_DISPLAYPORT);
2623 break;
2533 } 2624 }
2534 encoder->possible_crtcs = crtc_mask; 2625 encoder->possible_crtcs = crtc_mask;
2535 encoder->possible_clones = intel_connector_clones(dev, clone_mask); 2626 encoder->possible_clones = intel_connector_clones(dev, clone_mask);
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
new file mode 100644
index 000000000000..8f8d37d5663a
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -0,0 +1,1153 @@
1/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Keith Packard <keithp@keithp.com>
25 *
26 */
27
28#include <linux/i2c.h>
29#include "drmP.h"
30#include "drm.h"
31#include "drm_crtc.h"
32#include "drm_crtc_helper.h"
33#include "intel_drv.h"
34#include "i915_drm.h"
35#include "i915_drv.h"
36#include "intel_dp.h"
37
38#define DP_LINK_STATUS_SIZE 6
39#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
40
41#define DP_LINK_CONFIGURATION_SIZE 9
42
43struct intel_dp_priv {
44 uint32_t output_reg;
45 uint32_t DP;
46 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE];
47 uint32_t save_DP;
48 uint8_t save_link_configuration[DP_LINK_CONFIGURATION_SIZE];
49 bool has_audio;
50 int dpms_mode;
51 uint8_t link_bw;
52 uint8_t lane_count;
53 uint8_t dpcd[4];
54 struct intel_output *intel_output;
55 struct i2c_adapter adapter;
56 struct i2c_algo_dp_aux_data algo;
57};
58
59static void
60intel_dp_link_train(struct intel_output *intel_output, uint32_t DP,
61 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]);
62
63static void
64intel_dp_link_down(struct intel_output *intel_output, uint32_t DP);
65
66static int
67intel_dp_max_lane_count(struct intel_output *intel_output)
68{
69 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
70 int max_lane_count = 4;
71
72 if (dp_priv->dpcd[0] >= 0x11) {
73 max_lane_count = dp_priv->dpcd[2] & 0x1f;
74 switch (max_lane_count) {
75 case 1: case 2: case 4:
76 break;
77 default:
78 max_lane_count = 4;
79 }
80 }
81 return max_lane_count;
82}
83
84static int
85intel_dp_max_link_bw(struct intel_output *intel_output)
86{
87 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
88 int max_link_bw = dp_priv->dpcd[1];
89
90 switch (max_link_bw) {
91 case DP_LINK_BW_1_62:
92 case DP_LINK_BW_2_7:
93 break;
94 default:
95 max_link_bw = DP_LINK_BW_1_62;
96 break;
97 }
98 return max_link_bw;
99}
100
101static int
102intel_dp_link_clock(uint8_t link_bw)
103{
104 if (link_bw == DP_LINK_BW_2_7)
105 return 270000;
106 else
107 return 162000;
108}
109
110/* I think this is a fiction */
111static int
112intel_dp_link_required(int pixel_clock)
113{
114 return pixel_clock * 3;
115}
116
117static int
118intel_dp_mode_valid(struct drm_connector *connector,
119 struct drm_display_mode *mode)
120{
121 struct intel_output *intel_output = to_intel_output(connector);
122 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_output));
123 int max_lanes = intel_dp_max_lane_count(intel_output);
124
125 if (intel_dp_link_required(mode->clock) > max_link_clock * max_lanes)
126 return MODE_CLOCK_HIGH;
127
128 if (mode->clock < 10000)
129 return MODE_CLOCK_LOW;
130
131 return MODE_OK;
132}
133
134static uint32_t
135pack_aux(uint8_t *src, int src_bytes)
136{
137 int i;
138 uint32_t v = 0;
139
140 if (src_bytes > 4)
141 src_bytes = 4;
142 for (i = 0; i < src_bytes; i++)
143 v |= ((uint32_t) src[i]) << ((3-i) * 8);
144 return v;
145}
146
147static void
148unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
149{
150 int i;
151 if (dst_bytes > 4)
152 dst_bytes = 4;
153 for (i = 0; i < dst_bytes; i++)
154 dst[i] = src >> ((3-i) * 8);
155}
156
157/* hrawclock is 1/4 the FSB frequency */
158static int
159intel_hrawclk(struct drm_device *dev)
160{
161 struct drm_i915_private *dev_priv = dev->dev_private;
162 uint32_t clkcfg;
163
164 clkcfg = I915_READ(CLKCFG);
165 switch (clkcfg & CLKCFG_FSB_MASK) {
166 case CLKCFG_FSB_400:
167 return 100;
168 case CLKCFG_FSB_533:
169 return 133;
170 case CLKCFG_FSB_667:
171 return 166;
172 case CLKCFG_FSB_800:
173 return 200;
174 case CLKCFG_FSB_1067:
175 return 266;
176 case CLKCFG_FSB_1333:
177 return 333;
178 /* these two are just a guess; one of them might be right */
179 case CLKCFG_FSB_1600:
180 case CLKCFG_FSB_1600_ALT:
181 return 400;
182 default:
183 return 133;
184 }
185}
186
187static int
188intel_dp_aux_ch(struct intel_output *intel_output,
189 uint8_t *send, int send_bytes,
190 uint8_t *recv, int recv_size)
191{
192 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
193 uint32_t output_reg = dp_priv->output_reg;
194 struct drm_device *dev = intel_output->base.dev;
195 struct drm_i915_private *dev_priv = dev->dev_private;
196 uint32_t ch_ctl = output_reg + 0x10;
197 uint32_t ch_data = ch_ctl + 4;
198 int i;
199 int recv_bytes;
200 uint32_t ctl;
201 uint32_t status;
202 uint32_t aux_clock_divider;
203 int try;
204
205 /* The clock divider is based off the hrawclk,
206 * and would like to run at 2MHz. So, take the
207 * hrawclk value and divide by 2 and use that
208 */
209 aux_clock_divider = intel_hrawclk(dev) / 2;
210 /* Must try at least 3 times according to DP spec */
211 for (try = 0; try < 5; try++) {
212 /* Load the send data into the aux channel data registers */
213 for (i = 0; i < send_bytes; i += 4) {
214 uint32_t d = pack_aux(send + i, send_bytes - i);;
215
216 I915_WRITE(ch_data + i, d);
217 }
218
219 ctl = (DP_AUX_CH_CTL_SEND_BUSY |
220 DP_AUX_CH_CTL_TIME_OUT_400us |
221 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
222 (5 << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
223 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
224 DP_AUX_CH_CTL_DONE |
225 DP_AUX_CH_CTL_TIME_OUT_ERROR |
226 DP_AUX_CH_CTL_RECEIVE_ERROR);
227
228 /* Send the command and wait for it to complete */
229 I915_WRITE(ch_ctl, ctl);
230 (void) I915_READ(ch_ctl);
231 for (;;) {
232 udelay(100);
233 status = I915_READ(ch_ctl);
234 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
235 break;
236 }
237
238 /* Clear done status and any errors */
239 I915_WRITE(ch_ctl, (ctl |
240 DP_AUX_CH_CTL_DONE |
241 DP_AUX_CH_CTL_TIME_OUT_ERROR |
242 DP_AUX_CH_CTL_RECEIVE_ERROR));
243 (void) I915_READ(ch_ctl);
244 if ((status & DP_AUX_CH_CTL_TIME_OUT_ERROR) == 0)
245 break;
246 }
247
248 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
249 printk(KERN_ERR "dp_aux_ch not done status 0x%08x\n", status);
250 return -EBUSY;
251 }
252
253 /* Check for timeout or receive error.
254 * Timeouts occur when the sink is not connected
255 */
256 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
257 printk(KERN_ERR "dp_aux_ch receive error status 0x%08x\n", status);
258 return -EIO;
259 }
260 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
261 printk(KERN_ERR "dp_aux_ch timeout status 0x%08x\n", status);
262 return -ETIMEDOUT;
263 }
264
265 /* Unload any bytes sent back from the other side */
266 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
267 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
268
269 if (recv_bytes > recv_size)
270 recv_bytes = recv_size;
271
272 for (i = 0; i < recv_bytes; i += 4) {
273 uint32_t d = I915_READ(ch_data + i);
274
275 unpack_aux(d, recv + i, recv_bytes - i);
276 }
277
278 return recv_bytes;
279}
280
281/* Write data to the aux channel in native mode */
282static int
283intel_dp_aux_native_write(struct intel_output *intel_output,
284 uint16_t address, uint8_t *send, int send_bytes)
285{
286 int ret;
287 uint8_t msg[20];
288 int msg_bytes;
289 uint8_t ack;
290
291 if (send_bytes > 16)
292 return -1;
293 msg[0] = AUX_NATIVE_WRITE << 4;
294 msg[1] = address >> 8;
295 msg[2] = address;
296 msg[3] = send_bytes - 1;
297 memcpy(&msg[4], send, send_bytes);
298 msg_bytes = send_bytes + 4;
299 for (;;) {
300 ret = intel_dp_aux_ch(intel_output, msg, msg_bytes, &ack, 1);
301 if (ret < 0)
302 return ret;
303 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
304 break;
305 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
306 udelay(100);
307 else
308 return -EIO;
309 }
310 return send_bytes;
311}
312
313/* Write a single byte to the aux channel in native mode */
314static int
315intel_dp_aux_native_write_1(struct intel_output *intel_output,
316 uint16_t address, uint8_t byte)
317{
318 return intel_dp_aux_native_write(intel_output, address, &byte, 1);
319}
320
321/* read bytes from a native aux channel */
322static int
323intel_dp_aux_native_read(struct intel_output *intel_output,
324 uint16_t address, uint8_t *recv, int recv_bytes)
325{
326 uint8_t msg[4];
327 int msg_bytes;
328 uint8_t reply[20];
329 int reply_bytes;
330 uint8_t ack;
331 int ret;
332
333 msg[0] = AUX_NATIVE_READ << 4;
334 msg[1] = address >> 8;
335 msg[2] = address & 0xff;
336 msg[3] = recv_bytes - 1;
337
338 msg_bytes = 4;
339 reply_bytes = recv_bytes + 1;
340
341 for (;;) {
342 ret = intel_dp_aux_ch(intel_output, msg, msg_bytes,
343 reply, reply_bytes);
344 if (ret == 0)
345 return -EPROTO;
346 if (ret < 0)
347 return ret;
348 ack = reply[0];
349 if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
350 memcpy(recv, reply + 1, ret - 1);
351 return ret - 1;
352 }
353 else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
354 udelay(100);
355 else
356 return -EIO;
357 }
358}
359
360static int
361intel_dp_i2c_aux_ch(struct i2c_adapter *adapter,
362 uint8_t *send, int send_bytes,
363 uint8_t *recv, int recv_bytes)
364{
365 struct intel_dp_priv *dp_priv = container_of(adapter,
366 struct intel_dp_priv,
367 adapter);
368 struct intel_output *intel_output = dp_priv->intel_output;
369
370 return intel_dp_aux_ch(intel_output,
371 send, send_bytes, recv, recv_bytes);
372}
373
374static int
375intel_dp_i2c_init(struct intel_output *intel_output, const char *name)
376{
377 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
378
379 DRM_ERROR("i2c_init %s\n", name);
380 dp_priv->algo.running = false;
381 dp_priv->algo.address = 0;
382 dp_priv->algo.aux_ch = intel_dp_i2c_aux_ch;
383
384 memset(&dp_priv->adapter, '\0', sizeof (dp_priv->adapter));
385 dp_priv->adapter.owner = THIS_MODULE;
386 dp_priv->adapter.class = I2C_CLASS_DDC;
387 strncpy (dp_priv->adapter.name, name, sizeof dp_priv->adapter.name - 1);
388 dp_priv->adapter.name[sizeof dp_priv->adapter.name - 1] = '\0';
389 dp_priv->adapter.algo_data = &dp_priv->algo;
390 dp_priv->adapter.dev.parent = &intel_output->base.kdev;
391
392 return i2c_dp_aux_add_bus(&dp_priv->adapter);
393}
394
395static bool
396intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
397 struct drm_display_mode *adjusted_mode)
398{
399 struct intel_output *intel_output = enc_to_intel_output(encoder);
400 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
401 int lane_count, clock;
402 int max_lane_count = intel_dp_max_lane_count(intel_output);
403 int max_clock = intel_dp_max_link_bw(intel_output) == DP_LINK_BW_2_7 ? 1 : 0;
404 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
405
406 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
407 for (clock = 0; clock <= max_clock; clock++) {
408 int link_avail = intel_dp_link_clock(bws[clock]) * lane_count;
409
410 if (intel_dp_link_required(mode->clock) <= link_avail) {
411 dp_priv->link_bw = bws[clock];
412 dp_priv->lane_count = lane_count;
413 adjusted_mode->clock = intel_dp_link_clock(dp_priv->link_bw);
414 printk(KERN_ERR "link bw %02x lane count %d clock %d\n",
415 dp_priv->link_bw, dp_priv->lane_count,
416 adjusted_mode->clock);
417 return true;
418 }
419 }
420 }
421 return false;
422}
423
424struct intel_dp_m_n {
425 uint32_t tu;
426 uint32_t gmch_m;
427 uint32_t gmch_n;
428 uint32_t link_m;
429 uint32_t link_n;
430};
431
432static void
433intel_reduce_ratio(uint32_t *num, uint32_t *den)
434{
435 while (*num > 0xffffff || *den > 0xffffff) {
436 *num >>= 1;
437 *den >>= 1;
438 }
439}
440
441static void
442intel_dp_compute_m_n(int bytes_per_pixel,
443 int nlanes,
444 int pixel_clock,
445 int link_clock,
446 struct intel_dp_m_n *m_n)
447{
448 m_n->tu = 64;
449 m_n->gmch_m = pixel_clock * bytes_per_pixel;
450 m_n->gmch_n = link_clock * nlanes;
451 intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
452 m_n->link_m = pixel_clock;
453 m_n->link_n = link_clock;
454 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
455}
456
457void
458intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
459 struct drm_display_mode *adjusted_mode)
460{
461 struct drm_device *dev = crtc->dev;
462 struct drm_mode_config *mode_config = &dev->mode_config;
463 struct drm_connector *connector;
464 struct drm_i915_private *dev_priv = dev->dev_private;
465 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
466 int lane_count = 4;
467 struct intel_dp_m_n m_n;
468
469 /*
470 * Find the lane count in the intel_output private
471 */
472 list_for_each_entry(connector, &mode_config->connector_list, head) {
473 struct intel_output *intel_output = to_intel_output(connector);
474 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
475
476 if (!connector->encoder || connector->encoder->crtc != crtc)
477 continue;
478
479 if (intel_output->type == INTEL_OUTPUT_DISPLAYPORT) {
480 lane_count = dp_priv->lane_count;
481 break;
482 }
483 }
484
485 /*
486 * Compute the GMCH and Link ratios. The '3' here is
487 * the number of bytes_per_pixel post-LUT, which we always
488 * set up for 8-bits of R/G/B, or 3 bytes total.
489 */
490 intel_dp_compute_m_n(3, lane_count,
491 mode->clock, adjusted_mode->clock, &m_n);
492
493 if (intel_crtc->pipe == 0) {
494 I915_WRITE(PIPEA_GMCH_DATA_M,
495 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
496 m_n.gmch_m);
497 I915_WRITE(PIPEA_GMCH_DATA_N,
498 m_n.gmch_n);
499 I915_WRITE(PIPEA_DP_LINK_M, m_n.link_m);
500 I915_WRITE(PIPEA_DP_LINK_N, m_n.link_n);
501 } else {
502 I915_WRITE(PIPEB_GMCH_DATA_M,
503 ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
504 m_n.gmch_m);
505 I915_WRITE(PIPEB_GMCH_DATA_N,
506 m_n.gmch_n);
507 I915_WRITE(PIPEB_DP_LINK_M, m_n.link_m);
508 I915_WRITE(PIPEB_DP_LINK_N, m_n.link_n);
509 }
510}
511
512static void
513intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
514 struct drm_display_mode *adjusted_mode)
515{
516 struct intel_output *intel_output = enc_to_intel_output(encoder);
517 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
518 struct drm_crtc *crtc = intel_output->enc.crtc;
519 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
520
521 dp_priv->DP = (DP_LINK_TRAIN_OFF |
522 DP_VOLTAGE_0_4 |
523 DP_PRE_EMPHASIS_0 |
524 DP_SYNC_VS_HIGH |
525 DP_SYNC_HS_HIGH);
526
527 switch (dp_priv->lane_count) {
528 case 1:
529 dp_priv->DP |= DP_PORT_WIDTH_1;
530 break;
531 case 2:
532 dp_priv->DP |= DP_PORT_WIDTH_2;
533 break;
534 case 4:
535 dp_priv->DP |= DP_PORT_WIDTH_4;
536 break;
537 }
538 if (dp_priv->has_audio)
539 dp_priv->DP |= DP_AUDIO_OUTPUT_ENABLE;
540
541 memset(dp_priv->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
542 dp_priv->link_configuration[0] = dp_priv->link_bw;
543 dp_priv->link_configuration[1] = dp_priv->lane_count;
544
545 /*
546 * Check for DPCD version > 1.1,
547 * enable enahanced frame stuff in that case
548 */
549 if (dp_priv->dpcd[0] >= 0x11) {
550 dp_priv->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
551 dp_priv->DP |= DP_ENHANCED_FRAMING;
552 }
553
554 if (intel_crtc->pipe == 1)
555 dp_priv->DP |= DP_PIPEB_SELECT;
556}
557
558
559static void
560intel_dp_dpms(struct drm_encoder *encoder, int mode)
561{
562 struct intel_output *intel_output = enc_to_intel_output(encoder);
563 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
564 struct drm_device *dev = intel_output->base.dev;
565 struct drm_i915_private *dev_priv = dev->dev_private;
566 uint32_t dp_reg = I915_READ(dp_priv->output_reg);
567
568 if (mode != DRM_MODE_DPMS_ON) {
569 if (dp_reg & DP_PORT_EN)
570 intel_dp_link_down(intel_output, dp_priv->DP);
571 } else {
572 if (!(dp_reg & DP_PORT_EN))
573 intel_dp_link_train(intel_output, dp_priv->DP, dp_priv->link_configuration);
574 }
575 dp_priv->dpms_mode = mode;
576}
577
578/*
579 * Fetch AUX CH registers 0x202 - 0x207 which contain
580 * link status information
581 */
582static bool
583intel_dp_get_link_status(struct intel_output *intel_output,
584 uint8_t link_status[DP_LINK_STATUS_SIZE])
585{
586 int ret;
587
588 ret = intel_dp_aux_native_read(intel_output,
589 DP_LANE0_1_STATUS,
590 link_status, DP_LINK_STATUS_SIZE);
591 if (ret != DP_LINK_STATUS_SIZE)
592 return false;
593 return true;
594}
595
596static uint8_t
597intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
598 int r)
599{
600 return link_status[r - DP_LANE0_1_STATUS];
601}
602
603static void
604intel_dp_save(struct drm_connector *connector)
605{
606 struct intel_output *intel_output = to_intel_output(connector);
607 struct drm_device *dev = intel_output->base.dev;
608 struct drm_i915_private *dev_priv = dev->dev_private;
609 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
610
611 dp_priv->save_DP = I915_READ(dp_priv->output_reg);
612 intel_dp_aux_native_read(intel_output, DP_LINK_BW_SET,
613 dp_priv->save_link_configuration,
614 sizeof (dp_priv->save_link_configuration));
615}
616
617static uint8_t
618intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE],
619 int lane)
620{
621 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
622 int s = ((lane & 1) ?
623 DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
624 DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
625 uint8_t l = intel_dp_link_status(link_status, i);
626
627 return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
628}
629
630static uint8_t
631intel_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE],
632 int lane)
633{
634 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
635 int s = ((lane & 1) ?
636 DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
637 DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
638 uint8_t l = intel_dp_link_status(link_status, i);
639
640 return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
641}
642
643
644#if 0
645static char *voltage_names[] = {
646 "0.4V", "0.6V", "0.8V", "1.2V"
647};
648static char *pre_emph_names[] = {
649 "0dB", "3.5dB", "6dB", "9.5dB"
650};
651static char *link_train_names[] = {
652 "pattern 1", "pattern 2", "idle", "off"
653};
654#endif
655
656/*
657 * These are source-specific values; current Intel hardware supports
658 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
659 */
660#define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800
661
662static uint8_t
663intel_dp_pre_emphasis_max(uint8_t voltage_swing)
664{
665 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
666 case DP_TRAIN_VOLTAGE_SWING_400:
667 return DP_TRAIN_PRE_EMPHASIS_6;
668 case DP_TRAIN_VOLTAGE_SWING_600:
669 return DP_TRAIN_PRE_EMPHASIS_6;
670 case DP_TRAIN_VOLTAGE_SWING_800:
671 return DP_TRAIN_PRE_EMPHASIS_3_5;
672 case DP_TRAIN_VOLTAGE_SWING_1200:
673 default:
674 return DP_TRAIN_PRE_EMPHASIS_0;
675 }
676}
677
678static void
679intel_get_adjust_train(struct intel_output *intel_output,
680 uint8_t link_status[DP_LINK_STATUS_SIZE],
681 int lane_count,
682 uint8_t train_set[4])
683{
684 uint8_t v = 0;
685 uint8_t p = 0;
686 int lane;
687
688 for (lane = 0; lane < lane_count; lane++) {
689 uint8_t this_v = intel_get_adjust_request_voltage(link_status, lane);
690 uint8_t this_p = intel_get_adjust_request_pre_emphasis(link_status, lane);
691
692 if (this_v > v)
693 v = this_v;
694 if (this_p > p)
695 p = this_p;
696 }
697
698 if (v >= I830_DP_VOLTAGE_MAX)
699 v = I830_DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED;
700
701 if (p >= intel_dp_pre_emphasis_max(v))
702 p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
703
704 for (lane = 0; lane < 4; lane++)
705 train_set[lane] = v | p;
706}
707
708static uint32_t
709intel_dp_signal_levels(uint8_t train_set, int lane_count)
710{
711 uint32_t signal_levels = 0;
712
713 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
714 case DP_TRAIN_VOLTAGE_SWING_400:
715 default:
716 signal_levels |= DP_VOLTAGE_0_4;
717 break;
718 case DP_TRAIN_VOLTAGE_SWING_600:
719 signal_levels |= DP_VOLTAGE_0_6;
720 break;
721 case DP_TRAIN_VOLTAGE_SWING_800:
722 signal_levels |= DP_VOLTAGE_0_8;
723 break;
724 case DP_TRAIN_VOLTAGE_SWING_1200:
725 signal_levels |= DP_VOLTAGE_1_2;
726 break;
727 }
728 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
729 case DP_TRAIN_PRE_EMPHASIS_0:
730 default:
731 signal_levels |= DP_PRE_EMPHASIS_0;
732 break;
733 case DP_TRAIN_PRE_EMPHASIS_3_5:
734 signal_levels |= DP_PRE_EMPHASIS_3_5;
735 break;
736 case DP_TRAIN_PRE_EMPHASIS_6:
737 signal_levels |= DP_PRE_EMPHASIS_6;
738 break;
739 case DP_TRAIN_PRE_EMPHASIS_9_5:
740 signal_levels |= DP_PRE_EMPHASIS_9_5;
741 break;
742 }
743 return signal_levels;
744}
745
746static uint8_t
747intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
748 int lane)
749{
750 int i = DP_LANE0_1_STATUS + (lane >> 1);
751 int s = (lane & 1) * 4;
752 uint8_t l = intel_dp_link_status(link_status, i);
753
754 return (l >> s) & 0xf;
755}
756
757/* Check for clock recovery is done on all channels */
758static bool
759intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
760{
761 int lane;
762 uint8_t lane_status;
763
764 for (lane = 0; lane < lane_count; lane++) {
765 lane_status = intel_get_lane_status(link_status, lane);
766 if ((lane_status & DP_LANE_CR_DONE) == 0)
767 return false;
768 }
769 return true;
770}
771
772/* Check to see if channel eq is done on all channels */
773#define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\
774 DP_LANE_CHANNEL_EQ_DONE|\
775 DP_LANE_SYMBOL_LOCKED)
776static bool
777intel_channel_eq_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
778{
779 uint8_t lane_align;
780 uint8_t lane_status;
781 int lane;
782
783 lane_align = intel_dp_link_status(link_status,
784 DP_LANE_ALIGN_STATUS_UPDATED);
785 if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
786 return false;
787 for (lane = 0; lane < lane_count; lane++) {
788 lane_status = intel_get_lane_status(link_status, lane);
789 if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS)
790 return false;
791 }
792 return true;
793}
794
795static bool
796intel_dp_set_link_train(struct intel_output *intel_output,
797 uint32_t dp_reg_value,
798 uint8_t dp_train_pat,
799 uint8_t train_set[4],
800 bool first)
801{
802 struct drm_device *dev = intel_output->base.dev;
803 struct drm_i915_private *dev_priv = dev->dev_private;
804 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
805 int ret;
806
807 I915_WRITE(dp_priv->output_reg, dp_reg_value);
808 POSTING_READ(dp_priv->output_reg);
809 if (first)
810 intel_wait_for_vblank(dev);
811
812 intel_dp_aux_native_write_1(intel_output,
813 DP_TRAINING_PATTERN_SET,
814 dp_train_pat);
815
816 ret = intel_dp_aux_native_write(intel_output,
817 DP_TRAINING_LANE0_SET, train_set, 4);
818 if (ret != 4)
819 return false;
820
821 return true;
822}
823
824static void
825intel_dp_link_train(struct intel_output *intel_output, uint32_t DP,
826 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE])
827{
828 struct drm_device *dev = intel_output->base.dev;
829 struct drm_i915_private *dev_priv = dev->dev_private;
830 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
831 uint8_t train_set[4];
832 uint8_t link_status[DP_LINK_STATUS_SIZE];
833 int i;
834 uint8_t voltage;
835 bool clock_recovery = false;
836 bool channel_eq = false;
837 bool first = true;
838 int tries;
839
840 /* Write the link configuration data */
841 intel_dp_aux_native_write(intel_output, 0x100,
842 link_configuration, DP_LINK_CONFIGURATION_SIZE);
843
844 DP |= DP_PORT_EN;
845 DP &= ~DP_LINK_TRAIN_MASK;
846 memset(train_set, 0, 4);
847 voltage = 0xff;
848 tries = 0;
849 clock_recovery = false;
850 for (;;) {
851 /* Use train_set[0] to set the voltage and pre emphasis values */
852 uint32_t signal_levels = intel_dp_signal_levels(train_set[0], dp_priv->lane_count);
853 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
854
855 if (!intel_dp_set_link_train(intel_output, DP | DP_LINK_TRAIN_PAT_1,
856 DP_TRAINING_PATTERN_1, train_set, first))
857 break;
858 first = false;
859 /* Set training pattern 1 */
860
861 udelay(100);
862 if (!intel_dp_get_link_status(intel_output, link_status))
863 break;
864
865 if (intel_clock_recovery_ok(link_status, dp_priv->lane_count)) {
866 clock_recovery = true;
867 break;
868 }
869
870 /* Check to see if we've tried the max voltage */
871 for (i = 0; i < dp_priv->lane_count; i++)
872 if ((train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
873 break;
874 if (i == dp_priv->lane_count)
875 break;
876
877 /* Check to see if we've tried the same voltage 5 times */
878 if ((train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
879 ++tries;
880 if (tries == 5)
881 break;
882 } else
883 tries = 0;
884 voltage = train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
885
886 /* Compute new train_set as requested by target */
887 intel_get_adjust_train(intel_output, link_status, dp_priv->lane_count, train_set);
888 }
889
890 /* channel equalization */
891 tries = 0;
892 channel_eq = false;
893 for (;;) {
894 /* Use train_set[0] to set the voltage and pre emphasis values */
895 uint32_t signal_levels = intel_dp_signal_levels(train_set[0], dp_priv->lane_count);
896 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
897
898 /* channel eq pattern */
899 if (!intel_dp_set_link_train(intel_output, DP | DP_LINK_TRAIN_PAT_2,
900 DP_TRAINING_PATTERN_2, train_set,
901 false))
902 break;
903
904 udelay(400);
905 if (!intel_dp_get_link_status(intel_output, link_status))
906 break;
907
908 if (intel_channel_eq_ok(link_status, dp_priv->lane_count)) {
909 channel_eq = true;
910 break;
911 }
912
913 /* Try 5 times */
914 if (tries > 5)
915 break;
916
917 /* Compute new train_set as requested by target */
918 intel_get_adjust_train(intel_output, link_status, dp_priv->lane_count, train_set);
919 ++tries;
920 }
921
922 I915_WRITE(dp_priv->output_reg, DP | DP_LINK_TRAIN_OFF);
923 POSTING_READ(dp_priv->output_reg);
924 intel_dp_aux_native_write_1(intel_output,
925 DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE);
926}
927
928static void
929intel_dp_link_down(struct intel_output *intel_output, uint32_t DP)
930{
931 struct drm_device *dev = intel_output->base.dev;
932 struct drm_i915_private *dev_priv = dev->dev_private;
933 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
934
935 I915_WRITE(dp_priv->output_reg, DP & ~DP_PORT_EN);
936 POSTING_READ(dp_priv->output_reg);
937}
938
939static void
940intel_dp_restore(struct drm_connector *connector)
941{
942 struct intel_output *intel_output = to_intel_output(connector);
943 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
944
945 if (dp_priv->save_DP & DP_PORT_EN)
946 intel_dp_link_train(intel_output, dp_priv->save_DP, dp_priv->save_link_configuration);
947 else
948 intel_dp_link_down(intel_output, dp_priv->save_DP);
949}
950
951/*
952 * According to DP spec
953 * 5.1.2:
954 * 1. Read DPCD
955 * 2. Configure link according to Receiver Capabilities
956 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
957 * 4. Check link status on receipt of hot-plug interrupt
958 */
959
960static void
961intel_dp_check_link_status(struct intel_output *intel_output)
962{
963 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
964 uint8_t link_status[DP_LINK_STATUS_SIZE];
965
966 if (!intel_output->enc.crtc)
967 return;
968
969 if (!intel_dp_get_link_status(intel_output, link_status)) {
970 intel_dp_link_down(intel_output, dp_priv->DP);
971 return;
972 }
973
974 if (!intel_channel_eq_ok(link_status, dp_priv->lane_count))
975 intel_dp_link_train(intel_output, dp_priv->DP, dp_priv->link_configuration);
976}
977
978/**
979 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
980 *
981 * \return true if DP port is connected.
982 * \return false if DP port is disconnected.
983 */
984static enum drm_connector_status
985intel_dp_detect(struct drm_connector *connector)
986{
987 struct intel_output *intel_output = to_intel_output(connector);
988 struct drm_device *dev = intel_output->base.dev;
989 struct drm_i915_private *dev_priv = dev->dev_private;
990 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
991 uint32_t temp, bit;
992 enum drm_connector_status status;
993
994 dp_priv->has_audio = false;
995
996 temp = I915_READ(PORT_HOTPLUG_EN);
997
998 I915_WRITE(PORT_HOTPLUG_EN,
999 temp |
1000 DPB_HOTPLUG_INT_EN |
1001 DPC_HOTPLUG_INT_EN |
1002 DPD_HOTPLUG_INT_EN);
1003
1004 POSTING_READ(PORT_HOTPLUG_EN);
1005
1006 switch (dp_priv->output_reg) {
1007 case DP_B:
1008 bit = DPB_HOTPLUG_INT_STATUS;
1009 break;
1010 case DP_C:
1011 bit = DPC_HOTPLUG_INT_STATUS;
1012 break;
1013 case DP_D:
1014 bit = DPD_HOTPLUG_INT_STATUS;
1015 break;
1016 default:
1017 return connector_status_unknown;
1018 }
1019
1020 temp = I915_READ(PORT_HOTPLUG_STAT);
1021
1022 if ((temp & bit) == 0)
1023 return connector_status_disconnected;
1024
1025 status = connector_status_disconnected;
1026 if (intel_dp_aux_native_read(intel_output,
1027 0x000, dp_priv->dpcd,
1028 sizeof (dp_priv->dpcd)) == sizeof (dp_priv->dpcd))
1029 {
1030 if (dp_priv->dpcd[0] != 0)
1031 status = connector_status_connected;
1032 }
1033 return status;
1034}
1035
1036static int intel_dp_get_modes(struct drm_connector *connector)
1037{
1038 struct intel_output *intel_output = to_intel_output(connector);
1039
1040 /* We should parse the EDID data and find out if it has an audio sink
1041 */
1042
1043 return intel_ddc_get_modes(intel_output);
1044}
1045
1046static void
1047intel_dp_destroy (struct drm_connector *connector)
1048{
1049 struct intel_output *intel_output = to_intel_output(connector);
1050
1051 if (intel_output->i2c_bus)
1052 intel_i2c_destroy(intel_output->i2c_bus);
1053 drm_sysfs_connector_remove(connector);
1054 drm_connector_cleanup(connector);
1055 kfree(intel_output);
1056}
1057
1058static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
1059 .dpms = intel_dp_dpms,
1060 .mode_fixup = intel_dp_mode_fixup,
1061 .prepare = intel_encoder_prepare,
1062 .mode_set = intel_dp_mode_set,
1063 .commit = intel_encoder_commit,
1064};
1065
1066static const struct drm_connector_funcs intel_dp_connector_funcs = {
1067 .dpms = drm_helper_connector_dpms,
1068 .save = intel_dp_save,
1069 .restore = intel_dp_restore,
1070 .detect = intel_dp_detect,
1071 .fill_modes = drm_helper_probe_single_connector_modes,
1072 .destroy = intel_dp_destroy,
1073};
1074
1075static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
1076 .get_modes = intel_dp_get_modes,
1077 .mode_valid = intel_dp_mode_valid,
1078 .best_encoder = intel_best_encoder,
1079};
1080
1081static void intel_dp_enc_destroy(struct drm_encoder *encoder)
1082{
1083 drm_encoder_cleanup(encoder);
1084}
1085
1086static const struct drm_encoder_funcs intel_dp_enc_funcs = {
1087 .destroy = intel_dp_enc_destroy,
1088};
1089
1090void
1091intel_dp_hot_plug(struct intel_output *intel_output)
1092{
1093 struct intel_dp_priv *dp_priv = intel_output->dev_priv;
1094
1095 if (dp_priv->dpms_mode == DRM_MODE_DPMS_ON)
1096 intel_dp_check_link_status(intel_output);
1097}
1098
1099void
1100intel_dp_init(struct drm_device *dev, int output_reg)
1101{
1102 struct drm_i915_private *dev_priv = dev->dev_private;
1103 struct drm_connector *connector;
1104 struct intel_output *intel_output;
1105 struct intel_dp_priv *dp_priv;
1106
1107 intel_output = kcalloc(sizeof(struct intel_output) +
1108 sizeof(struct intel_dp_priv), 1, GFP_KERNEL);
1109 if (!intel_output)
1110 return;
1111
1112 dp_priv = (struct intel_dp_priv *)(intel_output + 1);
1113
1114 connector = &intel_output->base;
1115 drm_connector_init(dev, connector, &intel_dp_connector_funcs,
1116 DRM_MODE_CONNECTOR_DisplayPort);
1117 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
1118
1119 intel_output->type = INTEL_OUTPUT_DISPLAYPORT;
1120
1121 connector->interlace_allowed = true;
1122 connector->doublescan_allowed = 0;
1123
1124 dp_priv->intel_output = intel_output;
1125 dp_priv->output_reg = output_reg;
1126 dp_priv->has_audio = false;
1127 dp_priv->dpms_mode = DRM_MODE_DPMS_ON;
1128 intel_output->dev_priv = dp_priv;
1129
1130 drm_encoder_init(dev, &intel_output->enc, &intel_dp_enc_funcs,
1131 DRM_MODE_ENCODER_TMDS);
1132 drm_encoder_helper_add(&intel_output->enc, &intel_dp_helper_funcs);
1133
1134 drm_mode_connector_attach_encoder(&intel_output->base,
1135 &intel_output->enc);
1136 drm_sysfs_connector_add(connector);
1137
1138 /* Set up the DDC bus. */
1139 intel_dp_i2c_init(intel_output,
1140 (output_reg == DP_B) ? "DPDDC-B" :
1141 (output_reg == DP_C) ? "DPDDC-C" : "DPDDC-D");
1142 intel_output->ddc_bus = &dp_priv->adapter;
1143 intel_output->hot_plug = intel_dp_hot_plug;
1144
1145 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1146 * 0xd. Failure to do so will result in spurious interrupts being
1147 * generated on the port when a cable is not attached.
1148 */
1149 if (IS_G4X(dev) && !IS_GM45(dev)) {
1150 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1151 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1152 }
1153}
diff --git a/drivers/gpu/drm/i915/intel_dp.h b/drivers/gpu/drm/i915/intel_dp.h
new file mode 100644
index 000000000000..2b38054d3b6d
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_dp.h
@@ -0,0 +1,144 @@
1/*
2 * Copyright © 2008 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#ifndef _INTEL_DP_H_
24#define _INTEL_DP_H_
25
26/* From the VESA DisplayPort spec */
27
28#define AUX_NATIVE_WRITE 0x8
29#define AUX_NATIVE_READ 0x9
30#define AUX_I2C_WRITE 0x0
31#define AUX_I2C_READ 0x1
32#define AUX_I2C_STATUS 0x2
33#define AUX_I2C_MOT 0x4
34
35#define AUX_NATIVE_REPLY_ACK (0x0 << 4)
36#define AUX_NATIVE_REPLY_NACK (0x1 << 4)
37#define AUX_NATIVE_REPLY_DEFER (0x2 << 4)
38#define AUX_NATIVE_REPLY_MASK (0x3 << 4)
39
40#define AUX_I2C_REPLY_ACK (0x0 << 6)
41#define AUX_I2C_REPLY_NACK (0x1 << 6)
42#define AUX_I2C_REPLY_DEFER (0x2 << 6)
43#define AUX_I2C_REPLY_MASK (0x3 << 6)
44
45/* AUX CH addresses */
46#define DP_LINK_BW_SET 0x100
47# define DP_LINK_BW_1_62 0x06
48# define DP_LINK_BW_2_7 0x0a
49
50#define DP_LANE_COUNT_SET 0x101
51# define DP_LANE_COUNT_MASK 0x0f
52# define DP_LANE_COUNT_ENHANCED_FRAME_EN (1 << 7)
53
54#define DP_TRAINING_PATTERN_SET 0x102
55
56# define DP_TRAINING_PATTERN_DISABLE 0
57# define DP_TRAINING_PATTERN_1 1
58# define DP_TRAINING_PATTERN_2 2
59# define DP_TRAINING_PATTERN_MASK 0x3
60
61# define DP_LINK_QUAL_PATTERN_DISABLE (0 << 2)
62# define DP_LINK_QUAL_PATTERN_D10_2 (1 << 2)
63# define DP_LINK_QUAL_PATTERN_ERROR_RATE (2 << 2)
64# define DP_LINK_QUAL_PATTERN_PRBS7 (3 << 2)
65# define DP_LINK_QUAL_PATTERN_MASK (3 << 2)
66
67# define DP_RECOVERED_CLOCK_OUT_EN (1 << 4)
68# define DP_LINK_SCRAMBLING_DISABLE (1 << 5)
69
70# define DP_SYMBOL_ERROR_COUNT_BOTH (0 << 6)
71# define DP_SYMBOL_ERROR_COUNT_DISPARITY (1 << 6)
72# define DP_SYMBOL_ERROR_COUNT_SYMBOL (2 << 6)
73# define DP_SYMBOL_ERROR_COUNT_MASK (3 << 6)
74
75#define DP_TRAINING_LANE0_SET 0x103
76#define DP_TRAINING_LANE1_SET 0x104
77#define DP_TRAINING_LANE2_SET 0x105
78#define DP_TRAINING_LANE3_SET 0x106
79
80# define DP_TRAIN_VOLTAGE_SWING_MASK 0x3
81# define DP_TRAIN_VOLTAGE_SWING_SHIFT 0
82# define DP_TRAIN_MAX_SWING_REACHED (1 << 2)
83# define DP_TRAIN_VOLTAGE_SWING_400 (0 << 0)
84# define DP_TRAIN_VOLTAGE_SWING_600 (1 << 0)
85# define DP_TRAIN_VOLTAGE_SWING_800 (2 << 0)
86# define DP_TRAIN_VOLTAGE_SWING_1200 (3 << 0)
87
88# define DP_TRAIN_PRE_EMPHASIS_MASK (3 << 3)
89# define DP_TRAIN_PRE_EMPHASIS_0 (0 << 3)
90# define DP_TRAIN_PRE_EMPHASIS_3_5 (1 << 3)
91# define DP_TRAIN_PRE_EMPHASIS_6 (2 << 3)
92# define DP_TRAIN_PRE_EMPHASIS_9_5 (3 << 3)
93
94# define DP_TRAIN_PRE_EMPHASIS_SHIFT 3
95# define DP_TRAIN_MAX_PRE_EMPHASIS_REACHED (1 << 5)
96
97#define DP_DOWNSPREAD_CTRL 0x107
98# define DP_SPREAD_AMP_0_5 (1 << 4)
99
100#define DP_MAIN_LINK_CHANNEL_CODING_SET 0x108
101# define DP_SET_ANSI_8B10B (1 << 0)
102
103#define DP_LANE0_1_STATUS 0x202
104#define DP_LANE2_3_STATUS 0x203
105
106# define DP_LANE_CR_DONE (1 << 0)
107# define DP_LANE_CHANNEL_EQ_DONE (1 << 1)
108# define DP_LANE_SYMBOL_LOCKED (1 << 2)
109
110#define DP_LANE_ALIGN_STATUS_UPDATED 0x204
111
112#define DP_INTERLANE_ALIGN_DONE (1 << 0)
113#define DP_DOWNSTREAM_PORT_STATUS_CHANGED (1 << 6)
114#define DP_LINK_STATUS_UPDATED (1 << 7)
115
116#define DP_SINK_STATUS 0x205
117
118#define DP_RECEIVE_PORT_0_STATUS (1 << 0)
119#define DP_RECEIVE_PORT_1_STATUS (1 << 1)
120
121#define DP_ADJUST_REQUEST_LANE0_1 0x206
122#define DP_ADJUST_REQUEST_LANE2_3 0x207
123
124#define DP_ADJUST_VOLTAGE_SWING_LANE0_MASK 0x03
125#define DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT 0
126#define DP_ADJUST_PRE_EMPHASIS_LANE0_MASK 0x0c
127#define DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT 2
128#define DP_ADJUST_VOLTAGE_SWING_LANE1_MASK 0x30
129#define DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT 4
130#define DP_ADJUST_PRE_EMPHASIS_LANE1_MASK 0xc0
131#define DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT 6
132
133struct i2c_algo_dp_aux_data {
134 bool running;
135 u16 address;
136 int (*aux_ch) (struct i2c_adapter *adapter,
137 uint8_t *send, int send_bytes,
138 uint8_t *recv, int recv_bytes);
139};
140
141int
142i2c_dp_aux_add_bus(struct i2c_adapter *adapter);
143
144#endif /* _INTEL_DP_H_ */
diff --git a/drivers/gpu/drm/i915/intel_dp_i2c.c b/drivers/gpu/drm/i915/intel_dp_i2c.c
new file mode 100644
index 000000000000..4e60f14b1a6d
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_dp_i2c.c
@@ -0,0 +1,272 @@
1/*
2 * Copyright © 2009 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/delay.h>
26#include <linux/slab.h>
27#include <linux/init.h>
28#include <linux/errno.h>
29#include <linux/sched.h>
30#include <linux/i2c.h>
31#include "intel_dp.h"
32
33/* Run a single AUX_CH I2C transaction, writing/reading data as necessary */
34
35#define MODE_I2C_START 1
36#define MODE_I2C_WRITE 2
37#define MODE_I2C_READ 4
38#define MODE_I2C_STOP 8
39
40static int
41i2c_algo_dp_aux_transaction(struct i2c_adapter *adapter, int mode,
42 uint8_t write_byte, uint8_t *read_byte)
43{
44 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
45 uint16_t address = algo_data->address;
46 uint8_t msg[5];
47 uint8_t reply[2];
48 int msg_bytes;
49 int reply_bytes;
50 int ret;
51
52 /* Set up the command byte */
53 if (mode & MODE_I2C_READ)
54 msg[0] = AUX_I2C_READ << 4;
55 else
56 msg[0] = AUX_I2C_WRITE << 4;
57
58 if (!(mode & MODE_I2C_STOP))
59 msg[0] |= AUX_I2C_MOT << 4;
60
61 msg[1] = address >> 8;
62 msg[2] = address;
63
64 switch (mode) {
65 case MODE_I2C_WRITE:
66 msg[3] = 0;
67 msg[4] = write_byte;
68 msg_bytes = 5;
69 reply_bytes = 1;
70 break;
71 case MODE_I2C_READ:
72 msg[3] = 0;
73 msg_bytes = 4;
74 reply_bytes = 2;
75 break;
76 default:
77 msg_bytes = 3;
78 reply_bytes = 1;
79 break;
80 }
81
82 for (;;) {
83 ret = (*algo_data->aux_ch)(adapter,
84 msg, msg_bytes,
85 reply, reply_bytes);
86 if (ret < 0) {
87 printk(KERN_ERR "aux_ch failed %d\n", ret);
88 return ret;
89 }
90 switch (reply[0] & AUX_I2C_REPLY_MASK) {
91 case AUX_I2C_REPLY_ACK:
92 if (mode == MODE_I2C_READ) {
93 *read_byte = reply[1];
94 }
95 return reply_bytes - 1;
96 case AUX_I2C_REPLY_NACK:
97 printk(KERN_ERR "aux_ch nack\n");
98 return -EREMOTEIO;
99 case AUX_I2C_REPLY_DEFER:
100 printk(KERN_ERR "aux_ch defer\n");
101 udelay(100);
102 break;
103 default:
104 printk(KERN_ERR "aux_ch invalid reply 0x%02x\n", reply[0]);
105 return -EREMOTEIO;
106 }
107 }
108}
109
110/*
111 * I2C over AUX CH
112 */
113
114/*
115 * Send the address. If the I2C link is running, this 'restarts'
116 * the connection with the new address, this is used for doing
117 * a write followed by a read (as needed for DDC)
118 */
119static int
120i2c_algo_dp_aux_address(struct i2c_adapter *adapter, u16 address, bool reading)
121{
122 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
123 int mode = MODE_I2C_START;
124 int ret;
125
126 if (reading)
127 mode |= MODE_I2C_READ;
128 else
129 mode |= MODE_I2C_WRITE;
130 algo_data->address = address;
131 algo_data->running = true;
132 ret = i2c_algo_dp_aux_transaction(adapter, mode, 0, NULL);
133 return ret;
134}
135
136/*
137 * Stop the I2C transaction. This closes out the link, sending
138 * a bare address packet with the MOT bit turned off
139 */
140static void
141i2c_algo_dp_aux_stop(struct i2c_adapter *adapter, bool reading)
142{
143 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
144 int mode = MODE_I2C_STOP;
145
146 if (reading)
147 mode |= MODE_I2C_READ;
148 else
149 mode |= MODE_I2C_WRITE;
150 if (algo_data->running) {
151 (void) i2c_algo_dp_aux_transaction(adapter, mode, 0, NULL);
152 algo_data->running = false;
153 }
154}
155
156/*
157 * Write a single byte to the current I2C address, the
158 * the I2C link must be running or this returns -EIO
159 */
160static int
161i2c_algo_dp_aux_put_byte(struct i2c_adapter *adapter, u8 byte)
162{
163 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
164 int ret;
165
166 if (!algo_data->running)
167 return -EIO;
168
169 ret = i2c_algo_dp_aux_transaction(adapter, MODE_I2C_WRITE, byte, NULL);
170 return ret;
171}
172
173/*
174 * Read a single byte from the current I2C address, the
175 * I2C link must be running or this returns -EIO
176 */
177static int
178i2c_algo_dp_aux_get_byte(struct i2c_adapter *adapter, u8 *byte_ret)
179{
180 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
181 int ret;
182
183 if (!algo_data->running)
184 return -EIO;
185
186 ret = i2c_algo_dp_aux_transaction(adapter, MODE_I2C_READ, 0, byte_ret);
187 return ret;
188}
189
190static int
191i2c_algo_dp_aux_xfer(struct i2c_adapter *adapter,
192 struct i2c_msg *msgs,
193 int num)
194{
195 int ret = 0;
196 bool reading = false;
197 int m;
198 int b;
199
200 for (m = 0; m < num; m++) {
201 u16 len = msgs[m].len;
202 u8 *buf = msgs[m].buf;
203 reading = (msgs[m].flags & I2C_M_RD) != 0;
204 ret = i2c_algo_dp_aux_address(adapter, msgs[m].addr, reading);
205 if (ret < 0)
206 break;
207 if (reading) {
208 for (b = 0; b < len; b++) {
209 ret = i2c_algo_dp_aux_get_byte(adapter, &buf[b]);
210 if (ret < 0)
211 break;
212 }
213 } else {
214 for (b = 0; b < len; b++) {
215 ret = i2c_algo_dp_aux_put_byte(adapter, buf[b]);
216 if (ret < 0)
217 break;
218 }
219 }
220 if (ret < 0)
221 break;
222 }
223 if (ret >= 0)
224 ret = num;
225 i2c_algo_dp_aux_stop(adapter, reading);
226 printk(KERN_ERR "dp_aux_xfer return %d\n", ret);
227 return ret;
228}
229
230static u32
231i2c_algo_dp_aux_functionality(struct i2c_adapter *adapter)
232{
233 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
234 I2C_FUNC_SMBUS_READ_BLOCK_DATA |
235 I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
236 I2C_FUNC_10BIT_ADDR;
237}
238
239static const struct i2c_algorithm i2c_dp_aux_algo = {
240 .master_xfer = i2c_algo_dp_aux_xfer,
241 .functionality = i2c_algo_dp_aux_functionality,
242};
243
244static void
245i2c_dp_aux_reset_bus(struct i2c_adapter *adapter)
246{
247 (void) i2c_algo_dp_aux_address(adapter, 0, false);
248 (void) i2c_algo_dp_aux_stop(adapter, false);
249
250}
251
252static int
253i2c_dp_aux_prepare_bus(struct i2c_adapter *adapter)
254{
255 adapter->algo = &i2c_dp_aux_algo;
256 adapter->retries = 3;
257 i2c_dp_aux_reset_bus(adapter);
258 return 0;
259}
260
261int
262i2c_dp_aux_add_bus(struct i2c_adapter *adapter)
263{
264 int error;
265
266 error = i2c_dp_aux_prepare_bus(adapter);
267 if (error)
268 return error;
269 error = i2c_add_adapter(adapter);
270 return error;
271}
272EXPORT_SYMBOL(i2c_dp_aux_add_bus);
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index cd4b9c5f715e..004541c935a8 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -54,6 +54,7 @@
54#define INTEL_OUTPUT_LVDS 4 54#define INTEL_OUTPUT_LVDS 4
55#define INTEL_OUTPUT_TVOUT 5 55#define INTEL_OUTPUT_TVOUT 5
56#define INTEL_OUTPUT_HDMI 6 56#define INTEL_OUTPUT_HDMI 6
57#define INTEL_OUTPUT_DISPLAYPORT 7
57 58
58#define INTEL_DVO_CHIP_NONE 0 59#define INTEL_DVO_CHIP_NONE 0
59#define INTEL_DVO_CHIP_LVDS 1 60#define INTEL_DVO_CHIP_LVDS 1
@@ -65,7 +66,6 @@ struct intel_i2c_chan {
65 u32 reg; /* GPIO reg */ 66 u32 reg; /* GPIO reg */
66 struct i2c_adapter adapter; 67 struct i2c_adapter adapter;
67 struct i2c_algo_bit_data algo; 68 struct i2c_algo_bit_data algo;
68 u8 slave_addr;
69}; 69};
70 70
71struct intel_framebuffer { 71struct intel_framebuffer {
@@ -79,11 +79,12 @@ struct intel_output {
79 79
80 struct drm_encoder enc; 80 struct drm_encoder enc;
81 int type; 81 int type;
82 struct intel_i2c_chan *i2c_bus; /* for control functions */ 82 struct i2c_adapter *i2c_bus;
83 struct intel_i2c_chan *ddc_bus; /* for DDC only stuff */ 83 struct i2c_adapter *ddc_bus;
84 bool load_detect_temp; 84 bool load_detect_temp;
85 bool needs_tv_clock; 85 bool needs_tv_clock;
86 void *dev_priv; 86 void *dev_priv;
87 void (*hot_plug)(struct intel_output *);
87}; 88};
88 89
89struct intel_crtc { 90struct intel_crtc {
@@ -104,9 +105,9 @@ struct intel_crtc {
104#define enc_to_intel_output(x) container_of(x, struct intel_output, enc) 105#define enc_to_intel_output(x) container_of(x, struct intel_output, enc)
105#define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base) 106#define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
106 107
107struct intel_i2c_chan *intel_i2c_create(struct drm_device *dev, const u32 reg, 108struct i2c_adapter *intel_i2c_create(struct drm_device *dev, const u32 reg,
108 const char *name); 109 const char *name);
109void intel_i2c_destroy(struct intel_i2c_chan *chan); 110void intel_i2c_destroy(struct i2c_adapter *adapter);
110int intel_ddc_get_modes(struct intel_output *intel_output); 111int intel_ddc_get_modes(struct intel_output *intel_output);
111extern bool intel_ddc_probe(struct intel_output *intel_output); 112extern bool intel_ddc_probe(struct intel_output *intel_output);
112void intel_i2c_quirk_set(struct drm_device *dev, bool enable); 113void intel_i2c_quirk_set(struct drm_device *dev, bool enable);
@@ -116,6 +117,10 @@ extern bool intel_sdvo_init(struct drm_device *dev, int output_device);
116extern void intel_dvo_init(struct drm_device *dev); 117extern void intel_dvo_init(struct drm_device *dev);
117extern void intel_tv_init(struct drm_device *dev); 118extern void intel_tv_init(struct drm_device *dev);
118extern void intel_lvds_init(struct drm_device *dev); 119extern void intel_lvds_init(struct drm_device *dev);
120extern void intel_dp_init(struct drm_device *dev, int dp_reg);
121void
122intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
123 struct drm_display_mode *adjusted_mode);
119 124
120extern void intel_crtc_load_lut(struct drm_crtc *crtc); 125extern void intel_crtc_load_lut(struct drm_crtc *crtc);
121extern void intel_encoder_prepare (struct drm_encoder *encoder); 126extern void intel_encoder_prepare (struct drm_encoder *encoder);
diff --git a/drivers/gpu/drm/i915/intel_dvo.c b/drivers/gpu/drm/i915/intel_dvo.c
index 1ee3007d6ec0..13bff20930e8 100644
--- a/drivers/gpu/drm/i915/intel_dvo.c
+++ b/drivers/gpu/drm/i915/intel_dvo.c
@@ -384,10 +384,9 @@ void intel_dvo_init(struct drm_device *dev)
384{ 384{
385 struct intel_output *intel_output; 385 struct intel_output *intel_output;
386 struct intel_dvo_device *dvo; 386 struct intel_dvo_device *dvo;
387 struct intel_i2c_chan *i2cbus = NULL; 387 struct i2c_adapter *i2cbus = NULL;
388 int ret = 0; 388 int ret = 0;
389 int i; 389 int i;
390 int gpio_inited = 0;
391 int encoder_type = DRM_MODE_ENCODER_NONE; 390 int encoder_type = DRM_MODE_ENCODER_NONE;
392 intel_output = kzalloc (sizeof(struct intel_output), GFP_KERNEL); 391 intel_output = kzalloc (sizeof(struct intel_output), GFP_KERNEL);
393 if (!intel_output) 392 if (!intel_output)
@@ -420,14 +419,11 @@ void intel_dvo_init(struct drm_device *dev)
420 * It appears that everything is on GPIOE except for panels 419 * It appears that everything is on GPIOE except for panels
421 * on i830 laptops, which are on GPIOB (DVOA). 420 * on i830 laptops, which are on GPIOB (DVOA).
422 */ 421 */
423 if (gpio_inited != gpio) { 422 if (i2cbus != NULL)
424 if (i2cbus != NULL) 423 intel_i2c_destroy(i2cbus);
425 intel_i2c_destroy(i2cbus); 424 if (!(i2cbus = intel_i2c_create(dev, gpio,
426 if (!(i2cbus = intel_i2c_create(dev, gpio, 425 gpio == GPIOB ? "DVOI2C_B" : "DVOI2C_E"))) {
427 gpio == GPIOB ? "DVOI2C_B" : "DVOI2C_E"))) { 426 continue;
428 continue;
429 }
430 gpio_inited = gpio;
431 } 427 }
432 428
433 if (dvo->dev_ops!= NULL) 429 if (dvo->dev_ops!= NULL)
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 4ea2a651b92c..9e30daae37dc 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -31,6 +31,7 @@
31#include "drmP.h" 31#include "drmP.h"
32#include "drm.h" 32#include "drm.h"
33#include "drm_crtc.h" 33#include "drm_crtc.h"
34#include "drm_edid.h"
34#include "intel_drv.h" 35#include "intel_drv.h"
35#include "i915_drm.h" 36#include "i915_drm.h"
36#include "i915_drv.h" 37#include "i915_drv.h"
@@ -56,8 +57,7 @@ static void intel_hdmi_mode_set(struct drm_encoder *encoder,
56 sdvox = SDVO_ENCODING_HDMI | 57 sdvox = SDVO_ENCODING_HDMI |
57 SDVO_BORDER_ENABLE | 58 SDVO_BORDER_ENABLE |
58 SDVO_VSYNC_ACTIVE_HIGH | 59 SDVO_VSYNC_ACTIVE_HIGH |
59 SDVO_HSYNC_ACTIVE_HIGH | 60 SDVO_HSYNC_ACTIVE_HIGH;
60 SDVO_NULL_PACKETS_DURING_VSYNC;
61 61
62 if (hdmi_priv->has_hdmi_sink) 62 if (hdmi_priv->has_hdmi_sink)
63 sdvox |= SDVO_AUDIO_ENABLE; 63 sdvox |= SDVO_AUDIO_ENABLE;
@@ -129,20 +129,26 @@ static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
129 return true; 129 return true;
130} 130}
131 131
132static void 132static enum drm_connector_status
133intel_hdmi_sink_detect(struct drm_connector *connector) 133intel_hdmi_edid_detect(struct drm_connector *connector)
134{ 134{
135 struct intel_output *intel_output = to_intel_output(connector); 135 struct intel_output *intel_output = to_intel_output(connector);
136 struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; 136 struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv;
137 struct edid *edid = NULL; 137 struct edid *edid = NULL;
138 enum drm_connector_status status = connector_status_disconnected;
138 139
139 edid = drm_get_edid(&intel_output->base, 140 edid = drm_get_edid(&intel_output->base,
140 &intel_output->ddc_bus->adapter); 141 intel_output->ddc_bus);
141 if (edid != NULL) { 142 hdmi_priv->has_hdmi_sink = false;
142 hdmi_priv->has_hdmi_sink = drm_detect_hdmi_monitor(edid); 143 if (edid) {
143 kfree(edid); 144 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
145 status = connector_status_connected;
146 hdmi_priv->has_hdmi_sink = drm_detect_hdmi_monitor(edid);
147 }
144 intel_output->base.display_info.raw_edid = NULL; 148 intel_output->base.display_info.raw_edid = NULL;
149 kfree(edid);
145 } 150 }
151 return status;
146} 152}
147 153
148static enum drm_connector_status 154static enum drm_connector_status
@@ -154,11 +160,7 @@ igdng_hdmi_detect(struct drm_connector *connector)
154 /* FIXME hotplug detect */ 160 /* FIXME hotplug detect */
155 161
156 hdmi_priv->has_hdmi_sink = false; 162 hdmi_priv->has_hdmi_sink = false;
157 intel_hdmi_sink_detect(connector); 163 return intel_hdmi_edid_detect(connector);
158 if (hdmi_priv->has_hdmi_sink)
159 return connector_status_connected;
160 else
161 return connector_status_disconnected;
162} 164}
163 165
164static enum drm_connector_status 166static enum drm_connector_status
@@ -201,10 +203,9 @@ intel_hdmi_detect(struct drm_connector *connector)
201 return connector_status_unknown; 203 return connector_status_unknown;
202 } 204 }
203 205
204 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) != 0) { 206 if ((I915_READ(PORT_HOTPLUG_STAT) & bit) != 0)
205 intel_hdmi_sink_detect(connector); 207 return intel_hdmi_edid_detect(connector);
206 return connector_status_connected; 208 else
207 } else
208 return connector_status_disconnected; 209 return connector_status_disconnected;
209} 210}
210 211
diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
index f7061f68d050..62b8bead7652 100644
--- a/drivers/gpu/drm/i915/intel_i2c.c
+++ b/drivers/gpu/drm/i915/intel_i2c.c
@@ -124,6 +124,7 @@ static void set_data(void *data, int state_high)
124 * @output: driver specific output device 124 * @output: driver specific output device
125 * @reg: GPIO reg to use 125 * @reg: GPIO reg to use
126 * @name: name for this bus 126 * @name: name for this bus
127 * @slave_addr: slave address (if fixed)
127 * 128 *
128 * Creates and registers a new i2c bus with the Linux i2c layer, for use 129 * Creates and registers a new i2c bus with the Linux i2c layer, for use
129 * in output probing and control (e.g. DDC or SDVO control functions). 130 * in output probing and control (e.g. DDC or SDVO control functions).
@@ -139,8 +140,8 @@ static void set_data(void *data, int state_high)
139 * %GPIOH 140 * %GPIOH
140 * see PRM for details on how these different busses are used. 141 * see PRM for details on how these different busses are used.
141 */ 142 */
142struct intel_i2c_chan *intel_i2c_create(struct drm_device *dev, const u32 reg, 143struct i2c_adapter *intel_i2c_create(struct drm_device *dev, const u32 reg,
143 const char *name) 144 const char *name)
144{ 145{
145 struct intel_i2c_chan *chan; 146 struct intel_i2c_chan *chan;
146 147
@@ -174,7 +175,7 @@ struct intel_i2c_chan *intel_i2c_create(struct drm_device *dev, const u32 reg,
174 intel_i2c_quirk_set(dev, false); 175 intel_i2c_quirk_set(dev, false);
175 udelay(20); 176 udelay(20);
176 177
177 return chan; 178 return &chan->adapter;
178 179
179out_free: 180out_free:
180 kfree(chan); 181 kfree(chan);
@@ -187,11 +188,16 @@ out_free:
187 * 188 *
188 * Unregister the adapter from the i2c layer, then free the structure. 189 * Unregister the adapter from the i2c layer, then free the structure.
189 */ 190 */
190void intel_i2c_destroy(struct intel_i2c_chan *chan) 191void intel_i2c_destroy(struct i2c_adapter *adapter)
191{ 192{
192 if (!chan) 193 struct intel_i2c_chan *chan;
194
195 if (!adapter)
193 return; 196 return;
194 197
198 chan = container_of(adapter,
199 struct intel_i2c_chan,
200 adapter);
195 i2c_del_adapter(&chan->adapter); 201 i2c_del_adapter(&chan->adapter);
196 kfree(chan); 202 kfree(chan);
197} 203}
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index f073ed8432e8..9564ca44a977 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -39,6 +39,21 @@
39 39
40#define I915_LVDS "i915_lvds" 40#define I915_LVDS "i915_lvds"
41 41
42/*
43 * the following four scaling options are defined.
44 * #define DRM_MODE_SCALE_NON_GPU 0
45 * #define DRM_MODE_SCALE_FULLSCREEN 1
46 * #define DRM_MODE_SCALE_NO_SCALE 2
47 * #define DRM_MODE_SCALE_ASPECT 3
48 */
49
50/* Private structure for the integrated LVDS support */
51struct intel_lvds_priv {
52 int fitting_mode;
53 u32 pfit_control;
54 u32 pfit_pgm_ratios;
55};
56
42/** 57/**
43 * Sets the backlight level. 58 * Sets the backlight level.
44 * 59 *
@@ -213,10 +228,27 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
213 struct drm_display_mode *mode, 228 struct drm_display_mode *mode,
214 struct drm_display_mode *adjusted_mode) 229 struct drm_display_mode *adjusted_mode)
215{ 230{
231 /*
232 * float point operation is not supported . So the PANEL_RATIO_FACTOR
233 * is defined, which can avoid the float point computation when
234 * calculating the panel ratio.
235 */
236#define PANEL_RATIO_FACTOR 8192
216 struct drm_device *dev = encoder->dev; 237 struct drm_device *dev = encoder->dev;
217 struct drm_i915_private *dev_priv = dev->dev_private; 238 struct drm_i915_private *dev_priv = dev->dev_private;
218 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); 239 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
219 struct drm_encoder *tmp_encoder; 240 struct drm_encoder *tmp_encoder;
241 struct intel_output *intel_output = enc_to_intel_output(encoder);
242 struct intel_lvds_priv *lvds_priv = intel_output->dev_priv;
243 u32 pfit_control = 0, pfit_pgm_ratios = 0;
244 int left_border = 0, right_border = 0, top_border = 0;
245 int bottom_border = 0;
246 bool border = 0;
247 int panel_ratio, desired_ratio, vert_scale, horiz_scale;
248 int horiz_ratio, vert_ratio;
249 u32 hsync_width, vsync_width;
250 u32 hblank_width, vblank_width;
251 u32 hsync_pos, vsync_pos;
220 252
221 /* Should never happen!! */ 253 /* Should never happen!! */
222 if (!IS_I965G(dev) && intel_crtc->pipe == 0) { 254 if (!IS_I965G(dev) && intel_crtc->pipe == 0) {
@@ -232,7 +264,9 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
232 return false; 264 return false;
233 } 265 }
234 } 266 }
235 267 /* If we don't have a panel mode, there is nothing we can do */
268 if (dev_priv->panel_fixed_mode == NULL)
269 return true;
236 /* 270 /*
237 * If we have timings from the BIOS for the panel, put them in 271 * If we have timings from the BIOS for the panel, put them in
238 * to the adjusted mode. The CRTC will be set up for this mode, 272 * to the adjusted mode. The CRTC will be set up for this mode,
@@ -256,6 +290,243 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
256 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V); 290 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
257 } 291 }
258 292
293 /* Make sure pre-965s set dither correctly */
294 if (!IS_I965G(dev)) {
295 if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
296 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
297 }
298
299 /* Native modes don't need fitting */
300 if (adjusted_mode->hdisplay == mode->hdisplay &&
301 adjusted_mode->vdisplay == mode->vdisplay) {
302 pfit_pgm_ratios = 0;
303 border = 0;
304 goto out;
305 }
306
307 /* 965+ wants fuzzy fitting */
308 if (IS_I965G(dev))
309 pfit_control |= (intel_crtc->pipe << PFIT_PIPE_SHIFT) |
310 PFIT_FILTER_FUZZY;
311
312 hsync_width = adjusted_mode->crtc_hsync_end -
313 adjusted_mode->crtc_hsync_start;
314 vsync_width = adjusted_mode->crtc_vsync_end -
315 adjusted_mode->crtc_vsync_start;
316 hblank_width = adjusted_mode->crtc_hblank_end -
317 adjusted_mode->crtc_hblank_start;
318 vblank_width = adjusted_mode->crtc_vblank_end -
319 adjusted_mode->crtc_vblank_start;
320 /*
321 * Deal with panel fitting options. Figure out how to stretch the
322 * image based on its aspect ratio & the current panel fitting mode.
323 */
324 panel_ratio = adjusted_mode->hdisplay * PANEL_RATIO_FACTOR /
325 adjusted_mode->vdisplay;
326 desired_ratio = mode->hdisplay * PANEL_RATIO_FACTOR /
327 mode->vdisplay;
328 /*
329 * Enable automatic panel scaling for non-native modes so that they fill
330 * the screen. Should be enabled before the pipe is enabled, according
331 * to register description and PRM.
332 * Change the value here to see the borders for debugging
333 */
334 I915_WRITE(BCLRPAT_A, 0);
335 I915_WRITE(BCLRPAT_B, 0);
336
337 switch (lvds_priv->fitting_mode) {
338 case DRM_MODE_SCALE_NO_SCALE:
339 /*
340 * For centered modes, we have to calculate border widths &
341 * heights and modify the values programmed into the CRTC.
342 */
343 left_border = (adjusted_mode->hdisplay - mode->hdisplay) / 2;
344 right_border = left_border;
345 if (mode->hdisplay & 1)
346 right_border++;
347 top_border = (adjusted_mode->vdisplay - mode->vdisplay) / 2;
348 bottom_border = top_border;
349 if (mode->vdisplay & 1)
350 bottom_border++;
351 /* Set active & border values */
352 adjusted_mode->crtc_hdisplay = mode->hdisplay;
353 /* Keep the boder be even */
354 if (right_border & 1)
355 right_border++;
356 /* use the border directly instead of border minuse one */
357 adjusted_mode->crtc_hblank_start = mode->hdisplay +
358 right_border;
359 /* keep the blank width constant */
360 adjusted_mode->crtc_hblank_end =
361 adjusted_mode->crtc_hblank_start + hblank_width;
362 /* get the hsync pos relative to hblank start */
363 hsync_pos = (hblank_width - hsync_width) / 2;
364 /* keep the hsync pos be even */
365 if (hsync_pos & 1)
366 hsync_pos++;
367 adjusted_mode->crtc_hsync_start =
368 adjusted_mode->crtc_hblank_start + hsync_pos;
369 /* keep the hsync width constant */
370 adjusted_mode->crtc_hsync_end =
371 adjusted_mode->crtc_hsync_start + hsync_width;
372 adjusted_mode->crtc_vdisplay = mode->vdisplay;
373 /* use the border instead of border minus one */
374 adjusted_mode->crtc_vblank_start = mode->vdisplay +
375 bottom_border;
376 /* keep the vblank width constant */
377 adjusted_mode->crtc_vblank_end =
378 adjusted_mode->crtc_vblank_start + vblank_width;
379 /* get the vsync start postion relative to vblank start */
380 vsync_pos = (vblank_width - vsync_width) / 2;
381 adjusted_mode->crtc_vsync_start =
382 adjusted_mode->crtc_vblank_start + vsync_pos;
383 /* keep the vsync width constant */
384 adjusted_mode->crtc_vsync_end =
385 adjusted_mode->crtc_vblank_start + vsync_width;
386 border = 1;
387 break;
388 case DRM_MODE_SCALE_ASPECT:
389 /* Scale but preserve the spect ratio */
390 pfit_control |= PFIT_ENABLE;
391 if (IS_I965G(dev)) {
392 /* 965+ is easy, it does everything in hw */
393 if (panel_ratio > desired_ratio)
394 pfit_control |= PFIT_SCALING_PILLAR;
395 else if (panel_ratio < desired_ratio)
396 pfit_control |= PFIT_SCALING_LETTER;
397 else
398 pfit_control |= PFIT_SCALING_AUTO;
399 } else {
400 /*
401 * For earlier chips we have to calculate the scaling
402 * ratio by hand and program it into the
403 * PFIT_PGM_RATIO register
404 */
405 u32 horiz_bits, vert_bits, bits = 12;
406 horiz_ratio = mode->hdisplay * PANEL_RATIO_FACTOR/
407 adjusted_mode->hdisplay;
408 vert_ratio = mode->vdisplay * PANEL_RATIO_FACTOR/
409 adjusted_mode->vdisplay;
410 horiz_scale = adjusted_mode->hdisplay *
411 PANEL_RATIO_FACTOR / mode->hdisplay;
412 vert_scale = adjusted_mode->vdisplay *
413 PANEL_RATIO_FACTOR / mode->vdisplay;
414
415 /* retain aspect ratio */
416 if (panel_ratio > desired_ratio) { /* Pillar */
417 u32 scaled_width;
418 scaled_width = mode->hdisplay * vert_scale /
419 PANEL_RATIO_FACTOR;
420 horiz_ratio = vert_ratio;
421 pfit_control |= (VERT_AUTO_SCALE |
422 VERT_INTERP_BILINEAR |
423 HORIZ_INTERP_BILINEAR);
424 /* Pillar will have left/right borders */
425 left_border = (adjusted_mode->hdisplay -
426 scaled_width) / 2;
427 right_border = left_border;
428 if (mode->hdisplay & 1) /* odd resolutions */
429 right_border++;
430 /* keep the border be even */
431 if (right_border & 1)
432 right_border++;
433 adjusted_mode->crtc_hdisplay = scaled_width;
434 /* use border instead of border minus one */
435 adjusted_mode->crtc_hblank_start =
436 scaled_width + right_border;
437 /* keep the hblank width constant */
438 adjusted_mode->crtc_hblank_end =
439 adjusted_mode->crtc_hblank_start +
440 hblank_width;
441 /*
442 * get the hsync start pos relative to
443 * hblank start
444 */
445 hsync_pos = (hblank_width - hsync_width) / 2;
446 /* keep the hsync_pos be even */
447 if (hsync_pos & 1)
448 hsync_pos++;
449 adjusted_mode->crtc_hsync_start =
450 adjusted_mode->crtc_hblank_start +
451 hsync_pos;
452 /* keept hsync width constant */
453 adjusted_mode->crtc_hsync_end =
454 adjusted_mode->crtc_hsync_start +
455 hsync_width;
456 border = 1;
457 } else if (panel_ratio < desired_ratio) { /* letter */
458 u32 scaled_height = mode->vdisplay *
459 horiz_scale / PANEL_RATIO_FACTOR;
460 vert_ratio = horiz_ratio;
461 pfit_control |= (HORIZ_AUTO_SCALE |
462 VERT_INTERP_BILINEAR |
463 HORIZ_INTERP_BILINEAR);
464 /* Letterbox will have top/bottom border */
465 top_border = (adjusted_mode->vdisplay -
466 scaled_height) / 2;
467 bottom_border = top_border;
468 if (mode->vdisplay & 1)
469 bottom_border++;
470 adjusted_mode->crtc_vdisplay = scaled_height;
471 /* use border instead of border minus one */
472 adjusted_mode->crtc_vblank_start =
473 scaled_height + bottom_border;
474 /* keep the vblank width constant */
475 adjusted_mode->crtc_vblank_end =
476 adjusted_mode->crtc_vblank_start +
477 vblank_width;
478 /*
479 * get the vsync start pos relative to
480 * vblank start
481 */
482 vsync_pos = (vblank_width - vsync_width) / 2;
483 adjusted_mode->crtc_vsync_start =
484 adjusted_mode->crtc_vblank_start +
485 vsync_pos;
486 /* keep the vsync width constant */
487 adjusted_mode->crtc_vsync_end =
488 adjusted_mode->crtc_vsync_start +
489 vsync_width;
490 border = 1;
491 } else {
492 /* Aspects match, Let hw scale both directions */
493 pfit_control |= (VERT_AUTO_SCALE |
494 HORIZ_AUTO_SCALE |
495 VERT_INTERP_BILINEAR |
496 HORIZ_INTERP_BILINEAR);
497 }
498 horiz_bits = (1 << bits) * horiz_ratio /
499 PANEL_RATIO_FACTOR;
500 vert_bits = (1 << bits) * vert_ratio /
501 PANEL_RATIO_FACTOR;
502 pfit_pgm_ratios =
503 ((vert_bits << PFIT_VERT_SCALE_SHIFT) &
504 PFIT_VERT_SCALE_MASK) |
505 ((horiz_bits << PFIT_HORIZ_SCALE_SHIFT) &
506 PFIT_HORIZ_SCALE_MASK);
507 }
508 break;
509
510 case DRM_MODE_SCALE_FULLSCREEN:
511 /*
512 * Full scaling, even if it changes the aspect ratio.
513 * Fortunately this is all done for us in hw.
514 */
515 pfit_control |= PFIT_ENABLE;
516 if (IS_I965G(dev))
517 pfit_control |= PFIT_SCALING_AUTO;
518 else
519 pfit_control |= (VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
520 VERT_INTERP_BILINEAR |
521 HORIZ_INTERP_BILINEAR);
522 break;
523 default:
524 break;
525 }
526
527out:
528 lvds_priv->pfit_control = pfit_control;
529 lvds_priv->pfit_pgm_ratios = pfit_pgm_ratios;
259 /* 530 /*
260 * XXX: It would be nice to support lower refresh rates on the 531 * XXX: It would be nice to support lower refresh rates on the
261 * panels to reduce power consumption, and perhaps match the 532 * panels to reduce power consumption, and perhaps match the
@@ -301,8 +572,8 @@ static void intel_lvds_mode_set(struct drm_encoder *encoder,
301{ 572{
302 struct drm_device *dev = encoder->dev; 573 struct drm_device *dev = encoder->dev;
303 struct drm_i915_private *dev_priv = dev->dev_private; 574 struct drm_i915_private *dev_priv = dev->dev_private;
304 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); 575 struct intel_output *intel_output = enc_to_intel_output(encoder);
305 u32 pfit_control; 576 struct intel_lvds_priv *lvds_priv = intel_output->dev_priv;
306 577
307 /* 578 /*
308 * The LVDS pin pair will already have been turned on in the 579 * The LVDS pin pair will already have been turned on in the
@@ -319,22 +590,8 @@ static void intel_lvds_mode_set(struct drm_encoder *encoder,
319 * screen. Should be enabled before the pipe is enabled, according to 590 * screen. Should be enabled before the pipe is enabled, according to
320 * register description and PRM. 591 * register description and PRM.
321 */ 592 */
322 if (mode->hdisplay != adjusted_mode->hdisplay || 593 I915_WRITE(PFIT_PGM_RATIOS, lvds_priv->pfit_pgm_ratios);
323 mode->vdisplay != adjusted_mode->vdisplay) 594 I915_WRITE(PFIT_CONTROL, lvds_priv->pfit_control);
324 pfit_control = (PFIT_ENABLE | VERT_AUTO_SCALE |
325 HORIZ_AUTO_SCALE | VERT_INTERP_BILINEAR |
326 HORIZ_INTERP_BILINEAR);
327 else
328 pfit_control = 0;
329
330 if (!IS_I965G(dev)) {
331 if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
332 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
333 }
334 else
335 pfit_control |= intel_crtc->pipe << PFIT_PIPE_SHIFT;
336
337 I915_WRITE(PFIT_CONTROL, pfit_control);
338} 595}
339 596
340/** 597/**
@@ -406,6 +663,34 @@ static int intel_lvds_set_property(struct drm_connector *connector,
406 struct drm_property *property, 663 struct drm_property *property,
407 uint64_t value) 664 uint64_t value)
408{ 665{
666 struct drm_device *dev = connector->dev;
667 struct intel_output *intel_output =
668 to_intel_output(connector);
669
670 if (property == dev->mode_config.scaling_mode_property &&
671 connector->encoder) {
672 struct drm_crtc *crtc = connector->encoder->crtc;
673 struct intel_lvds_priv *lvds_priv = intel_output->dev_priv;
674 if (value == DRM_MODE_SCALE_NON_GPU) {
675 DRM_DEBUG_KMS(I915_LVDS,
676 "non_GPU property is unsupported\n");
677 return 0;
678 }
679 if (lvds_priv->fitting_mode == value) {
680 /* the LVDS scaling property is not changed */
681 return 0;
682 }
683 lvds_priv->fitting_mode = value;
684 if (crtc && crtc->enabled) {
685 /*
686 * If the CRTC is enabled, the display will be changed
687 * according to the new panel fitting mode.
688 */
689 drm_crtc_helper_set_mode(crtc, &crtc->mode,
690 crtc->x, crtc->y, crtc->fb);
691 }
692 }
693
409 return 0; 694 return 0;
410} 695}
411 696
@@ -456,7 +741,7 @@ static const struct dmi_system_id intel_no_lvds[] = {
456 .callback = intel_no_lvds_dmi_callback, 741 .callback = intel_no_lvds_dmi_callback,
457 .ident = "Apple Mac Mini (Core series)", 742 .ident = "Apple Mac Mini (Core series)",
458 .matches = { 743 .matches = {
459 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 744 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
460 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"), 745 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
461 }, 746 },
462 }, 747 },
@@ -464,7 +749,7 @@ static const struct dmi_system_id intel_no_lvds[] = {
464 .callback = intel_no_lvds_dmi_callback, 749 .callback = intel_no_lvds_dmi_callback,
465 .ident = "Apple Mac Mini (Core 2 series)", 750 .ident = "Apple Mac Mini (Core 2 series)",
466 .matches = { 751 .matches = {
467 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 752 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
468 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"), 753 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
469 }, 754 },
470 }, 755 },
@@ -518,6 +803,7 @@ void intel_lvds_init(struct drm_device *dev)
518 struct drm_encoder *encoder; 803 struct drm_encoder *encoder;
519 struct drm_display_mode *scan; /* *modes, *bios_mode; */ 804 struct drm_display_mode *scan; /* *modes, *bios_mode; */
520 struct drm_crtc *crtc; 805 struct drm_crtc *crtc;
806 struct intel_lvds_priv *lvds_priv;
521 u32 lvds; 807 u32 lvds;
522 int pipe, gpio = GPIOC; 808 int pipe, gpio = GPIOC;
523 809
@@ -531,7 +817,8 @@ void intel_lvds_init(struct drm_device *dev)
531 gpio = PCH_GPIOC; 817 gpio = PCH_GPIOC;
532 } 818 }
533 819
534 intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL); 820 intel_output = kzalloc(sizeof(struct intel_output) +
821 sizeof(struct intel_lvds_priv), GFP_KERNEL);
535 if (!intel_output) { 822 if (!intel_output) {
536 return; 823 return;
537 } 824 }
@@ -553,7 +840,18 @@ void intel_lvds_init(struct drm_device *dev)
553 connector->interlace_allowed = false; 840 connector->interlace_allowed = false;
554 connector->doublescan_allowed = false; 841 connector->doublescan_allowed = false;
555 842
843 lvds_priv = (struct intel_lvds_priv *)(intel_output + 1);
844 intel_output->dev_priv = lvds_priv;
845 /* create the scaling mode property */
846 drm_mode_create_scaling_mode_property(dev);
847 /*
848 * the initial panel fitting mode will be FULL_SCREEN.
849 */
556 850
851 drm_connector_attach_property(&intel_output->base,
852 dev->mode_config.scaling_mode_property,
853 DRM_MODE_SCALE_FULLSCREEN);
854 lvds_priv->fitting_mode = DRM_MODE_SCALE_FULLSCREEN;
557 /* 855 /*
558 * LVDS discovery: 856 * LVDS discovery:
559 * 1) check for EDID on DDC 857 * 1) check for EDID on DDC
@@ -649,5 +947,5 @@ failed:
649 if (intel_output->ddc_bus) 947 if (intel_output->ddc_bus)
650 intel_i2c_destroy(intel_output->ddc_bus); 948 intel_i2c_destroy(intel_output->ddc_bus);
651 drm_connector_cleanup(connector); 949 drm_connector_cleanup(connector);
652 kfree(connector); 950 kfree(intel_output);
653} 951}
diff --git a/drivers/gpu/drm/i915/intel_modes.c b/drivers/gpu/drm/i915/intel_modes.c
index e0910fefce87..67e2f4632a24 100644
--- a/drivers/gpu/drm/i915/intel_modes.c
+++ b/drivers/gpu/drm/i915/intel_modes.c
@@ -53,10 +53,9 @@ bool intel_ddc_probe(struct intel_output *intel_output)
53 } 53 }
54 }; 54 };
55 55
56 intel_i2c_quirk_set(intel_output->ddc_bus->drm_dev, true); 56 intel_i2c_quirk_set(intel_output->base.dev, true);
57 ret = i2c_transfer(&intel_output->ddc_bus->adapter, msgs, 2); 57 ret = i2c_transfer(intel_output->ddc_bus, msgs, 2);
58 intel_i2c_quirk_set(intel_output->ddc_bus->drm_dev, false); 58 intel_i2c_quirk_set(intel_output->base.dev, false);
59
60 if (ret == 2) 59 if (ret == 2)
61 return true; 60 return true;
62 61
@@ -74,10 +73,9 @@ int intel_ddc_get_modes(struct intel_output *intel_output)
74 struct edid *edid; 73 struct edid *edid;
75 int ret = 0; 74 int ret = 0;
76 75
77 intel_i2c_quirk_set(intel_output->ddc_bus->drm_dev, true); 76 intel_i2c_quirk_set(intel_output->base.dev, true);
78 edid = drm_get_edid(&intel_output->base, 77 edid = drm_get_edid(&intel_output->base, intel_output->ddc_bus);
79 &intel_output->ddc_bus->adapter); 78 intel_i2c_quirk_set(intel_output->base.dev, false);
80 intel_i2c_quirk_set(intel_output->ddc_bus->drm_dev, false);
81 if (edid) { 79 if (edid) {
82 drm_mode_connector_update_edid_property(&intel_output->base, 80 drm_mode_connector_update_edid_property(&intel_output->base,
83 edid); 81 edid);
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index 9a00adb3a508..f03473779feb 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -38,8 +38,7 @@
38#undef SDVO_DEBUG 38#undef SDVO_DEBUG
39#define I915_SDVO "i915_sdvo" 39#define I915_SDVO "i915_sdvo"
40struct intel_sdvo_priv { 40struct intel_sdvo_priv {
41 struct intel_i2c_chan *i2c_bus; 41 u8 slave_addr;
42 int slaveaddr;
43 42
44 /* Register for the SDVO device: SDVOB or SDVOC */ 43 /* Register for the SDVO device: SDVOB or SDVOC */
45 int output_device; 44 int output_device;
@@ -146,13 +145,13 @@ static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr,
146 145
147 struct i2c_msg msgs[] = { 146 struct i2c_msg msgs[] = {
148 { 147 {
149 .addr = sdvo_priv->i2c_bus->slave_addr, 148 .addr = sdvo_priv->slave_addr >> 1,
150 .flags = 0, 149 .flags = 0,
151 .len = 1, 150 .len = 1,
152 .buf = out_buf, 151 .buf = out_buf,
153 }, 152 },
154 { 153 {
155 .addr = sdvo_priv->i2c_bus->slave_addr, 154 .addr = sdvo_priv->slave_addr >> 1,
156 .flags = I2C_M_RD, 155 .flags = I2C_M_RD,
157 .len = 1, 156 .len = 1,
158 .buf = buf, 157 .buf = buf,
@@ -162,7 +161,7 @@ static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr,
162 out_buf[0] = addr; 161 out_buf[0] = addr;
163 out_buf[1] = 0; 162 out_buf[1] = 0;
164 163
165 if ((ret = i2c_transfer(&sdvo_priv->i2c_bus->adapter, msgs, 2)) == 2) 164 if ((ret = i2c_transfer(intel_output->i2c_bus, msgs, 2)) == 2)
166 { 165 {
167 *ch = buf[0]; 166 *ch = buf[0];
168 return true; 167 return true;
@@ -175,10 +174,11 @@ static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr,
175static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr, 174static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr,
176 u8 ch) 175 u8 ch)
177{ 176{
177 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
178 u8 out_buf[2]; 178 u8 out_buf[2];
179 struct i2c_msg msgs[] = { 179 struct i2c_msg msgs[] = {
180 { 180 {
181 .addr = intel_output->i2c_bus->slave_addr, 181 .addr = sdvo_priv->slave_addr >> 1,
182 .flags = 0, 182 .flags = 0,
183 .len = 2, 183 .len = 2,
184 .buf = out_buf, 184 .buf = out_buf,
@@ -188,7 +188,7 @@ static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr,
188 out_buf[0] = addr; 188 out_buf[0] = addr;
189 out_buf[1] = ch; 189 out_buf[1] = ch;
190 190
191 if (i2c_transfer(&intel_output->i2c_bus->adapter, msgs, 1) == 1) 191 if (i2c_transfer(intel_output->i2c_bus, msgs, 1) == 1)
192 { 192 {
193 return true; 193 return true;
194 } 194 }
@@ -1369,9 +1369,8 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector)
1369 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; 1369 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1370 struct edid *edid = NULL; 1370 struct edid *edid = NULL;
1371 1371
1372 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
1373 edid = drm_get_edid(&intel_output->base, 1372 edid = drm_get_edid(&intel_output->base,
1374 &intel_output->ddc_bus->adapter); 1373 intel_output->ddc_bus);
1375 if (edid != NULL) { 1374 if (edid != NULL) {
1376 sdvo_priv->is_hdmi = drm_detect_hdmi_monitor(edid); 1375 sdvo_priv->is_hdmi = drm_detect_hdmi_monitor(edid);
1377 kfree(edid); 1376 kfree(edid);
@@ -1549,7 +1548,6 @@ static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1549static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) 1548static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1550{ 1549{
1551 struct intel_output *intel_output = to_intel_output(connector); 1550 struct intel_output *intel_output = to_intel_output(connector);
1552 struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
1553 struct drm_i915_private *dev_priv = connector->dev->dev_private; 1551 struct drm_i915_private *dev_priv = connector->dev->dev_private;
1554 1552
1555 /* 1553 /*
@@ -1557,8 +1555,6 @@ static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1557 * Assume that the preferred modes are 1555 * Assume that the preferred modes are
1558 * arranged in priority order. 1556 * arranged in priority order.
1559 */ 1557 */
1560 /* set the bus switch and get the modes */
1561 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
1562 intel_ddc_get_modes(intel_output); 1558 intel_ddc_get_modes(intel_output);
1563 if (list_empty(&connector->probed_modes) == false) 1559 if (list_empty(&connector->probed_modes) == false)
1564 return; 1560 return;
@@ -1709,7 +1705,7 @@ intel_sdvo_chan_to_intel_output(struct intel_i2c_chan *chan)
1709 1705
1710 list_for_each_entry(connector, 1706 list_for_each_entry(connector,
1711 &dev->mode_config.connector_list, head) { 1707 &dev->mode_config.connector_list, head) {
1712 if (to_intel_output(connector)->ddc_bus == chan) { 1708 if (to_intel_output(connector)->ddc_bus == &chan->adapter) {
1713 intel_output = to_intel_output(connector); 1709 intel_output = to_intel_output(connector);
1714 break; 1710 break;
1715 } 1711 }
@@ -1723,7 +1719,7 @@ static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
1723 struct intel_output *intel_output; 1719 struct intel_output *intel_output;
1724 struct intel_sdvo_priv *sdvo_priv; 1720 struct intel_sdvo_priv *sdvo_priv;
1725 struct i2c_algo_bit_data *algo_data; 1721 struct i2c_algo_bit_data *algo_data;
1726 struct i2c_algorithm *algo; 1722 const struct i2c_algorithm *algo;
1727 1723
1728 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data; 1724 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
1729 intel_output = 1725 intel_output =
@@ -1733,7 +1729,7 @@ static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
1733 return -EINVAL; 1729 return -EINVAL;
1734 1730
1735 sdvo_priv = intel_output->dev_priv; 1731 sdvo_priv = intel_output->dev_priv;
1736 algo = (struct i2c_algorithm *)intel_output->i2c_bus->adapter.algo; 1732 algo = intel_output->i2c_bus->algo;
1737 1733
1738 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus); 1734 intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
1739 return algo->master_xfer(i2c_adap, msgs, num); 1735 return algo->master_xfer(i2c_adap, msgs, num);
@@ -1785,13 +1781,11 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
1785 struct drm_connector *connector; 1781 struct drm_connector *connector;
1786 struct intel_output *intel_output; 1782 struct intel_output *intel_output;
1787 struct intel_sdvo_priv *sdvo_priv; 1783 struct intel_sdvo_priv *sdvo_priv;
1788 struct intel_i2c_chan *i2cbus = NULL; 1784
1789 struct intel_i2c_chan *ddcbus = NULL;
1790 int connector_type; 1785 int connector_type;
1791 u8 ch[0x40]; 1786 u8 ch[0x40];
1792 int i; 1787 int i;
1793 int encoder_type, output_id; 1788 int encoder_type;
1794 u8 slave_addr;
1795 1789
1796 intel_output = kcalloc(sizeof(struct intel_output)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL); 1790 intel_output = kcalloc(sizeof(struct intel_output)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL);
1797 if (!intel_output) { 1791 if (!intel_output) {
@@ -1799,29 +1793,24 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
1799 } 1793 }
1800 1794
1801 sdvo_priv = (struct intel_sdvo_priv *)(intel_output + 1); 1795 sdvo_priv = (struct intel_sdvo_priv *)(intel_output + 1);
1796 sdvo_priv->output_device = output_device;
1797
1798 intel_output->dev_priv = sdvo_priv;
1802 intel_output->type = INTEL_OUTPUT_SDVO; 1799 intel_output->type = INTEL_OUTPUT_SDVO;
1803 1800
1804 /* setup the DDC bus. */ 1801 /* setup the DDC bus. */
1805 if (output_device == SDVOB) 1802 if (output_device == SDVOB)
1806 i2cbus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB"); 1803 intel_output->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB");
1807 else 1804 else
1808 i2cbus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC"); 1805 intel_output->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC");
1809 1806
1810 if (!i2cbus) 1807 if (!intel_output->i2c_bus)
1811 goto err_inteloutput; 1808 goto err_inteloutput;
1812 1809
1813 slave_addr = intel_sdvo_get_slave_addr(dev, output_device); 1810 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
1814 sdvo_priv->i2c_bus = i2cbus;
1815 1811
1816 if (output_device == SDVOB) { 1812 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
1817 output_id = 1; 1813 intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
1818 } else {
1819 output_id = 2;
1820 }
1821 sdvo_priv->i2c_bus->slave_addr = slave_addr >> 1;
1822 sdvo_priv->output_device = output_device;
1823 intel_output->i2c_bus = i2cbus;
1824 intel_output->dev_priv = sdvo_priv;
1825 1814
1826 /* Read the regs to test if we can talk to the device */ 1815 /* Read the regs to test if we can talk to the device */
1827 for (i = 0; i < 0x40; i++) { 1816 for (i = 0; i < 0x40; i++) {
@@ -1835,17 +1824,15 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
1835 1824
1836 /* setup the DDC bus. */ 1825 /* setup the DDC bus. */
1837 if (output_device == SDVOB) 1826 if (output_device == SDVOB)
1838 ddcbus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS"); 1827 intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS");
1839 else 1828 else
1840 ddcbus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS"); 1829 intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS");
1841 1830
1842 if (ddcbus == NULL) 1831 if (intel_output->ddc_bus == NULL)
1843 goto err_i2c; 1832 goto err_i2c;
1844 1833
1845 intel_sdvo_i2c_bit_algo.functionality = 1834 /* Wrap with our custom algo which switches to DDC mode */
1846 intel_output->i2c_bus->adapter.algo->functionality; 1835 intel_output->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
1847 ddcbus->adapter.algo = &intel_sdvo_i2c_bit_algo;
1848 intel_output->ddc_bus = ddcbus;
1849 1836
1850 /* In defaut case sdvo lvds is false */ 1837 /* In defaut case sdvo lvds is false */
1851 sdvo_priv->is_lvds = false; 1838 sdvo_priv->is_lvds = false;
@@ -1965,9 +1952,10 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
1965 return true; 1952 return true;
1966 1953
1967err_i2c: 1954err_i2c:
1968 if (ddcbus != NULL) 1955 if (intel_output->ddc_bus != NULL)
1969 intel_i2c_destroy(intel_output->ddc_bus); 1956 intel_i2c_destroy(intel_output->ddc_bus);
1970 intel_i2c_destroy(intel_output->i2c_bus); 1957 if (intel_output->i2c_bus != NULL)
1958 intel_i2c_destroy(intel_output->i2c_bus);
1971err_inteloutput: 1959err_inteloutput:
1972 kfree(intel_output); 1960 kfree(intel_output);
1973 1961
diff --git a/drivers/gpu/drm/i915/intel_tv.c b/drivers/gpu/drm/i915/intel_tv.c
index ea68992e4416..a43c98e3f077 100644
--- a/drivers/gpu/drm/i915/intel_tv.c
+++ b/drivers/gpu/drm/i915/intel_tv.c
@@ -1383,34 +1383,31 @@ intel_tv_detect_type (struct drm_crtc *crtc, struct intel_output *intel_output)
1383 /* 1383 /*
1384 * Detect TV by polling) 1384 * Detect TV by polling)
1385 */ 1385 */
1386 if (intel_output->load_detect_temp) { 1386 save_tv_dac = tv_dac;
1387 /* TV not currently running, prod it with destructive detect */ 1387 tv_ctl = I915_READ(TV_CTL);
1388 save_tv_dac = tv_dac; 1388 save_tv_ctl = tv_ctl;
1389 tv_ctl = I915_READ(TV_CTL); 1389 tv_ctl &= ~TV_ENC_ENABLE;
1390 save_tv_ctl = tv_ctl; 1390 tv_ctl &= ~TV_TEST_MODE_MASK;
1391 tv_ctl &= ~TV_ENC_ENABLE; 1391 tv_ctl |= TV_TEST_MODE_MONITOR_DETECT;
1392 tv_ctl &= ~TV_TEST_MODE_MASK; 1392 tv_dac &= ~TVDAC_SENSE_MASK;
1393 tv_ctl |= TV_TEST_MODE_MONITOR_DETECT; 1393 tv_dac &= ~DAC_A_MASK;
1394 tv_dac &= ~TVDAC_SENSE_MASK; 1394 tv_dac &= ~DAC_B_MASK;
1395 tv_dac &= ~DAC_A_MASK; 1395 tv_dac &= ~DAC_C_MASK;
1396 tv_dac &= ~DAC_B_MASK; 1396 tv_dac |= (TVDAC_STATE_CHG_EN |
1397 tv_dac &= ~DAC_C_MASK; 1397 TVDAC_A_SENSE_CTL |
1398 tv_dac |= (TVDAC_STATE_CHG_EN | 1398 TVDAC_B_SENSE_CTL |
1399 TVDAC_A_SENSE_CTL | 1399 TVDAC_C_SENSE_CTL |
1400 TVDAC_B_SENSE_CTL | 1400 DAC_CTL_OVERRIDE |
1401 TVDAC_C_SENSE_CTL | 1401 DAC_A_0_7_V |
1402 DAC_CTL_OVERRIDE | 1402 DAC_B_0_7_V |
1403 DAC_A_0_7_V | 1403 DAC_C_0_7_V);
1404 DAC_B_0_7_V | 1404 I915_WRITE(TV_CTL, tv_ctl);
1405 DAC_C_0_7_V); 1405 I915_WRITE(TV_DAC, tv_dac);
1406 I915_WRITE(TV_CTL, tv_ctl); 1406 intel_wait_for_vblank(dev);
1407 I915_WRITE(TV_DAC, tv_dac); 1407 tv_dac = I915_READ(TV_DAC);
1408 intel_wait_for_vblank(dev); 1408 I915_WRITE(TV_DAC, save_tv_dac);
1409 tv_dac = I915_READ(TV_DAC); 1409 I915_WRITE(TV_CTL, save_tv_ctl);
1410 I915_WRITE(TV_DAC, save_tv_dac); 1410 intel_wait_for_vblank(dev);
1411 I915_WRITE(TV_CTL, save_tv_ctl);
1412 intel_wait_for_vblank(dev);
1413 }
1414 /* 1411 /*
1415 * A B C 1412 * A B C
1416 * 0 1 1 Composite 1413 * 0 1 1 Composite
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index f30aa7274a54..f97563db4e59 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -35,6 +35,23 @@
35#include "atom.h" 35#include "atom.h"
36 36
37/* 37/*
38 * Clear GPU surface registers.
39 */
40static void radeon_surface_init(struct radeon_device *rdev)
41{
42 /* FIXME: check this out */
43 if (rdev->family < CHIP_R600) {
44 int i;
45
46 for (i = 0; i < 8; i++) {
47 WREG32(RADEON_SURFACE0_INFO +
48 i * (RADEON_SURFACE1_INFO - RADEON_SURFACE0_INFO),
49 0);
50 }
51 }
52}
53
54/*
38 * GPU scratch registers helpers function. 55 * GPU scratch registers helpers function.
39 */ 56 */
40static void radeon_scratch_init(struct radeon_device *rdev) 57static void radeon_scratch_init(struct radeon_device *rdev)
@@ -496,6 +513,8 @@ int radeon_device_init(struct radeon_device *rdev,
496 radeon_errata(rdev); 513 radeon_errata(rdev);
497 /* Initialize scratch registers */ 514 /* Initialize scratch registers */
498 radeon_scratch_init(rdev); 515 radeon_scratch_init(rdev);
516 /* Initialize surface registers */
517 radeon_surface_init(rdev);
499 518
500 /* TODO: disable VGA need to use VGA request */ 519 /* TODO: disable VGA need to use VGA request */
501 /* BIOS*/ 520 /* BIOS*/
@@ -604,9 +623,6 @@ int radeon_device_init(struct radeon_device *rdev,
604 if (r) { 623 if (r) {
605 return r; 624 return r;
606 } 625 }
607 if (rdev->fbdev_rfb && rdev->fbdev_rfb->obj) {
608 rdev->fbdev_robj = rdev->fbdev_rfb->obj->driver_private;
609 }
610 if (!ret) { 626 if (!ret) {
611 DRM_INFO("radeon: kernel modesetting successfully initialized.\n"); 627 DRM_INFO("radeon: kernel modesetting successfully initialized.\n");
612 } 628 }
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index 09c9fb9f6210..84ba69f48784 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -345,7 +345,7 @@ static void __exit radeon_exit(void)
345 drm_exit(driver); 345 drm_exit(driver);
346} 346}
347 347
348late_initcall(radeon_init); 348module_init(radeon_init);
349module_exit(radeon_exit); 349module_exit(radeon_exit);
350 350
351MODULE_AUTHOR(DRIVER_AUTHOR); 351MODULE_AUTHOR(DRIVER_AUTHOR);
diff --git a/drivers/gpu/drm/radeon/radeon_fb.c b/drivers/gpu/drm/radeon/radeon_fb.c
index fa86d398945e..9e8f191eb64a 100644
--- a/drivers/gpu/drm/radeon/radeon_fb.c
+++ b/drivers/gpu/drm/radeon/radeon_fb.c
@@ -478,14 +478,16 @@ int radeonfb_create(struct radeon_device *rdev,
478{ 478{
479 struct fb_info *info; 479 struct fb_info *info;
480 struct radeon_fb_device *rfbdev; 480 struct radeon_fb_device *rfbdev;
481 struct drm_framebuffer *fb; 481 struct drm_framebuffer *fb = NULL;
482 struct radeon_framebuffer *rfb; 482 struct radeon_framebuffer *rfb;
483 struct drm_mode_fb_cmd mode_cmd; 483 struct drm_mode_fb_cmd mode_cmd;
484 struct drm_gem_object *gobj = NULL; 484 struct drm_gem_object *gobj = NULL;
485 struct radeon_object *robj = NULL; 485 struct radeon_object *robj = NULL;
486 struct device *device = &rdev->pdev->dev; 486 struct device *device = &rdev->pdev->dev;
487 int size, aligned_size, ret; 487 int size, aligned_size, ret;
488 u64 fb_gpuaddr;
488 void *fbptr = NULL; 489 void *fbptr = NULL;
490 unsigned long tmp;
489 491
490 mode_cmd.width = surface_width; 492 mode_cmd.width = surface_width;
491 mode_cmd.height = surface_height; 493 mode_cmd.height = surface_height;
@@ -498,11 +500,12 @@ int radeonfb_create(struct radeon_device *rdev,
498 aligned_size = ALIGN(size, PAGE_SIZE); 500 aligned_size = ALIGN(size, PAGE_SIZE);
499 501
500 ret = radeon_gem_object_create(rdev, aligned_size, 0, 502 ret = radeon_gem_object_create(rdev, aligned_size, 0,
501 RADEON_GEM_DOMAIN_VRAM, 503 RADEON_GEM_DOMAIN_VRAM,
502 false, ttm_bo_type_kernel, 504 false, ttm_bo_type_kernel,
503 false, &gobj); 505 false, &gobj);
504 if (ret) { 506 if (ret) {
505 printk(KERN_ERR "failed to allocate framebuffer\n"); 507 printk(KERN_ERR "failed to allocate framebuffer (%d %d)\n",
508 surface_width, surface_height);
506 ret = -ENOMEM; 509 ret = -ENOMEM;
507 goto out; 510 goto out;
508 } 511 }
@@ -515,12 +518,19 @@ int radeonfb_create(struct radeon_device *rdev,
515 ret = -ENOMEM; 518 ret = -ENOMEM;
516 goto out_unref; 519 goto out_unref;
517 } 520 }
521 ret = radeon_object_pin(robj, RADEON_GEM_DOMAIN_VRAM, &fb_gpuaddr);
522 if (ret) {
523 printk(KERN_ERR "failed to pin framebuffer\n");
524 ret = -ENOMEM;
525 goto out_unref;
526 }
518 527
519 list_add(&fb->filp_head, &rdev->ddev->mode_config.fb_kernel_list); 528 list_add(&fb->filp_head, &rdev->ddev->mode_config.fb_kernel_list);
520 529
521 rfb = to_radeon_framebuffer(fb); 530 rfb = to_radeon_framebuffer(fb);
522 *rfb_p = rfb; 531 *rfb_p = rfb;
523 rdev->fbdev_rfb = rfb; 532 rdev->fbdev_rfb = rfb;
533 rdev->fbdev_robj = robj;
524 534
525 info = framebuffer_alloc(sizeof(struct radeon_fb_device), device); 535 info = framebuffer_alloc(sizeof(struct radeon_fb_device), device);
526 if (info == NULL) { 536 if (info == NULL) {
@@ -541,13 +551,13 @@ int radeonfb_create(struct radeon_device *rdev,
541 info->fix.xpanstep = 1; /* doing it in hw */ 551 info->fix.xpanstep = 1; /* doing it in hw */
542 info->fix.ypanstep = 1; /* doing it in hw */ 552 info->fix.ypanstep = 1; /* doing it in hw */
543 info->fix.ywrapstep = 0; 553 info->fix.ywrapstep = 0;
544 info->fix.accel = FB_ACCEL_I830; 554 info->fix.accel = FB_ACCEL_NONE;
545 info->fix.type_aux = 0; 555 info->fix.type_aux = 0;
546 info->flags = FBINFO_DEFAULT; 556 info->flags = FBINFO_DEFAULT;
547 info->fbops = &radeonfb_ops; 557 info->fbops = &radeonfb_ops;
548 info->fix.line_length = fb->pitch; 558 info->fix.line_length = fb->pitch;
549 info->screen_base = fbptr; 559 tmp = fb_gpuaddr - rdev->mc.vram_location;
550 info->fix.smem_start = (unsigned long)fbptr; 560 info->fix.smem_start = rdev->mc.aper_base + tmp;
551 info->fix.smem_len = size; 561 info->fix.smem_len = size;
552 info->screen_base = fbptr; 562 info->screen_base = fbptr;
553 info->screen_size = size; 563 info->screen_size = size;
@@ -562,8 +572,8 @@ int radeonfb_create(struct radeon_device *rdev,
562 info->var.width = -1; 572 info->var.width = -1;
563 info->var.xres = fb_width; 573 info->var.xres = fb_width;
564 info->var.yres = fb_height; 574 info->var.yres = fb_height;
565 info->fix.mmio_start = pci_resource_start(rdev->pdev, 2); 575 info->fix.mmio_start = 0;
566 info->fix.mmio_len = pci_resource_len(rdev->pdev, 2); 576 info->fix.mmio_len = 0;
567 info->pixmap.size = 64*1024; 577 info->pixmap.size = 64*1024;
568 info->pixmap.buf_align = 8; 578 info->pixmap.buf_align = 8;
569 info->pixmap.access_align = 32; 579 info->pixmap.access_align = 32;
@@ -644,7 +654,7 @@ out_unref:
644 if (robj) { 654 if (robj) {
645 radeon_object_kunmap(robj); 655 radeon_object_kunmap(robj);
646 } 656 }
647 if (ret) { 657 if (fb && ret) {
648 list_del(&fb->filp_head); 658 list_del(&fb->filp_head);
649 drm_gem_object_unreference(gobj); 659 drm_gem_object_unreference(gobj);
650 drm_framebuffer_cleanup(fb); 660 drm_framebuffer_cleanup(fb);
@@ -813,6 +823,7 @@ int radeonfb_remove(struct drm_device *dev, struct drm_framebuffer *fb)
813 robj = rfb->obj->driver_private; 823 robj = rfb->obj->driver_private;
814 unregister_framebuffer(info); 824 unregister_framebuffer(info);
815 radeon_object_kunmap(robj); 825 radeon_object_kunmap(robj);
826 radeon_object_unpin(robj);
816 framebuffer_release(info); 827 framebuffer_release(info);
817 } 828 }
818 829
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index 983e8df5e000..bac0d06c52ac 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -223,7 +223,6 @@ int radeon_object_pin(struct radeon_object *robj, uint32_t domain,
223{ 223{
224 uint32_t flags; 224 uint32_t flags;
225 uint32_t tmp; 225 uint32_t tmp;
226 void *fbptr;
227 int r; 226 int r;
228 227
229 flags = radeon_object_flags_from_domain(domain); 228 flags = radeon_object_flags_from_domain(domain);
@@ -242,10 +241,6 @@ int radeon_object_pin(struct radeon_object *robj, uint32_t domain,
242 DRM_ERROR("radeon: failed to reserve object for pinning it.\n"); 241 DRM_ERROR("radeon: failed to reserve object for pinning it.\n");
243 return r; 242 return r;
244 } 243 }
245 if (robj->rdev->fbdev_robj == robj) {
246 mutex_lock(&robj->rdev->fbdev_info->lock);
247 radeon_object_kunmap(robj);
248 }
249 tmp = robj->tobj.mem.placement; 244 tmp = robj->tobj.mem.placement;
250 ttm_flag_masked(&tmp, flags, TTM_PL_MASK_MEM); 245 ttm_flag_masked(&tmp, flags, TTM_PL_MASK_MEM);
251 robj->tobj.proposed_placement = tmp | TTM_PL_FLAG_NO_EVICT | TTM_PL_MASK_CACHING; 246 robj->tobj.proposed_placement = tmp | TTM_PL_FLAG_NO_EVICT | TTM_PL_MASK_CACHING;
@@ -261,23 +256,12 @@ int radeon_object_pin(struct radeon_object *robj, uint32_t domain,
261 DRM_ERROR("radeon: failed to pin object.\n"); 256 DRM_ERROR("radeon: failed to pin object.\n");
262 } 257 }
263 radeon_object_unreserve(robj); 258 radeon_object_unreserve(robj);
264 if (robj->rdev->fbdev_robj == robj) {
265 if (!r) {
266 r = radeon_object_kmap(robj, &fbptr);
267 }
268 if (!r) {
269 robj->rdev->fbdev_info->screen_base = fbptr;
270 robj->rdev->fbdev_info->fix.smem_start = (unsigned long)fbptr;
271 }
272 mutex_unlock(&robj->rdev->fbdev_info->lock);
273 }
274 return r; 259 return r;
275} 260}
276 261
277void radeon_object_unpin(struct radeon_object *robj) 262void radeon_object_unpin(struct radeon_object *robj)
278{ 263{
279 uint32_t flags; 264 uint32_t flags;
280 void *fbptr;
281 int r; 265 int r;
282 266
283 spin_lock(&robj->tobj.lock); 267 spin_lock(&robj->tobj.lock);
@@ -297,10 +281,6 @@ void radeon_object_unpin(struct radeon_object *robj)
297 DRM_ERROR("radeon: failed to reserve object for unpinning it.\n"); 281 DRM_ERROR("radeon: failed to reserve object for unpinning it.\n");
298 return; 282 return;
299 } 283 }
300 if (robj->rdev->fbdev_robj == robj) {
301 mutex_lock(&robj->rdev->fbdev_info->lock);
302 radeon_object_kunmap(robj);
303 }
304 flags = robj->tobj.mem.placement; 284 flags = robj->tobj.mem.placement;
305 robj->tobj.proposed_placement = flags & ~TTM_PL_FLAG_NO_EVICT; 285 robj->tobj.proposed_placement = flags & ~TTM_PL_FLAG_NO_EVICT;
306 r = ttm_buffer_object_validate(&robj->tobj, 286 r = ttm_buffer_object_validate(&robj->tobj,
@@ -310,16 +290,6 @@ void radeon_object_unpin(struct radeon_object *robj)
310 DRM_ERROR("radeon: failed to unpin buffer.\n"); 290 DRM_ERROR("radeon: failed to unpin buffer.\n");
311 } 291 }
312 radeon_object_unreserve(robj); 292 radeon_object_unreserve(robj);
313 if (robj->rdev->fbdev_robj == robj) {
314 if (!r) {
315 r = radeon_object_kmap(robj, &fbptr);
316 }
317 if (!r) {
318 robj->rdev->fbdev_info->screen_base = fbptr;
319 robj->rdev->fbdev_info->fix.smem_start = (unsigned long)fbptr;
320 }
321 mutex_unlock(&robj->rdev->fbdev_info->lock);
322 }
323} 293}
324 294
325int radeon_object_wait(struct radeon_object *robj) 295int radeon_object_wait(struct radeon_object *robj)
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 517c84559633..bdec583901eb 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -34,7 +34,6 @@
34#include <linux/highmem.h> 34#include <linux/highmem.h>
35#include <linux/wait.h> 35#include <linux/wait.h>
36#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
37#include <linux/version.h>
38#include <linux/module.h> 37#include <linux/module.h>
39 38
40void ttm_bo_free_old_node(struct ttm_buffer_object *bo) 39void ttm_bo_free_old_node(struct ttm_buffer_object *bo)
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 27b146c54fbc..40b75032ea47 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -32,7 +32,6 @@
32#include <ttm/ttm_bo_driver.h> 32#include <ttm/ttm_bo_driver.h>
33#include <ttm/ttm_placement.h> 33#include <ttm/ttm_placement.h>
34#include <linux/mm.h> 34#include <linux/mm.h>
35#include <linux/version.h>
36#include <linux/rbtree.h> 35#include <linux/rbtree.h>
37#include <linux/module.h> 36#include <linux/module.h>
38#include <linux/uaccess.h> 37#include <linux/uaccess.h>
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 0331fa74cd3f..75dc8bd24592 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -28,7 +28,6 @@
28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 28 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29 */ 29 */
30 30
31#include <linux/version.h>
32#include <linux/vmalloc.h> 31#include <linux/vmalloc.h>
33#include <linux/sched.h> 32#include <linux/sched.h>
34#include <linux/highmem.h> 33#include <linux/highmem.h>
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index aa87b6a3bbef..8206442fbabd 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -328,6 +328,7 @@ config I2C_DAVINCI
328 328
329config I2C_DESIGNWARE 329config I2C_DESIGNWARE
330 tristate "Synopsys DesignWare" 330 tristate "Synopsys DesignWare"
331 depends on HAVE_CLK
331 help 332 help
332 If you say yes to this option, support will be included for the 333 If you say yes to this option, support will be included for the
333 Synopsys DesignWare I2C adapter. Only master mode is supported. 334 Synopsys DesignWare I2C adapter. Only master mode is supported.
diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
index bd066bb9d611..09f98ed0731f 100644
--- a/drivers/ide/cs5520.c
+++ b/drivers/ide/cs5520.c
@@ -135,6 +135,7 @@ static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_devic
135 135
136 ide_pci_setup_ports(dev, d, &hw[0], &hws[0]); 136 ide_pci_setup_ports(dev, d, &hw[0], &hws[0]);
137 hw[0].irq = 14; 137 hw[0].irq = 14;
138 hw[1].irq = 15;
138 139
139 return ide_host_add(d, hws, 2, NULL); 140 return ide_host_add(d, hws, 2, NULL);
140} 141}
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 77f79d26b264..c509c9916464 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -92,6 +92,11 @@ int ide_acpi_init(void)
92 return 0; 92 return 0;
93} 93}
94 94
95bool ide_port_acpi(ide_hwif_t *hwif)
96{
97 return ide_noacpi == 0 && hwif->acpidata;
98}
99
95/** 100/**
96 * ide_get_dev_handle - finds acpi_handle and PCI device.function 101 * ide_get_dev_handle - finds acpi_handle and PCI device.function
97 * @dev: device to locate 102 * @dev: device to locate
@@ -352,9 +357,6 @@ int ide_acpi_exec_tfs(ide_drive_t *drive)
352 unsigned long gtf_address; 357 unsigned long gtf_address;
353 unsigned long obj_loc; 358 unsigned long obj_loc;
354 359
355 if (ide_noacpi)
356 return 0;
357
358 DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn); 360 DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn);
359 361
360 ret = do_drive_get_GTF(drive, &gtf_length, &gtf_address, &obj_loc); 362 ret = do_drive_get_GTF(drive, &gtf_length, &gtf_address, &obj_loc);
@@ -389,16 +391,6 @@ void ide_acpi_get_timing(ide_hwif_t *hwif)
389 struct acpi_buffer output; 391 struct acpi_buffer output;
390 union acpi_object *out_obj; 392 union acpi_object *out_obj;
391 393
392 if (ide_noacpi)
393 return;
394
395 DEBPRINT("ENTER:\n");
396
397 if (!hwif->acpidata) {
398 DEBPRINT("no ACPI data for %s\n", hwif->name);
399 return;
400 }
401
402 /* Setting up output buffer for _GTM */ 394 /* Setting up output buffer for _GTM */
403 output.length = ACPI_ALLOCATE_BUFFER; 395 output.length = ACPI_ALLOCATE_BUFFER;
404 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ 396 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
@@ -479,16 +471,6 @@ void ide_acpi_push_timing(ide_hwif_t *hwif)
479 struct ide_acpi_drive_link *master = &hwif->acpidata->master; 471 struct ide_acpi_drive_link *master = &hwif->acpidata->master;
480 struct ide_acpi_drive_link *slave = &hwif->acpidata->slave; 472 struct ide_acpi_drive_link *slave = &hwif->acpidata->slave;
481 473
482 if (ide_noacpi)
483 return;
484
485 DEBPRINT("ENTER:\n");
486
487 if (!hwif->acpidata) {
488 DEBPRINT("no ACPI data for %s\n", hwif->name);
489 return;
490 }
491
492 /* Give the GTM buffer + drive Identify data to the channel via the 474 /* Give the GTM buffer + drive Identify data to the channel via the
493 * _STM method: */ 475 * _STM method: */
494 /* setup input parameters buffer for _STM */ 476 /* setup input parameters buffer for _STM */
@@ -527,16 +509,11 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
527 ide_drive_t *drive; 509 ide_drive_t *drive;
528 int i; 510 int i;
529 511
530 if (ide_noacpi || ide_noacpi_psx) 512 if (ide_noacpi_psx)
531 return; 513 return;
532 514
533 DEBPRINT("ENTER:\n"); 515 DEBPRINT("ENTER:\n");
534 516
535 if (!hwif->acpidata) {
536 DEBPRINT("no ACPI data for %s\n", hwif->name);
537 return;
538 }
539
540 /* channel first and then drives for power on and verse versa for power off */ 517 /* channel first and then drives for power on and verse versa for power off */
541 if (on) 518 if (on)
542 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0); 519 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
@@ -616,7 +593,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
616 drive->name, err); 593 drive->name, err);
617 } 594 }
618 595
619 if (!ide_acpionboot) { 596 if (ide_noacpi || ide_acpionboot == 0) {
620 DEBPRINT("ACPI methods disabled on boot\n"); 597 DEBPRINT("ACPI methods disabled on boot\n");
621 return; 598 return;
622 } 599 }
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 4a19686fcfe9..6a9a769bffc1 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -592,9 +592,19 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
592 } 592 }
593 } else if (!blk_pc_request(rq)) { 593 } else if (!blk_pc_request(rq)) {
594 ide_cd_request_sense_fixup(drive, cmd); 594 ide_cd_request_sense_fixup(drive, cmd);
595 /* complain if we still have data left to transfer */ 595
596 uptodate = cmd->nleft ? 0 : 1; 596 uptodate = cmd->nleft ? 0 : 1;
597 if (uptodate == 0) 597
598 /*
599 * suck out the remaining bytes from the drive in an
600 * attempt to complete the data xfer. (see BZ#13399)
601 */
602 if (!(stat & ATA_ERR) && !uptodate && thislen) {
603 ide_pio_bytes(drive, cmd, write, thislen);
604 uptodate = cmd->nleft ? 0 : 1;
605 }
606
607 if (!uptodate)
598 rq->cmd_flags |= REQ_FAILED; 608 rq->cmd_flags |= REQ_FAILED;
599 } 609 }
600 goto out_end; 610 goto out_end;
@@ -876,9 +886,12 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
876 return stat; 886 return stat;
877 887
878 /* 888 /*
879 * Sanity check the given block size 889 * Sanity check the given block size, in so far as making
890 * sure the sectors_per_frame we give to the caller won't
891 * end up being bogus.
880 */ 892 */
881 blocklen = be32_to_cpu(capbuf.blocklen); 893 blocklen = be32_to_cpu(capbuf.blocklen);
894 blocklen = (blocklen >> SECTOR_BITS) << SECTOR_BITS;
882 switch (blocklen) { 895 switch (blocklen) {
883 case 512: 896 case 512:
884 case 1024: 897 case 1024:
@@ -886,10 +899,9 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
886 case 4096: 899 case 4096:
887 break; 900 break;
888 default: 901 default:
889 printk(KERN_ERR PFX "%s: weird block size %u\n", 902 printk_once(KERN_ERR PFX "%s: weird block size %u; "
903 "setting default block size to 2048\n",
890 drive->name, blocklen); 904 drive->name, blocklen);
891 printk(KERN_ERR PFX "%s: default to 2kb block size\n",
892 drive->name);
893 blocklen = 2048; 905 blocklen = 2048;
894 break; 906 break;
895 } 907 }
diff --git a/drivers/ide/ide-devsets.c b/drivers/ide/ide-devsets.c
index 5bf958e5b1d5..1099bf7cf968 100644
--- a/drivers/ide/ide-devsets.c
+++ b/drivers/ide/ide-devsets.c
@@ -183,6 +183,6 @@ ide_startstop_t ide_do_devset(ide_drive_t *drive, struct request *rq)
183 err = setfunc(drive, *(int *)&rq->cmd[1]); 183 err = setfunc(drive, *(int *)&rq->cmd[1]);
184 if (err) 184 if (err)
185 rq->errors = err; 185 rq->errors = err;
186 ide_complete_rq(drive, err, ide_rq_bytes(rq)); 186 ide_complete_rq(drive, err, blk_rq_bytes(rq));
187 return ide_stopped; 187 return ide_stopped;
188} 188}
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 219e6fb78dc6..ee58c88dee5a 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -361,9 +361,6 @@ static int ide_tune_dma(ide_drive_t *drive)
361 if (__ide_dma_bad_drive(drive)) 361 if (__ide_dma_bad_drive(drive))
362 return 0; 362 return 0;
363 363
364 if (ide_id_dma_bug(drive))
365 return 0;
366
367 if (hwif->host_flags & IDE_HFLAG_TRUST_BIOS_FOR_DMA) 364 if (hwif->host_flags & IDE_HFLAG_TRUST_BIOS_FOR_DMA)
368 return config_drive_for_dma(drive); 365 return config_drive_for_dma(drive);
369 366
@@ -394,24 +391,6 @@ static int ide_dma_check(ide_drive_t *drive)
394 return -1; 391 return -1;
395} 392}
396 393
397int ide_id_dma_bug(ide_drive_t *drive)
398{
399 u16 *id = drive->id;
400
401 if (id[ATA_ID_FIELD_VALID] & 4) {
402 if ((id[ATA_ID_UDMA_MODES] >> 8) &&
403 (id[ATA_ID_MWDMA_MODES] >> 8))
404 goto err_out;
405 } else if ((id[ATA_ID_MWDMA_MODES] >> 8) &&
406 (id[ATA_ID_SWDMA_MODES] >> 8))
407 goto err_out;
408
409 return 0;
410err_out:
411 printk(KERN_ERR "%s: bad DMA info in identify block\n", drive->name);
412 return 1;
413}
414
415int ide_set_dma(ide_drive_t *drive) 394int ide_set_dma(ide_drive_t *drive)
416{ 395{
417 int rc; 396 int rc;
diff --git a/drivers/ide/ide-eh.c b/drivers/ide/ide-eh.c
index 2b9141979613..e9abf2c3c335 100644
--- a/drivers/ide/ide-eh.c
+++ b/drivers/ide/ide-eh.c
@@ -149,7 +149,7 @@ static inline void ide_complete_drive_reset(ide_drive_t *drive, int err)
149 if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET) { 149 if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET) {
150 if (err <= 0 && rq->errors == 0) 150 if (err <= 0 && rq->errors == 0)
151 rq->errors = -EIO; 151 rq->errors = -EIO;
152 ide_complete_rq(drive, err ? err : 0, ide_rq_bytes(rq)); 152 ide_complete_rq(drive, err ? err : 0, blk_rq_bytes(rq));
153 } 153 }
154} 154}
155 155
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 8b3f204f7d73..fefbdfc8db06 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -293,7 +293,7 @@ out_end:
293 drive->failed_pc = NULL; 293 drive->failed_pc = NULL;
294 if (blk_fs_request(rq) == 0 && rq->errors == 0) 294 if (blk_fs_request(rq) == 0 && rq->errors == 0)
295 rq->errors = -EIO; 295 rq->errors = -EIO;
296 ide_complete_rq(drive, -EIO, ide_rq_bytes(rq)); 296 ide_complete_rq(drive, -EIO, blk_rq_bytes(rq));
297 return ide_stopped; 297 return ide_stopped;
298} 298}
299 299
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 1059f809b809..d5f3c77beadd 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -112,16 +112,6 @@ void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err)
112 } 112 }
113} 113}
114 114
115/* obsolete, blk_rq_bytes() should be used instead */
116unsigned int ide_rq_bytes(struct request *rq)
117{
118 if (blk_pc_request(rq))
119 return blk_rq_bytes(rq);
120 else
121 return blk_rq_cur_sectors(rq) << 9;
122}
123EXPORT_SYMBOL_GPL(ide_rq_bytes);
124
125int ide_complete_rq(ide_drive_t *drive, int error, unsigned int nr_bytes) 115int ide_complete_rq(ide_drive_t *drive, int error, unsigned int nr_bytes)
126{ 116{
127 ide_hwif_t *hwif = drive->hwif; 117 ide_hwif_t *hwif = drive->hwif;
@@ -152,14 +142,14 @@ void ide_kill_rq(ide_drive_t *drive, struct request *rq)
152 142
153 if ((media == ide_floppy || media == ide_tape) && drv_req) { 143 if ((media == ide_floppy || media == ide_tape) && drv_req) {
154 rq->errors = 0; 144 rq->errors = 0;
155 ide_complete_rq(drive, 0, blk_rq_bytes(rq));
156 } else { 145 } else {
157 if (media == ide_tape) 146 if (media == ide_tape)
158 rq->errors = IDE_DRV_ERROR_GENERAL; 147 rq->errors = IDE_DRV_ERROR_GENERAL;
159 else if (blk_fs_request(rq) == 0 && rq->errors == 0) 148 else if (blk_fs_request(rq) == 0 && rq->errors == 0)
160 rq->errors = -EIO; 149 rq->errors = -EIO;
161 ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
162 } 150 }
151
152 ide_complete_rq(drive, -EIO, blk_rq_bytes(rq));
163} 153}
164 154
165static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf) 155static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
@@ -476,10 +466,14 @@ void do_ide_request(struct request_queue *q)
476 466
477 if (!ide_lock_port(hwif)) { 467 if (!ide_lock_port(hwif)) {
478 ide_hwif_t *prev_port; 468 ide_hwif_t *prev_port;
479
480 WARN_ON_ONCE(hwif->rq);
481repeat: 469repeat:
482 prev_port = hwif->host->cur_port; 470 prev_port = hwif->host->cur_port;
471
472 if (drive->dev_flags & IDE_DFLAG_BLOCKED)
473 rq = hwif->rq;
474 else
475 WARN_ON_ONCE(hwif->rq);
476
483 if (drive->dev_flags & IDE_DFLAG_SLEEPING && 477 if (drive->dev_flags & IDE_DFLAG_SLEEPING &&
484 time_after(drive->sleep, jiffies)) { 478 time_after(drive->sleep, jiffies)) {
485 ide_unlock_port(hwif); 479 ide_unlock_port(hwif);
@@ -506,43 +500,29 @@ repeat:
506 hwif->cur_dev = drive; 500 hwif->cur_dev = drive;
507 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED); 501 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
508 502
509 spin_unlock_irq(&hwif->lock); 503 if (rq == NULL) {
510 spin_lock_irq(q->queue_lock); 504 spin_unlock_irq(&hwif->lock);
511 /* 505 spin_lock_irq(q->queue_lock);
512 * we know that the queue isn't empty, but this can happen 506 /*
513 * if the q->prep_rq_fn() decides to kill a request 507 * we know that the queue isn't empty, but this can
514 */ 508 * happen if ->prep_rq_fn() decides to kill a request
515 if (!rq) 509 */
516 rq = blk_fetch_request(drive->queue); 510 rq = blk_fetch_request(drive->queue);
511 spin_unlock_irq(q->queue_lock);
512 spin_lock_irq(&hwif->lock);
517 513
518 spin_unlock_irq(q->queue_lock); 514 if (rq == NULL) {
519 spin_lock_irq(&hwif->lock); 515 ide_unlock_port(hwif);
520 516 goto out;
521 if (!rq) { 517 }
522 ide_unlock_port(hwif);
523 goto out;
524 } 518 }
525 519
526 /* 520 /*
527 * Sanity: don't accept a request that isn't a PM request 521 * Sanity: don't accept a request that isn't a PM request
528 * if we are currently power managed. This is very important as 522 * if we are currently power managed.
529 * blk_stop_queue() doesn't prevent the blk_fetch_request()
530 * above to return us whatever is in the queue. Since we call
531 * ide_do_request() ourselves, we end up taking requests while
532 * the queue is blocked...
533 *
534 * We let requests forced at head of queue with ide-preempt
535 * though. I hope that doesn't happen too much, hopefully not
536 * unless the subdriver triggers such a thing in its own PM
537 * state machine.
538 */ 523 */
539 if ((drive->dev_flags & IDE_DFLAG_BLOCKED) && 524 BUG_ON((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
540 blk_pm_request(rq) == 0 && 525 blk_pm_request(rq) == 0);
541 (rq->cmd_flags & REQ_PREEMPT) == 0) {
542 /* there should be no pending command at this point */
543 ide_unlock_port(hwif);
544 goto plug_device;
545 }
546 526
547 hwif->rq = rq; 527 hwif->rq = rq;
548 528
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index 82f252c3ee6e..e246d3d3fbcc 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -64,7 +64,8 @@ static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd,
64 goto out; 64 goto out;
65 } 65 }
66 66
67 id = kmalloc(size, GFP_KERNEL); 67 /* ata_id_to_hd_driveid() relies on 'id' to be fully allocated. */
68 id = kmalloc(ATA_ID_WORDS * 2, GFP_KERNEL);
68 if (id == NULL) { 69 if (id == NULL) {
69 rc = -ENOMEM; 70 rc = -ENOMEM;
70 goto out; 71 goto out;
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index fa047150a1c6..2892b242bbe1 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -210,6 +210,7 @@ EXPORT_SYMBOL_GPL(ide_in_drive_list);
210 */ 210 */
211static const struct drive_list_entry ivb_list[] = { 211static const struct drive_list_entry ivb_list[] = {
212 { "QUANTUM FIREBALLlct10 05" , "A03.0900" }, 212 { "QUANTUM FIREBALLlct10 05" , "A03.0900" },
213 { "QUANTUM FIREBALLlct20 30" , "APL.0900" },
213 { "TSSTcorp CDDVDW SH-S202J" , "SB00" }, 214 { "TSSTcorp CDDVDW SH-S202J" , "SB00" },
214 { "TSSTcorp CDDVDW SH-S202J" , "SB01" }, 215 { "TSSTcorp CDDVDW SH-S202J" , "SB01" },
215 { "TSSTcorp CDDVDW SH-S202N" , "SB00" }, 216 { "TSSTcorp CDDVDW SH-S202N" , "SB00" },
@@ -329,9 +330,6 @@ int ide_driveid_update(ide_drive_t *drive)
329 330
330 kfree(id); 331 kfree(id);
331 332
332 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) && ide_id_dma_bug(drive))
333 ide_dma_off(drive);
334
335 return 1; 333 return 1;
336out_err: 334out_err:
337 if (rc == 2) 335 if (rc == 2)
diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c
index c14ca144cffe..ad7be2669dcb 100644
--- a/drivers/ide/ide-pm.c
+++ b/drivers/ide/ide-pm.c
@@ -10,9 +10,11 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
10 struct request_pm_state rqpm; 10 struct request_pm_state rqpm;
11 int ret; 11 int ret;
12 12
13 /* call ACPI _GTM only once */ 13 if (ide_port_acpi(hwif)) {
14 if ((drive->dn & 1) == 0 || pair == NULL) 14 /* call ACPI _GTM only once */
15 ide_acpi_get_timing(hwif); 15 if ((drive->dn & 1) == 0 || pair == NULL)
16 ide_acpi_get_timing(hwif);
17 }
16 18
17 memset(&rqpm, 0, sizeof(rqpm)); 19 memset(&rqpm, 0, sizeof(rqpm));
18 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 20 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
@@ -26,9 +28,11 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
26 ret = blk_execute_rq(drive->queue, NULL, rq, 0); 28 ret = blk_execute_rq(drive->queue, NULL, rq, 0);
27 blk_put_request(rq); 29 blk_put_request(rq);
28 30
29 /* call ACPI _PS3 only after both devices are suspended */ 31 if (ret == 0 && ide_port_acpi(hwif)) {
30 if (ret == 0 && ((drive->dn & 1) || pair == NULL)) 32 /* call ACPI _PS3 only after both devices are suspended */
31 ide_acpi_set_state(hwif, 0); 33 if ((drive->dn & 1) || pair == NULL)
34 ide_acpi_set_state(hwif, 0);
35 }
32 36
33 return ret; 37 return ret;
34} 38}
@@ -42,13 +46,15 @@ int generic_ide_resume(struct device *dev)
42 struct request_pm_state rqpm; 46 struct request_pm_state rqpm;
43 int err; 47 int err;
44 48
45 /* call ACPI _PS0 / _STM only once */ 49 if (ide_port_acpi(hwif)) {
46 if ((drive->dn & 1) == 0 || pair == NULL) { 50 /* call ACPI _PS0 / _STM only once */
47 ide_acpi_set_state(hwif, 1); 51 if ((drive->dn & 1) == 0 || pair == NULL) {
48 ide_acpi_push_timing(hwif); 52 ide_acpi_set_state(hwif, 1);
49 } 53 ide_acpi_push_timing(hwif);
54 }
50 55
51 ide_acpi_exec_tfs(drive); 56 ide_acpi_exec_tfs(drive);
57 }
52 58
53 memset(&rqpm, 0, sizeof(rqpm)); 59 memset(&rqpm, 0, sizeof(rqpm));
54 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 60 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 51af4eea0d36..1bb106f6221a 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -818,6 +818,24 @@ static int ide_port_setup_devices(ide_hwif_t *hwif)
818 return j; 818 return j;
819} 819}
820 820
821static void ide_host_enable_irqs(struct ide_host *host)
822{
823 ide_hwif_t *hwif;
824 int i;
825
826 ide_host_for_each_port(i, hwif, host) {
827 if (hwif == NULL)
828 continue;
829
830 /* clear any pending IRQs */
831 hwif->tp_ops->read_status(hwif);
832
833 /* unmask IRQs */
834 if (hwif->io_ports.ctl_addr)
835 hwif->tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
836 }
837}
838
821/* 839/*
822 * This routine sets up the IRQ for an IDE interface. 840 * This routine sets up the IRQ for an IDE interface.
823 */ 841 */
@@ -831,9 +849,6 @@ static int init_irq (ide_hwif_t *hwif)
831 if (irq_handler == NULL) 849 if (irq_handler == NULL)
832 irq_handler = ide_intr; 850 irq_handler = ide_intr;
833 851
834 if (io_ports->ctl_addr)
835 hwif->tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
836
837 if (request_irq(hwif->irq, irq_handler, sa, hwif->name, hwif)) 852 if (request_irq(hwif->irq, irq_handler, sa, hwif->name, hwif))
838 goto out_up; 853 goto out_up;
839 854
@@ -1404,6 +1419,8 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1404 ide_port_tune_devices(hwif); 1419 ide_port_tune_devices(hwif);
1405 } 1420 }
1406 1421
1422 ide_host_enable_irqs(host);
1423
1407 ide_host_for_each_port(i, hwif, host) { 1424 ide_host_for_each_port(i, hwif, host) {
1408 if (hwif == NULL) 1425 if (hwif == NULL)
1409 continue; 1426 continue;
diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
index 0384144c0b34..14045a7ba388 100644
--- a/drivers/ieee802154/fakehard.c
+++ b/drivers/ieee802154/fakehard.c
@@ -132,7 +132,7 @@ static int ieee802154_fake_xmit(struct sk_buff *skb, struct net_device *dev)
132 132
133 /* FIXME: do hardware work here ... */ 133 /* FIXME: do hardware work here ... */
134 134
135 return 0; 135 return NETDEV_TX_OK;
136} 136}
137 137
138 138
diff --git a/drivers/input/misc/cobalt_btns.c b/drivers/input/misc/cobalt_btns.c
index 2adf9cb265da..d114d3a9e1e9 100644
--- a/drivers/input/misc/cobalt_btns.c
+++ b/drivers/input/misc/cobalt_btns.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Cobalt button interface driver. 2 * Cobalt button interface driver.
3 * 3 *
4 * Copyright (C) 2007-2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007-2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -148,7 +148,7 @@ static int __devexit cobalt_buttons_remove(struct platform_device *pdev)
148 return 0; 148 return 0;
149} 149}
150 150
151MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); 151MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
152MODULE_DESCRIPTION("Cobalt button interface driver"); 152MODULE_DESCRIPTION("Cobalt button interface driver");
153MODULE_LICENSE("GPL"); 153MODULE_LICENSE("GPL");
154/* work with hotplug and coldplug */ 154/* work with hotplug and coldplug */
diff --git a/drivers/isdn/hysdn/hysdn_net.c b/drivers/isdn/hysdn/hysdn_net.c
index 579974cf4c9a..c73004b3b2ac 100644
--- a/drivers/isdn/hysdn/hysdn_net.c
+++ b/drivers/isdn/hysdn/hysdn_net.c
@@ -148,7 +148,7 @@ net_send_packet(struct sk_buff *skb, struct net_device *dev)
148 if (lp->sk_count <= 3) { 148 if (lp->sk_count <= 3) {
149 schedule_work(&((hysdn_card *) dev->ml_priv)->irq_queue); 149 schedule_work(&((hysdn_card *) dev->ml_priv)->irq_queue);
150 } 150 }
151 return (0); /* success */ 151 return NETDEV_TX_OK; /* success */
152} /* net_send_packet */ 152} /* net_send_packet */
153 153
154 154
diff --git a/drivers/isdn/i4l/isdn_net.c b/drivers/isdn/i4l/isdn_net.c
index de4aad076ebc..57bf4bf50278 100644
--- a/drivers/isdn/i4l/isdn_net.c
+++ b/drivers/isdn/i4l/isdn_net.c
@@ -1051,12 +1051,12 @@ isdn_net_xmit(struct net_device *ndev, struct sk_buff *skb)
1051 isdn_net_dev *nd; 1051 isdn_net_dev *nd;
1052 isdn_net_local *slp; 1052 isdn_net_local *slp;
1053 isdn_net_local *lp = (isdn_net_local *) netdev_priv(ndev); 1053 isdn_net_local *lp = (isdn_net_local *) netdev_priv(ndev);
1054 int retv = 0; 1054 int retv = NETDEV_TX_OK;
1055 1055
1056 if (((isdn_net_local *) netdev_priv(ndev))->master) { 1056 if (((isdn_net_local *) netdev_priv(ndev))->master) {
1057 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__); 1057 printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
1058 dev_kfree_skb(skb); 1058 dev_kfree_skb(skb);
1059 return 0; 1059 return NETDEV_TX_OK;
1060 } 1060 }
1061 1061
1062 /* For the other encaps the header has already been built */ 1062 /* For the other encaps the header has already been built */
@@ -1202,7 +1202,7 @@ isdn_net_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1202 if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) { 1202 if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) {
1203 isdn_net_unreachable(ndev, skb, "dial rejected: interface not in dialmode `auto'"); 1203 isdn_net_unreachable(ndev, skb, "dial rejected: interface not in dialmode `auto'");
1204 dev_kfree_skb(skb); 1204 dev_kfree_skb(skb);
1205 return 0; 1205 return NETDEV_TX_OK;
1206 } 1206 }
1207 if (lp->phone[1]) { 1207 if (lp->phone[1]) {
1208 ulong flags; 1208 ulong flags;
@@ -1215,7 +1215,7 @@ isdn_net_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1215 if(time_before(jiffies, lp->dialwait_timer)) { 1215 if(time_before(jiffies, lp->dialwait_timer)) {
1216 isdn_net_unreachable(ndev, skb, "dial rejected: retry-time not reached"); 1216 isdn_net_unreachable(ndev, skb, "dial rejected: retry-time not reached");
1217 dev_kfree_skb(skb); 1217 dev_kfree_skb(skb);
1218 return 0; 1218 return NETDEV_TX_OK;
1219 } else 1219 } else
1220 lp->dialwait_timer = 0; 1220 lp->dialwait_timer = 0;
1221 } 1221 }
@@ -1243,7 +1243,7 @@ isdn_net_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1243 isdn_net_unreachable(ndev, skb, 1243 isdn_net_unreachable(ndev, skb,
1244 "No channel"); 1244 "No channel");
1245 dev_kfree_skb(skb); 1245 dev_kfree_skb(skb);
1246 return 0; 1246 return NETDEV_TX_OK;
1247 } 1247 }
1248 /* Log packet, which triggered dialing */ 1248 /* Log packet, which triggered dialing */
1249 if (dev->net_verbose) 1249 if (dev->net_verbose)
@@ -1258,7 +1258,7 @@ isdn_net_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1258 dev_kfree_skb(skb); 1258 dev_kfree_skb(skb);
1259 isdn_net_unbind_channel(lp); 1259 isdn_net_unbind_channel(lp);
1260 spin_unlock_irqrestore(&dev->lock, flags); 1260 spin_unlock_irqrestore(&dev->lock, flags);
1261 return 0; /* STN (skb to nirvana) ;) */ 1261 return NETDEV_TX_OK; /* STN (skb to nirvana) ;) */
1262 } 1262 }
1263#ifdef CONFIG_IPPP_FILTER 1263#ifdef CONFIG_IPPP_FILTER
1264 if (isdn_ppp_autodial_filter(skb, lp)) { 1264 if (isdn_ppp_autodial_filter(skb, lp)) {
@@ -1267,7 +1267,7 @@ isdn_net_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1267 spin_unlock_irqrestore(&dev->lock, flags); 1267 spin_unlock_irqrestore(&dev->lock, flags);
1268 isdn_net_unreachable(ndev, skb, "dial rejected: packet filtered"); 1268 isdn_net_unreachable(ndev, skb, "dial rejected: packet filtered");
1269 dev_kfree_skb(skb); 1269 dev_kfree_skb(skb);
1270 return 0; 1270 return NETDEV_TX_OK;
1271 } 1271 }
1272#endif 1272#endif
1273 spin_unlock_irqrestore(&dev->lock, flags); 1273 spin_unlock_irqrestore(&dev->lock, flags);
@@ -1285,7 +1285,7 @@ isdn_net_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1285 isdn_net_unreachable(ndev, skb, 1285 isdn_net_unreachable(ndev, skb,
1286 "No phone number"); 1286 "No phone number");
1287 dev_kfree_skb(skb); 1287 dev_kfree_skb(skb);
1288 return 0; 1288 return NETDEV_TX_OK;
1289 } 1289 }
1290 } else { 1290 } else {
1291 /* Device is connected to an ISDN channel */ 1291 /* Device is connected to an ISDN channel */
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index aa30b5cb3513..2d14b64202a3 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -1223,7 +1223,7 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
1223 isdn_net_dev *nd; 1223 isdn_net_dev *nd;
1224 unsigned int proto = PPP_IP; /* 0x21 */ 1224 unsigned int proto = PPP_IP; /* 0x21 */
1225 struct ippp_struct *ipt,*ipts; 1225 struct ippp_struct *ipt,*ipts;
1226 int slot, retval = 0; 1226 int slot, retval = NETDEV_TX_OK;
1227 1227
1228 mlp = (isdn_net_local *) netdev_priv(netdev); 1228 mlp = (isdn_net_local *) netdev_priv(netdev);
1229 nd = mlp->netdev; /* get master lp */ 1229 nd = mlp->netdev; /* get master lp */
@@ -1240,7 +1240,7 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
1240 if (!(ipts->pppcfg & SC_ENABLE_IP)) { /* PPP connected ? */ 1240 if (!(ipts->pppcfg & SC_ENABLE_IP)) { /* PPP connected ? */
1241 if (ipts->debug & 0x1) 1241 if (ipts->debug & 0x1)
1242 printk(KERN_INFO "%s: IP frame delayed.\n", netdev->name); 1242 printk(KERN_INFO "%s: IP frame delayed.\n", netdev->name);
1243 retval = 1; 1243 retval = NETDEV_TX_BUSY;
1244 goto out; 1244 goto out;
1245 } 1245 }
1246 1246
@@ -1261,7 +1261,7 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
1261 lp = isdn_net_get_locked_lp(nd); 1261 lp = isdn_net_get_locked_lp(nd);
1262 if (!lp) { 1262 if (!lp) {
1263 printk(KERN_WARNING "%s: all channels busy - requeuing!\n", netdev->name); 1263 printk(KERN_WARNING "%s: all channels busy - requeuing!\n", netdev->name);
1264 retval = 1; 1264 retval = NETDEV_TX_BUSY;
1265 goto out; 1265 goto out;
1266 } 1266 }
1267 /* we have our lp locked from now on */ 1267 /* we have our lp locked from now on */
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 9b60b6b684d9..7c8e7122aaa9 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -75,6 +75,7 @@ config LEDS_ALIX2
75 depends on LEDS_CLASS && X86 && EXPERIMENTAL 75 depends on LEDS_CLASS && X86 && EXPERIMENTAL
76 help 76 help
77 This option enables support for the PCEngines ALIX.2 and ALIX.3 LEDs. 77 This option enables support for the PCEngines ALIX.2 and ALIX.3 LEDs.
78 You have to set leds-alix2.force=1 for boards with Award BIOS.
78 79
79config LEDS_H1940 80config LEDS_H1940
80 tristate "LED Support for iPAQ H1940 device" 81 tristate "LED Support for iPAQ H1940 device"
@@ -145,15 +146,16 @@ config LEDS_GPIO_OF
145 of_platform devices. For instance, LEDs which are listed in a "dts" 146 of_platform devices. For instance, LEDs which are listed in a "dts"
146 file. 147 file.
147 148
148config LEDS_LP5521 149config LEDS_LP3944
149 tristate "LED Support for the LP5521 LEDs" 150 tristate "LED Support for N.S. LP3944 (Fun Light) I2C chip"
150 depends on LEDS_CLASS && I2C 151 depends on LEDS_CLASS && I2C
151 help 152 help
152 If you say 'Y' here you get support for the National Semiconductor 153 This option enables support for LEDs connected to the National
153 LP5521 LED driver used in n8x0 boards. 154 Semiconductor LP3944 Lighting Management Unit (LMU) also known as
155 Fun Light Chip.
154 156
155 This driver can be built as a module by choosing 'M'. The module 157 To compile this driver as a module, choose M here: the
156 will be called leds-lp5521. 158 module will be called leds-lp3944.
157 159
158config LEDS_CLEVO_MAIL 160config LEDS_CLEVO_MAIL
159 tristate "Mail LED on Clevo notebook" 161 tristate "Mail LED on Clevo notebook"
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 2d41c4dcf92f..e8cdcf77a4c3 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o
20obj-$(CONFIG_LEDS_SUNFIRE) += leds-sunfire.o 20obj-$(CONFIG_LEDS_SUNFIRE) += leds-sunfire.o
21obj-$(CONFIG_LEDS_PCA9532) += leds-pca9532.o 21obj-$(CONFIG_LEDS_PCA9532) += leds-pca9532.o
22obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o 22obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
23obj-$(CONFIG_LEDS_LP3944) += leds-lp3944.o
23obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o 24obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
24obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o 25obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o
25obj-$(CONFIG_LEDS_FSG) += leds-fsg.o 26obj-$(CONFIG_LEDS_FSG) += leds-fsg.o
diff --git a/drivers/leds/leds-alix2.c b/drivers/leds/leds-alix2.c
index ddbd7730dfc8..731d4eef3425 100644
--- a/drivers/leds/leds-alix2.c
+++ b/drivers/leds/leds-alix2.c
@@ -14,7 +14,7 @@
14 14
15static int force = 0; 15static int force = 0;
16module_param(force, bool, 0444); 16module_param(force, bool, 0444);
17MODULE_PARM_DESC(force, "Assume system has ALIX.2 style LEDs"); 17MODULE_PARM_DESC(force, "Assume system has ALIX.2/ALIX.3 style LEDs");
18 18
19struct alix_led { 19struct alix_led {
20 struct led_classdev cdev; 20 struct led_classdev cdev;
@@ -155,6 +155,11 @@ static int __init alix_led_init(void)
155 goto out; 155 goto out;
156 } 156 }
157 157
158 /* enable output on GPIO for LED 1,2,3 */
159 outl(1 << 6, 0x6104);
160 outl(1 << 9, 0x6184);
161 outl(1 << 11, 0x6184);
162
158 pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0); 163 pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
159 if (!IS_ERR(pdev)) { 164 if (!IS_ERR(pdev)) {
160 ret = platform_driver_probe(&alix_led_driver, alix_led_probe); 165 ret = platform_driver_probe(&alix_led_driver, alix_led_probe);
diff --git a/drivers/leds/leds-bd2802.c b/drivers/leds/leds-bd2802.c
index 4149ecb3a9b2..779d7f262c04 100644
--- a/drivers/leds/leds-bd2802.c
+++ b/drivers/leds/leds-bd2802.c
@@ -97,6 +97,10 @@ struct bd2802_led {
97 enum led_ids led_id; 97 enum led_ids led_id;
98 enum led_colors color; 98 enum led_colors color;
99 enum led_bits state; 99 enum led_bits state;
100
101 /* General attributes of RGB LEDs */
102 int wave_pattern;
103 int rgb_current;
100}; 104};
101 105
102 106
@@ -254,7 +258,7 @@ static void bd2802_set_on(struct bd2802_led *led, enum led_ids id,
254 bd2802_reset_cancel(led); 258 bd2802_reset_cancel(led);
255 259
256 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT1SETUP); 260 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT1SETUP);
257 bd2802_write_byte(led->client, reg, BD2802_CURRENT_032); 261 bd2802_write_byte(led->client, reg, led->rgb_current);
258 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT2SETUP); 262 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT2SETUP);
259 bd2802_write_byte(led->client, reg, BD2802_CURRENT_000); 263 bd2802_write_byte(led->client, reg, BD2802_CURRENT_000);
260 reg = bd2802_get_reg_addr(id, color, BD2802_REG_WAVEPATTERN); 264 reg = bd2802_get_reg_addr(id, color, BD2802_REG_WAVEPATTERN);
@@ -275,9 +279,9 @@ static void bd2802_set_blink(struct bd2802_led *led, enum led_ids id,
275 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT1SETUP); 279 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT1SETUP);
276 bd2802_write_byte(led->client, reg, BD2802_CURRENT_000); 280 bd2802_write_byte(led->client, reg, BD2802_CURRENT_000);
277 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT2SETUP); 281 reg = bd2802_get_reg_addr(id, color, BD2802_REG_CURRENT2SETUP);
278 bd2802_write_byte(led->client, reg, BD2802_CURRENT_032); 282 bd2802_write_byte(led->client, reg, led->rgb_current);
279 reg = bd2802_get_reg_addr(id, color, BD2802_REG_WAVEPATTERN); 283 reg = bd2802_get_reg_addr(id, color, BD2802_REG_WAVEPATTERN);
280 bd2802_write_byte(led->client, reg, BD2802_PATTERN_HALF); 284 bd2802_write_byte(led->client, reg, led->wave_pattern);
281 285
282 bd2802_enable(led, id); 286 bd2802_enable(led, id);
283 bd2802_update_state(led, id, color, BD2802_BLINK); 287 bd2802_update_state(led, id, color, BD2802_BLINK);
@@ -406,7 +410,7 @@ static void bd2802_enable_adv_conf(struct bd2802_led *led)
406 ret = device_create_file(&led->client->dev, 410 ret = device_create_file(&led->client->dev,
407 bd2802_addr_attributes[i]); 411 bd2802_addr_attributes[i]);
408 if (ret) { 412 if (ret) {
409 dev_err(&led->client->dev, "failed to sysfs file %s\n", 413 dev_err(&led->client->dev, "failed: sysfs file %s\n",
410 bd2802_addr_attributes[i]->attr.name); 414 bd2802_addr_attributes[i]->attr.name);
411 goto failed_remove_files; 415 goto failed_remove_files;
412 } 416 }
@@ -483,6 +487,52 @@ static struct device_attribute bd2802_adv_conf_attr = {
483 .store = bd2802_store_adv_conf, 487 .store = bd2802_store_adv_conf,
484}; 488};
485 489
490#define BD2802_CONTROL_ATTR(attr_name, name_str) \
491static ssize_t bd2802_show_##attr_name(struct device *dev, \
492 struct device_attribute *attr, char *buf) \
493{ \
494 struct bd2802_led *led = i2c_get_clientdata(to_i2c_client(dev));\
495 ssize_t ret; \
496 down_read(&led->rwsem); \
497 ret = sprintf(buf, "0x%02x\n", led->attr_name); \
498 up_read(&led->rwsem); \
499 return ret; \
500} \
501static ssize_t bd2802_store_##attr_name(struct device *dev, \
502 struct device_attribute *attr, const char *buf, size_t count) \
503{ \
504 struct bd2802_led *led = i2c_get_clientdata(to_i2c_client(dev));\
505 unsigned long val; \
506 int ret; \
507 if (!count) \
508 return -EINVAL; \
509 ret = strict_strtoul(buf, 16, &val); \
510 if (ret) \
511 return ret; \
512 down_write(&led->rwsem); \
513 led->attr_name = val; \
514 up_write(&led->rwsem); \
515 return count; \
516} \
517static struct device_attribute bd2802_##attr_name##_attr = { \
518 .attr = { \
519 .name = name_str, \
520 .mode = 0644, \
521 .owner = THIS_MODULE \
522 }, \
523 .show = bd2802_show_##attr_name, \
524 .store = bd2802_store_##attr_name, \
525};
526
527BD2802_CONTROL_ATTR(wave_pattern, "wave_pattern");
528BD2802_CONTROL_ATTR(rgb_current, "rgb_current");
529
530static struct device_attribute *bd2802_attributes[] = {
531 &bd2802_adv_conf_attr,
532 &bd2802_wave_pattern_attr,
533 &bd2802_rgb_current_attr,
534};
535
486static void bd2802_led_work(struct work_struct *work) 536static void bd2802_led_work(struct work_struct *work)
487{ 537{
488 struct bd2802_led *led = container_of(work, struct bd2802_led, work); 538 struct bd2802_led *led = container_of(work, struct bd2802_led, work);
@@ -538,7 +588,6 @@ static int bd2802_register_led_classdev(struct bd2802_led *led)
538 led->cdev_led1r.brightness = LED_OFF; 588 led->cdev_led1r.brightness = LED_OFF;
539 led->cdev_led1r.brightness_set = bd2802_set_led1r_brightness; 589 led->cdev_led1r.brightness_set = bd2802_set_led1r_brightness;
540 led->cdev_led1r.blink_set = bd2802_set_led1r_blink; 590 led->cdev_led1r.blink_set = bd2802_set_led1r_blink;
541 led->cdev_led1r.flags |= LED_CORE_SUSPENDRESUME;
542 591
543 ret = led_classdev_register(&led->client->dev, &led->cdev_led1r); 592 ret = led_classdev_register(&led->client->dev, &led->cdev_led1r);
544 if (ret < 0) { 593 if (ret < 0) {
@@ -551,7 +600,6 @@ static int bd2802_register_led_classdev(struct bd2802_led *led)
551 led->cdev_led1g.brightness = LED_OFF; 600 led->cdev_led1g.brightness = LED_OFF;
552 led->cdev_led1g.brightness_set = bd2802_set_led1g_brightness; 601 led->cdev_led1g.brightness_set = bd2802_set_led1g_brightness;
553 led->cdev_led1g.blink_set = bd2802_set_led1g_blink; 602 led->cdev_led1g.blink_set = bd2802_set_led1g_blink;
554 led->cdev_led1g.flags |= LED_CORE_SUSPENDRESUME;
555 603
556 ret = led_classdev_register(&led->client->dev, &led->cdev_led1g); 604 ret = led_classdev_register(&led->client->dev, &led->cdev_led1g);
557 if (ret < 0) { 605 if (ret < 0) {
@@ -564,7 +612,6 @@ static int bd2802_register_led_classdev(struct bd2802_led *led)
564 led->cdev_led1b.brightness = LED_OFF; 612 led->cdev_led1b.brightness = LED_OFF;
565 led->cdev_led1b.brightness_set = bd2802_set_led1b_brightness; 613 led->cdev_led1b.brightness_set = bd2802_set_led1b_brightness;
566 led->cdev_led1b.blink_set = bd2802_set_led1b_blink; 614 led->cdev_led1b.blink_set = bd2802_set_led1b_blink;
567 led->cdev_led1b.flags |= LED_CORE_SUSPENDRESUME;
568 615
569 ret = led_classdev_register(&led->client->dev, &led->cdev_led1b); 616 ret = led_classdev_register(&led->client->dev, &led->cdev_led1b);
570 if (ret < 0) { 617 if (ret < 0) {
@@ -577,7 +624,6 @@ static int bd2802_register_led_classdev(struct bd2802_led *led)
577 led->cdev_led2r.brightness = LED_OFF; 624 led->cdev_led2r.brightness = LED_OFF;
578 led->cdev_led2r.brightness_set = bd2802_set_led2r_brightness; 625 led->cdev_led2r.brightness_set = bd2802_set_led2r_brightness;
579 led->cdev_led2r.blink_set = bd2802_set_led2r_blink; 626 led->cdev_led2r.blink_set = bd2802_set_led2r_blink;
580 led->cdev_led2r.flags |= LED_CORE_SUSPENDRESUME;
581 627
582 ret = led_classdev_register(&led->client->dev, &led->cdev_led2r); 628 ret = led_classdev_register(&led->client->dev, &led->cdev_led2r);
583 if (ret < 0) { 629 if (ret < 0) {
@@ -590,7 +636,6 @@ static int bd2802_register_led_classdev(struct bd2802_led *led)
590 led->cdev_led2g.brightness = LED_OFF; 636 led->cdev_led2g.brightness = LED_OFF;
591 led->cdev_led2g.brightness_set = bd2802_set_led2g_brightness; 637 led->cdev_led2g.brightness_set = bd2802_set_led2g_brightness;
592 led->cdev_led2g.blink_set = bd2802_set_led2g_blink; 638 led->cdev_led2g.blink_set = bd2802_set_led2g_blink;
593 led->cdev_led2g.flags |= LED_CORE_SUSPENDRESUME;
594 639
595 ret = led_classdev_register(&led->client->dev, &led->cdev_led2g); 640 ret = led_classdev_register(&led->client->dev, &led->cdev_led2g);
596 if (ret < 0) { 641 if (ret < 0) {
@@ -640,7 +685,7 @@ static int __devinit bd2802_probe(struct i2c_client *client,
640{ 685{
641 struct bd2802_led *led; 686 struct bd2802_led *led;
642 struct bd2802_led_platform_data *pdata; 687 struct bd2802_led_platform_data *pdata;
643 int ret; 688 int ret, i;
644 689
645 led = kzalloc(sizeof(struct bd2802_led), GFP_KERNEL); 690 led = kzalloc(sizeof(struct bd2802_led), GFP_KERNEL);
646 if (!led) { 691 if (!led) {
@@ -670,13 +715,20 @@ static int __devinit bd2802_probe(struct i2c_client *client,
670 /* To save the power, reset BD2802 after detecting */ 715 /* To save the power, reset BD2802 after detecting */
671 gpio_set_value(led->pdata->reset_gpio, 0); 716 gpio_set_value(led->pdata->reset_gpio, 0);
672 717
718 /* Default attributes */
719 led->wave_pattern = BD2802_PATTERN_HALF;
720 led->rgb_current = BD2802_CURRENT_032;
721
673 init_rwsem(&led->rwsem); 722 init_rwsem(&led->rwsem);
674 723
675 ret = device_create_file(&client->dev, &bd2802_adv_conf_attr); 724 for (i = 0; i < ARRAY_SIZE(bd2802_attributes); i++) {
676 if (ret) { 725 ret = device_create_file(&led->client->dev,
677 dev_err(&client->dev, "failed to create sysfs file %s\n", 726 bd2802_attributes[i]);
678 bd2802_adv_conf_attr.attr.name); 727 if (ret) {
679 goto failed_free; 728 dev_err(&led->client->dev, "failed: sysfs file %s\n",
729 bd2802_attributes[i]->attr.name);
730 goto failed_unregister_dev_file;
731 }
680 } 732 }
681 733
682 ret = bd2802_register_led_classdev(led); 734 ret = bd2802_register_led_classdev(led);
@@ -686,7 +738,8 @@ static int __devinit bd2802_probe(struct i2c_client *client,
686 return 0; 738 return 0;
687 739
688failed_unregister_dev_file: 740failed_unregister_dev_file:
689 device_remove_file(&client->dev, &bd2802_adv_conf_attr); 741 for (i--; i >= 0; i--)
742 device_remove_file(&led->client->dev, bd2802_attributes[i]);
690failed_free: 743failed_free:
691 i2c_set_clientdata(client, NULL); 744 i2c_set_clientdata(client, NULL);
692 kfree(led); 745 kfree(led);
@@ -697,12 +750,14 @@ failed_free:
697static int __exit bd2802_remove(struct i2c_client *client) 750static int __exit bd2802_remove(struct i2c_client *client)
698{ 751{
699 struct bd2802_led *led = i2c_get_clientdata(client); 752 struct bd2802_led *led = i2c_get_clientdata(client);
753 int i;
700 754
701 bd2802_unregister_led_classdev(led);
702 gpio_set_value(led->pdata->reset_gpio, 0); 755 gpio_set_value(led->pdata->reset_gpio, 0);
756 bd2802_unregister_led_classdev(led);
703 if (led->adf_on) 757 if (led->adf_on)
704 bd2802_disable_adv_conf(led); 758 bd2802_disable_adv_conf(led);
705 device_remove_file(&client->dev, &bd2802_adv_conf_attr); 759 for (i = 0; i < ARRAY_SIZE(bd2802_attributes); i++)
760 device_remove_file(&led->client->dev, bd2802_attributes[i]);
706 i2c_set_clientdata(client, NULL); 761 i2c_set_clientdata(client, NULL);
707 kfree(led); 762 kfree(led);
708 763
@@ -723,8 +778,7 @@ static int bd2802_resume(struct i2c_client *client)
723 struct bd2802_led *led = i2c_get_clientdata(client); 778 struct bd2802_led *led = i2c_get_clientdata(client);
724 779
725 if (!bd2802_is_all_off(led) || led->adf_on) { 780 if (!bd2802_is_all_off(led) || led->adf_on) {
726 gpio_set_value(led->pdata->reset_gpio, 1); 781 bd2802_reset_cancel(led);
727 udelay(100);
728 bd2802_restore_state(led); 782 bd2802_restore_state(led);
729 } 783 }
730 784
@@ -762,4 +816,4 @@ module_exit(bd2802_exit);
762 816
763MODULE_AUTHOR("Kim Kyuwon <q1.kim@samsung.com>"); 817MODULE_AUTHOR("Kim Kyuwon <q1.kim@samsung.com>");
764MODULE_DESCRIPTION("BD2802 LED driver"); 818MODULE_DESCRIPTION("BD2802 LED driver");
765MODULE_LICENSE("GPL"); 819MODULE_LICENSE("GPL v2");
diff --git a/drivers/leds/leds-cobalt-raq.c b/drivers/leds/leds-cobalt-raq.c
index ff0e8c3fbf9b..5f1ce810815f 100644
--- a/drivers/leds/leds-cobalt-raq.c
+++ b/drivers/leds/leds-cobalt-raq.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * LEDs driver for the Cobalt Raq series. 2 * LEDs driver for the Cobalt Raq series.
3 * 3 *
4 * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index d2109054de85..6b06638eb5b4 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -76,7 +76,7 @@ static int __devinit create_gpio_led(const struct gpio_led *template,
76 struct gpio_led_data *led_dat, struct device *parent, 76 struct gpio_led_data *led_dat, struct device *parent,
77 int (*blink_set)(unsigned, unsigned long *, unsigned long *)) 77 int (*blink_set)(unsigned, unsigned long *, unsigned long *))
78{ 78{
79 int ret; 79 int ret, state;
80 80
81 /* skip leds that aren't available */ 81 /* skip leds that aren't available */
82 if (!gpio_is_valid(template->gpio)) { 82 if (!gpio_is_valid(template->gpio)) {
@@ -99,11 +99,15 @@ static int __devinit create_gpio_led(const struct gpio_led *template,
99 led_dat->cdev.blink_set = gpio_blink_set; 99 led_dat->cdev.blink_set = gpio_blink_set;
100 } 100 }
101 led_dat->cdev.brightness_set = gpio_led_set; 101 led_dat->cdev.brightness_set = gpio_led_set;
102 led_dat->cdev.brightness = LED_OFF; 102 if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP)
103 state = !!gpio_get_value(led_dat->gpio) ^ led_dat->active_low;
104 else
105 state = (template->default_state == LEDS_GPIO_DEFSTATE_ON);
106 led_dat->cdev.brightness = state ? LED_FULL : LED_OFF;
103 if (!template->retain_state_suspended) 107 if (!template->retain_state_suspended)
104 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; 108 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
105 109
106 ret = gpio_direction_output(led_dat->gpio, led_dat->active_low); 110 ret = gpio_direction_output(led_dat->gpio, led_dat->active_low ^ state);
107 if (ret < 0) 111 if (ret < 0)
108 goto err; 112 goto err;
109 113
@@ -129,7 +133,7 @@ static void delete_gpio_led(struct gpio_led_data *led)
129} 133}
130 134
131#ifdef CONFIG_LEDS_GPIO_PLATFORM 135#ifdef CONFIG_LEDS_GPIO_PLATFORM
132static int gpio_led_probe(struct platform_device *pdev) 136static int __devinit gpio_led_probe(struct platform_device *pdev)
133{ 137{
134 struct gpio_led_platform_data *pdata = pdev->dev.platform_data; 138 struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
135 struct gpio_led_data *leds_data; 139 struct gpio_led_data *leds_data;
@@ -223,12 +227,22 @@ static int __devinit of_gpio_leds_probe(struct of_device *ofdev,
223 memset(&led, 0, sizeof(led)); 227 memset(&led, 0, sizeof(led));
224 for_each_child_of_node(np, child) { 228 for_each_child_of_node(np, child) {
225 enum of_gpio_flags flags; 229 enum of_gpio_flags flags;
230 const char *state;
226 231
227 led.gpio = of_get_gpio_flags(child, 0, &flags); 232 led.gpio = of_get_gpio_flags(child, 0, &flags);
228 led.active_low = flags & OF_GPIO_ACTIVE_LOW; 233 led.active_low = flags & OF_GPIO_ACTIVE_LOW;
229 led.name = of_get_property(child, "label", NULL) ? : child->name; 234 led.name = of_get_property(child, "label", NULL) ? : child->name;
230 led.default_trigger = 235 led.default_trigger =
231 of_get_property(child, "linux,default-trigger", NULL); 236 of_get_property(child, "linux,default-trigger", NULL);
237 state = of_get_property(child, "default-state", NULL);
238 if (state) {
239 if (!strcmp(state, "keep"))
240 led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
241 else if(!strcmp(state, "on"))
242 led.default_state = LEDS_GPIO_DEFSTATE_ON;
243 else
244 led.default_state = LEDS_GPIO_DEFSTATE_OFF;
245 }
232 246
233 ret = create_gpio_led(&led, &pdata->led_data[pdata->num_leds++], 247 ret = create_gpio_led(&led, &pdata->led_data[pdata->num_leds++],
234 &ofdev->dev, NULL); 248 &ofdev->dev, NULL);
diff --git a/drivers/leds/leds-lp3944.c b/drivers/leds/leds-lp3944.c
new file mode 100644
index 000000000000..5946208ba26e
--- /dev/null
+++ b/drivers/leds/leds-lp3944.c
@@ -0,0 +1,466 @@
1/*
2 * leds-lp3944.c - driver for National Semiconductor LP3944 Funlight Chip
3 *
4 * Copyright (C) 2009 Antonio Ospite <ospite@studenti.unina.it>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12/*
13 * I2C driver for National Semiconductor LP3944 Funlight Chip
14 * http://www.national.com/pf/LP/LP3944.html
15 *
16 * This helper chip can drive up to 8 leds, with two programmable DIM modes;
17 * it could even be used as a gpio expander but this driver assumes it is used
18 * as a led controller.
19 *
20 * The DIM modes are used to set _blink_ patterns for leds, the pattern is
21 * specified supplying two parameters:
22 * - period: from 0s to 1.6s
23 * - duty cycle: percentage of the period the led is on, from 0 to 100
24 *
25 * LP3944 can be found on Motorola A910 smartphone, where it drives the rgb
26 * leds, the camera flash light and the displays backlights.
27 */
28
29#include <linux/module.h>
30#include <linux/i2c.h>
31#include <linux/leds.h>
32#include <linux/mutex.h>
33#include <linux/workqueue.h>
34#include <linux/leds-lp3944.h>
35
36/* Read Only Registers */
37#define LP3944_REG_INPUT1 0x00 /* LEDs 0-7 InputRegister (Read Only) */
38#define LP3944_REG_REGISTER1 0x01 /* None (Read Only) */
39
40#define LP3944_REG_PSC0 0x02 /* Frequency Prescaler 0 (R/W) */
41#define LP3944_REG_PWM0 0x03 /* PWM Register 0 (R/W) */
42#define LP3944_REG_PSC1 0x04 /* Frequency Prescaler 1 (R/W) */
43#define LP3944_REG_PWM1 0x05 /* PWM Register 1 (R/W) */
44#define LP3944_REG_LS0 0x06 /* LEDs 0-3 Selector (R/W) */
45#define LP3944_REG_LS1 0x07 /* LEDs 4-7 Selector (R/W) */
46
47/* These registers are not used to control leds in LP3944, they can store
48 * arbitrary values which the chip will ignore.
49 */
50#define LP3944_REG_REGISTER8 0x08
51#define LP3944_REG_REGISTER9 0x09
52
53#define LP3944_DIM0 0
54#define LP3944_DIM1 1
55
56/* period in ms */
57#define LP3944_PERIOD_MIN 0
58#define LP3944_PERIOD_MAX 1600
59
60/* duty cycle is a percentage */
61#define LP3944_DUTY_CYCLE_MIN 0
62#define LP3944_DUTY_CYCLE_MAX 100
63
64#define ldev_to_led(c) container_of(c, struct lp3944_led_data, ldev)
65
66/* Saved data */
67struct lp3944_led_data {
68 u8 id;
69 enum lp3944_type type;
70 enum lp3944_status status;
71 struct led_classdev ldev;
72 struct i2c_client *client;
73 struct work_struct work;
74};
75
76struct lp3944_data {
77 struct mutex lock;
78 struct i2c_client *client;
79 struct lp3944_led_data leds[LP3944_LEDS_MAX];
80};
81
82static int lp3944_reg_read(struct i2c_client *client, u8 reg, u8 *value)
83{
84 int tmp;
85
86 tmp = i2c_smbus_read_byte_data(client, reg);
87 if (tmp < 0)
88 return -EINVAL;
89
90 *value = tmp;
91
92 return 0;
93}
94
95static int lp3944_reg_write(struct i2c_client *client, u8 reg, u8 value)
96{
97 return i2c_smbus_write_byte_data(client, reg, value);
98}
99
100/**
101 * Set the period for DIM status
102 *
103 * @client: the i2c client
104 * @dim: either LP3944_DIM0 or LP3944_DIM1
105 * @period: period of a blink, that is a on/off cycle, expressed in ms.
106 */
107static int lp3944_dim_set_period(struct i2c_client *client, u8 dim, u16 period)
108{
109 u8 psc_reg;
110 u8 psc_value;
111 int err;
112
113 if (dim == LP3944_DIM0)
114 psc_reg = LP3944_REG_PSC0;
115 else if (dim == LP3944_DIM1)
116 psc_reg = LP3944_REG_PSC1;
117 else
118 return -EINVAL;
119
120 /* Convert period to Prescaler value */
121 if (period > LP3944_PERIOD_MAX)
122 return -EINVAL;
123
124 psc_value = (period * 255) / LP3944_PERIOD_MAX;
125
126 err = lp3944_reg_write(client, psc_reg, psc_value);
127
128 return err;
129}
130
131/**
132 * Set the duty cycle for DIM status
133 *
134 * @client: the i2c client
135 * @dim: either LP3944_DIM0 or LP3944_DIM1
136 * @duty_cycle: percentage of a period during which a led is ON
137 */
138static int lp3944_dim_set_dutycycle(struct i2c_client *client, u8 dim,
139 u8 duty_cycle)
140{
141 u8 pwm_reg;
142 u8 pwm_value;
143 int err;
144
145 if (dim == LP3944_DIM0)
146 pwm_reg = LP3944_REG_PWM0;
147 else if (dim == LP3944_DIM1)
148 pwm_reg = LP3944_REG_PWM1;
149 else
150 return -EINVAL;
151
152 /* Convert duty cycle to PWM value */
153 if (duty_cycle > LP3944_DUTY_CYCLE_MAX)
154 return -EINVAL;
155
156 pwm_value = (duty_cycle * 255) / LP3944_DUTY_CYCLE_MAX;
157
158 err = lp3944_reg_write(client, pwm_reg, pwm_value);
159
160 return err;
161}
162
163/**
164 * Set the led status
165 *
166 * @led: a lp3944_led_data structure
167 * @status: one of LP3944_LED_STATUS_OFF
168 * LP3944_LED_STATUS_ON
169 * LP3944_LED_STATUS_DIM0
170 * LP3944_LED_STATUS_DIM1
171 */
172static int lp3944_led_set(struct lp3944_led_data *led, u8 status)
173{
174 struct lp3944_data *data = i2c_get_clientdata(led->client);
175 u8 id = led->id;
176 u8 reg;
177 u8 val = 0;
178 int err;
179
180 dev_dbg(&led->client->dev, "%s: %s, status before normalization:%d\n",
181 __func__, led->ldev.name, status);
182
183 switch (id) {
184 case LP3944_LED0:
185 case LP3944_LED1:
186 case LP3944_LED2:
187 case LP3944_LED3:
188 reg = LP3944_REG_LS0;
189 break;
190 case LP3944_LED4:
191 case LP3944_LED5:
192 case LP3944_LED6:
193 case LP3944_LED7:
194 id -= LP3944_LED4;
195 reg = LP3944_REG_LS1;
196 break;
197 default:
198 return -EINVAL;
199 }
200
201 if (status > LP3944_LED_STATUS_DIM1)
202 return -EINVAL;
203
204 /* invert only 0 and 1, leave unchanged the other values,
205 * remember we are abusing status to set blink patterns
206 */
207 if (led->type == LP3944_LED_TYPE_LED_INVERTED && status < 2)
208 status = 1 - status;
209
210 mutex_lock(&data->lock);
211 lp3944_reg_read(led->client, reg, &val);
212
213 val &= ~(LP3944_LED_STATUS_MASK << (id << 1));
214 val |= (status << (id << 1));
215
216 dev_dbg(&led->client->dev, "%s: %s, reg:%d id:%d status:%d val:%#x\n",
217 __func__, led->ldev.name, reg, id, status, val);
218
219 /* set led status */
220 err = lp3944_reg_write(led->client, reg, val);
221 mutex_unlock(&data->lock);
222
223 return err;
224}
225
226static int lp3944_led_set_blink(struct led_classdev *led_cdev,
227 unsigned long *delay_on,
228 unsigned long *delay_off)
229{
230 struct lp3944_led_data *led = ldev_to_led(led_cdev);
231 u16 period;
232 u8 duty_cycle;
233 int err;
234
235 /* units are in ms */
236 if (*delay_on + *delay_off > LP3944_PERIOD_MAX)
237 return -EINVAL;
238
239 if (*delay_on == 0 && *delay_off == 0) {
240 /* Special case: the leds subsystem requires a default user
241 * friendly blink pattern for the LED. Let's blink the led
242 * slowly (1Hz).
243 */
244 *delay_on = 500;
245 *delay_off = 500;
246 }
247
248 period = (*delay_on) + (*delay_off);
249
250 /* duty_cycle is the percentage of period during which the led is ON */
251 duty_cycle = 100 * (*delay_on) / period;
252
253 /* invert duty cycle for inverted leds, this has the same effect of
254 * swapping delay_on and delay_off
255 */
256 if (led->type == LP3944_LED_TYPE_LED_INVERTED)
257 duty_cycle = 100 - duty_cycle;
258
259 /* NOTE: using always the first DIM mode, this means that all leds
260 * will have the same blinking pattern.
261 *
262 * We could find a way later to have two leds blinking in hardware
263 * with different patterns at the same time, falling back to software
264 * control for the other ones.
265 */
266 err = lp3944_dim_set_period(led->client, LP3944_DIM0, period);
267 if (err)
268 return err;
269
270 err = lp3944_dim_set_dutycycle(led->client, LP3944_DIM0, duty_cycle);
271 if (err)
272 return err;
273
274 dev_dbg(&led->client->dev, "%s: OK hardware accelerated blink!\n",
275 __func__);
276
277 led->status = LP3944_LED_STATUS_DIM0;
278 schedule_work(&led->work);
279
280 return 0;
281}
282
283static void lp3944_led_set_brightness(struct led_classdev *led_cdev,
284 enum led_brightness brightness)
285{
286 struct lp3944_led_data *led = ldev_to_led(led_cdev);
287
288 dev_dbg(&led->client->dev, "%s: %s, %d\n",
289 __func__, led_cdev->name, brightness);
290
291 led->status = brightness;
292 schedule_work(&led->work);
293}
294
295static void lp3944_led_work(struct work_struct *work)
296{
297 struct lp3944_led_data *led;
298
299 led = container_of(work, struct lp3944_led_data, work);
300 lp3944_led_set(led, led->status);
301}
302
303static int lp3944_configure(struct i2c_client *client,
304 struct lp3944_data *data,
305 struct lp3944_platform_data *pdata)
306{
307 int i, err = 0;
308
309 for (i = 0; i < pdata->leds_size; i++) {
310 struct lp3944_led *pled = &pdata->leds[i];
311 struct lp3944_led_data *led = &data->leds[i];
312 led->client = client;
313 led->id = i;
314
315 switch (pled->type) {
316
317 case LP3944_LED_TYPE_LED:
318 case LP3944_LED_TYPE_LED_INVERTED:
319 led->type = pled->type;
320 led->status = pled->status;
321 led->ldev.name = pled->name;
322 led->ldev.max_brightness = 1;
323 led->ldev.brightness_set = lp3944_led_set_brightness;
324 led->ldev.blink_set = lp3944_led_set_blink;
325 led->ldev.flags = LED_CORE_SUSPENDRESUME;
326
327 INIT_WORK(&led->work, lp3944_led_work);
328 err = led_classdev_register(&client->dev, &led->ldev);
329 if (err < 0) {
330 dev_err(&client->dev,
331 "couldn't register LED %s\n",
332 led->ldev.name);
333 goto exit;
334 }
335
336 /* to expose the default value to userspace */
337 led->ldev.brightness = led->status;
338
339 /* Set the default led status */
340 err = lp3944_led_set(led, led->status);
341 if (err < 0) {
342 dev_err(&client->dev,
343 "%s couldn't set STATUS %d\n",
344 led->ldev.name, led->status);
345 goto exit;
346 }
347 break;
348
349 case LP3944_LED_TYPE_NONE:
350 default:
351 break;
352
353 }
354 }
355 return 0;
356
357exit:
358 if (i > 0)
359 for (i = i - 1; i >= 0; i--)
360 switch (pdata->leds[i].type) {
361
362 case LP3944_LED_TYPE_LED:
363 case LP3944_LED_TYPE_LED_INVERTED:
364 led_classdev_unregister(&data->leds[i].ldev);
365 cancel_work_sync(&data->leds[i].work);
366 break;
367
368 case LP3944_LED_TYPE_NONE:
369 default:
370 break;
371 }
372
373 return err;
374}
375
376static int __devinit lp3944_probe(struct i2c_client *client,
377 const struct i2c_device_id *id)
378{
379 struct lp3944_platform_data *lp3944_pdata = client->dev.platform_data;
380 struct lp3944_data *data;
381
382 if (lp3944_pdata == NULL) {
383 dev_err(&client->dev, "no platform data\n");
384 return -EINVAL;
385 }
386
387 /* Let's see whether this adapter can support what we need. */
388 if (!i2c_check_functionality(client->adapter,
389 I2C_FUNC_SMBUS_BYTE_DATA)) {
390 dev_err(&client->dev, "insufficient functionality!\n");
391 return -ENODEV;
392 }
393
394 data = kzalloc(sizeof(struct lp3944_data), GFP_KERNEL);
395 if (!data)
396 return -ENOMEM;
397
398 data->client = client;
399 i2c_set_clientdata(client, data);
400
401 mutex_init(&data->lock);
402
403 dev_info(&client->dev, "lp3944 enabled\n");
404
405 lp3944_configure(client, data, lp3944_pdata);
406 return 0;
407}
408
409static int __devexit lp3944_remove(struct i2c_client *client)
410{
411 struct lp3944_platform_data *pdata = client->dev.platform_data;
412 struct lp3944_data *data = i2c_get_clientdata(client);
413 int i;
414
415 for (i = 0; i < pdata->leds_size; i++)
416 switch (data->leds[i].type) {
417 case LP3944_LED_TYPE_LED:
418 case LP3944_LED_TYPE_LED_INVERTED:
419 led_classdev_unregister(&data->leds[i].ldev);
420 cancel_work_sync(&data->leds[i].work);
421 break;
422
423 case LP3944_LED_TYPE_NONE:
424 default:
425 break;
426 }
427
428 kfree(data);
429 i2c_set_clientdata(client, NULL);
430
431 return 0;
432}
433
434/* lp3944 i2c driver struct */
435static const struct i2c_device_id lp3944_id[] = {
436 {"lp3944", 0},
437 {}
438};
439
440MODULE_DEVICE_TABLE(i2c, lp3944_id);
441
442static struct i2c_driver lp3944_driver = {
443 .driver = {
444 .name = "lp3944",
445 },
446 .probe = lp3944_probe,
447 .remove = __devexit_p(lp3944_remove),
448 .id_table = lp3944_id,
449};
450
451static int __init lp3944_module_init(void)
452{
453 return i2c_add_driver(&lp3944_driver);
454}
455
456static void __exit lp3944_module_exit(void)
457{
458 i2c_del_driver(&lp3944_driver);
459}
460
461module_init(lp3944_module_init);
462module_exit(lp3944_module_exit);
463
464MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
465MODULE_DESCRIPTION("LP3944 Fun Light Chip");
466MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index 3937244fdcab..dba8921240f2 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -35,7 +35,7 @@ struct pca9532_data {
35 struct pca9532_led leds[16]; 35 struct pca9532_led leds[16];
36 struct mutex update_lock; 36 struct mutex update_lock;
37 struct input_dev *idev; 37 struct input_dev *idev;
38 struct work_struct work; 38 struct work_struct work;
39 u8 pwm[2]; 39 u8 pwm[2];
40 u8 psc[2]; 40 u8 psc[2];
41}; 41};
@@ -87,14 +87,14 @@ static int pca9532_calcpwm(struct i2c_client *client, int pwm, int blink,
87 if (b > 0xFF) 87 if (b > 0xFF)
88 return -EINVAL; 88 return -EINVAL;
89 data->pwm[pwm] = b; 89 data->pwm[pwm] = b;
90 data->psc[pwm] = blink; 90 data->psc[pwm] = blink;
91 return 0; 91 return 0;
92} 92}
93 93
94static int pca9532_setpwm(struct i2c_client *client, int pwm) 94static int pca9532_setpwm(struct i2c_client *client, int pwm)
95{ 95{
96 struct pca9532_data *data = i2c_get_clientdata(client); 96 struct pca9532_data *data = i2c_get_clientdata(client);
97 mutex_lock(&data->update_lock); 97 mutex_lock(&data->update_lock);
98 i2c_smbus_write_byte_data(client, PCA9532_REG_PWM(pwm), 98 i2c_smbus_write_byte_data(client, PCA9532_REG_PWM(pwm),
99 data->pwm[pwm]); 99 data->pwm[pwm]);
100 i2c_smbus_write_byte_data(client, PCA9532_REG_PSC(pwm), 100 i2c_smbus_write_byte_data(client, PCA9532_REG_PSC(pwm),
@@ -132,11 +132,11 @@ static void pca9532_set_brightness(struct led_classdev *led_cdev,
132 led->state = PCA9532_ON; 132 led->state = PCA9532_ON;
133 else { 133 else {
134 led->state = PCA9532_PWM0; /* Thecus: hardcode one pwm */ 134 led->state = PCA9532_PWM0; /* Thecus: hardcode one pwm */
135 err = pca9532_calcpwm(led->client, 0, 0, value); 135 err = pca9532_calcpwm(led->client, 0, 0, value);
136 if (err) 136 if (err)
137 return; /* XXX: led api doesn't allow error code? */ 137 return; /* XXX: led api doesn't allow error code? */
138 } 138 }
139 schedule_work(&led->work); 139 schedule_work(&led->work);
140} 140}
141 141
142static int pca9532_set_blink(struct led_classdev *led_cdev, 142static int pca9532_set_blink(struct led_classdev *led_cdev,
@@ -145,7 +145,7 @@ static int pca9532_set_blink(struct led_classdev *led_cdev,
145 struct pca9532_led *led = ldev_to_led(led_cdev); 145 struct pca9532_led *led = ldev_to_led(led_cdev);
146 struct i2c_client *client = led->client; 146 struct i2c_client *client = led->client;
147 int psc; 147 int psc;
148 int err = 0; 148 int err = 0;
149 149
150 if (*delay_on == 0 && *delay_off == 0) { 150 if (*delay_on == 0 && *delay_off == 0) {
151 /* led subsystem ask us for a blink rate */ 151 /* led subsystem ask us for a blink rate */
@@ -157,11 +157,11 @@ static int pca9532_set_blink(struct led_classdev *led_cdev,
157 157
158 /* Thecus specific: only use PSC/PWM 0 */ 158 /* Thecus specific: only use PSC/PWM 0 */
159 psc = (*delay_on * 152-1)/1000; 159 psc = (*delay_on * 152-1)/1000;
160 err = pca9532_calcpwm(client, 0, psc, led_cdev->brightness); 160 err = pca9532_calcpwm(client, 0, psc, led_cdev->brightness);
161 if (err) 161 if (err)
162 return err; 162 return err;
163 schedule_work(&led->work); 163 schedule_work(&led->work);
164 return 0; 164 return 0;
165} 165}
166 166
167static int pca9532_event(struct input_dev *dev, unsigned int type, 167static int pca9532_event(struct input_dev *dev, unsigned int type,
@@ -178,15 +178,15 @@ static int pca9532_event(struct input_dev *dev, unsigned int type,
178 else 178 else
179 data->pwm[1] = 0; 179 data->pwm[1] = 0;
180 180
181 schedule_work(&data->work); 181 schedule_work(&data->work);
182 182
183 return 0; 183 return 0;
184} 184}
185 185
186static void pca9532_input_work(struct work_struct *work) 186static void pca9532_input_work(struct work_struct *work)
187{ 187{
188 struct pca9532_data *data; 188 struct pca9532_data *data;
189 data = container_of(work, struct pca9532_data, work); 189 data = container_of(work, struct pca9532_data, work);
190 mutex_lock(&data->update_lock); 190 mutex_lock(&data->update_lock);
191 i2c_smbus_write_byte_data(data->client, PCA9532_REG_PWM(1), 191 i2c_smbus_write_byte_data(data->client, PCA9532_REG_PWM(1),
192 data->pwm[1]); 192 data->pwm[1]);
@@ -195,11 +195,11 @@ static void pca9532_input_work(struct work_struct *work)
195 195
196static void pca9532_led_work(struct work_struct *work) 196static void pca9532_led_work(struct work_struct *work)
197{ 197{
198 struct pca9532_led *led; 198 struct pca9532_led *led;
199 led = container_of(work, struct pca9532_led, work); 199 led = container_of(work, struct pca9532_led, work);
200 if (led->state == PCA9532_PWM0) 200 if (led->state == PCA9532_PWM0)
201 pca9532_setpwm(led->client, 0); 201 pca9532_setpwm(led->client, 0);
202 pca9532_setled(led); 202 pca9532_setled(led);
203} 203}
204 204
205static int pca9532_configure(struct i2c_client *client, 205static int pca9532_configure(struct i2c_client *client,
@@ -232,7 +232,7 @@ static int pca9532_configure(struct i2c_client *client,
232 led->ldev.brightness = LED_OFF; 232 led->ldev.brightness = LED_OFF;
233 led->ldev.brightness_set = pca9532_set_brightness; 233 led->ldev.brightness_set = pca9532_set_brightness;
234 led->ldev.blink_set = pca9532_set_blink; 234 led->ldev.blink_set = pca9532_set_blink;
235 INIT_WORK(&led->work, pca9532_led_work); 235 INIT_WORK(&led->work, pca9532_led_work);
236 err = led_classdev_register(&client->dev, &led->ldev); 236 err = led_classdev_register(&client->dev, &led->ldev);
237 if (err < 0) { 237 if (err < 0) {
238 dev_err(&client->dev, 238 dev_err(&client->dev,
@@ -262,11 +262,11 @@ static int pca9532_configure(struct i2c_client *client,
262 BIT_MASK(SND_TONE); 262 BIT_MASK(SND_TONE);
263 data->idev->event = pca9532_event; 263 data->idev->event = pca9532_event;
264 input_set_drvdata(data->idev, data); 264 input_set_drvdata(data->idev, data);
265 INIT_WORK(&data->work, pca9532_input_work); 265 INIT_WORK(&data->work, pca9532_input_work);
266 err = input_register_device(data->idev); 266 err = input_register_device(data->idev);
267 if (err) { 267 if (err) {
268 input_free_device(data->idev); 268 input_free_device(data->idev);
269 cancel_work_sync(&data->work); 269 cancel_work_sync(&data->work);
270 data->idev = NULL; 270 data->idev = NULL;
271 goto exit; 271 goto exit;
272 } 272 }
@@ -283,13 +283,13 @@ exit:
283 break; 283 break;
284 case PCA9532_TYPE_LED: 284 case PCA9532_TYPE_LED:
285 led_classdev_unregister(&data->leds[i].ldev); 285 led_classdev_unregister(&data->leds[i].ldev);
286 cancel_work_sync(&data->leds[i].work); 286 cancel_work_sync(&data->leds[i].work);
287 break; 287 break;
288 case PCA9532_TYPE_N2100_BEEP: 288 case PCA9532_TYPE_N2100_BEEP:
289 if (data->idev != NULL) { 289 if (data->idev != NULL) {
290 input_unregister_device(data->idev); 290 input_unregister_device(data->idev);
291 input_free_device(data->idev); 291 input_free_device(data->idev);
292 cancel_work_sync(&data->work); 292 cancel_work_sync(&data->work);
293 data->idev = NULL; 293 data->idev = NULL;
294 } 294 }
295 break; 295 break;
@@ -340,13 +340,13 @@ static int pca9532_remove(struct i2c_client *client)
340 break; 340 break;
341 case PCA9532_TYPE_LED: 341 case PCA9532_TYPE_LED:
342 led_classdev_unregister(&data->leds[i].ldev); 342 led_classdev_unregister(&data->leds[i].ldev);
343 cancel_work_sync(&data->leds[i].work); 343 cancel_work_sync(&data->leds[i].work);
344 break; 344 break;
345 case PCA9532_TYPE_N2100_BEEP: 345 case PCA9532_TYPE_N2100_BEEP:
346 if (data->idev != NULL) { 346 if (data->idev != NULL) {
347 input_unregister_device(data->idev); 347 input_unregister_device(data->idev);
348 input_free_device(data->idev); 348 input_free_device(data->idev);
349 cancel_work_sync(&data->work); 349 cancel_work_sync(&data->work);
350 data->idev = NULL; 350 data->idev = NULL;
351 } 351 }
352 break; 352 break;
diff --git a/drivers/lguest/lg.h b/drivers/lguest/lg.h
index d4e8979735cb..9c3138265f8e 100644
--- a/drivers/lguest/lg.h
+++ b/drivers/lguest/lg.h
@@ -82,7 +82,7 @@ struct lg_cpu {
82 82
83struct lg_eventfd { 83struct lg_eventfd {
84 unsigned long addr; 84 unsigned long addr;
85 struct file *event; 85 struct eventfd_ctx *event;
86}; 86};
87 87
88struct lg_eventfd_map { 88struct lg_eventfd_map {
diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
index 32e297121058..9f9a2953b383 100644
--- a/drivers/lguest/lguest_user.c
+++ b/drivers/lguest/lguest_user.c
@@ -50,7 +50,7 @@ static int add_eventfd(struct lguest *lg, unsigned long addr, int fd)
50 50
51 /* Now append new entry. */ 51 /* Now append new entry. */
52 new->map[new->num].addr = addr; 52 new->map[new->num].addr = addr;
53 new->map[new->num].event = eventfd_fget(fd); 53 new->map[new->num].event = eventfd_ctx_fdget(fd);
54 if (IS_ERR(new->map[new->num].event)) { 54 if (IS_ERR(new->map[new->num].event)) {
55 kfree(new); 55 kfree(new);
56 return PTR_ERR(new->map[new->num].event); 56 return PTR_ERR(new->map[new->num].event);
@@ -357,7 +357,7 @@ static int close(struct inode *inode, struct file *file)
357 357
358 /* Release any eventfds they registered. */ 358 /* Release any eventfds they registered. */
359 for (i = 0; i < lg->eventfds->num; i++) 359 for (i = 0; i < lg->eventfds->num; i++)
360 fput(lg->eventfds->map[i].event); 360 eventfd_ctx_put(lg->eventfds->map[i].event);
361 kfree(lg->eventfds); 361 kfree(lg->eventfds);
362 362
363 /* If lg->dead doesn't contain an error code it will be NULL or a 363 /* If lg->dead doesn't contain an error code it will be NULL or a
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index 6e149f4a1fff..a0f68386c12f 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -378,6 +378,17 @@ static struct macio_dev * macio_add_one_device(struct macio_chip *chip,
378 dev->ofdev.dev.bus = &macio_bus_type; 378 dev->ofdev.dev.bus = &macio_bus_type;
379 dev->ofdev.dev.release = macio_release_dev; 379 dev->ofdev.dev.release = macio_release_dev;
380 380
381#ifdef CONFIG_PCI
382 /* Set the DMA ops to the ones from the PCI device, this could be
383 * fishy if we didn't know that on PowerMac it's always direct ops
384 * or iommu ops that will work fine
385 */
386 dev->ofdev.dev.archdata.dma_ops =
387 chip->lbus.pdev->dev.archdata.dma_ops;
388 dev->ofdev.dev.archdata.dma_data =
389 chip->lbus.pdev->dev.archdata.dma_data;
390#endif /* CONFIG_PCI */
391
381#ifdef DEBUG 392#ifdef DEBUG
382 printk("preparing mdev @%p, ofdev @%p, dev @%p, kobj @%p\n", 393 printk("preparing mdev @%p, ofdev @%p, dev @%p, kobj @%p\n",
383 dev, &dev->ofdev, &dev->ofdev.dev, &dev->ofdev.dev.kobj); 394 dev, &dev->ofdev, &dev->ofdev.dev, &dev->ofdev.dev.kobj);
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index c3ae51584b12..3710ff88fc10 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -195,7 +195,7 @@ int dm_exception_store_create(struct dm_target *ti, int argc, char **argv,
195 struct dm_exception_store **store) 195 struct dm_exception_store **store)
196{ 196{
197 int r = 0; 197 int r = 0;
198 struct dm_exception_store_type *type; 198 struct dm_exception_store_type *type = NULL;
199 struct dm_exception_store *tmp_store; 199 struct dm_exception_store *tmp_store;
200 char persistent; 200 char persistent;
201 201
@@ -211,12 +211,15 @@ int dm_exception_store_create(struct dm_target *ti, int argc, char **argv,
211 } 211 }
212 212
213 persistent = toupper(*argv[1]); 213 persistent = toupper(*argv[1]);
214 if (persistent != 'P' && persistent != 'N') { 214 if (persistent == 'P')
215 type = get_type("P");
216 else if (persistent == 'N')
217 type = get_type("N");
218 else {
215 ti->error = "Persistent flag is not P or N"; 219 ti->error = "Persistent flag is not P or N";
216 return -EINVAL; 220 return -EINVAL;
217 } 221 }
218 222
219 type = get_type(&persistent);
220 if (!type) { 223 if (!type) {
221 ti->error = "Exception store type not recognised"; 224 ti->error = "Exception store type not recognised";
222 r = -EINVAL; 225 r = -EINVAL;
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 4899ebe767c8..2cba557d9e61 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -495,7 +495,7 @@ int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
495 return 0; 495 return 0;
496 } 496 }
497 497
498 if (blk_stack_limits(limits, &q->limits, start) < 0) 498 if (blk_stack_limits(limits, &q->limits, start << 9) < 0)
499 DMWARN("%s: target device %s is misaligned", 499 DMWARN("%s: target device %s is misaligned",
500 dm_device_name(ti->table->md), bdevname(bdev, b)); 500 dm_device_name(ti->table->md), bdevname(bdev, b));
501 501
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 3c6d4ee8921d..9acd54a5cffb 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1017,7 +1017,7 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector,
1017 clone->bi_flags |= 1 << BIO_CLONED; 1017 clone->bi_flags |= 1 << BIO_CLONED;
1018 1018
1019 if (bio_integrity(bio)) { 1019 if (bio_integrity(bio)) {
1020 bio_integrity_clone(clone, bio, GFP_NOIO); 1020 bio_integrity_clone(clone, bio, GFP_NOIO, bs);
1021 bio_integrity_trim(clone, 1021 bio_integrity_trim(clone,
1022 bio_sector_offset(bio, idx, offset), len); 1022 bio_sector_offset(bio, idx, offset), len);
1023 } 1023 }
@@ -1045,7 +1045,7 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector,
1045 clone->bi_flags &= ~(1 << BIO_SEG_VALID); 1045 clone->bi_flags &= ~(1 << BIO_SEG_VALID);
1046 1046
1047 if (bio_integrity(bio)) { 1047 if (bio_integrity(bio)) {
1048 bio_integrity_clone(clone, bio, GFP_NOIO); 1048 bio_integrity_clone(clone, bio, GFP_NOIO, bs);
1049 1049
1050 if (idx != bio->bi_idx || clone->bi_size < bio->bi_size) 1050 if (idx != bio->bi_idx || clone->bi_size < bio->bi_size)
1051 bio_integrity_trim(clone, 1051 bio_integrity_trim(clone,
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index 15c8b7b25a9b..5810fa906af0 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -166,8 +166,8 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
166 rdev->sectors = sectors * mddev->chunk_sectors; 166 rdev->sectors = sectors * mddev->chunk_sectors;
167 } 167 }
168 168
169 blk_queue_stack_limits(mddev->queue, 169 disk_stack_limits(mddev->gendisk, rdev->bdev,
170 rdev->bdev->bd_disk->queue); 170 rdev->data_offset << 9);
171 /* as we don't honour merge_bvec_fn, we must never risk 171 /* as we don't honour merge_bvec_fn, we must never risk
172 * violating it, so limit ->max_sector to one PAGE, as 172 * violating it, so limit ->max_sector to one PAGE, as
173 * a one page request is never in violation. 173 * a one page request is never in violation.
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 09be637d52cb..0f4a70c43ffc 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3573,7 +3573,8 @@ suspend_lo_store(mddev_t *mddev, const char *buf, size_t len)
3573 char *e; 3573 char *e;
3574 unsigned long long new = simple_strtoull(buf, &e, 10); 3574 unsigned long long new = simple_strtoull(buf, &e, 10);
3575 3575
3576 if (mddev->pers->quiesce == NULL) 3576 if (mddev->pers == NULL ||
3577 mddev->pers->quiesce == NULL)
3577 return -EINVAL; 3578 return -EINVAL;
3578 if (buf == e || (*e && *e != '\n')) 3579 if (buf == e || (*e && *e != '\n'))
3579 return -EINVAL; 3580 return -EINVAL;
@@ -3601,7 +3602,8 @@ suspend_hi_store(mddev_t *mddev, const char *buf, size_t len)
3601 char *e; 3602 char *e;
3602 unsigned long long new = simple_strtoull(buf, &e, 10); 3603 unsigned long long new = simple_strtoull(buf, &e, 10);
3603 3604
3604 if (mddev->pers->quiesce == NULL) 3605 if (mddev->pers == NULL ||
3606 mddev->pers->quiesce == NULL)
3605 return -EINVAL; 3607 return -EINVAL;
3606 if (buf == e || (*e && *e != '\n')) 3608 if (buf == e || (*e && *e != '\n'))
3607 return -EINVAL; 3609 return -EINVAL;
@@ -3844,11 +3846,9 @@ static int md_alloc(dev_t dev, char *name)
3844 flush_scheduled_work(); 3846 flush_scheduled_work();
3845 3847
3846 mutex_lock(&disks_mutex); 3848 mutex_lock(&disks_mutex);
3847 if (mddev->gendisk) { 3849 error = -EEXIST;
3848 mutex_unlock(&disks_mutex); 3850 if (mddev->gendisk)
3849 mddev_put(mddev); 3851 goto abort;
3850 return -EEXIST;
3851 }
3852 3852
3853 if (name) { 3853 if (name) {
3854 /* Need to ensure that 'name' is not a duplicate. 3854 /* Need to ensure that 'name' is not a duplicate.
@@ -3860,17 +3860,15 @@ static int md_alloc(dev_t dev, char *name)
3860 if (mddev2->gendisk && 3860 if (mddev2->gendisk &&
3861 strcmp(mddev2->gendisk->disk_name, name) == 0) { 3861 strcmp(mddev2->gendisk->disk_name, name) == 0) {
3862 spin_unlock(&all_mddevs_lock); 3862 spin_unlock(&all_mddevs_lock);
3863 return -EEXIST; 3863 goto abort;
3864 } 3864 }
3865 spin_unlock(&all_mddevs_lock); 3865 spin_unlock(&all_mddevs_lock);
3866 } 3866 }
3867 3867
3868 error = -ENOMEM;
3868 mddev->queue = blk_alloc_queue(GFP_KERNEL); 3869 mddev->queue = blk_alloc_queue(GFP_KERNEL);
3869 if (!mddev->queue) { 3870 if (!mddev->queue)
3870 mutex_unlock(&disks_mutex); 3871 goto abort;
3871 mddev_put(mddev);
3872 return -ENOMEM;
3873 }
3874 mddev->queue->queuedata = mddev; 3872 mddev->queue->queuedata = mddev;
3875 3873
3876 /* Can be unlocked because the queue is new: no concurrency */ 3874 /* Can be unlocked because the queue is new: no concurrency */
@@ -3880,11 +3878,9 @@ static int md_alloc(dev_t dev, char *name)
3880 3878
3881 disk = alloc_disk(1 << shift); 3879 disk = alloc_disk(1 << shift);
3882 if (!disk) { 3880 if (!disk) {
3883 mutex_unlock(&disks_mutex);
3884 blk_cleanup_queue(mddev->queue); 3881 blk_cleanup_queue(mddev->queue);
3885 mddev->queue = NULL; 3882 mddev->queue = NULL;
3886 mddev_put(mddev); 3883 goto abort;
3887 return -ENOMEM;
3888 } 3884 }
3889 disk->major = MAJOR(mddev->unit); 3885 disk->major = MAJOR(mddev->unit);
3890 disk->first_minor = unit << shift; 3886 disk->first_minor = unit << shift;
@@ -3906,16 +3902,22 @@ static int md_alloc(dev_t dev, char *name)
3906 mddev->gendisk = disk; 3902 mddev->gendisk = disk;
3907 error = kobject_init_and_add(&mddev->kobj, &md_ktype, 3903 error = kobject_init_and_add(&mddev->kobj, &md_ktype,
3908 &disk_to_dev(disk)->kobj, "%s", "md"); 3904 &disk_to_dev(disk)->kobj, "%s", "md");
3909 mutex_unlock(&disks_mutex); 3905 if (error) {
3910 if (error) 3906 /* This isn't possible, but as kobject_init_and_add is marked
3907 * __must_check, we must do something with the result
3908 */
3911 printk(KERN_WARNING "md: cannot register %s/md - name in use\n", 3909 printk(KERN_WARNING "md: cannot register %s/md - name in use\n",
3912 disk->disk_name); 3910 disk->disk_name);
3913 else { 3911 error = 0;
3912 }
3913 abort:
3914 mutex_unlock(&disks_mutex);
3915 if (!error) {
3914 kobject_uevent(&mddev->kobj, KOBJ_ADD); 3916 kobject_uevent(&mddev->kobj, KOBJ_ADD);
3915 mddev->sysfs_state = sysfs_get_dirent(mddev->kobj.sd, "array_state"); 3917 mddev->sysfs_state = sysfs_get_dirent(mddev->kobj.sd, "array_state");
3916 } 3918 }
3917 mddev_put(mddev); 3919 mddev_put(mddev);
3918 return 0; 3920 return error;
3919} 3921}
3920 3922
3921static struct kobject *md_probe(dev_t dev, int *part, void *data) 3923static struct kobject *md_probe(dev_t dev, int *part, void *data)
@@ -6334,10 +6336,16 @@ void md_do_sync(mddev_t *mddev)
6334 sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 6336 sysfs_notify(&mddev->kobj, NULL, "sync_completed");
6335 } 6337 }
6336 6338
6337 if (j >= mddev->resync_max) 6339 while (j >= mddev->resync_max && !kthread_should_stop()) {
6338 wait_event(mddev->recovery_wait, 6340 /* As this condition is controlled by user-space,
6339 mddev->resync_max > j 6341 * we can block indefinitely, so use '_interruptible'
6340 || kthread_should_stop()); 6342 * to avoid triggering warnings.
6343 */
6344 flush_signals(current); /* just in case */
6345 wait_event_interruptible(mddev->recovery_wait,
6346 mddev->resync_max > j
6347 || kthread_should_stop());
6348 }
6341 6349
6342 if (kthread_should_stop()) 6350 if (kthread_should_stop())
6343 goto interrupted; 6351 goto interrupted;
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index cbe368fa6598..237fe3fd235c 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -294,7 +294,8 @@ static int multipath_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
294 for (path = first; path <= last; path++) 294 for (path = first; path <= last; path++)
295 if ((p=conf->multipaths+path)->rdev == NULL) { 295 if ((p=conf->multipaths+path)->rdev == NULL) {
296 q = rdev->bdev->bd_disk->queue; 296 q = rdev->bdev->bd_disk->queue;
297 blk_queue_stack_limits(mddev->queue, q); 297 disk_stack_limits(mddev->gendisk, rdev->bdev,
298 rdev->data_offset << 9);
298 299
299 /* as we don't honour merge_bvec_fn, we must never risk 300 /* as we don't honour merge_bvec_fn, we must never risk
300 * violating it, so limit ->max_sector to one PAGE, as 301 * violating it, so limit ->max_sector to one PAGE, as
@@ -463,9 +464,9 @@ static int multipath_run (mddev_t *mddev)
463 464
464 disk = conf->multipaths + disk_idx; 465 disk = conf->multipaths + disk_idx;
465 disk->rdev = rdev; 466 disk->rdev = rdev;
467 disk_stack_limits(mddev->gendisk, rdev->bdev,
468 rdev->data_offset << 9);
466 469
467 blk_queue_stack_limits(mddev->queue,
468 rdev->bdev->bd_disk->queue);
469 /* as we don't honour merge_bvec_fn, we must never risk 470 /* as we don't honour merge_bvec_fn, we must never risk
470 * violating it, not that we ever expect a device with 471 * violating it, not that we ever expect a device with
471 * a merge_bvec_fn to be involved in multipath */ 472 * a merge_bvec_fn to be involved in multipath */
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index ab4a489d8695..335f490dcad6 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -170,8 +170,8 @@ static int create_strip_zones(mddev_t *mddev)
170 } 170 }
171 dev[j] = rdev1; 171 dev[j] = rdev1;
172 172
173 blk_queue_stack_limits(mddev->queue, 173 disk_stack_limits(mddev->gendisk, rdev1->bdev,
174 rdev1->bdev->bd_disk->queue); 174 rdev1->data_offset << 9);
175 /* as we don't honour merge_bvec_fn, we must never risk 175 /* as we don't honour merge_bvec_fn, we must never risk
176 * violating it, so limit ->max_sector to one PAGE, as 176 * violating it, so limit ->max_sector to one PAGE, as
177 * a one page request is never in violation. 177 * a one page request is never in violation.
@@ -250,6 +250,11 @@ static int create_strip_zones(mddev_t *mddev)
250 mddev->chunk_sectors << 9); 250 mddev->chunk_sectors << 9);
251 goto abort; 251 goto abort;
252 } 252 }
253
254 blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);
255 blk_queue_io_opt(mddev->queue,
256 (mddev->chunk_sectors << 9) * mddev->raid_disks);
257
253 printk(KERN_INFO "raid0: done.\n"); 258 printk(KERN_INFO "raid0: done.\n");
254 mddev->private = conf; 259 mddev->private = conf;
255 return 0; 260 return 0;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 89939a7aef57..0569efba0c02 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1123,8 +1123,8 @@ static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1123 for (mirror = first; mirror <= last; mirror++) 1123 for (mirror = first; mirror <= last; mirror++)
1124 if ( !(p=conf->mirrors+mirror)->rdev) { 1124 if ( !(p=conf->mirrors+mirror)->rdev) {
1125 1125
1126 blk_queue_stack_limits(mddev->queue, 1126 disk_stack_limits(mddev->gendisk, rdev->bdev,
1127 rdev->bdev->bd_disk->queue); 1127 rdev->data_offset << 9);
1128 /* as we don't honour merge_bvec_fn, we must never risk 1128 /* as we don't honour merge_bvec_fn, we must never risk
1129 * violating it, so limit ->max_sector to one PAGE, as 1129 * violating it, so limit ->max_sector to one PAGE, as
1130 * a one page request is never in violation. 1130 * a one page request is never in violation.
@@ -1988,9 +1988,8 @@ static int run(mddev_t *mddev)
1988 disk = conf->mirrors + disk_idx; 1988 disk = conf->mirrors + disk_idx;
1989 1989
1990 disk->rdev = rdev; 1990 disk->rdev = rdev;
1991 1991 disk_stack_limits(mddev->gendisk, rdev->bdev,
1992 blk_queue_stack_limits(mddev->queue, 1992 rdev->data_offset << 9);
1993 rdev->bdev->bd_disk->queue);
1994 /* as we don't honour merge_bvec_fn, we must never risk 1993 /* as we don't honour merge_bvec_fn, we must never risk
1995 * violating it, so limit ->max_sector to one PAGE, as 1994 * violating it, so limit ->max_sector to one PAGE, as
1996 * a one page request is never in violation. 1995 * a one page request is never in violation.
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index ae12ceafe10c..7298a5e5a183 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1151,8 +1151,8 @@ static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1151 for ( ; mirror <= last ; mirror++) 1151 for ( ; mirror <= last ; mirror++)
1152 if ( !(p=conf->mirrors+mirror)->rdev) { 1152 if ( !(p=conf->mirrors+mirror)->rdev) {
1153 1153
1154 blk_queue_stack_limits(mddev->queue, 1154 disk_stack_limits(mddev->gendisk, rdev->bdev,
1155 rdev->bdev->bd_disk->queue); 1155 rdev->data_offset << 9);
1156 /* as we don't honour merge_bvec_fn, we must never risk 1156 /* as we don't honour merge_bvec_fn, we must never risk
1157 * violating it, so limit ->max_sector to one PAGE, as 1157 * violating it, so limit ->max_sector to one PAGE, as
1158 * a one page request is never in violation. 1158 * a one page request is never in violation.
@@ -2044,7 +2044,7 @@ raid10_size(mddev_t *mddev, sector_t sectors, int raid_disks)
2044static int run(mddev_t *mddev) 2044static int run(mddev_t *mddev)
2045{ 2045{
2046 conf_t *conf; 2046 conf_t *conf;
2047 int i, disk_idx; 2047 int i, disk_idx, chunk_size;
2048 mirror_info_t *disk; 2048 mirror_info_t *disk;
2049 mdk_rdev_t *rdev; 2049 mdk_rdev_t *rdev;
2050 int nc, fc, fo; 2050 int nc, fc, fo;
@@ -2130,6 +2130,14 @@ static int run(mddev_t *mddev)
2130 spin_lock_init(&conf->device_lock); 2130 spin_lock_init(&conf->device_lock);
2131 mddev->queue->queue_lock = &conf->device_lock; 2131 mddev->queue->queue_lock = &conf->device_lock;
2132 2132
2133 chunk_size = mddev->chunk_sectors << 9;
2134 blk_queue_io_min(mddev->queue, chunk_size);
2135 if (conf->raid_disks % conf->near_copies)
2136 blk_queue_io_opt(mddev->queue, chunk_size * conf->raid_disks);
2137 else
2138 blk_queue_io_opt(mddev->queue, chunk_size *
2139 (conf->raid_disks / conf->near_copies));
2140
2133 list_for_each_entry(rdev, &mddev->disks, same_set) { 2141 list_for_each_entry(rdev, &mddev->disks, same_set) {
2134 disk_idx = rdev->raid_disk; 2142 disk_idx = rdev->raid_disk;
2135 if (disk_idx >= mddev->raid_disks 2143 if (disk_idx >= mddev->raid_disks
@@ -2138,9 +2146,8 @@ static int run(mddev_t *mddev)
2138 disk = conf->mirrors + disk_idx; 2146 disk = conf->mirrors + disk_idx;
2139 2147
2140 disk->rdev = rdev; 2148 disk->rdev = rdev;
2141 2149 disk_stack_limits(mddev->gendisk, rdev->bdev,
2142 blk_queue_stack_limits(mddev->queue, 2150 rdev->data_offset << 9);
2143 rdev->bdev->bd_disk->queue);
2144 /* as we don't honour merge_bvec_fn, we must never risk 2151 /* as we don't honour merge_bvec_fn, we must never risk
2145 * violating it, so limit ->max_sector to one PAGE, as 2152 * violating it, so limit ->max_sector to one PAGE, as
2146 * a one page request is never in violation. 2153 * a one page request is never in violation.
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index f9f991e6e138..37835538b58e 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -3699,13 +3699,21 @@ static int make_request(struct request_queue *q, struct bio * bi)
3699 goto retry; 3699 goto retry;
3700 } 3700 }
3701 } 3701 }
3702 /* FIXME what if we get a false positive because these 3702
3703 * are being updated. 3703 if (bio_data_dir(bi) == WRITE &&
3704 */ 3704 logical_sector >= mddev->suspend_lo &&
3705 if (logical_sector >= mddev->suspend_lo &&
3706 logical_sector < mddev->suspend_hi) { 3705 logical_sector < mddev->suspend_hi) {
3707 release_stripe(sh); 3706 release_stripe(sh);
3708 schedule(); 3707 /* As the suspend_* range is controlled by
3708 * userspace, we want an interruptible
3709 * wait.
3710 */
3711 flush_signals(current);
3712 prepare_to_wait(&conf->wait_for_overlap,
3713 &w, TASK_INTERRUPTIBLE);
3714 if (logical_sector >= mddev->suspend_lo &&
3715 logical_sector < mddev->suspend_hi)
3716 schedule();
3709 goto retry; 3717 goto retry;
3710 } 3718 }
3711 3719
@@ -4452,7 +4460,7 @@ static raid5_conf_t *setup_conf(mddev_t *mddev)
4452static int run(mddev_t *mddev) 4460static int run(mddev_t *mddev)
4453{ 4461{
4454 raid5_conf_t *conf; 4462 raid5_conf_t *conf;
4455 int working_disks = 0; 4463 int working_disks = 0, chunk_size;
4456 mdk_rdev_t *rdev; 4464 mdk_rdev_t *rdev;
4457 4465
4458 if (mddev->recovery_cp != MaxSector) 4466 if (mddev->recovery_cp != MaxSector)
@@ -4607,6 +4615,14 @@ static int run(mddev_t *mddev)
4607 md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); 4615 md_set_array_sectors(mddev, raid5_size(mddev, 0, 0));
4608 4616
4609 blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec); 4617 blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec);
4618 chunk_size = mddev->chunk_sectors << 9;
4619 blk_queue_io_min(mddev->queue, chunk_size);
4620 blk_queue_io_opt(mddev->queue, chunk_size *
4621 (conf->raid_disks - conf->max_degraded));
4622
4623 list_for_each_entry(rdev, &mddev->disks, same_set)
4624 disk_stack_limits(mddev->gendisk, rdev->bdev,
4625 rdev->data_offset << 9);
4610 4626
4611 return 0; 4627 return 0;
4612abort: 4628abort:
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index 8280f8d66a38..8c9ae0a3a272 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -904,7 +904,7 @@ static int dvb_net_sec_callback(const u8 *buffer1, size_t buffer1_len,
904static int dvb_net_tx(struct sk_buff *skb, struct net_device *dev) 904static int dvb_net_tx(struct sk_buff *skb, struct net_device *dev)
905{ 905{
906 dev_kfree_skb(skb); 906 dev_kfree_skb(skb);
907 return 0; 907 return NETDEV_TX_OK;
908} 908}
909 909
910static u8 mask_normal[6]={0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 910static u8 mask_normal[6]={0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c
index a9e48e28b1dc..bc2ec2182c00 100644
--- a/drivers/message/fusion/mptlan.c
+++ b/drivers/message/fusion/mptlan.c
@@ -795,7 +795,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev)
795 IOC_AND_NETDEV_NAMES_s_s(dev), 795 IOC_AND_NETDEV_NAMES_s_s(dev),
796 le32_to_cpu(pSimple->FlagsLength))); 796 le32_to_cpu(pSimple->FlagsLength)));
797 797
798 return 0; 798 return NETDEV_TX_OK;
799} 799}
800 800
801/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 801/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
diff --git a/drivers/mfd/ezx-pcap.c b/drivers/mfd/ezx-pcap.c
index 671a7efe86a8..c1de4afa89a6 100644
--- a/drivers/mfd/ezx-pcap.c
+++ b/drivers/mfd/ezx-pcap.c
@@ -238,8 +238,10 @@ static irqreturn_t pcap_adc_irq(int irq, void *_pcap)
238 mutex_lock(&pcap->adc_mutex); 238 mutex_lock(&pcap->adc_mutex);
239 req = pcap->adc_queue[pcap->adc_head]; 239 req = pcap->adc_queue[pcap->adc_head];
240 240
241 if (WARN(!req, KERN_WARNING "adc irq without pending request\n")) 241 if (WARN(!req, KERN_WARNING "adc irq without pending request\n")) {
242 mutex_unlock(&pcap->adc_mutex);
242 return IRQ_HANDLED; 243 return IRQ_HANDLED;
244 }
243 245
244 /* read requested channels results */ 246 /* read requested channels results */
245 ezx_pcap_read(pcap, PCAP_REG_ADC, &tmp); 247 ezx_pcap_read(pcap, PCAP_REG_ADC, &tmp);
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 4c7b7962f6b8..0cc5eeff5ee8 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -367,7 +367,8 @@ int sm501_unit_power(struct device *dev, unsigned int unit, unsigned int to)
367 break; 367 break;
368 368
369 default: 369 default:
370 return -1; 370 gate = -1;
371 goto already;
371 } 372 }
372 373
373 writel(mode, sm->regs + SM501_POWER_MODE_CONTROL); 374 writel(mode, sm->regs + SM501_POWER_MODE_CONTROL);
diff --git a/drivers/misc/sgi-xp/xpnet.c b/drivers/misc/sgi-xp/xpnet.c
index 8d1c60a3f0df..b681bf8abdc9 100644
--- a/drivers/misc/sgi-xp/xpnet.c
+++ b/drivers/misc/sgi-xp/xpnet.c
@@ -436,7 +436,7 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
436 436
437 if (skb->data[0] == 0x33) { 437 if (skb->data[0] == 0x33) {
438 dev_kfree_skb(skb); 438 dev_kfree_skb(skb);
439 return 0; /* nothing needed to be done */ 439 return NETDEV_TX_OK; /* nothing needed to be done */
440 } 440 }
441 441
442 /* 442 /*
@@ -503,7 +503,7 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
503 dev->stats.tx_packets++; 503 dev->stats.tx_packets++;
504 dev->stats.tx_bytes += skb->len; 504 dev->stats.tx_bytes += skb->len;
505 505
506 return 0; 506 return NETDEV_TX_OK;
507} 507}
508 508
509/* 509/*
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 240608cc7ae9..a461017ce5ce 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1313,6 +1313,12 @@ static int mmc_spi_probe(struct spi_device *spi)
1313 struct mmc_spi_host *host; 1313 struct mmc_spi_host *host;
1314 int status; 1314 int status;
1315 1315
1316 /* We rely on full duplex transfers, mostly to reduce
1317 * per-transfer overheads (by making fewer transfers).
1318 */
1319 if (spi->master->flags & SPI_MASTER_HALF_DUPLEX)
1320 return -EINVAL;
1321
1316 /* MMC and SD specs only seem to care that sampling is on the 1322 /* MMC and SD specs only seem to care that sampling is on the
1317 * rising edge ... meaning SPI modes 0 or 3. So either SPI mode 1323 * rising edge ... meaning SPI modes 0 or 3. So either SPI mode
1318 * should be legit. We'll use mode 0 since the steady state is 0, 1324 * should be legit. We'll use mode 0 since the steady state is 0,
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index 5011fa73f918..1479da6d3aa6 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -194,7 +194,7 @@ static struct mtd_partition * newpart(char *s,
194 parts[this_part].name = extra_mem; 194 parts[this_part].name = extra_mem;
195 extra_mem += name_len + 1; 195 extra_mem += name_len + 1;
196 196
197 dbg(("partition %d: name <%s>, offset %x, size %x, mask flags %x\n", 197 dbg(("partition %d: name <%s>, offset %llx, size %llx, mask flags %x\n",
198 this_part, 198 this_part,
199 parts[this_part].name, 199 parts[this_part].name,
200 parts[this_part].offset, 200 parts[this_part].offset,
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 59c46126a5ce..ae5fe91867e1 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -54,7 +54,7 @@
54#define SR_SRWD 0x80 /* SR write protect */ 54#define SR_SRWD 0x80 /* SR write protect */
55 55
56/* Define max times to check status register before we give up. */ 56/* Define max times to check status register before we give up. */
57#define MAX_READY_WAIT_JIFFIES (10 * HZ) /* eg. M25P128 specs 6s max sector erase */ 57#define MAX_READY_WAIT_JIFFIES (40 * HZ) /* M25P16 specs 40s max chip erase */
58#define CMD_SIZE 4 58#define CMD_SIZE 4
59 59
60#ifdef CONFIG_M25PXX_USE_FAST_READ 60#ifdef CONFIG_M25PXX_USE_FAST_READ
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index 73f05227dc8c..d8cf29c01cc4 100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
@@ -226,7 +226,7 @@ static u16 INFTL_findfreeblock(struct INFTLrecord *inftl, int desperate)
226 if (!desperate && inftl->numfreeEUNs < 2) { 226 if (!desperate && inftl->numfreeEUNs < 2) {
227 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: there are too few free " 227 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: there are too few free "
228 "EUNs (%d)\n", inftl->numfreeEUNs); 228 "EUNs (%d)\n", inftl->numfreeEUNs);
229 return 0xffff; 229 return BLOCK_NIL;
230 } 230 }
231 231
232 /* Scan for a free block */ 232 /* Scan for a free block */
@@ -281,7 +281,8 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
281 silly = MAX_LOOPS; 281 silly = MAX_LOOPS;
282 while (thisEUN < inftl->nb_blocks) { 282 while (thisEUN < inftl->nb_blocks) {
283 for (block = 0; block < inftl->EraseSize/SECTORSIZE; block ++) { 283 for (block = 0; block < inftl->EraseSize/SECTORSIZE; block ++) {
284 if ((BlockMap[block] != 0xffff) || BlockDeleted[block]) 284 if ((BlockMap[block] != BLOCK_NIL) ||
285 BlockDeleted[block])
285 continue; 286 continue;
286 287
287 if (inftl_read_oob(mtd, (thisEUN * inftl->EraseSize) 288 if (inftl_read_oob(mtd, (thisEUN * inftl->EraseSize)
@@ -525,7 +526,7 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
525 if (!silly--) { 526 if (!silly--) {
526 printk(KERN_WARNING "INFTL: infinite loop in " 527 printk(KERN_WARNING "INFTL: infinite loop in "
527 "Virtual Unit Chain 0x%x\n", thisVUC); 528 "Virtual Unit Chain 0x%x\n", thisVUC);
528 return 0xffff; 529 return BLOCK_NIL;
529 } 530 }
530 531
531 /* Skip to next block in chain */ 532 /* Skip to next block in chain */
@@ -549,7 +550,7 @@ hitused:
549 * waiting to be picked up. We're going to have to fold 550 * waiting to be picked up. We're going to have to fold
550 * a chain to make room. 551 * a chain to make room.
551 */ 552 */
552 thisEUN = INFTL_makefreeblock(inftl, 0xffff); 553 thisEUN = INFTL_makefreeblock(inftl, BLOCK_NIL);
553 554
554 /* 555 /*
555 * Hopefully we free something, lets try again. 556 * Hopefully we free something, lets try again.
@@ -631,7 +632,7 @@ hitused:
631 632
632 printk(KERN_WARNING "INFTL: error folding to make room for Virtual " 633 printk(KERN_WARNING "INFTL: error folding to make room for Virtual "
633 "Unit Chain 0x%x\n", thisVUC); 634 "Unit Chain 0x%x\n", thisVUC);
634 return 0xffff; 635 return BLOCK_NIL;
635} 636}
636 637
637/* 638/*
diff --git a/drivers/mtd/maps/integrator-flash.c b/drivers/mtd/maps/integrator-flash.c
index b08a798ee254..2aac41bde8b3 100644
--- a/drivers/mtd/maps/integrator-flash.c
+++ b/drivers/mtd/maps/integrator-flash.c
@@ -42,10 +42,8 @@
42#include <mach/hardware.h> 42#include <mach/hardware.h>
43#include <asm/system.h> 43#include <asm/system.h>
44 44
45#define SUBDEV_NAME_SIZE (BUS_ID_SIZE + 2)
46
47struct armflash_subdev_info { 45struct armflash_subdev_info {
48 char name[SUBDEV_NAME_SIZE]; 46 char *name;
49 struct mtd_info *mtd; 47 struct mtd_info *mtd;
50 struct map_info map; 48 struct map_info map;
51 struct flash_platform_data *plat; 49 struct flash_platform_data *plat;
@@ -134,6 +132,8 @@ static void armflash_subdev_remove(struct armflash_subdev_info *subdev)
134 map_destroy(subdev->mtd); 132 map_destroy(subdev->mtd);
135 if (subdev->map.virt) 133 if (subdev->map.virt)
136 iounmap(subdev->map.virt); 134 iounmap(subdev->map.virt);
135 kfree(subdev->name);
136 subdev->name = NULL;
137 release_mem_region(subdev->map.phys, subdev->map.size); 137 release_mem_region(subdev->map.phys, subdev->map.size);
138} 138}
139 139
@@ -177,16 +177,22 @@ static int armflash_probe(struct platform_device *dev)
177 177
178 if (nr == 1) 178 if (nr == 1)
179 /* No MTD concatenation, just use the default name */ 179 /* No MTD concatenation, just use the default name */
180 snprintf(subdev->name, SUBDEV_NAME_SIZE, "%s", 180 subdev->name = kstrdup(dev_name(&dev->dev), GFP_KERNEL);
181 dev_name(&dev->dev));
182 else 181 else
183 snprintf(subdev->name, SUBDEV_NAME_SIZE, "%s-%d", 182 subdev->name = kasprintf(GFP_KERNEL, "%s-%d",
184 dev_name(&dev->dev), i); 183 dev_name(&dev->dev), i);
184 if (!subdev->name) {
185 err = -ENOMEM;
186 break;
187 }
185 subdev->plat = plat; 188 subdev->plat = plat;
186 189
187 err = armflash_subdev_probe(subdev, res); 190 err = armflash_subdev_probe(subdev, res);
188 if (err) 191 if (err) {
192 kfree(subdev->name);
193 subdev->name = NULL;
189 break; 194 break;
195 }
190 } 196 }
191 info->nr_subdev = i; 197 info->nr_subdev = i;
192 198
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 2802992b39da..20c828ba9405 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -534,7 +534,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
534 &num_partitions); 534 &num_partitions);
535 535
536 if ((!partitions) || (num_partitions == 0)) { 536 if ((!partitions) || (num_partitions == 0)) {
537 printk(KERN_ERR "atmel_nand: No parititions defined, or unsupported device.\n"); 537 printk(KERN_ERR "atmel_nand: No partitions defined, or unsupported device.\n");
538 res = ENXIO; 538 res = ENXIO;
539 goto err_no_partitions; 539 goto err_no_partitions;
540 } 540 }
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 0cd76f89f4b0..ebd07e95b814 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -11,6 +11,8 @@
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/jiffies.h>
15#include <linux/sched.h>
14#include <linux/mtd/mtd.h> 16#include <linux/mtd/mtd.h>
15#include <linux/mtd/nand.h> 17#include <linux/mtd/nand.h>
16#include <linux/mtd/partitions.h> 18#include <linux/mtd/partitions.h>
@@ -541,7 +543,7 @@ static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
541 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 543 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
542 mtd); 544 mtd);
543 unsigned long timeo = jiffies; 545 unsigned long timeo = jiffies;
544 int status, state = this->state; 546 int status = NAND_STATUS_FAIL, state = this->state;
545 547
546 if (state == FL_ERASING) 548 if (state == FL_ERASING)
547 timeo += (HZ * 400) / 1000; 549 timeo += (HZ * 400) / 1000;
@@ -556,8 +558,9 @@ static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
556 558
557 while (time_before(jiffies, timeo)) { 559 while (time_before(jiffies, timeo)) {
558 status = __raw_readb(this->IO_ADDR_R); 560 status = __raw_readb(this->IO_ADDR_R);
559 if (!(status & 0x40)) 561 if (status & NAND_STATUS_READY)
560 break; 562 break;
563 cond_resched();
561 } 564 }
562 return status; 565 return status;
563} 566}
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index e3f8495a94c2..fb86cacd5bdb 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -208,7 +208,7 @@ static u16 NFTL_findfreeblock(struct NFTLrecord *nftl, int desperate )
208 /* Normally, we force a fold to happen before we run out of free blocks completely */ 208 /* Normally, we force a fold to happen before we run out of free blocks completely */
209 if (!desperate && nftl->numfreeEUNs < 2) { 209 if (!desperate && nftl->numfreeEUNs < 2) {
210 DEBUG(MTD_DEBUG_LEVEL1, "NFTL_findfreeblock: there are too few free EUNs\n"); 210 DEBUG(MTD_DEBUG_LEVEL1, "NFTL_findfreeblock: there are too few free EUNs\n");
211 return 0xffff; 211 return BLOCK_NIL;
212 } 212 }
213 213
214 /* Scan for a free block */ 214 /* Scan for a free block */
@@ -230,11 +230,11 @@ static u16 NFTL_findfreeblock(struct NFTLrecord *nftl, int desperate )
230 printk("Argh! No free blocks found! LastFreeEUN = %d, " 230 printk("Argh! No free blocks found! LastFreeEUN = %d, "
231 "FirstEUN = %d\n", nftl->LastFreeEUN, 231 "FirstEUN = %d\n", nftl->LastFreeEUN,
232 le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN)); 232 le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN));
233 return 0xffff; 233 return BLOCK_NIL;
234 } 234 }
235 } while (pot != nftl->LastFreeEUN); 235 } while (pot != nftl->LastFreeEUN);
236 236
237 return 0xffff; 237 return BLOCK_NIL;
238} 238}
239 239
240static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned pendingblock ) 240static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned pendingblock )
@@ -431,7 +431,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
431 431
432 /* add the header so that it is now a valid chain */ 432 /* add the header so that it is now a valid chain */
433 oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum = cpu_to_le16(thisVUC); 433 oob.u.a.VirtUnitNum = oob.u.a.SpareVirtUnitNum = cpu_to_le16(thisVUC);
434 oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum = 0xffff; 434 oob.u.a.ReplUnitNum = oob.u.a.SpareReplUnitNum = BLOCK_NIL;
435 435
436 nftl_write_oob(mtd, (nftl->EraseSize * targetEUN) + 8, 436 nftl_write_oob(mtd, (nftl->EraseSize * targetEUN) + 8,
437 8, &retlen, (char *)&oob.u); 437 8, &retlen, (char *)&oob.u);
@@ -515,7 +515,7 @@ static u16 NFTL_makefreeblock( struct NFTLrecord *nftl , unsigned pendingblock)
515 if (ChainLength < 2) { 515 if (ChainLength < 2) {
516 printk(KERN_WARNING "No Virtual Unit Chains available for folding. " 516 printk(KERN_WARNING "No Virtual Unit Chains available for folding. "
517 "Failing request\n"); 517 "Failing request\n");
518 return 0xffff; 518 return BLOCK_NIL;
519 } 519 }
520 520
521 return NFTL_foldchain (nftl, LongestChain, pendingblock); 521 return NFTL_foldchain (nftl, LongestChain, pendingblock);
@@ -578,7 +578,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
578 printk(KERN_WARNING 578 printk(KERN_WARNING
579 "Infinite loop in Virtual Unit Chain 0x%x\n", 579 "Infinite loop in Virtual Unit Chain 0x%x\n",
580 thisVUC); 580 thisVUC);
581 return 0xffff; 581 return BLOCK_NIL;
582 } 582 }
583 583
584 /* Skip to next block in chain */ 584 /* Skip to next block in chain */
@@ -601,7 +601,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
601 //u16 startEUN = nftl->EUNtable[thisVUC]; 601 //u16 startEUN = nftl->EUNtable[thisVUC];
602 602
603 //printk("Write to VirtualUnitChain %d, calling makefreeblock()\n", thisVUC); 603 //printk("Write to VirtualUnitChain %d, calling makefreeblock()\n", thisVUC);
604 writeEUN = NFTL_makefreeblock(nftl, 0xffff); 604 writeEUN = NFTL_makefreeblock(nftl, BLOCK_NIL);
605 605
606 if (writeEUN == BLOCK_NIL) { 606 if (writeEUN == BLOCK_NIL) {
607 /* OK, we accept that the above comment is 607 /* OK, we accept that the above comment is
@@ -673,7 +673,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
673 673
674 printk(KERN_WARNING "Error folding to make room for Virtual Unit Chain 0x%x\n", 674 printk(KERN_WARNING "Error folding to make room for Virtual Unit Chain 0x%x\n",
675 thisVUC); 675 thisVUC);
676 return 0xffff; 676 return BLOCK_NIL;
677} 677}
678 678
679static int nftl_writeblock(struct mtd_blktrans_dev *mbd, unsigned long block, 679static int nftl_writeblock(struct mtd_blktrans_dev *mbd, unsigned long block,
diff --git a/drivers/net/3c501.c b/drivers/net/3c501.c
index 367bec63620c..e29fb1a4a611 100644
--- a/drivers/net/3c501.c
+++ b/drivers/net/3c501.c
@@ -485,7 +485,7 @@ static int el_start_xmit(struct sk_buff *skb, struct net_device *dev)
485 if (el_debug > 2) 485 if (el_debug > 2)
486 pr_debug(" queued xmit.\n"); 486 pr_debug(" queued xmit.\n");
487 dev_kfree_skb(skb); 487 dev_kfree_skb(skb);
488 return 0; 488 return NETDEV_TX_OK;
489 } 489 }
490 /* A receive upset our load, despite our best efforts */ 490 /* A receive upset our load, despite our best efforts */
491 if (el_debug > 2) 491 if (el_debug > 2)
diff --git a/drivers/net/3c505.c b/drivers/net/3c505.c
index f71b35402755..7bba480d7220 100644
--- a/drivers/net/3c505.c
+++ b/drivers/net/3c505.c
@@ -1101,7 +1101,7 @@ static int elp_start_xmit(struct sk_buff *skb, struct net_device *dev)
1101 prime_rx(dev); 1101 prime_rx(dev);
1102 spin_unlock_irqrestore(&adapter->lock, flags); 1102 spin_unlock_irqrestore(&adapter->lock, flags);
1103 netif_start_queue(dev); 1103 netif_start_queue(dev);
1104 return 0; 1104 return NETDEV_TX_OK;
1105} 1105}
1106 1106
1107/****************************************************** 1107/******************************************************
diff --git a/drivers/net/3c507.c b/drivers/net/3c507.c
index 96b86659381a..9e93a0b39b6e 100644
--- a/drivers/net/3c507.c
+++ b/drivers/net/3c507.c
@@ -537,7 +537,7 @@ static int el16_send_packet (struct sk_buff *skb, struct net_device *dev)
537 537
538 /* You might need to clean up and record Tx statistics here. */ 538 /* You might need to clean up and record Tx statistics here. */
539 539
540 return 0; 540 return NETDEV_TX_OK;
541} 541}
542 542
543/* The typical workload of the driver: 543/* The typical workload of the driver:
diff --git a/drivers/net/3c509.c b/drivers/net/3c509.c
index d2137efbd455..d2515d840c00 100644
--- a/drivers/net/3c509.c
+++ b/drivers/net/3c509.c
@@ -892,7 +892,7 @@ el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
892 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */ 892 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
893 } 893 }
894 } 894 }
895 return 0; 895 return NETDEV_TX_OK;
896} 896}
897 897
898/* The EL3 interrupt handler. */ 898/* The EL3 interrupt handler. */
diff --git a/drivers/net/3c515.c b/drivers/net/3c515.c
index 3e00fa8ea65f..85ffd132bada 100644
--- a/drivers/net/3c515.c
+++ b/drivers/net/3c515.c
@@ -1054,7 +1054,7 @@ static int corkscrew_start_xmit(struct sk_buff *skb,
1054 netif_wake_queue(dev); 1054 netif_wake_queue(dev);
1055 } 1055 }
1056 dev->trans_start = jiffies; 1056 dev->trans_start = jiffies;
1057 return 0; 1057 return NETDEV_TX_OK;
1058 } 1058 }
1059 /* Put out the doubleword header... */ 1059 /* Put out the doubleword header... */
1060 outl(skb->len, ioaddr + TX_FIFO); 1060 outl(skb->len, ioaddr + TX_FIFO);
@@ -1117,7 +1117,7 @@ static int corkscrew_start_xmit(struct sk_buff *skb,
1117 outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */ 1117 outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
1118 } 1118 }
1119 } 1119 }
1120 return 0; 1120 return NETDEV_TX_OK;
1121} 1121}
1122 1122
1123/* The interrupt handler does all of the Rx thread work and cleans up 1123/* The interrupt handler does all of the Rx thread work and cleans up
diff --git a/drivers/net/3c523.c b/drivers/net/3c523.c
index cdd955c4014c..70c701b80d99 100644
--- a/drivers/net/3c523.c
+++ b/drivers/net/3c523.c
@@ -1198,7 +1198,7 @@ static int elmc_send_packet(struct sk_buff *skb, struct net_device *dev)
1198 netif_wake_queue(dev); 1198 netif_wake_queue(dev);
1199 dev_kfree_skb(skb); 1199 dev_kfree_skb(skb);
1200#endif 1200#endif
1201 return 0; 1201 return NETDEV_TX_OK;
1202} 1202}
1203 1203
1204/******************************************* 1204/*******************************************
diff --git a/drivers/net/3c527.c b/drivers/net/3c527.c
index aaa8a9f405d4..72b9ed7f4641 100644
--- a/drivers/net/3c527.c
+++ b/drivers/net/3c527.c
@@ -1035,7 +1035,7 @@ static int mc32_send_packet(struct sk_buff *skb, struct net_device *dev)
1035 1035
1036 if (skb_padto(skb, ETH_ZLEN)) { 1036 if (skb_padto(skb, ETH_ZLEN)) {
1037 netif_wake_queue(dev); 1037 netif_wake_queue(dev);
1038 return 0; 1038 return NETDEV_TX_OK;
1039 } 1039 }
1040 1040
1041 atomic_dec(&lp->tx_count); 1041 atomic_dec(&lp->tx_count);
@@ -1066,7 +1066,7 @@ static int mc32_send_packet(struct sk_buff *skb, struct net_device *dev)
1066 p->control &= ~CONTROL_EOL; 1066 p->control &= ~CONTROL_EOL;
1067 1067
1068 netif_wake_queue(dev); 1068 netif_wake_queue(dev);
1069 return 0; 1069 return NETDEV_TX_OK;
1070} 1070}
1071 1071
1072 1072
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index c34aee91250b..202048450eed 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -2083,7 +2083,7 @@ vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
2083 iowrite8(0x00, ioaddr + TxStatus); /* Pop the status stack. */ 2083 iowrite8(0x00, ioaddr + TxStatus); /* Pop the status stack. */
2084 } 2084 }
2085 } 2085 }
2086 return 0; 2086 return NETDEV_TX_OK;
2087} 2087}
2088 2088
2089static int 2089static int
@@ -2173,7 +2173,7 @@ boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2173 iowrite16(DownUnstall, ioaddr + EL3_CMD); 2173 iowrite16(DownUnstall, ioaddr + EL3_CMD);
2174 spin_unlock_irqrestore(&vp->lock, flags); 2174 spin_unlock_irqrestore(&vp->lock, flags);
2175 dev->trans_start = jiffies; 2175 dev->trans_start = jiffies;
2176 return 0; 2176 return NETDEV_TX_OK;
2177} 2177}
2178 2178
2179/* The interrupt handler does all of the Rx thread work and cleans up 2179/* The interrupt handler does all of the Rx thread work and cleans up
diff --git a/drivers/net/7990.c b/drivers/net/7990.c
index 69f5b7d298a6..b1e5764628c6 100644
--- a/drivers/net/7990.c
+++ b/drivers/net/7990.c
@@ -585,7 +585,7 @@ int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
585 lp->tx_full = 1; 585 lp->tx_full = 1;
586 spin_unlock_irqrestore (&lp->devlock, flags); 586 spin_unlock_irqrestore (&lp->devlock, flags);
587 587
588 return 0; 588 return NETDEV_TX_OK;
589} 589}
590EXPORT_SYMBOL_GPL(lance_start_xmit); 590EXPORT_SYMBOL_GPL(lance_start_xmit);
591 591
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index 50efde11ea6c..07919d0877ee 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -891,7 +891,7 @@ static int cp_start_xmit (struct sk_buff *skb, struct net_device *dev)
891 cpw8(TxPoll, NormalTxPoll); 891 cpw8(TxPoll, NormalTxPoll);
892 dev->trans_start = jiffies; 892 dev->trans_start = jiffies;
893 893
894 return 0; 894 return NETDEV_TX_OK;
895} 895}
896 896
897/* Set or clear the multicast filter for this adaptor. 897/* Set or clear the multicast filter for this adaptor.
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index 0e2ba21d4441..b39ec98345ea 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -1707,7 +1707,7 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
1707 } else { 1707 } else {
1708 dev_kfree_skb(skb); 1708 dev_kfree_skb(skb);
1709 dev->stats.tx_dropped++; 1709 dev->stats.tx_dropped++;
1710 return 0; 1710 return NETDEV_TX_OK;
1711 } 1711 }
1712 1712
1713 spin_lock_irqsave(&tp->lock, flags); 1713 spin_lock_irqsave(&tp->lock, flags);
@@ -1732,7 +1732,7 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
1732 pr_debug("%s: Queued Tx packet size %u to slot %d.\n", 1732 pr_debug("%s: Queued Tx packet size %u to slot %d.\n",
1733 dev->name, len, entry); 1733 dev->name, len, entry);
1734 1734
1735 return 0; 1735 return NETDEV_TX_OK;
1736} 1736}
1737 1737
1738 1738
diff --git a/drivers/net/82596.c b/drivers/net/82596.c
index 77547545509b..996cc9102215 100644
--- a/drivers/net/82596.c
+++ b/drivers/net/82596.c
@@ -1068,7 +1068,7 @@ static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
1068 1068
1069 if (skb->len < ETH_ZLEN) { 1069 if (skb->len < ETH_ZLEN) {
1070 if (skb_padto(skb, ETH_ZLEN)) 1070 if (skb_padto(skb, ETH_ZLEN))
1071 return 0; 1071 return NETDEV_TX_OK;
1072 length = ETH_ZLEN; 1072 length = ETH_ZLEN;
1073 } 1073 }
1074 netif_stop_queue(dev); 1074 netif_stop_queue(dev);
@@ -1110,7 +1110,7 @@ static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
1110 1110
1111 netif_start_queue(dev); 1111 netif_start_queue(dev);
1112 1112
1113 return 0; 1113 return NETDEV_TX_OK;
1114} 1114}
1115 1115
1116static void print_eth(unsigned char *add, char *str) 1116static void print_eth(unsigned char *add, char *str)
diff --git a/drivers/net/a2065.c b/drivers/net/a2065.c
index 85a18175730b..7302e4385bc4 100644
--- a/drivers/net/a2065.c
+++ b/drivers/net/a2065.c
@@ -553,11 +553,11 @@ static int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
553 volatile struct lance_regs *ll = lp->ll; 553 volatile struct lance_regs *ll = lp->ll;
554 volatile struct lance_init_block *ib = lp->init_block; 554 volatile struct lance_init_block *ib = lp->init_block;
555 int entry, skblen; 555 int entry, skblen;
556 int status = 0; 556 int status = NETDEV_TX_OK;
557 unsigned long flags; 557 unsigned long flags;
558 558
559 if (skb_padto(skb, ETH_ZLEN)) 559 if (skb_padto(skb, ETH_ZLEN))
560 return 0; 560 return NETDEV_TX_OK;
561 skblen = max_t(unsigned, skb->len, ETH_ZLEN); 561 skblen = max_t(unsigned, skb->len, ETH_ZLEN);
562 562
563 local_irq_save(flags); 563 local_irq_save(flags);
diff --git a/drivers/net/amd8111e.c b/drivers/net/amd8111e.c
index 19831bd64016..61ac671f97bf 100644
--- a/drivers/net/amd8111e.c
+++ b/drivers/net/amd8111e.c
@@ -1346,7 +1346,7 @@ static int amd8111e_start_xmit(struct sk_buff *skb, struct net_device * dev)
1346 netif_stop_queue(dev); 1346 netif_stop_queue(dev);
1347 } 1347 }
1348 spin_unlock_irqrestore(&lp->lock, flags); 1348 spin_unlock_irqrestore(&lp->lock, flags);
1349 return 0; 1349 return NETDEV_TX_OK;
1350} 1350}
1351/* 1351/*
1352This function returns all the memory mapped registers of the device. 1352This function returns all the memory mapped registers of the device.
diff --git a/drivers/net/appletalk/cops.c b/drivers/net/appletalk/cops.c
index 7f8325419803..29b279f88efb 100644
--- a/drivers/net/appletalk/cops.c
+++ b/drivers/net/appletalk/cops.c
@@ -920,7 +920,7 @@ static int cops_send_packet(struct sk_buff *skb, struct net_device *dev)
920 dev->stats.tx_bytes += skb->len; 920 dev->stats.tx_bytes += skb->len;
921 dev->trans_start = jiffies; 921 dev->trans_start = jiffies;
922 dev_kfree_skb (skb); 922 dev_kfree_skb (skb);
923 return 0; 923 return NETDEV_TX_OK;
924} 924}
925 925
926/* 926/*
diff --git a/drivers/net/appletalk/ipddp.c b/drivers/net/appletalk/ipddp.c
index 78cea5e80b1d..6cfd961bb8de 100644
--- a/drivers/net/appletalk/ipddp.c
+++ b/drivers/net/appletalk/ipddp.c
@@ -132,7 +132,7 @@ static int ipddp_xmit(struct sk_buff *skb, struct net_device *dev)
132 } 132 }
133 if(rt == NULL) { 133 if(rt == NULL) {
134 spin_unlock(&ipddp_route_lock); 134 spin_unlock(&ipddp_route_lock);
135 return 0; 135 return NETDEV_TX_OK;
136 } 136 }
137 137
138 our_addr = atalk_find_dev_addr(rt->dev); 138 our_addr = atalk_find_dev_addr(rt->dev);
@@ -181,7 +181,7 @@ static int ipddp_xmit(struct sk_buff *skb, struct net_device *dev)
181 181
182 spin_unlock(&ipddp_route_lock); 182 spin_unlock(&ipddp_route_lock);
183 183
184 return 0; 184 return NETDEV_TX_OK;
185} 185}
186 186
187/* 187/*
diff --git a/drivers/net/appletalk/ltpc.c b/drivers/net/appletalk/ltpc.c
index b642647170be..c80fb9cf8ffa 100644
--- a/drivers/net/appletalk/ltpc.c
+++ b/drivers/net/appletalk/ltpc.c
@@ -932,7 +932,7 @@ static int ltpc_xmit(struct sk_buff *skb, struct net_device *dev)
932 dev->stats.tx_bytes += skb->len; 932 dev->stats.tx_bytes += skb->len;
933 933
934 dev_kfree_skb(skb); 934 dev_kfree_skb(skb);
935 return 0; 935 return NETDEV_TX_OK;
936} 936}
937 937
938/* initialization stuff */ 938/* initialization stuff */
diff --git a/drivers/net/ariadne.c b/drivers/net/ariadne.c
index 58e8d522e5bc..47d976cc3d7d 100644
--- a/drivers/net/ariadne.c
+++ b/drivers/net/ariadne.c
@@ -610,7 +610,7 @@ static int ariadne_start_xmit(struct sk_buff *skb, struct net_device *dev)
610 if (skb->len < ETH_ZLEN) 610 if (skb->len < ETH_ZLEN)
611 { 611 {
612 if (skb_padto(skb, ETH_ZLEN)) 612 if (skb_padto(skb, ETH_ZLEN))
613 return 0; 613 return NETDEV_TX_OK;
614 len = ETH_ZLEN; 614 len = ETH_ZLEN;
615 } 615 }
616 616
@@ -685,7 +685,7 @@ static int ariadne_start_xmit(struct sk_buff *skb, struct net_device *dev)
685 } 685 }
686 local_irq_restore(flags); 686 local_irq_restore(flags);
687 687
688 return 0; 688 return NETDEV_TX_OK;
689} 689}
690 690
691 691
diff --git a/drivers/net/arm/am79c961a.c b/drivers/net/arm/am79c961a.c
index 627bc75da17d..164b37e85eea 100644
--- a/drivers/net/arm/am79c961a.c
+++ b/drivers/net/arm/am79c961a.c
@@ -482,7 +482,7 @@ am79c961_sendpacket(struct sk_buff *skb, struct net_device *dev)
482 482
483 dev_kfree_skb(skb); 483 dev_kfree_skb(skb);
484 484
485 return 0; 485 return NETDEV_TX_OK;
486} 486}
487 487
488/* 488/*
diff --git a/drivers/net/arm/at91_ether.c b/drivers/net/arm/at91_ether.c
index 2e7419a61191..d46a06e20db0 100644
--- a/drivers/net/arm/at91_ether.c
+++ b/drivers/net/arm/at91_ether.c
@@ -834,7 +834,7 @@ static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev)
834 we free and return(0) or don't free and return 1 */ 834 we free and return(0) or don't free and return 1 */
835 } 835 }
836 836
837 return 0; 837 return NETDEV_TX_OK;
838} 838}
839 839
840/* 840/*
diff --git a/drivers/net/arm/ether1.c b/drivers/net/arm/ether1.c
index edf770f639fa..e47c0d962857 100644
--- a/drivers/net/arm/ether1.c
+++ b/drivers/net/arm/ether1.c
@@ -748,7 +748,7 @@ ether1_sendpacket (struct sk_buff *skb, struct net_device *dev)
748 netif_stop_queue(dev); 748 netif_stop_queue(dev);
749 749
750 out: 750 out:
751 return 0; 751 return NETDEV_TX_OK;
752} 752}
753 753
754static void 754static void
diff --git a/drivers/net/arm/ether3.c b/drivers/net/arm/ether3.c
index 455037134aa3..1f7a69c929a6 100644
--- a/drivers/net/arm/ether3.c
+++ b/drivers/net/arm/ether3.c
@@ -511,7 +511,7 @@ ether3_sendpacket(struct sk_buff *skb, struct net_device *dev)
511 dev_kfree_skb(skb); 511 dev_kfree_skb(skb);
512 priv(dev)->stats.tx_dropped ++; 512 priv(dev)->stats.tx_dropped ++;
513 netif_start_queue(dev); 513 netif_start_queue(dev);
514 return 0; 514 return NETDEV_TX_OK;
515 } 515 }
516 516
517 length = (length + 1) & ~1; 517 length = (length + 1) & ~1;
@@ -562,7 +562,7 @@ ether3_sendpacket(struct sk_buff *skb, struct net_device *dev)
562 netif_stop_queue(dev); 562 netif_stop_queue(dev);
563 563
564 out: 564 out:
565 return 0; 565 return NETDEV_TX_OK;
566} 566}
567 567
568static irqreturn_t 568static irqreturn_t
diff --git a/drivers/net/at1700.c b/drivers/net/at1700.c
index 18b566ad4fd1..c2227d79673a 100644
--- a/drivers/net/at1700.c
+++ b/drivers/net/at1700.c
@@ -643,7 +643,7 @@ static int net_send_packet (struct sk_buff *skb, struct net_device *dev)
643 netif_start_queue (dev); 643 netif_start_queue (dev);
644 dev_kfree_skb (skb); 644 dev_kfree_skb (skb);
645 645
646 return 0; 646 return NETDEV_TX_OK;
647} 647}
648 648
649/* The typical workload of the driver: 649/* The typical workload of the driver:
diff --git a/drivers/net/atarilance.c b/drivers/net/atarilance.c
index 5425ab0c38c0..0c0deceb6938 100644
--- a/drivers/net/atarilance.c
+++ b/drivers/net/atarilance.c
@@ -796,7 +796,7 @@ static int lance_start_xmit( struct sk_buff *skb, struct net_device *dev )
796 796
797 if (len > skb->len) { 797 if (len > skb->len) {
798 if (skb_padto(skb, len)) 798 if (skb_padto(skb, len))
799 return 0; 799 return NETDEV_TX_OK;
800 } 800 }
801 801
802 netif_stop_queue (dev); 802 netif_stop_queue (dev);
@@ -846,7 +846,7 @@ static int lance_start_xmit( struct sk_buff *skb, struct net_device *dev )
846 lp->tx_full = 1; 846 lp->tx_full = 1;
847 spin_unlock_irqrestore (&lp->devlock, flags); 847 spin_unlock_irqrestore (&lp->devlock, flags);
848 848
849 return 0; 849 return NETDEV_TX_OK;
850} 850}
851 851
852/* The LANCE interrupt handler. */ 852/* The LANCE interrupt handler. */
diff --git a/drivers/net/atp.c b/drivers/net/atp.c
index 4317b3edb3d7..4beacc9c909f 100644
--- a/drivers/net/atp.c
+++ b/drivers/net/atp.c
@@ -587,7 +587,7 @@ static int atp_send_packet(struct sk_buff *skb, struct net_device *dev)
587 587
588 dev->trans_start = jiffies; 588 dev->trans_start = jiffies;
589 dev_kfree_skb (skb); 589 dev_kfree_skb (skb);
590 return 0; 590 return NETDEV_TX_OK;
591} 591}
592 592
593 593
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c
index d3c734f4d679..2aab1ebc6cd1 100644
--- a/drivers/net/au1000_eth.c
+++ b/drivers/net/au1000_eth.c
@@ -988,7 +988,7 @@ static int au1000_tx(struct sk_buff *skb, struct net_device *dev)
988 dev_kfree_skb(skb); 988 dev_kfree_skb(skb);
989 aup->tx_head = (aup->tx_head + 1) & (NUM_TX_DMA - 1); 989 aup->tx_head = (aup->tx_head + 1) & (NUM_TX_DMA - 1);
990 dev->trans_start = jiffies; 990 dev->trans_start = jiffies;
991 return 0; 991 return NETDEV_TX_OK;
992} 992}
993 993
994/* 994/*
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c
index c15fc281f79f..f580b21eabd1 100644
--- a/drivers/net/bfin_mac.c
+++ b/drivers/net/bfin_mac.c
@@ -656,7 +656,7 @@ out:
656 dev->trans_start = jiffies; 656 dev->trans_start = jiffies;
657 dev->stats.tx_packets++; 657 dev->stats.tx_packets++;
658 dev->stats.tx_bytes += (skb->len); 658 dev->stats.tx_bytes += (skb->len);
659 return 0; 659 return NETDEV_TX_OK;
660} 660}
661 661
662static void bfin_mac_rx(struct net_device *dev) 662static void bfin_mac_rx(struct net_device *dev)
diff --git a/drivers/net/bmac.c b/drivers/net/bmac.c
index 9578a3dfac01..41600011cfd0 100644
--- a/drivers/net/bmac.c
+++ b/drivers/net/bmac.c
@@ -1488,7 +1488,7 @@ bmac_output(struct sk_buff *skb, struct net_device *dev)
1488 struct bmac_data *bp = netdev_priv(dev); 1488 struct bmac_data *bp = netdev_priv(dev);
1489 skb_queue_tail(bp->queue, skb); 1489 skb_queue_tail(bp->queue, skb);
1490 bmac_start(dev); 1490 bmac_start(dev);
1491 return 0; 1491 return NETDEV_TX_OK;
1492} 1492}
1493 1493
1494static void bmac_tx_timeout(unsigned long data) 1494static void bmac_tx_timeout(unsigned long data)
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index d4b570886c6e..be799d2a8a8d 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -1109,7 +1109,8 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
1109 //mux machine in case of EXPIRED even if LINK_DOWN didn't arrive for the port. 1109 //mux machine in case of EXPIRED even if LINK_DOWN didn't arrive for the port.
1110 port->partner_oper.port_state &= ~AD_STATE_SYNCHRONIZATION; 1110 port->partner_oper.port_state &= ~AD_STATE_SYNCHRONIZATION;
1111 port->sm_vars &= ~AD_PORT_MATCHED; 1111 port->sm_vars &= ~AD_PORT_MATCHED;
1112 port->partner_oper.port_state |= AD_SHORT_TIMEOUT; 1112 port->partner_oper.port_state |=
1113 AD_STATE_LACP_ACTIVITY;
1113 port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(AD_SHORT_TIMEOUT)); 1114 port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(AD_SHORT_TIMEOUT));
1114 port->actor_oper_port_state |= AD_STATE_EXPIRED; 1115 port->actor_oper_port_state |= AD_STATE_EXPIRED;
1115 break; 1116 break;
@@ -2431,7 +2432,7 @@ out:
2431 dev_kfree_skb(skb); 2432 dev_kfree_skb(skb);
2432 } 2433 }
2433 read_unlock(&bond->lock); 2434 read_unlock(&bond->lock);
2434 return 0; 2435 return NETDEV_TX_OK;
2435} 2436}
2436 2437
2437int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type* ptype, struct net_device *orig_dev) 2438int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type* ptype, struct net_device *orig_dev)
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 46d312bedfb8..bf45d2002924 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -1413,7 +1413,7 @@ out:
1413 } 1413 }
1414 read_unlock(&bond->curr_slave_lock); 1414 read_unlock(&bond->curr_slave_lock);
1415 read_unlock(&bond->lock); 1415 read_unlock(&bond->lock);
1416 return 0; 1416 return NETDEV_TX_OK;
1417} 1417}
1418 1418
1419void bond_alb_monitor(struct work_struct *work) 1419void bond_alb_monitor(struct work_struct *work)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index aa1be1feceed..3bf0cc61e92c 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -4285,7 +4285,7 @@ out:
4285 dev_kfree_skb(skb); 4285 dev_kfree_skb(skb);
4286 } 4286 }
4287 read_unlock(&bond->lock); 4287 read_unlock(&bond->lock);
4288 return 0; 4288 return NETDEV_TX_OK;
4289} 4289}
4290 4290
4291 4291
@@ -4316,7 +4316,7 @@ out:
4316 4316
4317 read_unlock(&bond->curr_slave_lock); 4317 read_unlock(&bond->curr_slave_lock);
4318 read_unlock(&bond->lock); 4318 read_unlock(&bond->lock);
4319 return 0; 4319 return NETDEV_TX_OK;
4320} 4320}
4321 4321
4322/* 4322/*
@@ -4362,7 +4362,7 @@ out:
4362 dev_kfree_skb(skb); 4362 dev_kfree_skb(skb);
4363 } 4363 }
4364 read_unlock(&bond->lock); 4364 read_unlock(&bond->lock);
4365 return 0; 4365 return NETDEV_TX_OK;
4366} 4366}
4367 4367
4368/* 4368/*
@@ -4422,7 +4422,7 @@ out:
4422 4422
4423 /* frame sent to all suitable interfaces */ 4423 /* frame sent to all suitable interfaces */
4424 read_unlock(&bond->lock); 4424 read_unlock(&bond->lock);
4425 return 0; 4425 return NETDEV_TX_OK;
4426} 4426}
4427 4427
4428/*------------------------- Device initialization ---------------------------*/ 4428/*------------------------- Device initialization ---------------------------*/
diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index 571f133a8fec..1c30dbec1954 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -283,7 +283,7 @@ static int sja1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
283 283
284 priv->write_reg(priv, REG_CMR, CMD_TR); 284 priv->write_reg(priv, REG_CMR, CMD_TR);
285 285
286 return 0; 286 return NETDEV_TX_OK;
287} 287}
288 288
289static void sja1000_rx(struct net_device *dev) 289static void sja1000_rx(struct net_device *dev)
diff --git a/drivers/net/cassini.c b/drivers/net/cassini.c
index eb066673c2a0..299a33b914f8 100644
--- a/drivers/net/cassini.c
+++ b/drivers/net/cassini.c
@@ -2928,7 +2928,7 @@ static int cas_start_xmit(struct sk_buff *skb, struct net_device *dev)
2928 static int ring; 2928 static int ring;
2929 2929
2930 if (skb_padto(skb, cp->min_frame_size)) 2930 if (skb_padto(skb, cp->min_frame_size))
2931 return 0; 2931 return NETDEV_TX_OK;
2932 2932
2933 /* XXX: we need some higher-level QoS hooks to steer packets to 2933 /* XXX: we need some higher-level QoS hooks to steer packets to
2934 * individual queues. 2934 * individual queues.
@@ -2936,7 +2936,7 @@ static int cas_start_xmit(struct sk_buff *skb, struct net_device *dev)
2936 if (cas_xmit_tx_ringN(cp, ring++ & N_TX_RINGS_MASK, skb)) 2936 if (cas_xmit_tx_ringN(cp, ring++ & N_TX_RINGS_MASK, skb))
2937 return NETDEV_TX_BUSY; 2937 return NETDEV_TX_BUSY;
2938 dev->trans_start = jiffies; 2938 dev->trans_start = jiffies;
2939 return 0; 2939 return NETDEV_TX_OK;
2940} 2940}
2941 2941
2942static void cas_init_tx_dma(struct cas *cp) 2942static void cas_init_tx_dma(struct cas *cp)
diff --git a/drivers/net/cris/eth_v10.c b/drivers/net/cris/eth_v10.c
index 7a18dc7e5c7f..15c0195ebd31 100644
--- a/drivers/net/cris/eth_v10.c
+++ b/drivers/net/cris/eth_v10.c
@@ -1108,7 +1108,7 @@ e100_send_packet(struct sk_buff *skb, struct net_device *dev)
1108 1108
1109 spin_unlock_irqrestore(&np->lock, flags); 1109 spin_unlock_irqrestore(&np->lock, flags);
1110 1110
1111 return 0; 1111 return NETDEV_TX_OK;
1112} 1112}
1113 1113
1114/* 1114/*
diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index 55445f980f9c..ecf88abbf99e 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -1367,7 +1367,7 @@ net_open(struct net_device *dev)
1367 spin_lock_irqsave(&lp->lock, flags); 1367 spin_lock_irqsave(&lp->lock, flags);
1368 disable_dma(dev->dma); 1368 disable_dma(dev->dma);
1369 clear_dma_ff(dev->dma); 1369 clear_dma_ff(dev->dma);
1370 set_dma_mode(dev->dma, 0x14); /* auto_init as well */ 1370 set_dma_mode(dev->dma, DMA_RX_MODE); /* auto_init as well */
1371 set_dma_addr(dev->dma, isa_virt_to_bus(lp->dma_buff)); 1371 set_dma_addr(dev->dma, isa_virt_to_bus(lp->dma_buff));
1372 set_dma_count(dev->dma, lp->dmasize*1024); 1372 set_dma_count(dev->dma, lp->dmasize*1024);
1373 enable_dma(dev->dma); 1373 enable_dma(dev->dma);
@@ -1572,7 +1572,7 @@ static int net_send_packet(struct sk_buff *skb, struct net_device *dev)
1572 * to restart the netdevice layer 1572 * to restart the netdevice layer
1573 */ 1573 */
1574 1574
1575 return 0; 1575 return NETDEV_TX_OK;
1576} 1576}
1577 1577
1578/* The typical workload of the driver: 1578/* The typical workload of the driver:
diff --git a/drivers/net/cxgb3/adapter.h b/drivers/net/cxgb3/adapter.h
index 1694fad38720..74723f2e7431 100644
--- a/drivers/net/cxgb3/adapter.h
+++ b/drivers/net/cxgb3/adapter.h
@@ -276,6 +276,14 @@ static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)
276 return netdev_priv(adap->port[idx]); 276 return netdev_priv(adap->port[idx]);
277} 277}
278 278
279static inline int phy2portid(struct cphy *phy)
280{
281 struct adapter *adap = phy->adapter;
282 struct port_info *port0 = adap2pinfo(adap, 0);
283
284 return &port0->phy == phy ? 0 : 1;
285}
286
279#define OFFLOAD_DEVMAP_BIT 15 287#define OFFLOAD_DEVMAP_BIT 15
280 288
281#define tdev2adap(d) container_of(d, struct adapter, tdev) 289#define tdev2adap(d) container_of(d, struct adapter, tdev)
@@ -312,4 +320,6 @@ int t3_get_desc(const struct sge_qset *qs, unsigned int qnum, unsigned int idx,
312 unsigned char *data); 320 unsigned char *data);
313irqreturn_t t3_sge_intr_msix(int irq, void *cookie); 321irqreturn_t t3_sge_intr_msix(int irq, void *cookie);
314 322
323int t3_get_edc_fw(struct cphy *phy, int edc_idx, int size);
324
315#endif /* __T3_ADAPTER_H__ */ 325#endif /* __T3_ADAPTER_H__ */
diff --git a/drivers/net/cxgb3/ael1002.c b/drivers/net/cxgb3/ael1002.c
index 9fe008ec9ba5..5248f9e0b2f4 100644
--- a/drivers/net/cxgb3/ael1002.c
+++ b/drivers/net/cxgb3/ael1002.c
@@ -224,12 +224,6 @@ static int ael1006_reset(struct cphy *phy, int wait)
224 return t3_phy_reset(phy, MDIO_MMD_PMAPMD, wait); 224 return t3_phy_reset(phy, MDIO_MMD_PMAPMD, wait);
225} 225}
226 226
227static int ael1006_power_down(struct cphy *phy, int enable)
228{
229 return mdio_set_flag(&phy->mdio, phy->mdio.prtad, MDIO_MMD_PMAPMD,
230 MDIO_CTRL1, MDIO_CTRL1_LPOWER, enable);
231}
232
233static struct cphy_ops ael1006_ops = { 227static struct cphy_ops ael1006_ops = {
234 .reset = ael1006_reset, 228 .reset = ael1006_reset,
235 .intr_enable = t3_phy_lasi_intr_enable, 229 .intr_enable = t3_phy_lasi_intr_enable,
@@ -237,7 +231,7 @@ static struct cphy_ops ael1006_ops = {
237 .intr_clear = t3_phy_lasi_intr_clear, 231 .intr_clear = t3_phy_lasi_intr_clear,
238 .intr_handler = t3_phy_lasi_intr_handler, 232 .intr_handler = t3_phy_lasi_intr_handler,
239 .get_link_status = get_link_status_r, 233 .get_link_status = get_link_status_r,
240 .power_down = ael1006_power_down, 234 .power_down = ael1002_power_down,
241 .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS, 235 .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
242}; 236};
243 237
@@ -304,279 +298,7 @@ static int ael2005_setup_sr_edc(struct cphy *phy)
304 { MDIO_MMD_PMAPMD, 0xc04a, 0xffff, 0x5200 }, 298 { MDIO_MMD_PMAPMD, 0xc04a, 0xffff, 0x5200 },
305 { 0, 0, 0, 0 } 299 { 0, 0, 0, 0 }
306 }; 300 };
307 static u16 sr_edc[] = { 301
308 0xcc00, 0x2ff4,
309 0xcc01, 0x3cd4,
310 0xcc02, 0x2015,
311 0xcc03, 0x3105,
312 0xcc04, 0x6524,
313 0xcc05, 0x27ff,
314 0xcc06, 0x300f,
315 0xcc07, 0x2c8b,
316 0xcc08, 0x300b,
317 0xcc09, 0x4009,
318 0xcc0a, 0x400e,
319 0xcc0b, 0x2f72,
320 0xcc0c, 0x3002,
321 0xcc0d, 0x1002,
322 0xcc0e, 0x2172,
323 0xcc0f, 0x3012,
324 0xcc10, 0x1002,
325 0xcc11, 0x25d2,
326 0xcc12, 0x3012,
327 0xcc13, 0x1002,
328 0xcc14, 0xd01e,
329 0xcc15, 0x27d2,
330 0xcc16, 0x3012,
331 0xcc17, 0x1002,
332 0xcc18, 0x2004,
333 0xcc19, 0x3c84,
334 0xcc1a, 0x6436,
335 0xcc1b, 0x2007,
336 0xcc1c, 0x3f87,
337 0xcc1d, 0x8676,
338 0xcc1e, 0x40b7,
339 0xcc1f, 0xa746,
340 0xcc20, 0x4047,
341 0xcc21, 0x5673,
342 0xcc22, 0x2982,
343 0xcc23, 0x3002,
344 0xcc24, 0x13d2,
345 0xcc25, 0x8bbd,
346 0xcc26, 0x2862,
347 0xcc27, 0x3012,
348 0xcc28, 0x1002,
349 0xcc29, 0x2092,
350 0xcc2a, 0x3012,
351 0xcc2b, 0x1002,
352 0xcc2c, 0x5cc3,
353 0xcc2d, 0x314,
354 0xcc2e, 0x2942,
355 0xcc2f, 0x3002,
356 0xcc30, 0x1002,
357 0xcc31, 0xd019,
358 0xcc32, 0x2032,
359 0xcc33, 0x3012,
360 0xcc34, 0x1002,
361 0xcc35, 0x2a04,
362 0xcc36, 0x3c74,
363 0xcc37, 0x6435,
364 0xcc38, 0x2fa4,
365 0xcc39, 0x3cd4,
366 0xcc3a, 0x6624,
367 0xcc3b, 0x5563,
368 0xcc3c, 0x2d42,
369 0xcc3d, 0x3002,
370 0xcc3e, 0x13d2,
371 0xcc3f, 0x464d,
372 0xcc40, 0x2862,
373 0xcc41, 0x3012,
374 0xcc42, 0x1002,
375 0xcc43, 0x2032,
376 0xcc44, 0x3012,
377 0xcc45, 0x1002,
378 0xcc46, 0x2fb4,
379 0xcc47, 0x3cd4,
380 0xcc48, 0x6624,
381 0xcc49, 0x5563,
382 0xcc4a, 0x2d42,
383 0xcc4b, 0x3002,
384 0xcc4c, 0x13d2,
385 0xcc4d, 0x2ed2,
386 0xcc4e, 0x3002,
387 0xcc4f, 0x1002,
388 0xcc50, 0x2fd2,
389 0xcc51, 0x3002,
390 0xcc52, 0x1002,
391 0xcc53, 0x004,
392 0xcc54, 0x2942,
393 0xcc55, 0x3002,
394 0xcc56, 0x1002,
395 0xcc57, 0x2092,
396 0xcc58, 0x3012,
397 0xcc59, 0x1002,
398 0xcc5a, 0x5cc3,
399 0xcc5b, 0x317,
400 0xcc5c, 0x2f72,
401 0xcc5d, 0x3002,
402 0xcc5e, 0x1002,
403 0xcc5f, 0x2942,
404 0xcc60, 0x3002,
405 0xcc61, 0x1002,
406 0xcc62, 0x22cd,
407 0xcc63, 0x301d,
408 0xcc64, 0x2862,
409 0xcc65, 0x3012,
410 0xcc66, 0x1002,
411 0xcc67, 0x2ed2,
412 0xcc68, 0x3002,
413 0xcc69, 0x1002,
414 0xcc6a, 0x2d72,
415 0xcc6b, 0x3002,
416 0xcc6c, 0x1002,
417 0xcc6d, 0x628f,
418 0xcc6e, 0x2112,
419 0xcc6f, 0x3012,
420 0xcc70, 0x1002,
421 0xcc71, 0x5aa3,
422 0xcc72, 0x2dc2,
423 0xcc73, 0x3002,
424 0xcc74, 0x1312,
425 0xcc75, 0x6f72,
426 0xcc76, 0x1002,
427 0xcc77, 0x2807,
428 0xcc78, 0x31a7,
429 0xcc79, 0x20c4,
430 0xcc7a, 0x3c24,
431 0xcc7b, 0x6724,
432 0xcc7c, 0x1002,
433 0xcc7d, 0x2807,
434 0xcc7e, 0x3187,
435 0xcc7f, 0x20c4,
436 0xcc80, 0x3c24,
437 0xcc81, 0x6724,
438 0xcc82, 0x1002,
439 0xcc83, 0x2514,
440 0xcc84, 0x3c64,
441 0xcc85, 0x6436,
442 0xcc86, 0xdff4,
443 0xcc87, 0x6436,
444 0xcc88, 0x1002,
445 0xcc89, 0x40a4,
446 0xcc8a, 0x643c,
447 0xcc8b, 0x4016,
448 0xcc8c, 0x8c6c,
449 0xcc8d, 0x2b24,
450 0xcc8e, 0x3c24,
451 0xcc8f, 0x6435,
452 0xcc90, 0x1002,
453 0xcc91, 0x2b24,
454 0xcc92, 0x3c24,
455 0xcc93, 0x643a,
456 0xcc94, 0x4025,
457 0xcc95, 0x8a5a,
458 0xcc96, 0x1002,
459 0xcc97, 0x2731,
460 0xcc98, 0x3011,
461 0xcc99, 0x1001,
462 0xcc9a, 0xc7a0,
463 0xcc9b, 0x100,
464 0xcc9c, 0xc502,
465 0xcc9d, 0x53ac,
466 0xcc9e, 0xc503,
467 0xcc9f, 0xd5d5,
468 0xcca0, 0xc600,
469 0xcca1, 0x2a6d,
470 0xcca2, 0xc601,
471 0xcca3, 0x2a4c,
472 0xcca4, 0xc602,
473 0xcca5, 0x111,
474 0xcca6, 0xc60c,
475 0xcca7, 0x5900,
476 0xcca8, 0xc710,
477 0xcca9, 0x700,
478 0xccaa, 0xc718,
479 0xccab, 0x700,
480 0xccac, 0xc720,
481 0xccad, 0x4700,
482 0xccae, 0xc801,
483 0xccaf, 0x7f50,
484 0xccb0, 0xc802,
485 0xccb1, 0x7760,
486 0xccb2, 0xc803,
487 0xccb3, 0x7fce,
488 0xccb4, 0xc804,
489 0xccb5, 0x5700,
490 0xccb6, 0xc805,
491 0xccb7, 0x5f11,
492 0xccb8, 0xc806,
493 0xccb9, 0x4751,
494 0xccba, 0xc807,
495 0xccbb, 0x57e1,
496 0xccbc, 0xc808,
497 0xccbd, 0x2700,
498 0xccbe, 0xc809,
499 0xccbf, 0x000,
500 0xccc0, 0xc821,
501 0xccc1, 0x002,
502 0xccc2, 0xc822,
503 0xccc3, 0x014,
504 0xccc4, 0xc832,
505 0xccc5, 0x1186,
506 0xccc6, 0xc847,
507 0xccc7, 0x1e02,
508 0xccc8, 0xc013,
509 0xccc9, 0xf341,
510 0xccca, 0xc01a,
511 0xcccb, 0x446,
512 0xcccc, 0xc024,
513 0xcccd, 0x1000,
514 0xccce, 0xc025,
515 0xcccf, 0xa00,
516 0xccd0, 0xc026,
517 0xccd1, 0xc0c,
518 0xccd2, 0xc027,
519 0xccd3, 0xc0c,
520 0xccd4, 0xc029,
521 0xccd5, 0x0a0,
522 0xccd6, 0xc030,
523 0xccd7, 0xa00,
524 0xccd8, 0xc03c,
525 0xccd9, 0x01c,
526 0xccda, 0xc005,
527 0xccdb, 0x7a06,
528 0xccdc, 0x000,
529 0xccdd, 0x2731,
530 0xccde, 0x3011,
531 0xccdf, 0x1001,
532 0xcce0, 0xc620,
533 0xcce1, 0x000,
534 0xcce2, 0xc621,
535 0xcce3, 0x03f,
536 0xcce4, 0xc622,
537 0xcce5, 0x000,
538 0xcce6, 0xc623,
539 0xcce7, 0x000,
540 0xcce8, 0xc624,
541 0xcce9, 0x000,
542 0xccea, 0xc625,
543 0xcceb, 0x000,
544 0xccec, 0xc627,
545 0xcced, 0x000,
546 0xccee, 0xc628,
547 0xccef, 0x000,
548 0xccf0, 0xc62c,
549 0xccf1, 0x000,
550 0xccf2, 0x000,
551 0xccf3, 0x2806,
552 0xccf4, 0x3cb6,
553 0xccf5, 0xc161,
554 0xccf6, 0x6134,
555 0xccf7, 0x6135,
556 0xccf8, 0x5443,
557 0xccf9, 0x303,
558 0xccfa, 0x6524,
559 0xccfb, 0x00b,
560 0xccfc, 0x1002,
561 0xccfd, 0x2104,
562 0xccfe, 0x3c24,
563 0xccff, 0x2105,
564 0xcd00, 0x3805,
565 0xcd01, 0x6524,
566 0xcd02, 0xdff4,
567 0xcd03, 0x4005,
568 0xcd04, 0x6524,
569 0xcd05, 0x1002,
570 0xcd06, 0x5dd3,
571 0xcd07, 0x306,
572 0xcd08, 0x2ff7,
573 0xcd09, 0x38f7,
574 0xcd0a, 0x60b7,
575 0xcd0b, 0xdffd,
576 0xcd0c, 0x00a,
577 0xcd0d, 0x1002,
578 0xcd0e, 0
579 };
580 int i, err; 302 int i, err;
581 303
582 err = set_phy_regs(phy, regs); 304 err = set_phy_regs(phy, regs);
@@ -585,9 +307,16 @@ static int ael2005_setup_sr_edc(struct cphy *phy)
585 307
586 msleep(50); 308 msleep(50);
587 309
588 for (i = 0; i < ARRAY_SIZE(sr_edc) && !err; i += 2) 310 if (phy->priv != edc_sr)
589 err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, sr_edc[i], 311 err = t3_get_edc_fw(phy, EDC_OPT_AEL2005,
590 sr_edc[i + 1]); 312 EDC_OPT_AEL2005_SIZE);
313 if (err)
314 return err;
315
316 for (i = 0; i < EDC_OPT_AEL2005_SIZE / sizeof(u16) && !err; i += 2)
317 err = t3_mdio_write(phy, MDIO_MMD_PMAPMD,
318 phy->phy_cache[i],
319 phy->phy_cache[i + 1]);
591 if (!err) 320 if (!err)
592 phy->priv = edc_sr; 321 phy->priv = edc_sr;
593 return err; 322 return err;
@@ -604,374 +333,6 @@ static int ael2005_setup_twinax_edc(struct cphy *phy, int modtype)
604 { MDIO_MMD_PMAPMD, 0xc015, 0xffff, 0xa000 }, 333 { MDIO_MMD_PMAPMD, 0xc015, 0xffff, 0xa000 },
605 { 0, 0, 0, 0 } 334 { 0, 0, 0, 0 }
606 }; 335 };
607 static u16 twinax_edc[] = {
608 0xcc00, 0x4009,
609 0xcc01, 0x27ff,
610 0xcc02, 0x300f,
611 0xcc03, 0x40aa,
612 0xcc04, 0x401c,
613 0xcc05, 0x401e,
614 0xcc06, 0x2ff4,
615 0xcc07, 0x3cd4,
616 0xcc08, 0x2035,
617 0xcc09, 0x3145,
618 0xcc0a, 0x6524,
619 0xcc0b, 0x26a2,
620 0xcc0c, 0x3012,
621 0xcc0d, 0x1002,
622 0xcc0e, 0x29c2,
623 0xcc0f, 0x3002,
624 0xcc10, 0x1002,
625 0xcc11, 0x2072,
626 0xcc12, 0x3012,
627 0xcc13, 0x1002,
628 0xcc14, 0x22cd,
629 0xcc15, 0x301d,
630 0xcc16, 0x2e52,
631 0xcc17, 0x3012,
632 0xcc18, 0x1002,
633 0xcc19, 0x28e2,
634 0xcc1a, 0x3002,
635 0xcc1b, 0x1002,
636 0xcc1c, 0x628f,
637 0xcc1d, 0x2ac2,
638 0xcc1e, 0x3012,
639 0xcc1f, 0x1002,
640 0xcc20, 0x5553,
641 0xcc21, 0x2ae2,
642 0xcc22, 0x3002,
643 0xcc23, 0x1302,
644 0xcc24, 0x401e,
645 0xcc25, 0x2be2,
646 0xcc26, 0x3012,
647 0xcc27, 0x1002,
648 0xcc28, 0x2da2,
649 0xcc29, 0x3012,
650 0xcc2a, 0x1002,
651 0xcc2b, 0x2ba2,
652 0xcc2c, 0x3002,
653 0xcc2d, 0x1002,
654 0xcc2e, 0x5ee3,
655 0xcc2f, 0x305,
656 0xcc30, 0x400e,
657 0xcc31, 0x2bc2,
658 0xcc32, 0x3002,
659 0xcc33, 0x1002,
660 0xcc34, 0x2b82,
661 0xcc35, 0x3012,
662 0xcc36, 0x1002,
663 0xcc37, 0x5663,
664 0xcc38, 0x302,
665 0xcc39, 0x401e,
666 0xcc3a, 0x6f72,
667 0xcc3b, 0x1002,
668 0xcc3c, 0x628f,
669 0xcc3d, 0x2be2,
670 0xcc3e, 0x3012,
671 0xcc3f, 0x1002,
672 0xcc40, 0x22cd,
673 0xcc41, 0x301d,
674 0xcc42, 0x2e52,
675 0xcc43, 0x3012,
676 0xcc44, 0x1002,
677 0xcc45, 0x2522,
678 0xcc46, 0x3012,
679 0xcc47, 0x1002,
680 0xcc48, 0x2da2,
681 0xcc49, 0x3012,
682 0xcc4a, 0x1002,
683 0xcc4b, 0x2ca2,
684 0xcc4c, 0x3012,
685 0xcc4d, 0x1002,
686 0xcc4e, 0x2fa4,
687 0xcc4f, 0x3cd4,
688 0xcc50, 0x6624,
689 0xcc51, 0x410b,
690 0xcc52, 0x56b3,
691 0xcc53, 0x3c4,
692 0xcc54, 0x2fb2,
693 0xcc55, 0x3002,
694 0xcc56, 0x1002,
695 0xcc57, 0x220b,
696 0xcc58, 0x303b,
697 0xcc59, 0x56b3,
698 0xcc5a, 0x3c3,
699 0xcc5b, 0x866b,
700 0xcc5c, 0x400c,
701 0xcc5d, 0x23a2,
702 0xcc5e, 0x3012,
703 0xcc5f, 0x1002,
704 0xcc60, 0x2da2,
705 0xcc61, 0x3012,
706 0xcc62, 0x1002,
707 0xcc63, 0x2ca2,
708 0xcc64, 0x3012,
709 0xcc65, 0x1002,
710 0xcc66, 0x2fb4,
711 0xcc67, 0x3cd4,
712 0xcc68, 0x6624,
713 0xcc69, 0x56b3,
714 0xcc6a, 0x3c3,
715 0xcc6b, 0x866b,
716 0xcc6c, 0x401c,
717 0xcc6d, 0x2205,
718 0xcc6e, 0x3035,
719 0xcc6f, 0x5b53,
720 0xcc70, 0x2c52,
721 0xcc71, 0x3002,
722 0xcc72, 0x13c2,
723 0xcc73, 0x5cc3,
724 0xcc74, 0x317,
725 0xcc75, 0x2522,
726 0xcc76, 0x3012,
727 0xcc77, 0x1002,
728 0xcc78, 0x2da2,
729 0xcc79, 0x3012,
730 0xcc7a, 0x1002,
731 0xcc7b, 0x2b82,
732 0xcc7c, 0x3012,
733 0xcc7d, 0x1002,
734 0xcc7e, 0x5663,
735 0xcc7f, 0x303,
736 0xcc80, 0x401e,
737 0xcc81, 0x004,
738 0xcc82, 0x2c42,
739 0xcc83, 0x3012,
740 0xcc84, 0x1002,
741 0xcc85, 0x6f72,
742 0xcc86, 0x1002,
743 0xcc87, 0x628f,
744 0xcc88, 0x2304,
745 0xcc89, 0x3c84,
746 0xcc8a, 0x6436,
747 0xcc8b, 0xdff4,
748 0xcc8c, 0x6436,
749 0xcc8d, 0x2ff5,
750 0xcc8e, 0x3005,
751 0xcc8f, 0x8656,
752 0xcc90, 0xdfba,
753 0xcc91, 0x56a3,
754 0xcc92, 0xd05a,
755 0xcc93, 0x21c2,
756 0xcc94, 0x3012,
757 0xcc95, 0x1392,
758 0xcc96, 0xd05a,
759 0xcc97, 0x56a3,
760 0xcc98, 0xdfba,
761 0xcc99, 0x383,
762 0xcc9a, 0x6f72,
763 0xcc9b, 0x1002,
764 0xcc9c, 0x28c5,
765 0xcc9d, 0x3005,
766 0xcc9e, 0x4178,
767 0xcc9f, 0x5653,
768 0xcca0, 0x384,
769 0xcca1, 0x22b2,
770 0xcca2, 0x3012,
771 0xcca3, 0x1002,
772 0xcca4, 0x2be5,
773 0xcca5, 0x3005,
774 0xcca6, 0x41e8,
775 0xcca7, 0x5653,
776 0xcca8, 0x382,
777 0xcca9, 0x002,
778 0xccaa, 0x4258,
779 0xccab, 0x2474,
780 0xccac, 0x3c84,
781 0xccad, 0x6437,
782 0xccae, 0xdff4,
783 0xccaf, 0x6437,
784 0xccb0, 0x2ff5,
785 0xccb1, 0x3c05,
786 0xccb2, 0x8757,
787 0xccb3, 0xb888,
788 0xccb4, 0x9787,
789 0xccb5, 0xdff4,
790 0xccb6, 0x6724,
791 0xccb7, 0x866a,
792 0xccb8, 0x6f72,
793 0xccb9, 0x1002,
794 0xccba, 0x2d01,
795 0xccbb, 0x3011,
796 0xccbc, 0x1001,
797 0xccbd, 0xc620,
798 0xccbe, 0x14e5,
799 0xccbf, 0xc621,
800 0xccc0, 0xc53d,
801 0xccc1, 0xc622,
802 0xccc2, 0x3cbe,
803 0xccc3, 0xc623,
804 0xccc4, 0x4452,
805 0xccc5, 0xc624,
806 0xccc6, 0xc5c5,
807 0xccc7, 0xc625,
808 0xccc8, 0xe01e,
809 0xccc9, 0xc627,
810 0xccca, 0x000,
811 0xcccb, 0xc628,
812 0xcccc, 0x000,
813 0xcccd, 0xc62b,
814 0xccce, 0x000,
815 0xcccf, 0xc62c,
816 0xccd0, 0x000,
817 0xccd1, 0x000,
818 0xccd2, 0x2d01,
819 0xccd3, 0x3011,
820 0xccd4, 0x1001,
821 0xccd5, 0xc620,
822 0xccd6, 0x000,
823 0xccd7, 0xc621,
824 0xccd8, 0x000,
825 0xccd9, 0xc622,
826 0xccda, 0x0ce,
827 0xccdb, 0xc623,
828 0xccdc, 0x07f,
829 0xccdd, 0xc624,
830 0xccde, 0x032,
831 0xccdf, 0xc625,
832 0xcce0, 0x000,
833 0xcce1, 0xc627,
834 0xcce2, 0x000,
835 0xcce3, 0xc628,
836 0xcce4, 0x000,
837 0xcce5, 0xc62b,
838 0xcce6, 0x000,
839 0xcce7, 0xc62c,
840 0xcce8, 0x000,
841 0xcce9, 0x000,
842 0xccea, 0x2d01,
843 0xcceb, 0x3011,
844 0xccec, 0x1001,
845 0xcced, 0xc502,
846 0xccee, 0x609f,
847 0xccef, 0xc600,
848 0xccf0, 0x2a6e,
849 0xccf1, 0xc601,
850 0xccf2, 0x2a2c,
851 0xccf3, 0xc60c,
852 0xccf4, 0x5400,
853 0xccf5, 0xc710,
854 0xccf6, 0x700,
855 0xccf7, 0xc718,
856 0xccf8, 0x700,
857 0xccf9, 0xc720,
858 0xccfa, 0x4700,
859 0xccfb, 0xc728,
860 0xccfc, 0x700,
861 0xccfd, 0xc729,
862 0xccfe, 0x1207,
863 0xccff, 0xc801,
864 0xcd00, 0x7f50,
865 0xcd01, 0xc802,
866 0xcd02, 0x7760,
867 0xcd03, 0xc803,
868 0xcd04, 0x7fce,
869 0xcd05, 0xc804,
870 0xcd06, 0x520e,
871 0xcd07, 0xc805,
872 0xcd08, 0x5c11,
873 0xcd09, 0xc806,
874 0xcd0a, 0x3c51,
875 0xcd0b, 0xc807,
876 0xcd0c, 0x4061,
877 0xcd0d, 0xc808,
878 0xcd0e, 0x49c1,
879 0xcd0f, 0xc809,
880 0xcd10, 0x3840,
881 0xcd11, 0xc80a,
882 0xcd12, 0x000,
883 0xcd13, 0xc821,
884 0xcd14, 0x002,
885 0xcd15, 0xc822,
886 0xcd16, 0x046,
887 0xcd17, 0xc844,
888 0xcd18, 0x182f,
889 0xcd19, 0xc013,
890 0xcd1a, 0xf341,
891 0xcd1b, 0xc01a,
892 0xcd1c, 0x446,
893 0xcd1d, 0xc024,
894 0xcd1e, 0x1000,
895 0xcd1f, 0xc025,
896 0xcd20, 0xa00,
897 0xcd21, 0xc026,
898 0xcd22, 0xc0c,
899 0xcd23, 0xc027,
900 0xcd24, 0xc0c,
901 0xcd25, 0xc029,
902 0xcd26, 0x0a0,
903 0xcd27, 0xc030,
904 0xcd28, 0xa00,
905 0xcd29, 0xc03c,
906 0xcd2a, 0x01c,
907 0xcd2b, 0x000,
908 0xcd2c, 0x2b84,
909 0xcd2d, 0x3c74,
910 0xcd2e, 0x6435,
911 0xcd2f, 0xdff4,
912 0xcd30, 0x6435,
913 0xcd31, 0x2806,
914 0xcd32, 0x3006,
915 0xcd33, 0x8565,
916 0xcd34, 0x2b24,
917 0xcd35, 0x3c24,
918 0xcd36, 0x6436,
919 0xcd37, 0x1002,
920 0xcd38, 0x2b24,
921 0xcd39, 0x3c24,
922 0xcd3a, 0x6436,
923 0xcd3b, 0x4045,
924 0xcd3c, 0x8656,
925 0xcd3d, 0x1002,
926 0xcd3e, 0x2807,
927 0xcd3f, 0x31a7,
928 0xcd40, 0x20c4,
929 0xcd41, 0x3c24,
930 0xcd42, 0x6724,
931 0xcd43, 0x1002,
932 0xcd44, 0x2807,
933 0xcd45, 0x3187,
934 0xcd46, 0x20c4,
935 0xcd47, 0x3c24,
936 0xcd48, 0x6724,
937 0xcd49, 0x1002,
938 0xcd4a, 0x2514,
939 0xcd4b, 0x3c64,
940 0xcd4c, 0x6436,
941 0xcd4d, 0xdff4,
942 0xcd4e, 0x6436,
943 0xcd4f, 0x1002,
944 0xcd50, 0x2806,
945 0xcd51, 0x3cb6,
946 0xcd52, 0xc161,
947 0xcd53, 0x6134,
948 0xcd54, 0x6135,
949 0xcd55, 0x5443,
950 0xcd56, 0x303,
951 0xcd57, 0x6524,
952 0xcd58, 0x00b,
953 0xcd59, 0x1002,
954 0xcd5a, 0xd019,
955 0xcd5b, 0x2104,
956 0xcd5c, 0x3c24,
957 0xcd5d, 0x2105,
958 0xcd5e, 0x3805,
959 0xcd5f, 0x6524,
960 0xcd60, 0xdff4,
961 0xcd61, 0x4005,
962 0xcd62, 0x6524,
963 0xcd63, 0x2e8d,
964 0xcd64, 0x303d,
965 0xcd65, 0x5dd3,
966 0xcd66, 0x306,
967 0xcd67, 0x2ff7,
968 0xcd68, 0x38f7,
969 0xcd69, 0x60b7,
970 0xcd6a, 0xdffd,
971 0xcd6b, 0x00a,
972 0xcd6c, 0x1002,
973 0xcd6d, 0
974 };
975 int i, err; 336 int i, err;
976 337
977 err = set_phy_regs(phy, regs); 338 err = set_phy_regs(phy, regs);
@@ -982,9 +343,16 @@ static int ael2005_setup_twinax_edc(struct cphy *phy, int modtype)
982 343
983 msleep(50); 344 msleep(50);
984 345
985 for (i = 0; i < ARRAY_SIZE(twinax_edc) && !err; i += 2) 346 if (phy->priv != edc_twinax)
986 err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, twinax_edc[i], 347 err = t3_get_edc_fw(phy, EDC_TWX_AEL2005,
987 twinax_edc[i + 1]); 348 EDC_TWX_AEL2005_SIZE);
349 if (err)
350 return err;
351
352 for (i = 0; i < EDC_TWX_AEL2005_SIZE / sizeof(u16) && !err; i += 2)
353 err = t3_mdio_write(phy, MDIO_MMD_PMAPMD,
354 phy->phy_cache[i],
355 phy->phy_cache[i + 1]);
988 if (!err) 356 if (!err)
989 phy->priv = edc_twinax; 357 phy->priv = edc_twinax;
990 return err; 358 return err;
@@ -1201,405 +569,6 @@ static int ael2020_setup_twinax_edc(struct cphy *phy, int modtype)
1201 { MDIO_MMD_PMAPMD, 0xd092, 0xffff, 0x0000 }, 569 { MDIO_MMD_PMAPMD, 0xd092, 0xffff, 0x0000 },
1202 { 0, 0, 0, 0 } 570 { 0, 0, 0, 0 }
1203 }; 571 };
1204
1205 /* TWINAX EDC firmware */
1206 static u16 twinax_edc[] = {
1207 0xd800, 0x4009,
1208 0xd801, 0x2fff,
1209 0xd802, 0x300f,
1210 0xd803, 0x40aa,
1211 0xd804, 0x401c,
1212 0xd805, 0x401e,
1213 0xd806, 0x2ff4,
1214 0xd807, 0x3dc4,
1215 0xd808, 0x2035,
1216 0xd809, 0x3035,
1217 0xd80a, 0x6524,
1218 0xd80b, 0x2cb2,
1219 0xd80c, 0x3012,
1220 0xd80d, 0x1002,
1221 0xd80e, 0x26e2,
1222 0xd80f, 0x3022,
1223 0xd810, 0x1002,
1224 0xd811, 0x27d2,
1225 0xd812, 0x3022,
1226 0xd813, 0x1002,
1227 0xd814, 0x2822,
1228 0xd815, 0x3012,
1229 0xd816, 0x1002,
1230 0xd817, 0x2492,
1231 0xd818, 0x3022,
1232 0xd819, 0x1002,
1233 0xd81a, 0x2772,
1234 0xd81b, 0x3012,
1235 0xd81c, 0x1002,
1236 0xd81d, 0x23d2,
1237 0xd81e, 0x3022,
1238 0xd81f, 0x1002,
1239 0xd820, 0x22cd,
1240 0xd821, 0x301d,
1241 0xd822, 0x27f2,
1242 0xd823, 0x3022,
1243 0xd824, 0x1002,
1244 0xd825, 0x5553,
1245 0xd826, 0x0307,
1246 0xd827, 0x2522,
1247 0xd828, 0x3022,
1248 0xd829, 0x1002,
1249 0xd82a, 0x2142,
1250 0xd82b, 0x3012,
1251 0xd82c, 0x1002,
1252 0xd82d, 0x4016,
1253 0xd82e, 0x5e63,
1254 0xd82f, 0x0344,
1255 0xd830, 0x2142,
1256 0xd831, 0x3012,
1257 0xd832, 0x1002,
1258 0xd833, 0x400e,
1259 0xd834, 0x2522,
1260 0xd835, 0x3022,
1261 0xd836, 0x1002,
1262 0xd837, 0x2b52,
1263 0xd838, 0x3012,
1264 0xd839, 0x1002,
1265 0xd83a, 0x2742,
1266 0xd83b, 0x3022,
1267 0xd83c, 0x1002,
1268 0xd83d, 0x25e2,
1269 0xd83e, 0x3022,
1270 0xd83f, 0x1002,
1271 0xd840, 0x2fa4,
1272 0xd841, 0x3dc4,
1273 0xd842, 0x6624,
1274 0xd843, 0x414b,
1275 0xd844, 0x56b3,
1276 0xd845, 0x03c6,
1277 0xd846, 0x866b,
1278 0xd847, 0x400c,
1279 0xd848, 0x2712,
1280 0xd849, 0x3012,
1281 0xd84a, 0x1002,
1282 0xd84b, 0x2c4b,
1283 0xd84c, 0x309b,
1284 0xd84d, 0x56b3,
1285 0xd84e, 0x03c3,
1286 0xd84f, 0x866b,
1287 0xd850, 0x400c,
1288 0xd851, 0x2272,
1289 0xd852, 0x3022,
1290 0xd853, 0x1002,
1291 0xd854, 0x2742,
1292 0xd855, 0x3022,
1293 0xd856, 0x1002,
1294 0xd857, 0x25e2,
1295 0xd858, 0x3022,
1296 0xd859, 0x1002,
1297 0xd85a, 0x2fb4,
1298 0xd85b, 0x3dc4,
1299 0xd85c, 0x6624,
1300 0xd85d, 0x56b3,
1301 0xd85e, 0x03c3,
1302 0xd85f, 0x866b,
1303 0xd860, 0x401c,
1304 0xd861, 0x2c45,
1305 0xd862, 0x3095,
1306 0xd863, 0x5b53,
1307 0xd864, 0x2372,
1308 0xd865, 0x3012,
1309 0xd866, 0x13c2,
1310 0xd867, 0x5cc3,
1311 0xd868, 0x2712,
1312 0xd869, 0x3012,
1313 0xd86a, 0x1312,
1314 0xd86b, 0x2b52,
1315 0xd86c, 0x3012,
1316 0xd86d, 0x1002,
1317 0xd86e, 0x2742,
1318 0xd86f, 0x3022,
1319 0xd870, 0x1002,
1320 0xd871, 0x2582,
1321 0xd872, 0x3022,
1322 0xd873, 0x1002,
1323 0xd874, 0x2142,
1324 0xd875, 0x3012,
1325 0xd876, 0x1002,
1326 0xd877, 0x628f,
1327 0xd878, 0x2985,
1328 0xd879, 0x33a5,
1329 0xd87a, 0x25e2,
1330 0xd87b, 0x3022,
1331 0xd87c, 0x1002,
1332 0xd87d, 0x5653,
1333 0xd87e, 0x03d2,
1334 0xd87f, 0x401e,
1335 0xd880, 0x6f72,
1336 0xd881, 0x1002,
1337 0xd882, 0x628f,
1338 0xd883, 0x2304,
1339 0xd884, 0x3c84,
1340 0xd885, 0x6436,
1341 0xd886, 0xdff4,
1342 0xd887, 0x6436,
1343 0xd888, 0x2ff5,
1344 0xd889, 0x3005,
1345 0xd88a, 0x8656,
1346 0xd88b, 0xdfba,
1347 0xd88c, 0x56a3,
1348 0xd88d, 0xd05a,
1349 0xd88e, 0x2972,
1350 0xd88f, 0x3012,
1351 0xd890, 0x1392,
1352 0xd891, 0xd05a,
1353 0xd892, 0x56a3,
1354 0xd893, 0xdfba,
1355 0xd894, 0x0383,
1356 0xd895, 0x6f72,
1357 0xd896, 0x1002,
1358 0xd897, 0x2b45,
1359 0xd898, 0x3005,
1360 0xd899, 0x4178,
1361 0xd89a, 0x5653,
1362 0xd89b, 0x0384,
1363 0xd89c, 0x2a62,
1364 0xd89d, 0x3012,
1365 0xd89e, 0x1002,
1366 0xd89f, 0x2f05,
1367 0xd8a0, 0x3005,
1368 0xd8a1, 0x41c8,
1369 0xd8a2, 0x5653,
1370 0xd8a3, 0x0382,
1371 0xd8a4, 0x0002,
1372 0xd8a5, 0x4218,
1373 0xd8a6, 0x2474,
1374 0xd8a7, 0x3c84,
1375 0xd8a8, 0x6437,
1376 0xd8a9, 0xdff4,
1377 0xd8aa, 0x6437,
1378 0xd8ab, 0x2ff5,
1379 0xd8ac, 0x3c05,
1380 0xd8ad, 0x8757,
1381 0xd8ae, 0xb888,
1382 0xd8af, 0x9787,
1383 0xd8b0, 0xdff4,
1384 0xd8b1, 0x6724,
1385 0xd8b2, 0x866a,
1386 0xd8b3, 0x6f72,
1387 0xd8b4, 0x1002,
1388 0xd8b5, 0x2641,
1389 0xd8b6, 0x3021,
1390 0xd8b7, 0x1001,
1391 0xd8b8, 0xc620,
1392 0xd8b9, 0x0000,
1393 0xd8ba, 0xc621,
1394 0xd8bb, 0x0000,
1395 0xd8bc, 0xc622,
1396 0xd8bd, 0x00ce,
1397 0xd8be, 0xc623,
1398 0xd8bf, 0x007f,
1399 0xd8c0, 0xc624,
1400 0xd8c1, 0x0032,
1401 0xd8c2, 0xc625,
1402 0xd8c3, 0x0000,
1403 0xd8c4, 0xc627,
1404 0xd8c5, 0x0000,
1405 0xd8c6, 0xc628,
1406 0xd8c7, 0x0000,
1407 0xd8c8, 0xc62c,
1408 0xd8c9, 0x0000,
1409 0xd8ca, 0x0000,
1410 0xd8cb, 0x2641,
1411 0xd8cc, 0x3021,
1412 0xd8cd, 0x1001,
1413 0xd8ce, 0xc502,
1414 0xd8cf, 0x53ac,
1415 0xd8d0, 0xc503,
1416 0xd8d1, 0x2cd3,
1417 0xd8d2, 0xc600,
1418 0xd8d3, 0x2a6e,
1419 0xd8d4, 0xc601,
1420 0xd8d5, 0x2a2c,
1421 0xd8d6, 0xc605,
1422 0xd8d7, 0x5557,
1423 0xd8d8, 0xc60c,
1424 0xd8d9, 0x5400,
1425 0xd8da, 0xc710,
1426 0xd8db, 0x0700,
1427 0xd8dc, 0xc711,
1428 0xd8dd, 0x0f06,
1429 0xd8de, 0xc718,
1430 0xd8df, 0x0700,
1431 0xd8e0, 0xc719,
1432 0xd8e1, 0x0f06,
1433 0xd8e2, 0xc720,
1434 0xd8e3, 0x4700,
1435 0xd8e4, 0xc721,
1436 0xd8e5, 0x0f06,
1437 0xd8e6, 0xc728,
1438 0xd8e7, 0x0700,
1439 0xd8e8, 0xc729,
1440 0xd8e9, 0x1207,
1441 0xd8ea, 0xc801,
1442 0xd8eb, 0x7f50,
1443 0xd8ec, 0xc802,
1444 0xd8ed, 0x7760,
1445 0xd8ee, 0xc803,
1446 0xd8ef, 0x7fce,
1447 0xd8f0, 0xc804,
1448 0xd8f1, 0x520e,
1449 0xd8f2, 0xc805,
1450 0xd8f3, 0x5c11,
1451 0xd8f4, 0xc806,
1452 0xd8f5, 0x3c51,
1453 0xd8f6, 0xc807,
1454 0xd8f7, 0x4061,
1455 0xd8f8, 0xc808,
1456 0xd8f9, 0x49c1,
1457 0xd8fa, 0xc809,
1458 0xd8fb, 0x3840,
1459 0xd8fc, 0xc80a,
1460 0xd8fd, 0x0000,
1461 0xd8fe, 0xc821,
1462 0xd8ff, 0x0002,
1463 0xd900, 0xc822,
1464 0xd901, 0x0046,
1465 0xd902, 0xc844,
1466 0xd903, 0x182f,
1467 0xd904, 0xc013,
1468 0xd905, 0xf341,
1469 0xd906, 0xc084,
1470 0xd907, 0x0030,
1471 0xd908, 0xc904,
1472 0xd909, 0x1401,
1473 0xd90a, 0xcb0c,
1474 0xd90b, 0x0004,
1475 0xd90c, 0xcb0e,
1476 0xd90d, 0xa00a,
1477 0xd90e, 0xcb0f,
1478 0xd90f, 0xc0c0,
1479 0xd910, 0xcb10,
1480 0xd911, 0xc0c0,
1481 0xd912, 0xcb11,
1482 0xd913, 0x00a0,
1483 0xd914, 0xcb12,
1484 0xd915, 0x0007,
1485 0xd916, 0xc241,
1486 0xd917, 0xa000,
1487 0xd918, 0xc243,
1488 0xd919, 0x7fe0,
1489 0xd91a, 0xc604,
1490 0xd91b, 0x000e,
1491 0xd91c, 0xc609,
1492 0xd91d, 0x00f5,
1493 0xd91e, 0xc611,
1494 0xd91f, 0x000e,
1495 0xd920, 0xc660,
1496 0xd921, 0x9600,
1497 0xd922, 0xc687,
1498 0xd923, 0x0004,
1499 0xd924, 0xc60a,
1500 0xd925, 0x04f5,
1501 0xd926, 0x0000,
1502 0xd927, 0x2641,
1503 0xd928, 0x3021,
1504 0xd929, 0x1001,
1505 0xd92a, 0xc620,
1506 0xd92b, 0x14e5,
1507 0xd92c, 0xc621,
1508 0xd92d, 0xc53d,
1509 0xd92e, 0xc622,
1510 0xd92f, 0x3cbe,
1511 0xd930, 0xc623,
1512 0xd931, 0x4452,
1513 0xd932, 0xc624,
1514 0xd933, 0xc5c5,
1515 0xd934, 0xc625,
1516 0xd935, 0xe01e,
1517 0xd936, 0xc627,
1518 0xd937, 0x0000,
1519 0xd938, 0xc628,
1520 0xd939, 0x0000,
1521 0xd93a, 0xc62c,
1522 0xd93b, 0x0000,
1523 0xd93c, 0x0000,
1524 0xd93d, 0x2b84,
1525 0xd93e, 0x3c74,
1526 0xd93f, 0x6435,
1527 0xd940, 0xdff4,
1528 0xd941, 0x6435,
1529 0xd942, 0x2806,
1530 0xd943, 0x3006,
1531 0xd944, 0x8565,
1532 0xd945, 0x2b24,
1533 0xd946, 0x3c24,
1534 0xd947, 0x6436,
1535 0xd948, 0x1002,
1536 0xd949, 0x2b24,
1537 0xd94a, 0x3c24,
1538 0xd94b, 0x6436,
1539 0xd94c, 0x4045,
1540 0xd94d, 0x8656,
1541 0xd94e, 0x5663,
1542 0xd94f, 0x0302,
1543 0xd950, 0x401e,
1544 0xd951, 0x1002,
1545 0xd952, 0x2807,
1546 0xd953, 0x31a7,
1547 0xd954, 0x20c4,
1548 0xd955, 0x3c24,
1549 0xd956, 0x6724,
1550 0xd957, 0x1002,
1551 0xd958, 0x2807,
1552 0xd959, 0x3187,
1553 0xd95a, 0x20c4,
1554 0xd95b, 0x3c24,
1555 0xd95c, 0x6724,
1556 0xd95d, 0x1002,
1557 0xd95e, 0x24f4,
1558 0xd95f, 0x3c64,
1559 0xd960, 0x6436,
1560 0xd961, 0xdff4,
1561 0xd962, 0x6436,
1562 0xd963, 0x1002,
1563 0xd964, 0x2006,
1564 0xd965, 0x3d76,
1565 0xd966, 0xc161,
1566 0xd967, 0x6134,
1567 0xd968, 0x6135,
1568 0xd969, 0x5443,
1569 0xd96a, 0x0303,
1570 0xd96b, 0x6524,
1571 0xd96c, 0x00fb,
1572 0xd96d, 0x1002,
1573 0xd96e, 0x20d4,
1574 0xd96f, 0x3c24,
1575 0xd970, 0x2025,
1576 0xd971, 0x3005,
1577 0xd972, 0x6524,
1578 0xd973, 0x1002,
1579 0xd974, 0xd019,
1580 0xd975, 0x2104,
1581 0xd976, 0x3c24,
1582 0xd977, 0x2105,
1583 0xd978, 0x3805,
1584 0xd979, 0x6524,
1585 0xd97a, 0xdff4,
1586 0xd97b, 0x4005,
1587 0xd97c, 0x6524,
1588 0xd97d, 0x2e8d,
1589 0xd97e, 0x303d,
1590 0xd97f, 0x2408,
1591 0xd980, 0x35d8,
1592 0xd981, 0x5dd3,
1593 0xd982, 0x0307,
1594 0xd983, 0x8887,
1595 0xd984, 0x63a7,
1596 0xd985, 0x8887,
1597 0xd986, 0x63a7,
1598 0xd987, 0xdffd,
1599 0xd988, 0x00f9,
1600 0xd989, 0x1002,
1601 0xd98a, 0x0000,
1602 };
1603 int i, err; 572 int i, err;
1604 573
1605 /* set uC clock and activate it */ 574 /* set uC clock and activate it */
@@ -1612,10 +581,16 @@ static int ael2020_setup_twinax_edc(struct cphy *phy, int modtype)
1612 if (err) 581 if (err)
1613 return err; 582 return err;
1614 583
1615 /* write TWINAX EDC firmware into PHY */ 584 if (phy->priv != edc_twinax)
1616 for (i = 0; i < ARRAY_SIZE(twinax_edc) && !err; i += 2) 585 err = t3_get_edc_fw(phy, EDC_TWX_AEL2020,
1617 err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, twinax_edc[i], 586 EDC_TWX_AEL2020_SIZE);
1618 twinax_edc[i + 1]); 587 if (err)
588 return err;
589
590 for (i = 0; i < EDC_TWX_AEL2020_SIZE / sizeof(u16) && !err; i += 2)
591 err = t3_mdio_write(phy, MDIO_MMD_PMAPMD,
592 phy->phy_cache[i],
593 phy->phy_cache[i + 1]);
1619 /* activate uC */ 594 /* activate uC */
1620 err = set_phy_regs(phy, uCactivate); 595 err = set_phy_regs(phy, uCactivate);
1621 if (!err) 596 if (!err)
@@ -1649,9 +624,39 @@ static int ael2020_get_module_type(struct cphy *phy, int delay_ms)
1649 */ 624 */
1650static int ael2020_intr_enable(struct cphy *phy) 625static int ael2020_intr_enable(struct cphy *phy)
1651{ 626{
1652 int err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL, 627 struct reg_val regs[] = {
1653 0x2 << (AEL2020_GPIO_MODDET*4)); 628 /* output Module's Loss Of Signal (LOS) to LED */
1654 return err ? err : t3_phy_lasi_intr_enable(phy); 629 { MDIO_MMD_PMAPMD, AEL2020_GPIO_CFG+AEL2020_GPIO_LSTAT,
630 0xffff, 0x4 },
631 { MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
632 0xffff, 0x8 << (AEL2020_GPIO_LSTAT*4) },
633
634 /* enable module detect status change interrupts */
635 { MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
636 0xffff, 0x2 << (AEL2020_GPIO_MODDET*4) },
637
638 /* end */
639 { 0, 0, 0, 0 }
640 };
641 int err, link_ok = 0;
642
643 /* set up "link status" LED and enable module change interrupts */
644 err = set_phy_regs(phy, regs);
645 if (err)
646 return err;
647
648 err = get_link_status_r(phy, &link_ok, NULL, NULL, NULL);
649 if (err)
650 return err;
651 if (link_ok)
652 t3_link_changed(phy->adapter,
653 phy2portid(phy));
654
655 err = t3_phy_lasi_intr_enable(phy);
656 if (err)
657 return err;
658
659 return 0;
1655} 660}
1656 661
1657/* 662/*
@@ -1659,9 +664,26 @@ static int ael2020_intr_enable(struct cphy *phy)
1659 */ 664 */
1660static int ael2020_intr_disable(struct cphy *phy) 665static int ael2020_intr_disable(struct cphy *phy)
1661{ 666{
1662 int err = t3_mdio_write(phy, MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL, 667 struct reg_val regs[] = {
1663 0x1 << (AEL2020_GPIO_MODDET*4)); 668 /* reset "link status" LED to "off" */
1664 return err ? err : t3_phy_lasi_intr_disable(phy); 669 { MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
670 0xffff, 0xb << (AEL2020_GPIO_LSTAT*4) },
671
672 /* disable module detect status change interrupts */
673 { MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
674 0xffff, 0x1 << (AEL2020_GPIO_MODDET*4) },
675
676 /* end */
677 { 0, 0, 0, 0 }
678 };
679 int err;
680
681 /* turn off "link status" LED and disable module change interrupts */
682 err = set_phy_regs(phy, regs);
683 if (err)
684 return err;
685
686 return t3_phy_lasi_intr_disable(phy);
1665} 687}
1666 688
1667/* 689/*
@@ -1679,31 +701,26 @@ static int ael2020_intr_clear(struct cphy *phy)
1679 return err ? err : t3_phy_lasi_intr_clear(phy); 701 return err ? err : t3_phy_lasi_intr_clear(phy);
1680} 702}
1681 703
704static struct reg_val ael2020_reset_regs[] = {
705 /* Erratum #2: CDRLOL asserted, causing PMA link down status */
706 { MDIO_MMD_PMAPMD, 0xc003, 0xffff, 0x3101 },
707
708 /* force XAUI to send LF when RX_LOS is asserted */
709 { MDIO_MMD_PMAPMD, 0xcd40, 0xffff, 0x0001 },
710
711 /* allow writes to transceiver module EEPROM on i2c bus */
712 { MDIO_MMD_PMAPMD, 0xff02, 0xffff, 0x0023 },
713 { MDIO_MMD_PMAPMD, 0xff03, 0xffff, 0x0000 },
714 { MDIO_MMD_PMAPMD, 0xff04, 0xffff, 0x0000 },
715
716 /* end */
717 { 0, 0, 0, 0 }
718};
1682/* 719/*
1683 * Reset the PHY and put it into a canonical operating state. 720 * Reset the PHY and put it into a canonical operating state.
1684 */ 721 */
1685static int ael2020_reset(struct cphy *phy, int wait) 722static int ael2020_reset(struct cphy *phy, int wait)
1686{ 723{
1687 static struct reg_val regs0[] = {
1688 /* Erratum #2: CDRLOL asserted, causing PMA link down status */
1689 { MDIO_MMD_PMAPMD, 0xc003, 0xffff, 0x3101 },
1690
1691 /* force XAUI to send LF when RX_LOS is asserted */
1692 { MDIO_MMD_PMAPMD, 0xcd40, 0xffff, 0x0001 },
1693
1694 /* RX_LOS pin is active high */
1695 { MDIO_MMD_PMAPMD, AEL_OPT_SETTINGS,
1696 0x0020, 0x0020 },
1697
1698 /* output Module's Loss Of Signal (LOS) to LED */
1699 { MDIO_MMD_PMAPMD, AEL2020_GPIO_CFG+AEL2020_GPIO_LSTAT,
1700 0xffff, 0x0004 },
1701 { MDIO_MMD_PMAPMD, AEL2020_GPIO_CTRL,
1702 0xffff, 0x8 << (AEL2020_GPIO_LSTAT*4) },
1703
1704 /* end */
1705 { 0, 0, 0, 0 }
1706 };
1707 int err; 724 int err;
1708 unsigned int lasi_ctrl; 725 unsigned int lasi_ctrl;
1709 726
@@ -1720,7 +737,7 @@ static int ael2020_reset(struct cphy *phy, int wait)
1720 737
1721 /* basic initialization for all module types */ 738 /* basic initialization for all module types */
1722 phy->priv = edc_none; 739 phy->priv = edc_none;
1723 err = set_phy_regs(phy, regs0); 740 err = set_phy_regs(phy, ael2020_reset_regs);
1724 if (err) 741 if (err)
1725 return err; 742 return err;
1726 743
@@ -1798,10 +815,16 @@ static struct cphy_ops ael2020_ops = {
1798int t3_ael2020_phy_prep(struct cphy *phy, struct adapter *adapter, int phy_addr, 815int t3_ael2020_phy_prep(struct cphy *phy, struct adapter *adapter, int phy_addr,
1799 const struct mdio_ops *mdio_ops) 816 const struct mdio_ops *mdio_ops)
1800{ 817{
818 int err;
819
1801 cphy_init(phy, adapter, phy_addr, &ael2020_ops, mdio_ops, 820 cphy_init(phy, adapter, phy_addr, &ael2020_ops, mdio_ops,
1802 SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE | 821 SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE |
1803 SUPPORTED_IRQ, "10GBASE-R"); 822 SUPPORTED_IRQ, "10GBASE-R");
1804 msleep(125); 823 msleep(125);
824
825 err = set_phy_regs(phy, ael2020_reset_regs);
826 if (err)
827 return err;
1805 return 0; 828 return 0;
1806} 829}
1807 830
@@ -1840,7 +863,7 @@ static struct cphy_ops qt2045_ops = {
1840 .intr_clear = t3_phy_lasi_intr_clear, 863 .intr_clear = t3_phy_lasi_intr_clear,
1841 .intr_handler = t3_phy_lasi_intr_handler, 864 .intr_handler = t3_phy_lasi_intr_handler,
1842 .get_link_status = get_link_status_x, 865 .get_link_status = get_link_status_x,
1843 .power_down = ael1006_power_down, 866 .power_down = ael1002_power_down,
1844 .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS, 867 .mmds = MDIO_DEVS_PMAPMD | MDIO_DEVS_PCS | MDIO_DEVS_PHYXS,
1845}; 868};
1846 869
diff --git a/drivers/net/cxgb3/aq100x.c b/drivers/net/cxgb3/aq100x.c
index b1fd5bf836e4..341b7ef1508f 100644
--- a/drivers/net/cxgb3/aq100x.c
+++ b/drivers/net/cxgb3/aq100x.c
@@ -271,7 +271,8 @@ int t3_aq100x_phy_prep(struct cphy *phy, struct adapter *adapter, int phy_addr,
271 271
272 cphy_init(phy, adapter, phy_addr, &aq100x_ops, mdio_ops, 272 cphy_init(phy, adapter, phy_addr, &aq100x_ops, mdio_ops,
273 SUPPORTED_1000baseT_Full | SUPPORTED_10000baseT_Full | 273 SUPPORTED_1000baseT_Full | SUPPORTED_10000baseT_Full |
274 SUPPORTED_Autoneg | SUPPORTED_AUI, "1000/10GBASE-T"); 274 SUPPORTED_TP | SUPPORTED_Autoneg | SUPPORTED_AUI,
275 "1000/10GBASE-T");
275 276
276 /* 277 /*
277 * The PHY has been out of reset ever since the system powered up. So 278 * The PHY has been out of reset ever since the system powered up. So
@@ -316,11 +317,9 @@ int t3_aq100x_phy_prep(struct cphy *phy, struct adapter *adapter, int phy_addr,
316 317
317 /* Firmware version check. */ 318 /* Firmware version check. */
318 t3_mdio_read(phy, MDIO_MMD_VEND1, AQ_FW_VERSION, &v); 319 t3_mdio_read(phy, MDIO_MMD_VEND1, AQ_FW_VERSION, &v);
319 if (v != 30) { 320 if (v != 101)
320 CH_WARN(adapter, "PHY%d: unsupported firmware %d\n", 321 CH_WARN(adapter, "PHY%d: unsupported firmware %d\n",
321 phy_addr, v); 322 phy_addr, v);
322 return 0; /* allow t3_prep_adapter to succeed */
323 }
324 323
325 /* 324 /*
326 * The PHY should start in really-low-power mode. Prepare it for normal 325 * The PHY should start in really-low-power mode. Prepare it for normal
diff --git a/drivers/net/cxgb3/common.h b/drivers/net/cxgb3/common.h
index d21b705501a9..1b2c305fb82b 100644
--- a/drivers/net/cxgb3/common.h
+++ b/drivers/net/cxgb3/common.h
@@ -566,6 +566,15 @@ struct cphy_ops {
566 566
567 u32 mmds; 567 u32 mmds;
568}; 568};
569enum {
570 EDC_OPT_AEL2005 = 0,
571 EDC_OPT_AEL2005_SIZE = 1084,
572 EDC_TWX_AEL2005 = 1,
573 EDC_TWX_AEL2005_SIZE = 1464,
574 EDC_TWX_AEL2020 = 2,
575 EDC_TWX_AEL2020_SIZE = 1628,
576 EDC_MAX_SIZE = EDC_TWX_AEL2020_SIZE, /* Max cache size */
577};
569 578
570/* A PHY instance */ 579/* A PHY instance */
571struct cphy { 580struct cphy {
@@ -577,6 +586,7 @@ struct cphy {
577 unsigned long fifo_errors; /* FIFO over/under-flows */ 586 unsigned long fifo_errors; /* FIFO over/under-flows */
578 const struct cphy_ops *ops; /* PHY operations */ 587 const struct cphy_ops *ops; /* PHY operations */
579 struct mdio_if_info mdio; 588 struct mdio_if_info mdio;
589 u16 phy_cache[EDC_MAX_SIZE]; /* EDC cache */
580}; 590};
581 591
582/* Convenience MDIO read/write wrappers */ 592/* Convenience MDIO read/write wrappers */
diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c
index fb5df5c6203e..ec05149a9065 100644
--- a/drivers/net/cxgb3/cxgb3_main.c
+++ b/drivers/net/cxgb3/cxgb3_main.c
@@ -172,6 +172,23 @@ static void link_report(struct net_device *dev)
172 } 172 }
173} 173}
174 174
175static void enable_tx_fifo_drain(struct adapter *adapter,
176 struct port_info *pi)
177{
178 t3_set_reg_field(adapter, A_XGM_TXFIFO_CFG + pi->mac.offset, 0,
179 F_ENDROPPKT);
180 t3_write_reg(adapter, A_XGM_RX_CTRL + pi->mac.offset, 0);
181 t3_write_reg(adapter, A_XGM_TX_CTRL + pi->mac.offset, F_TXEN);
182 t3_write_reg(adapter, A_XGM_RX_CTRL + pi->mac.offset, F_RXEN);
183}
184
185static void disable_tx_fifo_drain(struct adapter *adapter,
186 struct port_info *pi)
187{
188 t3_set_reg_field(adapter, A_XGM_TXFIFO_CFG + pi->mac.offset,
189 F_ENDROPPKT, 0);
190}
191
175void t3_os_link_fault(struct adapter *adap, int port_id, int state) 192void t3_os_link_fault(struct adapter *adap, int port_id, int state)
176{ 193{
177 struct net_device *dev = adap->port[port_id]; 194 struct net_device *dev = adap->port[port_id];
@@ -185,6 +202,8 @@ void t3_os_link_fault(struct adapter *adap, int port_id, int state)
185 202
186 netif_carrier_on(dev); 203 netif_carrier_on(dev);
187 204
205 disable_tx_fifo_drain(adap, pi);
206
188 /* Clear local faults */ 207 /* Clear local faults */
189 t3_xgm_intr_disable(adap, pi->port_id); 208 t3_xgm_intr_disable(adap, pi->port_id);
190 t3_read_reg(adap, A_XGM_INT_STATUS + 209 t3_read_reg(adap, A_XGM_INT_STATUS +
@@ -200,9 +219,12 @@ void t3_os_link_fault(struct adapter *adap, int port_id, int state)
200 t3_xgm_intr_enable(adap, pi->port_id); 219 t3_xgm_intr_enable(adap, pi->port_id);
201 220
202 t3_mac_enable(mac, MAC_DIRECTION_TX); 221 t3_mac_enable(mac, MAC_DIRECTION_TX);
203 } else 222 } else {
204 netif_carrier_off(dev); 223 netif_carrier_off(dev);
205 224
225 /* Flush TX FIFO */
226 enable_tx_fifo_drain(adap, pi);
227 }
206 link_report(dev); 228 link_report(dev);
207} 229}
208 230
@@ -232,6 +254,8 @@ void t3_os_link_changed(struct adapter *adapter, int port_id, int link_stat,
232 254
233 if (link_stat != netif_carrier_ok(dev)) { 255 if (link_stat != netif_carrier_ok(dev)) {
234 if (link_stat) { 256 if (link_stat) {
257 disable_tx_fifo_drain(adapter, pi);
258
235 t3_mac_enable(mac, MAC_DIRECTION_RX); 259 t3_mac_enable(mac, MAC_DIRECTION_RX);
236 260
237 /* Clear local faults */ 261 /* Clear local faults */
@@ -263,6 +287,9 @@ void t3_os_link_changed(struct adapter *adapter, int port_id, int link_stat,
263 t3_read_reg(adapter, A_XGM_INT_STATUS + pi->mac.offset); 287 t3_read_reg(adapter, A_XGM_INT_STATUS + pi->mac.offset);
264 t3_mac_disable(mac, MAC_DIRECTION_RX); 288 t3_mac_disable(mac, MAC_DIRECTION_RX);
265 t3_link_start(&pi->phy, mac, &pi->link_config); 289 t3_link_start(&pi->phy, mac, &pi->link_config);
290
291 /* Flush TX FIFO */
292 enable_tx_fifo_drain(adapter, pi);
266 } 293 }
267 294
268 link_report(dev); 295 link_report(dev);
@@ -443,6 +470,7 @@ static int init_tp_parity(struct adapter *adap)
443 memset(req, 0, sizeof(*req)); 470 memset(req, 0, sizeof(*req));
444 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); 471 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
445 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SMT_WRITE_REQ, i)); 472 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SMT_WRITE_REQ, i));
473 req->mtu_idx = NMTUS - 1;
446 req->iff = i; 474 req->iff = i;
447 t3_mgmt_tx(adap, skb); 475 t3_mgmt_tx(adap, skb);
448 if (skb == adap->nofail_skb) { 476 if (skb == adap->nofail_skb) {
@@ -963,6 +991,75 @@ static int bind_qsets(struct adapter *adap)
963 991
964#define FW_FNAME "cxgb3/t3fw-%d.%d.%d.bin" 992#define FW_FNAME "cxgb3/t3fw-%d.%d.%d.bin"
965#define TPSRAM_NAME "cxgb3/t3%c_psram-%d.%d.%d.bin" 993#define TPSRAM_NAME "cxgb3/t3%c_psram-%d.%d.%d.bin"
994#define AEL2005_OPT_EDC_NAME "cxgb3/ael2005_opt_edc.bin"
995#define AEL2005_TWX_EDC_NAME "cxgb3/ael2005_twx_edc.bin"
996#define AEL2020_TWX_EDC_NAME "cxgb3/ael2005_twx_edc.bin"
997
998static inline const char *get_edc_fw_name(int edc_idx)
999{
1000 const char *fw_name = NULL;
1001
1002 switch (edc_idx) {
1003 case EDC_OPT_AEL2005:
1004 fw_name = AEL2005_OPT_EDC_NAME;
1005 break;
1006 case EDC_TWX_AEL2005:
1007 fw_name = AEL2005_TWX_EDC_NAME;
1008 break;
1009 case EDC_TWX_AEL2020:
1010 fw_name = AEL2020_TWX_EDC_NAME;
1011 break;
1012 }
1013 return fw_name;
1014}
1015
1016int t3_get_edc_fw(struct cphy *phy, int edc_idx, int size)
1017{
1018 struct adapter *adapter = phy->adapter;
1019 const struct firmware *fw;
1020 char buf[64];
1021 u32 csum;
1022 const __be32 *p;
1023 u16 *cache = phy->phy_cache;
1024 int i, ret;
1025
1026 snprintf(buf, sizeof(buf), get_edc_fw_name(edc_idx));
1027
1028 ret = request_firmware(&fw, buf, &adapter->pdev->dev);
1029 if (ret < 0) {
1030 dev_err(&adapter->pdev->dev,
1031 "could not upgrade firmware: unable to load %s\n",
1032 buf);
1033 return ret;
1034 }
1035
1036 /* check size, take checksum in account */
1037 if (fw->size > size + 4) {
1038 CH_ERR(adapter, "firmware image too large %u, expected %d\n",
1039 (unsigned int)fw->size, size + 4);
1040 ret = -EINVAL;
1041 }
1042
1043 /* compute checksum */
1044 p = (const __be32 *)fw->data;
1045 for (csum = 0, i = 0; i < fw->size / sizeof(csum); i++)
1046 csum += ntohl(p[i]);
1047
1048 if (csum != 0xffffffff) {
1049 CH_ERR(adapter, "corrupted firmware image, checksum %u\n",
1050 csum);
1051 ret = -EINVAL;
1052 }
1053
1054 for (i = 0; i < size / 4 ; i++) {
1055 *cache++ = (be32_to_cpu(p[i]) & 0xffff0000) >> 16;
1056 *cache++ = be32_to_cpu(p[i]) & 0xffff;
1057 }
1058
1059 release_firmware(fw);
1060
1061 return ret;
1062}
966 1063
967static int upgrade_fw(struct adapter *adap) 1064static int upgrade_fw(struct adapter *adap)
968{ 1065{
diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
index 870d44992c70..e78d341cbd60 100644
--- a/drivers/net/cxgb3/t3_hw.c
+++ b/drivers/net/cxgb3/t3_hw.c
@@ -3682,6 +3682,8 @@ static void mc7_prep(struct adapter *adapter, struct mc7 *mc7,
3682void mac_prep(struct cmac *mac, struct adapter *adapter, int index) 3682void mac_prep(struct cmac *mac, struct adapter *adapter, int index)
3683{ 3683{
3684 mac->adapter = adapter; 3684 mac->adapter = adapter;
3685 if (!adapter->params.vpd.xauicfg[1])
3686 index = 0;
3685 mac->offset = (XGMAC0_1_BASE_ADDR - XGMAC0_0_BASE_ADDR) * index; 3687 mac->offset = (XGMAC0_1_BASE_ADDR - XGMAC0_0_BASE_ADDR) * index;
3686 mac->nucast = 1; 3688 mac->nucast = 1;
3687 3689
diff --git a/drivers/net/cxgb3/xgmac.c b/drivers/net/cxgb3/xgmac.c
index f87f9435049f..0109ee4f2f91 100644
--- a/drivers/net/cxgb3/xgmac.c
+++ b/drivers/net/cxgb3/xgmac.c
@@ -447,11 +447,12 @@ int t3_mac_set_speed_duplex_fc(struct cmac *mac, int speed, int duplex, int fc)
447 447
448 val = t3_read_reg(adap, A_XGM_RXFIFO_CFG + oft); 448 val = t3_read_reg(adap, A_XGM_RXFIFO_CFG + oft);
449 val &= ~V_RXFIFOPAUSEHWM(M_RXFIFOPAUSEHWM); 449 val &= ~V_RXFIFOPAUSEHWM(M_RXFIFOPAUSEHWM);
450 if (fc & PAUSE_TX) 450 if (fc & PAUSE_TX) {
451 val |= V_RXFIFOPAUSEHWM(rx_fifo_hwm( 451 u32 rx_max_pkt_size =
452 t3_read_reg(adap, 452 G_RXMAXPKTSIZE(t3_read_reg(adap,
453 A_XGM_RX_MAX_PKT_SIZE 453 A_XGM_RX_MAX_PKT_SIZE + oft));
454 + oft)) / 8); 454 val |= V_RXFIFOPAUSEHWM(rx_fifo_hwm(rx_max_pkt_size) / 8);
455 }
455 t3_write_reg(adap, A_XGM_RXFIFO_CFG + oft, val); 456 t3_write_reg(adap, A_XGM_RXFIFO_CFG + oft, val);
456 457
457 t3_set_reg_field(adap, A_XGM_TX_CFG + oft, F_TXPAUSEEN, 458 t3_set_reg_field(adap, A_XGM_TX_CFG + oft, F_TXPAUSEEN,
diff --git a/drivers/net/de600.c b/drivers/net/de600.c
index e1af089064bc..6b13f4fd2e96 100644
--- a/drivers/net/de600.c
+++ b/drivers/net/de600.c
@@ -226,7 +226,7 @@ static int de600_start_xmit(struct sk_buff *skb, struct net_device *dev)
226 } 226 }
227 spin_unlock_irqrestore(&de600_lock, flags); 227 spin_unlock_irqrestore(&de600_lock, flags);
228 dev_kfree_skb(skb); 228 dev_kfree_skb(skb);
229 return 0; 229 return NETDEV_TX_OK;
230} 230}
231 231
232/* 232/*
diff --git a/drivers/net/de620.c b/drivers/net/de620.c
index 55d2bb67cffa..45794f6cb0f6 100644
--- a/drivers/net/de620.c
+++ b/drivers/net/de620.c
@@ -542,7 +542,7 @@ static int de620_start_xmit(struct sk_buff *skb, struct net_device *dev)
542 dev->stats.tx_packets++; 542 dev->stats.tx_packets++;
543 spin_unlock_irqrestore(&de620_lock, flags); 543 spin_unlock_irqrestore(&de620_lock, flags);
544 dev_kfree_skb (skb); 544 dev_kfree_skb (skb);
545 return 0; 545 return NETDEV_TX_OK;
546} 546}
547 547
548/***************************************************** 548/*****************************************************
diff --git a/drivers/net/declance.c b/drivers/net/declance.c
index 2b22e580c4de..a31696a3928e 100644
--- a/drivers/net/declance.c
+++ b/drivers/net/declance.c
@@ -902,7 +902,7 @@ static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
902 902
903 if (len < ETH_ZLEN) { 903 if (len < ETH_ZLEN) {
904 if (skb_padto(skb, ETH_ZLEN)) 904 if (skb_padto(skb, ETH_ZLEN))
905 return 0; 905 return NETDEV_TX_OK;
906 len = ETH_ZLEN; 906 len = ETH_ZLEN;
907 } 907 }
908 908
@@ -933,7 +933,7 @@ static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
933 dev->trans_start = jiffies; 933 dev->trans_start = jiffies;
934 dev_kfree_skb(skb); 934 dev_kfree_skb(skb);
935 935
936 return 0; 936 return NETDEV_TX_OK;
937} 937}
938 938
939static void lance_load_multicast(struct net_device *dev) 939static void lance_load_multicast(struct net_device *dev)
diff --git a/drivers/net/defxx.c b/drivers/net/defxx.c
index 102b8d439714..b2e0a8fc21d7 100644
--- a/drivers/net/defxx.c
+++ b/drivers/net/defxx.c
@@ -3218,7 +3218,7 @@ static int dfx_xmt_queue_pkt(
3218 bp->xmt_length_errors++; /* bump error counter */ 3218 bp->xmt_length_errors++; /* bump error counter */
3219 netif_wake_queue(dev); 3219 netif_wake_queue(dev);
3220 dev_kfree_skb(skb); 3220 dev_kfree_skb(skb);
3221 return(0); /* return "success" */ 3221 return NETDEV_TX_OK; /* return "success" */
3222 } 3222 }
3223 /* 3223 /*
3224 * See if adapter link is available, if not, free buffer 3224 * See if adapter link is available, if not, free buffer
@@ -3241,7 +3241,7 @@ static int dfx_xmt_queue_pkt(
3241 bp->xmt_discards++; /* bump error counter */ 3241 bp->xmt_discards++; /* bump error counter */
3242 dev_kfree_skb(skb); /* free sk_buff now */ 3242 dev_kfree_skb(skb); /* free sk_buff now */
3243 netif_wake_queue(dev); 3243 netif_wake_queue(dev);
3244 return(0); /* return "success" */ 3244 return NETDEV_TX_OK; /* return "success" */
3245 } 3245 }
3246 } 3246 }
3247 3247
@@ -3345,7 +3345,7 @@ static int dfx_xmt_queue_pkt(
3345 dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword); 3345 dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
3346 spin_unlock_irqrestore(&bp->lock, flags); 3346 spin_unlock_irqrestore(&bp->lock, flags);
3347 netif_wake_queue(dev); 3347 netif_wake_queue(dev);
3348 return(0); /* packet queued to adapter */ 3348 return NETDEV_TX_OK; /* packet queued to adapter */
3349 } 3349 }
3350 3350
3351 3351
diff --git a/drivers/net/depca.c b/drivers/net/depca.c
index 97ea2d6d3fe1..adb997c5bb5d 100644
--- a/drivers/net/depca.c
+++ b/drivers/net/depca.c
@@ -1793,7 +1793,7 @@ static int __init get_hw_addr(struct net_device *dev)
1793static int load_packet(struct net_device *dev, struct sk_buff *skb) 1793static int load_packet(struct net_device *dev, struct sk_buff *skb)
1794{ 1794{
1795 struct depca_private *lp = netdev_priv(dev); 1795 struct depca_private *lp = netdev_priv(dev);
1796 int i, entry, end, len, status = 0; 1796 int i, entry, end, len, status = NETDEV_TX_OK;
1797 1797
1798 entry = lp->tx_new; /* Ring around buffer number. */ 1798 entry = lp->tx_new; /* Ring around buffer number. */
1799 end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask; 1799 end = (entry + (skb->len - 1) / TX_BUFF_SZ) & lp->txRingMask;
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index dd771dea6ae6..8603806be898 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -92,6 +92,7 @@ typedef struct board_info {
92 u16 tx_pkt_cnt; 92 u16 tx_pkt_cnt;
93 u16 queue_pkt_len; 93 u16 queue_pkt_len;
94 u16 queue_start_addr; 94 u16 queue_start_addr;
95 u16 queue_ip_summed;
95 u16 dbug_cnt; 96 u16 dbug_cnt;
96 u8 io_mode; /* 0:word, 2:byte */ 97 u8 io_mode; /* 0:word, 2:byte */
97 u8 phy_addr; 98 u8 phy_addr;
@@ -124,6 +125,10 @@ typedef struct board_info {
124 125
125 struct mii_if_info mii; 126 struct mii_if_info mii;
126 u32 msg_enable; 127 u32 msg_enable;
128
129 int rx_csum;
130 int can_csum;
131 int ip_summed;
127} board_info_t; 132} board_info_t;
128 133
129/* debug code */ 134/* debug code */
@@ -460,6 +465,40 @@ static int dm9000_nway_reset(struct net_device *dev)
460 return mii_nway_restart(&dm->mii); 465 return mii_nway_restart(&dm->mii);
461} 466}
462 467
468static uint32_t dm9000_get_rx_csum(struct net_device *dev)
469{
470 board_info_t *dm = to_dm9000_board(dev);
471 return dm->rx_csum;
472}
473
474static int dm9000_set_rx_csum(struct net_device *dev, uint32_t data)
475{
476 board_info_t *dm = to_dm9000_board(dev);
477 unsigned long flags;
478
479 if (dm->can_csum) {
480 dm->rx_csum = data;
481
482 spin_lock_irqsave(&dm->lock, flags);
483 iow(dm, DM9000_RCSR, dm->rx_csum ? RCSR_CSUM : 0);
484 spin_unlock_irqrestore(&dm->lock, flags);
485
486 return 0;
487 }
488
489 return -EOPNOTSUPP;
490}
491
492static int dm9000_set_tx_csum(struct net_device *dev, uint32_t data)
493{
494 board_info_t *dm = to_dm9000_board(dev);
495 int ret = -EOPNOTSUPP;
496
497 if (dm->can_csum)
498 ret = ethtool_op_set_tx_csum(dev, data);
499 return ret;
500}
501
463static u32 dm9000_get_link(struct net_device *dev) 502static u32 dm9000_get_link(struct net_device *dev)
464{ 503{
465 board_info_t *dm = to_dm9000_board(dev); 504 board_info_t *dm = to_dm9000_board(dev);
@@ -540,6 +579,10 @@ static const struct ethtool_ops dm9000_ethtool_ops = {
540 .get_eeprom_len = dm9000_get_eeprom_len, 579 .get_eeprom_len = dm9000_get_eeprom_len,
541 .get_eeprom = dm9000_get_eeprom, 580 .get_eeprom = dm9000_get_eeprom,
542 .set_eeprom = dm9000_set_eeprom, 581 .set_eeprom = dm9000_set_eeprom,
582 .get_rx_csum = dm9000_get_rx_csum,
583 .set_rx_csum = dm9000_set_rx_csum,
584 .get_tx_csum = ethtool_op_get_tx_csum,
585 .set_tx_csum = dm9000_set_tx_csum,
543}; 586};
544 587
545static void dm9000_show_carrier(board_info_t *db, 588static void dm9000_show_carrier(board_info_t *db,
@@ -685,6 +728,9 @@ dm9000_init_dm9000(struct net_device *dev)
685 /* I/O mode */ 728 /* I/O mode */
686 db->io_mode = ior(db, DM9000_ISR) >> 6; /* ISR bit7:6 keeps I/O mode */ 729 db->io_mode = ior(db, DM9000_ISR) >> 6; /* ISR bit7:6 keeps I/O mode */
687 730
731 /* Checksum mode */
732 dm9000_set_rx_csum(dev, db->rx_csum);
733
688 /* GPIO0 on pre-activate PHY */ 734 /* GPIO0 on pre-activate PHY */
689 iow(db, DM9000_GPR, 0); /* REG_1F bit0 activate phyxcer */ 735 iow(db, DM9000_GPR, 0); /* REG_1F bit0 activate phyxcer */
690 iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */ 736 iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */
@@ -743,6 +789,29 @@ static void dm9000_timeout(struct net_device *dev)
743 spin_unlock_irqrestore(&db->lock, flags); 789 spin_unlock_irqrestore(&db->lock, flags);
744} 790}
745 791
792static void dm9000_send_packet(struct net_device *dev,
793 int ip_summed,
794 u16 pkt_len)
795{
796 board_info_t *dm = to_dm9000_board(dev);
797
798 /* The DM9000 is not smart enough to leave fragmented packets alone. */
799 if (dm->ip_summed != ip_summed) {
800 if (ip_summed == CHECKSUM_NONE)
801 iow(dm, DM9000_TCCR, 0);
802 else
803 iow(dm, DM9000_TCCR, TCCR_IP | TCCR_UDP | TCCR_TCP);
804 dm->ip_summed = ip_summed;
805 }
806
807 /* Set TX length to DM9000 */
808 iow(dm, DM9000_TXPLL, pkt_len);
809 iow(dm, DM9000_TXPLH, pkt_len >> 8);
810
811 /* Issue TX polling command */
812 iow(dm, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
813}
814
746/* 815/*
747 * Hardware start transmission. 816 * Hardware start transmission.
748 * Send a packet to media from the upper layer. 817 * Send a packet to media from the upper layer.
@@ -769,17 +838,11 @@ dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev)
769 db->tx_pkt_cnt++; 838 db->tx_pkt_cnt++;
770 /* TX control: First packet immediately send, second packet queue */ 839 /* TX control: First packet immediately send, second packet queue */
771 if (db->tx_pkt_cnt == 1) { 840 if (db->tx_pkt_cnt == 1) {
772 /* Set TX length to DM9000 */ 841 dm9000_send_packet(dev, skb->ip_summed, skb->len);
773 iow(db, DM9000_TXPLL, skb->len);
774 iow(db, DM9000_TXPLH, skb->len >> 8);
775
776 /* Issue TX polling command */
777 iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
778
779 dev->trans_start = jiffies; /* save the time stamp */
780 } else { 842 } else {
781 /* Second packet */ 843 /* Second packet */
782 db->queue_pkt_len = skb->len; 844 db->queue_pkt_len = skb->len;
845 db->queue_ip_summed = skb->ip_summed;
783 netif_stop_queue(dev); 846 netif_stop_queue(dev);
784 } 847 }
785 848
@@ -788,7 +851,7 @@ dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev)
788 /* free this SKB */ 851 /* free this SKB */
789 dev_kfree_skb(skb); 852 dev_kfree_skb(skb);
790 853
791 return 0; 854 return NETDEV_TX_OK;
792} 855}
793 856
794/* 857/*
@@ -809,12 +872,9 @@ static void dm9000_tx_done(struct net_device *dev, board_info_t *db)
809 dev_dbg(db->dev, "tx done, NSR %02x\n", tx_status); 872 dev_dbg(db->dev, "tx done, NSR %02x\n", tx_status);
810 873
811 /* Queue packet check & send */ 874 /* Queue packet check & send */
812 if (db->tx_pkt_cnt > 0) { 875 if (db->tx_pkt_cnt > 0)
813 iow(db, DM9000_TXPLL, db->queue_pkt_len); 876 dm9000_send_packet(dev, db->queue_ip_summed,
814 iow(db, DM9000_TXPLH, db->queue_pkt_len >> 8); 877 db->queue_pkt_len);
815 iow(db, DM9000_TCR, TCR_TXREQ);
816 dev->trans_start = jiffies;
817 }
818 netif_wake_queue(dev); 878 netif_wake_queue(dev);
819 } 879 }
820} 880}
@@ -846,14 +906,14 @@ dm9000_rx(struct net_device *dev)
846 rxbyte = readb(db->io_data); 906 rxbyte = readb(db->io_data);
847 907
848 /* Status check: this byte must be 0 or 1 */ 908 /* Status check: this byte must be 0 or 1 */
849 if (rxbyte > DM9000_PKT_RDY) { 909 if (rxbyte & DM9000_PKT_ERR) {
850 dev_warn(db->dev, "status check fail: %d\n", rxbyte); 910 dev_warn(db->dev, "status check fail: %d\n", rxbyte);
851 iow(db, DM9000_RCR, 0x00); /* Stop Device */ 911 iow(db, DM9000_RCR, 0x00); /* Stop Device */
852 iow(db, DM9000_ISR, IMR_PAR); /* Stop INT request */ 912 iow(db, DM9000_ISR, IMR_PAR); /* Stop INT request */
853 return; 913 return;
854 } 914 }
855 915
856 if (rxbyte != DM9000_PKT_RDY) 916 if (!(rxbyte & DM9000_PKT_RDY))
857 return; 917 return;
858 918
859 /* A packet ready now & Get status/length */ 919 /* A packet ready now & Get status/length */
@@ -914,6 +974,12 @@ dm9000_rx(struct net_device *dev)
914 974
915 /* Pass to upper layer */ 975 /* Pass to upper layer */
916 skb->protocol = eth_type_trans(skb, dev); 976 skb->protocol = eth_type_trans(skb, dev);
977 if (db->rx_csum) {
978 if ((((rxbyte & 0x1c) << 3) & rxbyte) == 0)
979 skb->ip_summed = CHECKSUM_UNNECESSARY;
980 else
981 skb->ip_summed = CHECKSUM_NONE;
982 }
917 netif_rx(skb); 983 netif_rx(skb);
918 dev->stats.rx_packets++; 984 dev->stats.rx_packets++;
919 985
@@ -922,7 +988,7 @@ dm9000_rx(struct net_device *dev)
922 988
923 (db->dumpblk)(db->io_data, RxLen); 989 (db->dumpblk)(db->io_data, RxLen);
924 } 990 }
925 } while (rxbyte == DM9000_PKT_RDY); 991 } while (rxbyte & DM9000_PKT_RDY);
926} 992}
927 993
928static irqreturn_t dm9000_interrupt(int irq, void *dev_id) 994static irqreturn_t dm9000_interrupt(int irq, void *dev_id)
@@ -1349,6 +1415,13 @@ dm9000_probe(struct platform_device *pdev)
1349 db->type = TYPE_DM9000E; 1415 db->type = TYPE_DM9000E;
1350 } 1416 }
1351 1417
1418 /* dm9000a/b are capable of hardware checksum offload */
1419 if (db->type == TYPE_DM9000A || db->type == TYPE_DM9000B) {
1420 db->can_csum = 1;
1421 db->rx_csum = 1;
1422 ndev->features |= NETIF_F_IP_CSUM;
1423 }
1424
1352 /* from this point we assume that we have found a DM9000 */ 1425 /* from this point we assume that we have found a DM9000 */
1353 1426
1354 /* driver system function */ 1427 /* driver system function */
diff --git a/drivers/net/dm9000.h b/drivers/net/dm9000.h
index ba25cf541420..80817c2edfb3 100644
--- a/drivers/net/dm9000.h
+++ b/drivers/net/dm9000.h
@@ -45,6 +45,10 @@
45#define DM9000_CHIPR 0x2C 45#define DM9000_CHIPR 0x2C
46#define DM9000_SMCR 0x2F 46#define DM9000_SMCR 0x2F
47 47
48#define DM9000_ETXCSR 0x30
49#define DM9000_TCCR 0x31
50#define DM9000_RCSR 0x32
51
48#define CHIPR_DM9000A 0x19 52#define CHIPR_DM9000A 0x19
49#define CHIPR_DM9000B 0x1B 53#define CHIPR_DM9000B 0x1B
50 54
@@ -131,7 +135,21 @@
131 135
132#define GPCR_GEP_CNTL (1<<0) 136#define GPCR_GEP_CNTL (1<<0)
133 137
138#define TCCR_IP (1<<0)
139#define TCCR_TCP (1<<1)
140#define TCCR_UDP (1<<2)
141
142#define RCSR_UDP_BAD (1<<7)
143#define RCSR_TCP_BAD (1<<6)
144#define RCSR_IP_BAD (1<<5)
145#define RCSR_UDP (1<<4)
146#define RCSR_TCP (1<<3)
147#define RCSR_IP (1<<2)
148#define RCSR_CSUM (1<<1)
149#define RCSR_DISCARD (1<<0)
150
134#define DM9000_PKT_RDY 0x01 /* Packet ready to receive */ 151#define DM9000_PKT_RDY 0x01 /* Packet ready to receive */
152#define DM9000_PKT_ERR 0x02
135#define DM9000_PKT_MAX 1536 /* Received packet max size */ 153#define DM9000_PKT_MAX 1536 /* Received packet max size */
136 154
137/* DM9000A / DM9000B definitions */ 155/* DM9000A / DM9000B definitions */
diff --git a/drivers/net/dnet.c b/drivers/net/dnet.c
index 33fa9eee4cac..2818d5de3940 100644
--- a/drivers/net/dnet.c
+++ b/drivers/net/dnet.c
@@ -596,7 +596,7 @@ static int dnet_start_xmit(struct sk_buff *skb, struct net_device *dev)
596 596
597 dev->trans_start = jiffies; 597 dev->trans_start = jiffies;
598 598
599 return 0; 599 return NETDEV_TX_OK;
600} 600}
601 601
602static void dnet_reset_hw(struct dnet *bp) 602static void dnet_reset_hw(struct dnet *bp)
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 8ebd7d789405..713ce6c532c5 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -85,7 +85,7 @@ static int dummy_xmit(struct sk_buff *skb, struct net_device *dev)
85 dev->stats.tx_bytes += skb->len; 85 dev->stats.tx_bytes += skb->len;
86 86
87 dev_kfree_skb(skb); 87 dev_kfree_skb(skb);
88 return 0; 88 return NETDEV_TX_OK;
89} 89}
90 90
91static int dummy_validate(struct nlattr *tb[], struct nlattr *data[]) 91static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index 41b648a67fec..569df19f0df5 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -1720,7 +1720,7 @@ static int e100_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1720 } 1720 }
1721 1721
1722 netdev->trans_start = jiffies; 1722 netdev->trans_start = jiffies;
1723 return 0; 1723 return NETDEV_TX_OK;
1724} 1724}
1725 1725
1726static int e100_tx_clean(struct nic *nic) 1726static int e100_tx_clean(struct nic *nic)
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index e9a416f40162..1a4f89c66a26 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -111,6 +111,9 @@ do { \
111#define E1000_MIN_RXD 80 111#define E1000_MIN_RXD 80
112#define E1000_MAX_82544_RXD 4096 112#define E1000_MAX_82544_RXD 4096
113 113
114#define E1000_MIN_ITR_USECS 10 /* 100000 irq/sec */
115#define E1000_MAX_ITR_USECS 10000 /* 100 irq/sec */
116
114/* this is the size past which hardware will drop packets when setting LPE=0 */ 117/* this is the size past which hardware will drop packets when setting LPE=0 */
115#define MAXIMUM_ETHERNET_VLAN_SIZE 1522 118#define MAXIMUM_ETHERNET_VLAN_SIZE 1522
116 119
@@ -137,7 +140,7 @@ do { \
137#define E1000_FC_HIGH_DIFF 0x1638 /* High: 5688 bytes below Rx FIFO size */ 140#define E1000_FC_HIGH_DIFF 0x1638 /* High: 5688 bytes below Rx FIFO size */
138#define E1000_FC_LOW_DIFF 0x1640 /* Low: 5696 bytes below Rx FIFO size */ 141#define E1000_FC_LOW_DIFF 0x1640 /* Low: 5696 bytes below Rx FIFO size */
139 142
140#define E1000_FC_PAUSE_TIME 0x0680 /* 858 usec */ 143#define E1000_FC_PAUSE_TIME 0xFFFF /* pause for the max or until send xon */
141 144
142/* How many Tx Descriptors do we need to call netif_wake_queue ? */ 145/* How many Tx Descriptors do we need to call netif_wake_queue ? */
143#define E1000_TX_QUEUE_WAKE 16 146#define E1000_TX_QUEUE_WAKE 16
@@ -161,6 +164,7 @@ do { \
161struct e1000_buffer { 164struct e1000_buffer {
162 struct sk_buff *skb; 165 struct sk_buff *skb;
163 dma_addr_t dma; 166 dma_addr_t dma;
167 struct page *page;
164 unsigned long time_stamp; 168 unsigned long time_stamp;
165 u16 length; 169 u16 length;
166 u16 next_to_watch; 170 u16 next_to_watch;
@@ -202,6 +206,7 @@ struct e1000_rx_ring {
202 unsigned int next_to_clean; 206 unsigned int next_to_clean;
203 /* array of buffer information structs */ 207 /* array of buffer information structs */
204 struct e1000_buffer *buffer_info; 208 struct e1000_buffer *buffer_info;
209 struct sk_buff *rx_skb_top;
205 210
206 /* cpu for rx queue */ 211 /* cpu for rx queue */
207 int cpu; 212 int cpu;
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index c854c96f5ab3..27f996a2010f 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -1904,6 +1904,53 @@ static int e1000_phys_id(struct net_device *netdev, u32 data)
1904 return 0; 1904 return 0;
1905} 1905}
1906 1906
1907static int e1000_get_coalesce(struct net_device *netdev,
1908 struct ethtool_coalesce *ec)
1909{
1910 struct e1000_adapter *adapter = netdev_priv(netdev);
1911
1912 if (adapter->hw.mac_type < e1000_82545)
1913 return -EOPNOTSUPP;
1914
1915 if (adapter->itr_setting <= 3)
1916 ec->rx_coalesce_usecs = adapter->itr_setting;
1917 else
1918 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1919
1920 return 0;
1921}
1922
1923static int e1000_set_coalesce(struct net_device *netdev,
1924 struct ethtool_coalesce *ec)
1925{
1926 struct e1000_adapter *adapter = netdev_priv(netdev);
1927 struct e1000_hw *hw = &adapter->hw;
1928
1929 if (hw->mac_type < e1000_82545)
1930 return -EOPNOTSUPP;
1931
1932 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1933 ((ec->rx_coalesce_usecs > 3) &&
1934 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1935 (ec->rx_coalesce_usecs == 2))
1936 return -EINVAL;
1937
1938 if (ec->rx_coalesce_usecs <= 3) {
1939 adapter->itr = 20000;
1940 adapter->itr_setting = ec->rx_coalesce_usecs;
1941 } else {
1942 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1943 adapter->itr_setting = adapter->itr & ~3;
1944 }
1945
1946 if (adapter->itr_setting != 0)
1947 ew32(ITR, 1000000000 / (adapter->itr * 256));
1948 else
1949 ew32(ITR, 0);
1950
1951 return 0;
1952}
1953
1907static int e1000_nway_reset(struct net_device *netdev) 1954static int e1000_nway_reset(struct net_device *netdev)
1908{ 1955{
1909 struct e1000_adapter *adapter = netdev_priv(netdev); 1956 struct e1000_adapter *adapter = netdev_priv(netdev);
@@ -1978,7 +2025,9 @@ static const struct ethtool_ops e1000_ethtool_ops = {
1978 .get_strings = e1000_get_strings, 2025 .get_strings = e1000_get_strings,
1979 .phys_id = e1000_phys_id, 2026 .phys_id = e1000_phys_id,
1980 .get_ethtool_stats = e1000_get_ethtool_stats, 2027 .get_ethtool_stats = e1000_get_ethtool_stats,
1981 .get_sset_count = e1000_get_sset_count, 2028 .get_sset_count = e1000_get_sset_count,
2029 .get_coalesce = e1000_get_coalesce,
2030 .set_coalesce = e1000_set_coalesce,
1982}; 2031};
1983 2032
1984void e1000_set_ethtool_ops(struct net_device *netdev) 2033void e1000_set_ethtool_ops(struct net_device *netdev)
diff --git a/drivers/net/e1000/e1000_hw.c b/drivers/net/e1000/e1000_hw.c
index e1a3fc1303ee..1e5ae112d57a 100644
--- a/drivers/net/e1000/e1000_hw.c
+++ b/drivers/net/e1000/e1000_hw.c
@@ -1955,7 +1955,7 @@ static s32 e1000_setup_copper_link(struct e1000_hw *hw)
1955 s32 ret_val; 1955 s32 ret_val;
1956 u16 i; 1956 u16 i;
1957 u16 phy_data; 1957 u16 phy_data;
1958 u16 reg_data; 1958 u16 reg_data = 0;
1959 1959
1960 DEBUGFUNC("e1000_setup_copper_link"); 1960 DEBUGFUNC("e1000_setup_copper_link");
1961 1961
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index 99fce2c5dd26..a8866bdbb671 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -523,11 +523,8 @@ s32 e1000_check_phy_reset_block(struct e1000_hw *hw);
523 523
524/* The sizes (in bytes) of a ethernet packet */ 524/* The sizes (in bytes) of a ethernet packet */
525#define ENET_HEADER_SIZE 14 525#define ENET_HEADER_SIZE 14
526#define MAXIMUM_ETHERNET_FRAME_SIZE 1518 /* With FCS */
527#define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */ 526#define MINIMUM_ETHERNET_FRAME_SIZE 64 /* With FCS */
528#define ETHERNET_FCS_SIZE 4 527#define ETHERNET_FCS_SIZE 4
529#define MAXIMUM_ETHERNET_PACKET_SIZE \
530 (MAXIMUM_ETHERNET_FRAME_SIZE - ETHERNET_FCS_SIZE)
531#define MINIMUM_ETHERNET_PACKET_SIZE \ 528#define MINIMUM_ETHERNET_PACKET_SIZE \
532 (MINIMUM_ETHERNET_FRAME_SIZE - ETHERNET_FCS_SIZE) 529 (MINIMUM_ETHERNET_FRAME_SIZE - ETHERNET_FCS_SIZE)
533#define CRC_LENGTH ETHERNET_FCS_SIZE 530#define CRC_LENGTH ETHERNET_FCS_SIZE
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 5b8cbdb4b520..d7df00c2dbd6 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -137,9 +137,15 @@ static int e1000_clean(struct napi_struct *napi, int budget);
137static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, 137static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
138 struct e1000_rx_ring *rx_ring, 138 struct e1000_rx_ring *rx_ring,
139 int *work_done, int work_to_do); 139 int *work_done, int work_to_do);
140static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
141 struct e1000_rx_ring *rx_ring,
142 int *work_done, int work_to_do);
140static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, 143static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
141 struct e1000_rx_ring *rx_ring, 144 struct e1000_rx_ring *rx_ring,
142 int cleaned_count); 145 int cleaned_count);
146static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring,
148 int cleaned_count);
143static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); 149static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
144static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, 150static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
145 int cmd); 151 int cmd);
@@ -635,8 +641,8 @@ void e1000_reset(struct e1000_adapter *adapter)
635{ 641{
636 struct e1000_hw *hw = &adapter->hw; 642 struct e1000_hw *hw = &adapter->hw;
637 u32 pba = 0, tx_space, min_tx_space, min_rx_space; 643 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
638 u16 fc_high_water_mark = E1000_FC_HIGH_DIFF;
639 bool legacy_pba_adjust = false; 644 bool legacy_pba_adjust = false;
645 u16 hwm;
640 646
641 /* Repartition Pba for greater than 9k mtu 647 /* Repartition Pba for greater than 9k mtu
642 * To take effect CTRL.RST is required. 648 * To take effect CTRL.RST is required.
@@ -680,7 +686,7 @@ void e1000_reset(struct e1000_adapter *adapter)
680 } 686 }
681 687
682 if (legacy_pba_adjust) { 688 if (legacy_pba_adjust) {
683 if (adapter->netdev->mtu > E1000_RXBUFFER_8192) 689 if (hw->max_frame_size > E1000_RXBUFFER_8192)
684 pba -= 8; /* allocate more FIFO for Tx */ 690 pba -= 8; /* allocate more FIFO for Tx */
685 691
686 if (hw->mac_type == e1000_82547) { 692 if (hw->mac_type == e1000_82547) {
@@ -690,14 +696,14 @@ void e1000_reset(struct e1000_adapter *adapter)
690 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; 696 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
691 atomic_set(&adapter->tx_fifo_stall, 0); 697 atomic_set(&adapter->tx_fifo_stall, 0);
692 } 698 }
693 } else if (hw->max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) { 699 } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
694 /* adjust PBA for jumbo frames */ 700 /* adjust PBA for jumbo frames */
695 ew32(PBA, pba); 701 ew32(PBA, pba);
696 702
697 /* To maintain wire speed transmits, the Tx FIFO should be 703 /* To maintain wire speed transmits, the Tx FIFO should be
698 * large enough to accomodate two full transmit packets, 704 * large enough to accommodate two full transmit packets,
699 * rounded up to the next 1KB and expressed in KB. Likewise, 705 * rounded up to the next 1KB and expressed in KB. Likewise,
700 * the Rx FIFO should be large enough to accomodate at least 706 * the Rx FIFO should be large enough to accommodate at least
701 * one full receive packet and is similarly rounded up and 707 * one full receive packet and is similarly rounded up and
702 * expressed in KB. */ 708 * expressed in KB. */
703 pba = er32(PBA); 709 pba = er32(PBA);
@@ -705,13 +711,17 @@ void e1000_reset(struct e1000_adapter *adapter)
705 tx_space = pba >> 16; 711 tx_space = pba >> 16;
706 /* lower 16 bits has Rx packet buffer allocation size in KB */ 712 /* lower 16 bits has Rx packet buffer allocation size in KB */
707 pba &= 0xffff; 713 pba &= 0xffff;
708 /* don't include ethernet FCS because hardware appends/strips */ 714 /*
709 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE + 715 * the tx fifo also stores 16 bytes of information about the tx
710 VLAN_TAG_SIZE; 716 * but don't include ethernet FCS because hardware appends it
711 min_tx_space = min_rx_space; 717 */
712 min_tx_space *= 2; 718 min_tx_space = (hw->max_frame_size +
719 sizeof(struct e1000_tx_desc) -
720 ETH_FCS_LEN) * 2;
713 min_tx_space = ALIGN(min_tx_space, 1024); 721 min_tx_space = ALIGN(min_tx_space, 1024);
714 min_tx_space >>= 10; 722 min_tx_space >>= 10;
723 /* software strips receive CRC, so leave room for it */
724 min_rx_space = hw->max_frame_size;
715 min_rx_space = ALIGN(min_rx_space, 1024); 725 min_rx_space = ALIGN(min_rx_space, 1024);
716 min_rx_space >>= 10; 726 min_rx_space >>= 10;
717 727
@@ -748,23 +758,22 @@ void e1000_reset(struct e1000_adapter *adapter)
748 758
749 ew32(PBA, pba); 759 ew32(PBA, pba);
750 760
751 /* flow control settings */ 761 /*
752 /* Set the FC high water mark to 90% of the FIFO size. 762 * flow control settings:
753 * Required to clear last 3 LSB */ 763 * The high water mark must be low enough to fit one full frame
754 fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8; 764 * (or the size used for early receive) above it in the Rx FIFO.
755 /* We can't use 90% on small FIFOs because the remainder 765 * Set it to the lower of:
756 * would be less than 1 full frame. In this case, we size 766 * - 90% of the Rx FIFO size, and
757 * it to allow at least a full frame above the high water 767 * - the full Rx FIFO size minus the early receive size (for parts
758 * mark. */ 768 * with ERT support assuming ERT set to E1000_ERT_2048), or
759 if (pba < E1000_PBA_16K) 769 * - the full Rx FIFO size minus one full frame
760 fc_high_water_mark = (pba * 1024) - 1600; 770 */
761 771 hwm = min(((pba << 10) * 9 / 10),
762 hw->fc_high_water = fc_high_water_mark; 772 ((pba << 10) - hw->max_frame_size));
763 hw->fc_low_water = fc_high_water_mark - 8; 773
764 if (hw->mac_type == e1000_80003es2lan) 774 hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */
765 hw->fc_pause_time = 0xFFFF; 775 hw->fc_low_water = hw->fc_high_water - 8;
766 else 776 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
767 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
768 hw->fc_send_xon = 1; 777 hw->fc_send_xon = 1;
769 hw->fc = hw->original_fc; 778 hw->fc = hw->original_fc;
770 779
@@ -1862,6 +1871,7 @@ setup_rx_desc_die:
1862 1871
1863 rxdr->next_to_clean = 0; 1872 rxdr->next_to_clean = 0;
1864 rxdr->next_to_use = 0; 1873 rxdr->next_to_use = 0;
1874 rxdr->rx_skb_top = NULL;
1865 1875
1866 return 0; 1876 return 0;
1867} 1877}
@@ -1968,10 +1978,17 @@ static void e1000_configure_rx(struct e1000_adapter *adapter)
1968 struct e1000_hw *hw = &adapter->hw; 1978 struct e1000_hw *hw = &adapter->hw;
1969 u32 rdlen, rctl, rxcsum, ctrl_ext; 1979 u32 rdlen, rctl, rxcsum, ctrl_ext;
1970 1980
1971 rdlen = adapter->rx_ring[0].count * 1981 if (adapter->netdev->mtu > ETH_DATA_LEN) {
1972 sizeof(struct e1000_rx_desc); 1982 rdlen = adapter->rx_ring[0].count *
1973 adapter->clean_rx = e1000_clean_rx_irq; 1983 sizeof(struct e1000_rx_desc);
1974 adapter->alloc_rx_buf = e1000_alloc_rx_buffers; 1984 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
1985 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
1986 } else {
1987 rdlen = adapter->rx_ring[0].count *
1988 sizeof(struct e1000_rx_desc);
1989 adapter->clean_rx = e1000_clean_rx_irq;
1990 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1991 }
1975 1992
1976 /* disable receives while setting up the descriptors */ 1993 /* disable receives while setting up the descriptors */
1977 rctl = er32(RCTL); 1994 rctl = er32(RCTL);
@@ -2185,26 +2202,39 @@ static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2185 /* Free all the Rx ring sk_buffs */ 2202 /* Free all the Rx ring sk_buffs */
2186 for (i = 0; i < rx_ring->count; i++) { 2203 for (i = 0; i < rx_ring->count; i++) {
2187 buffer_info = &rx_ring->buffer_info[i]; 2204 buffer_info = &rx_ring->buffer_info[i];
2188 if (buffer_info->dma) { 2205 if (buffer_info->dma &&
2189 pci_unmap_single(pdev, 2206 adapter->clean_rx == e1000_clean_rx_irq) {
2190 buffer_info->dma, 2207 pci_unmap_single(pdev, buffer_info->dma,
2191 buffer_info->length, 2208 buffer_info->length,
2192 PCI_DMA_FROMDEVICE); 2209 PCI_DMA_FROMDEVICE);
2210 } else if (buffer_info->dma &&
2211 adapter->clean_rx == e1000_clean_jumbo_rx_irq) {
2212 pci_unmap_page(pdev, buffer_info->dma,
2213 buffer_info->length,
2214 PCI_DMA_FROMDEVICE);
2193 } 2215 }
2194 2216
2195 buffer_info->dma = 0; 2217 buffer_info->dma = 0;
2196 2218 if (buffer_info->page) {
2219 put_page(buffer_info->page);
2220 buffer_info->page = NULL;
2221 }
2197 if (buffer_info->skb) { 2222 if (buffer_info->skb) {
2198 dev_kfree_skb(buffer_info->skb); 2223 dev_kfree_skb(buffer_info->skb);
2199 buffer_info->skb = NULL; 2224 buffer_info->skb = NULL;
2200 } 2225 }
2201 } 2226 }
2202 2227
2228 /* there also may be some cached data from a chained receive */
2229 if (rx_ring->rx_skb_top) {
2230 dev_kfree_skb(rx_ring->rx_skb_top);
2231 rx_ring->rx_skb_top = NULL;
2232 }
2233
2203 size = sizeof(struct e1000_buffer) * rx_ring->count; 2234 size = sizeof(struct e1000_buffer) * rx_ring->count;
2204 memset(rx_ring->buffer_info, 0, size); 2235 memset(rx_ring->buffer_info, 0, size);
2205 2236
2206 /* Zero out the descriptor ring */ 2237 /* Zero out the descriptor ring */
2207
2208 memset(rx_ring->desc, 0, rx_ring->size); 2238 memset(rx_ring->desc, 0, rx_ring->size);
2209 2239
2210 rx_ring->next_to_clean = 0; 2240 rx_ring->next_to_clean = 0;
@@ -3450,7 +3480,7 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3450 switch (hw->mac_type) { 3480 switch (hw->mac_type) {
3451 case e1000_undefined ... e1000_82542_rev2_1: 3481 case e1000_undefined ... e1000_82542_rev2_1:
3452 case e1000_ich8lan: 3482 case e1000_ich8lan:
3453 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { 3483 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
3454 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); 3484 DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3455 return -EINVAL; 3485 return -EINVAL;
3456 } 3486 }
@@ -3463,7 +3493,7 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3463 &eeprom_data); 3493 &eeprom_data);
3464 if ((hw->device_id != E1000_DEV_ID_82573L) || 3494 if ((hw->device_id != E1000_DEV_ID_82573L) ||
3465 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) { 3495 (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
3466 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { 3496 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
3467 DPRINTK(PROBE, ERR, 3497 DPRINTK(PROBE, ERR,
3468 "Jumbo Frames not supported.\n"); 3498 "Jumbo Frames not supported.\n");
3469 return -EINVAL; 3499 return -EINVAL;
@@ -3489,8 +3519,10 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3489 3519
3490 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN 3520 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3491 * means we reserve 2 more, this pushes us to allocate from the next 3521 * means we reserve 2 more, this pushes us to allocate from the next
3492 * larger slab size 3522 * larger slab size.
3493 * i.e. RXBUFFER_2048 --> size-4096 slab */ 3523 * i.e. RXBUFFER_2048 --> size-4096 slab
3524 * however with the new *_jumbo_rx* routines, jumbo receives will use
3525 * fragmented skbs */
3494 3526
3495 if (max_frame <= E1000_RXBUFFER_256) 3527 if (max_frame <= E1000_RXBUFFER_256)
3496 adapter->rx_buffer_len = E1000_RXBUFFER_256; 3528 adapter->rx_buffer_len = E1000_RXBUFFER_256;
@@ -3500,16 +3532,16 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3500 adapter->rx_buffer_len = E1000_RXBUFFER_1024; 3532 adapter->rx_buffer_len = E1000_RXBUFFER_1024;
3501 else if (max_frame <= E1000_RXBUFFER_2048) 3533 else if (max_frame <= E1000_RXBUFFER_2048)
3502 adapter->rx_buffer_len = E1000_RXBUFFER_2048; 3534 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3503 else if (max_frame <= E1000_RXBUFFER_4096) 3535 else
3504 adapter->rx_buffer_len = E1000_RXBUFFER_4096; 3536#if (PAGE_SIZE >= E1000_RXBUFFER_16384)
3505 else if (max_frame <= E1000_RXBUFFER_8192)
3506 adapter->rx_buffer_len = E1000_RXBUFFER_8192;
3507 else if (max_frame <= E1000_RXBUFFER_16384)
3508 adapter->rx_buffer_len = E1000_RXBUFFER_16384; 3537 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3538#elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3539 adapter->rx_buffer_len = PAGE_SIZE;
3540#endif
3509 3541
3510 /* adjust allocation if LPE protects us, and we aren't using SBP */ 3542 /* adjust allocation if LPE protects us, and we aren't using SBP */
3511 if (!hw->tbi_compatibility_on && 3543 if (!hw->tbi_compatibility_on &&
3512 ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) || 3544 ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
3513 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) 3545 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3514 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; 3546 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3515 3547
@@ -3987,9 +4019,227 @@ static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3987} 4019}
3988 4020
3989/** 4021/**
4022 * e1000_consume_page - helper function
4023 **/
4024static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
4025 u16 length)
4026{
4027 bi->page = NULL;
4028 skb->len += length;
4029 skb->data_len += length;
4030 skb->truesize += length;
4031}
4032
4033/**
4034 * e1000_receive_skb - helper function to handle rx indications
4035 * @adapter: board private structure
4036 * @status: descriptor status field as written by hardware
4037 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
4038 * @skb: pointer to sk_buff to be indicated to stack
4039 */
4040static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
4041 __le16 vlan, struct sk_buff *skb)
4042{
4043 if (unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP))) {
4044 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4045 le16_to_cpu(vlan) &
4046 E1000_RXD_SPC_VLAN_MASK);
4047 } else {
4048 netif_receive_skb(skb);
4049 }
4050}
4051
4052/**
4053 * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
4054 * @adapter: board private structure
4055 * @rx_ring: ring to clean
4056 * @work_done: amount of napi work completed this call
4057 * @work_to_do: max amount of work allowed for this call to do
4058 *
4059 * the return value indicates whether actual cleaning was done, there
4060 * is no guarantee that everything was cleaned
4061 */
4062static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
4063 struct e1000_rx_ring *rx_ring,
4064 int *work_done, int work_to_do)
4065{
4066 struct e1000_hw *hw = &adapter->hw;
4067 struct net_device *netdev = adapter->netdev;
4068 struct pci_dev *pdev = adapter->pdev;
4069 struct e1000_rx_desc *rx_desc, *next_rxd;
4070 struct e1000_buffer *buffer_info, *next_buffer;
4071 unsigned long irq_flags;
4072 u32 length;
4073 unsigned int i;
4074 int cleaned_count = 0;
4075 bool cleaned = false;
4076 unsigned int total_rx_bytes=0, total_rx_packets=0;
4077
4078 i = rx_ring->next_to_clean;
4079 rx_desc = E1000_RX_DESC(*rx_ring, i);
4080 buffer_info = &rx_ring->buffer_info[i];
4081
4082 while (rx_desc->status & E1000_RXD_STAT_DD) {
4083 struct sk_buff *skb;
4084 u8 status;
4085
4086 if (*work_done >= work_to_do)
4087 break;
4088 (*work_done)++;
4089
4090 status = rx_desc->status;
4091 skb = buffer_info->skb;
4092 buffer_info->skb = NULL;
4093
4094 if (++i == rx_ring->count) i = 0;
4095 next_rxd = E1000_RX_DESC(*rx_ring, i);
4096 prefetch(next_rxd);
4097
4098 next_buffer = &rx_ring->buffer_info[i];
4099
4100 cleaned = true;
4101 cleaned_count++;
4102 pci_unmap_page(pdev, buffer_info->dma, buffer_info->length,
4103 PCI_DMA_FROMDEVICE);
4104 buffer_info->dma = 0;
4105
4106 length = le16_to_cpu(rx_desc->length);
4107
4108 /* errors is only valid for DD + EOP descriptors */
4109 if (unlikely((status & E1000_RXD_STAT_EOP) &&
4110 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
4111 u8 last_byte = *(skb->data + length - 1);
4112 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4113 last_byte)) {
4114 spin_lock_irqsave(&adapter->stats_lock,
4115 irq_flags);
4116 e1000_tbi_adjust_stats(hw, &adapter->stats,
4117 length, skb->data);
4118 spin_unlock_irqrestore(&adapter->stats_lock,
4119 irq_flags);
4120 length--;
4121 } else {
4122 /* recycle both page and skb */
4123 buffer_info->skb = skb;
4124 /* an error means any chain goes out the window
4125 * too */
4126 if (rx_ring->rx_skb_top)
4127 dev_kfree_skb(rx_ring->rx_skb_top);
4128 rx_ring->rx_skb_top = NULL;
4129 goto next_desc;
4130 }
4131 }
4132
4133#define rxtop rx_ring->rx_skb_top
4134 if (!(status & E1000_RXD_STAT_EOP)) {
4135 /* this descriptor is only the beginning (or middle) */
4136 if (!rxtop) {
4137 /* this is the beginning of a chain */
4138 rxtop = skb;
4139 skb_fill_page_desc(rxtop, 0, buffer_info->page,
4140 0, length);
4141 } else {
4142 /* this is the middle of a chain */
4143 skb_fill_page_desc(rxtop,
4144 skb_shinfo(rxtop)->nr_frags,
4145 buffer_info->page, 0, length);
4146 /* re-use the skb, only consumed the page */
4147 buffer_info->skb = skb;
4148 }
4149 e1000_consume_page(buffer_info, rxtop, length);
4150 goto next_desc;
4151 } else {
4152 if (rxtop) {
4153 /* end of the chain */
4154 skb_fill_page_desc(rxtop,
4155 skb_shinfo(rxtop)->nr_frags,
4156 buffer_info->page, 0, length);
4157 /* re-use the current skb, we only consumed the
4158 * page */
4159 buffer_info->skb = skb;
4160 skb = rxtop;
4161 rxtop = NULL;
4162 e1000_consume_page(buffer_info, skb, length);
4163 } else {
4164 /* no chain, got EOP, this buf is the packet
4165 * copybreak to save the put_page/alloc_page */
4166 if (length <= copybreak &&
4167 skb_tailroom(skb) >= length) {
4168 u8 *vaddr;
4169 vaddr = kmap_atomic(buffer_info->page,
4170 KM_SKB_DATA_SOFTIRQ);
4171 memcpy(skb_tail_pointer(skb), vaddr, length);
4172 kunmap_atomic(vaddr,
4173 KM_SKB_DATA_SOFTIRQ);
4174 /* re-use the page, so don't erase
4175 * buffer_info->page */
4176 skb_put(skb, length);
4177 } else {
4178 skb_fill_page_desc(skb, 0,
4179 buffer_info->page, 0,
4180 length);
4181 e1000_consume_page(buffer_info, skb,
4182 length);
4183 }
4184 }
4185 }
4186
4187 /* Receive Checksum Offload XXX recompute due to CRC strip? */
4188 e1000_rx_checksum(adapter,
4189 (u32)(status) |
4190 ((u32)(rx_desc->errors) << 24),
4191 le16_to_cpu(rx_desc->csum), skb);
4192
4193 pskb_trim(skb, skb->len - 4);
4194
4195 /* probably a little skewed due to removing CRC */
4196 total_rx_bytes += skb->len;
4197 total_rx_packets++;
4198
4199 /* eth type trans needs skb->data to point to something */
4200 if (!pskb_may_pull(skb, ETH_HLEN)) {
4201 DPRINTK(DRV, ERR, "pskb_may_pull failed.\n");
4202 dev_kfree_skb(skb);
4203 goto next_desc;
4204 }
4205
4206 skb->protocol = eth_type_trans(skb, netdev);
4207
4208 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4209
4210next_desc:
4211 rx_desc->status = 0;
4212
4213 /* return some buffers to hardware, one at a time is too slow */
4214 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4215 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4216 cleaned_count = 0;
4217 }
4218
4219 /* use prefetched values */
4220 rx_desc = next_rxd;
4221 buffer_info = next_buffer;
4222 }
4223 rx_ring->next_to_clean = i;
4224
4225 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4226 if (cleaned_count)
4227 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4228
4229 adapter->total_rx_packets += total_rx_packets;
4230 adapter->total_rx_bytes += total_rx_bytes;
4231 adapter->net_stats.rx_bytes += total_rx_bytes;
4232 adapter->net_stats.rx_packets += total_rx_packets;
4233 return cleaned;
4234}
4235
4236/**
3990 * e1000_clean_rx_irq - Send received data up the network stack; legacy 4237 * e1000_clean_rx_irq - Send received data up the network stack; legacy
3991 * @adapter: board private structure 4238 * @adapter: board private structure
3992 **/ 4239 * @rx_ring: ring to clean
4240 * @work_done: amount of napi work completed this call
4241 * @work_to_do: max amount of work allowed for this call to do
4242 */
3993static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, 4243static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
3994 struct e1000_rx_ring *rx_ring, 4244 struct e1000_rx_ring *rx_ring,
3995 int *work_done, int work_to_do) 4245 int *work_done, int work_to_do)
@@ -4001,7 +4251,6 @@ static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4001 struct e1000_buffer *buffer_info, *next_buffer; 4251 struct e1000_buffer *buffer_info, *next_buffer;
4002 unsigned long flags; 4252 unsigned long flags;
4003 u32 length; 4253 u32 length;
4004 u8 last_byte;
4005 unsigned int i; 4254 unsigned int i;
4006 int cleaned_count = 0; 4255 int cleaned_count = 0;
4007 bool cleaned = false; 4256 bool cleaned = false;
@@ -4033,9 +4282,7 @@ static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4033 4282
4034 cleaned = true; 4283 cleaned = true;
4035 cleaned_count++; 4284 cleaned_count++;
4036 pci_unmap_single(pdev, 4285 pci_unmap_single(pdev, buffer_info->dma, buffer_info->length,
4037 buffer_info->dma,
4038 buffer_info->length,
4039 PCI_DMA_FROMDEVICE); 4286 PCI_DMA_FROMDEVICE);
4040 buffer_info->dma = 0; 4287 buffer_info->dma = 0;
4041 4288
@@ -4052,7 +4299,7 @@ static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4052 } 4299 }
4053 4300
4054 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { 4301 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
4055 last_byte = *(skb->data + length - 1); 4302 u8 last_byte = *(skb->data + length - 1);
4056 if (TBI_ACCEPT(hw, status, rx_desc->errors, length, 4303 if (TBI_ACCEPT(hw, status, rx_desc->errors, length,
4057 last_byte)) { 4304 last_byte)) {
4058 spin_lock_irqsave(&adapter->stats_lock, flags); 4305 spin_lock_irqsave(&adapter->stats_lock, flags);
@@ -4107,13 +4354,7 @@ static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4107 4354
4108 skb->protocol = eth_type_trans(skb, netdev); 4355 skb->protocol = eth_type_trans(skb, netdev);
4109 4356
4110 if (unlikely(adapter->vlgrp && 4357 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4111 (status & E1000_RXD_STAT_VP))) {
4112 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
4113 le16_to_cpu(rx_desc->special));
4114 } else {
4115 netif_receive_skb(skb);
4116 }
4117 4358
4118next_desc: 4359next_desc:
4119 rx_desc->status = 0; 4360 rx_desc->status = 0;
@@ -4142,6 +4383,114 @@ next_desc:
4142} 4383}
4143 4384
4144/** 4385/**
4386 * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
4387 * @adapter: address of board private structure
4388 * @rx_ring: pointer to receive ring structure
4389 * @cleaned_count: number of buffers to allocate this pass
4390 **/
4391
4392static void
4393e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
4394 struct e1000_rx_ring *rx_ring, int cleaned_count)
4395{
4396 struct net_device *netdev = adapter->netdev;
4397 struct pci_dev *pdev = adapter->pdev;
4398 struct e1000_rx_desc *rx_desc;
4399 struct e1000_buffer *buffer_info;
4400 struct sk_buff *skb;
4401 unsigned int i;
4402 unsigned int bufsz = 256 -
4403 16 /*for skb_reserve */ -
4404 NET_IP_ALIGN;
4405
4406 i = rx_ring->next_to_use;
4407 buffer_info = &rx_ring->buffer_info[i];
4408
4409 while (cleaned_count--) {
4410 skb = buffer_info->skb;
4411 if (skb) {
4412 skb_trim(skb, 0);
4413 goto check_page;
4414 }
4415
4416 skb = netdev_alloc_skb(netdev, bufsz);
4417 if (unlikely(!skb)) {
4418 /* Better luck next round */
4419 adapter->alloc_rx_buff_failed++;
4420 break;
4421 }
4422
4423 /* Fix for errata 23, can't cross 64kB boundary */
4424 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4425 struct sk_buff *oldskb = skb;
4426 DPRINTK(PROBE, ERR, "skb align check failed: %u bytes "
4427 "at %p\n", bufsz, skb->data);
4428 /* Try again, without freeing the previous */
4429 skb = netdev_alloc_skb(netdev, bufsz);
4430 /* Failed allocation, critical failure */
4431 if (!skb) {
4432 dev_kfree_skb(oldskb);
4433 adapter->alloc_rx_buff_failed++;
4434 break;
4435 }
4436
4437 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
4438 /* give up */
4439 dev_kfree_skb(skb);
4440 dev_kfree_skb(oldskb);
4441 break; /* while (cleaned_count--) */
4442 }
4443
4444 /* Use new allocation */
4445 dev_kfree_skb(oldskb);
4446 }
4447 /* Make buffer alignment 2 beyond a 16 byte boundary
4448 * this will result in a 16 byte aligned IP header after
4449 * the 14 byte MAC header is removed
4450 */
4451 skb_reserve(skb, NET_IP_ALIGN);
4452
4453 buffer_info->skb = skb;
4454 buffer_info->length = adapter->rx_buffer_len;
4455check_page:
4456 /* allocate a new page if necessary */
4457 if (!buffer_info->page) {
4458 buffer_info->page = alloc_page(GFP_ATOMIC);
4459 if (unlikely(!buffer_info->page)) {
4460 adapter->alloc_rx_buff_failed++;
4461 break;
4462 }
4463 }
4464
4465 if (!buffer_info->dma)
4466 buffer_info->dma = pci_map_page(pdev,
4467 buffer_info->page, 0,
4468 buffer_info->length,
4469 PCI_DMA_FROMDEVICE);
4470
4471 rx_desc = E1000_RX_DESC(*rx_ring, i);
4472 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4473
4474 if (unlikely(++i == rx_ring->count))
4475 i = 0;
4476 buffer_info = &rx_ring->buffer_info[i];
4477 }
4478
4479 if (likely(rx_ring->next_to_use != i)) {
4480 rx_ring->next_to_use = i;
4481 if (unlikely(i-- == 0))
4482 i = (rx_ring->count - 1);
4483
4484 /* Force memory writes to complete before letting h/w
4485 * know there are new descriptors to fetch. (Only
4486 * applicable for weak-ordered memory model archs,
4487 * such as IA-64). */
4488 wmb();
4489 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4490 }
4491}
4492
4493/**
4145 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended 4494 * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
4146 * @adapter: address of board private structure 4495 * @adapter: address of board private structure
4147 **/ 4496 **/
@@ -4186,6 +4535,7 @@ static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4186 /* Failed allocation, critical failure */ 4535 /* Failed allocation, critical failure */
4187 if (!skb) { 4536 if (!skb) {
4188 dev_kfree_skb(oldskb); 4537 dev_kfree_skb(oldskb);
4538 adapter->alloc_rx_buff_failed++;
4189 break; 4539 break;
4190 } 4540 }
4191 4541
@@ -4193,6 +4543,7 @@ static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4193 /* give up */ 4543 /* give up */
4194 dev_kfree_skb(skb); 4544 dev_kfree_skb(skb);
4195 dev_kfree_skb(oldskb); 4545 dev_kfree_skb(oldskb);
4546 adapter->alloc_rx_buff_failed++;
4196 break; /* while !buffer_info->skb */ 4547 break; /* while !buffer_info->skb */
4197 } 4548 }
4198 4549
@@ -4210,9 +4561,14 @@ static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4210map_skb: 4561map_skb:
4211 buffer_info->dma = pci_map_single(pdev, 4562 buffer_info->dma = pci_map_single(pdev,
4212 skb->data, 4563 skb->data,
4213 adapter->rx_buffer_len, 4564 buffer_info->length,
4214 PCI_DMA_FROMDEVICE); 4565 PCI_DMA_FROMDEVICE);
4215 4566
4567 /*
4568 * XXX if it was allocated cleanly it will never map to a
4569 * boundary crossing
4570 */
4571
4216 /* Fix for errata 23, can't cross 64kB boundary */ 4572 /* Fix for errata 23, can't cross 64kB boundary */
4217 if (!e1000_check_64k_bound(adapter, 4573 if (!e1000_check_64k_bound(adapter,
4218 (void *)(unsigned long)buffer_info->dma, 4574 (void *)(unsigned long)buffer_info->dma,
@@ -4229,6 +4585,7 @@ map_skb:
4229 PCI_DMA_FROMDEVICE); 4585 PCI_DMA_FROMDEVICE);
4230 buffer_info->dma = 0; 4586 buffer_info->dma = 0;
4231 4587
4588 adapter->alloc_rx_buff_failed++;
4232 break; /* while !buffer_info->skb */ 4589 break; /* while !buffer_info->skb */
4233 } 4590 }
4234 rx_desc = E1000_RX_DESC(*rx_ring, i); 4591 rx_desc = E1000_RX_DESC(*rx_ring, i);
diff --git a/drivers/net/eepro.c b/drivers/net/eepro.c
index cc2ab6412c73..71605d63708c 100644
--- a/drivers/net/eepro.c
+++ b/drivers/net/eepro.c
@@ -1145,7 +1145,7 @@ static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev)
1145 1145
1146 if (length < ETH_ZLEN) { 1146 if (length < ETH_ZLEN) {
1147 if (skb_padto(skb, ETH_ZLEN)) 1147 if (skb_padto(skb, ETH_ZLEN))
1148 return 0; 1148 return NETDEV_TX_OK;
1149 length = ETH_ZLEN; 1149 length = ETH_ZLEN;
1150 } 1150 }
1151 netif_stop_queue (dev); 1151 netif_stop_queue (dev);
@@ -1178,7 +1178,7 @@ static int eepro_send_packet(struct sk_buff *skb, struct net_device *dev)
1178 eepro_en_int(ioaddr); 1178 eepro_en_int(ioaddr);
1179 spin_unlock_irqrestore(&lp->lock, flags); 1179 spin_unlock_irqrestore(&lp->lock, flags);
1180 1180
1181 return 0; 1181 return NETDEV_TX_OK;
1182} 1182}
1183 1183
1184 1184
diff --git a/drivers/net/eexpress.c b/drivers/net/eexpress.c
index 1686dca28748..8c44ef4ba357 100644
--- a/drivers/net/eexpress.c
+++ b/drivers/net/eexpress.c
@@ -664,7 +664,7 @@ static int eexp_xmit(struct sk_buff *buf, struct net_device *dev)
664 664
665 if (buf->len < ETH_ZLEN) { 665 if (buf->len < ETH_ZLEN) {
666 if (skb_padto(buf, ETH_ZLEN)) 666 if (skb_padto(buf, ETH_ZLEN))
667 return 0; 667 return NETDEV_TX_OK;
668 length = ETH_ZLEN; 668 length = ETH_ZLEN;
669 } 669 }
670 670
@@ -691,7 +691,7 @@ static int eexp_xmit(struct sk_buff *buf, struct net_device *dev)
691 spin_unlock_irqrestore(&lp->lock, flags); 691 spin_unlock_irqrestore(&lp->lock, flags);
692#endif 692#endif
693 enable_irq(dev->irq); 693 enable_irq(dev->irq);
694 return 0; 694 return NETDEV_TX_OK;
695} 695}
696 696
697/* 697/*
diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c
index fc6cc038c7b8..372d6c6a4e7f 100644
--- a/drivers/net/enc28j60.c
+++ b/drivers/net/enc28j60.c
@@ -1299,7 +1299,7 @@ static int enc28j60_send_packet(struct sk_buff *skb, struct net_device *dev)
1299 priv->tx_skb = skb; 1299 priv->tx_skb = skb;
1300 schedule_work(&priv->tx_work); 1300 schedule_work(&priv->tx_work);
1301 1301
1302 return 0; 1302 return NETDEV_TX_OK;
1303} 1303}
1304 1304
1305static void enc28j60_tx_work_handler(struct work_struct *work) 1305static void enc28j60_tx_work_handler(struct work_struct *work)
diff --git a/drivers/net/epic100.c b/drivers/net/epic100.c
index b60e27dfcfa7..d6a7aa3142f9 100644
--- a/drivers/net/epic100.c
+++ b/drivers/net/epic100.c
@@ -970,7 +970,7 @@ static int epic_start_xmit(struct sk_buff *skb, struct net_device *dev)
970 unsigned long flags; 970 unsigned long flags;
971 971
972 if (skb_padto(skb, ETH_ZLEN)) 972 if (skb_padto(skb, ETH_ZLEN))
973 return 0; 973 return NETDEV_TX_OK;
974 974
975 /* Caution: the write order is important here, set the field with the 975 /* Caution: the write order is important here, set the field with the
976 "ownership" bit last. */ 976 "ownership" bit last. */
@@ -1014,7 +1014,7 @@ static int epic_start_xmit(struct sk_buff *skb, struct net_device *dev)
1014 dev->name, (int)skb->len, entry, ctrl_word, 1014 dev->name, (int)skb->len, entry, ctrl_word,
1015 (int)inl(dev->base_addr + TxSTAT)); 1015 (int)inl(dev->base_addr + TxSTAT));
1016 1016
1017 return 0; 1017 return NETDEV_TX_OK;
1018} 1018}
1019 1019
1020static void epic_tx_error(struct net_device *dev, struct epic_private *ep, 1020static void epic_tx_error(struct net_device *dev, struct epic_private *ep,
diff --git a/drivers/net/eql.c b/drivers/net/eql.c
index 19b7dd983944..c0e69c5cae84 100644
--- a/drivers/net/eql.c
+++ b/drivers/net/eql.c
@@ -348,7 +348,7 @@ static int eql_slave_xmit(struct sk_buff *skb, struct net_device *dev)
348 348
349 spin_unlock(&eql->queue.lock); 349 spin_unlock(&eql->queue.lock);
350 350
351 return 0; 351 return NETDEV_TX_OK;
352} 352}
353 353
354/* 354/*
diff --git a/drivers/net/eth16i.c b/drivers/net/eth16i.c
index 0d8b6da046f2..97d5205edc8f 100644
--- a/drivers/net/eth16i.c
+++ b/drivers/net/eth16i.c
@@ -1064,7 +1064,7 @@ static int eth16i_tx(struct sk_buff *skb, struct net_device *dev)
1064 1064
1065 if (length < ETH_ZLEN) { 1065 if (length < ETH_ZLEN) {
1066 if (skb_padto(skb, ETH_ZLEN)) 1066 if (skb_padto(skb, ETH_ZLEN))
1067 return 0; 1067 return NETDEV_TX_OK;
1068 length = ETH_ZLEN; 1068 length = ETH_ZLEN;
1069 } 1069 }
1070 buf = skb->data; 1070 buf = skb->data;
@@ -1126,7 +1126,7 @@ static int eth16i_tx(struct sk_buff *skb, struct net_device *dev)
1126 /* outb(TX_INTR_DONE | TX_INTR_16_COL, ioaddr + TX_INTR_REG); */ 1126 /* outb(TX_INTR_DONE | TX_INTR_16_COL, ioaddr + TX_INTR_REG); */
1127 status = 0; 1127 status = 0;
1128 dev_kfree_skb(skb); 1128 dev_kfree_skb(skb);
1129 return 0; 1129 return NETDEV_TX_OK;
1130} 1130}
1131 1131
1132static void eth16i_rx(struct net_device *dev) 1132static void eth16i_rx(struct net_device *dev)
diff --git a/drivers/net/ewrk3.c b/drivers/net/ewrk3.c
index 1e9723281405..9c51bc813ad3 100644
--- a/drivers/net/ewrk3.c
+++ b/drivers/net/ewrk3.c
@@ -868,7 +868,7 @@ static int ewrk3_queue_pkt (struct sk_buff *skb, struct net_device *dev)
868 if (inb (EWRK3_FMQC) == 0) 868 if (inb (EWRK3_FMQC) == 0)
869 netif_stop_queue (dev); 869 netif_stop_queue (dev);
870 870
871 return 0; 871 return NETDEV_TX_OK;
872 872
873err_out: 873err_out:
874 ENABLE_IRQs; 874 ENABLE_IRQs;
diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
index 891be28a7d4f..75e5fe5153d9 100644
--- a/drivers/net/fealnx.c
+++ b/drivers/net/fealnx.c
@@ -1374,7 +1374,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
1374 dev->trans_start = jiffies; 1374 dev->trans_start = jiffies;
1375 1375
1376 spin_unlock_irqrestore(&np->lock, flags); 1376 spin_unlock_irqrestore(&np->lock, flags);
1377 return 0; 1377 return NETDEV_TX_OK;
1378} 1378}
1379 1379
1380 1380
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index d4b98074b1b7..e3d99fe53ce6 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -366,7 +366,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
366 366
367 spin_unlock_irqrestore(&fep->hw_lock, flags); 367 spin_unlock_irqrestore(&fep->hw_lock, flags);
368 368
369 return 0; 369 return NETDEV_TX_OK;
370} 370}
371 371
372static void 372static void
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 43d813ed9f45..b2db449966e2 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -306,7 +306,6 @@ static int gfar_probe(struct of_device *ofdev,
306 u32 tempval; 306 u32 tempval;
307 struct net_device *dev = NULL; 307 struct net_device *dev = NULL;
308 struct gfar_private *priv = NULL; 308 struct gfar_private *priv = NULL;
309 DECLARE_MAC_BUF(mac);
310 int err = 0; 309 int err = 0;
311 int len_devname; 310 int len_devname;
312 311
diff --git a/drivers/net/hamachi.c b/drivers/net/hamachi.c
index 9d5b62cb30f7..4e8d3728e820 100644
--- a/drivers/net/hamachi.c
+++ b/drivers/net/hamachi.c
@@ -1369,7 +1369,7 @@ static int hamachi_start_xmit(struct sk_buff *skb, struct net_device *dev)
1369 printk(KERN_DEBUG "%s: Hamachi transmit frame #%d queued in slot %d.\n", 1369 printk(KERN_DEBUG "%s: Hamachi transmit frame #%d queued in slot %d.\n",
1370 dev->name, hmp->cur_tx, entry); 1370 dev->name, hmp->cur_tx, entry);
1371 } 1371 }
1372 return 0; 1372 return NETDEV_TX_OK;
1373} 1373}
1374 1374
1375/* The interrupt handler does all of the Rx thread work and cleans up 1375/* The interrupt handler does all of the Rx thread work and cleans up
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 155160052c8b..e88209fc2a2b 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -255,7 +255,7 @@ static int sp_xmit(struct sk_buff *skb, struct net_device *dev)
255 255
256 dev_kfree_skb(skb); 256 dev_kfree_skb(skb);
257 257
258 return 0; 258 return NETDEV_TX_OK;
259} 259}
260 260
261static int sp_open_dev(struct net_device *dev) 261static int sp_open_dev(struct net_device *dev)
diff --git a/drivers/net/hamradio/baycom_epp.c b/drivers/net/hamradio/baycom_epp.c
index 5e4b7afd0683..e229edf3261a 100644
--- a/drivers/net/hamradio/baycom_epp.c
+++ b/drivers/net/hamradio/baycom_epp.c
@@ -774,18 +774,18 @@ static int baycom_send_packet(struct sk_buff *skb, struct net_device *dev)
774 if (skb->data[0] != 0) { 774 if (skb->data[0] != 0) {
775 do_kiss_params(bc, skb->data, skb->len); 775 do_kiss_params(bc, skb->data, skb->len);
776 dev_kfree_skb(skb); 776 dev_kfree_skb(skb);
777 return 0; 777 return NETDEV_TX_OK;
778 } 778 }
779 if (bc->skb) 779 if (bc->skb)
780 return NETDEV_TX_LOCKED; 780 return NETDEV_TX_LOCKED;
781 /* strip KISS byte */ 781 /* strip KISS byte */
782 if (skb->len >= HDLCDRV_MAXFLEN+1 || skb->len < 3) { 782 if (skb->len >= HDLCDRV_MAXFLEN+1 || skb->len < 3) {
783 dev_kfree_skb(skb); 783 dev_kfree_skb(skb);
784 return 0; 784 return NETDEV_TX_OK;
785 } 785 }
786 netif_stop_queue(dev); 786 netif_stop_queue(dev);
787 bc->skb = skb; 787 bc->skb = skb;
788 return 0; 788 return NETDEV_TX_OK;
789} 789}
790 790
791/* --------------------------------------------------------------------- */ 791/* --------------------------------------------------------------------- */
diff --git a/drivers/net/hamradio/bpqether.c b/drivers/net/hamradio/bpqether.c
index abcd19a8bff9..4c5f4dfbe05e 100644
--- a/drivers/net/hamradio/bpqether.c
+++ b/drivers/net/hamradio/bpqether.c
@@ -305,7 +305,7 @@ static int bpq_xmit(struct sk_buff *skb, struct net_device *dev)
305 305
306 dev_queue_xmit(skb); 306 dev_queue_xmit(skb);
307 netif_wake_queue(dev); 307 netif_wake_queue(dev);
308 return 0; 308 return NETDEV_TX_OK;
309} 309}
310 310
311/* 311/*
diff --git a/drivers/net/hamradio/dmascc.c b/drivers/net/hamradio/dmascc.c
index 7459b3ac77a9..950f3bb21f9d 100644
--- a/drivers/net/hamradio/dmascc.c
+++ b/drivers/net/hamradio/dmascc.c
@@ -959,7 +959,7 @@ static int scc_send_packet(struct sk_buff *skb, struct net_device *dev)
959 spin_unlock_irqrestore(&priv->ring_lock, flags); 959 spin_unlock_irqrestore(&priv->ring_lock, flags);
960 dev_kfree_skb(skb); 960 dev_kfree_skb(skb);
961 961
962 return 0; 962 return NETDEV_TX_OK;
963} 963}
964 964
965 965
diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
index d034f8ca63cb..16b060b92117 100644
--- a/drivers/net/hamradio/hdlcdrv.c
+++ b/drivers/net/hamradio/hdlcdrv.c
@@ -406,13 +406,13 @@ static int hdlcdrv_send_packet(struct sk_buff *skb, struct net_device *dev)
406 if (skb->data[0] != 0) { 406 if (skb->data[0] != 0) {
407 do_kiss_params(sm, skb->data, skb->len); 407 do_kiss_params(sm, skb->data, skb->len);
408 dev_kfree_skb(skb); 408 dev_kfree_skb(skb);
409 return 0; 409 return NETDEV_TX_OK;
410 } 410 }
411 if (sm->skb) 411 if (sm->skb)
412 return NETDEV_TX_LOCKED; 412 return NETDEV_TX_LOCKED;
413 netif_stop_queue(dev); 413 netif_stop_queue(dev);
414 sm->skb = skb; 414 sm->skb = skb;
415 return 0; 415 return NETDEV_TX_OK;
416} 416}
417 417
418/* --------------------------------------------------------------------- */ 418/* --------------------------------------------------------------------- */
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index fda2fc83e9a1..ac191ef2119b 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -560,7 +560,7 @@ static int ax_xmit(struct sk_buff *skb, struct net_device *dev)
560 kfree_skb(skb); 560 kfree_skb(skb);
561 } 561 }
562 562
563 return 0; 563 return NETDEV_TX_OK;
564} 564}
565 565
566static int ax_open_dev(struct net_device *dev) 566static int ax_open_dev(struct net_device *dev)
diff --git a/drivers/net/hamradio/scc.c b/drivers/net/hamradio/scc.c
index d712e7af780c..c5406525c1ad 100644
--- a/drivers/net/hamradio/scc.c
+++ b/drivers/net/hamradio/scc.c
@@ -1643,7 +1643,7 @@ static int scc_net_tx(struct sk_buff *skb, struct net_device *dev)
1643 if (skb->len > scc->stat.bufsize || skb->len < 2) { 1643 if (skb->len > scc->stat.bufsize || skb->len < 2) {
1644 scc->dev_stat.tx_dropped++; /* bogus frame */ 1644 scc->dev_stat.tx_dropped++; /* bogus frame */
1645 dev_kfree_skb(skb); 1645 dev_kfree_skb(skb);
1646 return 0; 1646 return NETDEV_TX_OK;
1647 } 1647 }
1648 1648
1649 scc->dev_stat.tx_packets++; 1649 scc->dev_stat.tx_packets++;
@@ -1656,7 +1656,7 @@ static int scc_net_tx(struct sk_buff *skb, struct net_device *dev)
1656 if (kisscmd) { 1656 if (kisscmd) {
1657 scc_set_param(scc, kisscmd, *skb->data); 1657 scc_set_param(scc, kisscmd, *skb->data);
1658 dev_kfree_skb(skb); 1658 dev_kfree_skb(skb);
1659 return 0; 1659 return NETDEV_TX_OK;
1660 } 1660 }
1661 1661
1662 spin_lock_irqsave(&scc->lock, flags); 1662 spin_lock_irqsave(&scc->lock, flags);
@@ -1684,7 +1684,7 @@ static int scc_net_tx(struct sk_buff *skb, struct net_device *dev)
1684 __scc_start_tx_timer(scc, t_dwait, 0); 1684 __scc_start_tx_timer(scc, t_dwait, 0);
1685 } 1685 }
1686 spin_unlock_irqrestore(&scc->lock, flags); 1686 spin_unlock_irqrestore(&scc->lock, flags);
1687 return 0; 1687 return NETDEV_TX_OK;
1688} 1688}
1689 1689
1690/* ----> ioctl functions <---- */ 1690/* ----> ioctl functions <---- */
diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
index b06691937ce9..b85aa162314e 100644
--- a/drivers/net/hamradio/yam.c
+++ b/drivers/net/hamradio/yam.c
@@ -600,7 +600,7 @@ static int yam_send_packet(struct sk_buff *skb, struct net_device *dev)
600 600
601 skb_queue_tail(&yp->send_queue, skb); 601 skb_queue_tail(&yp->send_queue, skb);
602 dev->trans_start = jiffies; 602 dev->trans_start = jiffies;
603 return 0; 603 return NETDEV_TX_OK;
604} 604}
605 605
606static void yam_start_tx(struct net_device *dev, struct yam_port *yp) 606static void yam_start_tx(struct net_device *dev, struct yam_port *yp)
diff --git a/drivers/net/hp100.c b/drivers/net/hp100.c
index 1d3429a415e6..d1b63387e9bc 100644
--- a/drivers/net/hp100.c
+++ b/drivers/net/hp100.c
@@ -1499,7 +1499,7 @@ static int hp100_start_xmit_bm(struct sk_buff *skb, struct net_device *dev)
1499 goto drop; 1499 goto drop;
1500 1500
1501 if (lp->chip == HP100_CHIPID_SHASTA && skb_padto(skb, ETH_ZLEN)) 1501 if (lp->chip == HP100_CHIPID_SHASTA && skb_padto(skb, ETH_ZLEN))
1502 return 0; 1502 return NETDEV_TX_OK;
1503 1503
1504 /* Get Tx ring tail pointer */ 1504 /* Get Tx ring tail pointer */
1505 if (lp->txrtail->next == lp->txrhead) { 1505 if (lp->txrtail->next == lp->txrhead) {
@@ -1585,7 +1585,7 @@ static int hp100_start_xmit_bm(struct sk_buff *skb, struct net_device *dev)
1585 lp->stats.tx_bytes += skb->len; 1585 lp->stats.tx_bytes += skb->len;
1586 dev->trans_start = jiffies; 1586 dev->trans_start = jiffies;
1587 1587
1588 return 0; 1588 return NETDEV_TX_OK;
1589 1589
1590drop: 1590drop:
1591 dev_kfree_skb(skb); 1591 dev_kfree_skb(skb);
@@ -1752,7 +1752,7 @@ static int hp100_start_xmit(struct sk_buff *skb, struct net_device *dev)
1752 printk("hp100: %s: start_xmit: end\n", dev->name); 1752 printk("hp100: %s: start_xmit: end\n", dev->name);
1753#endif 1753#endif
1754 1754
1755 return 0; 1755 return NETDEV_TX_OK;
1756 1756
1757drop: 1757drop:
1758 dev_kfree_skb(skb); 1758 dev_kfree_skb(skb);
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index beb84213b671..5443558c439d 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -1342,7 +1342,7 @@ static inline int emac_xmit_finish(struct emac_instance *dev, int len)
1342 ++dev->stats.tx_packets; 1342 ++dev->stats.tx_packets;
1343 dev->stats.tx_bytes += len; 1343 dev->stats.tx_bytes += len;
1344 1344
1345 return 0; 1345 return NETDEV_TX_OK;
1346} 1346}
1347 1347
1348/* Tx lock BH */ 1348/* Tx lock BH */
diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index 0995c438f286..76b295a18185 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -971,7 +971,7 @@ out: spin_lock_irqsave(&adapter->stats_lock, flags);
971 spin_unlock_irqrestore(&adapter->stats_lock, flags); 971 spin_unlock_irqrestore(&adapter->stats_lock, flags);
972 972
973 dev_kfree_skb(skb); 973 dev_kfree_skb(skb);
974 return 0; 974 return NETDEV_TX_OK;
975} 975}
976 976
977static int ibmveth_poll(struct napi_struct *napi, int budget) 977static int ibmveth_poll(struct napi_struct *napi, int budget)
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index 96713ef06298..0a79b4517804 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -164,7 +164,7 @@ static int ifb_xmit(struct sk_buff *skb, struct net_device *dev)
164{ 164{
165 struct ifb_private *dp = netdev_priv(dev); 165 struct ifb_private *dp = netdev_priv(dev);
166 struct net_device_stats *stats = &dev->stats; 166 struct net_device_stats *stats = &dev->stats;
167 int ret = 0; 167 int ret = NETDEV_TX_OK;
168 u32 from = G_TC_FROM(skb->tc_verd); 168 u32 from = G_TC_FROM(skb->tc_verd);
169 169
170 stats->rx_packets++; 170 stats->rx_packets++;
diff --git a/drivers/net/ioc3-eth.c b/drivers/net/ioc3-eth.c
index e3cfefab670c..8ec15ab8c8c2 100644
--- a/drivers/net/ioc3-eth.c
+++ b/drivers/net/ioc3-eth.c
@@ -1515,7 +1515,7 @@ static int ioc3_start_xmit(struct sk_buff *skb, struct net_device *dev)
1515 1515
1516 spin_unlock_irq(&ip->ioc3_lock); 1516 spin_unlock_irq(&ip->ioc3_lock);
1517 1517
1518 return 0; 1518 return NETDEV_TX_OK;
1519} 1519}
1520 1520
1521static void ioc3_timeout(struct net_device *dev) 1521static void ioc3_timeout(struct net_device *dev)
diff --git a/drivers/net/irda/ali-ircc.c b/drivers/net/irda/ali-ircc.c
index ad1795580028..f0d0cea6e329 100644
--- a/drivers/net/irda/ali-ircc.c
+++ b/drivers/net/irda/ali-ircc.c
@@ -1466,7 +1466,7 @@ static int ali_ircc_fir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
1466 dev->trans_start = jiffies; 1466 dev->trans_start = jiffies;
1467 spin_unlock_irqrestore(&self->lock, flags); 1467 spin_unlock_irqrestore(&self->lock, flags);
1468 dev_kfree_skb(skb); 1468 dev_kfree_skb(skb);
1469 return 0; 1469 return NETDEV_TX_OK;
1470 } else 1470 } else
1471 self->new_speed = speed; 1471 self->new_speed = speed;
1472 } 1472 }
@@ -1577,7 +1577,7 @@ static int ali_ircc_fir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
1577 dev_kfree_skb(skb); 1577 dev_kfree_skb(skb);
1578 1578
1579 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ ); 1579 IRDA_DEBUG(1, "%s(), ----------------- End ------------------\n", __func__ );
1580 return 0; 1580 return NETDEV_TX_OK;
1581} 1581}
1582 1582
1583 1583
@@ -1966,10 +1966,10 @@ static int ali_ircc_sir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
1966 1966
1967 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__ ); 1967 IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __func__ );
1968 1968
1969 IRDA_ASSERT(dev != NULL, return 0;); 1969 IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
1970 1970
1971 self = netdev_priv(dev); 1971 self = netdev_priv(dev);
1972 IRDA_ASSERT(self != NULL, return 0;); 1972 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
1973 1973
1974 iobase = self->io.sir_base; 1974 iobase = self->io.sir_base;
1975 1975
@@ -1991,7 +1991,7 @@ static int ali_ircc_sir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
1991 dev->trans_start = jiffies; 1991 dev->trans_start = jiffies;
1992 spin_unlock_irqrestore(&self->lock, flags); 1992 spin_unlock_irqrestore(&self->lock, flags);
1993 dev_kfree_skb(skb); 1993 dev_kfree_skb(skb);
1994 return 0; 1994 return NETDEV_TX_OK;
1995 } else 1995 } else
1996 self->new_speed = speed; 1996 self->new_speed = speed;
1997 } 1997 }
@@ -2015,7 +2015,7 @@ static int ali_ircc_sir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
2015 2015
2016 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ ); 2016 IRDA_DEBUG(2, "%s(), ----------------- End ------------------\n", __func__ );
2017 2017
2018 return 0; 2018 return NETDEV_TX_OK;
2019} 2019}
2020 2020
2021 2021
diff --git a/drivers/net/irda/au1k_ir.c b/drivers/net/irda/au1k_ir.c
index c4361d466597..22baf65e1563 100644
--- a/drivers/net/irda/au1k_ir.c
+++ b/drivers/net/irda/au1k_ir.c
@@ -502,7 +502,7 @@ static int au1k_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
502 aup->newspeed = 0; 502 aup->newspeed = 0;
503 } 503 }
504 dev_kfree_skb(skb); 504 dev_kfree_skb(skb);
505 return 0; 505 return NETDEV_TX_OK;
506 } 506 }
507 507
508 ptxd = aup->tx_ring[aup->tx_head]; 508 ptxd = aup->tx_ring[aup->tx_head];
@@ -555,7 +555,7 @@ static int au1k_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
555 dev_kfree_skb(skb); 555 dev_kfree_skb(skb);
556 aup->tx_head = (aup->tx_head + 1) & (NUM_IR_DESC - 1); 556 aup->tx_head = (aup->tx_head + 1) & (NUM_IR_DESC - 1);
557 dev->trans_start = jiffies; 557 dev->trans_start = jiffies;
558 return 0; 558 return NETDEV_TX_OK;
559} 559}
560 560
561 561
diff --git a/drivers/net/irda/donauboe.c b/drivers/net/irda/donauboe.c
index 9a0346e751ac..e4e905698dc7 100644
--- a/drivers/net/irda/donauboe.c
+++ b/drivers/net/irda/donauboe.c
@@ -981,7 +981,7 @@ toshoboe_hard_xmit (struct sk_buff *skb, struct net_device *dev)
981 981
982 self = netdev_priv(dev); 982 self = netdev_priv(dev);
983 983
984 IRDA_ASSERT (self != NULL, return 0; ); 984 IRDA_ASSERT (self != NULL, return NETDEV_TX_OK; );
985 985
986 IRDA_DEBUG (1, "%s.tx:%x(%x)%x\n", __func__ 986 IRDA_DEBUG (1, "%s.tx:%x(%x)%x\n", __func__
987 ,skb->len,self->txpending,INB (OBOE_ENABLEH)); 987 ,skb->len,self->txpending,INB (OBOE_ENABLEH));
@@ -1021,7 +1021,7 @@ toshoboe_hard_xmit (struct sk_buff *skb, struct net_device *dev)
1021 { 1021 {
1022 spin_unlock_irqrestore(&self->spinlock, flags); 1022 spin_unlock_irqrestore(&self->spinlock, flags);
1023 dev_kfree_skb (skb); 1023 dev_kfree_skb (skb);
1024 return 0; 1024 return NETDEV_TX_OK;
1025 } 1025 }
1026 /* True packet, go on, but */ 1026 /* True packet, go on, but */
1027 /* do not accept anything before change speed execution */ 1027 /* do not accept anything before change speed execution */
@@ -1036,7 +1036,7 @@ toshoboe_hard_xmit (struct sk_buff *skb, struct net_device *dev)
1036 toshoboe_setbaud (self); 1036 toshoboe_setbaud (self);
1037 spin_unlock_irqrestore(&self->spinlock, flags); 1037 spin_unlock_irqrestore(&self->spinlock, flags);
1038 dev_kfree_skb (skb); 1038 dev_kfree_skb (skb);
1039 return 0; 1039 return NETDEV_TX_OK;
1040 } 1040 }
1041 1041
1042 } 1042 }
@@ -1143,7 +1143,7 @@ dumpbufs(skb->data,skb->len,'>');
1143 spin_unlock_irqrestore(&self->spinlock, flags); 1143 spin_unlock_irqrestore(&self->spinlock, flags);
1144 dev_kfree_skb (skb); 1144 dev_kfree_skb (skb);
1145 1145
1146 return 0; 1146 return NETDEV_TX_OK;
1147} 1147}
1148 1148
1149/*interrupt handler */ 1149/*interrupt handler */
diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
index 0c0831c03f64..6a1aa7a40fe2 100644
--- a/drivers/net/irda/irda-usb.c
+++ b/drivers/net/irda/irda-usb.c
@@ -534,7 +534,7 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
534 } 534 }
535 spin_unlock_irqrestore(&self->lock, flags); 535 spin_unlock_irqrestore(&self->lock, flags);
536 536
537 return 0; 537 return NETDEV_TX_OK;
538 538
539drop: 539drop:
540 /* Drop silently the skb and exit */ 540 /* Drop silently the skb and exit */
diff --git a/drivers/net/irda/nsc-ircc.c b/drivers/net/irda/nsc-ircc.c
index 45fd9c1eb343..51ca89c9a0ba 100644
--- a/drivers/net/irda/nsc-ircc.c
+++ b/drivers/net/irda/nsc-ircc.c
@@ -1365,7 +1365,7 @@ static int nsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
1365 1365
1366 self = netdev_priv(dev); 1366 self = netdev_priv(dev);
1367 1367
1368 IRDA_ASSERT(self != NULL, return 0;); 1368 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
1369 1369
1370 iobase = self->io.fir_base; 1370 iobase = self->io.fir_base;
1371 1371
@@ -1397,7 +1397,7 @@ static int nsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
1397 dev->trans_start = jiffies; 1397 dev->trans_start = jiffies;
1398 spin_unlock_irqrestore(&self->lock, flags); 1398 spin_unlock_irqrestore(&self->lock, flags);
1399 dev_kfree_skb(skb); 1399 dev_kfree_skb(skb);
1400 return 0; 1400 return NETDEV_TX_OK;
1401 } else 1401 } else
1402 self->new_speed = speed; 1402 self->new_speed = speed;
1403 } 1403 }
@@ -1424,7 +1424,7 @@ static int nsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
1424 1424
1425 dev_kfree_skb(skb); 1425 dev_kfree_skb(skb);
1426 1426
1427 return 0; 1427 return NETDEV_TX_OK;
1428} 1428}
1429 1429
1430static int nsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev) 1430static int nsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
@@ -1467,7 +1467,7 @@ static int nsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1467 dev->trans_start = jiffies; 1467 dev->trans_start = jiffies;
1468 spin_unlock_irqrestore(&self->lock, flags); 1468 spin_unlock_irqrestore(&self->lock, flags);
1469 dev_kfree_skb(skb); 1469 dev_kfree_skb(skb);
1470 return 0; 1470 return NETDEV_TX_OK;
1471 } else { 1471 } else {
1472 /* Change speed after current frame */ 1472 /* Change speed after current frame */
1473 self->new_speed = speed; 1473 self->new_speed = speed;
@@ -1554,7 +1554,7 @@ static int nsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1554 spin_unlock_irqrestore(&self->lock, flags); 1554 spin_unlock_irqrestore(&self->lock, flags);
1555 dev_kfree_skb(skb); 1555 dev_kfree_skb(skb);
1556 1556
1557 return 0; 1557 return NETDEV_TX_OK;
1558} 1558}
1559 1559
1560/* 1560/*
diff --git a/drivers/net/irda/pxaficp_ir.c b/drivers/net/irda/pxaficp_ir.c
index 3376a4f39e0a..e76a083f901a 100644
--- a/drivers/net/irda/pxaficp_ir.c
+++ b/drivers/net/irda/pxaficp_ir.c
@@ -504,7 +504,7 @@ static int pxa_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
504 pxa_irda_set_speed(si, speed); 504 pxa_irda_set_speed(si, speed);
505 } 505 }
506 dev_kfree_skb(skb); 506 dev_kfree_skb(skb);
507 return 0; 507 return NETDEV_TX_OK;
508 } 508 }
509 509
510 netif_stop_queue(dev); 510 netif_stop_queue(dev);
@@ -539,7 +539,7 @@ static int pxa_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
539 539
540 dev_kfree_skb(skb); 540 dev_kfree_skb(skb);
541 dev->trans_start = jiffies; 541 dev->trans_start = jiffies;
542 return 0; 542 return NETDEV_TX_OK;
543} 543}
544 544
545static int pxa_irda_ioctl(struct net_device *dev, struct ifreq *ifreq, int cmd) 545static int pxa_irda_ioctl(struct net_device *dev, struct ifreq *ifreq, int cmd)
diff --git a/drivers/net/irda/sa1100_ir.c b/drivers/net/irda/sa1100_ir.c
index 2aeb2e6aec1b..70e6acc597b0 100644
--- a/drivers/net/irda/sa1100_ir.c
+++ b/drivers/net/irda/sa1100_ir.c
@@ -667,7 +667,7 @@ static int sa1100_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
667 sa1100_irda_set_speed(si, speed); 667 sa1100_irda_set_speed(si, speed);
668 } 668 }
669 dev_kfree_skb(skb); 669 dev_kfree_skb(skb);
670 return 0; 670 return NETDEV_TX_OK;
671 } 671 }
672 672
673 if (!IS_FIR(si)) { 673 if (!IS_FIR(si)) {
@@ -715,7 +715,7 @@ static int sa1100_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
715 715
716 dev->trans_start = jiffies; 716 dev->trans_start = jiffies;
717 717
718 return 0; 718 return NETDEV_TX_OK;
719} 719}
720 720
721static int 721static int
diff --git a/drivers/net/irda/sir_dev.c b/drivers/net/irda/sir_dev.c
index fd0796c3db3c..71dce20e62be 100644
--- a/drivers/net/irda/sir_dev.c
+++ b/drivers/net/irda/sir_dev.c
@@ -590,7 +590,7 @@ static int sirdev_hard_xmit(struct sk_buff *skb, struct net_device *ndev)
590 int err; 590 int err;
591 s32 speed; 591 s32 speed;
592 592
593 IRDA_ASSERT(dev != NULL, return 0;); 593 IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
594 594
595 netif_stop_queue(ndev); 595 netif_stop_queue(ndev);
596 596
@@ -621,7 +621,7 @@ static int sirdev_hard_xmit(struct sk_buff *skb, struct net_device *ndev)
621 */ 621 */
622 622
623 dev_kfree_skb_any(skb); 623 dev_kfree_skb_any(skb);
624 return 0; 624 return NETDEV_TX_OK;
625 } else 625 } else
626 dev->new_speed = speed; 626 dev->new_speed = speed;
627 } 627 }
@@ -668,7 +668,7 @@ static int sirdev_hard_xmit(struct sk_buff *skb, struct net_device *ndev)
668 } 668 }
669 spin_unlock_irqrestore(&dev->tx_lock, flags); 669 spin_unlock_irqrestore(&dev->tx_lock, flags);
670 670
671 return 0; 671 return NETDEV_TX_OK;
672} 672}
673 673
674/* called from network layer with rtnl hold */ 674/* called from network layer with rtnl hold */
diff --git a/drivers/net/irda/smsc-ircc2.c b/drivers/net/irda/smsc-ircc2.c
index d0797adb5f8e..15f8a7f81600 100644
--- a/drivers/net/irda/smsc-ircc2.c
+++ b/drivers/net/irda/smsc-ircc2.c
@@ -886,10 +886,10 @@ static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
886 886
887 IRDA_DEBUG(1, "%s\n", __func__); 887 IRDA_DEBUG(1, "%s\n", __func__);
888 888
889 IRDA_ASSERT(dev != NULL, return 0;); 889 IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
890 890
891 self = netdev_priv(dev); 891 self = netdev_priv(dev);
892 IRDA_ASSERT(self != NULL, return 0;); 892 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
893 893
894 netif_stop_queue(dev); 894 netif_stop_queue(dev);
895 895
@@ -914,7 +914,7 @@ static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
914 smsc_ircc_change_speed(self, speed); 914 smsc_ircc_change_speed(self, speed);
915 spin_unlock_irqrestore(&self->lock, flags); 915 spin_unlock_irqrestore(&self->lock, flags);
916 dev_kfree_skb(skb); 916 dev_kfree_skb(skb);
917 return 0; 917 return NETDEV_TX_OK;
918 } 918 }
919 self->new_speed = speed; 919 self->new_speed = speed;
920 } 920 }
@@ -935,7 +935,7 @@ static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
935 935
936 dev_kfree_skb(skb); 936 dev_kfree_skb(skb);
937 937
938 return 0; 938 return NETDEV_TX_OK;
939} 939}
940 940
941/* 941/*
@@ -1190,9 +1190,9 @@ static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1190 s32 speed; 1190 s32 speed;
1191 int mtt; 1191 int mtt;
1192 1192
1193 IRDA_ASSERT(dev != NULL, return 0;); 1193 IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
1194 self = netdev_priv(dev); 1194 self = netdev_priv(dev);
1195 IRDA_ASSERT(self != NULL, return 0;); 1195 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
1196 1196
1197 netif_stop_queue(dev); 1197 netif_stop_queue(dev);
1198 1198
@@ -1210,7 +1210,7 @@ static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1210 smsc_ircc_change_speed(self, speed); 1210 smsc_ircc_change_speed(self, speed);
1211 spin_unlock_irqrestore(&self->lock, flags); 1211 spin_unlock_irqrestore(&self->lock, flags);
1212 dev_kfree_skb(skb); 1212 dev_kfree_skb(skb);
1213 return 0; 1213 return NETDEV_TX_OK;
1214 } 1214 }
1215 1215
1216 self->new_speed = speed; 1216 self->new_speed = speed;
@@ -1242,7 +1242,7 @@ static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1242 spin_unlock_irqrestore(&self->lock, flags); 1242 spin_unlock_irqrestore(&self->lock, flags);
1243 dev_kfree_skb(skb); 1243 dev_kfree_skb(skb);
1244 1244
1245 return 0; 1245 return NETDEV_TX_OK;
1246} 1246}
1247 1247
1248/* 1248/*
diff --git a/drivers/net/irda/stir4200.c b/drivers/net/irda/stir4200.c
index 8e5e45caf2f1..c475b23091bc 100644
--- a/drivers/net/irda/stir4200.c
+++ b/drivers/net/irda/stir4200.c
@@ -578,7 +578,7 @@ static int stir_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
578 dev_kfree_skb(skb); 578 dev_kfree_skb(skb);
579 } 579 }
580 580
581 return 0; 581 return NETDEV_TX_OK;
582} 582}
583 583
584/* 584/*
diff --git a/drivers/net/irda/via-ircc.c b/drivers/net/irda/via-ircc.c
index 864798502ff9..36a60748447b 100644
--- a/drivers/net/irda/via-ircc.c
+++ b/drivers/net/irda/via-ircc.c
@@ -832,7 +832,7 @@ static int via_ircc_hard_xmit_sir(struct sk_buff *skb,
832 __u32 speed; 832 __u32 speed;
833 833
834 self = netdev_priv(dev); 834 self = netdev_priv(dev);
835 IRDA_ASSERT(self != NULL, return 0;); 835 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
836 iobase = self->io.fir_base; 836 iobase = self->io.fir_base;
837 837
838 netif_stop_queue(dev); 838 netif_stop_queue(dev);
@@ -844,7 +844,7 @@ static int via_ircc_hard_xmit_sir(struct sk_buff *skb,
844 via_ircc_change_speed(self, speed); 844 via_ircc_change_speed(self, speed);
845 dev->trans_start = jiffies; 845 dev->trans_start = jiffies;
846 dev_kfree_skb(skb); 846 dev_kfree_skb(skb);
847 return 0; 847 return NETDEV_TX_OK;
848 } else 848 } else
849 self->new_speed = speed; 849 self->new_speed = speed;
850 } 850 }
@@ -892,7 +892,7 @@ static int via_ircc_hard_xmit_sir(struct sk_buff *skb,
892 dev->trans_start = jiffies; 892 dev->trans_start = jiffies;
893 spin_unlock_irqrestore(&self->lock, flags); 893 spin_unlock_irqrestore(&self->lock, flags);
894 dev_kfree_skb(skb); 894 dev_kfree_skb(skb);
895 return 0; 895 return NETDEV_TX_OK;
896} 896}
897 897
898static int via_ircc_hard_xmit_fir(struct sk_buff *skb, 898static int via_ircc_hard_xmit_fir(struct sk_buff *skb,
@@ -907,7 +907,7 @@ static int via_ircc_hard_xmit_fir(struct sk_buff *skb,
907 iobase = self->io.fir_base; 907 iobase = self->io.fir_base;
908 908
909 if (self->st_fifo.len) 909 if (self->st_fifo.len)
910 return 0; 910 return NETDEV_TX_OK;
911 if (self->chip_id == 0x3076) 911 if (self->chip_id == 0x3076)
912 iodelay(1500); 912 iodelay(1500);
913 else 913 else
@@ -919,7 +919,7 @@ static int via_ircc_hard_xmit_fir(struct sk_buff *skb,
919 via_ircc_change_speed(self, speed); 919 via_ircc_change_speed(self, speed);
920 dev->trans_start = jiffies; 920 dev->trans_start = jiffies;
921 dev_kfree_skb(skb); 921 dev_kfree_skb(skb);
922 return 0; 922 return NETDEV_TX_OK;
923 } else 923 } else
924 self->new_speed = speed; 924 self->new_speed = speed;
925 } 925 }
@@ -940,7 +940,7 @@ static int via_ircc_hard_xmit_fir(struct sk_buff *skb,
940 dev->trans_start = jiffies; 940 dev->trans_start = jiffies;
941 dev_kfree_skb(skb); 941 dev_kfree_skb(skb);
942 spin_unlock_irqrestore(&self->lock, flags); 942 spin_unlock_irqrestore(&self->lock, flags);
943 return 0; 943 return NETDEV_TX_OK;
944 944
945} 945}
946 946
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index ac0e4b6b6b66..08e26f1297b4 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -915,7 +915,7 @@ static int vlsi_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
915 */ 915 */
916 spin_unlock_irqrestore(&idev->lock, flags); 916 spin_unlock_irqrestore(&idev->lock, flags);
917 dev_kfree_skb_any(skb); 917 dev_kfree_skb_any(skb);
918 return 0; 918 return NETDEV_TX_OK;
919 } 919 }
920 920
921 /* sanity checks - simply drop the packet */ 921 /* sanity checks - simply drop the packet */
@@ -1044,7 +1044,7 @@ static int vlsi_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1044 } 1044 }
1045 spin_unlock_irqrestore(&idev->lock, flags); 1045 spin_unlock_irqrestore(&idev->lock, flags);
1046 1046
1047 return 0; 1047 return NETDEV_TX_OK;
1048 1048
1049drop_unlock: 1049drop_unlock:
1050 spin_unlock_irqrestore(&idev->lock, flags); 1050 spin_unlock_irqrestore(&idev->lock, flags);
@@ -1058,7 +1058,7 @@ drop:
1058 * packet for later retry of transmission - which isn't exactly 1058 * packet for later retry of transmission - which isn't exactly
1059 * what we want after we've just called dev_kfree_skb_any ;-) 1059 * what we want after we've just called dev_kfree_skb_any ;-)
1060 */ 1060 */
1061 return 0; 1061 return NETDEV_TX_OK;
1062} 1062}
1063 1063
1064static void vlsi_tx_interrupt(struct net_device *ndev) 1064static void vlsi_tx_interrupt(struct net_device *ndev)
diff --git a/drivers/net/irda/w83977af_ir.c b/drivers/net/irda/w83977af_ir.c
index d0883835b0c6..49ef76320f51 100644
--- a/drivers/net/irda/w83977af_ir.c
+++ b/drivers/net/irda/w83977af_ir.c
@@ -516,7 +516,7 @@ static int w83977af_hard_xmit(struct sk_buff *skb, struct net_device *dev)
516 w83977af_change_speed(self, speed); 516 w83977af_change_speed(self, speed);
517 dev->trans_start = jiffies; 517 dev->trans_start = jiffies;
518 dev_kfree_skb(skb); 518 dev_kfree_skb(skb);
519 return 0; 519 return NETDEV_TX_OK;
520 } else 520 } else
521 self->new_speed = speed; 521 self->new_speed = speed;
522 } 522 }
@@ -576,7 +576,7 @@ static int w83977af_hard_xmit(struct sk_buff *skb, struct net_device *dev)
576 /* Restore set register */ 576 /* Restore set register */
577 outb(set, iobase+SSR); 577 outb(set, iobase+SSR);
578 578
579 return 0; 579 return NETDEV_TX_OK;
580} 580}
581 581
582/* 582/*
diff --git a/drivers/net/isa-skeleton.c b/drivers/net/isa-skeleton.c
index d12377b84358..9706e64e367b 100644
--- a/drivers/net/isa-skeleton.c
+++ b/drivers/net/isa-skeleton.c
@@ -468,7 +468,7 @@ static int net_send_packet(struct sk_buff *skb, struct net_device *dev)
468 dev_kfree_skb (skb); 468 dev_kfree_skb (skb);
469#endif 469#endif
470 470
471 return 0; 471 return NETDEV_TX_OK;
472} 472}
473 473
474#if TX_RING 474#if TX_RING
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index e44215cb1882..e36e951cbc65 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -1205,7 +1205,7 @@ static int veth_start_xmit(struct sk_buff *skb, struct net_device *dev)
1205 1205
1206 if ( ! ((1 << rlp) & port->lpar_map) ) { 1206 if ( ! ((1 << rlp) & port->lpar_map) ) {
1207 dev_kfree_skb(skb); 1207 dev_kfree_skb(skb);
1208 return 0; 1208 return NETDEV_TX_OK;
1209 } 1209 }
1210 1210
1211 lpmask = 1 << rlp; 1211 lpmask = 1 << rlp;
@@ -1217,7 +1217,7 @@ static int veth_start_xmit(struct sk_buff *skb, struct net_device *dev)
1217 1217
1218 dev_kfree_skb(skb); 1218 dev_kfree_skb(skb);
1219 1219
1220 return 0; 1220 return NETDEV_TX_OK;
1221} 1221}
1222 1222
1223/* You must hold the connection's lock when you call this function. */ 1223/* You must hold the connection's lock when you call this function. */
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index 9c897cf86b9f..eb917f160274 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -1459,7 +1459,7 @@ ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1459 1459
1460 if (skb->len <= 0) { 1460 if (skb->len <= 0) {
1461 dev_kfree_skb(skb); 1461 dev_kfree_skb(skb);
1462 return 0; 1462 return NETDEV_TX_OK;
1463 } 1463 }
1464 1464
1465 if (unlikely(ixgb_maybe_stop_tx(netdev, &adapter->tx_ring, 1465 if (unlikely(ixgb_maybe_stop_tx(netdev, &adapter->tx_ring,
diff --git a/drivers/net/ixp2000/ixpdev.c b/drivers/net/ixp2000/ixpdev.c
index 2a0174b62e96..588b44d944ce 100644
--- a/drivers/net/ixp2000/ixpdev.c
+++ b/drivers/net/ixp2000/ixpdev.c
@@ -45,7 +45,7 @@ static int ixpdev_xmit(struct sk_buff *skb, struct net_device *dev)
45 if (unlikely(skb->len > PAGE_SIZE)) { 45 if (unlikely(skb->len > PAGE_SIZE)) {
46 /* @@@ Count drops. */ 46 /* @@@ Count drops. */
47 dev_kfree_skb(skb); 47 dev_kfree_skb(skb);
48 return 0; 48 return NETDEV_TX_OK;
49 } 49 }
50 50
51 entry = tx_pointer; 51 entry = tx_pointer;
@@ -69,7 +69,7 @@ static int ixpdev_xmit(struct sk_buff *skb, struct net_device *dev)
69 netif_stop_queue(dev); 69 netif_stop_queue(dev);
70 local_irq_enable(); 70 local_irq_enable();
71 71
72 return 0; 72 return NETDEV_TX_OK;
73} 73}
74 74
75 75
diff --git a/drivers/net/jme.c b/drivers/net/jme.c
index 1e3c63d67b91..e7068c7cd627 100644
--- a/drivers/net/jme.c
+++ b/drivers/net/jme.c
@@ -322,20 +322,6 @@ jme_stop_irq(struct jme_adapter *jme)
322 jwrite32f(jme, JME_IENC, INTR_ENABLE); 322 jwrite32f(jme, JME_IENC, INTR_ENABLE);
323} 323}
324 324
325static inline void
326jme_enable_shadow(struct jme_adapter *jme)
327{
328 jwrite32(jme,
329 JME_SHBA_LO,
330 ((u32)jme->shadow_dma & ~((u32)0x1F)) | SHBA_POSTEN);
331}
332
333static inline void
334jme_disable_shadow(struct jme_adapter *jme)
335{
336 jwrite32(jme, JME_SHBA_LO, 0x0);
337}
338
339static u32 325static u32
340jme_linkstat_from_phy(struct jme_adapter *jme) 326jme_linkstat_from_phy(struct jme_adapter *jme)
341{ 327{
@@ -522,12 +508,8 @@ jme_setup_tx_resources(struct jme_adapter *jme)
522 &(txring->dmaalloc), 508 &(txring->dmaalloc),
523 GFP_ATOMIC); 509 GFP_ATOMIC);
524 510
525 if (!txring->alloc) { 511 if (!txring->alloc)
526 txring->desc = NULL; 512 goto err_set_null;
527 txring->dmaalloc = 0;
528 txring->dma = 0;
529 return -ENOMEM;
530 }
531 513
532 /* 514 /*
533 * 16 Bytes align 515 * 16 Bytes align
@@ -539,6 +521,11 @@ jme_setup_tx_resources(struct jme_adapter *jme)
539 atomic_set(&txring->next_to_clean, 0); 521 atomic_set(&txring->next_to_clean, 0);
540 atomic_set(&txring->nr_free, jme->tx_ring_size); 522 atomic_set(&txring->nr_free, jme->tx_ring_size);
541 523
524 txring->bufinf = kmalloc(sizeof(struct jme_buffer_info) *
525 jme->tx_ring_size, GFP_ATOMIC);
526 if (unlikely(!(txring->bufinf)))
527 goto err_free_txring;
528
542 /* 529 /*
543 * Initialize Transmit Descriptors 530 * Initialize Transmit Descriptors
544 */ 531 */
@@ -547,6 +534,20 @@ jme_setup_tx_resources(struct jme_adapter *jme)
547 sizeof(struct jme_buffer_info) * jme->tx_ring_size); 534 sizeof(struct jme_buffer_info) * jme->tx_ring_size);
548 535
549 return 0; 536 return 0;
537
538err_free_txring:
539 dma_free_coherent(&(jme->pdev->dev),
540 TX_RING_ALLOC_SIZE(jme->tx_ring_size),
541 txring->alloc,
542 txring->dmaalloc);
543
544err_set_null:
545 txring->desc = NULL;
546 txring->dmaalloc = 0;
547 txring->dma = 0;
548 txring->bufinf = NULL;
549
550 return -ENOMEM;
550} 551}
551 552
552static void 553static void
@@ -554,19 +555,22 @@ jme_free_tx_resources(struct jme_adapter *jme)
554{ 555{
555 int i; 556 int i;
556 struct jme_ring *txring = &(jme->txring[0]); 557 struct jme_ring *txring = &(jme->txring[0]);
557 struct jme_buffer_info *txbi = txring->bufinf; 558 struct jme_buffer_info *txbi;
558 559
559 if (txring->alloc) { 560 if (txring->alloc) {
560 for (i = 0 ; i < jme->tx_ring_size ; ++i) { 561 if (txring->bufinf) {
561 txbi = txring->bufinf + i; 562 for (i = 0 ; i < jme->tx_ring_size ; ++i) {
562 if (txbi->skb) { 563 txbi = txring->bufinf + i;
563 dev_kfree_skb(txbi->skb); 564 if (txbi->skb) {
564 txbi->skb = NULL; 565 dev_kfree_skb(txbi->skb);
566 txbi->skb = NULL;
567 }
568 txbi->mapping = 0;
569 txbi->len = 0;
570 txbi->nr_desc = 0;
571 txbi->start_xmit = 0;
565 } 572 }
566 txbi->mapping = 0; 573 kfree(txring->bufinf);
567 txbi->len = 0;
568 txbi->nr_desc = 0;
569 txbi->start_xmit = 0;
570 } 574 }
571 575
572 dma_free_coherent(&(jme->pdev->dev), 576 dma_free_coherent(&(jme->pdev->dev),
@@ -578,11 +582,11 @@ jme_free_tx_resources(struct jme_adapter *jme)
578 txring->desc = NULL; 582 txring->desc = NULL;
579 txring->dmaalloc = 0; 583 txring->dmaalloc = 0;
580 txring->dma = 0; 584 txring->dma = 0;
585 txring->bufinf = NULL;
581 } 586 }
582 txring->next_to_use = 0; 587 txring->next_to_use = 0;
583 atomic_set(&txring->next_to_clean, 0); 588 atomic_set(&txring->next_to_clean, 0);
584 atomic_set(&txring->nr_free, 0); 589 atomic_set(&txring->nr_free, 0);
585
586} 590}
587 591
588static inline void 592static inline void
@@ -653,7 +657,7 @@ jme_disable_tx_engine(struct jme_adapter *jme)
653static void 657static void
654jme_set_clean_rxdesc(struct jme_adapter *jme, int i) 658jme_set_clean_rxdesc(struct jme_adapter *jme, int i)
655{ 659{
656 struct jme_ring *rxring = jme->rxring; 660 struct jme_ring *rxring = &(jme->rxring[0]);
657 register struct rxdesc *rxdesc = rxring->desc; 661 register struct rxdesc *rxdesc = rxring->desc;
658 struct jme_buffer_info *rxbi = rxring->bufinf; 662 struct jme_buffer_info *rxbi = rxring->bufinf;
659 rxdesc += i; 663 rxdesc += i;
@@ -720,8 +724,11 @@ jme_free_rx_resources(struct jme_adapter *jme)
720 struct jme_ring *rxring = &(jme->rxring[0]); 724 struct jme_ring *rxring = &(jme->rxring[0]);
721 725
722 if (rxring->alloc) { 726 if (rxring->alloc) {
723 for (i = 0 ; i < jme->rx_ring_size ; ++i) 727 if (rxring->bufinf) {
724 jme_free_rx_buf(jme, i); 728 for (i = 0 ; i < jme->rx_ring_size ; ++i)
729 jme_free_rx_buf(jme, i);
730 kfree(rxring->bufinf);
731 }
725 732
726 dma_free_coherent(&(jme->pdev->dev), 733 dma_free_coherent(&(jme->pdev->dev),
727 RX_RING_ALLOC_SIZE(jme->rx_ring_size), 734 RX_RING_ALLOC_SIZE(jme->rx_ring_size),
@@ -731,6 +738,7 @@ jme_free_rx_resources(struct jme_adapter *jme)
731 rxring->desc = NULL; 738 rxring->desc = NULL;
732 rxring->dmaalloc = 0; 739 rxring->dmaalloc = 0;
733 rxring->dma = 0; 740 rxring->dma = 0;
741 rxring->bufinf = NULL;
734 } 742 }
735 rxring->next_to_use = 0; 743 rxring->next_to_use = 0;
736 atomic_set(&rxring->next_to_clean, 0); 744 atomic_set(&rxring->next_to_clean, 0);
@@ -746,12 +754,8 @@ jme_setup_rx_resources(struct jme_adapter *jme)
746 RX_RING_ALLOC_SIZE(jme->rx_ring_size), 754 RX_RING_ALLOC_SIZE(jme->rx_ring_size),
747 &(rxring->dmaalloc), 755 &(rxring->dmaalloc),
748 GFP_ATOMIC); 756 GFP_ATOMIC);
749 if (!rxring->alloc) { 757 if (!rxring->alloc)
750 rxring->desc = NULL; 758 goto err_set_null;
751 rxring->dmaalloc = 0;
752 rxring->dma = 0;
753 return -ENOMEM;
754 }
755 759
756 /* 760 /*
757 * 16 Bytes align 761 * 16 Bytes align
@@ -762,9 +766,16 @@ jme_setup_rx_resources(struct jme_adapter *jme)
762 rxring->next_to_use = 0; 766 rxring->next_to_use = 0;
763 atomic_set(&rxring->next_to_clean, 0); 767 atomic_set(&rxring->next_to_clean, 0);
764 768
769 rxring->bufinf = kmalloc(sizeof(struct jme_buffer_info) *
770 jme->rx_ring_size, GFP_ATOMIC);
771 if (unlikely(!(rxring->bufinf)))
772 goto err_free_rxring;
773
765 /* 774 /*
766 * Initiallize Receive Descriptors 775 * Initiallize Receive Descriptors
767 */ 776 */
777 memset(rxring->bufinf, 0,
778 sizeof(struct jme_buffer_info) * jme->rx_ring_size);
768 for (i = 0 ; i < jme->rx_ring_size ; ++i) { 779 for (i = 0 ; i < jme->rx_ring_size ; ++i) {
769 if (unlikely(jme_make_new_rx_buf(jme, i))) { 780 if (unlikely(jme_make_new_rx_buf(jme, i))) {
770 jme_free_rx_resources(jme); 781 jme_free_rx_resources(jme);
@@ -775,6 +786,19 @@ jme_setup_rx_resources(struct jme_adapter *jme)
775 } 786 }
776 787
777 return 0; 788 return 0;
789
790err_free_rxring:
791 dma_free_coherent(&(jme->pdev->dev),
792 RX_RING_ALLOC_SIZE(jme->rx_ring_size),
793 rxring->alloc,
794 rxring->dmaalloc);
795err_set_null:
796 rxring->desc = NULL;
797 rxring->dmaalloc = 0;
798 rxring->dma = 0;
799 rxring->bufinf = NULL;
800
801 return -ENOMEM;
778} 802}
779 803
780static inline void 804static inline void
@@ -790,9 +814,9 @@ jme_enable_rx_engine(struct jme_adapter *jme)
790 /* 814 /*
791 * Setup RX DMA Bass Address 815 * Setup RX DMA Bass Address
792 */ 816 */
793 jwrite32(jme, JME_RXDBA_LO, (__u64)jme->rxring[0].dma & 0xFFFFFFFFUL); 817 jwrite32(jme, JME_RXDBA_LO, (__u64)(jme->rxring[0].dma) & 0xFFFFFFFFUL);
794 jwrite32(jme, JME_RXDBA_HI, (__u64)(jme->rxring[0].dma) >> 32); 818 jwrite32(jme, JME_RXDBA_HI, (__u64)(jme->rxring[0].dma) >> 32);
795 jwrite32(jme, JME_RXNDA, (__u64)jme->rxring[0].dma & 0xFFFFFFFFUL); 819 jwrite32(jme, JME_RXNDA, (__u64)(jme->rxring[0].dma) & 0xFFFFFFFFUL);
796 820
797 /* 821 /*
798 * Setup RX Descriptor Count 822 * Setup RX Descriptor Count
@@ -856,27 +880,27 @@ jme_rxsum_ok(struct jme_adapter *jme, u16 flags)
856 if (!(flags & (RXWBFLAG_TCPON | RXWBFLAG_UDPON | RXWBFLAG_IPV4))) 880 if (!(flags & (RXWBFLAG_TCPON | RXWBFLAG_UDPON | RXWBFLAG_IPV4)))
857 return false; 881 return false;
858 882
859 if (unlikely(!(flags & RXWBFLAG_MF) && 883 if (unlikely((flags & (RXWBFLAG_MF | RXWBFLAG_TCPON | RXWBFLAG_TCPCS))
860 (flags & RXWBFLAG_TCPON) && !(flags & RXWBFLAG_TCPCS))) { 884 == RXWBFLAG_TCPON)) {
861 msg_rx_err(jme, "TCP Checksum error.\n"); 885 if (flags & RXWBFLAG_IPV4)
862 goto out_sumerr; 886 msg_rx_err(jme, "TCP Checksum error\n");
887 return false;
863 } 888 }
864 889
865 if (unlikely(!(flags & RXWBFLAG_MF) && 890 if (unlikely((flags & (RXWBFLAG_MF | RXWBFLAG_UDPON | RXWBFLAG_UDPCS))
866 (flags & RXWBFLAG_UDPON) && !(flags & RXWBFLAG_UDPCS))) { 891 == RXWBFLAG_UDPON)) {
867 msg_rx_err(jme, "UDP Checksum error.\n"); 892 if (flags & RXWBFLAG_IPV4)
868 goto out_sumerr; 893 msg_rx_err(jme, "UDP Checksum error.\n");
894 return false;
869 } 895 }
870 896
871 if (unlikely((flags & RXWBFLAG_IPV4) && !(flags & RXWBFLAG_IPCS))) { 897 if (unlikely((flags & (RXWBFLAG_IPV4 | RXWBFLAG_IPCS))
898 == RXWBFLAG_IPV4)) {
872 msg_rx_err(jme, "IPv4 Checksum error.\n"); 899 msg_rx_err(jme, "IPv4 Checksum error.\n");
873 goto out_sumerr; 900 return false;
874 } 901 }
875 902
876 return true; 903 return true;
877
878out_sumerr:
879 return false;
880} 904}
881 905
882static void 906static void
@@ -1296,7 +1320,7 @@ jme_rx_empty_tasklet(unsigned long arg)
1296static void 1320static void
1297jme_wake_queue_if_stopped(struct jme_adapter *jme) 1321jme_wake_queue_if_stopped(struct jme_adapter *jme)
1298{ 1322{
1299 struct jme_ring *txring = jme->txring; 1323 struct jme_ring *txring = &(jme->txring[0]);
1300 1324
1301 smp_wmb(); 1325 smp_wmb();
1302 if (unlikely(netif_queue_stopped(jme->dev) && 1326 if (unlikely(netif_queue_stopped(jme->dev) &&
@@ -1483,12 +1507,7 @@ jme_msi(int irq, void *dev_id)
1483 struct jme_adapter *jme = netdev_priv(netdev); 1507 struct jme_adapter *jme = netdev_priv(netdev);
1484 u32 intrstat; 1508 u32 intrstat;
1485 1509
1486 pci_dma_sync_single_for_cpu(jme->pdev, 1510 intrstat = jread32(jme, JME_IEVE);
1487 jme->shadow_dma,
1488 sizeof(u32) * SHADOW_REG_NR,
1489 PCI_DMA_FROMDEVICE);
1490 intrstat = jme->shadow_regs[SHADOW_IEVE];
1491 jme->shadow_regs[SHADOW_IEVE] = 0;
1492 1511
1493 jme_intr_msi(jme, intrstat); 1512 jme_intr_msi(jme, intrstat);
1494 1513
@@ -1566,6 +1585,7 @@ jme_open(struct net_device *netdev)
1566 jme_clear_pm(jme); 1585 jme_clear_pm(jme);
1567 JME_NAPI_ENABLE(jme); 1586 JME_NAPI_ENABLE(jme);
1568 1587
1588 tasklet_enable(&jme->linkch_task);
1569 tasklet_enable(&jme->txclean_task); 1589 tasklet_enable(&jme->txclean_task);
1570 tasklet_hi_enable(&jme->rxclean_task); 1590 tasklet_hi_enable(&jme->rxclean_task);
1571 tasklet_hi_enable(&jme->rxempty_task); 1591 tasklet_hi_enable(&jme->rxempty_task);
@@ -1574,7 +1594,6 @@ jme_open(struct net_device *netdev)
1574 if (rc) 1594 if (rc)
1575 goto err_out; 1595 goto err_out;
1576 1596
1577 jme_enable_shadow(jme);
1578 jme_start_irq(jme); 1597 jme_start_irq(jme);
1579 1598
1580 if (test_bit(JME_FLAG_SSET, &jme->flags)) 1599 if (test_bit(JME_FLAG_SSET, &jme->flags))
@@ -1642,15 +1661,14 @@ jme_close(struct net_device *netdev)
1642 netif_carrier_off(netdev); 1661 netif_carrier_off(netdev);
1643 1662
1644 jme_stop_irq(jme); 1663 jme_stop_irq(jme);
1645 jme_disable_shadow(jme);
1646 jme_free_irq(jme); 1664 jme_free_irq(jme);
1647 1665
1648 JME_NAPI_DISABLE(jme); 1666 JME_NAPI_DISABLE(jme);
1649 1667
1650 tasklet_kill(&jme->linkch_task); 1668 tasklet_disable(&jme->linkch_task);
1651 tasklet_kill(&jme->txclean_task); 1669 tasklet_disable(&jme->txclean_task);
1652 tasklet_kill(&jme->rxclean_task); 1670 tasklet_disable(&jme->rxclean_task);
1653 tasklet_kill(&jme->rxempty_task); 1671 tasklet_disable(&jme->rxempty_task);
1654 1672
1655 jme_reset_ghc_speed(jme); 1673 jme_reset_ghc_speed(jme);
1656 jme_disable_rx_engine(jme); 1674 jme_disable_rx_engine(jme);
@@ -1668,7 +1686,7 @@ static int
1668jme_alloc_txdesc(struct jme_adapter *jme, 1686jme_alloc_txdesc(struct jme_adapter *jme,
1669 struct sk_buff *skb) 1687 struct sk_buff *skb)
1670{ 1688{
1671 struct jme_ring *txring = jme->txring; 1689 struct jme_ring *txring = &(jme->txring[0]);
1672 int idx, nr_alloc, mask = jme->tx_ring_mask; 1690 int idx, nr_alloc, mask = jme->tx_ring_mask;
1673 1691
1674 idx = txring->next_to_use; 1692 idx = txring->next_to_use;
@@ -1722,7 +1740,7 @@ jme_fill_tx_map(struct pci_dev *pdev,
1722static void 1740static void
1723jme_map_tx_skb(struct jme_adapter *jme, struct sk_buff *skb, int idx) 1741jme_map_tx_skb(struct jme_adapter *jme, struct sk_buff *skb, int idx)
1724{ 1742{
1725 struct jme_ring *txring = jme->txring; 1743 struct jme_ring *txring = &(jme->txring[0]);
1726 struct txdesc *txdesc = txring->desc, *ctxdesc; 1744 struct txdesc *txdesc = txring->desc, *ctxdesc;
1727 struct jme_buffer_info *txbi = txring->bufinf, *ctxbi; 1745 struct jme_buffer_info *txbi = txring->bufinf, *ctxbi;
1728 u8 hidma = jme->dev->features & NETIF_F_HIGHDMA; 1746 u8 hidma = jme->dev->features & NETIF_F_HIGHDMA;
@@ -1835,7 +1853,7 @@ jme_tx_vlan(struct sk_buff *skb, __le16 *vlan, u8 *flags)
1835static int 1853static int
1836jme_fill_tx_desc(struct jme_adapter *jme, struct sk_buff *skb, int idx) 1854jme_fill_tx_desc(struct jme_adapter *jme, struct sk_buff *skb, int idx)
1837{ 1855{
1838 struct jme_ring *txring = jme->txring; 1856 struct jme_ring *txring = &(jme->txring[0]);
1839 struct txdesc *txdesc; 1857 struct txdesc *txdesc;
1840 struct jme_buffer_info *txbi; 1858 struct jme_buffer_info *txbi;
1841 u8 flags; 1859 u8 flags;
@@ -1883,7 +1901,7 @@ jme_fill_tx_desc(struct jme_adapter *jme, struct sk_buff *skb, int idx)
1883static void 1901static void
1884jme_stop_queue_if_full(struct jme_adapter *jme) 1902jme_stop_queue_if_full(struct jme_adapter *jme)
1885{ 1903{
1886 struct jme_ring *txring = jme->txring; 1904 struct jme_ring *txring = &(jme->txring[0]);
1887 struct jme_buffer_info *txbi = txring->bufinf; 1905 struct jme_buffer_info *txbi = txring->bufinf;
1888 int idx = atomic_read(&txring->next_to_clean); 1906 int idx = atomic_read(&txring->next_to_clean);
1889 1907
@@ -2725,14 +2743,6 @@ jme_init_one(struct pci_dev *pdev,
2725 rc = -ENOMEM; 2743 rc = -ENOMEM;
2726 goto err_out_free_netdev; 2744 goto err_out_free_netdev;
2727 } 2745 }
2728 jme->shadow_regs = pci_alloc_consistent(pdev,
2729 sizeof(u32) * SHADOW_REG_NR,
2730 &(jme->shadow_dma));
2731 if (!(jme->shadow_regs)) {
2732 jeprintk(pdev, "Allocating shadow register mapping error.\n");
2733 rc = -ENOMEM;
2734 goto err_out_unmap;
2735 }
2736 2746
2737 if (no_pseudohp) { 2747 if (no_pseudohp) {
2738 apmc = jread32(jme, JME_APMC) & ~JME_APMC_PSEUDO_HP_EN; 2748 apmc = jread32(jme, JME_APMC) & ~JME_APMC_PSEUDO_HP_EN;
@@ -2768,6 +2778,7 @@ jme_init_one(struct pci_dev *pdev,
2768 tasklet_init(&jme->rxempty_task, 2778 tasklet_init(&jme->rxempty_task,
2769 &jme_rx_empty_tasklet, 2779 &jme_rx_empty_tasklet,
2770 (unsigned long) jme); 2780 (unsigned long) jme);
2781 tasklet_disable_nosync(&jme->linkch_task);
2771 tasklet_disable_nosync(&jme->txclean_task); 2782 tasklet_disable_nosync(&jme->txclean_task);
2772 tasklet_disable_nosync(&jme->rxclean_task); 2783 tasklet_disable_nosync(&jme->rxclean_task);
2773 tasklet_disable_nosync(&jme->rxempty_task); 2784 tasklet_disable_nosync(&jme->rxempty_task);
@@ -2817,7 +2828,7 @@ jme_init_one(struct pci_dev *pdev,
2817 if (!jme->mii_if.phy_id) { 2828 if (!jme->mii_if.phy_id) {
2818 rc = -EIO; 2829 rc = -EIO;
2819 jeprintk(pdev, "Can not find phy_id.\n"); 2830 jeprintk(pdev, "Can not find phy_id.\n");
2820 goto err_out_free_shadow; 2831 goto err_out_unmap;
2821 } 2832 }
2822 2833
2823 jme->reg_ghc |= GHC_LINK_POLL; 2834 jme->reg_ghc |= GHC_LINK_POLL;
@@ -2846,7 +2857,7 @@ jme_init_one(struct pci_dev *pdev,
2846 if (rc) { 2857 if (rc) {
2847 jeprintk(pdev, 2858 jeprintk(pdev,
2848 "Reload eeprom for reading MAC Address error.\n"); 2859 "Reload eeprom for reading MAC Address error.\n");
2849 goto err_out_free_shadow; 2860 goto err_out_unmap;
2850 } 2861 }
2851 jme_load_macaddr(netdev); 2862 jme_load_macaddr(netdev);
2852 2863
@@ -2862,7 +2873,7 @@ jme_init_one(struct pci_dev *pdev,
2862 rc = register_netdev(netdev); 2873 rc = register_netdev(netdev);
2863 if (rc) { 2874 if (rc) {
2864 jeprintk(pdev, "Cannot register net device.\n"); 2875 jeprintk(pdev, "Cannot register net device.\n");
2865 goto err_out_free_shadow; 2876 goto err_out_unmap;
2866 } 2877 }
2867 2878
2868 msg_probe(jme, "%s%s ver:%x rev:%x macaddr:%pM\n", 2879 msg_probe(jme, "%s%s ver:%x rev:%x macaddr:%pM\n",
@@ -2876,11 +2887,6 @@ jme_init_one(struct pci_dev *pdev,
2876 2887
2877 return 0; 2888 return 0;
2878 2889
2879err_out_free_shadow:
2880 pci_free_consistent(pdev,
2881 sizeof(u32) * SHADOW_REG_NR,
2882 jme->shadow_regs,
2883 jme->shadow_dma);
2884err_out_unmap: 2890err_out_unmap:
2885 iounmap(jme->regs); 2891 iounmap(jme->regs);
2886err_out_free_netdev: 2892err_out_free_netdev:
@@ -2901,10 +2907,6 @@ jme_remove_one(struct pci_dev *pdev)
2901 struct jme_adapter *jme = netdev_priv(netdev); 2907 struct jme_adapter *jme = netdev_priv(netdev);
2902 2908
2903 unregister_netdev(netdev); 2909 unregister_netdev(netdev);
2904 pci_free_consistent(pdev,
2905 sizeof(u32) * SHADOW_REG_NR,
2906 jme->shadow_regs,
2907 jme->shadow_dma);
2908 iounmap(jme->regs); 2910 iounmap(jme->regs);
2909 pci_set_drvdata(pdev, NULL); 2911 pci_set_drvdata(pdev, NULL);
2910 free_netdev(netdev); 2912 free_netdev(netdev);
@@ -2930,8 +2932,6 @@ jme_suspend(struct pci_dev *pdev, pm_message_t state)
2930 tasklet_disable(&jme->rxclean_task); 2932 tasklet_disable(&jme->rxclean_task);
2931 tasklet_disable(&jme->rxempty_task); 2933 tasklet_disable(&jme->rxempty_task);
2932 2934
2933 jme_disable_shadow(jme);
2934
2935 if (netif_carrier_ok(netdev)) { 2935 if (netif_carrier_ok(netdev)) {
2936 if (test_bit(JME_FLAG_POLL, &jme->flags)) 2936 if (test_bit(JME_FLAG_POLL, &jme->flags))
2937 jme_polling_mode(jme); 2937 jme_polling_mode(jme);
@@ -2983,7 +2983,6 @@ jme_resume(struct pci_dev *pdev)
2983 else 2983 else
2984 jme_reset_phy_processor(jme); 2984 jme_reset_phy_processor(jme);
2985 2985
2986 jme_enable_shadow(jme);
2987 jme_start_irq(jme); 2986 jme_start_irq(jme);
2988 netif_device_attach(netdev); 2987 netif_device_attach(netdev);
2989 2988
diff --git a/drivers/net/jme.h b/drivers/net/jme.h
index 0996a069ac7b..251abed3817e 100644
--- a/drivers/net/jme.h
+++ b/drivers/net/jme.h
@@ -25,7 +25,7 @@
25#define __JME_H_INCLUDED__ 25#define __JME_H_INCLUDED__
26 26
27#define DRV_NAME "jme" 27#define DRV_NAME "jme"
28#define DRV_VERSION "1.0.4" 28#define DRV_VERSION "1.0.5"
29#define PFX DRV_NAME ": " 29#define PFX DRV_NAME ": "
30 30
31#define PCI_DEVICE_ID_JMICRON_JMC250 0x0250 31#define PCI_DEVICE_ID_JMICRON_JMC250 0x0250
@@ -247,7 +247,7 @@ enum jme_txdesc_flags_bits {
247}; 247};
248 248
249#define TXDESC_MSS_SHIFT 2 249#define TXDESC_MSS_SHIFT 2
250enum jme_rxdescwb_flags_bits { 250enum jme_txwbdesc_flags_bits {
251 TXWBFLAG_OWN = 0x80, 251 TXWBFLAG_OWN = 0x80,
252 TXWBFLAG_INT = 0x40, 252 TXWBFLAG_INT = 0x40,
253 TXWBFLAG_TMOUT = 0x20, 253 TXWBFLAG_TMOUT = 0x20,
@@ -372,7 +372,6 @@ struct jme_buffer_info {
372/* 372/*
373 * The structure holding buffer information and ring descriptors all together. 373 * The structure holding buffer information and ring descriptors all together.
374 */ 374 */
375#define MAX_RING_DESC_NR 1024
376struct jme_ring { 375struct jme_ring {
377 void *alloc; /* pointer to allocated memory */ 376 void *alloc; /* pointer to allocated memory */
378 void *desc; /* pointer to ring memory */ 377 void *desc; /* pointer to ring memory */
@@ -380,7 +379,7 @@ struct jme_ring {
380 dma_addr_t dma; /* phys address for ring dma */ 379 dma_addr_t dma; /* phys address for ring dma */
381 380
382 /* Buffer information corresponding to each descriptor */ 381 /* Buffer information corresponding to each descriptor */
383 struct jme_buffer_info bufinf[MAX_RING_DESC_NR]; 382 struct jme_buffer_info *bufinf;
384 383
385 int next_to_use; 384 int next_to_use;
386 atomic_t next_to_clean; 385 atomic_t next_to_clean;
@@ -411,13 +410,10 @@ struct jme_ring {
411/* 410/*
412 * Jmac Adapter Private data 411 * Jmac Adapter Private data
413 */ 412 */
414#define SHADOW_REG_NR 8
415struct jme_adapter { 413struct jme_adapter {
416 struct pci_dev *pdev; 414 struct pci_dev *pdev;
417 struct net_device *dev; 415 struct net_device *dev;
418 void __iomem *regs; 416 void __iomem *regs;
419 dma_addr_t shadow_dma;
420 u32 *shadow_regs;
421 struct mii_if_info mii_if; 417 struct mii_if_info mii_if;
422 struct jme_ring rxring[RX_RING_NR]; 418 struct jme_ring rxring[RX_RING_NR];
423 struct jme_ring txring[TX_RING_NR]; 419 struct jme_ring txring[TX_RING_NR];
@@ -464,10 +460,6 @@ struct jme_adapter {
464 DECLARE_NET_DEVICE_STATS 460 DECLARE_NET_DEVICE_STATS
465}; 461};
466 462
467enum shadow_reg_val {
468 SHADOW_IEVE = 0,
469};
470
471enum jme_flags_bits { 463enum jme_flags_bits {
472 JME_FLAG_MSI = 1, 464 JME_FLAG_MSI = 1,
473 JME_FLAG_SSET = 2, 465 JME_FLAG_SSET = 2,
@@ -1104,13 +1096,6 @@ enum jme_chipmode_shifts {
1104}; 1096};
1105 1097
1106/* 1098/*
1107 * Shadow base address register bits
1108 */
1109enum jme_shadow_base_address_bits {
1110 SHBA_POSTEN = 0x1,
1111};
1112
1113/*
1114 * Aggressive Power Mode Control 1099 * Aggressive Power Mode Control
1115 */ 1100 */
1116enum jme_apmc_bits { 1101enum jme_apmc_bits {
diff --git a/drivers/net/lance.c b/drivers/net/lance.c
index 633808d447be..30fd4f5f1d5a 100644
--- a/drivers/net/lance.c
+++ b/drivers/net/lance.c
@@ -1016,7 +1016,7 @@ static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
1016 1016
1017out: 1017out:
1018 spin_unlock_irqrestore(&lp->devlock, flags); 1018 spin_unlock_irqrestore(&lp->devlock, flags);
1019 return 0; 1019 return NETDEV_TX_OK;
1020} 1020}
1021 1021
1022/* The LANCE interrupt handler. */ 1022/* The LANCE interrupt handler. */
diff --git a/drivers/net/lib82596.c b/drivers/net/lib82596.c
index 070fa4500871..51e11c3e53e1 100644
--- a/drivers/net/lib82596.c
+++ b/drivers/net/lib82596.c
@@ -983,7 +983,7 @@ static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
983 983
984 if (length < ETH_ZLEN) { 984 if (length < ETH_ZLEN) {
985 if (skb_padto(skb, ETH_ZLEN)) 985 if (skb_padto(skb, ETH_ZLEN))
986 return 0; 986 return NETDEV_TX_OK;
987 length = ETH_ZLEN; 987 length = ETH_ZLEN;
988 } 988 }
989 989
@@ -1028,7 +1028,7 @@ static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
1028 1028
1029 netif_start_queue(dev); 1029 netif_start_queue(dev);
1030 1030
1031 return 0; 1031 return NETDEV_TX_OK;
1032} 1032}
1033 1033
1034static void print_eth(unsigned char *add, char *str) 1034static void print_eth(unsigned char *add, char *str)
diff --git a/drivers/net/lib8390.c b/drivers/net/lib8390.c
index f28c23343009..d6be36000c5c 100644
--- a/drivers/net/lib8390.c
+++ b/drivers/net/lib8390.c
@@ -414,7 +414,7 @@ static int __ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
414 dev_kfree_skb (skb); 414 dev_kfree_skb (skb);
415 dev->stats.tx_bytes += send_length; 415 dev->stats.tx_bytes += send_length;
416 416
417 return 0; 417 return NETDEV_TX_OK;
418} 418}
419 419
420/** 420/**
diff --git a/drivers/net/ll_temac_main.c b/drivers/net/ll_temac_main.c
index 96e7248876c1..da8d0a0ca94f 100644
--- a/drivers/net/ll_temac_main.c
+++ b/drivers/net/ll_temac_main.c
@@ -591,7 +591,7 @@ static int temac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
591 /* Kick off the transfer */ 591 /* Kick off the transfer */
592 temac_dma_out32(lp, TX_TAILDESC_PTR, tail_p); /* DMA start */ 592 temac_dma_out32(lp, TX_TAILDESC_PTR, tail_p); /* DMA start */
593 593
594 return 0; 594 return NETDEV_TX_OK;
595} 595}
596 596
597 597
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index da472c687481..51bbce72bede 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -89,7 +89,7 @@ static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
89 } else 89 } else
90 lb_stats->drops++; 90 lb_stats->drops++;
91 91
92 return 0; 92 return NETDEV_TX_OK;
93} 93}
94 94
95static struct net_device_stats *loopback_get_stats(struct net_device *dev) 95static struct net_device_stats *loopback_get_stats(struct net_device *dev)
diff --git a/drivers/net/lp486e.c b/drivers/net/lp486e.c
index d44bddbee373..c292bad411ee 100644
--- a/drivers/net/lp486e.c
+++ b/drivers/net/lp486e.c
@@ -871,7 +871,7 @@ static int i596_start_xmit (struct sk_buff *skb, struct net_device *dev) {
871 871
872 if (length < ETH_ZLEN) { 872 if (length < ETH_ZLEN) {
873 if (skb_padto(skb, ETH_ZLEN)) 873 if (skb_padto(skb, ETH_ZLEN))
874 return 0; 874 return NETDEV_TX_OK;
875 length = ETH_ZLEN; 875 length = ETH_ZLEN;
876 } 876 }
877 877
@@ -906,7 +906,7 @@ static int i596_start_xmit (struct sk_buff *skb, struct net_device *dev) {
906 dev->stats.tx_packets++; 906 dev->stats.tx_packets++;
907 } 907 }
908 908
909 return 0; 909 return NETDEV_TX_OK;
910} 910}
911 911
912static void 912static void
diff --git a/drivers/net/mac89x0.c b/drivers/net/mac89x0.c
index dab45339d3a8..149e0ed4a055 100644
--- a/drivers/net/mac89x0.c
+++ b/drivers/net/mac89x0.c
@@ -411,7 +411,7 @@ net_send_packet(struct sk_buff *skb, struct net_device *dev)
411 dev->trans_start = jiffies; 411 dev->trans_start = jiffies;
412 dev_kfree_skb (skb); 412 dev_kfree_skb (skb);
413 413
414 return 0; 414 return NETDEV_TX_OK;
415} 415}
416 416
417/* The typical workload of the driver: 417/* The typical workload of the driver:
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 5b5c25368d1e..d22952c78f13 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -678,7 +678,7 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
678 678
679 dev->trans_start = jiffies; 679 dev->trans_start = jiffies;
680 680
681 return 0; 681 return NETDEV_TX_OK;
682} 682}
683 683
684static void macb_free_consistent(struct macb *bp) 684static void macb_free_consistent(struct macb *bp)
diff --git a/drivers/net/mace.c b/drivers/net/mace.c
index 1427755c224d..7d7577b598ea 100644
--- a/drivers/net/mace.c
+++ b/drivers/net/mace.c
@@ -581,7 +581,7 @@ static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev)
581 netif_stop_queue(dev); 581 netif_stop_queue(dev);
582 spin_unlock_irqrestore(&mp->lock, flags); 582 spin_unlock_irqrestore(&mp->lock, flags);
583 583
584 return 0; 584 return NETDEV_TX_OK;
585} 585}
586 586
587static void mace_set_multicast(struct net_device *dev) 587static void mace_set_multicast(struct net_device *dev)
diff --git a/drivers/net/meth.c b/drivers/net/meth.c
index 5d04d94f2a21..abea35de255f 100644
--- a/drivers/net/meth.c
+++ b/drivers/net/meth.c
@@ -715,7 +715,7 @@ static int meth_tx(struct sk_buff *skb, struct net_device *dev)
715 715
716 spin_unlock_irqrestore(&priv->meth_lock, flags); 716 spin_unlock_irqrestore(&priv->meth_lock, flags);
717 717
718 return 0; 718 return NETDEV_TX_OK;
719} 719}
720 720
721/* 721/*
diff --git a/drivers/net/mipsnet.c b/drivers/net/mipsnet.c
index b3b9a147d09a..8ea98bd89ff1 100644
--- a/drivers/net/mipsnet.c
+++ b/drivers/net/mipsnet.c
@@ -141,7 +141,7 @@ static int mipsnet_xmit(struct sk_buff *skb, struct net_device *dev)
141 netif_stop_queue(dev); 141 netif_stop_queue(dev);
142 mipsnet_put_todevice(dev, skb); 142 mipsnet_put_todevice(dev, skb);
143 143
144 return 0; 144 return NETDEV_TX_OK;
145} 145}
146 146
147static inline ssize_t mipsnet_get_fromdev(struct net_device *dev, size_t len) 147static inline ssize_t mipsnet_get_fromdev(struct net_device *dev, size_t len)
diff --git a/drivers/net/mlx4/en_tx.c b/drivers/net/mlx4/en_tx.c
index 08c43f2ae72b..d5c18c674255 100644
--- a/drivers/net/mlx4/en_tx.c
+++ b/drivers/net/mlx4/en_tx.c
@@ -764,7 +764,7 @@ int mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev)
764 /* Poll CQ here */ 764 /* Poll CQ here */
765 mlx4_en_xmit_poll(priv, tx_ind); 765 mlx4_en_xmit_poll(priv, tx_ind);
766 766
767 return 0; 767 return NETDEV_TX_OK;
768 768
769tx_drop: 769tx_drop:
770 dev_kfree_skb_any(skb); 770 dev_kfree_skb_any(skb);
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 1f6e36ea669e..1a34f7e11d98 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -2748,7 +2748,7 @@ again:
2748 /* The packet is gone, so we must 2748 /* The packet is gone, so we must
2749 * return 0 */ 2749 * return 0 */
2750 ss->stats.tx_dropped += 1; 2750 ss->stats.tx_dropped += 1;
2751 return 0; 2751 return NETDEV_TX_OK;
2752 } 2752 }
2753 /* adjust the len to account for the zero pad 2753 /* adjust the len to account for the zero pad
2754 * so that the nic can know how long it is */ 2754 * so that the nic can know how long it is */
@@ -2892,7 +2892,7 @@ again:
2892 tx->stop_queue++; 2892 tx->stop_queue++;
2893 netif_tx_stop_queue(netdev_queue); 2893 netif_tx_stop_queue(netdev_queue);
2894 } 2894 }
2895 return 0; 2895 return NETDEV_TX_OK;
2896 2896
2897abort_linearize: 2897abort_linearize:
2898 /* Free any DMA resources we've alloced and clear out the skb 2898 /* Free any DMA resources we've alloced and clear out the skb
@@ -2936,7 +2936,7 @@ abort_linearize:
2936drop: 2936drop:
2937 dev_kfree_skb_any(skb); 2937 dev_kfree_skb_any(skb);
2938 ss->stats.tx_dropped += 1; 2938 ss->stats.tx_dropped += 1;
2939 return 0; 2939 return NETDEV_TX_OK;
2940 2940
2941} 2941}
2942 2942
@@ -2968,13 +2968,13 @@ static int myri10ge_sw_tso(struct sk_buff *skb, struct net_device *dev)
2968 } 2968 }
2969 } 2969 }
2970 dev_kfree_skb_any(skb); 2970 dev_kfree_skb_any(skb);
2971 return 0; 2971 return NETDEV_TX_OK;
2972 2972
2973drop: 2973drop:
2974 ss = &mgp->ss[skb_get_queue_mapping(skb)]; 2974 ss = &mgp->ss[skb_get_queue_mapping(skb)];
2975 dev_kfree_skb_any(skb); 2975 dev_kfree_skb_any(skb);
2976 ss->stats.tx_dropped += 1; 2976 ss->stats.tx_dropped += 1;
2977 return 0; 2977 return NETDEV_TX_OK;
2978} 2978}
2979 2979
2980static struct net_device_stats *myri10ge_get_stats(struct net_device *dev) 2980static struct net_device_stats *myri10ge_get_stats(struct net_device *dev)
diff --git a/drivers/net/myri_sbus.c b/drivers/net/myri_sbus.c
index 5f0758bda6b3..29ebebc6a95b 100644
--- a/drivers/net/myri_sbus.c
+++ b/drivers/net/myri_sbus.c
@@ -692,7 +692,7 @@ static int myri_start_xmit(struct sk_buff *skb, struct net_device *dev)
692 DTX(("tbusy=0, returning 0\n")); 692 DTX(("tbusy=0, returning 0\n"));
693 netif_start_queue(dev); 693 netif_start_queue(dev);
694 spin_unlock_irqrestore(&mp->irq_lock, flags); 694 spin_unlock_irqrestore(&mp->irq_lock, flags);
695 return 0; 695 return NETDEV_TX_OK;
696} 696}
697 697
698/* Create the MyriNet MAC header for an arbitrary protocol layer 698/* Create the MyriNet MAC header for an arbitrary protocol layer
diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c
index c9bfe4eea189..481aa2d287a3 100644
--- a/drivers/net/natsemi.c
+++ b/drivers/net/natsemi.c
@@ -2125,7 +2125,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
2125 printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n", 2125 printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n",
2126 dev->name, np->cur_tx, entry); 2126 dev->name, np->cur_tx, entry);
2127 } 2127 }
2128 return 0; 2128 return NETDEV_TX_OK;
2129} 2129}
2130 2130
2131static void netdev_tx_done(struct net_device *dev) 2131static void netdev_tx_done(struct net_device *dev)
diff --git a/drivers/net/netx-eth.c b/drivers/net/netx-eth.c
index 946366dcc992..9f4235466d59 100644
--- a/drivers/net/netx-eth.c
+++ b/drivers/net/netx-eth.c
@@ -134,7 +134,7 @@ netx_eth_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
134 spin_unlock_irq(&priv->lock); 134 spin_unlock_irq(&priv->lock);
135 dev_kfree_skb(skb); 135 dev_kfree_skb(skb);
136 136
137 return 0; 137 return NETDEV_TX_OK;
138} 138}
139 139
140static void netx_eth_receive(struct net_device *ndev) 140static void netx_eth_receive(struct net_device *ndev)
diff --git a/drivers/net/ni5010.c b/drivers/net/ni5010.c
index 2a8da476ab3d..462d20f26436 100644
--- a/drivers/net/ni5010.c
+++ b/drivers/net/ni5010.c
@@ -463,7 +463,7 @@ static int ni5010_send_packet(struct sk_buff *skb, struct net_device *dev)
463 hardware_send_packet(dev, (unsigned char *)skb->data, skb->len, length-skb->len); 463 hardware_send_packet(dev, (unsigned char *)skb->data, skb->len, length-skb->len);
464 dev->trans_start = jiffies; 464 dev->trans_start = jiffies;
465 dev_kfree_skb (skb); 465 dev_kfree_skb (skb);
466 return 0; 466 return NETDEV_TX_OK;
467} 467}
468 468
469/* 469/*
diff --git a/drivers/net/ni52.c b/drivers/net/ni52.c
index 77d44a061703..a0ac5d4f27d3 100644
--- a/drivers/net/ni52.c
+++ b/drivers/net/ni52.c
@@ -1183,7 +1183,7 @@ static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
1183 1183
1184 if (skb->len > XMIT_BUFF_SIZE) { 1184 if (skb->len > XMIT_BUFF_SIZE) {
1185 printk(KERN_ERR "%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n", dev->name, XMIT_BUFF_SIZE, skb->len); 1185 printk(KERN_ERR "%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n", dev->name, XMIT_BUFF_SIZE, skb->len);
1186 return 0; 1186 return NETDEV_TX_OK;
1187 } 1187 }
1188 1188
1189 netif_stop_queue(dev); 1189 netif_stop_queue(dev);
@@ -1267,7 +1267,7 @@ static int ni52_send_packet(struct sk_buff *skb, struct net_device *dev)
1267 } 1267 }
1268 dev_kfree_skb(skb); 1268 dev_kfree_skb(skb);
1269#endif 1269#endif
1270 return 0; 1270 return NETDEV_TX_OK;
1271} 1271}
1272 1272
1273/******************************************* 1273/*******************************************
diff --git a/drivers/net/ni65.c b/drivers/net/ni65.c
index 1f10ed603e20..81a061785898 100644
--- a/drivers/net/ni65.c
+++ b/drivers/net/ni65.c
@@ -1216,7 +1216,7 @@ static int ni65_send_packet(struct sk_buff *skb, struct net_device *dev)
1216 spin_unlock_irqrestore(&p->ring_lock, flags); 1216 spin_unlock_irqrestore(&p->ring_lock, flags);
1217 } 1217 }
1218 1218
1219 return 0; 1219 return NETDEV_TX_OK;
1220} 1220}
1221 1221
1222static void set_multicast_list(struct net_device *dev) 1222static void set_multicast_list(struct net_device *dev)
diff --git a/drivers/net/pci-skeleton.c b/drivers/net/pci-skeleton.c
index 8c1f6988f398..e4a93b8ed485 100644
--- a/drivers/net/pci-skeleton.c
+++ b/drivers/net/pci-skeleton.c
@@ -1356,7 +1356,7 @@ static int netdrv_start_xmit (struct sk_buff *skb, struct net_device *dev)
1356 DPRINTK ("%s: Queued Tx packet at %p size %u to slot %d.\n", 1356 DPRINTK ("%s: Queued Tx packet at %p size %u to slot %d.\n",
1357 dev->name, skb->data, skb->len, entry); 1357 dev->name, skb->data, skb->len, entry);
1358 1358
1359 return 0; 1359 return NETDEV_TX_OK;
1360} 1360}
1361 1361
1362 1362
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index f35c609ba020..a23aa8724042 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -806,7 +806,7 @@ static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
806 pop_tx_status(dev); 806 pop_tx_status(dev);
807 spin_unlock_irqrestore(&lp->window_lock, flags); 807 spin_unlock_irqrestore(&lp->window_lock, flags);
808 dev_kfree_skb(skb); 808 dev_kfree_skb(skb);
809 return 0; 809 return NETDEV_TX_OK;
810} 810}
811 811
812/* The EL3 interrupt handler. */ 812/* The EL3 interrupt handler. */
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index ec7cf5ac4f05..a77417c51e44 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -635,7 +635,7 @@ static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
635 spin_unlock_irqrestore(&priv->lock, flags); 635 spin_unlock_irqrestore(&priv->lock, flags);
636 dev_kfree_skb(skb); 636 dev_kfree_skb(skb);
637 637
638 return 0; 638 return NETDEV_TX_OK;
639} 639}
640 640
641/* The EL3 interrupt handler. */ 641/* The EL3 interrupt handler. */
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index 0e38d80fd255..b5cfac7c5179 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -1179,7 +1179,7 @@ static int axnet_start_xmit(struct sk_buff *skb, struct net_device *dev)
1179 dev_kfree_skb (skb); 1179 dev_kfree_skb (skb);
1180 dev->stats.tx_bytes += send_length; 1180 dev->stats.tx_bytes += send_length;
1181 1181
1182 return 0; 1182 return NETDEV_TX_OK;
1183} 1183}
1184 1184
1185/** 1185/**
diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c
index 479d5b494371..434d9407bfb3 100644
--- a/drivers/net/pcmcia/fmvj18x_cs.c
+++ b/drivers/net/pcmcia/fmvj18x_cs.c
@@ -865,7 +865,7 @@ static int fjn_start_xmit(struct sk_buff *skb, struct net_device *dev)
865 if (length < ETH_ZLEN) 865 if (length < ETH_ZLEN)
866 { 866 {
867 if (skb_padto(skb, ETH_ZLEN)) 867 if (skb_padto(skb, ETH_ZLEN))
868 return 0; 868 return NETDEV_TX_OK;
869 length = ETH_ZLEN; 869 length = ETH_ZLEN;
870 } 870 }
871 871
@@ -924,7 +924,7 @@ static int fjn_start_xmit(struct sk_buff *skb, struct net_device *dev)
924 } 924 }
925 dev_kfree_skb (skb); 925 dev_kfree_skb (skb);
926 926
927 return 0; 927 return NETDEV_TX_OK;
928} /* fjn_start_xmit */ 928} /* fjn_start_xmit */
929 929
930/*====================================================================*/ 930/*====================================================================*/
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c
index 02ef63ed1f99..0f8118a82579 100644
--- a/drivers/net/pcmcia/nmclan_cs.c
+++ b/drivers/net/pcmcia/nmclan_cs.c
@@ -990,7 +990,7 @@ static int mace_start_xmit(struct sk_buff *skb, struct net_device *dev)
990 990
991 dev_kfree_skb(skb); 991 dev_kfree_skb(skb);
992 992
993 return 0; 993 return NETDEV_TX_OK;
994} /* mace_start_xmit */ 994} /* mace_start_xmit */
995 995
996/* ---------------------------------------------------------------------------- 996/* ----------------------------------------------------------------------------
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 37e05d3ab893..2f39244c17f2 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -1399,7 +1399,7 @@ static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1399 dev_kfree_skb (skb); 1399 dev_kfree_skb (skb);
1400 smc->saved_skb = NULL; 1400 smc->saved_skb = NULL;
1401 dev->stats.tx_dropped++; 1401 dev->stats.tx_dropped++;
1402 return 0; /* Do not re-queue this packet. */ 1402 return NETDEV_TX_OK; /* Do not re-queue this packet. */
1403 } 1403 }
1404 /* A packet is now waiting. */ 1404 /* A packet is now waiting. */
1405 smc->packets_waiting++; 1405 smc->packets_waiting++;
@@ -1422,7 +1422,7 @@ static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1422 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT); 1422 outw((ir&0xff00) | IM_ALLOC_INT, ioaddr + INTERRUPT);
1423 smc_hardware_send_packet(dev); /* Send the packet now.. */ 1423 smc_hardware_send_packet(dev); /* Send the packet now.. */
1424 spin_unlock_irqrestore(&smc->lock, flags); 1424 spin_unlock_irqrestore(&smc->lock, flags);
1425 return 0; 1425 return NETDEV_TX_OK;
1426 } 1426 }
1427 } 1427 }
1428 1428
@@ -1431,7 +1431,7 @@ static int smc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1431 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT); 1431 outw((IM_ALLOC_INT << 8) | (ir & 0xff00), ioaddr + INTERRUPT);
1432 spin_unlock_irqrestore(&smc->lock, flags); 1432 spin_unlock_irqrestore(&smc->lock, flags);
1433 1433
1434 return 0; 1434 return NETDEV_TX_OK;
1435} 1435}
1436 1436
1437/*====================================================================== 1437/*======================================================================
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index ef37d22c7e1d..eda7bf6047cd 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -1384,7 +1384,7 @@ do_start_xmit(struct sk_buff *skb, struct net_device *dev)
1384 if (pktlen < ETH_ZLEN) 1384 if (pktlen < ETH_ZLEN)
1385 { 1385 {
1386 if (skb_padto(skb, ETH_ZLEN)) 1386 if (skb_padto(skb, ETH_ZLEN))
1387 return 0; 1387 return NETDEV_TX_OK;
1388 pktlen = ETH_ZLEN; 1388 pktlen = ETH_ZLEN;
1389 } 1389 }
1390 1390
@@ -1414,7 +1414,7 @@ do_start_xmit(struct sk_buff *skb, struct net_device *dev)
1414 dev->trans_start = jiffies; 1414 dev->trans_start = jiffies;
1415 dev->stats.tx_bytes += pktlen; 1415 dev->stats.tx_bytes += pktlen;
1416 netif_start_queue(dev); 1416 netif_start_queue(dev);
1417 return 0; 1417 return NETDEV_TX_OK;
1418} 1418}
1419 1419
1420/**************** 1420/****************
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index 1c35e1d637a0..955a87ac9afa 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -2536,7 +2536,7 @@ static int pcnet32_start_xmit(struct sk_buff *skb, struct net_device *dev)
2536 netif_stop_queue(dev); 2536 netif_stop_queue(dev);
2537 } 2537 }
2538 spin_unlock_irqrestore(&lp->lock, flags); 2538 spin_unlock_irqrestore(&lp->lock, flags);
2539 return 0; 2539 return NETDEV_TX_OK;
2540} 2540}
2541 2541
2542/* The PCNET32 interrupt handler. */ 2542/* The PCNET32 interrupt handler. */
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index de9cf5136fdc..d5d8e1c5bc91 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -56,6 +56,12 @@ config BROADCOM_PHY
56 Currently supports the BCM5411, BCM5421, BCM5461, BCM5464, BCM5481 56 Currently supports the BCM5411, BCM5421, BCM5461, BCM5464, BCM5481
57 and BCM5482 PHYs. 57 and BCM5482 PHYs.
58 58
59config BCM63XX_PHY
60 tristate "Drivers for Broadcom 63xx SOCs internal PHY"
61 depends on BCM63XX
62 ---help---
63 Currently supports the 6348 and 6358 PHYs.
64
59config ICPLUS_PHY 65config ICPLUS_PHY
60 tristate "Drivers for ICPlus PHYs" 66 tristate "Drivers for ICPlus PHYs"
61 ---help--- 67 ---help---
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 3a1bfefefbc3..edfaac48cbd5 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_QSEMI_PHY) += qsemi.o
11obj-$(CONFIG_SMSC_PHY) += smsc.o 11obj-$(CONFIG_SMSC_PHY) += smsc.o
12obj-$(CONFIG_VITESSE_PHY) += vitesse.o 12obj-$(CONFIG_VITESSE_PHY) += vitesse.o
13obj-$(CONFIG_BROADCOM_PHY) += broadcom.o 13obj-$(CONFIG_BROADCOM_PHY) += broadcom.o
14obj-$(CONFIG_BCM63XX_PHY) += bcm63xx.o
14obj-$(CONFIG_ICPLUS_PHY) += icplus.o 15obj-$(CONFIG_ICPLUS_PHY) += icplus.o
15obj-$(CONFIG_REALTEK_PHY) += realtek.o 16obj-$(CONFIG_REALTEK_PHY) += realtek.o
16obj-$(CONFIG_LSI_ET1011C_PHY) += et1011c.o 17obj-$(CONFIG_LSI_ET1011C_PHY) += et1011c.o
diff --git a/drivers/net/phy/bcm63xx.c b/drivers/net/phy/bcm63xx.c
new file mode 100644
index 000000000000..4fed95e8350e
--- /dev/null
+++ b/drivers/net/phy/bcm63xx.c
@@ -0,0 +1,132 @@
1/*
2 * Driver for Broadcom 63xx SOCs integrated PHYs
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9#include <linux/module.h>
10#include <linux/phy.h>
11
12#define MII_BCM63XX_IR 0x1a /* interrupt register */
13#define MII_BCM63XX_IR_EN 0x4000 /* global interrupt enable */
14#define MII_BCM63XX_IR_DUPLEX 0x0800 /* duplex changed */
15#define MII_BCM63XX_IR_SPEED 0x0400 /* speed changed */
16#define MII_BCM63XX_IR_LINK 0x0200 /* link changed */
17#define MII_BCM63XX_IR_GMASK 0x0100 /* global interrupt mask */
18
19MODULE_DESCRIPTION("Broadcom 63xx internal PHY driver");
20MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
21MODULE_LICENSE("GPL");
22
23static int bcm63xx_config_init(struct phy_device *phydev)
24{
25 int reg, err;
26
27 reg = phy_read(phydev, MII_BCM63XX_IR);
28 if (reg < 0)
29 return reg;
30
31 /* Mask interrupts globally. */
32 reg |= MII_BCM63XX_IR_GMASK;
33 err = phy_write(phydev, MII_BCM63XX_IR, reg);
34 if (err < 0)
35 return err;
36
37 /* Unmask events we are interested in */
38 reg = ~(MII_BCM63XX_IR_DUPLEX |
39 MII_BCM63XX_IR_SPEED |
40 MII_BCM63XX_IR_LINK) |
41 MII_BCM63XX_IR_EN;
42 err = phy_write(phydev, MII_BCM63XX_IR, reg);
43 if (err < 0)
44 return err;
45 return 0;
46}
47
48static int bcm63xx_ack_interrupt(struct phy_device *phydev)
49{
50 int reg;
51
52 /* Clear pending interrupts. */
53 reg = phy_read(phydev, MII_BCM63XX_IR);
54 if (reg < 0)
55 return reg;
56
57 return 0;
58}
59
60static int bcm63xx_config_intr(struct phy_device *phydev)
61{
62 int reg, err;
63
64 reg = phy_read(phydev, MII_BCM63XX_IR);
65 if (reg < 0)
66 return reg;
67
68 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
69 reg &= ~MII_BCM63XX_IR_GMASK;
70 else
71 reg |= MII_BCM63XX_IR_GMASK;
72
73 err = phy_write(phydev, MII_BCM63XX_IR, reg);
74 return err;
75}
76
77static struct phy_driver bcm63xx_1_driver = {
78 .phy_id = 0x00406000,
79 .phy_id_mask = 0xfffffc00,
80 .name = "Broadcom BCM63XX (1)",
81 /* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */
82 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
83 .flags = PHY_HAS_INTERRUPT,
84 .config_init = bcm63xx_config_init,
85 .config_aneg = genphy_config_aneg,
86 .read_status = genphy_read_status,
87 .ack_interrupt = bcm63xx_ack_interrupt,
88 .config_intr = bcm63xx_config_intr,
89 .driver = { .owner = THIS_MODULE },
90};
91
92/* same phy as above, with just a different OUI */
93static struct phy_driver bcm63xx_2_driver = {
94 .phy_id = 0x002bdc00,
95 .phy_id_mask = 0xfffffc00,
96 .name = "Broadcom BCM63XX (2)",
97 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
98 .flags = PHY_HAS_INTERRUPT,
99 .config_init = bcm63xx_config_init,
100 .config_aneg = genphy_config_aneg,
101 .read_status = genphy_read_status,
102 .ack_interrupt = bcm63xx_ack_interrupt,
103 .config_intr = bcm63xx_config_intr,
104 .driver = { .owner = THIS_MODULE },
105};
106
107static int __init bcm63xx_phy_init(void)
108{
109 int ret;
110
111 ret = phy_driver_register(&bcm63xx_1_driver);
112 if (ret)
113 goto out_63xx_1;
114 ret = phy_driver_register(&bcm63xx_2_driver);
115 if (ret)
116 goto out_63xx_2;
117 return ret;
118
119out_63xx_2:
120 phy_driver_unregister(&bcm63xx_1_driver);
121out_63xx_1:
122 return ret;
123}
124
125static void __exit bcm63xx_phy_exit(void)
126{
127 phy_driver_unregister(&bcm63xx_1_driver);
128 phy_driver_unregister(&bcm63xx_2_driver);
129}
130
131module_init(bcm63xx_phy_init);
132module_exit(bcm63xx_phy_exit);
diff --git a/drivers/net/plip.c b/drivers/net/plip.c
index 2ca8b0d84ee2..00487f569cfd 100644
--- a/drivers/net/plip.c
+++ b/drivers/net/plip.c
@@ -990,7 +990,7 @@ plip_tx_packet(struct sk_buff *skb, struct net_device *dev)
990 schedule_work(&nl->immediate); 990 schedule_work(&nl->immediate);
991 spin_unlock_irq(&nl->lock); 991 spin_unlock_irq(&nl->lock);
992 992
993 return 0; 993 return NETDEV_TX_OK;
994} 994}
995 995
996static void 996static void
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 639d11bc444e..d0b965517b46 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -988,12 +988,12 @@ ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
988 netif_stop_queue(dev); 988 netif_stop_queue(dev);
989 skb_queue_tail(&ppp->file.xq, skb); 989 skb_queue_tail(&ppp->file.xq, skb);
990 ppp_xmit_process(ppp); 990 ppp_xmit_process(ppp);
991 return 0; 991 return NETDEV_TX_OK;
992 992
993 outf: 993 outf:
994 kfree_skb(skb); 994 kfree_skb(skb);
995 ++dev->stats.tx_dropped; 995 ++dev->stats.tx_dropped;
996 return 0; 996 return NETDEV_TX_OK;
997} 997}
998 998
999static int 999static int
diff --git a/drivers/net/r6040.c b/drivers/net/r6040.c
index 961b5397a531..840677f5ee82 100644
--- a/drivers/net/r6040.c
+++ b/drivers/net/r6040.c
@@ -1115,13 +1115,13 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
1115 } 1115 }
1116 1116
1117 /* IO Size check */ 1117 /* IO Size check */
1118 if (pci_resource_len(pdev, 0) < io_size) { 1118 if (pci_resource_len(pdev, bar) < io_size) {
1119 printk(KERN_ERR DRV_NAME ": Insufficient PCI resources, aborting\n"); 1119 printk(KERN_ERR DRV_NAME ": Insufficient PCI resources, aborting\n");
1120 err = -EIO; 1120 err = -EIO;
1121 goto err_out; 1121 goto err_out;
1122 } 1122 }
1123 1123
1124 pioaddr = pci_resource_start(pdev, 0); /* IO map base address */ 1124 pioaddr = pci_resource_start(pdev, bar); /* IO map base address */
1125 pci_set_master(pdev); 1125 pci_set_master(pdev);
1126 1126
1127 dev = alloc_etherdev(sizeof(struct r6040_private)); 1127 dev = alloc_etherdev(sizeof(struct r6040_private));
diff --git a/drivers/net/rionet.c b/drivers/net/rionet.c
index 8702e7acdee6..bc98e7f69ee9 100644
--- a/drivers/net/rionet.c
+++ b/drivers/net/rionet.c
@@ -114,11 +114,6 @@ static int rionet_rx_clean(struct net_device *ndev)
114 114
115 if (error == NET_RX_DROP) { 115 if (error == NET_RX_DROP) {
116 ndev->stats.rx_dropped++; 116 ndev->stats.rx_dropped++;
117 } else if (error == NET_RX_BAD) {
118 if (netif_msg_rx_err(rnet))
119 printk(KERN_WARNING "%s: bad rx packet\n",
120 DRV_NAME);
121 ndev->stats.rx_errors++;
122 } else { 117 } else {
123 ndev->stats.rx_packets++; 118 ndev->stats.rx_packets++;
124 ndev->stats.rx_bytes += RIO_MAX_MSG_SIZE; 119 ndev->stats.rx_bytes += RIO_MAX_MSG_SIZE;
@@ -208,7 +203,7 @@ static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
208 203
209 spin_unlock_irqrestore(&rnet->tx_lock, flags); 204 spin_unlock_irqrestore(&rnet->tx_lock, flags);
210 205
211 return 0; 206 return NETDEV_TX_OK;
212} 207}
213 208
214static void rionet_dbell_event(struct rio_mport *mport, void *dev_id, u16 sid, u16 tid, 209static void rionet_dbell_event(struct rio_mport *mport, void *dev_id, u16 sid, u16 tid,
diff --git a/drivers/net/rrunner.c b/drivers/net/rrunner.c
index 81dbcbb910f4..d95534655911 100644
--- a/drivers/net/rrunner.c
+++ b/drivers/net/rrunner.c
@@ -1466,7 +1466,7 @@ static int rr_start_xmit(struct sk_buff *skb, struct net_device *dev)
1466 spin_unlock_irqrestore(&rrpriv->lock, flags); 1466 spin_unlock_irqrestore(&rrpriv->lock, flags);
1467 1467
1468 dev->trans_start = jiffies; 1468 dev->trans_start = jiffies;
1469 return 0; 1469 return NETDEV_TX_OK;
1470} 1470}
1471 1471
1472 1472
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 458daa06ed41..d4df9330c447 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -4111,14 +4111,14 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
4111 if (unlikely(skb->len <= 0)) { 4111 if (unlikely(skb->len <= 0)) {
4112 DBG_PRINT(TX_DBG, "%s:Buffer has no data..\n", dev->name); 4112 DBG_PRINT(TX_DBG, "%s:Buffer has no data..\n", dev->name);
4113 dev_kfree_skb_any(skb); 4113 dev_kfree_skb_any(skb);
4114 return 0; 4114 return NETDEV_TX_OK;
4115 } 4115 }
4116 4116
4117 if (!is_s2io_card_up(sp)) { 4117 if (!is_s2io_card_up(sp)) {
4118 DBG_PRINT(TX_DBG, "%s: Card going down for reset\n", 4118 DBG_PRINT(TX_DBG, "%s: Card going down for reset\n",
4119 dev->name); 4119 dev->name);
4120 dev_kfree_skb(skb); 4120 dev_kfree_skb(skb);
4121 return 0; 4121 return NETDEV_TX_OK;
4122 } 4122 }
4123 4123
4124 queue = 0; 4124 queue = 0;
@@ -4192,7 +4192,7 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
4192 s2io_stop_tx_queue(sp, fifo->fifo_no); 4192 s2io_stop_tx_queue(sp, fifo->fifo_no);
4193 dev_kfree_skb(skb); 4193 dev_kfree_skb(skb);
4194 spin_unlock_irqrestore(&fifo->tx_lock, flags); 4194 spin_unlock_irqrestore(&fifo->tx_lock, flags);
4195 return 0; 4195 return NETDEV_TX_OK;
4196 } 4196 }
4197 4197
4198 offload_type = s2io_offload_type(skb); 4198 offload_type = s2io_offload_type(skb);
@@ -4304,14 +4304,14 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
4304 if (sp->config.intr_type == MSI_X) 4304 if (sp->config.intr_type == MSI_X)
4305 tx_intr_handler(fifo); 4305 tx_intr_handler(fifo);
4306 4306
4307 return 0; 4307 return NETDEV_TX_OK;
4308pci_map_failed: 4308pci_map_failed:
4309 stats->pci_map_fail_cnt++; 4309 stats->pci_map_fail_cnt++;
4310 s2io_stop_tx_queue(sp, fifo->fifo_no); 4310 s2io_stop_tx_queue(sp, fifo->fifo_no);
4311 stats->mem_freed += skb->truesize; 4311 stats->mem_freed += skb->truesize;
4312 dev_kfree_skb(skb); 4312 dev_kfree_skb(skb);
4313 spin_unlock_irqrestore(&fifo->tx_lock, flags); 4313 spin_unlock_irqrestore(&fifo->tx_lock, flags);
4314 return 0; 4314 return NETDEV_TX_OK;
4315} 4315}
4316 4316
4317static void 4317static void
diff --git a/drivers/net/sb1000.c b/drivers/net/sb1000.c
index fc0e38bddeeb..6a81aec645d9 100644
--- a/drivers/net/sb1000.c
+++ b/drivers/net/sb1000.c
@@ -1086,7 +1086,7 @@ sb1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1086 printk(KERN_WARNING "%s: trying to transmit!!!\n", dev->name); 1086 printk(KERN_WARNING "%s: trying to transmit!!!\n", dev->name);
1087 /* sb1000 can't xmit datagrams */ 1087 /* sb1000 can't xmit datagrams */
1088 dev_kfree_skb(skb); 1088 dev_kfree_skb(skb);
1089 return 0; 1089 return NETDEV_TX_OK;
1090} 1090}
1091 1091
1092/* SB1000 interrupt handler. */ 1092/* SB1000 interrupt handler. */
diff --git a/drivers/net/sb1250-mac.c b/drivers/net/sb1250-mac.c
index d8c9cf1b901d..4c2450b6bd0c 100644
--- a/drivers/net/sb1250-mac.c
+++ b/drivers/net/sb1250-mac.c
@@ -2091,7 +2091,7 @@ static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev)
2091 2091
2092 spin_unlock_irqrestore(&sc->sbm_lock, flags); 2092 spin_unlock_irqrestore(&sc->sbm_lock, flags);
2093 2093
2094 return 0; 2094 return NETDEV_TX_OK;
2095} 2095}
2096 2096
2097/********************************************************************** 2097/**********************************************************************
diff --git a/drivers/net/seeq8005.c b/drivers/net/seeq8005.c
index ebbbe09725fe..7cc8bb814137 100644
--- a/drivers/net/seeq8005.c
+++ b/drivers/net/seeq8005.c
@@ -401,7 +401,7 @@ static int seeq8005_send_packet(struct sk_buff *skb, struct net_device *dev)
401 401
402 if (length < ETH_ZLEN) { 402 if (length < ETH_ZLEN) {
403 if (skb_padto(skb, ETH_ZLEN)) 403 if (skb_padto(skb, ETH_ZLEN))
404 return 0; 404 return NETDEV_TX_OK;
405 length = ETH_ZLEN; 405 length = ETH_ZLEN;
406 } 406 }
407 buf = skb->data; 407 buf = skb->data;
@@ -415,7 +415,7 @@ static int seeq8005_send_packet(struct sk_buff *skb, struct net_device *dev)
415 dev_kfree_skb (skb); 415 dev_kfree_skb (skb);
416 /* You might need to clean up and record Tx statistics here. */ 416 /* You might need to clean up and record Tx statistics here. */
417 417
418 return 0; 418 return NETDEV_TX_OK;
419} 419}
420 420
421/* 421/*
diff --git a/drivers/net/sgiseeq.c b/drivers/net/sgiseeq.c
index 5fb88ca6dd7f..78f60089b552 100644
--- a/drivers/net/sgiseeq.c
+++ b/drivers/net/sgiseeq.c
@@ -594,7 +594,7 @@ static int sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev)
594 len = skb->len; 594 len = skb->len;
595 if (len < ETH_ZLEN) { 595 if (len < ETH_ZLEN) {
596 if (skb_padto(skb, ETH_ZLEN)) 596 if (skb_padto(skb, ETH_ZLEN))
597 return 0; 597 return NETDEV_TX_OK;
598 len = ETH_ZLEN; 598 len = ETH_ZLEN;
599 } 599 }
600 600
@@ -642,7 +642,7 @@ static int sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev)
642 netif_stop_queue(dev); 642 netif_stop_queue(dev);
643 spin_unlock_irqrestore(&sp->tx_lock, flags); 643 spin_unlock_irqrestore(&sp->tx_lock, flags);
644 644
645 return 0; 645 return NETDEV_TX_OK;
646} 646}
647 647
648static void timeout(struct net_device *dev) 648static void timeout(struct net_device *dev)
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
index a2d82ddb3b4d..4c4dcbf19026 100644
--- a/drivers/net/sh_eth.c
+++ b/drivers/net/sh_eth.c
@@ -1133,7 +1133,7 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1133 1133
1134 ndev->trans_start = jiffies; 1134 ndev->trans_start = jiffies;
1135 1135
1136 return 0; 1136 return NETDEV_TX_OK;
1137} 1137}
1138 1138
1139/* device close function */ 1139/* device close function */
diff --git a/drivers/net/sis900.c b/drivers/net/sis900.c
index a9a897bb42d5..61ceeaaf104d 100644
--- a/drivers/net/sis900.c
+++ b/drivers/net/sis900.c
@@ -1628,7 +1628,7 @@ sis900_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
1628 "to slot %d.\n", 1628 "to slot %d.\n",
1629 net_dev->name, skb->data, (int)skb->len, entry); 1629 net_dev->name, skb->data, (int)skb->len, entry);
1630 1630
1631 return 0; 1631 return NETDEV_TX_OK;
1632} 1632}
1633 1633
1634/** 1634/**
diff --git a/drivers/net/skfp/skfddi.c b/drivers/net/skfp/skfddi.c
index 088fe26484e7..888a14a045ef 100644
--- a/drivers/net/skfp/skfddi.c
+++ b/drivers/net/skfp/skfddi.c
@@ -1077,7 +1077,7 @@ static int skfp_send_pkt(struct sk_buff *skb, struct net_device *dev)
1077 // dequeue packets from xmt queue and send them 1077 // dequeue packets from xmt queue and send them
1078 netif_start_queue(dev); 1078 netif_start_queue(dev);
1079 dev_kfree_skb(skb); 1079 dev_kfree_skb(skb);
1080 return (0); /* return "success" */ 1080 return NETDEV_TX_OK; /* return "success" */
1081 } 1081 }
1082 if (bp->QueueSkb == 0) { // return with tbusy set: queue full 1082 if (bp->QueueSkb == 0) { // return with tbusy set: queue full
1083 1083
@@ -1091,7 +1091,7 @@ static int skfp_send_pkt(struct sk_buff *skb, struct net_device *dev)
1091 netif_stop_queue(dev); 1091 netif_stop_queue(dev);
1092 } 1092 }
1093 dev->trans_start = jiffies; 1093 dev->trans_start = jiffies;
1094 return 0; 1094 return NETDEV_TX_OK;
1095 1095
1096} // skfp_send_pkt 1096} // skfp_send_pkt
1097 1097
diff --git a/drivers/net/slip.c b/drivers/net/slip.c
index 5c61d5fad908..899c4a2112c9 100644
--- a/drivers/net/slip.c
+++ b/drivers/net/slip.c
@@ -484,12 +484,12 @@ sl_xmit(struct sk_buff *skb, struct net_device *dev)
484 spin_unlock(&sl->lock); 484 spin_unlock(&sl->lock);
485 printk(KERN_WARNING "%s: xmit call when iface is down\n", dev->name); 485 printk(KERN_WARNING "%s: xmit call when iface is down\n", dev->name);
486 dev_kfree_skb(skb); 486 dev_kfree_skb(skb);
487 return 0; 487 return NETDEV_TX_OK;
488 } 488 }
489 if (sl->tty == NULL) { 489 if (sl->tty == NULL) {
490 spin_unlock(&sl->lock); 490 spin_unlock(&sl->lock);
491 dev_kfree_skb(skb); 491 dev_kfree_skb(skb);
492 return 0; 492 return NETDEV_TX_OK;
493 } 493 }
494 494
495 sl_lock(sl); 495 sl_lock(sl);
@@ -498,7 +498,7 @@ sl_xmit(struct sk_buff *skb, struct net_device *dev)
498 spin_unlock(&sl->lock); 498 spin_unlock(&sl->lock);
499 499
500 dev_kfree_skb(skb); 500 dev_kfree_skb(skb);
501 return 0; 501 return NETDEV_TX_OK;
502} 502}
503 503
504 504
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index bc4976ac8712..2a6b6de95339 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -553,7 +553,7 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
553 dev->stats.tx_dropped++; 553 dev->stats.tx_dropped++;
554 spin_unlock_irqrestore(&lp->lock, flags); 554 spin_unlock_irqrestore(&lp->lock, flags);
555 dev_kfree_skb(skb); 555 dev_kfree_skb(skb);
556 return 0; 556 return NETDEV_TX_OK;
557 } 557 }
558 558
559#ifdef SMC_USE_DMA 559#ifdef SMC_USE_DMA
@@ -566,7 +566,7 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
566 lp->pending_tx_skb = skb; 566 lp->pending_tx_skb = skb;
567 netif_stop_queue(dev); 567 netif_stop_queue(dev);
568 spin_unlock_irqrestore(&lp->lock, flags); 568 spin_unlock_irqrestore(&lp->lock, flags);
569 return 0; 569 return NETDEV_TX_OK;
570 } else { 570 } else {
571 DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, "%s: Activating Tx DMA\n", dev->name); 571 DBG(SMC_DEBUG_TX | SMC_DEBUG_DMA, "%s: Activating Tx DMA\n", dev->name);
572 lp->txdma_active = 1; 572 lp->txdma_active = 1;
@@ -577,7 +577,7 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
577 smc911x_hardware_send_pkt(dev); 577 smc911x_hardware_send_pkt(dev);
578 spin_unlock_irqrestore(&lp->lock, flags); 578 spin_unlock_irqrestore(&lp->lock, flags);
579 579
580 return 0; 580 return NETDEV_TX_OK;
581} 581}
582 582
583/* 583/*
diff --git a/drivers/net/smc9194.c b/drivers/net/smc9194.c
index e02471b2f2b5..0a1b6f401087 100644
--- a/drivers/net/smc9194.c
+++ b/drivers/net/smc9194.c
@@ -512,7 +512,7 @@ static int smc_wait_to_send_packet( struct sk_buff * skb, struct net_device * de
512 if (length < ETH_ZLEN) { 512 if (length < ETH_ZLEN) {
513 if (skb_padto(skb, ETH_ZLEN)) { 513 if (skb_padto(skb, ETH_ZLEN)) {
514 netif_wake_queue(dev); 514 netif_wake_queue(dev);
515 return 0; 515 return NETDEV_TX_OK;
516 } 516 }
517 length = ETH_ZLEN; 517 length = ETH_ZLEN;
518 } 518 }
@@ -534,7 +534,7 @@ static int smc_wait_to_send_packet( struct sk_buff * skb, struct net_device * de
534 lp->saved_skb = NULL; 534 lp->saved_skb = NULL;
535 /* this IS an error, but, i don't want the skb saved */ 535 /* this IS an error, but, i don't want the skb saved */
536 netif_wake_queue(dev); 536 netif_wake_queue(dev);
537 return 0; 537 return NETDEV_TX_OK;
538 } 538 }
539 /* either way, a packet is waiting now */ 539 /* either way, a packet is waiting now */
540 lp->packets_waiting++; 540 lp->packets_waiting++;
@@ -571,12 +571,12 @@ static int smc_wait_to_send_packet( struct sk_buff * skb, struct net_device * de
571 SMC_ENABLE_INT( IM_ALLOC_INT ); 571 SMC_ENABLE_INT( IM_ALLOC_INT );
572 PRINTK2((CARDNAME": memory allocation deferred. \n")); 572 PRINTK2((CARDNAME": memory allocation deferred. \n"));
573 /* it's deferred, but I'll handle it later */ 573 /* it's deferred, but I'll handle it later */
574 return 0; 574 return NETDEV_TX_OK;
575 } 575 }
576 /* or YES! I can send the packet now.. */ 576 /* or YES! I can send the packet now.. */
577 smc_hardware_send_packet(dev); 577 smc_hardware_send_packet(dev);
578 netif_wake_queue(dev); 578 netif_wake_queue(dev);
579 return 0; 579 return NETDEV_TX_OK;
580} 580}
581 581
582/* 582/*
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index 1c70e999cc50..0f2c52c2e044 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -655,7 +655,7 @@ static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
655 dev->stats.tx_errors++; 655 dev->stats.tx_errors++;
656 dev->stats.tx_dropped++; 656 dev->stats.tx_dropped++;
657 dev_kfree_skb(skb); 657 dev_kfree_skb(skb);
658 return 0; 658 return NETDEV_TX_OK;
659 } 659 }
660 660
661 smc_special_lock(&lp->lock); 661 smc_special_lock(&lp->lock);
@@ -692,7 +692,7 @@ static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
692 smc_hardware_send_pkt((unsigned long)dev); 692 smc_hardware_send_pkt((unsigned long)dev);
693 } 693 }
694 694
695 return 0; 695 return NETDEV_TX_OK;
696} 696}
697 697
698/* 698/*
diff --git a/drivers/net/sonic.c b/drivers/net/sonic.c
index 753a1fba4609..9599ce77ef85 100644
--- a/drivers/net/sonic.c
+++ b/drivers/net/sonic.c
@@ -211,7 +211,7 @@ static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)
211 length = skb->len; 211 length = skb->len;
212 if (length < ETH_ZLEN) { 212 if (length < ETH_ZLEN) {
213 if (skb_padto(skb, ETH_ZLEN)) 213 if (skb_padto(skb, ETH_ZLEN))
214 return 0; 214 return NETDEV_TX_OK;
215 length = ETH_ZLEN; 215 length = ETH_ZLEN;
216 } 216 }
217 217
@@ -265,7 +265,7 @@ static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev)
265 265
266 dev->trans_start = jiffies; 266 dev->trans_start = jiffies;
267 267
268 return 0; 268 return NETDEV_TX_OK;
269} 269}
270 270
271/* 271/*
diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c
index 838cce8b8fff..1018349a29dc 100644
--- a/drivers/net/starfire.c
+++ b/drivers/net/starfire.c
@@ -1311,7 +1311,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
1311 1311
1312 dev->trans_start = jiffies; 1312 dev->trans_start = jiffies;
1313 1313
1314 return 0; 1314 return NETDEV_TX_OK;
1315} 1315}
1316 1316
1317 1317
diff --git a/drivers/net/sun3_82586.c b/drivers/net/sun3_82586.c
index 7bb27426dbd6..2f1eaaf7a727 100644
--- a/drivers/net/sun3_82586.c
+++ b/drivers/net/sun3_82586.c
@@ -1015,7 +1015,7 @@ static int sun3_82586_send_packet(struct sk_buff *skb, struct net_device *dev)
1015 if(skb->len > XMIT_BUFF_SIZE) 1015 if(skb->len > XMIT_BUFF_SIZE)
1016 { 1016 {
1017 printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len); 1017 printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len);
1018 return 0; 1018 return NETDEV_TX_OK;
1019 } 1019 }
1020 1020
1021 netif_stop_queue(dev); 1021 netif_stop_queue(dev);
@@ -1110,7 +1110,7 @@ static int sun3_82586_send_packet(struct sk_buff *skb, struct net_device *dev)
1110 dev_kfree_skb(skb); 1110 dev_kfree_skb(skb);
1111#endif 1111#endif
1112 } 1112 }
1113 return 0; 1113 return NETDEV_TX_OK;
1114} 1114}
1115 1115
1116/******************************************* 1116/*******************************************
diff --git a/drivers/net/sun3lance.c b/drivers/net/sun3lance.c
index 534dfe3eef6f..0ca4241b4f63 100644
--- a/drivers/net/sun3lance.c
+++ b/drivers/net/sun3lance.c
@@ -562,7 +562,7 @@ static int lance_start_xmit( struct sk_buff *skb, struct net_device *dev )
562 netif_start_queue(dev); 562 netif_start_queue(dev);
563 dev->trans_start = jiffies; 563 dev->trans_start = jiffies;
564 564
565 return 0; 565 return NETDEV_TX_OK;
566 } 566 }
567 567
568 568
@@ -648,7 +648,7 @@ static int lance_start_xmit( struct sk_buff *skb, struct net_device *dev )
648 648
649 local_irq_restore(flags); 649 local_irq_restore(flags);
650 650
651 return 0; 651 return NETDEV_TX_OK;
652} 652}
653 653
654/* The LANCE interrupt handler. */ 654/* The LANCE interrupt handler. */
diff --git a/drivers/net/sunbmac.c b/drivers/net/sunbmac.c
index 5017d7fcb40c..536cf7e06bfd 100644
--- a/drivers/net/sunbmac.c
+++ b/drivers/net/sunbmac.c
@@ -984,7 +984,7 @@ static int bigmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
984 984
985 dev->trans_start = jiffies; 985 dev->trans_start = jiffies;
986 986
987 return 0; 987 return NETDEV_TX_OK;
988} 988}
989 989
990static struct net_device_stats *bigmac_get_stats(struct net_device *dev) 990static struct net_device_stats *bigmac_get_stats(struct net_device *dev)
diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
index 545f81b34ad7..0df6332ed9ce 100644
--- a/drivers/net/sundance.c
+++ b/drivers/net/sundance.c
@@ -1091,7 +1091,7 @@ start_tx (struct sk_buff *skb, struct net_device *dev)
1091 "%s: Transmit frame #%d queued in slot %d.\n", 1091 "%s: Transmit frame #%d queued in slot %d.\n",
1092 dev->name, np->cur_tx, entry); 1092 dev->name, np->cur_tx, entry);
1093 } 1093 }
1094 return 0; 1094 return NETDEV_TX_OK;
1095} 1095}
1096 1096
1097/* Reset hardware tx and free all of tx buffers */ 1097/* Reset hardware tx and free all of tx buffers */
diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c
index 4ef729198e10..008bd59fc64b 100644
--- a/drivers/net/sunhme.c
+++ b/drivers/net/sunhme.c
@@ -2338,7 +2338,7 @@ static int happy_meal_start_xmit(struct sk_buff *skb, struct net_device *dev)
2338 dev->trans_start = jiffies; 2338 dev->trans_start = jiffies;
2339 2339
2340 tx_add_log(hp, TXLOG_ACTION_TXMIT, 0); 2340 tx_add_log(hp, TXLOG_ACTION_TXMIT, 0);
2341 return 0; 2341 return NETDEV_TX_OK;
2342} 2342}
2343 2343
2344static struct net_device_stats *happy_meal_get_stats(struct net_device *dev) 2344static struct net_device_stats *happy_meal_get_stats(struct net_device *dev)
diff --git a/drivers/net/sunlance.c b/drivers/net/sunlance.c
index afc7b351e5ec..9d6fd4760eab 100644
--- a/drivers/net/sunlance.c
+++ b/drivers/net/sunlance.c
@@ -1163,7 +1163,7 @@ static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
1163 dev->trans_start = jiffies; 1163 dev->trans_start = jiffies;
1164 dev_kfree_skb(skb); 1164 dev_kfree_skb(skb);
1165 1165
1166 return 0; 1166 return NETDEV_TX_OK;
1167} 1167}
1168 1168
1169/* taken from the depca driver */ 1169/* taken from the depca driver */
diff --git a/drivers/net/sunqe.c b/drivers/net/sunqe.c
index c6ec61e0accf..dcefb608a9f4 100644
--- a/drivers/net/sunqe.c
+++ b/drivers/net/sunqe.c
@@ -621,7 +621,7 @@ static int qe_start_xmit(struct sk_buff *skb, struct net_device *dev)
621 621
622 dev_kfree_skb(skb); 622 dev_kfree_skb(skb);
623 623
624 return 0; 624 return NETDEV_TX_OK;
625} 625}
626 626
627static void qe_set_multicast(struct net_device *dev) 627static void qe_set_multicast(struct net_device *dev)
diff --git a/drivers/net/tc35815.c b/drivers/net/tc35815.c
index d737f6b8f876..1ce2da172ca9 100644
--- a/drivers/net/tc35815.c
+++ b/drivers/net/tc35815.c
@@ -1509,7 +1509,7 @@ static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev)
1509 */ 1509 */
1510 1510
1511 spin_unlock_irqrestore(&lp->lock, flags); 1511 spin_unlock_irqrestore(&lp->lock, flags);
1512 return 0; 1512 return NETDEV_TX_OK;
1513} 1513}
1514 1514
1515#define FATAL_ERROR_INT \ 1515#define FATAL_ERROR_INT \
diff --git a/drivers/net/tlan.c b/drivers/net/tlan.c
index 384cb5e28397..70c9ec45d8fb 100644
--- a/drivers/net/tlan.c
+++ b/drivers/net/tlan.c
@@ -1095,11 +1095,11 @@ static int TLan_StartTx( struct sk_buff *skb, struct net_device *dev )
1095 TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n", 1095 TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
1096 dev->name ); 1096 dev->name );
1097 dev_kfree_skb_any(skb); 1097 dev_kfree_skb_any(skb);
1098 return 0; 1098 return NETDEV_TX_OK;
1099 } 1099 }
1100 1100
1101 if (skb_padto(skb, TLAN_MIN_FRAME_SIZE)) 1101 if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
1102 return 0; 1102 return NETDEV_TX_OK;
1103 txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE); 1103 txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE);
1104 1104
1105 tail_list = priv->txList + priv->txTail; 1105 tail_list = priv->txList + priv->txTail;
@@ -1150,7 +1150,7 @@ static int TLan_StartTx( struct sk_buff *skb, struct net_device *dev )
1150 CIRC_INC( priv->txTail, TLAN_NUM_TX_LISTS ); 1150 CIRC_INC( priv->txTail, TLAN_NUM_TX_LISTS );
1151 1151
1152 dev->trans_start = jiffies; 1152 dev->trans_start = jiffies;
1153 return 0; 1153 return NETDEV_TX_OK;
1154 1154
1155} /* TLan_StartTx */ 1155} /* TLan_StartTx */
1156 1156
diff --git a/drivers/net/tokenring/3c359.c b/drivers/net/tokenring/3c359.c
index b40b6de2d086..1787d52941bc 100644
--- a/drivers/net/tokenring/3c359.c
+++ b/drivers/net/tokenring/3c359.c
@@ -1240,7 +1240,7 @@ static int xl_xmit(struct sk_buff *skb, struct net_device *dev)
1240 1240
1241 spin_unlock_irqrestore(&xl_priv->xl_lock,flags) ; 1241 spin_unlock_irqrestore(&xl_priv->xl_lock,flags) ;
1242 1242
1243 return 0; 1243 return NETDEV_TX_OK;
1244 } else { 1244 } else {
1245 spin_unlock_irqrestore(&xl_priv->xl_lock,flags) ; 1245 spin_unlock_irqrestore(&xl_priv->xl_lock,flags) ;
1246 return NETDEV_TX_BUSY; 1246 return NETDEV_TX_BUSY;
diff --git a/drivers/net/tokenring/ibmtr.c b/drivers/net/tokenring/ibmtr.c
index 9d896116cf76..6472ba5cfc5e 100644
--- a/drivers/net/tokenring/ibmtr.c
+++ b/drivers/net/tokenring/ibmtr.c
@@ -1041,7 +1041,7 @@ static int tok_send_packet(struct sk_buff *skb, struct net_device *dev)
1041 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD); 1041 writeb(CMD_IN_SRB, ti->mmio + ACA_OFFSET + ACA_SET + ISRA_ODD);
1042 spin_unlock_irqrestore(&(ti->lock), flags); 1042 spin_unlock_irqrestore(&(ti->lock), flags);
1043 dev->trans_start = jiffies; 1043 dev->trans_start = jiffies;
1044 return 0; 1044 return NETDEV_TX_OK;
1045} 1045}
1046 1046
1047/*****************************************************************************/ 1047/*****************************************************************************/
diff --git a/drivers/net/tokenring/lanstreamer.c b/drivers/net/tokenring/lanstreamer.c
index b3715efdce56..d07e61a9499e 100644
--- a/drivers/net/tokenring/lanstreamer.c
+++ b/drivers/net/tokenring/lanstreamer.c
@@ -1183,7 +1183,7 @@ static int streamer_xmit(struct sk_buff *skb, struct net_device *dev)
1183 1183
1184 streamer_priv->tx_ring_free = (streamer_priv->tx_ring_free + 1) & (STREAMER_TX_RING_SIZE - 1); 1184 streamer_priv->tx_ring_free = (streamer_priv->tx_ring_free + 1) & (STREAMER_TX_RING_SIZE - 1);
1185 spin_unlock_irqrestore(&streamer_priv->streamer_lock,flags); 1185 spin_unlock_irqrestore(&streamer_priv->streamer_lock,flags);
1186 return 0; 1186 return NETDEV_TX_OK;
1187 } else { 1187 } else {
1188 netif_stop_queue(dev); 1188 netif_stop_queue(dev);
1189 spin_unlock_irqrestore(&streamer_priv->streamer_lock,flags); 1189 spin_unlock_irqrestore(&streamer_priv->streamer_lock,flags);
diff --git a/drivers/net/tokenring/olympic.c b/drivers/net/tokenring/olympic.c
index 451b54136ede..f73f4e684f33 100644
--- a/drivers/net/tokenring/olympic.c
+++ b/drivers/net/tokenring/olympic.c
@@ -1052,7 +1052,7 @@ static int olympic_xmit(struct sk_buff *skb, struct net_device *dev)
1052 writew((((readw(olympic_mmio+TXENQ_1)) & 0x8000) ^ 0x8000) | 1,olympic_mmio+TXENQ_1); 1052 writew((((readw(olympic_mmio+TXENQ_1)) & 0x8000) ^ 0x8000) | 1,olympic_mmio+TXENQ_1);
1053 netif_wake_queue(dev); 1053 netif_wake_queue(dev);
1054 spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags); 1054 spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
1055 return 0; 1055 return NETDEV_TX_OK;
1056 } else { 1056 } else {
1057 spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags); 1057 spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
1058 return NETDEV_TX_BUSY; 1058 return NETDEV_TX_BUSY;
diff --git a/drivers/net/tokenring/smctr.c b/drivers/net/tokenring/smctr.c
index 54ad4ed03374..6515894c83f5 100644
--- a/drivers/net/tokenring/smctr.c
+++ b/drivers/net/tokenring/smctr.c
@@ -4609,7 +4609,7 @@ static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev)
4609 if(tp->QueueSkb > 0) 4609 if(tp->QueueSkb > 0)
4610 netif_wake_queue(dev); 4610 netif_wake_queue(dev);
4611 4611
4612 return (0); 4612 return NETDEV_TX_OK;
4613} 4613}
4614 4614
4615static int smctr_send_lobe_media_test(struct net_device *dev) 4615static int smctr_send_lobe_media_test(struct net_device *dev)
diff --git a/drivers/net/tokenring/tms380tr.c b/drivers/net/tokenring/tms380tr.c
index a2eab72b507a..07f6dfd3ba0c 100644
--- a/drivers/net/tokenring/tms380tr.c
+++ b/drivers/net/tokenring/tms380tr.c
@@ -682,7 +682,7 @@ static int tms380tr_hardware_send_packet(struct sk_buff *skb, struct net_device
682 tms380tr_exec_sifcmd(dev, CMD_TX_VALID); 682 tms380tr_exec_sifcmd(dev, CMD_TX_VALID);
683 spin_unlock_irqrestore(&tp->lock, flags); 683 spin_unlock_irqrestore(&tp->lock, flags);
684 684
685 return 0; 685 return NETDEV_TX_OK;
686} 686}
687 687
688/* 688/*
diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
index 81f054dbb88d..769af558a345 100644
--- a/drivers/net/tulip/de2104x.c
+++ b/drivers/net/tulip/de2104x.c
@@ -651,7 +651,7 @@ static int de_start_xmit (struct sk_buff *skb, struct net_device *dev)
651 dw32(TxPoll, NormalTxPoll); 651 dw32(TxPoll, NormalTxPoll);
652 dev->trans_start = jiffies; 652 dev->trans_start = jiffies;
653 653
654 return 0; 654 return NETDEV_TX_OK;
655} 655}
656 656
657/* Set or clear the multicast filter for this adaptor. 657/* Set or clear the multicast filter for this adaptor.
diff --git a/drivers/net/tulip/dmfe.c b/drivers/net/tulip/dmfe.c
index 8e78f003f08f..5e15fab58c17 100644
--- a/drivers/net/tulip/dmfe.c
+++ b/drivers/net/tulip/dmfe.c
@@ -676,7 +676,7 @@ static int dmfe_start_xmit(struct sk_buff *skb, struct DEVICE *dev)
676 if (skb->len > MAX_PACKET_SIZE) { 676 if (skb->len > MAX_PACKET_SIZE) {
677 printk(KERN_ERR DRV_NAME ": big packet = %d\n", (u16)skb->len); 677 printk(KERN_ERR DRV_NAME ": big packet = %d\n", (u16)skb->len);
678 dev_kfree_skb(skb); 678 dev_kfree_skb(skb);
679 return 0; 679 return NETDEV_TX_OK;
680 } 680 }
681 681
682 spin_lock_irqsave(&db->lock, flags); 682 spin_lock_irqsave(&db->lock, flags);
@@ -722,7 +722,7 @@ static int dmfe_start_xmit(struct sk_buff *skb, struct DEVICE *dev)
722 /* free this SKB */ 722 /* free this SKB */
723 dev_kfree_skb(skb); 723 dev_kfree_skb(skb);
724 724
725 return 0; 725 return NETDEV_TX_OK;
726} 726}
727 727
728 728
diff --git a/drivers/net/tulip/tulip_core.c b/drivers/net/tulip/tulip_core.c
index 2abb5d3becc6..9d46638d250e 100644
--- a/drivers/net/tulip/tulip_core.c
+++ b/drivers/net/tulip/tulip_core.c
@@ -690,7 +690,7 @@ tulip_start_xmit(struct sk_buff *skb, struct net_device *dev)
690 690
691 dev->trans_start = jiffies; 691 dev->trans_start = jiffies;
692 692
693 return 0; 693 return NETDEV_TX_OK;
694} 694}
695 695
696static void tulip_clean_tx_ring(struct tulip_private *tp) 696static void tulip_clean_tx_ring(struct tulip_private *tp)
diff --git a/drivers/net/tulip/uli526x.c b/drivers/net/tulip/uli526x.c
index 9277ce8febe4..9074a34eb814 100644
--- a/drivers/net/tulip/uli526x.c
+++ b/drivers/net/tulip/uli526x.c
@@ -582,7 +582,7 @@ static int uli526x_start_xmit(struct sk_buff *skb, struct net_device *dev)
582 if (skb->len > MAX_PACKET_SIZE) { 582 if (skb->len > MAX_PACKET_SIZE) {
583 printk(KERN_ERR DRV_NAME ": big packet = %d\n", (u16)skb->len); 583 printk(KERN_ERR DRV_NAME ": big packet = %d\n", (u16)skb->len);
584 dev_kfree_skb(skb); 584 dev_kfree_skb(skb);
585 return 0; 585 return NETDEV_TX_OK;
586 } 586 }
587 587
588 spin_lock_irqsave(&db->lock, flags); 588 spin_lock_irqsave(&db->lock, flags);
@@ -624,7 +624,7 @@ static int uli526x_start_xmit(struct sk_buff *skb, struct net_device *dev)
624 /* free this SKB */ 624 /* free this SKB */
625 dev_kfree_skb(skb); 625 dev_kfree_skb(skb);
626 626
627 return 0; 627 return NETDEV_TX_OK;
628} 628}
629 629
630 630
diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
index 842b1a2c40d4..6bc7540b216e 100644
--- a/drivers/net/tulip/winbond-840.c
+++ b/drivers/net/tulip/winbond-840.c
@@ -1058,7 +1058,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
1058 printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n", 1058 printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n",
1059 dev->name, np->cur_tx, entry); 1059 dev->name, np->cur_tx, entry);
1060 } 1060 }
1061 return 0; 1061 return NETDEV_TX_OK;
1062} 1062}
1063 1063
1064static void netdev_tx_done(struct net_device *dev) 1064static void netdev_tx_done(struct net_device *dev)
diff --git a/drivers/net/tulip/xircom_cb.c b/drivers/net/tulip/xircom_cb.c
index c2ca9f40e40e..22b6a239fb33 100644
--- a/drivers/net/tulip/xircom_cb.c
+++ b/drivers/net/tulip/xircom_cb.c
@@ -434,7 +434,7 @@ static int xircom_start_xmit(struct sk_buff *skb, struct net_device *dev)
434 card->transmit_used = nextdescriptor; 434 card->transmit_used = nextdescriptor;
435 leave("xircom-start_xmit - sent"); 435 leave("xircom-start_xmit - sent");
436 spin_unlock_irqrestore(&card->lock,flags); 436 spin_unlock_irqrestore(&card->lock,flags);
437 return 0; 437 return NETDEV_TX_OK;
438 } 438 }
439 439
440 440
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 027f7aba26af..dfc1054e4cbd 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -398,12 +398,12 @@ static int tun_net_xmit(struct sk_buff *skb, struct net_device *dev)
398 if (tun->flags & TUN_FASYNC) 398 if (tun->flags & TUN_FASYNC)
399 kill_fasync(&tun->fasync, SIGIO, POLL_IN); 399 kill_fasync(&tun->fasync, SIGIO, POLL_IN);
400 wake_up_interruptible(&tun->socket.wait); 400 wake_up_interruptible(&tun->socket.wait);
401 return 0; 401 return NETDEV_TX_OK;
402 402
403drop: 403drop:
404 dev->stats.tx_dropped++; 404 dev->stats.tx_dropped++;
405 kfree_skb(skb); 405 kfree_skb(skb);
406 return 0; 406 return NETDEV_TX_OK;
407} 407}
408 408
409static void tun_net_mclist(struct net_device *dev) 409static void tun_net_mclist(struct net_device *dev)
@@ -997,7 +997,6 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
997 goto err_free_sk; 997 goto err_free_sk;
998 } 998 }
999 999
1000 err = -EINVAL;
1001 err = register_netdevice(tun->dev); 1000 err = register_netdevice(tun->dev);
1002 if (err < 0) 1001 if (err < 0)
1003 goto err_free_sk; 1002 goto err_free_sk;
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index cf25eb41b1ce..2c26b4577e8a 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -909,7 +909,7 @@ typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
909 netif_wake_queue(dev); 909 netif_wake_queue(dev);
910 } 910 }
911 911
912 return 0; 912 return NETDEV_TX_OK;
913} 913}
914 914
915static void 915static void
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 40c6eba775ce..ca476a58087c 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -209,9 +209,10 @@ static struct sk_buff *get_new_skb(struct ucc_geth_private *ugeth,
209{ 209{
210 struct sk_buff *skb = NULL; 210 struct sk_buff *skb = NULL;
211 211
212 skb = dev_alloc_skb(ugeth->ug_info->uf_info.max_rx_buf_length + 212 skb = __skb_dequeue(&ugeth->rx_recycle);
213 UCC_GETH_RX_DATA_BUF_ALIGNMENT); 213 if (!skb)
214 214 skb = dev_alloc_skb(ugeth->ug_info->uf_info.max_rx_buf_length +
215 UCC_GETH_RX_DATA_BUF_ALIGNMENT);
215 if (skb == NULL) 216 if (skb == NULL)
216 return NULL; 217 return NULL;
217 218
@@ -1986,6 +1987,8 @@ static void ucc_geth_memclean(struct ucc_geth_private *ugeth)
1986 iounmap(ugeth->ug_regs); 1987 iounmap(ugeth->ug_regs);
1987 ugeth->ug_regs = NULL; 1988 ugeth->ug_regs = NULL;
1988 } 1989 }
1990
1991 skb_queue_purge(&ugeth->rx_recycle);
1989} 1992}
1990 1993
1991static void ucc_geth_set_multi(struct net_device *dev) 1994static void ucc_geth_set_multi(struct net_device *dev)
@@ -2202,6 +2205,8 @@ static int ucc_struct_init(struct ucc_geth_private *ugeth)
2202 return -ENOMEM; 2205 return -ENOMEM;
2203 } 2206 }
2204 2207
2208 skb_queue_head_init(&ugeth->rx_recycle);
2209
2205 return 0; 2210 return 0;
2206} 2211}
2207 2212
@@ -3173,7 +3178,7 @@ static int ucc_geth_start_xmit(struct sk_buff *skb, struct net_device *dev)
3173#endif 3178#endif
3174 spin_unlock_irq(&ugeth->lock); 3179 spin_unlock_irq(&ugeth->lock);
3175 3180
3176 return 0; 3181 return NETDEV_TX_OK;
3177} 3182}
3178 3183
3179static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit) 3184static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit)
@@ -3208,8 +3213,10 @@ static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit
3208 if (netif_msg_rx_err(ugeth)) 3213 if (netif_msg_rx_err(ugeth))
3209 ugeth_err("%s, %d: ERROR!!! skb - 0x%08x", 3214 ugeth_err("%s, %d: ERROR!!! skb - 0x%08x",
3210 __func__, __LINE__, (u32) skb); 3215 __func__, __LINE__, (u32) skb);
3211 if (skb) 3216 if (skb) {
3212 dev_kfree_skb_any(skb); 3217 skb->data = skb->head + NET_SKB_PAD;
3218 __skb_queue_head(&ugeth->rx_recycle, skb);
3219 }
3213 3220
3214 ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = NULL; 3221 ugeth->rx_skbuff[rxQ][ugeth->skb_currx[rxQ]] = NULL;
3215 dev->stats.rx_dropped++; 3222 dev->stats.rx_dropped++;
@@ -3267,6 +3274,8 @@ static int ucc_geth_tx(struct net_device *dev, u8 txQ)
3267 3274
3268 /* Normal processing. */ 3275 /* Normal processing. */
3269 while ((bd_status & T_R) == 0) { 3276 while ((bd_status & T_R) == 0) {
3277 struct sk_buff *skb;
3278
3270 /* BD contains already transmitted buffer. */ 3279 /* BD contains already transmitted buffer. */
3271 /* Handle the transmitted buffer and release */ 3280 /* Handle the transmitted buffer and release */
3272 /* the BD to be used with the current frame */ 3281 /* the BD to be used with the current frame */
@@ -3276,9 +3285,16 @@ static int ucc_geth_tx(struct net_device *dev, u8 txQ)
3276 3285
3277 dev->stats.tx_packets++; 3286 dev->stats.tx_packets++;
3278 3287
3279 /* Free the sk buffer associated with this TxBD */ 3288 skb = ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]];
3280 dev_kfree_skb(ugeth-> 3289
3281 tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]]); 3290 if (skb_queue_len(&ugeth->rx_recycle) < RX_BD_RING_LEN &&
3291 skb_recycle_check(skb,
3292 ugeth->ug_info->uf_info.max_rx_buf_length +
3293 UCC_GETH_RX_DATA_BUF_ALIGNMENT))
3294 __skb_queue_head(&ugeth->rx_recycle, skb);
3295 else
3296 dev_kfree_skb(skb);
3297
3282 ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]] = NULL; 3298 ugeth->tx_skbuff[txQ][ugeth->skb_dirtytx[txQ]] = NULL;
3283 ugeth->skb_dirtytx[txQ] = 3299 ugeth->skb_dirtytx[txQ] =
3284 (ugeth->skb_dirtytx[txQ] + 3300 (ugeth->skb_dirtytx[txQ] +
@@ -3307,16 +3323,16 @@ static int ucc_geth_poll(struct napi_struct *napi, int budget)
3307 3323
3308 ug_info = ugeth->ug_info; 3324 ug_info = ugeth->ug_info;
3309 3325
3310 howmany = 0;
3311 for (i = 0; i < ug_info->numQueuesRx; i++)
3312 howmany += ucc_geth_rx(ugeth, i, budget - howmany);
3313
3314 /* Tx event processing */ 3326 /* Tx event processing */
3315 spin_lock(&ugeth->lock); 3327 spin_lock(&ugeth->lock);
3316 for (i = 0; i < ug_info->numQueuesTx; i++) 3328 for (i = 0; i < ug_info->numQueuesTx; i++)
3317 ucc_geth_tx(ugeth->ndev, i); 3329 ucc_geth_tx(ugeth->ndev, i);
3318 spin_unlock(&ugeth->lock); 3330 spin_unlock(&ugeth->lock);
3319 3331
3332 howmany = 0;
3333 for (i = 0; i < ug_info->numQueuesRx; i++)
3334 howmany += ucc_geth_rx(ugeth, i, budget - howmany);
3335
3320 if (howmany < budget) { 3336 if (howmany < budget) {
3321 napi_complete(napi); 3337 napi_complete(napi);
3322 setbits32(ugeth->uccf->p_uccm, UCCE_RX_EVENTS | UCCE_TX_EVENTS); 3338 setbits32(ugeth->uccf->p_uccm, UCCE_RX_EVENTS | UCCE_TX_EVENTS);
diff --git a/drivers/net/ucc_geth.h b/drivers/net/ucc_geth.h
index 195ab267ead7..cfb31afc08a9 100644
--- a/drivers/net/ucc_geth.h
+++ b/drivers/net/ucc_geth.h
@@ -1212,6 +1212,8 @@ struct ucc_geth_private {
1212 /* index of the first skb which hasn't been transmitted yet. */ 1212 /* index of the first skb which hasn't been transmitted yet. */
1213 u16 skb_dirtytx[NUM_TX_QUEUES]; 1213 u16 skb_dirtytx[NUM_TX_QUEUES];
1214 1214
1215 struct sk_buff_head rx_recycle;
1216
1215 struct ugeth_mii_info *mii_info; 1217 struct ugeth_mii_info *mii_info;
1216 struct phy_device *phydev; 1218 struct phy_device *phydev;
1217 phy_interface_t phy_interface; 1219 phy_interface_t phy_interface;
diff --git a/drivers/net/usb/catc.c b/drivers/net/usb/catc.c
index b9dd42574288..7abdc4abbe07 100644
--- a/drivers/net/usb/catc.c
+++ b/drivers/net/usb/catc.c
@@ -448,7 +448,7 @@ static int catc_start_xmit(struct sk_buff *skb, struct net_device *netdev)
448 448
449 dev_kfree_skb(skb); 449 dev_kfree_skb(skb);
450 450
451 return 0; 451 return NETDEV_TX_OK;
452} 452}
453 453
454static void catc_tx_timeout(struct net_device *netdev) 454static void catc_tx_timeout(struct net_device *netdev)
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index f8c6d7ea7264..ffe410635735 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -780,7 +780,7 @@ static int hso_net_start_xmit(struct sk_buff *skb, struct net_device *net)
780 netif_stop_queue(net); 780 netif_stop_queue(net);
781 if (hso_get_activity(odev->parent) == -EAGAIN) { 781 if (hso_get_activity(odev->parent) == -EAGAIN) {
782 odev->skb_tx_buf = skb; 782 odev->skb_tx_buf = skb;
783 return 0; 783 return NETDEV_TX_OK;
784 } 784 }
785 785
786 /* log if asked */ 786 /* log if asked */
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index 1f9ec29fce50..200fe3d525ca 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -829,7 +829,7 @@ static int kaweth_start_xmit(struct sk_buff *skb, struct net_device *net)
829 kaweth->stats.tx_errors++; 829 kaweth->stats.tx_errors++;
830 netif_start_queue(net); 830 netif_start_queue(net);
831 spin_unlock_irq(&kaweth->device_lock); 831 spin_unlock_irq(&kaweth->device_lock);
832 return 0; 832 return NETDEV_TX_OK;
833 } 833 }
834 } 834 }
835 835
@@ -864,7 +864,7 @@ skip:
864 864
865 spin_unlock_irq(&kaweth->device_lock); 865 spin_unlock_irq(&kaweth->device_lock);
866 866
867 return 0; 867 return NETDEV_TX_OK;
868} 868}
869 869
870/**************************************************************** 870/****************************************************************
diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c
index 631d269ac980..69d2df95ac86 100644
--- a/drivers/net/usb/pegasus.c
+++ b/drivers/net/usb/pegasus.c
@@ -914,7 +914,7 @@ static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net)
914 } 914 }
915 dev_kfree_skb(skb); 915 dev_kfree_skb(skb);
916 916
917 return 0; 917 return NETDEV_TX_OK;
918} 918}
919 919
920static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev) 920static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index fcc6fa0905d1..bac8b77fb25e 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -753,7 +753,7 @@ static int rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev)
753 netdev->trans_start = jiffies; 753 netdev->trans_start = jiffies;
754 } 754 }
755 755
756 return 0; 756 return NETDEV_TX_OK;
757} 757}
758 758
759 759
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index edfd9e10ceba..25e435c49040 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -575,7 +575,9 @@ EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs);
575int usbnet_stop (struct net_device *net) 575int usbnet_stop (struct net_device *net)
576{ 576{
577 struct usbnet *dev = netdev_priv(net); 577 struct usbnet *dev = netdev_priv(net);
578 struct driver_info *info = dev->driver_info;
578 int temp; 579 int temp;
580 int retval;
579 DECLARE_WAIT_QUEUE_HEAD_ONSTACK (unlink_wakeup); 581 DECLARE_WAIT_QUEUE_HEAD_ONSTACK (unlink_wakeup);
580 DECLARE_WAITQUEUE (wait, current); 582 DECLARE_WAITQUEUE (wait, current);
581 583
@@ -587,6 +589,18 @@ int usbnet_stop (struct net_device *net)
587 net->stats.rx_errors, net->stats.tx_errors 589 net->stats.rx_errors, net->stats.tx_errors
588 ); 590 );
589 591
592 /* allow minidriver to stop correctly (wireless devices to turn off
593 * radio etc) */
594 if (info->stop) {
595 retval = info->stop(dev);
596 if (retval < 0 && netif_msg_ifdown(dev))
597 devinfo(dev,
598 "stop fail (%d) usbnet usb-%s-%s, %s",
599 retval,
600 dev->udev->bus->bus_name, dev->udev->devpath,
601 info->description);
602 }
603
590 // ensure there are no more active urbs 604 // ensure there are no more active urbs
591 add_wait_queue (&unlink_wakeup, &wait); 605 add_wait_queue (&unlink_wakeup, &wait);
592 dev->wait = &unlink_wakeup; 606 dev->wait = &unlink_wakeup;
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 1097c72e44d5..f1d753daa5bd 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -189,17 +189,17 @@ static int veth_xmit(struct sk_buff *skb, struct net_device *dev)
189 rcv_stats->rx_packets++; 189 rcv_stats->rx_packets++;
190 190
191 netif_rx(skb); 191 netif_rx(skb);
192 return 0; 192 return NETDEV_TX_OK;
193 193
194tx_drop: 194tx_drop:
195 kfree_skb(skb); 195 kfree_skb(skb);
196 stats->tx_dropped++; 196 stats->tx_dropped++;
197 return 0; 197 return NETDEV_TX_OK;
198 198
199rx_drop: 199rx_drop:
200 kfree_skb(skb); 200 kfree_skb(skb);
201 rcv_stats->rx_dropped++; 201 rcv_stats->rx_dropped++;
202 return 0; 202 return NETDEV_TX_OK;
203} 203}
204 204
205/* 205/*
diff --git a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c
index 88c30a58b4bd..46eb618bbc90 100644
--- a/drivers/net/via-rhine.c
+++ b/drivers/net/via-rhine.c
@@ -1226,7 +1226,7 @@ static int rhine_start_tx(struct sk_buff *skb, struct net_device *dev)
1226 entry = rp->cur_tx % TX_RING_SIZE; 1226 entry = rp->cur_tx % TX_RING_SIZE;
1227 1227
1228 if (skb_padto(skb, ETH_ZLEN)) 1228 if (skb_padto(skb, ETH_ZLEN))
1229 return 0; 1229 return NETDEV_TX_OK;
1230 1230
1231 rp->tx_skbuff[entry] = skb; 1231 rp->tx_skbuff[entry] = skb;
1232 1232
@@ -1238,7 +1238,7 @@ static int rhine_start_tx(struct sk_buff *skb, struct net_device *dev)
1238 dev_kfree_skb(skb); 1238 dev_kfree_skb(skb);
1239 rp->tx_skbuff[entry] = NULL; 1239 rp->tx_skbuff[entry] = NULL;
1240 dev->stats.tx_dropped++; 1240 dev->stats.tx_dropped++;
1241 return 0; 1241 return NETDEV_TX_OK;
1242 } 1242 }
1243 1243
1244 /* Padding is not copied and so must be redone. */ 1244 /* Padding is not copied and so must be redone. */
@@ -1286,7 +1286,7 @@ static int rhine_start_tx(struct sk_buff *skb, struct net_device *dev)
1286 printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n", 1286 printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n",
1287 dev->name, rp->cur_tx-1, entry); 1287 dev->name, rp->cur_tx-1, entry);
1288 } 1288 }
1289 return 0; 1289 return NETDEV_TX_OK;
1290} 1290}
1291 1291
1292/* The interrupt handler does all of the Rx thread work and cleans up 1292/* The interrupt handler does all of the Rx thread work and cleans up
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index 3ba35956327a..42365e5f931b 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -2098,7 +2098,7 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
2098#ifdef VELOCITY_ZERO_COPY_SUPPORT 2098#ifdef VELOCITY_ZERO_COPY_SUPPORT
2099 if (skb_shinfo(skb)->nr_frags > 6 && __skb_linearize(skb)) { 2099 if (skb_shinfo(skb)->nr_frags > 6 && __skb_linearize(skb)) {
2100 kfree_skb(skb); 2100 kfree_skb(skb);
2101 return 0; 2101 return NETDEV_TX_OK;
2102 } 2102 }
2103#endif 2103#endif
2104 2104
diff --git a/drivers/net/vxge/vxge-config.c b/drivers/net/vxge/vxge-config.c
index 58d2551c78ed..9e94c4b0fb18 100644
--- a/drivers/net/vxge/vxge-config.c
+++ b/drivers/net/vxge/vxge-config.c
@@ -313,14 +313,6 @@ __vxge_hw_device_reg_addr_get(struct __vxge_hw_device *hldev)
313 hldev->kdfc = (u8 __iomem *)(hldev->bar0 + 313 hldev->kdfc = (u8 __iomem *)(hldev->bar0 +
314 VXGE_HW_TOC_GET_KDFC_INITIAL_OFFSET(val64)); 314 VXGE_HW_TOC_GET_KDFC_INITIAL_OFFSET(val64));
315 break; 315 break;
316 case 2:
317 hldev->kdfc = (u8 __iomem *)(hldev->bar1 +
318 VXGE_HW_TOC_GET_KDFC_INITIAL_OFFSET(val64));
319 break;
320 case 4:
321 hldev->kdfc = (u8 __iomem *)(hldev->bar2 +
322 VXGE_HW_TOC_GET_KDFC_INITIAL_OFFSET(val64));
323 break;
324 default: 316 default:
325 break; 317 break;
326 } 318 }
@@ -831,8 +823,6 @@ vxge_hw_device_initialize(
831 sizeof(struct vxge_hw_device_config)); 823 sizeof(struct vxge_hw_device_config));
832 824
833 hldev->bar0 = attr->bar0; 825 hldev->bar0 = attr->bar0;
834 hldev->bar1 = attr->bar1;
835 hldev->bar2 = attr->bar2;
836 hldev->pdev = attr->pdev; 826 hldev->pdev = attr->pdev;
837 827
838 hldev->uld_callbacks.link_up = attr->uld_callbacks.link_up; 828 hldev->uld_callbacks.link_up = attr->uld_callbacks.link_up;
diff --git a/drivers/net/vxge/vxge-config.h b/drivers/net/vxge/vxge-config.h
index afbdf6f4d224..224acea771ed 100644
--- a/drivers/net/vxge/vxge-config.h
+++ b/drivers/net/vxge/vxge-config.h
@@ -682,8 +682,6 @@ struct __vxge_hw_vpath_handle{
682 * @major_revision: PCI Device major revision 682 * @major_revision: PCI Device major revision
683 * @minor_revision: PCI Device minor revision 683 * @minor_revision: PCI Device minor revision
684 * @bar0: BAR0 virtual address. 684 * @bar0: BAR0 virtual address.
685 * @bar1: BAR1 virtual address.
686 * @bar2: BAR2 virtual address.
687 * @pdev: Physical device handle 685 * @pdev: Physical device handle
688 * @config: Confguration passed by the LL driver at initialization 686 * @config: Confguration passed by the LL driver at initialization
689 * @link_state: Link state 687 * @link_state: Link state
@@ -698,8 +696,6 @@ struct __vxge_hw_device {
698 u8 major_revision; 696 u8 major_revision;
699 u8 minor_revision; 697 u8 minor_revision;
700 void __iomem *bar0; 698 void __iomem *bar0;
701 void __iomem *bar1;
702 void __iomem *bar2;
703 struct pci_dev *pdev; 699 struct pci_dev *pdev;
704 struct net_device *ndev; 700 struct net_device *ndev;
705 struct vxge_hw_device_config config; 701 struct vxge_hw_device_config config;
@@ -788,17 +784,13 @@ struct vxge_hw_device_hw_info {
788/** 784/**
789 * struct vxge_hw_device_attr - Device memory spaces. 785 * struct vxge_hw_device_attr - Device memory spaces.
790 * @bar0: BAR0 virtual address. 786 * @bar0: BAR0 virtual address.
791 * @bar1: BAR1 virtual address.
792 * @bar2: BAR2 virtual address.
793 * @pdev: PCI device object. 787 * @pdev: PCI device object.
794 * 788 *
795 * Device memory spaces. Includes configuration, BAR0, BAR1, etc. per device 789 * Device memory spaces. Includes configuration, BAR0 etc. per device
796 * mapped memories. Also, includes a pointer to OS-specific PCI device object. 790 * mapped memories. Also, includes a pointer to OS-specific PCI device object.
797 */ 791 */
798struct vxge_hw_device_attr { 792struct vxge_hw_device_attr {
799 void __iomem *bar0; 793 void __iomem *bar0;
800 void __iomem *bar1;
801 void __iomem *bar2;
802 struct pci_dev *pdev; 794 struct pci_dev *pdev;
803 struct vxge_hw_uld_cbs uld_callbacks; 795 struct vxge_hw_uld_cbs uld_callbacks;
804}; 796};
diff --git a/drivers/net/vxge/vxge-main.c b/drivers/net/vxge/vxge-main.c
index 6034497536a4..7b5402b50d0a 100644
--- a/drivers/net/vxge/vxge-main.c
+++ b/drivers/net/vxge/vxge-main.c
@@ -374,10 +374,10 @@ vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
374 if (ring->vlgrp && ext_info->vlan && 374 if (ring->vlgrp && ext_info->vlan &&
375 (ring->vlan_tag_strip == 375 (ring->vlan_tag_strip ==
376 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)) 376 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
377 vlan_gro_receive(&ring->napi, ring->vlgrp, 377 vlan_gro_receive(ring->napi_p, ring->vlgrp,
378 ext_info->vlan, skb); 378 ext_info->vlan, skb);
379 else 379 else
380 napi_gro_receive(&ring->napi, skb); 380 napi_gro_receive(ring->napi_p, skb);
381 } else { 381 } else {
382 if (ring->vlgrp && vlan && 382 if (ring->vlgrp && vlan &&
383 (ring->vlan_tag_strip == 383 (ring->vlan_tag_strip ==
@@ -454,6 +454,8 @@ vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
454 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes); 454 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
455 pkt_length = dma_sizes; 455 pkt_length = dma_sizes;
456 456
457 pkt_length -= ETH_FCS_LEN;
458
457 vxge_debug_rx(VXGE_TRACE, 459 vxge_debug_rx(VXGE_TRACE,
458 "%s: %s:%d Packet Length = %d", 460 "%s: %s:%d Packet Length = %d",
459 ring->ndev->name, __func__, __LINE__, pkt_length); 461 ring->ndev->name, __func__, __LINE__, pkt_length);
@@ -817,7 +819,6 @@ vxge_xmit(struct sk_buff *skb, struct net_device *dev)
817 u64 dma_pointer; 819 u64 dma_pointer;
818 struct vxge_tx_priv *txdl_priv = NULL; 820 struct vxge_tx_priv *txdl_priv = NULL;
819 struct __vxge_hw_fifo *fifo_hw; 821 struct __vxge_hw_fifo *fifo_hw;
820 u32 max_mss = 0x0;
821 int offload_type; 822 int offload_type;
822 unsigned long flags = 0; 823 unsigned long flags = 0;
823 int vpath_no = 0; 824 int vpath_no = 0;
@@ -969,10 +970,6 @@ vxge_xmit(struct sk_buff *skb, struct net_device *dev)
969 970
970 int mss = vxge_tcp_mss(skb); 971 int mss = vxge_tcp_mss(skb);
971 if (mss) { 972 if (mss) {
972 max_mss = dev->mtu + ETH_HLEN -
973 VXGE_HW_TCPIP_HEADER_MAX_SIZE;
974 if (mss > max_mss)
975 mss = max_mss;
976 vxge_debug_tx(VXGE_TRACE, 973 vxge_debug_tx(VXGE_TRACE,
977 "%s: %s:%d mss = %d", 974 "%s: %s:%d mss = %d",
978 dev->name, __func__, __LINE__, mss); 975 dev->name, __func__, __LINE__, mss);
@@ -1000,7 +997,7 @@ vxge_xmit(struct sk_buff *skb, struct net_device *dev)
1000 VXGE_COMPLETE_VPATH_TX(fifo); 997 VXGE_COMPLETE_VPATH_TX(fifo);
1001 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...", 998 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
1002 dev->name, __func__, __LINE__); 999 dev->name, __func__, __LINE__);
1003 return 0; 1000 return NETDEV_TX_OK;
1004 1001
1005_exit0: 1002_exit0:
1006 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name); 1003 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
@@ -1024,7 +1021,7 @@ _exit2:
1024 spin_unlock_irqrestore(&fifo->tx_lock, flags); 1021 spin_unlock_irqrestore(&fifo->tx_lock, flags);
1025 VXGE_COMPLETE_VPATH_TX(fifo); 1022 VXGE_COMPLETE_VPATH_TX(fifo);
1026 1023
1027 return 0; 1024 return NETDEV_TX_OK;
1028} 1025}
1029 1026
1030/* 1027/*
@@ -2137,16 +2134,16 @@ int vxge_open_vpaths(struct vxgedev *vdev)
2137 */ 2134 */
2138static irqreturn_t vxge_isr_napi(int irq, void *dev_id) 2135static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2139{ 2136{
2140 struct __vxge_hw_device *hldev = (struct __vxge_hw_device *)dev_id;
2141 struct vxgedev *vdev;
2142 struct net_device *dev; 2137 struct net_device *dev;
2138 struct __vxge_hw_device *hldev;
2143 u64 reason; 2139 u64 reason;
2144 enum vxge_hw_status status; 2140 enum vxge_hw_status status;
2141 struct vxgedev *vdev = (struct vxgedev *) dev_id;;
2145 2142
2146 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__); 2143 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2147 2144
2148 dev = hldev->ndev; 2145 dev = vdev->ndev;
2149 vdev = netdev_priv(dev); 2146 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
2150 2147
2151 if (pci_channel_offline(vdev->pdev)) 2148 if (pci_channel_offline(vdev->pdev))
2152 return IRQ_NONE; 2149 return IRQ_NONE;
@@ -2417,15 +2414,13 @@ static void vxge_rem_isr(struct vxgedev *vdev)
2417#endif 2414#endif
2418 if (vdev->config.intr_type == INTA) { 2415 if (vdev->config.intr_type == INTA) {
2419 synchronize_irq(vdev->pdev->irq); 2416 synchronize_irq(vdev->pdev->irq);
2420 free_irq(vdev->pdev->irq, hldev); 2417 free_irq(vdev->pdev->irq, vdev);
2421 } 2418 }
2422} 2419}
2423 2420
2424static int vxge_add_isr(struct vxgedev *vdev) 2421static int vxge_add_isr(struct vxgedev *vdev)
2425{ 2422{
2426 int ret = 0; 2423 int ret = 0;
2427 struct __vxge_hw_device *hldev =
2428 (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2429#ifdef CONFIG_PCI_MSI 2424#ifdef CONFIG_PCI_MSI
2430 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0; 2425 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2431 u64 function_mode = vdev->config.device_hw_info.function_mode; 2426 u64 function_mode = vdev->config.device_hw_info.function_mode;
@@ -2579,7 +2574,7 @@ INTA_MODE:
2579 if (vdev->config.intr_type == INTA) { 2574 if (vdev->config.intr_type == INTA) {
2580 ret = request_irq((int) vdev->pdev->irq, 2575 ret = request_irq((int) vdev->pdev->irq,
2581 vxge_isr_napi, 2576 vxge_isr_napi,
2582 IRQF_SHARED, vdev->desc[0], hldev); 2577 IRQF_SHARED, vdev->desc[0], vdev);
2583 if (ret) { 2578 if (ret) {
2584 vxge_debug_init(VXGE_ERR, 2579 vxge_debug_init(VXGE_ERR,
2585 "%s %s-%d: ISR registration failed", 2580 "%s %s-%d: ISR registration failed",
@@ -2712,11 +2707,15 @@ vxge_open(struct net_device *dev)
2712 netif_napi_add(dev, &vdev->napi, vxge_poll_inta, 2707 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2713 vdev->config.napi_weight); 2708 vdev->config.napi_weight);
2714 napi_enable(&vdev->napi); 2709 napi_enable(&vdev->napi);
2710 for (i = 0; i < vdev->no_of_vpath; i++)
2711 vdev->vpaths[i].ring.napi_p = &vdev->napi;
2715 } else { 2712 } else {
2716 for (i = 0; i < vdev->no_of_vpath; i++) { 2713 for (i = 0; i < vdev->no_of_vpath; i++) {
2717 netif_napi_add(dev, &vdev->vpaths[i].ring.napi, 2714 netif_napi_add(dev, &vdev->vpaths[i].ring.napi,
2718 vxge_poll_msix, vdev->config.napi_weight); 2715 vxge_poll_msix, vdev->config.napi_weight);
2719 napi_enable(&vdev->vpaths[i].ring.napi); 2716 napi_enable(&vdev->vpaths[i].ring.napi);
2717 vdev->vpaths[i].ring.napi_p =
2718 &vdev->vpaths[i].ring.napi;
2720 } 2719 }
2721 } 2720 }
2722 2721
@@ -2890,6 +2889,9 @@ int do_vxge_close(struct net_device *dev, int do_io)
2890 vdev = (struct vxgedev *)netdev_priv(dev); 2889 vdev = (struct vxgedev *)netdev_priv(dev);
2891 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev); 2890 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2892 2891
2892 if (unlikely(!is_vxge_card_up(vdev)))
2893 return 0;
2894
2893 /* If vxge_handle_crit_err task is executing, 2895 /* If vxge_handle_crit_err task is executing,
2894 * wait till it completes. */ 2896 * wait till it completes. */
2895 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) 2897 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
@@ -4152,18 +4154,6 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4152 attr.bar0, 4154 attr.bar0,
4153 (unsigned long long)pci_resource_start(pdev, 0)); 4155 (unsigned long long)pci_resource_start(pdev, 0));
4154 4156
4155 attr.bar1 = pci_ioremap_bar(pdev, 2);
4156 if (!attr.bar1) {
4157 vxge_debug_init(VXGE_ERR,
4158 "%s : cannot remap io memory bar2", __func__);
4159 ret = -ENODEV;
4160 goto _exit3;
4161 }
4162 vxge_debug_ll_config(VXGE_TRACE,
4163 "pci ioremap bar1: %p:0x%llx",
4164 attr.bar1,
4165 (unsigned long long)pci_resource_start(pdev, 2));
4166
4167 status = vxge_hw_device_hw_info_get(attr.bar0, 4157 status = vxge_hw_device_hw_info_get(attr.bar0,
4168 &ll_config.device_hw_info); 4158 &ll_config.device_hw_info);
4169 if (status != VXGE_HW_OK) { 4159 if (status != VXGE_HW_OK) {
@@ -4171,17 +4161,17 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4171 "%s: Reading of hardware info failed." 4161 "%s: Reading of hardware info failed."
4172 "Please try upgrading the firmware.", VXGE_DRIVER_NAME); 4162 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4173 ret = -EINVAL; 4163 ret = -EINVAL;
4174 goto _exit4; 4164 goto _exit3;
4175 } 4165 }
4176 4166
4177 if (ll_config.device_hw_info.fw_version.major != 4167 if (ll_config.device_hw_info.fw_version.major !=
4178 VXGE_DRIVER_VERSION_MAJOR) { 4168 VXGE_DRIVER_FW_VERSION_MAJOR) {
4179 vxge_debug_init(VXGE_ERR, 4169 vxge_debug_init(VXGE_ERR,
4180 "FW Ver.(maj): %d not driver's expected version: %d", 4170 "%s: Incorrect firmware version."
4181 ll_config.device_hw_info.fw_version.major, 4171 "Please upgrade the firmware to version 1.x.x",
4182 VXGE_DRIVER_VERSION_MAJOR); 4172 VXGE_DRIVER_NAME);
4183 ret = -EINVAL; 4173 ret = -EINVAL;
4184 goto _exit4; 4174 goto _exit3;
4185 } 4175 }
4186 4176
4187 vpath_mask = ll_config.device_hw_info.vpath_mask; 4177 vpath_mask = ll_config.device_hw_info.vpath_mask;
@@ -4189,7 +4179,7 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4189 vxge_debug_ll_config(VXGE_TRACE, 4179 vxge_debug_ll_config(VXGE_TRACE,
4190 "%s: No vpaths available in device", VXGE_DRIVER_NAME); 4180 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4191 ret = -EINVAL; 4181 ret = -EINVAL;
4192 goto _exit4; 4182 goto _exit3;
4193 } 4183 }
4194 4184
4195 vxge_debug_ll_config(VXGE_TRACE, 4185 vxge_debug_ll_config(VXGE_TRACE,
@@ -4222,7 +4212,7 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4222 vxge_debug_ll_config(VXGE_ERR, 4212 vxge_debug_ll_config(VXGE_ERR,
4223 "%s: No more vpaths to configure", VXGE_DRIVER_NAME); 4213 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4224 ret = 0; 4214 ret = 0;
4225 goto _exit4; 4215 goto _exit3;
4226 } 4216 }
4227 4217
4228 /* Setting driver callbacks */ 4218 /* Setting driver callbacks */
@@ -4235,7 +4225,7 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4235 vxge_debug_init(VXGE_ERR, 4225 vxge_debug_init(VXGE_ERR,
4236 "Failed to initialize device (%d)", status); 4226 "Failed to initialize device (%d)", status);
4237 ret = -EINVAL; 4227 ret = -EINVAL;
4238 goto _exit4; 4228 goto _exit3;
4239 } 4229 }
4240 4230
4241 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL); 4231 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
@@ -4260,7 +4250,7 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4260 if (vxge_device_register(hldev, &ll_config, high_dma, no_of_vpath, 4250 if (vxge_device_register(hldev, &ll_config, high_dma, no_of_vpath,
4261 &vdev)) { 4251 &vdev)) {
4262 ret = -EINVAL; 4252 ret = -EINVAL;
4263 goto _exit5; 4253 goto _exit4;
4264 } 4254 }
4265 4255
4266 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL); 4256 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
@@ -4271,7 +4261,6 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4271 hldev->ndev = vdev->ndev; 4261 hldev->ndev = vdev->ndev;
4272 vdev->mtu = VXGE_HW_DEFAULT_MTU; 4262 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4273 vdev->bar0 = attr.bar0; 4263 vdev->bar0 = attr.bar0;
4274 vdev->bar1 = attr.bar1;
4275 vdev->max_vpath_supported = max_vpath_supported; 4264 vdev->max_vpath_supported = max_vpath_supported;
4276 vdev->no_of_vpath = no_of_vpath; 4265 vdev->no_of_vpath = no_of_vpath;
4277 4266
@@ -4336,6 +4325,27 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4336 ll_config.device_hw_info.fw_version.version, 4325 ll_config.device_hw_info.fw_version.version,
4337 ll_config.device_hw_info.fw_date.date); 4326 ll_config.device_hw_info.fw_date.date);
4338 4327
4328 if (new_device) {
4329 switch (ll_config.device_hw_info.function_mode) {
4330 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4331 vxge_debug_init(VXGE_TRACE,
4332 "%s: Single Function Mode Enabled", vdev->ndev->name);
4333 break;
4334 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4335 vxge_debug_init(VXGE_TRACE,
4336 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4337 break;
4338 case VXGE_HW_FUNCTION_MODE_SRIOV:
4339 vxge_debug_init(VXGE_TRACE,
4340 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4341 break;
4342 case VXGE_HW_FUNCTION_MODE_MRIOV:
4343 vxge_debug_init(VXGE_TRACE,
4344 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4345 break;
4346 }
4347 }
4348
4339 vxge_print_parm(vdev, vpath_mask); 4349 vxge_print_parm(vdev, vpath_mask);
4340 4350
4341 /* Store the fw version for ethttool option */ 4351 /* Store the fw version for ethttool option */
@@ -4353,7 +4363,7 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4353 "%s: mac_addr_list : memory allocation failed", 4363 "%s: mac_addr_list : memory allocation failed",
4354 vdev->ndev->name); 4364 vdev->ndev->name);
4355 ret = -EPERM; 4365 ret = -EPERM;
4356 goto _exit6; 4366 goto _exit5;
4357 } 4367 }
4358 macaddr = (u8 *)&entry->macaddr; 4368 macaddr = (u8 *)&entry->macaddr;
4359 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN); 4369 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
@@ -4361,6 +4371,7 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4361 vdev->vpaths[i].mac_addr_cnt = 1; 4371 vdev->vpaths[i].mac_addr_cnt = 1;
4362 } 4372 }
4363 4373
4374 kfree(device_config);
4364 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...", 4375 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4365 vdev->ndev->name, __func__, __LINE__); 4376 vdev->ndev->name, __func__, __LINE__);
4366 4377
@@ -4370,16 +4381,14 @@ vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4370 4381
4371 return 0; 4382 return 0;
4372 4383
4373_exit6: 4384_exit5:
4374 for (i = 0; i < vdev->no_of_vpath; i++) 4385 for (i = 0; i < vdev->no_of_vpath; i++)
4375 vxge_free_mac_add_list(&vdev->vpaths[i]); 4386 vxge_free_mac_add_list(&vdev->vpaths[i]);
4376 4387
4377 vxge_device_unregister(hldev); 4388 vxge_device_unregister(hldev);
4378_exit5: 4389_exit4:
4379 pci_disable_sriov(pdev); 4390 pci_disable_sriov(pdev);
4380 vxge_hw_device_terminate(hldev); 4391 vxge_hw_device_terminate(hldev);
4381_exit4:
4382 iounmap(attr.bar1);
4383_exit3: 4392_exit3:
4384 iounmap(attr.bar0); 4393 iounmap(attr.bar0);
4385_exit2: 4394_exit2:
@@ -4438,7 +4447,6 @@ vxge_remove(struct pci_dev *pdev)
4438 kfree(vdev->vpaths); 4447 kfree(vdev->vpaths);
4439 4448
4440 iounmap(vdev->bar0); 4449 iounmap(vdev->bar0);
4441 iounmap(vdev->bar1);
4442 4450
4443 pci_disable_sriov(pdev); 4451 pci_disable_sriov(pdev);
4444 4452
diff --git a/drivers/net/vxge/vxge-main.h b/drivers/net/vxge/vxge-main.h
index 9704b2bd4320..18d824c3ab93 100644
--- a/drivers/net/vxge/vxge-main.h
+++ b/drivers/net/vxge/vxge-main.h
@@ -21,7 +21,7 @@
21 21
22#define VXGE_DRIVER_NAME "vxge" 22#define VXGE_DRIVER_NAME "vxge"
23#define VXGE_DRIVER_VENDOR "Neterion, Inc" 23#define VXGE_DRIVER_VENDOR "Neterion, Inc"
24#define VXGE_DRIVER_VERSION_MAJOR 0 24#define VXGE_DRIVER_FW_VERSION_MAJOR 1
25 25
26#define DRV_VERSION VXGE_VERSION_MAJOR"."VXGE_VERSION_MINOR"."\ 26#define DRV_VERSION VXGE_VERSION_MAJOR"."VXGE_VERSION_MINOR"."\
27 VXGE_VERSION_FIX"."VXGE_VERSION_BUILD"-"\ 27 VXGE_VERSION_FIX"."VXGE_VERSION_BUILD"-"\
@@ -260,6 +260,7 @@ struct vxge_ring {
260 int gro_enable; 260 int gro_enable;
261 261
262 struct napi_struct napi; 262 struct napi_struct napi;
263 struct napi_struct *napi_p;
263 264
264#define VXGE_MAX_MAC_ADDR_COUNT 30 265#define VXGE_MAX_MAC_ADDR_COUNT 30
265 266
@@ -363,7 +364,6 @@ struct vxgedev {
363 364
364 struct __vxge_hw_vpath_handle *vp_handles[VXGE_HW_MAX_VIRTUAL_PATHS]; 365 struct __vxge_hw_vpath_handle *vp_handles[VXGE_HW_MAX_VIRTUAL_PATHS];
365 void __iomem *bar0; 366 void __iomem *bar0;
366 void __iomem *bar1;
367 struct vxge_sw_stats stats; 367 struct vxge_sw_stats stats;
368 int mtu; 368 int mtu;
369 /* Below variables are used for vpath selection to transmit a packet */ 369 /* Below variables are used for vpath selection to transmit a packet */
diff --git a/drivers/net/vxge/vxge-reg.h b/drivers/net/vxge/vxge-reg.h
index 10f4da32929f..9a3b823e08d4 100644
--- a/drivers/net/vxge/vxge-reg.h
+++ b/drivers/net/vxge/vxge-reg.h
@@ -1784,7 +1784,7 @@ struct vxge_hw_mrpcim_reg {
1784#define VXGE_HW_XMAC_GEN_ERR_REG_XMACJ_XMAC_FSM_ERR vxge_mBIT(63) 1784#define VXGE_HW_XMAC_GEN_ERR_REG_XMACJ_XMAC_FSM_ERR vxge_mBIT(63)
1785/*0x01e18*/ u64 xmac_gen_err_mask; 1785/*0x01e18*/ u64 xmac_gen_err_mask;
1786/*0x01e20*/ u64 xmac_gen_err_alarm; 1786/*0x01e20*/ u64 xmac_gen_err_alarm;
1787/*0x01e28*/ u64 xmac_link_err_port_reg[2]; 1787/*0x01e28*/ u64 xmac_link_err_port0_reg;
1788#define VXGE_HW_XMAC_LINK_ERR_PORT_REG_XMACJ_PORT_DOWN vxge_mBIT(3) 1788#define VXGE_HW_XMAC_LINK_ERR_PORT_REG_XMACJ_PORT_DOWN vxge_mBIT(3)
1789#define VXGE_HW_XMAC_LINK_ERR_PORT_REG_XMACJ_PORT_UP vxge_mBIT(7) 1789#define VXGE_HW_XMAC_LINK_ERR_PORT_REG_XMACJ_PORT_UP vxge_mBIT(7)
1790#define VXGE_HW_XMAC_LINK_ERR_PORT_REG_XMACJ_PORT_WENT_DOWN vxge_mBIT(11) 1790#define VXGE_HW_XMAC_LINK_ERR_PORT_REG_XMACJ_PORT_WENT_DOWN vxge_mBIT(11)
@@ -1798,8 +1798,11 @@ struct vxge_hw_mrpcim_reg {
1798#define VXGE_HW_XMAC_LINK_ERR_PORT_REG_RATEMGMT_LASI_INV vxge_mBIT(39) 1798#define VXGE_HW_XMAC_LINK_ERR_PORT_REG_RATEMGMT_LASI_INV vxge_mBIT(39)
1799#define VXGE_HW_XMAC_LINK_ERR_PORT_REG_XMDIO_MDIO_MGR_ACCESS_COMPLETE \ 1799#define VXGE_HW_XMAC_LINK_ERR_PORT_REG_XMDIO_MDIO_MGR_ACCESS_COMPLETE \
1800 vxge_mBIT(47) 1800 vxge_mBIT(47)
1801/*0x01e30*/ u64 xmac_link_err_port_mask[2]; 1801/*0x01e30*/ u64 xmac_link_err_port0_mask;
1802/*0x01e38*/ u64 xmac_link_err_port_alarm[2]; 1802/*0x01e38*/ u64 xmac_link_err_port0_alarm;
1803/*0x01e40*/ u64 xmac_link_err_port1_reg;
1804/*0x01e48*/ u64 xmac_link_err_port1_mask;
1805/*0x01e50*/ u64 xmac_link_err_port1_alarm;
1803/*0x01e58*/ u64 xgxs_gen_err_reg; 1806/*0x01e58*/ u64 xgxs_gen_err_reg;
1804#define VXGE_HW_XGXS_GEN_ERR_REG_XGXS_XGXS_FSM_ERR vxge_mBIT(63) 1807#define VXGE_HW_XGXS_GEN_ERR_REG_XGXS_XGXS_FSM_ERR vxge_mBIT(63)
1805/*0x01e60*/ u64 xgxs_gen_err_mask; 1808/*0x01e60*/ u64 xgxs_gen_err_mask;
diff --git a/drivers/net/vxge/vxge-traffic.h b/drivers/net/vxge/vxge-traffic.h
index 7567a1140d07..8260b91fd795 100644
--- a/drivers/net/vxge/vxge-traffic.h
+++ b/drivers/net/vxge/vxge-traffic.h
@@ -35,8 +35,6 @@
35 VXGE_HW_HEADER_VLAN_SIZE + \ 35 VXGE_HW_HEADER_VLAN_SIZE + \
36 VXGE_HW_HEADER_SNAP_SIZE) 36 VXGE_HW_HEADER_SNAP_SIZE)
37 37
38#define VXGE_HW_TCPIP_HEADER_MAX_SIZE (64 + 64)
39
40/* 32bit alignments */ 38/* 32bit alignments */
41#define VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN 2 39#define VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN 2
42#define VXGE_HW_HEADER_802_2_SNAP_ALIGN 2 40#define VXGE_HW_HEADER_802_2_SNAP_ALIGN 2
diff --git a/drivers/net/vxge/vxge-version.h b/drivers/net/vxge/vxge-version.h
index 82786ffb7dd9..580c6eb077b9 100644
--- a/drivers/net/vxge/vxge-version.h
+++ b/drivers/net/vxge/vxge-version.h
@@ -18,6 +18,6 @@
18#define VXGE_VERSION_MAJOR "2" 18#define VXGE_VERSION_MAJOR "2"
19#define VXGE_VERSION_MINOR "0" 19#define VXGE_VERSION_MINOR "0"
20#define VXGE_VERSION_FIX "4" 20#define VXGE_VERSION_FIX "4"
21#define VXGE_VERSION_BUILD "17795" 21#define VXGE_VERSION_BUILD "17899"
22#define VXGE_VERSION_FOR "k" 22#define VXGE_VERSION_FOR "k"
23#endif 23#endif
diff --git a/drivers/net/wan/cycx_x25.c b/drivers/net/wan/cycx_x25.c
index f525f9fe74db..4ae9bd297cc2 100644
--- a/drivers/net/wan/cycx_x25.c
+++ b/drivers/net/wan/cycx_x25.c
@@ -663,7 +663,7 @@ static int cycx_netdevice_hard_start_xmit(struct sk_buff *skb,
663free_packet: 663free_packet:
664 dev_kfree_skb(skb); 664 dev_kfree_skb(skb);
665 665
666 return 0; 666 return NETDEV_TX_OK;
667} 667}
668 668
669/* Get Ethernet-style interface statistics. 669/* Get Ethernet-style interface statistics.
diff --git a/drivers/net/wan/dlci.c b/drivers/net/wan/dlci.c
index 2fa275a58f9d..8526b6d1ee4d 100644
--- a/drivers/net/wan/dlci.c
+++ b/drivers/net/wan/dlci.c
@@ -194,7 +194,7 @@ static int dlci_transmit(struct sk_buff *skb, struct net_device *dev)
194 ret = 0; 194 ret = 0;
195 195
196 if (!skb || !dev) 196 if (!skb || !dev)
197 return(0); 197 return NETDEV_TX_OK;
198 198
199 dlp = netdev_priv(dev); 199 dlp = netdev_priv(dev);
200 200
@@ -219,7 +219,7 @@ static int dlci_transmit(struct sk_buff *skb, struct net_device *dev)
219 /* Alan Cox recommends always returning 0, and always freeing the packet */ 219 /* Alan Cox recommends always returning 0, and always freeing the packet */
220 /* experience suggest a slightly more conservative approach */ 220 /* experience suggest a slightly more conservative approach */
221 221
222 if (!ret) 222 if (ret == NETDEV_TX_OK)
223 { 223 {
224 dev_kfree_skb(skb); 224 dev_kfree_skb(skb);
225 netif_wake_queue(dev); 225 netif_wake_queue(dev);
diff --git a/drivers/net/wan/dscc4.c b/drivers/net/wan/dscc4.c
index 8face5db8f32..e81946d98543 100644
--- a/drivers/net/wan/dscc4.c
+++ b/drivers/net/wan/dscc4.c
@@ -1182,7 +1182,7 @@ static int dscc4_start_xmit(struct sk_buff *skb, struct net_device *dev)
1182 if (dscc4_tx_quiescent(dpriv, dev)) 1182 if (dscc4_tx_quiescent(dpriv, dev))
1183 dscc4_do_tx(dpriv, dev); 1183 dscc4_do_tx(dpriv, dev);
1184 1184
1185 return 0; 1185 return NETDEV_TX_OK;
1186} 1186}
1187 1187
1188static int dscc4_close(struct net_device *dev) 1188static int dscc4_close(struct net_device *dev)
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index 25c9ef6a1815..20a1237a3d74 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -792,25 +792,6 @@ fst_process_rx_status(int rx_status, char *name)
792 */ 792 */
793 break; 793 break;
794 } 794 }
795
796 case NET_RX_CN_LOW:
797 {
798 dbg(DBG_ASS, "%s: Receive Low Congestion\n", name);
799 break;
800 }
801
802 case NET_RX_CN_MOD:
803 {
804 dbg(DBG_ASS, "%s: Receive Moderate Congestion\n", name);
805 break;
806 }
807
808 case NET_RX_CN_HIGH:
809 {
810 dbg(DBG_ASS, "%s: Receive High Congestion\n", name);
811 break;
812 }
813
814 case NET_RX_DROP: 795 case NET_RX_DROP:
815 { 796 {
816 dbg(DBG_ASS, "%s: Received packet dropped\n", name); 797 dbg(DBG_ASS, "%s: Received packet dropped\n", name);
@@ -2313,7 +2294,7 @@ fst_start_xmit(struct sk_buff *skb, struct net_device *dev)
2313 dbg(DBG_ASS, 2294 dbg(DBG_ASS,
2314 "Tried to transmit but no carrier on card %d port %d\n", 2295 "Tried to transmit but no carrier on card %d port %d\n",
2315 card->card_no, port->index); 2296 card->card_no, port->index);
2316 return 0; 2297 return NETDEV_TX_OK;
2317 } 2298 }
2318 2299
2319 /* Drop it if it's too big! MTU failure ? */ 2300 /* Drop it if it's too big! MTU failure ? */
@@ -2322,7 +2303,7 @@ fst_start_xmit(struct sk_buff *skb, struct net_device *dev)
2322 LEN_TX_BUFFER); 2303 LEN_TX_BUFFER);
2323 dev_kfree_skb(skb); 2304 dev_kfree_skb(skb);
2324 dev->stats.tx_errors++; 2305 dev->stats.tx_errors++;
2325 return 0; 2306 return NETDEV_TX_OK;
2326 } 2307 }
2327 2308
2328 /* 2309 /*
@@ -2356,7 +2337,7 @@ fst_start_xmit(struct sk_buff *skb, struct net_device *dev)
2356 dev->stats.tx_errors++; 2337 dev->stats.tx_errors++;
2357 dbg(DBG_ASS, "Tx queue overflow card %d port %d\n", 2338 dbg(DBG_ASS, "Tx queue overflow card %d port %d\n",
2358 card->card_no, port->index); 2339 card->card_no, port->index);
2359 return 0; 2340 return NETDEV_TX_OK;
2360 } 2341 }
2361 2342
2362 /* 2343 /*
@@ -2373,7 +2354,7 @@ fst_start_xmit(struct sk_buff *skb, struct net_device *dev)
2373 fst_q_work_item(&fst_work_txq, card->card_no); 2354 fst_q_work_item(&fst_work_txq, card->card_no);
2374 tasklet_schedule(&fst_tx_task); 2355 tasklet_schedule(&fst_tx_task);
2375 2356
2376 return 0; 2357 return NETDEV_TX_OK;
2377} 2358}
2378 2359
2379/* 2360/*
diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index bfa0161a02d3..52438c76bf8a 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -421,7 +421,7 @@ static int pvc_xmit(struct sk_buff *skb, struct net_device *dev)
421 GFP_ATOMIC)) { 421 GFP_ATOMIC)) {
422 dev->stats.tx_dropped++; 422 dev->stats.tx_dropped++;
423 dev_kfree_skb(skb); 423 dev_kfree_skb(skb);
424 return 0; 424 return NETDEV_TX_OK;
425 } 425 }
426 skb_put(skb, pad); 426 skb_put(skb, pad);
427 memset(skb->data + len, 0, pad); 427 memset(skb->data + len, 0, pad);
@@ -435,13 +435,13 @@ static int pvc_xmit(struct sk_buff *skb, struct net_device *dev)
435 dev->stats.tx_compressed++; 435 dev->stats.tx_compressed++;
436 skb->dev = pvc->frad; 436 skb->dev = pvc->frad;
437 dev_queue_xmit(skb); 437 dev_queue_xmit(skb);
438 return 0; 438 return NETDEV_TX_OK;
439 } 439 }
440 } 440 }
441 441
442 dev->stats.tx_dropped++; 442 dev->stats.tx_dropped++;
443 dev_kfree_skb(skb); 443 dev_kfree_skb(skb);
444 return 0; 444 return NETDEV_TX_OK;
445} 445}
446 446
447static inline void fr_log_dlci_active(pvc_device *pvc) 447static inline void fr_log_dlci_active(pvc_device *pvc)
diff --git a/drivers/net/wan/lmc/lmc_main.c b/drivers/net/wan/lmc/lmc_main.c
index 45b1822c962d..d1492ae5d30a 100644
--- a/drivers/net/wan/lmc/lmc_main.c
+++ b/drivers/net/wan/lmc/lmc_main.c
@@ -1428,7 +1428,7 @@ static int lmc_start_xmit(struct sk_buff *skb, struct net_device *dev)
1428 lmc_softc_t *sc = dev_to_sc(dev); 1428 lmc_softc_t *sc = dev_to_sc(dev);
1429 u32 flag; 1429 u32 flag;
1430 int entry; 1430 int entry;
1431 int ret = 0; 1431 int ret = NETDEV_TX_OK;
1432 unsigned long flags; 1432 unsigned long flags;
1433 1433
1434 lmc_trace(dev, "lmc_start_xmit in"); 1434 lmc_trace(dev, "lmc_start_xmit in");
diff --git a/drivers/net/wan/sbni.c b/drivers/net/wan/sbni.c
index 3fb9dbc88a1a..545178e6765d 100644
--- a/drivers/net/wan/sbni.c
+++ b/drivers/net/wan/sbni.c
@@ -465,7 +465,7 @@ sbni_start_xmit( struct sk_buff *skb, struct net_device *dev )
465 prepare_to_send( skb, p ); 465 prepare_to_send( skb, p );
466 spin_unlock( &nl->lock ); 466 spin_unlock( &nl->lock );
467 netif_start_queue( dev ); 467 netif_start_queue( dev );
468 return 0; 468 return NETDEV_TX_OK;
469 } 469 }
470 } 470 }
471 471
@@ -485,7 +485,7 @@ sbni_start_xmit( struct sk_buff *skb, struct net_device *dev )
485 prepare_to_send( skb, dev ); 485 prepare_to_send( skb, dev );
486 486
487 spin_unlock( &nl->lock ); 487 spin_unlock( &nl->lock );
488 return 0; 488 return NETDEV_TX_OK;
489} 489}
490 490
491#endif /* CONFIG_SBNI_MULTILINE */ 491#endif /* CONFIG_SBNI_MULTILINE */
diff --git a/drivers/net/wan/wanxl.c b/drivers/net/wan/wanxl.c
index e4ad7b6b52eb..03b76adbe5f0 100644
--- a/drivers/net/wan/wanxl.c
+++ b/drivers/net/wan/wanxl.c
@@ -310,7 +310,7 @@ static int wanxl_xmit(struct sk_buff *skb, struct net_device *dev)
310 } 310 }
311 311
312 spin_unlock(&port->lock); 312 spin_unlock(&port->lock);
313 return 0; 313 return NETDEV_TX_OK;
314} 314}
315 315
316 316
diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
index d67e208ab375..1047920e742c 100644
--- a/drivers/net/wan/x25_asy.c
+++ b/drivers/net/wan/x25_asy.c
@@ -308,7 +308,7 @@ static int x25_asy_xmit(struct sk_buff *skb, struct net_device *dev)
308 printk(KERN_ERR "%s: xmit call when iface is down\n", 308 printk(KERN_ERR "%s: xmit call when iface is down\n",
309 dev->name); 309 dev->name);
310 kfree_skb(skb); 310 kfree_skb(skb);
311 return 0; 311 return NETDEV_TX_OK;
312 } 312 }
313 313
314 switch (skb->data[0]) { 314 switch (skb->data[0]) {
@@ -319,14 +319,14 @@ static int x25_asy_xmit(struct sk_buff *skb, struct net_device *dev)
319 if (err != LAPB_OK) 319 if (err != LAPB_OK)
320 printk(KERN_ERR "x25_asy: lapb_connect_request error - %d\n", err); 320 printk(KERN_ERR "x25_asy: lapb_connect_request error - %d\n", err);
321 kfree_skb(skb); 321 kfree_skb(skb);
322 return 0; 322 return NETDEV_TX_OK;
323 case 0x02: /* Disconnect request .. do nothing - hang up ?? */ 323 case 0x02: /* Disconnect request .. do nothing - hang up ?? */
324 err = lapb_disconnect_request(dev); 324 err = lapb_disconnect_request(dev);
325 if (err != LAPB_OK) 325 if (err != LAPB_OK)
326 printk(KERN_ERR "x25_asy: lapb_disconnect_request error - %d\n", err); 326 printk(KERN_ERR "x25_asy: lapb_disconnect_request error - %d\n", err);
327 default: 327 default:
328 kfree_skb(skb); 328 kfree_skb(skb);
329 return 0; 329 return NETDEV_TX_OK;
330 } 330 }
331 skb_pull(skb, 1); /* Remove control byte */ 331 skb_pull(skb, 1); /* Remove control byte */
332 /* 332 /*
@@ -344,9 +344,9 @@ static int x25_asy_xmit(struct sk_buff *skb, struct net_device *dev)
344 if (err != LAPB_OK) { 344 if (err != LAPB_OK) {
345 printk(KERN_ERR "x25_asy: lapb_data_request error - %d\n", err); 345 printk(KERN_ERR "x25_asy: lapb_data_request error - %d\n", err);
346 kfree_skb(skb); 346 kfree_skb(skb);
347 return 0; 347 return NETDEV_TX_OK;
348 } 348 }
349 return 0; 349 return NETDEV_TX_OK;
350} 350}
351 351
352 352
diff --git a/drivers/net/wireless/adm8211.c b/drivers/net/wireless/adm8211.c
index 2b9e379994a1..ecc93834533f 100644
--- a/drivers/net/wireless/adm8211.c
+++ b/drivers/net/wireless/adm8211.c
@@ -452,7 +452,8 @@ static void adm8211_interrupt_rci(struct ieee80211_hw *dev)
452 rx_status.freq = adm8211_channels[priv->channel - 1].center_freq; 452 rx_status.freq = adm8211_channels[priv->channel - 1].center_freq;
453 rx_status.band = IEEE80211_BAND_2GHZ; 453 rx_status.band = IEEE80211_BAND_2GHZ;
454 454
455 ieee80211_rx_irqsafe(dev, skb, &rx_status); 455 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
456 ieee80211_rx_irqsafe(dev, skb);
456 } 457 }
457 458
458 entry = (++priv->cur_rx) % priv->rx_ring_size; 459 entry = (++priv->cur_rx) % priv->rx_ring_size;
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index c70604f0329e..49f3139a3fe7 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -1927,7 +1927,7 @@ static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1927 1927
1928 if (!skb) { 1928 if (!skb) {
1929 airo_print_err(dev->name, "%s: skb == NULL!",__func__); 1929 airo_print_err(dev->name, "%s: skb == NULL!",__func__);
1930 return 0; 1930 return NETDEV_TX_OK;
1931 } 1931 }
1932 npacks = skb_queue_len (&ai->txq); 1932 npacks = skb_queue_len (&ai->txq);
1933 1933
@@ -1938,7 +1938,7 @@ static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1938 return NETDEV_TX_BUSY; 1938 return NETDEV_TX_BUSY;
1939 } 1939 }
1940 skb_queue_tail (&ai->txq, skb); 1940 skb_queue_tail (&ai->txq, skb);
1941 return 0; 1941 return NETDEV_TX_OK;
1942 } 1942 }
1943 1943
1944 spin_lock_irqsave(&ai->aux_lock, flags); 1944 spin_lock_irqsave(&ai->aux_lock, flags);
@@ -1951,7 +1951,7 @@ static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1951 set_bit(FLAG_PENDING_XMIT, &ai->flags); 1951 set_bit(FLAG_PENDING_XMIT, &ai->flags);
1952 mpi_send_packet (dev); 1952 mpi_send_packet (dev);
1953 } 1953 }
1954 return 0; 1954 return NETDEV_TX_OK;
1955} 1955}
1956 1956
1957/* 1957/*
@@ -2127,7 +2127,7 @@ static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
2127 2127
2128 if ( skb == NULL ) { 2128 if ( skb == NULL ) {
2129 airo_print_err(dev->name, "%s: skb == NULL!", __func__); 2129 airo_print_err(dev->name, "%s: skb == NULL!", __func__);
2130 return 0; 2130 return NETDEV_TX_OK;
2131 } 2131 }
2132 2132
2133 /* Find a vacant FID */ 2133 /* Find a vacant FID */
@@ -2155,7 +2155,7 @@ static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
2155 wake_up_interruptible(&priv->thr_wait); 2155 wake_up_interruptible(&priv->thr_wait);
2156 } else 2156 } else
2157 airo_end_xmit(dev); 2157 airo_end_xmit(dev);
2158 return 0; 2158 return NETDEV_TX_OK;
2159} 2159}
2160 2160
2161static void airo_end_xmit11(struct net_device *dev) { 2161static void airo_end_xmit11(struct net_device *dev) {
@@ -2199,7 +2199,7 @@ static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
2199 2199
2200 if ( skb == NULL ) { 2200 if ( skb == NULL ) {
2201 airo_print_err(dev->name, "%s: skb == NULL!", __func__); 2201 airo_print_err(dev->name, "%s: skb == NULL!", __func__);
2202 return 0; 2202 return NETDEV_TX_OK;
2203 } 2203 }
2204 2204
2205 /* Find a vacant FID */ 2205 /* Find a vacant FID */
@@ -2227,7 +2227,7 @@ static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
2227 wake_up_interruptible(&priv->thr_wait); 2227 wake_up_interruptible(&priv->thr_wait);
2228 } else 2228 } else
2229 airo_end_xmit11(dev); 2229 airo_end_xmit11(dev);
2230 return 0; 2230 return NETDEV_TX_OK;
2231} 2231}
2232 2232
2233static void airo_read_stats(struct net_device *dev) 2233static void airo_read_stats(struct net_device *dev)
diff --git a/drivers/net/wireless/arlan-main.c b/drivers/net/wireless/arlan-main.c
index d84caf198a23..d479f4735aaa 100644
--- a/drivers/net/wireless/arlan-main.c
+++ b/drivers/net/wireless/arlan-main.c
@@ -1193,7 +1193,7 @@ static int arlan_tx(struct sk_buff *skb, struct net_device *dev)
1193 1193
1194 arlan_process_interrupt(dev); 1194 arlan_process_interrupt(dev);
1195 ARLAN_DEBUG_EXIT("arlan_tx"); 1195 ARLAN_DEBUG_EXIT("arlan_tx");
1196 return 0; 1196 return NETDEV_TX_OK;
1197 1197
1198bad_end: 1198bad_end:
1199 arlan_process_interrupt(dev); 1199 arlan_process_interrupt(dev);
diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
index 4efbdbe6d6bf..13303fa34734 100644
--- a/drivers/net/wireless/at76c50x-usb.c
+++ b/drivers/net/wireless/at76c50x-usb.c
@@ -1568,7 +1568,8 @@ static void at76_rx_tasklet(unsigned long param)
1568 1568
1569 at76_dbg(DBG_MAC80211, "calling ieee80211_rx_irqsafe(): %d/%d", 1569 at76_dbg(DBG_MAC80211, "calling ieee80211_rx_irqsafe(): %d/%d",
1570 priv->rx_skb->len, priv->rx_skb->data_len); 1570 priv->rx_skb->len, priv->rx_skb->data_len);
1571 ieee80211_rx_irqsafe(priv->hw, priv->rx_skb, &rx_status); 1571 memcpy(IEEE80211_SKB_RXCB(priv->rx_skb), &rx_status, sizeof(rx_status));
1572 ieee80211_rx_irqsafe(priv->hw, priv->rx_skb);
1572 1573
1573 /* Use a new skb for the next receive */ 1574 /* Use a new skb for the next receive */
1574 priv->rx_skb = NULL; 1575 priv->rx_skb = NULL;
diff --git a/drivers/net/wireless/ath/ar9170/main.c b/drivers/net/wireless/ath/ar9170/main.c
index 9d38cf60a0db..51753ed1b8ba 100644
--- a/drivers/net/wireless/ath/ar9170/main.c
+++ b/drivers/net/wireless/ath/ar9170/main.c
@@ -917,8 +917,10 @@ static void ar9170_handle_mpdu(struct ar9170 *ar, u8 *buf, int len)
917 ar9170_rx_phy_status(ar, phy, &status); 917 ar9170_rx_phy_status(ar, phy, &status);
918 918
919 skb = ar9170_rx_copy_data(buf, mpdu_len); 919 skb = ar9170_rx_copy_data(buf, mpdu_len);
920 if (likely(skb)) 920 if (likely(skb)) {
921 ieee80211_rx_irqsafe(ar->hw, skb, &status); 921 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
922 ieee80211_rx_irqsafe(ar->hw, skb);
923 }
922} 924}
923 925
924void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb) 926void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb)
diff --git a/drivers/net/wireless/ath/ar9170/usb.c b/drivers/net/wireless/ath/ar9170/usb.c
index 754b1f8d8da9..1aec7afdffa7 100644
--- a/drivers/net/wireless/ath/ar9170/usb.c
+++ b/drivers/net/wireless/ath/ar9170/usb.c
@@ -779,7 +779,7 @@ static int ar9170_usb_probe(struct usb_interface *intf,
779 aru->req_one_stage_fw = ar9170_requires_one_stage(id); 779 aru->req_one_stage_fw = ar9170_requires_one_stage(id);
780 780
781 usb_set_intfdata(intf, aru); 781 usb_set_intfdata(intf, aru);
782 SET_IEEE80211_DEV(ar->hw, &udev->dev); 782 SET_IEEE80211_DEV(ar->hw, &intf->dev);
783 783
784 init_usb_anchor(&aru->rx_submitted); 784 init_usb_anchor(&aru->rx_submitted);
785 init_usb_anchor(&aru->tx_pending); 785 init_usb_anchor(&aru->tx_pending);
diff --git a/drivers/net/wireless/ath/ath5k/ath5k.h b/drivers/net/wireless/ath/ath5k/ath5k.h
index 6358233bac99..91375113916b 100644
--- a/drivers/net/wireless/ath/ath5k/ath5k.h
+++ b/drivers/net/wireless/ath/ath5k/ath5k.h
@@ -713,8 +713,8 @@ struct ath5k_gain {
713 * Used internaly for reset_tx_queue). 713 * Used internaly for reset_tx_queue).
714 * Also see struct struct ieee80211_channel. 714 * Also see struct struct ieee80211_channel.
715 */ 715 */
716#define IS_CHAN_XR(_c) ((_c.hw_value & CHANNEL_XR) != 0) 716#define IS_CHAN_XR(_c) ((_c->hw_value & CHANNEL_XR) != 0)
717#define IS_CHAN_B(_c) ((_c.hw_value & CHANNEL_B) != 0) 717#define IS_CHAN_B(_c) ((_c->hw_value & CHANNEL_B) != 0)
718 718
719/* 719/*
720 * The following structure is used to map 2GHz channels to 720 * The following structure is used to map 2GHz channels to
@@ -1029,14 +1029,15 @@ struct ath5k_hw {
1029 enum ath5k_int ah_imr; 1029 enum ath5k_int ah_imr;
1030 1030
1031 enum nl80211_iftype ah_op_mode; 1031 enum nl80211_iftype ah_op_mode;
1032 enum ath5k_power_mode ah_power_mode; 1032 struct ieee80211_channel *ah_current_channel;
1033 struct ieee80211_channel ah_current_channel;
1034 bool ah_turbo; 1033 bool ah_turbo;
1035 bool ah_calibration; 1034 bool ah_calibration;
1036 bool ah_running;
1037 bool ah_single_chip; 1035 bool ah_single_chip;
1038 bool ah_combined_mic; 1036 bool ah_combined_mic;
1039 1037
1038 enum ath5k_version ah_version;
1039 enum ath5k_radio ah_radio;
1040 u32 ah_phy;
1040 u32 ah_mac_srev; 1041 u32 ah_mac_srev;
1041 u16 ah_mac_version; 1042 u16 ah_mac_version;
1042 u16 ah_mac_revision; 1043 u16 ah_mac_revision;
@@ -1044,13 +1045,6 @@ struct ath5k_hw {
1044 u16 ah_radio_5ghz_revision; 1045 u16 ah_radio_5ghz_revision;
1045 u16 ah_radio_2ghz_revision; 1046 u16 ah_radio_2ghz_revision;
1046 1047
1047 enum ath5k_version ah_version;
1048 enum ath5k_radio ah_radio;
1049 u32 ah_phy;
1050
1051 bool ah_5ghz;
1052 bool ah_2ghz;
1053
1054#define ah_modes ah_capabilities.cap_mode 1048#define ah_modes ah_capabilities.cap_mode
1055#define ah_ee_version ah_capabilities.cap_eeprom.ee_version 1049#define ah_ee_version ah_capabilities.cap_eeprom.ee_version
1056 1050
@@ -1058,7 +1052,6 @@ struct ath5k_hw {
1058 u32 ah_aifs; 1052 u32 ah_aifs;
1059 u32 ah_cw_min; 1053 u32 ah_cw_min;
1060 u32 ah_cw_max; 1054 u32 ah_cw_max;
1061 bool ah_software_retry;
1062 u32 ah_limit_tx_retries; 1055 u32 ah_limit_tx_retries;
1063 1056
1064 /* Antenna Control */ 1057 /* Antenna Control */
@@ -1066,6 +1059,7 @@ struct ath5k_hw {
1066 u8 ah_ant_mode; 1059 u8 ah_ant_mode;
1067 u8 ah_tx_ant; 1060 u8 ah_tx_ant;
1068 u8 ah_def_ant; 1061 u8 ah_def_ant;
1062 bool ah_software_retry;
1069 1063
1070 u8 ah_sta_id[ETH_ALEN]; 1064 u8 ah_sta_id[ETH_ALEN];
1071 1065
@@ -1075,7 +1069,6 @@ struct ath5k_hw {
1075 u8 ah_bssid[ETH_ALEN]; 1069 u8 ah_bssid[ETH_ALEN];
1076 u8 ah_bssid_mask[ETH_ALEN]; 1070 u8 ah_bssid_mask[ETH_ALEN];
1077 1071
1078 u32 ah_gpio[AR5K_MAX_GPIO];
1079 int ah_gpio_npins; 1072 int ah_gpio_npins;
1080 1073
1081 struct ath_regulatory ah_regulatory; 1074 struct ath_regulatory ah_regulatory;
diff --git a/drivers/net/wireless/ath/ath5k/attach.c b/drivers/net/wireless/ath/ath5k/attach.c
index c41ef58393e7..9a84d9410b27 100644
--- a/drivers/net/wireless/ath/ath5k/attach.c
+++ b/drivers/net/wireless/ath/ath5k/attach.c
@@ -319,6 +319,9 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
319 319
320 ath5k_hw_rfgain_opt_init(ah); 320 ath5k_hw_rfgain_opt_init(ah);
321 321
322 /* turn on HW LEDs */
323 ath5k_hw_set_ledstate(ah, AR5K_LED_INIT);
324
322 return ah; 325 return ah;
323err_free: 326err_free:
324 kfree(ah); 327 kfree(ah);
diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
index ea045151f953..20ba6fa5f1f1 100644
--- a/drivers/net/wireless/ath/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -218,6 +218,8 @@ static struct pci_driver ath5k_pci_driver = {
218 * Prototypes - MAC 802.11 stack related functions 218 * Prototypes - MAC 802.11 stack related functions
219 */ 219 */
220static int ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb); 220static int ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
221static int ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb,
222 struct ath5k_txq *txq);
221static int ath5k_reset(struct ath5k_softc *sc, struct ieee80211_channel *chan); 223static int ath5k_reset(struct ath5k_softc *sc, struct ieee80211_channel *chan);
222static int ath5k_reset_wake(struct ath5k_softc *sc); 224static int ath5k_reset_wake(struct ath5k_softc *sc);
223static int ath5k_start(struct ieee80211_hw *hw); 225static int ath5k_start(struct ieee80211_hw *hw);
@@ -248,6 +250,8 @@ static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
248 struct ieee80211_vif *vif, 250 struct ieee80211_vif *vif,
249 struct ieee80211_bss_conf *bss_conf, 251 struct ieee80211_bss_conf *bss_conf,
250 u32 changes); 252 u32 changes);
253static void ath5k_sw_scan_start(struct ieee80211_hw *hw);
254static void ath5k_sw_scan_complete(struct ieee80211_hw *hw);
251 255
252static const struct ieee80211_ops ath5k_hw_ops = { 256static const struct ieee80211_ops ath5k_hw_ops = {
253 .tx = ath5k_tx, 257 .tx = ath5k_tx,
@@ -265,6 +269,8 @@ static const struct ieee80211_ops ath5k_hw_ops = {
265 .set_tsf = ath5k_set_tsf, 269 .set_tsf = ath5k_set_tsf,
266 .reset_tsf = ath5k_reset_tsf, 270 .reset_tsf = ath5k_reset_tsf,
267 .bss_info_changed = ath5k_bss_info_changed, 271 .bss_info_changed = ath5k_bss_info_changed,
272 .sw_scan_start = ath5k_sw_scan_start,
273 .sw_scan_complete = ath5k_sw_scan_complete,
268}; 274};
269 275
270/* 276/*
@@ -297,7 +303,8 @@ static void ath5k_desc_free(struct ath5k_softc *sc,
297static int ath5k_rxbuf_setup(struct ath5k_softc *sc, 303static int ath5k_rxbuf_setup(struct ath5k_softc *sc,
298 struct ath5k_buf *bf); 304 struct ath5k_buf *bf);
299static int ath5k_txbuf_setup(struct ath5k_softc *sc, 305static int ath5k_txbuf_setup(struct ath5k_softc *sc,
300 struct ath5k_buf *bf); 306 struct ath5k_buf *bf,
307 struct ath5k_txq *txq);
301static inline void ath5k_txbuf_free(struct ath5k_softc *sc, 308static inline void ath5k_txbuf_free(struct ath5k_softc *sc,
302 struct ath5k_buf *bf) 309 struct ath5k_buf *bf)
303{ 310{
@@ -512,6 +519,7 @@ ath5k_pci_probe(struct pci_dev *pdev,
512 /* Initialize driver private data */ 519 /* Initialize driver private data */
513 SET_IEEE80211_DEV(hw, &pdev->dev); 520 SET_IEEE80211_DEV(hw, &pdev->dev);
514 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | 521 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
522 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
515 IEEE80211_HW_SIGNAL_DBM | 523 IEEE80211_HW_SIGNAL_DBM |
516 IEEE80211_HW_NOISE_DBM; 524 IEEE80211_HW_NOISE_DBM;
517 525
@@ -666,7 +674,6 @@ ath5k_pci_suspend(struct pci_dev *pdev, pm_message_t state)
666 674
667 ath5k_led_off(sc); 675 ath5k_led_off(sc);
668 676
669 free_irq(pdev->irq, sc);
670 pci_save_state(pdev); 677 pci_save_state(pdev);
671 pci_disable_device(pdev); 678 pci_disable_device(pdev);
672 pci_set_power_state(pdev, PCI_D3hot); 679 pci_set_power_state(pdev, PCI_D3hot);
@@ -694,18 +701,8 @@ ath5k_pci_resume(struct pci_dev *pdev)
694 */ 701 */
695 pci_write_config_byte(pdev, 0x41, 0); 702 pci_write_config_byte(pdev, 0x41, 0);
696 703
697 err = request_irq(pdev->irq, ath5k_intr, IRQF_SHARED, "ath", sc);
698 if (err) {
699 ATH5K_ERR(sc, "request_irq failed\n");
700 goto err_no_irq;
701 }
702
703 ath5k_led_enable(sc); 704 ath5k_led_enable(sc);
704 return 0; 705 return 0;
705
706err_no_irq:
707 pci_disable_device(pdev);
708 return err;
709} 706}
710#endif /* CONFIG_PM */ 707#endif /* CONFIG_PM */
711 708
@@ -785,12 +782,18 @@ ath5k_attach(struct pci_dev *pdev, struct ieee80211_hw *hw)
785 goto err_desc; 782 goto err_desc;
786 } 783 }
787 sc->bhalq = ret; 784 sc->bhalq = ret;
785 sc->cabq = ath5k_txq_setup(sc, AR5K_TX_QUEUE_CAB, 0);
786 if (IS_ERR(sc->cabq)) {
787 ATH5K_ERR(sc, "can't setup cab queue\n");
788 ret = PTR_ERR(sc->cabq);
789 goto err_bhal;
790 }
788 791
789 sc->txq = ath5k_txq_setup(sc, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_BK); 792 sc->txq = ath5k_txq_setup(sc, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_BK);
790 if (IS_ERR(sc->txq)) { 793 if (IS_ERR(sc->txq)) {
791 ATH5K_ERR(sc, "can't setup xmit queue\n"); 794 ATH5K_ERR(sc, "can't setup xmit queue\n");
792 ret = PTR_ERR(sc->txq); 795 ret = PTR_ERR(sc->txq);
793 goto err_bhal; 796 goto err_queues;
794 } 797 }
795 798
796 tasklet_init(&sc->rxtq, ath5k_tasklet_rx, (unsigned long)sc); 799 tasklet_init(&sc->rxtq, ath5k_tasklet_rx, (unsigned long)sc);
@@ -1228,10 +1231,10 @@ ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
1228} 1231}
1229 1232
1230static int 1233static int
1231ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf) 1234ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
1235 struct ath5k_txq *txq)
1232{ 1236{
1233 struct ath5k_hw *ah = sc->ah; 1237 struct ath5k_hw *ah = sc->ah;
1234 struct ath5k_txq *txq = sc->txq;
1235 struct ath5k_desc *ds = bf->desc; 1238 struct ath5k_desc *ds = bf->desc;
1236 struct sk_buff *skb = bf->skb; 1239 struct sk_buff *skb = bf->skb;
1237 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1240 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
@@ -1901,7 +1904,8 @@ accept:
1901 if (sc->opmode == NL80211_IFTYPE_ADHOC) 1904 if (sc->opmode == NL80211_IFTYPE_ADHOC)
1902 ath5k_check_ibss_tsf(sc, skb, &rxs); 1905 ath5k_check_ibss_tsf(sc, skb, &rxs);
1903 1906
1904 __ieee80211_rx(sc->hw, skb, &rxs); 1907 memcpy(IEEE80211_SKB_RXCB(skb), &rxs, sizeof(rxs));
1908 ieee80211_rx(sc->hw, skb);
1905 1909
1906 bf->skb = next_skb; 1910 bf->skb = next_skb;
1907 bf->skbaddr = next_skb_addr; 1911 bf->skbaddr = next_skb_addr;
@@ -2078,13 +2082,6 @@ err_unmap:
2078 return ret; 2082 return ret;
2079} 2083}
2080 2084
2081static void ath5k_beacon_disable(struct ath5k_softc *sc)
2082{
2083 sc->imask &= ~(AR5K_INT_BMISS | AR5K_INT_SWBA);
2084 ath5k_hw_set_imr(sc->ah, sc->imask);
2085 ath5k_hw_stop_tx_dma(sc->ah, sc->bhalq);
2086}
2087
2088/* 2085/*
2089 * Transmit a beacon frame at SWBA. Dynamic updates to the 2086 * Transmit a beacon frame at SWBA. Dynamic updates to the
2090 * frame contents are done as needed and the slot time is 2087 * frame contents are done as needed and the slot time is
@@ -2098,6 +2095,7 @@ ath5k_beacon_send(struct ath5k_softc *sc)
2098{ 2095{
2099 struct ath5k_buf *bf = sc->bbuf; 2096 struct ath5k_buf *bf = sc->bbuf;
2100 struct ath5k_hw *ah = sc->ah; 2097 struct ath5k_hw *ah = sc->ah;
2098 struct sk_buff *skb;
2101 2099
2102 ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON, "in beacon_send\n"); 2100 ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON, "in beacon_send\n");
2103 2101
@@ -2151,6 +2149,12 @@ ath5k_beacon_send(struct ath5k_softc *sc)
2151 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, "TXDP[%u] = %llx (%p)\n", 2149 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, "TXDP[%u] = %llx (%p)\n",
2152 sc->bhalq, (unsigned long long)bf->daddr, bf->desc); 2150 sc->bhalq, (unsigned long long)bf->daddr, bf->desc);
2153 2151
2152 skb = ieee80211_get_buffered_bc(sc->hw, sc->vif);
2153 while (skb) {
2154 ath5k_tx_queue(sc->hw, skb, sc->cabq);
2155 skb = ieee80211_get_buffered_bc(sc->hw, sc->vif);
2156 }
2157
2154 sc->bsent++; 2158 sc->bsent++;
2155} 2159}
2156 2160
@@ -2271,13 +2275,11 @@ ath5k_beacon_config(struct ath5k_softc *sc)
2271 struct ath5k_hw *ah = sc->ah; 2275 struct ath5k_hw *ah = sc->ah;
2272 unsigned long flags; 2276 unsigned long flags;
2273 2277
2274 ath5k_hw_set_imr(ah, 0); 2278 spin_lock_irqsave(&sc->block, flags);
2275 sc->bmisscount = 0; 2279 sc->bmisscount = 0;
2276 sc->imask &= ~(AR5K_INT_BMISS | AR5K_INT_SWBA); 2280 sc->imask &= ~(AR5K_INT_BMISS | AR5K_INT_SWBA);
2277 2281
2278 if (sc->opmode == NL80211_IFTYPE_ADHOC || 2282 if (sc->enable_beacon) {
2279 sc->opmode == NL80211_IFTYPE_MESH_POINT ||
2280 sc->opmode == NL80211_IFTYPE_AP) {
2281 /* 2283 /*
2282 * In IBSS mode we use a self-linked tx descriptor and let the 2284 * In IBSS mode we use a self-linked tx descriptor and let the
2283 * hardware send the beacons automatically. We have to load it 2285 * hardware send the beacons automatically. We have to load it
@@ -2290,16 +2292,17 @@ ath5k_beacon_config(struct ath5k_softc *sc)
2290 sc->imask |= AR5K_INT_SWBA; 2292 sc->imask |= AR5K_INT_SWBA;
2291 2293
2292 if (sc->opmode == NL80211_IFTYPE_ADHOC) { 2294 if (sc->opmode == NL80211_IFTYPE_ADHOC) {
2293 if (ath5k_hw_hasveol(ah)) { 2295 if (ath5k_hw_hasveol(ah))
2294 spin_lock_irqsave(&sc->block, flags);
2295 ath5k_beacon_send(sc); 2296 ath5k_beacon_send(sc);
2296 spin_unlock_irqrestore(&sc->block, flags);
2297 }
2298 } else 2297 } else
2299 ath5k_beacon_update_timers(sc, -1); 2298 ath5k_beacon_update_timers(sc, -1);
2299 } else {
2300 ath5k_hw_stop_tx_dma(sc->ah, sc->bhalq);
2300 } 2301 }
2301 2302
2302 ath5k_hw_set_imr(ah, sc->imask); 2303 ath5k_hw_set_imr(ah, sc->imask);
2304 mmiowb();
2305 spin_unlock_irqrestore(&sc->block, flags);
2303} 2306}
2304 2307
2305static void ath5k_tasklet_beacon(unsigned long data) 2308static void ath5k_tasklet_beacon(unsigned long data)
@@ -2598,6 +2601,14 @@ static int
2598ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 2601ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2599{ 2602{
2600 struct ath5k_softc *sc = hw->priv; 2603 struct ath5k_softc *sc = hw->priv;
2604
2605 return ath5k_tx_queue(hw, skb, sc->txq);
2606}
2607
2608static int ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb,
2609 struct ath5k_txq *txq)
2610{
2611 struct ath5k_softc *sc = hw->priv;
2601 struct ath5k_buf *bf; 2612 struct ath5k_buf *bf;
2602 unsigned long flags; 2613 unsigned long flags;
2603 int hdrlen; 2614 int hdrlen;
@@ -2641,7 +2652,7 @@ ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2641 2652
2642 bf->skb = skb; 2653 bf->skb = skb;
2643 2654
2644 if (ath5k_txbuf_setup(sc, bf)) { 2655 if (ath5k_txbuf_setup(sc, bf, txq)) {
2645 bf->skb = NULL; 2656 bf->skb = NULL;
2646 spin_lock_irqsave(&sc->txbuflock, flags); 2657 spin_lock_irqsave(&sc->txbuflock, flags);
2647 list_add_tail(&bf->list, &sc->txbuf); 2658 list_add_tail(&bf->list, &sc->txbuf);
@@ -2676,7 +2687,7 @@ ath5k_reset(struct ath5k_softc *sc, struct ieee80211_channel *chan)
2676 sc->curchan = chan; 2687 sc->curchan = chan;
2677 sc->curband = &sc->sbands[chan->band]; 2688 sc->curband = &sc->sbands[chan->band];
2678 } 2689 }
2679 ret = ath5k_hw_reset(ah, sc->opmode, sc->curchan, true); 2690 ret = ath5k_hw_reset(ah, sc->opmode, sc->curchan, chan != NULL);
2680 if (ret) { 2691 if (ret) {
2681 ATH5K_ERR(sc, "can't reset hardware (%d)\n", ret); 2692 ATH5K_ERR(sc, "can't reset hardware (%d)\n", ret);
2682 goto err; 2693 goto err;
@@ -2776,7 +2787,6 @@ ath5k_remove_interface(struct ieee80211_hw *hw,
2776 goto end; 2787 goto end;
2777 2788
2778 ath5k_hw_set_lladdr(sc->ah, mac); 2789 ath5k_hw_set_lladdr(sc->ah, mac);
2779 ath5k_beacon_disable(sc);
2780 sc->vif = NULL; 2790 sc->vif = NULL;
2781end: 2791end:
2782 mutex_unlock(&sc->lock); 2792 mutex_unlock(&sc->lock);
@@ -3105,25 +3115,6 @@ out:
3105 return ret; 3115 return ret;
3106} 3116}
3107 3117
3108/*
3109 * Update the beacon and reconfigure the beacon queues.
3110 */
3111static void
3112ath5k_beacon_reconfig(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
3113{
3114 int ret;
3115 unsigned long flags;
3116 struct ath5k_softc *sc = hw->priv;
3117
3118 spin_lock_irqsave(&sc->block, flags);
3119 ret = ath5k_beacon_update(hw, vif);
3120 spin_unlock_irqrestore(&sc->block, flags);
3121 if (ret == 0) {
3122 ath5k_beacon_config(sc);
3123 mmiowb();
3124 }
3125}
3126
3127static void 3118static void
3128set_beacon_filter(struct ieee80211_hw *hw, bool enable) 3119set_beacon_filter(struct ieee80211_hw *hw, bool enable)
3129{ 3120{
@@ -3146,6 +3137,7 @@ static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
3146{ 3137{
3147 struct ath5k_softc *sc = hw->priv; 3138 struct ath5k_softc *sc = hw->priv;
3148 struct ath5k_hw *ah = sc->ah; 3139 struct ath5k_hw *ah = sc->ah;
3140 unsigned long flags;
3149 3141
3150 mutex_lock(&sc->lock); 3142 mutex_lock(&sc->lock);
3151 if (WARN_ON(sc->vif != vif)) 3143 if (WARN_ON(sc->vif != vif))
@@ -3167,15 +3159,37 @@ static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
3167 sc->assoc = bss_conf->assoc; 3159 sc->assoc = bss_conf->assoc;
3168 if (sc->opmode == NL80211_IFTYPE_STATION) 3160 if (sc->opmode == NL80211_IFTYPE_STATION)
3169 set_beacon_filter(hw, sc->assoc); 3161 set_beacon_filter(hw, sc->assoc);
3162 ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
3163 AR5K_LED_ASSOC : AR5K_LED_INIT);
3170 } 3164 }
3171 3165
3172 if (changes & BSS_CHANGED_BEACON && 3166 if (changes & BSS_CHANGED_BEACON) {
3173 (vif->type == NL80211_IFTYPE_ADHOC || 3167 spin_lock_irqsave(&sc->block, flags);
3174 vif->type == NL80211_IFTYPE_MESH_POINT || 3168 ath5k_beacon_update(hw, vif);
3175 vif->type == NL80211_IFTYPE_AP)) { 3169 spin_unlock_irqrestore(&sc->block, flags);
3176 ath5k_beacon_reconfig(hw, vif);
3177 } 3170 }
3178 3171
3172 if (changes & BSS_CHANGED_BEACON_ENABLED)
3173 sc->enable_beacon = bss_conf->enable_beacon;
3174
3175 if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
3176 BSS_CHANGED_BEACON_INT))
3177 ath5k_beacon_config(sc);
3178
3179 unlock: 3179 unlock:
3180 mutex_unlock(&sc->lock); 3180 mutex_unlock(&sc->lock);
3181} 3181}
3182
3183static void ath5k_sw_scan_start(struct ieee80211_hw *hw)
3184{
3185 struct ath5k_softc *sc = hw->priv;
3186 if (!sc->assoc)
3187 ath5k_hw_set_ledstate(sc->ah, AR5K_LED_SCAN);
3188}
3189
3190static void ath5k_sw_scan_complete(struct ieee80211_hw *hw)
3191{
3192 struct ath5k_softc *sc = hw->priv;
3193 ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
3194 AR5K_LED_ASSOC : AR5K_LED_INIT);
3195}
diff --git a/drivers/net/wireless/ath/ath5k/base.h b/drivers/net/wireless/ath/ath5k/base.h
index f9b7f2f819b7..778e422946ab 100644
--- a/drivers/net/wireless/ath/ath5k/base.h
+++ b/drivers/net/wireless/ath/ath5k/base.h
@@ -114,8 +114,7 @@ struct ath5k_softc {
114 struct pci_dev *pdev; /* for dma mapping */ 114 struct pci_dev *pdev; /* for dma mapping */
115 void __iomem *iobase; /* address of the device */ 115 void __iomem *iobase; /* address of the device */
116 struct mutex lock; /* dev-level lock */ 116 struct mutex lock; /* dev-level lock */
117 /* FIXME: how many does it really need? */ 117 struct ieee80211_tx_queue_stats tx_stats[AR5K_NUM_TX_QUEUES];
118 struct ieee80211_tx_queue_stats tx_stats[16];
119 struct ieee80211_low_level_stats ll_stats; 118 struct ieee80211_low_level_stats ll_stats;
120 struct ieee80211_hw *hw; /* IEEE 802.11 common */ 119 struct ieee80211_hw *hw; /* IEEE 802.11 common */
121 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS]; 120 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
@@ -171,9 +170,8 @@ struct ath5k_softc {
171 struct list_head txbuf; /* transmit buffer */ 170 struct list_head txbuf; /* transmit buffer */
172 spinlock_t txbuflock; 171 spinlock_t txbuflock;
173 unsigned int txbuf_len; /* buf count in txbuf list */ 172 unsigned int txbuf_len; /* buf count in txbuf list */
174 struct ath5k_txq txqs[2]; /* beacon and tx */ 173 struct ath5k_txq txqs[AR5K_NUM_TX_QUEUES]; /* tx queues */
175 174 struct ath5k_txq *txq; /* main tx queue */
176 struct ath5k_txq *txq; /* beacon and tx*/
177 struct tasklet_struct txtq; /* tx intr tasklet */ 175 struct tasklet_struct txtq; /* tx intr tasklet */
178 struct ath5k_led tx_led; /* tx led */ 176 struct ath5k_led tx_led; /* tx led */
179 177
@@ -187,10 +185,12 @@ struct ath5k_softc {
187 bintval, /* beacon interval in TU */ 185 bintval, /* beacon interval in TU */
188 bsent; 186 bsent;
189 unsigned int nexttbtt; /* next beacon time in TU */ 187 unsigned int nexttbtt; /* next beacon time in TU */
188 struct ath5k_txq *cabq; /* content after beacon */
190 189
191 struct timer_list calib_tim; /* calibration timer */ 190 struct timer_list calib_tim; /* calibration timer */
192 int power_level; /* Requested tx power in dbm */ 191 int power_level; /* Requested tx power in dbm */
193 bool assoc; /* assocate state */ 192 bool assoc; /* assocate state */
193 bool enable_beacon; /* true if beacons are on */
194}; 194};
195 195
196#define ath5k_hw_hasbssidmask(_ah) \ 196#define ath5k_hw_hasbssidmask(_ah) \
diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
index 4904a07e4b59..747508c15d34 100644
--- a/drivers/net/wireless/ath/ath5k/debug.c
+++ b/drivers/net/wireless/ath/ath5k/debug.c
@@ -380,13 +380,15 @@ ath5k_debug_init_device(struct ath5k_softc *sc)
380 sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy), 380 sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
381 ath5k_global_debugfs); 381 ath5k_global_debugfs);
382 382
383 sc->debug.debugfs_debug = debugfs_create_file("debug", S_IWUSR | S_IRUGO, 383 sc->debug.debugfs_debug = debugfs_create_file("debug",
384 S_IWUSR | S_IRUSR,
384 sc->debug.debugfs_phydir, sc, &fops_debug); 385 sc->debug.debugfs_phydir, sc, &fops_debug);
385 386
386 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUGO, 387 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
387 sc->debug.debugfs_phydir, sc, &fops_registers); 388 sc->debug.debugfs_phydir, sc, &fops_registers);
388 389
389 sc->debug.debugfs_beacon = debugfs_create_file("beacon", S_IWUSR | S_IRUGO, 390 sc->debug.debugfs_beacon = debugfs_create_file("beacon",
391 S_IWUSR | S_IRUSR,
390 sc->debug.debugfs_phydir, sc, &fops_beacon); 392 sc->debug.debugfs_phydir, sc, &fops_beacon);
391 393
392 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR, 394 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
diff --git a/drivers/net/wireless/ath/ath5k/phy.c b/drivers/net/wireless/ath/ath5k/phy.c
index a876ca8d69ef..2075ba993966 100644
--- a/drivers/net/wireless/ath/ath5k/phy.c
+++ b/drivers/net/wireless/ath/ath5k/phy.c
@@ -1085,8 +1085,7 @@ int ath5k_hw_channel(struct ath5k_hw *ah, struct ieee80211_channel *channel)
1085 AR5K_PHY_CCKTXCTL_WORLD); 1085 AR5K_PHY_CCKTXCTL_WORLD);
1086 } 1086 }
1087 1087
1088 ah->ah_current_channel.center_freq = channel->center_freq; 1088 ah->ah_current_channel = channel;
1089 ah->ah_current_channel.hw_value = channel->hw_value;
1090 ah->ah_turbo = channel->hw_value == CHANNEL_T ? true : false; 1089 ah->ah_turbo = channel->hw_value == CHANNEL_T ? true : false;
1091 1090
1092 return 0; 1091 return 0;
@@ -1731,7 +1730,7 @@ ath5k_hw_set_fast_div(struct ath5k_hw *ah, u8 ee_mode, bool enable)
1731void 1730void
1732ath5k_hw_set_antenna_mode(struct ath5k_hw *ah, u8 ant_mode) 1731ath5k_hw_set_antenna_mode(struct ath5k_hw *ah, u8 ant_mode)
1733{ 1732{
1734 struct ieee80211_channel *channel = &ah->ah_current_channel; 1733 struct ieee80211_channel *channel = ah->ah_current_channel;
1735 bool use_def_for_tx, update_def_on_tx, use_def_for_rts, fast_div; 1734 bool use_def_for_tx, update_def_on_tx, use_def_for_rts, fast_div;
1736 bool use_def_for_sg; 1735 bool use_def_for_sg;
1737 u8 def_ant, tx_ant, ee_mode; 1736 u8 def_ant, tx_ant, ee_mode;
@@ -3011,7 +3010,7 @@ ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel,
3011int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 txpower) 3010int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 txpower)
3012{ 3011{
3013 /*Just a try M.F.*/ 3012 /*Just a try M.F.*/
3014 struct ieee80211_channel *channel = &ah->ah_current_channel; 3013 struct ieee80211_channel *channel = ah->ah_current_channel;
3015 u8 ee_mode; 3014 u8 ee_mode;
3016 3015
3017 ATH5K_TRACE(ah->ah_sc); 3016 ATH5K_TRACE(ah->ah_sc);
diff --git a/drivers/net/wireless/ath/ath5k/qcu.c b/drivers/net/wireless/ath/ath5k/qcu.c
index 73407b3f53ef..6d5aaf00d8bb 100644
--- a/drivers/net/wireless/ath/ath5k/qcu.c
+++ b/drivers/net/wireless/ath/ath5k/qcu.c
@@ -411,7 +411,6 @@ int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
411 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue), 411 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
412 AR5K_QCU_MISC_FRSHED_BCN_SENT_GT | 412 AR5K_QCU_MISC_FRSHED_BCN_SENT_GT |
413 AR5K_QCU_MISC_CBREXP_DIS | 413 AR5K_QCU_MISC_CBREXP_DIS |
414 AR5K_QCU_MISC_RDY_VEOL_POLICY |
415 AR5K_QCU_MISC_CBREXP_BCN_DIS); 414 AR5K_QCU_MISC_CBREXP_BCN_DIS);
416 415
417 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL - 416 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
diff --git a/drivers/net/wireless/ath/ath5k/reset.c b/drivers/net/wireless/ath/ath5k/reset.c
index bd0a97a38d34..86733fdb4774 100644
--- a/drivers/net/wireless/ath/ath5k/reset.c
+++ b/drivers/net/wireless/ath/ath5k/reset.c
@@ -290,7 +290,6 @@ int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
290 } 290 }
291 291
292commit: 292commit:
293 ah->ah_power_mode = mode;
294 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1); 293 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
295 294
296 return 0; 295 return 0;
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index 5efc9345ca0d..eb9d5228cb6c 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -272,7 +272,6 @@ struct ath_atx_tid {
272 int sched; 272 int sched;
273 int paused; 273 int paused;
274 u8 state; 274 u8 state;
275 int addba_exchangeattempts;
276}; 275};
277 276
278struct ath_atx_ac { 277struct ath_atx_ac {
@@ -541,6 +540,7 @@ struct ath_softc {
541 int irq; 540 int irq;
542 spinlock_t sc_resetlock; 541 spinlock_t sc_resetlock;
543 spinlock_t sc_serial_rw; 542 spinlock_t sc_serial_rw;
543 spinlock_t ani_lock;
544 struct mutex mutex; 544 struct mutex mutex;
545 545
546 u8 curbssid[ETH_ALEN]; 546 u8 curbssid[ETH_ALEN];
diff --git a/drivers/net/wireless/ath/ath9k/beacon.c b/drivers/net/wireless/ath/ath9k/beacon.c
index 3639a2e6987d..45c4ea57616b 100644
--- a/drivers/net/wireless/ath/ath9k/beacon.c
+++ b/drivers/net/wireless/ath/ath9k/beacon.c
@@ -674,13 +674,6 @@ static void ath_beacon_config_adhoc(struct ath_softc *sc,
674 674
675 intval = conf->beacon_interval & ATH9K_BEACON_PERIOD; 675 intval = conf->beacon_interval & ATH9K_BEACON_PERIOD;
676 676
677 /*
678 * It looks like mac80211 may end up using beacon interval of zero in
679 * some cases (at least for mesh point). Avoid getting into an
680 * infinite loop by using a bit safer value instead..
681 */
682 if (intval == 0)
683 intval = 100;
684 677
685 /* Pull nexttbtt forward to reflect the current TSF */ 678 /* Pull nexttbtt forward to reflect the current TSF */
686 679
@@ -745,6 +738,14 @@ void ath_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif)
745 iftype = sc->sc_ah->opmode; 738 iftype = sc->sc_ah->opmode;
746 } 739 }
747 740
741 /*
742 * It looks like mac80211 may end up using beacon interval of zero in
743 * some cases (at least for mesh point). Avoid getting into an
744 * infinite loop by using a bit safer value instead. To be safe,
745 * do sanity check on beacon interval for all operating modes.
746 */
747 if (cur_conf->beacon_interval == 0)
748 cur_conf->beacon_interval = 100;
748 749
749 switch (iftype) { 750 switch (iftype) {
750 case NL80211_IFTYPE_AP: 751 case NL80211_IFTYPE_AP:
diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index 6d20725d6451..9f99f00c1447 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -500,31 +500,31 @@ int ath9k_init_debug(struct ath_softc *sc)
500 goto err; 500 goto err;
501 501
502 sc->debug.debugfs_debug = debugfs_create_file("debug", 502 sc->debug.debugfs_debug = debugfs_create_file("debug",
503 S_IRUGO | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug); 503 S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug);
504 if (!sc->debug.debugfs_debug) 504 if (!sc->debug.debugfs_debug)
505 goto err; 505 goto err;
506 506
507 sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUGO, 507 sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR,
508 sc->debug.debugfs_phy, sc, &fops_dma); 508 sc->debug.debugfs_phy, sc, &fops_dma);
509 if (!sc->debug.debugfs_dma) 509 if (!sc->debug.debugfs_dma)
510 goto err; 510 goto err;
511 511
512 sc->debug.debugfs_interrupt = debugfs_create_file("interrupt", 512 sc->debug.debugfs_interrupt = debugfs_create_file("interrupt",
513 S_IRUGO, 513 S_IRUSR,
514 sc->debug.debugfs_phy, 514 sc->debug.debugfs_phy,
515 sc, &fops_interrupt); 515 sc, &fops_interrupt);
516 if (!sc->debug.debugfs_interrupt) 516 if (!sc->debug.debugfs_interrupt)
517 goto err; 517 goto err;
518 518
519 sc->debug.debugfs_rcstat = debugfs_create_file("rcstat", 519 sc->debug.debugfs_rcstat = debugfs_create_file("rcstat",
520 S_IRUGO, 520 S_IRUSR,
521 sc->debug.debugfs_phy, 521 sc->debug.debugfs_phy,
522 sc, &fops_rcstat); 522 sc, &fops_rcstat);
523 if (!sc->debug.debugfs_rcstat) 523 if (!sc->debug.debugfs_rcstat)
524 goto err; 524 goto err;
525 525
526 sc->debug.debugfs_wiphy = debugfs_create_file( 526 sc->debug.debugfs_wiphy = debugfs_create_file(
527 "wiphy", S_IRUGO | S_IWUSR, sc->debug.debugfs_phy, sc, 527 "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
528 &fops_wiphy); 528 &fops_wiphy);
529 if (!sc->debug.debugfs_wiphy) 529 if (!sc->debug.debugfs_wiphy)
530 goto err; 530 goto err;
diff --git a/drivers/net/wireless/ath/ath9k/eeprom.c b/drivers/net/wireless/ath/ath9k/eeprom.c
index a2fda702b620..d82a0f97e6f5 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom.c
@@ -2516,10 +2516,8 @@ static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
2516 targetPowerCck.tPow2x[1]; 2516 targetPowerCck.tPow2x[1];
2517 ratesArray[rate5_5s] = ratesArray[rate5_5l] = 2517 ratesArray[rate5_5s] = ratesArray[rate5_5l] =
2518 targetPowerCck.tPow2x[2]; 2518 targetPowerCck.tPow2x[2];
2519 ;
2520 ratesArray[rate11s] = ratesArray[rate11l] = 2519 ratesArray[rate11s] = ratesArray[rate11l] =
2521 targetPowerCck.tPow2x[3]; 2520 targetPowerCck.tPow2x[3];
2522 ;
2523 } 2521 }
2524 if (IS_CHAN_HT40(chan)) { 2522 if (IS_CHAN_HT40(chan)) {
2525 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) { 2523 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 34935a8ee59d..cffb0789f669 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -2345,7 +2345,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
2345 ath9k_hw_init_bb(ah, chan); 2345 ath9k_hw_init_bb(ah, chan);
2346 2346
2347 if (!ath9k_hw_init_cal(ah, chan)) 2347 if (!ath9k_hw_init_cal(ah, chan))
2348 return -EIO;; 2348 return -EIO;
2349 2349
2350 rx_chainmask = ah->rxchainmask; 2350 rx_chainmask = ah->rxchainmask;
2351 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) { 2351 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 66a6c1f5022a..961b0ce6ef3e 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -342,6 +342,7 @@ static void ath_ani_calibrate(unsigned long data)
342 * don't calibrate when we're scanning. 342 * don't calibrate when we're scanning.
343 * we are most likely not on our home channel. 343 * we are most likely not on our home channel.
344 */ 344 */
345 spin_lock(&sc->ani_lock);
345 if (sc->sc_flags & SC_OP_SCANNING) 346 if (sc->sc_flags & SC_OP_SCANNING)
346 goto set_timer; 347 goto set_timer;
347 348
@@ -405,6 +406,7 @@ static void ath_ani_calibrate(unsigned long data)
405 ath9k_ps_restore(sc); 406 ath9k_ps_restore(sc);
406 407
407set_timer: 408set_timer:
409 spin_unlock(&sc->ani_lock);
408 /* 410 /*
409 * Set timer interval based on previous results. 411 * Set timer interval based on previous results.
410 * The interval must be the shortest necessary to satisfy ANI, 412 * The interval must be the shortest necessary to satisfy ANI,
@@ -887,6 +889,7 @@ static void setup_ht_cap(struct ath_softc *sc,
887{ 889{
888#define ATH9K_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */ 890#define ATH9K_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */
889#define ATH9K_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */ 891#define ATH9K_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */
892 u8 tx_streams, rx_streams;
890 893
891 ht_info->ht_supported = true; 894 ht_info->ht_supported = true;
892 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | 895 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
@@ -899,45 +902,43 @@ static void setup_ht_cap(struct ath_softc *sc,
899 902
900 /* set up supported mcs set */ 903 /* set up supported mcs set */
901 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs)); 904 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
905 tx_streams = !(sc->tx_chainmask & (sc->tx_chainmask - 1)) ? 1 : 2;
906 rx_streams = !(sc->rx_chainmask & (sc->rx_chainmask - 1)) ? 1 : 2;
902 907
903 switch(sc->rx_chainmask) { 908 if (tx_streams != rx_streams) {
904 case 1: 909 DPRINTF(sc, ATH_DBG_CONFIG, "TX streams %d, RX streams: %d\n",
905 ht_info->mcs.rx_mask[0] = 0xff; 910 tx_streams, rx_streams);
906 break; 911 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
907 case 3: 912 ht_info->mcs.tx_params |= ((tx_streams - 1) <<
908 case 5: 913 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
909 case 7:
910 default:
911 ht_info->mcs.rx_mask[0] = 0xff;
912 ht_info->mcs.rx_mask[1] = 0xff;
913 break;
914 } 914 }
915 915
916 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; 916 ht_info->mcs.rx_mask[0] = 0xff;
917 if (rx_streams >= 2)
918 ht_info->mcs.rx_mask[1] = 0xff;
919
920 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
917} 921}
918 922
919static void ath9k_bss_assoc_info(struct ath_softc *sc, 923static void ath9k_bss_assoc_info(struct ath_softc *sc,
920 struct ieee80211_vif *vif, 924 struct ieee80211_vif *vif,
921 struct ieee80211_bss_conf *bss_conf) 925 struct ieee80211_bss_conf *bss_conf)
922{ 926{
923 struct ath_vif *avp = (void *)vif->drv_priv;
924 927
925 if (bss_conf->assoc) { 928 if (bss_conf->assoc) {
926 DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info ASSOC %d, bssid: %pM\n", 929 DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
927 bss_conf->aid, sc->curbssid); 930 bss_conf->aid, sc->curbssid);
928 931
929 /* New association, store aid */ 932 /* New association, store aid */
930 if (avp->av_opmode == NL80211_IFTYPE_STATION) { 933 sc->curaid = bss_conf->aid;
931 sc->curaid = bss_conf->aid; 934 ath9k_hw_write_associd(sc);
932 ath9k_hw_write_associd(sc);
933 935
934 /* 936 /*
935 * Request a re-configuration of Beacon related timers 937 * Request a re-configuration of Beacon related timers
936 * on the receipt of the first Beacon frame (i.e., 938 * on the receipt of the first Beacon frame (i.e.,
937 * after time sync with the AP). 939 * after time sync with the AP).
938 */ 940 */
939 sc->sc_flags |= SC_OP_BEACON_SYNC; 941 sc->sc_flags |= SC_OP_BEACON_SYNC;
940 }
941 942
942 /* Configure the beacon */ 943 /* Configure the beacon */
943 ath_beacon_config(sc, vif); 944 ath_beacon_config(sc, vif);
@@ -952,6 +953,8 @@ static void ath9k_bss_assoc_info(struct ath_softc *sc,
952 } else { 953 } else {
953 DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info DISASSOC\n"); 954 DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
954 sc->curaid = 0; 955 sc->curaid = 0;
956 /* Stop ANI */
957 del_timer_sync(&sc->ani.timer);
955 } 958 }
956} 959}
957 960
@@ -1311,6 +1314,7 @@ static int ath_init(u16 devid, struct ath_softc *sc)
1311 spin_lock_init(&sc->wiphy_lock); 1314 spin_lock_init(&sc->wiphy_lock);
1312 spin_lock_init(&sc->sc_resetlock); 1315 spin_lock_init(&sc->sc_resetlock);
1313 spin_lock_init(&sc->sc_serial_rw); 1316 spin_lock_init(&sc->sc_serial_rw);
1317 spin_lock_init(&sc->ani_lock);
1314 mutex_init(&sc->mutex); 1318 mutex_init(&sc->mutex);
1315 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc); 1319 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
1316 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet, 1320 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
@@ -2196,7 +2200,9 @@ static int ath9k_add_interface(struct ieee80211_hw *hw,
2196 2200
2197 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask); 2201 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
2198 2202
2199 if (conf->type == NL80211_IFTYPE_AP) 2203 if (conf->type == NL80211_IFTYPE_AP ||
2204 conf->type == NL80211_IFTYPE_ADHOC ||
2205 conf->type == NL80211_IFTYPE_MONITOR)
2200 ath_start_ani(sc); 2206 ath_start_ani(sc);
2201 2207
2202out: 2208out:
@@ -2681,9 +2687,9 @@ static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2681 aphy->state = ATH_WIPHY_SCAN; 2687 aphy->state = ATH_WIPHY_SCAN;
2682 ath9k_wiphy_pause_all_forced(sc, aphy); 2688 ath9k_wiphy_pause_all_forced(sc, aphy);
2683 2689
2684 mutex_lock(&sc->mutex); 2690 spin_lock_bh(&sc->ani_lock);
2685 sc->sc_flags |= SC_OP_SCANNING; 2691 sc->sc_flags |= SC_OP_SCANNING;
2686 mutex_unlock(&sc->mutex); 2692 spin_unlock_bh(&sc->ani_lock);
2687} 2693}
2688 2694
2689static void ath9k_sw_scan_complete(struct ieee80211_hw *hw) 2695static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
@@ -2691,11 +2697,11 @@ static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2691 struct ath_wiphy *aphy = hw->priv; 2697 struct ath_wiphy *aphy = hw->priv;
2692 struct ath_softc *sc = aphy->sc; 2698 struct ath_softc *sc = aphy->sc;
2693 2699
2694 mutex_lock(&sc->mutex); 2700 spin_lock_bh(&sc->ani_lock);
2695 aphy->state = ATH_WIPHY_ACTIVE; 2701 aphy->state = ATH_WIPHY_ACTIVE;
2696 sc->sc_flags &= ~SC_OP_SCANNING; 2702 sc->sc_flags &= ~SC_OP_SCANNING;
2697 sc->sc_flags |= SC_OP_FULL_RESET; 2703 sc->sc_flags |= SC_OP_FULL_RESET;
2698 mutex_unlock(&sc->mutex); 2704 spin_unlock_bh(&sc->ani_lock);
2699} 2705}
2700 2706
2701struct ieee80211_ops ath9k_ops = { 2707struct ieee80211_ops ath9k_ops = {
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index cece1c4c6bda..b3da81db453b 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -236,10 +236,31 @@ static int ath_rx_prepare(struct sk_buff *skb, struct ath_desc *ds,
236 rx_status->signal = rx_status->noise + ds->ds_rxstat.rs_rssi; 236 rx_status->signal = rx_status->noise + ds->ds_rxstat.rs_rssi;
237 rx_status->antenna = ds->ds_rxstat.rs_antenna; 237 rx_status->antenna = ds->ds_rxstat.rs_antenna;
238 238
239 /* at 45 you will be able to use MCS 15 reliably. A more elaborate 239 /*
240 * scheme can be used here but it requires tables of SNR/throughput for 240 * Theory for reporting quality:
241 * each possible mode used. */ 241 *
242 rx_status->qual = ds->ds_rxstat.rs_rssi * 100 / 45; 242 * At a hardware RSSI of 45 you will be able to use MCS 7 reliably.
243 * At a hardware RSSI of 45 you will be able to use MCS 15 reliably.
244 * At a hardware RSSI of 35 you should be able use 54 Mbps reliably.
245 *
246 * MCS 7 is the highets MCS index usable by a 1-stream device.
247 * MCS 15 is the highest MCS index usable by a 2-stream device.
248 *
249 * All ath9k devices are either 1-stream or 2-stream.
250 *
251 * How many bars you see is derived from the qual reporting.
252 *
253 * A more elaborate scheme can be used here but it requires tables
254 * of SNR/throughput for each possible mode used. For the MCS table
255 * you can refer to the wireless wiki:
256 *
257 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
258 *
259 */
260 if (conf_is_ht(&hw->conf))
261 rx_status->qual = ds->ds_rxstat.rs_rssi * 100 / 45;
262 else
263 rx_status->qual = ds->ds_rxstat.rs_rssi * 100 / 35;
243 264
244 /* rssi can be more than 45 though, anything above that 265 /* rssi can be more than 45 though, anything above that
245 * should be considered at 100% */ 266 * should be considered at 100% */
@@ -505,11 +526,6 @@ static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
505 return false; 526 return false;
506} 527}
507 528
508static void ath_rx_ps_back_to_sleep(struct ath_softc *sc)
509{
510 sc->sc_flags &= ~(SC_OP_WAIT_FOR_BEACON | SC_OP_WAIT_FOR_CAB);
511}
512
513static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb) 529static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
514{ 530{
515 struct ieee80211_mgmt *mgmt; 531 struct ieee80211_mgmt *mgmt;
@@ -521,6 +537,8 @@ static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
521 if (memcmp(sc->curbssid, mgmt->bssid, ETH_ALEN) != 0) 537 if (memcmp(sc->curbssid, mgmt->bssid, ETH_ALEN) != 0)
522 return; /* not from our current AP */ 538 return; /* not from our current AP */
523 539
540 sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON;
541
524 if (sc->sc_flags & SC_OP_BEACON_SYNC) { 542 if (sc->sc_flags & SC_OP_BEACON_SYNC) {
525 sc->sc_flags &= ~SC_OP_BEACON_SYNC; 543 sc->sc_flags &= ~SC_OP_BEACON_SYNC;
526 DPRINTF(sc, ATH_DBG_PS, "Reconfigure Beacon timers based on " 544 DPRINTF(sc, ATH_DBG_PS, "Reconfigure Beacon timers based on "
@@ -528,14 +546,6 @@ static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
528 ath_beacon_config(sc, NULL); 546 ath_beacon_config(sc, NULL);
529 } 547 }
530 548
531 if (!(sc->hw->conf.flags & IEEE80211_CONF_PS)) {
532 /* We are not in PS mode anymore; remain awake */
533 DPRINTF(sc, ATH_DBG_PS, "Not in PS mode anymore, remain "
534 "awake\n");
535 sc->sc_flags &= ~(SC_OP_WAIT_FOR_BEACON | SC_OP_WAIT_FOR_CAB);
536 return;
537 }
538
539 if (ath_beacon_dtim_pending_cab(skb)) { 549 if (ath_beacon_dtim_pending_cab(skb)) {
540 /* 550 /*
541 * Remain awake waiting for buffered broadcast/multicast 551 * Remain awake waiting for buffered broadcast/multicast
@@ -556,11 +566,9 @@ static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
556 * fails to send a frame indicating that all CAB frames have 566 * fails to send a frame indicating that all CAB frames have
557 * been delivered. 567 * been delivered.
558 */ 568 */
569 sc->sc_flags &= ~SC_OP_WAIT_FOR_CAB;
559 DPRINTF(sc, ATH_DBG_PS, "PS wait for CAB frames timed out\n"); 570 DPRINTF(sc, ATH_DBG_PS, "PS wait for CAB frames timed out\n");
560 } 571 }
561
562 /* No more broadcast/multicast frames to be received at this point. */
563 ath_rx_ps_back_to_sleep(sc);
564} 572}
565 573
566static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb) 574static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb)
@@ -578,13 +586,13 @@ static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb)
578 ieee80211_is_action(hdr->frame_control)) && 586 ieee80211_is_action(hdr->frame_control)) &&
579 is_multicast_ether_addr(hdr->addr1) && 587 is_multicast_ether_addr(hdr->addr1) &&
580 !ieee80211_has_moredata(hdr->frame_control)) { 588 !ieee80211_has_moredata(hdr->frame_control)) {
581 DPRINTF(sc, ATH_DBG_PS, "All PS CAB frames received, back to "
582 "sleep\n");
583 /* 589 /*
584 * No more broadcast/multicast frames to be received at this 590 * No more broadcast/multicast frames to be received at this
585 * point. 591 * point.
586 */ 592 */
587 ath_rx_ps_back_to_sleep(sc); 593 sc->sc_flags &= ~SC_OP_WAIT_FOR_CAB;
594 DPRINTF(sc, ATH_DBG_PS, "All PS CAB frames received, back to "
595 "sleep\n");
588 } else if ((sc->sc_flags & SC_OP_WAIT_FOR_PSPOLL_DATA) && 596 } else if ((sc->sc_flags & SC_OP_WAIT_FOR_PSPOLL_DATA) &&
589 !is_multicast_ether_addr(hdr->addr1) && 597 !is_multicast_ether_addr(hdr->addr1) &&
590 !ieee80211_has_morefrags(hdr->frame_control)) { 598 !ieee80211_has_morefrags(hdr->frame_control)) {
@@ -619,13 +627,18 @@ static void ath_rx_send_to_mac80211(struct ath_softc *sc, struct sk_buff *skb,
619 if (aphy == NULL) 627 if (aphy == NULL)
620 continue; 628 continue;
621 nskb = skb_copy(skb, GFP_ATOMIC); 629 nskb = skb_copy(skb, GFP_ATOMIC);
622 if (nskb) 630 if (nskb) {
623 __ieee80211_rx(aphy->hw, nskb, rx_status); 631 memcpy(IEEE80211_SKB_RXCB(nskb), rx_status,
632 sizeof(*rx_status));
633 ieee80211_rx(aphy->hw, nskb);
634 }
624 } 635 }
625 __ieee80211_rx(sc->hw, skb, rx_status); 636 memcpy(IEEE80211_SKB_RXCB(skb), rx_status, sizeof(*rx_status));
637 ieee80211_rx(sc->hw, skb);
626 } else { 638 } else {
627 /* Deliver unicast frames based on receiver address */ 639 /* Deliver unicast frames based on receiver address */
628 __ieee80211_rx(ath_get_virt_hw(sc, hdr), skb, rx_status); 640 memcpy(IEEE80211_SKB_RXCB(skb), rx_status, sizeof(*rx_status));
641 ieee80211_rx(ath_get_virt_hw(sc, hdr), skb);
629 } 642 }
630} 643}
631 644
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 4ccf48e396df..5de9878d2c12 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -73,18 +73,6 @@ static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds,
73/* Aggregation logic */ 73/* Aggregation logic */
74/*********************/ 74/*********************/
75 75
76static int ath_aggr_query(struct ath_softc *sc, struct ath_node *an, u8 tidno)
77{
78 struct ath_atx_tid *tid;
79 tid = ATH_AN_2_TID(an, tidno);
80
81 if (tid->state & AGGR_ADDBA_COMPLETE ||
82 tid->state & AGGR_ADDBA_PROGRESS)
83 return 1;
84 else
85 return 0;
86}
87
88static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid) 76static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid)
89{ 77{
90 struct ath_atx_ac *ac = tid->ac; 78 struct ath_atx_ac *ac = tid->ac;
@@ -250,6 +238,10 @@ static struct ath_buf* ath_clone_txbuf(struct ath_softc *sc, struct ath_buf *bf)
250 struct ath_buf *tbf; 238 struct ath_buf *tbf;
251 239
252 spin_lock_bh(&sc->tx.txbuflock); 240 spin_lock_bh(&sc->tx.txbuflock);
241 if (WARN_ON(list_empty(&sc->tx.txbuf))) {
242 spin_unlock_bh(&sc->tx.txbuflock);
243 return NULL;
244 }
253 ASSERT(!list_empty((&sc->tx.txbuf))); 245 ASSERT(!list_empty((&sc->tx.txbuf)));
254 tbf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list); 246 tbf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list);
255 list_del(&tbf->list); 247 list_del(&tbf->list);
@@ -391,6 +383,8 @@ static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
391 struct ath_buf *tbf; 383 struct ath_buf *tbf;
392 384
393 tbf = ath_clone_txbuf(sc, bf_last); 385 tbf = ath_clone_txbuf(sc, bf_last);
386 if (!tbf)
387 break;
394 ath9k_hw_cleartxdesc(sc->sc_ah, tbf->bf_desc); 388 ath9k_hw_cleartxdesc(sc->sc_ah, tbf->bf_desc);
395 list_add_tail(&tbf->list, &bf_head); 389 list_add_tail(&tbf->list, &bf_head);
396 } else { 390 } else {
@@ -414,7 +408,6 @@ static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
414 if (tid->state & AGGR_CLEANUP) { 408 if (tid->state & AGGR_CLEANUP) {
415 if (tid->baw_head == tid->baw_tail) { 409 if (tid->baw_head == tid->baw_tail) {
416 tid->state &= ~AGGR_ADDBA_COMPLETE; 410 tid->state &= ~AGGR_ADDBA_COMPLETE;
417 tid->addba_exchangeattempts = 0;
418 tid->state &= ~AGGR_CLEANUP; 411 tid->state &= ~AGGR_CLEANUP;
419 412
420 /* send buffered frames as singles */ 413 /* send buffered frames as singles */
@@ -719,7 +712,6 @@ int ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
719 712
720 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) { 713 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
721 txtid->state &= ~AGGR_ADDBA_PROGRESS; 714 txtid->state &= ~AGGR_ADDBA_PROGRESS;
722 txtid->addba_exchangeattempts = 0;
723 return 0; 715 return 0;
724 } 716 }
725 717
@@ -747,7 +739,6 @@ int ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
747 txtid->state |= AGGR_CLEANUP; 739 txtid->state |= AGGR_CLEANUP;
748 } else { 740 } else {
749 txtid->state &= ~AGGR_ADDBA_COMPLETE; 741 txtid->state &= ~AGGR_ADDBA_COMPLETE;
750 txtid->addba_exchangeattempts = 0;
751 ath_tx_flush_tid(sc, txtid); 742 ath_tx_flush_tid(sc, txtid);
752 } 743 }
753 744
@@ -780,14 +771,8 @@ bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno)
780 771
781 txtid = ATH_AN_2_TID(an, tidno); 772 txtid = ATH_AN_2_TID(an, tidno);
782 773
783 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) { 774 if (!(txtid->state & (AGGR_ADDBA_COMPLETE | AGGR_ADDBA_PROGRESS)))
784 if (!(txtid->state & AGGR_ADDBA_PROGRESS) &&
785 (txtid->addba_exchangeattempts < ADDBA_EXCHANGE_ATTEMPTS)) {
786 txtid->addba_exchangeattempts++;
787 return true; 775 return true;
788 }
789 }
790
791 return false; 776 return false;
792} 777}
793 778
@@ -1636,7 +1621,7 @@ static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
1636 goto tx_done; 1621 goto tx_done;
1637 } 1622 }
1638 1623
1639 if (ath_aggr_query(sc, an, bf->bf_tidno)) { 1624 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
1640 /* 1625 /*
1641 * Try aggregation if it's a unicast data frame 1626 * Try aggregation if it's a unicast data frame
1642 * and the destination is HT capable. 1627 * and the destination is HT capable.
@@ -2122,7 +2107,6 @@ void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
2122 tid->ac = &an->ac[acno]; 2107 tid->ac = &an->ac[acno];
2123 tid->state &= ~AGGR_ADDBA_COMPLETE; 2108 tid->state &= ~AGGR_ADDBA_COMPLETE;
2124 tid->state &= ~AGGR_ADDBA_PROGRESS; 2109 tid->state &= ~AGGR_ADDBA_PROGRESS;
2125 tid->addba_exchangeattempts = 0;
2126 } 2110 }
2127 2111
2128 for (acno = 0, ac = &an->ac[acno]; 2112 for (acno = 0, ac = &an->ac[acno];
@@ -2179,7 +2163,6 @@ void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
2179 tid->sched = false; 2163 tid->sched = false;
2180 ath_tid_drain(sc, txq, tid); 2164 ath_tid_drain(sc, txq, tid);
2181 tid->state &= ~AGGR_ADDBA_COMPLETE; 2165 tid->state &= ~AGGR_ADDBA_COMPLETE;
2182 tid->addba_exchangeattempts = 0;
2183 tid->state &= ~AGGR_CLEANUP; 2166 tid->state &= ~AGGR_CLEANUP;
2184 } 2167 }
2185 } 2168 }
diff --git a/drivers/net/wireless/ath/regd.c b/drivers/net/wireless/ath/regd.c
index eef370bd1211..f37c83275793 100644
--- a/drivers/net/wireless/ath/regd.c
+++ b/drivers/net/wireless/ath/regd.c
@@ -569,7 +569,5 @@ u32 ath_regd_get_band_ctl(struct ath_regulatory *reg,
569 default: 569 default:
570 return NO_CTL; 570 return NO_CTL;
571 } 571 }
572
573 return NO_CTL;
574} 572}
575EXPORT_SYMBOL(ath_regd_get_band_ctl); 573EXPORT_SYMBOL(ath_regd_get_band_ctl);
diff --git a/drivers/net/wireless/atmel.c b/drivers/net/wireless/atmel.c
index 291a94bd46fd..05813bc3e308 100644
--- a/drivers/net/wireless/atmel.c
+++ b/drivers/net/wireless/atmel.c
@@ -793,13 +793,13 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
793 !(*priv->present_callback)(priv->card)) { 793 !(*priv->present_callback)(priv->card)) {
794 dev->stats.tx_errors++; 794 dev->stats.tx_errors++;
795 dev_kfree_skb(skb); 795 dev_kfree_skb(skb);
796 return 0; 796 return NETDEV_TX_OK;
797 } 797 }
798 798
799 if (priv->station_state != STATION_STATE_READY) { 799 if (priv->station_state != STATION_STATE_READY) {
800 dev->stats.tx_errors++; 800 dev->stats.tx_errors++;
801 dev_kfree_skb(skb); 801 dev_kfree_skb(skb);
802 return 0; 802 return NETDEV_TX_OK;
803 } 803 }
804 804
805 /* first ensure the timer func cannot run */ 805 /* first ensure the timer func cannot run */
@@ -856,7 +856,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
856 spin_unlock_bh(&priv->timerlock); 856 spin_unlock_bh(&priv->timerlock);
857 dev_kfree_skb(skb); 857 dev_kfree_skb(skb);
858 858
859 return 0; 859 return NETDEV_TX_OK;
860} 860}
861 861
862static void atmel_transmit_management_frame(struct atmel_private *priv, 862static void atmel_transmit_management_frame(struct atmel_private *priv,
diff --git a/drivers/net/wireless/b43/xmit.c b/drivers/net/wireless/b43/xmit.c
index 55f36a7254d9..5b85e7d73592 100644
--- a/drivers/net/wireless/b43/xmit.c
+++ b/drivers/net/wireless/b43/xmit.c
@@ -670,7 +670,8 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
670 goto drop; 670 goto drop;
671 } 671 }
672 672
673 ieee80211_rx_irqsafe(dev->wl->hw, skb, &status); 673 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
674 ieee80211_rx_irqsafe(dev->wl->hw, skb);
674 675
675 return; 676 return;
676drop: 677drop:
diff --git a/drivers/net/wireless/b43legacy/xmit.c b/drivers/net/wireless/b43legacy/xmit.c
index b8e39dd06e99..f79cee82601b 100644
--- a/drivers/net/wireless/b43legacy/xmit.c
+++ b/drivers/net/wireless/b43legacy/xmit.c
@@ -591,7 +591,8 @@ void b43legacy_rx(struct b43legacy_wldev *dev,
591 } 591 }
592 592
593 dev->stats.last_rx = jiffies; 593 dev->stats.last_rx = jiffies;
594 ieee80211_rx_irqsafe(dev->wl->hw, skb, &status); 594 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
595 ieee80211_rx_irqsafe(dev->wl->hw, skb);
595 596
596 return; 597 return;
597drop: 598drop:
diff --git a/drivers/net/wireless/hostap/hostap_80211_tx.c b/drivers/net/wireless/hostap/hostap_80211_tx.c
index d313b005114e..1fe1bbabb907 100644
--- a/drivers/net/wireless/hostap/hostap_80211_tx.c
+++ b/drivers/net/wireless/hostap/hostap_80211_tx.c
@@ -75,7 +75,7 @@ int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev)
75 printk(KERN_DEBUG "%s: hostap_data_start_xmit: short skb " 75 printk(KERN_DEBUG "%s: hostap_data_start_xmit: short skb "
76 "(len=%d)\n", dev->name, skb->len); 76 "(len=%d)\n", dev->name, skb->len);
77 kfree_skb(skb); 77 kfree_skb(skb);
78 return 0; 78 return NETDEV_TX_OK;
79 } 79 }
80 80
81 if (local->ddev != dev) { 81 if (local->ddev != dev) {
@@ -89,14 +89,14 @@ int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev)
89 printk(KERN_DEBUG "%s: prism2_tx: trying to use " 89 printk(KERN_DEBUG "%s: prism2_tx: trying to use "
90 "AP device with Ethernet net dev\n", dev->name); 90 "AP device with Ethernet net dev\n", dev->name);
91 kfree_skb(skb); 91 kfree_skb(skb);
92 return 0; 92 return NETDEV_TX_OK;
93 } 93 }
94 } else { 94 } else {
95 if (local->iw_mode == IW_MODE_REPEAT) { 95 if (local->iw_mode == IW_MODE_REPEAT) {
96 printk(KERN_DEBUG "%s: prism2_tx: trying to use " 96 printk(KERN_DEBUG "%s: prism2_tx: trying to use "
97 "non-WDS link in Repeater mode\n", dev->name); 97 "non-WDS link in Repeater mode\n", dev->name);
98 kfree_skb(skb); 98 kfree_skb(skb);
99 return 0; 99 return NETDEV_TX_OK;
100 } else if (local->iw_mode == IW_MODE_INFRA && 100 } else if (local->iw_mode == IW_MODE_INFRA &&
101 (local->wds_type & HOSTAP_WDS_AP_CLIENT) && 101 (local->wds_type & HOSTAP_WDS_AP_CLIENT) &&
102 memcmp(skb->data + ETH_ALEN, dev->dev_addr, 102 memcmp(skb->data + ETH_ALEN, dev->dev_addr,
@@ -210,13 +210,13 @@ int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev)
210 skb = skb_unshare(skb, GFP_ATOMIC); 210 skb = skb_unshare(skb, GFP_ATOMIC);
211 if (skb == NULL) { 211 if (skb == NULL) {
212 iface->stats.tx_dropped++; 212 iface->stats.tx_dropped++;
213 return 0; 213 return NETDEV_TX_OK;
214 } 214 }
215 if (pskb_expand_head(skb, need_headroom, need_tailroom, 215 if (pskb_expand_head(skb, need_headroom, need_tailroom,
216 GFP_ATOMIC)) { 216 GFP_ATOMIC)) {
217 kfree_skb(skb); 217 kfree_skb(skb);
218 iface->stats.tx_dropped++; 218 iface->stats.tx_dropped++;
219 return 0; 219 return NETDEV_TX_OK;
220 } 220 }
221 } else if (skb_headroom(skb) < need_headroom) { 221 } else if (skb_headroom(skb) < need_headroom) {
222 struct sk_buff *tmp = skb; 222 struct sk_buff *tmp = skb;
@@ -224,13 +224,13 @@ int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev)
224 kfree_skb(tmp); 224 kfree_skb(tmp);
225 if (skb == NULL) { 225 if (skb == NULL) {
226 iface->stats.tx_dropped++; 226 iface->stats.tx_dropped++;
227 return 0; 227 return NETDEV_TX_OK;
228 } 228 }
229 } else { 229 } else {
230 skb = skb_unshare(skb, GFP_ATOMIC); 230 skb = skb_unshare(skb, GFP_ATOMIC);
231 if (skb == NULL) { 231 if (skb == NULL) {
232 iface->stats.tx_dropped++; 232 iface->stats.tx_dropped++;
233 return 0; 233 return NETDEV_TX_OK;
234 } 234 }
235 } 235 }
236 236
@@ -256,7 +256,7 @@ int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev)
256 /* Send IEEE 802.11 encapsulated frame using the master radio device */ 256 /* Send IEEE 802.11 encapsulated frame using the master radio device */
257 skb->dev = local->dev; 257 skb->dev = local->dev;
258 dev_queue_xmit(skb); 258 dev_queue_xmit(skb);
259 return 0; 259 return NETDEV_TX_OK;
260} 260}
261 261
262 262
@@ -276,7 +276,7 @@ int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
276 printk(KERN_DEBUG "%s: hostap_mgmt_start_xmit: short skb " 276 printk(KERN_DEBUG "%s: hostap_mgmt_start_xmit: short skb "
277 "(len=%d)\n", dev->name, skb->len); 277 "(len=%d)\n", dev->name, skb->len);
278 kfree_skb(skb); 278 kfree_skb(skb);
279 return 0; 279 return NETDEV_TX_OK;
280 } 280 }
281 281
282 iface->stats.tx_packets++; 282 iface->stats.tx_packets++;
@@ -301,7 +301,7 @@ int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
301 /* Send IEEE 802.11 encapsulated frame using the master radio device */ 301 /* Send IEEE 802.11 encapsulated frame using the master radio device */
302 skb->dev = local->dev; 302 skb->dev = local->dev;
303 dev_queue_xmit(skb); 303 dev_queue_xmit(skb);
304 return 0; 304 return NETDEV_TX_OK;
305} 305}
306 306
307 307
@@ -396,7 +396,7 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
396 printk(KERN_DEBUG "%s: invalid skb->cb magic (0x%08x, " 396 printk(KERN_DEBUG "%s: invalid skb->cb magic (0x%08x, "
397 "expected 0x%08x)\n", 397 "expected 0x%08x)\n",
398 dev->name, meta->magic, HOSTAP_SKB_TX_DATA_MAGIC); 398 dev->name, meta->magic, HOSTAP_SKB_TX_DATA_MAGIC);
399 ret = 0; 399 ret = NETDEV_TX_OK;
400 iface->stats.tx_dropped++; 400 iface->stats.tx_dropped++;
401 goto fail; 401 goto fail;
402 } 402 }
@@ -414,7 +414,7 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
414 if (skb->len < 24) { 414 if (skb->len < 24) {
415 printk(KERN_DEBUG "%s: hostap_master_start_xmit: short skb " 415 printk(KERN_DEBUG "%s: hostap_master_start_xmit: short skb "
416 "(len=%d)\n", dev->name, skb->len); 416 "(len=%d)\n", dev->name, skb->len);
417 ret = 0; 417 ret = NETDEV_TX_OK;
418 iface->stats.tx_dropped++; 418 iface->stats.tx_dropped++;
419 goto fail; 419 goto fail;
420 } 420 }
@@ -441,13 +441,13 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
441 dev->name, meta->ethertype); 441 dev->name, meta->ethertype);
442 hostap_dump_tx_80211(dev->name, skb); 442 hostap_dump_tx_80211(dev->name, skb);
443 443
444 ret = 0; /* drop packet */ 444 ret = NETDEV_TX_OK; /* drop packet */
445 iface->stats.tx_dropped++; 445 iface->stats.tx_dropped++;
446 goto fail; 446 goto fail;
447 } 447 }
448 break; 448 break;
449 case AP_TX_DROP: 449 case AP_TX_DROP:
450 ret = 0; /* drop packet */ 450 ret = NETDEV_TX_OK; /* drop packet */
451 iface->stats.tx_dropped++; 451 iface->stats.tx_dropped++;
452 goto fail; 452 goto fail;
453 case AP_TX_RETRY: 453 case AP_TX_RETRY:
@@ -455,7 +455,7 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
455 case AP_TX_BUFFERED: 455 case AP_TX_BUFFERED:
456 /* do not free skb here, it will be freed when the 456 /* do not free skb here, it will be freed when the
457 * buffered frame is sent/timed out */ 457 * buffered frame is sent/timed out */
458 ret = 0; 458 ret = NETDEV_TX_OK;
459 goto tx_exit; 459 goto tx_exit;
460 } 460 }
461 461
@@ -501,7 +501,7 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
501 "frame (drop_unencrypted=1)\n", dev->name); 501 "frame (drop_unencrypted=1)\n", dev->name);
502 } 502 }
503 iface->stats.tx_dropped++; 503 iface->stats.tx_dropped++;
504 ret = 0; 504 ret = NETDEV_TX_OK;
505 goto fail; 505 goto fail;
506 } 506 }
507 507
@@ -510,7 +510,7 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
510 if (skb == NULL) { 510 if (skb == NULL) {
511 printk(KERN_DEBUG "%s: TX - encryption failed\n", 511 printk(KERN_DEBUG "%s: TX - encryption failed\n",
512 dev->name); 512 dev->name);
513 ret = 0; 513 ret = NETDEV_TX_OK;
514 goto fail; 514 goto fail;
515 } 515 }
516 meta = (struct hostap_skb_tx_data *) skb->cb; 516 meta = (struct hostap_skb_tx_data *) skb->cb;
@@ -519,23 +519,23 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
519 "expected 0x%08x) after hostap_tx_encrypt\n", 519 "expected 0x%08x) after hostap_tx_encrypt\n",
520 dev->name, meta->magic, 520 dev->name, meta->magic,
521 HOSTAP_SKB_TX_DATA_MAGIC); 521 HOSTAP_SKB_TX_DATA_MAGIC);
522 ret = 0; 522 ret = NETDEV_TX_OK;
523 iface->stats.tx_dropped++; 523 iface->stats.tx_dropped++;
524 goto fail; 524 goto fail;
525 } 525 }
526 } 526 }
527 527
528 if (local->func->tx == NULL || local->func->tx(skb, dev)) { 528 if (local->func->tx == NULL || local->func->tx(skb, dev)) {
529 ret = 0; 529 ret = NETDEV_TX_OK;
530 iface->stats.tx_dropped++; 530 iface->stats.tx_dropped++;
531 } else { 531 } else {
532 ret = 0; 532 ret = NETDEV_TX_OK;
533 iface->stats.tx_packets++; 533 iface->stats.tx_packets++;
534 iface->stats.tx_bytes += skb->len; 534 iface->stats.tx_bytes += skb->len;
535 } 535 }
536 536
537 fail: 537 fail:
538 if (!ret && skb) 538 if (ret == NETDEV_TX_OK && skb)
539 dev_kfree_skb(skb); 539 dev_kfree_skb(skb);
540 tx_exit: 540 tx_exit:
541 if (tx.sta_ptr) 541 if (tx.sta_ptr)
diff --git a/drivers/net/wireless/ipw2x00/ipw2200.c b/drivers/net/wireless/ipw2x00/ipw2200.c
index 44c29b3f6728..d726b3c6077a 100644
--- a/drivers/net/wireless/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/ipw2x00/ipw2200.c
@@ -11436,11 +11436,11 @@ static struct pci_device_id card_ids[] = {
11436 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, 11436 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11437 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, 11437 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11438 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, 11438 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11439 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 11439 {PCI_VDEVICE(INTEL, 0x104f), 0},
11440 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ 11440 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11441 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ 11441 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11442 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ 11442 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11443 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ 11443 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
11444 11444
11445 /* required last entry */ 11445 /* required last entry */
11446 {0,} 11446 {0,}
diff --git a/drivers/net/wireless/ipw2x00/libipw_tx.c b/drivers/net/wireless/ipw2x00/libipw_tx.c
index da2ad5437ce5..2e8f84fb29fa 100644
--- a/drivers/net/wireless/ipw2x00/libipw_tx.c
+++ b/drivers/net/wireless/ipw2x00/libipw_tx.c
@@ -527,13 +527,13 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
527 if (ret == 0) { 527 if (ret == 0) {
528 dev->stats.tx_packets++; 528 dev->stats.tx_packets++;
529 dev->stats.tx_bytes += txb->payload_size; 529 dev->stats.tx_bytes += txb->payload_size;
530 return 0; 530 return NETDEV_TX_OK;
531 } 531 }
532 532
533 ieee80211_txb_free(txb); 533 ieee80211_txb_free(txb);
534 } 534 }
535 535
536 return 0; 536 return NETDEV_TX_OK;
537 537
538 failed: 538 failed:
539 spin_unlock_irqrestore(&ieee->lock, flags); 539 spin_unlock_irqrestore(&ieee->lock, flags);
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index 46288e724889..b0246dbda99a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -577,7 +577,8 @@ static void iwl3945_pass_packet_to_mac80211(struct iwl_priv *priv,
577 if (ieee80211_is_data(hdr->frame_control)) 577 if (ieee80211_is_data(hdr->frame_control))
578 priv->rxtxpackets += len; 578 priv->rxtxpackets += len;
579#endif 579#endif
580 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); 580 memcpy(IEEE80211_SKB_RXCB(rxb->skb), stats, sizeof(*stats));
581 ieee80211_rx_irqsafe(priv->hw, rxb->skb);
581 rxb->skb = NULL; 582 rxb->skb = NULL;
582} 583}
583 584
@@ -1986,7 +1987,7 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1986 staging_rxon->reserved4 = 0; 1987 staging_rxon->reserved4 = 0;
1987 staging_rxon->reserved5 = 0; 1988 staging_rxon->reserved5 = 0;
1988 1989
1989 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); 1990 iwl_set_rxon_hwcrypto(priv, !iwl3945_mod_params.sw_crypto);
1990 1991
1991 /* Apply the new configuration */ 1992 /* Apply the new configuration */
1992 rc = iwl_send_cmd_pdu(priv, REPLY_RXON, 1993 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
@@ -2562,6 +2563,7 @@ int iwl3945_hw_set_hw_params(struct iwl_priv *priv)
2562 priv->hw_params.bcast_sta_id = IWL3945_BROADCAST_ID; 2563 priv->hw_params.bcast_sta_id = IWL3945_BROADCAST_ID;
2563 2564
2564 priv->hw_params.rx_wrt_ptr_reg = FH39_RSCSR_CHNL0_WPTR; 2565 priv->hw_params.rx_wrt_ptr_reg = FH39_RSCSR_CHNL0_WPTR;
2566 priv->hw_params.max_beacon_itrvl = IWL39_MAX_UCODE_BEACON_INTERVAL;
2565 2567
2566 return 0; 2568 return 0;
2567} 2569}
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index 8f3d4bc6a03f..edbb0bfd8cb7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -728,7 +728,7 @@ static int iwl4965_alive_notify(struct iwl_priv *priv)
728 728
729static struct iwl_sensitivity_ranges iwl4965_sensitivity = { 729static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
730 .min_nrg_cck = 97, 730 .min_nrg_cck = 97,
731 .max_nrg_cck = 0, 731 .max_nrg_cck = 0, /* not used, set to 0 */
732 732
733 .auto_corr_min_ofdm = 85, 733 .auto_corr_min_ofdm = 85,
734 .auto_corr_min_ofdm_mrc = 170, 734 .auto_corr_min_ofdm_mrc = 170,
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index b3c648ce8c7b..85e8bac499a7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -388,7 +388,7 @@ void iwl5000_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
388 388
389static struct iwl_sensitivity_ranges iwl5000_sensitivity = { 389static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
390 .min_nrg_cck = 95, 390 .min_nrg_cck = 95,
391 .max_nrg_cck = 0, 391 .max_nrg_cck = 0, /* not used, set to 0 */
392 .auto_corr_min_ofdm = 90, 392 .auto_corr_min_ofdm = 90,
393 .auto_corr_min_ofdm_mrc = 170, 393 .auto_corr_min_ofdm_mrc = 170,
394 .auto_corr_min_ofdm_x1 = 120, 394 .auto_corr_min_ofdm_x1 = 120,
@@ -407,6 +407,28 @@ static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
407 .nrg_th_ofdm = 95, 407 .nrg_th_ofdm = 95,
408}; 408};
409 409
410static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
411 .min_nrg_cck = 95,
412 .max_nrg_cck = 0, /* not used, set to 0 */
413 .auto_corr_min_ofdm = 90,
414 .auto_corr_min_ofdm_mrc = 170,
415 .auto_corr_min_ofdm_x1 = 105,
416 .auto_corr_min_ofdm_mrc_x1 = 220,
417
418 .auto_corr_max_ofdm = 120,
419 .auto_corr_max_ofdm_mrc = 210,
420 /* max = min for performance bug in 5150 DSP */
421 .auto_corr_max_ofdm_x1 = 105,
422 .auto_corr_max_ofdm_mrc_x1 = 220,
423
424 .auto_corr_min_cck = 125,
425 .auto_corr_max_cck = 200,
426 .auto_corr_min_cck_mrc = 170,
427 .auto_corr_max_cck_mrc = 400,
428 .nrg_th_cck = 95,
429 .nrg_th_ofdm = 95,
430};
431
410static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv, 432static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
411 size_t offset) 433 size_t offset)
412{ 434{
@@ -826,8 +848,6 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
826 BIT(IEEE80211_BAND_5GHZ); 848 BIT(IEEE80211_BAND_5GHZ);
827 priv->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR; 849 priv->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR;
828 850
829 priv->hw_params.sens = &iwl5000_sensitivity;
830
831 priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant); 851 priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
832 priv->hw_params.rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant); 852 priv->hw_params.rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
833 priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant; 853 priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
@@ -836,9 +856,11 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
836 if (priv->cfg->ops->lib->temp_ops.set_ct_kill) 856 if (priv->cfg->ops->lib->temp_ops.set_ct_kill)
837 priv->cfg->ops->lib->temp_ops.set_ct_kill(priv); 857 priv->cfg->ops->lib->temp_ops.set_ct_kill(priv);
838 858
859 /* Set initial sensitivity parameters */
839 /* Set initial calibration set */ 860 /* Set initial calibration set */
840 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) { 861 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
841 case CSR_HW_REV_TYPE_5150: 862 case CSR_HW_REV_TYPE_5150:
863 priv->hw_params.sens = &iwl5150_sensitivity;
842 priv->hw_params.calib_init_cfg = 864 priv->hw_params.calib_init_cfg =
843 BIT(IWL_CALIB_DC) | 865 BIT(IWL_CALIB_DC) |
844 BIT(IWL_CALIB_LO) | 866 BIT(IWL_CALIB_LO) |
@@ -847,6 +869,7 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
847 869
848 break; 870 break;
849 default: 871 default:
872 priv->hw_params.sens = &iwl5000_sensitivity;
850 priv->hw_params.calib_init_cfg = 873 priv->hw_params.calib_init_cfg =
851 BIT(IWL_CALIB_XTAL) | 874 BIT(IWL_CALIB_XTAL) |
852 BIT(IWL_CALIB_LO) | 875 BIT(IWL_CALIB_LO) |
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 6d1519e1f011..1d4e9cadb088 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -171,7 +171,7 @@ int iwl_commit_rxon(struct iwl_priv *priv)
171 le16_to_cpu(priv->staging_rxon.channel), 171 le16_to_cpu(priv->staging_rxon.channel),
172 priv->staging_rxon.bssid_addr); 172 priv->staging_rxon.bssid_addr);
173 173
174 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); 174 iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
175 175
176 /* Apply the new configuration 176 /* Apply the new configuration
177 * RXON unassoc clears the station table in uCode, send it before 177 * RXON unassoc clears the station table in uCode, send it before
@@ -512,70 +512,6 @@ int iwl_hw_tx_queue_init(struct iwl_priv *priv,
512 return 0; 512 return 0;
513} 513}
514 514
515
516/******************************************************************************
517 *
518 * Misc. internal state and helper functions
519 *
520 ******************************************************************************/
521
522#define MAX_UCODE_BEACON_INTERVAL 4096
523
524static u16 iwl_adjust_beacon_interval(u16 beacon_val)
525{
526 u16 new_val = 0;
527 u16 beacon_factor = 0;
528
529 beacon_factor = (beacon_val + MAX_UCODE_BEACON_INTERVAL)
530 / MAX_UCODE_BEACON_INTERVAL;
531 new_val = beacon_val / beacon_factor;
532
533 if (!new_val)
534 new_val = MAX_UCODE_BEACON_INTERVAL;
535
536 return new_val;
537}
538
539static void iwl_setup_rxon_timing(struct iwl_priv *priv)
540{
541 u64 tsf;
542 s32 interval_tm, rem;
543 unsigned long flags;
544 struct ieee80211_conf *conf = NULL;
545 u16 beacon_int = 0;
546
547 conf = ieee80211_get_hw_conf(priv->hw);
548
549 spin_lock_irqsave(&priv->lock, flags);
550 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
551 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
552
553 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
554 beacon_int = iwl_adjust_beacon_interval(priv->beacon_int);
555 priv->rxon_timing.atim_window = 0;
556 } else {
557 beacon_int = iwl_adjust_beacon_interval(
558 priv->vif->bss_conf.beacon_int);
559
560 /* TODO: we need to get atim_window from upper stack
561 * for now we set to 0 */
562 priv->rxon_timing.atim_window = 0;
563 }
564
565 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
566
567 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
568 interval_tm = beacon_int * 1024;
569 rem = do_div(tsf, interval_tm);
570 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
571
572 spin_unlock_irqrestore(&priv->lock, flags);
573 IWL_DEBUG_ASSOC(priv, "beacon interval %d beacon timer %d beacon tim %d\n",
574 le16_to_cpu(priv->rxon_timing.beacon_interval),
575 le32_to_cpu(priv->rxon_timing.beacon_init_val),
576 le16_to_cpu(priv->rxon_timing.atim_window));
577}
578
579/****************************************************************************** 515/******************************************************************************
580 * 516 *
581 * Generic RX handler implementations 517 * Generic RX handler implementations
@@ -1812,6 +1748,11 @@ static int iwl_prepare_card_hw(struct iwl_priv *priv)
1812 1748
1813 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter \n"); 1749 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter \n");
1814 1750
1751 ret = iwl_set_hw_ready(priv);
1752 if (priv->hw_ready)
1753 return ret;
1754
1755 /* If HW is not ready, prepare the conditions to check again */
1815 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, 1756 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1816 CSR_HW_IF_CONFIG_REG_PREPARE); 1757 CSR_HW_IF_CONFIG_REG_PREPARE);
1817 1758
@@ -1819,6 +1760,7 @@ static int iwl_prepare_card_hw(struct iwl_priv *priv)
1819 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 1760 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
1820 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000); 1761 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
1821 1762
1763 /* HW should be ready by now, check again. */
1822 if (ret != -ETIMEDOUT) 1764 if (ret != -ETIMEDOUT)
1823 iwl_set_hw_ready(priv); 1765 iwl_set_hw_ready(priv);
1824 1766
@@ -2331,7 +2273,7 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2331 2273
2332 IWL_DEBUG_MAC80211(priv, "enter\n"); 2274 IWL_DEBUG_MAC80211(priv, "enter\n");
2333 2275
2334 if (priv->hw_params.sw_crypto) { 2276 if (priv->cfg->mod_params->sw_crypto) {
2335 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n"); 2277 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
2336 return -EOPNOTSUPP; 2278 return -EOPNOTSUPP;
2337 } 2279 }
diff --git a/drivers/net/wireless/iwlwifi/iwl-calib.c b/drivers/net/wireless/iwlwifi/iwl-calib.c
index a5d63672ad39..f8bf592e939c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-calib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-calib.c
@@ -251,12 +251,7 @@ static int iwl_sens_energy_cck(struct iwl_priv *priv,
251 251
252 /* increase energy threshold (reduce nrg value) 252 /* increase energy threshold (reduce nrg value)
253 * to decrease sensitivity */ 253 * to decrease sensitivity */
254 if (data->nrg_th_cck > 254 data->nrg_th_cck = data->nrg_th_cck - NRG_STEP_CCK;
255 (ranges->max_nrg_cck + NRG_STEP_CCK))
256 data->nrg_th_cck = data->nrg_th_cck
257 - NRG_STEP_CCK;
258 else
259 data->nrg_th_cck = ranges->max_nrg_cck;
260 /* Else if we got fewer than desired, increase sensitivity */ 255 /* Else if we got fewer than desired, increase sensitivity */
261 } else if (false_alarms < min_false_alarms) { 256 } else if (false_alarms < min_false_alarms) {
262 data->nrg_curr_state = IWL_FA_TOO_FEW; 257 data->nrg_curr_state = IWL_FA_TOO_FEW;
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index c87033bf3ad2..ebb2fbce5365 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -765,6 +765,8 @@ struct iwl5000_rxon_assoc_cmd {
765} __attribute__ ((packed)); 765} __attribute__ ((packed));
766 766
767#define IWL_CONN_MAX_LISTEN_INTERVAL 10 767#define IWL_CONN_MAX_LISTEN_INTERVAL 10
768#define IWL_MAX_UCODE_BEACON_INTERVAL 4 /* 4096 */
769#define IWL39_MAX_UCODE_BEACON_INTERVAL 1 /* 1024 */
768 770
769/* 771/*
770 * REPLY_RXON_TIMING = 0x14 (command, has simple generic response) 772 * REPLY_RXON_TIMING = 0x14 (command, has simple generic response)
@@ -1922,7 +1924,7 @@ struct iwl_link_qual_general_params {
1922#define LINK_QUAL_AGG_DISABLE_START_MIN (0) 1924#define LINK_QUAL_AGG_DISABLE_START_MIN (0)
1923 1925
1924#define LINK_QUAL_AGG_FRAME_LIMIT_DEF (31) 1926#define LINK_QUAL_AGG_FRAME_LIMIT_DEF (31)
1925#define LINK_QUAL_AGG_FRAME_LIMIT_MAX (64) 1927#define LINK_QUAL_AGG_FRAME_LIMIT_MAX (63)
1926#define LINK_QUAL_AGG_FRAME_LIMIT_MIN (0) 1928#define LINK_QUAL_AGG_FRAME_LIMIT_MIN (0)
1927 1929
1928/** 1930/**
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index 6ab07165ea28..d5cd9a20edca 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -635,6 +635,63 @@ u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv,
635} 635}
636EXPORT_SYMBOL(iwl_is_fat_tx_allowed); 636EXPORT_SYMBOL(iwl_is_fat_tx_allowed);
637 637
638static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
639{
640 u16 new_val = 0;
641 u16 beacon_factor = 0;
642
643 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
644 new_val = beacon_val / beacon_factor;
645
646 if (!new_val)
647 new_val = max_beacon_val;
648
649 return new_val;
650}
651
652void iwl_setup_rxon_timing(struct iwl_priv *priv)
653{
654 u64 tsf;
655 s32 interval_tm, rem;
656 unsigned long flags;
657 struct ieee80211_conf *conf = NULL;
658 u16 beacon_int;
659
660 conf = ieee80211_get_hw_conf(priv->hw);
661
662 spin_lock_irqsave(&priv->lock, flags);
663 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
664 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
665
666 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
667 beacon_int = priv->beacon_int;
668 priv->rxon_timing.atim_window = 0;
669 } else {
670 beacon_int = priv->vif->bss_conf.beacon_int;
671
672 /* TODO: we need to get atim_window from upper stack
673 * for now we set to 0 */
674 priv->rxon_timing.atim_window = 0;
675 }
676
677 beacon_int = iwl_adjust_beacon_interval(beacon_int,
678 priv->hw_params.max_beacon_itrvl * 1024);
679 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
680
681 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
682 interval_tm = beacon_int * 1024;
683 rem = do_div(tsf, interval_tm);
684 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
685
686 spin_unlock_irqrestore(&priv->lock, flags);
687 IWL_DEBUG_ASSOC(priv,
688 "beacon interval %d beacon timer %d beacon tim %d\n",
689 le16_to_cpu(priv->rxon_timing.beacon_interval),
690 le32_to_cpu(priv->rxon_timing.beacon_init_val),
691 le16_to_cpu(priv->rxon_timing.atim_window));
692}
693EXPORT_SYMBOL(iwl_setup_rxon_timing);
694
638void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) 695void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
639{ 696{
640 struct iwl_rxon_cmd *rxon = &priv->staging_rxon; 697 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
@@ -1325,7 +1382,8 @@ int iwl_setup_mac(struct iwl_priv *priv)
1325 hw->flags = IEEE80211_HW_SIGNAL_DBM | 1382 hw->flags = IEEE80211_HW_SIGNAL_DBM |
1326 IEEE80211_HW_NOISE_DBM | 1383 IEEE80211_HW_NOISE_DBM |
1327 IEEE80211_HW_AMPDU_AGGREGATION | 1384 IEEE80211_HW_AMPDU_AGGREGATION |
1328 IEEE80211_HW_SPECTRUM_MGMT; 1385 IEEE80211_HW_SPECTRUM_MGMT |
1386 IEEE80211_HW_SUPPORTS_PS;
1329 hw->wiphy->interface_modes = 1387 hw->wiphy->interface_modes =
1330 BIT(NL80211_IFTYPE_STATION) | 1388 BIT(NL80211_IFTYPE_STATION) |
1331 BIT(NL80211_IFTYPE_ADHOC); 1389 BIT(NL80211_IFTYPE_ADHOC);
@@ -1361,7 +1419,6 @@ EXPORT_SYMBOL(iwl_setup_mac);
1361 1419
1362int iwl_set_hw_params(struct iwl_priv *priv) 1420int iwl_set_hw_params(struct iwl_priv *priv)
1363{ 1421{
1364 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
1365 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE; 1422 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
1366 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG; 1423 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
1367 if (priv->cfg->mod_params->amsdu_size_8K) 1424 if (priv->cfg->mod_params->amsdu_size_8K)
@@ -1370,6 +1427,8 @@ int iwl_set_hw_params(struct iwl_priv *priv)
1370 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K; 1427 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
1371 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256; 1428 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
1372 1429
1430 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
1431
1373 if (priv->cfg->mod_params->disable_11n) 1432 if (priv->cfg->mod_params->disable_11n)
1374 priv->cfg->sku &= ~IWL_SKU_N; 1433 priv->cfg->sku &= ~IWL_SKU_N;
1375 1434
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index dabf663e36e5..a658410e66a4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -384,7 +384,6 @@ static inline __le32 iwl_hw_set_rate_n_flags(u8 rate, u32 flags)
384void iwl_init_scan_params(struct iwl_priv *priv); 384void iwl_init_scan_params(struct iwl_priv *priv);
385int iwl_scan_cancel(struct iwl_priv *priv); 385int iwl_scan_cancel(struct iwl_priv *priv);
386int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms); 386int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms);
387int iwl_scan_initiate(struct iwl_priv *priv);
388int iwl_mac_hw_scan(struct ieee80211_hw *hw, struct cfg80211_scan_request *req); 387int iwl_mac_hw_scan(struct ieee80211_hw *hw, struct cfg80211_scan_request *req);
389u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame, 388u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame,
390 const u8 *ie, int ie_len, int left); 389 const u8 *ie, int ie_len, int left);
@@ -398,7 +397,6 @@ void iwl_bg_scan_check(struct work_struct *data);
398void iwl_bg_abort_scan(struct work_struct *work); 397void iwl_bg_abort_scan(struct work_struct *work);
399void iwl_bg_scan_completed(struct work_struct *work); 398void iwl_bg_scan_completed(struct work_struct *work);
400void iwl_setup_scan_deferred_work(struct iwl_priv *priv); 399void iwl_setup_scan_deferred_work(struct iwl_priv *priv);
401int iwl_send_scan_abort(struct iwl_priv *priv);
402 400
403/* For faster active scanning, scan will move to the next channel if fewer than 401/* For faster active scanning, scan will move to the next channel if fewer than
404 * PLCP_QUIET_THRESH packets are heard on this channel within 402 * PLCP_QUIET_THRESH packets are heard on this channel within
@@ -556,6 +554,7 @@ extern void iwl_rx_reply_rx_phy(struct iwl_priv *priv,
556void iwl_rx_reply_compressed_ba(struct iwl_priv *priv, 554void iwl_rx_reply_compressed_ba(struct iwl_priv *priv,
557 struct iwl_rx_mem_buffer *rxb); 555 struct iwl_rx_mem_buffer *rxb);
558 556
557void iwl_setup_rxon_timing(struct iwl_priv *priv);
559static inline int iwl_send_rxon_assoc(struct iwl_priv *priv) 558static inline int iwl_send_rxon_assoc(struct iwl_priv *priv)
560{ 559{
561 return priv->cfg->ops->hcmd->rxon_assoc(priv); 560 return priv->cfg->ops->hcmd->rxon_assoc(priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
index 2cf014f523be..65bbce0f1717 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
@@ -36,6 +36,12 @@ struct iwl_priv;
36#define IWL_INFO(p, f, a...) dev_info(&((p)->pci_dev->dev), f, ## a) 36#define IWL_INFO(p, f, a...) dev_info(&((p)->pci_dev->dev), f, ## a)
37#define IWL_CRIT(p, f, a...) dev_crit(&((p)->pci_dev->dev), f, ## a) 37#define IWL_CRIT(p, f, a...) dev_crit(&((p)->pci_dev->dev), f, ## a)
38 38
39#define iwl_print_hex_error(priv, p, len) \
40do { \
41 print_hex_dump(KERN_ERR, "iwl data: ", \
42 DUMP_PREFIX_OFFSET, 16, 1, p, len, 1); \
43} while (0)
44
39#ifdef CONFIG_IWLWIFI_DEBUG 45#ifdef CONFIG_IWLWIFI_DEBUG
40#define IWL_DEBUG(__priv, level, fmt, args...) \ 46#define IWL_DEBUG(__priv, level, fmt, args...) \
41do { \ 47do { \
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index 11e08c068917..f32ac74b69ac 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -615,7 +615,10 @@ int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
615 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal); 615 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
616 DEBUGFS_ADD_BOOL(disable_chain_noise, rf, 616 DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
617 &priv->disable_chain_noise_cal); 617 &priv->disable_chain_noise_cal);
618 DEBUGFS_ADD_BOOL(disable_tx_power, rf, &priv->disable_tx_power_cal); 618 if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
619 ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
620 DEBUGFS_ADD_BOOL(disable_tx_power, rf,
621 &priv->disable_tx_power_cal);
619 return 0; 622 return 0;
620 623
621err: 624err:
@@ -646,7 +649,9 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv)
646 DEBUGFS_REMOVE(priv->dbgfs->dir_data); 649 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
647 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity); 650 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
648 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise); 651 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
649 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power); 652 if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
653 ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
654 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
650 DEBUGFS_REMOVE(priv->dbgfs->dir_rf); 655 DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
651 DEBUGFS_REMOVE(priv->dbgfs->dir_drv); 656 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
652 kfree(priv->dbgfs); 657 kfree(priv->dbgfs);
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index e2d620f0b6e8..1a2fe37d4735 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -608,7 +608,7 @@ struct iwl_hw_params {
608 u8 max_stations; 608 u8 max_stations;
609 u8 bcast_sta_id; 609 u8 bcast_sta_id;
610 u8 fat_channel; 610 u8 fat_channel;
611 u8 sw_crypto; 611 u8 max_beacon_itrvl; /* in 1024 ms */
612 u32 max_inst_size; 612 u32 max_inst_size;
613 u32 max_data_size; 613 u32 max_data_size;
614 u32 max_bsm_size; 614 u32 max_bsm_size;
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c
index 2b8d40b37a1c..66fe365dd08a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rx.c
@@ -927,12 +927,13 @@ static void iwl_pass_packet_to_mac80211(struct iwl_priv *priv,
927 hdr = (struct ieee80211_hdr *)rxb->skb->data; 927 hdr = (struct ieee80211_hdr *)rxb->skb->data;
928 928
929 /* in case of HW accelerated crypto and bad decryption, drop */ 929 /* in case of HW accelerated crypto and bad decryption, drop */
930 if (!priv->hw_params.sw_crypto && 930 if (!priv->cfg->mod_params->sw_crypto &&
931 iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats)) 931 iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
932 return; 932 return;
933 933
934 iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len); 934 iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
935 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); 935 memcpy(IEEE80211_SKB_RXCB(rxb->skb), stats, sizeof(*stats));
936 ieee80211_rx_irqsafe(priv->hw, rxb->skb);
936 priv->alloc_rxb_skb--; 937 priv->alloc_rxb_skb--;
937 rxb->skb = NULL; 938 rxb->skb = NULL;
938} 939}
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
index e26875dbe859..00398d973a07 100644
--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
+++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
@@ -109,7 +109,7 @@ int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
109} 109}
110EXPORT_SYMBOL(iwl_scan_cancel_timeout); 110EXPORT_SYMBOL(iwl_scan_cancel_timeout);
111 111
112int iwl_send_scan_abort(struct iwl_priv *priv) 112static int iwl_send_scan_abort(struct iwl_priv *priv)
113{ 113{
114 int ret = 0; 114 int ret = 0;
115 struct iwl_rx_packet *res; 115 struct iwl_rx_packet *res;
@@ -150,7 +150,6 @@ int iwl_send_scan_abort(struct iwl_priv *priv)
150 150
151 return ret; 151 return ret;
152} 152}
153EXPORT_SYMBOL(iwl_send_scan_abort);
154 153
155/* Service response to REPLY_SCAN_CMD (0x80) */ 154/* Service response to REPLY_SCAN_CMD (0x80) */
156static void iwl_rx_reply_scan(struct iwl_priv *priv, 155static void iwl_rx_reply_scan(struct iwl_priv *priv,
@@ -322,7 +321,7 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv,
322 u8 is_active, u8 n_probes, 321 u8 is_active, u8 n_probes,
323 struct iwl_scan_channel *scan_ch) 322 struct iwl_scan_channel *scan_ch)
324{ 323{
325 const struct ieee80211_channel *channels = NULL; 324 struct ieee80211_channel *chan;
326 const struct ieee80211_supported_band *sband; 325 const struct ieee80211_supported_band *sband;
327 const struct iwl_channel_info *ch_info; 326 const struct iwl_channel_info *ch_info;
328 u16 passive_dwell = 0; 327 u16 passive_dwell = 0;
@@ -334,20 +333,19 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv,
334 if (!sband) 333 if (!sband)
335 return 0; 334 return 0;
336 335
337 channels = sband->channels;
338
339 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes); 336 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
340 passive_dwell = iwl_get_passive_dwell_time(priv, band); 337 passive_dwell = iwl_get_passive_dwell_time(priv, band);
341 338
342 if (passive_dwell <= active_dwell) 339 if (passive_dwell <= active_dwell)
343 passive_dwell = active_dwell + 1; 340 passive_dwell = active_dwell + 1;
344 341
345 for (i = 0, added = 0; i < sband->n_channels; i++) { 342 for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
346 if (channels[i].flags & IEEE80211_CHAN_DISABLED) 343 chan = priv->scan_request->channels[i];
344
345 if (chan->band != band)
347 continue; 346 continue;
348 347
349 channel = 348 channel = ieee80211_frequency_to_channel(chan->center_freq);
350 ieee80211_frequency_to_channel(channels[i].center_freq);
351 scan_ch->channel = cpu_to_le16(channel); 349 scan_ch->channel = cpu_to_le16(channel);
352 350
353 ch_info = iwl_get_channel_info(priv, band, channel); 351 ch_info = iwl_get_channel_info(priv, band, channel);
@@ -358,7 +356,7 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv,
358 } 356 }
359 357
360 if (!is_active || is_channel_passive(ch_info) || 358 if (!is_active || is_channel_passive(ch_info) ||
361 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) 359 (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
362 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; 360 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
363 else 361 else
364 scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE; 362 scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
@@ -405,7 +403,7 @@ void iwl_init_scan_params(struct iwl_priv *priv)
405 priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx; 403 priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx;
406} 404}
407 405
408int iwl_scan_initiate(struct iwl_priv *priv) 406static int iwl_scan_initiate(struct iwl_priv *priv)
409{ 407{
410 if (!iwl_is_ready_rf(priv)) { 408 if (!iwl_is_ready_rf(priv)) {
411 IWL_DEBUG_SCAN(priv, "Aborting scan due to not ready.\n"); 409 IWL_DEBUG_SCAN(priv, "Aborting scan due to not ready.\n");
@@ -423,10 +421,6 @@ int iwl_scan_initiate(struct iwl_priv *priv)
423 } 421 }
424 422
425 IWL_DEBUG_INFO(priv, "Starting scan...\n"); 423 IWL_DEBUG_INFO(priv, "Starting scan...\n");
426 if (priv->cfg->sku & IWL_SKU_G)
427 priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
428 if (priv->cfg->sku & IWL_SKU_A)
429 priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
430 set_bit(STATUS_SCANNING, &priv->status); 424 set_bit(STATUS_SCANNING, &priv->status);
431 priv->scan_start = jiffies; 425 priv->scan_start = jiffies;
432 priv->scan_pass_start = priv->scan_start; 426 priv->scan_pass_start = priv->scan_start;
@@ -435,7 +429,6 @@ int iwl_scan_initiate(struct iwl_priv *priv)
435 429
436 return 0; 430 return 0;
437} 431}
438EXPORT_SYMBOL(iwl_scan_initiate);
439 432
440#define IWL_DELAY_NEXT_SCAN (HZ*2) 433#define IWL_DELAY_NEXT_SCAN (HZ*2)
441 434
@@ -444,7 +437,7 @@ int iwl_mac_hw_scan(struct ieee80211_hw *hw,
444{ 437{
445 unsigned long flags; 438 unsigned long flags;
446 struct iwl_priv *priv = hw->priv; 439 struct iwl_priv *priv = hw->priv;
447 int ret; 440 int ret, i;
448 441
449 IWL_DEBUG_MAC80211(priv, "enter\n"); 442 IWL_DEBUG_MAC80211(priv, "enter\n");
450 443
@@ -478,6 +471,10 @@ int iwl_mac_hw_scan(struct ieee80211_hw *hw,
478 goto out_unlock; 471 goto out_unlock;
479 } 472 }
480 473
474 priv->scan_bands = 0;
475 for (i = 0; i < req->n_channels; i++)
476 priv->scan_bands |= BIT(req->channels[i]->band);
477
481 priv->scan_request = req; 478 priv->scan_request = req;
482 479
483 ret = iwl_scan_initiate(priv); 480 ret = iwl_scan_initiate(priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index 85ae7a62109c..753fca32d9df 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -348,6 +348,10 @@ int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq,
348 348
349 txq->need_update = 0; 349 txq->need_update = 0;
350 350
351 /* aggregation TX queues will get their ID when aggregation begins */
352 if (txq_id <= IWL_TX_FIFO_AC3)
353 txq->swq_id = txq_id;
354
351 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise 355 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
352 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ 356 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
353 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); 357 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
@@ -734,8 +738,7 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
734 738
735 IWL_DEBUG_TX(priv, "station Id %d\n", sta_id); 739 IWL_DEBUG_TX(priv, "station Id %d\n", sta_id);
736 740
737 swq_id = skb_get_queue_mapping(skb); 741 txq_id = skb_get_queue_mapping(skb);
738 txq_id = swq_id;
739 if (ieee80211_is_data_qos(fc)) { 742 if (ieee80211_is_data_qos(fc)) {
740 qc = ieee80211_get_qos_ctl(hdr); 743 qc = ieee80211_get_qos_ctl(hdr);
741 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 744 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
@@ -746,16 +749,14 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
746 hdr->seq_ctrl |= cpu_to_le16(seq_number); 749 hdr->seq_ctrl |= cpu_to_le16(seq_number);
747 seq_number += 0x10; 750 seq_number += 0x10;
748 /* aggregation is on for this <sta,tid> */ 751 /* aggregation is on for this <sta,tid> */
749 if (info->flags & IEEE80211_TX_CTL_AMPDU) { 752 if (info->flags & IEEE80211_TX_CTL_AMPDU)
750 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; 753 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
751 swq_id = iwl_virtual_agg_queue_num(swq_id, txq_id);
752 }
753 priv->stations[sta_id].tid[tid].tfds_in_queue++; 754 priv->stations[sta_id].tid[tid].tfds_in_queue++;
754 } 755 }
755 756
756 txq = &priv->txq[txq_id]; 757 txq = &priv->txq[txq_id];
758 swq_id = txq->swq_id;
757 q = &txq->q; 759 q = &txq->q;
758 txq->swq_id = swq_id;
759 760
760 spin_lock_irqsave(&priv->lock, flags); 761 spin_lock_irqsave(&priv->lock, flags);
761 762
@@ -1108,7 +1109,7 @@ void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1108 txq_id, sequence, 1109 txq_id, sequence,
1109 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr, 1110 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1110 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) { 1111 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1111 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32); 1112 iwl_print_hex_error(priv, rxb, 32);
1112 return; 1113 return;
1113 } 1114 }
1114 1115
@@ -1186,6 +1187,7 @@ int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
1186 tid_data = &priv->stations[sta_id].tid[tid]; 1187 tid_data = &priv->stations[sta_id].tid[tid];
1187 *ssn = SEQ_TO_SN(tid_data->seq_number); 1188 *ssn = SEQ_TO_SN(tid_data->seq_number);
1188 tid_data->agg.txq_id = txq_id; 1189 tid_data->agg.txq_id = txq_id;
1190 priv->txq[txq_id].swq_id = iwl_virtual_agg_queue_num(tx_fifo, txq_id);
1189 spin_unlock_irqrestore(&priv->sta_lock, flags); 1191 spin_unlock_irqrestore(&priv->sta_lock, flags);
1190 1192
1191 ret = priv->cfg->ops->lib->txq_agg_enable(priv, txq_id, tx_fifo, 1193 ret = priv->cfg->ops->lib->txq_agg_enable(priv, txq_id, tx_fifo,
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index cb9bd4c8f25e..303c4b483f5b 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -361,76 +361,6 @@ static void iwl3945_unset_hw_params(struct iwl_priv *priv)
361 priv->shared_phys); 361 priv->shared_phys);
362} 362}
363 363
364#define MAX_UCODE_BEACON_INTERVAL 1024
365#define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
366
367static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
368{
369 u16 new_val = 0;
370 u16 beacon_factor = 0;
371
372 beacon_factor =
373 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
374 / MAX_UCODE_BEACON_INTERVAL;
375 new_val = beacon_val / beacon_factor;
376
377 return cpu_to_le16(new_val);
378}
379
380static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
381{
382 u64 interval_tm_unit;
383 u64 tsf, result;
384 unsigned long flags;
385 struct ieee80211_conf *conf = NULL;
386 u16 beacon_int = 0;
387
388 conf = ieee80211_get_hw_conf(priv->hw);
389
390 spin_lock_irqsave(&priv->lock, flags);
391 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
392 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
393
394 tsf = priv->timestamp;
395
396 beacon_int = priv->beacon_int;
397 spin_unlock_irqrestore(&priv->lock, flags);
398
399 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
400 if (beacon_int == 0) {
401 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
402 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
403 } else {
404 priv->rxon_timing.beacon_interval =
405 cpu_to_le16(beacon_int);
406 priv->rxon_timing.beacon_interval =
407 iwl3945_adjust_beacon_interval(
408 le16_to_cpu(priv->rxon_timing.beacon_interval));
409 }
410
411 priv->rxon_timing.atim_window = 0;
412 } else {
413 priv->rxon_timing.beacon_interval =
414 iwl3945_adjust_beacon_interval(
415 priv->vif->bss_conf.beacon_int);
416 /* TODO: we need to get atim_window from upper stack
417 * for now we set to 0 */
418 priv->rxon_timing.atim_window = 0;
419 }
420
421 interval_tm_unit =
422 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
423 result = do_div(tsf, interval_tm_unit);
424 priv->rxon_timing.beacon_init_val =
425 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
426
427 IWL_DEBUG_ASSOC(priv,
428 "beacon interval %d beacon timer %d beacon tim %d\n",
429 le16_to_cpu(priv->rxon_timing.beacon_interval),
430 le32_to_cpu(priv->rxon_timing.beacon_init_val),
431 le16_to_cpu(priv->rxon_timing.atim_window));
432}
433
434static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv, 364static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
435 struct ieee80211_tx_info *info, 365 struct ieee80211_tx_info *info,
436 struct iwl_cmd *cmd, 366 struct iwl_cmd *cmd,
@@ -1844,7 +1774,7 @@ static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
1844 u8 is_active, u8 n_probes, 1774 u8 is_active, u8 n_probes,
1845 struct iwl3945_scan_channel *scan_ch) 1775 struct iwl3945_scan_channel *scan_ch)
1846{ 1776{
1847 const struct ieee80211_channel *channels = NULL; 1777 struct ieee80211_channel *chan;
1848 const struct ieee80211_supported_band *sband; 1778 const struct ieee80211_supported_band *sband;
1849 const struct iwl_channel_info *ch_info; 1779 const struct iwl_channel_info *ch_info;
1850 u16 passive_dwell = 0; 1780 u16 passive_dwell = 0;
@@ -1855,19 +1785,19 @@ static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
1855 if (!sband) 1785 if (!sband)
1856 return 0; 1786 return 0;
1857 1787
1858 channels = sband->channels;
1859
1860 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes); 1788 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
1861 passive_dwell = iwl_get_passive_dwell_time(priv, band); 1789 passive_dwell = iwl_get_passive_dwell_time(priv, band);
1862 1790
1863 if (passive_dwell <= active_dwell) 1791 if (passive_dwell <= active_dwell)
1864 passive_dwell = active_dwell + 1; 1792 passive_dwell = active_dwell + 1;
1865 1793
1866 for (i = 0, added = 0; i < sband->n_channels; i++) { 1794 for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
1867 if (channels[i].flags & IEEE80211_CHAN_DISABLED) 1795 chan = priv->scan_request->channels[i];
1796
1797 if (chan->band != band)
1868 continue; 1798 continue;
1869 1799
1870 scan_ch->channel = channels[i].hw_value; 1800 scan_ch->channel = chan->hw_value;
1871 1801
1872 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel); 1802 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
1873 if (!is_channel_valid(ch_info)) { 1803 if (!is_channel_valid(ch_info)) {
@@ -1882,7 +1812,7 @@ static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
1882 * and use long active_dwell time. 1812 * and use long active_dwell time.
1883 */ 1813 */
1884 if (!is_active || is_channel_passive(ch_info) || 1814 if (!is_active || is_channel_passive(ch_info) ||
1885 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) { 1815 (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
1886 scan_ch->type = 0; /* passive */ 1816 scan_ch->type = 0; /* passive */
1887 if (IWL_UCODE_API(priv->ucode_ver) == 1) 1817 if (IWL_UCODE_API(priv->ucode_ver) == 1)
1888 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1); 1818 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
@@ -3066,7 +2996,7 @@ void iwl3945_post_associate(struct iwl_priv *priv)
3066 iwlcore_commit_rxon(priv); 2996 iwlcore_commit_rxon(priv);
3067 2997
3068 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); 2998 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
3069 iwl3945_setup_rxon_timing(priv); 2999 iwl_setup_rxon_timing(priv);
3070 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, 3000 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3071 sizeof(priv->rxon_timing), &priv->rxon_timing); 3001 sizeof(priv->rxon_timing), &priv->rxon_timing);
3072 if (rc) 3002 if (rc)
@@ -3261,7 +3191,7 @@ void iwl3945_config_ap(struct iwl_priv *priv)
3261 3191
3262 /* RXON Timing */ 3192 /* RXON Timing */
3263 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); 3193 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
3264 iwl3945_setup_rxon_timing(priv); 3194 iwl_setup_rxon_timing(priv);
3265 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, 3195 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3266 sizeof(priv->rxon_timing), 3196 sizeof(priv->rxon_timing),
3267 &priv->rxon_timing); 3197 &priv->rxon_timing);
diff --git a/drivers/net/wireless/iwmc3200wifi/cfg80211.c b/drivers/net/wireless/iwmc3200wifi/cfg80211.c
index 96f714e6e12b..54bebba8e27e 100644
--- a/drivers/net/wireless/iwmc3200wifi/cfg80211.c
+++ b/drivers/net/wireless/iwmc3200wifi/cfg80211.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/netdevice.h> 25#include <linux/netdevice.h>
26#include <linux/etherdevice.h>
26#include <linux/wireless.h> 27#include <linux/wireless.h>
27#include <linux/ieee80211.h> 28#include <linux/ieee80211.h>
28#include <net/cfg80211.h> 29#include <net/cfg80211.h>
@@ -130,6 +131,181 @@ static struct ieee80211_supported_band iwm_band_5ghz = {
130 .n_bitrates = iwm_a_rates_size, 131 .n_bitrates = iwm_a_rates_size,
131}; 132};
132 133
134static int iwm_key_init(struct iwm_key *key, u8 key_index,
135 const u8 *mac_addr, struct key_params *params)
136{
137 key->hdr.key_idx = key_index;
138 if (!mac_addr || is_broadcast_ether_addr(mac_addr)) {
139 key->hdr.multicast = 1;
140 memset(key->hdr.mac, 0xff, ETH_ALEN);
141 } else {
142 key->hdr.multicast = 0;
143 memcpy(key->hdr.mac, mac_addr, ETH_ALEN);
144 }
145
146 if (params) {
147 if (params->key_len > WLAN_MAX_KEY_LEN ||
148 params->seq_len > IW_ENCODE_SEQ_MAX_SIZE)
149 return -EINVAL;
150
151 key->cipher = params->cipher;
152 key->key_len = params->key_len;
153 key->seq_len = params->seq_len;
154 memcpy(key->key, params->key, key->key_len);
155 memcpy(key->seq, params->seq, key->seq_len);
156 }
157
158 return 0;
159}
160
161static int iwm_reset_profile(struct iwm_priv *iwm)
162{
163 int ret;
164
165 if (!iwm->umac_profile_active)
166 return 0;
167
168 /*
169 * If there is a current active profile, but no
170 * default key, it's not worth trying to associate again.
171 */
172 if (iwm->default_key < 0)
173 return 0;
174
175 /*
176 * Here we have an active profile, but a key setting changed.
177 * We thus have to invalidate the current profile, and push the
178 * new one. Keys will be pushed when association takes place.
179 */
180 ret = iwm_invalidate_mlme_profile(iwm);
181 if (ret < 0) {
182 IWM_ERR(iwm, "Couldn't invalidate profile\n");
183 return ret;
184 }
185
186 return iwm_send_mlme_profile(iwm);
187}
188
189static int iwm_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
190 u8 key_index, const u8 *mac_addr,
191 struct key_params *params)
192{
193 struct iwm_priv *iwm = ndev_to_iwm(ndev);
194 struct iwm_key *key = &iwm->keys[key_index];
195 int ret;
196
197 IWM_DBG_WEXT(iwm, DBG, "Adding key for %pM\n", mac_addr);
198
199 memset(key, 0, sizeof(struct iwm_key));
200 ret = iwm_key_init(key, key_index, mac_addr, params);
201 if (ret < 0) {
202 IWM_ERR(iwm, "Invalid key_params\n");
203 return ret;
204 }
205
206 /*
207 * The WEP keys can be set before or after setting the essid.
208 * We need to handle both cases by simply pushing the keys after
209 * we send the profile.
210 * If the profile is not set yet (i.e. we're pushing keys before
211 * the essid), we set the cipher appropriately.
212 * If the profile is set, we havent associated yet because our
213 * cipher was incorrectly set. So we invalidate and send the
214 * profile again.
215 */
216 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
217 key->cipher == WLAN_CIPHER_SUITE_WEP104) {
218 u8 *ucast_cipher = &iwm->umac_profile->sec.ucast_cipher;
219 u8 *mcast_cipher = &iwm->umac_profile->sec.mcast_cipher;
220
221 IWM_DBG_WEXT(iwm, DBG, "WEP key\n");
222
223 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
224 *ucast_cipher = *mcast_cipher = UMAC_CIPHER_TYPE_WEP_40;
225 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
226 *ucast_cipher = *mcast_cipher =
227 UMAC_CIPHER_TYPE_WEP_104;
228
229 return iwm_reset_profile(iwm);
230 }
231
232 return iwm_set_key(iwm, 0, key);
233}
234
235static int iwm_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
236 u8 key_index, const u8 *mac_addr, void *cookie,
237 void (*callback)(void *cookie,
238 struct key_params*))
239{
240 struct iwm_priv *iwm = ndev_to_iwm(ndev);
241 struct iwm_key *key = &iwm->keys[key_index];
242 struct key_params params;
243
244 IWM_DBG_WEXT(iwm, DBG, "Getting key %d\n", key_index);
245
246 memset(&params, 0, sizeof(params));
247
248 params.cipher = key->cipher;
249 params.key_len = key->key_len;
250 params.seq_len = key->seq_len;
251 params.seq = key->seq;
252 params.key = key->key;
253
254 callback(cookie, &params);
255
256 return key->key_len ? 0 : -ENOENT;
257}
258
259
260static int iwm_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
261 u8 key_index, const u8 *mac_addr)
262{
263 struct iwm_priv *iwm = ndev_to_iwm(ndev);
264 struct iwm_key *key = &iwm->keys[key_index];
265
266 if (!iwm->keys[key_index].key_len) {
267 IWM_DBG_WEXT(iwm, DBG, "Key %d not used\n", key_index);
268 return 0;
269 }
270
271 if (key_index == iwm->default_key)
272 iwm->default_key = -1;
273
274 /* If the interface is down, we just cache this */
275 if (!test_bit(IWM_STATUS_READY, &iwm->status))
276 return 0;
277
278 return iwm_set_key(iwm, 1, key);
279}
280
281static int iwm_cfg80211_set_default_key(struct wiphy *wiphy,
282 struct net_device *ndev,
283 u8 key_index)
284{
285 struct iwm_priv *iwm = ndev_to_iwm(ndev);
286 int ret;
287
288 IWM_DBG_WEXT(iwm, DBG, "Default key index is: %d\n", key_index);
289
290 if (!iwm->keys[key_index].key_len) {
291 IWM_ERR(iwm, "Key %d not used\n", key_index);
292 return -EINVAL;
293 }
294
295 iwm->default_key = key_index;
296
297 /* If the interface is down, we just cache this */
298 if (!test_bit(IWM_STATUS_READY, &iwm->status))
299 return 0;
300
301 ret = iwm_set_tx_key(iwm, key_index);
302 if (ret < 0)
303 return ret;
304
305 return iwm_reset_profile(iwm);
306}
307
308
133int iwm_cfg80211_inform_bss(struct iwm_priv *iwm) 309int iwm_cfg80211_inform_bss(struct iwm_priv *iwm)
134{ 310{
135 struct wiphy *wiphy = iwm_to_wiphy(iwm); 311 struct wiphy *wiphy = iwm_to_wiphy(iwm);
@@ -167,20 +343,15 @@ int iwm_cfg80211_inform_bss(struct iwm_priv *iwm)
167 return 0; 343 return 0;
168} 344}
169 345
170static int iwm_cfg80211_change_iface(struct wiphy *wiphy, int ifindex, 346static int iwm_cfg80211_change_iface(struct wiphy *wiphy,
347 struct net_device *ndev,
171 enum nl80211_iftype type, u32 *flags, 348 enum nl80211_iftype type, u32 *flags,
172 struct vif_params *params) 349 struct vif_params *params)
173{ 350{
174 struct net_device *ndev;
175 struct wireless_dev *wdev; 351 struct wireless_dev *wdev;
176 struct iwm_priv *iwm; 352 struct iwm_priv *iwm;
177 u32 old_mode; 353 u32 old_mode;
178 354
179 /* we're under RTNL */
180 ndev = __dev_get_by_index(&init_net, ifindex);
181 if (!ndev)
182 return -ENODEV;
183
184 wdev = ndev->ieee80211_ptr; 355 wdev = ndev->ieee80211_ptr;
185 iwm = ndev_to_iwm(ndev); 356 iwm = ndev_to_iwm(ndev);
186 old_mode = iwm->conf.mode; 357 old_mode = iwm->conf.mode;
@@ -329,12 +500,62 @@ static int iwm_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
329 return 0; 500 return 0;
330} 501}
331 502
503static int iwm_cfg80211_set_txpower(struct wiphy *wiphy,
504 enum tx_power_setting type, int dbm)
505{
506 switch (type) {
507 case TX_POWER_AUTOMATIC:
508 return 0;
509 default:
510 return -EOPNOTSUPP;
511 }
512
513 return 0;
514}
515
516static int iwm_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm)
517{
518 struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
519
520 *dbm = iwm->txpower;
521
522 return 0;
523}
524
525static int iwm_cfg80211_set_power_mgmt(struct wiphy *wiphy,
526 struct net_device *dev,
527 bool enabled, int timeout)
528{
529 struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
530 u32 power_index;
531
532 if (enabled)
533 power_index = IWM_POWER_INDEX_DEFAULT;
534 else
535 power_index = IWM_POWER_INDEX_MIN;
536
537 if (power_index == iwm->conf.power_index)
538 return 0;
539
540 iwm->conf.power_index = power_index;
541
542 return iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
543 CFG_POWER_INDEX, iwm->conf.power_index);
544}
545
332static struct cfg80211_ops iwm_cfg80211_ops = { 546static struct cfg80211_ops iwm_cfg80211_ops = {
333 .change_virtual_intf = iwm_cfg80211_change_iface, 547 .change_virtual_intf = iwm_cfg80211_change_iface,
548 .add_key = iwm_cfg80211_add_key,
549 .get_key = iwm_cfg80211_get_key,
550 .del_key = iwm_cfg80211_del_key,
551 .set_default_key = iwm_cfg80211_set_default_key,
334 .scan = iwm_cfg80211_scan, 552 .scan = iwm_cfg80211_scan,
335 .set_wiphy_params = iwm_cfg80211_set_wiphy_params, 553 .set_wiphy_params = iwm_cfg80211_set_wiphy_params,
336 .join_ibss = iwm_cfg80211_join_ibss, 554 .join_ibss = iwm_cfg80211_join_ibss,
337 .leave_ibss = iwm_cfg80211_leave_ibss, 555 .leave_ibss = iwm_cfg80211_leave_ibss,
556 .set_tx_power = iwm_cfg80211_set_txpower,
557 .get_tx_power = iwm_cfg80211_get_txpower,
558 .set_power_mgmt = iwm_cfg80211_set_power_mgmt,
338}; 559};
339 560
340struct wireless_dev *iwm_wdev_alloc(int sizeof_bus, struct device *dev) 561struct wireless_dev *iwm_wdev_alloc(int sizeof_bus, struct device *dev)
diff --git a/drivers/net/wireless/iwmc3200wifi/commands.c b/drivers/net/wireless/iwmc3200wifi/commands.c
index 834a7f544e5d..0d35afefb61c 100644
--- a/drivers/net/wireless/iwmc3200wifi/commands.c
+++ b/drivers/net/wireless/iwmc3200wifi/commands.c
@@ -70,14 +70,28 @@ static int iwm_send_lmac_ptrough_cmd(struct iwm_priv *iwm,
70int iwm_send_wifi_if_cmd(struct iwm_priv *iwm, void *payload, u16 payload_size, 70int iwm_send_wifi_if_cmd(struct iwm_priv *iwm, void *payload, u16 payload_size,
71 bool resp) 71 bool resp)
72{ 72{
73 struct iwm_umac_wifi_if *hdr = (struct iwm_umac_wifi_if *)payload;
73 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT; 74 struct iwm_udma_wifi_cmd udma_cmd = UDMA_UMAC_INIT;
74 struct iwm_umac_cmd umac_cmd; 75 struct iwm_umac_cmd umac_cmd;
76 int ret;
77 u8 oid = hdr->oid;
75 78
76 umac_cmd.id = UMAC_CMD_OPCODE_WIFI_IF_WRAPPER; 79 umac_cmd.id = UMAC_CMD_OPCODE_WIFI_IF_WRAPPER;
77 umac_cmd.resp = resp; 80 umac_cmd.resp = resp;
78 81
79 return iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd, 82 ret = iwm_hal_send_umac_cmd(iwm, &udma_cmd, &umac_cmd,
80 payload, payload_size); 83 payload, payload_size);
84
85 if (resp) {
86 ret = wait_event_interruptible_timeout(iwm->wifi_ntfy_queue,
87 test_and_clear_bit(oid, &iwm->wifi_ntfy[0]),
88 3 * HZ);
89
90 if (!ret)
91 ret = -EBUSY;
92 }
93
94 return ret;
81} 95}
82 96
83static struct coex_event iwm_sta_xor_prio_tbl[COEX_EVENTS_NUM] = 97static struct coex_event iwm_sta_xor_prio_tbl[COEX_EVENTS_NUM] =
@@ -106,7 +120,7 @@ static struct coex_event iwm_sta_cm_prio_tbl[COEX_EVENTS_NUM] =
106 {4, 3, 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS}, 120 {4, 3, 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
107 {3, 3, 0, COEX_UNASSOC_AUTO_SCAN_FLAGS}, 121 {3, 3, 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
108 {5, 5, 0, COEX_CALIBRATION_FLAGS}, 122 {5, 5, 0, COEX_CALIBRATION_FLAGS},
109 {4, 4, 0, COEX_PERIODIC_CALIBRATION_FLAGS}, 123 {3, 3, 0, COEX_PERIODIC_CALIBRATION_FLAGS},
110 {5, 4, 0, COEX_CONNECTION_ESTAB_FLAGS}, 124 {5, 4, 0, COEX_CONNECTION_ESTAB_FLAGS},
111 {4, 4, 0, COEX_ASSOCIATED_IDLE_FLAGS}, 125 {4, 4, 0, COEX_ASSOCIATED_IDLE_FLAGS},
112 {4, 4, 0, COEX_ASSOC_MANUAL_SCAN_FLAGS}, 126 {4, 4, 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
@@ -331,8 +345,7 @@ int iwm_umac_set_config_var(struct iwm_priv *iwm, u16 key,
331 return ret; 345 return ret;
332} 346}
333 347
334int iwm_send_umac_config(struct iwm_priv *iwm, 348int iwm_send_umac_config(struct iwm_priv *iwm, __le32 reset_flags)
335 __le32 reset_flags)
336{ 349{
337 int ret; 350 int ret;
338 351
@@ -360,6 +373,12 @@ int iwm_send_umac_config(struct iwm_priv *iwm,
360 return ret; 373 return ret;
361 374
362 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, 375 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
376 CFG_WIRELESS_MODE,
377 iwm->conf.wireless_mode);
378 if (ret < 0)
379 return ret;
380
381 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
363 CFG_COEX_MODE, iwm->conf.coexist_mode); 382 CFG_COEX_MODE, iwm->conf.coexist_mode);
364 if (ret < 0) 383 if (ret < 0)
365 return ret; 384 return ret;
@@ -401,7 +420,7 @@ int iwm_send_umac_config(struct iwm_priv *iwm,
401 return ret; 420 return ret;
402 421
403 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, 422 ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
404 CFG_PM_CTRL_FLAGS, 0x30001); 423 CFG_PM_CTRL_FLAGS, 0x1);
405 if (ret < 0) 424 if (ret < 0)
406 return ret; 425 return ret;
407 426
@@ -510,9 +529,6 @@ int iwm_set_tx_key(struct iwm_priv *iwm, u8 key_idx)
510{ 529{
511 struct iwm_umac_tx_key_id tx_key_id; 530 struct iwm_umac_tx_key_id tx_key_id;
512 531
513 if (!iwm->default_key || !iwm->default_key->in_use)
514 return -EINVAL;
515
516 tx_key_id.hdr.oid = UMAC_WIFI_IF_CMD_GLOBAL_TX_KEY_ID; 532 tx_key_id.hdr.oid = UMAC_WIFI_IF_CMD_GLOBAL_TX_KEY_ID;
517 tx_key_id.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_tx_key_id) - 533 tx_key_id.hdr.buf_size = cpu_to_le16(sizeof(struct iwm_umac_tx_key_id) -
518 sizeof(struct iwm_umac_wifi_if)); 534 sizeof(struct iwm_umac_wifi_if));
@@ -555,10 +571,9 @@ static int iwm_check_profile(struct iwm_priv *iwm)
555 return 0; 571 return 0;
556} 572}
557 573
558int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key, 574int iwm_set_key(struct iwm_priv *iwm, bool remove, struct iwm_key *key)
559 struct iwm_key *key)
560{ 575{
561 int ret; 576 int ret = 0;
562 u8 cmd[64], *sta_addr, *key_data, key_len; 577 u8 cmd[64], *sta_addr, *key_data, key_len;
563 s8 key_idx; 578 s8 key_idx;
564 u16 cmd_size = 0; 579 u16 cmd_size = 0;
@@ -568,9 +583,6 @@ int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
568 struct iwm_umac_key_tkip *tkip = (struct iwm_umac_key_tkip *)cmd; 583 struct iwm_umac_key_tkip *tkip = (struct iwm_umac_key_tkip *)cmd;
569 struct iwm_umac_key_ccmp *ccmp = (struct iwm_umac_key_ccmp *)cmd; 584 struct iwm_umac_key_ccmp *ccmp = (struct iwm_umac_key_ccmp *)cmd;
570 585
571 if (set_tx_key)
572 iwm->default_key = key;
573
574 /* 586 /*
575 * We check if our current profile is valid. 587 * We check if our current profile is valid.
576 * If not, we dont push the key, we just cache them, 588 * If not, we dont push the key, we just cache them,
@@ -589,8 +601,7 @@ int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
589 key_idx = key->hdr.key_idx; 601 key_idx = key->hdr.key_idx;
590 602
591 if (!remove) { 603 if (!remove) {
592 IWM_DBG_WEXT(iwm, DBG, "key_idx:%d set tx key:%d\n", 604 IWM_DBG_WEXT(iwm, DBG, "key_idx:%d\n", key_idx);
593 key_idx, set_tx_key);
594 IWM_DBG_WEXT(iwm, DBG, "key_len:%d\n", key_len); 605 IWM_DBG_WEXT(iwm, DBG, "key_len:%d\n", key_len);
595 IWM_DBG_WEXT(iwm, DBG, "MAC:%pM, idx:%d, multicast:%d\n", 606 IWM_DBG_WEXT(iwm, DBG, "MAC:%pM, idx:%d, multicast:%d\n",
596 key_hdr->mac, key_hdr->key_idx, key_hdr->multicast); 607 key_hdr->mac, key_hdr->key_idx, key_hdr->multicast);
@@ -602,8 +613,8 @@ int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
602 iwm->umac_profile->sec.auth_type, 613 iwm->umac_profile->sec.auth_type,
603 iwm->umac_profile->sec.flags); 614 iwm->umac_profile->sec.flags);
604 615
605 switch (key->alg) { 616 switch (key->cipher) {
606 case UMAC_CIPHER_TYPE_WEP_40: 617 case WLAN_CIPHER_SUITE_WEP40:
607 wep40->hdr.oid = UMAC_WIFI_IF_CMD_ADD_WEP40_KEY; 618 wep40->hdr.oid = UMAC_WIFI_IF_CMD_ADD_WEP40_KEY;
608 wep40->hdr.buf_size = 619 wep40->hdr.buf_size =
609 cpu_to_le16(sizeof(struct iwm_umac_key_wep40) - 620 cpu_to_le16(sizeof(struct iwm_umac_key_wep40) -
@@ -617,7 +628,7 @@ int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
617 cmd_size = sizeof(struct iwm_umac_key_wep40); 628 cmd_size = sizeof(struct iwm_umac_key_wep40);
618 break; 629 break;
619 630
620 case UMAC_CIPHER_TYPE_WEP_104: 631 case WLAN_CIPHER_SUITE_WEP104:
621 wep104->hdr.oid = UMAC_WIFI_IF_CMD_ADD_WEP104_KEY; 632 wep104->hdr.oid = UMAC_WIFI_IF_CMD_ADD_WEP104_KEY;
622 wep104->hdr.buf_size = 633 wep104->hdr.buf_size =
623 cpu_to_le16(sizeof(struct iwm_umac_key_wep104) - 634 cpu_to_le16(sizeof(struct iwm_umac_key_wep104) -
@@ -631,7 +642,7 @@ int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
631 cmd_size = sizeof(struct iwm_umac_key_wep104); 642 cmd_size = sizeof(struct iwm_umac_key_wep104);
632 break; 643 break;
633 644
634 case UMAC_CIPHER_TYPE_CCMP: 645 case WLAN_CIPHER_SUITE_CCMP:
635 key_hdr->key_idx++; 646 key_hdr->key_idx++;
636 ccmp->hdr.oid = UMAC_WIFI_IF_CMD_ADD_CCMP_KEY; 647 ccmp->hdr.oid = UMAC_WIFI_IF_CMD_ADD_CCMP_KEY;
637 ccmp->hdr.buf_size = 648 ccmp->hdr.buf_size =
@@ -643,13 +654,13 @@ int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
643 654
644 memcpy(ccmp->key, key_data, key_len); 655 memcpy(ccmp->key, key_data, key_len);
645 656
646 if (key->flags & IW_ENCODE_EXT_RX_SEQ_VALID) 657 if (key->seq_len)
647 memcpy(ccmp->iv_count, key->rx_seq, 6); 658 memcpy(ccmp->iv_count, key->seq, key->seq_len);
648 659
649 cmd_size = sizeof(struct iwm_umac_key_ccmp); 660 cmd_size = sizeof(struct iwm_umac_key_ccmp);
650 break; 661 break;
651 662
652 case UMAC_CIPHER_TYPE_TKIP: 663 case WLAN_CIPHER_SUITE_TKIP:
653 key_hdr->key_idx++; 664 key_hdr->key_idx++;
654 tkip->hdr.oid = UMAC_WIFI_IF_CMD_ADD_TKIP_KEY; 665 tkip->hdr.oid = UMAC_WIFI_IF_CMD_ADD_TKIP_KEY;
655 tkip->hdr.buf_size = 666 tkip->hdr.buf_size =
@@ -666,8 +677,8 @@ int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
666 key_data + IWM_TKIP_KEY_SIZE + IWM_TKIP_MIC_SIZE, 677 key_data + IWM_TKIP_KEY_SIZE + IWM_TKIP_MIC_SIZE,
667 IWM_TKIP_MIC_SIZE); 678 IWM_TKIP_MIC_SIZE);
668 679
669 if (key->flags & IW_ENCODE_EXT_RX_SEQ_VALID) 680 if (key->seq_len)
670 memcpy(ccmp->iv_count, key->rx_seq, 6); 681 memcpy(ccmp->iv_count, key->seq, key->seq_len);
671 682
672 cmd_size = sizeof(struct iwm_umac_key_tkip); 683 cmd_size = sizeof(struct iwm_umac_key_tkip);
673 break; 684 break;
@@ -676,8 +687,8 @@ int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
676 return -ENOTSUPP; 687 return -ENOTSUPP;
677 } 688 }
678 689
679 if ((key->alg == UMAC_CIPHER_TYPE_CCMP) || 690 if ((key->cipher == WLAN_CIPHER_SUITE_TKIP) ||
680 (key->alg == UMAC_CIPHER_TYPE_TKIP)) 691 (key->cipher == WLAN_CIPHER_SUITE_CCMP))
681 /* 692 /*
682 * UGLY_UGLY_UGLY 693 * UGLY_UGLY_UGLY
683 * Copied HACK from the MWG driver. 694 * Copied HACK from the MWG driver.
@@ -688,23 +699,11 @@ int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
688 schedule_timeout_interruptible(usecs_to_jiffies(300)); 699 schedule_timeout_interruptible(usecs_to_jiffies(300));
689 700
690 ret = iwm_send_wifi_if_cmd(iwm, cmd, cmd_size, 1); 701 ret = iwm_send_wifi_if_cmd(iwm, cmd, cmd_size, 1);
691 if (ret < 0)
692 goto err;
693
694 /*
695 * We need a default key only if it is set and
696 * if we're doing WEP.
697 */
698 if (iwm->default_key == key &&
699 ((key->alg == UMAC_CIPHER_TYPE_WEP_40) ||
700 (key->alg == UMAC_CIPHER_TYPE_WEP_104))) {
701 ret = iwm_set_tx_key(iwm, key_idx);
702 if (ret < 0)
703 goto err;
704 }
705 } else { 702 } else {
706 struct iwm_umac_key_remove key_remove; 703 struct iwm_umac_key_remove key_remove;
707 704
705 IWM_DBG_WEXT(iwm, ERR, "Removing key_idx:%d\n", key_idx);
706
708 key_remove.hdr.oid = UMAC_WIFI_IF_CMD_REMOVE_KEY; 707 key_remove.hdr.oid = UMAC_WIFI_IF_CMD_REMOVE_KEY;
709 key_remove.hdr.buf_size = 708 key_remove.hdr.buf_size =
710 cpu_to_le16(sizeof(struct iwm_umac_key_remove) - 709 cpu_to_le16(sizeof(struct iwm_umac_key_remove) -
@@ -718,13 +717,9 @@ int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key,
718 if (ret < 0) 717 if (ret < 0)
719 return ret; 718 return ret;
720 719
721 iwm->keys[key_idx].in_use = 0; 720 iwm->keys[key_idx].key_len = 0;
722 } 721 }
723 722
724 return 0;
725
726 err:
727 kfree(key);
728 return ret; 723 return ret;
729} 724}
730 725
@@ -746,31 +741,25 @@ int iwm_send_mlme_profile(struct iwm_priv *iwm)
746 return ret; 741 return ret;
747 } 742 }
748 743
749 /* Wait for the profile to be active */
750 ret = wait_event_interruptible_timeout(iwm->mlme_queue,
751 iwm->umac_profile_active == 1,
752 3 * HZ);
753 if (!ret)
754 return -EBUSY;
755
756
757 for (i = 0; i < IWM_NUM_KEYS; i++) 744 for (i = 0; i < IWM_NUM_KEYS; i++)
758 if (iwm->keys[i].in_use) { 745 if (iwm->keys[i].key_len) {
759 int default_key = 0;
760 struct iwm_key *key = &iwm->keys[i]; 746 struct iwm_key *key = &iwm->keys[i];
761 747
762 if (key == iwm->default_key)
763 default_key = 1;
764
765 /* Wait for the profile before sending the keys */ 748 /* Wait for the profile before sending the keys */
766 wait_event_interruptible_timeout(iwm->mlme_queue, 749 wait_event_interruptible_timeout(iwm->mlme_queue,
767 (test_bit(IWM_STATUS_ASSOCIATING, &iwm->status) || 750 (test_bit(IWM_STATUS_ASSOCIATING, &iwm->status) ||
768 test_bit(IWM_STATUS_ASSOCIATED, &iwm->status)), 751 test_bit(IWM_STATUS_ASSOCIATED, &iwm->status)),
769 3 * HZ); 752 3 * HZ);
770 753
771 ret = iwm_set_key(iwm, 0, default_key, key); 754 ret = iwm_set_key(iwm, 0, key);
772 if (ret < 0) 755 if (ret < 0)
773 return ret; 756 return ret;
757
758 if (iwm->default_key == i) {
759 ret = iwm_set_tx_key(iwm, i);
760 if (ret < 0)
761 return ret;
762 }
774 } 763 }
775 764
776 return 0; 765 return 0;
@@ -778,8 +767,8 @@ int iwm_send_mlme_profile(struct iwm_priv *iwm)
778 767
779int iwm_invalidate_mlme_profile(struct iwm_priv *iwm) 768int iwm_invalidate_mlme_profile(struct iwm_priv *iwm)
780{ 769{
781 int ret;
782 struct iwm_umac_invalidate_profile invalid; 770 struct iwm_umac_invalidate_profile invalid;
771 int ret;
783 772
784 invalid.hdr.oid = UMAC_WIFI_IF_CMD_INVALIDATE_PROFILE; 773 invalid.hdr.oid = UMAC_WIFI_IF_CMD_INVALIDATE_PROFILE;
785 invalid.hdr.buf_size = 774 invalid.hdr.buf_size =
@@ -793,8 +782,7 @@ int iwm_invalidate_mlme_profile(struct iwm_priv *iwm)
793 return ret; 782 return ret;
794 783
795 ret = wait_event_interruptible_timeout(iwm->mlme_queue, 784 ret = wait_event_interruptible_timeout(iwm->mlme_queue,
796 (iwm->umac_profile_active == 0), 785 (iwm->umac_profile_active == 0), 2 * HZ);
797 2 * HZ);
798 if (!ret) 786 if (!ret)
799 return -EBUSY; 787 return -EBUSY;
800 788
diff --git a/drivers/net/wireless/iwmc3200wifi/commands.h b/drivers/net/wireless/iwmc3200wifi/commands.h
index 36b13a130595..e24d5b633997 100644
--- a/drivers/net/wireless/iwmc3200wifi/commands.h
+++ b/drivers/net/wireless/iwmc3200wifi/commands.h
@@ -106,8 +106,7 @@ enum {
106 CFG_TLC_SPATIAL_STREAM_SUPPORTED, 106 CFG_TLC_SPATIAL_STREAM_SUPPORTED,
107 CFG_TLC_RETRY_PER_RATE, 107 CFG_TLC_RETRY_PER_RATE,
108 CFG_TLC_RETRY_PER_HT_RATE, 108 CFG_TLC_RETRY_PER_HT_RATE,
109 CFG_TLC_FIXED_RATE, 109 CFG_TLC_FIXED_MCS,
110 CFG_TLC_FIXED_RATE_FLAGS,
111 CFG_TLC_CONTROL_FLAGS, 110 CFG_TLC_CONTROL_FLAGS,
112 CFG_TLC_SR_MIN_FAIL, 111 CFG_TLC_SR_MIN_FAIL,
113 CFG_TLC_SR_MIN_PASS, 112 CFG_TLC_SR_MIN_PASS,
@@ -232,6 +231,7 @@ struct iwm_umac_cmd_get_channel_list {
232/* Wireless mode */ 231/* Wireless mode */
233#define WIRELESS_MODE_11A 0x1 232#define WIRELESS_MODE_11A 0x1
234#define WIRELESS_MODE_11G 0x2 233#define WIRELESS_MODE_11G 0x2
234#define WIRELESS_MODE_11N 0x4
235 235
236#define UMAC_PROFILE_EX_IE_REQUIRED 0x1 236#define UMAC_PROFILE_EX_IE_REQUIRED 0x1
237#define UMAC_PROFILE_QOS_ALLOWED 0x2 237#define UMAC_PROFILE_QOS_ALLOWED 0x2
@@ -406,8 +406,7 @@ int iwm_send_mlme_profile(struct iwm_priv *iwm);
406int iwm_invalidate_mlme_profile(struct iwm_priv *iwm); 406int iwm_invalidate_mlme_profile(struct iwm_priv *iwm);
407int iwm_send_packet(struct iwm_priv *iwm, struct sk_buff *skb, int pool_id); 407int iwm_send_packet(struct iwm_priv *iwm, struct sk_buff *skb, int pool_id);
408int iwm_set_tx_key(struct iwm_priv *iwm, u8 key_idx); 408int iwm_set_tx_key(struct iwm_priv *iwm, u8 key_idx);
409int iwm_set_key(struct iwm_priv *iwm, bool remove, bool set_tx_key, 409int iwm_set_key(struct iwm_priv *iwm, bool remove, struct iwm_key *key);
410 struct iwm_key *key);
411int iwm_send_umac_stats_req(struct iwm_priv *iwm, u32 flags); 410int iwm_send_umac_stats_req(struct iwm_priv *iwm, u32 flags);
412int iwm_send_umac_channel_list(struct iwm_priv *iwm); 411int iwm_send_umac_channel_list(struct iwm_priv *iwm);
413int iwm_scan_ssids(struct iwm_priv *iwm, struct cfg80211_ssid *ssids, 412int iwm_scan_ssids(struct iwm_priv *iwm, struct cfg80211_ssid *ssids,
diff --git a/drivers/net/wireless/iwmc3200wifi/eeprom.c b/drivers/net/wireless/iwmc3200wifi/eeprom.c
index 0f34b84fd2eb..365910fbe01e 100644
--- a/drivers/net/wireless/iwmc3200wifi/eeprom.c
+++ b/drivers/net/wireless/iwmc3200wifi/eeprom.c
@@ -156,10 +156,6 @@ int iwm_eeprom_init(struct iwm_priv *iwm)
156 return -ENOMEM; 156 return -ENOMEM;
157 157
158 for (i = IWM_EEPROM_FIRST; i < IWM_EEPROM_LAST; i++) { 158 for (i = IWM_EEPROM_FIRST; i < IWM_EEPROM_LAST; i++) {
159#ifdef CONFIG_IWM_B0_HW_SUPPORT
160 if (iwm->conf.hw_b0 && (i >= IWM_EEPROM_INDIRECT_OFFSET))
161 break;
162#endif
163 ret = iwm_eeprom_read(iwm, i); 159 ret = iwm_eeprom_read(iwm, i);
164 if (ret < 0) { 160 if (ret < 0) {
165 IWM_ERR(iwm, "Couldn't read eeprom entry #%d: %s\n", 161 IWM_ERR(iwm, "Couldn't read eeprom entry #%d: %s\n",
diff --git a/drivers/net/wireless/iwmc3200wifi/fw.c b/drivers/net/wireless/iwmc3200wifi/fw.c
index ec1a15a5a0e4..0f32cab9ced4 100644
--- a/drivers/net/wireless/iwmc3200wifi/fw.c
+++ b/drivers/net/wireless/iwmc3200wifi/fw.c
@@ -275,6 +275,7 @@ static int iwm_load_lmac(struct iwm_priv *iwm, const char *img_name)
275 */ 275 */
276int iwm_load_fw(struct iwm_priv *iwm) 276int iwm_load_fw(struct iwm_priv *iwm)
277{ 277{
278 unsigned long init_calib_map, periodic_calib_map;
278 int ret; 279 int ret;
279 280
280 /* We first start downloading the UMAC */ 281 /* We first start downloading the UMAC */
@@ -315,23 +316,19 @@ int iwm_load_fw(struct iwm_priv *iwm)
315 return ret; 316 return ret;
316 } 317 }
317 318
318#ifdef CONFIG_IWM_B0_HW_SUPPORT 319 init_calib_map = iwm->conf.calib_map & IWM_CALIB_MAP_INIT_MSK;
319 if (iwm->conf.hw_b0) { 320 periodic_calib_map = IWM_CALIB_MAP_PER_LMAC(iwm->conf.calib_map);
320 clear_bit(PHY_CALIBRATE_RX_IQ_CMD, &iwm->conf.init_calib_map); 321
321 clear_bit(PHY_CALIBRATE_RX_IQ_CMD,
322 &iwm->conf.periodic_calib_map);
323 }
324#endif
325 /* Read RX IQ calibration result from EEPROM */ 322 /* Read RX IQ calibration result from EEPROM */
326 if (test_bit(PHY_CALIBRATE_RX_IQ_CMD, &iwm->conf.init_calib_map)) { 323 if (test_bit(PHY_CALIBRATE_RX_IQ_CMD, &init_calib_map)) {
327 iwm_store_rxiq_calib_result(iwm); 324 iwm_store_rxiq_calib_result(iwm);
328 set_bit(PHY_CALIBRATE_RX_IQ_CMD, &iwm->calib_done_map); 325 set_bit(PHY_CALIBRATE_RX_IQ_CMD, &iwm->calib_done_map);
329 } 326 }
330 327
331 iwm_send_prio_table(iwm); 328 iwm_send_prio_table(iwm);
332 iwm_send_init_calib_cfg(iwm, iwm->conf.init_calib_map); 329 iwm_send_init_calib_cfg(iwm, init_calib_map);
333 330
334 while (iwm->calib_done_map != iwm->conf.init_calib_map) { 331 while (iwm->calib_done_map != init_calib_map) {
335 ret = iwm_notif_handle(iwm, CALIBRATION_RES_NOTIFICATION, 332 ret = iwm_notif_handle(iwm, CALIBRATION_RES_NOTIFICATION,
336 IWM_SRC_LMAC, WAIT_NOTIF_TIMEOUT); 333 IWM_SRC_LMAC, WAIT_NOTIF_TIMEOUT);
337 if (ret) { 334 if (ret) {
@@ -340,7 +337,7 @@ int iwm_load_fw(struct iwm_priv *iwm)
340 } 337 }
341 IWM_DBG_FW(iwm, DBG, "Got calibration result. calib_done_map: " 338 IWM_DBG_FW(iwm, DBG, "Got calibration result. calib_done_map: "
342 "0x%lx, requested calibrations: 0x%lx\n", 339 "0x%lx, requested calibrations: 0x%lx\n",
343 iwm->calib_done_map, iwm->conf.init_calib_map); 340 iwm->calib_done_map, init_calib_map);
344 } 341 }
345 342
346 /* Handle LMAC CALIBRATION_COMPLETE notification */ 343 /* Handle LMAC CALIBRATION_COMPLETE notification */
@@ -378,7 +375,7 @@ int iwm_load_fw(struct iwm_priv *iwm)
378 375
379 iwm_send_prio_table(iwm); 376 iwm_send_prio_table(iwm);
380 iwm_send_calib_results(iwm); 377 iwm_send_calib_results(iwm);
381 iwm_send_periodic_calib_cfg(iwm, iwm->conf.periodic_calib_map); 378 iwm_send_periodic_calib_cfg(iwm, periodic_calib_map);
382 379
383 return 0; 380 return 0;
384 381
diff --git a/drivers/net/wireless/iwmc3200wifi/iwm.h b/drivers/net/wireless/iwmc3200wifi/iwm.h
index 77c339f8516c..79d9d89d47ae 100644
--- a/drivers/net/wireless/iwmc3200wifi/iwm.h
+++ b/drivers/net/wireless/iwmc3200wifi/iwm.h
@@ -52,8 +52,6 @@
52#define IWM_COPYRIGHT "Copyright(c) 2009 Intel Corporation" 52#define IWM_COPYRIGHT "Copyright(c) 2009 Intel Corporation"
53#define IWM_AUTHOR "<ilw@linux.intel.com>" 53#define IWM_AUTHOR "<ilw@linux.intel.com>"
54 54
55#define CONFIG_IWM_B0_HW_SUPPORT 1
56
57#define IWM_SRC_LMAC UMAC_HDI_IN_SOURCE_FHRX 55#define IWM_SRC_LMAC UMAC_HDI_IN_SOURCE_FHRX
58#define IWM_SRC_UDMA UMAC_HDI_IN_SOURCE_UDMA 56#define IWM_SRC_UDMA UMAC_HDI_IN_SOURCE_UDMA
59#define IWM_SRC_UMAC UMAC_HDI_IN_SOURCE_FW 57#define IWM_SRC_UMAC UMAC_HDI_IN_SOURCE_FW
@@ -65,8 +63,7 @@
65 63
66struct iwm_conf { 64struct iwm_conf {
67 u32 sdio_ior_timeout; 65 u32 sdio_ior_timeout;
68 unsigned long init_calib_map; 66 unsigned long calib_map;
69 unsigned long periodic_calib_map;
70 bool reset_on_fatal_err; 67 bool reset_on_fatal_err;
71 bool auto_connect; 68 bool auto_connect;
72 bool wimax_not_present; 69 bool wimax_not_present;
@@ -87,9 +84,6 @@ struct iwm_conf {
87 u8 ibss_channel; 84 u8 ibss_channel;
88 85
89 u8 mac_addr[ETH_ALEN]; 86 u8 mac_addr[ETH_ALEN];
90#ifdef CONFIG_IWM_B0_HW_SUPPORT
91 bool hw_b0;
92#endif
93}; 87};
94 88
95enum { 89enum {
@@ -162,13 +156,11 @@ struct iwm_umac_key_hdr {
162 156
163struct iwm_key { 157struct iwm_key {
164 struct iwm_umac_key_hdr hdr; 158 struct iwm_umac_key_hdr hdr;
165 u8 in_use; 159 u32 cipher;
166 u8 alg; 160 u8 key[WLAN_MAX_KEY_LEN];
167 u32 flags; 161 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
168 u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; 162 int key_len;
169 u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; 163 int seq_len;
170 u8 key_len;
171 u8 key[32];
172}; 164};
173 165
174#define IWM_RX_ID_HASH 0xff 166#define IWM_RX_ID_HASH 0xff
@@ -186,10 +178,6 @@ struct iwm_key {
186#define IWM_STATUS_ASSOCIATING 3 178#define IWM_STATUS_ASSOCIATING 3
187#define IWM_STATUS_ASSOCIATED 4 179#define IWM_STATUS_ASSOCIATED 4
188 180
189#define IWM_RADIO_RFKILL_OFF 0
190#define IWM_RADIO_RFKILL_HW 1
191#define IWM_RADIO_RFKILL_SW 2
192
193struct iwm_tx_queue { 181struct iwm_tx_queue {
194 int id; 182 int id;
195 struct sk_buff_head queue; 183 struct sk_buff_head queue;
@@ -223,7 +211,6 @@ struct iwm_priv {
223 struct iwm_conf conf; 211 struct iwm_conf conf;
224 212
225 unsigned long status; 213 unsigned long status;
226 unsigned long radio;
227 214
228 struct list_head pending_notif; 215 struct list_head pending_notif;
229 wait_queue_head_t notif_queue; 216 wait_queue_head_t notif_queue;
@@ -242,6 +229,7 @@ struct iwm_priv {
242 u8 bssid[ETH_ALEN]; 229 u8 bssid[ETH_ALEN];
243 u8 channel; 230 u8 channel;
244 u16 rate; 231 u16 rate;
232 u32 txpower;
245 233
246 struct iwm_sta_info sta_table[IWM_STA_TABLE_NUM]; 234 struct iwm_sta_info sta_table[IWM_STA_TABLE_NUM];
247 struct list_head bss_list; 235 struct list_head bss_list;
@@ -276,7 +264,10 @@ struct iwm_priv {
276 struct iwm_tx_queue txq[IWM_TX_QUEUES]; 264 struct iwm_tx_queue txq[IWM_TX_QUEUES];
277 265
278 struct iwm_key keys[IWM_NUM_KEYS]; 266 struct iwm_key keys[IWM_NUM_KEYS];
279 struct iwm_key *default_key; 267 s8 default_key;
268
269 DECLARE_BITMAP(wifi_ntfy, WIFI_IF_NTFY_MAX);
270 wait_queue_head_t wifi_ntfy_queue;
280 271
281 wait_queue_head_t mlme_queue; 272 wait_queue_head_t mlme_queue;
282 273
@@ -289,7 +280,6 @@ struct iwm_priv {
289 struct timer_list watchdog; 280 struct timer_list watchdog;
290 struct work_struct reset_worker; 281 struct work_struct reset_worker;
291 struct mutex mutex; 282 struct mutex mutex;
292 struct rfkill *rfkill;
293 283
294 char private[0] __attribute__((__aligned__(NETDEV_ALIGN))); 284 char private[0] __attribute__((__aligned__(NETDEV_ALIGN)));
295}; 285};
diff --git a/drivers/net/wireless/iwmc3200wifi/lmac.h b/drivers/net/wireless/iwmc3200wifi/lmac.h
index db2e5eea1895..19213e165f5f 100644
--- a/drivers/net/wireless/iwmc3200wifi/lmac.h
+++ b/drivers/net/wireless/iwmc3200wifi/lmac.h
@@ -396,6 +396,10 @@ enum {
396 CALIBRATION_CMD_NUM, 396 CALIBRATION_CMD_NUM,
397}; 397};
398 398
399#define IWM_CALIB_MAP_INIT_MSK 0xFFFF
400#define IWM_CALIB_MAP_PER_LMAC(m) ((m & 0xFF0000) >> 16)
401#define IWM_CALIB_MAP_PER_UMAC(m) ((m & 0xFF000000) >> 24)
402
399struct iwm_lmac_calib_hdr { 403struct iwm_lmac_calib_hdr {
400 u8 opcode; 404 u8 opcode;
401 u8 first_grp; 405 u8 first_grp;
diff --git a/drivers/net/wireless/iwmc3200wifi/main.c b/drivers/net/wireless/iwmc3200wifi/main.c
index 8be206d58222..484f110151b7 100644
--- a/drivers/net/wireless/iwmc3200wifi/main.c
+++ b/drivers/net/wireless/iwmc3200wifi/main.c
@@ -53,11 +53,7 @@
53static struct iwm_conf def_iwm_conf = { 53static struct iwm_conf def_iwm_conf = {
54 54
55 .sdio_ior_timeout = 5000, 55 .sdio_ior_timeout = 5000,
56 .init_calib_map = BIT(PHY_CALIBRATE_DC_CMD) | 56 .calib_map = BIT(PHY_CALIBRATE_DC_CMD) |
57 BIT(PHY_CALIBRATE_LO_CMD) |
58 BIT(PHY_CALIBRATE_TX_IQ_CMD) |
59 BIT(PHY_CALIBRATE_RX_IQ_CMD),
60 .periodic_calib_map = BIT(PHY_CALIBRATE_DC_CMD) |
61 BIT(PHY_CALIBRATE_LO_CMD) | 57 BIT(PHY_CALIBRATE_LO_CMD) |
62 BIT(PHY_CALIBRATE_TX_IQ_CMD) | 58 BIT(PHY_CALIBRATE_TX_IQ_CMD) |
63 BIT(PHY_CALIBRATE_RX_IQ_CMD) | 59 BIT(PHY_CALIBRATE_RX_IQ_CMD) |
@@ -191,6 +187,7 @@ int iwm_priv_init(struct iwm_priv *iwm)
191 INIT_LIST_HEAD(&iwm->pending_notif); 187 INIT_LIST_HEAD(&iwm->pending_notif);
192 init_waitqueue_head(&iwm->notif_queue); 188 init_waitqueue_head(&iwm->notif_queue);
193 init_waitqueue_head(&iwm->nonwifi_queue); 189 init_waitqueue_head(&iwm->nonwifi_queue);
190 init_waitqueue_head(&iwm->wifi_ntfy_queue);
194 init_waitqueue_head(&iwm->mlme_queue); 191 init_waitqueue_head(&iwm->mlme_queue);
195 memcpy(&iwm->conf, &def_iwm_conf, sizeof(struct iwm_conf)); 192 memcpy(&iwm->conf, &def_iwm_conf, sizeof(struct iwm_conf));
196 spin_lock_init(&iwm->tx_credit.lock); 193 spin_lock_init(&iwm->tx_credit.lock);
@@ -229,7 +226,7 @@ int iwm_priv_init(struct iwm_priv *iwm)
229 for (i = 0; i < IWM_NUM_KEYS; i++) 226 for (i = 0; i < IWM_NUM_KEYS; i++)
230 memset(&iwm->keys[i], 0, sizeof(struct iwm_key)); 227 memset(&iwm->keys[i], 0, sizeof(struct iwm_key));
231 228
232 iwm->default_key = NULL; 229 iwm->default_key = -1;
233 230
234 init_timer(&iwm->watchdog); 231 init_timer(&iwm->watchdog);
235 iwm->watchdog.function = iwm_watchdog; 232 iwm->watchdog.function = iwm_watchdog;
@@ -518,13 +515,6 @@ static int iwm_channels_init(struct iwm_priv *iwm)
518{ 515{
519 int ret; 516 int ret;
520 517
521#ifdef CONFIG_IWM_B0_HW_SUPPORT
522 if (iwm->conf.hw_b0) {
523 IWM_INFO(iwm, "Workaround EEPROM channels for B0 hardware\n");
524 return 0;
525 }
526#endif
527
528 ret = iwm_send_umac_channel_list(iwm); 518 ret = iwm_send_umac_channel_list(iwm);
529 if (ret) { 519 if (ret) {
530 IWM_ERR(iwm, "Send channel list failed\n"); 520 IWM_ERR(iwm, "Send channel list failed\n");
@@ -642,19 +632,10 @@ int __iwm_up(struct iwm_priv *iwm)
642 } 632 }
643 } 633 }
644 634
645 iwm->umac_profile = kmalloc(sizeof(struct iwm_umac_profile),
646 GFP_KERNEL);
647 if (!iwm->umac_profile) {
648 IWM_ERR(iwm, "Couldn't alloc memory for profile\n");
649 goto err_fw;
650 }
651
652 iwm_init_default_profile(iwm, iwm->umac_profile);
653
654 ret = iwm_channels_init(iwm); 635 ret = iwm_channels_init(iwm);
655 if (ret < 0) { 636 if (ret < 0) {
656 IWM_ERR(iwm, "Couldn't init channels\n"); 637 IWM_ERR(iwm, "Couldn't init channels\n");
657 goto err_profile; 638 goto err_fw;
658 } 639 }
659 640
660 /* Set the READY bit to indicate interface is brought up successfully */ 641 /* Set the READY bit to indicate interface is brought up successfully */
@@ -662,10 +643,6 @@ int __iwm_up(struct iwm_priv *iwm)
662 643
663 return 0; 644 return 0;
664 645
665 err_profile:
666 kfree(iwm->umac_profile);
667 iwm->umac_profile = NULL;
668
669 err_fw: 646 err_fw:
670 iwm_eeprom_exit(iwm); 647 iwm_eeprom_exit(iwm);
671 648
@@ -704,11 +681,10 @@ int __iwm_down(struct iwm_priv *iwm)
704 clear_bit(IWM_STATUS_READY, &iwm->status); 681 clear_bit(IWM_STATUS_READY, &iwm->status);
705 682
706 iwm_eeprom_exit(iwm); 683 iwm_eeprom_exit(iwm);
707 kfree(iwm->umac_profile);
708 iwm->umac_profile = NULL;
709 iwm_bss_list_clean(iwm); 684 iwm_bss_list_clean(iwm);
710 685 iwm_init_default_profile(iwm, iwm->umac_profile);
711 iwm->default_key = NULL; 686 iwm->umac_profile_active = false;
687 iwm->default_key = -1;
712 iwm->core_enabled = 0; 688 iwm->core_enabled = 0;
713 689
714 ret = iwm_bus_disable(iwm); 690 ret = iwm_bus_disable(iwm);
diff --git a/drivers/net/wireless/iwmc3200wifi/netdev.c b/drivers/net/wireless/iwmc3200wifi/netdev.c
index aaa20c6885c8..e94e96955b99 100644
--- a/drivers/net/wireless/iwmc3200wifi/netdev.c
+++ b/drivers/net/wireless/iwmc3200wifi/netdev.c
@@ -48,29 +48,22 @@
48#include <linux/netdevice.h> 48#include <linux/netdevice.h>
49 49
50#include "iwm.h" 50#include "iwm.h"
51#include "commands.h"
51#include "cfg80211.h" 52#include "cfg80211.h"
52#include "debug.h" 53#include "debug.h"
53 54
54static int iwm_open(struct net_device *ndev) 55static int iwm_open(struct net_device *ndev)
55{ 56{
56 struct iwm_priv *iwm = ndev_to_iwm(ndev); 57 struct iwm_priv *iwm = ndev_to_iwm(ndev);
57 int ret = 0;
58
59 if (!test_bit(IWM_RADIO_RFKILL_SW, &iwm->radio))
60 ret = iwm_up(iwm);
61 58
62 return ret; 59 return iwm_up(iwm);
63} 60}
64 61
65static int iwm_stop(struct net_device *ndev) 62static int iwm_stop(struct net_device *ndev)
66{ 63{
67 struct iwm_priv *iwm = ndev_to_iwm(ndev); 64 struct iwm_priv *iwm = ndev_to_iwm(ndev);
68 int ret = 0;
69
70 if (!test_bit(IWM_RADIO_RFKILL_SW, &iwm->radio))
71 ret = iwm_down(iwm);
72 65
73 return ret; 66 return iwm_down(iwm);
74} 67}
75 68
76/* 69/*
@@ -135,8 +128,20 @@ void *iwm_if_alloc(int sizeof_bus, struct device *dev,
135 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy)); 128 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
136 wdev->netdev = ndev; 129 wdev->netdev = ndev;
137 130
131 iwm->umac_profile = kmalloc(sizeof(struct iwm_umac_profile),
132 GFP_KERNEL);
133 if (!iwm->umac_profile) {
134 dev_err(dev, "Couldn't alloc memory for profile\n");
135 goto out_profile;
136 }
137
138 iwm_init_default_profile(iwm, iwm->umac_profile);
139
138 return iwm; 140 return iwm;
139 141
142 out_profile:
143 free_netdev(ndev);
144
140 out_priv: 145 out_priv:
141 iwm_priv_deinit(iwm); 146 iwm_priv_deinit(iwm);
142 147
@@ -153,6 +158,8 @@ void iwm_if_free(struct iwm_priv *iwm)
153 free_netdev(iwm_to_ndev(iwm)); 158 free_netdev(iwm_to_ndev(iwm));
154 iwm_wdev_free(iwm); 159 iwm_wdev_free(iwm);
155 iwm_priv_deinit(iwm); 160 iwm_priv_deinit(iwm);
161 kfree(iwm->umac_profile);
162 iwm->umac_profile = NULL;
156} 163}
157 164
158int iwm_if_add(struct iwm_priv *iwm) 165int iwm_if_add(struct iwm_priv *iwm)
diff --git a/drivers/net/wireless/iwmc3200wifi/rx.c b/drivers/net/wireless/iwmc3200wifi/rx.c
index d73cf96c6dc6..3909477fb3bf 100644
--- a/drivers/net/wireless/iwmc3200wifi/rx.c
+++ b/drivers/net/wireless/iwmc3200wifi/rx.c
@@ -143,17 +143,18 @@ static int iwm_ntf_init_complete(struct iwm_priv *iwm, u8 *buf,
143 unsigned long buf_size, 143 unsigned long buf_size,
144 struct iwm_wifi_cmd *cmd) 144 struct iwm_wifi_cmd *cmd)
145{ 145{
146 struct wiphy *wiphy = iwm_to_wiphy(iwm);
146 struct iwm_umac_notif_init_complete *init_complete = 147 struct iwm_umac_notif_init_complete *init_complete =
147 (struct iwm_umac_notif_init_complete *)(buf); 148 (struct iwm_umac_notif_init_complete *)(buf);
148 u16 status = le16_to_cpu(init_complete->status); 149 u16 status = le16_to_cpu(init_complete->status);
150 bool blocked = (status == UMAC_NTFY_INIT_COMPLETE_STATUS_ERR);
149 151
150 if (status == UMAC_NTFY_INIT_COMPLETE_STATUS_ERR) { 152 if (blocked)
151 IWM_DBG_NTF(iwm, DBG, "Hardware rf kill is on (radio off)\n"); 153 IWM_DBG_NTF(iwm, DBG, "Hardware rf kill is on (radio off)\n");
152 set_bit(IWM_RADIO_RFKILL_HW, &iwm->radio); 154 else
153 } else {
154 IWM_DBG_NTF(iwm, DBG, "Hardware rf kill is off (radio on)\n"); 155 IWM_DBG_NTF(iwm, DBG, "Hardware rf kill is off (radio on)\n");
155 clear_bit(IWM_RADIO_RFKILL_HW, &iwm->radio); 156
156 } 157 wiphy_rfkill_set_hw_state(wiphy, blocked);
157 158
158 return 0; 159 return 0;
159} 160}
@@ -875,6 +876,7 @@ static int iwm_ntf_statistics(struct iwm_priv *iwm, u8 *buf,
875 /* UMAC passes rate info multiplies by 2 */ 876 /* UMAC passes rate info multiplies by 2 */
876 iwm->rate = max_rate >> 1; 877 iwm->rate = max_rate >> 1;
877 } 878 }
879 iwm->txpower = le32_to_cpu(stats->tx_power);
878 880
879 wstats->status = 0; 881 wstats->status = 0;
880 882
@@ -922,13 +924,6 @@ static int iwm_ntf_eeprom_proxy(struct iwm_priv *iwm, u8 *buf,
922 if ((hdr_offset + hdr_len) > IWM_EEPROM_LEN) 924 if ((hdr_offset + hdr_len) > IWM_EEPROM_LEN)
923 return -EINVAL; 925 return -EINVAL;
924 926
925#ifdef CONFIG_IWM_B0_HW_SUPPORT
926 if (hdr_offset == IWM_EEPROM_SKU_CAP_OFF) {
927 if (eeprom_proxy->buf[0] == 0xff)
928 iwm->conf.hw_b0 = 1;
929 }
930#endif
931
932 switch (hdr_type) { 927 switch (hdr_type) {
933 case IWM_UMAC_CMD_EEPROM_TYPE_READ: 928 case IWM_UMAC_CMD_EEPROM_TYPE_READ:
934 memcpy(iwm->eeprom + hdr_offset, eeprom_proxy->buf, hdr_len); 929 memcpy(iwm->eeprom + hdr_offset, eeprom_proxy->buf, hdr_len);
@@ -993,12 +988,17 @@ static int iwm_ntf_wifi_if_wrapper(struct iwm_priv *iwm, u8 *buf,
993 (struct iwm_umac_wifi_if *)cmd->buf.payload; 988 (struct iwm_umac_wifi_if *)cmd->buf.payload;
994 989
995 IWM_DBG_NTF(iwm, DBG, "WIFI_IF_WRAPPER cmd is delivered to UMAC: " 990 IWM_DBG_NTF(iwm, DBG, "WIFI_IF_WRAPPER cmd is delivered to UMAC: "
996 "oid is %d\n", hdr->oid); 991 "oid is 0x%x\n", hdr->oid);
992
993 if (hdr->oid <= WIFI_IF_NTFY_MAX) {
994 set_bit(hdr->oid, &iwm->wifi_ntfy[0]);
995 wake_up_interruptible(&iwm->wifi_ntfy_queue);
996 } else
997 return -EINVAL;
997 998
998 switch (hdr->oid) { 999 switch (hdr->oid) {
999 case UMAC_WIFI_IF_CMD_SET_PROFILE: 1000 case UMAC_WIFI_IF_CMD_SET_PROFILE:
1000 iwm->umac_profile_active = 1; 1001 iwm->umac_profile_active = 1;
1001 wake_up_interruptible(&iwm->mlme_queue);
1002 break; 1002 break;
1003 default: 1003 default:
1004 break; 1004 break;
@@ -1010,6 +1010,7 @@ static int iwm_ntf_wifi_if_wrapper(struct iwm_priv *iwm, u8 *buf,
1010static int iwm_ntf_card_state(struct iwm_priv *iwm, u8 *buf, 1010static int iwm_ntf_card_state(struct iwm_priv *iwm, u8 *buf,
1011 unsigned long buf_size, struct iwm_wifi_cmd *cmd) 1011 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
1012{ 1012{
1013 struct wiphy *wiphy = iwm_to_wiphy(iwm);
1013 struct iwm_lmac_card_state *state = (struct iwm_lmac_card_state *) 1014 struct iwm_lmac_card_state *state = (struct iwm_lmac_card_state *)
1014 (buf + sizeof(struct iwm_umac_wifi_in_hdr)); 1015 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
1015 u32 flags = le32_to_cpu(state->flags); 1016 u32 flags = le32_to_cpu(state->flags);
@@ -1018,10 +1019,7 @@ static int iwm_ntf_card_state(struct iwm_priv *iwm, u8 *buf,
1018 flags & IWM_CARD_STATE_HW_DISABLED ? "ON" : "OFF", 1019 flags & IWM_CARD_STATE_HW_DISABLED ? "ON" : "OFF",
1019 flags & IWM_CARD_STATE_CTKILL_DISABLED ? "ON" : "OFF"); 1020 flags & IWM_CARD_STATE_CTKILL_DISABLED ? "ON" : "OFF");
1020 1021
1021 if (flags & IWM_CARD_STATE_HW_DISABLED) 1022 wiphy_rfkill_set_hw_state(wiphy, flags & IWM_CARD_STATE_HW_DISABLED);
1022 set_bit(IWM_RADIO_RFKILL_HW, &iwm->radio);
1023 else
1024 clear_bit(IWM_RADIO_RFKILL_HW, &iwm->radio);
1025 1023
1026 return 0; 1024 return 0;
1027} 1025}
@@ -1368,7 +1366,7 @@ static void iwm_rx_process_packet(struct iwm_priv *iwm,
1368 ndev->stats.rx_packets++; 1366 ndev->stats.rx_packets++;
1369 ndev->stats.rx_bytes += skb->len; 1367 ndev->stats.rx_bytes += skb->len;
1370 1368
1371 if (netif_rx(skb) == NET_RX_DROP) { 1369 if (netif_rx_ni(skb) == NET_RX_DROP) {
1372 IWM_ERR(iwm, "Packet dropped\n"); 1370 IWM_ERR(iwm, "Packet dropped\n");
1373 ndev->stats.rx_dropped++; 1371 ndev->stats.rx_dropped++;
1374 } 1372 }
diff --git a/drivers/net/wireless/iwmc3200wifi/sdio.c b/drivers/net/wireless/iwmc3200wifi/sdio.c
index 916681837fd2..b93f620ee4f1 100644
--- a/drivers/net/wireless/iwmc3200wifi/sdio.c
+++ b/drivers/net/wireless/iwmc3200wifi/sdio.c
@@ -506,11 +506,7 @@ static struct sdio_driver iwm_sdio_driver = {
506 506
507static int __init iwm_sdio_init_module(void) 507static int __init iwm_sdio_init_module(void)
508{ 508{
509 int ret; 509 return sdio_register_driver(&iwm_sdio_driver);
510
511 ret = sdio_register_driver(&iwm_sdio_driver);
512
513 return ret;
514} 510}
515 511
516static void __exit iwm_sdio_exit_module(void) 512static void __exit iwm_sdio_exit_module(void)
diff --git a/drivers/net/wireless/iwmc3200wifi/umac.h b/drivers/net/wireless/iwmc3200wifi/umac.h
index 4a95cce1f0a6..0af2a3c76281 100644
--- a/drivers/net/wireless/iwmc3200wifi/umac.h
+++ b/drivers/net/wireless/iwmc3200wifi/umac.h
@@ -495,6 +495,8 @@ struct iwm_fw_alive_hdr {
495#define WIFI_DBG_IF_NTFY_COEX_HANDLE_ENVELOP 0xE8 495#define WIFI_DBG_IF_NTFY_COEX_HANDLE_ENVELOP 0xE8
496#define WIFI_DBG_IF_NTFY_COEX_HANDLE_RELEASE_ENVELOP 0xE9 496#define WIFI_DBG_IF_NTFY_COEX_HANDLE_RELEASE_ENVELOP 0xE9
497 497
498#define WIFI_IF_NTFY_MAX 0xff
499
498/* Notification structures */ 500/* Notification structures */
499struct iwm_umac_notif_wifi_if { 501struct iwm_umac_notif_wifi_if {
500 struct iwm_umac_wifi_in_hdr hdr; 502 struct iwm_umac_wifi_in_hdr hdr;
diff --git a/drivers/net/wireless/iwmc3200wifi/wext.c b/drivers/net/wireless/iwmc3200wifi/wext.c
index 584c94d0f399..2e7eaf96cf93 100644
--- a/drivers/net/wireless/iwmc3200wifi/wext.c
+++ b/drivers/net/wireless/iwmc3200wifi/wext.c
@@ -82,6 +82,9 @@ static int iwm_wext_siwap(struct net_device *dev, struct iw_request_info *info,
82 struct sockaddr *ap_addr, char *extra) 82 struct sockaddr *ap_addr, char *extra)
83{ 83{
84 struct iwm_priv *iwm = ndev_to_iwm(dev); 84 struct iwm_priv *iwm = ndev_to_iwm(dev);
85 int ret;
86
87 IWM_DBG_WEXT(iwm, DBG, "Set BSSID: %pM\n", ap_addr->sa_data);
85 88
86 if (iwm->conf.mode == UMAC_MODE_IBSS) 89 if (iwm->conf.mode == UMAC_MODE_IBSS)
87 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); 90 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
@@ -104,10 +107,25 @@ static int iwm_wext_siwap(struct net_device *dev, struct iw_request_info *info,
104 } 107 }
105 108
106 if (iwm->umac_profile_active) { 109 if (iwm->umac_profile_active) {
110 int i;
111
107 if (!memcmp(&iwm->umac_profile->bssid[0], iwm->bssid, ETH_ALEN)) 112 if (!memcmp(&iwm->umac_profile->bssid[0], iwm->bssid, ETH_ALEN))
108 return 0; 113 return 0;
109 114
110 iwm_invalidate_mlme_profile(iwm); 115 /*
116 * If we're clearing the BSSID, and we're associated,
117 * we have to clear the keys as they're no longer valid.
118 */
119 if (is_zero_ether_addr(ap_addr->sa_data)) {
120 for (i = 0; i < IWM_NUM_KEYS; i++)
121 iwm->keys[i].key_len = 0;
122 }
123
124 ret = iwm_invalidate_mlme_profile(iwm);
125 if (ret < 0) {
126 IWM_ERR(iwm, "Couldn't invalidate profile\n");
127 return ret;
128 }
111 } 129 }
112 130
113 if (iwm->umac_profile->ssid.ssid_len) 131 if (iwm->umac_profile->ssid.ssid_len)
@@ -146,6 +164,8 @@ static int iwm_wext_siwessid(struct net_device *dev,
146 size_t len = data->length; 164 size_t len = data->length;
147 int ret; 165 int ret;
148 166
167 IWM_DBG_WEXT(iwm, DBG, "Set ESSID: >%s<\n", ssid);
168
149 if (iwm->conf.mode == UMAC_MODE_IBSS) 169 if (iwm->conf.mode == UMAC_MODE_IBSS)
150 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid); 170 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
151 171
@@ -195,27 +215,6 @@ static int iwm_wext_giwessid(struct net_device *dev,
195 return 0; 215 return 0;
196} 216}
197 217
198static struct iwm_key *
199iwm_key_init(struct iwm_priv *iwm, u8 key_idx, bool in_use,
200 struct iw_encode_ext *ext, u8 alg)
201{
202 struct iwm_key *key = &iwm->keys[key_idx];
203
204 memset(key, 0, sizeof(struct iwm_key));
205 memcpy(key->hdr.mac, ext->addr.sa_data, ETH_ALEN);
206 key->hdr.key_idx = key_idx;
207 if (is_broadcast_ether_addr(ext->addr.sa_data))
208 key->hdr.multicast = 1;
209
210 key->in_use = in_use;
211 key->flags = ext->ext_flags;
212 key->alg = alg;
213 key->key_len = ext->key_len;
214 memcpy(key->key, ext->key, ext->key_len);
215
216 return key;
217}
218
219static int iwm_wext_giwrate(struct net_device *dev, 218static int iwm_wext_giwrate(struct net_device *dev,
220 struct iw_request_info *info, 219 struct iw_request_info *info,
221 struct iw_param *rate, char *extra) 220 struct iw_param *rate, char *extra)
@@ -227,184 +226,6 @@ static int iwm_wext_giwrate(struct net_device *dev,
227 return 0; 226 return 0;
228} 227}
229 228
230static int iwm_wext_siwencode(struct net_device *dev,
231 struct iw_request_info *info,
232 struct iw_point *erq, char *key_buf)
233{
234 struct iwm_priv *iwm = ndev_to_iwm(dev);
235 struct iwm_key *uninitialized_var(key);
236 int idx, i, uninitialized_var(alg), remove = 0, ret;
237
238 IWM_DBG_WEXT(iwm, DBG, "key len: %d\n", erq->length);
239 IWM_DBG_WEXT(iwm, DBG, "flags: 0x%x\n", erq->flags);
240
241 if (!iwm->umac_profile) {
242 IWM_ERR(iwm, "UMAC profile not allocated yet\n");
243 return -ENODEV;
244 }
245
246 if (erq->length == WLAN_KEY_LEN_WEP40) {
247 alg = UMAC_CIPHER_TYPE_WEP_40;
248 iwm->umac_profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_WEP_40;
249 iwm->umac_profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_WEP_40;
250 } else if (erq->length == WLAN_KEY_LEN_WEP104) {
251 alg = UMAC_CIPHER_TYPE_WEP_104;
252 iwm->umac_profile->sec.ucast_cipher = UMAC_CIPHER_TYPE_WEP_104;
253 iwm->umac_profile->sec.mcast_cipher = UMAC_CIPHER_TYPE_WEP_104;
254 }
255
256 if (erq->flags & IW_ENCODE_RESTRICTED)
257 iwm->umac_profile->sec.auth_type = UMAC_AUTH_TYPE_LEGACY_PSK;
258 else
259 iwm->umac_profile->sec.auth_type = UMAC_AUTH_TYPE_OPEN;
260
261 idx = erq->flags & IW_ENCODE_INDEX;
262 if (idx == 0) {
263 if (iwm->default_key)
264 for (i = 0; i < IWM_NUM_KEYS; i++) {
265 if (iwm->default_key == &iwm->keys[i]) {
266 idx = i;
267 break;
268 }
269 }
270 else
271 iwm->default_key = &iwm->keys[idx];
272 } else if (idx < 1 || idx > 4) {
273 return -EINVAL;
274 } else
275 idx--;
276
277 if (erq->flags & IW_ENCODE_DISABLED)
278 remove = 1;
279 else if (erq->length == 0) {
280 if (!iwm->keys[idx].in_use)
281 return -EINVAL;
282 iwm->default_key = &iwm->keys[idx];
283 }
284
285 if (erq->length) {
286 key = &iwm->keys[idx];
287 memset(key, 0, sizeof(struct iwm_key));
288 memset(key->hdr.mac, 0xff, ETH_ALEN);
289 key->hdr.key_idx = idx;
290 key->hdr.multicast = 1;
291 key->in_use = !remove;
292 key->alg = alg;
293 key->key_len = erq->length;
294 memcpy(key->key, key_buf, erq->length);
295
296 IWM_DBG_WEXT(iwm, DBG, "Setting key %d, default: %d\n",
297 idx, !!iwm->default_key);
298 }
299
300 if (remove) {
301 if ((erq->flags & IW_ENCODE_NOKEY) || (erq->length == 0)) {
302 int j;
303 for (j = 0; j < IWM_NUM_KEYS; j++)
304 if (iwm->keys[j].in_use) {
305 struct iwm_key *k = &iwm->keys[j];
306
307 k->in_use = 0;
308 ret = iwm_set_key(iwm, remove, 0, k);
309 if (ret < 0)
310 return ret;
311 }
312
313 iwm->umac_profile->sec.ucast_cipher =
314 UMAC_CIPHER_TYPE_NONE;
315 iwm->umac_profile->sec.mcast_cipher =
316 UMAC_CIPHER_TYPE_NONE;
317 iwm->umac_profile->sec.auth_type =
318 UMAC_AUTH_TYPE_OPEN;
319
320 return 0;
321 } else {
322 key->in_use = 0;
323 return iwm_set_key(iwm, remove, 0, key);
324 }
325 }
326
327 /*
328 * If we havent set a profile yet, we cant set keys.
329 * Keys will be pushed after we're associated.
330 */
331 if (!iwm->umac_profile_active)
332 return 0;
333
334 /*
335 * If there is a current active profile, but no
336 * default key, it's not worth trying to associate again.
337 */
338 if (!iwm->default_key)
339 return 0;
340
341 /*
342 * Here we have an active profile, but a key setting changed.
343 * We thus have to invalidate the current profile, and push the
344 * new one. Keys will be pushed when association takes place.
345 */
346 ret = iwm_invalidate_mlme_profile(iwm);
347 if (ret < 0) {
348 IWM_ERR(iwm, "Couldn't invalidate profile\n");
349 return ret;
350 }
351
352 return iwm_send_mlme_profile(iwm);
353}
354
355static int iwm_wext_giwencode(struct net_device *dev,
356 struct iw_request_info *info,
357 struct iw_point *erq, char *key)
358{
359 struct iwm_priv *iwm = ndev_to_iwm(dev);
360 int idx, i;
361
362 idx = erq->flags & IW_ENCODE_INDEX;
363 if (idx < 1 || idx > 4) {
364 idx = -1;
365 if (!iwm->default_key) {
366 erq->length = 0;
367 erq->flags |= IW_ENCODE_NOKEY;
368 return 0;
369 } else
370 for (i = 0; i < IWM_NUM_KEYS; i++) {
371 if (iwm->default_key == &iwm->keys[i]) {
372 idx = i;
373 break;
374 }
375 }
376 if (idx < 0)
377 return -EINVAL;
378 } else
379 idx--;
380
381 erq->flags = idx + 1;
382
383 if (!iwm->keys[idx].in_use) {
384 erq->length = 0;
385 erq->flags |= IW_ENCODE_DISABLED;
386 return 0;
387 }
388
389 memcpy(key, iwm->keys[idx].key,
390 min_t(int, erq->length, iwm->keys[idx].key_len));
391 erq->length = iwm->keys[idx].key_len;
392 erq->flags |= IW_ENCODE_ENABLED;
393
394 if (iwm->umac_profile->mode == UMAC_MODE_BSS) {
395 switch (iwm->umac_profile->sec.auth_type) {
396 case UMAC_AUTH_TYPE_OPEN:
397 erq->flags |= IW_ENCODE_OPEN;
398 break;
399 default:
400 erq->flags |= IW_ENCODE_RESTRICTED;
401 break;
402 }
403 }
404
405 return 0;
406}
407
408static int iwm_set_wpa_version(struct iwm_priv *iwm, u8 wpa_version) 229static int iwm_set_wpa_version(struct iwm_priv *iwm, u8 wpa_version)
409{ 230{
410 if (wpa_version & IW_AUTH_WPA_VERSION_WPA2) 231 if (wpa_version & IW_AUTH_WPA_VERSION_WPA2)
@@ -417,53 +238,12 @@ static int iwm_set_wpa_version(struct iwm_priv *iwm, u8 wpa_version)
417 return 0; 238 return 0;
418} 239}
419 240
420static int iwm_wext_siwpower(struct net_device *dev,
421 struct iw_request_info *info,
422 struct iw_param *wrq, char *extra)
423{
424 struct iwm_priv *iwm = ndev_to_iwm(dev);
425 u32 power_index;
426
427 if (wrq->disabled) {
428 power_index = IWM_POWER_INDEX_MIN;
429 goto set;
430 } else
431 power_index = IWM_POWER_INDEX_DEFAULT;
432
433 switch (wrq->flags & IW_POWER_MODE) {
434 case IW_POWER_ON:
435 case IW_POWER_MODE:
436 case IW_POWER_ALL_R:
437 break;
438 default:
439 return -EINVAL;
440 }
441
442 set:
443 if (power_index == iwm->conf.power_index)
444 return 0;
445
446 iwm->conf.power_index = power_index;
447
448 return iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
449 CFG_POWER_INDEX, iwm->conf.power_index);
450}
451
452static int iwm_wext_giwpower(struct net_device *dev,
453 struct iw_request_info *info,
454 union iwreq_data *wrqu, char *extra)
455{
456 struct iwm_priv *iwm = ndev_to_iwm(dev);
457
458 wrqu->power.disabled = (iwm->conf.power_index == IWM_POWER_INDEX_MIN);
459
460 return 0;
461}
462
463static int iwm_set_key_mgt(struct iwm_priv *iwm, u8 key_mgt) 241static int iwm_set_key_mgt(struct iwm_priv *iwm, u8 key_mgt)
464{ 242{
465 u8 *auth_type = &iwm->umac_profile->sec.auth_type; 243 u8 *auth_type = &iwm->umac_profile->sec.auth_type;
466 244
245 IWM_DBG_WEXT(iwm, DBG, "key_mgt: 0x%x\n", key_mgt);
246
467 if (key_mgt == IW_AUTH_KEY_MGMT_802_1X) 247 if (key_mgt == IW_AUTH_KEY_MGMT_802_1X)
468 *auth_type = UMAC_AUTH_TYPE_8021X; 248 *auth_type = UMAC_AUTH_TYPE_8021X;
469 else if (key_mgt == IW_AUTH_KEY_MGMT_PSK) { 249 else if (key_mgt == IW_AUTH_KEY_MGMT_PSK) {
@@ -513,6 +293,8 @@ static int iwm_set_auth_alg(struct iwm_priv *iwm, u8 auth_alg)
513{ 293{
514 u8 *auth_type = &iwm->umac_profile->sec.auth_type; 294 u8 *auth_type = &iwm->umac_profile->sec.auth_type;
515 295
296 IWM_DBG_WEXT(iwm, DBG, "auth_alg: 0x%x\n", auth_alg);
297
516 switch (auth_alg) { 298 switch (auth_alg) {
517 case IW_AUTH_ALG_OPEN_SYSTEM: 299 case IW_AUTH_ALG_OPEN_SYSTEM:
518 *auth_type = UMAC_AUTH_TYPE_OPEN; 300 *auth_type = UMAC_AUTH_TYPE_OPEN;
@@ -524,6 +306,7 @@ static int iwm_set_auth_alg(struct iwm_priv *iwm, u8 auth_alg)
524 return -EINVAL; 306 return -EINVAL;
525 *auth_type = UMAC_AUTH_TYPE_RSNA_PSK; 307 *auth_type = UMAC_AUTH_TYPE_RSNA_PSK;
526 } else { 308 } else {
309 IWM_DBG_WEXT(iwm, DBG, "WEP shared key\n");
527 *auth_type = UMAC_AUTH_TYPE_LEGACY_PSK; 310 *auth_type = UMAC_AUTH_TYPE_LEGACY_PSK;
528 } 311 }
529 break; 312 break;
@@ -586,75 +369,6 @@ static int iwm_wext_giwauth(struct net_device *dev,
586 return 0; 369 return 0;
587} 370}
588 371
589static int iwm_wext_siwencodeext(struct net_device *dev,
590 struct iw_request_info *info,
591 struct iw_point *erq, char *extra)
592{
593 struct iwm_priv *iwm = ndev_to_iwm(dev);
594 struct iwm_key *key;
595 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
596 int uninitialized_var(alg), idx, i, remove = 0;
597
598 IWM_DBG_WEXT(iwm, DBG, "alg: 0x%x\n", ext->alg);
599 IWM_DBG_WEXT(iwm, DBG, "key len: %d\n", ext->key_len);
600 IWM_DBG_WEXT(iwm, DBG, "ext_flags: 0x%x\n", ext->ext_flags);
601 IWM_DBG_WEXT(iwm, DBG, "flags: 0x%x\n", erq->flags);
602 IWM_DBG_WEXT(iwm, DBG, "length: 0x%x\n", erq->length);
603
604 switch (ext->alg) {
605 case IW_ENCODE_ALG_NONE:
606 remove = 1;
607 break;
608 case IW_ENCODE_ALG_WEP:
609 if (ext->key_len == WLAN_KEY_LEN_WEP40)
610 alg = UMAC_CIPHER_TYPE_WEP_40;
611 else if (ext->key_len == WLAN_KEY_LEN_WEP104)
612 alg = UMAC_CIPHER_TYPE_WEP_104;
613 else {
614 IWM_ERR(iwm, "Invalid key length: %d\n", ext->key_len);
615 return -EINVAL;
616 }
617
618 break;
619 case IW_ENCODE_ALG_TKIP:
620 alg = UMAC_CIPHER_TYPE_TKIP;
621 break;
622 case IW_ENCODE_ALG_CCMP:
623 alg = UMAC_CIPHER_TYPE_CCMP;
624 break;
625 default:
626 return -EOPNOTSUPP;
627 }
628
629 idx = erq->flags & IW_ENCODE_INDEX;
630
631 if (idx == 0) {
632 if (iwm->default_key)
633 for (i = 0; i < IWM_NUM_KEYS; i++) {
634 if (iwm->default_key == &iwm->keys[i]) {
635 idx = i;
636 break;
637 }
638 }
639 } else if (idx < 1 || idx > 4) {
640 return -EINVAL;
641 } else
642 idx--;
643
644 if (erq->flags & IW_ENCODE_DISABLED)
645 remove = 1;
646 else if ((erq->length == 0) ||
647 (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) {
648 iwm->default_key = &iwm->keys[idx];
649 if (iwm->umac_profile_active && ext->alg == IW_ENCODE_ALG_WEP)
650 return iwm_set_tx_key(iwm, idx);
651 }
652
653 key = iwm_key_init(iwm, idx, !remove, ext, alg);
654
655 return iwm_set_key(iwm, remove, !iwm->default_key, key);
656}
657
658static const iw_handler iwm_handlers[] = 372static const iw_handler iwm_handlers[] =
659{ 373{
660 (iw_handler) NULL, /* SIOCSIWCOMMIT */ 374 (iw_handler) NULL, /* SIOCSIWCOMMIT */
@@ -695,21 +409,21 @@ static const iw_handler iwm_handlers[] =
695 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */ 409 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
696 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */ 410 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
697 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */ 411 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */
698 (iw_handler) NULL, /* SIOCSIWTXPOW */ 412 (iw_handler) cfg80211_wext_siwtxpower, /* SIOCSIWTXPOW */
699 (iw_handler) NULL, /* SIOCGIWTXPOW */ 413 (iw_handler) cfg80211_wext_giwtxpower, /* SIOCGIWTXPOW */
700 (iw_handler) NULL, /* SIOCSIWRETRY */ 414 (iw_handler) NULL, /* SIOCSIWRETRY */
701 (iw_handler) NULL, /* SIOCGIWRETRY */ 415 (iw_handler) NULL, /* SIOCGIWRETRY */
702 (iw_handler) iwm_wext_siwencode, /* SIOCSIWENCODE */ 416 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */
703 (iw_handler) iwm_wext_giwencode, /* SIOCGIWENCODE */ 417 (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */
704 (iw_handler) iwm_wext_siwpower, /* SIOCSIWPOWER */ 418 (iw_handler) cfg80211_wext_siwpower, /* SIOCSIWPOWER */
705 (iw_handler) iwm_wext_giwpower, /* SIOCGIWPOWER */ 419 (iw_handler) cfg80211_wext_giwpower, /* SIOCGIWPOWER */
706 (iw_handler) NULL, /* -- hole -- */ 420 (iw_handler) NULL, /* -- hole -- */
707 (iw_handler) NULL, /* -- hole -- */ 421 (iw_handler) NULL, /* -- hole -- */
708 (iw_handler) NULL, /* SIOCSIWGENIE */ 422 (iw_handler) NULL, /* SIOCSIWGENIE */
709 (iw_handler) NULL, /* SIOCGIWGENIE */ 423 (iw_handler) NULL, /* SIOCGIWGENIE */
710 (iw_handler) iwm_wext_siwauth, /* SIOCSIWAUTH */ 424 (iw_handler) iwm_wext_siwauth, /* SIOCSIWAUTH */
711 (iw_handler) iwm_wext_giwauth, /* SIOCGIWAUTH */ 425 (iw_handler) iwm_wext_giwauth, /* SIOCGIWAUTH */
712 (iw_handler) iwm_wext_siwencodeext, /* SIOCSIWENCODEEXT */ 426 (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */
713 (iw_handler) NULL, /* SIOCGIWENCODEEXT */ 427 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
714 (iw_handler) NULL, /* SIOCSIWPMKSA */ 428 (iw_handler) NULL, /* SIOCSIWPMKSA */
715 (iw_handler) NULL, /* -- hole -- */ 429 (iw_handler) NULL, /* -- hole -- */
diff --git a/drivers/net/wireless/libertas/assoc.c b/drivers/net/wireless/libertas/assoc.c
index b9b374119033..fbf26499c9a9 100644
--- a/drivers/net/wireless/libertas/assoc.c
+++ b/drivers/net/wireless/libertas/assoc.c
@@ -1368,11 +1368,17 @@ static int assoc_helper_wpa_keys(struct lbs_private *priv,
1368 if (ret) 1368 if (ret)
1369 goto out; 1369 goto out;
1370 1370
1371 memcpy(&priv->wpa_unicast_key, &assoc_req->wpa_unicast_key,
1372 sizeof(struct enc_key));
1373
1371 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { 1374 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
1372 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags); 1375 clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1373 1376
1374 ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req); 1377 ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req);
1375 assoc_req->flags = flags; 1378 assoc_req->flags = flags;
1379
1380 memcpy(&priv->wpa_mcast_key, &assoc_req->wpa_mcast_key,
1381 sizeof(struct enc_key));
1376 } 1382 }
1377 1383
1378out: 1384out:
diff --git a/drivers/net/wireless/libertas/dev.h b/drivers/net/wireless/libertas/dev.h
index f9ec69e04734..578c69783589 100644
--- a/drivers/net/wireless/libertas/dev.h
+++ b/drivers/net/wireless/libertas/dev.h
@@ -260,7 +260,6 @@ struct lbs_private {
260 u16 psmode; /* Wlan802_11PowermodeCAM=disable 260 u16 psmode; /* Wlan802_11PowermodeCAM=disable
261 Wlan802_11PowermodeMAX_PSP=enable */ 261 Wlan802_11PowermodeMAX_PSP=enable */
262 u32 psstate; 262 u32 psstate;
263 char ps_supported;
264 u8 needtowakeup; 263 u8 needtowakeup;
265 264
266 struct assoc_request * pending_assoc_req; 265 struct assoc_request * pending_assoc_req;
diff --git a/drivers/net/wireless/libertas/if_cs.c b/drivers/net/wireless/libertas/if_cs.c
index 2a5b083bf9bd..f658fd6a2c0c 100644
--- a/drivers/net/wireless/libertas/if_cs.c
+++ b/drivers/net/wireless/libertas/if_cs.c
@@ -933,9 +933,6 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
933 goto out3; 933 goto out3;
934 } 934 }
935 935
936 /* The firmware for the CF card supports powersave */
937 priv->ps_supported = 1;
938
939 ret = 0; 936 ret = 0;
940 goto out; 937 goto out;
941 938
diff --git a/drivers/net/wireless/libertas/if_sdio.c b/drivers/net/wireless/libertas/if_sdio.c
index 8cdb88c6ca28..485a8d406525 100644
--- a/drivers/net/wireless/libertas/if_sdio.c
+++ b/drivers/net/wireless/libertas/if_sdio.c
@@ -1039,9 +1039,6 @@ static int if_sdio_probe(struct sdio_func *func,
1039 if (ret) 1039 if (ret)
1040 goto err_activate_card; 1040 goto err_activate_card;
1041 1041
1042 if (priv->fwcapinfo & FW_CAPINFO_PS)
1043 priv->ps_supported = 1;
1044
1045out: 1042out:
1046 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); 1043 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret);
1047 1044
@@ -1096,11 +1093,11 @@ static void if_sdio_remove(struct sdio_func *func)
1096 lbs_pr_alert("CMD_FUNC_SHUTDOWN cmd failed\n"); 1093 lbs_pr_alert("CMD_FUNC_SHUTDOWN cmd failed\n");
1097 } 1094 }
1098 1095
1099 card->priv->surpriseremoved = 1;
1100 1096
1101 lbs_deb_sdio("call remove card\n"); 1097 lbs_deb_sdio("call remove card\n");
1102 lbs_stop_card(card->priv); 1098 lbs_stop_card(card->priv);
1103 lbs_remove_card(card->priv); 1099 lbs_remove_card(card->priv);
1100 card->priv->surpriseremoved = 1;
1104 1101
1105 flush_workqueue(card->workqueue); 1102 flush_workqueue(card->workqueue);
1106 destroy_workqueue(card->workqueue); 1103 destroy_workqueue(card->workqueue);
diff --git a/drivers/net/wireless/libertas/if_spi.c b/drivers/net/wireless/libertas/if_spi.c
index 6564282ce476..963c20125fc9 100644
--- a/drivers/net/wireless/libertas/if_spi.c
+++ b/drivers/net/wireless/libertas/if_spi.c
@@ -737,7 +737,7 @@ static int if_spi_c2h_data(struct if_spi_card *card)
737 goto out; 737 goto out;
738 } else if (len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) { 738 } else if (len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
739 lbs_pr_err("%s: error: card has %d bytes of data, but " 739 lbs_pr_err("%s: error: card has %d bytes of data, but "
740 "our maximum skb size is %lu\n", 740 "our maximum skb size is %zu\n",
741 __func__, len, MRVDRV_ETH_RX_PACKET_BUFFER_SIZE); 741 __func__, len, MRVDRV_ETH_RX_PACKET_BUFFER_SIZE);
742 err = -EINVAL; 742 err = -EINVAL;
743 goto out; 743 goto out;
@@ -1118,7 +1118,6 @@ static int __devinit if_spi_probe(struct spi_device *spi)
1118 priv->card = card; 1118 priv->card = card;
1119 priv->hw_host_to_card = if_spi_host_to_card; 1119 priv->hw_host_to_card = if_spi_host_to_card;
1120 priv->fw_ready = 1; 1120 priv->fw_ready = 1;
1121 priv->ps_supported = 1;
1122 1121
1123 /* Initialize interrupt handling stuff. */ 1122 /* Initialize interrupt handling stuff. */
1124 card->run_thread = 1; 1123 card->run_thread = 1;
@@ -1171,12 +1170,13 @@ static int __devexit libertas_spi_remove(struct spi_device *spi)
1171 1170
1172 lbs_deb_spi("libertas_spi_remove\n"); 1171 lbs_deb_spi("libertas_spi_remove\n");
1173 lbs_deb_enter(LBS_DEB_SPI); 1172 lbs_deb_enter(LBS_DEB_SPI);
1174 priv->surpriseremoved = 1;
1175 1173
1176 lbs_stop_card(priv); 1174 lbs_stop_card(priv);
1175 lbs_remove_card(priv); /* will call free_netdev */
1176
1177 priv->surpriseremoved = 1;
1177 free_irq(spi->irq, card); 1178 free_irq(spi->irq, card);
1178 if_spi_terminate_spi_thread(card); 1179 if_spi_terminate_spi_thread(card);
1179 lbs_remove_card(priv); /* will call free_netdev */
1180 if (card->pdata->teardown) 1180 if (card->pdata->teardown)
1181 card->pdata->teardown(spi); 1181 card->pdata->teardown(spi);
1182 free_if_spi_card(card); 1182 free_if_spi_card(card);
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 1844c5adf6e9..92bc8c5f1ca2 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -181,13 +181,14 @@ static void if_usb_setup_firmware(struct lbs_private *priv)
181 wake_method.action = cpu_to_le16(CMD_ACT_GET); 181 wake_method.action = cpu_to_le16(CMD_ACT_GET);
182 if (lbs_cmd_with_response(priv, CMD_802_11_FW_WAKE_METHOD, &wake_method)) { 182 if (lbs_cmd_with_response(priv, CMD_802_11_FW_WAKE_METHOD, &wake_method)) {
183 lbs_pr_info("Firmware does not seem to support PS mode\n"); 183 lbs_pr_info("Firmware does not seem to support PS mode\n");
184 priv->fwcapinfo &= ~FW_CAPINFO_PS;
184 } else { 185 } else {
185 if (le16_to_cpu(wake_method.method) == CMD_WAKE_METHOD_COMMAND_INT) { 186 if (le16_to_cpu(wake_method.method) == CMD_WAKE_METHOD_COMMAND_INT) {
186 lbs_deb_usb("Firmware seems to support PS with wake-via-command\n"); 187 lbs_deb_usb("Firmware seems to support PS with wake-via-command\n");
187 priv->ps_supported = 1;
188 } else { 188 } else {
189 /* The versions which boot up this way don't seem to 189 /* The versions which boot up this way don't seem to
190 work even if we set it to the command interrupt */ 190 work even if we set it to the command interrupt */
191 priv->fwcapinfo &= ~FW_CAPINFO_PS;
191 lbs_pr_info("Firmware doesn't wake via command interrupt; disabling PS mode\n"); 192 lbs_pr_info("Firmware doesn't wake via command interrupt; disabling PS mode\n");
192 } 193 }
193 } 194 }
diff --git a/drivers/net/wireless/libertas/wext.c b/drivers/net/wireless/libertas/wext.c
index 8bc1907458b1..e96451ce470b 100644
--- a/drivers/net/wireless/libertas/wext.c
+++ b/drivers/net/wireless/libertas/wext.c
@@ -712,7 +712,7 @@ static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
712 712
713 lbs_deb_enter(LBS_DEB_WEXT); 713 lbs_deb_enter(LBS_DEB_WEXT);
714 714
715 if (!priv->ps_supported) { 715 if (!(priv->fwcapinfo & FW_CAPINFO_PS)) {
716 if (vwrq->disabled) 716 if (vwrq->disabled)
717 return 0; 717 return 0;
718 else 718 else
diff --git a/drivers/net/wireless/libertas_tf/main.c b/drivers/net/wireless/libertas_tf/main.c
index 10a99e26d392..4872345a2f61 100644
--- a/drivers/net/wireless/libertas_tf/main.c
+++ b/drivers/net/wireless/libertas_tf/main.c
@@ -503,7 +503,8 @@ int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb)
503 skb_reserve(skb, 2); 503 skb_reserve(skb, 2);
504 } 504 }
505 505
506 ieee80211_rx_irqsafe(priv->hw, skb, &stats); 506 memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
507 ieee80211_rx_irqsafe(priv->hw, skb);
507 return 0; 508 return 0;
508} 509}
509EXPORT_SYMBOL_GPL(lbtf_rx); 510EXPORT_SYMBOL_GPL(lbtf_rx);
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index a111bda392e2..4befa48dbc34 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -15,6 +15,8 @@
15 15
16#include <linux/list.h> 16#include <linux/list.h>
17#include <linux/spinlock.h> 17#include <linux/spinlock.h>
18#include <net/dst.h>
19#include <net/xfrm.h>
18#include <net/mac80211.h> 20#include <net/mac80211.h>
19#include <net/ieee80211_radiotap.h> 21#include <net/ieee80211_radiotap.h>
20#include <linux/if_arp.h> 22#include <linux/if_arp.h>
@@ -314,7 +316,7 @@ static int hwsim_mon_xmit(struct sk_buff *skb, struct net_device *dev)
314{ 316{
315 /* TODO: allow packet injection */ 317 /* TODO: allow packet injection */
316 dev_kfree_skb(skb); 318 dev_kfree_skb(skb);
317 return 0; 319 return NETDEV_TX_OK;
318} 320}
319 321
320 322
@@ -409,6 +411,13 @@ static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
409 if (data->ps != PS_DISABLED) 411 if (data->ps != PS_DISABLED)
410 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); 412 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
411 413
414 /* release the skb's source info */
415 skb_orphan(skb);
416 skb_dst_drop(skb);
417 skb->mark = 0;
418 secpath_reset(skb);
419 nf_reset(skb);
420
412 /* Copy skb to all enabled radios that are on the current frequency */ 421 /* Copy skb to all enabled radios that are on the current frequency */
413 spin_lock(&hwsim_radio_lock); 422 spin_lock(&hwsim_radio_lock);
414 list_for_each_entry(data2, &hwsim_radios, list) { 423 list_for_each_entry(data2, &hwsim_radios, list) {
@@ -430,7 +439,8 @@ static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
430 if (memcmp(hdr->addr1, data2->hw->wiphy->perm_addr, 439 if (memcmp(hdr->addr1, data2->hw->wiphy->perm_addr,
431 ETH_ALEN) == 0) 440 ETH_ALEN) == 0)
432 ack = true; 441 ack = true;
433 ieee80211_rx_irqsafe(data2->hw, nskb, &rx_status); 442 memcpy(IEEE80211_SKB_RXCB(nskb), &rx_status, sizeof(rx_status));
443 ieee80211_rx_irqsafe(data2->hw, nskb);
434 } 444 }
435 spin_unlock(&hwsim_radio_lock); 445 spin_unlock(&hwsim_radio_lock);
436 446
@@ -690,6 +700,74 @@ static int mac80211_hwsim_conf_tx(
690 return 0; 700 return 0;
691} 701}
692 702
703#ifdef CONFIG_NL80211_TESTMODE
704/*
705 * This section contains example code for using netlink
706 * attributes with the testmode command in nl80211.
707 */
708
709/* These enums need to be kept in sync with userspace */
710enum hwsim_testmode_attr {
711 __HWSIM_TM_ATTR_INVALID = 0,
712 HWSIM_TM_ATTR_CMD = 1,
713 HWSIM_TM_ATTR_PS = 2,
714
715 /* keep last */
716 __HWSIM_TM_ATTR_AFTER_LAST,
717 HWSIM_TM_ATTR_MAX = __HWSIM_TM_ATTR_AFTER_LAST - 1
718};
719
720enum hwsim_testmode_cmd {
721 HWSIM_TM_CMD_SET_PS = 0,
722 HWSIM_TM_CMD_GET_PS = 1,
723};
724
725static const struct nla_policy hwsim_testmode_policy[HWSIM_TM_ATTR_MAX + 1] = {
726 [HWSIM_TM_ATTR_CMD] = { .type = NLA_U32 },
727 [HWSIM_TM_ATTR_PS] = { .type = NLA_U32 },
728};
729
730static int hwsim_fops_ps_write(void *dat, u64 val);
731
732static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw *hw,
733 void *data, int len)
734{
735 struct mac80211_hwsim_data *hwsim = hw->priv;
736 struct nlattr *tb[HWSIM_TM_ATTR_MAX + 1];
737 struct sk_buff *skb;
738 int err, ps;
739
740 err = nla_parse(tb, HWSIM_TM_ATTR_MAX, data, len,
741 hwsim_testmode_policy);
742 if (err)
743 return err;
744
745 if (!tb[HWSIM_TM_ATTR_CMD])
746 return -EINVAL;
747
748 switch (nla_get_u32(tb[HWSIM_TM_ATTR_CMD])) {
749 case HWSIM_TM_CMD_SET_PS:
750 if (!tb[HWSIM_TM_ATTR_PS])
751 return -EINVAL;
752 ps = nla_get_u32(tb[HWSIM_TM_ATTR_PS]);
753 return hwsim_fops_ps_write(hwsim, ps);
754 case HWSIM_TM_CMD_GET_PS:
755 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
756 nla_total_size(sizeof(u32)));
757 if (!skb)
758 return -ENOMEM;
759 NLA_PUT_U32(skb, HWSIM_TM_ATTR_PS, hwsim->ps);
760 return cfg80211_testmode_reply(skb);
761 default:
762 return -EOPNOTSUPP;
763 }
764
765 nla_put_failure:
766 kfree_skb(skb);
767 return -ENOBUFS;
768}
769#endif
770
693static const struct ieee80211_ops mac80211_hwsim_ops = 771static const struct ieee80211_ops mac80211_hwsim_ops =
694{ 772{
695 .tx = mac80211_hwsim_tx, 773 .tx = mac80211_hwsim_tx,
@@ -703,6 +781,7 @@ static const struct ieee80211_ops mac80211_hwsim_ops =
703 .sta_notify = mac80211_hwsim_sta_notify, 781 .sta_notify = mac80211_hwsim_sta_notify,
704 .set_tim = mac80211_hwsim_set_tim, 782 .set_tim = mac80211_hwsim_set_tim,
705 .conf_tx = mac80211_hwsim_conf_tx, 783 .conf_tx = mac80211_hwsim_conf_tx,
784 CFG80211_TESTMODE_CMD(mac80211_hwsim_testmode_cmd)
706}; 785};
707 786
708 787
diff --git a/drivers/net/wireless/mwl8k.c b/drivers/net/wireless/mwl8k.c
index a263d5c84c08..b9eded88c322 100644
--- a/drivers/net/wireless/mwl8k.c
+++ b/drivers/net/wireless/mwl8k.c
@@ -1047,7 +1047,8 @@ static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
1047 status.flag = 0; 1047 status.flag = 0;
1048 status.band = IEEE80211_BAND_2GHZ; 1048 status.band = IEEE80211_BAND_2GHZ;
1049 status.freq = ieee80211_channel_to_frequency(rx_desc->channel); 1049 status.freq = ieee80211_channel_to_frequency(rx_desc->channel);
1050 ieee80211_rx_irqsafe(hw, skb, &status); 1050 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1051 ieee80211_rx_irqsafe(hw, skb);
1051 1052
1052 processed++; 1053 processed++;
1053 } 1054 }
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index d63c8992f229..712f26eef35d 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -1047,7 +1047,7 @@ static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1047 } 1047 }
1048 dev_kfree_skb(skb); 1048 dev_kfree_skb(skb);
1049 1049
1050 return 0; 1050 return NETDEV_TX_OK;
1051} /* netwave_start_xmit */ 1051} /* netwave_start_xmit */
1052 1052
1053/* 1053/*
diff --git a/drivers/net/wireless/orinoco/Kconfig b/drivers/net/wireless/orinoco/Kconfig
index 44411eb4e91b..83b635fd7784 100644
--- a/drivers/net/wireless/orinoco/Kconfig
+++ b/drivers/net/wireless/orinoco/Kconfig
@@ -1,6 +1,7 @@
1config HERMES 1config HERMES
2 tristate "Hermes chipset 802.11b support (Orinoco/Prism2/Symbol)" 2 tristate "Hermes chipset 802.11b support (Orinoco/Prism2/Symbol)"
3 depends on (PPC_PMAC || PCI || PCMCIA) && WLAN_80211 3 depends on (PPC_PMAC || PCI || PCMCIA) && WLAN_80211
4 depends on CFG80211
4 select WIRELESS_EXT 5 select WIRELESS_EXT
5 select FW_LOADER 6 select FW_LOADER
6 select CRYPTO 7 select CRYPTO
diff --git a/drivers/net/wireless/orinoco/Makefile b/drivers/net/wireless/orinoco/Makefile
index 1fc7409d6699..9abd6329bcbd 100644
--- a/drivers/net/wireless/orinoco/Makefile
+++ b/drivers/net/wireless/orinoco/Makefile
@@ -1,7 +1,7 @@
1# 1#
2# Makefile for the orinoco wireless device drivers. 2# Makefile for the orinoco wireless device drivers.
3# 3#
4orinoco-objs := main.o fw.o hw.o mic.o scan.o wext.o hermes_dld.o hermes.o 4orinoco-objs := main.o fw.o hw.o mic.o scan.o wext.o hermes_dld.o hermes.o cfg.o
5 5
6obj-$(CONFIG_HERMES) += orinoco.o 6obj-$(CONFIG_HERMES) += orinoco.o
7obj-$(CONFIG_PCMCIA_HERMES) += orinoco_cs.o 7obj-$(CONFIG_PCMCIA_HERMES) += orinoco_cs.o
diff --git a/drivers/net/wireless/orinoco/airport.c b/drivers/net/wireless/orinoco/airport.c
index 8c4065f1b0d0..c60df2c1aca3 100644
--- a/drivers/net/wireless/orinoco/airport.c
+++ b/drivers/net/wireless/orinoco/airport.c
@@ -27,6 +27,7 @@
27struct airport { 27struct airport {
28 struct macio_dev *mdev; 28 struct macio_dev *mdev;
29 void __iomem *vaddr; 29 void __iomem *vaddr;
30 unsigned int irq;
30 int irq_requested; 31 int irq_requested;
31 int ndev_registered; 32 int ndev_registered;
32}; 33};
@@ -34,8 +35,9 @@ struct airport {
34static int 35static int
35airport_suspend(struct macio_dev *mdev, pm_message_t state) 36airport_suspend(struct macio_dev *mdev, pm_message_t state)
36{ 37{
37 struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev); 38 struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
38 struct orinoco_private *priv = netdev_priv(dev); 39 struct net_device *dev = priv->ndev;
40 struct airport *card = priv->card;
39 unsigned long flags; 41 unsigned long flags;
40 int err; 42 int err;
41 43
@@ -48,18 +50,10 @@ airport_suspend(struct macio_dev *mdev, pm_message_t state)
48 return 0; 50 return 0;
49 } 51 }
50 52
51 err = __orinoco_down(dev); 53 orinoco_down(priv);
52 if (err)
53 printk(KERN_WARNING "%s: PBOOK_SLEEP_NOW: Error %d downing interface\n",
54 dev->name, err);
55
56 netif_device_detach(dev);
57
58 priv->hw_unavailable++;
59
60 orinoco_unlock(priv, &flags); 54 orinoco_unlock(priv, &flags);
61 55
62 disable_irq(dev->irq); 56 disable_irq(card->irq);
63 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, 57 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
64 macio_get_of_node(mdev), 0, 0); 58 macio_get_of_node(mdev), 0, 0);
65 59
@@ -69,8 +63,9 @@ airport_suspend(struct macio_dev *mdev, pm_message_t state)
69static int 63static int
70airport_resume(struct macio_dev *mdev) 64airport_resume(struct macio_dev *mdev)
71{ 65{
72 struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev); 66 struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
73 struct orinoco_private *priv = netdev_priv(dev); 67 struct net_device *dev = priv->ndev;
68 struct airport *card = priv->card;
74 unsigned long flags; 69 unsigned long flags;
75 int err; 70 int err;
76 71
@@ -80,47 +75,27 @@ airport_resume(struct macio_dev *mdev)
80 macio_get_of_node(mdev), 0, 1); 75 macio_get_of_node(mdev), 0, 1);
81 msleep(200); 76 msleep(200);
82 77
83 enable_irq(dev->irq); 78 enable_irq(card->irq);
84
85 err = orinoco_reinit_firmware(dev);
86 if (err) {
87 printk(KERN_ERR "%s: Error %d re-initializing firmware on PBOOK_WAKE\n",
88 dev->name, err);
89 return 0;
90 }
91 79
92 spin_lock_irqsave(&priv->lock, flags); 80 spin_lock_irqsave(&priv->lock, flags);
93 81 err = orinoco_up(priv);
94 netif_device_attach(dev);
95
96 priv->hw_unavailable--;
97
98 if (priv->open && (!priv->hw_unavailable)) {
99 err = __orinoco_up(dev);
100 if (err)
101 printk(KERN_ERR "%s: Error %d restarting card on PBOOK_WAKE\n",
102 dev->name, err);
103 }
104
105
106 spin_unlock_irqrestore(&priv->lock, flags); 82 spin_unlock_irqrestore(&priv->lock, flags);
107 83
108 return 0; 84 return err;
109} 85}
110 86
111static int 87static int
112airport_detach(struct macio_dev *mdev) 88airport_detach(struct macio_dev *mdev)
113{ 89{
114 struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev); 90 struct orinoco_private *priv = dev_get_drvdata(&mdev->ofdev.dev);
115 struct orinoco_private *priv = netdev_priv(dev);
116 struct airport *card = priv->card; 91 struct airport *card = priv->card;
117 92
118 if (card->ndev_registered) 93 if (card->ndev_registered)
119 unregister_netdev(dev); 94 orinoco_if_del(priv);
120 card->ndev_registered = 0; 95 card->ndev_registered = 0;
121 96
122 if (card->irq_requested) 97 if (card->irq_requested)
123 free_irq(dev->irq, dev); 98 free_irq(card->irq, priv);
124 card->irq_requested = 0; 99 card->irq_requested = 0;
125 100
126 if (card->vaddr) 101 if (card->vaddr)
@@ -134,7 +109,7 @@ airport_detach(struct macio_dev *mdev)
134 ssleep(1); 109 ssleep(1);
135 110
136 macio_set_drvdata(mdev, NULL); 111 macio_set_drvdata(mdev, NULL);
137 free_orinocodev(dev); 112 free_orinocodev(priv);
138 113
139 return 0; 114 return 0;
140} 115}
@@ -146,7 +121,6 @@ static int airport_hard_reset(struct orinoco_private *priv)
146 * re-initialize properly, it falls in a screaming heap 121 * re-initialize properly, it falls in a screaming heap
147 * shortly afterwards. */ 122 * shortly afterwards. */
148#if 0 123#if 0
149 struct net_device *dev = priv->ndev;
150 struct airport *card = priv->card; 124 struct airport *card = priv->card;
151 125
152 /* Vitally important. If we don't do this it seems we get an 126 /* Vitally important. If we don't do this it seems we get an
@@ -154,7 +128,7 @@ static int airport_hard_reset(struct orinoco_private *priv)
154 * hw_unavailable is already set it doesn't get ACKed, we get 128 * hw_unavailable is already set it doesn't get ACKed, we get
155 * into an interrupt loop and the PMU decides to turn us 129 * into an interrupt loop and the PMU decides to turn us
156 * off. */ 130 * off. */
157 disable_irq(dev->irq); 131 disable_irq(card->irq);
158 132
159 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, 133 pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE,
160 macio_get_of_node(card->mdev), 0, 0); 134 macio_get_of_node(card->mdev), 0, 0);
@@ -163,7 +137,7 @@ static int airport_hard_reset(struct orinoco_private *priv)
163 macio_get_of_node(card->mdev), 0, 1); 137 macio_get_of_node(card->mdev), 0, 1);
164 ssleep(1); 138 ssleep(1);
165 139
166 enable_irq(dev->irq); 140 enable_irq(card->irq);
167 ssleep(1); 141 ssleep(1);
168#endif 142#endif
169 143
@@ -174,7 +148,6 @@ static int
174airport_attach(struct macio_dev *mdev, const struct of_device_id *match) 148airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
175{ 149{
176 struct orinoco_private *priv; 150 struct orinoco_private *priv;
177 struct net_device *dev;
178 struct airport *card; 151 struct airport *card;
179 unsigned long phys_addr; 152 unsigned long phys_addr;
180 hermes_t *hw; 153 hermes_t *hw;
@@ -185,33 +158,29 @@ airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
185 } 158 }
186 159
187 /* Allocate space for private device-specific data */ 160 /* Allocate space for private device-specific data */
188 dev = alloc_orinocodev(sizeof(*card), &mdev->ofdev.dev, 161 priv = alloc_orinocodev(sizeof(*card), &mdev->ofdev.dev,
189 airport_hard_reset, NULL); 162 airport_hard_reset, NULL);
190 if (!dev) { 163 if (!priv) {
191 printk(KERN_ERR PFX "Cannot allocate network device\n"); 164 printk(KERN_ERR PFX "Cannot allocate network device\n");
192 return -ENODEV; 165 return -ENODEV;
193 } 166 }
194 priv = netdev_priv(dev);
195 card = priv->card; 167 card = priv->card;
196 168
197 hw = &priv->hw; 169 hw = &priv->hw;
198 card->mdev = mdev; 170 card->mdev = mdev;
199 171
200 if (macio_request_resource(mdev, 0, "airport")) { 172 if (macio_request_resource(mdev, 0, DRIVER_NAME)) {
201 printk(KERN_ERR PFX "can't request IO resource !\n"); 173 printk(KERN_ERR PFX "can't request IO resource !\n");
202 free_orinocodev(dev); 174 free_orinocodev(priv);
203 return -EBUSY; 175 return -EBUSY;
204 } 176 }
205 177
206 SET_NETDEV_DEV(dev, &mdev->ofdev.dev); 178 macio_set_drvdata(mdev, priv);
207
208 macio_set_drvdata(mdev, dev);
209 179
210 /* Setup interrupts & base address */ 180 /* Setup interrupts & base address */
211 dev->irq = macio_irq(mdev, 0); 181 card->irq = macio_irq(mdev, 0);
212 phys_addr = macio_resource_start(mdev, 0); /* Physical address */ 182 phys_addr = macio_resource_start(mdev, 0); /* Physical address */
213 printk(KERN_DEBUG PFX "Physical address %lx\n", phys_addr); 183 printk(KERN_DEBUG PFX "Physical address %lx\n", phys_addr);
214 dev->base_addr = phys_addr;
215 card->vaddr = ioremap(phys_addr, AIRPORT_IO_LEN); 184 card->vaddr = ioremap(phys_addr, AIRPORT_IO_LEN);
216 if (!card->vaddr) { 185 if (!card->vaddr) {
217 printk(KERN_ERR PFX "ioremap() failed\n"); 186 printk(KERN_ERR PFX "ioremap() failed\n");
@@ -228,18 +197,23 @@ airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
228 /* Reset it before we get the interrupt */ 197 /* Reset it before we get the interrupt */
229 hermes_init(hw); 198 hermes_init(hw);
230 199
231 if (request_irq(dev->irq, orinoco_interrupt, 0, dev->name, dev)) { 200 if (request_irq(card->irq, orinoco_interrupt, 0, DRIVER_NAME, priv)) {
232 printk(KERN_ERR PFX "Couldn't get IRQ %d\n", dev->irq); 201 printk(KERN_ERR PFX "Couldn't get IRQ %d\n", card->irq);
233 goto failed; 202 goto failed;
234 } 203 }
235 card->irq_requested = 1; 204 card->irq_requested = 1;
236 205
237 /* Tell the stack we exist */ 206 /* Initialise the main driver */
238 if (register_netdev(dev) != 0) { 207 if (orinoco_init(priv) != 0) {
239 printk(KERN_ERR PFX "register_netdev() failed\n"); 208 printk(KERN_ERR PFX "orinoco_init() failed\n");
209 goto failed;
210 }
211
212 /* Register an interface with the stack */
213 if (orinoco_if_add(priv, phys_addr, card->irq) != 0) {
214 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
240 goto failed; 215 goto failed;
241 } 216 }
242 printk(KERN_DEBUG PFX "Card registered for interface %s\n", dev->name);
243 card->ndev_registered = 1; 217 card->ndev_registered = 1;
244 return 0; 218 return 0;
245 failed: 219 failed:
diff --git a/drivers/net/wireless/orinoco/cfg.c b/drivers/net/wireless/orinoco/cfg.c
new file mode 100644
index 000000000000..1a87d3a0967c
--- /dev/null
+++ b/drivers/net/wireless/orinoco/cfg.c
@@ -0,0 +1,162 @@
1/* cfg80211 support
2 *
3 * See copyright notice in main.c
4 */
5#include <linux/ieee80211.h>
6#include <net/cfg80211.h>
7#include "hw.h"
8#include "main.h"
9#include "orinoco.h"
10
11#include "cfg.h"
12
13/* Supported bitrates. Must agree with hw.c */
14static struct ieee80211_rate orinoco_rates[] = {
15 { .bitrate = 10 },
16 { .bitrate = 20 },
17 { .bitrate = 55 },
18 { .bitrate = 110 },
19};
20
21static const void * const orinoco_wiphy_privid = &orinoco_wiphy_privid;
22
23/* Called after orinoco_private is allocated. */
24void orinoco_wiphy_init(struct wiphy *wiphy)
25{
26 struct orinoco_private *priv = wiphy_priv(wiphy);
27
28 wiphy->privid = orinoco_wiphy_privid;
29
30 set_wiphy_dev(wiphy, priv->dev);
31}
32
33/* Called after firmware is initialised */
34int orinoco_wiphy_register(struct wiphy *wiphy)
35{
36 struct orinoco_private *priv = wiphy_priv(wiphy);
37 int i, channels = 0;
38
39 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
40 wiphy->max_scan_ssids = 1;
41 else
42 wiphy->max_scan_ssids = 0;
43
44 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
45
46 /* TODO: should we set if we only have demo ad-hoc?
47 * (priv->has_port3)
48 */
49 if (priv->has_ibss)
50 wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
51
52 if (!priv->broken_monitor || force_monitor)
53 wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
54
55 priv->band.bitrates = orinoco_rates;
56 priv->band.n_bitrates = ARRAY_SIZE(orinoco_rates);
57
58 /* Only support channels allowed by the card EEPROM */
59 for (i = 0; i < NUM_CHANNELS; i++) {
60 if (priv->channel_mask & (1 << i)) {
61 priv->channels[i].center_freq =
62 ieee80211_dsss_chan_to_freq(i+1);
63 channels++;
64 }
65 }
66 priv->band.channels = priv->channels;
67 priv->band.n_channels = channels;
68
69 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
70 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
71
72 i = 0;
73 if (priv->has_wep) {
74 priv->cipher_suites[i] = WLAN_CIPHER_SUITE_WEP40;
75 i++;
76
77 if (priv->has_big_wep) {
78 priv->cipher_suites[i] = WLAN_CIPHER_SUITE_WEP104;
79 i++;
80 }
81 }
82 if (priv->has_wpa) {
83 priv->cipher_suites[i] = WLAN_CIPHER_SUITE_TKIP;
84 i++;
85 }
86 wiphy->cipher_suites = priv->cipher_suites;
87 wiphy->n_cipher_suites = i;
88
89 wiphy->rts_threshold = priv->rts_thresh;
90 if (!priv->has_mwo)
91 wiphy->frag_threshold = priv->frag_thresh;
92
93 return wiphy_register(wiphy);
94}
95
96static int orinoco_change_vif(struct wiphy *wiphy, struct net_device *dev,
97 enum nl80211_iftype type, u32 *flags,
98 struct vif_params *params)
99{
100 struct orinoco_private *priv = wiphy_priv(wiphy);
101 int err = 0;
102 unsigned long lock;
103
104 if (orinoco_lock(priv, &lock) != 0)
105 return -EBUSY;
106
107 switch (type) {
108 case NL80211_IFTYPE_ADHOC:
109 if (!priv->has_ibss && !priv->has_port3)
110 err = -EINVAL;
111 break;
112
113 case NL80211_IFTYPE_STATION:
114 break;
115
116 case NL80211_IFTYPE_MONITOR:
117 if (priv->broken_monitor && !force_monitor) {
118 printk(KERN_WARNING "%s: Monitor mode support is "
119 "buggy in this firmware, not enabling\n",
120 wiphy_name(wiphy));
121 err = -EINVAL;
122 }
123 break;
124
125 default:
126 err = -EINVAL;
127 }
128
129 if (!err) {
130 priv->iw_mode = type;
131 set_port_type(priv);
132 err = orinoco_commit(priv);
133 }
134
135 orinoco_unlock(priv, &lock);
136
137 return err;
138}
139
140static int orinoco_scan(struct wiphy *wiphy, struct net_device *dev,
141 struct cfg80211_scan_request *request)
142{
143 struct orinoco_private *priv = wiphy_priv(wiphy);
144 int err;
145
146 if (!request)
147 return -EINVAL;
148
149 if (priv->scan_request && priv->scan_request != request)
150 return -EBUSY;
151
152 priv->scan_request = request;
153
154 err = orinoco_hw_trigger_scan(priv, request->ssids);
155
156 return err;
157}
158
159const struct cfg80211_ops orinoco_cfg_ops = {
160 .change_virtual_intf = orinoco_change_vif,
161 .scan = orinoco_scan,
162};
diff --git a/drivers/net/wireless/orinoco/cfg.h b/drivers/net/wireless/orinoco/cfg.h
new file mode 100644
index 000000000000..3ddc96a06cd7
--- /dev/null
+++ b/drivers/net/wireless/orinoco/cfg.h
@@ -0,0 +1,15 @@
1/* cfg80211 support.
2 *
3 * See copyright notice in main.c
4 */
5#ifndef ORINOCO_CFG_H
6#define ORINOCO_CFG_H
7
8#include <net/cfg80211.h>
9
10extern const struct cfg80211_ops orinoco_cfg_ops;
11
12void orinoco_wiphy_init(struct wiphy *wiphy);
13int orinoco_wiphy_register(struct wiphy *wiphy);
14
15#endif /* ORINOCO_CFG_H */
diff --git a/drivers/net/wireless/orinoco/fw.c b/drivers/net/wireless/orinoco/fw.c
index 1084b43e04bc..1257250a1e22 100644
--- a/drivers/net/wireless/orinoco/fw.c
+++ b/drivers/net/wireless/orinoco/fw.c
@@ -4,6 +4,7 @@
4 */ 4 */
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/firmware.h> 6#include <linux/firmware.h>
7#include <linux/device.h>
7 8
8#include "hermes.h" 9#include "hermes.h"
9#include "hermes_dld.h" 10#include "hermes_dld.h"
@@ -99,7 +100,7 @@ orinoco_dl_firmware(struct orinoco_private *priv,
99 const void *end; 100 const void *end;
100 const char *firmware; 101 const char *firmware;
101 const char *fw_err; 102 const char *fw_err;
102 struct net_device *dev = priv->ndev; 103 struct device *dev = priv->dev;
103 int err = 0; 104 int err = 0;
104 105
105 pda = kzalloc(fw->pda_size, GFP_KERNEL); 106 pda = kzalloc(fw->pda_size, GFP_KERNEL);
@@ -111,12 +112,11 @@ orinoco_dl_firmware(struct orinoco_private *priv,
111 else 112 else
112 firmware = fw->sta_fw; 113 firmware = fw->sta_fw;
113 114
114 printk(KERN_DEBUG "%s: Attempting to download firmware %s\n", 115 dev_dbg(dev, "Attempting to download firmware %s\n", firmware);
115 dev->name, firmware);
116 116
117 /* Read current plug data */ 117 /* Read current plug data */
118 err = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 0); 118 err = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 0);
119 printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err); 119 dev_dbg(dev, "Read PDA returned %d\n", err);
120 if (err) 120 if (err)
121 goto free; 121 goto free;
122 122
@@ -124,8 +124,7 @@ orinoco_dl_firmware(struct orinoco_private *priv,
124 err = request_firmware(&fw_entry, firmware, priv->dev); 124 err = request_firmware(&fw_entry, firmware, priv->dev);
125 125
126 if (err) { 126 if (err) {
127 printk(KERN_ERR "%s: Cannot find firmware %s\n", 127 dev_err(dev, "Cannot find firmware %s\n", firmware);
128 dev->name, firmware);
129 err = -ENOENT; 128 err = -ENOENT;
130 goto free; 129 goto free;
131 } 130 }
@@ -136,16 +135,15 @@ orinoco_dl_firmware(struct orinoco_private *priv,
136 135
137 fw_err = validate_fw(hdr, fw_entry->size); 136 fw_err = validate_fw(hdr, fw_entry->size);
138 if (fw_err) { 137 if (fw_err) {
139 printk(KERN_WARNING "%s: Invalid firmware image detected (%s). " 138 dev_warn(dev, "Invalid firmware image detected (%s). "
140 "Aborting download\n", 139 "Aborting download\n", fw_err);
141 dev->name, fw_err);
142 err = -EINVAL; 140 err = -EINVAL;
143 goto abort; 141 goto abort;
144 } 142 }
145 143
146 /* Enable aux port to allow programming */ 144 /* Enable aux port to allow programming */
147 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point)); 145 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
148 printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err); 146 dev_dbg(dev, "Program init returned %d\n", err);
149 if (err != 0) 147 if (err != 0)
150 goto abort; 148 goto abort;
151 149
@@ -156,7 +154,7 @@ orinoco_dl_firmware(struct orinoco_private *priv,
156 end = fw_entry->data + fw_entry->size; 154 end = fw_entry->data + fw_entry->size;
157 155
158 err = hermes_program(hw, first_block, end); 156 err = hermes_program(hw, first_block, end);
159 printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err); 157 dev_dbg(dev, "Program returned %d\n", err);
160 if (err != 0) 158 if (err != 0)
161 goto abort; 159 goto abort;
162 160
@@ -167,19 +165,18 @@ orinoco_dl_firmware(struct orinoco_private *priv,
167 165
168 err = hermes_apply_pda_with_defaults(hw, first_block, end, pda, 166 err = hermes_apply_pda_with_defaults(hw, first_block, end, pda,
169 &pda[fw->pda_size / sizeof(*pda)]); 167 &pda[fw->pda_size / sizeof(*pda)]);
170 printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err); 168 dev_dbg(dev, "Apply PDA returned %d\n", err);
171 if (err) 169 if (err)
172 goto abort; 170 goto abort;
173 171
174 /* Tell card we've finished */ 172 /* Tell card we've finished */
175 err = hermesi_program_end(hw); 173 err = hermesi_program_end(hw);
176 printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err); 174 dev_dbg(dev, "Program end returned %d\n", err);
177 if (err != 0) 175 if (err != 0)
178 goto abort; 176 goto abort;
179 177
180 /* Check if we're running */ 178 /* Check if we're running */
181 printk(KERN_DEBUG "%s: hermes_present returned %d\n", 179 dev_dbg(dev, "hermes_present returned %d\n", hermes_present(hw));
182 dev->name, hermes_present(hw));
183 180
184abort: 181abort:
185 /* If we requested the firmware, release it. */ 182 /* If we requested the firmware, release it. */
@@ -282,14 +279,13 @@ static int
282symbol_dl_firmware(struct orinoco_private *priv, 279symbol_dl_firmware(struct orinoco_private *priv,
283 const struct fw_info *fw) 280 const struct fw_info *fw)
284{ 281{
285 struct net_device *dev = priv->ndev; 282 struct device *dev = priv->dev;
286 int ret; 283 int ret;
287 const struct firmware *fw_entry; 284 const struct firmware *fw_entry;
288 285
289 if (!orinoco_cached_fw_get(priv, true)) { 286 if (!orinoco_cached_fw_get(priv, true)) {
290 if (request_firmware(&fw_entry, fw->pri_fw, priv->dev) != 0) { 287 if (request_firmware(&fw_entry, fw->pri_fw, priv->dev) != 0) {
291 printk(KERN_ERR "%s: Cannot find firmware: %s\n", 288 dev_err(dev, "Cannot find firmware: %s\n", fw->pri_fw);
292 dev->name, fw->pri_fw);
293 return -ENOENT; 289 return -ENOENT;
294 } 290 }
295 } else 291 } else
@@ -302,15 +298,13 @@ symbol_dl_firmware(struct orinoco_private *priv,
302 if (!orinoco_cached_fw_get(priv, true)) 298 if (!orinoco_cached_fw_get(priv, true))
303 release_firmware(fw_entry); 299 release_firmware(fw_entry);
304 if (ret) { 300 if (ret) {
305 printk(KERN_ERR "%s: Primary firmware download failed\n", 301 dev_err(dev, "Primary firmware download failed\n");
306 dev->name);
307 return ret; 302 return ret;
308 } 303 }
309 304
310 if (!orinoco_cached_fw_get(priv, false)) { 305 if (!orinoco_cached_fw_get(priv, false)) {
311 if (request_firmware(&fw_entry, fw->sta_fw, priv->dev) != 0) { 306 if (request_firmware(&fw_entry, fw->sta_fw, priv->dev) != 0) {
312 printk(KERN_ERR "%s: Cannot find firmware: %s\n", 307 dev_err(dev, "Cannot find firmware: %s\n", fw->sta_fw);
313 dev->name, fw->sta_fw);
314 return -ENOENT; 308 return -ENOENT;
315 } 309 }
316 } else 310 } else
@@ -322,8 +316,7 @@ symbol_dl_firmware(struct orinoco_private *priv,
322 if (!orinoco_cached_fw_get(priv, false)) 316 if (!orinoco_cached_fw_get(priv, false))
323 release_firmware(fw_entry); 317 release_firmware(fw_entry);
324 if (ret) { 318 if (ret) {
325 printk(KERN_ERR "%s: Secondary firmware download failed\n", 319 dev_err(dev, "Secondary firmware download failed\n");
326 dev->name);
327 } 320 }
328 321
329 return ret; 322 return ret;
diff --git a/drivers/net/wireless/orinoco/hermes.c b/drivers/net/wireless/orinoco/hermes.c
index f2c918c2572d..1a2fca76fd3c 100644
--- a/drivers/net/wireless/orinoco/hermes.c
+++ b/drivers/net/wireless/orinoco/hermes.c
@@ -469,7 +469,7 @@ int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned bufsize,
469 u16 rlength, rtype; 469 u16 rlength, rtype;
470 unsigned nwords; 470 unsigned nwords;
471 471
472 if ((bufsize < 0) || (bufsize % 2)) 472 if (bufsize % 2)
473 return -EINVAL; 473 return -EINVAL;
474 474
475 err = hermes_docmd_wait(hw, HERMES_CMD_ACCESS, rid, NULL); 475 err = hermes_docmd_wait(hw, HERMES_CMD_ACCESS, rid, NULL);
diff --git a/drivers/net/wireless/orinoco/hermes.h b/drivers/net/wireless/orinoco/hermes.h
index c78c442a02c8..2dddbb597c4d 100644
--- a/drivers/net/wireless/orinoco/hermes.h
+++ b/drivers/net/wireless/orinoco/hermes.h
@@ -342,7 +342,7 @@ struct agere_ext_scan_info {
342 __le64 timestamp; 342 __le64 timestamp;
343 __le16 beacon_interval; 343 __le16 beacon_interval;
344 __le16 capabilities; 344 __le16 capabilities;
345 u8 data[316]; 345 u8 data[0];
346} __attribute__ ((packed)); 346} __attribute__ ((packed));
347 347
348#define HERMES_LINKSTATUS_NOT_CONNECTED (0x0000) 348#define HERMES_LINKSTATUS_NOT_CONNECTED (0x0000)
diff --git a/drivers/net/wireless/orinoco/hermes_dld.c b/drivers/net/wireless/orinoco/hermes_dld.c
index a9ba195cdada..a3eefe109df4 100644
--- a/drivers/net/wireless/orinoco/hermes_dld.c
+++ b/drivers/net/wireless/orinoco/hermes_dld.c
@@ -309,7 +309,7 @@ int hermes_read_pda(hermes_t *hw,
309 309
310 /* Open auxiliary port */ 310 /* Open auxiliary port */
311 ret = hermes_aux_control(hw, 1); 311 ret = hermes_aux_control(hw, 1);
312 printk(KERN_DEBUG PFX "AUX enable returned %d\n", ret); 312 pr_debug(PFX "AUX enable returned %d\n", ret);
313 if (ret) 313 if (ret)
314 return ret; 314 return ret;
315 315
@@ -319,12 +319,12 @@ int hermes_read_pda(hermes_t *hw,
319 319
320 /* Close aux port */ 320 /* Close aux port */
321 ret = hermes_aux_control(hw, 0); 321 ret = hermes_aux_control(hw, 0);
322 printk(KERN_DEBUG PFX "AUX disable returned %d\n", ret); 322 pr_debug(PFX "AUX disable returned %d\n", ret);
323 323
324 /* Check PDA length */ 324 /* Check PDA length */
325 pda_size = le16_to_cpu(pda[0]); 325 pda_size = le16_to_cpu(pda[0]);
326 printk(KERN_DEBUG PFX "Actual PDA length %d, Max allowed %d\n", 326 pr_debug(PFX "Actual PDA length %d, Max allowed %d\n",
327 pda_size, pda_len); 327 pda_size, pda_len);
328 if (pda_size > pda_len) 328 if (pda_size > pda_len)
329 return -EINVAL; 329 return -EINVAL;
330 330
@@ -422,20 +422,19 @@ int hermesi_program_init(hermes_t *hw, u32 offset)
422 return err; 422 return err;
423 423
424 err = hermes_aux_control(hw, 1); 424 err = hermes_aux_control(hw, 1);
425 printk(KERN_DEBUG PFX "AUX enable returned %d\n", err); 425 pr_debug(PFX "AUX enable returned %d\n", err);
426 426
427 if (err) 427 if (err)
428 return err; 428 return err;
429 429
430 printk(KERN_DEBUG PFX "Enabling volatile, EP 0x%08x\n", offset); 430 pr_debug(KERN_DEBUG PFX "Enabling volatile, EP 0x%08x\n", offset);
431 err = hermes_doicmd_wait(hw, 431 err = hermes_doicmd_wait(hw,
432 HERMES_PROGRAM_ENABLE_VOLATILE, 432 HERMES_PROGRAM_ENABLE_VOLATILE,
433 offset & 0xFFFFu, 433 offset & 0xFFFFu,
434 offset >> 16, 434 offset >> 16,
435 0, 435 0,
436 NULL); 436 NULL);
437 printk(KERN_DEBUG PFX "PROGRAM_ENABLE returned %d\n", 437 pr_debug(PFX "PROGRAM_ENABLE returned %d\n", err);
438 err);
439 438
440 return err; 439 return err;
441} 440}
@@ -454,16 +453,16 @@ int hermesi_program_end(hermes_t *hw)
454 453
455 rc = hermes_docmd_wait(hw, HERMES_PROGRAM_DISABLE, 0, &resp); 454 rc = hermes_docmd_wait(hw, HERMES_PROGRAM_DISABLE, 0, &resp);
456 455
457 printk(KERN_DEBUG PFX "PROGRAM_DISABLE returned %d, " 456 pr_debug(PFX "PROGRAM_DISABLE returned %d, "
458 "r0 0x%04x, r1 0x%04x, r2 0x%04x\n", 457 "r0 0x%04x, r1 0x%04x, r2 0x%04x\n",
459 rc, resp.resp0, resp.resp1, resp.resp2); 458 rc, resp.resp0, resp.resp1, resp.resp2);
460 459
461 if ((rc == 0) && 460 if ((rc == 0) &&
462 ((resp.status & HERMES_STATUS_CMDCODE) != HERMES_CMD_DOWNLD)) 461 ((resp.status & HERMES_STATUS_CMDCODE) != HERMES_CMD_DOWNLD))
463 rc = -EIO; 462 rc = -EIO;
464 463
465 err = hermes_aux_control(hw, 0); 464 err = hermes_aux_control(hw, 0);
466 printk(KERN_DEBUG PFX "AUX disable returned %d\n", err); 465 pr_debug(PFX "AUX disable returned %d\n", err);
467 466
468 /* Acknowledge any outstanding command */ 467 /* Acknowledge any outstanding command */
469 hermes_write_regn(hw, EVACK, 0xFFFF); 468 hermes_write_regn(hw, EVACK, 0xFFFF);
@@ -496,9 +495,8 @@ int hermes_program(hermes_t *hw, const char *first_block, const void *end)
496 495
497 while ((blkaddr != BLOCK_END) && 496 while ((blkaddr != BLOCK_END) &&
498 (((void *) blk + blklen) <= end)) { 497 (((void *) blk + blklen) <= end)) {
499 printk(KERN_DEBUG PFX 498 pr_debug(PFX "Programming block of length %d "
500 "Programming block of length %d to address 0x%08x\n", 499 "to address 0x%08x\n", blklen, blkaddr);
501 blklen, blkaddr);
502 500
503#if !LIMIT_PROGRAM_SIZE 501#if !LIMIT_PROGRAM_SIZE
504 /* wl_lkm driver splits this into writes of 2000 bytes */ 502 /* wl_lkm driver splits this into writes of 2000 bytes */
@@ -510,10 +508,9 @@ int hermes_program(hermes_t *hw, const char *first_block, const void *end)
510 addr = blkaddr; 508 addr = blkaddr;
511 509
512 while (addr < (blkaddr + blklen)) { 510 while (addr < (blkaddr + blklen)) {
513 printk(KERN_DEBUG PFX 511 pr_debug(PFX "Programming subblock of length %d "
514 "Programming subblock of length %d " 512 "to address 0x%08x. Data @ %p\n",
515 "to address 0x%08x. Data @ %p\n", 513 len, addr, &blk->data[addr - blkaddr]);
516 len, addr, &blk->data[addr - blkaddr]);
517 514
518 hermes_aux_setaddr(hw, addr); 515 hermes_aux_setaddr(hw, addr);
519 hermes_write_bytes(hw, HERMES_AUXDATA, 516 hermes_write_bytes(hw, HERMES_AUXDATA,
@@ -643,8 +640,8 @@ int hermes_apply_pda_with_defaults(hermes_t *hw,
643 640
644 pdi = hermes_find_pdi(first_pdi, record_id, pda_end); 641 pdi = hermes_find_pdi(first_pdi, record_id, pda_end);
645 if (pdi) 642 if (pdi)
646 printk(KERN_DEBUG PFX "Found record 0x%04x at %p\n", 643 pr_debug(PFX "Found record 0x%04x at %p\n",
647 record_id, pdi); 644 record_id, pdi);
648 645
649 switch (record_id) { 646 switch (record_id) {
650 case 0x110: /* Modem REFDAC values */ 647 case 0x110: /* Modem REFDAC values */
@@ -654,9 +651,9 @@ int hermes_apply_pda_with_defaults(hermes_t *hw,
654 default_pdi = NULL; 651 default_pdi = NULL;
655 if (outdoor_pdi) { 652 if (outdoor_pdi) {
656 pdi = outdoor_pdi; 653 pdi = outdoor_pdi;
657 printk(KERN_DEBUG PFX 654 pr_debug(PFX
658 "Using outdoor record 0x%04x at %p\n", 655 "Using outdoor record 0x%04x at %p\n",
659 record_id + 1, pdi); 656 record_id + 1, pdi);
660 } 657 }
661 break; 658 break;
662 case 0x5: /* HWIF Compatiblity */ 659 case 0x5: /* HWIF Compatiblity */
@@ -684,9 +681,8 @@ int hermes_apply_pda_with_defaults(hermes_t *hw,
684 if (!pdi && default_pdi) { 681 if (!pdi && default_pdi) {
685 /* Use default */ 682 /* Use default */
686 pdi = default_pdi; 683 pdi = default_pdi;
687 printk(KERN_DEBUG PFX 684 pr_debug(PFX "Using default record 0x%04x at %p\n",
688 "Using default record 0x%04x at %p\n", 685 record_id, pdi);
689 record_id, pdi);
690 } 686 }
691 687
692 if (pdi) { 688 if (pdi) {
diff --git a/drivers/net/wireless/orinoco/hw.c b/drivers/net/wireless/orinoco/hw.c
index 632fac86a308..fa508af1a351 100644
--- a/drivers/net/wireless/orinoco/hw.c
+++ b/drivers/net/wireless/orinoco/hw.c
@@ -3,16 +3,22 @@
3 * See copyright notice in main.c 3 * See copyright notice in main.c
4 */ 4 */
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/device.h>
6#include <linux/if_arp.h> 7#include <linux/if_arp.h>
7#include <linux/ieee80211.h> 8#include <linux/ieee80211.h>
8#include <linux/wireless.h> 9#include <linux/wireless.h>
9 10#include <net/cfg80211.h>
10#include "hermes.h" 11#include "hermes.h"
11#include "hermes_rid.h" 12#include "hermes_rid.h"
12#include "orinoco.h" 13#include "orinoco.h"
13 14
14#include "hw.h" 15#include "hw.h"
15 16
17#define SYMBOL_MAX_VER_LEN (14)
18
19/* Symbol firmware has a bug allocating buffers larger than this */
20#define TX_NICBUF_SIZE_BUG 1585
21
16/********************************************************************/ 22/********************************************************************/
17/* Data tables */ 23/* Data tables */
18/********************************************************************/ 24/********************************************************************/
@@ -36,6 +42,343 @@ static const struct {
36}; 42};
37#define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table) 43#define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
38 44
45/* Firmware version encoding */
46struct comp_id {
47 u16 id, variant, major, minor;
48} __attribute__ ((packed));
49
50static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
51{
52 if (nic_id->id < 0x8000)
53 return FIRMWARE_TYPE_AGERE;
54 else if (nic_id->id == 0x8000 && nic_id->major == 0)
55 return FIRMWARE_TYPE_SYMBOL;
56 else
57 return FIRMWARE_TYPE_INTERSIL;
58}
59
60/* Set priv->firmware type, determine firmware properties
61 * This function can be called before we have registerred with netdev,
62 * so all errors go out with dev_* rather than printk
63 */
64int determine_fw_capabilities(struct orinoco_private *priv)
65{
66 struct device *dev = priv->dev;
67 hermes_t *hw = &priv->hw;
68 int err;
69 struct comp_id nic_id, sta_id;
70 unsigned int firmver;
71 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
72
73 /* Get the hardware version */
74 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
75 if (err) {
76 dev_err(dev, "Cannot read hardware identity: error %d\n",
77 err);
78 return err;
79 }
80
81 le16_to_cpus(&nic_id.id);
82 le16_to_cpus(&nic_id.variant);
83 le16_to_cpus(&nic_id.major);
84 le16_to_cpus(&nic_id.minor);
85 dev_info(dev, "Hardware identity %04x:%04x:%04x:%04x\n",
86 nic_id.id, nic_id.variant, nic_id.major, nic_id.minor);
87
88 priv->firmware_type = determine_firmware_type(&nic_id);
89
90 /* Get the firmware version */
91 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
92 if (err) {
93 dev_err(dev, "Cannot read station identity: error %d\n",
94 err);
95 return err;
96 }
97
98 le16_to_cpus(&sta_id.id);
99 le16_to_cpus(&sta_id.variant);
100 le16_to_cpus(&sta_id.major);
101 le16_to_cpus(&sta_id.minor);
102 dev_info(dev, "Station identity %04x:%04x:%04x:%04x\n",
103 sta_id.id, sta_id.variant, sta_id.major, sta_id.minor);
104
105 switch (sta_id.id) {
106 case 0x15:
107 dev_err(dev, "Primary firmware is active\n");
108 return -ENODEV;
109 case 0x14b:
110 dev_err(dev, "Tertiary firmware is active\n");
111 return -ENODEV;
112 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
113 case 0x21: /* Symbol Spectrum24 Trilogy */
114 break;
115 default:
116 dev_notice(dev, "Unknown station ID, please report\n");
117 break;
118 }
119
120 /* Default capabilities */
121 priv->has_sensitivity = 1;
122 priv->has_mwo = 0;
123 priv->has_preamble = 0;
124 priv->has_port3 = 1;
125 priv->has_ibss = 1;
126 priv->has_wep = 0;
127 priv->has_big_wep = 0;
128 priv->has_alt_txcntl = 0;
129 priv->has_ext_scan = 0;
130 priv->has_wpa = 0;
131 priv->do_fw_download = 0;
132
133 /* Determine capabilities from the firmware version */
134 switch (priv->firmware_type) {
135 case FIRMWARE_TYPE_AGERE:
136 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
137 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
138 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
139 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
140
141 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
142
143 priv->has_ibss = (firmver >= 0x60006);
144 priv->has_wep = (firmver >= 0x40020);
145 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
146 Gold cards from the others? */
147 priv->has_mwo = (firmver >= 0x60000);
148 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
149 priv->ibss_port = 1;
150 priv->has_hostscan = (firmver >= 0x8000a);
151 priv->do_fw_download = 1;
152 priv->broken_monitor = (firmver >= 0x80000);
153 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
154 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
155 priv->has_wpa = (firmver >= 0x9002a);
156 /* Tested with Agere firmware :
157 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
158 * Tested CableTron firmware : 4.32 => Anton */
159 break;
160 case FIRMWARE_TYPE_SYMBOL:
161 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
162 /* Intel MAC : 00:02:B3:* */
163 /* 3Com MAC : 00:50:DA:* */
164 memset(tmp, 0, sizeof(tmp));
165 /* Get the Symbol firmware version */
166 err = hermes_read_ltv(hw, USER_BAP,
167 HERMES_RID_SECONDARYVERSION_SYMBOL,
168 SYMBOL_MAX_VER_LEN, NULL, &tmp);
169 if (err) {
170 dev_warn(dev, "Error %d reading Symbol firmware info. "
171 "Wildly guessing capabilities...\n", err);
172 firmver = 0;
173 tmp[0] = '\0';
174 } else {
175 /* The firmware revision is a string, the format is
176 * something like : "V2.20-01".
177 * Quick and dirty parsing... - Jean II
178 */
179 firmver = ((tmp[1] - '0') << 16)
180 | ((tmp[3] - '0') << 12)
181 | ((tmp[4] - '0') << 8)
182 | ((tmp[6] - '0') << 4)
183 | (tmp[7] - '0');
184
185 tmp[SYMBOL_MAX_VER_LEN] = '\0';
186 }
187
188 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
189 "Symbol %s", tmp);
190
191 priv->has_ibss = (firmver >= 0x20000);
192 priv->has_wep = (firmver >= 0x15012);
193 priv->has_big_wep = (firmver >= 0x20000);
194 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
195 (firmver >= 0x29000 && firmver < 0x30000) ||
196 firmver >= 0x31000;
197 priv->has_preamble = (firmver >= 0x20000);
198 priv->ibss_port = 4;
199
200 /* Symbol firmware is found on various cards, but
201 * there has been no attempt to check firmware
202 * download on non-spectrum_cs based cards.
203 *
204 * Given that the Agere firmware download works
205 * differently, we should avoid doing a firmware
206 * download with the Symbol algorithm on non-spectrum
207 * cards.
208 *
209 * For now we can identify a spectrum_cs based card
210 * because it has a firmware reset function.
211 */
212 priv->do_fw_download = (priv->stop_fw != NULL);
213
214 priv->broken_disableport = (firmver == 0x25013) ||
215 (firmver >= 0x30000 && firmver <= 0x31000);
216 priv->has_hostscan = (firmver >= 0x31001) ||
217 (firmver >= 0x29057 && firmver < 0x30000);
218 /* Tested with Intel firmware : 0x20015 => Jean II */
219 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
220 break;
221 case FIRMWARE_TYPE_INTERSIL:
222 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
223 * Samsung, Compaq 100/200 and Proxim are slightly
224 * different and less well tested */
225 /* D-Link MAC : 00:40:05:* */
226 /* Addtron MAC : 00:90:D1:* */
227 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
228 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
229 sta_id.variant);
230
231 firmver = ((unsigned long)sta_id.major << 16) |
232 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
233
234 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
235 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
236 priv->has_pm = (firmver >= 0x000700);
237 priv->has_hostscan = (firmver >= 0x010301);
238
239 if (firmver >= 0x000800)
240 priv->ibss_port = 0;
241 else {
242 dev_notice(dev, "Intersil firmware earlier than v0.8.x"
243 " - several features not supported\n");
244 priv->ibss_port = 1;
245 }
246 break;
247 }
248 dev_info(dev, "Firmware determined as %s\n", priv->fw_name);
249
250 return 0;
251}
252
253/* Read settings from EEPROM into our private structure.
254 * MAC address gets dropped into callers buffer
255 * Can be called before netdev registration.
256 */
257int orinoco_hw_read_card_settings(struct orinoco_private *priv, u8 *dev_addr)
258{
259 struct device *dev = priv->dev;
260 struct hermes_idstring nickbuf;
261 hermes_t *hw = &priv->hw;
262 int len;
263 int err;
264 u16 reclen;
265
266 /* Get the MAC address */
267 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
268 ETH_ALEN, NULL, dev_addr);
269 if (err) {
270 dev_warn(dev, "Failed to read MAC address!\n");
271 goto out;
272 }
273
274 dev_dbg(dev, "MAC address %pM\n", dev_addr);
275
276 /* Get the station name */
277 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
278 sizeof(nickbuf), &reclen, &nickbuf);
279 if (err) {
280 dev_err(dev, "failed to read station name\n");
281 goto out;
282 }
283 if (nickbuf.len)
284 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
285 else
286 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
287 memcpy(priv->nick, &nickbuf.val, len);
288 priv->nick[len] = '\0';
289
290 dev_dbg(dev, "Station name \"%s\"\n", priv->nick);
291
292 /* Get allowed channels */
293 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
294 &priv->channel_mask);
295 if (err) {
296 dev_err(dev, "Failed to read channel list!\n");
297 goto out;
298 }
299
300 /* Get initial AP density */
301 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
302 &priv->ap_density);
303 if (err || priv->ap_density < 1 || priv->ap_density > 3)
304 priv->has_sensitivity = 0;
305
306 /* Get initial RTS threshold */
307 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
308 &priv->rts_thresh);
309 if (err) {
310 dev_err(dev, "Failed to read RTS threshold!\n");
311 goto out;
312 }
313
314 /* Get initial fragmentation settings */
315 if (priv->has_mwo)
316 err = hermes_read_wordrec(hw, USER_BAP,
317 HERMES_RID_CNFMWOROBUST_AGERE,
318 &priv->mwo_robust);
319 else
320 err = hermes_read_wordrec(hw, USER_BAP,
321 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
322 &priv->frag_thresh);
323 if (err) {
324 dev_err(dev, "Failed to read fragmentation settings!\n");
325 goto out;
326 }
327
328 /* Power management setup */
329 if (priv->has_pm) {
330 priv->pm_on = 0;
331 priv->pm_mcast = 1;
332 err = hermes_read_wordrec(hw, USER_BAP,
333 HERMES_RID_CNFMAXSLEEPDURATION,
334 &priv->pm_period);
335 if (err) {
336 dev_err(dev, "Failed to read power management "
337 "period!\n");
338 goto out;
339 }
340 err = hermes_read_wordrec(hw, USER_BAP,
341 HERMES_RID_CNFPMHOLDOVERDURATION,
342 &priv->pm_timeout);
343 if (err) {
344 dev_err(dev, "Failed to read power management "
345 "timeout!\n");
346 goto out;
347 }
348 }
349
350 /* Preamble setup */
351 if (priv->has_preamble) {
352 err = hermes_read_wordrec(hw, USER_BAP,
353 HERMES_RID_CNFPREAMBLE_SYMBOL,
354 &priv->preamble);
355 }
356
357out:
358 return err;
359}
360
361/* Can be called before netdev registration */
362int orinoco_hw_allocate_fid(struct orinoco_private *priv)
363{
364 struct device *dev = priv->dev;
365 struct hermes *hw = &priv->hw;
366 int err;
367
368 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
369 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
370 /* Try workaround for old Symbol firmware bug */
371 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
372 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
373
374 dev_warn(dev, "Firmware ALLOC bug detected "
375 "(old Symbol firmware?). Work around %s\n",
376 err ? "failed!" : "ok.");
377 }
378
379 return err;
380}
381
39int orinoco_get_bitratemode(int bitrate, int automatic) 382int orinoco_get_bitratemode(int bitrate, int automatic)
40{ 383{
41 int ratemode = -1; 384 int ratemode = -1;
@@ -63,6 +406,237 @@ void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic)
63 *automatic = bitrate_table[ratemode].automatic; 406 *automatic = bitrate_table[ratemode].automatic;
64} 407}
65 408
409int orinoco_hw_program_rids(struct orinoco_private *priv)
410{
411 struct net_device *dev = priv->ndev;
412 struct wireless_dev *wdev = netdev_priv(dev);
413 hermes_t *hw = &priv->hw;
414 int err;
415 struct hermes_idstring idbuf;
416
417 /* Set the MAC address */
418 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
419 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
420 if (err) {
421 printk(KERN_ERR "%s: Error %d setting MAC address\n",
422 dev->name, err);
423 return err;
424 }
425
426 /* Set up the link mode */
427 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
428 priv->port_type);
429 if (err) {
430 printk(KERN_ERR "%s: Error %d setting port type\n",
431 dev->name, err);
432 return err;
433 }
434 /* Set the channel/frequency */
435 if (priv->channel != 0 && priv->iw_mode != NL80211_IFTYPE_STATION) {
436 err = hermes_write_wordrec(hw, USER_BAP,
437 HERMES_RID_CNFOWNCHANNEL,
438 priv->channel);
439 if (err) {
440 printk(KERN_ERR "%s: Error %d setting channel %d\n",
441 dev->name, err, priv->channel);
442 return err;
443 }
444 }
445
446 if (priv->has_ibss) {
447 u16 createibss;
448
449 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
450 printk(KERN_WARNING "%s: This firmware requires an "
451 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
452 /* With wvlan_cs, in this case, we would crash.
453 * hopefully, this driver will behave better...
454 * Jean II */
455 createibss = 0;
456 } else {
457 createibss = priv->createibss;
458 }
459
460 err = hermes_write_wordrec(hw, USER_BAP,
461 HERMES_RID_CNFCREATEIBSS,
462 createibss);
463 if (err) {
464 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
465 dev->name, err);
466 return err;
467 }
468 }
469
470 /* Set the desired BSSID */
471 err = __orinoco_hw_set_wap(priv);
472 if (err) {
473 printk(KERN_ERR "%s: Error %d setting AP address\n",
474 dev->name, err);
475 return err;
476 }
477
478 /* Set the desired ESSID */
479 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
480 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
481 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
482 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
483 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
484 &idbuf);
485 if (err) {
486 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
487 dev->name, err);
488 return err;
489 }
490 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
491 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
492 &idbuf);
493 if (err) {
494 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
495 dev->name, err);
496 return err;
497 }
498
499 /* Set the station name */
500 idbuf.len = cpu_to_le16(strlen(priv->nick));
501 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
502 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
503 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
504 &idbuf);
505 if (err) {
506 printk(KERN_ERR "%s: Error %d setting nickname\n",
507 dev->name, err);
508 return err;
509 }
510
511 /* Set AP density */
512 if (priv->has_sensitivity) {
513 err = hermes_write_wordrec(hw, USER_BAP,
514 HERMES_RID_CNFSYSTEMSCALE,
515 priv->ap_density);
516 if (err) {
517 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
518 "Disabling sensitivity control\n",
519 dev->name, err);
520
521 priv->has_sensitivity = 0;
522 }
523 }
524
525 /* Set RTS threshold */
526 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
527 priv->rts_thresh);
528 if (err) {
529 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
530 dev->name, err);
531 return err;
532 }
533
534 /* Set fragmentation threshold or MWO robustness */
535 if (priv->has_mwo)
536 err = hermes_write_wordrec(hw, USER_BAP,
537 HERMES_RID_CNFMWOROBUST_AGERE,
538 priv->mwo_robust);
539 else
540 err = hermes_write_wordrec(hw, USER_BAP,
541 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
542 priv->frag_thresh);
543 if (err) {
544 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
545 dev->name, err);
546 return err;
547 }
548
549 /* Set bitrate */
550 err = __orinoco_hw_set_bitrate(priv);
551 if (err) {
552 printk(KERN_ERR "%s: Error %d setting bitrate\n",
553 dev->name, err);
554 return err;
555 }
556
557 /* Set power management */
558 if (priv->has_pm) {
559 err = hermes_write_wordrec(hw, USER_BAP,
560 HERMES_RID_CNFPMENABLED,
561 priv->pm_on);
562 if (err) {
563 printk(KERN_ERR "%s: Error %d setting up PM\n",
564 dev->name, err);
565 return err;
566 }
567
568 err = hermes_write_wordrec(hw, USER_BAP,
569 HERMES_RID_CNFMULTICASTRECEIVE,
570 priv->pm_mcast);
571 if (err) {
572 printk(KERN_ERR "%s: Error %d setting up PM\n",
573 dev->name, err);
574 return err;
575 }
576 err = hermes_write_wordrec(hw, USER_BAP,
577 HERMES_RID_CNFMAXSLEEPDURATION,
578 priv->pm_period);
579 if (err) {
580 printk(KERN_ERR "%s: Error %d setting up PM\n",
581 dev->name, err);
582 return err;
583 }
584 err = hermes_write_wordrec(hw, USER_BAP,
585 HERMES_RID_CNFPMHOLDOVERDURATION,
586 priv->pm_timeout);
587 if (err) {
588 printk(KERN_ERR "%s: Error %d setting up PM\n",
589 dev->name, err);
590 return err;
591 }
592 }
593
594 /* Set preamble - only for Symbol so far... */
595 if (priv->has_preamble) {
596 err = hermes_write_wordrec(hw, USER_BAP,
597 HERMES_RID_CNFPREAMBLE_SYMBOL,
598 priv->preamble);
599 if (err) {
600 printk(KERN_ERR "%s: Error %d setting preamble\n",
601 dev->name, err);
602 return err;
603 }
604 }
605
606 /* Set up encryption */
607 if (priv->has_wep || priv->has_wpa) {
608 err = __orinoco_hw_setup_enc(priv);
609 if (err) {
610 printk(KERN_ERR "%s: Error %d activating encryption\n",
611 dev->name, err);
612 return err;
613 }
614 }
615
616 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
617 /* Enable monitor mode */
618 dev->type = ARPHRD_IEEE80211;
619 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
620 HERMES_TEST_MONITOR, 0, NULL);
621 } else {
622 /* Disable monitor mode */
623 dev->type = ARPHRD_ETHER;
624 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
625 HERMES_TEST_STOP, 0, NULL);
626 }
627 if (err)
628 return err;
629
630 /* Reset promiscuity / multicast*/
631 priv->promiscuous = 0;
632 priv->mc_count = 0;
633
634 /* Record mode change */
635 wdev->iftype = priv->iw_mode;
636
637 return 0;
638}
639
66/* Get tsc from the firmware */ 640/* Get tsc from the firmware */
67int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc) 641int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc)
68{ 642{
@@ -314,7 +888,7 @@ int __orinoco_hw_setup_enc(struct orinoco_private *priv)
314 } else 888 } else
315 master_wep_flag = 0; 889 master_wep_flag = 0;
316 890
317 if (priv->iw_mode == IW_MODE_MONITOR) 891 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
318 master_wep_flag |= HERMES_WEP_HOST_DECRYPT; 892 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
319 893
320 /* Master WEP setting : on/off */ 894 /* Master WEP setting : on/off */
@@ -334,8 +908,8 @@ int __orinoco_hw_setup_enc(struct orinoco_private *priv)
334 * rsc must be 8 bytes 908 * rsc must be 8 bytes
335 * tsc must be 8 bytes or NULL 909 * tsc must be 8 bytes or NULL
336 */ 910 */
337int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx, 911int __orinoco_hw_set_tkip_key(struct orinoco_private *priv, int key_idx,
338 u8 *key, u8 *rsc, u8 *tsc) 912 int set_tx, u8 *key, u8 *rsc, u8 *tsc)
339{ 913{
340 struct { 914 struct {
341 __le16 idx; 915 __le16 idx;
@@ -345,6 +919,7 @@ int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
345 u8 rx_mic[MIC_KEYLEN]; 919 u8 rx_mic[MIC_KEYLEN];
346 u8 tsc[IW_ENCODE_SEQ_MAX_SIZE]; 920 u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
347 } __attribute__ ((packed)) buf; 921 } __attribute__ ((packed)) buf;
922 hermes_t *hw = &priv->hw;
348 int ret; 923 int ret;
349 int err; 924 int err;
350 int k; 925 int k;
@@ -582,3 +1157,88 @@ int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
582 1157
583 return 0; 1158 return 0;
584} 1159}
1160
1161int orinoco_hw_trigger_scan(struct orinoco_private *priv,
1162 const struct cfg80211_ssid *ssid)
1163{
1164 struct net_device *dev = priv->ndev;
1165 hermes_t *hw = &priv->hw;
1166 unsigned long flags;
1167 int err = 0;
1168
1169 if (orinoco_lock(priv, &flags) != 0)
1170 return -EBUSY;
1171
1172 /* Scanning with port 0 disabled would fail */
1173 if (!netif_running(dev)) {
1174 err = -ENETDOWN;
1175 goto out;
1176 }
1177
1178 /* In monitor mode, the scan results are always empty.
1179 * Probe responses are passed to the driver as received
1180 * frames and could be processed in software. */
1181 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
1182 err = -EOPNOTSUPP;
1183 goto out;
1184 }
1185
1186 if (priv->has_hostscan) {
1187 switch (priv->firmware_type) {
1188 case FIRMWARE_TYPE_SYMBOL:
1189 err = hermes_write_wordrec(hw, USER_BAP,
1190 HERMES_RID_CNFHOSTSCAN_SYMBOL,
1191 HERMES_HOSTSCAN_SYMBOL_ONCE |
1192 HERMES_HOSTSCAN_SYMBOL_BCAST);
1193 break;
1194 case FIRMWARE_TYPE_INTERSIL: {
1195 __le16 req[3];
1196
1197 req[0] = cpu_to_le16(0x3fff); /* All channels */
1198 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
1199 req[2] = 0; /* Any ESSID */
1200 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1201 HERMES_RID_CNFHOSTSCAN, &req);
1202 break;
1203 }
1204 case FIRMWARE_TYPE_AGERE:
1205 if (ssid->ssid_len > 0) {
1206 struct hermes_idstring idbuf;
1207 size_t len = ssid->ssid_len;
1208
1209 idbuf.len = cpu_to_le16(len);
1210 memcpy(idbuf.val, ssid->ssid, len);
1211
1212 err = hermes_write_ltv(hw, USER_BAP,
1213 HERMES_RID_CNFSCANSSID_AGERE,
1214 HERMES_BYTES_TO_RECLEN(len + 2),
1215 &idbuf);
1216 } else
1217 err = hermes_write_wordrec(hw, USER_BAP,
1218 HERMES_RID_CNFSCANSSID_AGERE,
1219 0); /* Any ESSID */
1220 if (err)
1221 break;
1222
1223 if (priv->has_ext_scan) {
1224 err = hermes_write_wordrec(hw, USER_BAP,
1225 HERMES_RID_CNFSCANCHANNELS2GHZ,
1226 0x7FFF);
1227 if (err)
1228 goto out;
1229
1230 err = hermes_inquire(hw,
1231 HERMES_INQ_CHANNELINFO);
1232 } else
1233 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1234
1235 break;
1236 }
1237 } else
1238 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1239
1240 out:
1241 orinoco_unlock(priv, &flags);
1242
1243 return err;
1244}
diff --git a/drivers/net/wireless/orinoco/hw.h b/drivers/net/wireless/orinoco/hw.h
index dc3f23a9c1c7..27b427649d1b 100644
--- a/drivers/net/wireless/orinoco/hw.h
+++ b/drivers/net/wireless/orinoco/hw.h
@@ -7,6 +7,7 @@
7 7
8#include <linux/types.h> 8#include <linux/types.h>
9#include <linux/wireless.h> 9#include <linux/wireless.h>
10#include <net/cfg80211.h>
10 11
11/* Hardware BAPs */ 12/* Hardware BAPs */
12#define USER_BAP 0 13#define USER_BAP 0
@@ -23,17 +24,21 @@
23struct orinoco_private; 24struct orinoco_private;
24struct dev_addr_list; 25struct dev_addr_list;
25 26
27int determine_fw_capabilities(struct orinoco_private *priv);
28int orinoco_hw_read_card_settings(struct orinoco_private *priv, u8 *dev_addr);
29int orinoco_hw_allocate_fid(struct orinoco_private *priv);
26int orinoco_get_bitratemode(int bitrate, int automatic); 30int orinoco_get_bitratemode(int bitrate, int automatic);
27void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic); 31void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic);
28 32
33int orinoco_hw_program_rids(struct orinoco_private *priv);
29int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc); 34int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc);
30int __orinoco_hw_set_bitrate(struct orinoco_private *priv); 35int __orinoco_hw_set_bitrate(struct orinoco_private *priv);
31int orinoco_hw_get_act_bitrate(struct orinoco_private *priv, int *bitrate); 36int orinoco_hw_get_act_bitrate(struct orinoco_private *priv, int *bitrate);
32int __orinoco_hw_set_wap(struct orinoco_private *priv); 37int __orinoco_hw_set_wap(struct orinoco_private *priv);
33int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv); 38int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv);
34int __orinoco_hw_setup_enc(struct orinoco_private *priv); 39int __orinoco_hw_setup_enc(struct orinoco_private *priv);
35int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx, 40int __orinoco_hw_set_tkip_key(struct orinoco_private *priv, int key_idx,
36 u8 *key, u8 *rsc, u8 *tsc); 41 int set_tx, u8 *key, u8 *rsc, u8 *tsc);
37int orinoco_clear_tkip_key(struct orinoco_private *priv, int key_idx); 42int orinoco_clear_tkip_key(struct orinoco_private *priv, int key_idx);
38int __orinoco_hw_set_multicast_list(struct orinoco_private *priv, 43int __orinoco_hw_set_multicast_list(struct orinoco_private *priv,
39 struct dev_addr_list *mc_list, 44 struct dev_addr_list *mc_list,
@@ -43,5 +48,7 @@ int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
43int orinoco_hw_get_freq(struct orinoco_private *priv); 48int orinoco_hw_get_freq(struct orinoco_private *priv);
44int orinoco_hw_get_bitratelist(struct orinoco_private *priv, 49int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
45 int *numrates, s32 *rates, int max); 50 int *numrates, s32 *rates, int max);
51int orinoco_hw_trigger_scan(struct orinoco_private *priv,
52 const struct cfg80211_ssid *ssid);
46 53
47#endif /* _ORINOCO_HW_H_ */ 54#endif /* _ORINOCO_HW_H_ */
diff --git a/drivers/net/wireless/orinoco/main.c b/drivers/net/wireless/orinoco/main.c
index a370e510f19f..e8c550a61f33 100644
--- a/drivers/net/wireless/orinoco/main.c
+++ b/drivers/net/wireless/orinoco/main.c
@@ -80,6 +80,7 @@
80#include <linux/kernel.h> 80#include <linux/kernel.h>
81#include <linux/init.h> 81#include <linux/init.h>
82#include <linux/delay.h> 82#include <linux/delay.h>
83#include <linux/device.h>
83#include <linux/netdevice.h> 84#include <linux/netdevice.h>
84#include <linux/etherdevice.h> 85#include <linux/etherdevice.h>
85#include <linux/ethtool.h> 86#include <linux/ethtool.h>
@@ -88,6 +89,7 @@
88#include <linux/wireless.h> 89#include <linux/wireless.h>
89#include <linux/ieee80211.h> 90#include <linux/ieee80211.h>
90#include <net/iw_handler.h> 91#include <net/iw_handler.h>
92#include <net/cfg80211.h>
91 93
92#include "hermes_rid.h" 94#include "hermes_rid.h"
93#include "hermes_dld.h" 95#include "hermes_dld.h"
@@ -96,6 +98,7 @@
96#include "mic.h" 98#include "mic.h"
97#include "fw.h" 99#include "fw.h"
98#include "wext.h" 100#include "wext.h"
101#include "cfg.h"
99#include "main.h" 102#include "main.h"
100 103
101#include "orinoco.h" 104#include "orinoco.h"
@@ -142,13 +145,11 @@ static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
142#define ORINOCO_MIN_MTU 256 145#define ORINOCO_MIN_MTU 256
143#define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD) 146#define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
144 147
145#define SYMBOL_MAX_VER_LEN (14)
146#define MAX_IRQLOOPS_PER_IRQ 10 148#define MAX_IRQLOOPS_PER_IRQ 10
147#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of 149#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
148 * how many events the 150 * how many events the
149 * device could 151 * device could
150 * legitimately generate */ 152 * legitimately generate */
151#define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
152 153
153#define DUMMY_FID 0xFFFF 154#define DUMMY_FID 0xFFFF
154 155
@@ -205,11 +206,21 @@ struct orinoco_rx_data {
205 struct list_head list; 206 struct list_head list;
206}; 207};
207 208
209struct orinoco_scan_data {
210 void *buf;
211 size_t len;
212 int type;
213 struct list_head list;
214};
215
208/********************************************************************/ 216/********************************************************************/
209/* Function prototypes */ 217/* Function prototypes */
210/********************************************************************/ 218/********************************************************************/
211 219
212static void __orinoco_set_multicast_list(struct net_device *dev); 220static int __orinoco_set_multicast_list(struct net_device *dev);
221static int __orinoco_up(struct orinoco_private *priv);
222static int __orinoco_down(struct orinoco_private *priv);
223static int __orinoco_commit(struct orinoco_private *priv);
213 224
214/********************************************************************/ 225/********************************************************************/
215/* Internal helper functions */ 226/* Internal helper functions */
@@ -218,11 +229,11 @@ static void __orinoco_set_multicast_list(struct net_device *dev);
218void set_port_type(struct orinoco_private *priv) 229void set_port_type(struct orinoco_private *priv)
219{ 230{
220 switch (priv->iw_mode) { 231 switch (priv->iw_mode) {
221 case IW_MODE_INFRA: 232 case NL80211_IFTYPE_STATION:
222 priv->port_type = 1; 233 priv->port_type = 1;
223 priv->createibss = 0; 234 priv->createibss = 0;
224 break; 235 break;
225 case IW_MODE_ADHOC: 236 case NL80211_IFTYPE_ADHOC:
226 if (priv->prefer_port3) { 237 if (priv->prefer_port3) {
227 priv->port_type = 3; 238 priv->port_type = 3;
228 priv->createibss = 0; 239 priv->createibss = 0;
@@ -231,7 +242,7 @@ void set_port_type(struct orinoco_private *priv)
231 priv->createibss = 1; 242 priv->createibss = 1;
232 } 243 }
233 break; 244 break;
234 case IW_MODE_MONITOR: 245 case NL80211_IFTYPE_MONITOR:
235 priv->port_type = 3; 246 priv->port_type = 3;
236 priv->createibss = 0; 247 priv->createibss = 0;
237 break; 248 break;
@@ -247,14 +258,14 @@ void set_port_type(struct orinoco_private *priv)
247 258
248static int orinoco_open(struct net_device *dev) 259static int orinoco_open(struct net_device *dev)
249{ 260{
250 struct orinoco_private *priv = netdev_priv(dev); 261 struct orinoco_private *priv = ndev_priv(dev);
251 unsigned long flags; 262 unsigned long flags;
252 int err; 263 int err;
253 264
254 if (orinoco_lock(priv, &flags) != 0) 265 if (orinoco_lock(priv, &flags) != 0)
255 return -EBUSY; 266 return -EBUSY;
256 267
257 err = __orinoco_up(dev); 268 err = __orinoco_up(priv);
258 269
259 if (!err) 270 if (!err)
260 priv->open = 1; 271 priv->open = 1;
@@ -266,7 +277,7 @@ static int orinoco_open(struct net_device *dev)
266 277
267static int orinoco_stop(struct net_device *dev) 278static int orinoco_stop(struct net_device *dev)
268{ 279{
269 struct orinoco_private *priv = netdev_priv(dev); 280 struct orinoco_private *priv = ndev_priv(dev);
270 int err = 0; 281 int err = 0;
271 282
272 /* We mustn't use orinoco_lock() here, because we need to be 283 /* We mustn't use orinoco_lock() here, because we need to be
@@ -276,7 +287,7 @@ static int orinoco_stop(struct net_device *dev)
276 287
277 priv->open = 0; 288 priv->open = 0;
278 289
279 err = __orinoco_down(dev); 290 err = __orinoco_down(priv);
280 291
281 spin_unlock_irq(&priv->lock); 292 spin_unlock_irq(&priv->lock);
282 293
@@ -285,14 +296,14 @@ static int orinoco_stop(struct net_device *dev)
285 296
286static struct net_device_stats *orinoco_get_stats(struct net_device *dev) 297static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
287{ 298{
288 struct orinoco_private *priv = netdev_priv(dev); 299 struct orinoco_private *priv = ndev_priv(dev);
289 300
290 return &priv->stats; 301 return &priv->stats;
291} 302}
292 303
293static void orinoco_set_multicast_list(struct net_device *dev) 304static void orinoco_set_multicast_list(struct net_device *dev)
294{ 305{
295 struct orinoco_private *priv = netdev_priv(dev); 306 struct orinoco_private *priv = ndev_priv(dev);
296 unsigned long flags; 307 unsigned long flags;
297 308
298 if (orinoco_lock(priv, &flags) != 0) { 309 if (orinoco_lock(priv, &flags) != 0) {
@@ -307,7 +318,7 @@ static void orinoco_set_multicast_list(struct net_device *dev)
307 318
308static int orinoco_change_mtu(struct net_device *dev, int new_mtu) 319static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
309{ 320{
310 struct orinoco_private *priv = netdev_priv(dev); 321 struct orinoco_private *priv = ndev_priv(dev);
311 322
312 if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU)) 323 if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
313 return -EINVAL; 324 return -EINVAL;
@@ -328,7 +339,7 @@ static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
328 339
329static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev) 340static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
330{ 341{
331 struct orinoco_private *priv = netdev_priv(dev); 342 struct orinoco_private *priv = ndev_priv(dev);
332 struct net_device_stats *stats = &priv->stats; 343 struct net_device_stats *stats = &priv->stats;
333 hermes_t *hw = &priv->hw; 344 hermes_t *hw = &priv->hw;
334 int err = 0; 345 int err = 0;
@@ -355,7 +366,8 @@ static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
355 return NETDEV_TX_BUSY; 366 return NETDEV_TX_BUSY;
356 } 367 }
357 368
358 if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) { 369 if (!netif_carrier_ok(dev) ||
370 (priv->iw_mode == NL80211_IFTYPE_MONITOR)) {
359 /* Oops, the firmware hasn't established a connection, 371 /* Oops, the firmware hasn't established a connection,
360 silently drop the packet (this seems to be the 372 silently drop the packet (this seems to be the
361 safest approach). */ 373 safest approach). */
@@ -518,7 +530,7 @@ static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
518 530
519static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw) 531static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
520{ 532{
521 struct orinoco_private *priv = netdev_priv(dev); 533 struct orinoco_private *priv = ndev_priv(dev);
522 u16 fid = hermes_read_regn(hw, ALLOCFID); 534 u16 fid = hermes_read_regn(hw, ALLOCFID);
523 535
524 if (fid != priv->txfid) { 536 if (fid != priv->txfid) {
@@ -533,7 +545,7 @@ static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
533 545
534static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw) 546static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
535{ 547{
536 struct orinoco_private *priv = netdev_priv(dev); 548 struct orinoco_private *priv = ndev_priv(dev);
537 struct net_device_stats *stats = &priv->stats; 549 struct net_device_stats *stats = &priv->stats;
538 550
539 stats->tx_packets++; 551 stats->tx_packets++;
@@ -545,7 +557,7 @@ static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
545 557
546static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw) 558static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
547{ 559{
548 struct orinoco_private *priv = netdev_priv(dev); 560 struct orinoco_private *priv = ndev_priv(dev);
549 struct net_device_stats *stats = &priv->stats; 561 struct net_device_stats *stats = &priv->stats;
550 u16 fid = hermes_read_regn(hw, TXCOMPLFID); 562 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
551 u16 status; 563 u16 status;
@@ -601,7 +613,7 @@ static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
601 613
602static void orinoco_tx_timeout(struct net_device *dev) 614static void orinoco_tx_timeout(struct net_device *dev)
603{ 615{
604 struct orinoco_private *priv = netdev_priv(dev); 616 struct orinoco_private *priv = ndev_priv(dev);
605 struct net_device_stats *stats = &priv->stats; 617 struct net_device_stats *stats = &priv->stats;
606 struct hermes *hw = &priv->hw; 618 struct hermes *hw = &priv->hw;
607 619
@@ -650,7 +662,7 @@ static void orinoco_stat_gather(struct net_device *dev,
650 struct sk_buff *skb, 662 struct sk_buff *skb,
651 struct hermes_rx_descriptor *desc) 663 struct hermes_rx_descriptor *desc)
652{ 664{
653 struct orinoco_private *priv = netdev_priv(dev); 665 struct orinoco_private *priv = ndev_priv(dev);
654 666
655 /* Using spy support with lots of Rx packets, like in an 667 /* Using spy support with lots of Rx packets, like in an
656 * infrastructure (AP), will really slow down everything, because 668 * infrastructure (AP), will really slow down everything, because
@@ -687,7 +699,7 @@ static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
687 int err; 699 int err;
688 int len; 700 int len;
689 struct sk_buff *skb; 701 struct sk_buff *skb;
690 struct orinoco_private *priv = netdev_priv(dev); 702 struct orinoco_private *priv = ndev_priv(dev);
691 struct net_device_stats *stats = &priv->stats; 703 struct net_device_stats *stats = &priv->stats;
692 hermes_t *hw = &priv->hw; 704 hermes_t *hw = &priv->hw;
693 705
@@ -778,7 +790,7 @@ static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
778 790
779static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw) 791static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
780{ 792{
781 struct orinoco_private *priv = netdev_priv(dev); 793 struct orinoco_private *priv = ndev_priv(dev);
782 struct net_device_stats *stats = &priv->stats; 794 struct net_device_stats *stats = &priv->stats;
783 struct iw_statistics *wstats = &priv->wstats; 795 struct iw_statistics *wstats = &priv->wstats;
784 struct sk_buff *skb = NULL; 796 struct sk_buff *skb = NULL;
@@ -816,7 +828,7 @@ static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
816 } 828 }
817 829
818 /* Handle frames in monitor mode */ 830 /* Handle frames in monitor mode */
819 if (priv->iw_mode == IW_MODE_MONITOR) { 831 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
820 orinoco_rx_monitor(dev, rxfid, desc); 832 orinoco_rx_monitor(dev, rxfid, desc);
821 goto out; 833 goto out;
822 } 834 }
@@ -902,7 +914,7 @@ static void orinoco_rx(struct net_device *dev,
902 struct hermes_rx_descriptor *desc, 914 struct hermes_rx_descriptor *desc,
903 struct sk_buff *skb) 915 struct sk_buff *skb)
904{ 916{
905 struct orinoco_private *priv = netdev_priv(dev); 917 struct orinoco_private *priv = ndev_priv(dev);
906 struct net_device_stats *stats = &priv->stats; 918 struct net_device_stats *stats = &priv->stats;
907 u16 status, fc; 919 u16 status, fc;
908 int length; 920 int length;
@@ -1016,8 +1028,8 @@ static void orinoco_rx(struct net_device *dev,
1016 1028
1017static void orinoco_rx_isr_tasklet(unsigned long data) 1029static void orinoco_rx_isr_tasklet(unsigned long data)
1018{ 1030{
1019 struct net_device *dev = (struct net_device *) data; 1031 struct orinoco_private *priv = (struct orinoco_private *) data;
1020 struct orinoco_private *priv = netdev_priv(dev); 1032 struct net_device *dev = priv->ndev;
1021 struct orinoco_rx_data *rx_data, *temp; 1033 struct orinoco_rx_data *rx_data, *temp;
1022 struct hermes_rx_descriptor *desc; 1034 struct hermes_rx_descriptor *desc;
1023 struct sk_buff *skb; 1035 struct sk_buff *skb;
@@ -1260,9 +1272,81 @@ static void orinoco_send_wevents(struct work_struct *work)
1260 orinoco_unlock(priv, &flags); 1272 orinoco_unlock(priv, &flags);
1261} 1273}
1262 1274
1275static void qbuf_scan(struct orinoco_private *priv, void *buf,
1276 int len, int type)
1277{
1278 struct orinoco_scan_data *sd;
1279 unsigned long flags;
1280
1281 sd = kmalloc(sizeof(*sd), GFP_ATOMIC);
1282 sd->buf = buf;
1283 sd->len = len;
1284 sd->type = type;
1285
1286 spin_lock_irqsave(&priv->scan_lock, flags);
1287 list_add_tail(&sd->list, &priv->scan_list);
1288 spin_unlock_irqrestore(&priv->scan_lock, flags);
1289
1290 schedule_work(&priv->process_scan);
1291}
1292
1293static void qabort_scan(struct orinoco_private *priv)
1294{
1295 struct orinoco_scan_data *sd;
1296 unsigned long flags;
1297
1298 sd = kmalloc(sizeof(*sd), GFP_ATOMIC);
1299 sd->len = -1; /* Abort */
1300
1301 spin_lock_irqsave(&priv->scan_lock, flags);
1302 list_add_tail(&sd->list, &priv->scan_list);
1303 spin_unlock_irqrestore(&priv->scan_lock, flags);
1304
1305 schedule_work(&priv->process_scan);
1306}
1307
1308static void orinoco_process_scan_results(struct work_struct *work)
1309{
1310 struct orinoco_private *priv =
1311 container_of(work, struct orinoco_private, process_scan);
1312 struct orinoco_scan_data *sd, *temp;
1313 unsigned long flags;
1314 void *buf;
1315 int len;
1316 int type;
1317
1318 spin_lock_irqsave(&priv->scan_lock, flags);
1319 list_for_each_entry_safe(sd, temp, &priv->scan_list, list) {
1320 spin_unlock_irqrestore(&priv->scan_lock, flags);
1321
1322 buf = sd->buf;
1323 len = sd->len;
1324 type = sd->type;
1325
1326 list_del(&sd->list);
1327 kfree(sd);
1328
1329 if (len > 0) {
1330 if (type == HERMES_INQ_CHANNELINFO)
1331 orinoco_add_extscan_result(priv, buf, len);
1332 else
1333 orinoco_add_hostscan_results(priv, buf, len);
1334
1335 kfree(buf);
1336 } else if (priv->scan_request) {
1337 /* Either abort or complete the scan */
1338 cfg80211_scan_done(priv->scan_request, (len < 0));
1339 priv->scan_request = NULL;
1340 }
1341
1342 spin_lock_irqsave(&priv->scan_lock, flags);
1343 }
1344 spin_unlock_irqrestore(&priv->scan_lock, flags);
1345}
1346
1263static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw) 1347static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1264{ 1348{
1265 struct orinoco_private *priv = netdev_priv(dev); 1349 struct orinoco_private *priv = ndev_priv(dev);
1266 u16 infofid; 1350 u16 infofid;
1267 struct { 1351 struct {
1268 __le16 len; 1352 __le16 len;
@@ -1327,7 +1411,7 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1327 u16 newstatus; 1411 u16 newstatus;
1328 int connected; 1412 int connected;
1329 1413
1330 if (priv->iw_mode == IW_MODE_MONITOR) 1414 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
1331 break; 1415 break;
1332 1416
1333 if (len != sizeof(linkstatus)) { 1417 if (len != sizeof(linkstatus)) {
@@ -1346,7 +1430,7 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1346 * the hostscan frame can be requested. */ 1430 * the hostscan frame can be requested. */
1347 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE && 1431 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1348 priv->firmware_type == FIRMWARE_TYPE_SYMBOL && 1432 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1349 priv->has_hostscan && priv->scan_inprogress) { 1433 priv->has_hostscan && priv->scan_request) {
1350 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL); 1434 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1351 break; 1435 break;
1352 } 1436 }
@@ -1372,7 +1456,7 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1372 } 1456 }
1373 break; 1457 break;
1374 case HERMES_INQ_SCAN: 1458 case HERMES_INQ_SCAN:
1375 if (!priv->scan_inprogress && priv->bssid_fixed && 1459 if (!priv->scan_request && priv->bssid_fixed &&
1376 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) { 1460 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1377 schedule_work(&priv->join_work); 1461 schedule_work(&priv->join_work);
1378 break; 1462 break;
@@ -1382,30 +1466,30 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1382 case HERMES_INQ_HOSTSCAN_SYMBOL: { 1466 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1383 /* Result of a scanning. Contains information about 1467 /* Result of a scanning. Contains information about
1384 * cells in the vicinity - Jean II */ 1468 * cells in the vicinity - Jean II */
1385 union iwreq_data wrqu;
1386 unsigned char *buf; 1469 unsigned char *buf;
1387 1470
1388 /* Scan is no longer in progress */
1389 priv->scan_inprogress = 0;
1390
1391 /* Sanity check */ 1471 /* Sanity check */
1392 if (len > 4096) { 1472 if (len > 4096) {
1393 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n", 1473 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1394 dev->name, len); 1474 dev->name, len);
1475 qabort_scan(priv);
1395 break; 1476 break;
1396 } 1477 }
1397 1478
1398 /* Allocate buffer for results */ 1479 /* Allocate buffer for results */
1399 buf = kmalloc(len, GFP_ATOMIC); 1480 buf = kmalloc(len, GFP_ATOMIC);
1400 if (buf == NULL) 1481 if (buf == NULL) {
1401 /* No memory, so can't printk()... */ 1482 /* No memory, so can't printk()... */
1483 qabort_scan(priv);
1402 break; 1484 break;
1485 }
1403 1486
1404 /* Read scan data */ 1487 /* Read scan data */
1405 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len, 1488 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1406 infofid, sizeof(info)); 1489 infofid, sizeof(info));
1407 if (err) { 1490 if (err) {
1408 kfree(buf); 1491 kfree(buf);
1492 qabort_scan(priv);
1409 break; 1493 break;
1410 } 1494 }
1411 1495
@@ -1419,24 +1503,14 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1419 } 1503 }
1420#endif /* ORINOCO_DEBUG */ 1504#endif /* ORINOCO_DEBUG */
1421 1505
1422 if (orinoco_process_scan_results(priv, buf, len) == 0) { 1506 qbuf_scan(priv, buf, len, type);
1423 /* Send an empty event to user space.
1424 * We don't send the received data on the event because
1425 * it would require us to do complex transcoding, and
1426 * we want to minimise the work done in the irq handler
1427 * Use a request to extract the data - Jean II */
1428 wrqu.data.length = 0;
1429 wrqu.data.flags = 0;
1430 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1431 }
1432 kfree(buf);
1433 } 1507 }
1434 break; 1508 break;
1435 case HERMES_INQ_CHANNELINFO: 1509 case HERMES_INQ_CHANNELINFO:
1436 { 1510 {
1437 struct agere_ext_scan_info *bss; 1511 struct agere_ext_scan_info *bss;
1438 1512
1439 if (!priv->scan_inprogress) { 1513 if (!priv->scan_request) {
1440 printk(KERN_DEBUG "%s: Got chaninfo without scan, " 1514 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
1441 "len=%d\n", dev->name, len); 1515 "len=%d\n", dev->name, len);
1442 break; 1516 break;
@@ -1444,25 +1518,12 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1444 1518
1445 /* An empty result indicates that the scan is complete */ 1519 /* An empty result indicates that the scan is complete */
1446 if (len == 0) { 1520 if (len == 0) {
1447 union iwreq_data wrqu; 1521 qbuf_scan(priv, NULL, len, type);
1448
1449 /* Scan is no longer in progress */
1450 priv->scan_inprogress = 0;
1451
1452 wrqu.data.length = 0;
1453 wrqu.data.flags = 0;
1454 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1455 break; 1522 break;
1456 } 1523 }
1457 1524
1458 /* Sanity check */ 1525 /* Sanity check */
1459 else if (len > sizeof(*bss)) { 1526 else if (len < (offsetof(struct agere_ext_scan_info,
1460 printk(KERN_WARNING
1461 "%s: Ext scan results too large (%d bytes). "
1462 "Truncating results to %zd bytes.\n",
1463 dev->name, len, sizeof(*bss));
1464 len = sizeof(*bss);
1465 } else if (len < (offsetof(struct agere_ext_scan_info,
1466 data) + 2)) { 1527 data) + 2)) {
1467 /* Drop this result now so we don't have to 1528 /* Drop this result now so we don't have to
1468 * keep checking later */ 1529 * keep checking later */
@@ -1472,21 +1533,18 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1472 break; 1533 break;
1473 } 1534 }
1474 1535
1475 bss = kmalloc(sizeof(*bss), GFP_ATOMIC); 1536 bss = kmalloc(len, GFP_ATOMIC);
1476 if (bss == NULL) 1537 if (bss == NULL)
1477 break; 1538 break;
1478 1539
1479 /* Read scan data */ 1540 /* Read scan data */
1480 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len, 1541 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
1481 infofid, sizeof(info)); 1542 infofid, sizeof(info));
1482 if (err) { 1543 if (err)
1483 kfree(bss); 1544 kfree(bss);
1484 break; 1545 else
1485 } 1546 qbuf_scan(priv, bss, len, type);
1486
1487 orinoco_add_ext_scan_result(priv, bss);
1488 1547
1489 kfree(bss);
1490 break; 1548 break;
1491 } 1549 }
1492 case HERMES_INQ_SEC_STAT_AGERE: 1550 case HERMES_INQ_SEC_STAT_AGERE:
@@ -1501,6 +1559,8 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1501 /* We don't actually do anything about it */ 1559 /* We don't actually do anything about it */
1502 break; 1560 break;
1503 } 1561 }
1562
1563 return;
1504} 1564}
1505 1565
1506static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw) 1566static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
@@ -1513,15 +1573,15 @@ static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1513/* Internal hardware control routines */ 1573/* Internal hardware control routines */
1514/********************************************************************/ 1574/********************************************************************/
1515 1575
1516int __orinoco_up(struct net_device *dev) 1576static int __orinoco_up(struct orinoco_private *priv)
1517{ 1577{
1518 struct orinoco_private *priv = netdev_priv(dev); 1578 struct net_device *dev = priv->ndev;
1519 struct hermes *hw = &priv->hw; 1579 struct hermes *hw = &priv->hw;
1520 int err; 1580 int err;
1521 1581
1522 netif_carrier_off(dev); /* just to make sure */ 1582 netif_carrier_off(dev); /* just to make sure */
1523 1583
1524 err = __orinoco_program_rids(dev); 1584 err = __orinoco_commit(priv);
1525 if (err) { 1585 if (err) {
1526 printk(KERN_ERR "%s: Error %d configuring card\n", 1586 printk(KERN_ERR "%s: Error %d configuring card\n",
1527 dev->name, err); 1587 dev->name, err);
@@ -1541,11 +1601,10 @@ int __orinoco_up(struct net_device *dev)
1541 1601
1542 return 0; 1602 return 0;
1543} 1603}
1544EXPORT_SYMBOL(__orinoco_up);
1545 1604
1546int __orinoco_down(struct net_device *dev) 1605static int __orinoco_down(struct orinoco_private *priv)
1547{ 1606{
1548 struct orinoco_private *priv = netdev_priv(dev); 1607 struct net_device *dev = priv->ndev;
1549 struct hermes *hw = &priv->hw; 1608 struct hermes *hw = &priv->hw;
1550 int err; 1609 int err;
1551 1610
@@ -1573,31 +1632,9 @@ int __orinoco_down(struct net_device *dev)
1573 1632
1574 return 0; 1633 return 0;
1575} 1634}
1576EXPORT_SYMBOL(__orinoco_down);
1577 1635
1578static int orinoco_allocate_fid(struct net_device *dev) 1636static int orinoco_reinit_firmware(struct orinoco_private *priv)
1579{ 1637{
1580 struct orinoco_private *priv = netdev_priv(dev);
1581 struct hermes *hw = &priv->hw;
1582 int err;
1583
1584 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1585 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1586 /* Try workaround for old Symbol firmware bug */
1587 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1588 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1589
1590 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1591 "(old Symbol firmware?). Work around %s\n",
1592 dev->name, err ? "failed!" : "ok.");
1593 }
1594
1595 return err;
1596}
1597
1598int orinoco_reinit_firmware(struct net_device *dev)
1599{
1600 struct orinoco_private *priv = netdev_priv(dev);
1601 struct hermes *hw = &priv->hw; 1638 struct hermes *hw = &priv->hw;
1602 int err; 1639 int err;
1603 1640
@@ -1608,246 +1645,15 @@ int orinoco_reinit_firmware(struct net_device *dev)
1608 priv->do_fw_download = 0; 1645 priv->do_fw_download = 0;
1609 } 1646 }
1610 if (!err) 1647 if (!err)
1611 err = orinoco_allocate_fid(dev); 1648 err = orinoco_hw_allocate_fid(priv);
1612 1649
1613 return err; 1650 return err;
1614} 1651}
1615EXPORT_SYMBOL(orinoco_reinit_firmware);
1616
1617int __orinoco_program_rids(struct net_device *dev)
1618{
1619 struct orinoco_private *priv = netdev_priv(dev);
1620 hermes_t *hw = &priv->hw;
1621 int err;
1622 struct hermes_idstring idbuf;
1623
1624 /* Set the MAC address */
1625 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1626 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1627 if (err) {
1628 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1629 dev->name, err);
1630 return err;
1631 }
1632
1633 /* Set up the link mode */
1634 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1635 priv->port_type);
1636 if (err) {
1637 printk(KERN_ERR "%s: Error %d setting port type\n",
1638 dev->name, err);
1639 return err;
1640 }
1641 /* Set the channel/frequency */
1642 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1643 err = hermes_write_wordrec(hw, USER_BAP,
1644 HERMES_RID_CNFOWNCHANNEL,
1645 priv->channel);
1646 if (err) {
1647 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1648 dev->name, err, priv->channel);
1649 return err;
1650 }
1651 }
1652
1653 if (priv->has_ibss) {
1654 u16 createibss;
1655
1656 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1657 printk(KERN_WARNING "%s: This firmware requires an "
1658 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1659 /* With wvlan_cs, in this case, we would crash.
1660 * hopefully, this driver will behave better...
1661 * Jean II */
1662 createibss = 0;
1663 } else {
1664 createibss = priv->createibss;
1665 }
1666
1667 err = hermes_write_wordrec(hw, USER_BAP,
1668 HERMES_RID_CNFCREATEIBSS,
1669 createibss);
1670 if (err) {
1671 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1672 dev->name, err);
1673 return err;
1674 }
1675 }
1676
1677 /* Set the desired BSSID */
1678 err = __orinoco_hw_set_wap(priv);
1679 if (err) {
1680 printk(KERN_ERR "%s: Error %d setting AP address\n",
1681 dev->name, err);
1682 return err;
1683 }
1684 /* Set the desired ESSID */
1685 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1686 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1687 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1688 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1689 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1690 &idbuf);
1691 if (err) {
1692 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1693 dev->name, err);
1694 return err;
1695 }
1696 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1697 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1698 &idbuf);
1699 if (err) {
1700 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1701 dev->name, err);
1702 return err;
1703 }
1704
1705 /* Set the station name */
1706 idbuf.len = cpu_to_le16(strlen(priv->nick));
1707 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1708 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1709 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1710 &idbuf);
1711 if (err) {
1712 printk(KERN_ERR "%s: Error %d setting nickname\n",
1713 dev->name, err);
1714 return err;
1715 }
1716
1717 /* Set AP density */
1718 if (priv->has_sensitivity) {
1719 err = hermes_write_wordrec(hw, USER_BAP,
1720 HERMES_RID_CNFSYSTEMSCALE,
1721 priv->ap_density);
1722 if (err) {
1723 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1724 "Disabling sensitivity control\n",
1725 dev->name, err);
1726
1727 priv->has_sensitivity = 0;
1728 }
1729 }
1730
1731 /* Set RTS threshold */
1732 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1733 priv->rts_thresh);
1734 if (err) {
1735 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1736 dev->name, err);
1737 return err;
1738 }
1739
1740 /* Set fragmentation threshold or MWO robustness */
1741 if (priv->has_mwo)
1742 err = hermes_write_wordrec(hw, USER_BAP,
1743 HERMES_RID_CNFMWOROBUST_AGERE,
1744 priv->mwo_robust);
1745 else
1746 err = hermes_write_wordrec(hw, USER_BAP,
1747 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1748 priv->frag_thresh);
1749 if (err) {
1750 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1751 dev->name, err);
1752 return err;
1753 }
1754
1755 /* Set bitrate */
1756 err = __orinoco_hw_set_bitrate(priv);
1757 if (err) {
1758 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1759 dev->name, err);
1760 return err;
1761 }
1762
1763 /* Set power management */
1764 if (priv->has_pm) {
1765 err = hermes_write_wordrec(hw, USER_BAP,
1766 HERMES_RID_CNFPMENABLED,
1767 priv->pm_on);
1768 if (err) {
1769 printk(KERN_ERR "%s: Error %d setting up PM\n",
1770 dev->name, err);
1771 return err;
1772 }
1773
1774 err = hermes_write_wordrec(hw, USER_BAP,
1775 HERMES_RID_CNFMULTICASTRECEIVE,
1776 priv->pm_mcast);
1777 if (err) {
1778 printk(KERN_ERR "%s: Error %d setting up PM\n",
1779 dev->name, err);
1780 return err;
1781 }
1782 err = hermes_write_wordrec(hw, USER_BAP,
1783 HERMES_RID_CNFMAXSLEEPDURATION,
1784 priv->pm_period);
1785 if (err) {
1786 printk(KERN_ERR "%s: Error %d setting up PM\n",
1787 dev->name, err);
1788 return err;
1789 }
1790 err = hermes_write_wordrec(hw, USER_BAP,
1791 HERMES_RID_CNFPMHOLDOVERDURATION,
1792 priv->pm_timeout);
1793 if (err) {
1794 printk(KERN_ERR "%s: Error %d setting up PM\n",
1795 dev->name, err);
1796 return err;
1797 }
1798 }
1799
1800 /* Set preamble - only for Symbol so far... */
1801 if (priv->has_preamble) {
1802 err = hermes_write_wordrec(hw, USER_BAP,
1803 HERMES_RID_CNFPREAMBLE_SYMBOL,
1804 priv->preamble);
1805 if (err) {
1806 printk(KERN_ERR "%s: Error %d setting preamble\n",
1807 dev->name, err);
1808 return err;
1809 }
1810 }
1811
1812 /* Set up encryption */
1813 if (priv->has_wep || priv->has_wpa) {
1814 err = __orinoco_hw_setup_enc(priv);
1815 if (err) {
1816 printk(KERN_ERR "%s: Error %d activating encryption\n",
1817 dev->name, err);
1818 return err;
1819 }
1820 }
1821
1822 if (priv->iw_mode == IW_MODE_MONITOR) {
1823 /* Enable monitor mode */
1824 dev->type = ARPHRD_IEEE80211;
1825 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1826 HERMES_TEST_MONITOR, 0, NULL);
1827 } else {
1828 /* Disable monitor mode */
1829 dev->type = ARPHRD_ETHER;
1830 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1831 HERMES_TEST_STOP, 0, NULL);
1832 }
1833 if (err)
1834 return err;
1835
1836 /* Set promiscuity / multicast*/
1837 priv->promiscuous = 0;
1838 priv->mc_count = 0;
1839
1840 /* FIXME: what about netif_tx_lock */
1841 __orinoco_set_multicast_list(dev);
1842
1843 return 0;
1844}
1845 1652
1846/* FIXME: return int? */ 1653static int
1847static void
1848__orinoco_set_multicast_list(struct net_device *dev) 1654__orinoco_set_multicast_list(struct net_device *dev)
1849{ 1655{
1850 struct orinoco_private *priv = netdev_priv(dev); 1656 struct orinoco_private *priv = ndev_priv(dev);
1851 int err = 0; 1657 int err = 0;
1852 int promisc, mc_count; 1658 int promisc, mc_count;
1853 1659
@@ -1864,6 +1670,8 @@ __orinoco_set_multicast_list(struct net_device *dev)
1864 1670
1865 err = __orinoco_hw_set_multicast_list(priv, dev->mc_list, mc_count, 1671 err = __orinoco_hw_set_multicast_list(priv, dev->mc_list, mc_count,
1866 promisc); 1672 promisc);
1673
1674 return err;
1867} 1675}
1868 1676
1869/* This must be called from user context, without locks held - use 1677/* This must be called from user context, without locks held - use
@@ -1896,9 +1704,11 @@ void orinoco_reset(struct work_struct *work)
1896 1704
1897 orinoco_unlock(priv, &flags); 1705 orinoco_unlock(priv, &flags);
1898 1706
1899 /* Scanning support: Cleanup of driver struct */ 1707 /* Scanning support: Notify scan cancellation */
1900 orinoco_clear_scan_results(priv, 0); 1708 if (priv->scan_request) {
1901 priv->scan_inprogress = 0; 1709 cfg80211_scan_done(priv->scan_request, 1);
1710 priv->scan_request = NULL;
1711 }
1902 1712
1903 if (priv->hard_reset) { 1713 if (priv->hard_reset) {
1904 err = (*priv->hard_reset)(priv); 1714 err = (*priv->hard_reset)(priv);
@@ -1909,7 +1719,7 @@ void orinoco_reset(struct work_struct *work)
1909 } 1719 }
1910 } 1720 }
1911 1721
1912 err = orinoco_reinit_firmware(dev); 1722 err = orinoco_reinit_firmware(priv);
1913 if (err) { 1723 if (err) {
1914 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n", 1724 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1915 dev->name, err); 1725 dev->name, err);
@@ -1924,7 +1734,7 @@ void orinoco_reset(struct work_struct *work)
1924 /* priv->open or priv->hw_unavailable might have changed while 1734 /* priv->open or priv->hw_unavailable might have changed while
1925 * we dropped the lock */ 1735 * we dropped the lock */
1926 if (priv->open && (!priv->hw_unavailable)) { 1736 if (priv->open && (!priv->hw_unavailable)) {
1927 err = __orinoco_up(dev); 1737 err = __orinoco_up(priv);
1928 if (err) { 1738 if (err) {
1929 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n", 1739 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1930 dev->name, err); 1740 dev->name, err);
@@ -1941,6 +1751,64 @@ void orinoco_reset(struct work_struct *work)
1941 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name); 1751 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1942} 1752}
1943 1753
1754static int __orinoco_commit(struct orinoco_private *priv)
1755{
1756 struct net_device *dev = priv->ndev;
1757 int err = 0;
1758
1759 err = orinoco_hw_program_rids(priv);
1760
1761 /* FIXME: what about netif_tx_lock */
1762 (void) __orinoco_set_multicast_list(dev);
1763
1764 return err;
1765}
1766
1767/* Ensures configuration changes are applied. May result in a reset.
1768 * The caller should hold priv->lock
1769 */
1770int orinoco_commit(struct orinoco_private *priv)
1771{
1772 struct net_device *dev = priv->ndev;
1773 hermes_t *hw = &priv->hw;
1774 int err;
1775
1776 if (priv->broken_disableport) {
1777 schedule_work(&priv->reset_work);
1778 return 0;
1779 }
1780
1781 err = hermes_disable_port(hw, 0);
1782 if (err) {
1783 printk(KERN_WARNING "%s: Unable to disable port "
1784 "while reconfiguring card\n", dev->name);
1785 priv->broken_disableport = 1;
1786 goto out;
1787 }
1788
1789 err = __orinoco_commit(priv);
1790 if (err) {
1791 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
1792 dev->name);
1793 goto out;
1794 }
1795
1796 err = hermes_enable_port(hw, 0);
1797 if (err) {
1798 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
1799 dev->name);
1800 goto out;
1801 }
1802
1803 out:
1804 if (err) {
1805 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
1806 schedule_work(&priv->reset_work);
1807 err = 0;
1808 }
1809 return err;
1810}
1811
1944/********************************************************************/ 1812/********************************************************************/
1945/* Interrupt handler */ 1813/* Interrupt handler */
1946/********************************************************************/ 1814/********************************************************************/
@@ -1960,8 +1828,8 @@ static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1960 1828
1961irqreturn_t orinoco_interrupt(int irq, void *dev_id) 1829irqreturn_t orinoco_interrupt(int irq, void *dev_id)
1962{ 1830{
1963 struct net_device *dev = dev_id; 1831 struct orinoco_private *priv = dev_id;
1964 struct orinoco_private *priv = netdev_priv(dev); 1832 struct net_device *dev = priv->ndev;
1965 hermes_t *hw = &priv->hw; 1833 hermes_t *hw = &priv->hw;
1966 int count = MAX_IRQLOOPS_PER_IRQ; 1834 int count = MAX_IRQLOOPS_PER_IRQ;
1967 u16 evstat, events; 1835 u16 evstat, events;
@@ -2096,227 +1964,12 @@ static void orinoco_unregister_pm_notifier(struct orinoco_private *priv)
2096/* Initialization */ 1964/* Initialization */
2097/********************************************************************/ 1965/********************************************************************/
2098 1966
2099struct comp_id { 1967int orinoco_init(struct orinoco_private *priv)
2100 u16 id, variant, major, minor;
2101} __attribute__ ((packed));
2102
2103static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2104{
2105 if (nic_id->id < 0x8000)
2106 return FIRMWARE_TYPE_AGERE;
2107 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2108 return FIRMWARE_TYPE_SYMBOL;
2109 else
2110 return FIRMWARE_TYPE_INTERSIL;
2111}
2112
2113/* Set priv->firmware type, determine firmware properties */
2114static int determine_firmware(struct net_device *dev)
2115{
2116 struct orinoco_private *priv = netdev_priv(dev);
2117 hermes_t *hw = &priv->hw;
2118 int err;
2119 struct comp_id nic_id, sta_id;
2120 unsigned int firmver;
2121 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
2122
2123 /* Get the hardware version */
2124 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2125 if (err) {
2126 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2127 dev->name, err);
2128 return err;
2129 }
2130
2131 le16_to_cpus(&nic_id.id);
2132 le16_to_cpus(&nic_id.variant);
2133 le16_to_cpus(&nic_id.major);
2134 le16_to_cpus(&nic_id.minor);
2135 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2136 dev->name, nic_id.id, nic_id.variant,
2137 nic_id.major, nic_id.minor);
2138
2139 priv->firmware_type = determine_firmware_type(&nic_id);
2140
2141 /* Get the firmware version */
2142 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2143 if (err) {
2144 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2145 dev->name, err);
2146 return err;
2147 }
2148
2149 le16_to_cpus(&sta_id.id);
2150 le16_to_cpus(&sta_id.variant);
2151 le16_to_cpus(&sta_id.major);
2152 le16_to_cpus(&sta_id.minor);
2153 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2154 dev->name, sta_id.id, sta_id.variant,
2155 sta_id.major, sta_id.minor);
2156
2157 switch (sta_id.id) {
2158 case 0x15:
2159 printk(KERN_ERR "%s: Primary firmware is active\n",
2160 dev->name);
2161 return -ENODEV;
2162 case 0x14b:
2163 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2164 dev->name);
2165 return -ENODEV;
2166 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2167 case 0x21: /* Symbol Spectrum24 Trilogy */
2168 break;
2169 default:
2170 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2171 dev->name);
2172 break;
2173 }
2174
2175 /* Default capabilities */
2176 priv->has_sensitivity = 1;
2177 priv->has_mwo = 0;
2178 priv->has_preamble = 0;
2179 priv->has_port3 = 1;
2180 priv->has_ibss = 1;
2181 priv->has_wep = 0;
2182 priv->has_big_wep = 0;
2183 priv->has_alt_txcntl = 0;
2184 priv->has_ext_scan = 0;
2185 priv->has_wpa = 0;
2186 priv->do_fw_download = 0;
2187
2188 /* Determine capabilities from the firmware version */
2189 switch (priv->firmware_type) {
2190 case FIRMWARE_TYPE_AGERE:
2191 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2192 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2193 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2194 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2195
2196 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2197
2198 priv->has_ibss = (firmver >= 0x60006);
2199 priv->has_wep = (firmver >= 0x40020);
2200 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2201 Gold cards from the others? */
2202 priv->has_mwo = (firmver >= 0x60000);
2203 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2204 priv->ibss_port = 1;
2205 priv->has_hostscan = (firmver >= 0x8000a);
2206 priv->do_fw_download = 1;
2207 priv->broken_monitor = (firmver >= 0x80000);
2208 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
2209 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
2210 priv->has_wpa = (firmver >= 0x9002a);
2211 /* Tested with Agere firmware :
2212 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2213 * Tested CableTron firmware : 4.32 => Anton */
2214 break;
2215 case FIRMWARE_TYPE_SYMBOL:
2216 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2217 /* Intel MAC : 00:02:B3:* */
2218 /* 3Com MAC : 00:50:DA:* */
2219 memset(tmp, 0, sizeof(tmp));
2220 /* Get the Symbol firmware version */
2221 err = hermes_read_ltv(hw, USER_BAP,
2222 HERMES_RID_SECONDARYVERSION_SYMBOL,
2223 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2224 if (err) {
2225 printk(KERN_WARNING
2226 "%s: Error %d reading Symbol firmware info. "
2227 "Wildly guessing capabilities...\n",
2228 dev->name, err);
2229 firmver = 0;
2230 tmp[0] = '\0';
2231 } else {
2232 /* The firmware revision is a string, the format is
2233 * something like : "V2.20-01".
2234 * Quick and dirty parsing... - Jean II
2235 */
2236 firmver = ((tmp[1] - '0') << 16)
2237 | ((tmp[3] - '0') << 12)
2238 | ((tmp[4] - '0') << 8)
2239 | ((tmp[6] - '0') << 4)
2240 | (tmp[7] - '0');
2241
2242 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2243 }
2244
2245 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2246 "Symbol %s", tmp);
2247
2248 priv->has_ibss = (firmver >= 0x20000);
2249 priv->has_wep = (firmver >= 0x15012);
2250 priv->has_big_wep = (firmver >= 0x20000);
2251 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2252 (firmver >= 0x29000 && firmver < 0x30000) ||
2253 firmver >= 0x31000;
2254 priv->has_preamble = (firmver >= 0x20000);
2255 priv->ibss_port = 4;
2256
2257 /* Symbol firmware is found on various cards, but
2258 * there has been no attempt to check firmware
2259 * download on non-spectrum_cs based cards.
2260 *
2261 * Given that the Agere firmware download works
2262 * differently, we should avoid doing a firmware
2263 * download with the Symbol algorithm on non-spectrum
2264 * cards.
2265 *
2266 * For now we can identify a spectrum_cs based card
2267 * because it has a firmware reset function.
2268 */
2269 priv->do_fw_download = (priv->stop_fw != NULL);
2270
2271 priv->broken_disableport = (firmver == 0x25013) ||
2272 (firmver >= 0x30000 && firmver <= 0x31000);
2273 priv->has_hostscan = (firmver >= 0x31001) ||
2274 (firmver >= 0x29057 && firmver < 0x30000);
2275 /* Tested with Intel firmware : 0x20015 => Jean II */
2276 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2277 break;
2278 case FIRMWARE_TYPE_INTERSIL:
2279 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2280 * Samsung, Compaq 100/200 and Proxim are slightly
2281 * different and less well tested */
2282 /* D-Link MAC : 00:40:05:* */
2283 /* Addtron MAC : 00:90:D1:* */
2284 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2285 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2286 sta_id.variant);
2287
2288 firmver = ((unsigned long)sta_id.major << 16) |
2289 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2290
2291 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2292 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2293 priv->has_pm = (firmver >= 0x000700);
2294 priv->has_hostscan = (firmver >= 0x010301);
2295
2296 if (firmver >= 0x000800)
2297 priv->ibss_port = 0;
2298 else {
2299 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2300 "than v0.8.x - several features not supported\n",
2301 dev->name);
2302 priv->ibss_port = 1;
2303 }
2304 break;
2305 }
2306 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2307 priv->fw_name);
2308
2309 return 0;
2310}
2311
2312static int orinoco_init(struct net_device *dev)
2313{ 1968{
2314 struct orinoco_private *priv = netdev_priv(dev); 1969 struct device *dev = priv->dev;
1970 struct wiphy *wiphy = priv_to_wiphy(priv);
2315 hermes_t *hw = &priv->hw; 1971 hermes_t *hw = &priv->hw;
2316 int err = 0; 1972 int err = 0;
2317 struct hermes_idstring nickbuf;
2318 u16 reclen;
2319 int len;
2320 1973
2321 /* No need to lock, the hw_unavailable flag is already set in 1974 /* No need to lock, the hw_unavailable flag is already set in
2322 * alloc_orinocodev() */ 1975 * alloc_orinocodev() */
@@ -2325,15 +1978,14 @@ static int orinoco_init(struct net_device *dev)
2325 /* Initialize the firmware */ 1978 /* Initialize the firmware */
2326 err = hermes_init(hw); 1979 err = hermes_init(hw);
2327 if (err != 0) { 1980 if (err != 0) {
2328 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n", 1981 dev_err(dev, "Failed to initialize firmware (err = %d)\n",
2329 dev->name, err); 1982 err);
2330 goto out; 1983 goto out;
2331 } 1984 }
2332 1985
2333 err = determine_firmware(dev); 1986 err = determine_fw_capabilities(priv);
2334 if (err != 0) { 1987 if (err != 0) {
2335 printk(KERN_ERR "%s: Incompatible firmware, aborting\n", 1988 dev_err(dev, "Incompatible firmware, aborting\n");
2336 dev->name);
2337 goto out; 1989 goto out;
2338 } 1990 }
2339 1991
@@ -2347,147 +1999,41 @@ static int orinoco_init(struct net_device *dev)
2347 priv->do_fw_download = 0; 1999 priv->do_fw_download = 0;
2348 2000
2349 /* Check firmware version again */ 2001 /* Check firmware version again */
2350 err = determine_firmware(dev); 2002 err = determine_fw_capabilities(priv);
2351 if (err != 0) { 2003 if (err != 0) {
2352 printk(KERN_ERR "%s: Incompatible firmware, aborting\n", 2004 dev_err(dev, "Incompatible firmware, aborting\n");
2353 dev->name);
2354 goto out; 2005 goto out;
2355 } 2006 }
2356 } 2007 }
2357 2008
2358 if (priv->has_port3) 2009 if (priv->has_port3)
2359 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", 2010 dev_info(dev, "Ad-hoc demo mode supported\n");
2360 dev->name);
2361 if (priv->has_ibss) 2011 if (priv->has_ibss)
2362 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n", 2012 dev_info(dev, "IEEE standard IBSS ad-hoc mode supported\n");
2363 dev->name); 2013 if (priv->has_wep)
2364 if (priv->has_wep) { 2014 dev_info(dev, "WEP supported, %s-bit key\n",
2365 printk(KERN_DEBUG "%s: WEP supported, %s-bit key\n", dev->name, 2015 priv->has_big_wep ? "104" : "40");
2366 priv->has_big_wep ? "104" : "40");
2367 }
2368 if (priv->has_wpa) { 2016 if (priv->has_wpa) {
2369 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name); 2017 dev_info(dev, "WPA-PSK supported\n");
2370 if (orinoco_mic_init(priv)) { 2018 if (orinoco_mic_init(priv)) {
2371 printk(KERN_ERR "%s: Failed to setup MIC crypto " 2019 dev_err(dev, "Failed to setup MIC crypto algorithm. "
2372 "algorithm. Disabling WPA support\n", dev->name); 2020 "Disabling WPA support\n");
2373 priv->has_wpa = 0; 2021 priv->has_wpa = 0;
2374 } 2022 }
2375 } 2023 }
2376 2024
2377 /* Now we have the firmware capabilities, allocate appropiate 2025 err = orinoco_hw_read_card_settings(priv, wiphy->perm_addr);
2378 * sized scan buffers */ 2026 if (err)
2379 if (orinoco_bss_data_allocate(priv))
2380 goto out;
2381 orinoco_bss_data_init(priv);
2382
2383 /* Get the MAC address */
2384 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2385 ETH_ALEN, NULL, dev->dev_addr);
2386 if (err) {
2387 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2388 dev->name);
2389 goto out;
2390 }
2391
2392 printk(KERN_DEBUG "%s: MAC address %pM\n",
2393 dev->name, dev->dev_addr);
2394
2395 /* Get the station name */
2396 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2397 sizeof(nickbuf), &reclen, &nickbuf);
2398 if (err) {
2399 printk(KERN_ERR "%s: failed to read station name\n",
2400 dev->name);
2401 goto out;
2402 }
2403 if (nickbuf.len)
2404 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2405 else
2406 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2407 memcpy(priv->nick, &nickbuf.val, len);
2408 priv->nick[len] = '\0';
2409
2410 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2411
2412 err = orinoco_allocate_fid(dev);
2413 if (err) {
2414 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2415 dev->name);
2416 goto out;
2417 }
2418
2419 /* Get allowed channels */
2420 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2421 &priv->channel_mask);
2422 if (err) {
2423 printk(KERN_ERR "%s: failed to read channel list!\n",
2424 dev->name);
2425 goto out;
2426 }
2427
2428 /* Get initial AP density */
2429 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2430 &priv->ap_density);
2431 if (err || priv->ap_density < 1 || priv->ap_density > 3)
2432 priv->has_sensitivity = 0;
2433
2434 /* Get initial RTS threshold */
2435 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2436 &priv->rts_thresh);
2437 if (err) {
2438 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2439 dev->name);
2440 goto out; 2027 goto out;
2441 }
2442 2028
2443 /* Get initial fragmentation settings */ 2029 err = orinoco_hw_allocate_fid(priv);
2444 if (priv->has_mwo)
2445 err = hermes_read_wordrec(hw, USER_BAP,
2446 HERMES_RID_CNFMWOROBUST_AGERE,
2447 &priv->mwo_robust);
2448 else
2449 err = hermes_read_wordrec(hw, USER_BAP,
2450 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2451 &priv->frag_thresh);
2452 if (err) { 2030 if (err) {
2453 printk(KERN_ERR "%s: failed to read fragmentation settings!\n", 2031 dev_err(dev, "Failed to allocate NIC buffer!\n");
2454 dev->name);
2455 goto out; 2032 goto out;
2456 } 2033 }
2457 2034
2458 /* Power management setup */
2459 if (priv->has_pm) {
2460 priv->pm_on = 0;
2461 priv->pm_mcast = 1;
2462 err = hermes_read_wordrec(hw, USER_BAP,
2463 HERMES_RID_CNFMAXSLEEPDURATION,
2464 &priv->pm_period);
2465 if (err) {
2466 printk(KERN_ERR "%s: failed to read power management period!\n",
2467 dev->name);
2468 goto out;
2469 }
2470 err = hermes_read_wordrec(hw, USER_BAP,
2471 HERMES_RID_CNFPMHOLDOVERDURATION,
2472 &priv->pm_timeout);
2473 if (err) {
2474 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2475 dev->name);
2476 goto out;
2477 }
2478 }
2479
2480 /* Preamble setup */
2481 if (priv->has_preamble) {
2482 err = hermes_read_wordrec(hw, USER_BAP,
2483 HERMES_RID_CNFPREAMBLE_SYMBOL,
2484 &priv->preamble);
2485 if (err)
2486 goto out;
2487 }
2488
2489 /* Set up the default configuration */ 2035 /* Set up the default configuration */
2490 priv->iw_mode = IW_MODE_INFRA; 2036 priv->iw_mode = NL80211_IFTYPE_STATION;
2491 /* By default use IEEE/IBSS ad-hoc mode if we have it */ 2037 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2492 priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss); 2038 priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
2493 set_port_type(priv); 2039 set_port_type(priv);
@@ -2502,20 +2048,25 @@ static int orinoco_init(struct net_device *dev)
2502 priv->wpa_ie_len = 0; 2048 priv->wpa_ie_len = 0;
2503 priv->wpa_ie = NULL; 2049 priv->wpa_ie = NULL;
2504 2050
2051 if (orinoco_wiphy_register(wiphy)) {
2052 err = -ENODEV;
2053 goto out;
2054 }
2055
2505 /* Make the hardware available, as long as it hasn't been 2056 /* Make the hardware available, as long as it hasn't been
2506 * removed elsewhere (e.g. by PCMCIA hot unplug) */ 2057 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2507 spin_lock_irq(&priv->lock); 2058 spin_lock_irq(&priv->lock);
2508 priv->hw_unavailable--; 2059 priv->hw_unavailable--;
2509 spin_unlock_irq(&priv->lock); 2060 spin_unlock_irq(&priv->lock);
2510 2061
2511 printk(KERN_DEBUG "%s: ready\n", dev->name); 2062 dev_dbg(dev, "Ready\n");
2512 2063
2513 out: 2064 out:
2514 return err; 2065 return err;
2515} 2066}
2067EXPORT_SYMBOL(orinoco_init);
2516 2068
2517static const struct net_device_ops orinoco_netdev_ops = { 2069static const struct net_device_ops orinoco_netdev_ops = {
2518 .ndo_init = orinoco_init,
2519 .ndo_open = orinoco_open, 2070 .ndo_open = orinoco_open,
2520 .ndo_stop = orinoco_stop, 2071 .ndo_stop = orinoco_stop,
2521 .ndo_start_xmit = orinoco_xmit, 2072 .ndo_start_xmit = orinoco_xmit,
@@ -2527,40 +2078,64 @@ static const struct net_device_ops orinoco_netdev_ops = {
2527 .ndo_get_stats = orinoco_get_stats, 2078 .ndo_get_stats = orinoco_get_stats,
2528}; 2079};
2529 2080
2530struct net_device 2081/* Allocate private data.
2082 *
2083 * This driver has a number of structures associated with it
2084 * netdev - Net device structure for each network interface
2085 * wiphy - structure associated with wireless phy
2086 * wireless_dev (wdev) - structure for each wireless interface
2087 * hw - structure for hermes chip info
2088 * card - card specific structure for use by the card driver
2089 * (airport, orinoco_cs)
2090 * priv - orinoco private data
2091 * device - generic linux device structure
2092 *
2093 * +---------+ +---------+
2094 * | wiphy | | netdev |
2095 * | +-------+ | +-------+
2096 * | | priv | | | wdev |
2097 * | | +-----+ +-+-------+
2098 * | | | hw |
2099 * | +-+-----+
2100 * | | card |
2101 * +-+-------+
2102 *
2103 * priv has a link to netdev and device
2104 * wdev has a link to wiphy
2105 */
2106struct orinoco_private
2531*alloc_orinocodev(int sizeof_card, 2107*alloc_orinocodev(int sizeof_card,
2532 struct device *device, 2108 struct device *device,
2533 int (*hard_reset)(struct orinoco_private *), 2109 int (*hard_reset)(struct orinoco_private *),
2534 int (*stop_fw)(struct orinoco_private *, int)) 2110 int (*stop_fw)(struct orinoco_private *, int))
2535{ 2111{
2536 struct net_device *dev;
2537 struct orinoco_private *priv; 2112 struct orinoco_private *priv;
2113 struct wiphy *wiphy;
2538 2114
2539 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card); 2115 /* allocate wiphy
2540 if (!dev) 2116 * NOTE: We only support a single virtual interface
2117 * but this may change when monitor mode is added
2118 */
2119 wiphy = wiphy_new(&orinoco_cfg_ops,
2120 sizeof(struct orinoco_private) + sizeof_card);
2121 if (!wiphy)
2541 return NULL; 2122 return NULL;
2542 priv = netdev_priv(dev); 2123
2543 priv->ndev = dev; 2124 priv = wiphy_priv(wiphy);
2125 priv->dev = device;
2126
2544 if (sizeof_card) 2127 if (sizeof_card)
2545 priv->card = (void *)((unsigned long)priv 2128 priv->card = (void *)((unsigned long)priv
2546 + sizeof(struct orinoco_private)); 2129 + sizeof(struct orinoco_private));
2547 else 2130 else
2548 priv->card = NULL; 2131 priv->card = NULL;
2549 priv->dev = device;
2550 2132
2551 /* Setup / override net_device fields */ 2133 orinoco_wiphy_init(wiphy);
2552 dev->netdev_ops = &orinoco_netdev_ops; 2134
2553 dev->watchdog_timeo = HZ; /* 1 second timeout */
2554 dev->ethtool_ops = &orinoco_ethtool_ops;
2555 dev->wireless_handlers = &orinoco_handler_def;
2556#ifdef WIRELESS_SPY 2135#ifdef WIRELESS_SPY
2557 priv->wireless_data.spy_data = &priv->spy_data; 2136 priv->wireless_data.spy_data = &priv->spy_data;
2558 dev->wireless_data = &priv->wireless_data;
2559#endif 2137#endif
2560 2138
2561 /* Reserve space in skb for the SNAP header */
2562 dev->hard_header_len += ENCAPS_OVERHEAD;
2563
2564 /* Set up default callbacks */ 2139 /* Set up default callbacks */
2565 priv->hard_reset = hard_reset; 2140 priv->hard_reset = hard_reset;
2566 priv->stop_fw = stop_fw; 2141 priv->stop_fw = stop_fw;
@@ -2576,9 +2151,12 @@ struct net_device
2576 2151
2577 INIT_LIST_HEAD(&priv->rx_list); 2152 INIT_LIST_HEAD(&priv->rx_list);
2578 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet, 2153 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
2579 (unsigned long) dev); 2154 (unsigned long) priv);
2155
2156 spin_lock_init(&priv->scan_lock);
2157 INIT_LIST_HEAD(&priv->scan_list);
2158 INIT_WORK(&priv->process_scan, orinoco_process_scan_results);
2580 2159
2581 netif_carrier_off(dev);
2582 priv->last_linkstatus = 0xffff; 2160 priv->last_linkstatus = 0xffff;
2583 2161
2584#if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP) 2162#if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
@@ -2589,14 +2167,91 @@ struct net_device
2589 /* Register PM notifiers */ 2167 /* Register PM notifiers */
2590 orinoco_register_pm_notifier(priv); 2168 orinoco_register_pm_notifier(priv);
2591 2169
2592 return dev; 2170 return priv;
2593} 2171}
2594EXPORT_SYMBOL(alloc_orinocodev); 2172EXPORT_SYMBOL(alloc_orinocodev);
2595 2173
2596void free_orinocodev(struct net_device *dev) 2174/* We can only support a single interface. We provide a separate
2175 * function to set it up to distinguish between hardware
2176 * initialisation and interface setup.
2177 *
2178 * The base_addr and irq parameters are passed on to netdev for use
2179 * with SIOCGIFMAP.
2180 */
2181int orinoco_if_add(struct orinoco_private *priv,
2182 unsigned long base_addr,
2183 unsigned int irq)
2184{
2185 struct wiphy *wiphy = priv_to_wiphy(priv);
2186 struct wireless_dev *wdev;
2187 struct net_device *dev;
2188 int ret;
2189
2190 dev = alloc_etherdev(sizeof(struct wireless_dev));
2191
2192 if (!dev)
2193 return -ENOMEM;
2194
2195 /* Initialise wireless_dev */
2196 wdev = netdev_priv(dev);
2197 wdev->wiphy = wiphy;
2198 wdev->iftype = NL80211_IFTYPE_STATION;
2199
2200 /* Setup / override net_device fields */
2201 dev->ieee80211_ptr = wdev;
2202 dev->netdev_ops = &orinoco_netdev_ops;
2203 dev->watchdog_timeo = HZ; /* 1 second timeout */
2204 dev->ethtool_ops = &orinoco_ethtool_ops;
2205 dev->wireless_handlers = &orinoco_handler_def;
2206#ifdef WIRELESS_SPY
2207 dev->wireless_data = &priv->wireless_data;
2208#endif
2209 /* we use the default eth_mac_addr for setting the MAC addr */
2210
2211 /* Reserve space in skb for the SNAP header */
2212 dev->hard_header_len += ENCAPS_OVERHEAD;
2213
2214 netif_carrier_off(dev);
2215
2216 memcpy(dev->dev_addr, wiphy->perm_addr, ETH_ALEN);
2217
2218 dev->base_addr = base_addr;
2219 dev->irq = irq;
2220
2221 SET_NETDEV_DEV(dev, priv->dev);
2222 ret = register_netdev(dev);
2223 if (ret)
2224 goto fail;
2225
2226 priv->ndev = dev;
2227
2228 /* Report what we've done */
2229 dev_dbg(priv->dev, "Registerred interface %s.\n", dev->name);
2230
2231 return 0;
2232
2233 fail:
2234 free_netdev(dev);
2235 return ret;
2236}
2237EXPORT_SYMBOL(orinoco_if_add);
2238
2239void orinoco_if_del(struct orinoco_private *priv)
2240{
2241 struct net_device *dev = priv->ndev;
2242
2243 unregister_netdev(dev);
2244 free_netdev(dev);
2245}
2246EXPORT_SYMBOL(orinoco_if_del);
2247
2248void free_orinocodev(struct orinoco_private *priv)
2597{ 2249{
2598 struct orinoco_private *priv = netdev_priv(dev); 2250 struct wiphy *wiphy = priv_to_wiphy(priv);
2599 struct orinoco_rx_data *rx_data, *temp; 2251 struct orinoco_rx_data *rx_data, *temp;
2252 struct orinoco_scan_data *sd, *sdtemp;
2253
2254 wiphy_unregister(wiphy);
2600 2255
2601 /* If the tasklet is scheduled when we call tasklet_kill it 2256 /* If the tasklet is scheduled when we call tasklet_kill it
2602 * will run one final time. However the tasklet will only 2257 * will run one final time. However the tasklet will only
@@ -2612,21 +2267,80 @@ void free_orinocodev(struct net_device *dev)
2612 kfree(rx_data); 2267 kfree(rx_data);
2613 } 2268 }
2614 2269
2270 cancel_work_sync(&priv->process_scan);
2271 /* Explicitly drain priv->scan_list */
2272 list_for_each_entry_safe(sd, sdtemp, &priv->scan_list, list) {
2273 list_del(&sd->list);
2274
2275 if ((sd->len > 0) && sd->buf)
2276 kfree(sd->buf);
2277 kfree(sd);
2278 }
2279
2615 orinoco_unregister_pm_notifier(priv); 2280 orinoco_unregister_pm_notifier(priv);
2616 orinoco_uncache_fw(priv); 2281 orinoco_uncache_fw(priv);
2617 2282
2618 priv->wpa_ie_len = 0; 2283 priv->wpa_ie_len = 0;
2619 kfree(priv->wpa_ie); 2284 kfree(priv->wpa_ie);
2620 orinoco_mic_free(priv); 2285 orinoco_mic_free(priv);
2621 orinoco_bss_data_free(priv); 2286 wiphy_free(wiphy);
2622 free_netdev(dev);
2623} 2287}
2624EXPORT_SYMBOL(free_orinocodev); 2288EXPORT_SYMBOL(free_orinocodev);
2625 2289
2290int orinoco_up(struct orinoco_private *priv)
2291{
2292 struct net_device *dev = priv->ndev;
2293 unsigned long flags;
2294 int err;
2295
2296 spin_lock_irqsave(&priv->lock, flags);
2297
2298 err = orinoco_reinit_firmware(priv);
2299 if (err) {
2300 printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
2301 dev->name, err);
2302 goto exit;
2303 }
2304
2305 netif_device_attach(dev);
2306 priv->hw_unavailable--;
2307
2308 if (priv->open && !priv->hw_unavailable) {
2309 err = __orinoco_up(priv);
2310 if (err)
2311 printk(KERN_ERR "%s: Error %d restarting card\n",
2312 dev->name, err);
2313 }
2314
2315exit:
2316 spin_unlock_irqrestore(&priv->lock, flags);
2317
2318 return 0;
2319}
2320EXPORT_SYMBOL(orinoco_up);
2321
2322void orinoco_down(struct orinoco_private *priv)
2323{
2324 struct net_device *dev = priv->ndev;
2325 unsigned long flags;
2326 int err;
2327
2328 spin_lock_irqsave(&priv->lock, flags);
2329 err = __orinoco_down(priv);
2330 if (err)
2331 printk(KERN_WARNING "%s: Error %d downing interface\n",
2332 dev->name, err);
2333
2334 netif_device_detach(dev);
2335 priv->hw_unavailable++;
2336 spin_unlock_irqrestore(&priv->lock, flags);
2337}
2338EXPORT_SYMBOL(orinoco_down);
2339
2626static void orinoco_get_drvinfo(struct net_device *dev, 2340static void orinoco_get_drvinfo(struct net_device *dev,
2627 struct ethtool_drvinfo *info) 2341 struct ethtool_drvinfo *info)
2628{ 2342{
2629 struct orinoco_private *priv = netdev_priv(dev); 2343 struct orinoco_private *priv = ndev_priv(dev);
2630 2344
2631 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1); 2345 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
2632 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1); 2346 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
diff --git a/drivers/net/wireless/orinoco/main.h b/drivers/net/wireless/orinoco/main.h
index af2bae4fe395..21ab36cd76c7 100644
--- a/drivers/net/wireless/orinoco/main.h
+++ b/drivers/net/wireless/orinoco/main.h
@@ -29,10 +29,9 @@ struct net_device;
29struct work_struct; 29struct work_struct;
30 30
31void set_port_type(struct orinoco_private *priv); 31void set_port_type(struct orinoco_private *priv);
32int __orinoco_program_rids(struct net_device *dev); 32int orinoco_commit(struct orinoco_private *priv);
33void orinoco_reset(struct work_struct *work); 33void orinoco_reset(struct work_struct *work);
34 34
35
36/* Information element helpers - find a home for these... */ 35/* Information element helpers - find a home for these... */
37static inline u8 *orinoco_get_ie(u8 *data, size_t len, 36static inline u8 *orinoco_get_ie(u8 *data, size_t len,
38 enum ieee80211_eid eid) 37 enum ieee80211_eid eid)
diff --git a/drivers/net/wireless/orinoco/orinoco.h b/drivers/net/wireless/orinoco/orinoco.h
index 8e5a72cc297f..5f4f5c9eef79 100644
--- a/drivers/net/wireless/orinoco/orinoco.h
+++ b/drivers/net/wireless/orinoco/orinoco.h
@@ -14,6 +14,7 @@
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/wireless.h> 15#include <linux/wireless.h>
16#include <net/iw_handler.h> 16#include <net/iw_handler.h>
17#include <net/cfg80211.h>
17 18
18#include "hermes.h" 19#include "hermes.h"
19 20
@@ -47,18 +48,6 @@ typedef enum {
47 FIRMWARE_TYPE_SYMBOL 48 FIRMWARE_TYPE_SYMBOL
48} fwtype_t; 49} fwtype_t;
49 50
50struct bss_element {
51 union hermes_scan_info bss;
52 unsigned long last_scanned;
53 struct list_head list;
54};
55
56struct xbss_element {
57 struct agere_ext_scan_info bss;
58 unsigned long last_scanned;
59 struct list_head list;
60};
61
62struct firmware; 51struct firmware;
63 52
64struct orinoco_private { 53struct orinoco_private {
@@ -67,6 +56,10 @@ struct orinoco_private {
67 int (*hard_reset)(struct orinoco_private *); 56 int (*hard_reset)(struct orinoco_private *);
68 int (*stop_fw)(struct orinoco_private *, int); 57 int (*stop_fw)(struct orinoco_private *, int);
69 58
59 struct ieee80211_supported_band band;
60 struct ieee80211_channel channels[14];
61 u32 cipher_suites[3];
62
70 /* Synchronisation stuff */ 63 /* Synchronisation stuff */
71 spinlock_t lock; 64 spinlock_t lock;
72 int hw_unavailable; 65 int hw_unavailable;
@@ -116,7 +109,7 @@ struct orinoco_private {
116 unsigned int broken_monitor:1; 109 unsigned int broken_monitor:1;
117 110
118 /* Configuration paramaters */ 111 /* Configuration paramaters */
119 u32 iw_mode; 112 enum nl80211_iftype iw_mode;
120 int prefer_port3; 113 int prefer_port3;
121 u16 encode_alg, wep_restrict, tx_key; 114 u16 encode_alg, wep_restrict, tx_key;
122 struct orinoco_key keys[ORINOCO_MAX_KEYS]; 115 struct orinoco_key keys[ORINOCO_MAX_KEYS];
@@ -140,12 +133,10 @@ struct orinoco_private {
140 int promiscuous, mc_count; 133 int promiscuous, mc_count;
141 134
142 /* Scanning support */ 135 /* Scanning support */
143 struct list_head bss_list; 136 struct cfg80211_scan_request *scan_request;
144 struct list_head bss_free_list; 137 struct work_struct process_scan;
145 void *bss_xbss_data; 138 struct list_head scan_list;
146 139 spinlock_t scan_lock; /* protects the scan list */
147 int scan_inprogress; /* Scan pending... */
148 u32 scan_mode; /* Type of scan done */
149 140
150 /* WPA support */ 141 /* WPA support */
151 u8 *wpa_ie; 142 u8 *wpa_ie;
@@ -182,14 +173,18 @@ extern int orinoco_debug;
182/* Exported prototypes */ 173/* Exported prototypes */
183/********************************************************************/ 174/********************************************************************/
184 175
185extern struct net_device *alloc_orinocodev( 176extern struct orinoco_private *alloc_orinocodev(
186 int sizeof_card, struct device *device, 177 int sizeof_card, struct device *device,
187 int (*hard_reset)(struct orinoco_private *), 178 int (*hard_reset)(struct orinoco_private *),
188 int (*stop_fw)(struct orinoco_private *, int)); 179 int (*stop_fw)(struct orinoco_private *, int));
189extern void free_orinocodev(struct net_device *dev); 180extern void free_orinocodev(struct orinoco_private *priv);
190extern int __orinoco_up(struct net_device *dev); 181extern int orinoco_init(struct orinoco_private *priv);
191extern int __orinoco_down(struct net_device *dev); 182extern int orinoco_if_add(struct orinoco_private *priv,
192extern int orinoco_reinit_firmware(struct net_device *dev); 183 unsigned long base_addr,
184 unsigned int irq);
185extern void orinoco_if_del(struct orinoco_private *priv);
186extern int orinoco_up(struct orinoco_private *priv);
187extern void orinoco_down(struct orinoco_private *priv);
193extern irqreturn_t orinoco_interrupt(int irq, void *dev_id); 188extern irqreturn_t orinoco_interrupt(int irq, void *dev_id);
194 189
195/********************************************************************/ 190/********************************************************************/
@@ -215,4 +210,10 @@ static inline void orinoco_unlock(struct orinoco_private *priv,
215 spin_unlock_irqrestore(&priv->lock, *flags); 210 spin_unlock_irqrestore(&priv->lock, *flags);
216} 211}
217 212
213/*** Navigate from net_device to orinoco_private ***/
214static inline struct orinoco_private *ndev_priv(struct net_device *dev)
215{
216 struct wireless_dev *wdev = netdev_priv(dev);
217 return wdev_priv(wdev);
218}
218#endif /* _ORINOCO_H */ 219#endif /* _ORINOCO_H */
diff --git a/drivers/net/wireless/orinoco/orinoco_cs.c b/drivers/net/wireless/orinoco/orinoco_cs.c
index b381aed24d73..38c1c9d2abb8 100644
--- a/drivers/net/wireless/orinoco/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco/orinoco_cs.c
@@ -106,26 +106,24 @@ orinoco_cs_hard_reset(struct orinoco_private *priv)
106static int 106static int
107orinoco_cs_probe(struct pcmcia_device *link) 107orinoco_cs_probe(struct pcmcia_device *link)
108{ 108{
109 struct net_device *dev;
110 struct orinoco_private *priv; 109 struct orinoco_private *priv;
111 struct orinoco_pccard *card; 110 struct orinoco_pccard *card;
112 111
113 dev = alloc_orinocodev(sizeof(*card), &handle_to_dev(link), 112 priv = alloc_orinocodev(sizeof(*card), &handle_to_dev(link),
114 orinoco_cs_hard_reset, NULL); 113 orinoco_cs_hard_reset, NULL);
115 if (!dev) 114 if (!priv)
116 return -ENOMEM; 115 return -ENOMEM;
117 priv = netdev_priv(dev);
118 card = priv->card; 116 card = priv->card;
119 117
120 /* Link both structures together */ 118 /* Link both structures together */
121 card->p_dev = link; 119 card->p_dev = link;
122 link->priv = dev; 120 link->priv = priv;
123 121
124 /* Interrupt setup */ 122 /* Interrupt setup */
125 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT; 123 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
126 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 124 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
127 link->irq.Handler = orinoco_interrupt; 125 link->irq.Handler = orinoco_interrupt;
128 link->irq.Instance = dev; 126 link->irq.Instance = priv;
129 127
130 /* General socket configuration defaults can go here. In this 128 /* General socket configuration defaults can go here. In this
131 * client, we assume very little, and rely on the CIS for 129 * client, we assume very little, and rely on the CIS for
@@ -146,14 +144,14 @@ orinoco_cs_probe(struct pcmcia_device *link)
146 */ 144 */
147static void orinoco_cs_detach(struct pcmcia_device *link) 145static void orinoco_cs_detach(struct pcmcia_device *link)
148{ 146{
149 struct net_device *dev = link->priv; 147 struct orinoco_private *priv = link->priv;
150 148
151 if (link->dev_node) 149 if (link->dev_node)
152 unregister_netdev(dev); 150 orinoco_if_del(priv);
153 151
154 orinoco_cs_release(link); 152 orinoco_cs_release(link);
155 153
156 free_orinocodev(dev); 154 free_orinocodev(priv);
157} /* orinoco_cs_detach */ 155} /* orinoco_cs_detach */
158 156
159/* 157/*
@@ -239,8 +237,7 @@ next_entry:
239static int 237static int
240orinoco_cs_config(struct pcmcia_device *link) 238orinoco_cs_config(struct pcmcia_device *link)
241{ 239{
242 struct net_device *dev = link->priv; 240 struct orinoco_private *priv = link->priv;
243 struct orinoco_private *priv = netdev_priv(dev);
244 struct orinoco_pccard *card = priv->card; 241 struct orinoco_pccard *card = priv->card;
245 hermes_t *hw = &priv->hw; 242 hermes_t *hw = &priv->hw;
246 int last_fn, last_ret; 243 int last_fn, last_ret;
@@ -295,29 +292,27 @@ orinoco_cs_config(struct pcmcia_device *link)
295 pcmcia_request_configuration(link, &link->conf)); 292 pcmcia_request_configuration(link, &link->conf));
296 293
297 /* Ok, we have the configuration, prepare to register the netdev */ 294 /* Ok, we have the configuration, prepare to register the netdev */
298 dev->base_addr = link->io.BasePort1;
299 dev->irq = link->irq.AssignedIRQ;
300 card->node.major = card->node.minor = 0; 295 card->node.major = card->node.minor = 0;
301 296
302 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 297 /* Initialise the main driver */
303 /* Tell the stack we exist */ 298 if (orinoco_init(priv) != 0) {
304 if (register_netdev(dev) != 0) { 299 printk(KERN_ERR PFX "orinoco_init() failed\n");
305 printk(KERN_ERR PFX "register_netdev() failed\n"); 300 goto failed;
301 }
302
303 /* Register an interface with the stack */
304 if (orinoco_if_add(priv, link->io.BasePort1,
305 link->irq.AssignedIRQ) != 0) {
306 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
306 goto failed; 307 goto failed;
307 } 308 }
308 309
309 /* At this point, the dev_node_t structure(s) needs to be 310 /* At this point, the dev_node_t structure(s) needs to be
310 * initialized and arranged in a linked list at link->dev_node. */ 311 * initialized and arranged in a linked list at link->dev_node. */
311 strcpy(card->node.dev_name, dev->name); 312 strcpy(card->node.dev_name, priv->ndev->name);
312 link->dev_node = &card->node; /* link->dev_node being non-NULL is also 313 link->dev_node = &card->node; /* link->dev_node being non-NULL is also
313 * used to indicate that the 314 * used to indicate that the
314 * net_device has been registered */ 315 * net_device has been registered */
315
316 /* Finally, report what we've done */
317 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s, irq %d, io "
318 "0x%04x-0x%04x\n", dev->name, dev_name(dev->dev.parent),
319 link->irq.AssignedIRQ, link->io.BasePort1,
320 link->io.BasePort1 + link->io.NumPorts1 - 1);
321 return 0; 316 return 0;
322 317
323 cs_failed: 318 cs_failed:
@@ -336,8 +331,7 @@ orinoco_cs_config(struct pcmcia_device *link)
336static void 331static void
337orinoco_cs_release(struct pcmcia_device *link) 332orinoco_cs_release(struct pcmcia_device *link)
338{ 333{
339 struct net_device *dev = link->priv; 334 struct orinoco_private *priv = link->priv;
340 struct orinoco_private *priv = netdev_priv(dev);
341 unsigned long flags; 335 unsigned long flags;
342 336
343 /* We're committed to taking the device away now, so mark the 337 /* We're committed to taking the device away now, so mark the
@@ -353,62 +347,26 @@ orinoco_cs_release(struct pcmcia_device *link)
353 347
354static int orinoco_cs_suspend(struct pcmcia_device *link) 348static int orinoco_cs_suspend(struct pcmcia_device *link)
355{ 349{
356 struct net_device *dev = link->priv; 350 struct orinoco_private *priv = link->priv;
357 struct orinoco_private *priv = netdev_priv(dev);
358 struct orinoco_pccard *card = priv->card; 351 struct orinoco_pccard *card = priv->card;
359 int err = 0;
360 unsigned long flags;
361 352
362 /* This is probably racy, but I can't think of 353 /* This is probably racy, but I can't think of
363 a better way, short of rewriting the PCMCIA 354 a better way, short of rewriting the PCMCIA
364 layer to not suck :-( */ 355 layer to not suck :-( */
365 if (!test_bit(0, &card->hard_reset_in_progress)) { 356 if (!test_bit(0, &card->hard_reset_in_progress))
366 spin_lock_irqsave(&priv->lock, flags); 357 orinoco_down(priv);
367
368 err = __orinoco_down(dev);
369 if (err)
370 printk(KERN_WARNING "%s: Error %d downing interface\n",
371 dev->name, err);
372
373 netif_device_detach(dev);
374 priv->hw_unavailable++;
375
376 spin_unlock_irqrestore(&priv->lock, flags);
377 }
378 358
379 return 0; 359 return 0;
380} 360}
381 361
382static int orinoco_cs_resume(struct pcmcia_device *link) 362static int orinoco_cs_resume(struct pcmcia_device *link)
383{ 363{
384 struct net_device *dev = link->priv; 364 struct orinoco_private *priv = link->priv;
385 struct orinoco_private *priv = netdev_priv(dev);
386 struct orinoco_pccard *card = priv->card; 365 struct orinoco_pccard *card = priv->card;
387 int err = 0; 366 int err = 0;
388 unsigned long flags;
389
390 if (!test_bit(0, &card->hard_reset_in_progress)) {
391 err = orinoco_reinit_firmware(dev);
392 if (err) {
393 printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
394 dev->name, err);
395 return -EIO;
396 }
397
398 spin_lock_irqsave(&priv->lock, flags);
399 367
400 netif_device_attach(dev); 368 if (!test_bit(0, &card->hard_reset_in_progress))
401 priv->hw_unavailable--; 369 err = orinoco_up(priv);
402
403 if (priv->open && !priv->hw_unavailable) {
404 err = __orinoco_up(dev);
405 if (err)
406 printk(KERN_ERR "%s: Error %d restarting card\n",
407 dev->name, err);
408 }
409
410 spin_unlock_irqrestore(&priv->lock, flags);
411 }
412 370
413 return err; 371 return err;
414} 372}
diff --git a/drivers/net/wireless/orinoco/orinoco_nortel.c b/drivers/net/wireless/orinoco/orinoco_nortel.c
index b01726255c6f..c13a4c383410 100644
--- a/drivers/net/wireless/orinoco/orinoco_nortel.c
+++ b/drivers/net/wireless/orinoco/orinoco_nortel.c
@@ -144,7 +144,6 @@ static int orinoco_nortel_init_one(struct pci_dev *pdev,
144 int err; 144 int err;
145 struct orinoco_private *priv; 145 struct orinoco_private *priv;
146 struct orinoco_pci_card *card; 146 struct orinoco_pci_card *card;
147 struct net_device *dev;
148 void __iomem *hermes_io, *bridge_io, *attr_io; 147 void __iomem *hermes_io, *bridge_io, *attr_io;
149 148
150 err = pci_enable_device(pdev); 149 err = pci_enable_device(pdev);
@@ -181,24 +180,22 @@ static int orinoco_nortel_init_one(struct pci_dev *pdev,
181 } 180 }
182 181
183 /* Allocate network device */ 182 /* Allocate network device */
184 dev = alloc_orinocodev(sizeof(*card), &pdev->dev, 183 priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
185 orinoco_nortel_cor_reset, NULL); 184 orinoco_nortel_cor_reset, NULL);
186 if (!dev) { 185 if (!priv) {
187 printk(KERN_ERR PFX "Cannot allocate network device\n"); 186 printk(KERN_ERR PFX "Cannot allocate network device\n");
188 err = -ENOMEM; 187 err = -ENOMEM;
189 goto fail_alloc; 188 goto fail_alloc;
190 } 189 }
191 190
192 priv = netdev_priv(dev);
193 card = priv->card; 191 card = priv->card;
194 card->bridge_io = bridge_io; 192 card->bridge_io = bridge_io;
195 card->attr_io = attr_io; 193 card->attr_io = attr_io;
196 SET_NETDEV_DEV(dev, &pdev->dev);
197 194
198 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING); 195 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
199 196
200 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED, 197 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
201 dev->name, dev); 198 DRIVER_NAME, priv);
202 if (err) { 199 if (err) {
203 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq); 200 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
204 err = -EBUSY; 201 err = -EBUSY;
@@ -217,24 +214,28 @@ static int orinoco_nortel_init_one(struct pci_dev *pdev,
217 goto fail; 214 goto fail;
218 } 215 }
219 216
220 err = register_netdev(dev); 217 err = orinoco_init(priv);
221 if (err) { 218 if (err) {
222 printk(KERN_ERR PFX "Cannot register network device\n"); 219 printk(KERN_ERR PFX "orinoco_init() failed\n");
223 goto fail; 220 goto fail;
224 } 221 }
225 222
226 pci_set_drvdata(pdev, dev); 223 err = orinoco_if_add(priv, 0, 0);
227 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name, 224 if (err) {
228 pci_name(pdev)); 225 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
226 goto fail;
227 }
228
229 pci_set_drvdata(pdev, priv);
229 230
230 return 0; 231 return 0;
231 232
232 fail: 233 fail:
233 free_irq(pdev->irq, dev); 234 free_irq(pdev->irq, priv);
234 235
235 fail_irq: 236 fail_irq:
236 pci_set_drvdata(pdev, NULL); 237 pci_set_drvdata(pdev, NULL);
237 free_orinocodev(dev); 238 free_orinocodev(priv);
238 239
239 fail_alloc: 240 fail_alloc:
240 pci_iounmap(pdev, hermes_io); 241 pci_iounmap(pdev, hermes_io);
@@ -256,17 +257,16 @@ static int orinoco_nortel_init_one(struct pci_dev *pdev,
256 257
257static void __devexit orinoco_nortel_remove_one(struct pci_dev *pdev) 258static void __devexit orinoco_nortel_remove_one(struct pci_dev *pdev)
258{ 259{
259 struct net_device *dev = pci_get_drvdata(pdev); 260 struct orinoco_private *priv = pci_get_drvdata(pdev);
260 struct orinoco_private *priv = netdev_priv(dev);
261 struct orinoco_pci_card *card = priv->card; 261 struct orinoco_pci_card *card = priv->card;
262 262
263 /* Clear LEDs */ 263 /* Clear LEDs */
264 iowrite16(0, card->bridge_io + 10); 264 iowrite16(0, card->bridge_io + 10);
265 265
266 unregister_netdev(dev); 266 orinoco_if_del(priv);
267 free_irq(pdev->irq, dev); 267 free_irq(pdev->irq, priv);
268 pci_set_drvdata(pdev, NULL); 268 pci_set_drvdata(pdev, NULL);
269 free_orinocodev(dev); 269 free_orinocodev(priv);
270 pci_iounmap(pdev, priv->hw.iobase); 270 pci_iounmap(pdev, priv->hw.iobase);
271 pci_iounmap(pdev, card->attr_io); 271 pci_iounmap(pdev, card->attr_io);
272 pci_iounmap(pdev, card->bridge_io); 272 pci_iounmap(pdev, card->bridge_io);
diff --git a/drivers/net/wireless/orinoco/orinoco_pci.c b/drivers/net/wireless/orinoco/orinoco_pci.c
index 78cafff1fb2e..fea7781948e7 100644
--- a/drivers/net/wireless/orinoco/orinoco_pci.c
+++ b/drivers/net/wireless/orinoco/orinoco_pci.c
@@ -116,7 +116,6 @@ static int orinoco_pci_init_one(struct pci_dev *pdev,
116 int err; 116 int err;
117 struct orinoco_private *priv; 117 struct orinoco_private *priv;
118 struct orinoco_pci_card *card; 118 struct orinoco_pci_card *card;
119 struct net_device *dev;
120 void __iomem *hermes_io; 119 void __iomem *hermes_io;
121 120
122 err = pci_enable_device(pdev); 121 err = pci_enable_device(pdev);
@@ -139,22 +138,20 @@ static int orinoco_pci_init_one(struct pci_dev *pdev,
139 } 138 }
140 139
141 /* Allocate network device */ 140 /* Allocate network device */
142 dev = alloc_orinocodev(sizeof(*card), &pdev->dev, 141 priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
143 orinoco_pci_cor_reset, NULL); 142 orinoco_pci_cor_reset, NULL);
144 if (!dev) { 143 if (!priv) {
145 printk(KERN_ERR PFX "Cannot allocate network device\n"); 144 printk(KERN_ERR PFX "Cannot allocate network device\n");
146 err = -ENOMEM; 145 err = -ENOMEM;
147 goto fail_alloc; 146 goto fail_alloc;
148 } 147 }
149 148
150 priv = netdev_priv(dev);
151 card = priv->card; 149 card = priv->card;
152 SET_NETDEV_DEV(dev, &pdev->dev);
153 150
154 hermes_struct_init(&priv->hw, hermes_io, HERMES_32BIT_REGSPACING); 151 hermes_struct_init(&priv->hw, hermes_io, HERMES_32BIT_REGSPACING);
155 152
156 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED, 153 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
157 dev->name, dev); 154 DRIVER_NAME, priv);
158 if (err) { 155 if (err) {
159 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq); 156 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
160 err = -EBUSY; 157 err = -EBUSY;
@@ -167,24 +164,28 @@ static int orinoco_pci_init_one(struct pci_dev *pdev,
167 goto fail; 164 goto fail;
168 } 165 }
169 166
170 err = register_netdev(dev); 167 err = orinoco_init(priv);
171 if (err) { 168 if (err) {
172 printk(KERN_ERR PFX "Cannot register network device\n"); 169 printk(KERN_ERR PFX "orinoco_init() failed\n");
173 goto fail; 170 goto fail;
174 } 171 }
175 172
176 pci_set_drvdata(pdev, dev); 173 err = orinoco_if_add(priv, 0, 0);
177 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name, 174 if (err) {
178 pci_name(pdev)); 175 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
176 goto fail;
177 }
178
179 pci_set_drvdata(pdev, priv);
179 180
180 return 0; 181 return 0;
181 182
182 fail: 183 fail:
183 free_irq(pdev->irq, dev); 184 free_irq(pdev->irq, priv);
184 185
185 fail_irq: 186 fail_irq:
186 pci_set_drvdata(pdev, NULL); 187 pci_set_drvdata(pdev, NULL);
187 free_orinocodev(dev); 188 free_orinocodev(priv);
188 189
189 fail_alloc: 190 fail_alloc:
190 pci_iounmap(pdev, hermes_io); 191 pci_iounmap(pdev, hermes_io);
@@ -200,13 +201,12 @@ static int orinoco_pci_init_one(struct pci_dev *pdev,
200 201
201static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev) 202static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev)
202{ 203{
203 struct net_device *dev = pci_get_drvdata(pdev); 204 struct orinoco_private *priv = pci_get_drvdata(pdev);
204 struct orinoco_private *priv = netdev_priv(dev);
205 205
206 unregister_netdev(dev); 206 orinoco_if_del(priv);
207 free_irq(pdev->irq, dev); 207 free_irq(pdev->irq, priv);
208 pci_set_drvdata(pdev, NULL); 208 pci_set_drvdata(pdev, NULL);
209 free_orinocodev(dev); 209 free_orinocodev(priv);
210 pci_iounmap(pdev, priv->hw.iobase); 210 pci_iounmap(pdev, priv->hw.iobase);
211 pci_release_regions(pdev); 211 pci_release_regions(pdev);
212 pci_disable_device(pdev); 212 pci_disable_device(pdev);
diff --git a/drivers/net/wireless/orinoco/orinoco_pci.h b/drivers/net/wireless/orinoco/orinoco_pci.h
index c655b4a3de16..ea7231af40a8 100644
--- a/drivers/net/wireless/orinoco/orinoco_pci.h
+++ b/drivers/net/wireless/orinoco/orinoco_pci.h
@@ -21,30 +21,10 @@ struct orinoco_pci_card {
21#ifdef CONFIG_PM 21#ifdef CONFIG_PM
22static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state) 22static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
23{ 23{
24 struct net_device *dev = pci_get_drvdata(pdev); 24 struct orinoco_private *priv = pci_get_drvdata(pdev);
25 struct orinoco_private *priv = netdev_priv(dev);
26 unsigned long flags;
27 int err;
28
29 err = orinoco_lock(priv, &flags);
30 if (err) {
31 printk(KERN_ERR "%s: cannot lock hardware for suspend\n",
32 dev->name);
33 return err;
34 }
35
36 err = __orinoco_down(dev);
37 if (err)
38 printk(KERN_WARNING "%s: error %d bringing interface down "
39 "for suspend\n", dev->name, err);
40
41 netif_device_detach(dev);
42
43 priv->hw_unavailable++;
44
45 orinoco_unlock(priv, &flags);
46 25
47 free_irq(pdev->irq, dev); 26 orinoco_down(priv);
27 free_irq(pdev->irq, priv);
48 pci_save_state(pdev); 28 pci_save_state(pdev);
49 pci_disable_device(pdev); 29 pci_disable_device(pdev);
50 pci_set_power_state(pdev, PCI_D3hot); 30 pci_set_power_state(pdev, PCI_D3hot);
@@ -54,9 +34,8 @@ static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
54 34
55static int orinoco_pci_resume(struct pci_dev *pdev) 35static int orinoco_pci_resume(struct pci_dev *pdev)
56{ 36{
57 struct net_device *dev = pci_get_drvdata(pdev); 37 struct orinoco_private *priv = pci_get_drvdata(pdev);
58 struct orinoco_private *priv = netdev_priv(dev); 38 struct net_device *dev = priv->ndev;
59 unsigned long flags;
60 int err; 39 int err;
61 40
62 pci_set_power_state(pdev, 0); 41 pci_set_power_state(pdev, 0);
@@ -69,7 +48,7 @@ static int orinoco_pci_resume(struct pci_dev *pdev)
69 pci_restore_state(pdev); 48 pci_restore_state(pdev);
70 49
71 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED, 50 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
72 dev->name, dev); 51 dev->name, priv);
73 if (err) { 52 if (err) {
74 printk(KERN_ERR "%s: cannot re-allocate IRQ on resume\n", 53 printk(KERN_ERR "%s: cannot re-allocate IRQ on resume\n",
75 dev->name); 54 dev->name);
@@ -77,29 +56,9 @@ static int orinoco_pci_resume(struct pci_dev *pdev)
77 return -EBUSY; 56 return -EBUSY;
78 } 57 }
79 58
80 err = orinoco_reinit_firmware(dev); 59 err = orinoco_up(priv);
81 if (err) {
82 printk(KERN_ERR "%s: error %d re-initializing firmware "
83 "on resume\n", dev->name, err);
84 return err;
85 }
86
87 spin_lock_irqsave(&priv->lock, flags);
88
89 netif_device_attach(dev);
90 60
91 priv->hw_unavailable--; 61 return err;
92
93 if (priv->open && (!priv->hw_unavailable)) {
94 err = __orinoco_up(dev);
95 if (err)
96 printk(KERN_ERR "%s: Error %d restarting card on resume\n",
97 dev->name, err);
98 }
99
100 spin_unlock_irqrestore(&priv->lock, flags);
101
102 return 0;
103} 62}
104#else 63#else
105#define orinoco_pci_suspend NULL 64#define orinoco_pci_suspend NULL
diff --git a/drivers/net/wireless/orinoco/orinoco_plx.c b/drivers/net/wireless/orinoco/orinoco_plx.c
index a2a4471c0337..3f2942a1e4f5 100644
--- a/drivers/net/wireless/orinoco/orinoco_plx.c
+++ b/drivers/net/wireless/orinoco/orinoco_plx.c
@@ -183,7 +183,6 @@ static int orinoco_plx_init_one(struct pci_dev *pdev,
183 int err; 183 int err;
184 struct orinoco_private *priv; 184 struct orinoco_private *priv;
185 struct orinoco_pci_card *card; 185 struct orinoco_pci_card *card;
186 struct net_device *dev;
187 void __iomem *hermes_io, *attr_io, *bridge_io; 186 void __iomem *hermes_io, *attr_io, *bridge_io;
188 187
189 err = pci_enable_device(pdev); 188 err = pci_enable_device(pdev);
@@ -220,24 +219,22 @@ static int orinoco_plx_init_one(struct pci_dev *pdev,
220 } 219 }
221 220
222 /* Allocate network device */ 221 /* Allocate network device */
223 dev = alloc_orinocodev(sizeof(*card), &pdev->dev, 222 priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
224 orinoco_plx_cor_reset, NULL); 223 orinoco_plx_cor_reset, NULL);
225 if (!dev) { 224 if (!priv) {
226 printk(KERN_ERR PFX "Cannot allocate network device\n"); 225 printk(KERN_ERR PFX "Cannot allocate network device\n");
227 err = -ENOMEM; 226 err = -ENOMEM;
228 goto fail_alloc; 227 goto fail_alloc;
229 } 228 }
230 229
231 priv = netdev_priv(dev);
232 card = priv->card; 230 card = priv->card;
233 card->bridge_io = bridge_io; 231 card->bridge_io = bridge_io;
234 card->attr_io = attr_io; 232 card->attr_io = attr_io;
235 SET_NETDEV_DEV(dev, &pdev->dev);
236 233
237 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING); 234 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
238 235
239 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED, 236 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
240 dev->name, dev); 237 DRIVER_NAME, priv);
241 if (err) { 238 if (err) {
242 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq); 239 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
243 err = -EBUSY; 240 err = -EBUSY;
@@ -256,24 +253,28 @@ static int orinoco_plx_init_one(struct pci_dev *pdev,
256 goto fail; 253 goto fail;
257 } 254 }
258 255
259 err = register_netdev(dev); 256 err = orinoco_init(priv);
260 if (err) { 257 if (err) {
261 printk(KERN_ERR PFX "Cannot register network device\n"); 258 printk(KERN_ERR PFX "orinoco_init() failed\n");
262 goto fail; 259 goto fail;
263 } 260 }
264 261
265 pci_set_drvdata(pdev, dev); 262 err = orinoco_if_add(priv, 0, 0);
266 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name, 263 if (err) {
267 pci_name(pdev)); 264 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
265 goto fail;
266 }
267
268 pci_set_drvdata(pdev, priv);
268 269
269 return 0; 270 return 0;
270 271
271 fail: 272 fail:
272 free_irq(pdev->irq, dev); 273 free_irq(pdev->irq, priv);
273 274
274 fail_irq: 275 fail_irq:
275 pci_set_drvdata(pdev, NULL); 276 pci_set_drvdata(pdev, NULL);
276 free_orinocodev(dev); 277 free_orinocodev(priv);
277 278
278 fail_alloc: 279 fail_alloc:
279 pci_iounmap(pdev, hermes_io); 280 pci_iounmap(pdev, hermes_io);
@@ -295,14 +296,13 @@ static int orinoco_plx_init_one(struct pci_dev *pdev,
295 296
296static void __devexit orinoco_plx_remove_one(struct pci_dev *pdev) 297static void __devexit orinoco_plx_remove_one(struct pci_dev *pdev)
297{ 298{
298 struct net_device *dev = pci_get_drvdata(pdev); 299 struct orinoco_private *priv = pci_get_drvdata(pdev);
299 struct orinoco_private *priv = netdev_priv(dev);
300 struct orinoco_pci_card *card = priv->card; 300 struct orinoco_pci_card *card = priv->card;
301 301
302 unregister_netdev(dev); 302 orinoco_if_del(priv);
303 free_irq(pdev->irq, dev); 303 free_irq(pdev->irq, priv);
304 pci_set_drvdata(pdev, NULL); 304 pci_set_drvdata(pdev, NULL);
305 free_orinocodev(dev); 305 free_orinocodev(priv);
306 pci_iounmap(pdev, priv->hw.iobase); 306 pci_iounmap(pdev, priv->hw.iobase);
307 pci_iounmap(pdev, card->attr_io); 307 pci_iounmap(pdev, card->attr_io);
308 pci_iounmap(pdev, card->bridge_io); 308 pci_iounmap(pdev, card->bridge_io);
diff --git a/drivers/net/wireless/orinoco/orinoco_tmd.c b/drivers/net/wireless/orinoco/orinoco_tmd.c
index cda0e6e4d7a1..d3452548cc71 100644
--- a/drivers/net/wireless/orinoco/orinoco_tmd.c
+++ b/drivers/net/wireless/orinoco/orinoco_tmd.c
@@ -94,7 +94,6 @@ static int orinoco_tmd_init_one(struct pci_dev *pdev,
94 int err; 94 int err;
95 struct orinoco_private *priv; 95 struct orinoco_private *priv;
96 struct orinoco_pci_card *card; 96 struct orinoco_pci_card *card;
97 struct net_device *dev;
98 void __iomem *hermes_io, *bridge_io; 97 void __iomem *hermes_io, *bridge_io;
99 98
100 err = pci_enable_device(pdev); 99 err = pci_enable_device(pdev);
@@ -124,23 +123,21 @@ static int orinoco_tmd_init_one(struct pci_dev *pdev,
124 } 123 }
125 124
126 /* Allocate network device */ 125 /* Allocate network device */
127 dev = alloc_orinocodev(sizeof(*card), &pdev->dev, 126 priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
128 orinoco_tmd_cor_reset, NULL); 127 orinoco_tmd_cor_reset, NULL);
129 if (!dev) { 128 if (!priv) {
130 printk(KERN_ERR PFX "Cannot allocate network device\n"); 129 printk(KERN_ERR PFX "Cannot allocate network device\n");
131 err = -ENOMEM; 130 err = -ENOMEM;
132 goto fail_alloc; 131 goto fail_alloc;
133 } 132 }
134 133
135 priv = netdev_priv(dev);
136 card = priv->card; 134 card = priv->card;
137 card->bridge_io = bridge_io; 135 card->bridge_io = bridge_io;
138 SET_NETDEV_DEV(dev, &pdev->dev);
139 136
140 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING); 137 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
141 138
142 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED, 139 err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
143 dev->name, dev); 140 DRIVER_NAME, priv);
144 if (err) { 141 if (err) {
145 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq); 142 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
146 err = -EBUSY; 143 err = -EBUSY;
@@ -153,24 +150,28 @@ static int orinoco_tmd_init_one(struct pci_dev *pdev,
153 goto fail; 150 goto fail;
154 } 151 }
155 152
156 err = register_netdev(dev); 153 err = orinoco_init(priv);
157 if (err) { 154 if (err) {
158 printk(KERN_ERR PFX "Cannot register network device\n"); 155 printk(KERN_ERR PFX "orinoco_init() failed\n");
159 goto fail; 156 goto fail;
160 } 157 }
161 158
162 pci_set_drvdata(pdev, dev); 159 err = orinoco_if_add(priv, 0, 0);
163 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s\n", dev->name, 160 if (err) {
164 pci_name(pdev)); 161 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
162 goto fail;
163 }
164
165 pci_set_drvdata(pdev, priv);
165 166
166 return 0; 167 return 0;
167 168
168 fail: 169 fail:
169 free_irq(pdev->irq, dev); 170 free_irq(pdev->irq, priv);
170 171
171 fail_irq: 172 fail_irq:
172 pci_set_drvdata(pdev, NULL); 173 pci_set_drvdata(pdev, NULL);
173 free_orinocodev(dev); 174 free_orinocodev(priv);
174 175
175 fail_alloc: 176 fail_alloc:
176 pci_iounmap(pdev, hermes_io); 177 pci_iounmap(pdev, hermes_io);
@@ -189,14 +190,13 @@ static int orinoco_tmd_init_one(struct pci_dev *pdev,
189 190
190static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev) 191static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
191{ 192{
192 struct net_device *dev = pci_get_drvdata(pdev); 193 struct orinoco_private *priv = pci_get_drvdata(pdev);
193 struct orinoco_private *priv = netdev_priv(dev);
194 struct orinoco_pci_card *card = priv->card; 194 struct orinoco_pci_card *card = priv->card;
195 195
196 unregister_netdev(dev); 196 orinoco_if_del(priv);
197 free_irq(pdev->irq, dev); 197 free_irq(pdev->irq, priv);
198 pci_set_drvdata(pdev, NULL); 198 pci_set_drvdata(pdev, NULL);
199 free_orinocodev(dev); 199 free_orinocodev(priv);
200 pci_iounmap(pdev, priv->hw.iobase); 200 pci_iounmap(pdev, priv->hw.iobase);
201 pci_iounmap(pdev, card->bridge_io); 201 pci_iounmap(pdev, card->bridge_io);
202 pci_release_regions(pdev); 202 pci_release_regions(pdev);
diff --git a/drivers/net/wireless/orinoco/scan.c b/drivers/net/wireless/orinoco/scan.c
index 89d699d4dfe6..d2f10e9c2162 100644
--- a/drivers/net/wireless/orinoco/scan.c
+++ b/drivers/net/wireless/orinoco/scan.c
@@ -5,147 +5,166 @@
5 5
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <linux/string.h> 7#include <linux/string.h>
8#include <linux/etherdevice.h> 8#include <linux/ieee80211.h>
9#include <net/cfg80211.h>
9 10
10#include "hermes.h" 11#include "hermes.h"
11#include "orinoco.h" 12#include "orinoco.h"
13#include "main.h"
12 14
13#include "scan.h" 15#include "scan.h"
14 16
15#define ORINOCO_MAX_BSS_COUNT 64 17#define ZERO_DBM_OFFSET 0x95
18#define MAX_SIGNAL_LEVEL 0x8A
19#define MIN_SIGNAL_LEVEL 0x2F
16 20
17#define PRIV_BSS ((struct bss_element *)priv->bss_xbss_data) 21#define SIGNAL_TO_DBM(x) \
18#define PRIV_XBSS ((struct xbss_element *)priv->bss_xbss_data) 22 (clamp_t(s32, (x), MIN_SIGNAL_LEVEL, MAX_SIGNAL_LEVEL) \
23 - ZERO_DBM_OFFSET)
24#define SIGNAL_TO_MBM(x) (SIGNAL_TO_DBM(x) * 100)
19 25
20int orinoco_bss_data_allocate(struct orinoco_private *priv) 26static int symbol_build_supp_rates(u8 *buf, const __le16 *rates)
21{ 27{
22 if (priv->bss_xbss_data) 28 int i;
23 return 0; 29 u8 rate;
24 30
25 if (priv->has_ext_scan) 31 buf[0] = WLAN_EID_SUPP_RATES;
26 priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT * 32 for (i = 0; i < 5; i++) {
27 sizeof(struct xbss_element), 33 rate = le16_to_cpu(rates[i]);
28 GFP_KERNEL); 34 /* NULL terminated */
29 else 35 if (rate == 0x0)
30 priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT * 36 break;
31 sizeof(struct bss_element), 37 buf[i + 2] = rate;
32 GFP_KERNEL);
33
34 if (!priv->bss_xbss_data) {
35 printk(KERN_WARNING "Out of memory allocating beacons");
36 return -ENOMEM;
37 } 38 }
38 return 0; 39 buf[1] = i;
39}
40 40
41void orinoco_bss_data_free(struct orinoco_private *priv) 41 return i + 2;
42{
43 kfree(priv->bss_xbss_data);
44 priv->bss_xbss_data = NULL;
45} 42}
46 43
47void orinoco_bss_data_init(struct orinoco_private *priv) 44static int prism_build_supp_rates(u8 *buf, const u8 *rates)
48{ 45{
49 int i; 46 int i;
50 47
51 INIT_LIST_HEAD(&priv->bss_free_list); 48 buf[0] = WLAN_EID_SUPP_RATES;
52 INIT_LIST_HEAD(&priv->bss_list); 49 for (i = 0; i < 8; i++) {
53 if (priv->has_ext_scan) 50 /* NULL terminated */
54 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++) 51 if (rates[i] == 0x0)
55 list_add_tail(&(PRIV_XBSS[i].list), 52 break;
56 &priv->bss_free_list); 53 buf[i + 2] = rates[i];
57 else 54 }
58 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++) 55 buf[1] = i;
59 list_add_tail(&(PRIV_BSS[i].list), 56
60 &priv->bss_free_list); 57 /* We might still have another 2 rates, which need to go in
61 58 * extended supported rates */
62} 59 if (i == 8 && rates[i] > 0) {
63 60 buf[10] = WLAN_EID_EXT_SUPP_RATES;
64void orinoco_clear_scan_results(struct orinoco_private *priv, 61 for (; i < 10; i++) {
65 unsigned long scan_age) 62 /* NULL terminated */
66{ 63 if (rates[i] == 0x0)
67 if (priv->has_ext_scan) { 64 break;
68 struct xbss_element *bss; 65 buf[i + 2] = rates[i];
69 struct xbss_element *tmp_bss;
70
71 /* Blow away current list of scan results */
72 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
73 if (!scan_age ||
74 time_after(jiffies, bss->last_scanned + scan_age)) {
75 list_move_tail(&bss->list,
76 &priv->bss_free_list);
77 /* Don't blow away ->list, just BSS data */
78 memset(&bss->bss, 0, sizeof(bss->bss));
79 bss->last_scanned = 0;
80 }
81 }
82 } else {
83 struct bss_element *bss;
84 struct bss_element *tmp_bss;
85
86 /* Blow away current list of scan results */
87 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
88 if (!scan_age ||
89 time_after(jiffies, bss->last_scanned + scan_age)) {
90 list_move_tail(&bss->list,
91 &priv->bss_free_list);
92 /* Don't blow away ->list, just BSS data */
93 memset(&bss->bss, 0, sizeof(bss->bss));
94 bss->last_scanned = 0;
95 }
96 } 66 }
67 buf[11] = i - 8;
97 } 68 }
69
70 return (i < 8) ? i + 2 : i + 4;
98} 71}
99 72
100void orinoco_add_ext_scan_result(struct orinoco_private *priv, 73static void orinoco_add_hostscan_result(struct orinoco_private *priv,
101 struct agere_ext_scan_info *atom) 74 const union hermes_scan_info *bss)
102{ 75{
103 struct xbss_element *bss = NULL; 76 struct wiphy *wiphy = priv_to_wiphy(priv);
104 int found = 0; 77 struct ieee80211_channel *channel;
105 78 u8 *ie;
106 /* Try to update an existing bss first */ 79 u8 ie_buf[46];
107 list_for_each_entry(bss, &priv->bss_list, list) { 80 u64 timestamp;
108 if (compare_ether_addr(bss->bss.bssid, atom->bssid)) 81 s32 signal;
109 continue; 82 u16 capability;
110 /* ESSID lengths */ 83 u16 beacon_interval;
111 if (bss->bss.data[1] != atom->data[1]) 84 int ie_len;
112 continue; 85 int freq;
113 if (memcmp(&bss->bss.data[2], &atom->data[2], 86 int len;
114 atom->data[1])) 87
115 continue; 88 len = le16_to_cpu(bss->a.essid_len);
116 found = 1; 89
90 /* Reconstruct SSID and bitrate IEs to pass up */
91 ie_buf[0] = WLAN_EID_SSID;
92 ie_buf[1] = len;
93 memcpy(&ie_buf[2], bss->a.essid, len);
94
95 ie = ie_buf + len + 2;
96 ie_len = ie_buf[1] + 2;
97 switch (priv->firmware_type) {
98 case FIRMWARE_TYPE_SYMBOL:
99 ie_len += symbol_build_supp_rates(ie, bss->s.rates);
117 break; 100 break;
118 }
119 101
120 /* Grab a bss off the free list */ 102 case FIRMWARE_TYPE_INTERSIL:
121 if (!found && !list_empty(&priv->bss_free_list)) { 103 ie_len += prism_build_supp_rates(ie, bss->p.rates);
122 bss = list_entry(priv->bss_free_list.next, 104 break;
123 struct xbss_element, list);
124 list_del(priv->bss_free_list.next);
125 105
126 list_add_tail(&bss->list, &priv->bss_list); 106 case FIRMWARE_TYPE_AGERE:
107 default:
108 break;
127 } 109 }
128 110
129 if (bss) { 111 freq = ieee80211_dsss_chan_to_freq(le16_to_cpu(bss->a.channel));
130 /* Always update the BSS to get latest beacon info */ 112 channel = ieee80211_get_channel(wiphy, freq);
131 memcpy(&bss->bss, atom, sizeof(bss->bss)); 113 timestamp = 0;
132 bss->last_scanned = jiffies; 114 capability = le16_to_cpu(bss->a.capabilities);
133 } 115 beacon_interval = le16_to_cpu(bss->a.beacon_interv);
116 signal = SIGNAL_TO_MBM(le16_to_cpu(bss->a.level));
117
118 cfg80211_inform_bss(wiphy, channel, bss->a.bssid, timestamp,
119 capability, beacon_interval, ie_buf, ie_len,
120 signal, GFP_KERNEL);
134} 121}
135 122
136int orinoco_process_scan_results(struct orinoco_private *priv, 123void orinoco_add_extscan_result(struct orinoco_private *priv,
137 unsigned char *buf, 124 struct agere_ext_scan_info *bss,
138 int len) 125 size_t len)
139{ 126{
140 int offset; /* In the scan data */ 127 struct wiphy *wiphy = priv_to_wiphy(priv);
141 union hermes_scan_info *atom; 128 struct ieee80211_channel *channel;
142 int atom_len; 129 u8 *ie;
130 u64 timestamp;
131 s32 signal;
132 u16 capability;
133 u16 beacon_interval;
134 size_t ie_len;
135 int chan, freq;
136
137 ie_len = len - sizeof(*bss);
138 ie = orinoco_get_ie(bss->data, ie_len, WLAN_EID_DS_PARAMS);
139 chan = ie ? ie[2] : 0;
140 freq = ieee80211_dsss_chan_to_freq(chan);
141 channel = ieee80211_get_channel(wiphy, freq);
142
143 timestamp = le64_to_cpu(bss->timestamp);
144 capability = le16_to_cpu(bss->capabilities);
145 beacon_interval = le16_to_cpu(bss->beacon_interval);
146 ie = bss->data;
147 signal = SIGNAL_TO_MBM(bss->level);
148
149 cfg80211_inform_bss(wiphy, channel, bss->bssid, timestamp,
150 capability, beacon_interval, ie, ie_len,
151 signal, GFP_KERNEL);
152}
153
154void orinoco_add_hostscan_results(struct orinoco_private *priv,
155 unsigned char *buf,
156 size_t len)
157{
158 int offset; /* In the scan data */
159 size_t atom_len;
160 bool abort = false;
143 161
144 switch (priv->firmware_type) { 162 switch (priv->firmware_type) {
145 case FIRMWARE_TYPE_AGERE: 163 case FIRMWARE_TYPE_AGERE:
146 atom_len = sizeof(struct agere_scan_apinfo); 164 atom_len = sizeof(struct agere_scan_apinfo);
147 offset = 0; 165 offset = 0;
148 break; 166 break;
167
149 case FIRMWARE_TYPE_SYMBOL: 168 case FIRMWARE_TYPE_SYMBOL:
150 /* Lack of documentation necessitates this hack. 169 /* Lack of documentation necessitates this hack.
151 * Different firmwares have 68 or 76 byte long atoms. 170 * Different firmwares have 68 or 76 byte long atoms.
@@ -163,6 +182,7 @@ int orinoco_process_scan_results(struct orinoco_private *priv,
163 atom_len = 68; 182 atom_len = 68;
164 offset = 0; 183 offset = 0;
165 break; 184 break;
185
166 case FIRMWARE_TYPE_INTERSIL: 186 case FIRMWARE_TYPE_INTERSIL:
167 offset = 4; 187 offset = 4;
168 if (priv->has_hostscan) { 188 if (priv->has_hostscan) {
@@ -170,64 +190,41 @@ int orinoco_process_scan_results(struct orinoco_private *priv,
170 /* Sanity check for atom_len */ 190 /* Sanity check for atom_len */
171 if (atom_len < sizeof(struct prism2_scan_apinfo)) { 191 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
172 printk(KERN_ERR "%s: Invalid atom_len in scan " 192 printk(KERN_ERR "%s: Invalid atom_len in scan "
173 "data: %d\n", priv->ndev->name, 193 "data: %zu\n", priv->ndev->name,
174 atom_len); 194 atom_len);
175 return -EIO; 195 abort = true;
196 goto scan_abort;
176 } 197 }
177 } else 198 } else
178 atom_len = offsetof(struct prism2_scan_apinfo, atim); 199 atom_len = offsetof(struct prism2_scan_apinfo, atim);
179 break; 200 break;
201
180 default: 202 default:
181 return -EOPNOTSUPP; 203 abort = true;
204 goto scan_abort;
182 } 205 }
183 206
184 /* Check that we got an whole number of atoms */ 207 /* Check that we got an whole number of atoms */
185 if ((len - offset) % atom_len) { 208 if ((len - offset) % atom_len) {
186 printk(KERN_ERR "%s: Unexpected scan data length %d, " 209 printk(KERN_ERR "%s: Unexpected scan data length %zu, "
187 "atom_len %d, offset %d\n", priv->ndev->name, len, 210 "atom_len %zu, offset %d\n", priv->ndev->name, len,
188 atom_len, offset); 211 atom_len, offset);
189 return -EIO; 212 abort = true;
213 goto scan_abort;
190 } 214 }
191 215
192 orinoco_clear_scan_results(priv, msecs_to_jiffies(15000)); 216 /* Process the entries one by one */
193
194 /* Read the entries one by one */
195 for (; offset + atom_len <= len; offset += atom_len) { 217 for (; offset + atom_len <= len; offset += atom_len) {
196 int found = 0; 218 union hermes_scan_info *atom;
197 struct bss_element *bss = NULL;
198 219
199 /* Get next atom */
200 atom = (union hermes_scan_info *) (buf + offset); 220 atom = (union hermes_scan_info *) (buf + offset);
201 221
202 /* Try to update an existing bss first */ 222 orinoco_add_hostscan_result(priv, atom);
203 list_for_each_entry(bss, &priv->bss_list, list) {
204 if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
205 continue;
206 if (le16_to_cpu(bss->bss.a.essid_len) !=
207 le16_to_cpu(atom->a.essid_len))
208 continue;
209 if (memcmp(bss->bss.a.essid, atom->a.essid,
210 le16_to_cpu(atom->a.essid_len)))
211 continue;
212 found = 1;
213 break;
214 }
215
216 /* Grab a bss off the free list */
217 if (!found && !list_empty(&priv->bss_free_list)) {
218 bss = list_entry(priv->bss_free_list.next,
219 struct bss_element, list);
220 list_del(priv->bss_free_list.next);
221
222 list_add_tail(&bss->list, &priv->bss_list);
223 }
224
225 if (bss) {
226 /* Always update the BSS to get latest beacon info */
227 memcpy(&bss->bss, atom, sizeof(bss->bss));
228 bss->last_scanned = jiffies;
229 }
230 } 223 }
231 224
232 return 0; 225 scan_abort:
226 if (priv->scan_request) {
227 cfg80211_scan_done(priv->scan_request, abort);
228 priv->scan_request = NULL;
229 }
233} 230}
diff --git a/drivers/net/wireless/orinoco/scan.h b/drivers/net/wireless/orinoco/scan.h
index f319f7466af1..2dc4e046dbdb 100644
--- a/drivers/net/wireless/orinoco/scan.h
+++ b/drivers/net/wireless/orinoco/scan.h
@@ -9,21 +9,12 @@
9struct orinoco_private; 9struct orinoco_private;
10struct agere_ext_scan_info; 10struct agere_ext_scan_info;
11 11
12/* Setup and free memory for scan results */
13int orinoco_bss_data_allocate(struct orinoco_private *priv);
14void orinoco_bss_data_free(struct orinoco_private *priv);
15void orinoco_bss_data_init(struct orinoco_private *priv);
16
17/* Add scan results */ 12/* Add scan results */
18void orinoco_add_ext_scan_result(struct orinoco_private *priv, 13void orinoco_add_extscan_result(struct orinoco_private *priv,
19 struct agere_ext_scan_info *atom); 14 struct agere_ext_scan_info *atom,
20int orinoco_process_scan_results(struct orinoco_private *dev, 15 size_t len);
21 unsigned char *buf, 16void orinoco_add_hostscan_results(struct orinoco_private *dev,
22 int len); 17 unsigned char *buf,
23 18 size_t len);
24/* Clear scan results */
25void orinoco_clear_scan_results(struct orinoco_private *priv,
26 unsigned long scan_age);
27
28 19
29#endif /* _ORINOCO_SCAN_H_ */ 20#endif /* _ORINOCO_SCAN_H_ */
diff --git a/drivers/net/wireless/orinoco/spectrum_cs.c b/drivers/net/wireless/orinoco/spectrum_cs.c
index 38e5198e44c7..c361310b885d 100644
--- a/drivers/net/wireless/orinoco/spectrum_cs.c
+++ b/drivers/net/wireless/orinoco/spectrum_cs.c
@@ -178,27 +178,25 @@ spectrum_cs_stop_firmware(struct orinoco_private *priv, int idle)
178static int 178static int
179spectrum_cs_probe(struct pcmcia_device *link) 179spectrum_cs_probe(struct pcmcia_device *link)
180{ 180{
181 struct net_device *dev;
182 struct orinoco_private *priv; 181 struct orinoco_private *priv;
183 struct orinoco_pccard *card; 182 struct orinoco_pccard *card;
184 183
185 dev = alloc_orinocodev(sizeof(*card), &handle_to_dev(link), 184 priv = alloc_orinocodev(sizeof(*card), &handle_to_dev(link),
186 spectrum_cs_hard_reset, 185 spectrum_cs_hard_reset,
187 spectrum_cs_stop_firmware); 186 spectrum_cs_stop_firmware);
188 if (!dev) 187 if (!priv)
189 return -ENOMEM; 188 return -ENOMEM;
190 priv = netdev_priv(dev);
191 card = priv->card; 189 card = priv->card;
192 190
193 /* Link both structures together */ 191 /* Link both structures together */
194 card->p_dev = link; 192 card->p_dev = link;
195 link->priv = dev; 193 link->priv = priv;
196 194
197 /* Interrupt setup */ 195 /* Interrupt setup */
198 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT; 196 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
199 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 197 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
200 link->irq.Handler = orinoco_interrupt; 198 link->irq.Handler = orinoco_interrupt;
201 link->irq.Instance = dev; 199 link->irq.Instance = priv;
202 200
203 /* General socket configuration defaults can go here. In this 201 /* General socket configuration defaults can go here. In this
204 * client, we assume very little, and rely on the CIS for 202 * client, we assume very little, and rely on the CIS for
@@ -219,14 +217,14 @@ spectrum_cs_probe(struct pcmcia_device *link)
219 */ 217 */
220static void spectrum_cs_detach(struct pcmcia_device *link) 218static void spectrum_cs_detach(struct pcmcia_device *link)
221{ 219{
222 struct net_device *dev = link->priv; 220 struct orinoco_private *priv = link->priv;
223 221
224 if (link->dev_node) 222 if (link->dev_node)
225 unregister_netdev(dev); 223 orinoco_if_del(priv);
226 224
227 spectrum_cs_release(link); 225 spectrum_cs_release(link);
228 226
229 free_orinocodev(dev); 227 free_orinocodev(priv);
230} /* spectrum_cs_detach */ 228} /* spectrum_cs_detach */
231 229
232/* 230/*
@@ -306,8 +304,7 @@ next_entry:
306static int 304static int
307spectrum_cs_config(struct pcmcia_device *link) 305spectrum_cs_config(struct pcmcia_device *link)
308{ 306{
309 struct net_device *dev = link->priv; 307 struct orinoco_private *priv = link->priv;
310 struct orinoco_private *priv = netdev_priv(dev);
311 struct orinoco_pccard *card = priv->card; 308 struct orinoco_pccard *card = priv->card;
312 hermes_t *hw = &priv->hw; 309 hermes_t *hw = &priv->hw;
313 int last_fn, last_ret; 310 int last_fn, last_ret;
@@ -362,34 +359,31 @@ spectrum_cs_config(struct pcmcia_device *link)
362 pcmcia_request_configuration(link, &link->conf)); 359 pcmcia_request_configuration(link, &link->conf));
363 360
364 /* Ok, we have the configuration, prepare to register the netdev */ 361 /* Ok, we have the configuration, prepare to register the netdev */
365 dev->base_addr = link->io.BasePort1;
366 dev->irq = link->irq.AssignedIRQ;
367 card->node.major = card->node.minor = 0; 362 card->node.major = card->node.minor = 0;
368 363
369 /* Reset card */ 364 /* Reset card */
370 if (spectrum_cs_hard_reset(priv) != 0) 365 if (spectrum_cs_hard_reset(priv) != 0)
371 goto failed; 366 goto failed;
372 367
373 SET_NETDEV_DEV(dev, &handle_to_dev(link)); 368 /* Initialise the main driver */
374 /* Tell the stack we exist */ 369 if (orinoco_init(priv) != 0) {
375 if (register_netdev(dev) != 0) { 370 printk(KERN_ERR PFX "orinoco_init() failed\n");
376 printk(KERN_ERR PFX "register_netdev() failed\n"); 371 goto failed;
372 }
373
374 /* Register an interface with the stack */
375 if (orinoco_if_add(priv, link->io.BasePort1,
376 link->irq.AssignedIRQ) != 0) {
377 printk(KERN_ERR PFX "orinoco_if_add() failed\n");
377 goto failed; 378 goto failed;
378 } 379 }
379 380
380 /* At this point, the dev_node_t structure(s) needs to be 381 /* At this point, the dev_node_t structure(s) needs to be
381 * initialized and arranged in a linked list at link->dev_node. */ 382 * initialized and arranged in a linked list at link->dev_node. */
382 strcpy(card->node.dev_name, dev->name); 383 strcpy(card->node.dev_name, priv->ndev->name);
383 link->dev_node = &card->node; /* link->dev_node being non-NULL is also 384 link->dev_node = &card->node; /* link->dev_node being non-NULL is also
384 * used to indicate that the 385 * used to indicate that the
385 * net_device has been registered */ 386 * net_device has been registered */
386
387 /* Finally, report what we've done */
388 printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s, irq %d, io "
389 "0x%04x-0x%04x\n", dev->name, dev_name(dev->dev.parent),
390 link->irq.AssignedIRQ, link->io.BasePort1,
391 link->io.BasePort1 + link->io.NumPorts1 - 1);
392
393 return 0; 387 return 0;
394 388
395 cs_failed: 389 cs_failed:
@@ -408,8 +402,7 @@ spectrum_cs_config(struct pcmcia_device *link)
408static void 402static void
409spectrum_cs_release(struct pcmcia_device *link) 403spectrum_cs_release(struct pcmcia_device *link)
410{ 404{
411 struct net_device *dev = link->priv; 405 struct orinoco_private *priv = link->priv;
412 struct orinoco_private *priv = netdev_priv(dev);
413 unsigned long flags; 406 unsigned long flags;
414 407
415 /* We're committed to taking the device away now, so mark the 408 /* We're committed to taking the device away now, so mark the
@@ -427,23 +420,11 @@ spectrum_cs_release(struct pcmcia_device *link)
427static int 420static int
428spectrum_cs_suspend(struct pcmcia_device *link) 421spectrum_cs_suspend(struct pcmcia_device *link)
429{ 422{
430 struct net_device *dev = link->priv; 423 struct orinoco_private *priv = link->priv;
431 struct orinoco_private *priv = netdev_priv(dev);
432 unsigned long flags;
433 int err = 0; 424 int err = 0;
434 425
435 /* Mark the device as stopped, to block IO until later */ 426 /* Mark the device as stopped, to block IO until later */
436 spin_lock_irqsave(&priv->lock, flags); 427 orinoco_down(priv);
437
438 err = __orinoco_down(dev);
439 if (err)
440 printk(KERN_WARNING "%s: Error %d downing interface\n",
441 dev->name, err);
442
443 netif_device_detach(dev);
444 priv->hw_unavailable++;
445
446 spin_unlock_irqrestore(&priv->lock, flags);
447 428
448 return err; 429 return err;
449} 430}
@@ -451,33 +432,10 @@ spectrum_cs_suspend(struct pcmcia_device *link)
451static int 432static int
452spectrum_cs_resume(struct pcmcia_device *link) 433spectrum_cs_resume(struct pcmcia_device *link)
453{ 434{
454 struct net_device *dev = link->priv; 435 struct orinoco_private *priv = link->priv;
455 struct orinoco_private *priv = netdev_priv(dev); 436 int err = orinoco_up(priv);
456 unsigned long flags;
457 int err;
458
459 err = orinoco_reinit_firmware(dev);
460 if (err) {
461 printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
462 dev->name, err);
463 return -EIO;
464 }
465
466 spin_lock_irqsave(&priv->lock, flags);
467
468 netif_device_attach(dev);
469 priv->hw_unavailable--;
470 437
471 if (priv->open && !priv->hw_unavailable) { 438 return err;
472 err = __orinoco_up(dev);
473 if (err)
474 printk(KERN_ERR "%s: Error %d restarting card\n",
475 dev->name, err);
476 }
477
478 spin_unlock_irqrestore(&priv->lock, flags);
479
480 return 0;
481} 439}
482 440
483 441
diff --git a/drivers/net/wireless/orinoco/wext.c b/drivers/net/wireless/orinoco/wext.c
index 3f0814234392..b6ff3dbb7dd6 100644
--- a/drivers/net/wireless/orinoco/wext.c
+++ b/drivers/net/wireless/orinoco/wext.c
@@ -7,6 +7,7 @@
7#include <linux/wireless.h> 7#include <linux/wireless.h>
8#include <linux/ieee80211.h> 8#include <linux/ieee80211.h>
9#include <net/iw_handler.h> 9#include <net/iw_handler.h>
10#include <net/cfg80211.h>
10 11
11#include "hermes.h" 12#include "hermes.h"
12#include "hermes_rid.h" 13#include "hermes_rid.h"
@@ -23,7 +24,7 @@
23 24
24static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev) 25static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
25{ 26{
26 struct orinoco_private *priv = netdev_priv(dev); 27 struct orinoco_private *priv = ndev_priv(dev);
27 hermes_t *hw = &priv->hw; 28 hermes_t *hw = &priv->hw;
28 struct iw_statistics *wstats = &priv->wstats; 29 struct iw_statistics *wstats = &priv->wstats;
29 int err; 30 int err;
@@ -51,7 +52,7 @@ static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
51 * here so we're not safe to sleep here. */ 52 * here so we're not safe to sleep here. */
52 hermes_inquire(hw, HERMES_INQ_TALLIES); 53 hermes_inquire(hw, HERMES_INQ_TALLIES);
53 54
54 if (priv->iw_mode == IW_MODE_ADHOC) { 55 if (priv->iw_mode == NL80211_IFTYPE_ADHOC) {
55 memset(&wstats->qual, 0, sizeof(wstats->qual)); 56 memset(&wstats->qual, 0, sizeof(wstats->qual));
56 /* If a spy address is defined, we report stats of the 57 /* If a spy address is defined, we report stats of the
57 * first spy address - Jean II */ 58 * first spy address - Jean II */
@@ -87,31 +88,12 @@ static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
87/* Wireless extensions */ 88/* Wireless extensions */
88/********************************************************************/ 89/********************************************************************/
89 90
90static int orinoco_ioctl_getname(struct net_device *dev,
91 struct iw_request_info *info,
92 char *name,
93 char *extra)
94{
95 struct orinoco_private *priv = netdev_priv(dev);
96 int numrates;
97 int err;
98
99 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
100
101 if (!err && (numrates > 2))
102 strcpy(name, "IEEE 802.11b");
103 else
104 strcpy(name, "IEEE 802.11-DS");
105
106 return 0;
107}
108
109static int orinoco_ioctl_setwap(struct net_device *dev, 91static int orinoco_ioctl_setwap(struct net_device *dev,
110 struct iw_request_info *info, 92 struct iw_request_info *info,
111 struct sockaddr *ap_addr, 93 struct sockaddr *ap_addr,
112 char *extra) 94 char *extra)
113{ 95{
114 struct orinoco_private *priv = netdev_priv(dev); 96 struct orinoco_private *priv = ndev_priv(dev);
115 int err = -EINPROGRESS; /* Call commit handler */ 97 int err = -EINPROGRESS; /* Call commit handler */
116 unsigned long flags; 98 unsigned long flags;
117 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 99 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
@@ -142,7 +124,7 @@ static int orinoco_ioctl_setwap(struct net_device *dev,
142 goto out; 124 goto out;
143 } 125 }
144 126
145 if (priv->iw_mode != IW_MODE_INFRA) { 127 if (priv->iw_mode != NL80211_IFTYPE_STATION) {
146 printk(KERN_WARNING "%s: Manual roaming supported only in " 128 printk(KERN_WARNING "%s: Manual roaming supported only in "
147 "managed mode\n", dev->name); 129 "managed mode\n", dev->name);
148 err = -EOPNOTSUPP; 130 err = -EOPNOTSUPP;
@@ -172,7 +154,7 @@ static int orinoco_ioctl_getwap(struct net_device *dev,
172 struct sockaddr *ap_addr, 154 struct sockaddr *ap_addr,
173 char *extra) 155 char *extra)
174{ 156{
175 struct orinoco_private *priv = netdev_priv(dev); 157 struct orinoco_private *priv = ndev_priv(dev);
176 158
177 hermes_t *hw = &priv->hw; 159 hermes_t *hw = &priv->hw;
178 int err = 0; 160 int err = 0;
@@ -190,184 +172,12 @@ static int orinoco_ioctl_getwap(struct net_device *dev,
190 return err; 172 return err;
191} 173}
192 174
193static int orinoco_ioctl_setmode(struct net_device *dev,
194 struct iw_request_info *info,
195 u32 *mode,
196 char *extra)
197{
198 struct orinoco_private *priv = netdev_priv(dev);
199 int err = -EINPROGRESS; /* Call commit handler */
200 unsigned long flags;
201
202 if (priv->iw_mode == *mode)
203 return 0;
204
205 if (orinoco_lock(priv, &flags) != 0)
206 return -EBUSY;
207
208 switch (*mode) {
209 case IW_MODE_ADHOC:
210 if (!priv->has_ibss && !priv->has_port3)
211 err = -EOPNOTSUPP;
212 break;
213
214 case IW_MODE_INFRA:
215 break;
216
217 case IW_MODE_MONITOR:
218 if (priv->broken_monitor && !force_monitor) {
219 printk(KERN_WARNING "%s: Monitor mode support is "
220 "buggy in this firmware, not enabling\n",
221 dev->name);
222 err = -EOPNOTSUPP;
223 }
224 break;
225
226 default:
227 err = -EOPNOTSUPP;
228 break;
229 }
230
231 if (err == -EINPROGRESS) {
232 priv->iw_mode = *mode;
233 set_port_type(priv);
234 }
235
236 orinoco_unlock(priv, &flags);
237
238 return err;
239}
240
241static int orinoco_ioctl_getmode(struct net_device *dev,
242 struct iw_request_info *info,
243 u32 *mode,
244 char *extra)
245{
246 struct orinoco_private *priv = netdev_priv(dev);
247
248 *mode = priv->iw_mode;
249 return 0;
250}
251
252static int orinoco_ioctl_getiwrange(struct net_device *dev,
253 struct iw_request_info *info,
254 struct iw_point *rrq,
255 char *extra)
256{
257 struct orinoco_private *priv = netdev_priv(dev);
258 int err = 0;
259 struct iw_range *range = (struct iw_range *) extra;
260 int numrates;
261 int i, k;
262
263 rrq->length = sizeof(struct iw_range);
264 memset(range, 0, sizeof(struct iw_range));
265
266 range->we_version_compiled = WIRELESS_EXT;
267 range->we_version_source = 22;
268
269 /* Set available channels/frequencies */
270 range->num_channels = NUM_CHANNELS;
271 k = 0;
272 for (i = 0; i < NUM_CHANNELS; i++) {
273 if (priv->channel_mask & (1 << i)) {
274 range->freq[k].i = i + 1;
275 range->freq[k].m = (ieee80211_dsss_chan_to_freq(i + 1) *
276 100000);
277 range->freq[k].e = 1;
278 k++;
279 }
280
281 if (k >= IW_MAX_FREQUENCIES)
282 break;
283 }
284 range->num_frequency = k;
285 range->sensitivity = 3;
286
287 if (priv->has_wep) {
288 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
289 range->encoding_size[0] = SMALL_KEY_SIZE;
290 range->num_encoding_sizes = 1;
291
292 if (priv->has_big_wep) {
293 range->encoding_size[1] = LARGE_KEY_SIZE;
294 range->num_encoding_sizes = 2;
295 }
296 }
297
298 if (priv->has_wpa)
299 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
300
301 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))) {
302 /* Quality stats meaningless in ad-hoc mode */
303 } else {
304 range->max_qual.qual = 0x8b - 0x2f;
305 range->max_qual.level = 0x2f - 0x95 - 1;
306 range->max_qual.noise = 0x2f - 0x95 - 1;
307 /* Need to get better values */
308 range->avg_qual.qual = 0x24;
309 range->avg_qual.level = 0xC2;
310 range->avg_qual.noise = 0x9E;
311 }
312
313 err = orinoco_hw_get_bitratelist(priv, &numrates,
314 range->bitrate, IW_MAX_BITRATES);
315 if (err)
316 return err;
317 range->num_bitrates = numrates;
318
319 /* Set an indication of the max TCP throughput in bit/s that we can
320 * expect using this interface. May be use for QoS stuff...
321 * Jean II */
322 if (numrates > 2)
323 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
324 else
325 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
326
327 range->min_rts = 0;
328 range->max_rts = 2347;
329 range->min_frag = 256;
330 range->max_frag = 2346;
331
332 range->min_pmp = 0;
333 range->max_pmp = 65535000;
334 range->min_pmt = 0;
335 range->max_pmt = 65535 * 1000; /* ??? */
336 range->pmp_flags = IW_POWER_PERIOD;
337 range->pmt_flags = IW_POWER_TIMEOUT;
338 range->pm_capa = (IW_POWER_PERIOD | IW_POWER_TIMEOUT |
339 IW_POWER_UNICAST_R);
340
341 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
342 range->retry_flags = IW_RETRY_LIMIT;
343 range->r_time_flags = IW_RETRY_LIFETIME;
344 range->min_retry = 0;
345 range->max_retry = 65535; /* ??? */
346 range->min_r_time = 0;
347 range->max_r_time = 65535 * 1000; /* ??? */
348
349 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
350 range->scan_capa = IW_SCAN_CAPA_ESSID;
351 else
352 range->scan_capa = IW_SCAN_CAPA_NONE;
353
354 /* Event capability (kernel) */
355 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
356 /* Event capability (driver) */
357 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
358 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
359 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
360 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
361
362 return 0;
363}
364
365static int orinoco_ioctl_setiwencode(struct net_device *dev, 175static int orinoco_ioctl_setiwencode(struct net_device *dev,
366 struct iw_request_info *info, 176 struct iw_request_info *info,
367 struct iw_point *erq, 177 struct iw_point *erq,
368 char *keybuf) 178 char *keybuf)
369{ 179{
370 struct orinoco_private *priv = netdev_priv(dev); 180 struct orinoco_private *priv = ndev_priv(dev);
371 int index = (erq->flags & IW_ENCODE_INDEX) - 1; 181 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
372 int setindex = priv->tx_key; 182 int setindex = priv->tx_key;
373 int encode_alg = priv->encode_alg; 183 int encode_alg = priv->encode_alg;
@@ -469,7 +279,7 @@ static int orinoco_ioctl_getiwencode(struct net_device *dev,
469 struct iw_point *erq, 279 struct iw_point *erq,
470 char *keybuf) 280 char *keybuf)
471{ 281{
472 struct orinoco_private *priv = netdev_priv(dev); 282 struct orinoco_private *priv = ndev_priv(dev);
473 int index = (erq->flags & IW_ENCODE_INDEX) - 1; 283 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
474 u16 xlen = 0; 284 u16 xlen = 0;
475 unsigned long flags; 285 unsigned long flags;
@@ -508,7 +318,7 @@ static int orinoco_ioctl_setessid(struct net_device *dev,
508 struct iw_point *erq, 318 struct iw_point *erq,
509 char *essidbuf) 319 char *essidbuf)
510{ 320{
511 struct orinoco_private *priv = netdev_priv(dev); 321 struct orinoco_private *priv = ndev_priv(dev);
512 unsigned long flags; 322 unsigned long flags;
513 323
514 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it 324 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
@@ -539,7 +349,7 @@ static int orinoco_ioctl_getessid(struct net_device *dev,
539 struct iw_point *erq, 349 struct iw_point *erq,
540 char *essidbuf) 350 char *essidbuf)
541{ 351{
542 struct orinoco_private *priv = netdev_priv(dev); 352 struct orinoco_private *priv = ndev_priv(dev);
543 int active; 353 int active;
544 int err = 0; 354 int err = 0;
545 unsigned long flags; 355 unsigned long flags;
@@ -562,59 +372,18 @@ static int orinoco_ioctl_getessid(struct net_device *dev,
562 return 0; 372 return 0;
563} 373}
564 374
565static int orinoco_ioctl_setnick(struct net_device *dev,
566 struct iw_request_info *info,
567 struct iw_point *nrq,
568 char *nickbuf)
569{
570 struct orinoco_private *priv = netdev_priv(dev);
571 unsigned long flags;
572
573 if (nrq->length > IW_ESSID_MAX_SIZE)
574 return -E2BIG;
575
576 if (orinoco_lock(priv, &flags) != 0)
577 return -EBUSY;
578
579 memset(priv->nick, 0, sizeof(priv->nick));
580 memcpy(priv->nick, nickbuf, nrq->length);
581
582 orinoco_unlock(priv, &flags);
583
584 return -EINPROGRESS; /* Call commit handler */
585}
586
587static int orinoco_ioctl_getnick(struct net_device *dev,
588 struct iw_request_info *info,
589 struct iw_point *nrq,
590 char *nickbuf)
591{
592 struct orinoco_private *priv = netdev_priv(dev);
593 unsigned long flags;
594
595 if (orinoco_lock(priv, &flags) != 0)
596 return -EBUSY;
597
598 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
599 orinoco_unlock(priv, &flags);
600
601 nrq->length = strlen(priv->nick);
602
603 return 0;
604}
605
606static int orinoco_ioctl_setfreq(struct net_device *dev, 375static int orinoco_ioctl_setfreq(struct net_device *dev,
607 struct iw_request_info *info, 376 struct iw_request_info *info,
608 struct iw_freq *frq, 377 struct iw_freq *frq,
609 char *extra) 378 char *extra)
610{ 379{
611 struct orinoco_private *priv = netdev_priv(dev); 380 struct orinoco_private *priv = ndev_priv(dev);
612 int chan = -1; 381 int chan = -1;
613 unsigned long flags; 382 unsigned long flags;
614 int err = -EINPROGRESS; /* Call commit handler */ 383 int err = -EINPROGRESS; /* Call commit handler */
615 384
616 /* In infrastructure mode the AP sets the channel */ 385 /* In infrastructure mode the AP sets the channel */
617 if (priv->iw_mode == IW_MODE_INFRA) 386 if (priv->iw_mode == NL80211_IFTYPE_STATION)
618 return -EBUSY; 387 return -EBUSY;
619 388
620 if ((frq->e == 0) && (frq->m <= 1000)) { 389 if ((frq->e == 0) && (frq->m <= 1000)) {
@@ -640,7 +409,7 @@ static int orinoco_ioctl_setfreq(struct net_device *dev,
640 return -EBUSY; 409 return -EBUSY;
641 410
642 priv->channel = chan; 411 priv->channel = chan;
643 if (priv->iw_mode == IW_MODE_MONITOR) { 412 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
644 /* Fast channel change - no commit if successful */ 413 /* Fast channel change - no commit if successful */
645 hermes_t *hw = &priv->hw; 414 hermes_t *hw = &priv->hw;
646 err = hermes_docmd_wait(hw, HERMES_CMD_TEST | 415 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
@@ -657,7 +426,7 @@ static int orinoco_ioctl_getfreq(struct net_device *dev,
657 struct iw_freq *frq, 426 struct iw_freq *frq,
658 char *extra) 427 char *extra)
659{ 428{
660 struct orinoco_private *priv = netdev_priv(dev); 429 struct orinoco_private *priv = ndev_priv(dev);
661 int tmp; 430 int tmp;
662 431
663 /* Locking done in there */ 432 /* Locking done in there */
@@ -676,7 +445,7 @@ static int orinoco_ioctl_getsens(struct net_device *dev,
676 struct iw_param *srq, 445 struct iw_param *srq,
677 char *extra) 446 char *extra)
678{ 447{
679 struct orinoco_private *priv = netdev_priv(dev); 448 struct orinoco_private *priv = ndev_priv(dev);
680 hermes_t *hw = &priv->hw; 449 hermes_t *hw = &priv->hw;
681 u16 val; 450 u16 val;
682 int err; 451 int err;
@@ -705,7 +474,7 @@ static int orinoco_ioctl_setsens(struct net_device *dev,
705 struct iw_param *srq, 474 struct iw_param *srq,
706 char *extra) 475 char *extra)
707{ 476{
708 struct orinoco_private *priv = netdev_priv(dev); 477 struct orinoco_private *priv = ndev_priv(dev);
709 int val = srq->value; 478 int val = srq->value;
710 unsigned long flags; 479 unsigned long flags;
711 480
@@ -728,7 +497,7 @@ static int orinoco_ioctl_setrts(struct net_device *dev,
728 struct iw_param *rrq, 497 struct iw_param *rrq,
729 char *extra) 498 char *extra)
730{ 499{
731 struct orinoco_private *priv = netdev_priv(dev); 500 struct orinoco_private *priv = ndev_priv(dev);
732 int val = rrq->value; 501 int val = rrq->value;
733 unsigned long flags; 502 unsigned long flags;
734 503
@@ -752,7 +521,7 @@ static int orinoco_ioctl_getrts(struct net_device *dev,
752 struct iw_param *rrq, 521 struct iw_param *rrq,
753 char *extra) 522 char *extra)
754{ 523{
755 struct orinoco_private *priv = netdev_priv(dev); 524 struct orinoco_private *priv = ndev_priv(dev);
756 525
757 rrq->value = priv->rts_thresh; 526 rrq->value = priv->rts_thresh;
758 rrq->disabled = (rrq->value == 2347); 527 rrq->disabled = (rrq->value == 2347);
@@ -766,7 +535,7 @@ static int orinoco_ioctl_setfrag(struct net_device *dev,
766 struct iw_param *frq, 535 struct iw_param *frq,
767 char *extra) 536 char *extra)
768{ 537{
769 struct orinoco_private *priv = netdev_priv(dev); 538 struct orinoco_private *priv = ndev_priv(dev);
770 int err = -EINPROGRESS; /* Call commit handler */ 539 int err = -EINPROGRESS; /* Call commit handler */
771 unsigned long flags; 540 unsigned long flags;
772 541
@@ -806,7 +575,7 @@ static int orinoco_ioctl_getfrag(struct net_device *dev,
806 struct iw_param *frq, 575 struct iw_param *frq,
807 char *extra) 576 char *extra)
808{ 577{
809 struct orinoco_private *priv = netdev_priv(dev); 578 struct orinoco_private *priv = ndev_priv(dev);
810 hermes_t *hw = &priv->hw; 579 hermes_t *hw = &priv->hw;
811 int err; 580 int err;
812 u16 val; 581 u16 val;
@@ -847,7 +616,7 @@ static int orinoco_ioctl_setrate(struct net_device *dev,
847 struct iw_param *rrq, 616 struct iw_param *rrq,
848 char *extra) 617 char *extra)
849{ 618{
850 struct orinoco_private *priv = netdev_priv(dev); 619 struct orinoco_private *priv = ndev_priv(dev);
851 int ratemode; 620 int ratemode;
852 int bitrate; /* 100s of kilobits */ 621 int bitrate; /* 100s of kilobits */
853 unsigned long flags; 622 unsigned long flags;
@@ -881,7 +650,7 @@ static int orinoco_ioctl_getrate(struct net_device *dev,
881 struct iw_param *rrq, 650 struct iw_param *rrq,
882 char *extra) 651 char *extra)
883{ 652{
884 struct orinoco_private *priv = netdev_priv(dev); 653 struct orinoco_private *priv = ndev_priv(dev);
885 int err = 0; 654 int err = 0;
886 int bitrate, automatic; 655 int bitrate, automatic;
887 unsigned long flags; 656 unsigned long flags;
@@ -910,7 +679,7 @@ static int orinoco_ioctl_setpower(struct net_device *dev,
910 struct iw_param *prq, 679 struct iw_param *prq,
911 char *extra) 680 char *extra)
912{ 681{
913 struct orinoco_private *priv = netdev_priv(dev); 682 struct orinoco_private *priv = ndev_priv(dev);
914 int err = -EINPROGRESS; /* Call commit handler */ 683 int err = -EINPROGRESS; /* Call commit handler */
915 unsigned long flags; 684 unsigned long flags;
916 685
@@ -964,7 +733,7 @@ static int orinoco_ioctl_getpower(struct net_device *dev,
964 struct iw_param *prq, 733 struct iw_param *prq,
965 char *extra) 734 char *extra)
966{ 735{
967 struct orinoco_private *priv = netdev_priv(dev); 736 struct orinoco_private *priv = ndev_priv(dev);
968 hermes_t *hw = &priv->hw; 737 hermes_t *hw = &priv->hw;
969 int err = 0; 738 int err = 0;
970 u16 enable, period, timeout, mcast; 739 u16 enable, period, timeout, mcast;
@@ -1018,7 +787,7 @@ static int orinoco_ioctl_set_encodeext(struct net_device *dev,
1018 union iwreq_data *wrqu, 787 union iwreq_data *wrqu,
1019 char *extra) 788 char *extra)
1020{ 789{
1021 struct orinoco_private *priv = netdev_priv(dev); 790 struct orinoco_private *priv = ndev_priv(dev);
1022 struct iw_point *encoding = &wrqu->encoding; 791 struct iw_point *encoding = &wrqu->encoding;
1023 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; 792 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1024 int idx, alg = ext->alg, set_key = 1; 793 int idx, alg = ext->alg, set_key = 1;
@@ -1079,7 +848,6 @@ static int orinoco_ioctl_set_encodeext(struct net_device *dev,
1079 848
1080 case IW_ENCODE_ALG_TKIP: 849 case IW_ENCODE_ALG_TKIP:
1081 { 850 {
1082 hermes_t *hw = &priv->hw;
1083 u8 *tkip_iv = NULL; 851 u8 *tkip_iv = NULL;
1084 852
1085 if (!priv->has_wpa || 853 if (!priv->has_wpa ||
@@ -1094,7 +862,7 @@ static int orinoco_ioctl_set_encodeext(struct net_device *dev,
1094 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) 862 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
1095 tkip_iv = &ext->rx_seq[0]; 863 tkip_iv = &ext->rx_seq[0];
1096 864
1097 err = __orinoco_hw_set_tkip_key(hw, idx, 865 err = __orinoco_hw_set_tkip_key(priv, idx,
1098 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, 866 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
1099 (u8 *) &priv->tkip_key[idx], 867 (u8 *) &priv->tkip_key[idx],
1100 tkip_iv, NULL); 868 tkip_iv, NULL);
@@ -1120,7 +888,7 @@ static int orinoco_ioctl_get_encodeext(struct net_device *dev,
1120 union iwreq_data *wrqu, 888 union iwreq_data *wrqu,
1121 char *extra) 889 char *extra)
1122{ 890{
1123 struct orinoco_private *priv = netdev_priv(dev); 891 struct orinoco_private *priv = ndev_priv(dev);
1124 struct iw_point *encoding = &wrqu->encoding; 892 struct iw_point *encoding = &wrqu->encoding;
1125 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; 893 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1126 int idx, max_key_len; 894 int idx, max_key_len;
@@ -1177,7 +945,7 @@ static int orinoco_ioctl_set_auth(struct net_device *dev,
1177 struct iw_request_info *info, 945 struct iw_request_info *info,
1178 union iwreq_data *wrqu, char *extra) 946 union iwreq_data *wrqu, char *extra)
1179{ 947{
1180 struct orinoco_private *priv = netdev_priv(dev); 948 struct orinoco_private *priv = ndev_priv(dev);
1181 hermes_t *hw = &priv->hw; 949 hermes_t *hw = &priv->hw;
1182 struct iw_param *param = &wrqu->param; 950 struct iw_param *param = &wrqu->param;
1183 unsigned long flags; 951 unsigned long flags;
@@ -1255,7 +1023,7 @@ static int orinoco_ioctl_get_auth(struct net_device *dev,
1255 struct iw_request_info *info, 1023 struct iw_request_info *info,
1256 union iwreq_data *wrqu, char *extra) 1024 union iwreq_data *wrqu, char *extra)
1257{ 1025{
1258 struct orinoco_private *priv = netdev_priv(dev); 1026 struct orinoco_private *priv = ndev_priv(dev);
1259 struct iw_param *param = &wrqu->param; 1027 struct iw_param *param = &wrqu->param;
1260 unsigned long flags; 1028 unsigned long flags;
1261 int ret = 0; 1029 int ret = 0;
@@ -1295,7 +1063,7 @@ static int orinoco_ioctl_set_genie(struct net_device *dev,
1295 struct iw_request_info *info, 1063 struct iw_request_info *info,
1296 union iwreq_data *wrqu, char *extra) 1064 union iwreq_data *wrqu, char *extra)
1297{ 1065{
1298 struct orinoco_private *priv = netdev_priv(dev); 1066 struct orinoco_private *priv = ndev_priv(dev);
1299 u8 *buf; 1067 u8 *buf;
1300 unsigned long flags; 1068 unsigned long flags;
1301 1069
@@ -1338,7 +1106,7 @@ static int orinoco_ioctl_get_genie(struct net_device *dev,
1338 struct iw_request_info *info, 1106 struct iw_request_info *info,
1339 union iwreq_data *wrqu, char *extra) 1107 union iwreq_data *wrqu, char *extra)
1340{ 1108{
1341 struct orinoco_private *priv = netdev_priv(dev); 1109 struct orinoco_private *priv = ndev_priv(dev);
1342 unsigned long flags; 1110 unsigned long flags;
1343 int err = 0; 1111 int err = 0;
1344 1112
@@ -1367,7 +1135,7 @@ static int orinoco_ioctl_set_mlme(struct net_device *dev,
1367 struct iw_request_info *info, 1135 struct iw_request_info *info,
1368 union iwreq_data *wrqu, char *extra) 1136 union iwreq_data *wrqu, char *extra)
1369{ 1137{
1370 struct orinoco_private *priv = netdev_priv(dev); 1138 struct orinoco_private *priv = ndev_priv(dev);
1371 hermes_t *hw = &priv->hw; 1139 hermes_t *hw = &priv->hw;
1372 struct iw_mlme *mlme = (struct iw_mlme *)extra; 1140 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1373 unsigned long flags; 1141 unsigned long flags;
@@ -1408,7 +1176,7 @@ static int orinoco_ioctl_getretry(struct net_device *dev,
1408 struct iw_param *rrq, 1176 struct iw_param *rrq,
1409 char *extra) 1177 char *extra)
1410{ 1178{
1411 struct orinoco_private *priv = netdev_priv(dev); 1179 struct orinoco_private *priv = ndev_priv(dev);
1412 hermes_t *hw = &priv->hw; 1180 hermes_t *hw = &priv->hw;
1413 int err = 0; 1181 int err = 0;
1414 u16 short_limit, long_limit, lifetime; 1182 u16 short_limit, long_limit, lifetime;
@@ -1462,7 +1230,7 @@ static int orinoco_ioctl_reset(struct net_device *dev,
1462 void *wrqu, 1230 void *wrqu,
1463 char *extra) 1231 char *extra)
1464{ 1232{
1465 struct orinoco_private *priv = netdev_priv(dev); 1233 struct orinoco_private *priv = ndev_priv(dev);
1466 1234
1467 if (!capable(CAP_NET_ADMIN)) 1235 if (!capable(CAP_NET_ADMIN))
1468 return -EPERM; 1236 return -EPERM;
@@ -1487,7 +1255,7 @@ static int orinoco_ioctl_setibssport(struct net_device *dev,
1487 char *extra) 1255 char *extra)
1488 1256
1489{ 1257{
1490 struct orinoco_private *priv = netdev_priv(dev); 1258 struct orinoco_private *priv = ndev_priv(dev);
1491 int val = *((int *) extra); 1259 int val = *((int *) extra);
1492 unsigned long flags; 1260 unsigned long flags;
1493 1261
@@ -1508,7 +1276,7 @@ static int orinoco_ioctl_getibssport(struct net_device *dev,
1508 void *wrqu, 1276 void *wrqu,
1509 char *extra) 1277 char *extra)
1510{ 1278{
1511 struct orinoco_private *priv = netdev_priv(dev); 1279 struct orinoco_private *priv = ndev_priv(dev);
1512 int *val = (int *) extra; 1280 int *val = (int *) extra;
1513 1281
1514 *val = priv->ibss_port; 1282 *val = priv->ibss_port;
@@ -1520,7 +1288,7 @@ static int orinoco_ioctl_setport3(struct net_device *dev,
1520 void *wrqu, 1288 void *wrqu,
1521 char *extra) 1289 char *extra)
1522{ 1290{
1523 struct orinoco_private *priv = netdev_priv(dev); 1291 struct orinoco_private *priv = ndev_priv(dev);
1524 int val = *((int *) extra); 1292 int val = *((int *) extra);
1525 int err = 0; 1293 int err = 0;
1526 unsigned long flags; 1294 unsigned long flags;
@@ -1566,7 +1334,7 @@ static int orinoco_ioctl_getport3(struct net_device *dev,
1566 void *wrqu, 1334 void *wrqu,
1567 char *extra) 1335 char *extra)
1568{ 1336{
1569 struct orinoco_private *priv = netdev_priv(dev); 1337 struct orinoco_private *priv = ndev_priv(dev);
1570 int *val = (int *) extra; 1338 int *val = (int *) extra;
1571 1339
1572 *val = priv->prefer_port3; 1340 *val = priv->prefer_port3;
@@ -1578,7 +1346,7 @@ static int orinoco_ioctl_setpreamble(struct net_device *dev,
1578 void *wrqu, 1346 void *wrqu,
1579 char *extra) 1347 char *extra)
1580{ 1348{
1581 struct orinoco_private *priv = netdev_priv(dev); 1349 struct orinoco_private *priv = ndev_priv(dev);
1582 unsigned long flags; 1350 unsigned long flags;
1583 int val; 1351 int val;
1584 1352
@@ -1610,7 +1378,7 @@ static int orinoco_ioctl_getpreamble(struct net_device *dev,
1610 void *wrqu, 1378 void *wrqu,
1611 char *extra) 1379 char *extra)
1612{ 1380{
1613 struct orinoco_private *priv = netdev_priv(dev); 1381 struct orinoco_private *priv = ndev_priv(dev);
1614 int *val = (int *) extra; 1382 int *val = (int *) extra;
1615 1383
1616 if (!priv->has_preamble) 1384 if (!priv->has_preamble)
@@ -1630,7 +1398,7 @@ static int orinoco_ioctl_getrid(struct net_device *dev,
1630 struct iw_point *data, 1398 struct iw_point *data,
1631 char *extra) 1399 char *extra)
1632{ 1400{
1633 struct orinoco_private *priv = netdev_priv(dev); 1401 struct orinoco_private *priv = ndev_priv(dev);
1634 hermes_t *hw = &priv->hw; 1402 hermes_t *hw = &priv->hw;
1635 int rid = data->flags; 1403 int rid = data->flags;
1636 u16 length; 1404 u16 length;
@@ -1661,519 +1429,6 @@ static int orinoco_ioctl_getrid(struct net_device *dev,
1661 return err; 1429 return err;
1662} 1430}
1663 1431
1664/* Trigger a scan (look for other cells in the vicinity) */
1665static int orinoco_ioctl_setscan(struct net_device *dev,
1666 struct iw_request_info *info,
1667 struct iw_point *srq,
1668 char *extra)
1669{
1670 struct orinoco_private *priv = netdev_priv(dev);
1671 hermes_t *hw = &priv->hw;
1672 struct iw_scan_req *si = (struct iw_scan_req *) extra;
1673 int err = 0;
1674 unsigned long flags;
1675
1676 /* Note : you may have realised that, as this is a SET operation,
1677 * this is privileged and therefore a normal user can't
1678 * perform scanning.
1679 * This is not an error, while the device perform scanning,
1680 * traffic doesn't flow, so it's a perfect DoS...
1681 * Jean II */
1682
1683 if (orinoco_lock(priv, &flags) != 0)
1684 return -EBUSY;
1685
1686 /* Scanning with port 0 disabled would fail */
1687 if (!netif_running(dev)) {
1688 err = -ENETDOWN;
1689 goto out;
1690 }
1691
1692 /* In monitor mode, the scan results are always empty.
1693 * Probe responses are passed to the driver as received
1694 * frames and could be processed in software. */
1695 if (priv->iw_mode == IW_MODE_MONITOR) {
1696 err = -EOPNOTSUPP;
1697 goto out;
1698 }
1699
1700 /* Note : because we don't lock out the irq handler, the way
1701 * we access scan variables in priv is critical.
1702 * o scan_inprogress : not touched by irq handler
1703 * o scan_mode : not touched by irq handler
1704 * Before modifying anything on those variables, please think hard !
1705 * Jean II */
1706
1707 /* Save flags */
1708 priv->scan_mode = srq->flags;
1709
1710 /* Always trigger scanning, even if it's in progress.
1711 * This way, if the info frame get lost, we will recover somewhat
1712 * gracefully - Jean II */
1713
1714 if (priv->has_hostscan) {
1715 switch (priv->firmware_type) {
1716 case FIRMWARE_TYPE_SYMBOL:
1717 err = hermes_write_wordrec(hw, USER_BAP,
1718 HERMES_RID_CNFHOSTSCAN_SYMBOL,
1719 HERMES_HOSTSCAN_SYMBOL_ONCE |
1720 HERMES_HOSTSCAN_SYMBOL_BCAST);
1721 break;
1722 case FIRMWARE_TYPE_INTERSIL: {
1723 __le16 req[3];
1724
1725 req[0] = cpu_to_le16(0x3fff); /* All channels */
1726 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
1727 req[2] = 0; /* Any ESSID */
1728 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1729 HERMES_RID_CNFHOSTSCAN, &req);
1730 }
1731 break;
1732 case FIRMWARE_TYPE_AGERE:
1733 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
1734 struct hermes_idstring idbuf;
1735 size_t len = min(sizeof(idbuf.val),
1736 (size_t) si->essid_len);
1737 idbuf.len = cpu_to_le16(len);
1738 memcpy(idbuf.val, si->essid, len);
1739
1740 err = hermes_write_ltv(hw, USER_BAP,
1741 HERMES_RID_CNFSCANSSID_AGERE,
1742 HERMES_BYTES_TO_RECLEN(len + 2),
1743 &idbuf);
1744 } else
1745 err = hermes_write_wordrec(hw, USER_BAP,
1746 HERMES_RID_CNFSCANSSID_AGERE,
1747 0); /* Any ESSID */
1748 if (err)
1749 break;
1750
1751 if (priv->has_ext_scan) {
1752 /* Clear scan results at the start of
1753 * an extended scan */
1754 orinoco_clear_scan_results(priv,
1755 msecs_to_jiffies(15000));
1756
1757 /* TODO: Is this available on older firmware?
1758 * Can we use it to scan specific channels
1759 * for IW_SCAN_THIS_FREQ? */
1760 err = hermes_write_wordrec(hw, USER_BAP,
1761 HERMES_RID_CNFSCANCHANNELS2GHZ,
1762 0x7FFF);
1763 if (err)
1764 goto out;
1765
1766 err = hermes_inquire(hw,
1767 HERMES_INQ_CHANNELINFO);
1768 } else
1769 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1770 break;
1771 }
1772 } else
1773 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1774
1775 /* One more client */
1776 if (!err)
1777 priv->scan_inprogress = 1;
1778
1779 out:
1780 orinoco_unlock(priv, &flags);
1781 return err;
1782}
1783
1784#define MAX_CUSTOM_LEN 64
1785
1786/* Translate scan data returned from the card to a card independant
1787 * format that the Wireless Tools will understand - Jean II */
1788static inline char *orinoco_translate_scan(struct net_device *dev,
1789 struct iw_request_info *info,
1790 char *current_ev,
1791 char *end_buf,
1792 union hermes_scan_info *bss,
1793 unsigned long last_scanned)
1794{
1795 struct orinoco_private *priv = netdev_priv(dev);
1796 u16 capabilities;
1797 u16 channel;
1798 struct iw_event iwe; /* Temporary buffer */
1799 char custom[MAX_CUSTOM_LEN];
1800
1801 memset(&iwe, 0, sizeof(iwe));
1802
1803 /* First entry *MUST* be the AP MAC address */
1804 iwe.cmd = SIOCGIWAP;
1805 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1806 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
1807 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1808 &iwe, IW_EV_ADDR_LEN);
1809
1810 /* Other entries will be displayed in the order we give them */
1811
1812 /* Add the ESSID */
1813 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
1814 if (iwe.u.data.length > 32)
1815 iwe.u.data.length = 32;
1816 iwe.cmd = SIOCGIWESSID;
1817 iwe.u.data.flags = 1;
1818 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1819 &iwe, bss->a.essid);
1820
1821 /* Add mode */
1822 iwe.cmd = SIOCGIWMODE;
1823 capabilities = le16_to_cpu(bss->a.capabilities);
1824 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
1825 if (capabilities & WLAN_CAPABILITY_ESS)
1826 iwe.u.mode = IW_MODE_MASTER;
1827 else
1828 iwe.u.mode = IW_MODE_ADHOC;
1829 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1830 &iwe, IW_EV_UINT_LEN);
1831 }
1832
1833 channel = bss->s.channel;
1834 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
1835 /* Add channel and frequency */
1836 iwe.cmd = SIOCGIWFREQ;
1837 iwe.u.freq.m = channel;
1838 iwe.u.freq.e = 0;
1839 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1840 &iwe, IW_EV_FREQ_LEN);
1841
1842 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
1843 iwe.u.freq.e = 1;
1844 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1845 &iwe, IW_EV_FREQ_LEN);
1846 }
1847
1848 /* Add quality statistics. level and noise in dB. No link quality */
1849 iwe.cmd = IWEVQUAL;
1850 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
1851 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
1852 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
1853 /* Wireless tools prior to 27.pre22 will show link quality
1854 * anyway, so we provide a reasonable value. */
1855 if (iwe.u.qual.level > iwe.u.qual.noise)
1856 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
1857 else
1858 iwe.u.qual.qual = 0;
1859 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1860 &iwe, IW_EV_QUAL_LEN);
1861
1862 /* Add encryption capability */
1863 iwe.cmd = SIOCGIWENCODE;
1864 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1865 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1866 else
1867 iwe.u.data.flags = IW_ENCODE_DISABLED;
1868 iwe.u.data.length = 0;
1869 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1870 &iwe, NULL);
1871
1872 /* Bit rate is not available in Lucent/Agere firmwares */
1873 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
1874 char *current_val = current_ev + iwe_stream_lcp_len(info);
1875 int i;
1876 int step;
1877
1878 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
1879 step = 2;
1880 else
1881 step = 1;
1882
1883 iwe.cmd = SIOCGIWRATE;
1884 /* Those two flags are ignored... */
1885 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1886 /* Max 10 values */
1887 for (i = 0; i < 10; i += step) {
1888 /* NULL terminated */
1889 if (bss->p.rates[i] == 0x0)
1890 break;
1891 /* Bit rate given in 500 kb/s units (+ 0x80) */
1892 iwe.u.bitrate.value =
1893 ((bss->p.rates[i] & 0x7f) * 500000);
1894 current_val = iwe_stream_add_value(info, current_ev,
1895 current_val,
1896 end_buf, &iwe,
1897 IW_EV_PARAM_LEN);
1898 }
1899 /* Check if we added any event */
1900 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
1901 current_ev = current_val;
1902 }
1903
1904 /* Beacon interval */
1905 iwe.cmd = IWEVCUSTOM;
1906 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
1907 "bcn_int=%d",
1908 le16_to_cpu(bss->a.beacon_interv));
1909 if (iwe.u.data.length)
1910 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1911 &iwe, custom);
1912
1913 /* Capabilites */
1914 iwe.cmd = IWEVCUSTOM;
1915 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
1916 "capab=0x%04x",
1917 capabilities);
1918 if (iwe.u.data.length)
1919 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1920 &iwe, custom);
1921
1922 /* Add EXTRA: Age to display seconds since last beacon/probe response
1923 * for given network. */
1924 iwe.cmd = IWEVCUSTOM;
1925 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
1926 " Last beacon: %dms ago",
1927 jiffies_to_msecs(jiffies - last_scanned));
1928 if (iwe.u.data.length)
1929 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1930 &iwe, custom);
1931
1932 return current_ev;
1933}
1934
1935static inline char *orinoco_translate_ext_scan(struct net_device *dev,
1936 struct iw_request_info *info,
1937 char *current_ev,
1938 char *end_buf,
1939 struct agere_ext_scan_info *bss,
1940 unsigned long last_scanned)
1941{
1942 u16 capabilities;
1943 u16 channel;
1944 struct iw_event iwe; /* Temporary buffer */
1945 char custom[MAX_CUSTOM_LEN];
1946 u8 *ie;
1947
1948 memset(&iwe, 0, sizeof(iwe));
1949
1950 /* First entry *MUST* be the AP MAC address */
1951 iwe.cmd = SIOCGIWAP;
1952 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1953 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
1954 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1955 &iwe, IW_EV_ADDR_LEN);
1956
1957 /* Other entries will be displayed in the order we give them */
1958
1959 /* Add the ESSID */
1960 ie = bss->data;
1961 iwe.u.data.length = ie[1];
1962 if (iwe.u.data.length) {
1963 if (iwe.u.data.length > 32)
1964 iwe.u.data.length = 32;
1965 iwe.cmd = SIOCGIWESSID;
1966 iwe.u.data.flags = 1;
1967 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1968 &iwe, &ie[2]);
1969 }
1970
1971 /* Add mode */
1972 capabilities = le16_to_cpu(bss->capabilities);
1973 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
1974 iwe.cmd = SIOCGIWMODE;
1975 if (capabilities & WLAN_CAPABILITY_ESS)
1976 iwe.u.mode = IW_MODE_MASTER;
1977 else
1978 iwe.u.mode = IW_MODE_ADHOC;
1979 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1980 &iwe, IW_EV_UINT_LEN);
1981 }
1982
1983 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
1984 channel = ie ? ie[2] : 0;
1985 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
1986 /* Add channel and frequency */
1987 iwe.cmd = SIOCGIWFREQ;
1988 iwe.u.freq.m = channel;
1989 iwe.u.freq.e = 0;
1990 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1991 &iwe, IW_EV_FREQ_LEN);
1992
1993 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
1994 iwe.u.freq.e = 1;
1995 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1996 &iwe, IW_EV_FREQ_LEN);
1997 }
1998
1999 /* Add quality statistics. level and noise in dB. No link quality */
2000 iwe.cmd = IWEVQUAL;
2001 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
2002 iwe.u.qual.level = bss->level - 0x95;
2003 iwe.u.qual.noise = bss->noise - 0x95;
2004 /* Wireless tools prior to 27.pre22 will show link quality
2005 * anyway, so we provide a reasonable value. */
2006 if (iwe.u.qual.level > iwe.u.qual.noise)
2007 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
2008 else
2009 iwe.u.qual.qual = 0;
2010 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
2011 &iwe, IW_EV_QUAL_LEN);
2012
2013 /* Add encryption capability */
2014 iwe.cmd = SIOCGIWENCODE;
2015 if (capabilities & WLAN_CAPABILITY_PRIVACY)
2016 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
2017 else
2018 iwe.u.data.flags = IW_ENCODE_DISABLED;
2019 iwe.u.data.length = 0;
2020 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2021 &iwe, NULL);
2022
2023 /* WPA IE */
2024 ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
2025 if (ie) {
2026 iwe.cmd = IWEVGENIE;
2027 iwe.u.data.length = ie[1] + 2;
2028 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2029 &iwe, ie);
2030 }
2031
2032 /* RSN IE */
2033 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
2034 if (ie) {
2035 iwe.cmd = IWEVGENIE;
2036 iwe.u.data.length = ie[1] + 2;
2037 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2038 &iwe, ie);
2039 }
2040
2041 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
2042 if (ie) {
2043 char *p = current_ev + iwe_stream_lcp_len(info);
2044 int i;
2045
2046 iwe.cmd = SIOCGIWRATE;
2047 /* Those two flags are ignored... */
2048 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
2049
2050 for (i = 2; i < (ie[1] + 2); i++) {
2051 iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
2052 p = iwe_stream_add_value(info, current_ev, p, end_buf,
2053 &iwe, IW_EV_PARAM_LEN);
2054 }
2055 /* Check if we added any event */
2056 if (p > (current_ev + iwe_stream_lcp_len(info)))
2057 current_ev = p;
2058 }
2059
2060 /* Timestamp */
2061 iwe.cmd = IWEVCUSTOM;
2062 iwe.u.data.length =
2063 snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
2064 (unsigned long long) le64_to_cpu(bss->timestamp));
2065 if (iwe.u.data.length)
2066 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2067 &iwe, custom);
2068
2069 /* Beacon interval */
2070 iwe.cmd = IWEVCUSTOM;
2071 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
2072 "bcn_int=%d",
2073 le16_to_cpu(bss->beacon_interval));
2074 if (iwe.u.data.length)
2075 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2076 &iwe, custom);
2077
2078 /* Capabilites */
2079 iwe.cmd = IWEVCUSTOM;
2080 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
2081 "capab=0x%04x",
2082 capabilities);
2083 if (iwe.u.data.length)
2084 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2085 &iwe, custom);
2086
2087 /* Add EXTRA: Age to display seconds since last beacon/probe response
2088 * for given network. */
2089 iwe.cmd = IWEVCUSTOM;
2090 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
2091 " Last beacon: %dms ago",
2092 jiffies_to_msecs(jiffies - last_scanned));
2093 if (iwe.u.data.length)
2094 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2095 &iwe, custom);
2096
2097 return current_ev;
2098}
2099
2100/* Return results of a scan */
2101static int orinoco_ioctl_getscan(struct net_device *dev,
2102 struct iw_request_info *info,
2103 struct iw_point *srq,
2104 char *extra)
2105{
2106 struct orinoco_private *priv = netdev_priv(dev);
2107 int err = 0;
2108 unsigned long flags;
2109 char *current_ev = extra;
2110
2111 if (orinoco_lock(priv, &flags) != 0)
2112 return -EBUSY;
2113
2114 if (priv->scan_inprogress) {
2115 /* Important note : we don't want to block the caller
2116 * until results are ready for various reasons.
2117 * First, managing wait queues is complex and racy.
2118 * Second, we grab some rtnetlink lock before comming
2119 * here (in dev_ioctl()).
2120 * Third, we generate an Wireless Event, so the
2121 * caller can wait itself on that - Jean II */
2122 err = -EAGAIN;
2123 goto out;
2124 }
2125
2126 if (priv->has_ext_scan) {
2127 struct xbss_element *bss;
2128
2129 list_for_each_entry(bss, &priv->bss_list, list) {
2130 /* Translate this entry to WE format */
2131 current_ev =
2132 orinoco_translate_ext_scan(dev, info,
2133 current_ev,
2134 extra + srq->length,
2135 &bss->bss,
2136 bss->last_scanned);
2137
2138 /* Check if there is space for one more entry */
2139 if ((extra + srq->length - current_ev)
2140 <= IW_EV_ADDR_LEN) {
2141 /* Ask user space to try again with a
2142 * bigger buffer */
2143 err = -E2BIG;
2144 goto out;
2145 }
2146 }
2147
2148 } else {
2149 struct bss_element *bss;
2150
2151 list_for_each_entry(bss, &priv->bss_list, list) {
2152 /* Translate this entry to WE format */
2153 current_ev = orinoco_translate_scan(dev, info,
2154 current_ev,
2155 extra + srq->length,
2156 &bss->bss,
2157 bss->last_scanned);
2158
2159 /* Check if there is space for one more entry */
2160 if ((extra + srq->length - current_ev)
2161 <= IW_EV_ADDR_LEN) {
2162 /* Ask user space to try again with a
2163 * bigger buffer */
2164 err = -E2BIG;
2165 goto out;
2166 }
2167 }
2168 }
2169
2170 srq->length = (current_ev - extra);
2171 srq->flags = (__u16) priv->scan_mode;
2172
2173out:
2174 orinoco_unlock(priv, &flags);
2175 return err;
2176}
2177 1432
2178/* Commit handler, called after set operations */ 1433/* Commit handler, called after set operations */
2179static int orinoco_ioctl_commit(struct net_device *dev, 1434static int orinoco_ioctl_commit(struct net_device *dev,
@@ -2181,50 +1436,17 @@ static int orinoco_ioctl_commit(struct net_device *dev,
2181 void *wrqu, 1436 void *wrqu,
2182 char *extra) 1437 char *extra)
2183{ 1438{
2184 struct orinoco_private *priv = netdev_priv(dev); 1439 struct orinoco_private *priv = ndev_priv(dev);
2185 struct hermes *hw = &priv->hw;
2186 unsigned long flags; 1440 unsigned long flags;
2187 int err = 0; 1441 int err = 0;
2188 1442
2189 if (!priv->open) 1443 if (!priv->open)
2190 return 0; 1444 return 0;
2191 1445
2192 if (priv->broken_disableport) {
2193 orinoco_reset(&priv->reset_work);
2194 return 0;
2195 }
2196
2197 if (orinoco_lock(priv, &flags) != 0) 1446 if (orinoco_lock(priv, &flags) != 0)
2198 return err; 1447 return err;
2199 1448
2200 err = hermes_disable_port(hw, 0); 1449 err = orinoco_commit(priv);
2201 if (err) {
2202 printk(KERN_WARNING "%s: Unable to disable port "
2203 "while reconfiguring card\n", dev->name);
2204 priv->broken_disableport = 1;
2205 goto out;
2206 }
2207
2208 err = __orinoco_program_rids(dev);
2209 if (err) {
2210 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
2211 dev->name);
2212 goto out;
2213 }
2214
2215 err = hermes_enable_port(hw, 0);
2216 if (err) {
2217 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
2218 dev->name);
2219 goto out;
2220 }
2221
2222 out:
2223 if (err) {
2224 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
2225 schedule_work(&priv->reset_work);
2226 err = 0;
2227 }
2228 1450
2229 orinoco_unlock(priv, &flags); 1451 orinoco_unlock(priv, &flags);
2230 return err; 1452 return err;
@@ -2258,26 +1480,24 @@ static const struct iw_priv_args orinoco_privtab[] = {
2258 [IW_IOCTL_IDX(id)] = (iw_handler) func 1480 [IW_IOCTL_IDX(id)] = (iw_handler) func
2259static const iw_handler orinoco_handler[] = { 1481static const iw_handler orinoco_handler[] = {
2260 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit), 1482 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
2261 STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname), 1483 STD_IW_HANDLER(SIOCGIWNAME, cfg80211_wext_giwname),
2262 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq), 1484 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
2263 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq), 1485 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
2264 STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode), 1486 STD_IW_HANDLER(SIOCSIWMODE, cfg80211_wext_siwmode),
2265 STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode), 1487 STD_IW_HANDLER(SIOCGIWMODE, cfg80211_wext_giwmode),
2266 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens), 1488 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
2267 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens), 1489 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
2268 STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange), 1490 STD_IW_HANDLER(SIOCGIWRANGE, cfg80211_wext_giwrange),
2269 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy), 1491 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
2270 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy), 1492 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
2271 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy), 1493 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
2272 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy), 1494 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
2273 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap), 1495 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
2274 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap), 1496 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
2275 STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan), 1497 STD_IW_HANDLER(SIOCSIWSCAN, cfg80211_wext_siwscan),
2276 STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan), 1498 STD_IW_HANDLER(SIOCGIWSCAN, cfg80211_wext_giwscan),
2277 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid), 1499 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
2278 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid), 1500 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
2279 STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
2280 STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
2281 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate), 1501 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
2282 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate), 1502 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
2283 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts), 1503 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
diff --git a/drivers/net/wireless/p54/Makefile b/drivers/net/wireless/p54/Makefile
index c2050dee6293..b542e68f1781 100644
--- a/drivers/net/wireless/p54/Makefile
+++ b/drivers/net/wireless/p54/Makefile
@@ -1,3 +1,6 @@
1p54common-objs := eeprom.o fwio.o txrx.o main.o
2p54common-$(CONFIG_P54_LEDS) += led.o
3
1obj-$(CONFIG_P54_COMMON) += p54common.o 4obj-$(CONFIG_P54_COMMON) += p54common.o
2obj-$(CONFIG_P54_USB) += p54usb.o 5obj-$(CONFIG_P54_USB) += p54usb.o
3obj-$(CONFIG_P54_PCI) += p54pci.o 6obj-$(CONFIG_P54_PCI) += p54pci.o
diff --git a/drivers/net/wireless/p54/eeprom.c b/drivers/net/wireless/p54/eeprom.c
new file mode 100644
index 000000000000..a2a044ef1012
--- /dev/null
+++ b/drivers/net/wireless/p54/eeprom.c
@@ -0,0 +1,564 @@
1/*
2 * EEPROM parser code for mac80211 Prism54 drivers
3 *
4 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
5 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 *
8 * Based on:
9 * - the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
11 * - stlc45xx driver
12 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/init.h>
20#include <linux/firmware.h>
21#include <linux/etherdevice.h>
22
23#include <net/mac80211.h>
24
25#include "p54.h"
26#include "eeprom.h"
27#include "lmac.h"
28
29static struct ieee80211_rate p54_bgrates[] = {
30 { .bitrate = 10, .hw_value = 0, },
31 { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
32 { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
33 { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
34 { .bitrate = 60, .hw_value = 4, },
35 { .bitrate = 90, .hw_value = 5, },
36 { .bitrate = 120, .hw_value = 6, },
37 { .bitrate = 180, .hw_value = 7, },
38 { .bitrate = 240, .hw_value = 8, },
39 { .bitrate = 360, .hw_value = 9, },
40 { .bitrate = 480, .hw_value = 10, },
41 { .bitrate = 540, .hw_value = 11, },
42};
43
44static struct ieee80211_channel p54_bgchannels[] = {
45 { .center_freq = 2412, .hw_value = 1, },
46 { .center_freq = 2417, .hw_value = 2, },
47 { .center_freq = 2422, .hw_value = 3, },
48 { .center_freq = 2427, .hw_value = 4, },
49 { .center_freq = 2432, .hw_value = 5, },
50 { .center_freq = 2437, .hw_value = 6, },
51 { .center_freq = 2442, .hw_value = 7, },
52 { .center_freq = 2447, .hw_value = 8, },
53 { .center_freq = 2452, .hw_value = 9, },
54 { .center_freq = 2457, .hw_value = 10, },
55 { .center_freq = 2462, .hw_value = 11, },
56 { .center_freq = 2467, .hw_value = 12, },
57 { .center_freq = 2472, .hw_value = 13, },
58 { .center_freq = 2484, .hw_value = 14, },
59};
60
61static struct ieee80211_supported_band band_2GHz = {
62 .channels = p54_bgchannels,
63 .n_channels = ARRAY_SIZE(p54_bgchannels),
64 .bitrates = p54_bgrates,
65 .n_bitrates = ARRAY_SIZE(p54_bgrates),
66};
67
68static struct ieee80211_rate p54_arates[] = {
69 { .bitrate = 60, .hw_value = 4, },
70 { .bitrate = 90, .hw_value = 5, },
71 { .bitrate = 120, .hw_value = 6, },
72 { .bitrate = 180, .hw_value = 7, },
73 { .bitrate = 240, .hw_value = 8, },
74 { .bitrate = 360, .hw_value = 9, },
75 { .bitrate = 480, .hw_value = 10, },
76 { .bitrate = 540, .hw_value = 11, },
77};
78
79static struct ieee80211_channel p54_achannels[] = {
80 { .center_freq = 4920 },
81 { .center_freq = 4940 },
82 { .center_freq = 4960 },
83 { .center_freq = 4980 },
84 { .center_freq = 5040 },
85 { .center_freq = 5060 },
86 { .center_freq = 5080 },
87 { .center_freq = 5170 },
88 { .center_freq = 5180 },
89 { .center_freq = 5190 },
90 { .center_freq = 5200 },
91 { .center_freq = 5210 },
92 { .center_freq = 5220 },
93 { .center_freq = 5230 },
94 { .center_freq = 5240 },
95 { .center_freq = 5260 },
96 { .center_freq = 5280 },
97 { .center_freq = 5300 },
98 { .center_freq = 5320 },
99 { .center_freq = 5500 },
100 { .center_freq = 5520 },
101 { .center_freq = 5540 },
102 { .center_freq = 5560 },
103 { .center_freq = 5580 },
104 { .center_freq = 5600 },
105 { .center_freq = 5620 },
106 { .center_freq = 5640 },
107 { .center_freq = 5660 },
108 { .center_freq = 5680 },
109 { .center_freq = 5700 },
110 { .center_freq = 5745 },
111 { .center_freq = 5765 },
112 { .center_freq = 5785 },
113 { .center_freq = 5805 },
114 { .center_freq = 5825 },
115};
116
117static struct ieee80211_supported_band band_5GHz = {
118 .channels = p54_achannels,
119 .n_channels = ARRAY_SIZE(p54_achannels),
120 .bitrates = p54_arates,
121 .n_bitrates = ARRAY_SIZE(p54_arates),
122};
123
124static int p54_convert_rev0(struct ieee80211_hw *dev,
125 struct pda_pa_curve_data *curve_data)
126{
127 struct p54_common *priv = dev->priv;
128 struct p54_pa_curve_data_sample *dst;
129 struct pda_pa_curve_data_sample_rev0 *src;
130 size_t cd_len = sizeof(*curve_data) +
131 (curve_data->points_per_channel*sizeof(*dst) + 2) *
132 curve_data->channels;
133 unsigned int i, j;
134 void *source, *target;
135
136 priv->curve_data = kmalloc(sizeof(*priv->curve_data) + cd_len,
137 GFP_KERNEL);
138 if (!priv->curve_data)
139 return -ENOMEM;
140
141 priv->curve_data->entries = curve_data->channels;
142 priv->curve_data->entry_size = sizeof(__le16) +
143 sizeof(*dst) * curve_data->points_per_channel;
144 priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data);
145 priv->curve_data->len = cd_len;
146 memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data));
147 source = curve_data->data;
148 target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data;
149 for (i = 0; i < curve_data->channels; i++) {
150 __le16 *freq = source;
151 source += sizeof(__le16);
152 *((__le16 *)target) = *freq;
153 target += sizeof(__le16);
154 for (j = 0; j < curve_data->points_per_channel; j++) {
155 dst = target;
156 src = source;
157
158 dst->rf_power = src->rf_power;
159 dst->pa_detector = src->pa_detector;
160 dst->data_64qam = src->pcv;
161 /* "invent" the points for the other modulations */
162#define SUB(x, y) (u8)(((x) - (y)) > (x) ? 0 : (x) - (y))
163 dst->data_16qam = SUB(src->pcv, 12);
164 dst->data_qpsk = SUB(dst->data_16qam, 12);
165 dst->data_bpsk = SUB(dst->data_qpsk, 12);
166 dst->data_barker = SUB(dst->data_bpsk, 14);
167#undef SUB
168 target += sizeof(*dst);
169 source += sizeof(*src);
170 }
171 }
172
173 return 0;
174}
175
176static int p54_convert_rev1(struct ieee80211_hw *dev,
177 struct pda_pa_curve_data *curve_data)
178{
179 struct p54_common *priv = dev->priv;
180 struct p54_pa_curve_data_sample *dst;
181 struct pda_pa_curve_data_sample_rev1 *src;
182 size_t cd_len = sizeof(*curve_data) +
183 (curve_data->points_per_channel*sizeof(*dst) + 2) *
184 curve_data->channels;
185 unsigned int i, j;
186 void *source, *target;
187
188 priv->curve_data = kzalloc(cd_len + sizeof(*priv->curve_data),
189 GFP_KERNEL);
190 if (!priv->curve_data)
191 return -ENOMEM;
192
193 priv->curve_data->entries = curve_data->channels;
194 priv->curve_data->entry_size = sizeof(__le16) +
195 sizeof(*dst) * curve_data->points_per_channel;
196 priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data);
197 priv->curve_data->len = cd_len;
198 memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data));
199 source = curve_data->data;
200 target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data;
201 for (i = 0; i < curve_data->channels; i++) {
202 __le16 *freq = source;
203 source += sizeof(__le16);
204 *((__le16 *)target) = *freq;
205 target += sizeof(__le16);
206 for (j = 0; j < curve_data->points_per_channel; j++) {
207 memcpy(target, source, sizeof(*src));
208
209 target += sizeof(*dst);
210 source += sizeof(*src);
211 }
212 source++;
213 }
214
215 return 0;
216}
217
218static const char *p54_rf_chips[] = { "INVALID-0", "Duette3", "Duette2",
219 "Frisbee", "Xbow", "Longbow", "INVALID-6", "INVALID-7" };
220
221static void p54_parse_rssical(struct ieee80211_hw *dev, void *data, int len,
222 u16 type)
223{
224 struct p54_common *priv = dev->priv;
225 int offset = (type == PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED) ? 2 : 0;
226 int entry_size = sizeof(struct pda_rssi_cal_entry) + offset;
227 int num_entries = (type == PDR_RSSI_LINEAR_APPROXIMATION) ? 1 : 2;
228 int i;
229
230 if (len != (entry_size * num_entries)) {
231 printk(KERN_ERR "%s: unknown rssi calibration data packing "
232 " type:(%x) len:%d.\n",
233 wiphy_name(dev->wiphy), type, len);
234
235 print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE,
236 data, len);
237
238 printk(KERN_ERR "%s: please report this issue.\n",
239 wiphy_name(dev->wiphy));
240 return;
241 }
242
243 for (i = 0; i < num_entries; i++) {
244 struct pda_rssi_cal_entry *cal = data +
245 (offset + i * entry_size);
246 priv->rssical_db[i].mul = (s16) le16_to_cpu(cal->mul);
247 priv->rssical_db[i].add = (s16) le16_to_cpu(cal->add);
248 }
249}
250
251static void p54_parse_default_country(struct ieee80211_hw *dev,
252 void *data, int len)
253{
254 struct pda_country *country;
255
256 if (len != sizeof(*country)) {
257 printk(KERN_ERR "%s: found possible invalid default country "
258 "eeprom entry. (entry size: %d)\n",
259 wiphy_name(dev->wiphy), len);
260
261 print_hex_dump_bytes("country:", DUMP_PREFIX_NONE,
262 data, len);
263
264 printk(KERN_ERR "%s: please report this issue.\n",
265 wiphy_name(dev->wiphy));
266 return;
267 }
268
269 country = (struct pda_country *) data;
270 if (country->flags == PDR_COUNTRY_CERT_CODE_PSEUDO)
271 regulatory_hint(dev->wiphy, country->alpha2);
272 else {
273 /* TODO:
274 * write a shared/common function that converts
275 * "Regulatory domain codes" (802.11-2007 14.8.2.2)
276 * into ISO/IEC 3166-1 alpha2 for regulatory_hint.
277 */
278 }
279}
280
281static int p54_convert_output_limits(struct ieee80211_hw *dev,
282 u8 *data, size_t len)
283{
284 struct p54_common *priv = dev->priv;
285
286 if (len < 2)
287 return -EINVAL;
288
289 if (data[0] != 0) {
290 printk(KERN_ERR "%s: unknown output power db revision:%x\n",
291 wiphy_name(dev->wiphy), data[0]);
292 return -EINVAL;
293 }
294
295 if (2 + data[1] * sizeof(struct pda_channel_output_limit) > len)
296 return -EINVAL;
297
298 priv->output_limit = kmalloc(data[1] *
299 sizeof(struct pda_channel_output_limit) +
300 sizeof(*priv->output_limit), GFP_KERNEL);
301
302 if (!priv->output_limit)
303 return -ENOMEM;
304
305 priv->output_limit->offset = 0;
306 priv->output_limit->entries = data[1];
307 priv->output_limit->entry_size =
308 sizeof(struct pda_channel_output_limit);
309 priv->output_limit->len = priv->output_limit->entry_size *
310 priv->output_limit->entries +
311 priv->output_limit->offset;
312
313 memcpy(priv->output_limit->data, &data[2],
314 data[1] * sizeof(struct pda_channel_output_limit));
315
316 return 0;
317}
318
319static struct p54_cal_database *p54_convert_db(struct pda_custom_wrapper *src,
320 size_t total_len)
321{
322 struct p54_cal_database *dst;
323 size_t payload_len, entries, entry_size, offset;
324
325 payload_len = le16_to_cpu(src->len);
326 entries = le16_to_cpu(src->entries);
327 entry_size = le16_to_cpu(src->entry_size);
328 offset = le16_to_cpu(src->offset);
329 if (((entries * entry_size + offset) != payload_len) ||
330 (payload_len + sizeof(*src) != total_len))
331 return NULL;
332
333 dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL);
334 if (!dst)
335 return NULL;
336
337 dst->entries = entries;
338 dst->entry_size = entry_size;
339 dst->offset = offset;
340 dst->len = payload_len;
341
342 memcpy(dst->data, src->data, payload_len);
343 return dst;
344}
345
346int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
347{
348 struct p54_common *priv = dev->priv;
349 struct eeprom_pda_wrap *wrap = NULL;
350 struct pda_entry *entry;
351 unsigned int data_len, entry_len;
352 void *tmp;
353 int err;
354 u8 *end = (u8 *)eeprom + len;
355 u16 synth = 0;
356
357 wrap = (struct eeprom_pda_wrap *) eeprom;
358 entry = (void *)wrap->data + le16_to_cpu(wrap->len);
359
360 /* verify that at least the entry length/code fits */
361 while ((u8 *)entry <= end - sizeof(*entry)) {
362 entry_len = le16_to_cpu(entry->len);
363 data_len = ((entry_len - 1) << 1);
364
365 /* abort if entry exceeds whole structure */
366 if ((u8 *)entry + sizeof(*entry) + data_len > end)
367 break;
368
369 switch (le16_to_cpu(entry->code)) {
370 case PDR_MAC_ADDRESS:
371 if (data_len != ETH_ALEN)
372 break;
373 SET_IEEE80211_PERM_ADDR(dev, entry->data);
374 break;
375 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS:
376 if (priv->output_limit)
377 break;
378 err = p54_convert_output_limits(dev, entry->data,
379 data_len);
380 if (err)
381 goto err;
382 break;
383 case PDR_PRISM_PA_CAL_CURVE_DATA: {
384 struct pda_pa_curve_data *curve_data =
385 (struct pda_pa_curve_data *)entry->data;
386 if (data_len < sizeof(*curve_data)) {
387 err = -EINVAL;
388 goto err;
389 }
390
391 switch (curve_data->cal_method_rev) {
392 case 0:
393 err = p54_convert_rev0(dev, curve_data);
394 break;
395 case 1:
396 err = p54_convert_rev1(dev, curve_data);
397 break;
398 default:
399 printk(KERN_ERR "%s: unknown curve data "
400 "revision %d\n",
401 wiphy_name(dev->wiphy),
402 curve_data->cal_method_rev);
403 err = -ENODEV;
404 break;
405 }
406 if (err)
407 goto err;
408 }
409 break;
410 case PDR_PRISM_ZIF_TX_IQ_CALIBRATION:
411 priv->iq_autocal = kmalloc(data_len, GFP_KERNEL);
412 if (!priv->iq_autocal) {
413 err = -ENOMEM;
414 goto err;
415 }
416
417 memcpy(priv->iq_autocal, entry->data, data_len);
418 priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry);
419 break;
420 case PDR_DEFAULT_COUNTRY:
421 p54_parse_default_country(dev, entry->data, data_len);
422 break;
423 case PDR_INTERFACE_LIST:
424 tmp = entry->data;
425 while ((u8 *)tmp < entry->data + data_len) {
426 struct exp_if *exp_if = tmp;
427 if (exp_if->if_id == cpu_to_le16(IF_ID_ISL39000))
428 synth = le16_to_cpu(exp_if->variant);
429 tmp += sizeof(*exp_if);
430 }
431 break;
432 case PDR_HARDWARE_PLATFORM_COMPONENT_ID:
433 if (data_len < 2)
434 break;
435 priv->version = *(u8 *)(entry->data + 1);
436 break;
437 case PDR_RSSI_LINEAR_APPROXIMATION:
438 case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
439 case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED:
440 p54_parse_rssical(dev, entry->data, data_len,
441 le16_to_cpu(entry->code));
442 break;
443 case PDR_RSSI_LINEAR_APPROXIMATION_CUSTOM: {
444 __le16 *src = (void *) entry->data;
445 s16 *dst = (void *) &priv->rssical_db;
446 int i;
447
448 if (data_len != sizeof(priv->rssical_db)) {
449 err = -EINVAL;
450 goto err;
451 }
452 for (i = 0; i < sizeof(priv->rssical_db) /
453 sizeof(*src); i++)
454 *(dst++) = (s16) le16_to_cpu(*(src++));
455 }
456 break;
457 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM: {
458 struct pda_custom_wrapper *pda = (void *) entry->data;
459 if (priv->output_limit || data_len < sizeof(*pda))
460 break;
461 priv->output_limit = p54_convert_db(pda, data_len);
462 }
463 break;
464 case PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM: {
465 struct pda_custom_wrapper *pda = (void *) entry->data;
466 if (priv->curve_data || data_len < sizeof(*pda))
467 break;
468 priv->curve_data = p54_convert_db(pda, data_len);
469 }
470 break;
471 case PDR_END:
472 /* make it overrun */
473 entry_len = len;
474 break;
475 default:
476 break;
477 }
478
479 entry = (void *)entry + (entry_len + 1)*2;
480 }
481
482 if (!synth || !priv->iq_autocal || !priv->output_limit ||
483 !priv->curve_data) {
484 printk(KERN_ERR "%s: not all required entries found in eeprom!\n",
485 wiphy_name(dev->wiphy));
486 err = -EINVAL;
487 goto err;
488 }
489
490 priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK;
491 if (priv->rxhw == PDR_SYNTH_FRONTEND_XBOW)
492 p54_init_xbow_synth(priv);
493 if (!(synth & PDR_SYNTH_24_GHZ_DISABLED))
494 dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz;
495 if (!(synth & PDR_SYNTH_5_GHZ_DISABLED))
496 dev->wiphy->bands[IEEE80211_BAND_5GHZ] = &band_5GHz;
497 if ((synth & PDR_SYNTH_RX_DIV_MASK) == PDR_SYNTH_RX_DIV_SUPPORTED)
498 priv->rx_diversity_mask = 3;
499 if ((synth & PDR_SYNTH_TX_DIV_MASK) == PDR_SYNTH_TX_DIV_SUPPORTED)
500 priv->tx_diversity_mask = 3;
501
502 if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
503 u8 perm_addr[ETH_ALEN];
504
505 printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n",
506 wiphy_name(dev->wiphy));
507 random_ether_addr(perm_addr);
508 SET_IEEE80211_PERM_ADDR(dev, perm_addr);
509 }
510
511 printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n",
512 wiphy_name(dev->wiphy), dev->wiphy->perm_addr, priv->version,
513 p54_rf_chips[priv->rxhw]);
514
515 return 0;
516
517err:
518 kfree(priv->iq_autocal);
519 kfree(priv->output_limit);
520 kfree(priv->curve_data);
521 priv->iq_autocal = NULL;
522 priv->output_limit = NULL;
523 priv->curve_data = NULL;
524
525 printk(KERN_ERR "%s: eeprom parse failed!\n",
526 wiphy_name(dev->wiphy));
527 return err;
528}
529EXPORT_SYMBOL_GPL(p54_parse_eeprom);
530
531int p54_read_eeprom(struct ieee80211_hw *dev)
532{
533 struct p54_common *priv = dev->priv;
534 size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize;
535 int ret = -ENOMEM;
536 void *eeprom = NULL;
537
538 maxblocksize = EEPROM_READBACK_LEN;
539 if (priv->fw_var >= 0x509)
540 maxblocksize -= 0xc;
541 else
542 maxblocksize -= 0x4;
543
544 eeprom = kzalloc(eeprom_size, GFP_KERNEL);
545 if (unlikely(!eeprom))
546 goto free;
547
548 while (eeprom_size) {
549 blocksize = min(eeprom_size, maxblocksize);
550 ret = p54_download_eeprom(priv, (void *) (eeprom + offset),
551 offset, blocksize);
552 if (unlikely(ret))
553 goto free;
554
555 offset += blocksize;
556 eeprom_size -= blocksize;
557 }
558
559 ret = p54_parse_eeprom(dev, eeprom, offset);
560free:
561 kfree(eeprom);
562 return ret;
563}
564EXPORT_SYMBOL_GPL(p54_read_eeprom);
diff --git a/drivers/net/wireless/p54/eeprom.h b/drivers/net/wireless/p54/eeprom.h
new file mode 100644
index 000000000000..9051aef11249
--- /dev/null
+++ b/drivers/net/wireless/p54/eeprom.h
@@ -0,0 +1,226 @@
1/*
2 * eeprom specific definitions for mac80211 Prism54 drivers
3 *
4 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
5 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
6 *
7 * Based on:
8 * - the islsm (softmac prism54) driver, which is:
9 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
10 *
11 * - LMAC API interface header file for STLC4560 (lmac_longbow.h)
12 * Copyright (C) 2007 Conexant Systems, Inc.
13 *
14 * - islmvc driver
15 * Copyright (C) 2001 Intersil Americas Inc.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
20 */
21
22#ifndef EEPROM_H
23#define EEPROM_H
24
25/* PDA defines are Copyright (C) 2005 Nokia Corporation (taken from islsm_pda.h) */
26
27struct pda_entry {
28 __le16 len; /* includes both code and data */
29 __le16 code;
30 u8 data[0];
31} __packed;
32
33struct eeprom_pda_wrap {
34 __le32 magic;
35 __le16 pad;
36 __le16 len;
37 __le32 arm_opcode;
38 u8 data[0];
39} __packed;
40
41struct p54_iq_autocal_entry {
42 __le16 iq_param[4];
43} __packed;
44
45struct pda_iq_autocal_entry {
46 __le16 freq;
47 struct p54_iq_autocal_entry params;
48} __packed;
49
50struct pda_channel_output_limit {
51 __le16 freq;
52 u8 val_bpsk;
53 u8 val_qpsk;
54 u8 val_16qam;
55 u8 val_64qam;
56 u8 rate_set_mask;
57 u8 rate_set_size;
58} __packed;
59
60struct pda_pa_curve_data_sample_rev0 {
61 u8 rf_power;
62 u8 pa_detector;
63 u8 pcv;
64} __packed;
65
66struct pda_pa_curve_data_sample_rev1 {
67 u8 rf_power;
68 u8 pa_detector;
69 u8 data_barker;
70 u8 data_bpsk;
71 u8 data_qpsk;
72 u8 data_16qam;
73 u8 data_64qam;
74} __packed;
75
76struct pda_pa_curve_data {
77 u8 cal_method_rev;
78 u8 channels;
79 u8 points_per_channel;
80 u8 padding;
81 u8 data[0];
82} __packed;
83
84struct pda_rssi_cal_entry {
85 __le16 mul;
86 __le16 add;
87} __packed;
88
89struct pda_country {
90 u8 regdomain;
91 u8 alpha2[2];
92 u8 flags;
93} __packed;
94
95struct pda_antenna_gain {
96 struct {
97 u8 gain_5GHz; /* 0.25 dBi units */
98 u8 gain_2GHz; /* 0.25 dBi units */
99 } __packed antenna[0];
100} __packed;
101
102struct pda_custom_wrapper {
103 __le16 entries;
104 __le16 entry_size;
105 __le16 offset;
106 __le16 len;
107 u8 data[0];
108} __packed;
109
110/*
111 * this defines the PDR codes used to build PDAs as defined in document
112 * number 553155. The current implementation mirrors version 1.1 of the
113 * document and lists only PDRs supported by the ARM platform.
114 */
115
116/* common and choice range (0x0000 - 0x0fff) */
117#define PDR_END 0x0000
118#define PDR_MANUFACTURING_PART_NUMBER 0x0001
119#define PDR_PDA_VERSION 0x0002
120#define PDR_NIC_SERIAL_NUMBER 0x0003
121#define PDR_NIC_RAM_SIZE 0x0005
122#define PDR_RFMODEM_SUP_RANGE 0x0006
123#define PDR_PRISM_MAC_SUP_RANGE 0x0007
124#define PDR_NIC_ID 0x0008
125
126#define PDR_MAC_ADDRESS 0x0101
127#define PDR_REGULATORY_DOMAIN_LIST 0x0103 /* obsolete */
128#define PDR_ALLOWED_CHAN_SET 0x0104
129#define PDR_DEFAULT_CHAN 0x0105
130#define PDR_TEMPERATURE_TYPE 0x0107
131
132#define PDR_IFR_SETTING 0x0200
133#define PDR_RFR_SETTING 0x0201
134#define PDR_3861_BASELINE_REG_SETTINGS 0x0202
135#define PDR_3861_SHADOW_REG_SETTINGS 0x0203
136#define PDR_3861_IFRF_REG_SETTINGS 0x0204
137
138#define PDR_3861_CHAN_CALIB_SET_POINTS 0x0300
139#define PDR_3861_CHAN_CALIB_INTEGRATOR 0x0301
140
141#define PDR_3842_PRISM_II_NIC_CONFIG 0x0400
142#define PDR_PRISM_USB_ID 0x0401
143#define PDR_PRISM_PCI_ID 0x0402
144#define PDR_PRISM_PCI_IF_CONFIG 0x0403
145#define PDR_PRISM_PCI_PM_CONFIG 0x0404
146
147#define PDR_3861_MF_TEST_CHAN_SET_POINTS 0x0900
148#define PDR_3861_MF_TEST_CHAN_INTEGRATORS 0x0901
149
150/* ARM range (0x1000 - 0x1fff) */
151#define PDR_COUNTRY_INFORMATION 0x1000 /* obsolete */
152#define PDR_INTERFACE_LIST 0x1001
153#define PDR_HARDWARE_PLATFORM_COMPONENT_ID 0x1002
154#define PDR_OEM_NAME 0x1003
155#define PDR_PRODUCT_NAME 0x1004
156#define PDR_UTF8_OEM_NAME 0x1005
157#define PDR_UTF8_PRODUCT_NAME 0x1006
158#define PDR_COUNTRY_LIST 0x1007
159#define PDR_DEFAULT_COUNTRY 0x1008
160
161#define PDR_ANTENNA_GAIN 0x1100
162
163#define PDR_PRISM_INDIGO_PA_CALIBRATION_DATA 0x1901
164#define PDR_RSSI_LINEAR_APPROXIMATION 0x1902
165#define PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS 0x1903
166#define PDR_PRISM_PA_CAL_CURVE_DATA 0x1904
167#define PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND 0x1905
168#define PDR_PRISM_ZIF_TX_IQ_CALIBRATION 0x1906
169#define PDR_REGULATORY_POWER_LIMITS 0x1907
170#define PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED 0x1908
171#define PDR_RADIATED_TRANSMISSION_CORRECTION 0x1909
172#define PDR_PRISM_TX_IQ_CALIBRATION 0x190a
173
174/* reserved range (0x2000 - 0x7fff) */
175
176/* customer range (0x8000 - 0xffff) */
177#define PDR_BASEBAND_REGISTERS 0x8000
178#define PDR_PER_CHANNEL_BASEBAND_REGISTERS 0x8001
179
180/* used by our modificated eeprom image */
181#define PDR_RSSI_LINEAR_APPROXIMATION_CUSTOM 0xDEAD
182#define PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM 0xBEEF
183#define PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM 0xB05D
184
185/* Interface Definitions */
186#define PDR_INTERFACE_ROLE_SERVER 0x0000
187#define PDR_INTERFACE_ROLE_CLIENT 0x0001
188
189/* PDR definitions for default country & country list */
190#define PDR_COUNTRY_CERT_CODE 0x80
191#define PDR_COUNTRY_CERT_CODE_REAL 0x00
192#define PDR_COUNTRY_CERT_CODE_PSEUDO 0x80
193#define PDR_COUNTRY_CERT_BAND 0x40
194#define PDR_COUNTRY_CERT_BAND_2GHZ 0x00
195#define PDR_COUNTRY_CERT_BAND_5GHZ 0x40
196#define PDR_COUNTRY_CERT_IODOOR 0x30
197#define PDR_COUNTRY_CERT_IODOOR_BOTH 0x00
198#define PDR_COUNTRY_CERT_IODOOR_INDOOR 0x20
199#define PDR_COUNTRY_CERT_IODOOR_OUTDOOR 0x30
200#define PDR_COUNTRY_CERT_INDEX 0x0f
201
202/* Specific LMAC FW/HW variant definitions */
203#define PDR_SYNTH_FRONTEND_MASK 0x0007
204#define PDR_SYNTH_FRONTEND_DUETTE3 0x0001
205#define PDR_SYNTH_FRONTEND_DUETTE2 0x0002
206#define PDR_SYNTH_FRONTEND_FRISBEE 0x0003
207#define PDR_SYNTH_FRONTEND_XBOW 0x0004
208#define PDR_SYNTH_FRONTEND_LONGBOW 0x0005
209#define PDR_SYNTH_IQ_CAL_MASK 0x0018
210#define PDR_SYNTH_IQ_CAL_PA_DETECTOR 0x0000
211#define PDR_SYNTH_IQ_CAL_DISABLED 0x0008
212#define PDR_SYNTH_IQ_CAL_ZIF 0x0010
213#define PDR_SYNTH_FAA_SWITCH_MASK 0x0020
214#define PDR_SYNTH_FAA_SWITCH_ENABLED 0x0020
215#define PDR_SYNTH_24_GHZ_MASK 0x0040
216#define PDR_SYNTH_24_GHZ_DISABLED 0x0040
217#define PDR_SYNTH_5_GHZ_MASK 0x0080
218#define PDR_SYNTH_5_GHZ_DISABLED 0x0080
219#define PDR_SYNTH_RX_DIV_MASK 0x0100
220#define PDR_SYNTH_RX_DIV_SUPPORTED 0x0100
221#define PDR_SYNTH_TX_DIV_MASK 0x0200
222#define PDR_SYNTH_TX_DIV_SUPPORTED 0x0200
223#define PDR_SYNTH_ASM_MASK 0x0400
224#define PDR_SYNTH_ASM_XSWON 0x0400
225
226#endif /* EEPROM_H */
diff --git a/drivers/net/wireless/p54/fwio.c b/drivers/net/wireless/p54/fwio.c
new file mode 100644
index 000000000000..dc4f3f5ee0c8
--- /dev/null
+++ b/drivers/net/wireless/p54/fwio.c
@@ -0,0 +1,698 @@
1/*
2 * Firmware I/O code for mac80211 Prism54 drivers
3 *
4 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
5 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 *
8 * Based on:
9 * - the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
11 * - stlc45xx driver
12 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/init.h>
20#include <linux/firmware.h>
21#include <linux/etherdevice.h>
22
23#include <net/mac80211.h>
24
25#include "p54.h"
26#include "eeprom.h"
27#include "lmac.h"
28
29int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
30{
31 struct p54_common *priv = dev->priv;
32 struct exp_if *exp_if;
33 struct bootrec *bootrec;
34 u32 *data = (u32 *)fw->data;
35 u32 *end_data = (u32 *)fw->data + (fw->size >> 2);
36 u8 *fw_version = NULL;
37 size_t len;
38 int i;
39 int maxlen;
40
41 if (priv->rx_start)
42 return 0;
43
44 while (data < end_data && *data)
45 data++;
46
47 while (data < end_data && !*data)
48 data++;
49
50 bootrec = (struct bootrec *) data;
51
52 while (bootrec->data <= end_data && (bootrec->data +
53 (len = le32_to_cpu(bootrec->len))) <= end_data) {
54 u32 code = le32_to_cpu(bootrec->code);
55 switch (code) {
56 case BR_CODE_COMPONENT_ID:
57 priv->fw_interface = be32_to_cpup((__be32 *)
58 bootrec->data);
59 switch (priv->fw_interface) {
60 case FW_LM86:
61 case FW_LM20:
62 case FW_LM87: {
63 char *iftype = (char *)bootrec->data;
64 printk(KERN_INFO "%s: p54 detected a LM%c%c "
65 "firmware\n",
66 wiphy_name(priv->hw->wiphy),
67 iftype[2], iftype[3]);
68 break;
69 }
70 case FW_FMAC:
71 default:
72 printk(KERN_ERR "%s: unsupported firmware\n",
73 wiphy_name(priv->hw->wiphy));
74 return -ENODEV;
75 }
76 break;
77 case BR_CODE_COMPONENT_VERSION:
78 /* 24 bytes should be enough for all firmwares */
79 if (strnlen((unsigned char *) bootrec->data, 24) < 24)
80 fw_version = (unsigned char *) bootrec->data;
81 break;
82 case BR_CODE_DESCR: {
83 struct bootrec_desc *desc =
84 (struct bootrec_desc *)bootrec->data;
85 priv->rx_start = le32_to_cpu(desc->rx_start);
86 /* FIXME add sanity checking */
87 priv->rx_end = le32_to_cpu(desc->rx_end) - 0x3500;
88 priv->headroom = desc->headroom;
89 priv->tailroom = desc->tailroom;
90 priv->privacy_caps = desc->privacy_caps;
91 priv->rx_keycache_size = desc->rx_keycache_size;
92 if (le32_to_cpu(bootrec->len) == 11)
93 priv->rx_mtu = le16_to_cpu(desc->rx_mtu);
94 else
95 priv->rx_mtu = (size_t)
96 0x620 - priv->tx_hdr_len;
97 maxlen = priv->tx_hdr_len + /* USB devices */
98 sizeof(struct p54_rx_data) +
99 4 + /* rx alignment */
100 IEEE80211_MAX_FRAG_THRESHOLD;
101 if (priv->rx_mtu > maxlen && PAGE_SIZE == 4096) {
102 printk(KERN_INFO "p54: rx_mtu reduced from %d "
103 "to %d\n", priv->rx_mtu, maxlen);
104 priv->rx_mtu = maxlen;
105 }
106 break;
107 }
108 case BR_CODE_EXPOSED_IF:
109 exp_if = (struct exp_if *) bootrec->data;
110 for (i = 0; i < (len * sizeof(*exp_if) / 4); i++)
111 if (exp_if[i].if_id == cpu_to_le16(IF_ID_LMAC))
112 priv->fw_var = le16_to_cpu(exp_if[i].variant);
113 break;
114 case BR_CODE_DEPENDENT_IF:
115 break;
116 case BR_CODE_END_OF_BRA:
117 case LEGACY_BR_CODE_END_OF_BRA:
118 end_data = NULL;
119 break;
120 default:
121 break;
122 }
123 bootrec = (struct bootrec *)&bootrec->data[len];
124 }
125
126 if (fw_version)
127 printk(KERN_INFO "%s: FW rev %s - Softmac protocol %x.%x\n",
128 wiphy_name(priv->hw->wiphy), fw_version,
129 priv->fw_var >> 8, priv->fw_var & 0xff);
130
131 if (priv->fw_var < 0x500)
132 printk(KERN_INFO "%s: you are using an obsolete firmware. "
133 "visit http://wireless.kernel.org/en/users/Drivers/p54 "
134 "and grab one for \"kernel >= 2.6.28\"!\n",
135 wiphy_name(priv->hw->wiphy));
136
137 if (priv->fw_var >= 0x300) {
138 /* Firmware supports QoS, use it! */
139
140 if (priv->fw_var >= 0x500) {
141 priv->tx_stats[P54_QUEUE_AC_VO].limit = 16;
142 priv->tx_stats[P54_QUEUE_AC_VI].limit = 16;
143 priv->tx_stats[P54_QUEUE_AC_BE].limit = 16;
144 priv->tx_stats[P54_QUEUE_AC_BK].limit = 16;
145 } else {
146 priv->tx_stats[P54_QUEUE_AC_VO].limit = 3;
147 priv->tx_stats[P54_QUEUE_AC_VI].limit = 4;
148 priv->tx_stats[P54_QUEUE_AC_BE].limit = 3;
149 priv->tx_stats[P54_QUEUE_AC_BK].limit = 2;
150 }
151 priv->hw->queues = P54_QUEUE_AC_NUM;
152 }
153
154 printk(KERN_INFO "%s: cryptographic accelerator "
155 "WEP:%s, TKIP:%s, CCMP:%s\n", wiphy_name(priv->hw->wiphy),
156 (priv->privacy_caps & BR_DESC_PRIV_CAP_WEP) ? "YES" :
157 "no", (priv->privacy_caps & (BR_DESC_PRIV_CAP_TKIP |
158 BR_DESC_PRIV_CAP_MICHAEL)) ? "YES" : "no",
159 (priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP) ?
160 "YES" : "no");
161
162 if (priv->rx_keycache_size) {
163 /*
164 * NOTE:
165 *
166 * The firmware provides at most 255 (0 - 254) slots
167 * for keys which are then used to offload decryption.
168 * As a result the 255 entry (aka 0xff) can be used
169 * safely by the driver to mark keys that didn't fit
170 * into the full cache. This trick saves us from
171 * keeping a extra list for uploaded keys.
172 */
173
174 priv->used_rxkeys = kzalloc(BITS_TO_LONGS(
175 priv->rx_keycache_size), GFP_KERNEL);
176
177 if (!priv->used_rxkeys)
178 return -ENOMEM;
179 }
180
181 return 0;
182}
183EXPORT_SYMBOL_GPL(p54_parse_firmware);
184
185static struct sk_buff *p54_alloc_skb(struct p54_common *priv, u16 hdr_flags,
186 u16 payload_len, u16 type, gfp_t memflags)
187{
188 struct p54_hdr *hdr;
189 struct sk_buff *skb;
190 size_t frame_len = sizeof(*hdr) + payload_len;
191
192 if (frame_len > P54_MAX_CTRL_FRAME_LEN)
193 return NULL;
194
195 if (unlikely(skb_queue_len(&priv->tx_pending) > 64))
196 return NULL;
197
198 skb = __dev_alloc_skb(priv->tx_hdr_len + frame_len, memflags);
199 if (!skb)
200 return NULL;
201 skb_reserve(skb, priv->tx_hdr_len);
202
203 hdr = (struct p54_hdr *) skb_put(skb, sizeof(*hdr));
204 hdr->flags = cpu_to_le16(hdr_flags);
205 hdr->len = cpu_to_le16(payload_len);
206 hdr->type = cpu_to_le16(type);
207 hdr->tries = hdr->rts_tries = 0;
208 return skb;
209}
210
211int p54_download_eeprom(struct p54_common *priv, void *buf,
212 u16 offset, u16 len)
213{
214 struct p54_eeprom_lm86 *eeprom_hdr;
215 struct sk_buff *skb;
216 size_t eeprom_hdr_size;
217 int ret = 0;
218
219 if (priv->fw_var >= 0x509)
220 eeprom_hdr_size = sizeof(*eeprom_hdr);
221 else
222 eeprom_hdr_size = 0x4;
223
224 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL, eeprom_hdr_size +
225 len, P54_CONTROL_TYPE_EEPROM_READBACK,
226 GFP_KERNEL);
227 if (unlikely(!skb))
228 return -ENOMEM;
229
230 mutex_lock(&priv->eeprom_mutex);
231 priv->eeprom = buf;
232 eeprom_hdr = (struct p54_eeprom_lm86 *) skb_put(skb,
233 eeprom_hdr_size + len);
234
235 if (priv->fw_var < 0x509) {
236 eeprom_hdr->v1.offset = cpu_to_le16(offset);
237 eeprom_hdr->v1.len = cpu_to_le16(len);
238 } else {
239 eeprom_hdr->v2.offset = cpu_to_le32(offset);
240 eeprom_hdr->v2.len = cpu_to_le16(len);
241 eeprom_hdr->v2.magic2 = 0xf;
242 memcpy(eeprom_hdr->v2.magic, (const char *)"LOCK", 4);
243 }
244
245 p54_tx(priv, skb);
246
247 if (!wait_for_completion_interruptible_timeout(
248 &priv->eeprom_comp, HZ)) {
249 printk(KERN_ERR "%s: device does not respond!\n",
250 wiphy_name(priv->hw->wiphy));
251 ret = -EBUSY;
252 }
253 priv->eeprom = NULL;
254 mutex_unlock(&priv->eeprom_mutex);
255 return ret;
256}
257
258int p54_update_beacon_tim(struct p54_common *priv, u16 aid, bool set)
259{
260 struct sk_buff *skb;
261 struct p54_tim *tim;
262
263 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*tim),
264 P54_CONTROL_TYPE_TIM, GFP_ATOMIC);
265 if (unlikely(!skb))
266 return -ENOMEM;
267
268 tim = (struct p54_tim *) skb_put(skb, sizeof(*tim));
269 tim->count = 1;
270 tim->entry[0] = cpu_to_le16(set ? (aid | 0x8000) : aid);
271 p54_tx(priv, skb);
272 return 0;
273}
274
275int p54_sta_unlock(struct p54_common *priv, u8 *addr)
276{
277 struct sk_buff *skb;
278 struct p54_sta_unlock *sta;
279
280 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*sta),
281 P54_CONTROL_TYPE_PSM_STA_UNLOCK, GFP_ATOMIC);
282 if (unlikely(!skb))
283 return -ENOMEM;
284
285 sta = (struct p54_sta_unlock *)skb_put(skb, sizeof(*sta));
286 memcpy(sta->addr, addr, ETH_ALEN);
287 p54_tx(priv, skb);
288 return 0;
289}
290
291int p54_tx_cancel(struct p54_common *priv, __le32 req_id)
292{
293 struct sk_buff *skb;
294 struct p54_txcancel *cancel;
295 u32 _req_id = le32_to_cpu(req_id);
296
297 if (unlikely(_req_id < priv->rx_start || _req_id > priv->rx_end))
298 return -EINVAL;
299
300 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*cancel),
301 P54_CONTROL_TYPE_TXCANCEL, GFP_ATOMIC);
302 if (unlikely(!skb))
303 return -ENOMEM;
304
305 cancel = (struct p54_txcancel *)skb_put(skb, sizeof(*cancel));
306 cancel->req_id = req_id;
307 p54_tx(priv, skb);
308 return 0;
309}
310
311int p54_setup_mac(struct p54_common *priv)
312{
313 struct sk_buff *skb;
314 struct p54_setup_mac *setup;
315 u16 mode;
316
317 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup),
318 P54_CONTROL_TYPE_SETUP, GFP_ATOMIC);
319 if (!skb)
320 return -ENOMEM;
321
322 setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup));
323 if (priv->hw->conf.radio_enabled) {
324 switch (priv->mode) {
325 case NL80211_IFTYPE_STATION:
326 mode = P54_FILTER_TYPE_STATION;
327 break;
328 case NL80211_IFTYPE_AP:
329 mode = P54_FILTER_TYPE_AP;
330 break;
331 case NL80211_IFTYPE_ADHOC:
332 case NL80211_IFTYPE_MESH_POINT:
333 mode = P54_FILTER_TYPE_IBSS;
334 break;
335 case NL80211_IFTYPE_MONITOR:
336 mode = P54_FILTER_TYPE_PROMISCUOUS;
337 break;
338 default:
339 mode = P54_FILTER_TYPE_HIBERNATE;
340 break;
341 }
342
343 /*
344 * "TRANSPARENT and PROMISCUOUS are mutually exclusive"
345 * STSW45X0C LMAC API - page 12
346 */
347 if (((priv->filter_flags & FIF_PROMISC_IN_BSS) ||
348 (priv->filter_flags & FIF_OTHER_BSS)) &&
349 (mode != P54_FILTER_TYPE_PROMISCUOUS))
350 mode |= P54_FILTER_TYPE_TRANSPARENT;
351 } else
352 mode = P54_FILTER_TYPE_HIBERNATE;
353
354 setup->mac_mode = cpu_to_le16(mode);
355 memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN);
356 memcpy(setup->bssid, priv->bssid, ETH_ALEN);
357 setup->rx_antenna = 2 & priv->rx_diversity_mask; /* automatic */
358 setup->rx_align = 0;
359 if (priv->fw_var < 0x500) {
360 setup->v1.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
361 memset(setup->v1.rts_rates, 0, 8);
362 setup->v1.rx_addr = cpu_to_le32(priv->rx_end);
363 setup->v1.max_rx = cpu_to_le16(priv->rx_mtu);
364 setup->v1.rxhw = cpu_to_le16(priv->rxhw);
365 setup->v1.wakeup_timer = cpu_to_le16(priv->wakeup_timer);
366 setup->v1.unalloc0 = cpu_to_le16(0);
367 } else {
368 setup->v2.rx_addr = cpu_to_le32(priv->rx_end);
369 setup->v2.max_rx = cpu_to_le16(priv->rx_mtu);
370 setup->v2.rxhw = cpu_to_le16(priv->rxhw);
371 setup->v2.timer = cpu_to_le16(priv->wakeup_timer);
372 setup->v2.truncate = cpu_to_le16(48896);
373 setup->v2.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
374 setup->v2.sbss_offset = 0;
375 setup->v2.mcast_window = 0;
376 setup->v2.rx_rssi_threshold = 0;
377 setup->v2.rx_ed_threshold = 0;
378 setup->v2.ref_clock = cpu_to_le32(644245094);
379 setup->v2.lpf_bandwidth = cpu_to_le16(65535);
380 setup->v2.osc_start_delay = cpu_to_le16(65535);
381 }
382 p54_tx(priv, skb);
383 return 0;
384}
385
386int p54_scan(struct p54_common *priv, u16 mode, u16 dwell)
387{
388 struct sk_buff *skb;
389 struct p54_hdr *hdr;
390 struct p54_scan_head *head;
391 struct p54_iq_autocal_entry *iq_autocal;
392 union p54_scan_body_union *body;
393 struct p54_scan_tail_rate *rate;
394 struct pda_rssi_cal_entry *rssi;
395 unsigned int i;
396 void *entry;
397 int band = priv->hw->conf.channel->band;
398 __le16 freq = cpu_to_le16(priv->hw->conf.channel->center_freq);
399
400 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*head) +
401 2 + sizeof(*iq_autocal) + sizeof(*body) +
402 sizeof(*rate) + 2 * sizeof(*rssi),
403 P54_CONTROL_TYPE_SCAN, GFP_ATOMIC);
404 if (!skb)
405 return -ENOMEM;
406
407 head = (struct p54_scan_head *) skb_put(skb, sizeof(*head));
408 memset(head->scan_params, 0, sizeof(head->scan_params));
409 head->mode = cpu_to_le16(mode);
410 head->dwell = cpu_to_le16(dwell);
411 head->freq = freq;
412
413 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
414 __le16 *pa_power_points = (__le16 *) skb_put(skb, 2);
415 *pa_power_points = cpu_to_le16(0x0c);
416 }
417
418 iq_autocal = (void *) skb_put(skb, sizeof(*iq_autocal));
419 for (i = 0; i < priv->iq_autocal_len; i++) {
420 if (priv->iq_autocal[i].freq != freq)
421 continue;
422
423 memcpy(iq_autocal, &priv->iq_autocal[i].params,
424 sizeof(struct p54_iq_autocal_entry));
425 break;
426 }
427 if (i == priv->iq_autocal_len)
428 goto err;
429
430 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW)
431 body = (void *) skb_put(skb, sizeof(body->longbow));
432 else
433 body = (void *) skb_put(skb, sizeof(body->normal));
434
435 for (i = 0; i < priv->output_limit->entries; i++) {
436 __le16 *entry_freq = (void *) (priv->output_limit->data +
437 priv->output_limit->entry_size * i);
438
439 if (*entry_freq != freq)
440 continue;
441
442 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
443 memcpy(&body->longbow.power_limits,
444 (void *) entry_freq + sizeof(__le16),
445 priv->output_limit->entry_size);
446 } else {
447 struct pda_channel_output_limit *limits =
448 (void *) entry_freq;
449
450 body->normal.val_barker = 0x38;
451 body->normal.val_bpsk = body->normal.dup_bpsk =
452 limits->val_bpsk;
453 body->normal.val_qpsk = body->normal.dup_qpsk =
454 limits->val_qpsk;
455 body->normal.val_16qam = body->normal.dup_16qam =
456 limits->val_16qam;
457 body->normal.val_64qam = body->normal.dup_64qam =
458 limits->val_64qam;
459 }
460 break;
461 }
462 if (i == priv->output_limit->entries)
463 goto err;
464
465 entry = (void *)(priv->curve_data->data + priv->curve_data->offset);
466 for (i = 0; i < priv->curve_data->entries; i++) {
467 if (*((__le16 *)entry) != freq) {
468 entry += priv->curve_data->entry_size;
469 continue;
470 }
471
472 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
473 memcpy(&body->longbow.curve_data,
474 (void *) entry + sizeof(__le16),
475 priv->curve_data->entry_size);
476 } else {
477 struct p54_scan_body *chan = &body->normal;
478 struct pda_pa_curve_data *curve_data =
479 (void *) priv->curve_data->data;
480
481 entry += sizeof(__le16);
482 chan->pa_points_per_curve = 8;
483 memset(chan->curve_data, 0, sizeof(*chan->curve_data));
484 memcpy(chan->curve_data, entry,
485 sizeof(struct p54_pa_curve_data_sample) *
486 min((u8)8, curve_data->points_per_channel));
487 }
488 break;
489 }
490 if (i == priv->curve_data->entries)
491 goto err;
492
493 if ((priv->fw_var >= 0x500) && (priv->fw_var < 0x509)) {
494 rate = (void *) skb_put(skb, sizeof(*rate));
495 rate->basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
496 for (i = 0; i < sizeof(rate->rts_rates); i++)
497 rate->rts_rates[i] = i;
498 }
499
500 rssi = (struct pda_rssi_cal_entry *) skb_put(skb, sizeof(*rssi));
501 rssi->mul = cpu_to_le16(priv->rssical_db[band].mul);
502 rssi->add = cpu_to_le16(priv->rssical_db[band].add);
503 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
504 /* Longbow frontend needs ever more */
505 rssi = (void *) skb_put(skb, sizeof(*rssi));
506 rssi->mul = cpu_to_le16(priv->rssical_db[band].longbow_unkn);
507 rssi->add = cpu_to_le16(priv->rssical_db[band].longbow_unk2);
508 }
509
510 if (priv->fw_var >= 0x509) {
511 rate = (void *) skb_put(skb, sizeof(*rate));
512 rate->basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
513 for (i = 0; i < sizeof(rate->rts_rates); i++)
514 rate->rts_rates[i] = i;
515 }
516
517 hdr = (struct p54_hdr *) skb->data;
518 hdr->len = cpu_to_le16(skb->len - sizeof(*hdr));
519
520 p54_tx(priv, skb);
521 return 0;
522
523err:
524 printk(KERN_ERR "%s: frequency change to channel %d failed.\n",
525 wiphy_name(priv->hw->wiphy), ieee80211_frequency_to_channel(
526 priv->hw->conf.channel->center_freq));
527
528 dev_kfree_skb_any(skb);
529 return -EINVAL;
530}
531
532int p54_set_leds(struct p54_common *priv)
533{
534 struct sk_buff *skb;
535 struct p54_led *led;
536
537 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*led),
538 P54_CONTROL_TYPE_LED, GFP_ATOMIC);
539 if (unlikely(!skb))
540 return -ENOMEM;
541
542 led = (struct p54_led *) skb_put(skb, sizeof(*led));
543 led->flags = cpu_to_le16(0x0003);
544 led->mask[0] = led->mask[1] = cpu_to_le16(priv->softled_state);
545 led->delay[0] = cpu_to_le16(1);
546 led->delay[1] = cpu_to_le16(0);
547 p54_tx(priv, skb);
548 return 0;
549}
550
551int p54_set_edcf(struct p54_common *priv)
552{
553 struct sk_buff *skb;
554 struct p54_edcf *edcf;
555
556 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*edcf),
557 P54_CONTROL_TYPE_DCFINIT, GFP_ATOMIC);
558 if (unlikely(!skb))
559 return -ENOMEM;
560
561 edcf = (struct p54_edcf *)skb_put(skb, sizeof(*edcf));
562 if (priv->use_short_slot) {
563 edcf->slottime = 9;
564 edcf->sifs = 0x10;
565 edcf->eofpad = 0x00;
566 } else {
567 edcf->slottime = 20;
568 edcf->sifs = 0x0a;
569 edcf->eofpad = 0x06;
570 }
571 /* (see prism54/isl_oid.h for further details) */
572 edcf->frameburst = cpu_to_le16(0);
573 edcf->round_trip_delay = cpu_to_le16(0);
574 edcf->flags = 0;
575 memset(edcf->mapping, 0, sizeof(edcf->mapping));
576 memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue));
577 p54_tx(priv, skb);
578 return 0;
579}
580
581int p54_set_ps(struct p54_common *priv)
582{
583 struct sk_buff *skb;
584 struct p54_psm *psm;
585 unsigned int i;
586 u16 mode;
587
588 if (priv->hw->conf.flags & IEEE80211_CONF_PS)
589 mode = P54_PSM | P54_PSM_BEACON_TIMEOUT | P54_PSM_DTIM |
590 P54_PSM_CHECKSUM | P54_PSM_MCBC;
591 else
592 mode = P54_PSM_CAM;
593
594 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*psm),
595 P54_CONTROL_TYPE_PSM, GFP_ATOMIC);
596 if (!skb)
597 return -ENOMEM;
598
599 psm = (struct p54_psm *)skb_put(skb, sizeof(*psm));
600 psm->mode = cpu_to_le16(mode);
601 psm->aid = cpu_to_le16(priv->aid);
602 for (i = 0; i < ARRAY_SIZE(psm->intervals); i++) {
603 psm->intervals[i].interval =
604 cpu_to_le16(priv->hw->conf.listen_interval);
605 psm->intervals[i].periods = cpu_to_le16(1);
606 }
607
608 psm->beacon_rssi_skip_max = 200;
609 psm->rssi_delta_threshold = 0;
610 psm->nr = 10;
611 psm->exclude[0] = 0;
612
613 p54_tx(priv, skb);
614 return 0;
615}
616
617int p54_init_xbow_synth(struct p54_common *priv)
618{
619 struct sk_buff *skb;
620 struct p54_xbow_synth *xbow;
621
622 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*xbow),
623 P54_CONTROL_TYPE_XBOW_SYNTH_CFG, GFP_KERNEL);
624 if (unlikely(!skb))
625 return -ENOMEM;
626
627 xbow = (struct p54_xbow_synth *)skb_put(skb, sizeof(*xbow));
628 xbow->magic1 = cpu_to_le16(0x1);
629 xbow->magic2 = cpu_to_le16(0x2);
630 xbow->freq = cpu_to_le16(5390);
631 memset(xbow->padding, 0, sizeof(xbow->padding));
632 p54_tx(priv, skb);
633 return 0;
634}
635
636int p54_upload_key(struct p54_common *priv, u8 algo, int slot, u8 idx, u8 len,
637 u8 *addr, u8* key)
638{
639 struct sk_buff *skb;
640 struct p54_keycache *rxkey;
641
642 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*rxkey),
643 P54_CONTROL_TYPE_RX_KEYCACHE, GFP_KERNEL);
644 if (unlikely(!skb))
645 return -ENOMEM;
646
647 rxkey = (struct p54_keycache *)skb_put(skb, sizeof(*rxkey));
648 rxkey->entry = slot;
649 rxkey->key_id = idx;
650 rxkey->key_type = algo;
651 if (addr)
652 memcpy(rxkey->mac, addr, ETH_ALEN);
653 else
654 memset(rxkey->mac, ~0, ETH_ALEN);
655
656 switch (algo) {
657 case P54_CRYPTO_WEP:
658 case P54_CRYPTO_AESCCMP:
659 rxkey->key_len = min_t(u8, 16, len);
660 memcpy(rxkey->key, key, rxkey->key_len);
661 break;
662
663 case P54_CRYPTO_TKIPMICHAEL:
664 rxkey->key_len = 24;
665 memcpy(rxkey->key, key, 16);
666 memcpy(&(rxkey->key[16]), &(key
667 [NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]), 8);
668 break;
669
670 case P54_CRYPTO_NONE:
671 rxkey->key_len = 0;
672 memset(rxkey->key, 0, sizeof(rxkey->key));
673 break;
674
675 default:
676 printk(KERN_ERR "%s: invalid cryptographic algorithm: %d\n",
677 wiphy_name(priv->hw->wiphy), algo);
678 dev_kfree_skb(skb);
679 return -EINVAL;
680 }
681
682 p54_tx(priv, skb);
683 return 0;
684}
685
686int p54_fetch_statistics(struct p54_common *priv)
687{
688 struct sk_buff *skb;
689
690 skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL,
691 sizeof(struct p54_statistics),
692 P54_CONTROL_TYPE_STAT_READBACK, GFP_KERNEL);
693 if (!skb)
694 return -ENOMEM;
695
696 p54_tx(priv, skb);
697 return 0;
698}
diff --git a/drivers/net/wireless/p54/led.c b/drivers/net/wireless/p54/led.c
new file mode 100644
index 000000000000..c00115b206d4
--- /dev/null
+++ b/drivers/net/wireless/p54/led.c
@@ -0,0 +1,163 @@
1/*
2 * Common code for mac80211 Prism54 drivers
3 *
4 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
5 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 *
8 * Based on:
9 * - the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
11 * - stlc45xx driver
12 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/init.h>
20#include <linux/firmware.h>
21#include <linux/etherdevice.h>
22
23#include <net/mac80211.h>
24#ifdef CONFIG_P54_LEDS
25#include <linux/leds.h>
26#endif /* CONFIG_P54_LEDS */
27
28#include "p54.h"
29#include "lmac.h"
30
31static void p54_update_leds(struct work_struct *work)
32{
33 struct p54_common *priv = container_of(work, struct p54_common,
34 led_work.work);
35 int err, i, tmp, blink_delay = 400;
36 bool rerun = false;
37
38 /* Don't toggle the LED, when the device is down. */
39 if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
40 return ;
41
42 for (i = 0; i < ARRAY_SIZE(priv->leds); i++)
43 if (priv->leds[i].toggled) {
44 priv->softled_state |= BIT(i);
45
46 tmp = 70 + 200 / (priv->leds[i].toggled);
47 if (tmp < blink_delay)
48 blink_delay = tmp;
49
50 if (priv->leds[i].led_dev.brightness == LED_OFF)
51 rerun = true;
52
53 priv->leds[i].toggled =
54 !!priv->leds[i].led_dev.brightness;
55 } else
56 priv->softled_state &= ~BIT(i);
57
58 err = p54_set_leds(priv);
59 if (err && net_ratelimit())
60 printk(KERN_ERR "%s: failed to update LEDs (%d).\n",
61 wiphy_name(priv->hw->wiphy), err);
62
63 if (rerun)
64 queue_delayed_work(priv->hw->workqueue, &priv->led_work,
65 msecs_to_jiffies(blink_delay));
66}
67
68static void p54_led_brightness_set(struct led_classdev *led_dev,
69 enum led_brightness brightness)
70{
71 struct p54_led_dev *led = container_of(led_dev, struct p54_led_dev,
72 led_dev);
73 struct ieee80211_hw *dev = led->hw_dev;
74 struct p54_common *priv = dev->priv;
75
76 if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
77 return ;
78
79 if ((brightness) && (led->registered)) {
80 led->toggled++;
81 queue_delayed_work(priv->hw->workqueue, &priv->led_work,
82 HZ/10);
83 }
84}
85
86static int p54_register_led(struct p54_common *priv,
87 unsigned int led_index,
88 char *name, char *trigger)
89{
90 struct p54_led_dev *led = &priv->leds[led_index];
91 int err;
92
93 if (led->registered)
94 return -EEXIST;
95
96 snprintf(led->name, sizeof(led->name), "p54-%s::%s",
97 wiphy_name(priv->hw->wiphy), name);
98 led->hw_dev = priv->hw;
99 led->index = led_index;
100 led->led_dev.name = led->name;
101 led->led_dev.default_trigger = trigger;
102 led->led_dev.brightness_set = p54_led_brightness_set;
103
104 err = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_dev);
105 if (err)
106 printk(KERN_ERR "%s: Failed to register %s LED.\n",
107 wiphy_name(priv->hw->wiphy), name);
108 else
109 led->registered = 1;
110
111 return err;
112}
113
114int p54_init_leds(struct p54_common *priv)
115{
116 int err;
117
118 /*
119 * TODO:
120 * Figure out if the EEPROM contains some hints about the number
121 * of available/programmable LEDs of the device.
122 */
123
124 INIT_DELAYED_WORK(&priv->led_work, p54_update_leds);
125
126 err = p54_register_led(priv, 0, "assoc",
127 ieee80211_get_assoc_led_name(priv->hw));
128 if (err)
129 return err;
130
131 err = p54_register_led(priv, 1, "tx",
132 ieee80211_get_tx_led_name(priv->hw));
133 if (err)
134 return err;
135
136 err = p54_register_led(priv, 2, "rx",
137 ieee80211_get_rx_led_name(priv->hw));
138 if (err)
139 return err;
140
141 err = p54_register_led(priv, 3, "radio",
142 ieee80211_get_radio_led_name(priv->hw));
143 if (err)
144 return err;
145
146 err = p54_set_leds(priv);
147 return err;
148}
149
150void p54_unregister_leds(struct p54_common *priv)
151{
152 int i;
153
154 for (i = 0; i < ARRAY_SIZE(priv->leds); i++) {
155 if (priv->leds[i].registered) {
156 priv->leds[i].registered = false;
157 priv->leds[i].toggled = 0;
158 led_classdev_unregister(&priv->leds[i].led_dev);
159 }
160 }
161
162 cancel_delayed_work_sync(&priv->led_work);
163}
diff --git a/drivers/net/wireless/p54/lmac.h b/drivers/net/wireless/p54/lmac.h
new file mode 100644
index 000000000000..0496cff26b35
--- /dev/null
+++ b/drivers/net/wireless/p54/lmac.h
@@ -0,0 +1,551 @@
1/*
2 * LMAC Interface specific definitions for mac80211 Prism54 drivers
3 *
4 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
5 * Copyright (c) 2007 - 2009, Christian Lamparter <chunkeey@web.de>
6 *
7 * Based on:
8 * - the islsm (softmac prism54) driver, which is:
9 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
10 *
11 * - LMAC API interface header file for STLC4560 (lmac_longbow.h)
12 * Copyright (C) 2007 Conexant Systems, Inc.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#ifndef LMAC_H
20#define LMAC_H
21
22enum p54_control_frame_types {
23 P54_CONTROL_TYPE_SETUP = 0,
24 P54_CONTROL_TYPE_SCAN,
25 P54_CONTROL_TYPE_TRAP,
26 P54_CONTROL_TYPE_DCFINIT,
27 P54_CONTROL_TYPE_RX_KEYCACHE,
28 P54_CONTROL_TYPE_TIM,
29 P54_CONTROL_TYPE_PSM,
30 P54_CONTROL_TYPE_TXCANCEL,
31 P54_CONTROL_TYPE_TXDONE,
32 P54_CONTROL_TYPE_BURST,
33 P54_CONTROL_TYPE_STAT_READBACK,
34 P54_CONTROL_TYPE_BBP,
35 P54_CONTROL_TYPE_EEPROM_READBACK,
36 P54_CONTROL_TYPE_LED,
37 P54_CONTROL_TYPE_GPIO,
38 P54_CONTROL_TYPE_TIMER,
39 P54_CONTROL_TYPE_MODULATION,
40 P54_CONTROL_TYPE_SYNTH_CONFIG,
41 P54_CONTROL_TYPE_DETECTOR_VALUE,
42 P54_CONTROL_TYPE_XBOW_SYNTH_CFG,
43 P54_CONTROL_TYPE_CCE_QUIET,
44 P54_CONTROL_TYPE_PSM_STA_UNLOCK,
45 P54_CONTROL_TYPE_PCS,
46 P54_CONTROL_TYPE_BT_BALANCER = 28,
47 P54_CONTROL_TYPE_GROUP_ADDRESS_TABLE = 30,
48 P54_CONTROL_TYPE_ARPTABLE = 31,
49 P54_CONTROL_TYPE_BT_OPTIONS = 35,
50};
51
52#define P54_HDR_FLAG_CONTROL BIT(15)
53#define P54_HDR_FLAG_CONTROL_OPSET (BIT(15) + BIT(0))
54#define P54_HDR_FLAG_DATA_ALIGN BIT(14)
55
56#define P54_HDR_FLAG_DATA_OUT_PROMISC BIT(0)
57#define P54_HDR_FLAG_DATA_OUT_TIMESTAMP BIT(1)
58#define P54_HDR_FLAG_DATA_OUT_SEQNR BIT(2)
59#define P54_HDR_FLAG_DATA_OUT_BIT3 BIT(3)
60#define P54_HDR_FLAG_DATA_OUT_BURST BIT(4)
61#define P54_HDR_FLAG_DATA_OUT_NOCANCEL BIT(5)
62#define P54_HDR_FLAG_DATA_OUT_CLEARTIM BIT(6)
63#define P54_HDR_FLAG_DATA_OUT_HITCHHIKE BIT(7)
64#define P54_HDR_FLAG_DATA_OUT_COMPRESS BIT(8)
65#define P54_HDR_FLAG_DATA_OUT_CONCAT BIT(9)
66#define P54_HDR_FLAG_DATA_OUT_PCS_ACCEPT BIT(10)
67#define P54_HDR_FLAG_DATA_OUT_WAITEOSP BIT(11)
68
69#define P54_HDR_FLAG_DATA_IN_FCS_GOOD BIT(0)
70#define P54_HDR_FLAG_DATA_IN_MATCH_MAC BIT(1)
71#define P54_HDR_FLAG_DATA_IN_MCBC BIT(2)
72#define P54_HDR_FLAG_DATA_IN_BEACON BIT(3)
73#define P54_HDR_FLAG_DATA_IN_MATCH_BSS BIT(4)
74#define P54_HDR_FLAG_DATA_IN_BCAST_BSS BIT(5)
75#define P54_HDR_FLAG_DATA_IN_DATA BIT(6)
76#define P54_HDR_FLAG_DATA_IN_TRUNCATED BIT(7)
77#define P54_HDR_FLAG_DATA_IN_BIT8 BIT(8)
78#define P54_HDR_FLAG_DATA_IN_TRANSPARENT BIT(9)
79
80struct p54_hdr {
81 __le16 flags;
82 __le16 len;
83 __le32 req_id;
84 __le16 type; /* enum p54_control_frame_types */
85 u8 rts_tries;
86 u8 tries;
87 u8 data[0];
88} __packed;
89
90#define GET_REQ_ID(skb) \
91 (((struct p54_hdr *) ((struct sk_buff *) skb)->data)->req_id) \
92
93#define FREE_AFTER_TX(skb) \
94 ((((struct p54_hdr *) ((struct sk_buff *) skb)->data)-> \
95 flags) == cpu_to_le16(P54_HDR_FLAG_CONTROL_OPSET))
96
97#define IS_DATA_FRAME(skb) \
98 (!((((struct p54_hdr *) ((struct sk_buff *) skb)->data)-> \
99 flags) & cpu_to_le16(P54_HDR_FLAG_CONTROL)))
100
101/*
102 * shared interface ID definitions
103 * The interface ID is a unique identification of a specific interface.
104 * The following values are reserved: 0x0000, 0x0002, 0x0012, 0x0014, 0x0015
105 */
106#define IF_ID_ISL36356A 0x0001 /* ISL36356A <-> Firmware */
107#define IF_ID_MVC 0x0003 /* MAC Virtual Coprocessor */
108#define IF_ID_DEBUG 0x0008 /* PolDebug Interface */
109#define IF_ID_PRODUCT 0x0009
110#define IF_ID_OEM 0x000a
111#define IF_ID_PCI3877 0x000b /* 3877 <-> Host PCI */
112#define IF_ID_ISL37704C 0x000c /* ISL37704C <-> Fw */
113#define IF_ID_ISL39000 0x000f /* ISL39000 <-> Fw */
114#define IF_ID_ISL39300A 0x0010 /* ISL39300A <-> Fw */
115#define IF_ID_ISL37700_UAP 0x0016 /* ISL37700 uAP Fw <-> Fw */
116#define IF_ID_ISL39000_UAP 0x0017 /* ISL39000 uAP Fw <-> Fw */
117#define IF_ID_LMAC 0x001a /* Interface exposed by LMAC */
118
119struct exp_if {
120 __le16 role;
121 __le16 if_id;
122 __le16 variant;
123 __le16 btm_compat;
124 __le16 top_compat;
125} __packed;
126
127struct dep_if {
128 __le16 role;
129 __le16 if_id;
130 __le16 variant;
131} __packed;
132
133/* driver <-> lmac definitions */
134struct p54_eeprom_lm86 {
135 union {
136 struct {
137 __le16 offset;
138 __le16 len;
139 u8 data[0];
140 } __packed v1;
141 struct {
142 __le32 offset;
143 __le16 len;
144 u8 magic2;
145 u8 pad;
146 u8 magic[4];
147 u8 data[0];
148 } __packed v2;
149 } __packed;
150} __packed;
151
152enum p54_rx_decrypt_status {
153 P54_DECRYPT_NONE = 0,
154 P54_DECRYPT_OK,
155 P54_DECRYPT_NOKEY,
156 P54_DECRYPT_NOMICHAEL,
157 P54_DECRYPT_NOCKIPMIC,
158 P54_DECRYPT_FAIL_WEP,
159 P54_DECRYPT_FAIL_TKIP,
160 P54_DECRYPT_FAIL_MICHAEL,
161 P54_DECRYPT_FAIL_CKIPKP,
162 P54_DECRYPT_FAIL_CKIPMIC,
163 P54_DECRYPT_FAIL_AESCCMP
164};
165
166struct p54_rx_data {
167 __le16 flags;
168 __le16 len;
169 __le16 freq;
170 u8 antenna;
171 u8 rate;
172 u8 rssi;
173 u8 quality;
174 u8 decrypt_status;
175 u8 rssi_raw;
176 __le32 tsf32;
177 __le32 unalloc0;
178 u8 align[0];
179} __packed;
180
181enum p54_trap_type {
182 P54_TRAP_SCAN = 0,
183 P54_TRAP_TIMER,
184 P54_TRAP_BEACON_TX,
185 P54_TRAP_FAA_RADIO_ON,
186 P54_TRAP_FAA_RADIO_OFF,
187 P54_TRAP_RADAR,
188 P54_TRAP_NO_BEACON,
189 P54_TRAP_TBTT,
190 P54_TRAP_SCO_ENTER,
191 P54_TRAP_SCO_EXIT
192};
193
194struct p54_trap {
195 __le16 event;
196 __le16 frequency;
197} __packed;
198
199enum p54_frame_sent_status {
200 P54_TX_OK = 0,
201 P54_TX_FAILED,
202 P54_TX_PSM,
203 P54_TX_PSM_CANCELLED = 4
204};
205
206struct p54_frame_sent {
207 u8 status;
208 u8 tries;
209 u8 ack_rssi;
210 u8 quality;
211 __le16 seq;
212 u8 antenna;
213 u8 padding;
214} __packed;
215
216enum p54_tx_data_crypt {
217 P54_CRYPTO_NONE = 0,
218 P54_CRYPTO_WEP,
219 P54_CRYPTO_TKIP,
220 P54_CRYPTO_TKIPMICHAEL,
221 P54_CRYPTO_CCX_WEPMIC,
222 P54_CRYPTO_CCX_KPMIC,
223 P54_CRYPTO_CCX_KP,
224 P54_CRYPTO_AESCCMP
225};
226
227enum p54_tx_data_queue {
228 P54_QUEUE_BEACON = 0,
229 P54_QUEUE_FWSCAN = 1,
230 P54_QUEUE_MGMT = 2,
231 P54_QUEUE_CAB = 3,
232 P54_QUEUE_DATA = 4,
233
234 P54_QUEUE_AC_NUM = 4,
235 P54_QUEUE_AC_VO = 4,
236 P54_QUEUE_AC_VI = 5,
237 P54_QUEUE_AC_BE = 6,
238 P54_QUEUE_AC_BK = 7,
239
240 /* keep last */
241 P54_QUEUE_NUM = 8,
242};
243
244#define IS_QOS_QUEUE(n) (n >= P54_QUEUE_DATA)
245
246struct p54_tx_data {
247 u8 rateset[8];
248 u8 rts_rate_idx;
249 u8 crypt_offset;
250 u8 key_type;
251 u8 key_len;
252 u8 key[16];
253 u8 hw_queue;
254 u8 backlog;
255 __le16 durations[4];
256 u8 tx_antenna;
257 union {
258 struct {
259 u8 cts_rate;
260 __le16 output_power;
261 } __packed longbow;
262 struct {
263 u8 output_power;
264 u8 cts_rate;
265 u8 unalloc;
266 } __packed normal;
267 } __packed;
268 u8 unalloc2[2];
269 u8 align[0];
270} __packed;
271
272/* unit is ms */
273#define P54_TX_FRAME_LIFETIME 2000
274#define P54_TX_TIMEOUT 4000
275#define P54_STATISTICS_UPDATE 5000
276
277#define P54_FILTER_TYPE_NONE 0
278#define P54_FILTER_TYPE_STATION BIT(0)
279#define P54_FILTER_TYPE_IBSS BIT(1)
280#define P54_FILTER_TYPE_AP BIT(2)
281#define P54_FILTER_TYPE_TRANSPARENT BIT(3)
282#define P54_FILTER_TYPE_PROMISCUOUS BIT(4)
283#define P54_FILTER_TYPE_HIBERNATE BIT(5)
284#define P54_FILTER_TYPE_NOACK BIT(6)
285#define P54_FILTER_TYPE_RX_DISABLED BIT(7)
286
287struct p54_setup_mac {
288 __le16 mac_mode;
289 u8 mac_addr[ETH_ALEN];
290 u8 bssid[ETH_ALEN];
291 u8 rx_antenna;
292 u8 rx_align;
293 union {
294 struct {
295 __le32 basic_rate_mask;
296 u8 rts_rates[8];
297 __le32 rx_addr;
298 __le16 max_rx;
299 __le16 rxhw;
300 __le16 wakeup_timer;
301 __le16 unalloc0;
302 } __packed v1;
303 struct {
304 __le32 rx_addr;
305 __le16 max_rx;
306 __le16 rxhw;
307 __le16 timer;
308 __le16 truncate;
309 __le32 basic_rate_mask;
310 u8 sbss_offset;
311 u8 mcast_window;
312 u8 rx_rssi_threshold;
313 u8 rx_ed_threshold;
314 __le32 ref_clock;
315 __le16 lpf_bandwidth;
316 __le16 osc_start_delay;
317 } __packed v2;
318 } __packed;
319} __packed;
320
321#define P54_SETUP_V1_LEN 40
322#define P54_SETUP_V2_LEN (sizeof(struct p54_setup_mac))
323
324#define P54_SCAN_EXIT BIT(0)
325#define P54_SCAN_TRAP BIT(1)
326#define P54_SCAN_ACTIVE BIT(2)
327#define P54_SCAN_FILTER BIT(3)
328
329struct p54_scan_head {
330 __le16 mode;
331 __le16 dwell;
332 u8 scan_params[20];
333 __le16 freq;
334} __packed;
335
336struct p54_pa_curve_data_sample {
337 u8 rf_power;
338 u8 pa_detector;
339 u8 data_barker;
340 u8 data_bpsk;
341 u8 data_qpsk;
342 u8 data_16qam;
343 u8 data_64qam;
344 u8 padding;
345} __packed;
346
347struct p54_scan_body {
348 u8 pa_points_per_curve;
349 u8 val_barker;
350 u8 val_bpsk;
351 u8 val_qpsk;
352 u8 val_16qam;
353 u8 val_64qam;
354 struct p54_pa_curve_data_sample curve_data[8];
355 u8 dup_bpsk;
356 u8 dup_qpsk;
357 u8 dup_16qam;
358 u8 dup_64qam;
359} __packed;
360
361/*
362 * Warning: Longbow's structures are bogus.
363 */
364struct p54_channel_output_limit_longbow {
365 __le16 rf_power_points[12];
366} __packed;
367
368struct p54_pa_curve_data_sample_longbow {
369 __le16 rf_power;
370 __le16 pa_detector;
371 struct {
372 __le16 data[4];
373 } points[3] __packed;
374} __packed;
375
376struct p54_scan_body_longbow {
377 struct p54_channel_output_limit_longbow power_limits;
378 struct p54_pa_curve_data_sample_longbow curve_data[8];
379 __le16 unkn[6]; /* maybe more power_limits or rate_mask */
380} __packed;
381
382union p54_scan_body_union {
383 struct p54_scan_body normal;
384 struct p54_scan_body_longbow longbow;
385} __packed;
386
387struct p54_scan_tail_rate {
388 __le32 basic_rate_mask;
389 u8 rts_rates[8];
390} __packed;
391
392struct p54_led {
393 __le16 flags;
394 __le16 mask[2];
395 __le16 delay[2];
396} __packed;
397
398struct p54_edcf {
399 u8 flags;
400 u8 slottime;
401 u8 sifs;
402 u8 eofpad;
403 struct p54_edcf_queue_param queue[8];
404 u8 mapping[4];
405 __le16 frameburst;
406 __le16 round_trip_delay;
407} __packed;
408
409struct p54_statistics {
410 __le32 rx_success;
411 __le32 rx_bad_fcs;
412 __le32 rx_abort;
413 __le32 rx_abort_phy;
414 __le32 rts_success;
415 __le32 rts_fail;
416 __le32 tsf32;
417 __le32 airtime;
418 __le32 noise;
419 __le32 sample_noise[8];
420 __le32 sample_cca;
421 __le32 sample_tx;
422} __packed;
423
424struct p54_xbow_synth {
425 __le16 magic1;
426 __le16 magic2;
427 __le16 freq;
428 u32 padding[5];
429} __packed;
430
431struct p54_timer {
432 __le32 interval;
433} __packed;
434
435struct p54_keycache {
436 u8 entry;
437 u8 key_id;
438 u8 mac[ETH_ALEN];
439 u8 padding[2];
440 u8 key_type;
441 u8 key_len;
442 u8 key[24];
443} __packed;
444
445struct p54_burst {
446 u8 flags;
447 u8 queue;
448 u8 backlog;
449 u8 pad;
450 __le16 durations[32];
451} __packed;
452
453struct p54_psm_interval {
454 __le16 interval;
455 __le16 periods;
456} __packed;
457
458#define P54_PSM_CAM 0
459#define P54_PSM BIT(0)
460#define P54_PSM_DTIM BIT(1)
461#define P54_PSM_MCBC BIT(2)
462#define P54_PSM_CHECKSUM BIT(3)
463#define P54_PSM_SKIP_MORE_DATA BIT(4)
464#define P54_PSM_BEACON_TIMEOUT BIT(5)
465#define P54_PSM_HFOSLEEP BIT(6)
466#define P54_PSM_AUTOSWITCH_SLEEP BIT(7)
467#define P54_PSM_LPIT BIT(8)
468#define P54_PSM_BF_UCAST_SKIP BIT(9)
469#define P54_PSM_BF_MCAST_SKIP BIT(10)
470
471struct p54_psm {
472 __le16 mode;
473 __le16 aid;
474 struct p54_psm_interval intervals[4];
475 u8 beacon_rssi_skip_max;
476 u8 rssi_delta_threshold;
477 u8 nr;
478 u8 exclude[1];
479} __packed;
480
481#define MC_FILTER_ADDRESS_NUM 4
482
483struct p54_group_address_table {
484 __le16 filter_enable;
485 __le16 num_address;
486 u8 mac_list[MC_FILTER_ADDRESS_NUM][ETH_ALEN];
487} __packed;
488
489struct p54_txcancel {
490 __le32 req_id;
491} __packed;
492
493struct p54_sta_unlock {
494 u8 addr[ETH_ALEN];
495 u16 padding;
496} __packed;
497
498#define P54_TIM_CLEAR BIT(15)
499struct p54_tim {
500 u8 count;
501 u8 padding[3];
502 __le16 entry[8];
503} __packed;
504
505struct p54_cce_quiet {
506 __le32 period;
507} __packed;
508
509struct p54_bt_balancer {
510 __le16 prio_thresh;
511 __le16 acl_thresh;
512} __packed;
513
514struct p54_arp_table {
515 __le16 filter_enable;
516 u8 ipv4_addr[4];
517} __packed;
518
519/* LED control */
520int p54_set_leds(struct p54_common *priv);
521int p54_init_leds(struct p54_common *priv);
522void p54_unregister_leds(struct p54_common *priv);
523
524/* xmit functions */
525int p54_tx_80211(struct ieee80211_hw *dev, struct sk_buff *skb);
526int p54_tx_cancel(struct p54_common *priv, __le32 req_id);
527void p54_tx(struct p54_common *priv, struct sk_buff *skb);
528
529/* synth/phy configuration */
530int p54_init_xbow_synth(struct p54_common *priv);
531int p54_scan(struct p54_common *priv, u16 mode, u16 dwell);
532
533/* MAC */
534int p54_sta_unlock(struct p54_common *priv, u8 *addr);
535int p54_update_beacon_tim(struct p54_common *priv, u16 aid, bool set);
536int p54_setup_mac(struct p54_common *priv);
537int p54_set_ps(struct p54_common *priv);
538int p54_fetch_statistics(struct p54_common *priv);
539
540/* e/v DCF setup */
541int p54_set_edcf(struct p54_common *priv);
542
543/* cryptographic engine */
544int p54_upload_key(struct p54_common *priv, u8 algo, int slot,
545 u8 idx, u8 len, u8 *addr, u8* key);
546
547/* eeprom */
548int p54_download_eeprom(struct p54_common *priv, void *buf,
549 u16 offset, u16 len);
550
551#endif /* LMAC_H */
diff --git a/drivers/net/wireless/p54/main.c b/drivers/net/wireless/p54/main.c
new file mode 100644
index 000000000000..f9b4f6a238ea
--- /dev/null
+++ b/drivers/net/wireless/p54/main.c
@@ -0,0 +1,607 @@
1/*
2 * mac80211 glue code for mac80211 Prism54 drivers
3 *
4 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
5 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 *
8 * Based on:
9 * - the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
11 * - stlc45xx driver
12 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/init.h>
20#include <linux/firmware.h>
21#include <linux/etherdevice.h>
22
23#include <net/mac80211.h>
24
25#include "p54.h"
26#include "lmac.h"
27
28static int modparam_nohwcrypt;
29module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
30MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
31MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
32MODULE_DESCRIPTION("Softmac Prism54 common code");
33MODULE_LICENSE("GPL");
34MODULE_ALIAS("prism54common");
35
36static void p54_sta_notify(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
37 enum sta_notify_cmd notify_cmd,
38 struct ieee80211_sta *sta)
39{
40 struct p54_common *priv = dev->priv;
41 switch (notify_cmd) {
42 case STA_NOTIFY_ADD:
43 case STA_NOTIFY_REMOVE:
44 /*
45 * Notify the firmware that we don't want or we don't
46 * need to buffer frames for this station anymore.
47 */
48
49 p54_sta_unlock(priv, sta->addr);
50 break;
51 case STA_NOTIFY_AWAKE:
52 /* update the firmware's filter table */
53 p54_sta_unlock(priv, sta->addr);
54 break;
55 default:
56 break;
57 }
58}
59
60static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
61 bool set)
62{
63 struct p54_common *priv = dev->priv;
64
65 return p54_update_beacon_tim(priv, sta->aid, set);
66}
67
68static int p54_beacon_format_ie_tim(struct sk_buff *skb)
69{
70 /*
71 * the good excuse for this mess is ... the firmware.
72 * The dummy TIM MUST be at the end of the beacon frame,
73 * because it'll be overwritten!
74 */
75
76 struct ieee80211_mgmt *mgmt = (void *)skb->data;
77 u8 *pos, *end;
78
79 if (skb->len <= sizeof(mgmt))
80 return -EINVAL;
81
82 pos = (u8 *)mgmt->u.beacon.variable;
83 end = skb->data + skb->len;
84 while (pos < end) {
85 if (pos + 2 + pos[1] > end)
86 return -EINVAL;
87
88 if (pos[0] == WLAN_EID_TIM) {
89 u8 dtim_len = pos[1];
90 u8 dtim_period = pos[3];
91 u8 *next = pos + 2 + dtim_len;
92
93 if (dtim_len < 3)
94 return -EINVAL;
95
96 memmove(pos, next, end - next);
97
98 if (dtim_len > 3)
99 skb_trim(skb, skb->len - (dtim_len - 3));
100
101 pos = end - (dtim_len + 2);
102
103 /* add the dummy at the end */
104 pos[0] = WLAN_EID_TIM;
105 pos[1] = 3;
106 pos[2] = 0;
107 pos[3] = dtim_period;
108 pos[4] = 0;
109 return 0;
110 }
111 pos += 2 + pos[1];
112 }
113 return 0;
114}
115
116static int p54_beacon_update(struct p54_common *priv,
117 struct ieee80211_vif *vif)
118{
119 struct sk_buff *beacon;
120 __le32 old_beacon_req_id;
121 int ret;
122
123 beacon = ieee80211_beacon_get(priv->hw, vif);
124 if (!beacon)
125 return -ENOMEM;
126 ret = p54_beacon_format_ie_tim(beacon);
127 if (ret)
128 return ret;
129
130 old_beacon_req_id = priv->beacon_req_id;
131 priv->beacon_req_id = GET_REQ_ID(beacon);
132
133 ret = p54_tx_80211(priv->hw, beacon);
134 if (ret) {
135 priv->beacon_req_id = old_beacon_req_id;
136 return -ENOSPC;
137 }
138
139 priv->tsf_high32 = 0;
140 priv->tsf_low32 = 0;
141
142 return 0;
143}
144
145static int p54_start(struct ieee80211_hw *dev)
146{
147 struct p54_common *priv = dev->priv;
148 int err;
149
150 mutex_lock(&priv->conf_mutex);
151 err = priv->open(dev);
152 if (err)
153 goto out;
154 P54_SET_QUEUE(priv->qos_params[0], 0x0002, 0x0003, 0x0007, 47);
155 P54_SET_QUEUE(priv->qos_params[1], 0x0002, 0x0007, 0x000f, 94);
156 P54_SET_QUEUE(priv->qos_params[2], 0x0003, 0x000f, 0x03ff, 0);
157 P54_SET_QUEUE(priv->qos_params[3], 0x0007, 0x000f, 0x03ff, 0);
158 err = p54_set_edcf(priv);
159 if (err)
160 goto out;
161
162 memset(priv->bssid, ~0, ETH_ALEN);
163 priv->mode = NL80211_IFTYPE_MONITOR;
164 err = p54_setup_mac(priv);
165 if (err) {
166 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
167 goto out;
168 }
169
170 queue_delayed_work(dev->workqueue, &priv->work, 0);
171
172 priv->softled_state = 0;
173 err = p54_set_leds(priv);
174
175out:
176 mutex_unlock(&priv->conf_mutex);
177 return err;
178}
179
180static void p54_stop(struct ieee80211_hw *dev)
181{
182 struct p54_common *priv = dev->priv;
183 int i;
184
185 mutex_lock(&priv->conf_mutex);
186 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
187 priv->softled_state = 0;
188 p54_set_leds(priv);
189
190 cancel_delayed_work_sync(&priv->work);
191
192 priv->stop(dev);
193 skb_queue_purge(&priv->tx_pending);
194 skb_queue_purge(&priv->tx_queue);
195 for (i = 0; i < P54_QUEUE_NUM; i++) {
196 priv->tx_stats[i].count = 0;
197 priv->tx_stats[i].len = 0;
198 }
199
200 priv->beacon_req_id = cpu_to_le32(0);
201 priv->tsf_high32 = priv->tsf_low32 = 0;
202 mutex_unlock(&priv->conf_mutex);
203}
204
205static int p54_add_interface(struct ieee80211_hw *dev,
206 struct ieee80211_if_init_conf *conf)
207{
208 struct p54_common *priv = dev->priv;
209
210 mutex_lock(&priv->conf_mutex);
211 if (priv->mode != NL80211_IFTYPE_MONITOR) {
212 mutex_unlock(&priv->conf_mutex);
213 return -EOPNOTSUPP;
214 }
215
216 priv->vif = conf->vif;
217
218 switch (conf->type) {
219 case NL80211_IFTYPE_STATION:
220 case NL80211_IFTYPE_ADHOC:
221 case NL80211_IFTYPE_AP:
222 case NL80211_IFTYPE_MESH_POINT:
223 priv->mode = conf->type;
224 break;
225 default:
226 mutex_unlock(&priv->conf_mutex);
227 return -EOPNOTSUPP;
228 }
229
230 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
231 p54_setup_mac(priv);
232 mutex_unlock(&priv->conf_mutex);
233 return 0;
234}
235
236static void p54_remove_interface(struct ieee80211_hw *dev,
237 struct ieee80211_if_init_conf *conf)
238{
239 struct p54_common *priv = dev->priv;
240
241 mutex_lock(&priv->conf_mutex);
242 priv->vif = NULL;
243 if (priv->beacon_req_id) {
244 p54_tx_cancel(priv, priv->beacon_req_id);
245 priv->beacon_req_id = cpu_to_le32(0);
246 }
247 priv->mode = NL80211_IFTYPE_MONITOR;
248 memset(priv->mac_addr, 0, ETH_ALEN);
249 memset(priv->bssid, 0, ETH_ALEN);
250 p54_setup_mac(priv);
251 mutex_unlock(&priv->conf_mutex);
252}
253
254static int p54_config(struct ieee80211_hw *dev, u32 changed)
255{
256 int ret = 0;
257 struct p54_common *priv = dev->priv;
258 struct ieee80211_conf *conf = &dev->conf;
259
260 mutex_lock(&priv->conf_mutex);
261 if (changed & IEEE80211_CONF_CHANGE_POWER)
262 priv->output_power = conf->power_level << 2;
263 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
264 ret = p54_scan(priv, P54_SCAN_EXIT, 0);
265 if (ret)
266 goto out;
267 }
268 if (changed & IEEE80211_CONF_CHANGE_PS) {
269 ret = p54_set_ps(priv);
270 if (ret)
271 goto out;
272 }
273
274out:
275 mutex_unlock(&priv->conf_mutex);
276 return ret;
277}
278
279static void p54_configure_filter(struct ieee80211_hw *dev,
280 unsigned int changed_flags,
281 unsigned int *total_flags,
282 int mc_count, struct dev_mc_list *mclist)
283{
284 struct p54_common *priv = dev->priv;
285
286 *total_flags &= FIF_PROMISC_IN_BSS |
287 FIF_OTHER_BSS;
288
289 priv->filter_flags = *total_flags;
290
291 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS))
292 p54_setup_mac(priv);
293}
294
295static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue,
296 const struct ieee80211_tx_queue_params *params)
297{
298 struct p54_common *priv = dev->priv;
299 int ret;
300
301 mutex_lock(&priv->conf_mutex);
302 if ((params) && !(queue > 4)) {
303 P54_SET_QUEUE(priv->qos_params[queue], params->aifs,
304 params->cw_min, params->cw_max, params->txop);
305 ret = p54_set_edcf(priv);
306 } else
307 ret = -EINVAL;
308 mutex_unlock(&priv->conf_mutex);
309 return ret;
310}
311
312static void p54_work(struct work_struct *work)
313{
314 struct p54_common *priv = container_of(work, struct p54_common,
315 work.work);
316
317 if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
318 return ;
319
320 /*
321 * TODO: walk through tx_queue and do the following tasks
322 * 1. initiate bursts.
323 * 2. cancel stuck frames / reset the device if necessary.
324 */
325
326 p54_fetch_statistics(priv);
327}
328
329static int p54_get_stats(struct ieee80211_hw *dev,
330 struct ieee80211_low_level_stats *stats)
331{
332 struct p54_common *priv = dev->priv;
333
334 memcpy(stats, &priv->stats, sizeof(*stats));
335 return 0;
336}
337
338static int p54_get_tx_stats(struct ieee80211_hw *dev,
339 struct ieee80211_tx_queue_stats *stats)
340{
341 struct p54_common *priv = dev->priv;
342
343 memcpy(stats, &priv->tx_stats[P54_QUEUE_DATA],
344 sizeof(stats[0]) * dev->queues);
345 return 0;
346}
347
348static void p54_bss_info_changed(struct ieee80211_hw *dev,
349 struct ieee80211_vif *vif,
350 struct ieee80211_bss_conf *info,
351 u32 changed)
352{
353 struct p54_common *priv = dev->priv;
354
355 mutex_lock(&priv->conf_mutex);
356 if (changed & BSS_CHANGED_BSSID) {
357 memcpy(priv->bssid, info->bssid, ETH_ALEN);
358 p54_setup_mac(priv);
359 }
360
361 if (changed & BSS_CHANGED_BEACON) {
362 p54_scan(priv, P54_SCAN_EXIT, 0);
363 p54_setup_mac(priv);
364 p54_beacon_update(priv, vif);
365 p54_set_edcf(priv);
366 }
367
368 if (changed & (BSS_CHANGED_ERP_SLOT | BSS_CHANGED_BEACON)) {
369 priv->use_short_slot = info->use_short_slot;
370 p54_set_edcf(priv);
371 }
372 if (changed & BSS_CHANGED_BASIC_RATES) {
373 if (dev->conf.channel->band == IEEE80211_BAND_5GHZ)
374 priv->basic_rate_mask = (info->basic_rates << 4);
375 else
376 priv->basic_rate_mask = info->basic_rates;
377 p54_setup_mac(priv);
378 if (priv->fw_var >= 0x500)
379 p54_scan(priv, P54_SCAN_EXIT, 0);
380 }
381 if (changed & BSS_CHANGED_ASSOC) {
382 if (info->assoc) {
383 priv->aid = info->aid;
384 priv->wakeup_timer = info->beacon_int *
385 info->dtim_period * 5;
386 p54_setup_mac(priv);
387 }
388 }
389
390 mutex_unlock(&priv->conf_mutex);
391}
392
393static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
394 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
395 struct ieee80211_key_conf *key)
396{
397 struct p54_common *priv = dev->priv;
398 int slot, ret = 0;
399 u8 algo = 0;
400 u8 *addr = NULL;
401
402 if (modparam_nohwcrypt)
403 return -EOPNOTSUPP;
404
405 mutex_lock(&priv->conf_mutex);
406 if (cmd == SET_KEY) {
407 switch (key->alg) {
408 case ALG_TKIP:
409 if (!(priv->privacy_caps & (BR_DESC_PRIV_CAP_MICHAEL |
410 BR_DESC_PRIV_CAP_TKIP))) {
411 ret = -EOPNOTSUPP;
412 goto out_unlock;
413 }
414 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
415 algo = P54_CRYPTO_TKIPMICHAEL;
416 break;
417 case ALG_WEP:
418 if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_WEP)) {
419 ret = -EOPNOTSUPP;
420 goto out_unlock;
421 }
422 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
423 algo = P54_CRYPTO_WEP;
424 break;
425 case ALG_CCMP:
426 if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP)) {
427 ret = -EOPNOTSUPP;
428 goto out_unlock;
429 }
430 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
431 algo = P54_CRYPTO_AESCCMP;
432 break;
433 default:
434 ret = -EOPNOTSUPP;
435 goto out_unlock;
436 }
437 slot = bitmap_find_free_region(priv->used_rxkeys,
438 priv->rx_keycache_size, 0);
439
440 if (slot < 0) {
441 /*
442 * The device supports the choosen algorithm, but the
443 * firmware does not provide enough key slots to store
444 * all of them.
445 * But encryption offload for outgoing frames is always
446 * possible, so we just pretend that the upload was
447 * successful and do the decryption in software.
448 */
449
450 /* mark the key as invalid. */
451 key->hw_key_idx = 0xff;
452 goto out_unlock;
453 }
454 } else {
455 slot = key->hw_key_idx;
456
457 if (slot == 0xff) {
458 /* This key was not uploaded into the rx key cache. */
459
460 goto out_unlock;
461 }
462
463 bitmap_release_region(priv->used_rxkeys, slot, 0);
464 algo = 0;
465 }
466
467 if (sta)
468 addr = sta->addr;
469
470 ret = p54_upload_key(priv, algo, slot, key->keyidx,
471 key->keylen, addr, key->key);
472 if (ret) {
473 bitmap_release_region(priv->used_rxkeys, slot, 0);
474 ret = -EOPNOTSUPP;
475 goto out_unlock;
476 }
477
478 key->hw_key_idx = slot;
479
480out_unlock:
481 mutex_unlock(&priv->conf_mutex);
482 return ret;
483}
484
485static const struct ieee80211_ops p54_ops = {
486 .tx = p54_tx_80211,
487 .start = p54_start,
488 .stop = p54_stop,
489 .add_interface = p54_add_interface,
490 .remove_interface = p54_remove_interface,
491 .set_tim = p54_set_tim,
492 .sta_notify = p54_sta_notify,
493 .set_key = p54_set_key,
494 .config = p54_config,
495 .bss_info_changed = p54_bss_info_changed,
496 .configure_filter = p54_configure_filter,
497 .conf_tx = p54_conf_tx,
498 .get_stats = p54_get_stats,
499 .get_tx_stats = p54_get_tx_stats
500};
501
502struct ieee80211_hw *p54_init_common(size_t priv_data_len)
503{
504 struct ieee80211_hw *dev;
505 struct p54_common *priv;
506
507 dev = ieee80211_alloc_hw(priv_data_len, &p54_ops);
508 if (!dev)
509 return NULL;
510
511 priv = dev->priv;
512 priv->hw = dev;
513 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
514 priv->basic_rate_mask = 0x15f;
515 spin_lock_init(&priv->tx_stats_lock);
516 skb_queue_head_init(&priv->tx_queue);
517 skb_queue_head_init(&priv->tx_pending);
518 dev->flags = IEEE80211_HW_RX_INCLUDES_FCS |
519 IEEE80211_HW_SIGNAL_DBM |
520 IEEE80211_HW_NOISE_DBM;
521
522 dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
523 BIT(NL80211_IFTYPE_ADHOC) |
524 BIT(NL80211_IFTYPE_AP) |
525 BIT(NL80211_IFTYPE_MESH_POINT);
526
527 dev->channel_change_time = 1000; /* TODO: find actual value */
528 priv->tx_stats[P54_QUEUE_BEACON].limit = 1;
529 priv->tx_stats[P54_QUEUE_FWSCAN].limit = 1;
530 priv->tx_stats[P54_QUEUE_MGMT].limit = 3;
531 priv->tx_stats[P54_QUEUE_CAB].limit = 3;
532 priv->tx_stats[P54_QUEUE_DATA].limit = 5;
533 dev->queues = 1;
534 priv->noise = -94;
535 /*
536 * We support at most 8 tries no matter which rate they're at,
537 * we cannot support max_rates * max_rate_tries as we set it
538 * here, but setting it correctly to 4/2 or so would limit us
539 * artificially if the RC algorithm wants just two rates, so
540 * let's say 4/7, we'll redistribute it at TX time, see the
541 * comments there.
542 */
543 dev->max_rates = 4;
544 dev->max_rate_tries = 7;
545 dev->extra_tx_headroom = sizeof(struct p54_hdr) + 4 +
546 sizeof(struct p54_tx_data);
547
548 mutex_init(&priv->conf_mutex);
549 mutex_init(&priv->eeprom_mutex);
550 init_completion(&priv->eeprom_comp);
551 INIT_DELAYED_WORK(&priv->work, p54_work);
552
553 return dev;
554}
555EXPORT_SYMBOL_GPL(p54_init_common);
556
557int p54_register_common(struct ieee80211_hw *dev, struct device *pdev)
558{
559 struct p54_common *priv = dev->priv;
560 int err;
561
562 err = ieee80211_register_hw(dev);
563 if (err) {
564 dev_err(pdev, "Cannot register device (%d).\n", err);
565 return err;
566 }
567
568#ifdef CONFIG_P54_LEDS
569 err = p54_init_leds(priv);
570 if (err)
571 return err;
572#endif /* CONFIG_P54_LEDS */
573
574 dev_info(pdev, "is registered as '%s'\n", wiphy_name(dev->wiphy));
575 return 0;
576}
577EXPORT_SYMBOL_GPL(p54_register_common);
578
579void p54_free_common(struct ieee80211_hw *dev)
580{
581 struct p54_common *priv = dev->priv;
582
583 kfree(priv->iq_autocal);
584 kfree(priv->output_limit);
585 kfree(priv->curve_data);
586 kfree(priv->used_rxkeys);
587 priv->iq_autocal = NULL;
588 priv->output_limit = NULL;
589 priv->curve_data = NULL;
590 priv->used_rxkeys = NULL;
591 ieee80211_free_hw(dev);
592}
593EXPORT_SYMBOL_GPL(p54_free_common);
594
595void p54_unregister_common(struct ieee80211_hw *dev)
596{
597 struct p54_common *priv = dev->priv;
598
599#ifdef CONFIG_P54_LEDS
600 p54_unregister_leds(priv);
601#endif /* CONFIG_P54_LEDS */
602
603 ieee80211_unregister_hw(dev);
604 mutex_destroy(&priv->conf_mutex);
605 mutex_destroy(&priv->eeprom_mutex);
606}
607EXPORT_SYMBOL_GPL(p54_unregister_common);
diff --git a/drivers/net/wireless/p54/p54.h b/drivers/net/wireless/p54/p54.h
index db3df947d8ed..19d085c73d7d 100644
--- a/drivers/net/wireless/p54/p54.h
+++ b/drivers/net/wireless/p54/p54.h
@@ -1,6 +1,3 @@
1#ifndef P54_H
2#define P54_H
3
4/* 1/*
5 * Shared defines for all mac80211 Prism54 code 2 * Shared defines for all mac80211 Prism54 code
6 * 3 *
@@ -14,39 +11,78 @@
14 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
15 */ 12 */
16 13
14#ifndef P54_H
15#define P54_H
16
17#ifdef CONFIG_P54_LEDS 17#ifdef CONFIG_P54_LEDS
18#include <linux/leds.h> 18#include <linux/leds.h>
19#endif /* CONFIG_P54_LEDS */ 19#endif /* CONFIG_P54_LEDS */
20 20
21enum p54_control_frame_types { 21#define ISL38XX_DEV_FIRMWARE_ADDR 0x20000
22 P54_CONTROL_TYPE_SETUP = 0, 22
23 P54_CONTROL_TYPE_SCAN, 23#define BR_CODE_MIN 0x80000000
24 P54_CONTROL_TYPE_TRAP, 24#define BR_CODE_COMPONENT_ID 0x80000001
25 P54_CONTROL_TYPE_DCFINIT, 25#define BR_CODE_COMPONENT_VERSION 0x80000002
26 P54_CONTROL_TYPE_RX_KEYCACHE, 26#define BR_CODE_DEPENDENT_IF 0x80000003
27 P54_CONTROL_TYPE_TIM, 27#define BR_CODE_EXPOSED_IF 0x80000004
28 P54_CONTROL_TYPE_PSM, 28#define BR_CODE_DESCR 0x80000101
29 P54_CONTROL_TYPE_TXCANCEL, 29#define BR_CODE_MAX 0x8FFFFFFF
30 P54_CONTROL_TYPE_TXDONE, 30#define BR_CODE_END_OF_BRA 0xFF0000FF
31 P54_CONTROL_TYPE_BURST, 31#define LEGACY_BR_CODE_END_OF_BRA 0xFFFFFFFF
32 P54_CONTROL_TYPE_STAT_READBACK, 32
33 P54_CONTROL_TYPE_BBP, 33struct bootrec {
34 P54_CONTROL_TYPE_EEPROM_READBACK, 34 __le32 code;
35 P54_CONTROL_TYPE_LED, 35 __le32 len;
36 P54_CONTROL_TYPE_GPIO, 36 u32 data[10];
37 P54_CONTROL_TYPE_TIMER, 37} __packed;
38 P54_CONTROL_TYPE_MODULATION, 38
39 P54_CONTROL_TYPE_SYNTH_CONFIG, 39/* Interface role definitions */
40 P54_CONTROL_TYPE_DETECTOR_VALUE, 40#define BR_INTERFACE_ROLE_SERVER 0x0000
41 P54_CONTROL_TYPE_XBOW_SYNTH_CFG, 41#define BR_INTERFACE_ROLE_CLIENT 0x8000
42 P54_CONTROL_TYPE_CCE_QUIET, 42
43 P54_CONTROL_TYPE_PSM_STA_UNLOCK, 43#define BR_DESC_PRIV_CAP_WEP BIT(0)
44 P54_CONTROL_TYPE_PCS, 44#define BR_DESC_PRIV_CAP_TKIP BIT(1)
45 P54_CONTROL_TYPE_BT_BALANCER = 28, 45#define BR_DESC_PRIV_CAP_MICHAEL BIT(2)
46 P54_CONTROL_TYPE_GROUP_ADDRESS_TABLE = 30, 46#define BR_DESC_PRIV_CAP_CCX_CP BIT(3)
47 P54_CONTROL_TYPE_ARPTABLE = 31, 47#define BR_DESC_PRIV_CAP_CCX_MIC BIT(4)
48 P54_CONTROL_TYPE_BT_OPTIONS = 35 48#define BR_DESC_PRIV_CAP_AESCCMP BIT(5)
49}; 49
50struct bootrec_desc {
51 __le16 modes;
52 __le16 flags;
53 __le32 rx_start;
54 __le32 rx_end;
55 u8 headroom;
56 u8 tailroom;
57 u8 tx_queues;
58 u8 tx_depth;
59 u8 privacy_caps;
60 u8 rx_keycache_size;
61 u8 time_size;
62 u8 padding;
63 u8 rates[16];
64 u8 padding2[4];
65 __le16 rx_mtu;
66} __packed;
67
68#define FW_FMAC 0x464d4143
69#define FW_LM86 0x4c4d3836
70#define FW_LM87 0x4c4d3837
71#define FW_LM20 0x4c4d3230
72
73struct bootrec_comp_id {
74 __le32 fw_variant;
75} __packed;
76
77struct bootrec_comp_ver {
78 char fw_version[24];
79} __packed;
80
81struct bootrec_end {
82 __le16 crc;
83 u8 padding[2];
84 u8 md5[16];
85} __packed;
50 86
51/* provide 16 bytes for the transport back-end */ 87/* provide 16 bytes for the transport back-end */
52#define P54_TX_INFO_DATA_SIZE 16 88#define P54_TX_INFO_DATA_SIZE 16
@@ -55,34 +91,30 @@ enum p54_control_frame_types {
55struct p54_tx_info { 91struct p54_tx_info {
56 u32 start_addr; 92 u32 start_addr;
57 u32 end_addr; 93 u32 end_addr;
58 void *data[P54_TX_INFO_DATA_SIZE / sizeof(void *)]; 94 union {
95 void *data[P54_TX_INFO_DATA_SIZE / sizeof(void *)];
96 struct {
97 u32 extra_len;
98 };
99 };
59}; 100};
60 101
61#define P54_MAX_CTRL_FRAME_LEN 0x1000 102#define P54_MAX_CTRL_FRAME_LEN 0x1000
62 103
63#define P54_HDR_FLAG_CONTROL BIT(15) 104#define P54_SET_QUEUE(queue, ai_fs, cw_min, cw_max, _txop) \
64#define P54_HDR_FLAG_CONTROL_OPSET (BIT(15) + BIT(0)) 105do { \
65 106 queue.aifs = cpu_to_le16(ai_fs); \
66struct p54_hdr { 107 queue.cwmin = cpu_to_le16(cw_min); \
67 __le16 flags; 108 queue.cwmax = cpu_to_le16(cw_max); \
68 __le16 len; 109 queue.txop = cpu_to_le16(_txop); \
69 __le32 req_id; 110} while (0)
70 __le16 type; /* enum p54_control_frame_types */
71 u8 rts_tries;
72 u8 tries;
73 u8 data[0];
74} __attribute__ ((packed));
75
76#define FREE_AFTER_TX(skb) \
77 ((((struct p54_hdr *) ((struct sk_buff *) skb)->data)-> \
78 flags) == cpu_to_le16(P54_HDR_FLAG_CONTROL_OPSET))
79 111
80struct p54_edcf_queue_param { 112struct p54_edcf_queue_param {
81 __le16 aifs; 113 __le16 aifs;
82 __le16 cwmin; 114 __le16 cwmin;
83 __le16 cwmax; 115 __le16 cwmax;
84 __le16 txop; 116 __le16 txop;
85} __attribute__ ((packed)); 117} __packed;
86 118
87struct p54_rssi_linear_approximation { 119struct p54_rssi_linear_approximation {
88 s16 mul; 120 s16 mul;
@@ -101,13 +133,6 @@ struct p54_cal_database {
101 133
102#define EEPROM_READBACK_LEN 0x3fc 134#define EEPROM_READBACK_LEN 0x3fc
103 135
104#define ISL38XX_DEV_FIRMWARE_ADDR 0x20000
105
106#define FW_FMAC 0x464d4143
107#define FW_LM86 0x4c4d3836
108#define FW_LM87 0x4c4d3837
109#define FW_LM20 0x4c4d3230
110
111enum fw_state { 136enum fw_state {
112 FW_STATE_OFF, 137 FW_STATE_OFF,
113 FW_STATE_BOOTING, 138 FW_STATE_BOOTING,
@@ -138,6 +163,7 @@ struct p54_common {
138 void (*tx)(struct ieee80211_hw *dev, struct sk_buff *skb); 163 void (*tx)(struct ieee80211_hw *dev, struct sk_buff *skb);
139 int (*open)(struct ieee80211_hw *dev); 164 int (*open)(struct ieee80211_hw *dev);
140 void (*stop)(struct ieee80211_hw *dev); 165 void (*stop)(struct ieee80211_hw *dev);
166 struct sk_buff_head tx_pending;
141 struct sk_buff_head tx_queue; 167 struct sk_buff_head tx_queue;
142 struct mutex conf_mutex; 168 struct mutex conf_mutex;
143 169
@@ -156,6 +182,7 @@ struct p54_common {
156 182
157 /* (e)DCF / QOS state */ 183 /* (e)DCF / QOS state */
158 bool use_short_slot; 184 bool use_short_slot;
185 spinlock_t tx_stats_lock;
159 struct ieee80211_tx_queue_stats tx_stats[8]; 186 struct ieee80211_tx_queue_stats tx_stats[8];
160 struct p54_edcf_queue_param qos_params[8]; 187 struct p54_edcf_queue_param qos_params[8];
161 188
@@ -181,7 +208,7 @@ struct p54_common {
181 u32 tsf_low32, tsf_high32; 208 u32 tsf_low32, tsf_high32;
182 u32 basic_rate_mask; 209 u32 basic_rate_mask;
183 u16 aid; 210 u16 aid;
184 struct sk_buff *cached_beacon; 211 __le32 beacon_req_id;
185 212
186 /* cryptographic engine information */ 213 /* cryptographic engine information */
187 u8 privacy_caps; 214 u8 privacy_caps;
@@ -202,15 +229,20 @@ struct p54_common {
202 /* eeprom handling */ 229 /* eeprom handling */
203 void *eeprom; 230 void *eeprom;
204 struct completion eeprom_comp; 231 struct completion eeprom_comp;
232 struct mutex eeprom_mutex;
205}; 233};
206 234
235/* interfaces for the drivers */
207int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb); 236int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb);
208void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb); 237void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb);
209int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw); 238int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw);
210int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len); 239int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len);
211int p54_read_eeprom(struct ieee80211_hw *dev); 240int p54_read_eeprom(struct ieee80211_hw *dev);
241
212struct ieee80211_hw *p54_init_common(size_t priv_data_len); 242struct ieee80211_hw *p54_init_common(size_t priv_data_len);
213int p54_register_common(struct ieee80211_hw *dev, struct device *pdev); 243int p54_register_common(struct ieee80211_hw *dev, struct device *pdev);
214void p54_free_common(struct ieee80211_hw *dev); 244void p54_free_common(struct ieee80211_hw *dev);
215 245
246void p54_unregister_common(struct ieee80211_hw *dev);
247
216#endif /* P54_H */ 248#endif /* P54_H */
diff --git a/drivers/net/wireless/p54/p54common.c b/drivers/net/wireless/p54/p54common.c
deleted file mode 100644
index 22ca122bd798..000000000000
--- a/drivers/net/wireless/p54/p54common.c
+++ /dev/null
@@ -1,2688 +0,0 @@
1/*
2 * Common code for mac80211 Prism54 drivers
3 *
4 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
5 * Copyright (c) 2007, Christian Lamparter <chunkeey@web.de>
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 *
8 * Based on:
9 * - the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
11 * - stlc45xx driver
12 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/init.h>
20#include <linux/firmware.h>
21#include <linux/etherdevice.h>
22
23#include <net/mac80211.h>
24#ifdef CONFIG_P54_LEDS
25#include <linux/leds.h>
26#endif /* CONFIG_P54_LEDS */
27
28#include "p54.h"
29#include "p54common.h"
30
31static int modparam_nohwcrypt;
32module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
33MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
34MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
35MODULE_DESCRIPTION("Softmac Prism54 common code");
36MODULE_LICENSE("GPL");
37MODULE_ALIAS("prism54common");
38
39static struct ieee80211_rate p54_bgrates[] = {
40 { .bitrate = 10, .hw_value = 0, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
41 { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
42 { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
43 { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
44 { .bitrate = 60, .hw_value = 4, },
45 { .bitrate = 90, .hw_value = 5, },
46 { .bitrate = 120, .hw_value = 6, },
47 { .bitrate = 180, .hw_value = 7, },
48 { .bitrate = 240, .hw_value = 8, },
49 { .bitrate = 360, .hw_value = 9, },
50 { .bitrate = 480, .hw_value = 10, },
51 { .bitrate = 540, .hw_value = 11, },
52};
53
54static struct ieee80211_channel p54_bgchannels[] = {
55 { .center_freq = 2412, .hw_value = 1, },
56 { .center_freq = 2417, .hw_value = 2, },
57 { .center_freq = 2422, .hw_value = 3, },
58 { .center_freq = 2427, .hw_value = 4, },
59 { .center_freq = 2432, .hw_value = 5, },
60 { .center_freq = 2437, .hw_value = 6, },
61 { .center_freq = 2442, .hw_value = 7, },
62 { .center_freq = 2447, .hw_value = 8, },
63 { .center_freq = 2452, .hw_value = 9, },
64 { .center_freq = 2457, .hw_value = 10, },
65 { .center_freq = 2462, .hw_value = 11, },
66 { .center_freq = 2467, .hw_value = 12, },
67 { .center_freq = 2472, .hw_value = 13, },
68 { .center_freq = 2484, .hw_value = 14, },
69};
70
71static struct ieee80211_supported_band band_2GHz = {
72 .channels = p54_bgchannels,
73 .n_channels = ARRAY_SIZE(p54_bgchannels),
74 .bitrates = p54_bgrates,
75 .n_bitrates = ARRAY_SIZE(p54_bgrates),
76};
77
78static struct ieee80211_rate p54_arates[] = {
79 { .bitrate = 60, .hw_value = 4, },
80 { .bitrate = 90, .hw_value = 5, },
81 { .bitrate = 120, .hw_value = 6, },
82 { .bitrate = 180, .hw_value = 7, },
83 { .bitrate = 240, .hw_value = 8, },
84 { .bitrate = 360, .hw_value = 9, },
85 { .bitrate = 480, .hw_value = 10, },
86 { .bitrate = 540, .hw_value = 11, },
87};
88
89static struct ieee80211_channel p54_achannels[] = {
90 { .center_freq = 4920 },
91 { .center_freq = 4940 },
92 { .center_freq = 4960 },
93 { .center_freq = 4980 },
94 { .center_freq = 5040 },
95 { .center_freq = 5060 },
96 { .center_freq = 5080 },
97 { .center_freq = 5170 },
98 { .center_freq = 5180 },
99 { .center_freq = 5190 },
100 { .center_freq = 5200 },
101 { .center_freq = 5210 },
102 { .center_freq = 5220 },
103 { .center_freq = 5230 },
104 { .center_freq = 5240 },
105 { .center_freq = 5260 },
106 { .center_freq = 5280 },
107 { .center_freq = 5300 },
108 { .center_freq = 5320 },
109 { .center_freq = 5500 },
110 { .center_freq = 5520 },
111 { .center_freq = 5540 },
112 { .center_freq = 5560 },
113 { .center_freq = 5580 },
114 { .center_freq = 5600 },
115 { .center_freq = 5620 },
116 { .center_freq = 5640 },
117 { .center_freq = 5660 },
118 { .center_freq = 5680 },
119 { .center_freq = 5700 },
120 { .center_freq = 5745 },
121 { .center_freq = 5765 },
122 { .center_freq = 5785 },
123 { .center_freq = 5805 },
124 { .center_freq = 5825 },
125};
126
127static struct ieee80211_supported_band band_5GHz = {
128 .channels = p54_achannels,
129 .n_channels = ARRAY_SIZE(p54_achannels),
130 .bitrates = p54_arates,
131 .n_bitrates = ARRAY_SIZE(p54_arates),
132};
133
134int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
135{
136 struct p54_common *priv = dev->priv;
137 struct bootrec_exp_if *exp_if;
138 struct bootrec *bootrec;
139 u32 *data = (u32 *)fw->data;
140 u32 *end_data = (u32 *)fw->data + (fw->size >> 2);
141 u8 *fw_version = NULL;
142 size_t len;
143 int i;
144 int maxlen;
145
146 if (priv->rx_start)
147 return 0;
148
149 while (data < end_data && *data)
150 data++;
151
152 while (data < end_data && !*data)
153 data++;
154
155 bootrec = (struct bootrec *) data;
156
157 while (bootrec->data <= end_data &&
158 (bootrec->data + (len = le32_to_cpu(bootrec->len))) <= end_data) {
159 u32 code = le32_to_cpu(bootrec->code);
160 switch (code) {
161 case BR_CODE_COMPONENT_ID:
162 priv->fw_interface = be32_to_cpup((__be32 *)
163 bootrec->data);
164 switch (priv->fw_interface) {
165 case FW_LM86:
166 case FW_LM20:
167 case FW_LM87: {
168 char *iftype = (char *)bootrec->data;
169 printk(KERN_INFO "%s: p54 detected a LM%c%c "
170 "firmware\n",
171 wiphy_name(dev->wiphy),
172 iftype[2], iftype[3]);
173 break;
174 }
175 case FW_FMAC:
176 default:
177 printk(KERN_ERR "%s: unsupported firmware\n",
178 wiphy_name(dev->wiphy));
179 return -ENODEV;
180 }
181 break;
182 case BR_CODE_COMPONENT_VERSION:
183 /* 24 bytes should be enough for all firmwares */
184 if (strnlen((unsigned char*)bootrec->data, 24) < 24)
185 fw_version = (unsigned char*)bootrec->data;
186 break;
187 case BR_CODE_DESCR: {
188 struct bootrec_desc *desc =
189 (struct bootrec_desc *)bootrec->data;
190 priv->rx_start = le32_to_cpu(desc->rx_start);
191 /* FIXME add sanity checking */
192 priv->rx_end = le32_to_cpu(desc->rx_end) - 0x3500;
193 priv->headroom = desc->headroom;
194 priv->tailroom = desc->tailroom;
195 priv->privacy_caps = desc->privacy_caps;
196 priv->rx_keycache_size = desc->rx_keycache_size;
197 if (le32_to_cpu(bootrec->len) == 11)
198 priv->rx_mtu = le16_to_cpu(desc->rx_mtu);
199 else
200 priv->rx_mtu = (size_t)
201 0x620 - priv->tx_hdr_len;
202 maxlen = priv->tx_hdr_len + /* USB devices */
203 sizeof(struct p54_rx_data) +
204 4 + /* rx alignment */
205 IEEE80211_MAX_FRAG_THRESHOLD;
206 if (priv->rx_mtu > maxlen && PAGE_SIZE == 4096) {
207 printk(KERN_INFO "p54: rx_mtu reduced from %d "
208 "to %d\n", priv->rx_mtu,
209 maxlen);
210 priv->rx_mtu = maxlen;
211 }
212 break;
213 }
214 case BR_CODE_EXPOSED_IF:
215 exp_if = (struct bootrec_exp_if *) bootrec->data;
216 for (i = 0; i < (len * sizeof(*exp_if) / 4); i++)
217 if (exp_if[i].if_id == cpu_to_le16(0x1a))
218 priv->fw_var = le16_to_cpu(exp_if[i].variant);
219 break;
220 case BR_CODE_DEPENDENT_IF:
221 break;
222 case BR_CODE_END_OF_BRA:
223 case LEGACY_BR_CODE_END_OF_BRA:
224 end_data = NULL;
225 break;
226 default:
227 break;
228 }
229 bootrec = (struct bootrec *)&bootrec->data[len];
230 }
231
232 if (fw_version)
233 printk(KERN_INFO "%s: FW rev %s - Softmac protocol %x.%x\n",
234 wiphy_name(dev->wiphy), fw_version,
235 priv->fw_var >> 8, priv->fw_var & 0xff);
236
237 if (priv->fw_var < 0x500)
238 printk(KERN_INFO "%s: you are using an obsolete firmware. "
239 "visit http://wireless.kernel.org/en/users/Drivers/p54 "
240 "and grab one for \"kernel >= 2.6.28\"!\n",
241 wiphy_name(dev->wiphy));
242
243 if (priv->fw_var >= 0x300) {
244 /* Firmware supports QoS, use it! */
245 priv->tx_stats[P54_QUEUE_AC_VO].limit = 3;
246 priv->tx_stats[P54_QUEUE_AC_VI].limit = 4;
247 priv->tx_stats[P54_QUEUE_AC_BE].limit = 3;
248 priv->tx_stats[P54_QUEUE_AC_BK].limit = 2;
249 dev->queues = P54_QUEUE_AC_NUM;
250 }
251
252 if (!modparam_nohwcrypt) {
253 printk(KERN_INFO "%s: cryptographic accelerator "
254 "WEP:%s, TKIP:%s, CCMP:%s\n",
255 wiphy_name(dev->wiphy),
256 (priv->privacy_caps & BR_DESC_PRIV_CAP_WEP) ? "YES" :
257 "no", (priv->privacy_caps & (BR_DESC_PRIV_CAP_TKIP |
258 BR_DESC_PRIV_CAP_MICHAEL)) ? "YES" : "no",
259 (priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP) ?
260 "YES" : "no");
261
262 if (priv->rx_keycache_size) {
263 /*
264 * NOTE:
265 *
266 * The firmware provides at most 255 (0 - 254) slots
267 * for keys which are then used to offload decryption.
268 * As a result the 255 entry (aka 0xff) can be used
269 * safely by the driver to mark keys that didn't fit
270 * into the full cache. This trick saves us from
271 * keeping a extra list for uploaded keys.
272 */
273
274 priv->used_rxkeys = kzalloc(BITS_TO_LONGS(
275 priv->rx_keycache_size), GFP_KERNEL);
276
277 if (!priv->used_rxkeys)
278 return -ENOMEM;
279 }
280 }
281
282 return 0;
283}
284EXPORT_SYMBOL_GPL(p54_parse_firmware);
285
286static int p54_convert_rev0(struct ieee80211_hw *dev,
287 struct pda_pa_curve_data *curve_data)
288{
289 struct p54_common *priv = dev->priv;
290 struct p54_pa_curve_data_sample *dst;
291 struct pda_pa_curve_data_sample_rev0 *src;
292 size_t cd_len = sizeof(*curve_data) +
293 (curve_data->points_per_channel*sizeof(*dst) + 2) *
294 curve_data->channels;
295 unsigned int i, j;
296 void *source, *target;
297
298 priv->curve_data = kmalloc(sizeof(*priv->curve_data) + cd_len,
299 GFP_KERNEL);
300 if (!priv->curve_data)
301 return -ENOMEM;
302
303 priv->curve_data->entries = curve_data->channels;
304 priv->curve_data->entry_size = sizeof(__le16) +
305 sizeof(*dst) * curve_data->points_per_channel;
306 priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data);
307 priv->curve_data->len = cd_len;
308 memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data));
309 source = curve_data->data;
310 target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data;
311 for (i = 0; i < curve_data->channels; i++) {
312 __le16 *freq = source;
313 source += sizeof(__le16);
314 *((__le16 *)target) = *freq;
315 target += sizeof(__le16);
316 for (j = 0; j < curve_data->points_per_channel; j++) {
317 dst = target;
318 src = source;
319
320 dst->rf_power = src->rf_power;
321 dst->pa_detector = src->pa_detector;
322 dst->data_64qam = src->pcv;
323 /* "invent" the points for the other modulations */
324#define SUB(x,y) (u8)((x) - (y)) > (x) ? 0 : (x) - (y)
325 dst->data_16qam = SUB(src->pcv, 12);
326 dst->data_qpsk = SUB(dst->data_16qam, 12);
327 dst->data_bpsk = SUB(dst->data_qpsk, 12);
328 dst->data_barker = SUB(dst->data_bpsk, 14);
329#undef SUB
330 target += sizeof(*dst);
331 source += sizeof(*src);
332 }
333 }
334
335 return 0;
336}
337
338static int p54_convert_rev1(struct ieee80211_hw *dev,
339 struct pda_pa_curve_data *curve_data)
340{
341 struct p54_common *priv = dev->priv;
342 struct p54_pa_curve_data_sample *dst;
343 struct pda_pa_curve_data_sample_rev1 *src;
344 size_t cd_len = sizeof(*curve_data) +
345 (curve_data->points_per_channel*sizeof(*dst) + 2) *
346 curve_data->channels;
347 unsigned int i, j;
348 void *source, *target;
349
350 priv->curve_data = kzalloc(cd_len + sizeof(*priv->curve_data),
351 GFP_KERNEL);
352 if (!priv->curve_data)
353 return -ENOMEM;
354
355 priv->curve_data->entries = curve_data->channels;
356 priv->curve_data->entry_size = sizeof(__le16) +
357 sizeof(*dst) * curve_data->points_per_channel;
358 priv->curve_data->offset = offsetof(struct pda_pa_curve_data, data);
359 priv->curve_data->len = cd_len;
360 memcpy(priv->curve_data->data, curve_data, sizeof(*curve_data));
361 source = curve_data->data;
362 target = ((struct pda_pa_curve_data *) priv->curve_data->data)->data;
363 for (i = 0; i < curve_data->channels; i++) {
364 __le16 *freq = source;
365 source += sizeof(__le16);
366 *((__le16 *)target) = *freq;
367 target += sizeof(__le16);
368 for (j = 0; j < curve_data->points_per_channel; j++) {
369 memcpy(target, source, sizeof(*src));
370
371 target += sizeof(*dst);
372 source += sizeof(*src);
373 }
374 source++;
375 }
376
377 return 0;
378}
379
380static const char *p54_rf_chips[] = { "NULL", "Duette3", "Duette2",
381 "Frisbee", "Xbow", "Longbow", "NULL", "NULL" };
382static int p54_init_xbow_synth(struct ieee80211_hw *dev);
383
384static void p54_parse_rssical(struct ieee80211_hw *dev, void *data, int len,
385 u16 type)
386{
387 struct p54_common *priv = dev->priv;
388 int offset = (type == PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED) ? 2 : 0;
389 int entry_size = sizeof(struct pda_rssi_cal_entry) + offset;
390 int num_entries = (type == PDR_RSSI_LINEAR_APPROXIMATION) ? 1 : 2;
391 int i;
392
393 if (len != (entry_size * num_entries)) {
394 printk(KERN_ERR "%s: unknown rssi calibration data packing "
395 " type:(%x) len:%d.\n",
396 wiphy_name(dev->wiphy), type, len);
397
398 print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE,
399 data, len);
400
401 printk(KERN_ERR "%s: please report this issue.\n",
402 wiphy_name(dev->wiphy));
403 return;
404 }
405
406 for (i = 0; i < num_entries; i++) {
407 struct pda_rssi_cal_entry *cal = data +
408 (offset + i * entry_size);
409 priv->rssical_db[i].mul = (s16) le16_to_cpu(cal->mul);
410 priv->rssical_db[i].add = (s16) le16_to_cpu(cal->add);
411 }
412}
413
414static void p54_parse_default_country(struct ieee80211_hw *dev,
415 void *data, int len)
416{
417 struct pda_country *country;
418
419 if (len != sizeof(*country)) {
420 printk(KERN_ERR "%s: found possible invalid default country "
421 "eeprom entry. (entry size: %d)\n",
422 wiphy_name(dev->wiphy), len);
423
424 print_hex_dump_bytes("country:", DUMP_PREFIX_NONE,
425 data, len);
426
427 printk(KERN_ERR "%s: please report this issue.\n",
428 wiphy_name(dev->wiphy));
429 return;
430 }
431
432 country = (struct pda_country *) data;
433 if (country->flags == PDR_COUNTRY_CERT_CODE_PSEUDO)
434 regulatory_hint(dev->wiphy, country->alpha2);
435 else {
436 /* TODO:
437 * write a shared/common function that converts
438 * "Regulatory domain codes" (802.11-2007 14.8.2.2)
439 * into ISO/IEC 3166-1 alpha2 for regulatory_hint.
440 */
441 }
442}
443
444static int p54_convert_output_limits(struct ieee80211_hw *dev,
445 u8 *data, size_t len)
446{
447 struct p54_common *priv = dev->priv;
448
449 if (len < 2)
450 return -EINVAL;
451
452 if (data[0] != 0) {
453 printk(KERN_ERR "%s: unknown output power db revision:%x\n",
454 wiphy_name(dev->wiphy), data[0]);
455 return -EINVAL;
456 }
457
458 if (2 + data[1] * sizeof(struct pda_channel_output_limit) > len)
459 return -EINVAL;
460
461 priv->output_limit = kmalloc(data[1] *
462 sizeof(struct pda_channel_output_limit) +
463 sizeof(*priv->output_limit), GFP_KERNEL);
464
465 if (!priv->output_limit)
466 return -ENOMEM;
467
468 priv->output_limit->offset = 0;
469 priv->output_limit->entries = data[1];
470 priv->output_limit->entry_size =
471 sizeof(struct pda_channel_output_limit);
472 priv->output_limit->len = priv->output_limit->entry_size *
473 priv->output_limit->entries +
474 priv->output_limit->offset;
475
476 memcpy(priv->output_limit->data, &data[2],
477 data[1] * sizeof(struct pda_channel_output_limit));
478
479 return 0;
480}
481
482static struct p54_cal_database *p54_convert_db(struct pda_custom_wrapper *src,
483 size_t total_len)
484{
485 struct p54_cal_database *dst;
486 size_t payload_len, entries, entry_size, offset;
487
488 payload_len = le16_to_cpu(src->len);
489 entries = le16_to_cpu(src->entries);
490 entry_size = le16_to_cpu(src->entry_size);
491 offset = le16_to_cpu(src->offset);
492 if (((entries * entry_size + offset) != payload_len) ||
493 (payload_len + sizeof(*src) != total_len))
494 return NULL;
495
496 dst = kmalloc(sizeof(*dst) + payload_len, GFP_KERNEL);
497 if (!dst)
498 return NULL;
499
500 dst->entries = entries;
501 dst->entry_size = entry_size;
502 dst->offset = offset;
503 dst->len = payload_len;
504
505 memcpy(dst->data, src->data, payload_len);
506 return dst;
507}
508
509int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
510{
511 struct p54_common *priv = dev->priv;
512 struct eeprom_pda_wrap *wrap = NULL;
513 struct pda_entry *entry;
514 unsigned int data_len, entry_len;
515 void *tmp;
516 int err;
517 u8 *end = (u8 *)eeprom + len;
518 u16 synth = 0;
519
520 wrap = (struct eeprom_pda_wrap *) eeprom;
521 entry = (void *)wrap->data + le16_to_cpu(wrap->len);
522
523 /* verify that at least the entry length/code fits */
524 while ((u8 *)entry <= end - sizeof(*entry)) {
525 entry_len = le16_to_cpu(entry->len);
526 data_len = ((entry_len - 1) << 1);
527
528 /* abort if entry exceeds whole structure */
529 if ((u8 *)entry + sizeof(*entry) + data_len > end)
530 break;
531
532 switch (le16_to_cpu(entry->code)) {
533 case PDR_MAC_ADDRESS:
534 if (data_len != ETH_ALEN)
535 break;
536 SET_IEEE80211_PERM_ADDR(dev, entry->data);
537 break;
538 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS:
539 if (priv->output_limit)
540 break;
541 err = p54_convert_output_limits(dev, entry->data,
542 data_len);
543 if (err)
544 goto err;
545 break;
546 case PDR_PRISM_PA_CAL_CURVE_DATA: {
547 struct pda_pa_curve_data *curve_data =
548 (struct pda_pa_curve_data *)entry->data;
549 if (data_len < sizeof(*curve_data)) {
550 err = -EINVAL;
551 goto err;
552 }
553
554 switch (curve_data->cal_method_rev) {
555 case 0:
556 err = p54_convert_rev0(dev, curve_data);
557 break;
558 case 1:
559 err = p54_convert_rev1(dev, curve_data);
560 break;
561 default:
562 printk(KERN_ERR "%s: unknown curve data "
563 "revision %d\n",
564 wiphy_name(dev->wiphy),
565 curve_data->cal_method_rev);
566 err = -ENODEV;
567 break;
568 }
569 if (err)
570 goto err;
571 }
572 break;
573 case PDR_PRISM_ZIF_TX_IQ_CALIBRATION:
574 priv->iq_autocal = kmalloc(data_len, GFP_KERNEL);
575 if (!priv->iq_autocal) {
576 err = -ENOMEM;
577 goto err;
578 }
579
580 memcpy(priv->iq_autocal, entry->data, data_len);
581 priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry);
582 break;
583 case PDR_DEFAULT_COUNTRY:
584 p54_parse_default_country(dev, entry->data, data_len);
585 break;
586 case PDR_INTERFACE_LIST:
587 tmp = entry->data;
588 while ((u8 *)tmp < entry->data + data_len) {
589 struct bootrec_exp_if *exp_if = tmp;
590 if (le16_to_cpu(exp_if->if_id) == 0xf)
591 synth = le16_to_cpu(exp_if->variant);
592 tmp += sizeof(struct bootrec_exp_if);
593 }
594 break;
595 case PDR_HARDWARE_PLATFORM_COMPONENT_ID:
596 if (data_len < 2)
597 break;
598 priv->version = *(u8 *)(entry->data + 1);
599 break;
600 case PDR_RSSI_LINEAR_APPROXIMATION:
601 case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
602 case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED:
603 p54_parse_rssical(dev, entry->data, data_len,
604 le16_to_cpu(entry->code));
605 break;
606 case PDR_RSSI_LINEAR_APPROXIMATION_CUSTOM: {
607 __le16 *src = (void *) entry->data;
608 s16 *dst = (void *) &priv->rssical_db;
609 int i;
610
611 if (data_len != sizeof(priv->rssical_db)) {
612 err = -EINVAL;
613 goto err;
614 }
615 for (i = 0; i < sizeof(priv->rssical_db) /
616 sizeof(*src); i++)
617 *(dst++) = (s16) le16_to_cpu(*(src++));
618 }
619 break;
620 case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM: {
621 struct pda_custom_wrapper *pda = (void *) entry->data;
622 if (priv->output_limit || data_len < sizeof(*pda))
623 break;
624 priv->output_limit = p54_convert_db(pda, data_len);
625 }
626 break;
627 case PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM: {
628 struct pda_custom_wrapper *pda = (void *) entry->data;
629 if (priv->curve_data || data_len < sizeof(*pda))
630 break;
631 priv->curve_data = p54_convert_db(pda, data_len);
632 }
633 break;
634 case PDR_END:
635 /* make it overrun */
636 entry_len = len;
637 break;
638 case PDR_MANUFACTURING_PART_NUMBER:
639 case PDR_PDA_VERSION:
640 case PDR_NIC_SERIAL_NUMBER:
641 case PDR_REGULATORY_DOMAIN_LIST:
642 case PDR_TEMPERATURE_TYPE:
643 case PDR_PRISM_PCI_IDENTIFIER:
644 case PDR_COUNTRY_INFORMATION:
645 case PDR_OEM_NAME:
646 case PDR_PRODUCT_NAME:
647 case PDR_UTF8_OEM_NAME:
648 case PDR_UTF8_PRODUCT_NAME:
649 case PDR_COUNTRY_LIST:
650 case PDR_ANTENNA_GAIN:
651 case PDR_PRISM_INDIGO_PA_CALIBRATION_DATA:
652 case PDR_REGULATORY_POWER_LIMITS:
653 case PDR_RADIATED_TRANSMISSION_CORRECTION:
654 case PDR_PRISM_TX_IQ_CALIBRATION:
655 case PDR_BASEBAND_REGISTERS:
656 case PDR_PER_CHANNEL_BASEBAND_REGISTERS:
657 break;
658 default:
659 printk(KERN_INFO "%s: unknown eeprom code : 0x%x\n",
660 wiphy_name(dev->wiphy),
661 le16_to_cpu(entry->code));
662 break;
663 }
664
665 entry = (void *)entry + (entry_len + 1)*2;
666 }
667
668 if (!synth || !priv->iq_autocal || !priv->output_limit ||
669 !priv->curve_data) {
670 printk(KERN_ERR "%s: not all required entries found in eeprom!\n",
671 wiphy_name(dev->wiphy));
672 err = -EINVAL;
673 goto err;
674 }
675
676 priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK;
677 if (priv->rxhw == PDR_SYNTH_FRONTEND_XBOW)
678 p54_init_xbow_synth(dev);
679 if (!(synth & PDR_SYNTH_24_GHZ_DISABLED))
680 dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz;
681 if (!(synth & PDR_SYNTH_5_GHZ_DISABLED))
682 dev->wiphy->bands[IEEE80211_BAND_5GHZ] = &band_5GHz;
683 if ((synth & PDR_SYNTH_RX_DIV_MASK) == PDR_SYNTH_RX_DIV_SUPPORTED)
684 priv->rx_diversity_mask = 3;
685 if ((synth & PDR_SYNTH_TX_DIV_MASK) == PDR_SYNTH_TX_DIV_SUPPORTED)
686 priv->tx_diversity_mask = 3;
687
688 if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
689 u8 perm_addr[ETH_ALEN];
690
691 printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n",
692 wiphy_name(dev->wiphy));
693 random_ether_addr(perm_addr);
694 SET_IEEE80211_PERM_ADDR(dev, perm_addr);
695 }
696
697 printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n",
698 wiphy_name(dev->wiphy),
699 dev->wiphy->perm_addr,
700 priv->version, p54_rf_chips[priv->rxhw]);
701
702 return 0;
703
704 err:
705 if (priv->iq_autocal) {
706 kfree(priv->iq_autocal);
707 priv->iq_autocal = NULL;
708 }
709
710 if (priv->output_limit) {
711 kfree(priv->output_limit);
712 priv->output_limit = NULL;
713 }
714
715 if (priv->curve_data) {
716 kfree(priv->curve_data);
717 priv->curve_data = NULL;
718 }
719
720 printk(KERN_ERR "%s: eeprom parse failed!\n",
721 wiphy_name(dev->wiphy));
722 return err;
723}
724EXPORT_SYMBOL_GPL(p54_parse_eeprom);
725
726static int p54_rssi_to_dbm(struct ieee80211_hw *dev, int rssi)
727{
728 struct p54_common *priv = dev->priv;
729 int band = dev->conf.channel->band;
730
731 if (priv->rxhw != PDR_SYNTH_FRONTEND_LONGBOW)
732 return ((rssi * priv->rssical_db[band].mul) / 64 +
733 priv->rssical_db[band].add) / 4;
734 else
735 /*
736 * TODO: find the correct formula
737 */
738 return ((rssi * priv->rssical_db[band].mul) / 64 +
739 priv->rssical_db[band].add) / 4;
740}
741
742static int p54_rx_data(struct ieee80211_hw *dev, struct sk_buff *skb)
743{
744 struct p54_common *priv = dev->priv;
745 struct p54_rx_data *hdr = (struct p54_rx_data *) skb->data;
746 struct ieee80211_rx_status rx_status = {0};
747 u16 freq = le16_to_cpu(hdr->freq);
748 size_t header_len = sizeof(*hdr);
749 u32 tsf32;
750 u8 rate = hdr->rate & 0xf;
751
752 /*
753 * If the device is in a unspecified state we have to
754 * ignore all data frames. Else we could end up with a
755 * nasty crash.
756 */
757 if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
758 return 0;
759
760 if (!(hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_IN_FCS_GOOD))) {
761 return 0;
762 }
763
764 if (hdr->decrypt_status == P54_DECRYPT_OK)
765 rx_status.flag |= RX_FLAG_DECRYPTED;
766 if ((hdr->decrypt_status == P54_DECRYPT_FAIL_MICHAEL) ||
767 (hdr->decrypt_status == P54_DECRYPT_FAIL_TKIP))
768 rx_status.flag |= RX_FLAG_MMIC_ERROR;
769
770 rx_status.signal = p54_rssi_to_dbm(dev, hdr->rssi);
771 rx_status.noise = priv->noise;
772 if (hdr->rate & 0x10)
773 rx_status.flag |= RX_FLAG_SHORTPRE;
774 if (dev->conf.channel->band == IEEE80211_BAND_5GHZ)
775 rx_status.rate_idx = (rate < 4) ? 0 : rate - 4;
776 else
777 rx_status.rate_idx = rate;
778
779 rx_status.freq = freq;
780 rx_status.band = dev->conf.channel->band;
781 rx_status.antenna = hdr->antenna;
782
783 tsf32 = le32_to_cpu(hdr->tsf32);
784 if (tsf32 < priv->tsf_low32)
785 priv->tsf_high32++;
786 rx_status.mactime = ((u64)priv->tsf_high32) << 32 | tsf32;
787 priv->tsf_low32 = tsf32;
788
789 rx_status.flag |= RX_FLAG_TSFT;
790
791 if (hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN))
792 header_len += hdr->align[0];
793
794 skb_pull(skb, header_len);
795 skb_trim(skb, le16_to_cpu(hdr->len));
796
797 ieee80211_rx_irqsafe(dev, skb, &rx_status);
798
799 queue_delayed_work(dev->workqueue, &priv->work,
800 msecs_to_jiffies(P54_STATISTICS_UPDATE));
801
802 return -1;
803}
804
805static void inline p54_wake_free_queues(struct ieee80211_hw *dev)
806{
807 struct p54_common *priv = dev->priv;
808 int i;
809
810 if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
811 return ;
812
813 for (i = 0; i < dev->queues; i++)
814 if (priv->tx_stats[i + P54_QUEUE_DATA].len <
815 priv->tx_stats[i + P54_QUEUE_DATA].limit)
816 ieee80211_wake_queue(dev, i);
817}
818
819void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb)
820{
821 struct p54_common *priv = dev->priv;
822 struct ieee80211_tx_info *info;
823 struct p54_tx_info *range;
824 unsigned long flags;
825
826 if (unlikely(!skb || !dev || !skb_queue_len(&priv->tx_queue)))
827 return;
828
829 /*
830 * don't try to free an already unlinked skb
831 */
832 if (unlikely((!skb->next) || (!skb->prev)))
833 return;
834
835 spin_lock_irqsave(&priv->tx_queue.lock, flags);
836 info = IEEE80211_SKB_CB(skb);
837 range = (void *)info->rate_driver_data;
838 if (skb->prev != (struct sk_buff *)&priv->tx_queue) {
839 struct ieee80211_tx_info *ni;
840 struct p54_tx_info *mr;
841
842 ni = IEEE80211_SKB_CB(skb->prev);
843 mr = (struct p54_tx_info *)ni->rate_driver_data;
844 }
845 if (skb->next != (struct sk_buff *)&priv->tx_queue) {
846 struct ieee80211_tx_info *ni;
847 struct p54_tx_info *mr;
848
849 ni = IEEE80211_SKB_CB(skb->next);
850 mr = (struct p54_tx_info *)ni->rate_driver_data;
851 }
852 __skb_unlink(skb, &priv->tx_queue);
853 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
854 dev_kfree_skb_any(skb);
855 p54_wake_free_queues(dev);
856}
857EXPORT_SYMBOL_GPL(p54_free_skb);
858
859static struct sk_buff *p54_find_tx_entry(struct ieee80211_hw *dev,
860 __le32 req_id)
861{
862 struct p54_common *priv = dev->priv;
863 struct sk_buff *entry;
864 unsigned long flags;
865
866 spin_lock_irqsave(&priv->tx_queue.lock, flags);
867 entry = priv->tx_queue.next;
868 while (entry != (struct sk_buff *)&priv->tx_queue) {
869 struct p54_hdr *hdr = (struct p54_hdr *) entry->data;
870
871 if (hdr->req_id == req_id) {
872 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
873 return entry;
874 }
875 entry = entry->next;
876 }
877 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
878 return NULL;
879}
880
881static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
882{
883 struct p54_common *priv = dev->priv;
884 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
885 struct p54_frame_sent *payload = (struct p54_frame_sent *) hdr->data;
886 struct sk_buff *entry;
887 u32 addr = le32_to_cpu(hdr->req_id) - priv->headroom;
888 struct p54_tx_info *range = NULL;
889 unsigned long flags;
890 int count, idx;
891
892 spin_lock_irqsave(&priv->tx_queue.lock, flags);
893 entry = (struct sk_buff *) priv->tx_queue.next;
894 while (entry != (struct sk_buff *)&priv->tx_queue) {
895 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry);
896 struct p54_hdr *entry_hdr;
897 struct p54_tx_data *entry_data;
898 unsigned int pad = 0, frame_len;
899
900 range = (void *)info->rate_driver_data;
901 if (range->start_addr != addr) {
902 entry = entry->next;
903 continue;
904 }
905
906 if (entry->next != (struct sk_buff *)&priv->tx_queue) {
907 struct ieee80211_tx_info *ni;
908 struct p54_tx_info *mr;
909
910 ni = IEEE80211_SKB_CB(entry->next);
911 mr = (struct p54_tx_info *)ni->rate_driver_data;
912 }
913
914 __skb_unlink(entry, &priv->tx_queue);
915
916 frame_len = entry->len;
917 entry_hdr = (struct p54_hdr *) entry->data;
918 entry_data = (struct p54_tx_data *) entry_hdr->data;
919 if (priv->tx_stats[entry_data->hw_queue].len)
920 priv->tx_stats[entry_data->hw_queue].len--;
921 priv->stats.dot11ACKFailureCount += payload->tries - 1;
922 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
923
924 /*
925 * Frames in P54_QUEUE_FWSCAN and P54_QUEUE_BEACON are
926 * generated by the driver. Therefore tx_status is bogus
927 * and we don't want to confuse the mac80211 stack.
928 */
929 if (unlikely(entry_data->hw_queue < P54_QUEUE_FWSCAN)) {
930 if (entry_data->hw_queue == P54_QUEUE_BEACON)
931 priv->cached_beacon = NULL;
932
933 kfree_skb(entry);
934 goto out;
935 }
936
937 /*
938 * Clear manually, ieee80211_tx_info_clear_status would
939 * clear the counts too and we need them.
940 */
941 memset(&info->status.ampdu_ack_len, 0,
942 sizeof(struct ieee80211_tx_info) -
943 offsetof(struct ieee80211_tx_info, status.ampdu_ack_len));
944 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info,
945 status.ampdu_ack_len) != 23);
946
947 if (entry_hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN))
948 pad = entry_data->align[0];
949
950 /* walk through the rates array and adjust the counts */
951 count = payload->tries;
952 for (idx = 0; idx < 4; idx++) {
953 if (count >= info->status.rates[idx].count) {
954 count -= info->status.rates[idx].count;
955 } else if (count > 0) {
956 info->status.rates[idx].count = count;
957 count = 0;
958 } else {
959 info->status.rates[idx].idx = -1;
960 info->status.rates[idx].count = 0;
961 }
962 }
963
964 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
965 (!payload->status))
966 info->flags |= IEEE80211_TX_STAT_ACK;
967 if (payload->status & P54_TX_PSM_CANCELLED)
968 info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
969 info->status.ack_signal = p54_rssi_to_dbm(dev,
970 (int)payload->ack_rssi);
971
972 /* Undo all changes to the frame. */
973 switch (entry_data->key_type) {
974 case P54_CRYPTO_TKIPMICHAEL: {
975 u8 *iv = (u8 *)(entry_data->align + pad +
976 entry_data->crypt_offset);
977
978 /* Restore the original TKIP IV. */
979 iv[2] = iv[0];
980 iv[0] = iv[1];
981 iv[1] = (iv[0] | 0x20) & 0x7f; /* WEPSeed - 8.3.2.2 */
982
983 frame_len -= 12; /* remove TKIP_MMIC + TKIP_ICV */
984 break;
985 }
986 case P54_CRYPTO_AESCCMP:
987 frame_len -= 8; /* remove CCMP_MIC */
988 break;
989 case P54_CRYPTO_WEP:
990 frame_len -= 4; /* remove WEP_ICV */
991 break;
992 }
993 skb_trim(entry, frame_len);
994 skb_pull(entry, sizeof(*hdr) + pad + sizeof(*entry_data));
995 ieee80211_tx_status_irqsafe(dev, entry);
996 goto out;
997 }
998 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
999
1000out:
1001 p54_wake_free_queues(dev);
1002}
1003
1004static void p54_rx_eeprom_readback(struct ieee80211_hw *dev,
1005 struct sk_buff *skb)
1006{
1007 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
1008 struct p54_eeprom_lm86 *eeprom = (struct p54_eeprom_lm86 *) hdr->data;
1009 struct p54_common *priv = dev->priv;
1010
1011 if (!priv->eeprom)
1012 return ;
1013
1014 if (priv->fw_var >= 0x509) {
1015 memcpy(priv->eeprom, eeprom->v2.data,
1016 le16_to_cpu(eeprom->v2.len));
1017 } else {
1018 memcpy(priv->eeprom, eeprom->v1.data,
1019 le16_to_cpu(eeprom->v1.len));
1020 }
1021
1022 complete(&priv->eeprom_comp);
1023}
1024
1025static void p54_rx_stats(struct ieee80211_hw *dev, struct sk_buff *skb)
1026{
1027 struct p54_common *priv = dev->priv;
1028 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
1029 struct p54_statistics *stats = (struct p54_statistics *) hdr->data;
1030 u32 tsf32;
1031
1032 if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
1033 return ;
1034
1035 tsf32 = le32_to_cpu(stats->tsf32);
1036 if (tsf32 < priv->tsf_low32)
1037 priv->tsf_high32++;
1038 priv->tsf_low32 = tsf32;
1039
1040 priv->stats.dot11RTSFailureCount = le32_to_cpu(stats->rts_fail);
1041 priv->stats.dot11RTSSuccessCount = le32_to_cpu(stats->rts_success);
1042 priv->stats.dot11FCSErrorCount = le32_to_cpu(stats->rx_bad_fcs);
1043
1044 priv->noise = p54_rssi_to_dbm(dev, le32_to_cpu(stats->noise));
1045
1046 p54_free_skb(dev, p54_find_tx_entry(dev, hdr->req_id));
1047}
1048
1049static void p54_rx_trap(struct ieee80211_hw *dev, struct sk_buff *skb)
1050{
1051 struct p54_common *priv = dev->priv;
1052 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
1053 struct p54_trap *trap = (struct p54_trap *) hdr->data;
1054 u16 event = le16_to_cpu(trap->event);
1055 u16 freq = le16_to_cpu(trap->frequency);
1056
1057 switch (event) {
1058 case P54_TRAP_BEACON_TX:
1059 break;
1060 case P54_TRAP_RADAR:
1061 printk(KERN_INFO "%s: radar (freq:%d MHz)\n",
1062 wiphy_name(dev->wiphy), freq);
1063 break;
1064 case P54_TRAP_NO_BEACON:
1065 if (priv->vif)
1066 ieee80211_beacon_loss(priv->vif);
1067 break;
1068 case P54_TRAP_SCAN:
1069 break;
1070 case P54_TRAP_TBTT:
1071 break;
1072 case P54_TRAP_TIMER:
1073 break;
1074 default:
1075 printk(KERN_INFO "%s: received event:%x freq:%d\n",
1076 wiphy_name(dev->wiphy), event, freq);
1077 break;
1078 }
1079}
1080
1081static int p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb)
1082{
1083 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
1084
1085 switch (le16_to_cpu(hdr->type)) {
1086 case P54_CONTROL_TYPE_TXDONE:
1087 p54_rx_frame_sent(dev, skb);
1088 break;
1089 case P54_CONTROL_TYPE_TRAP:
1090 p54_rx_trap(dev, skb);
1091 break;
1092 case P54_CONTROL_TYPE_BBP:
1093 break;
1094 case P54_CONTROL_TYPE_STAT_READBACK:
1095 p54_rx_stats(dev, skb);
1096 break;
1097 case P54_CONTROL_TYPE_EEPROM_READBACK:
1098 p54_rx_eeprom_readback(dev, skb);
1099 break;
1100 default:
1101 printk(KERN_DEBUG "%s: not handling 0x%02x type control frame\n",
1102 wiphy_name(dev->wiphy), le16_to_cpu(hdr->type));
1103 break;
1104 }
1105
1106 return 0;
1107}
1108
1109/* returns zero if skb can be reused */
1110int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb)
1111{
1112 u16 type = le16_to_cpu(*((__le16 *)skb->data));
1113
1114 if (type & P54_HDR_FLAG_CONTROL)
1115 return p54_rx_control(dev, skb);
1116 else
1117 return p54_rx_data(dev, skb);
1118}
1119EXPORT_SYMBOL_GPL(p54_rx);
1120
1121/*
1122 * So, the firmware is somewhat stupid and doesn't know what places in its
1123 * memory incoming data should go to. By poking around in the firmware, we
1124 * can find some unused memory to upload our packets to. However, data that we
1125 * want the card to TX needs to stay intact until the card has told us that
1126 * it is done with it. This function finds empty places we can upload to and
1127 * marks allocated areas as reserved if necessary. p54_rx_frame_sent or
1128 * p54_free_skb frees allocated areas.
1129 */
1130static int p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb,
1131 struct p54_hdr *data, u32 len)
1132{
1133 struct p54_common *priv = dev->priv;
1134 struct sk_buff *entry;
1135 struct sk_buff *target_skb = NULL;
1136 struct ieee80211_tx_info *info;
1137 struct p54_tx_info *range;
1138 u32 last_addr = priv->rx_start;
1139 u32 largest_hole = 0;
1140 u32 target_addr = priv->rx_start;
1141 unsigned long flags;
1142 unsigned int left;
1143 len = (len + priv->headroom + priv->tailroom + 3) & ~0x3;
1144
1145 if (!skb)
1146 return -EINVAL;
1147
1148 spin_lock_irqsave(&priv->tx_queue.lock, flags);
1149
1150 left = skb_queue_len(&priv->tx_queue);
1151 if (unlikely(left >= 28)) {
1152 /*
1153 * The tx_queue is nearly full!
1154 * We have throttle normal data traffic, because we must
1155 * have a few spare slots for control frames left.
1156 */
1157 ieee80211_stop_queues(dev);
1158 queue_delayed_work(dev->workqueue, &priv->work,
1159 msecs_to_jiffies(P54_TX_TIMEOUT));
1160
1161 if (unlikely(left == 32)) {
1162 /*
1163 * The tx_queue is now really full.
1164 *
1165 * TODO: check if the device has crashed and reset it.
1166 */
1167 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
1168 return -ENOSPC;
1169 }
1170 }
1171
1172 entry = priv->tx_queue.next;
1173 while (left--) {
1174 u32 hole_size;
1175 info = IEEE80211_SKB_CB(entry);
1176 range = (void *)info->rate_driver_data;
1177 hole_size = range->start_addr - last_addr;
1178 if (!target_skb && hole_size >= len) {
1179 target_skb = entry->prev;
1180 hole_size -= len;
1181 target_addr = last_addr;
1182 }
1183 largest_hole = max(largest_hole, hole_size);
1184 last_addr = range->end_addr;
1185 entry = entry->next;
1186 }
1187 if (!target_skb && priv->rx_end - last_addr >= len) {
1188 target_skb = priv->tx_queue.prev;
1189 largest_hole = max(largest_hole, priv->rx_end - last_addr - len);
1190 if (!skb_queue_empty(&priv->tx_queue)) {
1191 info = IEEE80211_SKB_CB(target_skb);
1192 range = (void *)info->rate_driver_data;
1193 target_addr = range->end_addr;
1194 }
1195 } else
1196 largest_hole = max(largest_hole, priv->rx_end - last_addr);
1197
1198 if (!target_skb) {
1199 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
1200 ieee80211_stop_queues(dev);
1201 return -ENOSPC;
1202 }
1203
1204 info = IEEE80211_SKB_CB(skb);
1205 range = (void *)info->rate_driver_data;
1206 range->start_addr = target_addr;
1207 range->end_addr = target_addr + len;
1208 __skb_queue_after(&priv->tx_queue, target_skb, skb);
1209 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
1210
1211 if (largest_hole < priv->headroom + sizeof(struct p54_hdr) +
1212 48 + IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom)
1213 ieee80211_stop_queues(dev);
1214
1215 data->req_id = cpu_to_le32(target_addr + priv->headroom);
1216 return 0;
1217}
1218
1219static struct sk_buff *p54_alloc_skb(struct ieee80211_hw *dev, u16 hdr_flags,
1220 u16 payload_len, u16 type, gfp_t memflags)
1221{
1222 struct p54_common *priv = dev->priv;
1223 struct p54_hdr *hdr;
1224 struct sk_buff *skb;
1225 size_t frame_len = sizeof(*hdr) + payload_len;
1226
1227 if (frame_len > P54_MAX_CTRL_FRAME_LEN)
1228 return NULL;
1229
1230 skb = __dev_alloc_skb(priv->tx_hdr_len + frame_len, memflags);
1231 if (!skb)
1232 return NULL;
1233 skb_reserve(skb, priv->tx_hdr_len);
1234
1235 hdr = (struct p54_hdr *) skb_put(skb, sizeof(*hdr));
1236 hdr->flags = cpu_to_le16(hdr_flags);
1237 hdr->len = cpu_to_le16(payload_len);
1238 hdr->type = cpu_to_le16(type);
1239 hdr->tries = hdr->rts_tries = 0;
1240
1241 if (p54_assign_address(dev, skb, hdr, frame_len)) {
1242 kfree_skb(skb);
1243 return NULL;
1244 }
1245 return skb;
1246}
1247
1248int p54_read_eeprom(struct ieee80211_hw *dev)
1249{
1250 struct p54_common *priv = dev->priv;
1251 struct p54_eeprom_lm86 *eeprom_hdr;
1252 struct sk_buff *skb;
1253 size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize;
1254 int ret = -ENOMEM;
1255 void *eeprom = NULL;
1256
1257 maxblocksize = EEPROM_READBACK_LEN;
1258 if (priv->fw_var >= 0x509)
1259 maxblocksize -= 0xc;
1260 else
1261 maxblocksize -= 0x4;
1262
1263 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL, sizeof(*eeprom_hdr) +
1264 maxblocksize, P54_CONTROL_TYPE_EEPROM_READBACK,
1265 GFP_KERNEL);
1266 if (!skb)
1267 goto free;
1268 priv->eeprom = kzalloc(EEPROM_READBACK_LEN, GFP_KERNEL);
1269 if (!priv->eeprom)
1270 goto free;
1271 eeprom = kzalloc(eeprom_size, GFP_KERNEL);
1272 if (!eeprom)
1273 goto free;
1274
1275 eeprom_hdr = (struct p54_eeprom_lm86 *) skb_put(skb,
1276 sizeof(*eeprom_hdr) + maxblocksize);
1277
1278 while (eeprom_size) {
1279 blocksize = min(eeprom_size, maxblocksize);
1280 if (priv->fw_var < 0x509) {
1281 eeprom_hdr->v1.offset = cpu_to_le16(offset);
1282 eeprom_hdr->v1.len = cpu_to_le16(blocksize);
1283 } else {
1284 eeprom_hdr->v2.offset = cpu_to_le32(offset);
1285 eeprom_hdr->v2.len = cpu_to_le16(blocksize);
1286 eeprom_hdr->v2.magic2 = 0xf;
1287 memcpy(eeprom_hdr->v2.magic, (const char *)"LOCK", 4);
1288 }
1289 priv->tx(dev, skb);
1290
1291 if (!wait_for_completion_interruptible_timeout(&priv->eeprom_comp, HZ)) {
1292 printk(KERN_ERR "%s: device does not respond!\n",
1293 wiphy_name(dev->wiphy));
1294 ret = -EBUSY;
1295 goto free;
1296 }
1297
1298 memcpy(eeprom + offset, priv->eeprom, blocksize);
1299 offset += blocksize;
1300 eeprom_size -= blocksize;
1301 }
1302
1303 ret = p54_parse_eeprom(dev, eeprom, offset);
1304free:
1305 kfree(priv->eeprom);
1306 priv->eeprom = NULL;
1307 p54_free_skb(dev, skb);
1308 kfree(eeprom);
1309
1310 return ret;
1311}
1312EXPORT_SYMBOL_GPL(p54_read_eeprom);
1313
1314static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
1315 bool set)
1316{
1317 struct p54_common *priv = dev->priv;
1318 struct sk_buff *skb;
1319 struct p54_tim *tim;
1320
1321 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*tim),
1322 P54_CONTROL_TYPE_TIM, GFP_ATOMIC);
1323 if (!skb)
1324 return -ENOMEM;
1325
1326 tim = (struct p54_tim *) skb_put(skb, sizeof(*tim));
1327 tim->count = 1;
1328 tim->entry[0] = cpu_to_le16(set ? (sta->aid | 0x8000) : sta->aid);
1329 priv->tx(dev, skb);
1330 return 0;
1331}
1332
1333static int p54_sta_unlock(struct ieee80211_hw *dev, u8 *addr)
1334{
1335 struct p54_common *priv = dev->priv;
1336 struct sk_buff *skb;
1337 struct p54_sta_unlock *sta;
1338
1339 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*sta),
1340 P54_CONTROL_TYPE_PSM_STA_UNLOCK, GFP_ATOMIC);
1341 if (!skb)
1342 return -ENOMEM;
1343
1344 sta = (struct p54_sta_unlock *)skb_put(skb, sizeof(*sta));
1345 memcpy(sta->addr, addr, ETH_ALEN);
1346 priv->tx(dev, skb);
1347 return 0;
1348}
1349
1350static void p54_sta_notify(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
1351 enum sta_notify_cmd notify_cmd,
1352 struct ieee80211_sta *sta)
1353{
1354 switch (notify_cmd) {
1355 case STA_NOTIFY_ADD:
1356 case STA_NOTIFY_REMOVE:
1357 /*
1358 * Notify the firmware that we don't want or we don't
1359 * need to buffer frames for this station anymore.
1360 */
1361
1362 p54_sta_unlock(dev, sta->addr);
1363 break;
1364 case STA_NOTIFY_AWAKE:
1365 /* update the firmware's filter table */
1366 p54_sta_unlock(dev, sta->addr);
1367 break;
1368 default:
1369 break;
1370 }
1371}
1372
1373static int p54_tx_cancel(struct ieee80211_hw *dev, struct sk_buff *entry)
1374{
1375 struct p54_common *priv = dev->priv;
1376 struct sk_buff *skb;
1377 struct p54_hdr *hdr;
1378 struct p54_txcancel *cancel;
1379
1380 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*cancel),
1381 P54_CONTROL_TYPE_TXCANCEL, GFP_ATOMIC);
1382 if (!skb)
1383 return -ENOMEM;
1384
1385 hdr = (void *)entry->data;
1386 cancel = (struct p54_txcancel *)skb_put(skb, sizeof(*cancel));
1387 cancel->req_id = hdr->req_id;
1388 priv->tx(dev, skb);
1389 return 0;
1390}
1391
1392static int p54_tx_fill(struct ieee80211_hw *dev, struct sk_buff *skb,
1393 struct ieee80211_tx_info *info, u8 *queue, size_t *extra_len,
1394 u16 *flags, u16 *aid)
1395{
1396 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1397 struct p54_common *priv = dev->priv;
1398 int ret = 1;
1399
1400 switch (priv->mode) {
1401 case NL80211_IFTYPE_MONITOR:
1402 /*
1403 * We have to set P54_HDR_FLAG_DATA_OUT_PROMISC for
1404 * every frame in promiscuous/monitor mode.
1405 * see STSW45x0C LMAC API - page 12.
1406 */
1407 *aid = 0;
1408 *flags = P54_HDR_FLAG_DATA_OUT_PROMISC;
1409 *queue += P54_QUEUE_DATA;
1410 break;
1411 case NL80211_IFTYPE_STATION:
1412 *aid = 1;
1413 if (unlikely(ieee80211_is_mgmt(hdr->frame_control))) {
1414 *queue = P54_QUEUE_MGMT;
1415 ret = 0;
1416 } else
1417 *queue += P54_QUEUE_DATA;
1418 break;
1419 case NL80211_IFTYPE_AP:
1420 case NL80211_IFTYPE_ADHOC:
1421 case NL80211_IFTYPE_MESH_POINT:
1422 if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
1423 *aid = 0;
1424 *queue = P54_QUEUE_CAB;
1425 return 0;
1426 }
1427
1428 if (unlikely(ieee80211_is_mgmt(hdr->frame_control))) {
1429 if (ieee80211_is_probe_resp(hdr->frame_control)) {
1430 *aid = 0;
1431 *queue = P54_QUEUE_MGMT;
1432 *flags = P54_HDR_FLAG_DATA_OUT_TIMESTAMP |
1433 P54_HDR_FLAG_DATA_OUT_NOCANCEL;
1434 return 0;
1435 } else if (ieee80211_is_beacon(hdr->frame_control)) {
1436 *aid = 0;
1437
1438 if (info->flags & IEEE80211_TX_CTL_INJECTED) {
1439 /*
1440 * Injecting beacons on top of a AP is
1441 * not a good idea... nevertheless,
1442 * it should be doable.
1443 */
1444
1445 *queue += P54_QUEUE_DATA;
1446 return 1;
1447 }
1448
1449 *flags = P54_HDR_FLAG_DATA_OUT_TIMESTAMP;
1450 *queue = P54_QUEUE_BEACON;
1451 *extra_len = IEEE80211_MAX_TIM_LEN;
1452 return 0;
1453 } else {
1454 *queue = P54_QUEUE_MGMT;
1455 ret = 0;
1456 }
1457 } else
1458 *queue += P54_QUEUE_DATA;
1459
1460 if (info->control.sta)
1461 *aid = info->control.sta->aid;
1462
1463 if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
1464 *flags |= P54_HDR_FLAG_DATA_OUT_NOCANCEL;
1465 break;
1466 }
1467 return ret;
1468}
1469
1470static u8 p54_convert_algo(enum ieee80211_key_alg alg)
1471{
1472 switch (alg) {
1473 case ALG_WEP:
1474 return P54_CRYPTO_WEP;
1475 case ALG_TKIP:
1476 return P54_CRYPTO_TKIPMICHAEL;
1477 case ALG_CCMP:
1478 return P54_CRYPTO_AESCCMP;
1479 default:
1480 return 0;
1481 }
1482}
1483
1484static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
1485{
1486 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1487 struct ieee80211_tx_queue_stats *current_queue;
1488 struct p54_common *priv = dev->priv;
1489 struct p54_hdr *hdr;
1490 struct p54_tx_data *txhdr;
1491 size_t padding, len, tim_len = 0;
1492 int i, j, ridx, ret;
1493 u16 hdr_flags = 0, aid = 0;
1494 u8 rate, queue, crypt_offset = 0;
1495 u8 cts_rate = 0x20;
1496 u8 rc_flags;
1497 u8 calculated_tries[4];
1498 u8 nrates = 0, nremaining = 8;
1499
1500 queue = skb_get_queue_mapping(skb);
1501
1502 ret = p54_tx_fill(dev, skb, info, &queue, &tim_len, &hdr_flags, &aid);
1503 current_queue = &priv->tx_stats[queue];
1504 if (unlikely((current_queue->len > current_queue->limit) && ret))
1505 return NETDEV_TX_BUSY;
1506 current_queue->len++;
1507 current_queue->count++;
1508 if ((current_queue->len == current_queue->limit) && ret)
1509 ieee80211_stop_queue(dev, skb_get_queue_mapping(skb));
1510
1511 padding = (unsigned long)(skb->data - (sizeof(*hdr) + sizeof(*txhdr))) & 3;
1512 len = skb->len;
1513
1514 if (info->control.hw_key) {
1515 crypt_offset = ieee80211_get_hdrlen_from_skb(skb);
1516 if (info->control.hw_key->alg == ALG_TKIP) {
1517 u8 *iv = (u8 *)(skb->data + crypt_offset);
1518 /*
1519 * The firmware excepts that the IV has to have
1520 * this special format
1521 */
1522 iv[1] = iv[0];
1523 iv[0] = iv[2];
1524 iv[2] = 0;
1525 }
1526 }
1527
1528 txhdr = (struct p54_tx_data *) skb_push(skb, sizeof(*txhdr) + padding);
1529 hdr = (struct p54_hdr *) skb_push(skb, sizeof(*hdr));
1530
1531 if (padding)
1532 hdr_flags |= P54_HDR_FLAG_DATA_ALIGN;
1533 hdr->type = cpu_to_le16(aid);
1534 hdr->rts_tries = info->control.rates[0].count;
1535
1536 /*
1537 * we register the rates in perfect order, and
1538 * RTS/CTS won't happen on 5 GHz
1539 */
1540 cts_rate = info->control.rts_cts_rate_idx;
1541
1542 memset(&txhdr->rateset, 0, sizeof(txhdr->rateset));
1543
1544 /* see how many rates got used */
1545 for (i = 0; i < 4; i++) {
1546 if (info->control.rates[i].idx < 0)
1547 break;
1548 nrates++;
1549 }
1550
1551 /* limit tries to 8/nrates per rate */
1552 for (i = 0; i < nrates; i++) {
1553 /*
1554 * The magic expression here is equivalent to 8/nrates for
1555 * all values that matter, but avoids division and jumps.
1556 * Note that nrates can only take the values 1 through 4.
1557 */
1558 calculated_tries[i] = min_t(int, ((15 >> nrates) | 1) + 1,
1559 info->control.rates[i].count);
1560 nremaining -= calculated_tries[i];
1561 }
1562
1563 /* if there are tries left, distribute from back to front */
1564 for (i = nrates - 1; nremaining > 0 && i >= 0; i--) {
1565 int tmp = info->control.rates[i].count - calculated_tries[i];
1566
1567 if (tmp <= 0)
1568 continue;
1569 /* RC requested more tries at this rate */
1570
1571 tmp = min_t(int, tmp, nremaining);
1572 calculated_tries[i] += tmp;
1573 nremaining -= tmp;
1574 }
1575
1576 ridx = 0;
1577 for (i = 0; i < nrates && ridx < 8; i++) {
1578 /* we register the rates in perfect order */
1579 rate = info->control.rates[i].idx;
1580 if (info->band == IEEE80211_BAND_5GHZ)
1581 rate += 4;
1582
1583 /* store the count we actually calculated for TX status */
1584 info->control.rates[i].count = calculated_tries[i];
1585
1586 rc_flags = info->control.rates[i].flags;
1587 if (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) {
1588 rate |= 0x10;
1589 cts_rate |= 0x10;
1590 }
1591 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS)
1592 rate |= 0x40;
1593 else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
1594 rate |= 0x20;
1595 for (j = 0; j < calculated_tries[i] && ridx < 8; j++) {
1596 txhdr->rateset[ridx] = rate;
1597 ridx++;
1598 }
1599 }
1600
1601 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
1602 hdr_flags |= P54_HDR_FLAG_DATA_OUT_SEQNR;
1603
1604 /* TODO: enable bursting */
1605 hdr->flags = cpu_to_le16(hdr_flags);
1606 hdr->tries = ridx;
1607 txhdr->rts_rate_idx = 0;
1608 if (info->control.hw_key) {
1609 txhdr->key_type = p54_convert_algo(info->control.hw_key->alg);
1610 txhdr->key_len = min((u8)16, info->control.hw_key->keylen);
1611 memcpy(txhdr->key, info->control.hw_key->key, txhdr->key_len);
1612 if (info->control.hw_key->alg == ALG_TKIP) {
1613 if (unlikely(skb_tailroom(skb) < 12))
1614 goto err;
1615 /* reserve space for the MIC key */
1616 len += 8;
1617 memcpy(skb_put(skb, 8), &(info->control.hw_key->key
1618 [NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY]), 8);
1619 }
1620 /* reserve some space for ICV */
1621 len += info->control.hw_key->icv_len;
1622 memset(skb_put(skb, info->control.hw_key->icv_len), 0,
1623 info->control.hw_key->icv_len);
1624 } else {
1625 txhdr->key_type = 0;
1626 txhdr->key_len = 0;
1627 }
1628 txhdr->crypt_offset = crypt_offset;
1629 txhdr->hw_queue = queue;
1630 txhdr->backlog = current_queue->len;
1631 memset(txhdr->durations, 0, sizeof(txhdr->durations));
1632 txhdr->tx_antenna = ((info->antenna_sel_tx == 0) ?
1633 2 : info->antenna_sel_tx - 1) & priv->tx_diversity_mask;
1634 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
1635 txhdr->longbow.cts_rate = cts_rate;
1636 txhdr->longbow.output_power = cpu_to_le16(priv->output_power);
1637 } else {
1638 txhdr->normal.output_power = priv->output_power;
1639 txhdr->normal.cts_rate = cts_rate;
1640 }
1641 if (padding)
1642 txhdr->align[0] = padding;
1643
1644 hdr->len = cpu_to_le16(len);
1645 /* modifies skb->cb and with it info, so must be last! */
1646 if (unlikely(p54_assign_address(dev, skb, hdr, skb->len + tim_len)))
1647 goto err;
1648 priv->tx(dev, skb);
1649
1650 queue_delayed_work(dev->workqueue, &priv->work,
1651 msecs_to_jiffies(P54_TX_FRAME_LIFETIME));
1652
1653 return NETDEV_TX_OK;
1654
1655 err:
1656 skb_pull(skb, sizeof(*hdr) + sizeof(*txhdr) + padding);
1657 current_queue->len--;
1658 current_queue->count--;
1659 return NETDEV_TX_BUSY;
1660}
1661
1662static int p54_setup_mac(struct ieee80211_hw *dev)
1663{
1664 struct p54_common *priv = dev->priv;
1665 struct sk_buff *skb;
1666 struct p54_setup_mac *setup;
1667 u16 mode;
1668
1669 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup),
1670 P54_CONTROL_TYPE_SETUP, GFP_ATOMIC);
1671 if (!skb)
1672 return -ENOMEM;
1673
1674 setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup));
1675 if (dev->conf.radio_enabled) {
1676 switch (priv->mode) {
1677 case NL80211_IFTYPE_STATION:
1678 mode = P54_FILTER_TYPE_STATION;
1679 break;
1680 case NL80211_IFTYPE_AP:
1681 mode = P54_FILTER_TYPE_AP;
1682 break;
1683 case NL80211_IFTYPE_ADHOC:
1684 case NL80211_IFTYPE_MESH_POINT:
1685 mode = P54_FILTER_TYPE_IBSS;
1686 break;
1687 case NL80211_IFTYPE_MONITOR:
1688 mode = P54_FILTER_TYPE_PROMISCUOUS;
1689 break;
1690 default:
1691 mode = P54_FILTER_TYPE_HIBERNATE;
1692 break;
1693 }
1694
1695 /*
1696 * "TRANSPARENT and PROMISCUOUS are mutually exclusive"
1697 * STSW45X0C LMAC API - page 12
1698 */
1699 if (((priv->filter_flags & FIF_PROMISC_IN_BSS) ||
1700 (priv->filter_flags & FIF_OTHER_BSS)) &&
1701 (mode != P54_FILTER_TYPE_PROMISCUOUS))
1702 mode |= P54_FILTER_TYPE_TRANSPARENT;
1703 } else
1704 mode = P54_FILTER_TYPE_HIBERNATE;
1705
1706 setup->mac_mode = cpu_to_le16(mode);
1707 memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN);
1708 memcpy(setup->bssid, priv->bssid, ETH_ALEN);
1709 setup->rx_antenna = 2 & priv->rx_diversity_mask; /* automatic */
1710 setup->rx_align = 0;
1711 if (priv->fw_var < 0x500) {
1712 setup->v1.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
1713 memset(setup->v1.rts_rates, 0, 8);
1714 setup->v1.rx_addr = cpu_to_le32(priv->rx_end);
1715 setup->v1.max_rx = cpu_to_le16(priv->rx_mtu);
1716 setup->v1.rxhw = cpu_to_le16(priv->rxhw);
1717 setup->v1.wakeup_timer = cpu_to_le16(priv->wakeup_timer);
1718 setup->v1.unalloc0 = cpu_to_le16(0);
1719 } else {
1720 setup->v2.rx_addr = cpu_to_le32(priv->rx_end);
1721 setup->v2.max_rx = cpu_to_le16(priv->rx_mtu);
1722 setup->v2.rxhw = cpu_to_le16(priv->rxhw);
1723 setup->v2.timer = cpu_to_le16(priv->wakeup_timer);
1724 setup->v2.truncate = cpu_to_le16(48896);
1725 setup->v2.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
1726 setup->v2.sbss_offset = 0;
1727 setup->v2.mcast_window = 0;
1728 setup->v2.rx_rssi_threshold = 0;
1729 setup->v2.rx_ed_threshold = 0;
1730 setup->v2.ref_clock = cpu_to_le32(644245094);
1731 setup->v2.lpf_bandwidth = cpu_to_le16(65535);
1732 setup->v2.osc_start_delay = cpu_to_le16(65535);
1733 }
1734 priv->tx(dev, skb);
1735 return 0;
1736}
1737
1738static int p54_scan(struct ieee80211_hw *dev, u16 mode, u16 dwell)
1739{
1740 struct p54_common *priv = dev->priv;
1741 struct sk_buff *skb;
1742 struct p54_hdr *hdr;
1743 struct p54_scan_head *head;
1744 struct p54_iq_autocal_entry *iq_autocal;
1745 union p54_scan_body_union *body;
1746 struct p54_scan_tail_rate *rate;
1747 struct pda_rssi_cal_entry *rssi;
1748 unsigned int i;
1749 void *entry;
1750 int band = dev->conf.channel->band;
1751 __le16 freq = cpu_to_le16(dev->conf.channel->center_freq);
1752
1753 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*head) +
1754 2 + sizeof(*iq_autocal) + sizeof(*body) +
1755 sizeof(*rate) + 2 * sizeof(*rssi),
1756 P54_CONTROL_TYPE_SCAN, GFP_ATOMIC);
1757 if (!skb)
1758 return -ENOMEM;
1759
1760 head = (struct p54_scan_head *) skb_put(skb, sizeof(*head));
1761 memset(head->scan_params, 0, sizeof(head->scan_params));
1762 head->mode = cpu_to_le16(mode);
1763 head->dwell = cpu_to_le16(dwell);
1764 head->freq = freq;
1765
1766 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
1767 __le16 *pa_power_points = (__le16 *) skb_put(skb, 2);
1768 *pa_power_points = cpu_to_le16(0x0c);
1769 }
1770
1771 iq_autocal = (void *) skb_put(skb, sizeof(*iq_autocal));
1772 for (i = 0; i < priv->iq_autocal_len; i++) {
1773 if (priv->iq_autocal[i].freq != freq)
1774 continue;
1775
1776 memcpy(iq_autocal, &priv->iq_autocal[i].params,
1777 sizeof(struct p54_iq_autocal_entry));
1778 break;
1779 }
1780 if (i == priv->iq_autocal_len)
1781 goto err;
1782
1783 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW)
1784 body = (void *) skb_put(skb, sizeof(body->longbow));
1785 else
1786 body = (void *) skb_put(skb, sizeof(body->normal));
1787
1788 for (i = 0; i < priv->output_limit->entries; i++) {
1789 __le16 *entry_freq = (void *) (priv->output_limit->data +
1790 priv->output_limit->entry_size * i);
1791
1792 if (*entry_freq != freq)
1793 continue;
1794
1795 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
1796 memcpy(&body->longbow.power_limits,
1797 (void *) entry_freq + sizeof(__le16),
1798 priv->output_limit->entry_size);
1799 } else {
1800 struct pda_channel_output_limit *limits =
1801 (void *) entry_freq;
1802
1803 body->normal.val_barker = 0x38;
1804 body->normal.val_bpsk = body->normal.dup_bpsk =
1805 limits->val_bpsk;
1806 body->normal.val_qpsk = body->normal.dup_qpsk =
1807 limits->val_qpsk;
1808 body->normal.val_16qam = body->normal.dup_16qam =
1809 limits->val_16qam;
1810 body->normal.val_64qam = body->normal.dup_64qam =
1811 limits->val_64qam;
1812 }
1813 break;
1814 }
1815 if (i == priv->output_limit->entries)
1816 goto err;
1817
1818 entry = (void *)(priv->curve_data->data + priv->curve_data->offset);
1819 for (i = 0; i < priv->curve_data->entries; i++) {
1820 if (*((__le16 *)entry) != freq) {
1821 entry += priv->curve_data->entry_size;
1822 continue;
1823 }
1824
1825 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
1826 memcpy(&body->longbow.curve_data,
1827 (void *) entry + sizeof(__le16),
1828 priv->curve_data->entry_size);
1829 } else {
1830 struct p54_scan_body *chan = &body->normal;
1831 struct pda_pa_curve_data *curve_data =
1832 (void *) priv->curve_data->data;
1833
1834 entry += sizeof(__le16);
1835 chan->pa_points_per_curve = 8;
1836 memset(chan->curve_data, 0, sizeof(*chan->curve_data));
1837 memcpy(chan->curve_data, entry,
1838 sizeof(struct p54_pa_curve_data_sample) *
1839 min((u8)8, curve_data->points_per_channel));
1840 }
1841 break;
1842 }
1843 if (i == priv->curve_data->entries)
1844 goto err;
1845
1846 if ((priv->fw_var >= 0x500) && (priv->fw_var < 0x509)) {
1847 rate = (void *) skb_put(skb, sizeof(*rate));
1848 rate->basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
1849 for (i = 0; i < sizeof(rate->rts_rates); i++)
1850 rate->rts_rates[i] = i;
1851 }
1852
1853 rssi = (struct pda_rssi_cal_entry *) skb_put(skb, sizeof(*rssi));
1854 rssi->mul = cpu_to_le16(priv->rssical_db[band].mul);
1855 rssi->add = cpu_to_le16(priv->rssical_db[band].add);
1856 if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
1857 /* Longbow frontend needs ever more */
1858 rssi = (void *) skb_put(skb, sizeof(*rssi));
1859 rssi->mul = cpu_to_le16(priv->rssical_db[band].longbow_unkn);
1860 rssi->add = cpu_to_le16(priv->rssical_db[band].longbow_unk2);
1861 }
1862
1863 if (priv->fw_var >= 0x509) {
1864 rate = (void *) skb_put(skb, sizeof(*rate));
1865 rate->basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
1866 for (i = 0; i < sizeof(rate->rts_rates); i++)
1867 rate->rts_rates[i] = i;
1868 }
1869
1870 hdr = (struct p54_hdr *) skb->data;
1871 hdr->len = cpu_to_le16(skb->len - sizeof(*hdr));
1872
1873 priv->tx(dev, skb);
1874 return 0;
1875
1876 err:
1877 printk(KERN_ERR "%s: frequency change failed\n", wiphy_name(dev->wiphy));
1878 p54_free_skb(dev, skb);
1879 return -EINVAL;
1880}
1881
1882static int p54_set_leds(struct ieee80211_hw *dev)
1883{
1884 struct p54_common *priv = dev->priv;
1885 struct sk_buff *skb;
1886 struct p54_led *led;
1887
1888 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*led),
1889 P54_CONTROL_TYPE_LED, GFP_ATOMIC);
1890 if (!skb)
1891 return -ENOMEM;
1892
1893 led = (struct p54_led *) skb_put(skb, sizeof(*led));
1894 led->flags = cpu_to_le16(0x0003);
1895 led->mask[0] = led->mask[1] = cpu_to_le16(priv->softled_state);
1896 led->delay[0] = cpu_to_le16(1);
1897 led->delay[1] = cpu_to_le16(0);
1898 priv->tx(dev, skb);
1899 return 0;
1900}
1901
1902#define P54_SET_QUEUE(queue, ai_fs, cw_min, cw_max, _txop) \
1903do { \
1904 queue.aifs = cpu_to_le16(ai_fs); \
1905 queue.cwmin = cpu_to_le16(cw_min); \
1906 queue.cwmax = cpu_to_le16(cw_max); \
1907 queue.txop = cpu_to_le16(_txop); \
1908} while(0)
1909
1910static int p54_set_edcf(struct ieee80211_hw *dev)
1911{
1912 struct p54_common *priv = dev->priv;
1913 struct sk_buff *skb;
1914 struct p54_edcf *edcf;
1915
1916 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*edcf),
1917 P54_CONTROL_TYPE_DCFINIT, GFP_ATOMIC);
1918 if (!skb)
1919 return -ENOMEM;
1920
1921 edcf = (struct p54_edcf *)skb_put(skb, sizeof(*edcf));
1922 if (priv->use_short_slot) {
1923 edcf->slottime = 9;
1924 edcf->sifs = 0x10;
1925 edcf->eofpad = 0x00;
1926 } else {
1927 edcf->slottime = 20;
1928 edcf->sifs = 0x0a;
1929 edcf->eofpad = 0x06;
1930 }
1931 /* (see prism54/isl_oid.h for further details) */
1932 edcf->frameburst = cpu_to_le16(0);
1933 edcf->round_trip_delay = cpu_to_le16(0);
1934 edcf->flags = 0;
1935 memset(edcf->mapping, 0, sizeof(edcf->mapping));
1936 memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue));
1937 priv->tx(dev, skb);
1938 return 0;
1939}
1940
1941static int p54_set_ps(struct ieee80211_hw *dev)
1942{
1943 struct p54_common *priv = dev->priv;
1944 struct sk_buff *skb;
1945 struct p54_psm *psm;
1946 u16 mode;
1947 int i;
1948
1949 if (dev->conf.flags & IEEE80211_CONF_PS)
1950 mode = P54_PSM | P54_PSM_BEACON_TIMEOUT | P54_PSM_DTIM |
1951 P54_PSM_CHECKSUM | P54_PSM_MCBC;
1952 else
1953 mode = P54_PSM_CAM;
1954
1955 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*psm),
1956 P54_CONTROL_TYPE_PSM, GFP_ATOMIC);
1957 if (!skb)
1958 return -ENOMEM;
1959
1960 psm = (struct p54_psm *)skb_put(skb, sizeof(*psm));
1961 psm->mode = cpu_to_le16(mode);
1962 psm->aid = cpu_to_le16(priv->aid);
1963 for (i = 0; i < ARRAY_SIZE(psm->intervals); i++) {
1964 psm->intervals[i].interval =
1965 cpu_to_le16(dev->conf.listen_interval);
1966 psm->intervals[i].periods = cpu_to_le16(1);
1967 }
1968
1969 psm->beacon_rssi_skip_max = 200;
1970 psm->rssi_delta_threshold = 0;
1971 psm->nr = 10;
1972 psm->exclude[0] = 0;
1973
1974 priv->tx(dev, skb);
1975
1976 return 0;
1977}
1978
1979static int p54_beacon_tim(struct sk_buff *skb)
1980{
1981 /*
1982 * the good excuse for this mess is ... the firmware.
1983 * The dummy TIM MUST be at the end of the beacon frame,
1984 * because it'll be overwritten!
1985 */
1986
1987 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1988 u8 *pos, *end;
1989
1990 if (skb->len <= sizeof(mgmt))
1991 return -EINVAL;
1992
1993 pos = (u8 *)mgmt->u.beacon.variable;
1994 end = skb->data + skb->len;
1995 while (pos < end) {
1996 if (pos + 2 + pos[1] > end)
1997 return -EINVAL;
1998
1999 if (pos[0] == WLAN_EID_TIM) {
2000 u8 dtim_len = pos[1];
2001 u8 dtim_period = pos[3];
2002 u8 *next = pos + 2 + dtim_len;
2003
2004 if (dtim_len < 3)
2005 return -EINVAL;
2006
2007 memmove(pos, next, end - next);
2008
2009 if (dtim_len > 3)
2010 skb_trim(skb, skb->len - (dtim_len - 3));
2011
2012 pos = end - (dtim_len + 2);
2013
2014 /* add the dummy at the end */
2015 pos[0] = WLAN_EID_TIM;
2016 pos[1] = 3;
2017 pos[2] = 0;
2018 pos[3] = dtim_period;
2019 pos[4] = 0;
2020 return 0;
2021 }
2022 pos += 2 + pos[1];
2023 }
2024 return 0;
2025}
2026
2027static int p54_beacon_update(struct ieee80211_hw *dev,
2028 struct ieee80211_vif *vif)
2029{
2030 struct p54_common *priv = dev->priv;
2031 struct sk_buff *beacon;
2032 int ret;
2033
2034 if (priv->cached_beacon) {
2035 p54_tx_cancel(dev, priv->cached_beacon);
2036 /* wait for the last beacon the be freed */
2037 msleep(10);
2038 }
2039
2040 beacon = ieee80211_beacon_get(dev, vif);
2041 if (!beacon)
2042 return -ENOMEM;
2043 ret = p54_beacon_tim(beacon);
2044 if (ret)
2045 return ret;
2046 ret = p54_tx(dev, beacon);
2047 if (ret)
2048 return ret;
2049 priv->cached_beacon = beacon;
2050 priv->tsf_high32 = 0;
2051 priv->tsf_low32 = 0;
2052
2053 return 0;
2054}
2055
2056static int p54_start(struct ieee80211_hw *dev)
2057{
2058 struct p54_common *priv = dev->priv;
2059 int err;
2060
2061 mutex_lock(&priv->conf_mutex);
2062 err = priv->open(dev);
2063 if (err)
2064 goto out;
2065 P54_SET_QUEUE(priv->qos_params[0], 0x0002, 0x0003, 0x0007, 47);
2066 P54_SET_QUEUE(priv->qos_params[1], 0x0002, 0x0007, 0x000f, 94);
2067 P54_SET_QUEUE(priv->qos_params[2], 0x0003, 0x000f, 0x03ff, 0);
2068 P54_SET_QUEUE(priv->qos_params[3], 0x0007, 0x000f, 0x03ff, 0);
2069 err = p54_set_edcf(dev);
2070 if (err)
2071 goto out;
2072
2073 memset(priv->bssid, ~0, ETH_ALEN);
2074 priv->mode = NL80211_IFTYPE_MONITOR;
2075 err = p54_setup_mac(dev);
2076 if (err) {
2077 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
2078 goto out;
2079 }
2080
2081 queue_delayed_work(dev->workqueue, &priv->work, 0);
2082
2083 priv->softled_state = 0;
2084 err = p54_set_leds(dev);
2085
2086out:
2087 mutex_unlock(&priv->conf_mutex);
2088 return err;
2089}
2090
2091static void p54_stop(struct ieee80211_hw *dev)
2092{
2093 struct p54_common *priv = dev->priv;
2094 struct sk_buff *skb;
2095
2096 mutex_lock(&priv->conf_mutex);
2097 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
2098 priv->softled_state = 0;
2099 p54_set_leds(dev);
2100
2101#ifdef CONFIG_P54_LEDS
2102 cancel_delayed_work_sync(&priv->led_work);
2103#endif /* CONFIG_P54_LEDS */
2104 cancel_delayed_work_sync(&priv->work);
2105 if (priv->cached_beacon)
2106 p54_tx_cancel(dev, priv->cached_beacon);
2107
2108 priv->stop(dev);
2109 while ((skb = skb_dequeue(&priv->tx_queue)))
2110 kfree_skb(skb);
2111 priv->cached_beacon = NULL;
2112 priv->tsf_high32 = priv->tsf_low32 = 0;
2113 mutex_unlock(&priv->conf_mutex);
2114}
2115
2116static int p54_add_interface(struct ieee80211_hw *dev,
2117 struct ieee80211_if_init_conf *conf)
2118{
2119 struct p54_common *priv = dev->priv;
2120
2121 mutex_lock(&priv->conf_mutex);
2122 if (priv->mode != NL80211_IFTYPE_MONITOR) {
2123 mutex_unlock(&priv->conf_mutex);
2124 return -EOPNOTSUPP;
2125 }
2126
2127 priv->vif = conf->vif;
2128
2129 switch (conf->type) {
2130 case NL80211_IFTYPE_STATION:
2131 case NL80211_IFTYPE_ADHOC:
2132 case NL80211_IFTYPE_AP:
2133 case NL80211_IFTYPE_MESH_POINT:
2134 priv->mode = conf->type;
2135 break;
2136 default:
2137 mutex_unlock(&priv->conf_mutex);
2138 return -EOPNOTSUPP;
2139 }
2140
2141 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2142 p54_setup_mac(dev);
2143 mutex_unlock(&priv->conf_mutex);
2144 return 0;
2145}
2146
2147static void p54_remove_interface(struct ieee80211_hw *dev,
2148 struct ieee80211_if_init_conf *conf)
2149{
2150 struct p54_common *priv = dev->priv;
2151
2152 mutex_lock(&priv->conf_mutex);
2153 priv->vif = NULL;
2154 if (priv->cached_beacon)
2155 p54_tx_cancel(dev, priv->cached_beacon);
2156 priv->mode = NL80211_IFTYPE_MONITOR;
2157 memset(priv->mac_addr, 0, ETH_ALEN);
2158 memset(priv->bssid, 0, ETH_ALEN);
2159 p54_setup_mac(dev);
2160 mutex_unlock(&priv->conf_mutex);
2161}
2162
2163static int p54_config(struct ieee80211_hw *dev, u32 changed)
2164{
2165 int ret = 0;
2166 struct p54_common *priv = dev->priv;
2167 struct ieee80211_conf *conf = &dev->conf;
2168
2169 mutex_lock(&priv->conf_mutex);
2170 if (changed & IEEE80211_CONF_CHANGE_POWER)
2171 priv->output_power = conf->power_level << 2;
2172 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
2173 ret = p54_setup_mac(dev);
2174 if (ret)
2175 goto out;
2176 }
2177 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2178 ret = p54_scan(dev, P54_SCAN_EXIT, 0);
2179 if (ret)
2180 goto out;
2181 }
2182 if (changed & IEEE80211_CONF_CHANGE_PS) {
2183 ret = p54_set_ps(dev);
2184 if (ret)
2185 goto out;
2186 }
2187
2188out:
2189 mutex_unlock(&priv->conf_mutex);
2190 return ret;
2191}
2192
2193static void p54_configure_filter(struct ieee80211_hw *dev,
2194 unsigned int changed_flags,
2195 unsigned int *total_flags,
2196 int mc_count, struct dev_mc_list *mclist)
2197{
2198 struct p54_common *priv = dev->priv;
2199
2200 *total_flags &= FIF_PROMISC_IN_BSS |
2201 FIF_OTHER_BSS;
2202
2203 priv->filter_flags = *total_flags;
2204
2205 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS))
2206 p54_setup_mac(dev);
2207}
2208
2209static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue,
2210 const struct ieee80211_tx_queue_params *params)
2211{
2212 struct p54_common *priv = dev->priv;
2213 int ret;
2214
2215 mutex_lock(&priv->conf_mutex);
2216 if ((params) && !(queue > 4)) {
2217 P54_SET_QUEUE(priv->qos_params[queue], params->aifs,
2218 params->cw_min, params->cw_max, params->txop);
2219 ret = p54_set_edcf(dev);
2220 } else
2221 ret = -EINVAL;
2222 mutex_unlock(&priv->conf_mutex);
2223 return ret;
2224}
2225
2226static int p54_init_xbow_synth(struct ieee80211_hw *dev)
2227{
2228 struct p54_common *priv = dev->priv;
2229 struct sk_buff *skb;
2230 struct p54_xbow_synth *xbow;
2231
2232 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*xbow),
2233 P54_CONTROL_TYPE_XBOW_SYNTH_CFG, GFP_KERNEL);
2234 if (!skb)
2235 return -ENOMEM;
2236
2237 xbow = (struct p54_xbow_synth *)skb_put(skb, sizeof(*xbow));
2238 xbow->magic1 = cpu_to_le16(0x1);
2239 xbow->magic2 = cpu_to_le16(0x2);
2240 xbow->freq = cpu_to_le16(5390);
2241 memset(xbow->padding, 0, sizeof(xbow->padding));
2242 priv->tx(dev, skb);
2243 return 0;
2244}
2245
2246static void p54_work(struct work_struct *work)
2247{
2248 struct p54_common *priv = container_of(work, struct p54_common,
2249 work.work);
2250 struct ieee80211_hw *dev = priv->hw;
2251 struct sk_buff *skb;
2252
2253 if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
2254 return ;
2255
2256 /*
2257 * TODO: walk through tx_queue and do the following tasks
2258 * 1. initiate bursts.
2259 * 2. cancel stuck frames / reset the device if necessary.
2260 */
2261
2262 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL,
2263 sizeof(struct p54_statistics),
2264 P54_CONTROL_TYPE_STAT_READBACK, GFP_KERNEL);
2265 if (!skb)
2266 return ;
2267
2268 priv->tx(dev, skb);
2269}
2270
2271static int p54_get_stats(struct ieee80211_hw *dev,
2272 struct ieee80211_low_level_stats *stats)
2273{
2274 struct p54_common *priv = dev->priv;
2275
2276 memcpy(stats, &priv->stats, sizeof(*stats));
2277 return 0;
2278}
2279
2280static int p54_get_tx_stats(struct ieee80211_hw *dev,
2281 struct ieee80211_tx_queue_stats *stats)
2282{
2283 struct p54_common *priv = dev->priv;
2284
2285 memcpy(stats, &priv->tx_stats[P54_QUEUE_DATA],
2286 sizeof(stats[0]) * dev->queues);
2287 return 0;
2288}
2289
2290static void p54_bss_info_changed(struct ieee80211_hw *dev,
2291 struct ieee80211_vif *vif,
2292 struct ieee80211_bss_conf *info,
2293 u32 changed)
2294{
2295 struct p54_common *priv = dev->priv;
2296 int ret;
2297
2298 mutex_lock(&priv->conf_mutex);
2299 if (changed & BSS_CHANGED_BSSID) {
2300 memcpy(priv->bssid, info->bssid, ETH_ALEN);
2301 ret = p54_setup_mac(dev);
2302 if (ret)
2303 goto out;
2304 }
2305
2306 if (changed & BSS_CHANGED_BEACON) {
2307 ret = p54_scan(dev, P54_SCAN_EXIT, 0);
2308 if (ret)
2309 goto out;
2310 ret = p54_setup_mac(dev);
2311 if (ret)
2312 goto out;
2313 ret = p54_beacon_update(dev, vif);
2314 if (ret)
2315 goto out;
2316 }
2317 /* XXX: this mimics having two callbacks... clean up */
2318 out:
2319 mutex_unlock(&priv->conf_mutex);
2320
2321 if (changed & (BSS_CHANGED_ERP_SLOT | BSS_CHANGED_BEACON)) {
2322 priv->use_short_slot = info->use_short_slot;
2323 p54_set_edcf(dev);
2324 }
2325 if (changed & BSS_CHANGED_BASIC_RATES) {
2326 if (dev->conf.channel->band == IEEE80211_BAND_5GHZ)
2327 priv->basic_rate_mask = (info->basic_rates << 4);
2328 else
2329 priv->basic_rate_mask = info->basic_rates;
2330 p54_setup_mac(dev);
2331 if (priv->fw_var >= 0x500)
2332 p54_scan(dev, P54_SCAN_EXIT, 0);
2333 }
2334 if (changed & BSS_CHANGED_ASSOC) {
2335 if (info->assoc) {
2336 priv->aid = info->aid;
2337 priv->wakeup_timer = info->beacon_int *
2338 info->dtim_period * 5;
2339 p54_setup_mac(dev);
2340 }
2341 }
2342}
2343
2344static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
2345 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2346 struct ieee80211_key_conf *key)
2347{
2348 struct p54_common *priv = dev->priv;
2349 struct sk_buff *skb;
2350 struct p54_keycache *rxkey;
2351 int slot, ret = 0;
2352 u8 algo = 0;
2353
2354 if (modparam_nohwcrypt)
2355 return -EOPNOTSUPP;
2356
2357 mutex_lock(&priv->conf_mutex);
2358 if (cmd == SET_KEY) {
2359 switch (key->alg) {
2360 case ALG_TKIP:
2361 if (!(priv->privacy_caps & (BR_DESC_PRIV_CAP_MICHAEL |
2362 BR_DESC_PRIV_CAP_TKIP))) {
2363 ret = -EOPNOTSUPP;
2364 goto out_unlock;
2365 }
2366 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2367 algo = P54_CRYPTO_TKIPMICHAEL;
2368 break;
2369 case ALG_WEP:
2370 if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_WEP)) {
2371 ret = -EOPNOTSUPP;
2372 goto out_unlock;
2373 }
2374 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2375 algo = P54_CRYPTO_WEP;
2376 break;
2377 case ALG_CCMP:
2378 if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP)) {
2379 ret = -EOPNOTSUPP;
2380 goto out_unlock;
2381 }
2382 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2383 algo = P54_CRYPTO_AESCCMP;
2384 break;
2385 default:
2386 ret = -EOPNOTSUPP;
2387 goto out_unlock;
2388 }
2389 slot = bitmap_find_free_region(priv->used_rxkeys,
2390 priv->rx_keycache_size, 0);
2391
2392 if (slot < 0) {
2393 /*
2394 * The device supports the choosen algorithm, but the
2395 * firmware does not provide enough key slots to store
2396 * all of them.
2397 * But encryption offload for outgoing frames is always
2398 * possible, so we just pretend that the upload was
2399 * successful and do the decryption in software.
2400 */
2401
2402 /* mark the key as invalid. */
2403 key->hw_key_idx = 0xff;
2404 goto out_unlock;
2405 }
2406 } else {
2407 slot = key->hw_key_idx;
2408
2409 if (slot == 0xff) {
2410 /* This key was not uploaded into the rx key cache. */
2411
2412 goto out_unlock;
2413 }
2414
2415 bitmap_release_region(priv->used_rxkeys, slot, 0);
2416 algo = 0;
2417 }
2418
2419 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*rxkey),
2420 P54_CONTROL_TYPE_RX_KEYCACHE, GFP_KERNEL);
2421 if (!skb) {
2422 bitmap_release_region(priv->used_rxkeys, slot, 0);
2423 ret = -ENOSPC;
2424 goto out_unlock;
2425 }
2426
2427 rxkey = (struct p54_keycache *)skb_put(skb, sizeof(*rxkey));
2428 rxkey->entry = slot;
2429 rxkey->key_id = key->keyidx;
2430 rxkey->key_type = algo;
2431 if (sta)
2432 memcpy(rxkey->mac, sta->addr, ETH_ALEN);
2433 else
2434 memset(rxkey->mac, ~0, ETH_ALEN);
2435 if (key->alg != ALG_TKIP) {
2436 rxkey->key_len = min((u8)16, key->keylen);
2437 memcpy(rxkey->key, key->key, rxkey->key_len);
2438 } else {
2439 rxkey->key_len = 24;
2440 memcpy(rxkey->key, key->key, 16);
2441 memcpy(&(rxkey->key[16]), &(key->key
2442 [NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]), 8);
2443 }
2444
2445 priv->tx(dev, skb);
2446 key->hw_key_idx = slot;
2447
2448out_unlock:
2449 mutex_unlock(&priv->conf_mutex);
2450 return ret;
2451}
2452
2453#ifdef CONFIG_P54_LEDS
2454static void p54_update_leds(struct work_struct *work)
2455{
2456 struct p54_common *priv = container_of(work, struct p54_common,
2457 led_work.work);
2458 int err, i, tmp, blink_delay = 400;
2459 bool rerun = false;
2460
2461 /* Don't toggle the LED, when the device is down. */
2462 if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
2463 return ;
2464
2465 for (i = 0; i < ARRAY_SIZE(priv->leds); i++)
2466 if (priv->leds[i].toggled) {
2467 priv->softled_state |= BIT(i);
2468
2469 tmp = 70 + 200 / (priv->leds[i].toggled);
2470 if (tmp < blink_delay)
2471 blink_delay = tmp;
2472
2473 if (priv->leds[i].led_dev.brightness == LED_OFF)
2474 rerun = true;
2475
2476 priv->leds[i].toggled =
2477 !!priv->leds[i].led_dev.brightness;
2478 } else
2479 priv->softled_state &= ~BIT(i);
2480
2481 err = p54_set_leds(priv->hw);
2482 if (err && net_ratelimit())
2483 printk(KERN_ERR "%s: failed to update LEDs.\n",
2484 wiphy_name(priv->hw->wiphy));
2485
2486 if (rerun)
2487 queue_delayed_work(priv->hw->workqueue, &priv->led_work,
2488 msecs_to_jiffies(blink_delay));
2489}
2490
2491static void p54_led_brightness_set(struct led_classdev *led_dev,
2492 enum led_brightness brightness)
2493{
2494 struct p54_led_dev *led = container_of(led_dev, struct p54_led_dev,
2495 led_dev);
2496 struct ieee80211_hw *dev = led->hw_dev;
2497 struct p54_common *priv = dev->priv;
2498
2499 if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
2500 return ;
2501
2502 if (brightness) {
2503 led->toggled++;
2504 queue_delayed_work(priv->hw->workqueue, &priv->led_work,
2505 HZ/10);
2506 }
2507}
2508
2509static int p54_register_led(struct ieee80211_hw *dev,
2510 unsigned int led_index,
2511 char *name, char *trigger)
2512{
2513 struct p54_common *priv = dev->priv;
2514 struct p54_led_dev *led = &priv->leds[led_index];
2515 int err;
2516
2517 if (led->registered)
2518 return -EEXIST;
2519
2520 snprintf(led->name, sizeof(led->name), "p54-%s::%s",
2521 wiphy_name(dev->wiphy), name);
2522 led->hw_dev = dev;
2523 led->index = led_index;
2524 led->led_dev.name = led->name;
2525 led->led_dev.default_trigger = trigger;
2526 led->led_dev.brightness_set = p54_led_brightness_set;
2527
2528 err = led_classdev_register(wiphy_dev(dev->wiphy), &led->led_dev);
2529 if (err)
2530 printk(KERN_ERR "%s: Failed to register %s LED.\n",
2531 wiphy_name(dev->wiphy), name);
2532 else
2533 led->registered = 1;
2534
2535 return err;
2536}
2537
2538static int p54_init_leds(struct ieee80211_hw *dev)
2539{
2540 struct p54_common *priv = dev->priv;
2541 int err;
2542
2543 /*
2544 * TODO:
2545 * Figure out if the EEPROM contains some hints about the number
2546 * of available/programmable LEDs of the device.
2547 */
2548
2549 INIT_DELAYED_WORK(&priv->led_work, p54_update_leds);
2550
2551 err = p54_register_led(dev, 0, "assoc",
2552 ieee80211_get_assoc_led_name(dev));
2553 if (err)
2554 return err;
2555
2556 err = p54_register_led(dev, 1, "tx",
2557 ieee80211_get_tx_led_name(dev));
2558 if (err)
2559 return err;
2560
2561 err = p54_register_led(dev, 2, "rx",
2562 ieee80211_get_rx_led_name(dev));
2563 if (err)
2564 return err;
2565
2566 err = p54_register_led(dev, 3, "radio",
2567 ieee80211_get_radio_led_name(dev));
2568 if (err)
2569 return err;
2570
2571 err = p54_set_leds(dev);
2572 return err;
2573}
2574
2575static void p54_unregister_leds(struct ieee80211_hw *dev)
2576{
2577 struct p54_common *priv = dev->priv;
2578 int i;
2579
2580 for (i = 0; i < ARRAY_SIZE(priv->leds); i++)
2581 if (priv->leds[i].registered)
2582 led_classdev_unregister(&priv->leds[i].led_dev);
2583}
2584#endif /* CONFIG_P54_LEDS */
2585
2586static const struct ieee80211_ops p54_ops = {
2587 .tx = p54_tx,
2588 .start = p54_start,
2589 .stop = p54_stop,
2590 .add_interface = p54_add_interface,
2591 .remove_interface = p54_remove_interface,
2592 .set_tim = p54_set_tim,
2593 .sta_notify = p54_sta_notify,
2594 .set_key = p54_set_key,
2595 .config = p54_config,
2596 .bss_info_changed = p54_bss_info_changed,
2597 .configure_filter = p54_configure_filter,
2598 .conf_tx = p54_conf_tx,
2599 .get_stats = p54_get_stats,
2600 .get_tx_stats = p54_get_tx_stats
2601};
2602
2603struct ieee80211_hw *p54_init_common(size_t priv_data_len)
2604{
2605 struct ieee80211_hw *dev;
2606 struct p54_common *priv;
2607
2608 dev = ieee80211_alloc_hw(priv_data_len, &p54_ops);
2609 if (!dev)
2610 return NULL;
2611
2612 priv = dev->priv;
2613 priv->hw = dev;
2614 priv->mode = NL80211_IFTYPE_UNSPECIFIED;
2615 priv->basic_rate_mask = 0x15f;
2616 skb_queue_head_init(&priv->tx_queue);
2617 dev->flags = IEEE80211_HW_RX_INCLUDES_FCS |
2618 IEEE80211_HW_SIGNAL_DBM |
2619 IEEE80211_HW_NOISE_DBM;
2620
2621 dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2622 BIT(NL80211_IFTYPE_ADHOC) |
2623 BIT(NL80211_IFTYPE_AP) |
2624 BIT(NL80211_IFTYPE_MESH_POINT);
2625
2626 dev->channel_change_time = 1000; /* TODO: find actual value */
2627 priv->tx_stats[P54_QUEUE_BEACON].limit = 1;
2628 priv->tx_stats[P54_QUEUE_FWSCAN].limit = 1;
2629 priv->tx_stats[P54_QUEUE_MGMT].limit = 3;
2630 priv->tx_stats[P54_QUEUE_CAB].limit = 3;
2631 priv->tx_stats[P54_QUEUE_DATA].limit = 5;
2632 dev->queues = 1;
2633 priv->noise = -94;
2634 /*
2635 * We support at most 8 tries no matter which rate they're at,
2636 * we cannot support max_rates * max_rate_tries as we set it
2637 * here, but setting it correctly to 4/2 or so would limit us
2638 * artificially if the RC algorithm wants just two rates, so
2639 * let's say 4/7, we'll redistribute it at TX time, see the
2640 * comments there.
2641 */
2642 dev->max_rates = 4;
2643 dev->max_rate_tries = 7;
2644 dev->extra_tx_headroom = sizeof(struct p54_hdr) + 4 +
2645 sizeof(struct p54_tx_data);
2646
2647 mutex_init(&priv->conf_mutex);
2648 init_completion(&priv->eeprom_comp);
2649 INIT_DELAYED_WORK(&priv->work, p54_work);
2650
2651 return dev;
2652}
2653EXPORT_SYMBOL_GPL(p54_init_common);
2654
2655int p54_register_common(struct ieee80211_hw *dev, struct device *pdev)
2656{
2657 int err;
2658
2659 err = ieee80211_register_hw(dev);
2660 if (err) {
2661 dev_err(pdev, "Cannot register device (%d).\n", err);
2662 return err;
2663 }
2664
2665#ifdef CONFIG_P54_LEDS
2666 err = p54_init_leds(dev);
2667 if (err)
2668 return err;
2669#endif /* CONFIG_P54_LEDS */
2670
2671 dev_info(pdev, "is registered as '%s'\n", wiphy_name(dev->wiphy));
2672 return 0;
2673}
2674EXPORT_SYMBOL_GPL(p54_register_common);
2675
2676void p54_free_common(struct ieee80211_hw *dev)
2677{
2678 struct p54_common *priv = dev->priv;
2679 kfree(priv->iq_autocal);
2680 kfree(priv->output_limit);
2681 kfree(priv->curve_data);
2682 kfree(priv->used_rxkeys);
2683
2684#ifdef CONFIG_P54_LEDS
2685 p54_unregister_leds(dev);
2686#endif /* CONFIG_P54_LEDS */
2687}
2688EXPORT_SYMBOL_GPL(p54_free_common);
diff --git a/drivers/net/wireless/p54/p54common.h b/drivers/net/wireless/p54/p54common.h
deleted file mode 100644
index 75ead7a150fc..000000000000
--- a/drivers/net/wireless/p54/p54common.h
+++ /dev/null
@@ -1,644 +0,0 @@
1#ifndef P54COMMON_H
2#define P54COMMON_H
3
4/*
5 * Common code specific definitions for mac80211 Prism54 drivers
6 *
7 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
8 * Copyright (c) 2007, Christian Lamparter <chunkeey@web.de>
9 *
10 * Based on:
11 * - the islsm (softmac prism54) driver, which is:
12 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
13 *
14 * - LMAC API interface header file for STLC4560 (lmac_longbow.h)
15 * Copyright (C) 2007 Conexant Systems, Inc.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
20 */
21
22struct bootrec {
23 __le32 code;
24 __le32 len;
25 u32 data[10];
26} __attribute__((packed));
27
28#define PDR_SYNTH_FRONTEND_MASK 0x0007
29#define PDR_SYNTH_FRONTEND_DUETTE3 0x0001
30#define PDR_SYNTH_FRONTEND_DUETTE2 0x0002
31#define PDR_SYNTH_FRONTEND_FRISBEE 0x0003
32#define PDR_SYNTH_FRONTEND_XBOW 0x0004
33#define PDR_SYNTH_FRONTEND_LONGBOW 0x0005
34#define PDR_SYNTH_IQ_CAL_MASK 0x0018
35#define PDR_SYNTH_IQ_CAL_PA_DETECTOR 0x0000
36#define PDR_SYNTH_IQ_CAL_DISABLED 0x0008
37#define PDR_SYNTH_IQ_CAL_ZIF 0x0010
38#define PDR_SYNTH_FAA_SWITCH_MASK 0x0020
39#define PDR_SYNTH_FAA_SWITCH_ENABLED 0x0020
40#define PDR_SYNTH_24_GHZ_MASK 0x0040
41#define PDR_SYNTH_24_GHZ_DISABLED 0x0040
42#define PDR_SYNTH_5_GHZ_MASK 0x0080
43#define PDR_SYNTH_5_GHZ_DISABLED 0x0080
44#define PDR_SYNTH_RX_DIV_MASK 0x0100
45#define PDR_SYNTH_RX_DIV_SUPPORTED 0x0100
46#define PDR_SYNTH_TX_DIV_MASK 0x0200
47#define PDR_SYNTH_TX_DIV_SUPPORTED 0x0200
48
49struct bootrec_exp_if {
50 __le16 role;
51 __le16 if_id;
52 __le16 variant;
53 __le16 btm_compat;
54 __le16 top_compat;
55} __attribute__((packed));
56
57#define BR_DESC_PRIV_CAP_WEP BIT(0)
58#define BR_DESC_PRIV_CAP_TKIP BIT(1)
59#define BR_DESC_PRIV_CAP_MICHAEL BIT(2)
60#define BR_DESC_PRIV_CAP_CCX_CP BIT(3)
61#define BR_DESC_PRIV_CAP_CCX_MIC BIT(4)
62#define BR_DESC_PRIV_CAP_AESCCMP BIT(5)
63
64struct bootrec_desc {
65 __le16 modes;
66 __le16 flags;
67 __le32 rx_start;
68 __le32 rx_end;
69 u8 headroom;
70 u8 tailroom;
71 u8 tx_queues;
72 u8 tx_depth;
73 u8 privacy_caps;
74 u8 rx_keycache_size;
75 u8 time_size;
76 u8 padding;
77 u8 rates[16];
78 u8 padding2[4];
79 __le16 rx_mtu;
80} __attribute__((packed));
81
82#define BR_CODE_MIN 0x80000000
83#define BR_CODE_COMPONENT_ID 0x80000001
84#define BR_CODE_COMPONENT_VERSION 0x80000002
85#define BR_CODE_DEPENDENT_IF 0x80000003
86#define BR_CODE_EXPOSED_IF 0x80000004
87#define BR_CODE_DESCR 0x80000101
88#define BR_CODE_MAX 0x8FFFFFFF
89#define BR_CODE_END_OF_BRA 0xFF0000FF
90#define LEGACY_BR_CODE_END_OF_BRA 0xFFFFFFFF
91
92#define P54_HDR_FLAG_DATA_ALIGN BIT(14)
93#define P54_HDR_FLAG_DATA_OUT_PROMISC BIT(0)
94#define P54_HDR_FLAG_DATA_OUT_TIMESTAMP BIT(1)
95#define P54_HDR_FLAG_DATA_OUT_SEQNR BIT(2)
96#define P54_HDR_FLAG_DATA_OUT_BIT3 BIT(3)
97#define P54_HDR_FLAG_DATA_OUT_BURST BIT(4)
98#define P54_HDR_FLAG_DATA_OUT_NOCANCEL BIT(5)
99#define P54_HDR_FLAG_DATA_OUT_CLEARTIM BIT(6)
100#define P54_HDR_FLAG_DATA_OUT_HITCHHIKE BIT(7)
101#define P54_HDR_FLAG_DATA_OUT_COMPRESS BIT(8)
102#define P54_HDR_FLAG_DATA_OUT_CONCAT BIT(9)
103#define P54_HDR_FLAG_DATA_OUT_PCS_ACCEPT BIT(10)
104#define P54_HDR_FLAG_DATA_OUT_WAITEOSP BIT(11)
105
106#define P54_HDR_FLAG_DATA_IN_FCS_GOOD BIT(0)
107#define P54_HDR_FLAG_DATA_IN_MATCH_MAC BIT(1)
108#define P54_HDR_FLAG_DATA_IN_MCBC BIT(2)
109#define P54_HDR_FLAG_DATA_IN_BEACON BIT(3)
110#define P54_HDR_FLAG_DATA_IN_MATCH_BSS BIT(4)
111#define P54_HDR_FLAG_DATA_IN_BCAST_BSS BIT(5)
112#define P54_HDR_FLAG_DATA_IN_DATA BIT(6)
113#define P54_HDR_FLAG_DATA_IN_TRUNCATED BIT(7)
114#define P54_HDR_FLAG_DATA_IN_BIT8 BIT(8)
115#define P54_HDR_FLAG_DATA_IN_TRANSPARENT BIT(9)
116
117/* PDA defines are Copyright (C) 2005 Nokia Corporation (taken from islsm_pda.h) */
118
119struct pda_entry {
120 __le16 len; /* includes both code and data */
121 __le16 code;
122 u8 data[0];
123} __attribute__ ((packed));
124
125struct eeprom_pda_wrap {
126 __le32 magic;
127 __le16 pad;
128 __le16 len;
129 __le32 arm_opcode;
130 u8 data[0];
131} __attribute__ ((packed));
132
133struct p54_iq_autocal_entry {
134 __le16 iq_param[4];
135} __attribute__ ((packed));
136
137struct pda_iq_autocal_entry {
138 __le16 freq;
139 struct p54_iq_autocal_entry params;
140} __attribute__ ((packed));
141
142struct pda_channel_output_limit {
143 __le16 freq;
144 u8 val_bpsk;
145 u8 val_qpsk;
146 u8 val_16qam;
147 u8 val_64qam;
148 u8 rate_set_mask;
149 u8 rate_set_size;
150} __attribute__ ((packed));
151
152struct pda_pa_curve_data_sample_rev0 {
153 u8 rf_power;
154 u8 pa_detector;
155 u8 pcv;
156} __attribute__ ((packed));
157
158struct pda_pa_curve_data_sample_rev1 {
159 u8 rf_power;
160 u8 pa_detector;
161 u8 data_barker;
162 u8 data_bpsk;
163 u8 data_qpsk;
164 u8 data_16qam;
165 u8 data_64qam;
166} __attribute__ ((packed));
167
168struct p54_pa_curve_data_sample {
169 u8 rf_power;
170 u8 pa_detector;
171 u8 data_barker;
172 u8 data_bpsk;
173 u8 data_qpsk;
174 u8 data_16qam;
175 u8 data_64qam;
176 u8 padding;
177} __attribute__ ((packed));
178
179struct pda_pa_curve_data {
180 u8 cal_method_rev;
181 u8 channels;
182 u8 points_per_channel;
183 u8 padding;
184 u8 data[0];
185} __attribute__ ((packed));
186
187struct pda_rssi_cal_entry {
188 __le16 mul;
189 __le16 add;
190} __attribute__ ((packed));
191
192struct pda_country {
193 u8 regdomain;
194 u8 alpha2[2];
195 u8 flags;
196} __attribute__ ((packed));
197
198/*
199 * Warning: Longbow's structures are bogus.
200 */
201struct p54_channel_output_limit_longbow {
202 __le16 rf_power_points[12];
203} __attribute__ ((packed));
204
205struct p54_pa_curve_data_sample_longbow {
206 __le16 rf_power;
207 __le16 pa_detector;
208 struct {
209 __le16 data[4];
210 } points[3] __attribute__ ((packed));
211} __attribute__ ((packed));
212
213struct pda_custom_wrapper {
214 __le16 entries;
215 __le16 entry_size;
216 __le16 offset;
217 __le16 len;
218 u8 data[0];
219} __attribute__ ((packed));
220
221/*
222 * this defines the PDR codes used to build PDAs as defined in document
223 * number 553155. The current implementation mirrors version 1.1 of the
224 * document and lists only PDRs supported by the ARM platform.
225 */
226
227/* common and choice range (0x0000 - 0x0fff) */
228#define PDR_END 0x0000
229#define PDR_MANUFACTURING_PART_NUMBER 0x0001
230#define PDR_PDA_VERSION 0x0002
231#define PDR_NIC_SERIAL_NUMBER 0x0003
232
233#define PDR_MAC_ADDRESS 0x0101
234#define PDR_REGULATORY_DOMAIN_LIST 0x0103
235#define PDR_TEMPERATURE_TYPE 0x0107
236
237#define PDR_PRISM_PCI_IDENTIFIER 0x0402
238
239/* ARM range (0x1000 - 0x1fff) */
240#define PDR_COUNTRY_INFORMATION 0x1000
241#define PDR_INTERFACE_LIST 0x1001
242#define PDR_HARDWARE_PLATFORM_COMPONENT_ID 0x1002
243#define PDR_OEM_NAME 0x1003
244#define PDR_PRODUCT_NAME 0x1004
245#define PDR_UTF8_OEM_NAME 0x1005
246#define PDR_UTF8_PRODUCT_NAME 0x1006
247#define PDR_COUNTRY_LIST 0x1007
248#define PDR_DEFAULT_COUNTRY 0x1008
249
250#define PDR_ANTENNA_GAIN 0x1100
251
252#define PDR_PRISM_INDIGO_PA_CALIBRATION_DATA 0x1901
253#define PDR_RSSI_LINEAR_APPROXIMATION 0x1902
254#define PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS 0x1903
255#define PDR_PRISM_PA_CAL_CURVE_DATA 0x1904
256#define PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND 0x1905
257#define PDR_PRISM_ZIF_TX_IQ_CALIBRATION 0x1906
258#define PDR_REGULATORY_POWER_LIMITS 0x1907
259#define PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED 0x1908
260#define PDR_RADIATED_TRANSMISSION_CORRECTION 0x1909
261#define PDR_PRISM_TX_IQ_CALIBRATION 0x190a
262
263/* reserved range (0x2000 - 0x7fff) */
264
265/* customer range (0x8000 - 0xffff) */
266#define PDR_BASEBAND_REGISTERS 0x8000
267#define PDR_PER_CHANNEL_BASEBAND_REGISTERS 0x8001
268
269/* used by our modificated eeprom image */
270#define PDR_RSSI_LINEAR_APPROXIMATION_CUSTOM 0xDEAD
271#define PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM 0xBEEF
272#define PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM 0xB05D
273
274/* PDR definitions for default country & country list */
275#define PDR_COUNTRY_CERT_CODE 0x80
276#define PDR_COUNTRY_CERT_CODE_REAL 0x00
277#define PDR_COUNTRY_CERT_CODE_PSEUDO 0x80
278#define PDR_COUNTRY_CERT_BAND 0x40
279#define PDR_COUNTRY_CERT_BAND_2GHZ 0x00
280#define PDR_COUNTRY_CERT_BAND_5GHZ 0x40
281#define PDR_COUNTRY_CERT_IODOOR 0x30
282#define PDR_COUNTRY_CERT_IODOOR_BOTH 0x00
283#define PDR_COUNTRY_CERT_IODOOR_INDOOR 0x20
284#define PDR_COUNTRY_CERT_IODOOR_OUTDOOR 0x30
285#define PDR_COUNTRY_CERT_INDEX 0x0F
286
287struct p54_eeprom_lm86 {
288 union {
289 struct {
290 __le16 offset;
291 __le16 len;
292 u8 data[0];
293 } v1;
294 struct {
295 __le32 offset;
296 __le16 len;
297 u8 magic2;
298 u8 pad;
299 u8 magic[4];
300 u8 data[0];
301 } v2;
302 } __attribute__ ((packed));
303} __attribute__ ((packed));
304
305enum p54_rx_decrypt_status {
306 P54_DECRYPT_NONE = 0,
307 P54_DECRYPT_OK,
308 P54_DECRYPT_NOKEY,
309 P54_DECRYPT_NOMICHAEL,
310 P54_DECRYPT_NOCKIPMIC,
311 P54_DECRYPT_FAIL_WEP,
312 P54_DECRYPT_FAIL_TKIP,
313 P54_DECRYPT_FAIL_MICHAEL,
314 P54_DECRYPT_FAIL_CKIPKP,
315 P54_DECRYPT_FAIL_CKIPMIC,
316 P54_DECRYPT_FAIL_AESCCMP
317};
318
319struct p54_rx_data {
320 __le16 flags;
321 __le16 len;
322 __le16 freq;
323 u8 antenna;
324 u8 rate;
325 u8 rssi;
326 u8 quality;
327 u8 decrypt_status;
328 u8 rssi_raw;
329 __le32 tsf32;
330 __le32 unalloc0;
331 u8 align[0];
332} __attribute__ ((packed));
333
334enum p54_trap_type {
335 P54_TRAP_SCAN = 0,
336 P54_TRAP_TIMER,
337 P54_TRAP_BEACON_TX,
338 P54_TRAP_FAA_RADIO_ON,
339 P54_TRAP_FAA_RADIO_OFF,
340 P54_TRAP_RADAR,
341 P54_TRAP_NO_BEACON,
342 P54_TRAP_TBTT,
343 P54_TRAP_SCO_ENTER,
344 P54_TRAP_SCO_EXIT
345};
346
347struct p54_trap {
348 __le16 event;
349 __le16 frequency;
350} __attribute__ ((packed));
351
352enum p54_frame_sent_status {
353 P54_TX_OK = 0,
354 P54_TX_FAILED,
355 P54_TX_PSM,
356 P54_TX_PSM_CANCELLED = 4
357};
358
359struct p54_frame_sent {
360 u8 status;
361 u8 tries;
362 u8 ack_rssi;
363 u8 quality;
364 __le16 seq;
365 u8 antenna;
366 u8 padding;
367} __attribute__ ((packed));
368
369enum p54_tx_data_crypt {
370 P54_CRYPTO_NONE = 0,
371 P54_CRYPTO_WEP,
372 P54_CRYPTO_TKIP,
373 P54_CRYPTO_TKIPMICHAEL,
374 P54_CRYPTO_CCX_WEPMIC,
375 P54_CRYPTO_CCX_KPMIC,
376 P54_CRYPTO_CCX_KP,
377 P54_CRYPTO_AESCCMP
378};
379
380enum p54_tx_data_queue {
381 P54_QUEUE_BEACON = 0,
382 P54_QUEUE_FWSCAN = 1,
383 P54_QUEUE_MGMT = 2,
384 P54_QUEUE_CAB = 3,
385 P54_QUEUE_DATA = 4,
386
387 P54_QUEUE_AC_NUM = 4,
388 P54_QUEUE_AC_VO = 4,
389 P54_QUEUE_AC_VI = 5,
390 P54_QUEUE_AC_BE = 6,
391 P54_QUEUE_AC_BK = 7,
392
393 /* keep last */
394 P54_QUEUE_NUM = 8,
395};
396
397struct p54_tx_data {
398 u8 rateset[8];
399 u8 rts_rate_idx;
400 u8 crypt_offset;
401 u8 key_type;
402 u8 key_len;
403 u8 key[16];
404 u8 hw_queue;
405 u8 backlog;
406 __le16 durations[4];
407 u8 tx_antenna;
408 union {
409 struct {
410 u8 cts_rate;
411 __le16 output_power;
412 } __attribute__((packed)) longbow;
413 struct {
414 u8 output_power;
415 u8 cts_rate;
416 u8 unalloc;
417 } __attribute__ ((packed)) normal;
418 } __attribute__ ((packed));
419 u8 unalloc2[2];
420 u8 align[0];
421} __attribute__ ((packed));
422
423/* unit is ms */
424#define P54_TX_FRAME_LIFETIME 2000
425#define P54_TX_TIMEOUT 4000
426#define P54_STATISTICS_UPDATE 5000
427
428#define P54_FILTER_TYPE_NONE 0
429#define P54_FILTER_TYPE_STATION BIT(0)
430#define P54_FILTER_TYPE_IBSS BIT(1)
431#define P54_FILTER_TYPE_AP BIT(2)
432#define P54_FILTER_TYPE_TRANSPARENT BIT(3)
433#define P54_FILTER_TYPE_PROMISCUOUS BIT(4)
434#define P54_FILTER_TYPE_HIBERNATE BIT(5)
435#define P54_FILTER_TYPE_NOACK BIT(6)
436#define P54_FILTER_TYPE_RX_DISABLED BIT(7)
437
438struct p54_setup_mac {
439 __le16 mac_mode;
440 u8 mac_addr[ETH_ALEN];
441 u8 bssid[ETH_ALEN];
442 u8 rx_antenna;
443 u8 rx_align;
444 union {
445 struct {
446 __le32 basic_rate_mask;
447 u8 rts_rates[8];
448 __le32 rx_addr;
449 __le16 max_rx;
450 __le16 rxhw;
451 __le16 wakeup_timer;
452 __le16 unalloc0;
453 } v1 __attribute__ ((packed));
454 struct {
455 __le32 rx_addr;
456 __le16 max_rx;
457 __le16 rxhw;
458 __le16 timer;
459 __le16 truncate;
460 __le32 basic_rate_mask;
461 u8 sbss_offset;
462 u8 mcast_window;
463 u8 rx_rssi_threshold;
464 u8 rx_ed_threshold;
465 __le32 ref_clock;
466 __le16 lpf_bandwidth;
467 __le16 osc_start_delay;
468 } v2 __attribute__ ((packed));
469 } __attribute__ ((packed));
470} __attribute__ ((packed));
471
472#define P54_SETUP_V1_LEN 40
473#define P54_SETUP_V2_LEN (sizeof(struct p54_setup_mac))
474
475#define P54_SCAN_EXIT BIT(0)
476#define P54_SCAN_TRAP BIT(1)
477#define P54_SCAN_ACTIVE BIT(2)
478#define P54_SCAN_FILTER BIT(3)
479
480struct p54_scan_head {
481 __le16 mode;
482 __le16 dwell;
483 u8 scan_params[20];
484 __le16 freq;
485} __attribute__ ((packed));
486
487struct p54_scan_body {
488 u8 pa_points_per_curve;
489 u8 val_barker;
490 u8 val_bpsk;
491 u8 val_qpsk;
492 u8 val_16qam;
493 u8 val_64qam;
494 struct p54_pa_curve_data_sample curve_data[8];
495 u8 dup_bpsk;
496 u8 dup_qpsk;
497 u8 dup_16qam;
498 u8 dup_64qam;
499} __attribute__ ((packed));
500
501struct p54_scan_body_longbow {
502 struct p54_channel_output_limit_longbow power_limits;
503 struct p54_pa_curve_data_sample_longbow curve_data[8];
504 __le16 unkn[6]; /* maybe more power_limits or rate_mask */
505} __attribute__ ((packed));
506
507union p54_scan_body_union {
508 struct p54_scan_body normal;
509 struct p54_scan_body_longbow longbow;
510} __attribute__ ((packed));
511
512struct p54_scan_tail_rate {
513 __le32 basic_rate_mask;
514 u8 rts_rates[8];
515} __attribute__ ((packed));
516
517struct p54_led {
518 __le16 flags;
519 __le16 mask[2];
520 __le16 delay[2];
521} __attribute__ ((packed));
522
523struct p54_edcf {
524 u8 flags;
525 u8 slottime;
526 u8 sifs;
527 u8 eofpad;
528 struct p54_edcf_queue_param queue[8];
529 u8 mapping[4];
530 __le16 frameburst;
531 __le16 round_trip_delay;
532} __attribute__ ((packed));
533
534struct p54_statistics {
535 __le32 rx_success;
536 __le32 rx_bad_fcs;
537 __le32 rx_abort;
538 __le32 rx_abort_phy;
539 __le32 rts_success;
540 __le32 rts_fail;
541 __le32 tsf32;
542 __le32 airtime;
543 __le32 noise;
544 __le32 sample_noise[8];
545 __le32 sample_cca;
546 __le32 sample_tx;
547} __attribute__ ((packed));
548
549struct p54_xbow_synth {
550 __le16 magic1;
551 __le16 magic2;
552 __le16 freq;
553 u32 padding[5];
554} __attribute__ ((packed));
555
556struct p54_timer {
557 __le32 interval;
558} __attribute__ ((packed));
559
560struct p54_keycache {
561 u8 entry;
562 u8 key_id;
563 u8 mac[ETH_ALEN];
564 u8 padding[2];
565 u8 key_type;
566 u8 key_len;
567 u8 key[24];
568} __attribute__ ((packed));
569
570struct p54_burst {
571 u8 flags;
572 u8 queue;
573 u8 backlog;
574 u8 pad;
575 __le16 durations[32];
576} __attribute__ ((packed));
577
578struct p54_psm_interval {
579 __le16 interval;
580 __le16 periods;
581} __attribute__ ((packed));
582
583#define P54_PSM_CAM 0
584#define P54_PSM BIT(0)
585#define P54_PSM_DTIM BIT(1)
586#define P54_PSM_MCBC BIT(2)
587#define P54_PSM_CHECKSUM BIT(3)
588#define P54_PSM_SKIP_MORE_DATA BIT(4)
589#define P54_PSM_BEACON_TIMEOUT BIT(5)
590#define P54_PSM_HFOSLEEP BIT(6)
591#define P54_PSM_AUTOSWITCH_SLEEP BIT(7)
592#define P54_PSM_LPIT BIT(8)
593#define P54_PSM_BF_UCAST_SKIP BIT(9)
594#define P54_PSM_BF_MCAST_SKIP BIT(10)
595
596struct p54_psm {
597 __le16 mode;
598 __le16 aid;
599 struct p54_psm_interval intervals[4];
600 u8 beacon_rssi_skip_max;
601 u8 rssi_delta_threshold;
602 u8 nr;
603 u8 exclude[1];
604} __attribute__ ((packed));
605
606#define MC_FILTER_ADDRESS_NUM 4
607
608struct p54_group_address_table {
609 __le16 filter_enable;
610 __le16 num_address;
611 u8 mac_list[MC_FILTER_ADDRESS_NUM][ETH_ALEN];
612} __attribute__ ((packed));
613
614struct p54_txcancel {
615 __le32 req_id;
616} __attribute__ ((packed));
617
618struct p54_sta_unlock {
619 u8 addr[ETH_ALEN];
620 u16 padding;
621} __attribute__ ((packed));
622
623#define P54_TIM_CLEAR BIT(15)
624struct p54_tim {
625 u8 count;
626 u8 padding[3];
627 __le16 entry[8];
628} __attribute__ ((packed));
629
630struct p54_cce_quiet {
631 __le32 period;
632} __attribute__ ((packed));
633
634struct p54_bt_balancer {
635 __le16 prio_thresh;
636 __le16 acl_thresh;
637} __attribute__ ((packed));
638
639struct p54_arp_table {
640 __le16 filter_enable;
641 u8 ipv4_addr[4];
642} __attribute__ ((packed));
643
644#endif /* P54COMMON_H */
diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c
index b1610ea4bb3d..d348c265e867 100644
--- a/drivers/net/wireless/p54/p54pci.c
+++ b/drivers/net/wireless/p54/p54pci.c
@@ -22,6 +22,7 @@
22#include <net/mac80211.h> 22#include <net/mac80211.h>
23 23
24#include "p54.h" 24#include "p54.h"
25#include "lmac.h"
25#include "p54pci.h" 26#include "p54pci.h"
26 27
27MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>"); 28MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
@@ -564,7 +565,6 @@ static int __devinit p54p_probe(struct pci_dev *pdev,
564 565
565 err_free_common: 566 err_free_common:
566 release_firmware(priv->firmware); 567 release_firmware(priv->firmware);
567 p54_free_common(dev);
568 pci_free_consistent(pdev, sizeof(*priv->ring_control), 568 pci_free_consistent(pdev, sizeof(*priv->ring_control),
569 priv->ring_control, priv->ring_control_dma); 569 priv->ring_control, priv->ring_control_dma);
570 570
@@ -573,7 +573,7 @@ static int __devinit p54p_probe(struct pci_dev *pdev,
573 573
574 err_free_dev: 574 err_free_dev:
575 pci_set_drvdata(pdev, NULL); 575 pci_set_drvdata(pdev, NULL);
576 ieee80211_free_hw(dev); 576 p54_free_common(dev);
577 577
578 err_free_reg: 578 err_free_reg:
579 pci_release_regions(pdev); 579 pci_release_regions(pdev);
@@ -590,16 +590,15 @@ static void __devexit p54p_remove(struct pci_dev *pdev)
590 if (!dev) 590 if (!dev)
591 return; 591 return;
592 592
593 ieee80211_unregister_hw(dev); 593 p54_unregister_common(dev);
594 priv = dev->priv; 594 priv = dev->priv;
595 release_firmware(priv->firmware); 595 release_firmware(priv->firmware);
596 pci_free_consistent(pdev, sizeof(*priv->ring_control), 596 pci_free_consistent(pdev, sizeof(*priv->ring_control),
597 priv->ring_control, priv->ring_control_dma); 597 priv->ring_control, priv->ring_control_dma);
598 p54_free_common(dev);
599 iounmap(priv->map); 598 iounmap(priv->map);
600 pci_release_regions(pdev); 599 pci_release_regions(pdev);
601 pci_disable_device(pdev); 600 pci_disable_device(pdev);
602 ieee80211_free_hw(dev); 601 p54_free_common(dev);
603} 602}
604 603
605#ifdef CONFIG_PM 604#ifdef CONFIG_PM
diff --git a/drivers/net/wireless/p54/p54spi.c b/drivers/net/wireless/p54/p54spi.c
index 83116baeb110..d5f181ad37fc 100644
--- a/drivers/net/wireless/p54/p54spi.c
+++ b/drivers/net/wireless/p54/p54spi.c
@@ -34,7 +34,7 @@
34#include "p54spi_eeprom.h" 34#include "p54spi_eeprom.h"
35#include "p54.h" 35#include "p54.h"
36 36
37#include "p54common.h" 37#include "lmac.h"
38 38
39MODULE_FIRMWARE("3826.arm"); 39MODULE_FIRMWARE("3826.arm");
40MODULE_ALIAS("stlc45xx"); 40MODULE_ALIAS("stlc45xx");
@@ -111,15 +111,6 @@ static void p54spi_spi_write(struct p54s_priv *priv, u8 address,
111 spi_sync(priv->spi, &m); 111 spi_sync(priv->spi, &m);
112} 112}
113 113
114static u16 p54spi_read16(struct p54s_priv *priv, u8 addr)
115{
116 __le16 val;
117
118 p54spi_spi_read(priv, addr, &val, sizeof(val));
119
120 return le16_to_cpu(val);
121}
122
123static u32 p54spi_read32(struct p54s_priv *priv, u8 addr) 114static u32 p54spi_read32(struct p54s_priv *priv, u8 addr)
124{ 115{
125 __le32 val; 116 __le32 val;
@@ -139,37 +130,12 @@ static inline void p54spi_write32(struct p54s_priv *priv, u8 addr, __le32 val)
139 p54spi_spi_write(priv, addr, &val, sizeof(val)); 130 p54spi_spi_write(priv, addr, &val, sizeof(val));
140} 131}
141 132
142struct p54spi_spi_reg { 133static int p54spi_wait_bit(struct p54s_priv *priv, u16 reg, u32 bits)
143 u16 address; /* __le16 ? */
144 u16 length;
145 char *name;
146};
147
148static const struct p54spi_spi_reg p54spi_registers_array[] =
149{
150 { SPI_ADRS_ARM_INTERRUPTS, 32, "ARM_INT " },
151 { SPI_ADRS_ARM_INT_EN, 32, "ARM_INT_ENA " },
152 { SPI_ADRS_HOST_INTERRUPTS, 32, "HOST_INT " },
153 { SPI_ADRS_HOST_INT_EN, 32, "HOST_INT_ENA" },
154 { SPI_ADRS_HOST_INT_ACK, 32, "HOST_INT_ACK" },
155 { SPI_ADRS_GEN_PURP_1, 32, "GP1_COMM " },
156 { SPI_ADRS_GEN_PURP_2, 32, "GP2_COMM " },
157 { SPI_ADRS_DEV_CTRL_STAT, 32, "DEV_CTRL_STA" },
158 { SPI_ADRS_DMA_DATA, 16, "DMA_DATA " },
159 { SPI_ADRS_DMA_WRITE_CTRL, 16, "DMA_WR_CTRL " },
160 { SPI_ADRS_DMA_WRITE_LEN, 16, "DMA_WR_LEN " },
161 { SPI_ADRS_DMA_WRITE_BASE, 32, "DMA_WR_BASE " },
162 { SPI_ADRS_DMA_READ_CTRL, 16, "DMA_RD_CTRL " },
163 { SPI_ADRS_DMA_READ_LEN, 16, "DMA_RD_LEN " },
164 { SPI_ADRS_DMA_WRITE_BASE, 32, "DMA_RD_BASE " }
165};
166
167static int p54spi_wait_bit(struct p54s_priv *priv, u16 reg, __le32 bits)
168{ 134{
169 int i; 135 int i;
170 136
171 for (i = 0; i < 2000; i++) { 137 for (i = 0; i < 2000; i++) {
172 __le32 buffer = p54spi_read32(priv, reg); 138 u32 buffer = p54spi_read32(priv, reg);
173 if ((buffer & bits) == bits) 139 if ((buffer & bits) == bits)
174 return 1; 140 return 1;
175 } 141 }
@@ -179,8 +145,7 @@ static int p54spi_wait_bit(struct p54s_priv *priv, u16 reg, __le32 bits)
179static int p54spi_spi_write_dma(struct p54s_priv *priv, __le32 base, 145static int p54spi_spi_write_dma(struct p54s_priv *priv, __le32 base,
180 const void *buf, size_t len) 146 const void *buf, size_t len)
181{ 147{
182 if (!p54spi_wait_bit(priv, SPI_ADRS_DMA_WRITE_CTRL, 148 if (!p54spi_wait_bit(priv, SPI_ADRS_DMA_WRITE_CTRL, HOST_ALLOWED)) {
183 cpu_to_le32(HOST_ALLOWED))) {
184 dev_err(&priv->spi->dev, "spi_write_dma not allowed " 149 dev_err(&priv->spi->dev, "spi_write_dma not allowed "
185 "to DMA write.\n"); 150 "to DMA write.\n");
186 return -EAGAIN; 151 return -EAGAIN;
@@ -333,7 +298,7 @@ static int p54spi_wakeup(struct p54s_priv *priv)
333 298
334 /* And wait for the READY interrupt */ 299 /* And wait for the READY interrupt */
335 if (!p54spi_wait_bit(priv, SPI_ADRS_HOST_INTERRUPTS, 300 if (!p54spi_wait_bit(priv, SPI_ADRS_HOST_INTERRUPTS,
336 cpu_to_le32(SPI_HOST_INT_READY))) { 301 SPI_HOST_INT_READY)) {
337 dev_err(&priv->spi->dev, "INT_READY timeout\n"); 302 dev_err(&priv->spi->dev, "INT_READY timeout\n");
338 return -EBUSY; 303 return -EBUSY;
339 } 304 }
@@ -444,7 +409,7 @@ static int p54spi_tx_frame(struct p54s_priv *priv, struct sk_buff *skb)
444 goto out; 409 goto out;
445 410
446 if (!p54spi_wait_bit(priv, SPI_ADRS_HOST_INTERRUPTS, 411 if (!p54spi_wait_bit(priv, SPI_ADRS_HOST_INTERRUPTS,
447 cpu_to_le32(SPI_HOST_INT_WR_READY))) { 412 SPI_HOST_INT_WR_READY)) {
448 dev_err(&priv->spi->dev, "WR_READY timeout\n"); 413 dev_err(&priv->spi->dev, "WR_READY timeout\n");
449 ret = -EAGAIN; 414 ret = -EAGAIN;
450 goto out; 415 goto out;
@@ -713,7 +678,7 @@ static int __devexit p54spi_remove(struct spi_device *spi)
713{ 678{
714 struct p54s_priv *priv = dev_get_drvdata(&spi->dev); 679 struct p54s_priv *priv = dev_get_drvdata(&spi->dev);
715 680
716 ieee80211_unregister_hw(priv->hw); 681 p54_unregister_common(priv->hw);
717 682
718 free_irq(gpio_to_irq(p54spi_gpio_irq), spi); 683 free_irq(gpio_to_irq(p54spi_gpio_irq), spi);
719 684
@@ -724,7 +689,6 @@ static int __devexit p54spi_remove(struct spi_device *spi)
724 mutex_destroy(&priv->mutex); 689 mutex_destroy(&priv->mutex);
725 690
726 p54_free_common(priv->hw); 691 p54_free_common(priv->hw);
727 ieee80211_free_hw(priv->hw);
728 692
729 return 0; 693 return 0;
730} 694}
diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
index 0e877a104a89..e44460ff149c 100644
--- a/drivers/net/wireless/p54/p54usb.c
+++ b/drivers/net/wireless/p54/p54usb.c
@@ -22,6 +22,7 @@
22#include <net/mac80211.h> 22#include <net/mac80211.h>
23 23
24#include "p54.h" 24#include "p54.h"
25#include "lmac.h"
25#include "p54usb.h" 26#include "p54usb.h"
26 27
27MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>"); 28MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
@@ -245,8 +246,10 @@ static void p54u_tx_lm87(struct ieee80211_hw *dev, struct sk_buff *skb)
245 struct lm87_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr); 246 struct lm87_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr);
246 247
247 data_urb = usb_alloc_urb(0, GFP_ATOMIC); 248 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
248 if (!data_urb) 249 if (!data_urb) {
250 p54_free_skb(dev, skb);
249 return; 251 return;
252 }
250 253
251 hdr->chksum = p54u_lm87_chksum((__le32 *)skb->data, skb->len); 254 hdr->chksum = p54u_lm87_chksum((__le32 *)skb->data, skb->len);
252 hdr->device_addr = ((struct p54_hdr *)skb->data)->req_id; 255 hdr->device_addr = ((struct p54_hdr *)skb->data)->req_id;
@@ -268,27 +271,22 @@ static void p54u_tx_lm87(struct ieee80211_hw *dev, struct sk_buff *skb)
268static void p54u_tx_net2280(struct ieee80211_hw *dev, struct sk_buff *skb) 271static void p54u_tx_net2280(struct ieee80211_hw *dev, struct sk_buff *skb)
269{ 272{
270 struct p54u_priv *priv = dev->priv; 273 struct p54u_priv *priv = dev->priv;
271 struct urb *int_urb, *data_urb; 274 struct urb *int_urb = NULL, *data_urb = NULL;
272 struct net2280_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr); 275 struct net2280_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr);
273 struct net2280_reg_write *reg; 276 struct net2280_reg_write *reg = NULL;
274 int err = 0; 277 int err = -ENOMEM;
275 278
276 reg = kmalloc(sizeof(*reg), GFP_ATOMIC); 279 reg = kmalloc(sizeof(*reg), GFP_ATOMIC);
277 if (!reg) 280 if (!reg)
278 return; 281 goto out;
279 282
280 int_urb = usb_alloc_urb(0, GFP_ATOMIC); 283 int_urb = usb_alloc_urb(0, GFP_ATOMIC);
281 if (!int_urb) { 284 if (!int_urb)
282 kfree(reg); 285 goto out;
283 return;
284 }
285 286
286 data_urb = usb_alloc_urb(0, GFP_ATOMIC); 287 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
287 if (!data_urb) { 288 if (!data_urb)
288 kfree(reg); 289 goto out;
289 usb_free_urb(int_urb);
290 return;
291 }
292 290
293 reg->port = cpu_to_le16(NET2280_DEV_U32); 291 reg->port = cpu_to_le16(NET2280_DEV_U32);
294 reg->addr = cpu_to_le32(P54U_DEV_BASE); 292 reg->addr = cpu_to_le32(P54U_DEV_BASE);
@@ -303,11 +301,12 @@ static void p54u_tx_net2280(struct ieee80211_hw *dev, struct sk_buff *skb)
303 p54u_tx_dummy_cb, dev); 301 p54u_tx_dummy_cb, dev);
304 302
305 /* 303 /*
306 * This flag triggers a code path in the USB subsystem that will 304 * URB_FREE_BUFFER triggers a code path in the USB subsystem that will
307 * free what's inside the transfer_buffer after the callback routine 305 * free what is inside the transfer_buffer after the last reference to
308 * has completed. 306 * the int_urb is dropped.
309 */ 307 */
310 int_urb->transfer_flags |= URB_FREE_BUFFER | URB_ZERO_PACKET; 308 int_urb->transfer_flags |= URB_FREE_BUFFER | URB_ZERO_PACKET;
309 reg = NULL;
311 310
312 usb_fill_bulk_urb(data_urb, priv->udev, 311 usb_fill_bulk_urb(data_urb, priv->udev,
313 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA), 312 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
@@ -328,12 +327,12 @@ static void p54u_tx_net2280(struct ieee80211_hw *dev, struct sk_buff *skb)
328 usb_unanchor_urb(data_urb); 327 usb_unanchor_urb(data_urb);
329 goto out; 328 goto out;
330 } 329 }
331 out: 330out:
332 usb_free_urb(int_urb); 331 usb_free_urb(int_urb);
333 usb_free_urb(data_urb); 332 usb_free_urb(data_urb);
334 333
335 if (err) { 334 if (err) {
336 skb_pull(skb, sizeof(*hdr)); 335 kfree(reg);
337 p54_free_skb(dev, skb); 336 p54_free_skb(dev, skb);
338 } 337 }
339} 338}
@@ -961,7 +960,7 @@ err_free_fw:
961 release_firmware(priv->fw); 960 release_firmware(priv->fw);
962 961
963err_free_dev: 962err_free_dev:
964 ieee80211_free_hw(dev); 963 p54_free_common(dev);
965 usb_set_intfdata(intf, NULL); 964 usb_set_intfdata(intf, NULL);
966 usb_put_dev(udev); 965 usb_put_dev(udev);
967 return err; 966 return err;
@@ -975,13 +974,12 @@ static void __devexit p54u_disconnect(struct usb_interface *intf)
975 if (!dev) 974 if (!dev)
976 return; 975 return;
977 976
978 ieee80211_unregister_hw(dev); 977 p54_unregister_common(dev);
979 978
980 priv = dev->priv; 979 priv = dev->priv;
981 usb_put_dev(interface_to_usbdev(intf)); 980 usb_put_dev(interface_to_usbdev(intf));
982 release_firmware(priv->fw); 981 release_firmware(priv->fw);
983 p54_free_common(dev); 982 p54_free_common(dev);
984 ieee80211_free_hw(dev);
985} 983}
986 984
987static int p54u_pre_reset(struct usb_interface *intf) 985static int p54u_pre_reset(struct usb_interface *intf)
diff --git a/drivers/net/wireless/p54/txrx.c b/drivers/net/wireless/p54/txrx.c
new file mode 100644
index 000000000000..6426d2cae6de
--- /dev/null
+++ b/drivers/net/wireless/p54/txrx.c
@@ -0,0 +1,826 @@
1/*
2 * Common code for mac80211 Prism54 drivers
3 *
4 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
5 * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 *
8 * Based on:
9 * - the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
11 * - stlc45xx driver
12 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/init.h>
20#include <linux/firmware.h>
21#include <linux/etherdevice.h>
22
23#include <net/mac80211.h>
24
25#include "p54.h"
26#include "lmac.h"
27
28#ifdef P54_MM_DEBUG
29static void p54_dump_tx_queue(struct p54_common *priv)
30{
31 unsigned long flags;
32 struct ieee80211_tx_info *info;
33 struct p54_tx_info *range;
34 struct sk_buff *skb;
35 struct p54_hdr *hdr;
36 unsigned int i = 0;
37 u32 prev_addr;
38 u32 largest_hole = 0, free;
39
40 spin_lock_irqsave(&priv->tx_queue.lock, flags);
41 printk(KERN_DEBUG "%s: / --- tx queue dump (%d entries) --- \n",
42 wiphy_name(priv->hw->wiphy), skb_queue_len(&priv->tx_queue));
43
44 prev_addr = priv->rx_start;
45 skb_queue_walk(&priv->tx_queue, skb) {
46 info = IEEE80211_SKB_CB(skb);
47 range = (void *) info->rate_driver_data;
48 hdr = (void *) skb->data;
49
50 free = range->start_addr - prev_addr;
51 printk(KERN_DEBUG "%s: | [%02d] => [skb:%p skb_len:0x%04x "
52 "hdr:{flags:%02x len:%04x req_id:%04x type:%02x} "
53 "mem:{start:%04x end:%04x, free:%d}]\n",
54 wiphy_name(priv->hw->wiphy), i++, skb, skb->len,
55 le16_to_cpu(hdr->flags), le16_to_cpu(hdr->len),
56 le32_to_cpu(hdr->req_id), le16_to_cpu(hdr->type),
57 range->start_addr, range->end_addr, free);
58
59 prev_addr = range->end_addr;
60 largest_hole = max(largest_hole, free);
61 }
62 free = priv->rx_end - prev_addr;
63 largest_hole = max(largest_hole, free);
64 printk(KERN_DEBUG "%s: \\ --- [free: %d], largest free block: %d ---\n",
65 wiphy_name(priv->hw->wiphy), free, largest_hole);
66 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
67}
68#endif /* P54_MM_DEBUG */
69
70/*
71 * So, the firmware is somewhat stupid and doesn't know what places in its
72 * memory incoming data should go to. By poking around in the firmware, we
73 * can find some unused memory to upload our packets to. However, data that we
74 * want the card to TX needs to stay intact until the card has told us that
75 * it is done with it. This function finds empty places we can upload to and
76 * marks allocated areas as reserved if necessary. p54_find_and_unlink_skb or
77 * p54_free_skb frees allocated areas.
78 */
79static int p54_assign_address(struct p54_common *priv, struct sk_buff *skb)
80{
81 struct sk_buff *entry, *target_skb = NULL;
82 struct ieee80211_tx_info *info;
83 struct p54_tx_info *range;
84 struct p54_hdr *data = (void *) skb->data;
85 unsigned long flags;
86 u32 last_addr = priv->rx_start;
87 u32 target_addr = priv->rx_start;
88 u16 len = priv->headroom + skb->len + priv->tailroom + 3;
89
90 if (unlikely(WARN_ON(!skb || !priv)))
91 return -EINVAL;
92
93 info = IEEE80211_SKB_CB(skb);
94 range = (void *) info->rate_driver_data;
95 len = (range->extra_len + len) & ~0x3;
96
97 spin_lock_irqsave(&priv->tx_queue.lock, flags);
98 if (unlikely(skb_queue_len(&priv->tx_queue) == 32)) {
99 /*
100 * The tx_queue is now really full.
101 *
102 * TODO: check if the device has crashed and reset it.
103 */
104 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
105 return -EBUSY;
106 }
107
108 skb_queue_walk(&priv->tx_queue, entry) {
109 u32 hole_size;
110 info = IEEE80211_SKB_CB(entry);
111 range = (void *) info->rate_driver_data;
112 hole_size = range->start_addr - last_addr;
113
114 if (!entry->next) {
115 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
116 return -ENOSPC;
117 }
118
119 if (!target_skb && hole_size >= len) {
120 target_skb = entry->prev;
121 hole_size -= len;
122 target_addr = last_addr;
123 break;
124 }
125 last_addr = range->end_addr;
126 }
127 if (unlikely(!target_skb)) {
128 if (priv->rx_end - last_addr >= len) {
129 target_skb = priv->tx_queue.prev;
130 if (!skb_queue_empty(&priv->tx_queue)) {
131 info = IEEE80211_SKB_CB(target_skb);
132 range = (void *)info->rate_driver_data;
133 target_addr = range->end_addr;
134 }
135 } else {
136 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
137 return -ENOSPC;
138 }
139 }
140
141 info = IEEE80211_SKB_CB(skb);
142 range = (void *) info->rate_driver_data;
143 range->start_addr = target_addr;
144 range->end_addr = target_addr + len;
145 __skb_queue_after(&priv->tx_queue, target_skb, skb);
146 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
147 data->req_id = cpu_to_le32(target_addr + priv->headroom);
148 return 0;
149}
150
151static void p54_tx_pending(struct p54_common *priv)
152{
153 struct sk_buff *skb;
154 int ret;
155
156 if (unlikely(WARN_ON(!priv)))
157 return ;
158
159 skb = skb_dequeue(&priv->tx_pending);
160 if (unlikely(!skb))
161 return ;
162
163 ret = p54_assign_address(priv, skb);
164 if (unlikely(ret))
165 skb_queue_head(&priv->tx_pending, skb);
166 else
167 priv->tx(priv->hw, skb);
168}
169
170static void p54_wake_queues(struct p54_common *priv)
171{
172 unsigned long flags;
173 unsigned int i;
174
175 if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
176 return ;
177
178 p54_tx_pending(priv);
179
180 spin_lock_irqsave(&priv->tx_stats_lock, flags);
181 for (i = 0; i < priv->hw->queues; i++) {
182 if (priv->tx_stats[i + P54_QUEUE_DATA].len <
183 priv->tx_stats[i + P54_QUEUE_DATA].limit)
184 ieee80211_wake_queue(priv->hw, i);
185 }
186 spin_unlock_irqrestore(&priv->tx_stats_lock, flags);
187}
188
189static int p54_tx_qos_accounting_alloc(struct p54_common *priv,
190 struct sk_buff *skb,
191 const u16 p54_queue)
192{
193 struct ieee80211_tx_queue_stats *queue;
194 unsigned long flags;
195
196 if (WARN_ON(p54_queue > P54_QUEUE_NUM))
197 return -EINVAL;
198
199 queue = &priv->tx_stats[p54_queue];
200
201 spin_lock_irqsave(&priv->tx_stats_lock, flags);
202 if (unlikely(queue->len >= queue->limit && IS_QOS_QUEUE(p54_queue))) {
203 spin_unlock_irqrestore(&priv->tx_stats_lock, flags);
204 return -ENOSPC;
205 }
206
207 queue->len++;
208 queue->count++;
209
210 if (unlikely(queue->len == queue->limit && IS_QOS_QUEUE(p54_queue))) {
211 u16 ac_queue = p54_queue - P54_QUEUE_DATA;
212 ieee80211_stop_queue(priv->hw, ac_queue);
213 }
214
215 spin_unlock_irqrestore(&priv->tx_stats_lock, flags);
216 return 0;
217}
218
219static void p54_tx_qos_accounting_free(struct p54_common *priv,
220 struct sk_buff *skb)
221{
222 if (skb && IS_DATA_FRAME(skb)) {
223 struct p54_hdr *hdr = (void *) skb->data;
224 struct p54_tx_data *data = (void *) hdr->data;
225 unsigned long flags;
226
227 spin_lock_irqsave(&priv->tx_stats_lock, flags);
228 priv->tx_stats[data->hw_queue].len--;
229 spin_unlock_irqrestore(&priv->tx_stats_lock, flags);
230 }
231 p54_wake_queues(priv);
232}
233
234void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb)
235{
236 struct p54_common *priv = dev->priv;
237 if (unlikely(!skb))
238 return ;
239
240 skb_unlink(skb, &priv->tx_queue);
241 p54_tx_qos_accounting_free(priv, skb);
242 dev_kfree_skb_any(skb);
243}
244EXPORT_SYMBOL_GPL(p54_free_skb);
245
246static struct sk_buff *p54_find_and_unlink_skb(struct p54_common *priv,
247 const __le32 req_id)
248{
249 struct sk_buff *entry;
250 unsigned long flags;
251
252 spin_lock_irqsave(&priv->tx_queue.lock, flags);
253 skb_queue_walk(&priv->tx_queue, entry) {
254 struct p54_hdr *hdr = (struct p54_hdr *) entry->data;
255
256 if (hdr->req_id == req_id) {
257 __skb_unlink(entry, &priv->tx_queue);
258 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
259 p54_tx_qos_accounting_free(priv, entry);
260 return entry;
261 }
262 }
263 spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
264 return NULL;
265}
266
267void p54_tx(struct p54_common *priv, struct sk_buff *skb)
268{
269 if (unlikely(WARN_ON(!priv)))
270 return ;
271
272 skb_queue_tail(&priv->tx_pending, skb);
273 p54_tx_pending(priv);
274}
275
276static int p54_rssi_to_dbm(struct p54_common *priv, int rssi)
277{
278 int band = priv->hw->conf.channel->band;
279
280 if (priv->rxhw != 5)
281 return ((rssi * priv->rssical_db[band].mul) / 64 +
282 priv->rssical_db[band].add) / 4;
283 else
284 /*
285 * TODO: find the correct formula
286 */
287 return ((rssi * priv->rssical_db[band].mul) / 64 +
288 priv->rssical_db[band].add) / 4;
289}
290
291static int p54_rx_data(struct p54_common *priv, struct sk_buff *skb)
292{
293 struct p54_rx_data *hdr = (struct p54_rx_data *) skb->data;
294 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
295 u16 freq = le16_to_cpu(hdr->freq);
296 size_t header_len = sizeof(*hdr);
297 u32 tsf32;
298 u8 rate = hdr->rate & 0xf;
299
300 /*
301 * If the device is in a unspecified state we have to
302 * ignore all data frames. Else we could end up with a
303 * nasty crash.
304 */
305 if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
306 return 0;
307
308 if (!(hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_IN_FCS_GOOD)))
309 return 0;
310
311 if (hdr->decrypt_status == P54_DECRYPT_OK)
312 rx_status->flag |= RX_FLAG_DECRYPTED;
313 if ((hdr->decrypt_status == P54_DECRYPT_FAIL_MICHAEL) ||
314 (hdr->decrypt_status == P54_DECRYPT_FAIL_TKIP))
315 rx_status->flag |= RX_FLAG_MMIC_ERROR;
316
317 rx_status->signal = p54_rssi_to_dbm(priv, hdr->rssi);
318 rx_status->noise = priv->noise;
319 if (hdr->rate & 0x10)
320 rx_status->flag |= RX_FLAG_SHORTPRE;
321 if (priv->hw->conf.channel->band == IEEE80211_BAND_5GHZ)
322 rx_status->rate_idx = (rate < 4) ? 0 : rate - 4;
323 else
324 rx_status->rate_idx = rate;
325
326 rx_status->freq = freq;
327 rx_status->band = priv->hw->conf.channel->band;
328 rx_status->antenna = hdr->antenna;
329
330 tsf32 = le32_to_cpu(hdr->tsf32);
331 if (tsf32 < priv->tsf_low32)
332 priv->tsf_high32++;
333 rx_status->mactime = ((u64)priv->tsf_high32) << 32 | tsf32;
334 priv->tsf_low32 = tsf32;
335
336 rx_status->flag |= RX_FLAG_TSFT;
337
338 if (hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN))
339 header_len += hdr->align[0];
340
341 skb_pull(skb, header_len);
342 skb_trim(skb, le16_to_cpu(hdr->len));
343 ieee80211_rx_irqsafe(priv->hw, skb);
344
345 queue_delayed_work(priv->hw->workqueue, &priv->work,
346 msecs_to_jiffies(P54_STATISTICS_UPDATE));
347
348 return -1;
349}
350
351static void p54_rx_frame_sent(struct p54_common *priv, struct sk_buff *skb)
352{
353 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
354 struct p54_frame_sent *payload = (struct p54_frame_sent *) hdr->data;
355 struct ieee80211_tx_info *info;
356 struct p54_hdr *entry_hdr;
357 struct p54_tx_data *entry_data;
358 struct sk_buff *entry;
359 unsigned int pad = 0, frame_len;
360 int count, idx;
361
362 entry = p54_find_and_unlink_skb(priv, hdr->req_id);
363 if (unlikely(!entry))
364 return ;
365
366 frame_len = entry->len;
367 info = IEEE80211_SKB_CB(entry);
368 entry_hdr = (struct p54_hdr *) entry->data;
369 entry_data = (struct p54_tx_data *) entry_hdr->data;
370 priv->stats.dot11ACKFailureCount += payload->tries - 1;
371
372 /*
373 * Frames in P54_QUEUE_FWSCAN and P54_QUEUE_BEACON are
374 * generated by the driver. Therefore tx_status is bogus
375 * and we don't want to confuse the mac80211 stack.
376 */
377 if (unlikely(entry_data->hw_queue < P54_QUEUE_FWSCAN)) {
378 if (entry_data->hw_queue == P54_QUEUE_BEACON &&
379 hdr->req_id == priv->beacon_req_id)
380 priv->beacon_req_id = cpu_to_le32(0);
381
382 dev_kfree_skb_any(entry);
383 return ;
384 }
385
386 /*
387 * Clear manually, ieee80211_tx_info_clear_status would
388 * clear the counts too and we need them.
389 */
390 memset(&info->status.ampdu_ack_len, 0,
391 sizeof(struct ieee80211_tx_info) -
392 offsetof(struct ieee80211_tx_info, status.ampdu_ack_len));
393 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info,
394 status.ampdu_ack_len) != 23);
395
396 if (entry_hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN))
397 pad = entry_data->align[0];
398
399 /* walk through the rates array and adjust the counts */
400 count = payload->tries;
401 for (idx = 0; idx < 4; idx++) {
402 if (count >= info->status.rates[idx].count) {
403 count -= info->status.rates[idx].count;
404 } else if (count > 0) {
405 info->status.rates[idx].count = count;
406 count = 0;
407 } else {
408 info->status.rates[idx].idx = -1;
409 info->status.rates[idx].count = 0;
410 }
411 }
412
413 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
414 (!payload->status))
415 info->flags |= IEEE80211_TX_STAT_ACK;
416 if (payload->status & P54_TX_PSM_CANCELLED)
417 info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
418 info->status.ack_signal = p54_rssi_to_dbm(priv,
419 (int)payload->ack_rssi);
420
421 /* Undo all changes to the frame. */
422 switch (entry_data->key_type) {
423 case P54_CRYPTO_TKIPMICHAEL: {
424 u8 *iv = (u8 *)(entry_data->align + pad +
425 entry_data->crypt_offset);
426
427 /* Restore the original TKIP IV. */
428 iv[2] = iv[0];
429 iv[0] = iv[1];
430 iv[1] = (iv[0] | 0x20) & 0x7f; /* WEPSeed - 8.3.2.2 */
431
432 frame_len -= 12; /* remove TKIP_MMIC + TKIP_ICV */
433 break;
434 }
435 case P54_CRYPTO_AESCCMP:
436 frame_len -= 8; /* remove CCMP_MIC */
437 break;
438 case P54_CRYPTO_WEP:
439 frame_len -= 4; /* remove WEP_ICV */
440 break;
441 }
442
443 skb_trim(entry, frame_len);
444 skb_pull(entry, sizeof(*hdr) + pad + sizeof(*entry_data));
445 ieee80211_tx_status_irqsafe(priv->hw, entry);
446}
447
448static void p54_rx_eeprom_readback(struct p54_common *priv,
449 struct sk_buff *skb)
450{
451 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
452 struct p54_eeprom_lm86 *eeprom = (struct p54_eeprom_lm86 *) hdr->data;
453 struct sk_buff *tmp;
454
455 if (!priv->eeprom)
456 return ;
457
458 if (priv->fw_var >= 0x509) {
459 memcpy(priv->eeprom, eeprom->v2.data,
460 le16_to_cpu(eeprom->v2.len));
461 } else {
462 memcpy(priv->eeprom, eeprom->v1.data,
463 le16_to_cpu(eeprom->v1.len));
464 }
465
466 priv->eeprom = NULL;
467 tmp = p54_find_and_unlink_skb(priv, hdr->req_id);
468 dev_kfree_skb_any(tmp);
469 complete(&priv->eeprom_comp);
470}
471
472static void p54_rx_stats(struct p54_common *priv, struct sk_buff *skb)
473{
474 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
475 struct p54_statistics *stats = (struct p54_statistics *) hdr->data;
476 struct sk_buff *tmp;
477 u32 tsf32;
478
479 if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
480 return ;
481
482 tsf32 = le32_to_cpu(stats->tsf32);
483 if (tsf32 < priv->tsf_low32)
484 priv->tsf_high32++;
485 priv->tsf_low32 = tsf32;
486
487 priv->stats.dot11RTSFailureCount = le32_to_cpu(stats->rts_fail);
488 priv->stats.dot11RTSSuccessCount = le32_to_cpu(stats->rts_success);
489 priv->stats.dot11FCSErrorCount = le32_to_cpu(stats->rx_bad_fcs);
490
491 priv->noise = p54_rssi_to_dbm(priv, le32_to_cpu(stats->noise));
492
493 tmp = p54_find_and_unlink_skb(priv, hdr->req_id);
494 dev_kfree_skb_any(tmp);
495}
496
497static void p54_rx_trap(struct p54_common *priv, struct sk_buff *skb)
498{
499 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
500 struct p54_trap *trap = (struct p54_trap *) hdr->data;
501 u16 event = le16_to_cpu(trap->event);
502 u16 freq = le16_to_cpu(trap->frequency);
503
504 switch (event) {
505 case P54_TRAP_BEACON_TX:
506 break;
507 case P54_TRAP_RADAR:
508 printk(KERN_INFO "%s: radar (freq:%d MHz)\n",
509 wiphy_name(priv->hw->wiphy), freq);
510 break;
511 case P54_TRAP_NO_BEACON:
512 if (priv->vif)
513 ieee80211_beacon_loss(priv->vif);
514 break;
515 case P54_TRAP_SCAN:
516 break;
517 case P54_TRAP_TBTT:
518 break;
519 case P54_TRAP_TIMER:
520 break;
521 default:
522 printk(KERN_INFO "%s: received event:%x freq:%d\n",
523 wiphy_name(priv->hw->wiphy), event, freq);
524 break;
525 }
526}
527
528static int p54_rx_control(struct p54_common *priv, struct sk_buff *skb)
529{
530 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
531
532 switch (le16_to_cpu(hdr->type)) {
533 case P54_CONTROL_TYPE_TXDONE:
534 p54_rx_frame_sent(priv, skb);
535 break;
536 case P54_CONTROL_TYPE_TRAP:
537 p54_rx_trap(priv, skb);
538 break;
539 case P54_CONTROL_TYPE_BBP:
540 break;
541 case P54_CONTROL_TYPE_STAT_READBACK:
542 p54_rx_stats(priv, skb);
543 break;
544 case P54_CONTROL_TYPE_EEPROM_READBACK:
545 p54_rx_eeprom_readback(priv, skb);
546 break;
547 default:
548 printk(KERN_DEBUG "%s: not handling 0x%02x type control frame\n",
549 wiphy_name(priv->hw->wiphy), le16_to_cpu(hdr->type));
550 break;
551 }
552 return 0;
553}
554
555/* returns zero if skb can be reused */
556int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb)
557{
558 struct p54_common *priv = dev->priv;
559 u16 type = le16_to_cpu(*((__le16 *)skb->data));
560
561 if (type & P54_HDR_FLAG_CONTROL)
562 return p54_rx_control(priv, skb);
563 else
564 return p54_rx_data(priv, skb);
565}
566EXPORT_SYMBOL_GPL(p54_rx);
567
568static void p54_tx_80211_header(struct p54_common *priv, struct sk_buff *skb,
569 struct ieee80211_tx_info *info, u8 *queue,
570 u32 *extra_len, u16 *flags, u16 *aid,
571 bool *burst_possible)
572{
573 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
574
575 if (ieee80211_is_data_qos(hdr->frame_control))
576 *burst_possible = true;
577 else
578 *burst_possible = false;
579
580 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
581 *flags |= P54_HDR_FLAG_DATA_OUT_SEQNR;
582
583 if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
584 *flags |= P54_HDR_FLAG_DATA_OUT_NOCANCEL;
585
586 *queue = skb_get_queue_mapping(skb) + P54_QUEUE_DATA;
587
588 switch (priv->mode) {
589 case NL80211_IFTYPE_MONITOR:
590 /*
591 * We have to set P54_HDR_FLAG_DATA_OUT_PROMISC for
592 * every frame in promiscuous/monitor mode.
593 * see STSW45x0C LMAC API - page 12.
594 */
595 *aid = 0;
596 *flags |= P54_HDR_FLAG_DATA_OUT_PROMISC;
597 break;
598 case NL80211_IFTYPE_STATION:
599 *aid = 1;
600 break;
601 case NL80211_IFTYPE_AP:
602 case NL80211_IFTYPE_ADHOC:
603 case NL80211_IFTYPE_MESH_POINT:
604 if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
605 *aid = 0;
606 *queue = P54_QUEUE_CAB;
607 return;
608 }
609
610 if (unlikely(ieee80211_is_mgmt(hdr->frame_control))) {
611 if (ieee80211_is_probe_resp(hdr->frame_control)) {
612 *aid = 0;
613 *flags |= P54_HDR_FLAG_DATA_OUT_TIMESTAMP |
614 P54_HDR_FLAG_DATA_OUT_NOCANCEL;
615 return;
616 } else if (ieee80211_is_beacon(hdr->frame_control)) {
617 *aid = 0;
618
619 if (info->flags & IEEE80211_TX_CTL_INJECTED) {
620 /*
621 * Injecting beacons on top of a AP is
622 * not a good idea... nevertheless,
623 * it should be doable.
624 */
625
626 return;
627 }
628
629 *flags |= P54_HDR_FLAG_DATA_OUT_TIMESTAMP;
630 *queue = P54_QUEUE_BEACON;
631 *extra_len = IEEE80211_MAX_TIM_LEN;
632 return;
633 }
634 }
635
636 if (info->control.sta)
637 *aid = info->control.sta->aid;
638 break;
639 }
640}
641
642static u8 p54_convert_algo(enum ieee80211_key_alg alg)
643{
644 switch (alg) {
645 case ALG_WEP:
646 return P54_CRYPTO_WEP;
647 case ALG_TKIP:
648 return P54_CRYPTO_TKIPMICHAEL;
649 case ALG_CCMP:
650 return P54_CRYPTO_AESCCMP;
651 default:
652 return 0;
653 }
654}
655
656int p54_tx_80211(struct ieee80211_hw *dev, struct sk_buff *skb)
657{
658 struct p54_common *priv = dev->priv;
659 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
660 struct p54_tx_info *p54info;
661 struct p54_hdr *hdr;
662 struct p54_tx_data *txhdr;
663 unsigned int padding, len, extra_len;
664 int i, j, ridx;
665 u16 hdr_flags = 0, aid = 0;
666 u8 rate, queue = 0, crypt_offset = 0;
667 u8 cts_rate = 0x20;
668 u8 rc_flags;
669 u8 calculated_tries[4];
670 u8 nrates = 0, nremaining = 8;
671 bool burst_allowed = false;
672
673 p54_tx_80211_header(priv, skb, info, &queue, &extra_len,
674 &hdr_flags, &aid, &burst_allowed);
675
676 if (p54_tx_qos_accounting_alloc(priv, skb, queue)) {
677 if (!IS_QOS_QUEUE(queue)) {
678 dev_kfree_skb_any(skb);
679 return NETDEV_TX_OK;
680 } else {
681 return NETDEV_TX_BUSY;
682 }
683 }
684
685 padding = (unsigned long)(skb->data - (sizeof(*hdr) + sizeof(*txhdr))) & 3;
686 len = skb->len;
687
688 if (info->control.hw_key) {
689 crypt_offset = ieee80211_get_hdrlen_from_skb(skb);
690 if (info->control.hw_key->alg == ALG_TKIP) {
691 u8 *iv = (u8 *)(skb->data + crypt_offset);
692 /*
693 * The firmware excepts that the IV has to have
694 * this special format
695 */
696 iv[1] = iv[0];
697 iv[0] = iv[2];
698 iv[2] = 0;
699 }
700 }
701
702 txhdr = (struct p54_tx_data *) skb_push(skb, sizeof(*txhdr) + padding);
703 hdr = (struct p54_hdr *) skb_push(skb, sizeof(*hdr));
704
705 if (padding)
706 hdr_flags |= P54_HDR_FLAG_DATA_ALIGN;
707 hdr->type = cpu_to_le16(aid);
708 hdr->rts_tries = info->control.rates[0].count;
709
710 /*
711 * we register the rates in perfect order, and
712 * RTS/CTS won't happen on 5 GHz
713 */
714 cts_rate = info->control.rts_cts_rate_idx;
715
716 memset(&txhdr->rateset, 0, sizeof(txhdr->rateset));
717
718 /* see how many rates got used */
719 for (i = 0; i < dev->max_rates; i++) {
720 if (info->control.rates[i].idx < 0)
721 break;
722 nrates++;
723 }
724
725 /* limit tries to 8/nrates per rate */
726 for (i = 0; i < nrates; i++) {
727 /*
728 * The magic expression here is equivalent to 8/nrates for
729 * all values that matter, but avoids division and jumps.
730 * Note that nrates can only take the values 1 through 4.
731 */
732 calculated_tries[i] = min_t(int, ((15 >> nrates) | 1) + 1,
733 info->control.rates[i].count);
734 nremaining -= calculated_tries[i];
735 }
736
737 /* if there are tries left, distribute from back to front */
738 for (i = nrates - 1; nremaining > 0 && i >= 0; i--) {
739 int tmp = info->control.rates[i].count - calculated_tries[i];
740
741 if (tmp <= 0)
742 continue;
743 /* RC requested more tries at this rate */
744
745 tmp = min_t(int, tmp, nremaining);
746 calculated_tries[i] += tmp;
747 nremaining -= tmp;
748 }
749
750 ridx = 0;
751 for (i = 0; i < nrates && ridx < 8; i++) {
752 /* we register the rates in perfect order */
753 rate = info->control.rates[i].idx;
754 if (info->band == IEEE80211_BAND_5GHZ)
755 rate += 4;
756
757 /* store the count we actually calculated for TX status */
758 info->control.rates[i].count = calculated_tries[i];
759
760 rc_flags = info->control.rates[i].flags;
761 if (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) {
762 rate |= 0x10;
763 cts_rate |= 0x10;
764 }
765 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
766 burst_allowed = false;
767 rate |= 0x40;
768 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
769 rate |= 0x20;
770 burst_allowed = false;
771 }
772 for (j = 0; j < calculated_tries[i] && ridx < 8; j++) {
773 txhdr->rateset[ridx] = rate;
774 ridx++;
775 }
776 }
777
778 if (burst_allowed)
779 hdr_flags |= P54_HDR_FLAG_DATA_OUT_BURST;
780
781 /* TODO: enable bursting */
782 hdr->flags = cpu_to_le16(hdr_flags);
783 hdr->tries = ridx;
784 txhdr->rts_rate_idx = 0;
785 if (info->control.hw_key) {
786 txhdr->key_type = p54_convert_algo(info->control.hw_key->alg);
787 txhdr->key_len = min((u8)16, info->control.hw_key->keylen);
788 memcpy(txhdr->key, info->control.hw_key->key, txhdr->key_len);
789 if (info->control.hw_key->alg == ALG_TKIP) {
790 /* reserve space for the MIC key */
791 len += 8;
792 memcpy(skb_put(skb, 8), &(info->control.hw_key->key
793 [NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY]), 8);
794 }
795 /* reserve some space for ICV */
796 len += info->control.hw_key->icv_len;
797 memset(skb_put(skb, info->control.hw_key->icv_len), 0,
798 info->control.hw_key->icv_len);
799 } else {
800 txhdr->key_type = 0;
801 txhdr->key_len = 0;
802 }
803 txhdr->crypt_offset = crypt_offset;
804 txhdr->hw_queue = queue;
805 txhdr->backlog = priv->tx_stats[queue].len - 1;
806 memset(txhdr->durations, 0, sizeof(txhdr->durations));
807 txhdr->tx_antenna = ((info->antenna_sel_tx == 0) ?
808 2 : info->antenna_sel_tx - 1) & priv->tx_diversity_mask;
809 if (priv->rxhw == 5) {
810 txhdr->longbow.cts_rate = cts_rate;
811 txhdr->longbow.output_power = cpu_to_le16(priv->output_power);
812 } else {
813 txhdr->normal.output_power = priv->output_power;
814 txhdr->normal.cts_rate = cts_rate;
815 }
816 if (padding)
817 txhdr->align[0] = padding;
818
819 hdr->len = cpu_to_le16(len);
820 /* modifies skb->cb and with it info, so must be last! */
821 p54info = (void *) info->rate_driver_data;
822 p54info->extra_len = extra_len;
823
824 p54_tx(priv, skb);
825 return NETDEV_TX_OK;
826}
diff --git a/drivers/net/wireless/prism54/islpci_eth.c b/drivers/net/wireless/prism54/islpci_eth.c
index 8f6210993448..c255d9c6a5f1 100644
--- a/drivers/net/wireless/prism54/islpci_eth.c
+++ b/drivers/net/wireless/prism54/islpci_eth.c
@@ -234,7 +234,7 @@ islpci_eth_transmit(struct sk_buff *skb, struct net_device *ndev)
234 /* unlock the driver code */ 234 /* unlock the driver code */
235 spin_unlock_irqrestore(&priv->slock, flags); 235 spin_unlock_irqrestore(&priv->slock, flags);
236 236
237 return 0; 237 return NETDEV_TX_OK;
238 238
239 drop_free: 239 drop_free:
240 ndev->stats.tx_dropped++; 240 ndev->stats.tx_dropped++;
diff --git a/drivers/net/wireless/prism54/islpci_hotplug.c b/drivers/net/wireless/prism54/islpci_hotplug.c
index 30876728d7e6..83d366258c81 100644
--- a/drivers/net/wireless/prism54/islpci_hotplug.c
+++ b/drivers/net/wireless/prism54/islpci_hotplug.c
@@ -49,9 +49,7 @@ static const struct pci_device_id prism54_id_tbl[] = {
49 49
50 /* 3COM 3CRWE154G72 Wireless LAN adapter */ 50 /* 3COM 3CRWE154G72 Wireless LAN adapter */
51 { 51 {
52 0x10b7, 0x6001, 52 PCI_VDEVICE(3COM, 0x6001), 0
53 PCI_ANY_ID, PCI_ANY_ID,
54 0, 0, 0
55 }, 53 },
56 54
57 /* Intersil PRISM Indigo Wireless LAN adapter */ 55 /* Intersil PRISM Indigo Wireless LAN adapter */
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index b10b0383dfa5..64e574c3655c 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -937,7 +937,7 @@ static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev)
937 937
938 if (length < ETH_ZLEN) { 938 if (length < ETH_ZLEN) {
939 if (skb_padto(skb, ETH_ZLEN)) 939 if (skb_padto(skb, ETH_ZLEN))
940 return 0; 940 return NETDEV_TX_OK;
941 length = ETH_ZLEN; 941 length = ETH_ZLEN;
942 } 942 }
943 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) { 943 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
@@ -951,9 +951,9 @@ static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev)
951 default: 951 default:
952 dev->trans_start = jiffies; 952 dev->trans_start = jiffies;
953 dev_kfree_skb(skb); 953 dev_kfree_skb(skb);
954 return 0; 954 return NETDEV_TX_OK;
955 } 955 }
956 return 0; 956 return NETDEV_TX_OK;
957} /* ray_dev_start_xmit */ 957} /* ray_dev_start_xmit */
958 958
959/*===========================================================================*/ 959/*===========================================================================*/
diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
index 3bec3dbd3450..09c0702ae645 100644
--- a/drivers/net/wireless/rndis_wlan.c
+++ b/drivers/net/wireless/rndis_wlan.c
@@ -139,9 +139,15 @@ MODULE_PARM_DESC(workaround_interval,
139/* Assume that Broadcom 4320 (only chipset at time of writing known to be 139/* Assume that Broadcom 4320 (only chipset at time of writing known to be
140 * based on wireless rndis) has default txpower of 13dBm. 140 * based on wireless rndis) has default txpower of 13dBm.
141 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications. 141 * This value is from Linksys WUSB54GSC User Guide, Appendix F: Specifications.
142 * 13dBm == 19.9mW 142 * 100% : 20 mW ~ 13dBm
143 * 75% : 15 mW ~ 12dBm
144 * 50% : 10 mW ~ 10dBm
145 * 25% : 5 mW ~ 7dBm
143 */ 146 */
144#define BCM4320_DEFAULT_TXPOWER 20 147#define BCM4320_DEFAULT_TXPOWER_DBM_100 13
148#define BCM4320_DEFAULT_TXPOWER_DBM_75 12
149#define BCM4320_DEFAULT_TXPOWER_DBM_50 10
150#define BCM4320_DEFAULT_TXPOWER_DBM_25 7
145 151
146 152
147/* codes for "status" field of completion messages */ 153/* codes for "status" field of completion messages */
@@ -420,21 +426,30 @@ struct rndis_wlan_private {
420/* 426/*
421 * cfg80211 ops 427 * cfg80211 ops
422 */ 428 */
423static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex, 429static int rndis_change_virtual_intf(struct wiphy *wiphy,
430 struct net_device *dev,
424 enum nl80211_iftype type, u32 *flags, 431 enum nl80211_iftype type, u32 *flags,
425 struct vif_params *params); 432 struct vif_params *params);
426 433
427static int rndis_scan(struct wiphy *wiphy, struct net_device *dev, 434static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
428 struct cfg80211_scan_request *request); 435 struct cfg80211_scan_request *request);
429 436
437static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed);
438
439static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
440 int dbm);
441static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm);
442
430static struct cfg80211_ops rndis_config_ops = { 443static struct cfg80211_ops rndis_config_ops = {
431 .change_virtual_intf = rndis_change_virtual_intf, 444 .change_virtual_intf = rndis_change_virtual_intf,
432 .scan = rndis_scan, 445 .scan = rndis_scan,
446 .set_wiphy_params = rndis_set_wiphy_params,
447 .set_tx_power = rndis_set_tx_power,
448 .get_tx_power = rndis_get_tx_power,
433}; 449};
434 450
435static void *rndis_wiphy_privid = &rndis_wiphy_privid; 451static void *rndis_wiphy_privid = &rndis_wiphy_privid;
436 452
437static const int bcm4320_power_output[4] = { 25, 50, 75, 100 };
438 453
439static const unsigned char zero_bssid[ETH_ALEN] = {0,}; 454static const unsigned char zero_bssid[ETH_ALEN] = {0,};
440static const unsigned char ffff_bssid[ETH_ALEN] = { 0xff, 0xff, 0xff, 455static const unsigned char ffff_bssid[ETH_ALEN] = { 0xff, 0xff, 0xff,
@@ -447,10 +462,19 @@ static struct rndis_wlan_private *get_rndis_wlan_priv(struct usbnet *dev)
447} 462}
448 463
449 464
450static u32 get_bcm4320_power(struct rndis_wlan_private *priv) 465static u32 get_bcm4320_power_dbm(struct rndis_wlan_private *priv)
451{ 466{
452 return BCM4320_DEFAULT_TXPOWER * 467 switch (priv->param_power_output) {
453 bcm4320_power_output[priv->param_power_output] / 100; 468 default:
469 case 3:
470 return BCM4320_DEFAULT_TXPOWER_DBM_100;
471 case 2:
472 return BCM4320_DEFAULT_TXPOWER_DBM_75;
473 case 1:
474 return BCM4320_DEFAULT_TXPOWER_DBM_50;
475 case 0:
476 return BCM4320_DEFAULT_TXPOWER_DBM_25;
477 }
454} 478}
455 479
456 480
@@ -968,6 +992,36 @@ static int set_infra_mode(struct usbnet *usbdev, int mode)
968} 992}
969 993
970 994
995static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
996{
997 __le32 tmp;
998
999 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
1000
1001 if (rts_threshold < 0 || rts_threshold > 2347)
1002 rts_threshold = 2347;
1003
1004 tmp = cpu_to_le32(rts_threshold);
1005 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1006 sizeof(tmp));
1007}
1008
1009
1010static int set_frag_threshold(struct usbnet *usbdev, u32 frag_threshold)
1011{
1012 __le32 tmp;
1013
1014 devdbg(usbdev, "set_frag_threshold %i", frag_threshold);
1015
1016 if (frag_threshold < 256 || frag_threshold > 2346)
1017 frag_threshold = 2346;
1018
1019 tmp = cpu_to_le32(frag_threshold);
1020 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1021 sizeof(tmp));
1022}
1023
1024
971static void set_default_iw_params(struct usbnet *usbdev) 1025static void set_default_iw_params(struct usbnet *usbdev)
972{ 1026{
973 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev); 1027 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
@@ -1222,20 +1276,14 @@ static void set_multicast_list(struct usbnet *usbdev)
1222/* 1276/*
1223 * cfg80211 ops 1277 * cfg80211 ops
1224 */ 1278 */
1225static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex, 1279static int rndis_change_virtual_intf(struct wiphy *wiphy,
1280 struct net_device *dev,
1226 enum nl80211_iftype type, u32 *flags, 1281 enum nl80211_iftype type, u32 *flags,
1227 struct vif_params *params) 1282 struct vif_params *params)
1228{ 1283{
1229 struct net_device *dev; 1284 struct usbnet *usbdev = netdev_priv(dev);
1230 struct usbnet *usbdev;
1231 int mode; 1285 int mode;
1232 1286
1233 /* we're under RTNL */
1234 dev = __dev_get_by_index(&init_net, ifindex);
1235 if (!dev)
1236 return -ENODEV;
1237 usbdev = netdev_priv(dev);
1238
1239 switch (type) { 1287 switch (type) {
1240 case NL80211_IFTYPE_ADHOC: 1288 case NL80211_IFTYPE_ADHOC:
1241 mode = NDIS_80211_INFRA_ADHOC; 1289 mode = NDIS_80211_INFRA_ADHOC;
@@ -1251,6 +1299,64 @@ static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex,
1251} 1299}
1252 1300
1253 1301
1302static int rndis_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1303{
1304 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1305 struct usbnet *usbdev = priv->usbdev;
1306 int err;
1307
1308 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1309 err = set_frag_threshold(usbdev, wiphy->frag_threshold);
1310 if (err < 0)
1311 return err;
1312 }
1313
1314 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1315 err = set_rts_threshold(usbdev, wiphy->rts_threshold);
1316 if (err < 0)
1317 return err;
1318 }
1319
1320 return 0;
1321}
1322
1323
1324static int rndis_set_tx_power(struct wiphy *wiphy, enum tx_power_setting type,
1325 int dbm)
1326{
1327 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1328 struct usbnet *usbdev = priv->usbdev;
1329
1330 devdbg(usbdev, "rndis_set_tx_power type:0x%x dbm:%i", type, dbm);
1331
1332 /* Device doesn't support changing txpower after initialization, only
1333 * turn off/on radio. Support 'auto' mode and setting same dBm that is
1334 * currently used.
1335 */
1336 if (type == TX_POWER_AUTOMATIC || dbm == get_bcm4320_power_dbm(priv)) {
1337 if (!priv->radio_on)
1338 disassociate(usbdev, 1); /* turn on radio */
1339
1340 return 0;
1341 }
1342
1343 return -ENOTSUPP;
1344}
1345
1346
1347static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
1348{
1349 struct rndis_wlan_private *priv = wiphy_priv(wiphy);
1350 struct usbnet *usbdev = priv->usbdev;
1351
1352 *dbm = get_bcm4320_power_dbm(priv);
1353
1354 devdbg(usbdev, "rndis_get_tx_power dbm:%i", *dbm);
1355
1356 return 0;
1357}
1358
1359
1254#define SCAN_DELAY_JIFFIES (HZ) 1360#define SCAN_DELAY_JIFFIES (HZ)
1255static int rndis_scan(struct wiphy *wiphy, struct net_device *dev, 1361static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1256 struct cfg80211_scan_request *request) 1362 struct cfg80211_scan_request *request)
@@ -1766,74 +1872,6 @@ static int rndis_iw_get_genie(struct net_device *dev,
1766} 1872}
1767 1873
1768 1874
1769static int rndis_iw_set_rts(struct net_device *dev,
1770 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1771{
1772 struct usbnet *usbdev = netdev_priv(dev);
1773 __le32 tmp;
1774 devdbg(usbdev, "SIOCSIWRTS");
1775
1776 tmp = cpu_to_le32(wrqu->rts.value);
1777 return rndis_set_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp,
1778 sizeof(tmp));
1779}
1780
1781
1782static int rndis_iw_get_rts(struct net_device *dev,
1783 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1784{
1785 struct usbnet *usbdev = netdev_priv(dev);
1786 __le32 tmp;
1787 int len, ret;
1788
1789 len = sizeof(tmp);
1790 ret = rndis_query_oid(usbdev, OID_802_11_RTS_THRESHOLD, &tmp, &len);
1791 if (ret == 0) {
1792 wrqu->rts.value = le32_to_cpu(tmp);
1793 wrqu->rts.flags = 1;
1794 wrqu->rts.disabled = 0;
1795 }
1796
1797 devdbg(usbdev, "SIOCGIWRTS: %d", wrqu->rts.value);
1798
1799 return ret;
1800}
1801
1802
1803static int rndis_iw_set_frag(struct net_device *dev,
1804 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1805{
1806 struct usbnet *usbdev = netdev_priv(dev);
1807 __le32 tmp;
1808
1809 devdbg(usbdev, "SIOCSIWFRAG");
1810
1811 tmp = cpu_to_le32(wrqu->frag.value);
1812 return rndis_set_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1813 sizeof(tmp));
1814}
1815
1816
1817static int rndis_iw_get_frag(struct net_device *dev,
1818 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1819{
1820 struct usbnet *usbdev = netdev_priv(dev);
1821 __le32 tmp;
1822 int len, ret;
1823
1824 len = sizeof(tmp);
1825 ret = rndis_query_oid(usbdev, OID_802_11_FRAGMENTATION_THRESHOLD, &tmp,
1826 &len);
1827 if (ret == 0) {
1828 wrqu->frag.value = le32_to_cpu(tmp);
1829 wrqu->frag.flags = 1;
1830 wrqu->frag.disabled = 0;
1831 }
1832 devdbg(usbdev, "SIOCGIWFRAG: %d", wrqu->frag.value);
1833 return ret;
1834}
1835
1836
1837static int rndis_iw_set_freq(struct net_device *dev, 1875static int rndis_iw_set_freq(struct net_device *dev,
1838 struct iw_request_info *info, union iwreq_data *wrqu, char *extra) 1876 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1839{ 1877{
@@ -1882,71 +1920,6 @@ static int rndis_iw_get_freq(struct net_device *dev,
1882} 1920}
1883 1921
1884 1922
1885static int rndis_iw_get_txpower(struct net_device *dev,
1886 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1887{
1888 struct usbnet *usbdev = netdev_priv(dev);
1889 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1890 __le32 tx_power;
1891
1892 if (priv->radio_on) {
1893 /* fake since changing tx_power (by userlevel) not supported */
1894 tx_power = cpu_to_le32(get_bcm4320_power(priv));
1895
1896 wrqu->txpower.flags = IW_TXPOW_MWATT;
1897 wrqu->txpower.value = le32_to_cpu(tx_power);
1898 wrqu->txpower.disabled = 0;
1899 } else {
1900 wrqu->txpower.flags = IW_TXPOW_MWATT;
1901 wrqu->txpower.value = 0;
1902 wrqu->txpower.disabled = 1;
1903 }
1904
1905 devdbg(usbdev, "SIOCGIWTXPOW: %d", wrqu->txpower.value);
1906
1907 return 0;
1908}
1909
1910
1911static int rndis_iw_set_txpower(struct net_device *dev,
1912 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1913{
1914 struct usbnet *usbdev = netdev_priv(dev);
1915 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
1916 __le32 tx_power = 0;
1917
1918 if (!wrqu->txpower.disabled) {
1919 if (wrqu->txpower.flags == IW_TXPOW_MWATT)
1920 tx_power = cpu_to_le32(wrqu->txpower.value);
1921 else { /* wrqu->txpower.flags == IW_TXPOW_DBM */
1922 if (wrqu->txpower.value > 20)
1923 tx_power = cpu_to_le32(128);
1924 else if (wrqu->txpower.value < -43)
1925 tx_power = cpu_to_le32(127);
1926 else {
1927 signed char tmp;
1928 tmp = wrqu->txpower.value;
1929 tmp = -12 - tmp;
1930 tmp <<= 2;
1931 tx_power = cpu_to_le32((unsigned char)tmp);
1932 }
1933 }
1934 }
1935
1936 devdbg(usbdev, "SIOCSIWTXPOW: %d", le32_to_cpu(tx_power));
1937
1938 if (le32_to_cpu(tx_power) != 0) {
1939 /* txpower unsupported, just turn radio on */
1940 if (!priv->radio_on)
1941 return disassociate(usbdev, 1);
1942 return 0; /* all ready on */
1943 }
1944
1945 /* tx_power == 0, turn off radio */
1946 return disassociate(usbdev, 0);
1947}
1948
1949
1950static int rndis_iw_get_rate(struct net_device *dev, 1923static int rndis_iw_get_rate(struct net_device *dev,
1951 struct iw_request_info *info, union iwreq_data *wrqu, char *extra) 1924 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1952{ 1925{
@@ -2022,12 +1995,12 @@ static const iw_handler rndis_iw_handler[] =
2022 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid, 1995 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
2023 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid, 1996 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
2024 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate, 1997 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
2025 IW_IOCTL(SIOCSIWRTS) = rndis_iw_set_rts, 1998 IW_IOCTL(SIOCSIWRTS) = (iw_handler) cfg80211_wext_siwrts,
2026 IW_IOCTL(SIOCGIWRTS) = rndis_iw_get_rts, 1999 IW_IOCTL(SIOCGIWRTS) = (iw_handler) cfg80211_wext_giwrts,
2027 IW_IOCTL(SIOCSIWFRAG) = rndis_iw_set_frag, 2000 IW_IOCTL(SIOCSIWFRAG) = (iw_handler) cfg80211_wext_siwfrag,
2028 IW_IOCTL(SIOCGIWFRAG) = rndis_iw_get_frag, 2001 IW_IOCTL(SIOCGIWFRAG) = (iw_handler) cfg80211_wext_giwfrag,
2029 IW_IOCTL(SIOCSIWTXPOW) = rndis_iw_set_txpower, 2002 IW_IOCTL(SIOCSIWTXPOW) = (iw_handler) cfg80211_wext_siwtxpower,
2030 IW_IOCTL(SIOCGIWTXPOW) = rndis_iw_get_txpower, 2003 IW_IOCTL(SIOCGIWTXPOW) = (iw_handler) cfg80211_wext_giwtxpower,
2031 IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode, 2004 IW_IOCTL(SIOCSIWENCODE) = rndis_iw_set_encode,
2032 IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext, 2005 IW_IOCTL(SIOCSIWENCODEEXT) = rndis_iw_set_encode_ext,
2033 IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth, 2006 IW_IOCTL(SIOCSIWAUTH) = rndis_iw_set_auth,
@@ -2475,6 +2448,10 @@ static int rndis_wlan_bind(struct usbnet *usbdev, struct usb_interface *intf)
2475 2448
2476 set_default_iw_params(usbdev); 2449 set_default_iw_params(usbdev);
2477 2450
2451 /* set default rts/frag */
2452 rndis_set_wiphy_params(wiphy,
2453 WIPHY_PARAM_FRAG_THRESHOLD | WIPHY_PARAM_RTS_THRESHOLD);
2454
2478 /* turn radio on */ 2455 /* turn radio on */
2479 priv->radio_on = 1; 2456 priv->radio_on = 1;
2480 disassociate(usbdev, 1); 2457 disassociate(usbdev, 1);
@@ -2522,10 +2499,18 @@ static void rndis_wlan_unbind(struct usbnet *usbdev, struct usb_interface *intf)
2522 2499
2523static int rndis_wlan_reset(struct usbnet *usbdev) 2500static int rndis_wlan_reset(struct usbnet *usbdev)
2524{ 2501{
2502 devdbg(usbdev, "rndis_wlan_reset");
2525 return deauthenticate(usbdev); 2503 return deauthenticate(usbdev);
2526} 2504}
2527 2505
2528 2506
2507static int rndis_wlan_stop(struct usbnet *usbdev)
2508{
2509 devdbg(usbdev, "rndis_wlan_stop");
2510 return disassociate(usbdev, 0);
2511}
2512
2513
2529static const struct driver_info bcm4320b_info = { 2514static const struct driver_info bcm4320b_info = {
2530 .description = "Wireless RNDIS device, BCM4320b based", 2515 .description = "Wireless RNDIS device, BCM4320b based",
2531 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT, 2516 .flags = FLAG_WLAN | FLAG_FRAMING_RN | FLAG_NO_SETINT,
@@ -2535,6 +2520,7 @@ static const struct driver_info bcm4320b_info = {
2535 .rx_fixup = rndis_rx_fixup, 2520 .rx_fixup = rndis_rx_fixup,
2536 .tx_fixup = rndis_tx_fixup, 2521 .tx_fixup = rndis_tx_fixup,
2537 .reset = rndis_wlan_reset, 2522 .reset = rndis_wlan_reset,
2523 .stop = rndis_wlan_stop,
2538 .early_init = bcm4320b_early_init, 2524 .early_init = bcm4320b_early_init,
2539 .link_change = rndis_wlan_link_change, 2525 .link_change = rndis_wlan_link_change,
2540}; 2526};
@@ -2548,6 +2534,7 @@ static const struct driver_info bcm4320a_info = {
2548 .rx_fixup = rndis_rx_fixup, 2534 .rx_fixup = rndis_rx_fixup,
2549 .tx_fixup = rndis_tx_fixup, 2535 .tx_fixup = rndis_tx_fixup,
2550 .reset = rndis_wlan_reset, 2536 .reset = rndis_wlan_reset,
2537 .stop = rndis_wlan_stop,
2551 .early_init = bcm4320a_early_init, 2538 .early_init = bcm4320a_early_init,
2552 .link_change = rndis_wlan_link_change, 2539 .link_change = rndis_wlan_link_change,
2553}; 2540};
@@ -2561,6 +2548,7 @@ static const struct driver_info rndis_wlan_info = {
2561 .rx_fixup = rndis_rx_fixup, 2548 .rx_fixup = rndis_rx_fixup,
2562 .tx_fixup = rndis_tx_fixup, 2549 .tx_fixup = rndis_tx_fixup,
2563 .reset = rndis_wlan_reset, 2550 .reset = rndis_wlan_reset,
2551 .stop = rndis_wlan_stop,
2564 .early_init = bcm4320a_early_init, 2552 .early_init = bcm4320a_early_init,
2565 .link_change = rndis_wlan_link_change, 2553 .link_change = rndis_wlan_link_change,
2566}; 2554};
diff --git a/drivers/net/wireless/rt2x00/Kconfig b/drivers/net/wireless/rt2x00/Kconfig
index 8aab3e6754bd..f970aa25326a 100644
--- a/drivers/net/wireless/rt2x00/Kconfig
+++ b/drivers/net/wireless/rt2x00/Kconfig
@@ -112,14 +112,6 @@ config RT2X00_LIB_FIRMWARE
112config RT2X00_LIB_CRYPTO 112config RT2X00_LIB_CRYPTO
113 boolean 113 boolean
114 114
115config RT2X00_LIB_RFKILL
116 boolean
117 default y if (RT2X00_LIB=y && INPUT=y) || (RT2X00_LIB=m && INPUT!=n)
118 select INPUT_POLLDEV
119
120comment "rt2x00 rfkill support disabled due to modularized INPUT and built-in rt2x00"
121 depends on RT2X00_LIB=y && INPUT=m
122
123config RT2X00_LIB_LEDS 115config RT2X00_LIB_LEDS
124 boolean 116 boolean
125 default y if (RT2X00_LIB=y && LEDS_CLASS=y) || (RT2X00_LIB=m && LEDS_CLASS!=n) 117 default y if (RT2X00_LIB=y && LEDS_CLASS=y) || (RT2X00_LIB=m && LEDS_CLASS!=n)
diff --git a/drivers/net/wireless/rt2x00/Makefile b/drivers/net/wireless/rt2x00/Makefile
index bfc7226f0afe..13043ea97667 100644
--- a/drivers/net/wireless/rt2x00/Makefile
+++ b/drivers/net/wireless/rt2x00/Makefile
@@ -5,7 +5,6 @@ rt2x00lib-y += rt2x00queue.o
5rt2x00lib-y += rt2x00link.o 5rt2x00lib-y += rt2x00link.o
6rt2x00lib-$(CONFIG_RT2X00_LIB_DEBUGFS) += rt2x00debug.o 6rt2x00lib-$(CONFIG_RT2X00_LIB_DEBUGFS) += rt2x00debug.o
7rt2x00lib-$(CONFIG_RT2X00_LIB_CRYPTO) += rt2x00crypto.o 7rt2x00lib-$(CONFIG_RT2X00_LIB_CRYPTO) += rt2x00crypto.o
8rt2x00lib-$(CONFIG_RT2X00_LIB_RFKILL) += rt2x00rfkill.o
9rt2x00lib-$(CONFIG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o 8rt2x00lib-$(CONFIG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o
10rt2x00lib-$(CONFIG_RT2X00_LIB_LEDS) += rt2x00leds.o 9rt2x00lib-$(CONFIG_RT2X00_LIB_LEDS) += rt2x00leds.o
11rt2x00lib-$(CONFIG_RT2X00_LIB_HT) += rt2x00ht.o 10rt2x00lib-$(CONFIG_RT2X00_LIB_HT) += rt2x00ht.o
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c
index 435f945fe64d..d8035e3575e8 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.c
+++ b/drivers/net/wireless/rt2x00/rt2400pci.c
@@ -199,7 +199,6 @@ static const struct rt2x00debug rt2400pci_rt2x00debug = {
199}; 199};
200#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 200#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
201 201
202#ifdef CONFIG_RT2X00_LIB_RFKILL
203static int rt2400pci_rfkill_poll(struct rt2x00_dev *rt2x00dev) 202static int rt2400pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
204{ 203{
205 u32 reg; 204 u32 reg;
@@ -207,9 +206,6 @@ static int rt2400pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
207 rt2x00pci_register_read(rt2x00dev, GPIOCSR, &reg); 206 rt2x00pci_register_read(rt2x00dev, GPIOCSR, &reg);
208 return rt2x00_get_field32(reg, GPIOCSR_BIT0); 207 return rt2x00_get_field32(reg, GPIOCSR_BIT0);
209} 208}
210#else
211#define rt2400pci_rfkill_poll NULL
212#endif /* CONFIG_RT2X00_LIB_RFKILL */
213 209
214#ifdef CONFIG_RT2X00_LIB_LEDS 210#ifdef CONFIG_RT2X00_LIB_LEDS
215static void rt2400pci_brightness_set(struct led_classdev *led_cdev, 211static void rt2400pci_brightness_set(struct led_classdev *led_cdev,
@@ -1391,10 +1387,8 @@ static int rt2400pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
1391 /* 1387 /*
1392 * Detect if this device has an hardware controlled radio. 1388 * Detect if this device has an hardware controlled radio.
1393 */ 1389 */
1394#ifdef CONFIG_RT2X00_LIB_RFKILL
1395 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) 1390 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
1396 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); 1391 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
1397#endif /* CONFIG_RT2X00_LIB_RFKILL */
1398 1392
1399 /* 1393 /*
1400 * Check if the BBP tuning should be enabled. 1394 * Check if the BBP tuning should be enabled.
@@ -1573,6 +1567,7 @@ static const struct ieee80211_ops rt2400pci_mac80211_ops = {
1573 .get_tx_stats = rt2x00mac_get_tx_stats, 1567 .get_tx_stats = rt2x00mac_get_tx_stats,
1574 .get_tsf = rt2400pci_get_tsf, 1568 .get_tsf = rt2400pci_get_tsf,
1575 .tx_last_beacon = rt2400pci_tx_last_beacon, 1569 .tx_last_beacon = rt2400pci_tx_last_beacon,
1570 .rfkill_poll = rt2x00mac_rfkill_poll,
1576}; 1571};
1577 1572
1578static const struct rt2x00lib_ops rt2400pci_rt2x00_ops = { 1573static const struct rt2x00lib_ops rt2400pci_rt2x00_ops = {
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c
index 08b30d01e67d..c123e28396d0 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.c
+++ b/drivers/net/wireless/rt2x00/rt2500pci.c
@@ -199,7 +199,6 @@ static const struct rt2x00debug rt2500pci_rt2x00debug = {
199}; 199};
200#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 200#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
201 201
202#ifdef CONFIG_RT2X00_LIB_RFKILL
203static int rt2500pci_rfkill_poll(struct rt2x00_dev *rt2x00dev) 202static int rt2500pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
204{ 203{
205 u32 reg; 204 u32 reg;
@@ -207,9 +206,6 @@ static int rt2500pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
207 rt2x00pci_register_read(rt2x00dev, GPIOCSR, &reg); 206 rt2x00pci_register_read(rt2x00dev, GPIOCSR, &reg);
208 return rt2x00_get_field32(reg, GPIOCSR_BIT0); 207 return rt2x00_get_field32(reg, GPIOCSR_BIT0);
209} 208}
210#else
211#define rt2500pci_rfkill_poll NULL
212#endif /* CONFIG_RT2X00_LIB_RFKILL */
213 209
214#ifdef CONFIG_RT2X00_LIB_LEDS 210#ifdef CONFIG_RT2X00_LIB_LEDS
215static void rt2500pci_brightness_set(struct led_classdev *led_cdev, 211static void rt2500pci_brightness_set(struct led_classdev *led_cdev,
@@ -1548,10 +1544,8 @@ static int rt2500pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
1548 /* 1544 /*
1549 * Detect if this device has an hardware controlled radio. 1545 * Detect if this device has an hardware controlled radio.
1550 */ 1546 */
1551#ifdef CONFIG_RT2X00_LIB_RFKILL
1552 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) 1547 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
1553 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); 1548 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
1554#endif /* CONFIG_RT2X00_LIB_RFKILL */
1555 1549
1556 /* 1550 /*
1557 * Check if the BBP tuning should be enabled. 1551 * Check if the BBP tuning should be enabled.
@@ -1872,6 +1866,7 @@ static const struct ieee80211_ops rt2500pci_mac80211_ops = {
1872 .get_tx_stats = rt2x00mac_get_tx_stats, 1866 .get_tx_stats = rt2x00mac_get_tx_stats,
1873 .get_tsf = rt2500pci_get_tsf, 1867 .get_tsf = rt2500pci_get_tsf,
1874 .tx_last_beacon = rt2500pci_tx_last_beacon, 1868 .tx_last_beacon = rt2500pci_tx_last_beacon,
1869 .rfkill_poll = rt2x00mac_rfkill_poll,
1875}; 1870};
1876 1871
1877static const struct rt2x00lib_ops rt2500pci_rt2x00_ops = { 1872static const struct rt2x00lib_ops rt2500pci_rt2x00_ops = {
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index 66daf68ff0ee..795706d63b94 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -277,7 +277,6 @@ static const struct rt2x00debug rt2500usb_rt2x00debug = {
277}; 277};
278#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 278#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
279 279
280#ifdef CONFIG_RT2X00_LIB_RFKILL
281static int rt2500usb_rfkill_poll(struct rt2x00_dev *rt2x00dev) 280static int rt2500usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
282{ 281{
283 u16 reg; 282 u16 reg;
@@ -285,9 +284,6 @@ static int rt2500usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
285 rt2500usb_register_read(rt2x00dev, MAC_CSR19, &reg); 284 rt2500usb_register_read(rt2x00dev, MAC_CSR19, &reg);
286 return rt2x00_get_field32(reg, MAC_CSR19_BIT7); 285 return rt2x00_get_field32(reg, MAC_CSR19_BIT7);
287} 286}
288#else
289#define rt2500usb_rfkill_poll NULL
290#endif /* CONFIG_RT2X00_LIB_RFKILL */
291 287
292#ifdef CONFIG_RT2X00_LIB_LEDS 288#ifdef CONFIG_RT2X00_LIB_LEDS
293static void rt2500usb_brightness_set(struct led_classdev *led_cdev, 289static void rt2500usb_brightness_set(struct led_classdev *led_cdev,
@@ -1601,10 +1597,8 @@ static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1601 /* 1597 /*
1602 * Detect if this device has an hardware controlled radio. 1598 * Detect if this device has an hardware controlled radio.
1603 */ 1599 */
1604#ifdef CONFIG_RT2X00_LIB_RFKILL
1605 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) 1600 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
1606 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); 1601 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
1607#endif /* CONFIG_RT2X00_LIB_RFKILL */
1608 1602
1609 /* 1603 /*
1610 * Check if the BBP tuning should be disabled. 1604 * Check if the BBP tuning should be disabled.
@@ -1905,6 +1899,7 @@ static const struct ieee80211_ops rt2500usb_mac80211_ops = {
1905 .bss_info_changed = rt2x00mac_bss_info_changed, 1899 .bss_info_changed = rt2x00mac_bss_info_changed,
1906 .conf_tx = rt2x00mac_conf_tx, 1900 .conf_tx = rt2x00mac_conf_tx,
1907 .get_tx_stats = rt2x00mac_get_tx_stats, 1901 .get_tx_stats = rt2x00mac_get_tx_stats,
1902 .rfkill_poll = rt2x00mac_rfkill_poll,
1908}; 1903};
1909 1904
1910static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = { 1905static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index 37561667925b..a204e66753c2 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -264,7 +264,6 @@ static const struct rt2x00debug rt2800usb_rt2x00debug = {
264}; 264};
265#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 265#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
266 266
267#ifdef CONFIG_RT2X00_LIB_RFKILL
268static int rt2800usb_rfkill_poll(struct rt2x00_dev *rt2x00dev) 267static int rt2800usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
269{ 268{
270 u32 reg; 269 u32 reg;
@@ -272,9 +271,6 @@ static int rt2800usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
272 rt2x00usb_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg); 271 rt2x00usb_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
273 return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2); 272 return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2);
274} 273}
275#else
276#define rt2800usb_rfkill_poll NULL
277#endif /* CONFIG_RT2X00_LIB_RFKILL */
278 274
279#ifdef CONFIG_RT2X00_LIB_LEDS 275#ifdef CONFIG_RT2X00_LIB_LEDS
280static void rt2800usb_brightness_set(struct led_classdev *led_cdev, 276static void rt2800usb_brightness_set(struct led_classdev *led_cdev,
@@ -2385,10 +2381,8 @@ static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
2385 /* 2381 /*
2386 * Detect if this device has an hardware controlled radio. 2382 * Detect if this device has an hardware controlled radio.
2387 */ 2383 */
2388#ifdef CONFIG_RT2X00_LIB_RFKILL
2389 if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO)) 2384 if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
2390 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); 2385 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
2391#endif /* CONFIG_RT2X00_LIB_RFKILL */
2392 2386
2393 /* 2387 /*
2394 * Store led settings, for correct led behaviour. 2388 * Store led settings, for correct led behaviour.
@@ -2800,6 +2794,7 @@ static const struct ieee80211_ops rt2800usb_mac80211_ops = {
2800 .conf_tx = rt2800usb_conf_tx, 2794 .conf_tx = rt2800usb_conf_tx,
2801 .get_tx_stats = rt2x00mac_get_tx_stats, 2795 .get_tx_stats = rt2x00mac_get_tx_stats,
2802 .get_tsf = rt2800usb_get_tsf, 2796 .get_tsf = rt2800usb_get_tsf,
2797 .rfkill_poll = rt2x00mac_rfkill_poll,
2803}; 2798};
2804 2799
2805static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = { 2800static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index a498dde024e1..71f37cb476b0 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -651,18 +651,6 @@ struct rt2x00_dev {
651 enum ieee80211_band curr_band; 651 enum ieee80211_band curr_band;
652 652
653 /* 653 /*
654 * rfkill structure for RF state switching support.
655 * This will only be compiled in when required.
656 */
657#ifdef CONFIG_RT2X00_LIB_RFKILL
658 unsigned long rfkill_state;
659#define RFKILL_STATE_ALLOCATED 1
660#define RFKILL_STATE_REGISTERED 2
661#define RFKILL_STATE_BLOCKED 3
662 struct input_polled_dev *rfkill_poll_dev;
663#endif /* CONFIG_RT2X00_LIB_RFKILL */
664
665 /*
666 * If enabled, the debugfs interface structures 654 * If enabled, the debugfs interface structures
667 * required for deregistration of debugfs. 655 * required for deregistration of debugfs.
668 */ 656 */
@@ -992,6 +980,7 @@ void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
992 u32 changes); 980 u32 changes);
993int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue, 981int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
994 const struct ieee80211_tx_queue_params *params); 982 const struct ieee80211_tx_queue_params *params);
983void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw);
995 984
996/* 985/*
997 * Driver allocation handlers. 986 * Driver allocation handlers.
diff --git a/drivers/net/wireless/rt2x00/rt2x00crypto.c b/drivers/net/wireless/rt2x00/rt2x00crypto.c
index bc4e81e21841..c54eda3c2db0 100644
--- a/drivers/net/wireless/rt2x00/rt2x00crypto.c
+++ b/drivers/net/wireless/rt2x00/rt2x00crypto.c
@@ -53,8 +53,7 @@ void rt2x00crypto_create_tx_descriptor(struct queue_entry *entry,
53 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb); 53 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
54 struct ieee80211_key_conf *hw_key = tx_info->control.hw_key; 54 struct ieee80211_key_conf *hw_key = tx_info->control.hw_key;
55 55
56 if (!test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags) || 56 if (!test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags) || !hw_key)
57 !hw_key || entry->skb->do_not_encrypt)
58 return; 57 return;
59 58
60 __set_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags); 59 __set_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags);
@@ -82,8 +81,7 @@ unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
82 struct ieee80211_key_conf *key = tx_info->control.hw_key; 81 struct ieee80211_key_conf *key = tx_info->control.hw_key;
83 unsigned int overhead = 0; 82 unsigned int overhead = 0;
84 83
85 if (!test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags) || 84 if (!test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags) || !key)
86 !key || skb->do_not_encrypt)
87 return overhead; 85 return overhead;
88 86
89 /* 87 /*
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index 57813e72c808..4fff3a83f7df 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -449,7 +449,8 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev,
449 * mac80211 will clean up the skb structure. 449 * mac80211 will clean up the skb structure.
450 */ 450 */
451 rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_RXDONE, entry->skb); 451 rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_RXDONE, entry->skb);
452 ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb, rx_status); 452 memcpy(IEEE80211_SKB_RXCB(entry->skb), rx_status, sizeof(*rx_status));
453 ieee80211_rx_irqsafe(rt2x00dev->hw, entry->skb);
453 454
454 /* 455 /*
455 * Replace the skb with the freshly allocated one. 456 * Replace the skb with the freshly allocated one.
@@ -870,7 +871,6 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
870 */ 871 */
871 rt2x00link_register(rt2x00dev); 872 rt2x00link_register(rt2x00dev);
872 rt2x00leds_register(rt2x00dev); 873 rt2x00leds_register(rt2x00dev);
873 rt2x00rfkill_allocate(rt2x00dev);
874 rt2x00debug_register(rt2x00dev); 874 rt2x00debug_register(rt2x00dev);
875 875
876 set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags); 876 set_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags);
@@ -902,7 +902,6 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
902 * Free extra components 902 * Free extra components
903 */ 903 */
904 rt2x00debug_deregister(rt2x00dev); 904 rt2x00debug_deregister(rt2x00dev);
905 rt2x00rfkill_free(rt2x00dev);
906 rt2x00leds_unregister(rt2x00dev); 905 rt2x00leds_unregister(rt2x00dev);
907 906
908 /* 907 /*
diff --git a/drivers/net/wireless/rt2x00/rt2x00lib.h b/drivers/net/wireless/rt2x00/rt2x00lib.h
index 0bf2715fa93a..512fa2bc3a10 100644
--- a/drivers/net/wireless/rt2x00/rt2x00lib.h
+++ b/drivers/net/wireless/rt2x00/rt2x00lib.h
@@ -30,10 +30,8 @@
30 30
31/* 31/*
32 * Interval defines 32 * Interval defines
33 * Both the link tuner as the rfkill will be called once per second.
34 */ 33 */
35#define LINK_TUNE_INTERVAL round_jiffies_relative(HZ) 34#define LINK_TUNE_INTERVAL round_jiffies_relative(HZ)
36#define RFKILL_POLL_INTERVAL 1000
37 35
38/* 36/*
39 * rt2x00_rate: Per rate device information 37 * rt2x00_rate: Per rate device information
@@ -386,29 +384,18 @@ static inline void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
386/* 384/*
387 * RFkill handlers. 385 * RFkill handlers.
388 */ 386 */
389#ifdef CONFIG_RT2X00_LIB_RFKILL
390void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev);
391void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev);
392void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev);
393void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev);
394#else
395static inline void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev) 387static inline void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
396{ 388{
389 if (test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
390 wiphy_rfkill_start_polling(rt2x00dev->hw->wiphy);
397} 391}
398 392
399static inline void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev) 393static inline void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
400{ 394{
395 if (test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
396 wiphy_rfkill_stop_polling(rt2x00dev->hw->wiphy);
401} 397}
402 398
403static inline void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
404{
405}
406
407static inline void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev)
408{
409}
410#endif /* CONFIG_RT2X00_LIB_RFKILL */
411
412/* 399/*
413 * LED handlers 400 * LED handlers
414 */ 401 */
diff --git a/drivers/net/wireless/rt2x00/rt2x00mac.c b/drivers/net/wireless/rt2x00/rt2x00mac.c
index c4c06b4e1f08..b7e0ddda38f5 100644
--- a/drivers/net/wireless/rt2x00/rt2x00mac.c
+++ b/drivers/net/wireless/rt2x00/rt2x00mac.c
@@ -73,7 +73,8 @@ static int rt2x00mac_tx_rts_cts(struct rt2x00_dev *rt2x00dev,
73 else 73 else
74 rts_info->flags &= ~IEEE80211_TX_CTL_NO_ACK; 74 rts_info->flags &= ~IEEE80211_TX_CTL_NO_ACK;
75 75
76 skb->do_not_encrypt = 1; 76 /* Disable hardware encryption */
77 rts_info->control.hw_key = NULL;
77 78
78 /* 79 /*
79 * RTS/CTS frame should use the length of the frame plus any 80 * RTS/CTS frame should use the length of the frame plus any
@@ -687,3 +688,12 @@ int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
687 return 0; 688 return 0;
688} 689}
689EXPORT_SYMBOL_GPL(rt2x00mac_conf_tx); 690EXPORT_SYMBOL_GPL(rt2x00mac_conf_tx);
691
692void rt2x00mac_rfkill_poll(struct ieee80211_hw *hw)
693{
694 struct rt2x00_dev *rt2x00dev = hw->priv;
695 bool blocked = !!rt2x00dev->ops->lib->rfkill_poll(rt2x00dev);
696
697 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
698}
699EXPORT_SYMBOL_GPL(rt2x00mac_rfkill_poll);
diff --git a/drivers/net/wireless/rt2x00/rt2x00rfkill.c b/drivers/net/wireless/rt2x00/rt2x00rfkill.c
deleted file mode 100644
index b6d4c6700bf3..000000000000
--- a/drivers/net/wireless/rt2x00/rt2x00rfkill.c
+++ /dev/null
@@ -1,127 +0,0 @@
1/*
2 Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
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 as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2x00rfkill
23 Abstract: rt2x00 rfkill routines.
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28
29#include "rt2x00.h"
30#include "rt2x00lib.h"
31
32static void rt2x00rfkill_poll(struct input_polled_dev *poll_dev)
33{
34 struct rt2x00_dev *rt2x00dev = poll_dev->private;
35 int state, old_state;
36
37 if (!test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state) ||
38 !test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
39 return;
40
41 /*
42 * Poll latest state, if the state is different then the previous state,
43 * we should generate an input event.
44 */
45 state = !!rt2x00dev->ops->lib->rfkill_poll(rt2x00dev);
46 old_state = !!test_bit(RFKILL_STATE_BLOCKED, &rt2x00dev->rfkill_state);
47
48 if (old_state != state) {
49 input_report_switch(poll_dev->input, SW_RFKILL_ALL, state);
50 change_bit(RFKILL_STATE_BLOCKED, &rt2x00dev->rfkill_state);
51 }
52}
53
54void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
55{
56 if (!test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state) ||
57 test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state))
58 return;
59
60 if (input_register_polled_device(rt2x00dev->rfkill_poll_dev)) {
61 ERROR(rt2x00dev, "Failed to register polled device.\n");
62 return;
63 }
64
65 __set_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state);
66
67 /*
68 * Force initial poll which will detect the initial device state,
69 * and correctly sends the signal to the input layer about this
70 * state.
71 */
72 rt2x00rfkill_poll(rt2x00dev->rfkill_poll_dev);
73}
74
75void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
76{
77 if (!test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state) ||
78 !test_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state))
79 return;
80
81 input_unregister_polled_device(rt2x00dev->rfkill_poll_dev);
82
83 __clear_bit(RFKILL_STATE_REGISTERED, &rt2x00dev->rfkill_state);
84}
85
86void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
87{
88 struct input_polled_dev *poll_dev;
89
90 if (test_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state) ||
91 !test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
92 return;
93
94 poll_dev = input_allocate_polled_device();
95 if (!poll_dev) {
96 ERROR(rt2x00dev, "Failed to allocate polled device.\n");
97 return;
98 }
99
100 poll_dev->private = rt2x00dev;
101 poll_dev->poll = rt2x00rfkill_poll;
102 poll_dev->poll_interval = RFKILL_POLL_INTERVAL;
103
104 poll_dev->input->name = rt2x00dev->ops->name;
105 poll_dev->input->phys = wiphy_name(rt2x00dev->hw->wiphy);
106 poll_dev->input->id.bustype = BUS_HOST;
107 poll_dev->input->id.vendor = 0x1814;
108 poll_dev->input->id.product = rt2x00dev->chip.rt;
109 poll_dev->input->id.version = rt2x00dev->chip.rev;
110 poll_dev->input->dev.parent = wiphy_dev(rt2x00dev->hw->wiphy);
111 poll_dev->input->evbit[0] = BIT(EV_SW);
112 poll_dev->input->swbit[0] = BIT(SW_RFKILL_ALL);
113
114 rt2x00dev->rfkill_poll_dev = poll_dev;
115
116 __set_bit(RFKILL_STATE_ALLOCATED, &rt2x00dev->rfkill_state);
117}
118
119void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev)
120{
121 if (!__test_and_clear_bit(RFKILL_STATE_ALLOCATED,
122 &rt2x00dev->rfkill_state))
123 return;
124
125 input_free_polled_device(rt2x00dev->rfkill_poll_dev);
126 rt2x00dev->rfkill_poll_dev = NULL;
127}
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index 49b29ff90c47..8a49d99df682 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -237,7 +237,6 @@ static const struct rt2x00debug rt61pci_rt2x00debug = {
237}; 237};
238#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 238#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
239 239
240#ifdef CONFIG_RT2X00_LIB_RFKILL
241static int rt61pci_rfkill_poll(struct rt2x00_dev *rt2x00dev) 240static int rt61pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
242{ 241{
243 u32 reg; 242 u32 reg;
@@ -245,9 +244,6 @@ static int rt61pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
245 rt2x00pci_register_read(rt2x00dev, MAC_CSR13, &reg); 244 rt2x00pci_register_read(rt2x00dev, MAC_CSR13, &reg);
246 return rt2x00_get_field32(reg, MAC_CSR13_BIT5); 245 return rt2x00_get_field32(reg, MAC_CSR13_BIT5);
247} 246}
248#else
249#define rt61pci_rfkill_poll NULL
250#endif /* CONFIG_RT2X00_LIB_RFKILL */
251 247
252#ifdef CONFIG_RT2X00_LIB_LEDS 248#ifdef CONFIG_RT2X00_LIB_LEDS
253static void rt61pci_brightness_set(struct led_classdev *led_cdev, 249static void rt61pci_brightness_set(struct led_classdev *led_cdev,
@@ -2338,10 +2334,8 @@ static int rt61pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2338 /* 2334 /*
2339 * Detect if this device has an hardware controlled radio. 2335 * Detect if this device has an hardware controlled radio.
2340 */ 2336 */
2341#ifdef CONFIG_RT2X00_LIB_RFKILL
2342 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) 2337 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
2343 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); 2338 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
2344#endif /* CONFIG_RT2X00_LIB_RFKILL */
2345 2339
2346 /* 2340 /*
2347 * Read frequency offset and RF programming sequence. 2341 * Read frequency offset and RF programming sequence.
@@ -2728,6 +2722,7 @@ static const struct ieee80211_ops rt61pci_mac80211_ops = {
2728 .conf_tx = rt61pci_conf_tx, 2722 .conf_tx = rt61pci_conf_tx,
2729 .get_tx_stats = rt2x00mac_get_tx_stats, 2723 .get_tx_stats = rt2x00mac_get_tx_stats,
2730 .get_tsf = rt61pci_get_tsf, 2724 .get_tsf = rt61pci_get_tsf,
2725 .rfkill_poll = rt2x00mac_rfkill_poll,
2731}; 2726};
2732 2727
2733static const struct rt2x00lib_ops rt61pci_rt2x00_ops = { 2728static const struct rt2x00lib_ops rt61pci_rt2x00_ops = {
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index c18848836f2d..ad2898ca8677 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -183,7 +183,6 @@ static const struct rt2x00debug rt73usb_rt2x00debug = {
183}; 183};
184#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 184#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
185 185
186#ifdef CONFIG_RT2X00_LIB_RFKILL
187static int rt73usb_rfkill_poll(struct rt2x00_dev *rt2x00dev) 186static int rt73usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
188{ 187{
189 u32 reg; 188 u32 reg;
@@ -191,9 +190,6 @@ static int rt73usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
191 rt2x00usb_register_read(rt2x00dev, MAC_CSR13, &reg); 190 rt2x00usb_register_read(rt2x00dev, MAC_CSR13, &reg);
192 return rt2x00_get_field32(reg, MAC_CSR13_BIT7); 191 return rt2x00_get_field32(reg, MAC_CSR13_BIT7);
193} 192}
194#else
195#define rt73usb_rfkill_poll NULL
196#endif /* CONFIG_RT2X00_LIB_RFKILL */
197 193
198#ifdef CONFIG_RT2X00_LIB_LEDS 194#ifdef CONFIG_RT2X00_LIB_LEDS
199static void rt73usb_brightness_set(struct led_classdev *led_cdev, 195static void rt73usb_brightness_set(struct led_classdev *led_cdev,
@@ -1863,10 +1859,8 @@ static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1863 /* 1859 /*
1864 * Detect if this device has an hardware controlled radio. 1860 * Detect if this device has an hardware controlled radio.
1865 */ 1861 */
1866#ifdef CONFIG_RT2X00_LIB_RFKILL
1867 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) 1862 if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
1868 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags); 1863 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
1869#endif /* CONFIG_RT2X00_LIB_RFKILL */
1870 1864
1871 /* 1865 /*
1872 * Read frequency offset. 1866 * Read frequency offset.
@@ -2253,6 +2247,7 @@ static const struct ieee80211_ops rt73usb_mac80211_ops = {
2253 .conf_tx = rt73usb_conf_tx, 2247 .conf_tx = rt73usb_conf_tx,
2254 .get_tx_stats = rt2x00mac_get_tx_stats, 2248 .get_tx_stats = rt2x00mac_get_tx_stats,
2255 .get_tsf = rt73usb_get_tsf, 2249 .get_tsf = rt73usb_get_tsf,
2250 .rfkill_poll = rt2x00mac_rfkill_poll,
2256}; 2251};
2257 2252
2258static const struct rt2x00lib_ops rt73usb_rt2x00_ops = { 2253static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
diff --git a/drivers/net/wireless/rtl818x/rtl8180_dev.c b/drivers/net/wireless/rtl818x/rtl8180_dev.c
index 7e65d7c31802..09f46abc730a 100644
--- a/drivers/net/wireless/rtl818x/rtl8180_dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8180_dev.c
@@ -143,7 +143,8 @@ static void rtl8180_handle_rx(struct ieee80211_hw *dev)
143 if (flags & RTL818X_RX_DESC_FLAG_CRC32_ERR) 143 if (flags & RTL818X_RX_DESC_FLAG_CRC32_ERR)
144 rx_status.flag |= RX_FLAG_FAILED_FCS_CRC; 144 rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
145 145
146 ieee80211_rx_irqsafe(dev, skb, &rx_status); 146 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
147 ieee80211_rx_irqsafe(dev, skb);
147 148
148 skb = new_skb; 149 skb = new_skb;
149 priv->rx_buf[priv->rx_idx] = skb; 150 priv->rx_buf[priv->rx_idx] = skb;
@@ -280,7 +281,7 @@ static int rtl8180_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
280 (ieee80211_get_tx_rate(dev, info)->bitrate * 2) / 10); 281 (ieee80211_get_tx_rate(dev, info)->bitrate * 2) / 10);
281 remainder = (16 * (skb->len + 4)) % 282 remainder = (16 * (skb->len + 4)) %
282 ((ieee80211_get_tx_rate(dev, info)->bitrate * 2) / 10); 283 ((ieee80211_get_tx_rate(dev, info)->bitrate * 2) / 10);
283 if (remainder > 0 && remainder <= 6) 284 if (remainder <= 6)
284 plcp_len |= 1 << 15; 285 plcp_len |= 1 << 15;
285 } 286 }
286 287
diff --git a/drivers/net/wireless/rtl818x/rtl8187_dev.c b/drivers/net/wireless/rtl818x/rtl8187_dev.c
index 294250e294dd..c9b9dbe584c6 100644
--- a/drivers/net/wireless/rtl818x/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c
@@ -380,7 +380,8 @@ static void rtl8187_rx_cb(struct urb *urb)
380 rx_status.flag |= RX_FLAG_TSFT; 380 rx_status.flag |= RX_FLAG_TSFT;
381 if (flags & RTL818X_RX_DESC_FLAG_CRC32_ERR) 381 if (flags & RTL818X_RX_DESC_FLAG_CRC32_ERR)
382 rx_status.flag |= RX_FLAG_FAILED_FCS_CRC; 382 rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
383 ieee80211_rx_irqsafe(dev, skb, &rx_status); 383 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
384 ieee80211_rx_irqsafe(dev, skb);
384 385
385 skb = dev_alloc_skb(RTL8187_MAX_RX); 386 skb = dev_alloc_skb(RTL8187_MAX_RX);
386 if (unlikely(!skb)) { 387 if (unlikely(!skb)) {
diff --git a/drivers/net/wireless/strip.c b/drivers/net/wireless/strip.c
index 38366a56b71f..73300c226f67 100644
--- a/drivers/net/wireless/strip.c
+++ b/drivers/net/wireless/strip.c
@@ -1582,7 +1582,7 @@ static int strip_xmit(struct sk_buff *skb, struct net_device *dev)
1582 1582
1583 if (skb) 1583 if (skb)
1584 dev_kfree_skb(skb); 1584 dev_kfree_skb(skb);
1585 return 0; 1585 return NETDEV_TX_OK;
1586} 1586}
1587 1587
1588/* 1588/*
diff --git a/drivers/net/wireless/wavelan.c b/drivers/net/wireless/wavelan.c
index ab7fc5c0c8b4..5cb5329a20d1 100644
--- a/drivers/net/wireless/wavelan.c
+++ b/drivers/net/wireless/wavelan.c
@@ -2891,7 +2891,7 @@ static int wavelan_packet_xmit(struct sk_buff *skb, struct net_device * dev)
2891#ifdef DEBUG_TX_TRACE 2891#ifdef DEBUG_TX_TRACE
2892 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name); 2892 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
2893#endif 2893#endif
2894 return 0; 2894 return NETDEV_TX_OK;
2895} 2895}
2896 2896
2897/*********************** HARDWARE CONFIGURATION ***********************/ 2897/*********************** HARDWARE CONFIGURATION ***********************/
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index 6af706408ac0..9dd241adc379 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -3113,7 +3113,7 @@ wavelan_packet_xmit(struct sk_buff * skb,
3113 * able to detect collisions, therefore in theory we don't really 3113 * able to detect collisions, therefore in theory we don't really
3114 * need to pad. Jean II */ 3114 * need to pad. Jean II */
3115 if (skb_padto(skb, ETH_ZLEN)) 3115 if (skb_padto(skb, ETH_ZLEN))
3116 return 0; 3116 return NETDEV_TX_OK;
3117 3117
3118 wv_packet_write(dev, skb->data, skb->len); 3118 wv_packet_write(dev, skb->data, skb->len);
3119 3119
@@ -3122,7 +3122,7 @@ wavelan_packet_xmit(struct sk_buff * skb,
3122#ifdef DEBUG_TX_TRACE 3122#ifdef DEBUG_TX_TRACE
3123 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name); 3123 printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
3124#endif 3124#endif
3125 return(0); 3125 return NETDEV_TX_OK;
3126} 3126}
3127 3127
3128/********************** HARDWARE CONFIGURATION **********************/ 3128/********************** HARDWARE CONFIGURATION **********************/
diff --git a/drivers/net/wireless/wl12xx/Kconfig b/drivers/net/wireless/wl12xx/Kconfig
index a82c4cd436d8..82a0f97975de 100644
--- a/drivers/net/wireless/wl12xx/Kconfig
+++ b/drivers/net/wireless/wl12xx/Kconfig
@@ -1,11 +1,18 @@
1config WL12XX 1menuconfig WL12XX
2 tristate "TI wl1251/wl1271 support" 2 boolean "TI wl12xx driver support"
3 depends on MAC80211 && WLAN_80211 && SPI_MASTER && GENERIC_HARDIRQS && EXPERIMENTAL 3 depends on MAC80211 && WLAN_80211 && EXPERIMENTAL
4 ---help---
5 This will enable TI wl12xx driver support. The drivers make
6 use of the mac80211 stack.
7
8config WL1251
9 tristate "TI wl1251 support"
10 depends on WL12XX && SPI_MASTER && GENERIC_HARDIRQS
4 select FW_LOADER 11 select FW_LOADER
5 select CRC7 12 select CRC7
6 ---help--- 13 ---help---
7 This module adds support for wireless adapters based on 14 This module adds support for wireless adapters based on
8 TI wl1251/wl1271 chipsets. 15 TI wl1251 chipset.
9 16
10 If you choose to build a module, it'll be called wl12xx. Say N if 17 If you choose to build a module, it'll be called wl1251. Say N if
11 unsure. 18 unsure.
diff --git a/drivers/net/wireless/wl12xx/Makefile b/drivers/net/wireless/wl12xx/Makefile
index d43de27dc54c..d5595a841f5f 100644
--- a/drivers/net/wireless/wl12xx/Makefile
+++ b/drivers/net/wireless/wl12xx/Makefile
@@ -1,4 +1,5 @@
1wl12xx-objs = main.o spi.o event.o tx.o rx.o \ 1wl1251-objs = wl1251_main.o wl1251_spi.o wl1251_event.o \
2 ps.o cmd.o acx.o boot.o init.o wl1251.o \ 2 wl1251_tx.o wl1251_rx.o wl1251_ps.o wl1251_cmd.o \
3 debugfs.o 3 wl1251_acx.o wl1251_boot.o wl1251_init.o \
4obj-$(CONFIG_WL12XX) += wl12xx.o 4 wl1251_ops.o wl1251_debugfs.o
5obj-$(CONFIG_WL1251) += wl1251.o
diff --git a/drivers/net/wireless/wl12xx/acx.c b/drivers/net/wireless/wl12xx/acx.c
deleted file mode 100644
index 1cfd458ad5ab..000000000000
--- a/drivers/net/wireless/wl12xx/acx.c
+++ /dev/null
@@ -1,689 +0,0 @@
1#include "acx.h"
2
3#include <linux/module.h>
4#include <linux/crc7.h>
5#include <linux/spi/spi.h>
6
7#include "wl12xx.h"
8#include "wl12xx_80211.h"
9#include "reg.h"
10#include "spi.h"
11#include "ps.h"
12
13int wl12xx_acx_frame_rates(struct wl12xx *wl, u8 ctrl_rate, u8 ctrl_mod,
14 u8 mgt_rate, u8 mgt_mod)
15{
16 int ret;
17 struct acx_fw_gen_frame_rates rates;
18
19 wl12xx_debug(DEBUG_ACX, "acx frame rates");
20
21 rates.header.id = ACX_FW_GEN_FRAME_RATES;
22 rates.header.len = sizeof(struct acx_fw_gen_frame_rates) -
23 sizeof(struct acx_header);
24
25 rates.tx_ctrl_frame_rate = ctrl_rate;
26 rates.tx_ctrl_frame_mod = ctrl_mod;
27 rates.tx_mgt_frame_rate = mgt_rate;
28 rates.tx_mgt_frame_mod = mgt_mod;
29
30 ret = wl12xx_cmd_configure(wl, &rates, sizeof(rates));
31 if (ret < 0) {
32 wl12xx_error("Failed to set FW rates and modulation");
33 return ret;
34 }
35
36 return 0;
37}
38
39
40int wl12xx_acx_station_id(struct wl12xx *wl)
41{
42 int ret, i;
43 struct dot11_station_id mac;
44
45 wl12xx_debug(DEBUG_ACX, "acx dot11_station_id");
46
47 mac.header.id = DOT11_STATION_ID;
48 mac.header.len = sizeof(mac) - sizeof(struct acx_header);
49
50 for (i = 0; i < ETH_ALEN; i++)
51 mac.mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
52
53 ret = wl12xx_cmd_configure(wl, &mac, sizeof(mac));
54 if (ret < 0)
55 return ret;
56
57 return 0;
58}
59
60int wl12xx_acx_default_key(struct wl12xx *wl, u8 key_id)
61{
62 struct acx_dot11_default_key default_key;
63 int ret;
64
65 wl12xx_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
66
67 default_key.header.id = DOT11_DEFAULT_KEY;
68 default_key.header.len = sizeof(default_key) -
69 sizeof(struct acx_header);
70
71 default_key.id = key_id;
72
73 ret = wl12xx_cmd_configure(wl, &default_key, sizeof(default_key));
74 if (ret < 0) {
75 wl12xx_error("Couldnt set default key");
76 return ret;
77 }
78
79 wl->default_key = key_id;
80
81 return 0;
82}
83
84int wl12xx_acx_wake_up_conditions(struct wl12xx *wl, u8 listen_interval)
85{
86 struct acx_wake_up_condition wake_up;
87
88 wl12xx_debug(DEBUG_ACX, "acx wake up conditions");
89
90 wake_up.header.id = ACX_WAKE_UP_CONDITIONS;
91 wake_up.header.len = sizeof(wake_up) - sizeof(struct acx_header);
92
93 wake_up.wake_up_event = WAKE_UP_EVENT_DTIM_BITMAP;
94 wake_up.listen_interval = listen_interval;
95
96 return wl12xx_cmd_configure(wl, &wake_up, sizeof(wake_up));
97}
98
99int wl12xx_acx_sleep_auth(struct wl12xx *wl, u8 sleep_auth)
100{
101 int ret;
102 struct acx_sleep_auth auth;
103
104 wl12xx_debug(DEBUG_ACX, "acx sleep auth");
105
106 auth.header.id = ACX_SLEEP_AUTH;
107 auth.header.len = sizeof(auth) - sizeof(struct acx_header);
108
109 auth.sleep_auth = sleep_auth;
110
111 ret = wl12xx_cmd_configure(wl, &auth, sizeof(auth));
112 if (ret < 0)
113 return ret;
114
115 return 0;
116}
117
118int wl12xx_acx_fw_version(struct wl12xx *wl, char *buf, size_t len)
119{
120 struct wl12xx_command cmd;
121 struct acx_revision *rev;
122 int ret;
123
124 wl12xx_debug(DEBUG_ACX, "acx fw rev");
125
126 memset(&cmd, 0, sizeof(cmd));
127
128 ret = wl12xx_cmd_interrogate(wl, ACX_FW_REV, sizeof(*rev), &cmd);
129 if (ret < 0) {
130 wl12xx_warning("ACX_FW_REV interrogate failed");
131 return ret;
132 }
133
134 rev = (struct acx_revision *) &cmd.parameters;
135
136 /* be careful with the buffer sizes */
137 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
138
139 /*
140 * if the firmware version string is exactly
141 * sizeof(rev->fw_version) long or fw_len is less than
142 * sizeof(rev->fw_version) it won't be null terminated
143 */
144 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
145
146 return 0;
147}
148
149int wl12xx_acx_tx_power(struct wl12xx *wl, int power)
150{
151 struct acx_current_tx_power ie;
152 int ret;
153
154 wl12xx_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
155
156 if (power < 0 || power > 25)
157 return -EINVAL;
158
159 memset(&ie, 0, sizeof(ie));
160
161 ie.header.id = DOT11_CUR_TX_PWR;
162 ie.header.len = sizeof(ie) - sizeof(struct acx_header);
163 ie.current_tx_power = power * 10;
164
165 ret = wl12xx_cmd_configure(wl, &ie, sizeof(ie));
166 if (ret < 0) {
167 wl12xx_warning("configure of tx power failed: %d", ret);
168 return ret;
169 }
170
171 return 0;
172}
173
174int wl12xx_acx_feature_cfg(struct wl12xx *wl)
175{
176 struct acx_feature_config feature;
177 int ret;
178
179 wl12xx_debug(DEBUG_ACX, "acx feature cfg");
180
181 memset(&feature, 0, sizeof(feature));
182
183 feature.header.id = ACX_FEATURE_CFG;
184 feature.header.len = sizeof(feature) - sizeof(struct acx_header);
185
186 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
187 feature.data_flow_options = 0;
188 feature.options = 0;
189
190 ret = wl12xx_cmd_configure(wl, &feature, sizeof(feature));
191 if (ret < 0)
192 wl12xx_error("Couldnt set HW encryption");
193
194 return ret;
195}
196
197int wl12xx_acx_mem_map(struct wl12xx *wl, void *mem_map, size_t len)
198{
199 struct wl12xx_command cmd;
200 int ret;
201
202 wl12xx_debug(DEBUG_ACX, "acx mem map");
203
204 ret = wl12xx_cmd_interrogate(wl, ACX_MEM_MAP, len, &cmd);
205 if (ret < 0)
206 return ret;
207 else if (cmd.status != CMD_STATUS_SUCCESS)
208 return -EIO;
209
210 memcpy(mem_map, &cmd.parameters, len);
211
212 return 0;
213}
214
215int wl12xx_acx_data_path_params(struct wl12xx *wl,
216 struct acx_data_path_params_resp *data_path)
217{
218 struct acx_data_path_params params;
219 struct wl12xx_command cmd;
220 int ret;
221
222 wl12xx_debug(DEBUG_ACX, "acx data path params");
223
224 params.rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
225 params.tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
226
227 params.rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
228 params.tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
229
230 params.tx_complete_threshold = 1;
231
232 params.tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
233
234 params.tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
235
236 params.header.id = ACX_DATA_PATH_PARAMS;
237 params.header.len = sizeof(params) - sizeof(struct acx_header);
238
239 ret = wl12xx_cmd_configure(wl, &params, sizeof(params));
240 if (ret < 0)
241 return ret;
242
243
244 ret = wl12xx_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
245 sizeof(struct acx_data_path_params_resp),
246 &cmd);
247
248 if (ret < 0) {
249 wl12xx_warning("failed to read data path parameters: %d", ret);
250 return ret;
251 } else if (cmd.status != CMD_STATUS_SUCCESS) {
252 wl12xx_warning("data path parameter acx status failed");
253 return -EIO;
254 }
255
256 memcpy(data_path, &cmd.parameters, sizeof(*data_path));
257
258 return 0;
259}
260
261int wl12xx_acx_rx_msdu_life_time(struct wl12xx *wl, u32 life_time)
262{
263 struct rx_msdu_lifetime msdu_lifetime;
264 int ret;
265
266 wl12xx_debug(DEBUG_ACX, "acx rx msdu life time");
267
268 msdu_lifetime.header.id = DOT11_RX_MSDU_LIFE_TIME;
269 msdu_lifetime.header.len = sizeof(msdu_lifetime) -
270 sizeof(struct acx_header);
271 msdu_lifetime.lifetime = life_time;
272
273 ret = wl12xx_cmd_configure(wl, &msdu_lifetime, sizeof(msdu_lifetime));
274 if (ret < 0) {
275 wl12xx_warning("failed to set rx msdu life time: %d", ret);
276 return ret;
277 }
278
279 return 0;
280}
281
282int wl12xx_acx_rx_config(struct wl12xx *wl, u32 config, u32 filter)
283{
284 struct acx_rx_config rx_config;
285 int ret;
286
287 wl12xx_debug(DEBUG_ACX, "acx rx config");
288
289 rx_config.header.id = ACX_RX_CFG;
290 rx_config.header.len = sizeof(rx_config) - sizeof(struct acx_header);
291 rx_config.config_options = config;
292 rx_config.filter_options = filter;
293
294 ret = wl12xx_cmd_configure(wl, &rx_config, sizeof(rx_config));
295 if (ret < 0) {
296 wl12xx_warning("failed to set rx config: %d", ret);
297 return ret;
298 }
299
300 return 0;
301}
302
303int wl12xx_acx_pd_threshold(struct wl12xx *wl)
304{
305 struct acx_packet_detection packet_detection;
306 int ret;
307
308 wl12xx_debug(DEBUG_ACX, "acx data pd threshold");
309
310 /* FIXME: threshold value not set */
311 packet_detection.header.id = ACX_PD_THRESHOLD;
312 packet_detection.header.len = sizeof(packet_detection) -
313 sizeof(struct acx_header);
314
315 ret = wl12xx_cmd_configure(wl, &packet_detection,
316 sizeof(packet_detection));
317 if (ret < 0) {
318 wl12xx_warning("failed to set pd threshold: %d", ret);
319 return ret;
320 }
321
322 return 0;
323}
324
325int wl12xx_acx_slot(struct wl12xx *wl, enum acx_slot_type slot_time)
326{
327 struct acx_slot slot;
328 int ret;
329
330 wl12xx_debug(DEBUG_ACX, "acx slot");
331
332 slot.header.id = ACX_SLOT;
333 slot.header.len = sizeof(slot) - sizeof(struct acx_header);
334
335 slot.wone_index = STATION_WONE_INDEX;
336 slot.slot_time = slot_time;
337
338 ret = wl12xx_cmd_configure(wl, &slot, sizeof(slot));
339 if (ret < 0) {
340 wl12xx_warning("failed to set slot time: %d", ret);
341 return ret;
342 }
343
344 return 0;
345}
346
347int wl12xx_acx_group_address_tbl(struct wl12xx *wl)
348{
349 struct multicast_grp_addr_start multicast;
350 int ret;
351
352 wl12xx_debug(DEBUG_ACX, "acx group address tbl");
353
354 /* MAC filtering */
355 multicast.header.id = DOT11_GROUP_ADDRESS_TBL;
356 multicast.header.len = sizeof(multicast) - sizeof(struct acx_header);
357
358 multicast.enabled = 0;
359 multicast.num_groups = 0;
360 memset(multicast.mac_table, 0, ADDRESS_GROUP_MAX_LEN);
361
362 ret = wl12xx_cmd_configure(wl, &multicast, sizeof(multicast));
363 if (ret < 0) {
364 wl12xx_warning("failed to set group addr table: %d", ret);
365 return ret;
366 }
367
368 return 0;
369}
370
371int wl12xx_acx_service_period_timeout(struct wl12xx *wl)
372{
373 struct acx_rx_timeout rx_timeout;
374 int ret;
375
376 wl12xx_debug(DEBUG_ACX, "acx service period timeout");
377
378 /* RX timeout */
379 rx_timeout.header.id = ACX_SERVICE_PERIOD_TIMEOUT;
380 rx_timeout.header.len = sizeof(rx_timeout) - sizeof(struct acx_header);
381
382 rx_timeout.ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
383 rx_timeout.upsd_timeout = RX_TIMEOUT_UPSD_DEF;
384
385 ret = wl12xx_cmd_configure(wl, &rx_timeout, sizeof(rx_timeout));
386 if (ret < 0) {
387 wl12xx_warning("failed to set service period timeout: %d",
388 ret);
389 return ret;
390 }
391
392 return 0;
393}
394
395int wl12xx_acx_rts_threshold(struct wl12xx *wl, u16 rts_threshold)
396{
397 struct acx_rts_threshold rts;
398 int ret;
399
400 wl12xx_debug(DEBUG_ACX, "acx rts threshold");
401
402 rts.header.id = DOT11_RTS_THRESHOLD;
403 rts.header.len = sizeof(rts) - sizeof(struct acx_header);
404
405 rts.threshold = rts_threshold;
406
407 ret = wl12xx_cmd_configure(wl, &rts, sizeof(rts));
408 if (ret < 0) {
409 wl12xx_warning("failed to set rts threshold: %d", ret);
410 return ret;
411 }
412
413 return 0;
414}
415
416int wl12xx_acx_beacon_filter_opt(struct wl12xx *wl)
417{
418 struct acx_beacon_filter_option beacon_filter;
419 int ret;
420
421 wl12xx_debug(DEBUG_ACX, "acx beacon filter opt");
422
423 beacon_filter.header.id = ACX_BEACON_FILTER_OPT;
424 beacon_filter.header.len = sizeof(beacon_filter) -
425 sizeof(struct acx_header);
426
427 beacon_filter.enable = 0;
428 beacon_filter.max_num_beacons = 0;
429
430 ret = wl12xx_cmd_configure(wl, &beacon_filter, sizeof(beacon_filter));
431 if (ret < 0) {
432 wl12xx_warning("failed to set beacon filter opt: %d", ret);
433 return ret;
434 }
435
436 return 0;
437}
438
439int wl12xx_acx_beacon_filter_table(struct wl12xx *wl)
440{
441 struct acx_beacon_filter_ie_table ie_table;
442 int ret;
443
444 wl12xx_debug(DEBUG_ACX, "acx beacon filter table");
445
446 ie_table.header.id = ACX_BEACON_FILTER_TABLE;
447 ie_table.header.len = sizeof(ie_table) - sizeof(struct acx_header);
448
449 ie_table.num_ie = 0;
450 memset(ie_table.table, 0, BEACON_FILTER_TABLE_MAX_SIZE);
451
452 ret = wl12xx_cmd_configure(wl, &ie_table, sizeof(ie_table));
453 if (ret < 0) {
454 wl12xx_warning("failed to set beacon filter table: %d", ret);
455 return ret;
456 }
457
458 return 0;
459}
460
461int wl12xx_acx_sg_enable(struct wl12xx *wl)
462{
463 struct acx_bt_wlan_coex pta;
464 int ret;
465
466 wl12xx_debug(DEBUG_ACX, "acx sg enable");
467
468 pta.header.id = ACX_SG_ENABLE;
469 pta.header.len = sizeof(pta) - sizeof(struct acx_header);
470
471 pta.enable = SG_ENABLE;
472
473 ret = wl12xx_cmd_configure(wl, &pta, sizeof(pta));
474 if (ret < 0) {
475 wl12xx_warning("failed to set softgemini enable: %d", ret);
476 return ret;
477 }
478
479 return 0;
480}
481
482int wl12xx_acx_sg_cfg(struct wl12xx *wl)
483{
484 struct acx_bt_wlan_coex_param param;
485 int ret;
486
487 wl12xx_debug(DEBUG_ACX, "acx sg cfg");
488
489 /* BT-WLAN coext parameters */
490 param.header.id = ACX_SG_CFG;
491 param.header.len = sizeof(param) - sizeof(struct acx_header);
492
493 param.min_rate = RATE_INDEX_24MBPS;
494 param.bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
495 param.wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
496 param.sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
497 param.rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
498 param.tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
499 param.rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
500 param.tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
501 param.wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
502 param.bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
503 param.next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
504 param.wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
505 param.hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
506 param.next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
507 param.antenna_type = PTA_ANTENNA_TYPE_DEF;
508 param.signal_type = PTA_SIGNALING_TYPE_DEF;
509 param.afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
510 param.quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
511 param.max_cts = PTA_MAX_NUM_CTS_DEF;
512 param.wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
513 param.bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
514 param.missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
515 param.wlan_elp_hp = PTA_ELP_HP_DEF;
516 param.bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
517 param.ack_mode_dual_ant = PTA_ACK_MODE_DEF;
518 param.pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
519 param.pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
520 param.bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
521
522 ret = wl12xx_cmd_configure(wl, &param, sizeof(param));
523 if (ret < 0) {
524 wl12xx_warning("failed to set sg config: %d", ret);
525 return ret;
526 }
527
528 return 0;
529}
530
531int wl12xx_acx_cca_threshold(struct wl12xx *wl)
532{
533 struct acx_energy_detection detection;
534 int ret;
535
536 wl12xx_debug(DEBUG_ACX, "acx cca threshold");
537
538 detection.header.id = ACX_CCA_THRESHOLD;
539 detection.header.len = sizeof(detection) - sizeof(struct acx_header);
540
541 detection.rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
542 detection.tx_energy_detection = 0;
543
544 ret = wl12xx_cmd_configure(wl, &detection, sizeof(detection));
545 if (ret < 0) {
546 wl12xx_warning("failed to set cca threshold: %d", ret);
547 return ret;
548 }
549
550 return 0;
551}
552
553int wl12xx_acx_bcn_dtim_options(struct wl12xx *wl)
554{
555 struct acx_beacon_broadcast bb;
556 int ret;
557
558 wl12xx_debug(DEBUG_ACX, "acx bcn dtim options");
559
560 bb.header.id = ACX_BCN_DTIM_OPTIONS;
561 bb.header.len = sizeof(bb) - sizeof(struct acx_header);
562
563 bb.beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
564 bb.broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
565 bb.rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
566 bb.ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
567
568 ret = wl12xx_cmd_configure(wl, &bb, sizeof(bb));
569 if (ret < 0) {
570 wl12xx_warning("failed to set rx config: %d", ret);
571 return ret;
572 }
573
574 return 0;
575}
576
577int wl12xx_acx_aid(struct wl12xx *wl, u16 aid)
578{
579 struct acx_aid acx_aid;
580 int ret;
581
582 wl12xx_debug(DEBUG_ACX, "acx aid");
583
584 acx_aid.header.id = ACX_AID;
585 acx_aid.header.len = sizeof(acx_aid) - sizeof(struct acx_header);
586
587 acx_aid.aid = aid;
588
589 ret = wl12xx_cmd_configure(wl, &acx_aid, sizeof(acx_aid));
590 if (ret < 0) {
591 wl12xx_warning("failed to set aid: %d", ret);
592 return ret;
593 }
594
595 return 0;
596}
597
598int wl12xx_acx_event_mbox_mask(struct wl12xx *wl, u32 event_mask)
599{
600 struct acx_event_mask mask;
601 int ret;
602
603 wl12xx_debug(DEBUG_ACX, "acx event mbox mask");
604
605 mask.header.id = ACX_EVENT_MBOX_MASK;
606 mask.header.len = sizeof(mask) - sizeof(struct acx_header);
607
608 /* high event mask is unused */
609 mask.high_event_mask = 0xffffffff;
610
611 mask.event_mask = event_mask;
612
613 ret = wl12xx_cmd_configure(wl, &mask, sizeof(mask));
614 if (ret < 0) {
615 wl12xx_warning("failed to set aid: %d", ret);
616 return ret;
617 }
618
619 return 0;
620}
621
622int wl12xx_acx_set_preamble(struct wl12xx *wl, enum acx_preamble_type preamble)
623{
624 struct acx_preamble ie;
625 int ret;
626
627 wl12xx_debug(DEBUG_ACX, "acx_set_preamble");
628
629 memset(&ie, 0, sizeof(ie));
630
631 ie.header.id = ACX_PREAMBLE_TYPE;
632 ie.header.len = sizeof(ie) - sizeof(struct acx_header);
633 ie.preamble = preamble;
634 ret = wl12xx_cmd_configure(wl, &ie, sizeof(ie));
635 if (ret < 0) {
636 wl12xx_warning("Setting of preamble failed: %d", ret);
637 return ret;
638 }
639 return 0;
640}
641
642int wl12xx_acx_cts_protect(struct wl12xx *wl,
643 enum acx_ctsprotect_type ctsprotect)
644{
645 struct acx_ctsprotect ie;
646 int ret;
647
648 wl12xx_debug(DEBUG_ACX, "acx_set_ctsprotect");
649
650 memset(&ie, 0, sizeof(ie));
651
652 ie.header.id = ACX_CTS_PROTECTION;
653 ie.header.len = sizeof(ie) - sizeof(struct acx_header);
654 ie.ctsprotect = ctsprotect;
655 ret = wl12xx_cmd_configure(wl, &ie, sizeof(ie));
656 if (ret < 0) {
657 wl12xx_warning("Setting of ctsprotect failed: %d", ret);
658 return ret;
659 }
660 return 0;
661}
662
663int wl12xx_acx_statistics(struct wl12xx *wl, struct acx_statistics *stats)
664{
665 struct wl12xx_command *answer;
666 int ret;
667
668 wl12xx_debug(DEBUG_ACX, "acx statistics");
669
670 answer = kmalloc(sizeof(*answer), GFP_KERNEL);
671 if (!answer) {
672 wl12xx_warning("could not allocate memory for acx statistics");
673 ret = -ENOMEM;
674 goto out;
675 }
676
677 ret = wl12xx_cmd_interrogate(wl, ACX_STATISTICS, sizeof(*answer),
678 answer);
679 if (ret < 0) {
680 wl12xx_warning("acx statistics failed: %d", ret);
681 goto out;
682 }
683
684 memcpy(stats, answer->parameters, sizeof(*stats));
685
686out:
687 kfree(answer);
688 return ret;
689}
diff --git a/drivers/net/wireless/wl12xx/cmd.c b/drivers/net/wireless/wl12xx/cmd.c
deleted file mode 100644
index f73ab602b7ae..000000000000
--- a/drivers/net/wireless/wl12xx/cmd.c
+++ /dev/null
@@ -1,353 +0,0 @@
1#include "cmd.h"
2
3#include <linux/module.h>
4#include <linux/crc7.h>
5#include <linux/spi/spi.h>
6
7#include "wl12xx.h"
8#include "wl12xx_80211.h"
9#include "reg.h"
10#include "spi.h"
11#include "ps.h"
12
13int wl12xx_cmd_send(struct wl12xx *wl, u16 type, void *buf, size_t buf_len)
14{
15 struct wl12xx_command cmd;
16 unsigned long timeout;
17 size_t cmd_len;
18 u32 intr;
19 int ret = 0;
20
21 memset(&cmd, 0, sizeof(cmd));
22 cmd.id = type;
23 cmd.status = 0;
24 memcpy(cmd.parameters, buf, buf_len);
25 cmd_len = ALIGN(buf_len, 4) + CMDMBOX_HEADER_LEN;
26
27 wl12xx_ps_elp_wakeup(wl);
28
29 wl12xx_spi_mem_write(wl, wl->cmd_box_addr, &cmd, cmd_len);
30
31 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
32
33 timeout = jiffies + msecs_to_jiffies(WL12XX_COMMAND_TIMEOUT);
34
35 intr = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
36 while (!(intr & wl->chip.intr_cmd_complete)) {
37 if (time_after(jiffies, timeout)) {
38 wl12xx_error("command complete timeout");
39 ret = -ETIMEDOUT;
40 goto out;
41 }
42
43 msleep(1);
44
45 intr = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
46 }
47
48 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
49 wl->chip.intr_cmd_complete);
50
51out:
52 wl12xx_ps_elp_sleep(wl);
53
54 return ret;
55}
56
57int wl12xx_cmd_test(struct wl12xx *wl, void *buf, size_t buf_len, u8 answer)
58{
59 int ret;
60
61 wl12xx_debug(DEBUG_CMD, "cmd test");
62
63 ret = wl12xx_cmd_send(wl, CMD_TEST, buf, buf_len);
64 if (ret < 0) {
65 wl12xx_warning("TEST command failed");
66 return ret;
67 }
68
69 if (answer) {
70 struct wl12xx_command *cmd_answer;
71
72 /*
73 * The test command got in, we can read the answer.
74 * The answer would be a wl12xx_command, where the
75 * parameter array contains the actual answer.
76 */
77
78 wl12xx_ps_elp_wakeup(wl);
79
80 wl12xx_spi_mem_read(wl, wl->cmd_box_addr, buf, buf_len);
81
82 wl12xx_ps_elp_sleep(wl);
83
84 cmd_answer = buf;
85 if (cmd_answer->status != CMD_STATUS_SUCCESS)
86 wl12xx_error("TEST command answer error: %d",
87 cmd_answer->status);
88 }
89
90 return 0;
91}
92
93
94int wl12xx_cmd_interrogate(struct wl12xx *wl, u16 ie_id, u16 ie_len,
95 void *answer)
96{
97 struct wl12xx_command *cmd;
98 struct acx_header header;
99 int ret;
100
101 wl12xx_debug(DEBUG_CMD, "cmd interrogate");
102
103 header.id = ie_id;
104 header.len = ie_len - sizeof(header);
105
106 ret = wl12xx_cmd_send(wl, CMD_INTERROGATE, &header, sizeof(header));
107 if (ret < 0) {
108 wl12xx_error("INTERROGATE command failed");
109 return ret;
110 }
111
112 wl12xx_ps_elp_wakeup(wl);
113
114 /* the interrogate command got in, we can read the answer */
115 wl12xx_spi_mem_read(wl, wl->cmd_box_addr, answer,
116 CMDMBOX_HEADER_LEN + ie_len);
117
118 wl12xx_ps_elp_sleep(wl);
119
120 cmd = answer;
121 if (cmd->status != CMD_STATUS_SUCCESS)
122 wl12xx_error("INTERROGATE command error: %d",
123 cmd->status);
124
125 return 0;
126
127}
128
129int wl12xx_cmd_configure(struct wl12xx *wl, void *ie, int ie_len)
130{
131 int ret;
132
133 wl12xx_debug(DEBUG_CMD, "cmd configure");
134
135 ret = wl12xx_cmd_send(wl, CMD_CONFIGURE, ie,
136 ie_len);
137 if (ret < 0) {
138 wl12xx_warning("CONFIGURE command NOK");
139 return ret;
140 }
141
142 return 0;
143
144}
145
146int wl12xx_cmd_vbm(struct wl12xx *wl, u8 identity,
147 void *bitmap, u16 bitmap_len, u8 bitmap_control)
148{
149 struct vbm_update_request vbm;
150 int ret;
151
152 wl12xx_debug(DEBUG_CMD, "cmd vbm");
153
154 /* Count and period will be filled by the target */
155 vbm.tim.bitmap_ctrl = bitmap_control;
156 if (bitmap_len > PARTIAL_VBM_MAX) {
157 wl12xx_warning("cmd vbm len is %d B, truncating to %d",
158 bitmap_len, PARTIAL_VBM_MAX);
159 bitmap_len = PARTIAL_VBM_MAX;
160 }
161 memcpy(vbm.tim.pvb_field, bitmap, bitmap_len);
162 vbm.tim.identity = identity;
163 vbm.tim.length = bitmap_len + 3;
164
165 vbm.len = cpu_to_le16(bitmap_len + 5);
166
167 ret = wl12xx_cmd_send(wl, CMD_VBM, &vbm, sizeof(vbm));
168 if (ret < 0) {
169 wl12xx_error("VBM command failed");
170 return ret;
171 }
172
173 return 0;
174}
175
176int wl12xx_cmd_data_path(struct wl12xx *wl, u8 channel, u8 enable)
177{
178 int ret;
179 u16 cmd_rx, cmd_tx;
180
181 wl12xx_debug(DEBUG_CMD, "cmd data path");
182
183 if (enable) {
184 cmd_rx = CMD_ENABLE_RX;
185 cmd_tx = CMD_ENABLE_TX;
186 } else {
187 cmd_rx = CMD_DISABLE_RX;
188 cmd_tx = CMD_DISABLE_TX;
189 }
190
191 ret = wl12xx_cmd_send(wl, cmd_rx, &channel, sizeof(channel));
192 if (ret < 0) {
193 wl12xx_error("rx %s cmd for channel %d failed",
194 enable ? "start" : "stop", channel);
195 return ret;
196 }
197
198 wl12xx_debug(DEBUG_BOOT, "rx %s cmd channel %d",
199 enable ? "start" : "stop", channel);
200
201 ret = wl12xx_cmd_send(wl, cmd_tx, &channel, sizeof(channel));
202 if (ret < 0) {
203 wl12xx_error("tx %s cmd for channel %d failed",
204 enable ? "start" : "stop", channel);
205 return ret;
206 }
207
208 wl12xx_debug(DEBUG_BOOT, "tx %s cmd channel %d",
209 enable ? "start" : "stop", channel);
210
211 return 0;
212}
213
214int wl12xx_cmd_join(struct wl12xx *wl, u8 bss_type, u8 dtim_interval,
215 u16 beacon_interval, u8 wait)
216{
217 unsigned long timeout;
218 struct cmd_join join = {};
219 int ret, i;
220 u8 *bssid;
221
222 /* FIXME: this should be in main.c */
223 ret = wl12xx_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE,
224 DEFAULT_HW_GEN_MODULATION_TYPE,
225 wl->tx_mgmt_frm_rate,
226 wl->tx_mgmt_frm_mod);
227 if (ret < 0)
228 return ret;
229
230 wl12xx_debug(DEBUG_CMD, "cmd join");
231
232 /* Reverse order BSSID */
233 bssid = (u8 *)&join.bssid_lsb;
234 for (i = 0; i < ETH_ALEN; i++)
235 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
236
237 join.rx_config_options = wl->rx_config;
238 join.rx_filter_options = wl->rx_filter;
239
240 join.basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS |
241 RATE_MASK_5_5MBPS | RATE_MASK_11MBPS;
242
243 join.beacon_interval = beacon_interval;
244 join.dtim_interval = dtim_interval;
245 join.bss_type = bss_type;
246 join.channel = wl->channel;
247 join.ctrl = JOIN_CMD_CTRL_TX_FLUSH;
248
249 ret = wl12xx_cmd_send(wl, CMD_START_JOIN, &join, sizeof(join));
250 if (ret < 0) {
251 wl12xx_error("failed to initiate cmd join");
252 return ret;
253 }
254
255 timeout = msecs_to_jiffies(JOIN_TIMEOUT);
256
257 /*
258 * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to
259 * simplify locking we just sleep instead, for now
260 */
261 if (wait)
262 msleep(10);
263
264 return 0;
265}
266
267int wl12xx_cmd_ps_mode(struct wl12xx *wl, u8 ps_mode)
268{
269 int ret;
270 struct acx_ps_params ps_params;
271
272 /* FIXME: this should be in ps.c */
273 ret = wl12xx_acx_wake_up_conditions(wl, wl->listen_int);
274 if (ret < 0) {
275 wl12xx_error("Couldnt set wake up conditions");
276 return ret;
277 }
278
279 wl12xx_debug(DEBUG_CMD, "cmd set ps mode");
280
281 ps_params.ps_mode = ps_mode;
282 ps_params.send_null_data = 1;
283 ps_params.retries = 5;
284 ps_params.hang_over_period = 128;
285 ps_params.null_data_rate = 1; /* 1 Mbps */
286
287 ret = wl12xx_cmd_send(wl, CMD_SET_PS_MODE, &ps_params,
288 sizeof(ps_params));
289 if (ret < 0) {
290 wl12xx_error("cmd set_ps_mode failed");
291 return ret;
292 }
293
294 return 0;
295}
296
297int wl12xx_cmd_read_memory(struct wl12xx *wl, u32 addr, u32 len, void *answer)
298{
299 struct cmd_read_write_memory mem_cmd, *mem_answer;
300 struct wl12xx_command cmd;
301 int ret;
302
303 wl12xx_debug(DEBUG_CMD, "cmd read memory");
304
305 memset(&mem_cmd, 0, sizeof(mem_cmd));
306 mem_cmd.addr = addr;
307 mem_cmd.size = len;
308
309 ret = wl12xx_cmd_send(wl, CMD_READ_MEMORY, &mem_cmd, sizeof(mem_cmd));
310 if (ret < 0) {
311 wl12xx_error("read memory command failed: %d", ret);
312 return ret;
313 }
314
315 /* the read command got in, we can now read the answer */
316 wl12xx_spi_mem_read(wl, wl->cmd_box_addr, &cmd,
317 CMDMBOX_HEADER_LEN + sizeof(mem_cmd));
318
319 if (cmd.status != CMD_STATUS_SUCCESS)
320 wl12xx_error("error in read command result: %d", cmd.status);
321
322 mem_answer = (struct cmd_read_write_memory *) cmd.parameters;
323 memcpy(answer, mem_answer->value, len);
324
325 return 0;
326}
327
328int wl12xx_cmd_template_set(struct wl12xx *wl, u16 cmd_id,
329 void *buf, size_t buf_len)
330{
331 struct wl12xx_cmd_packet_template template;
332 int ret;
333
334 wl12xx_debug(DEBUG_CMD, "cmd template %d", cmd_id);
335
336 memset(&template, 0, sizeof(template));
337
338 WARN_ON(buf_len > WL12XX_MAX_TEMPLATE_SIZE);
339 buf_len = min_t(size_t, buf_len, WL12XX_MAX_TEMPLATE_SIZE);
340 template.size = cpu_to_le16(buf_len);
341
342 if (buf)
343 memcpy(template.template, buf, buf_len);
344
345 ret = wl12xx_cmd_send(wl, cmd_id, &template,
346 sizeof(template.size) + buf_len);
347 if (ret < 0) {
348 wl12xx_warning("cmd set_template failed: %d", ret);
349 return ret;
350 }
351
352 return 0;
353}
diff --git a/drivers/net/wireless/wl12xx/reg.h b/drivers/net/wireless/wl12xx/reg.h
index e421643215cd..2de47cc32b8b 100644
--- a/drivers/net/wireless/wl12xx/reg.h
+++ b/drivers/net/wireless/wl12xx/reg.h
@@ -26,7 +26,6 @@
26#define __REG_H__ 26#define __REG_H__
27 27
28#include <linux/bitops.h> 28#include <linux/bitops.h>
29#include "wl12xx.h"
30 29
31#define REGISTERS_BASE 0x00300000 30#define REGISTERS_BASE 0x00300000
32#define DRPW_BASE 0x00310000 31#define DRPW_BASE 0x00310000
diff --git a/drivers/net/wireless/wl12xx/wl1251.h b/drivers/net/wireless/wl12xx/wl1251.h
index 1f4a44330394..665aca02bea9 100644
--- a/drivers/net/wireless/wl12xx/wl1251.h
+++ b/drivers/net/wireless/wl12xx/wl1251.h
@@ -1,7 +1,8 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008-2009 Nokia Corporation
5 * 6 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com> 7 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 * 8 *
@@ -24,142 +25,396 @@
24#ifndef __WL1251_H__ 25#ifndef __WL1251_H__
25#define __WL1251_H__ 26#define __WL1251_H__
26 27
28#include <linux/mutex.h>
29#include <linux/list.h>
27#include <linux/bitops.h> 30#include <linux/bitops.h>
28 31#include <net/mac80211.h>
29#include "wl12xx.h" 32
30#include "acx.h" 33#define DRIVER_NAME "wl1251"
31 34#define DRIVER_PREFIX DRIVER_NAME ": "
32#define WL1251_FW_NAME "wl1251-fw.bin" 35
33#define WL1251_NVS_NAME "wl1251-nvs.bin" 36enum {
34 37 DEBUG_NONE = 0,
35#define WL1251_POWER_ON_SLEEP 10 /* in miliseconds */ 38 DEBUG_IRQ = BIT(0),
36 39 DEBUG_SPI = BIT(1),
37void wl1251_setup(struct wl12xx *wl); 40 DEBUG_BOOT = BIT(2),
38 41 DEBUG_MAILBOX = BIT(3),
39 42 DEBUG_NETLINK = BIT(4),
40struct wl1251_acx_memory { 43 DEBUG_EVENT = BIT(5),
41 __le16 num_stations; /* number of STAs to be supported. */ 44 DEBUG_TX = BIT(6),
42 u16 reserved_1; 45 DEBUG_RX = BIT(7),
46 DEBUG_SCAN = BIT(8),
47 DEBUG_CRYPT = BIT(9),
48 DEBUG_PSM = BIT(10),
49 DEBUG_MAC80211 = BIT(11),
50 DEBUG_CMD = BIT(12),
51 DEBUG_ACX = BIT(13),
52 DEBUG_ALL = ~0,
53};
54
55#define DEBUG_LEVEL (DEBUG_NONE)
56
57#define DEBUG_DUMP_LIMIT 1024
58
59#define wl1251_error(fmt, arg...) \
60 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
61
62#define wl1251_warning(fmt, arg...) \
63 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
64
65#define wl1251_notice(fmt, arg...) \
66 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
67
68#define wl1251_info(fmt, arg...) \
69 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
70
71#define wl1251_debug(level, fmt, arg...) \
72 do { \
73 if (level & DEBUG_LEVEL) \
74 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
75 } while (0)
76
77#define wl1251_dump(level, prefix, buf, len) \
78 do { \
79 if (level & DEBUG_LEVEL) \
80 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
81 DUMP_PREFIX_OFFSET, 16, 1, \
82 buf, \
83 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
84 0); \
85 } while (0)
86
87#define wl1251_dump_ascii(level, prefix, buf, len) \
88 do { \
89 if (level & DEBUG_LEVEL) \
90 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
91 DUMP_PREFIX_OFFSET, 16, 1, \
92 buf, \
93 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
94 true); \
95 } while (0)
96
97#define WL1251_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
98 CFG_BSSID_FILTER_EN)
99
100#define WL1251_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN | \
101 CFG_RX_MGMT_EN | \
102 CFG_RX_DATA_EN | \
103 CFG_RX_CTL_EN | \
104 CFG_RX_BCN_EN | \
105 CFG_RX_AUTH_EN | \
106 CFG_RX_ASSOC_EN)
107
108#define WL1251_BUSY_WORD_LEN 8
109
110struct boot_attr {
111 u32 radio_type;
112 u8 mac_clock;
113 u8 arm_clock;
114 int firmware_debug;
115 u32 minor;
116 u32 major;
117 u32 bugfix;
118};
119
120enum wl1251_state {
121 WL1251_STATE_OFF,
122 WL1251_STATE_ON,
123 WL1251_STATE_PLT,
124};
125
126enum wl1251_partition_type {
127 PART_DOWN,
128 PART_WORK,
129 PART_DRPW,
130
131 PART_TABLE_LEN
132};
133
134struct wl1251_partition {
135 u32 size;
136 u32 start;
137};
138
139struct wl1251_partition_set {
140 struct wl1251_partition mem;
141 struct wl1251_partition reg;
142};
143
144struct wl1251;
145
146/* FIXME: I'm not sure about this structure name */
147struct wl1251_chip {
148 u32 id;
149
150 const char *fw_filename;
151 const char *nvs_filename;
152
153 char fw_ver[21];
154
155 unsigned int power_on_sleep;
156 int intr_cmd_complete;
157 int intr_init_complete;
158
159 int (*op_upload_fw)(struct wl1251 *wl);
160 int (*op_upload_nvs)(struct wl1251 *wl);
161 int (*op_boot)(struct wl1251 *wl);
162 void (*op_set_ecpu_ctrl)(struct wl1251 *wl, u32 flag);
163 void (*op_target_enable_interrupts)(struct wl1251 *wl);
164 int (*op_hw_init)(struct wl1251 *wl);
165 int (*op_plt_init)(struct wl1251 *wl);
166 void (*op_tx_flush)(struct wl1251 *wl);
167 void (*op_fw_version)(struct wl1251 *wl);
168 int (*op_cmd_join)(struct wl1251 *wl, u8 bss_type, u8 dtim_interval,
169 u16 beacon_interval, u8 wait);
170
171 struct wl1251_partition_set *p_table;
172 enum wl12xx_acx_int_reg *acx_reg_table;
173};
174
175struct wl1251_stats {
176 struct acx_statistics *fw_stats;
177 unsigned long fw_stats_update;
178
179 unsigned int retry_count;
180 unsigned int excessive_retries;
181};
182
183struct wl1251_debugfs {
184 struct dentry *rootdir;
185 struct dentry *fw_statistics;
186
187 struct dentry *tx_internal_desc_overflow;
188
189 struct dentry *rx_out_of_mem;
190 struct dentry *rx_hdr_overflow;
191 struct dentry *rx_hw_stuck;
192 struct dentry *rx_dropped;
193 struct dentry *rx_fcs_err;
194 struct dentry *rx_xfr_hint_trig;
195 struct dentry *rx_path_reset;
196 struct dentry *rx_reset_counter;
197
198 struct dentry *dma_rx_requested;
199 struct dentry *dma_rx_errors;
200 struct dentry *dma_tx_requested;
201 struct dentry *dma_tx_errors;
202
203 struct dentry *isr_cmd_cmplt;
204 struct dentry *isr_fiqs;
205 struct dentry *isr_rx_headers;
206 struct dentry *isr_rx_mem_overflow;
207 struct dentry *isr_rx_rdys;
208 struct dentry *isr_irqs;
209 struct dentry *isr_tx_procs;
210 struct dentry *isr_decrypt_done;
211 struct dentry *isr_dma0_done;
212 struct dentry *isr_dma1_done;
213 struct dentry *isr_tx_exch_complete;
214 struct dentry *isr_commands;
215 struct dentry *isr_rx_procs;
216 struct dentry *isr_hw_pm_mode_changes;
217 struct dentry *isr_host_acknowledges;
218 struct dentry *isr_pci_pm;
219 struct dentry *isr_wakeups;
220 struct dentry *isr_low_rssi;
221
222 struct dentry *wep_addr_key_count;
223 struct dentry *wep_default_key_count;
224 /* skipping wep.reserved */
225 struct dentry *wep_key_not_found;
226 struct dentry *wep_decrypt_fail;
227 struct dentry *wep_packets;
228 struct dentry *wep_interrupt;
229
230 struct dentry *pwr_ps_enter;
231 struct dentry *pwr_elp_enter;
232 struct dentry *pwr_missing_bcns;
233 struct dentry *pwr_wake_on_host;
234 struct dentry *pwr_wake_on_timer_exp;
235 struct dentry *pwr_tx_with_ps;
236 struct dentry *pwr_tx_without_ps;
237 struct dentry *pwr_rcvd_beacons;
238 struct dentry *pwr_power_save_off;
239 struct dentry *pwr_enable_ps;
240 struct dentry *pwr_disable_ps;
241 struct dentry *pwr_fix_tsf_ps;
242 /* skipping cont_miss_bcns_spread for now */
243 struct dentry *pwr_rcvd_awake_beacons;
244
245 struct dentry *mic_rx_pkts;
246 struct dentry *mic_calc_failure;
247
248 struct dentry *aes_encrypt_fail;
249 struct dentry *aes_decrypt_fail;
250 struct dentry *aes_encrypt_packets;
251 struct dentry *aes_decrypt_packets;
252 struct dentry *aes_encrypt_interrupt;
253 struct dentry *aes_decrypt_interrupt;
254
255 struct dentry *event_heart_beat;
256 struct dentry *event_calibration;
257 struct dentry *event_rx_mismatch;
258 struct dentry *event_rx_mem_empty;
259 struct dentry *event_rx_pool;
260 struct dentry *event_oom_late;
261 struct dentry *event_phy_transmit_error;
262 struct dentry *event_tx_stuck;
263
264 struct dentry *ps_pspoll_timeouts;
265 struct dentry *ps_upsd_timeouts;
266 struct dentry *ps_upsd_max_sptime;
267 struct dentry *ps_upsd_max_apturn;
268 struct dentry *ps_pspoll_max_apturn;
269 struct dentry *ps_pspoll_utilization;
270 struct dentry *ps_upsd_utilization;
271
272 struct dentry *rxpipe_rx_prep_beacon_drop;
273 struct dentry *rxpipe_descr_host_int_trig_rx_data;
274 struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
275 struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
276 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
277
278 struct dentry *tx_queue_len;
279
280 struct dentry *retry_count;
281 struct dentry *excessive_retries;
282};
283
284struct wl1251 {
285 struct ieee80211_hw *hw;
286 bool mac80211_registered;
287
288 struct spi_device *spi;
289
290 void (*set_power)(bool enable);
291 int irq;
292
293 enum wl1251_state state;
294 struct mutex mutex;
295
296 int physical_mem_addr;
297 int physical_reg_addr;
298 int virtual_mem_addr;
299 int virtual_reg_addr;
300
301 struct wl1251_chip chip;
302
303 int cmd_box_addr;
304 int event_box_addr;
305 struct boot_attr boot_attr;
306
307 u8 *fw;
308 size_t fw_len;
309 u8 *nvs;
310 size_t nvs_len;
311
312 u8 bssid[ETH_ALEN];
313 u8 mac_addr[ETH_ALEN];
314 u8 bss_type;
315 u8 listen_int;
316 int channel;
317
318 void *target_mem_map;
319 struct acx_data_path_params_resp *data_path;
320
321 /* Number of TX packets transferred to the FW, modulo 16 */
322 u32 data_in_count;
323
324 /* Frames scheduled for transmission, not handled yet */
325 struct sk_buff_head tx_queue;
326 bool tx_queue_stopped;
327
328 struct work_struct tx_work;
329 struct work_struct filter_work;
330
331 /* Pending TX frames */
332 struct sk_buff *tx_frames[16];
43 333
44 /* 334 /*
45 * Nmber of memory buffers for the RX mem pool. 335 * Index pointing to the next TX complete entry
46 * The actual number may be less if there are 336 * in the cyclic XT complete array we get from
47 * not enough blocks left for the minimum num 337 * the FW.
48 * of TX ones.
49 */ 338 */
50 u8 rx_mem_block_num; 339 u32 next_tx_complete;
51 u8 reserved_2;
52 u8 num_tx_queues; /* From 1 to 16 */
53 u8 host_if_options; /* HOST_IF* */
54 u8 tx_min_mem_block_num;
55 u8 num_ssid_profiles;
56 __le16 debug_buffer_size;
57} __attribute__ ((packed));
58
59
60#define ACX_RX_DESC_MIN 1
61#define ACX_RX_DESC_MAX 127
62#define ACX_RX_DESC_DEF 32
63struct wl1251_acx_rx_queue_config {
64 u8 num_descs;
65 u8 pad;
66 u8 type;
67 u8 priority;
68 __le32 dma_address;
69} __attribute__ ((packed));
70
71#define ACX_TX_DESC_MIN 1
72#define ACX_TX_DESC_MAX 127
73#define ACX_TX_DESC_DEF 16
74struct wl1251_acx_tx_queue_config {
75 u8 num_descs;
76 u8 pad[2];
77 u8 attributes;
78} __attribute__ ((packed));
79
80#define MAX_TX_QUEUE_CONFIGS 5
81#define MAX_TX_QUEUES 4
82struct wl1251_acx_config_memory {
83 struct acx_header header;
84
85 struct wl1251_acx_memory mem_config;
86 struct wl1251_acx_rx_queue_config rx_queue_config;
87 struct wl1251_acx_tx_queue_config tx_queue_config[MAX_TX_QUEUE_CONFIGS];
88} __attribute__ ((packed));
89
90struct wl1251_acx_mem_map {
91 struct acx_header header;
92
93 void *code_start;
94 void *code_end;
95
96 void *wep_defkey_start;
97 void *wep_defkey_end;
98 340
99 void *sta_table_start; 341 /* FW Rx counter */
100 void *sta_table_end; 342 u32 rx_counter;
101 343
102 void *packet_template_start; 344 /* Rx frames handled */
103 void *packet_template_end; 345 u32 rx_handled;
104 346
105 void *queue_memory_start; 347 /* Current double buffer */
106 void *queue_memory_end; 348 u32 rx_current_buffer;
349 u32 rx_last_id;
107 350
108 void *packet_memory_pool_start; 351 /* The target interrupt mask */
109 void *packet_memory_pool_end; 352 u32 intr_mask;
353 struct work_struct irq_work;
110 354
111 void *debug_buffer1_start; 355 /* The mbox event mask */
112 void *debug_buffer1_end; 356 u32 event_mask;
113 357
114 void *debug_buffer2_start; 358 /* Mailbox pointers */
115 void *debug_buffer2_end; 359 u32 mbox_ptr[2];
116 360
117 /* Number of blocks FW allocated for TX packets */ 361 /* Are we currently scanning */
118 u32 num_tx_mem_blocks; 362 bool scanning;
119 363
120 /* Number of blocks FW allocated for RX packets */ 364 /* Our association ID */
121 u32 num_rx_mem_blocks; 365 u16 aid;
122} __attribute__ ((packed));
123 366
124/************************************************************************* 367 /* Default key (for WEP) */
368 u32 default_key;
125 369
126 Host Interrupt Register (WiLink -> Host) 370 unsigned int tx_mgmt_frm_rate;
371 unsigned int tx_mgmt_frm_mod;
127 372
128**************************************************************************/ 373 unsigned int rx_config;
374 unsigned int rx_filter;
129 375
130/* RX packet is ready in Xfer buffer #0 */ 376 /* is firmware in elp mode */
131#define WL1251_ACX_INTR_RX0_DATA BIT(0) 377 bool elp;
132 378
133/* TX result(s) are in the TX complete buffer */ 379 /* we can be in psm, but not in elp, we have to differentiate */
134#define WL1251_ACX_INTR_TX_RESULT BIT(1) 380 bool psm;
135 381
136/* OBSOLETE */ 382 /* PSM mode requested */
137#define WL1251_ACX_INTR_TX_XFR BIT(2) 383 bool psm_requested;
138 384
139/* RX packet is ready in Xfer buffer #1 */ 385 /* in dBm */
140#define WL1251_ACX_INTR_RX1_DATA BIT(3) 386 int power_level;
141 387
142/* Event was entered to Event MBOX #A */ 388 struct wl1251_stats stats;
143#define WL1251_ACX_INTR_EVENT_A BIT(4) 389 struct wl1251_debugfs debugfs;
144 390
145/* Event was entered to Event MBOX #B */ 391 u32 buffer_32;
146#define WL1251_ACX_INTR_EVENT_B BIT(5) 392 u32 buffer_cmd;
393 u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
394 struct wl1251_rx_descriptor *rx_descriptor;
395};
147 396
148/* OBSOLETE */ 397int wl1251_plt_start(struct wl1251 *wl);
149#define WL1251_ACX_INTR_WAKE_ON_HOST BIT(6) 398int wl1251_plt_stop(struct wl1251 *wl);
150 399
151/* Trace meassge on MBOX #A */ 400#define DEFAULT_HW_GEN_MODULATION_TYPE CCK_LONG /* Long Preamble */
152#define WL1251_ACX_INTR_TRACE_A BIT(7) 401#define DEFAULT_HW_GEN_TX_RATE RATE_2MBPS
402#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
153 403
154/* Trace meassge on MBOX #B */ 404#define WL1251_DEFAULT_POWER_LEVEL 20
155#define WL1251_ACX_INTR_TRACE_B BIT(8)
156 405
157/* Command processing completion */ 406#define WL1251_TX_QUEUE_MAX_LENGTH 20
158#define WL1251_ACX_INTR_CMD_COMPLETE BIT(9)
159 407
160/* Init sequence is done */ 408/* Different chips need different sleep times after power on. WL1271 needs
161#define WL1251_ACX_INTR_INIT_COMPLETE BIT(14) 409 * 200ms, WL1251 needs only 10ms. By default we use 200ms, but as soon as we
410 * know the chip ID, we change the sleep value in the wl1251 chip structure,
411 * so in subsequent power ons, we don't waste more time then needed. */
412#define WL1251_DEFAULT_POWER_ON_SLEEP 200
162 413
163#define WL1251_ACX_INTR_ALL 0xFFFFFFFF 414#define CHIP_ID_1251_PG10 (0x7010101)
415#define CHIP_ID_1251_PG11 (0x7020101)
416#define CHIP_ID_1251_PG12 (0x7030101)
417#define CHIP_ID_1271_PG10 (0x4030101)
418#define CHIP_ID_1271_PG20 (0x4030111)
164 419
165#endif 420#endif
diff --git a/drivers/net/wireless/wl12xx/wl1251_acx.c b/drivers/net/wireless/wl12xx/wl1251_acx.c
new file mode 100644
index 000000000000..5a8d21c3192d
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1251_acx.c
@@ -0,0 +1,840 @@
1#include "wl1251_acx.h"
2
3#include <linux/module.h>
4#include <linux/crc7.h>
5#include <linux/spi/spi.h>
6
7#include "wl1251.h"
8#include "reg.h"
9#include "wl1251_spi.h"
10#include "wl1251_ps.h"
11
12int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
13 u8 mgt_rate, u8 mgt_mod)
14{
15 struct acx_fw_gen_frame_rates *rates;
16 int ret;
17
18 wl1251_debug(DEBUG_ACX, "acx frame rates");
19
20 rates = kzalloc(sizeof(*rates), GFP_KERNEL);
21 if (!rates) {
22 ret = -ENOMEM;
23 goto out;
24 }
25
26 rates->tx_ctrl_frame_rate = ctrl_rate;
27 rates->tx_ctrl_frame_mod = ctrl_mod;
28 rates->tx_mgt_frame_rate = mgt_rate;
29 rates->tx_mgt_frame_mod = mgt_mod;
30
31 ret = wl1251_cmd_configure(wl, ACX_FW_GEN_FRAME_RATES,
32 rates, sizeof(*rates));
33 if (ret < 0) {
34 wl1251_error("Failed to set FW rates and modulation");
35 goto out;
36 }
37
38out:
39 kfree(rates);
40 return ret;
41}
42
43
44int wl1251_acx_station_id(struct wl1251 *wl)
45{
46 struct acx_dot11_station_id *mac;
47 int ret, i;
48
49 wl1251_debug(DEBUG_ACX, "acx dot11_station_id");
50
51 mac = kzalloc(sizeof(*mac), GFP_KERNEL);
52 if (!mac) {
53 ret = -ENOMEM;
54 goto out;
55 }
56
57 for (i = 0; i < ETH_ALEN; i++)
58 mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
59
60 ret = wl1251_cmd_configure(wl, DOT11_STATION_ID, mac, sizeof(*mac));
61 if (ret < 0)
62 goto out;
63
64out:
65 kfree(mac);
66 return ret;
67}
68
69int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id)
70{
71 struct acx_dot11_default_key *default_key;
72 int ret;
73
74 wl1251_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
75
76 default_key = kzalloc(sizeof(*default_key), GFP_KERNEL);
77 if (!default_key) {
78 ret = -ENOMEM;
79 goto out;
80 }
81
82 default_key->id = key_id;
83
84 ret = wl1251_cmd_configure(wl, DOT11_DEFAULT_KEY,
85 default_key, sizeof(*default_key));
86 if (ret < 0) {
87 wl1251_error("Couldnt set default key");
88 goto out;
89 }
90
91 wl->default_key = key_id;
92
93out:
94 kfree(default_key);
95 return ret;
96}
97
98int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
99 u8 listen_interval)
100{
101 struct acx_wake_up_condition *wake_up;
102 int ret;
103
104 wl1251_debug(DEBUG_ACX, "acx wake up conditions");
105
106 wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
107 if (!wake_up) {
108 ret = -ENOMEM;
109 goto out;
110 }
111
112 wake_up->wake_up_event = wake_up_event;
113 wake_up->listen_interval = listen_interval;
114
115 ret = wl1251_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
116 wake_up, sizeof(*wake_up));
117 if (ret < 0) {
118 wl1251_warning("could not set wake up conditions: %d", ret);
119 goto out;
120 }
121
122out:
123 kfree(wake_up);
124 return ret;
125}
126
127int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth)
128{
129 struct acx_sleep_auth *auth;
130 int ret;
131
132 wl1251_debug(DEBUG_ACX, "acx sleep auth");
133
134 auth = kzalloc(sizeof(*auth), GFP_KERNEL);
135 if (!auth) {
136 ret = -ENOMEM;
137 goto out;
138 }
139
140 auth->sleep_auth = sleep_auth;
141
142 ret = wl1251_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
143 if (ret < 0)
144 return ret;
145
146out:
147 kfree(auth);
148 return ret;
149}
150
151int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
152{
153 struct acx_revision *rev;
154 int ret;
155
156 wl1251_debug(DEBUG_ACX, "acx fw rev");
157
158 rev = kzalloc(sizeof(*rev), GFP_KERNEL);
159 if (!rev) {
160 ret = -ENOMEM;
161 goto out;
162 }
163
164 ret = wl1251_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
165 if (ret < 0) {
166 wl1251_warning("ACX_FW_REV interrogate failed");
167 goto out;
168 }
169
170 /* be careful with the buffer sizes */
171 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
172
173 /*
174 * if the firmware version string is exactly
175 * sizeof(rev->fw_version) long or fw_len is less than
176 * sizeof(rev->fw_version) it won't be null terminated
177 */
178 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
179
180out:
181 kfree(rev);
182 return ret;
183}
184
185int wl1251_acx_tx_power(struct wl1251 *wl, int power)
186{
187 struct acx_current_tx_power *acx;
188 int ret;
189
190 wl1251_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
191
192 if (power < 0 || power > 25)
193 return -EINVAL;
194
195 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
196 if (!acx) {
197 ret = -ENOMEM;
198 goto out;
199 }
200
201 acx->current_tx_power = power * 10;
202
203 ret = wl1251_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
204 if (ret < 0) {
205 wl1251_warning("configure of tx power failed: %d", ret);
206 goto out;
207 }
208
209out:
210 kfree(acx);
211 return ret;
212}
213
214int wl1251_acx_feature_cfg(struct wl1251 *wl)
215{
216 struct acx_feature_config *feature;
217 int ret;
218
219 wl1251_debug(DEBUG_ACX, "acx feature cfg");
220
221 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
222 if (!feature) {
223 ret = -ENOMEM;
224 goto out;
225 }
226
227 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
228 feature->data_flow_options = 0;
229 feature->options = 0;
230
231 ret = wl1251_cmd_configure(wl, ACX_FEATURE_CFG,
232 feature, sizeof(*feature));
233 if (ret < 0) {
234 wl1251_error("Couldnt set HW encryption");
235 goto out;
236 }
237
238out:
239 kfree(feature);
240 return ret;
241}
242
243int wl1251_acx_mem_map(struct wl1251 *wl, struct acx_header *mem_map,
244 size_t len)
245{
246 int ret;
247
248 wl1251_debug(DEBUG_ACX, "acx mem map");
249
250 ret = wl1251_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
251 if (ret < 0)
252 return ret;
253
254 return 0;
255}
256
257int wl1251_acx_data_path_params(struct wl1251 *wl,
258 struct acx_data_path_params_resp *resp)
259{
260 struct acx_data_path_params *params;
261 int ret;
262
263 wl1251_debug(DEBUG_ACX, "acx data path params");
264
265 params = kzalloc(sizeof(*params), GFP_KERNEL);
266 if (!params) {
267 ret = -ENOMEM;
268 goto out;
269 }
270
271 params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
272 params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
273
274 params->rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
275 params->tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
276
277 params->tx_complete_threshold = 1;
278
279 params->tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
280
281 params->tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
282
283 ret = wl1251_cmd_configure(wl, ACX_DATA_PATH_PARAMS,
284 params, sizeof(*params));
285 if (ret < 0)
286 goto out;
287
288 /* FIXME: shouldn't this be ACX_DATA_PATH_RESP_PARAMS? */
289 ret = wl1251_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
290 resp, sizeof(*resp));
291
292 if (ret < 0) {
293 wl1251_warning("failed to read data path parameters: %d", ret);
294 goto out;
295 } else if (resp->header.cmd.status != CMD_STATUS_SUCCESS) {
296 wl1251_warning("data path parameter acx status failed");
297 ret = -EIO;
298 goto out;
299 }
300
301out:
302 kfree(params);
303 return ret;
304}
305
306int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time)
307{
308 struct acx_rx_msdu_lifetime *acx;
309 int ret;
310
311 wl1251_debug(DEBUG_ACX, "acx rx msdu life time");
312
313 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
314 if (!acx) {
315 ret = -ENOMEM;
316 goto out;
317 }
318
319 acx->lifetime = life_time;
320 ret = wl1251_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
321 acx, sizeof(*acx));
322 if (ret < 0) {
323 wl1251_warning("failed to set rx msdu life time: %d", ret);
324 goto out;
325 }
326
327out:
328 kfree(acx);
329 return ret;
330}
331
332int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter)
333{
334 struct acx_rx_config *rx_config;
335 int ret;
336
337 wl1251_debug(DEBUG_ACX, "acx rx config");
338
339 rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
340 if (!rx_config) {
341 ret = -ENOMEM;
342 goto out;
343 }
344
345 rx_config->config_options = config;
346 rx_config->filter_options = filter;
347
348 ret = wl1251_cmd_configure(wl, ACX_RX_CFG,
349 rx_config, sizeof(*rx_config));
350 if (ret < 0) {
351 wl1251_warning("failed to set rx config: %d", ret);
352 goto out;
353 }
354
355out:
356 kfree(rx_config);
357 return ret;
358}
359
360int wl1251_acx_pd_threshold(struct wl1251 *wl)
361{
362 struct acx_packet_detection *pd;
363 int ret;
364
365 wl1251_debug(DEBUG_ACX, "acx data pd threshold");
366
367 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
368 if (!pd) {
369 ret = -ENOMEM;
370 goto out;
371 }
372
373 /* FIXME: threshold value not set */
374
375 ret = wl1251_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
376 if (ret < 0) {
377 wl1251_warning("failed to set pd threshold: %d", ret);
378 goto out;
379 }
380
381out:
382 kfree(pd);
383 return 0;
384}
385
386int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time)
387{
388 struct acx_slot *slot;
389 int ret;
390
391 wl1251_debug(DEBUG_ACX, "acx slot");
392
393 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
394 if (!slot) {
395 ret = -ENOMEM;
396 goto out;
397 }
398
399 slot->wone_index = STATION_WONE_INDEX;
400 slot->slot_time = slot_time;
401
402 ret = wl1251_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
403 if (ret < 0) {
404 wl1251_warning("failed to set slot time: %d", ret);
405 goto out;
406 }
407
408out:
409 kfree(slot);
410 return ret;
411}
412
413int wl1251_acx_group_address_tbl(struct wl1251 *wl)
414{
415 struct acx_dot11_grp_addr_tbl *acx;
416 int ret;
417
418 wl1251_debug(DEBUG_ACX, "acx group address tbl");
419
420 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
421 if (!acx) {
422 ret = -ENOMEM;
423 goto out;
424 }
425
426 /* MAC filtering */
427 acx->enabled = 0;
428 acx->num_groups = 0;
429 memset(acx->mac_table, 0, ADDRESS_GROUP_MAX_LEN);
430
431 ret = wl1251_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
432 acx, sizeof(*acx));
433 if (ret < 0) {
434 wl1251_warning("failed to set group addr table: %d", ret);
435 goto out;
436 }
437
438out:
439 kfree(acx);
440 return ret;
441}
442
443int wl1251_acx_service_period_timeout(struct wl1251 *wl)
444{
445 struct acx_rx_timeout *rx_timeout;
446 int ret;
447
448 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
449 if (!rx_timeout) {
450 ret = -ENOMEM;
451 goto out;
452 }
453
454 wl1251_debug(DEBUG_ACX, "acx service period timeout");
455
456 rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
457 rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF;
458
459 ret = wl1251_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
460 rx_timeout, sizeof(*rx_timeout));
461 if (ret < 0) {
462 wl1251_warning("failed to set service period timeout: %d",
463 ret);
464 goto out;
465 }
466
467out:
468 kfree(rx_timeout);
469 return ret;
470}
471
472int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold)
473{
474 struct acx_rts_threshold *rts;
475 int ret;
476
477 wl1251_debug(DEBUG_ACX, "acx rts threshold");
478
479 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
480 if (!rts) {
481 ret = -ENOMEM;
482 goto out;
483 }
484
485 rts->threshold = rts_threshold;
486
487 ret = wl1251_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
488 if (ret < 0) {
489 wl1251_warning("failed to set rts threshold: %d", ret);
490 goto out;
491 }
492
493out:
494 kfree(rts);
495 return ret;
496}
497
498int wl1251_acx_beacon_filter_opt(struct wl1251 *wl)
499{
500 struct acx_beacon_filter_option *beacon_filter;
501 int ret;
502
503 wl1251_debug(DEBUG_ACX, "acx beacon filter opt");
504
505 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
506 if (!beacon_filter) {
507 ret = -ENOMEM;
508 goto out;
509 }
510
511 beacon_filter->enable = 0;
512 beacon_filter->max_num_beacons = 0;
513
514 ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
515 beacon_filter, sizeof(*beacon_filter));
516 if (ret < 0) {
517 wl1251_warning("failed to set beacon filter opt: %d", ret);
518 goto out;
519 }
520
521out:
522 kfree(beacon_filter);
523 return ret;
524}
525
526int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
527{
528 struct acx_beacon_filter_ie_table *ie_table;
529 int ret;
530
531 wl1251_debug(DEBUG_ACX, "acx beacon filter table");
532
533 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
534 if (!ie_table) {
535 ret = -ENOMEM;
536 goto out;
537 }
538
539 ie_table->num_ie = 0;
540 memset(ie_table->table, 0, BEACON_FILTER_TABLE_MAX_SIZE);
541
542 ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
543 ie_table, sizeof(*ie_table));
544 if (ret < 0) {
545 wl1251_warning("failed to set beacon filter table: %d", ret);
546 goto out;
547 }
548
549out:
550 kfree(ie_table);
551 return ret;
552}
553
554int wl1251_acx_sg_enable(struct wl1251 *wl)
555{
556 struct acx_bt_wlan_coex *pta;
557 int ret;
558
559 wl1251_debug(DEBUG_ACX, "acx sg enable");
560
561 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
562 if (!pta) {
563 ret = -ENOMEM;
564 goto out;
565 }
566
567 pta->enable = SG_ENABLE;
568
569 ret = wl1251_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
570 if (ret < 0) {
571 wl1251_warning("failed to set softgemini enable: %d", ret);
572 goto out;
573 }
574
575out:
576 kfree(pta);
577 return ret;
578}
579
580int wl1251_acx_sg_cfg(struct wl1251 *wl)
581{
582 struct acx_bt_wlan_coex_param *param;
583 int ret;
584
585 wl1251_debug(DEBUG_ACX, "acx sg cfg");
586
587 param = kzalloc(sizeof(*param), GFP_KERNEL);
588 if (!param) {
589 ret = -ENOMEM;
590 goto out;
591 }
592
593 /* BT-WLAN coext parameters */
594 param->min_rate = RATE_INDEX_24MBPS;
595 param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
596 param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
597 param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
598 param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
599 param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
600 param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
601 param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
602 param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
603 param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
604 param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
605 param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
606 param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
607 param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
608 param->antenna_type = PTA_ANTENNA_TYPE_DEF;
609 param->signal_type = PTA_SIGNALING_TYPE_DEF;
610 param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
611 param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
612 param->max_cts = PTA_MAX_NUM_CTS_DEF;
613 param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
614 param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
615 param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
616 param->wlan_elp_hp = PTA_ELP_HP_DEF;
617 param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
618 param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
619 param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
620 param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
621 param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
622
623 ret = wl1251_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
624 if (ret < 0) {
625 wl1251_warning("failed to set sg config: %d", ret);
626 goto out;
627 }
628
629out:
630 kfree(param);
631 return ret;
632}
633
634int wl1251_acx_cca_threshold(struct wl1251 *wl)
635{
636 struct acx_energy_detection *detection;
637 int ret;
638
639 wl1251_debug(DEBUG_ACX, "acx cca threshold");
640
641 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
642 if (!detection) {
643 ret = -ENOMEM;
644 goto out;
645 }
646
647 detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
648 detection->tx_energy_detection = 0;
649
650 ret = wl1251_cmd_configure(wl, ACX_CCA_THRESHOLD,
651 detection, sizeof(*detection));
652 if (ret < 0) {
653 wl1251_warning("failed to set cca threshold: %d", ret);
654 return ret;
655 }
656
657out:
658 kfree(detection);
659 return ret;
660}
661
662int wl1251_acx_bcn_dtim_options(struct wl1251 *wl)
663{
664 struct acx_beacon_broadcast *bb;
665 int ret;
666
667 wl1251_debug(DEBUG_ACX, "acx bcn dtim options");
668
669 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
670 if (!bb) {
671 ret = -ENOMEM;
672 goto out;
673 }
674
675 bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
676 bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
677 bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
678 bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
679
680 ret = wl1251_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
681 if (ret < 0) {
682 wl1251_warning("failed to set rx config: %d", ret);
683 goto out;
684 }
685
686out:
687 kfree(bb);
688 return ret;
689}
690
691int wl1251_acx_aid(struct wl1251 *wl, u16 aid)
692{
693 struct acx_aid *acx_aid;
694 int ret;
695
696 wl1251_debug(DEBUG_ACX, "acx aid");
697
698 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
699 if (!acx_aid) {
700 ret = -ENOMEM;
701 goto out;
702 }
703
704 acx_aid->aid = aid;
705
706 ret = wl1251_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
707 if (ret < 0) {
708 wl1251_warning("failed to set aid: %d", ret);
709 goto out;
710 }
711
712out:
713 kfree(acx_aid);
714 return ret;
715}
716
717int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask)
718{
719 struct acx_event_mask *mask;
720 int ret;
721
722 wl1251_debug(DEBUG_ACX, "acx event mbox mask");
723
724 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
725 if (!mask) {
726 ret = -ENOMEM;
727 goto out;
728 }
729
730 /* high event mask is unused */
731 mask->high_event_mask = 0xffffffff;
732
733 mask->event_mask = event_mask;
734
735 ret = wl1251_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
736 mask, sizeof(*mask));
737 if (ret < 0) {
738 wl1251_warning("failed to set acx_event_mbox_mask: %d", ret);
739 goto out;
740 }
741
742out:
743 kfree(mask);
744 return ret;
745}
746
747int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble)
748{
749 struct acx_preamble *acx;
750 int ret;
751
752 wl1251_debug(DEBUG_ACX, "acx_set_preamble");
753
754 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
755 if (!acx) {
756 ret = -ENOMEM;
757 goto out;
758 }
759
760 acx->preamble = preamble;
761
762 ret = wl1251_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
763 if (ret < 0) {
764 wl1251_warning("Setting of preamble failed: %d", ret);
765 goto out;
766 }
767
768out:
769 kfree(acx);
770 return ret;
771}
772
773int wl1251_acx_cts_protect(struct wl1251 *wl,
774 enum acx_ctsprotect_type ctsprotect)
775{
776 struct acx_ctsprotect *acx;
777 int ret;
778
779 wl1251_debug(DEBUG_ACX, "acx_set_ctsprotect");
780
781 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
782 if (!acx) {
783 ret = -ENOMEM;
784 goto out;
785 }
786
787 acx->ctsprotect = ctsprotect;
788
789 ret = wl1251_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
790 if (ret < 0) {
791 wl1251_warning("Setting of ctsprotect failed: %d", ret);
792 goto out;
793 }
794
795out:
796 kfree(acx);
797 return ret;
798}
799
800int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime)
801{
802 struct acx_tsf_info *tsf_info;
803 int ret;
804
805 tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
806 if (!tsf_info) {
807 ret = -ENOMEM;
808 goto out;
809 }
810
811 ret = wl1251_cmd_interrogate(wl, ACX_TSF_INFO,
812 tsf_info, sizeof(*tsf_info));
813 if (ret < 0) {
814 wl1251_warning("ACX_FW_REV interrogate failed");
815 goto out;
816 }
817
818 *mactime = tsf_info->current_tsf_lsb |
819 (tsf_info->current_tsf_msb << 31);
820
821out:
822 kfree(tsf_info);
823 return ret;
824}
825
826int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats)
827{
828 int ret;
829
830 wl1251_debug(DEBUG_ACX, "acx statistics");
831
832 ret = wl1251_cmd_interrogate(wl, ACX_STATISTICS, stats,
833 sizeof(*stats));
834 if (ret < 0) {
835 wl1251_warning("acx statistics failed: %d", ret);
836 return -ENOMEM;
837 }
838
839 return 0;
840}
diff --git a/drivers/net/wireless/wl12xx/acx.h b/drivers/net/wireless/wl12xx/wl1251_acx.h
index fb2d2340993c..2e7b1933a8f9 100644
--- a/drivers/net/wireless/wl12xx/acx.h
+++ b/drivers/net/wireless/wl12xx/wl1251_acx.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated 4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation 5 * Copyright (C) 2008 Nokia Corporation
@@ -22,14 +22,20 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL12XX_ACX_H__ 25#ifndef __WL1251_ACX_H__
26#define __WL12XX_ACX_H__ 26#define __WL1251_ACX_H__
27 27
28#include "wl12xx.h" 28#include "wl1251.h"
29#include "wl1251_cmd.h"
29 30
30/* Target's information element */ 31/* Target's information element */
31struct acx_header { 32struct acx_header {
33 struct wl1251_cmd_header cmd;
34
35 /* acx (or information element) header */
32 u16 id; 36 u16 id;
37
38 /* payload length (not including headers */
33 u16 len; 39 u16 len;
34}; 40};
35 41
@@ -85,15 +91,15 @@ struct acx_revision {
85 u32 hw_version; 91 u32 hw_version;
86} __attribute__ ((packed)); 92} __attribute__ ((packed));
87 93
88enum wl12xx_psm_mode { 94enum wl1251_psm_mode {
89 /* Active mode */ 95 /* Active mode */
90 WL12XX_PSM_CAM = 0, 96 WL1251_PSM_CAM = 0,
91 97
92 /* Power save mode */ 98 /* Power save mode */
93 WL12XX_PSM_PS = 1, 99 WL1251_PSM_PS = 1,
94 100
95 /* Extreme low power */ 101 /* Extreme low power */
96 WL12XX_PSM_ELP = 2, 102 WL1251_PSM_ELP = 2,
97}; 103};
98 104
99struct acx_sleep_auth { 105struct acx_sleep_auth {
@@ -107,25 +113,6 @@ struct acx_sleep_auth {
107 u8 padding[3]; 113 u8 padding[3];
108} __attribute__ ((packed)); 114} __attribute__ ((packed));
109 115
110#define TIM_ELE_ID 5
111#define PARTIAL_VBM_MAX 251
112
113struct tim {
114 u8 identity;
115 u8 length;
116 u8 dtim_count;
117 u8 dtim_period;
118 u8 bitmap_ctrl;
119 u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */
120} __attribute__ ((packed));
121
122/* Virtual Bit Map update */
123struct vbm_update_request {
124 __le16 len;
125 u8 padding[2];
126 struct tim tim;
127} __attribute__ ((packed));
128
129enum { 116enum {
130 HOSTIF_PCI_MASTER_HOST_INDIRECT, 117 HOSTIF_PCI_MASTER_HOST_INDIRECT,
131 HOSTIF_PCI_MASTER_HOST_DIRECT, 118 HOSTIF_PCI_MASTER_HOST_DIRECT,
@@ -202,7 +189,7 @@ struct acx_data_path_params_resp {
202#define RX_MSDU_LIFETIME_MAX 0xFFFFFFFF 189#define RX_MSDU_LIFETIME_MAX 0xFFFFFFFF
203#define RX_MSDU_LIFETIME_DEF 512000 190#define RX_MSDU_LIFETIME_DEF 512000
204 191
205struct rx_msdu_lifetime { 192struct acx_rx_msdu_lifetime {
206 struct acx_header header; 193 struct acx_header header;
207 194
208 /* 195 /*
@@ -368,7 +355,7 @@ struct acx_slot {
368#define ADDRESS_GROUP_MAX (8) 355#define ADDRESS_GROUP_MAX (8)
369#define ADDRESS_GROUP_MAX_LEN (ETH_ALEN * ADDRESS_GROUP_MAX) 356#define ADDRESS_GROUP_MAX_LEN (ETH_ALEN * ADDRESS_GROUP_MAX)
370 357
371struct multicast_grp_addr_start { 358struct acx_dot11_grp_addr_tbl {
372 struct acx_header header; 359 struct acx_header header;
373 360
374 u8 enabled; 361 u8 enabled;
@@ -730,22 +717,13 @@ struct acx_fw_gen_frame_rates {
730} __attribute__ ((packed)); 717} __attribute__ ((packed));
731 718
732/* STA MAC */ 719/* STA MAC */
733struct dot11_station_id { 720struct acx_dot11_station_id {
734 struct acx_header header; 721 struct acx_header header;
735 722
736 u8 mac[ETH_ALEN]; 723 u8 mac[ETH_ALEN];
737 u8 pad[2]; 724 u8 pad[2];
738} __attribute__ ((packed)); 725} __attribute__ ((packed));
739 726
740/* HW encryption keys */
741#define NUM_ACCESS_CATEGORIES_COPY 4
742#define MAX_KEY_SIZE 32
743
744/* When set, disable HW encryption */
745#define DF_ENCRYPTION_DISABLE 0x01
746/* When set, disable HW decryption */
747#define DF_SNIFF_MODE_ENABLE 0x80
748
749struct acx_feature_config { 727struct acx_feature_config {
750 struct acx_header header; 728 struct acx_header header;
751 729
@@ -753,67 +731,6 @@ struct acx_feature_config {
753 u32 data_flow_options; 731 u32 data_flow_options;
754} __attribute__ ((packed)); 732} __attribute__ ((packed));
755 733
756enum acx_key_action {
757 KEY_ADD_OR_REPLACE = 1,
758 KEY_REMOVE = 2,
759 KEY_SET_ID = 3,
760 MAX_KEY_ACTION = 0xffff,
761};
762
763enum acx_key_type {
764 KEY_WEP_DEFAULT = 0,
765 KEY_WEP_ADDR = 1,
766 KEY_AES_GROUP = 4,
767 KEY_AES_PAIRWISE = 5,
768 KEY_WEP_GROUP = 6,
769 KEY_TKIP_MIC_GROUP = 10,
770 KEY_TKIP_MIC_PAIRWISE = 11,
771};
772
773/*
774 *
775 * key_type_e key size key format
776 * ---------- --------- ----------
777 * 0x00 5, 13, 29 Key data
778 * 0x01 5, 13, 29 Key data
779 * 0x04 16 16 bytes of key data
780 * 0x05 16 16 bytes of key data
781 * 0x0a 32 16 bytes of TKIP key data
782 * 8 bytes of RX MIC key data
783 * 8 bytes of TX MIC key data
784 * 0x0b 32 16 bytes of TKIP key data
785 * 8 bytes of RX MIC key data
786 * 8 bytes of TX MIC key data
787 *
788 */
789
790struct acx_set_key {
791 /* Ignored for default WEP key */
792 u8 addr[ETH_ALEN];
793
794 /* key_action_e */
795 u16 key_action;
796
797 u16 reserved_1;
798
799 /* key size in bytes */
800 u8 key_size;
801
802 /* key_type_e */
803 u8 key_type;
804 u8 ssid_profile;
805
806 /*
807 * TKIP, AES: frame's key id field.
808 * For WEP default key: key id;
809 */
810 u8 id;
811 u8 reserved_2[6];
812 u8 key[MAX_KEY_SIZE];
813 u16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
814 u32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
815} __attribute__ ((packed));
816
817struct acx_current_tx_power { 734struct acx_current_tx_power {
818 struct acx_header header; 735 struct acx_header header;
819 736
@@ -839,26 +756,6 @@ struct acx_tsf_info {
839 u8 pad[3]; 756 u8 pad[3];
840} __attribute__ ((packed)); 757} __attribute__ ((packed));
841 758
842/* 802.11 PS */
843enum acx_ps_mode {
844 STATION_ACTIVE_MODE,
845 STATION_POWER_SAVE_MODE
846};
847
848struct acx_ps_params {
849 u8 ps_mode; /* STATION_* */
850 u8 send_null_data; /* Do we have to send NULL data packet ? */
851 u8 retries; /* Number of retires for the initial NULL data packet */
852
853 /*
854 * TUs during which the target stays awake after switching
855 * to power save mode.
856 */
857 u8 hang_over_period;
858 u16 null_data_rate;
859 u8 pad[2];
860} __attribute__ ((packed));
861
862enum acx_wake_up_event { 759enum acx_wake_up_event {
863 WAKE_UP_EVENT_BEACON_BITMAP = 0x01, /* Wake on every Beacon*/ 760 WAKE_UP_EVENT_BEACON_BITMAP = 0x01, /* Wake on every Beacon*/
864 WAKE_UP_EVENT_DTIM_BITMAP = 0x02, /* Wake on every DTIM*/ 761 WAKE_UP_EVENT_DTIM_BITMAP = 0x02, /* Wake on every DTIM*/
@@ -892,6 +789,7 @@ enum acx_preamble_type {
892 789
893struct acx_preamble { 790struct acx_preamble {
894 struct acx_header header; 791 struct acx_header header;
792
895 /* 793 /*
896 * When set, the WiLink transmits the frames with a short preamble and 794 * When set, the WiLink transmits the frames with a short preamble and
897 * when cleared, the WiLink transmits the frames with a long preamble. 795 * when cleared, the WiLink transmits the frames with a long preamble.
@@ -1210,36 +1108,39 @@ enum {
1210}; 1108};
1211 1109
1212 1110
1213int wl12xx_acx_frame_rates(struct wl12xx *wl, u8 ctrl_rate, u8 ctrl_mod, 1111int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
1214 u8 mgt_rate, u8 mgt_mod); 1112 u8 mgt_rate, u8 mgt_mod);
1215int wl12xx_acx_station_id(struct wl12xx *wl); 1113int wl1251_acx_station_id(struct wl1251 *wl);
1216int wl12xx_acx_default_key(struct wl12xx *wl, u8 key_id); 1114int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id);
1217int wl12xx_acx_wake_up_conditions(struct wl12xx *wl, u8 listen_interval); 1115int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
1218int wl12xx_acx_sleep_auth(struct wl12xx *wl, u8 sleep_auth); 1116 u8 listen_interval);
1219int wl12xx_acx_fw_version(struct wl12xx *wl, char *buf, size_t len); 1117int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth);
1220int wl12xx_acx_tx_power(struct wl12xx *wl, int power); 1118int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len);
1221int wl12xx_acx_feature_cfg(struct wl12xx *wl); 1119int wl1251_acx_tx_power(struct wl1251 *wl, int power);
1222int wl12xx_acx_mem_map(struct wl12xx *wl, void *mem_map, size_t len); 1120int wl1251_acx_feature_cfg(struct wl1251 *wl);
1223int wl12xx_acx_data_path_params(struct wl12xx *wl, 1121int wl1251_acx_mem_map(struct wl1251 *wl,
1122 struct acx_header *mem_map, size_t len);
1123int wl1251_acx_data_path_params(struct wl1251 *wl,
1224 struct acx_data_path_params_resp *data_path); 1124 struct acx_data_path_params_resp *data_path);
1225int wl12xx_acx_rx_msdu_life_time(struct wl12xx *wl, u32 life_time); 1125int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time);
1226int wl12xx_acx_rx_config(struct wl12xx *wl, u32 config, u32 filter); 1126int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter);
1227int wl12xx_acx_pd_threshold(struct wl12xx *wl); 1127int wl1251_acx_pd_threshold(struct wl1251 *wl);
1228int wl12xx_acx_slot(struct wl12xx *wl, enum acx_slot_type slot_time); 1128int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time);
1229int wl12xx_acx_group_address_tbl(struct wl12xx *wl); 1129int wl1251_acx_group_address_tbl(struct wl1251 *wl);
1230int wl12xx_acx_service_period_timeout(struct wl12xx *wl); 1130int wl1251_acx_service_period_timeout(struct wl1251 *wl);
1231int wl12xx_acx_rts_threshold(struct wl12xx *wl, u16 rts_threshold); 1131int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold);
1232int wl12xx_acx_beacon_filter_opt(struct wl12xx *wl); 1132int wl1251_acx_beacon_filter_opt(struct wl1251 *wl);
1233int wl12xx_acx_beacon_filter_table(struct wl12xx *wl); 1133int wl1251_acx_beacon_filter_table(struct wl1251 *wl);
1234int wl12xx_acx_sg_enable(struct wl12xx *wl); 1134int wl1251_acx_sg_enable(struct wl1251 *wl);
1235int wl12xx_acx_sg_cfg(struct wl12xx *wl); 1135int wl1251_acx_sg_cfg(struct wl1251 *wl);
1236int wl12xx_acx_cca_threshold(struct wl12xx *wl); 1136int wl1251_acx_cca_threshold(struct wl1251 *wl);
1237int wl12xx_acx_bcn_dtim_options(struct wl12xx *wl); 1137int wl1251_acx_bcn_dtim_options(struct wl1251 *wl);
1238int wl12xx_acx_aid(struct wl12xx *wl, u16 aid); 1138int wl1251_acx_aid(struct wl1251 *wl, u16 aid);
1239int wl12xx_acx_event_mbox_mask(struct wl12xx *wl, u32 event_mask); 1139int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask);
1240int wl12xx_acx_set_preamble(struct wl12xx *wl, enum acx_preamble_type preamble); 1140int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble);
1241int wl12xx_acx_cts_protect(struct wl12xx *wl, 1141int wl1251_acx_cts_protect(struct wl1251 *wl,
1242 enum acx_ctsprotect_type ctsprotect); 1142 enum acx_ctsprotect_type ctsprotect);
1243int wl12xx_acx_statistics(struct wl12xx *wl, struct acx_statistics *stats); 1143int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats);
1144int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime);
1244 1145
1245#endif /* __WL12XX_ACX_H__ */ 1146#endif /* __WL1251_ACX_H__ */
diff --git a/drivers/net/wireless/wl12xx/boot.c b/drivers/net/wireless/wl12xx/wl1251_boot.c
index 48ac08c429bd..d8a155dc2fa1 100644
--- a/drivers/net/wireless/wl12xx/boot.c
+++ b/drivers/net/wireless/wl12xx/wl1251_boot.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (C) 2008 Nokia Corporation
5 * 5 *
@@ -24,41 +24,41 @@
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25 25
26#include "reg.h" 26#include "reg.h"
27#include "boot.h" 27#include "wl1251_boot.h"
28#include "spi.h" 28#include "wl1251_spi.h"
29#include "event.h" 29#include "wl1251_event.h"
30 30
31static void wl12xx_boot_enable_interrupts(struct wl12xx *wl) 31static void wl1251_boot_enable_interrupts(struct wl1251 *wl)
32{ 32{
33 enable_irq(wl->irq); 33 enable_irq(wl->irq);
34} 34}
35 35
36void wl12xx_boot_target_enable_interrupts(struct wl12xx *wl) 36void wl1251_boot_target_enable_interrupts(struct wl1251 *wl)
37{ 37{
38 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask)); 38 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
39 wl12xx_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL); 39 wl1251_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
40} 40}
41 41
42int wl12xx_boot_soft_reset(struct wl12xx *wl) 42int wl1251_boot_soft_reset(struct wl1251 *wl)
43{ 43{
44 unsigned long timeout; 44 unsigned long timeout;
45 u32 boot_data; 45 u32 boot_data;
46 46
47 /* perform soft reset */ 47 /* perform soft reset */
48 wl12xx_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT); 48 wl1251_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
49 49
50 /* SOFT_RESET is self clearing */ 50 /* SOFT_RESET is self clearing */
51 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME); 51 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
52 while (1) { 52 while (1) {
53 boot_data = wl12xx_reg_read32(wl, ACX_REG_SLV_SOFT_RESET); 53 boot_data = wl1251_reg_read32(wl, ACX_REG_SLV_SOFT_RESET);
54 wl12xx_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data); 54 wl1251_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
55 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0) 55 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
56 break; 56 break;
57 57
58 if (time_after(jiffies, timeout)) { 58 if (time_after(jiffies, timeout)) {
59 /* 1.2 check pWhalBus->uSelfClearTime if the 59 /* 1.2 check pWhalBus->uSelfClearTime if the
60 * timeout was reached */ 60 * timeout was reached */
61 wl12xx_error("soft reset timeout"); 61 wl1251_error("soft reset timeout");
62 return -1; 62 return -1;
63 } 63 }
64 64
@@ -66,15 +66,15 @@ int wl12xx_boot_soft_reset(struct wl12xx *wl)
66 } 66 }
67 67
68 /* disable Rx/Tx */ 68 /* disable Rx/Tx */
69 wl12xx_reg_write32(wl, ENABLE, 0x0); 69 wl1251_reg_write32(wl, ENABLE, 0x0);
70 70
71 /* disable auto calibration on start*/ 71 /* disable auto calibration on start*/
72 wl12xx_reg_write32(wl, SPARE_A2, 0xffff); 72 wl1251_reg_write32(wl, SPARE_A2, 0xffff);
73 73
74 return 0; 74 return 0;
75} 75}
76 76
77int wl12xx_boot_init_seq(struct wl12xx *wl) 77int wl1251_boot_init_seq(struct wl1251 *wl)
78{ 78{
79 u32 scr_pad6, init_data, tmp, elp_cmd, ref_freq; 79 u32 scr_pad6, init_data, tmp, elp_cmd, ref_freq;
80 80
@@ -96,23 +96,23 @@ int wl12xx_boot_init_seq(struct wl12xx *wl)
96 }; 96 };
97 97
98 /* read NVS params */ 98 /* read NVS params */
99 scr_pad6 = wl12xx_reg_read32(wl, SCR_PAD6); 99 scr_pad6 = wl1251_reg_read32(wl, SCR_PAD6);
100 wl12xx_debug(DEBUG_BOOT, "scr_pad6 0x%x", scr_pad6); 100 wl1251_debug(DEBUG_BOOT, "scr_pad6 0x%x", scr_pad6);
101 101
102 /* read ELP_CMD */ 102 /* read ELP_CMD */
103 elp_cmd = wl12xx_reg_read32(wl, ELP_CMD); 103 elp_cmd = wl1251_reg_read32(wl, ELP_CMD);
104 wl12xx_debug(DEBUG_BOOT, "elp_cmd 0x%x", elp_cmd); 104 wl1251_debug(DEBUG_BOOT, "elp_cmd 0x%x", elp_cmd);
105 105
106 /* set the BB calibration time to be 300 usec (PLL_CAL_TIME) */ 106 /* set the BB calibration time to be 300 usec (PLL_CAL_TIME) */
107 ref_freq = scr_pad6 & 0x000000FF; 107 ref_freq = scr_pad6 & 0x000000FF;
108 wl12xx_debug(DEBUG_BOOT, "ref_freq 0x%x", ref_freq); 108 wl1251_debug(DEBUG_BOOT, "ref_freq 0x%x", ref_freq);
109 109
110 wl12xx_reg_write32(wl, PLL_CAL_TIME, 0x9); 110 wl1251_reg_write32(wl, PLL_CAL_TIME, 0x9);
111 111
112 /* 112 /*
113 * PG 1.2: set the clock buffer time to be 210 usec (CLK_BUF_TIME) 113 * PG 1.2: set the clock buffer time to be 210 usec (CLK_BUF_TIME)
114 */ 114 */
115 wl12xx_reg_write32(wl, CLK_BUF_TIME, 0x6); 115 wl1251_reg_write32(wl, CLK_BUF_TIME, 0x6);
116 116
117 /* 117 /*
118 * set the clock detect feature to work in the restart wu procedure 118 * set the clock detect feature to work in the restart wu procedure
@@ -120,18 +120,18 @@ int wl12xx_boot_init_seq(struct wl12xx *wl)
120 * (ELP_CFG_MODE[13:12]) 120 * (ELP_CFG_MODE[13:12])
121 */ 121 */
122 tmp = ((scr_pad6 & 0x0000FF00) << 4) | 0x00004000; 122 tmp = ((scr_pad6 & 0x0000FF00) << 4) | 0x00004000;
123 wl12xx_reg_write32(wl, ELP_CFG_MODE, tmp); 123 wl1251_reg_write32(wl, ELP_CFG_MODE, tmp);
124 124
125 /* PG 1.2: enable the BB PLL fix. Enable the PLL_LIMP_CLK_EN_CMD */ 125 /* PG 1.2: enable the BB PLL fix. Enable the PLL_LIMP_CLK_EN_CMD */
126 elp_cmd |= 0x00000040; 126 elp_cmd |= 0x00000040;
127 wl12xx_reg_write32(wl, ELP_CMD, elp_cmd); 127 wl1251_reg_write32(wl, ELP_CMD, elp_cmd);
128 128
129 /* PG 1.2: Set the BB PLL stable time to be 1000usec 129 /* PG 1.2: Set the BB PLL stable time to be 1000usec
130 * (PLL_STABLE_TIME) */ 130 * (PLL_STABLE_TIME) */
131 wl12xx_reg_write32(wl, CFG_PLL_SYNC_CNT, 0x20); 131 wl1251_reg_write32(wl, CFG_PLL_SYNC_CNT, 0x20);
132 132
133 /* PG 1.2: read clock request time */ 133 /* PG 1.2: read clock request time */
134 init_data = wl12xx_reg_read32(wl, CLK_REQ_TIME); 134 init_data = wl1251_reg_read32(wl, CLK_REQ_TIME);
135 135
136 /* 136 /*
137 * PG 1.2: set the clock request time to be ref_clk_settling_time - 137 * PG 1.2: set the clock request time to be ref_clk_settling_time -
@@ -141,35 +141,35 @@ int wl12xx_boot_init_seq(struct wl12xx *wl)
141 tmp = init_data - 0x21; 141 tmp = init_data - 0x21;
142 else 142 else
143 tmp = 0; 143 tmp = 0;
144 wl12xx_reg_write32(wl, CLK_REQ_TIME, tmp); 144 wl1251_reg_write32(wl, CLK_REQ_TIME, tmp);
145 145
146 /* set BB PLL configurations in RF AFE */ 146 /* set BB PLL configurations in RF AFE */
147 wl12xx_reg_write32(wl, 0x003058cc, 0x4B5); 147 wl1251_reg_write32(wl, 0x003058cc, 0x4B5);
148 148
149 /* set RF_AFE_REG_5 */ 149 /* set RF_AFE_REG_5 */
150 wl12xx_reg_write32(wl, 0x003058d4, 0x50); 150 wl1251_reg_write32(wl, 0x003058d4, 0x50);
151 151
152 /* set RF_AFE_CTRL_REG_2 */ 152 /* set RF_AFE_CTRL_REG_2 */
153 wl12xx_reg_write32(wl, 0x00305948, 0x11c001); 153 wl1251_reg_write32(wl, 0x00305948, 0x11c001);
154 154
155 /* 155 /*
156 * change RF PLL and BB PLL divider for VCO clock and adjust VCO 156 * change RF PLL and BB PLL divider for VCO clock and adjust VCO
157 * bais current(RF_AFE_REG_13) 157 * bais current(RF_AFE_REG_13)
158 */ 158 */
159 wl12xx_reg_write32(wl, 0x003058f4, 0x1e); 159 wl1251_reg_write32(wl, 0x003058f4, 0x1e);
160 160
161 /* set BB PLL configurations */ 161 /* set BB PLL configurations */
162 tmp = LUT[ref_freq][LUT_PARAM_INTEGER_DIVIDER] | 0x00017000; 162 tmp = LUT[ref_freq][LUT_PARAM_INTEGER_DIVIDER] | 0x00017000;
163 wl12xx_reg_write32(wl, 0x00305840, tmp); 163 wl1251_reg_write32(wl, 0x00305840, tmp);
164 164
165 /* set fractional divider according to Appendix C-BB PLL 165 /* set fractional divider according to Appendix C-BB PLL
166 * Calculations 166 * Calculations
167 */ 167 */
168 tmp = LUT[ref_freq][LUT_PARAM_FRACTIONAL_DIVIDER]; 168 tmp = LUT[ref_freq][LUT_PARAM_FRACTIONAL_DIVIDER];
169 wl12xx_reg_write32(wl, 0x00305844, tmp); 169 wl1251_reg_write32(wl, 0x00305844, tmp);
170 170
171 /* set the initial data for the sigma delta */ 171 /* set the initial data for the sigma delta */
172 wl12xx_reg_write32(wl, 0x00305848, 0x3039); 172 wl1251_reg_write32(wl, 0x00305848, 0x3039);
173 173
174 /* 174 /*
175 * set the accumulator attenuation value, calibration loop1 175 * set the accumulator attenuation value, calibration loop1
@@ -178,14 +178,14 @@ int wl12xx_boot_init_seq(struct wl12xx *wl)
178 */ 178 */
179 tmp = (LUT[ref_freq][LUT_PARAM_ATTN_BB] << 16) | 179 tmp = (LUT[ref_freq][LUT_PARAM_ATTN_BB] << 16) |
180 (LUT[ref_freq][LUT_PARAM_ALPHA_BB] << 12) | 0x1; 180 (LUT[ref_freq][LUT_PARAM_ALPHA_BB] << 12) | 0x1;
181 wl12xx_reg_write32(wl, 0x00305854, tmp); 181 wl1251_reg_write32(wl, 0x00305854, tmp);
182 182
183 /* 183 /*
184 * set the calibration stop time after holdoff time expires and set 184 * set the calibration stop time after holdoff time expires and set
185 * settling time HOLD_OFF_TIME_BB 185 * settling time HOLD_OFF_TIME_BB
186 */ 186 */
187 tmp = LUT[ref_freq][LUT_PARAM_STOP_TIME_BB] | 0x000A0000; 187 tmp = LUT[ref_freq][LUT_PARAM_STOP_TIME_BB] | 0x000A0000;
188 wl12xx_reg_write32(wl, 0x00305858, tmp); 188 wl1251_reg_write32(wl, 0x00305858, tmp);
189 189
190 /* 190 /*
191 * set BB PLL Loop filter capacitor3- BB_C3[2:0] and set BB PLL 191 * set BB PLL Loop filter capacitor3- BB_C3[2:0] and set BB PLL
@@ -193,7 +193,7 @@ int wl12xx_boot_init_seq(struct wl12xx *wl)
193 * BB_ILOOPF[7:3] 193 * BB_ILOOPF[7:3]
194 */ 194 */
195 tmp = LUT[ref_freq][LUT_PARAM_BB_PLL_LOOP_FILTER] | 0x00000030; 195 tmp = LUT[ref_freq][LUT_PARAM_BB_PLL_LOOP_FILTER] | 0x00000030;
196 wl12xx_reg_write32(wl, 0x003058f8, tmp); 196 wl1251_reg_write32(wl, 0x003058f8, tmp);
197 197
198 /* 198 /*
199 * set regulator output voltage for n divider to 199 * set regulator output voltage for n divider to
@@ -201,10 +201,10 @@ int wl12xx_boot_init_seq(struct wl12xx *wl)
201 * set BB PLL Loop filter capacitor2- BB_C2[7:5], set gain of BB 201 * set BB PLL Loop filter capacitor2- BB_C2[7:5], set gain of BB
202 * PLL auto-call to normal mode- BB_CALGAIN_3DB[8] 202 * PLL auto-call to normal mode- BB_CALGAIN_3DB[8]
203 */ 203 */
204 wl12xx_reg_write32(wl, 0x003058f0, 0x29); 204 wl1251_reg_write32(wl, 0x003058f0, 0x29);
205 205
206 /* enable restart wakeup sequence (ELP_CMD[0]) */ 206 /* enable restart wakeup sequence (ELP_CMD[0]) */
207 wl12xx_reg_write32(wl, ELP_CMD, elp_cmd | 0x1); 207 wl1251_reg_write32(wl, ELP_CMD, elp_cmd | 0x1);
208 208
209 /* restart sequence completed */ 209 /* restart sequence completed */
210 udelay(2000); 210 udelay(2000);
@@ -212,19 +212,19 @@ int wl12xx_boot_init_seq(struct wl12xx *wl)
212 return 0; 212 return 0;
213} 213}
214 214
215int wl12xx_boot_run_firmware(struct wl12xx *wl) 215int wl1251_boot_run_firmware(struct wl1251 *wl)
216{ 216{
217 int loop, ret; 217 int loop, ret;
218 u32 chip_id, interrupt; 218 u32 chip_id, interrupt;
219 219
220 wl->chip.op_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT); 220 wl->chip.op_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
221 221
222 chip_id = wl12xx_reg_read32(wl, CHIP_ID_B); 222 chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
223 223
224 wl12xx_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id); 224 wl1251_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
225 225
226 if (chip_id != wl->chip.id) { 226 if (chip_id != wl->chip.id) {
227 wl12xx_error("chip id doesn't match after firmware boot"); 227 wl1251_error("chip id doesn't match after firmware boot");
228 return -EIO; 228 return -EIO;
229 } 229 }
230 230
@@ -232,63 +232,65 @@ int wl12xx_boot_run_firmware(struct wl12xx *wl)
232 loop = 0; 232 loop = 0;
233 while (loop++ < INIT_LOOP) { 233 while (loop++ < INIT_LOOP) {
234 udelay(INIT_LOOP_DELAY); 234 udelay(INIT_LOOP_DELAY);
235 interrupt = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); 235 interrupt = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
236 236
237 if (interrupt == 0xffffffff) { 237 if (interrupt == 0xffffffff) {
238 wl12xx_error("error reading hardware complete " 238 wl1251_error("error reading hardware complete "
239 "init indication"); 239 "init indication");
240 return -EIO; 240 return -EIO;
241 } 241 }
242 /* check that ACX_INTR_INIT_COMPLETE is enabled */ 242 /* check that ACX_INTR_INIT_COMPLETE is enabled */
243 else if (interrupt & wl->chip.intr_init_complete) { 243 else if (interrupt & wl->chip.intr_init_complete) {
244 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_ACK, 244 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
245 wl->chip.intr_init_complete); 245 wl->chip.intr_init_complete);
246 break; 246 break;
247 } 247 }
248 } 248 }
249 249
250 if (loop >= INIT_LOOP) { 250 if (loop >= INIT_LOOP) {
251 wl12xx_error("timeout waiting for the hardware to " 251 wl1251_error("timeout waiting for the hardware to "
252 "complete initialization"); 252 "complete initialization");
253 return -EIO; 253 return -EIO;
254 } 254 }
255 255
256 /* get hardware config command mail box */ 256 /* get hardware config command mail box */
257 wl->cmd_box_addr = wl12xx_reg_read32(wl, REG_COMMAND_MAILBOX_PTR); 257 wl->cmd_box_addr = wl1251_reg_read32(wl, REG_COMMAND_MAILBOX_PTR);
258 258
259 /* get hardware config event mail box */ 259 /* get hardware config event mail box */
260 wl->event_box_addr = wl12xx_reg_read32(wl, REG_EVENT_MAILBOX_PTR); 260 wl->event_box_addr = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
261 261
262 /* set the working partition to its "running" mode offset */ 262 /* set the working partition to its "running" mode offset */
263 wl12xx_set_partition(wl, 263 wl1251_set_partition(wl,
264 wl->chip.p_table[PART_WORK].mem.start, 264 wl->chip.p_table[PART_WORK].mem.start,
265 wl->chip.p_table[PART_WORK].mem.size, 265 wl->chip.p_table[PART_WORK].mem.size,
266 wl->chip.p_table[PART_WORK].reg.start, 266 wl->chip.p_table[PART_WORK].reg.start,
267 wl->chip.p_table[PART_WORK].reg.size); 267 wl->chip.p_table[PART_WORK].reg.size);
268 268
269 wl12xx_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x", 269 wl1251_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
270 wl->cmd_box_addr, wl->event_box_addr); 270 wl->cmd_box_addr, wl->event_box_addr);
271 271
272 wl->chip.op_fw_version(wl);
273
272 /* 274 /*
273 * in case of full asynchronous mode the firmware event must be 275 * in case of full asynchronous mode the firmware event must be
274 * ready to receive event from the command mailbox 276 * ready to receive event from the command mailbox
275 */ 277 */
276 278
277 /* enable gpio interrupts */ 279 /* enable gpio interrupts */
278 wl12xx_boot_enable_interrupts(wl); 280 wl1251_boot_enable_interrupts(wl);
279 281
280 wl->chip.op_target_enable_interrupts(wl); 282 wl->chip.op_target_enable_interrupts(wl);
281 283
282 /* unmask all mbox events */ 284 /* unmask all mbox events */
283 wl->event_mask = 0xffffffff; 285 wl->event_mask = 0xffffffff;
284 286
285 ret = wl12xx_event_unmask(wl); 287 ret = wl1251_event_unmask(wl);
286 if (ret < 0) { 288 if (ret < 0) {
287 wl12xx_error("EVENT mask setting failed"); 289 wl1251_error("EVENT mask setting failed");
288 return ret; 290 return ret;
289 } 291 }
290 292
291 wl12xx_event_mbox_config(wl); 293 wl1251_event_mbox_config(wl);
292 294
293 /* firmware startup completed */ 295 /* firmware startup completed */
294 return 0; 296 return 0;
diff --git a/drivers/net/wireless/wl12xx/boot.h b/drivers/net/wireless/wl12xx/wl1251_boot.h
index 4fa73132baae..798362d71e3f 100644
--- a/drivers/net/wireless/wl12xx/boot.h
+++ b/drivers/net/wireless/wl12xx/wl1251_boot.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (C) 2008 Nokia Corporation
5 * 5 *
@@ -24,12 +24,12 @@
24#ifndef __BOOT_H__ 24#ifndef __BOOT_H__
25#define __BOOT_H__ 25#define __BOOT_H__
26 26
27#include "wl12xx.h" 27#include "wl1251.h"
28 28
29int wl12xx_boot_soft_reset(struct wl12xx *wl); 29int wl1251_boot_soft_reset(struct wl1251 *wl);
30int wl12xx_boot_init_seq(struct wl12xx *wl); 30int wl1251_boot_init_seq(struct wl1251 *wl);
31int wl12xx_boot_run_firmware(struct wl12xx *wl); 31int wl1251_boot_run_firmware(struct wl1251 *wl);
32void wl12xx_boot_target_enable_interrupts(struct wl12xx *wl); 32void wl1251_boot_target_enable_interrupts(struct wl1251 *wl);
33 33
34/* number of times we try to read the INIT interrupt */ 34/* number of times we try to read the INIT interrupt */
35#define INIT_LOOP 20000 35#define INIT_LOOP 20000
diff --git a/drivers/net/wireless/wl12xx/wl1251_cmd.c b/drivers/net/wireless/wl12xx/wl1251_cmd.c
new file mode 100644
index 000000000000..dc04d1fc2ee4
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1251_cmd.c
@@ -0,0 +1,428 @@
1#include "wl1251_cmd.h"
2
3#include <linux/module.h>
4#include <linux/crc7.h>
5#include <linux/spi/spi.h>
6
7#include "wl1251.h"
8#include "reg.h"
9#include "wl1251_spi.h"
10#include "wl1251_ps.h"
11#include "wl1251_acx.h"
12
13/**
14 * send command to firmware
15 *
16 * @wl: wl struct
17 * @id: command id
18 * @buf: buffer containing the command, must work with dma
19 * @len: length of the buffer
20 */
21int wl1251_cmd_send(struct wl1251 *wl, u16 id, void *buf, size_t len)
22{
23 struct wl1251_cmd_header *cmd;
24 unsigned long timeout;
25 u32 intr;
26 int ret = 0;
27
28 cmd = buf;
29 cmd->id = id;
30 cmd->status = 0;
31
32 WARN_ON(len % 4 != 0);
33
34 wl1251_spi_mem_write(wl, wl->cmd_box_addr, buf, len);
35
36 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
37
38 timeout = jiffies + msecs_to_jiffies(WL1251_COMMAND_TIMEOUT);
39
40 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
41 while (!(intr & wl->chip.intr_cmd_complete)) {
42 if (time_after(jiffies, timeout)) {
43 wl1251_error("command complete timeout");
44 ret = -ETIMEDOUT;
45 goto out;
46 }
47
48 msleep(1);
49
50 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
51 }
52
53 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
54 wl->chip.intr_cmd_complete);
55
56out:
57 return ret;
58}
59
60/**
61 * send test command to firmware
62 *
63 * @wl: wl struct
64 * @buf: buffer containing the command, with all headers, must work with dma
65 * @len: length of the buffer
66 * @answer: is answer needed
67 */
68int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer)
69{
70 int ret;
71
72 wl1251_debug(DEBUG_CMD, "cmd test");
73
74 ret = wl1251_cmd_send(wl, CMD_TEST, buf, buf_len);
75
76 if (ret < 0) {
77 wl1251_warning("TEST command failed");
78 return ret;
79 }
80
81 if (answer) {
82 struct wl1251_command *cmd_answer;
83
84 /*
85 * The test command got in, we can read the answer.
86 * The answer would be a wl1251_command, where the
87 * parameter array contains the actual answer.
88 */
89 wl1251_spi_mem_read(wl, wl->cmd_box_addr, buf, buf_len);
90
91 cmd_answer = buf;
92
93 if (cmd_answer->header.status != CMD_STATUS_SUCCESS)
94 wl1251_error("TEST command answer error: %d",
95 cmd_answer->header.status);
96 }
97
98 return 0;
99}
100
101/**
102 * read acx from firmware
103 *
104 * @wl: wl struct
105 * @id: acx id
106 * @buf: buffer for the response, including all headers, must work with dma
107 * @len: lenght of buf
108 */
109int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len)
110{
111 struct acx_header *acx = buf;
112 int ret;
113
114 wl1251_debug(DEBUG_CMD, "cmd interrogate");
115
116 acx->id = id;
117
118 /* payload length, does not include any headers */
119 acx->len = len - sizeof(*acx);
120
121 ret = wl1251_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx));
122 if (ret < 0) {
123 wl1251_error("INTERROGATE command failed");
124 goto out;
125 }
126
127 /* the interrogate command got in, we can read the answer */
128 wl1251_spi_mem_read(wl, wl->cmd_box_addr, buf, len);
129
130 acx = buf;
131 if (acx->cmd.status != CMD_STATUS_SUCCESS)
132 wl1251_error("INTERROGATE command error: %d",
133 acx->cmd.status);
134
135out:
136 return ret;
137}
138
139/**
140 * write acx value to firmware
141 *
142 * @wl: wl struct
143 * @id: acx id
144 * @buf: buffer containing acx, including all headers, must work with dma
145 * @len: length of buf
146 */
147int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len)
148{
149 struct acx_header *acx = buf;
150 int ret;
151
152 wl1251_debug(DEBUG_CMD, "cmd configure");
153
154 acx->id = id;
155
156 /* payload length, does not include any headers */
157 acx->len = len - sizeof(*acx);
158
159 ret = wl1251_cmd_send(wl, CMD_CONFIGURE, acx, len);
160 if (ret < 0) {
161 wl1251_warning("CONFIGURE command NOK");
162 return ret;
163 }
164
165 return 0;
166}
167
168int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
169 void *bitmap, u16 bitmap_len, u8 bitmap_control)
170{
171 struct wl1251_cmd_vbm_update *vbm;
172 int ret;
173
174 wl1251_debug(DEBUG_CMD, "cmd vbm");
175
176 vbm = kzalloc(sizeof(*vbm), GFP_KERNEL);
177 if (!vbm) {
178 ret = -ENOMEM;
179 goto out;
180 }
181
182 /* Count and period will be filled by the target */
183 vbm->tim.bitmap_ctrl = bitmap_control;
184 if (bitmap_len > PARTIAL_VBM_MAX) {
185 wl1251_warning("cmd vbm len is %d B, truncating to %d",
186 bitmap_len, PARTIAL_VBM_MAX);
187 bitmap_len = PARTIAL_VBM_MAX;
188 }
189 memcpy(vbm->tim.pvb_field, bitmap, bitmap_len);
190 vbm->tim.identity = identity;
191 vbm->tim.length = bitmap_len + 3;
192
193 vbm->len = cpu_to_le16(bitmap_len + 5);
194
195 ret = wl1251_cmd_send(wl, CMD_VBM, vbm, sizeof(*vbm));
196 if (ret < 0) {
197 wl1251_error("VBM command failed");
198 goto out;
199 }
200
201out:
202 kfree(vbm);
203 return 0;
204}
205
206int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable)
207{
208 struct cmd_enabledisable_path *cmd;
209 int ret;
210 u16 cmd_rx, cmd_tx;
211
212 wl1251_debug(DEBUG_CMD, "cmd data path");
213
214 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
215 if (!cmd) {
216 ret = -ENOMEM;
217 goto out;
218 }
219
220 cmd->channel = channel;
221
222 if (enable) {
223 cmd_rx = CMD_ENABLE_RX;
224 cmd_tx = CMD_ENABLE_TX;
225 } else {
226 cmd_rx = CMD_DISABLE_RX;
227 cmd_tx = CMD_DISABLE_TX;
228 }
229
230 ret = wl1251_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd));
231 if (ret < 0) {
232 wl1251_error("rx %s cmd for channel %d failed",
233 enable ? "start" : "stop", channel);
234 goto out;
235 }
236
237 wl1251_debug(DEBUG_BOOT, "rx %s cmd channel %d",
238 enable ? "start" : "stop", channel);
239
240 ret = wl1251_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd));
241 if (ret < 0) {
242 wl1251_error("tx %s cmd for channel %d failed",
243 enable ? "start" : "stop", channel);
244 return ret;
245 }
246
247 wl1251_debug(DEBUG_BOOT, "tx %s cmd channel %d",
248 enable ? "start" : "stop", channel);
249
250out:
251 kfree(cmd);
252 return ret;
253}
254
255int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 dtim_interval,
256 u16 beacon_interval, u8 wait)
257{
258 unsigned long timeout;
259 struct cmd_join *join;
260 int ret, i;
261 u8 *bssid;
262
263 join = kzalloc(sizeof(*join), GFP_KERNEL);
264 if (!join) {
265 ret = -ENOMEM;
266 goto out;
267 }
268
269 /* FIXME: this should be in main.c */
270 ret = wl1251_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE,
271 DEFAULT_HW_GEN_MODULATION_TYPE,
272 wl->tx_mgmt_frm_rate,
273 wl->tx_mgmt_frm_mod);
274 if (ret < 0)
275 goto out;
276
277 wl1251_debug(DEBUG_CMD, "cmd join");
278
279 /* Reverse order BSSID */
280 bssid = (u8 *) &join->bssid_lsb;
281 for (i = 0; i < ETH_ALEN; i++)
282 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
283
284 join->rx_config_options = wl->rx_config;
285 join->rx_filter_options = wl->rx_filter;
286
287 join->basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS |
288 RATE_MASK_5_5MBPS | RATE_MASK_11MBPS;
289
290 join->beacon_interval = beacon_interval;
291 join->dtim_interval = dtim_interval;
292 join->bss_type = bss_type;
293 join->channel = wl->channel;
294 join->ctrl = JOIN_CMD_CTRL_TX_FLUSH;
295
296 ret = wl1251_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join));
297 if (ret < 0) {
298 wl1251_error("failed to initiate cmd join");
299 goto out;
300 }
301
302 timeout = msecs_to_jiffies(JOIN_TIMEOUT);
303
304 /*
305 * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to
306 * simplify locking we just sleep instead, for now
307 */
308 if (wait)
309 msleep(10);
310
311out:
312 kfree(join);
313 return ret;
314}
315
316int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode)
317{
318 struct wl1251_cmd_ps_params *ps_params = NULL;
319 int ret = 0;
320
321 /* FIXME: this should be in ps.c */
322 ret = wl1251_acx_wake_up_conditions(wl, WAKE_UP_EVENT_DTIM_BITMAP,
323 wl->listen_int);
324 if (ret < 0) {
325 wl1251_error("couldn't set wake up conditions");
326 goto out;
327 }
328
329 wl1251_debug(DEBUG_CMD, "cmd set ps mode");
330
331 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
332 if (!ps_params) {
333 ret = -ENOMEM;
334 goto out;
335 }
336
337 ps_params->ps_mode = ps_mode;
338 ps_params->send_null_data = 1;
339 ps_params->retries = 5;
340 ps_params->hang_over_period = 128;
341 ps_params->null_data_rate = 1; /* 1 Mbps */
342
343 ret = wl1251_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
344 sizeof(*ps_params));
345 if (ret < 0) {
346 wl1251_error("cmd set_ps_mode failed");
347 goto out;
348 }
349
350out:
351 kfree(ps_params);
352 return ret;
353}
354
355int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
356 size_t len)
357{
358 struct cmd_read_write_memory *cmd;
359 int ret = 0;
360
361 wl1251_debug(DEBUG_CMD, "cmd read memory");
362
363 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
364 if (!cmd) {
365 ret = -ENOMEM;
366 goto out;
367 }
368
369 WARN_ON(len > MAX_READ_SIZE);
370 len = min_t(size_t, len, MAX_READ_SIZE);
371
372 cmd->addr = addr;
373 cmd->size = len;
374
375 ret = wl1251_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd));
376 if (ret < 0) {
377 wl1251_error("read memory command failed: %d", ret);
378 goto out;
379 }
380
381 /* the read command got in, we can now read the answer */
382 wl1251_spi_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
383
384 if (cmd->header.status != CMD_STATUS_SUCCESS)
385 wl1251_error("error in read command result: %d",
386 cmd->header.status);
387
388 memcpy(answer, cmd->value, len);
389
390out:
391 kfree(cmd);
392 return ret;
393}
394
395int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
396 void *buf, size_t buf_len)
397{
398 struct wl1251_cmd_packet_template *cmd;
399 size_t cmd_len;
400 int ret = 0;
401
402 wl1251_debug(DEBUG_CMD, "cmd template %d", cmd_id);
403
404 WARN_ON(buf_len > WL1251_MAX_TEMPLATE_SIZE);
405 buf_len = min_t(size_t, buf_len, WL1251_MAX_TEMPLATE_SIZE);
406 cmd_len = ALIGN(sizeof(*cmd) + buf_len, 4);
407
408 cmd = kzalloc(cmd_len, GFP_KERNEL);
409 if (!cmd) {
410 ret = -ENOMEM;
411 goto out;
412 }
413
414 cmd->size = cpu_to_le16(buf_len);
415
416 if (buf)
417 memcpy(cmd->data, buf, buf_len);
418
419 ret = wl1251_cmd_send(wl, cmd_id, cmd, cmd_len);
420 if (ret < 0) {
421 wl1251_warning("cmd set_template failed: %d", ret);
422 goto out;
423 }
424
425out:
426 kfree(cmd);
427 return ret;
428}
diff --git a/drivers/net/wireless/wl12xx/cmd.h b/drivers/net/wireless/wl12xx/wl1251_cmd.h
index aa307dcd081f..64f228dd9a9b 100644
--- a/drivers/net/wireless/wl12xx/cmd.h
+++ b/drivers/net/wireless/wl12xx/wl1251_cmd.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated 4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation 5 * Copyright (C) 2008 Nokia Corporation
@@ -22,37 +22,32 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL12XX_CMD_H__ 25#ifndef __WL1251_CMD_H__
26#define __WL12XX_CMD_H__ 26#define __WL1251_CMD_H__
27 27
28#include "wl12xx.h" 28#include "wl1251.h"
29 29
30int wl12xx_cmd_send(struct wl12xx *wl, u16 type, void *buf, size_t buf_len); 30struct acx_header;
31int wl12xx_cmd_test(struct wl12xx *wl, void *buf, size_t buf_len, u8 answer); 31
32int wl12xx_cmd_interrogate(struct wl12xx *wl, u16 ie_id, u16 ie_len, 32int wl1251_cmd_send(struct wl1251 *wl, u16 type, void *buf, size_t buf_len);
33 void *answer); 33int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer);
34int wl12xx_cmd_configure(struct wl12xx *wl, void *ie, int ie_len); 34int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len);
35int wl12xx_cmd_vbm(struct wl12xx *wl, u8 identity, 35int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len);
36int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
36 void *bitmap, u16 bitmap_len, u8 bitmap_control); 37 void *bitmap, u16 bitmap_len, u8 bitmap_control);
37int wl12xx_cmd_data_path(struct wl12xx *wl, u8 channel, u8 enable); 38int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable);
38int wl12xx_cmd_join(struct wl12xx *wl, u8 bss_type, u8 dtim_interval, 39int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 dtim_interval,
39 u16 beacon_interval, u8 wait); 40 u16 beacon_interval, u8 wait);
40int wl12xx_cmd_ps_mode(struct wl12xx *wl, u8 ps_mode); 41int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode);
41int wl12xx_cmd_read_memory(struct wl12xx *wl, u32 addr, u32 len, void *answer); 42int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
42int wl12xx_cmd_template_set(struct wl12xx *wl, u16 cmd_id, 43 size_t len);
44int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
43 void *buf, size_t buf_len); 45 void *buf, size_t buf_len);
44 46
45/* unit ms */ 47/* unit ms */
46#define WL12XX_COMMAND_TIMEOUT 2000 48#define WL1251_COMMAND_TIMEOUT 2000
47
48#define WL12XX_MAX_TEMPLATE_SIZE 300
49 49
50struct wl12xx_cmd_packet_template { 50enum wl1251_commands {
51 __le16 size;
52 u8 template[WL12XX_MAX_TEMPLATE_SIZE];
53} __attribute__ ((packed));
54
55enum wl12xx_commands {
56 CMD_RESET = 0, 51 CMD_RESET = 0,
57 CMD_INTERROGATE = 1, /*use this to read information elements*/ 52 CMD_INTERROGATE = 1, /*use this to read information elements*/
58 CMD_CONFIGURE = 2, /*use this to write information elements*/ 53 CMD_CONFIGURE = 2, /*use this to write information elements*/
@@ -100,9 +95,15 @@ enum wl12xx_commands {
100 95
101#define MAX_CMD_PARAMS 572 96#define MAX_CMD_PARAMS 572
102 97
103struct wl12xx_command { 98struct wl1251_cmd_header {
104 u16 id; 99 u16 id;
105 u16 status; 100 u16 status;
101 /* payload */
102 u8 data[0];
103} __attribute__ ((packed));
104
105struct wl1251_command {
106 struct wl1251_cmd_header header;
106 u8 parameters[MAX_CMD_PARAMS]; 107 u8 parameters[MAX_CMD_PARAMS];
107}; 108};
108 109
@@ -144,6 +145,8 @@ enum {
144#define MAX_READ_SIZE 256 145#define MAX_READ_SIZE 256
145 146
146struct cmd_read_write_memory { 147struct cmd_read_write_memory {
148 struct wl1251_cmd_header header;
149
147 /* The address of the memory to read from or write to.*/ 150 /* The address of the memory to read from or write to.*/
148 u32 addr; 151 u32 addr;
149 152
@@ -211,6 +214,8 @@ struct basic_scan_channel_parameters {
211#define SCAN_MAX_NUM_OF_CHANNELS 16 214#define SCAN_MAX_NUM_OF_CHANNELS 16
212 215
213struct cmd_scan { 216struct cmd_scan {
217 struct wl1251_cmd_header header;
218
214 struct basic_scan_parameters params; 219 struct basic_scan_parameters params;
215 struct basic_scan_channel_parameters channels[SCAN_MAX_NUM_OF_CHANNELS]; 220 struct basic_scan_channel_parameters channels[SCAN_MAX_NUM_OF_CHANNELS];
216} __attribute__ ((packed)); 221} __attribute__ ((packed));
@@ -227,6 +232,8 @@ enum {
227 232
228 233
229struct cmd_join { 234struct cmd_join {
235 struct wl1251_cmd_header header;
236
230 u32 bssid_lsb; 237 u32 bssid_lsb;
231 u16 bssid_msb; 238 u16 bssid_msb;
232 u16 beacon_interval; /* in TBTTs */ 239 u16 beacon_interval; /* in TBTTs */
@@ -261,5 +268,140 @@ struct cmd_join {
261 u8 reserved; 268 u8 reserved;
262} __attribute__ ((packed)); 269} __attribute__ ((packed));
263 270
271struct cmd_enabledisable_path {
272 struct wl1251_cmd_header header;
273
274 u8 channel;
275 u8 padding[3];
276} __attribute__ ((packed));
277
278#define WL1251_MAX_TEMPLATE_SIZE 300
279
280struct wl1251_cmd_packet_template {
281 struct wl1251_cmd_header header;
282
283 __le16 size;
284 u8 data[0];
285} __attribute__ ((packed));
286
287#define TIM_ELE_ID 5
288#define PARTIAL_VBM_MAX 251
289
290struct wl1251_tim {
291 u8 identity;
292 u8 length;
293 u8 dtim_count;
294 u8 dtim_period;
295 u8 bitmap_ctrl;
296 u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */
297} __attribute__ ((packed));
298
299/* Virtual Bit Map update */
300struct wl1251_cmd_vbm_update {
301 struct wl1251_cmd_header header;
302 __le16 len;
303 u8 padding[2];
304 struct wl1251_tim tim;
305} __attribute__ ((packed));
306
307enum wl1251_cmd_ps_mode {
308 STATION_ACTIVE_MODE,
309 STATION_POWER_SAVE_MODE
310};
311
312struct wl1251_cmd_ps_params {
313 struct wl1251_cmd_header header;
314
315 u8 ps_mode; /* STATION_* */
316 u8 send_null_data; /* Do we have to send NULL data packet ? */
317 u8 retries; /* Number of retires for the initial NULL data packet */
318
319 /*
320 * TUs during which the target stays awake after switching
321 * to power save mode.
322 */
323 u8 hang_over_period;
324 u16 null_data_rate;
325 u8 pad[2];
326} __attribute__ ((packed));
327
328struct wl1251_cmd_trigger_scan_to {
329 struct wl1251_cmd_header header;
330
331 u32 timeout;
332};
333
334/* HW encryption keys */
335#define NUM_ACCESS_CATEGORIES_COPY 4
336#define MAX_KEY_SIZE 32
337
338/* When set, disable HW encryption */
339#define DF_ENCRYPTION_DISABLE 0x01
340/* When set, disable HW decryption */
341#define DF_SNIFF_MODE_ENABLE 0x80
342
343enum wl1251_cmd_key_action {
344 KEY_ADD_OR_REPLACE = 1,
345 KEY_REMOVE = 2,
346 KEY_SET_ID = 3,
347 MAX_KEY_ACTION = 0xffff,
348};
349
350enum wl1251_cmd_key_type {
351 KEY_WEP_DEFAULT = 0,
352 KEY_WEP_ADDR = 1,
353 KEY_AES_GROUP = 4,
354 KEY_AES_PAIRWISE = 5,
355 KEY_WEP_GROUP = 6,
356 KEY_TKIP_MIC_GROUP = 10,
357 KEY_TKIP_MIC_PAIRWISE = 11,
358};
359
360/*
361 *
362 * key_type_e key size key format
363 * ---------- --------- ----------
364 * 0x00 5, 13, 29 Key data
365 * 0x01 5, 13, 29 Key data
366 * 0x04 16 16 bytes of key data
367 * 0x05 16 16 bytes of key data
368 * 0x0a 32 16 bytes of TKIP key data
369 * 8 bytes of RX MIC key data
370 * 8 bytes of TX MIC key data
371 * 0x0b 32 16 bytes of TKIP key data
372 * 8 bytes of RX MIC key data
373 * 8 bytes of TX MIC key data
374 *
375 */
376
377struct wl1251_cmd_set_keys {
378 struct wl1251_cmd_header header;
379
380 /* Ignored for default WEP key */
381 u8 addr[ETH_ALEN];
382
383 /* key_action_e */
384 u16 key_action;
385
386 u16 reserved_1;
387
388 /* key size in bytes */
389 u8 key_size;
390
391 /* key_type_e */
392 u8 key_type;
393 u8 ssid_profile;
394
395 /*
396 * TKIP, AES: frame's key id field.
397 * For WEP default key: key id;
398 */
399 u8 id;
400 u8 reserved_2[6];
401 u8 key[MAX_KEY_SIZE];
402 u16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
403 u32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
404} __attribute__ ((packed));
405
264 406
265#endif /* __WL12XX_CMD_H__ */ 407#endif /* __WL1251_CMD_H__ */
diff --git a/drivers/net/wireless/wl12xx/debugfs.c b/drivers/net/wireless/wl12xx/wl1251_debugfs.c
index cdb368ce4dae..a00723059f83 100644
--- a/drivers/net/wireless/wl12xx/debugfs.c
+++ b/drivers/net/wireless/wl12xx/wl1251_debugfs.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2009 Nokia Corporation 4 * Copyright (C) 2009 Nokia Corporation
5 * 5 *
@@ -21,15 +21,16 @@
21 * 21 *
22 */ 22 */
23 23
24#include "debugfs.h" 24#include "wl1251_debugfs.h"
25 25
26#include <linux/skbuff.h> 26#include <linux/skbuff.h>
27 27
28#include "wl12xx.h" 28#include "wl1251.h"
29#include "acx.h" 29#include "wl1251_acx.h"
30#include "wl1251_ps.h"
30 31
31/* ms */ 32/* ms */
32#define WL12XX_DEBUGFS_STATS_LIFETIME 1000 33#define WL1251_DEBUGFS_STATS_LIFETIME 1000
33 34
34/* debugfs macros idea from mac80211 */ 35/* debugfs macros idea from mac80211 */
35 36
@@ -37,7 +38,7 @@
37static ssize_t name## _read(struct file *file, char __user *userbuf, \ 38static ssize_t name## _read(struct file *file, char __user *userbuf, \
38 size_t count, loff_t *ppos) \ 39 size_t count, loff_t *ppos) \
39{ \ 40{ \
40 struct wl12xx *wl = file->private_data; \ 41 struct wl1251 *wl = file->private_data; \
41 char buf[buflen]; \ 42 char buf[buflen]; \
42 int res; \ 43 int res; \
43 \ 44 \
@@ -47,7 +48,7 @@ static ssize_t name## _read(struct file *file, char __user *userbuf, \
47 \ 48 \
48static const struct file_operations name## _ops = { \ 49static const struct file_operations name## _ops = { \
49 .read = name## _read, \ 50 .read = name## _read, \
50 .open = wl12xx_open_file_generic, \ 51 .open = wl1251_open_file_generic, \
51}; 52};
52 53
53#define DEBUGFS_ADD(name, parent) \ 54#define DEBUGFS_ADD(name, parent) \
@@ -70,11 +71,11 @@ static ssize_t sub## _ ##name## _read(struct file *file, \
70 char __user *userbuf, \ 71 char __user *userbuf, \
71 size_t count, loff_t *ppos) \ 72 size_t count, loff_t *ppos) \
72{ \ 73{ \
73 struct wl12xx *wl = file->private_data; \ 74 struct wl1251 *wl = file->private_data; \
74 char buf[buflen]; \ 75 char buf[buflen]; \
75 int res; \ 76 int res; \
76 \ 77 \
77 wl12xx_debugfs_update_stats(wl); \ 78 wl1251_debugfs_update_stats(wl); \
78 \ 79 \
79 res = scnprintf(buf, buflen, fmt "\n", \ 80 res = scnprintf(buf, buflen, fmt "\n", \
80 wl->stats.fw_stats->sub.name); \ 81 wl->stats.fw_stats->sub.name); \
@@ -83,7 +84,7 @@ static ssize_t sub## _ ##name## _read(struct file *file, \
83 \ 84 \
84static const struct file_operations sub## _ ##name## _ops = { \ 85static const struct file_operations sub## _ ##name## _ops = { \
85 .read = sub## _ ##name## _read, \ 86 .read = sub## _ ##name## _read, \
86 .open = wl12xx_open_file_generic, \ 87 .open = wl1251_open_file_generic, \
87}; 88};
88 89
89#define DEBUGFS_FWSTATS_ADD(sub, name) \ 90#define DEBUGFS_FWSTATS_ADD(sub, name) \
@@ -92,21 +93,30 @@ static const struct file_operations sub## _ ##name## _ops = { \
92#define DEBUGFS_FWSTATS_DEL(sub, name) \ 93#define DEBUGFS_FWSTATS_DEL(sub, name) \
93 DEBUGFS_DEL(sub## _ ##name) 94 DEBUGFS_DEL(sub## _ ##name)
94 95
95static void wl12xx_debugfs_update_stats(struct wl12xx *wl) 96static void wl1251_debugfs_update_stats(struct wl1251 *wl)
96{ 97{
98 int ret;
99
97 mutex_lock(&wl->mutex); 100 mutex_lock(&wl->mutex);
98 101
99 if (wl->state == WL12XX_STATE_ON && 102 ret = wl1251_ps_elp_wakeup(wl);
103 if (ret < 0)
104 goto out;
105
106 if (wl->state == WL1251_STATE_ON &&
100 time_after(jiffies, wl->stats.fw_stats_update + 107 time_after(jiffies, wl->stats.fw_stats_update +
101 msecs_to_jiffies(WL12XX_DEBUGFS_STATS_LIFETIME))) { 108 msecs_to_jiffies(WL1251_DEBUGFS_STATS_LIFETIME))) {
102 wl12xx_acx_statistics(wl, wl->stats.fw_stats); 109 wl1251_acx_statistics(wl, wl->stats.fw_stats);
103 wl->stats.fw_stats_update = jiffies; 110 wl->stats.fw_stats_update = jiffies;
104 } 111 }
105 112
113 wl1251_ps_elp_sleep(wl);
114
115out:
106 mutex_unlock(&wl->mutex); 116 mutex_unlock(&wl->mutex);
107} 117}
108 118
109static int wl12xx_open_file_generic(struct inode *inode, struct file *file) 119static int wl1251_open_file_generic(struct inode *inode, struct file *file)
110{ 120{
111 file->private_data = inode->i_private; 121 file->private_data = inode->i_private;
112 return 0; 122 return 0;
@@ -211,7 +221,7 @@ DEBUGFS_READONLY_FILE(excessive_retries, 20, "%u",
211static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf, 221static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
212 size_t count, loff_t *ppos) 222 size_t count, loff_t *ppos)
213{ 223{
214 struct wl12xx *wl = file->private_data; 224 struct wl1251 *wl = file->private_data;
215 u32 queue_len; 225 u32 queue_len;
216 char buf[20]; 226 char buf[20];
217 int res; 227 int res;
@@ -224,10 +234,10 @@ static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
224 234
225static const struct file_operations tx_queue_len_ops = { 235static const struct file_operations tx_queue_len_ops = {
226 .read = tx_queue_len_read, 236 .read = tx_queue_len_read,
227 .open = wl12xx_open_file_generic, 237 .open = wl1251_open_file_generic,
228}; 238};
229 239
230static void wl12xx_debugfs_delete_files(struct wl12xx *wl) 240static void wl1251_debugfs_delete_files(struct wl1251 *wl)
231{ 241{
232 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow); 242 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow);
233 243
@@ -325,7 +335,7 @@ static void wl12xx_debugfs_delete_files(struct wl12xx *wl)
325 DEBUGFS_DEL(excessive_retries); 335 DEBUGFS_DEL(excessive_retries);
326} 336}
327 337
328static int wl12xx_debugfs_add_files(struct wl12xx *wl) 338static int wl1251_debugfs_add_files(struct wl1251 *wl)
329{ 339{
330 int ret = 0; 340 int ret = 0;
331 341
@@ -426,19 +436,19 @@ static int wl12xx_debugfs_add_files(struct wl12xx *wl)
426 436
427out: 437out:
428 if (ret < 0) 438 if (ret < 0)
429 wl12xx_debugfs_delete_files(wl); 439 wl1251_debugfs_delete_files(wl);
430 440
431 return ret; 441 return ret;
432} 442}
433 443
434void wl12xx_debugfs_reset(struct wl12xx *wl) 444void wl1251_debugfs_reset(struct wl1251 *wl)
435{ 445{
436 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats)); 446 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
437 wl->stats.retry_count = 0; 447 wl->stats.retry_count = 0;
438 wl->stats.excessive_retries = 0; 448 wl->stats.excessive_retries = 0;
439} 449}
440 450
441int wl12xx_debugfs_init(struct wl12xx *wl) 451int wl1251_debugfs_init(struct wl1251 *wl)
442{ 452{
443 int ret; 453 int ret;
444 454
@@ -469,7 +479,7 @@ int wl12xx_debugfs_init(struct wl12xx *wl)
469 479
470 wl->stats.fw_stats_update = jiffies; 480 wl->stats.fw_stats_update = jiffies;
471 481
472 ret = wl12xx_debugfs_add_files(wl); 482 ret = wl1251_debugfs_add_files(wl);
473 483
474 if (ret < 0) 484 if (ret < 0)
475 goto err_file; 485 goto err_file;
@@ -492,9 +502,9 @@ err:
492 return ret; 502 return ret;
493} 503}
494 504
495void wl12xx_debugfs_exit(struct wl12xx *wl) 505void wl1251_debugfs_exit(struct wl1251 *wl)
496{ 506{
497 wl12xx_debugfs_delete_files(wl); 507 wl1251_debugfs_delete_files(wl);
498 508
499 kfree(wl->stats.fw_stats); 509 kfree(wl->stats.fw_stats);
500 wl->stats.fw_stats = NULL; 510 wl->stats.fw_stats = NULL;
diff --git a/drivers/net/wireless/wl12xx/debugfs.h b/drivers/net/wireless/wl12xx/wl1251_debugfs.h
index 562cdcbcc874..6dc3d080853c 100644
--- a/drivers/net/wireless/wl12xx/debugfs.h
+++ b/drivers/net/wireless/wl12xx/wl1251_debugfs.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2009 Nokia Corporation 4 * Copyright (C) 2009 Nokia Corporation
5 * 5 *
@@ -21,13 +21,13 @@
21 * 21 *
22 */ 22 */
23 23
24#ifndef WL12XX_DEBUGFS_H 24#ifndef WL1251_DEBUGFS_H
25#define WL12XX_DEBUGFS_H 25#define WL1251_DEBUGFS_H
26 26
27#include "wl12xx.h" 27#include "wl1251.h"
28 28
29int wl12xx_debugfs_init(struct wl12xx *wl); 29int wl1251_debugfs_init(struct wl1251 *wl);
30void wl12xx_debugfs_exit(struct wl12xx *wl); 30void wl1251_debugfs_exit(struct wl1251 *wl);
31void wl12xx_debugfs_reset(struct wl12xx *wl); 31void wl1251_debugfs_reset(struct wl1251 *wl);
32 32
33#endif /* WL12XX_DEBUGFS_H */ 33#endif /* WL1251_DEBUGFS_H */
diff --git a/drivers/net/wireless/wl12xx/event.c b/drivers/net/wireless/wl12xx/wl1251_event.c
index 99529ca89a7e..1a0a0bc1a31f 100644
--- a/drivers/net/wireless/wl12xx/event.c
+++ b/drivers/net/wireless/wl12xx/wl1251_event.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated 4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation 5 * Copyright (C) 2008 Nokia Corporation
@@ -22,16 +22,16 @@
22 * 22 *
23 */ 23 */
24 24
25#include "wl12xx.h" 25#include "wl1251.h"
26#include "reg.h" 26#include "reg.h"
27#include "spi.h" 27#include "wl1251_spi.h"
28#include "event.h" 28#include "wl1251_event.h"
29#include "ps.h" 29#include "wl1251_ps.h"
30 30
31static int wl12xx_event_scan_complete(struct wl12xx *wl, 31static int wl1251_event_scan_complete(struct wl1251 *wl,
32 struct event_mailbox *mbox) 32 struct event_mailbox *mbox)
33{ 33{
34 wl12xx_debug(DEBUG_EVENT, "status: 0x%x, channels: %d", 34 wl1251_debug(DEBUG_EVENT, "status: 0x%x, channels: %d",
35 mbox->scheduled_scan_status, 35 mbox->scheduled_scan_status,
36 mbox->scheduled_scan_channels); 36 mbox->scheduled_scan_channels);
37 37
@@ -45,34 +45,34 @@ static int wl12xx_event_scan_complete(struct wl12xx *wl,
45 return 0; 45 return 0;
46} 46}
47 47
48static void wl12xx_event_mbox_dump(struct event_mailbox *mbox) 48static void wl1251_event_mbox_dump(struct event_mailbox *mbox)
49{ 49{
50 wl12xx_debug(DEBUG_EVENT, "MBOX DUMP:"); 50 wl1251_debug(DEBUG_EVENT, "MBOX DUMP:");
51 wl12xx_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector); 51 wl1251_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
52 wl12xx_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask); 52 wl1251_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
53} 53}
54 54
55static int wl12xx_event_process(struct wl12xx *wl, struct event_mailbox *mbox) 55static int wl1251_event_process(struct wl1251 *wl, struct event_mailbox *mbox)
56{ 56{
57 int ret; 57 int ret;
58 u32 vector; 58 u32 vector;
59 59
60 wl12xx_event_mbox_dump(mbox); 60 wl1251_event_mbox_dump(mbox);
61 61
62 vector = mbox->events_vector & ~(mbox->events_mask); 62 vector = mbox->events_vector & ~(mbox->events_mask);
63 wl12xx_debug(DEBUG_EVENT, "vector: 0x%x", vector); 63 wl1251_debug(DEBUG_EVENT, "vector: 0x%x", vector);
64 64
65 if (vector & SCAN_COMPLETE_EVENT_ID) { 65 if (vector & SCAN_COMPLETE_EVENT_ID) {
66 ret = wl12xx_event_scan_complete(wl, mbox); 66 ret = wl1251_event_scan_complete(wl, mbox);
67 if (ret < 0) 67 if (ret < 0)
68 return ret; 68 return ret;
69 } 69 }
70 70
71 if (vector & BSS_LOSE_EVENT_ID) { 71 if (vector & BSS_LOSE_EVENT_ID) {
72 wl12xx_debug(DEBUG_EVENT, "BSS_LOSE_EVENT"); 72 wl1251_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
73 73
74 if (wl->psm_requested && wl->psm) { 74 if (wl->psm_requested && wl->psm) {
75 ret = wl12xx_ps_set_mode(wl, STATION_ACTIVE_MODE); 75 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
76 if (ret < 0) 76 if (ret < 0)
77 return ret; 77 return ret;
78 } 78 }
@@ -81,47 +81,47 @@ static int wl12xx_event_process(struct wl12xx *wl, struct event_mailbox *mbox)
81 return 0; 81 return 0;
82} 82}
83 83
84int wl12xx_event_unmask(struct wl12xx *wl) 84int wl1251_event_unmask(struct wl1251 *wl)
85{ 85{
86 int ret; 86 int ret;
87 87
88 ret = wl12xx_acx_event_mbox_mask(wl, ~(wl->event_mask)); 88 ret = wl1251_acx_event_mbox_mask(wl, ~(wl->event_mask));
89 if (ret < 0) 89 if (ret < 0)
90 return ret; 90 return ret;
91 91
92 return 0; 92 return 0;
93} 93}
94 94
95void wl12xx_event_mbox_config(struct wl12xx *wl) 95void wl1251_event_mbox_config(struct wl1251 *wl)
96{ 96{
97 wl->mbox_ptr[0] = wl12xx_reg_read32(wl, REG_EVENT_MAILBOX_PTR); 97 wl->mbox_ptr[0] = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
98 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox); 98 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
99 99
100 wl12xx_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x", 100 wl1251_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
101 wl->mbox_ptr[0], wl->mbox_ptr[1]); 101 wl->mbox_ptr[0], wl->mbox_ptr[1]);
102} 102}
103 103
104int wl12xx_event_handle(struct wl12xx *wl, u8 mbox_num) 104int wl1251_event_handle(struct wl1251 *wl, u8 mbox_num)
105{ 105{
106 struct event_mailbox mbox; 106 struct event_mailbox mbox;
107 int ret; 107 int ret;
108 108
109 wl12xx_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num); 109 wl1251_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
110 110
111 if (mbox_num > 1) 111 if (mbox_num > 1)
112 return -EINVAL; 112 return -EINVAL;
113 113
114 /* first we read the mbox descriptor */ 114 /* first we read the mbox descriptor */
115 wl12xx_spi_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox, 115 wl1251_spi_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox,
116 sizeof(struct event_mailbox)); 116 sizeof(struct event_mailbox));
117 117
118 /* process the descriptor */ 118 /* process the descriptor */
119 ret = wl12xx_event_process(wl, &mbox); 119 ret = wl1251_event_process(wl, &mbox);
120 if (ret < 0) 120 if (ret < 0)
121 return ret; 121 return ret;
122 122
123 /* then we let the firmware know it can go on...*/ 123 /* then we let the firmware know it can go on...*/
124 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK); 124 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
125 125
126 return 0; 126 return 0;
127} 127}
diff --git a/drivers/net/wireless/wl12xx/event.h b/drivers/net/wireless/wl12xx/wl1251_event.h
index 1f4c2f7438a7..be0ac54d6246 100644
--- a/drivers/net/wireless/wl12xx/event.h
+++ b/drivers/net/wireless/wl12xx/wl1251_event.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated 4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation 5 * Copyright (C) 2008 Nokia Corporation
@@ -22,8 +22,8 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL12XX_EVENT_H__ 25#ifndef __WL1251_EVENT_H__
26#define __WL12XX_EVENT_H__ 26#define __WL1251_EVENT_H__
27 27
28/* 28/*
29 * Mbox events 29 * Mbox events
@@ -114,8 +114,8 @@ struct event_mailbox {
114 u8 padding[19]; 114 u8 padding[19];
115} __attribute__ ((packed)); 115} __attribute__ ((packed));
116 116
117int wl12xx_event_unmask(struct wl12xx *wl); 117int wl1251_event_unmask(struct wl1251 *wl);
118void wl12xx_event_mbox_config(struct wl12xx *wl); 118void wl1251_event_mbox_config(struct wl1251 *wl);
119int wl12xx_event_handle(struct wl12xx *wl, u8 mbox); 119int wl1251_event_handle(struct wl1251 *wl, u8 mbox);
120 120
121#endif 121#endif
diff --git a/drivers/net/wireless/wl12xx/init.c b/drivers/net/wireless/wl12xx/wl1251_init.c
index 2a573a6010bd..df6c60f0fd66 100644
--- a/drivers/net/wireless/wl12xx/init.c
+++ b/drivers/net/wireless/wl12xx/wl1251_init.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2009 Nokia Corporation 4 * Copyright (C) 2009 Nokia Corporation
5 * 5 *
@@ -24,64 +24,64 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/module.h> 25#include <linux/module.h>
26 26
27#include "init.h" 27#include "wl1251_init.h"
28#include "wl12xx_80211.h" 28#include "wl12xx_80211.h"
29#include "acx.h" 29#include "wl1251_acx.h"
30#include "cmd.h" 30#include "wl1251_cmd.h"
31 31
32int wl12xx_hw_init_hwenc_config(struct wl12xx *wl) 32int wl1251_hw_init_hwenc_config(struct wl1251 *wl)
33{ 33{
34 int ret; 34 int ret;
35 35
36 ret = wl12xx_acx_feature_cfg(wl); 36 ret = wl1251_acx_feature_cfg(wl);
37 if (ret < 0) { 37 if (ret < 0) {
38 wl12xx_warning("couldn't set feature config"); 38 wl1251_warning("couldn't set feature config");
39 return ret; 39 return ret;
40 } 40 }
41 41
42 ret = wl12xx_acx_default_key(wl, wl->default_key); 42 ret = wl1251_acx_default_key(wl, wl->default_key);
43 if (ret < 0) { 43 if (ret < 0) {
44 wl12xx_warning("couldn't set default key"); 44 wl1251_warning("couldn't set default key");
45 return ret; 45 return ret;
46 } 46 }
47 47
48 return 0; 48 return 0;
49} 49}
50 50
51int wl12xx_hw_init_templates_config(struct wl12xx *wl) 51int wl1251_hw_init_templates_config(struct wl1251 *wl)
52{ 52{
53 int ret; 53 int ret;
54 u8 partial_vbm[PARTIAL_VBM_MAX]; 54 u8 partial_vbm[PARTIAL_VBM_MAX];
55 55
56 /* send empty templates for fw memory reservation */ 56 /* send empty templates for fw memory reservation */
57 ret = wl12xx_cmd_template_set(wl, CMD_PROBE_REQ, NULL, 57 ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
58 sizeof(struct wl12xx_probe_req_template)); 58 sizeof(struct wl12xx_probe_req_template));
59 if (ret < 0) 59 if (ret < 0)
60 return ret; 60 return ret;
61 61
62 ret = wl12xx_cmd_template_set(wl, CMD_NULL_DATA, NULL, 62 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
63 sizeof(struct wl12xx_null_data_template)); 63 sizeof(struct wl12xx_null_data_template));
64 if (ret < 0) 64 if (ret < 0)
65 return ret; 65 return ret;
66 66
67 ret = wl12xx_cmd_template_set(wl, CMD_PS_POLL, NULL, 67 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
68 sizeof(struct wl12xx_ps_poll_template)); 68 sizeof(struct wl12xx_ps_poll_template));
69 if (ret < 0) 69 if (ret < 0)
70 return ret; 70 return ret;
71 71
72 ret = wl12xx_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL, 72 ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
73 sizeof 73 sizeof
74 (struct wl12xx_qos_null_data_template)); 74 (struct wl12xx_qos_null_data_template));
75 if (ret < 0) 75 if (ret < 0)
76 return ret; 76 return ret;
77 77
78 ret = wl12xx_cmd_template_set(wl, CMD_PROBE_RESP, NULL, 78 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
79 sizeof 79 sizeof
80 (struct wl12xx_probe_resp_template)); 80 (struct wl12xx_probe_resp_template));
81 if (ret < 0) 81 if (ret < 0)
82 return ret; 82 return ret;
83 83
84 ret = wl12xx_cmd_template_set(wl, CMD_BEACON, NULL, 84 ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
85 sizeof 85 sizeof
86 (struct wl12xx_beacon_template)); 86 (struct wl12xx_beacon_template));
87 if (ret < 0) 87 if (ret < 0)
@@ -89,112 +89,112 @@ int wl12xx_hw_init_templates_config(struct wl12xx *wl)
89 89
90 /* tim templates, first reserve space then allocate an empty one */ 90 /* tim templates, first reserve space then allocate an empty one */
91 memset(partial_vbm, 0, PARTIAL_VBM_MAX); 91 memset(partial_vbm, 0, PARTIAL_VBM_MAX);
92 ret = wl12xx_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0); 92 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
93 if (ret < 0) 93 if (ret < 0)
94 return ret; 94 return ret;
95 95
96 ret = wl12xx_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0); 96 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
97 if (ret < 0) 97 if (ret < 0)
98 return ret; 98 return ret;
99 99
100 return 0; 100 return 0;
101} 101}
102 102
103int wl12xx_hw_init_rx_config(struct wl12xx *wl, u32 config, u32 filter) 103int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
104{ 104{
105 int ret; 105 int ret;
106 106
107 ret = wl12xx_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF); 107 ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
108 if (ret < 0) 108 if (ret < 0)
109 return ret; 109 return ret;
110 110
111 ret = wl12xx_acx_rx_config(wl, config, filter); 111 ret = wl1251_acx_rx_config(wl, config, filter);
112 if (ret < 0) 112 if (ret < 0)
113 return ret; 113 return ret;
114 114
115 return 0; 115 return 0;
116} 116}
117 117
118int wl12xx_hw_init_phy_config(struct wl12xx *wl) 118int wl1251_hw_init_phy_config(struct wl1251 *wl)
119{ 119{
120 int ret; 120 int ret;
121 121
122 ret = wl12xx_acx_pd_threshold(wl); 122 ret = wl1251_acx_pd_threshold(wl);
123 if (ret < 0) 123 if (ret < 0)
124 return ret; 124 return ret;
125 125
126 ret = wl12xx_acx_slot(wl, DEFAULT_SLOT_TIME); 126 ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
127 if (ret < 0) 127 if (ret < 0)
128 return ret; 128 return ret;
129 129
130 ret = wl12xx_acx_group_address_tbl(wl); 130 ret = wl1251_acx_group_address_tbl(wl);
131 if (ret < 0) 131 if (ret < 0)
132 return ret; 132 return ret;
133 133
134 ret = wl12xx_acx_service_period_timeout(wl); 134 ret = wl1251_acx_service_period_timeout(wl);
135 if (ret < 0) 135 if (ret < 0)
136 return ret; 136 return ret;
137 137
138 ret = wl12xx_acx_rts_threshold(wl, RTS_THRESHOLD_DEF); 138 ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
139 if (ret < 0) 139 if (ret < 0)
140 return ret; 140 return ret;
141 141
142 return 0; 142 return 0;
143} 143}
144 144
145int wl12xx_hw_init_beacon_filter(struct wl12xx *wl) 145int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
146{ 146{
147 int ret; 147 int ret;
148 148
149 ret = wl12xx_acx_beacon_filter_opt(wl); 149 ret = wl1251_acx_beacon_filter_opt(wl);
150 if (ret < 0) 150 if (ret < 0)
151 return ret; 151 return ret;
152 152
153 ret = wl12xx_acx_beacon_filter_table(wl); 153 ret = wl1251_acx_beacon_filter_table(wl);
154 if (ret < 0) 154 if (ret < 0)
155 return ret; 155 return ret;
156 156
157 return 0; 157 return 0;
158} 158}
159 159
160int wl12xx_hw_init_pta(struct wl12xx *wl) 160int wl1251_hw_init_pta(struct wl1251 *wl)
161{ 161{
162 int ret; 162 int ret;
163 163
164 ret = wl12xx_acx_sg_enable(wl); 164 ret = wl1251_acx_sg_enable(wl);
165 if (ret < 0) 165 if (ret < 0)
166 return ret; 166 return ret;
167 167
168 ret = wl12xx_acx_sg_cfg(wl); 168 ret = wl1251_acx_sg_cfg(wl);
169 if (ret < 0) 169 if (ret < 0)
170 return ret; 170 return ret;
171 171
172 return 0; 172 return 0;
173} 173}
174 174
175int wl12xx_hw_init_energy_detection(struct wl12xx *wl) 175int wl1251_hw_init_energy_detection(struct wl1251 *wl)
176{ 176{
177 int ret; 177 int ret;
178 178
179 ret = wl12xx_acx_cca_threshold(wl); 179 ret = wl1251_acx_cca_threshold(wl);
180 if (ret < 0) 180 if (ret < 0)
181 return ret; 181 return ret;
182 182
183 return 0; 183 return 0;
184} 184}
185 185
186int wl12xx_hw_init_beacon_broadcast(struct wl12xx *wl) 186int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
187{ 187{
188 int ret; 188 int ret;
189 189
190 ret = wl12xx_acx_bcn_dtim_options(wl); 190 ret = wl1251_acx_bcn_dtim_options(wl);
191 if (ret < 0) 191 if (ret < 0)
192 return ret; 192 return ret;
193 193
194 return 0; 194 return 0;
195} 195}
196 196
197int wl12xx_hw_init_power_auth(struct wl12xx *wl) 197int wl1251_hw_init_power_auth(struct wl1251 *wl)
198{ 198{
199 return wl12xx_acx_sleep_auth(wl, WL12XX_PSM_CAM); 199 return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
200} 200}
diff --git a/drivers/net/wireless/wl12xx/init.h b/drivers/net/wireless/wl12xx/wl1251_init.h
index c8b6cd0b7c3e..8596188e834e 100644
--- a/drivers/net/wireless/wl12xx/init.h
+++ b/drivers/net/wireless/wl12xx/wl1251_init.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2009 Nokia Corporation 4 * Copyright (C) 2009 Nokia Corporation
5 * 5 *
@@ -21,20 +21,19 @@
21 * 21 *
22 */ 22 */
23 23
24#ifndef __WL12XX_INIT_H__ 24#ifndef __WL1251_INIT_H__
25#define __WL12XX_INIT_H__ 25#define __WL1251_INIT_H__
26 26
27#include "wl12xx.h" 27#include "wl1251.h"
28 28
29int wl12xx_hw_init_hwenc_config(struct wl12xx *wl); 29int wl1251_hw_init_hwenc_config(struct wl1251 *wl);
30int wl12xx_hw_init_templates_config(struct wl12xx *wl); 30int wl1251_hw_init_templates_config(struct wl1251 *wl);
31int wl12xx_hw_init_mem_config(struct wl12xx *wl); 31int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter);
32int wl12xx_hw_init_rx_config(struct wl12xx *wl, u32 config, u32 filter); 32int wl1251_hw_init_phy_config(struct wl1251 *wl);
33int wl12xx_hw_init_phy_config(struct wl12xx *wl); 33int wl1251_hw_init_beacon_filter(struct wl1251 *wl);
34int wl12xx_hw_init_beacon_filter(struct wl12xx *wl); 34int wl1251_hw_init_pta(struct wl1251 *wl);
35int wl12xx_hw_init_pta(struct wl12xx *wl); 35int wl1251_hw_init_energy_detection(struct wl1251 *wl);
36int wl12xx_hw_init_energy_detection(struct wl12xx *wl); 36int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl);
37int wl12xx_hw_init_beacon_broadcast(struct wl12xx *wl); 37int wl1251_hw_init_power_auth(struct wl1251 *wl);
38int wl12xx_hw_init_power_auth(struct wl12xx *wl);
39 38
40#endif 39#endif
diff --git a/drivers/net/wireless/wl12xx/main.c b/drivers/net/wireless/wl12xx/wl1251_main.c
index 603d6114882e..cf5e0549fa14 100644
--- a/drivers/net/wireless/wl12xx/main.c
+++ b/drivers/net/wireless/wl12xx/wl1251_main.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2008-2009 Nokia Corporation 4 * Copyright (C) 2008-2009 Nokia Corporation
5 * 5 *
@@ -31,38 +31,38 @@
31#include <linux/etherdevice.h> 31#include <linux/etherdevice.h>
32#include <linux/spi/wl12xx.h> 32#include <linux/spi/wl12xx.h>
33 33
34#include "wl12xx.h" 34#include "wl1251.h"
35#include "wl12xx_80211.h" 35#include "wl12xx_80211.h"
36#include "reg.h" 36#include "reg.h"
37#include "wl1251.h" 37#include "wl1251_ops.h"
38#include "spi.h" 38#include "wl1251_spi.h"
39#include "event.h" 39#include "wl1251_event.h"
40#include "tx.h" 40#include "wl1251_tx.h"
41#include "rx.h" 41#include "wl1251_rx.h"
42#include "ps.h" 42#include "wl1251_ps.h"
43#include "init.h" 43#include "wl1251_init.h"
44#include "debugfs.h" 44#include "wl1251_debugfs.h"
45 45
46static void wl12xx_disable_interrupts(struct wl12xx *wl) 46static void wl1251_disable_interrupts(struct wl1251 *wl)
47{ 47{
48 disable_irq(wl->irq); 48 disable_irq(wl->irq);
49} 49}
50 50
51static void wl12xx_power_off(struct wl12xx *wl) 51static void wl1251_power_off(struct wl1251 *wl)
52{ 52{
53 wl->set_power(false); 53 wl->set_power(false);
54} 54}
55 55
56static void wl12xx_power_on(struct wl12xx *wl) 56static void wl1251_power_on(struct wl1251 *wl)
57{ 57{
58 wl->set_power(true); 58 wl->set_power(true);
59} 59}
60 60
61static irqreturn_t wl12xx_irq(int irq, void *cookie) 61static irqreturn_t wl1251_irq(int irq, void *cookie)
62{ 62{
63 struct wl12xx *wl; 63 struct wl1251 *wl;
64 64
65 wl12xx_debug(DEBUG_IRQ, "IRQ"); 65 wl1251_debug(DEBUG_IRQ, "IRQ");
66 66
67 wl = cookie; 67 wl = cookie;
68 68
@@ -71,7 +71,7 @@ static irqreturn_t wl12xx_irq(int irq, void *cookie)
71 return IRQ_HANDLED; 71 return IRQ_HANDLED;
72} 72}
73 73
74static int wl12xx_fetch_firmware(struct wl12xx *wl) 74static int wl1251_fetch_firmware(struct wl1251 *wl)
75{ 75{
76 const struct firmware *fw; 76 const struct firmware *fw;
77 int ret; 77 int ret;
@@ -79,12 +79,12 @@ static int wl12xx_fetch_firmware(struct wl12xx *wl)
79 ret = request_firmware(&fw, wl->chip.fw_filename, &wl->spi->dev); 79 ret = request_firmware(&fw, wl->chip.fw_filename, &wl->spi->dev);
80 80
81 if (ret < 0) { 81 if (ret < 0) {
82 wl12xx_error("could not get firmware: %d", ret); 82 wl1251_error("could not get firmware: %d", ret);
83 return ret; 83 return ret;
84 } 84 }
85 85
86 if (fw->size % 4) { 86 if (fw->size % 4) {
87 wl12xx_error("firmware size is not multiple of 32 bits: %zu", 87 wl1251_error("firmware size is not multiple of 32 bits: %zu",
88 fw->size); 88 fw->size);
89 ret = -EILSEQ; 89 ret = -EILSEQ;
90 goto out; 90 goto out;
@@ -94,7 +94,7 @@ static int wl12xx_fetch_firmware(struct wl12xx *wl)
94 wl->fw = kmalloc(wl->fw_len, GFP_KERNEL); 94 wl->fw = kmalloc(wl->fw_len, GFP_KERNEL);
95 95
96 if (!wl->fw) { 96 if (!wl->fw) {
97 wl12xx_error("could not allocate memory for the firmware"); 97 wl1251_error("could not allocate memory for the firmware");
98 ret = -ENOMEM; 98 ret = -ENOMEM;
99 goto out; 99 goto out;
100 } 100 }
@@ -109,7 +109,7 @@ out:
109 return ret; 109 return ret;
110} 110}
111 111
112static int wl12xx_fetch_nvs(struct wl12xx *wl) 112static int wl1251_fetch_nvs(struct wl1251 *wl)
113{ 113{
114 const struct firmware *fw; 114 const struct firmware *fw;
115 int ret; 115 int ret;
@@ -117,12 +117,12 @@ static int wl12xx_fetch_nvs(struct wl12xx *wl)
117 ret = request_firmware(&fw, wl->chip.nvs_filename, &wl->spi->dev); 117 ret = request_firmware(&fw, wl->chip.nvs_filename, &wl->spi->dev);
118 118
119 if (ret < 0) { 119 if (ret < 0) {
120 wl12xx_error("could not get nvs file: %d", ret); 120 wl1251_error("could not get nvs file: %d", ret);
121 return ret; 121 return ret;
122 } 122 }
123 123
124 if (fw->size % 4) { 124 if (fw->size % 4) {
125 wl12xx_error("nvs size is not multiple of 32 bits: %zu", 125 wl1251_error("nvs size is not multiple of 32 bits: %zu",
126 fw->size); 126 fw->size);
127 ret = -EILSEQ; 127 ret = -EILSEQ;
128 goto out; 128 goto out;
@@ -132,7 +132,7 @@ static int wl12xx_fetch_nvs(struct wl12xx *wl)
132 wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL); 132 wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
133 133
134 if (!wl->nvs) { 134 if (!wl->nvs) {
135 wl12xx_error("could not allocate memory for the nvs file"); 135 wl1251_error("could not allocate memory for the nvs file");
136 ret = -ENOMEM; 136 ret = -ENOMEM;
137 goto out; 137 goto out;
138 } 138 }
@@ -147,74 +147,70 @@ out:
147 return ret; 147 return ret;
148} 148}
149 149
150static void wl12xx_fw_wakeup(struct wl12xx *wl) 150static void wl1251_fw_wakeup(struct wl1251 *wl)
151{ 151{
152 u32 elp_reg; 152 u32 elp_reg;
153 153
154 elp_reg = ELPCTRL_WAKE_UP; 154 elp_reg = ELPCTRL_WAKE_UP;
155 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg); 155 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
156 elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); 156 elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
157 157
158 if (!(elp_reg & ELPCTRL_WLAN_READY)) { 158 if (!(elp_reg & ELPCTRL_WLAN_READY))
159 wl12xx_warning("WLAN not ready"); 159 wl1251_warning("WLAN not ready");
160 elp_reg = ELPCTRL_WAKE_UP_WLAN_READY;
161 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
162 }
163} 160}
164 161
165static int wl12xx_chip_wakeup(struct wl12xx *wl) 162static int wl1251_chip_wakeup(struct wl1251 *wl)
166{ 163{
167 int ret = 0; 164 int ret = 0;
168 165
169 wl12xx_power_on(wl); 166 wl1251_power_on(wl);
170 msleep(wl->chip.power_on_sleep); 167 msleep(wl->chip.power_on_sleep);
171 wl12xx_spi_reset(wl); 168 wl1251_spi_reset(wl);
172 wl12xx_spi_init(wl); 169 wl1251_spi_init(wl);
173 170
174 /* We don't need a real memory partition here, because we only want 171 /* We don't need a real memory partition here, because we only want
175 * to use the registers at this point. */ 172 * to use the registers at this point. */
176 wl12xx_set_partition(wl, 173 wl1251_set_partition(wl,
177 0x00000000, 174 0x00000000,
178 0x00000000, 175 0x00000000,
179 REGISTERS_BASE, 176 REGISTERS_BASE,
180 REGISTERS_DOWN_SIZE); 177 REGISTERS_DOWN_SIZE);
181 178
182 /* ELP module wake up */ 179 /* ELP module wake up */
183 wl12xx_fw_wakeup(wl); 180 wl1251_fw_wakeup(wl);
184 181
185 /* whal_FwCtrl_BootSm() */ 182 /* whal_FwCtrl_BootSm() */
186 183
187 /* 0. read chip id from CHIP_ID */ 184 /* 0. read chip id from CHIP_ID */
188 wl->chip.id = wl12xx_reg_read32(wl, CHIP_ID_B); 185 wl->chip.id = wl1251_reg_read32(wl, CHIP_ID_B);
189 186
190 /* 1. check if chip id is valid */ 187 /* 1. check if chip id is valid */
191 188
192 switch (wl->chip.id) { 189 switch (wl->chip.id) {
193 case CHIP_ID_1251_PG12: 190 case CHIP_ID_1251_PG12:
194 wl12xx_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)", 191 wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
195 wl->chip.id); 192 wl->chip.id);
196 193
197 wl1251_setup(wl); 194 wl1251_setup(wl);
198 195
199 break; 196 break;
200 case CHIP_ID_1271_PG10:
201 case CHIP_ID_1251_PG10: 197 case CHIP_ID_1251_PG10:
202 case CHIP_ID_1251_PG11: 198 case CHIP_ID_1251_PG11:
203 default: 199 default:
204 wl12xx_error("unsupported chip id: 0x%x", wl->chip.id); 200 wl1251_error("unsupported chip id: 0x%x", wl->chip.id);
205 ret = -ENODEV; 201 ret = -ENODEV;
206 goto out; 202 goto out;
207 } 203 }
208 204
209 if (wl->fw == NULL) { 205 if (wl->fw == NULL) {
210 ret = wl12xx_fetch_firmware(wl); 206 ret = wl1251_fetch_firmware(wl);
211 if (ret < 0) 207 if (ret < 0)
212 goto out; 208 goto out;
213 } 209 }
214 210
215 /* No NVS from netlink, try to get it from the filesystem */ 211 /* No NVS from netlink, try to get it from the filesystem */
216 if (wl->nvs == NULL) { 212 if (wl->nvs == NULL) {
217 ret = wl12xx_fetch_nvs(wl); 213 ret = wl1251_fetch_nvs(wl);
218 if (ret < 0) 214 if (ret < 0)
219 goto out; 215 goto out;
220 } 216 }
@@ -223,40 +219,50 @@ out:
223 return ret; 219 return ret;
224} 220}
225 221
226static void wl12xx_filter_work(struct work_struct *work) 222static void wl1251_filter_work(struct work_struct *work)
227{ 223{
228 struct wl12xx *wl = 224 struct wl1251 *wl =
229 container_of(work, struct wl12xx, filter_work); 225 container_of(work, struct wl1251, filter_work);
230 int ret; 226 int ret;
231 227
232 mutex_lock(&wl->mutex); 228 mutex_lock(&wl->mutex);
233 229
234 if (wl->state == WL12XX_STATE_OFF) 230 if (wl->state == WL1251_STATE_OFF)
235 goto out; 231 goto out;
236 232
237 ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0); 233 ret = wl1251_ps_elp_wakeup(wl);
238 if (ret < 0) 234 if (ret < 0)
239 goto out; 235 goto out;
240 236
237 /* FIXME: replace the magic numbers with proper definitions */
238 ret = wl->chip.op_cmd_join(wl, wl->bss_type, 1, 100, 0);
239 if (ret < 0)
240 goto out_sleep;
241
242out_sleep:
243 wl1251_ps_elp_sleep(wl);
244
241out: 245out:
242 mutex_unlock(&wl->mutex); 246 mutex_unlock(&wl->mutex);
243} 247}
244 248
245int wl12xx_plt_start(struct wl12xx *wl) 249int wl1251_plt_start(struct wl1251 *wl)
246{ 250{
247 int ret; 251 int ret;
248 252
249 wl12xx_notice("power up"); 253 mutex_lock(&wl->mutex);
254
255 wl1251_notice("power up");
250 256
251 if (wl->state != WL12XX_STATE_OFF) { 257 if (wl->state != WL1251_STATE_OFF) {
252 wl12xx_error("cannot go into PLT state because not " 258 wl1251_error("cannot go into PLT state because not "
253 "in off state: %d", wl->state); 259 "in off state: %d", wl->state);
254 return -EBUSY; 260 return -EBUSY;
255 } 261 }
256 262
257 wl->state = WL12XX_STATE_PLT; 263 wl->state = WL1251_STATE_PLT;
258 264
259 ret = wl12xx_chip_wakeup(wl); 265 ret = wl1251_chip_wakeup(wl);
260 if (ret < 0) 266 if (ret < 0)
261 return ret; 267 return ret;
262 268
@@ -264,7 +270,7 @@ int wl12xx_plt_start(struct wl12xx *wl)
264 if (ret < 0) 270 if (ret < 0)
265 return ret; 271 return ret;
266 272
267 wl12xx_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver); 273 wl1251_notice("firmware booted in PLT mode (%s)", wl->chip.fw_ver);
268 274
269 ret = wl->chip.op_plt_init(wl); 275 ret = wl->chip.op_plt_init(wl);
270 if (ret < 0) 276 if (ret < 0)
@@ -273,38 +279,45 @@ int wl12xx_plt_start(struct wl12xx *wl)
273 return 0; 279 return 0;
274} 280}
275 281
276int wl12xx_plt_stop(struct wl12xx *wl) 282int wl1251_plt_stop(struct wl1251 *wl)
277{ 283{
278 wl12xx_notice("power down"); 284 mutex_lock(&wl->mutex);
285
286 wl1251_notice("power down");
279 287
280 if (wl->state != WL12XX_STATE_PLT) { 288 if (wl->state != WL1251_STATE_PLT) {
281 wl12xx_error("cannot power down because not in PLT " 289 wl1251_error("cannot power down because not in PLT "
282 "state: %d", wl->state); 290 "state: %d", wl->state);
283 return -EBUSY; 291 return -EBUSY;
284 } 292 }
285 293
286 wl12xx_disable_interrupts(wl); 294 wl1251_disable_interrupts(wl);
287 wl12xx_power_off(wl); 295 wl1251_power_off(wl);
288 296
289 wl->state = WL12XX_STATE_OFF; 297 wl->state = WL1251_STATE_OFF;
290 298
291 return 0; 299 return 0;
292} 300}
293 301
294 302
295static int wl12xx_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 303static int wl1251_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
296{ 304{
297 struct wl12xx *wl = hw->priv; 305 struct wl1251 *wl = hw->priv;
298 306
299 skb_queue_tail(&wl->tx_queue, skb); 307 skb_queue_tail(&wl->tx_queue, skb);
300 308
309 /*
310 * The chip specific setup must run before the first TX packet -
311 * before that, the tx_work will not be initialized!
312 */
313
301 schedule_work(&wl->tx_work); 314 schedule_work(&wl->tx_work);
302 315
303 /* 316 /*
304 * The workqueue is slow to process the tx_queue and we need stop 317 * The workqueue is slow to process the tx_queue and we need stop
305 * the queue here, otherwise the queue will get too long. 318 * the queue here, otherwise the queue will get too long.
306 */ 319 */
307 if (skb_queue_len(&wl->tx_queue) >= WL12XX_TX_QUEUE_MAX_LENGTH) { 320 if (skb_queue_len(&wl->tx_queue) >= WL1251_TX_QUEUE_MAX_LENGTH) {
308 ieee80211_stop_queues(wl->hw); 321 ieee80211_stop_queues(wl->hw);
309 322
310 /* 323 /*
@@ -318,23 +331,23 @@ static int wl12xx_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
318 return NETDEV_TX_OK; 331 return NETDEV_TX_OK;
319} 332}
320 333
321static int wl12xx_op_start(struct ieee80211_hw *hw) 334static int wl1251_op_start(struct ieee80211_hw *hw)
322{ 335{
323 struct wl12xx *wl = hw->priv; 336 struct wl1251 *wl = hw->priv;
324 int ret = 0; 337 int ret = 0;
325 338
326 wl12xx_debug(DEBUG_MAC80211, "mac80211 start"); 339 wl1251_debug(DEBUG_MAC80211, "mac80211 start");
327 340
328 mutex_lock(&wl->mutex); 341 mutex_lock(&wl->mutex);
329 342
330 if (wl->state != WL12XX_STATE_OFF) { 343 if (wl->state != WL1251_STATE_OFF) {
331 wl12xx_error("cannot start because not in off state: %d", 344 wl1251_error("cannot start because not in off state: %d",
332 wl->state); 345 wl->state);
333 ret = -EBUSY; 346 ret = -EBUSY;
334 goto out; 347 goto out;
335 } 348 }
336 349
337 ret = wl12xx_chip_wakeup(wl); 350 ret = wl1251_chip_wakeup(wl);
338 if (ret < 0) 351 if (ret < 0)
339 return ret; 352 return ret;
340 353
@@ -346,34 +359,34 @@ static int wl12xx_op_start(struct ieee80211_hw *hw)
346 if (ret < 0) 359 if (ret < 0)
347 goto out; 360 goto out;
348 361
349 ret = wl12xx_acx_station_id(wl); 362 ret = wl1251_acx_station_id(wl);
350 if (ret < 0) 363 if (ret < 0)
351 goto out; 364 goto out;
352 365
353 wl->state = WL12XX_STATE_ON; 366 wl->state = WL1251_STATE_ON;
354 367
355 wl12xx_info("firmware booted (%s)", wl->chip.fw_ver); 368 wl1251_info("firmware booted (%s)", wl->chip.fw_ver);
356 369
357out: 370out:
358 if (ret < 0) 371 if (ret < 0)
359 wl12xx_power_off(wl); 372 wl1251_power_off(wl);
360 373
361 mutex_unlock(&wl->mutex); 374 mutex_unlock(&wl->mutex);
362 375
363 return ret; 376 return ret;
364} 377}
365 378
366static void wl12xx_op_stop(struct ieee80211_hw *hw) 379static void wl1251_op_stop(struct ieee80211_hw *hw)
367{ 380{
368 struct wl12xx *wl = hw->priv; 381 struct wl1251 *wl = hw->priv;
369 382
370 wl12xx_info("down"); 383 wl1251_info("down");
371 384
372 wl12xx_debug(DEBUG_MAC80211, "mac80211 stop"); 385 wl1251_debug(DEBUG_MAC80211, "mac80211 stop");
373 386
374 mutex_lock(&wl->mutex); 387 mutex_lock(&wl->mutex);
375 388
376 WARN_ON(wl->state != WL12XX_STATE_ON); 389 WARN_ON(wl->state != WL1251_STATE_ON);
377 390
378 if (wl->scanning) { 391 if (wl->scanning) {
379 mutex_unlock(&wl->mutex); 392 mutex_unlock(&wl->mutex);
@@ -382,9 +395,9 @@ static void wl12xx_op_stop(struct ieee80211_hw *hw)
382 wl->scanning = false; 395 wl->scanning = false;
383 } 396 }
384 397
385 wl->state = WL12XX_STATE_OFF; 398 wl->state = WL1251_STATE_OFF;
386 399
387 wl12xx_disable_interrupts(wl); 400 wl1251_disable_interrupts(wl);
388 401
389 mutex_unlock(&wl->mutex); 402 mutex_unlock(&wl->mutex);
390 403
@@ -395,9 +408,8 @@ static void wl12xx_op_stop(struct ieee80211_hw *hw)
395 mutex_lock(&wl->mutex); 408 mutex_lock(&wl->mutex);
396 409
397 /* let's notify MAC80211 about the remaining pending TX frames */ 410 /* let's notify MAC80211 about the remaining pending TX frames */
398 wl12xx_tx_flush(wl); 411 wl->chip.op_tx_flush(wl);
399 412 wl1251_power_off(wl);
400 wl12xx_power_off(wl);
401 413
402 memset(wl->bssid, 0, ETH_ALEN); 414 memset(wl->bssid, 0, ETH_ALEN);
403 wl->listen_int = 1; 415 wl->listen_int = 1;
@@ -412,21 +424,21 @@ static void wl12xx_op_stop(struct ieee80211_hw *hw)
412 wl->elp = false; 424 wl->elp = false;
413 wl->psm = 0; 425 wl->psm = 0;
414 wl->tx_queue_stopped = false; 426 wl->tx_queue_stopped = false;
415 wl->power_level = WL12XX_DEFAULT_POWER_LEVEL; 427 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
416 428
417 wl12xx_debugfs_reset(wl); 429 wl1251_debugfs_reset(wl);
418 430
419 mutex_unlock(&wl->mutex); 431 mutex_unlock(&wl->mutex);
420} 432}
421 433
422static int wl12xx_op_add_interface(struct ieee80211_hw *hw, 434static int wl1251_op_add_interface(struct ieee80211_hw *hw,
423 struct ieee80211_if_init_conf *conf) 435 struct ieee80211_if_init_conf *conf)
424{ 436{
425 struct wl12xx *wl = hw->priv; 437 struct wl1251 *wl = hw->priv;
426 DECLARE_MAC_BUF(mac); 438 DECLARE_MAC_BUF(mac);
427 int ret = 0; 439 int ret = 0;
428 440
429 wl12xx_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %s", 441 wl1251_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %s",
430 conf->type, print_mac(mac, conf->mac_addr)); 442 conf->type, print_mac(mac, conf->mac_addr));
431 443
432 mutex_lock(&wl->mutex); 444 mutex_lock(&wl->mutex);
@@ -446,7 +458,7 @@ static int wl12xx_op_add_interface(struct ieee80211_hw *hw,
446 if (memcmp(wl->mac_addr, conf->mac_addr, ETH_ALEN)) { 458 if (memcmp(wl->mac_addr, conf->mac_addr, ETH_ALEN)) {
447 memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN); 459 memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN);
448 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr); 460 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
449 ret = wl12xx_acx_station_id(wl); 461 ret = wl1251_acx_station_id(wl);
450 if (ret < 0) 462 if (ret < 0)
451 goto out; 463 goto out;
452 } 464 }
@@ -456,13 +468,13 @@ out:
456 return ret; 468 return ret;
457} 469}
458 470
459static void wl12xx_op_remove_interface(struct ieee80211_hw *hw, 471static void wl1251_op_remove_interface(struct ieee80211_hw *hw,
460 struct ieee80211_if_init_conf *conf) 472 struct ieee80211_if_init_conf *conf)
461{ 473{
462 wl12xx_debug(DEBUG_MAC80211, "mac80211 remove interface"); 474 wl1251_debug(DEBUG_MAC80211, "mac80211 remove interface");
463} 475}
464 476
465static int wl12xx_build_null_data(struct wl12xx *wl) 477static int wl1251_build_null_data(struct wl1251 *wl)
466{ 478{
467 struct wl12xx_null_data_template template; 479 struct wl12xx_null_data_template template;
468 480
@@ -478,12 +490,12 @@ static int wl12xx_build_null_data(struct wl12xx *wl)
478 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA | 490 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
479 IEEE80211_STYPE_NULLFUNC); 491 IEEE80211_STYPE_NULLFUNC);
480 492
481 return wl12xx_cmd_template_set(wl, CMD_NULL_DATA, &template, 493 return wl1251_cmd_template_set(wl, CMD_NULL_DATA, &template,
482 sizeof(template)); 494 sizeof(template));
483 495
484} 496}
485 497
486static int wl12xx_build_ps_poll(struct wl12xx *wl, u16 aid) 498static int wl1251_build_ps_poll(struct wl1251 *wl, u16 aid)
487{ 499{
488 struct wl12xx_ps_poll_template template; 500 struct wl12xx_ps_poll_template template;
489 501
@@ -492,41 +504,45 @@ static int wl12xx_build_ps_poll(struct wl12xx *wl, u16 aid)
492 template.aid = aid; 504 template.aid = aid;
493 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL); 505 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
494 506
495 return wl12xx_cmd_template_set(wl, CMD_PS_POLL, &template, 507 return wl1251_cmd_template_set(wl, CMD_PS_POLL, &template,
496 sizeof(template)); 508 sizeof(template));
497 509
498} 510}
499 511
500static int wl12xx_op_config(struct ieee80211_hw *hw, u32 changed) 512static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
501{ 513{
502 struct wl12xx *wl = hw->priv; 514 struct wl1251 *wl = hw->priv;
503 struct ieee80211_conf *conf = &hw->conf; 515 struct ieee80211_conf *conf = &hw->conf;
504 int channel, ret = 0; 516 int channel, ret = 0;
505 517
506 channel = ieee80211_frequency_to_channel(conf->channel->center_freq); 518 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
507 519
508 wl12xx_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d", 520 wl1251_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
509 channel, 521 channel,
510 conf->flags & IEEE80211_CONF_PS ? "on" : "off", 522 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
511 conf->power_level); 523 conf->power_level);
512 524
513 mutex_lock(&wl->mutex); 525 mutex_lock(&wl->mutex);
514 526
527 ret = wl1251_ps_elp_wakeup(wl);
528 if (ret < 0)
529 goto out;
530
515 if (channel != wl->channel) { 531 if (channel != wl->channel) {
516 /* FIXME: use beacon interval provided by mac80211 */ 532 /* FIXME: use beacon interval provided by mac80211 */
517 ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0); 533 ret = wl->chip.op_cmd_join(wl, wl->bss_type, 1, 100, 0);
518 if (ret < 0) 534 if (ret < 0)
519 goto out; 535 goto out_sleep;
520 536
521 wl->channel = channel; 537 wl->channel = channel;
522 } 538 }
523 539
524 ret = wl12xx_build_null_data(wl); 540 ret = wl1251_build_null_data(wl);
525 if (ret < 0) 541 if (ret < 0)
526 goto out; 542 goto out_sleep;
527 543
528 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) { 544 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
529 wl12xx_info("psm enabled"); 545 wl1251_debug(DEBUG_PSM, "psm enabled");
530 546
531 wl->psm_requested = true; 547 wl->psm_requested = true;
532 548
@@ -535,49 +551,53 @@ static int wl12xx_op_config(struct ieee80211_hw *hw, u32 changed)
535 * If we're not, we'll enter it when joining an SSID, 551 * If we're not, we'll enter it when joining an SSID,
536 * through the bss_info_changed() hook. 552 * through the bss_info_changed() hook.
537 */ 553 */
538 ret = wl12xx_ps_set_mode(wl, STATION_POWER_SAVE_MODE); 554 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
539 } else if (!(conf->flags & IEEE80211_CONF_PS) && 555 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
540 wl->psm_requested) { 556 wl->psm_requested) {
541 wl12xx_info("psm disabled"); 557 wl1251_debug(DEBUG_PSM, "psm disabled");
542 558
543 wl->psm_requested = false; 559 wl->psm_requested = false;
544 560
545 if (wl->psm) 561 if (wl->psm)
546 ret = wl12xx_ps_set_mode(wl, STATION_ACTIVE_MODE); 562 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
547 } 563 }
548 564
549 if (conf->power_level != wl->power_level) { 565 if (conf->power_level != wl->power_level) {
550 ret = wl12xx_acx_tx_power(wl, conf->power_level); 566 ret = wl1251_acx_tx_power(wl, conf->power_level);
551 if (ret < 0) 567 if (ret < 0)
552 goto out; 568 goto out;
553 569
554 wl->power_level = conf->power_level; 570 wl->power_level = conf->power_level;
555 } 571 }
556 572
573out_sleep:
574 wl1251_ps_elp_sleep(wl);
575
557out: 576out:
558 mutex_unlock(&wl->mutex); 577 mutex_unlock(&wl->mutex);
578
559 return ret; 579 return ret;
560} 580}
561 581
562#define WL12XX_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ 582#define WL1251_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
563 FIF_ALLMULTI | \ 583 FIF_ALLMULTI | \
564 FIF_FCSFAIL | \ 584 FIF_FCSFAIL | \
565 FIF_BCN_PRBRESP_PROMISC | \ 585 FIF_BCN_PRBRESP_PROMISC | \
566 FIF_CONTROL | \ 586 FIF_CONTROL | \
567 FIF_OTHER_BSS) 587 FIF_OTHER_BSS)
568 588
569static void wl12xx_op_configure_filter(struct ieee80211_hw *hw, 589static void wl1251_op_configure_filter(struct ieee80211_hw *hw,
570 unsigned int changed, 590 unsigned int changed,
571 unsigned int *total, 591 unsigned int *total,
572 int mc_count, 592 int mc_count,
573 struct dev_addr_list *mc_list) 593 struct dev_addr_list *mc_list)
574{ 594{
575 struct wl12xx *wl = hw->priv; 595 struct wl1251 *wl = hw->priv;
576 596
577 wl12xx_debug(DEBUG_MAC80211, "mac80211 configure filter"); 597 wl1251_debug(DEBUG_MAC80211, "mac80211 configure filter");
578 598
579 *total &= WL12XX_SUPPORTED_FILTERS; 599 *total &= WL1251_SUPPORTED_FILTERS;
580 changed &= WL12XX_SUPPORTED_FILTERS; 600 changed &= WL1251_SUPPORTED_FILTERS;
581 601
582 if (changed == 0) 602 if (changed == 0)
583 /* no filters which we support changed */ 603 /* no filters which we support changed */
@@ -585,8 +605,8 @@ static void wl12xx_op_configure_filter(struct ieee80211_hw *hw,
585 605
586 /* FIXME: wl->rx_config and wl->rx_filter are not protected */ 606 /* FIXME: wl->rx_config and wl->rx_filter are not protected */
587 607
588 wl->rx_config = WL12XX_DEFAULT_RX_CONFIG; 608 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
589 wl->rx_filter = WL12XX_DEFAULT_RX_FILTER; 609 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
590 610
591 if (*total & FIF_PROMISC_IN_BSS) { 611 if (*total & FIF_PROMISC_IN_BSS) {
592 wl->rx_config |= CFG_BSSID_FILTER_EN; 612 wl->rx_config |= CFG_BSSID_FILTER_EN;
@@ -618,7 +638,8 @@ static void wl12xx_op_configure_filter(struct ieee80211_hw *hw,
618} 638}
619 639
620/* HW encryption */ 640/* HW encryption */
621static int wl12xx_set_key_type(struct wl12xx *wl, struct acx_set_key *key, 641static int wl1251_set_key_type(struct wl1251 *wl,
642 struct wl1251_cmd_set_keys *key,
622 enum set_key_cmd cmd, 643 enum set_key_cmd cmd,
623 struct ieee80211_key_conf *mac80211_key, 644 struct ieee80211_key_conf *mac80211_key,
624 const u8 *addr) 645 const u8 *addr)
@@ -648,95 +669,116 @@ static int wl12xx_set_key_type(struct wl12xx *wl, struct acx_set_key *key,
648 mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 669 mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
649 break; 670 break;
650 default: 671 default:
651 wl12xx_error("Unknown key algo 0x%x", mac80211_key->alg); 672 wl1251_error("Unknown key algo 0x%x", mac80211_key->alg);
652 return -EOPNOTSUPP; 673 return -EOPNOTSUPP;
653 } 674 }
654 675
655 return 0; 676 return 0;
656} 677}
657 678
658static int wl12xx_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 679static int wl1251_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
659 struct ieee80211_vif *vif, 680 struct ieee80211_vif *vif,
660 struct ieee80211_sta *sta, 681 struct ieee80211_sta *sta,
661 struct ieee80211_key_conf *key) 682 struct ieee80211_key_conf *key)
662{ 683{
663 struct wl12xx *wl = hw->priv; 684 struct wl1251 *wl = hw->priv;
664 struct acx_set_key wl_key; 685 struct wl1251_cmd_set_keys *wl_cmd;
665 const u8 *addr; 686 const u8 *addr;
666 int ret; 687 int ret;
667 688
668 static const u8 bcast_addr[ETH_ALEN] = 689 static const u8 bcast_addr[ETH_ALEN] =
669 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 690 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
670 691
671 wl12xx_debug(DEBUG_MAC80211, "mac80211 set key"); 692 wl1251_debug(DEBUG_MAC80211, "mac80211 set key");
672 693
673 memset(&wl_key, 0, sizeof(wl_key)); 694 wl_cmd = kzalloc(sizeof(*wl_cmd), GFP_KERNEL);
695 if (!wl_cmd) {
696 ret = -ENOMEM;
697 goto out;
698 }
674 699
675 addr = sta ? sta->addr : bcast_addr; 700 addr = sta ? sta->addr : bcast_addr;
676 701
677 wl12xx_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd); 702 wl1251_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
678 wl12xx_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN); 703 wl1251_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
679 wl12xx_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x", 704 wl1251_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
680 key->alg, key->keyidx, key->keylen, key->flags); 705 key->alg, key->keyidx, key->keylen, key->flags);
681 wl12xx_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen); 706 wl1251_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
707
708 if (is_zero_ether_addr(addr)) {
709 /* We dont support TX only encryption */
710 ret = -EOPNOTSUPP;
711 goto out;
712 }
682 713
683 mutex_lock(&wl->mutex); 714 mutex_lock(&wl->mutex);
684 715
716 ret = wl1251_ps_elp_wakeup(wl);
717 if (ret < 0)
718 goto out_unlock;
719
685 switch (cmd) { 720 switch (cmd) {
686 case SET_KEY: 721 case SET_KEY:
687 wl_key.key_action = KEY_ADD_OR_REPLACE; 722 wl_cmd->key_action = KEY_ADD_OR_REPLACE;
688 break; 723 break;
689 case DISABLE_KEY: 724 case DISABLE_KEY:
690 wl_key.key_action = KEY_REMOVE; 725 wl_cmd->key_action = KEY_REMOVE;
691 break; 726 break;
692 default: 727 default:
693 wl12xx_error("Unsupported key cmd 0x%x", cmd); 728 wl1251_error("Unsupported key cmd 0x%x", cmd);
694 break; 729 break;
695 } 730 }
696 731
697 ret = wl12xx_set_key_type(wl, &wl_key, cmd, key, addr); 732 ret = wl1251_set_key_type(wl, wl_cmd, cmd, key, addr);
698 if (ret < 0) { 733 if (ret < 0) {
699 wl12xx_error("Set KEY type failed"); 734 wl1251_error("Set KEY type failed");
700 goto out; 735 goto out_sleep;
701 } 736 }
702 737
703 if (wl_key.key_type != KEY_WEP_DEFAULT) 738 if (wl_cmd->key_type != KEY_WEP_DEFAULT)
704 memcpy(wl_key.addr, addr, ETH_ALEN); 739 memcpy(wl_cmd->addr, addr, ETH_ALEN);
705 740
706 if ((wl_key.key_type == KEY_TKIP_MIC_GROUP) || 741 if ((wl_cmd->key_type == KEY_TKIP_MIC_GROUP) ||
707 (wl_key.key_type == KEY_TKIP_MIC_PAIRWISE)) { 742 (wl_cmd->key_type == KEY_TKIP_MIC_PAIRWISE)) {
708 /* 743 /*
709 * We get the key in the following form: 744 * We get the key in the following form:
710 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) 745 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
711 * but the target is expecting: 746 * but the target is expecting:
712 * TKIP - RX MIC - TX MIC 747 * TKIP - RX MIC - TX MIC
713 */ 748 */
714 memcpy(wl_key.key, key->key, 16); 749 memcpy(wl_cmd->key, key->key, 16);
715 memcpy(wl_key.key + 16, key->key + 24, 8); 750 memcpy(wl_cmd->key + 16, key->key + 24, 8);
716 memcpy(wl_key.key + 24, key->key + 16, 8); 751 memcpy(wl_cmd->key + 24, key->key + 16, 8);
717 752
718 } else { 753 } else {
719 memcpy(wl_key.key, key->key, key->keylen); 754 memcpy(wl_cmd->key, key->key, key->keylen);
720 } 755 }
721 wl_key.key_size = key->keylen; 756 wl_cmd->key_size = key->keylen;
722 757
723 wl_key.id = key->keyidx; 758 wl_cmd->id = key->keyidx;
724 wl_key.ssid_profile = 0; 759 wl_cmd->ssid_profile = 0;
725 760
726 wl12xx_dump(DEBUG_CRYPT, "TARGET KEY: ", &wl_key, sizeof(wl_key)); 761 wl1251_dump(DEBUG_CRYPT, "TARGET KEY: ", wl_cmd, sizeof(*wl_cmd));
727 762
728 if (wl12xx_cmd_send(wl, CMD_SET_KEYS, &wl_key, sizeof(wl_key)) < 0) { 763 ret = wl1251_cmd_send(wl, CMD_SET_KEYS, wl_cmd, sizeof(*wl_cmd));
729 wl12xx_error("Set KEY failed"); 764 if (ret < 0) {
730 ret = -EOPNOTSUPP; 765 wl1251_warning("could not set keys");
731 goto out; 766 goto out_sleep;
732 } 767 }
733 768
734out: 769out_sleep:
770 wl1251_ps_elp_sleep(wl);
771
772out_unlock:
735 mutex_unlock(&wl->mutex); 773 mutex_unlock(&wl->mutex);
774
775out:
776 kfree(wl_cmd);
777
736 return ret; 778 return ret;
737} 779}
738 780
739static int wl12xx_build_basic_rates(char *rates) 781static int wl1251_build_basic_rates(char *rates)
740{ 782{
741 u8 index = 0; 783 u8 index = 0;
742 784
@@ -748,7 +790,7 @@ static int wl12xx_build_basic_rates(char *rates)
748 return index; 790 return index;
749} 791}
750 792
751static int wl12xx_build_extended_rates(char *rates) 793static int wl1251_build_extended_rates(char *rates)
752{ 794{
753 u8 index = 0; 795 u8 index = 0;
754 796
@@ -765,7 +807,7 @@ static int wl12xx_build_extended_rates(char *rates)
765} 807}
766 808
767 809
768static int wl12xx_build_probe_req(struct wl12xx *wl, u8 *ssid, size_t ssid_len) 810static int wl1251_build_probe_req(struct wl1251 *wl, u8 *ssid, size_t ssid_len)
769{ 811{
770 struct wl12xx_probe_req_template template; 812 struct wl12xx_probe_req_template template;
771 struct wl12xx_ie_rates *rates; 813 struct wl12xx_ie_rates *rates;
@@ -792,31 +834,30 @@ static int wl12xx_build_probe_req(struct wl12xx *wl, u8 *ssid, size_t ssid_len)
792 /* Basic Rates */ 834 /* Basic Rates */
793 rates = (struct wl12xx_ie_rates *)ptr; 835 rates = (struct wl12xx_ie_rates *)ptr;
794 rates->header.id = WLAN_EID_SUPP_RATES; 836 rates->header.id = WLAN_EID_SUPP_RATES;
795 rates->header.len = wl12xx_build_basic_rates(rates->rates); 837 rates->header.len = wl1251_build_basic_rates(rates->rates);
796 size += sizeof(struct wl12xx_ie_header) + rates->header.len; 838 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
797 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len; 839 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
798 840
799 /* Extended rates */ 841 /* Extended rates */
800 rates = (struct wl12xx_ie_rates *)ptr; 842 rates = (struct wl12xx_ie_rates *)ptr;
801 rates->header.id = WLAN_EID_EXT_SUPP_RATES; 843 rates->header.id = WLAN_EID_EXT_SUPP_RATES;
802 rates->header.len = wl12xx_build_extended_rates(rates->rates); 844 rates->header.len = wl1251_build_extended_rates(rates->rates);
803 size += sizeof(struct wl12xx_ie_header) + rates->header.len; 845 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
804 846
805 wl12xx_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size); 847 wl1251_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
806 848
807 return wl12xx_cmd_template_set(wl, CMD_PROBE_REQ, &template, 849 return wl1251_cmd_template_set(wl, CMD_PROBE_REQ, &template,
808 size); 850 size);
809} 851}
810 852
811static int wl12xx_hw_scan(struct wl12xx *wl, u8 *ssid, size_t len, 853static int wl1251_hw_scan(struct wl1251 *wl, u8 *ssid, size_t len,
812 u8 active_scan, u8 high_prio, u8 num_channels, 854 u8 active_scan, u8 high_prio, u8 num_channels,
813 u8 probe_requests) 855 u8 probe_requests)
814{ 856{
857 struct wl1251_cmd_trigger_scan_to *trigger = NULL;
858 struct cmd_scan *params = NULL;
815 int i, ret; 859 int i, ret;
816 u32 split_scan = 0;
817 u16 scan_options = 0; 860 u16 scan_options = 0;
818 struct cmd_scan *params;
819 struct wl12xx_command *cmd_answer;
820 861
821 if (wl->scanning) 862 if (wl->scanning)
822 return -EINVAL; 863 return -EINVAL;
@@ -864,33 +905,38 @@ static int wl12xx_hw_scan(struct wl12xx *wl, u8 *ssid, size_t len,
864 memset(params->params.ssid, 0, 32); 905 memset(params->params.ssid, 0, 32);
865 } 906 }
866 907
867 ret = wl12xx_build_probe_req(wl, ssid, len); 908 ret = wl1251_build_probe_req(wl, ssid, len);
868 if (ret < 0) { 909 if (ret < 0) {
869 wl12xx_error("PROBE request template failed"); 910 wl1251_error("PROBE request template failed");
870 goto out; 911 goto out;
871 } 912 }
872 913
873 ret = wl12xx_cmd_send(wl, CMD_TRIGGER_SCAN_TO, &split_scan, 914 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
874 sizeof(u32)); 915 if (!trigger)
916 goto out;
917
918 trigger->timeout = 0;
919
920 ret = wl1251_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
921 sizeof(*trigger));
875 if (ret < 0) { 922 if (ret < 0) {
876 wl12xx_error("Split SCAN failed"); 923 wl1251_error("trigger scan to failed for hw scan");
877 goto out; 924 goto out;
878 } 925 }
879 926
880 wl12xx_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params)); 927 wl1251_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
881 928
882 wl->scanning = true; 929 wl->scanning = true;
883 930
884 ret = wl12xx_cmd_send(wl, CMD_SCAN, params, sizeof(*params)); 931 ret = wl1251_cmd_send(wl, CMD_SCAN, params, sizeof(*params));
885 if (ret < 0) 932 if (ret < 0)
886 wl12xx_error("SCAN failed"); 933 wl1251_error("SCAN failed");
887 934
888 wl12xx_spi_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params)); 935 wl1251_spi_mem_read(wl, wl->cmd_box_addr, params, sizeof(*params));
889 936
890 cmd_answer = (struct wl12xx_command *) params; 937 if (params->header.status != CMD_STATUS_SUCCESS) {
891 if (cmd_answer->status != CMD_STATUS_SUCCESS) { 938 wl1251_error("TEST command answer error: %d",
892 wl12xx_error("TEST command answer error: %d", 939 params->header.status);
893 cmd_answer->status);
894 wl->scanning = false; 940 wl->scanning = false;
895 ret = -EIO; 941 ret = -EIO;
896 goto out; 942 goto out;
@@ -902,15 +948,15 @@ out:
902 948
903} 949}
904 950
905static int wl12xx_op_hw_scan(struct ieee80211_hw *hw, 951static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
906 struct cfg80211_scan_request *req) 952 struct cfg80211_scan_request *req)
907{ 953{
908 struct wl12xx *wl = hw->priv; 954 struct wl1251 *wl = hw->priv;
909 int ret; 955 int ret;
910 u8 *ssid = NULL; 956 u8 *ssid = NULL;
911 size_t ssid_len = 0; 957 size_t ssid_len = 0;
912 958
913 wl12xx_debug(DEBUG_MAC80211, "mac80211 hw scan"); 959 wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan");
914 960
915 if (req->n_ssids) { 961 if (req->n_ssids) {
916 ssid = req->ssids[0].ssid; 962 ssid = req->ssids[0].ssid;
@@ -918,85 +964,108 @@ static int wl12xx_op_hw_scan(struct ieee80211_hw *hw,
918 } 964 }
919 965
920 mutex_lock(&wl->mutex); 966 mutex_lock(&wl->mutex);
921 ret = wl12xx_hw_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3); 967
968 ret = wl1251_ps_elp_wakeup(wl);
969 if (ret < 0)
970 goto out;
971
972 ret = wl1251_hw_scan(hw->priv, ssid, ssid_len, 1, 0, 13, 3);
973
974 wl1251_ps_elp_sleep(wl);
975
976out:
922 mutex_unlock(&wl->mutex); 977 mutex_unlock(&wl->mutex);
923 978
924 return ret; 979 return ret;
925} 980}
926 981
927static int wl12xx_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 982static int wl1251_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
928{ 983{
929 struct wl12xx *wl = hw->priv; 984 struct wl1251 *wl = hw->priv;
930 int ret; 985 int ret;
931 986
932 ret = wl12xx_acx_rts_threshold(wl, (u16) value); 987 mutex_lock(&wl->mutex);
988
989 ret = wl1251_ps_elp_wakeup(wl);
990 if (ret < 0)
991 goto out;
933 992
993 ret = wl1251_acx_rts_threshold(wl, (u16) value);
934 if (ret < 0) 994 if (ret < 0)
935 wl12xx_warning("wl12xx_op_set_rts_threshold failed: %d", ret); 995 wl1251_warning("wl1251_op_set_rts_threshold failed: %d", ret);
996
997 wl1251_ps_elp_sleep(wl);
998
999out:
1000 mutex_unlock(&wl->mutex);
936 1001
937 return ret; 1002 return ret;
938} 1003}
939 1004
940static void wl12xx_op_bss_info_changed(struct ieee80211_hw *hw, 1005static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
941 struct ieee80211_vif *vif, 1006 struct ieee80211_vif *vif,
942 struct ieee80211_bss_conf *bss_conf, 1007 struct ieee80211_bss_conf *bss_conf,
943 u32 changed) 1008 u32 changed)
944{ 1009{
945 enum acx_ps_mode mode; 1010 enum wl1251_cmd_ps_mode mode;
946 struct wl12xx *wl = hw->priv; 1011 struct wl1251 *wl = hw->priv;
947 struct sk_buff *beacon; 1012 struct sk_buff *beacon;
948 int ret; 1013 int ret;
949 1014
950 wl12xx_debug(DEBUG_MAC80211, "mac80211 bss info changed"); 1015 wl1251_debug(DEBUG_MAC80211, "mac80211 bss info changed");
951 1016
952 mutex_lock(&wl->mutex); 1017 mutex_lock(&wl->mutex);
953 1018
1019 ret = wl1251_ps_elp_wakeup(wl);
1020 if (ret < 0)
1021 goto out;
1022
954 if (changed & BSS_CHANGED_ASSOC) { 1023 if (changed & BSS_CHANGED_ASSOC) {
955 if (bss_conf->assoc) { 1024 if (bss_conf->assoc) {
956 wl->aid = bss_conf->aid; 1025 wl->aid = bss_conf->aid;
957 1026
958 ret = wl12xx_build_ps_poll(wl, wl->aid); 1027 ret = wl1251_build_ps_poll(wl, wl->aid);
959 if (ret < 0) 1028 if (ret < 0)
960 goto out; 1029 goto out_sleep;
961 1030
962 ret = wl12xx_acx_aid(wl, wl->aid); 1031 ret = wl1251_acx_aid(wl, wl->aid);
963 if (ret < 0) 1032 if (ret < 0)
964 goto out; 1033 goto out_sleep;
965 1034
966 /* If we want to go in PSM but we're not there yet */ 1035 /* If we want to go in PSM but we're not there yet */
967 if (wl->psm_requested && !wl->psm) { 1036 if (wl->psm_requested && !wl->psm) {
968 mode = STATION_POWER_SAVE_MODE; 1037 mode = STATION_POWER_SAVE_MODE;
969 ret = wl12xx_ps_set_mode(wl, mode); 1038 ret = wl1251_ps_set_mode(wl, mode);
970 if (ret < 0) 1039 if (ret < 0)
971 goto out; 1040 goto out_sleep;
972 } 1041 }
973 } 1042 }
974 } 1043 }
975 if (changed & BSS_CHANGED_ERP_SLOT) { 1044 if (changed & BSS_CHANGED_ERP_SLOT) {
976 if (bss_conf->use_short_slot) 1045 if (bss_conf->use_short_slot)
977 ret = wl12xx_acx_slot(wl, SLOT_TIME_SHORT); 1046 ret = wl1251_acx_slot(wl, SLOT_TIME_SHORT);
978 else 1047 else
979 ret = wl12xx_acx_slot(wl, SLOT_TIME_LONG); 1048 ret = wl1251_acx_slot(wl, SLOT_TIME_LONG);
980 if (ret < 0) { 1049 if (ret < 0) {
981 wl12xx_warning("Set slot time failed %d", ret); 1050 wl1251_warning("Set slot time failed %d", ret);
982 goto out; 1051 goto out_sleep;
983 } 1052 }
984 } 1053 }
985 1054
986 if (changed & BSS_CHANGED_ERP_PREAMBLE) { 1055 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
987 if (bss_conf->use_short_preamble) 1056 if (bss_conf->use_short_preamble)
988 wl12xx_acx_set_preamble(wl, ACX_PREAMBLE_SHORT); 1057 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
989 else 1058 else
990 wl12xx_acx_set_preamble(wl, ACX_PREAMBLE_LONG); 1059 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
991 } 1060 }
992 1061
993 if (changed & BSS_CHANGED_ERP_CTS_PROT) { 1062 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
994 if (bss_conf->use_cts_prot) 1063 if (bss_conf->use_cts_prot)
995 ret = wl12xx_acx_cts_protect(wl, CTSPROTECT_ENABLE); 1064 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_ENABLE);
996 else 1065 else
997 ret = wl12xx_acx_cts_protect(wl, CTSPROTECT_DISABLE); 1066 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
998 if (ret < 0) { 1067 if (ret < 0) {
999 wl12xx_warning("Set ctsprotect failed %d", ret); 1068 wl1251_warning("Set ctsprotect failed %d", ret);
1000 goto out; 1069 goto out;
1001 } 1070 }
1002 } 1071 }
@@ -1004,20 +1073,22 @@ static void wl12xx_op_bss_info_changed(struct ieee80211_hw *hw,
1004 if (changed & BSS_CHANGED_BSSID) { 1073 if (changed & BSS_CHANGED_BSSID) {
1005 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN); 1074 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1006 1075
1007 ret = wl12xx_build_null_data(wl); 1076 ret = wl1251_build_null_data(wl);
1008 if (ret < 0) 1077 if (ret < 0)
1009 goto out; 1078 goto out;
1010 1079
1011 if (wl->bss_type != BSS_TYPE_IBSS) { 1080 if (wl->bss_type != BSS_TYPE_IBSS) {
1012 ret = wl12xx_cmd_join(wl, wl->bss_type, 5, 100, 1); 1081 ret = wl1251_cmd_join(wl, wl->bss_type, 5, 100, 1);
1013 if (ret < 0) 1082 if (ret < 0)
1014 goto out; 1083 goto out_sleep;
1084 wl1251_warning("Set ctsprotect failed %d", ret);
1085 goto out_sleep;
1015 } 1086 }
1016 } 1087 }
1017 1088
1018 if (changed & BSS_CHANGED_BEACON) { 1089 if (changed & BSS_CHANGED_BEACON) {
1019 beacon = ieee80211_beacon_get(hw, vif); 1090 beacon = ieee80211_beacon_get(hw, vif);
1020 ret = wl12xx_cmd_template_set(wl, CMD_BEACON, beacon->data, 1091 ret = wl1251_cmd_template_set(wl, CMD_BEACON, beacon->data,
1021 beacon->len); 1092 beacon->len);
1022 1093
1023 if (ret < 0) { 1094 if (ret < 0) {
@@ -1025,7 +1096,7 @@ static void wl12xx_op_bss_info_changed(struct ieee80211_hw *hw,
1025 goto out; 1096 goto out;
1026 } 1097 }
1027 1098
1028 ret = wl12xx_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data, 1099 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
1029 beacon->len); 1100 beacon->len);
1030 1101
1031 dev_kfree_skb(beacon); 1102 dev_kfree_skb(beacon);
@@ -1033,19 +1104,22 @@ static void wl12xx_op_bss_info_changed(struct ieee80211_hw *hw,
1033 if (ret < 0) 1104 if (ret < 0)
1034 goto out; 1105 goto out;
1035 1106
1036 ret = wl12xx_cmd_join(wl, wl->bss_type, 1, 100, 0); 1107 ret = wl->chip.op_cmd_join(wl, wl->bss_type, 1, 100, 0);
1037 1108
1038 if (ret < 0) 1109 if (ret < 0)
1039 goto out; 1110 goto out;
1040 } 1111 }
1041 1112
1113out_sleep:
1114 wl1251_ps_elp_sleep(wl);
1115
1042out: 1116out:
1043 mutex_unlock(&wl->mutex); 1117 mutex_unlock(&wl->mutex);
1044} 1118}
1045 1119
1046 1120
1047/* can't be const, mac80211 writes to this */ 1121/* can't be const, mac80211 writes to this */
1048static struct ieee80211_rate wl12xx_rates[] = { 1122static struct ieee80211_rate wl1251_rates[] = {
1049 { .bitrate = 10, 1123 { .bitrate = 10,
1050 .hw_value = 0x1, 1124 .hw_value = 0x1,
1051 .hw_value_short = 0x1, }, 1125 .hw_value_short = 0x1, },
@@ -1088,7 +1162,7 @@ static struct ieee80211_rate wl12xx_rates[] = {
1088}; 1162};
1089 1163
1090/* can't be const, mac80211 writes to this */ 1164/* can't be const, mac80211 writes to this */
1091static struct ieee80211_channel wl12xx_channels[] = { 1165static struct ieee80211_channel wl1251_channels[] = {
1092 { .hw_value = 1, .center_freq = 2412}, 1166 { .hw_value = 1, .center_freq = 2412},
1093 { .hw_value = 2, .center_freq = 2417}, 1167 { .hw_value = 2, .center_freq = 2417},
1094 { .hw_value = 3, .center_freq = 2422}, 1168 { .hw_value = 3, .center_freq = 2422},
@@ -1105,28 +1179,28 @@ static struct ieee80211_channel wl12xx_channels[] = {
1105}; 1179};
1106 1180
1107/* can't be const, mac80211 writes to this */ 1181/* can't be const, mac80211 writes to this */
1108static struct ieee80211_supported_band wl12xx_band_2ghz = { 1182static struct ieee80211_supported_band wl1251_band_2ghz = {
1109 .channels = wl12xx_channels, 1183 .channels = wl1251_channels,
1110 .n_channels = ARRAY_SIZE(wl12xx_channels), 1184 .n_channels = ARRAY_SIZE(wl1251_channels),
1111 .bitrates = wl12xx_rates, 1185 .bitrates = wl1251_rates,
1112 .n_bitrates = ARRAY_SIZE(wl12xx_rates), 1186 .n_bitrates = ARRAY_SIZE(wl1251_rates),
1113}; 1187};
1114 1188
1115static const struct ieee80211_ops wl12xx_ops = { 1189static const struct ieee80211_ops wl1251_ops = {
1116 .start = wl12xx_op_start, 1190 .start = wl1251_op_start,
1117 .stop = wl12xx_op_stop, 1191 .stop = wl1251_op_stop,
1118 .add_interface = wl12xx_op_add_interface, 1192 .add_interface = wl1251_op_add_interface,
1119 .remove_interface = wl12xx_op_remove_interface, 1193 .remove_interface = wl1251_op_remove_interface,
1120 .config = wl12xx_op_config, 1194 .config = wl1251_op_config,
1121 .configure_filter = wl12xx_op_configure_filter, 1195 .configure_filter = wl1251_op_configure_filter,
1122 .tx = wl12xx_op_tx, 1196 .tx = wl1251_op_tx,
1123 .set_key = wl12xx_op_set_key, 1197 .set_key = wl1251_op_set_key,
1124 .hw_scan = wl12xx_op_hw_scan, 1198 .hw_scan = wl1251_op_hw_scan,
1125 .bss_info_changed = wl12xx_op_bss_info_changed, 1199 .bss_info_changed = wl1251_op_bss_info_changed,
1126 .set_rts_threshold = wl12xx_op_set_rts_threshold, 1200 .set_rts_threshold = wl1251_op_set_rts_threshold,
1127}; 1201};
1128 1202
1129static int wl12xx_register_hw(struct wl12xx *wl) 1203static int wl1251_register_hw(struct wl1251 *wl)
1130{ 1204{
1131 int ret; 1205 int ret;
1132 1206
@@ -1137,22 +1211,22 @@ static int wl12xx_register_hw(struct wl12xx *wl)
1137 1211
1138 ret = ieee80211_register_hw(wl->hw); 1212 ret = ieee80211_register_hw(wl->hw);
1139 if (ret < 0) { 1213 if (ret < 0) {
1140 wl12xx_error("unable to register mac80211 hw: %d", ret); 1214 wl1251_error("unable to register mac80211 hw: %d", ret);
1141 return ret; 1215 return ret;
1142 } 1216 }
1143 1217
1144 wl->mac80211_registered = true; 1218 wl->mac80211_registered = true;
1145 1219
1146 wl12xx_notice("loaded"); 1220 wl1251_notice("loaded");
1147 1221
1148 return 0; 1222 return 0;
1149} 1223}
1150 1224
1151static int wl12xx_init_ieee80211(struct wl12xx *wl) 1225static int wl1251_init_ieee80211(struct wl1251 *wl)
1152{ 1226{
1153 /* The tx descriptor buffer and the TKIP space */ 1227 /* The tx descriptor buffer and the TKIP space */
1154 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc) 1228 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
1155 + WL12XX_TKIP_IV_SPACE; 1229 + WL1251_TKIP_IV_SPACE;
1156 1230
1157 /* unit us */ 1231 /* unit us */
1158 /* FIXME: find a proper value */ 1232 /* FIXME: find a proper value */
@@ -1163,31 +1237,31 @@ static int wl12xx_init_ieee80211(struct wl12xx *wl)
1163 1237
1164 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); 1238 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1165 wl->hw->wiphy->max_scan_ssids = 1; 1239 wl->hw->wiphy->max_scan_ssids = 1;
1166 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl12xx_band_2ghz; 1240 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz;
1167 1241
1168 SET_IEEE80211_DEV(wl->hw, &wl->spi->dev); 1242 SET_IEEE80211_DEV(wl->hw, &wl->spi->dev);
1169 1243
1170 return 0; 1244 return 0;
1171} 1245}
1172 1246
1173#define WL12XX_DEFAULT_CHANNEL 1 1247#define WL1251_DEFAULT_CHANNEL 1
1174static int __devinit wl12xx_probe(struct spi_device *spi) 1248static int __devinit wl1251_probe(struct spi_device *spi)
1175{ 1249{
1176 struct wl12xx_platform_data *pdata; 1250 struct wl12xx_platform_data *pdata;
1177 struct ieee80211_hw *hw; 1251 struct ieee80211_hw *hw;
1178 struct wl12xx *wl; 1252 struct wl1251 *wl;
1179 int ret, i; 1253 int ret, i;
1180 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf}; 1254 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1181 1255
1182 pdata = spi->dev.platform_data; 1256 pdata = spi->dev.platform_data;
1183 if (!pdata) { 1257 if (!pdata) {
1184 wl12xx_error("no platform data"); 1258 wl1251_error("no platform data");
1185 return -ENODEV; 1259 return -ENODEV;
1186 } 1260 }
1187 1261
1188 hw = ieee80211_alloc_hw(sizeof(*wl), &wl12xx_ops); 1262 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops);
1189 if (!hw) { 1263 if (!hw) {
1190 wl12xx_error("could not alloc ieee80211_hw"); 1264 wl1251_error("could not alloc ieee80211_hw");
1191 return -ENOMEM; 1265 return -ENOMEM;
1192 } 1266 }
1193 1267
@@ -1202,9 +1276,8 @@ static int __devinit wl12xx_probe(struct spi_device *spi)
1202 1276
1203 skb_queue_head_init(&wl->tx_queue); 1277 skb_queue_head_init(&wl->tx_queue);
1204 1278
1205 INIT_WORK(&wl->tx_work, wl12xx_tx_work); 1279 INIT_WORK(&wl->filter_work, wl1251_filter_work);
1206 INIT_WORK(&wl->filter_work, wl12xx_filter_work); 1280 wl->channel = WL1251_DEFAULT_CHANNEL;
1207 wl->channel = WL12XX_DEFAULT_CHANNEL;
1208 wl->scanning = false; 1281 wl->scanning = false;
1209 wl->default_key = 0; 1282 wl->default_key = 0;
1210 wl->listen_int = 1; 1283 wl->listen_int = 1;
@@ -1212,17 +1285,17 @@ static int __devinit wl12xx_probe(struct spi_device *spi)
1212 wl->rx_handled = 0; 1285 wl->rx_handled = 0;
1213 wl->rx_current_buffer = 0; 1286 wl->rx_current_buffer = 0;
1214 wl->rx_last_id = 0; 1287 wl->rx_last_id = 0;
1215 wl->rx_config = WL12XX_DEFAULT_RX_CONFIG; 1288 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
1216 wl->rx_filter = WL12XX_DEFAULT_RX_FILTER; 1289 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
1217 wl->elp = false; 1290 wl->elp = false;
1218 wl->psm = 0; 1291 wl->psm = 0;
1219 wl->psm_requested = false; 1292 wl->psm_requested = false;
1220 wl->tx_queue_stopped = false; 1293 wl->tx_queue_stopped = false;
1221 wl->power_level = WL12XX_DEFAULT_POWER_LEVEL; 1294 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
1222 1295
1223 /* We use the default power on sleep time until we know which chip 1296 /* We use the default power on sleep time until we know which chip
1224 * we're using */ 1297 * we're using */
1225 wl->chip.power_on_sleep = WL12XX_DEFAULT_POWER_ON_SLEEP; 1298 wl->chip.power_on_sleep = WL1251_DEFAULT_POWER_ON_SLEEP;
1226 1299
1227 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++) 1300 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
1228 wl->tx_frames[i] = NULL; 1301 wl->tx_frames[i] = NULL;
@@ -1236,37 +1309,46 @@ static int __devinit wl12xx_probe(struct spi_device *spi)
1236 memcpy(wl->mac_addr, nokia_oui, 3); 1309 memcpy(wl->mac_addr, nokia_oui, 3);
1237 get_random_bytes(wl->mac_addr + 3, 3); 1310 get_random_bytes(wl->mac_addr + 3, 3);
1238 1311
1239 wl->state = WL12XX_STATE_OFF; 1312 wl->state = WL1251_STATE_OFF;
1240 mutex_init(&wl->mutex); 1313 mutex_init(&wl->mutex);
1241 1314
1242 wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE; 1315 wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
1243 wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE; 1316 wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
1244 1317
1318 wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
1319 if (!wl->rx_descriptor) {
1320 wl1251_error("could not allocate memory for rx descriptor");
1321 ret = -ENOMEM;
1322 goto out_free;
1323 }
1324
1245 /* This is the only SPI value that we need to set here, the rest 1325 /* This is the only SPI value that we need to set here, the rest
1246 * comes from the board-peripherals file */ 1326 * comes from the board-peripherals file */
1247 spi->bits_per_word = 32; 1327 spi->bits_per_word = 32;
1248 1328
1249 ret = spi_setup(spi); 1329 ret = spi_setup(spi);
1250 if (ret < 0) { 1330 if (ret < 0) {
1251 wl12xx_error("spi_setup failed"); 1331 wl1251_error("spi_setup failed");
1252 goto out_free; 1332 goto out_free;
1253 } 1333 }
1254 1334
1255 wl->set_power = pdata->set_power; 1335 wl->set_power = pdata->set_power;
1256 if (!wl->set_power) { 1336 if (!wl->set_power) {
1257 wl12xx_error("set power function missing in platform data"); 1337 wl1251_error("set power function missing in platform data");
1258 return -ENODEV; 1338 ret = -ENODEV;
1339 goto out_free;
1259 } 1340 }
1260 1341
1261 wl->irq = spi->irq; 1342 wl->irq = spi->irq;
1262 if (wl->irq < 0) { 1343 if (wl->irq < 0) {
1263 wl12xx_error("irq missing in platform data"); 1344 wl1251_error("irq missing in platform data");
1264 return -ENODEV; 1345 ret = -ENODEV;
1346 goto out_free;
1265 } 1347 }
1266 1348
1267 ret = request_irq(wl->irq, wl12xx_irq, 0, DRIVER_NAME, wl); 1349 ret = request_irq(wl->irq, wl1251_irq, 0, DRIVER_NAME, wl);
1268 if (ret < 0) { 1350 if (ret < 0) {
1269 wl12xx_error("request_irq() failed: %d", ret); 1351 wl1251_error("request_irq() failed: %d", ret);
1270 goto out_free; 1352 goto out_free;
1271 } 1353 }
1272 1354
@@ -1274,17 +1356,17 @@ static int __devinit wl12xx_probe(struct spi_device *spi)
1274 1356
1275 disable_irq(wl->irq); 1357 disable_irq(wl->irq);
1276 1358
1277 ret = wl12xx_init_ieee80211(wl); 1359 ret = wl1251_init_ieee80211(wl);
1278 if (ret) 1360 if (ret)
1279 goto out_irq; 1361 goto out_irq;
1280 1362
1281 ret = wl12xx_register_hw(wl); 1363 ret = wl1251_register_hw(wl);
1282 if (ret) 1364 if (ret)
1283 goto out_irq; 1365 goto out_irq;
1284 1366
1285 wl12xx_debugfs_init(wl); 1367 wl1251_debugfs_init(wl);
1286 1368
1287 wl12xx_notice("initialized"); 1369 wl1251_notice("initialized");
1288 1370
1289 return 0; 1371 return 0;
1290 1372
@@ -1292,18 +1374,21 @@ static int __devinit wl12xx_probe(struct spi_device *spi)
1292 free_irq(wl->irq, wl); 1374 free_irq(wl->irq, wl);
1293 1375
1294 out_free: 1376 out_free:
1377 kfree(wl->rx_descriptor);
1378 wl->rx_descriptor = NULL;
1379
1295 ieee80211_free_hw(hw); 1380 ieee80211_free_hw(hw);
1296 1381
1297 return ret; 1382 return ret;
1298} 1383}
1299 1384
1300static int __devexit wl12xx_remove(struct spi_device *spi) 1385static int __devexit wl1251_remove(struct spi_device *spi)
1301{ 1386{
1302 struct wl12xx *wl = dev_get_drvdata(&spi->dev); 1387 struct wl1251 *wl = dev_get_drvdata(&spi->dev);
1303 1388
1304 ieee80211_unregister_hw(wl->hw); 1389 ieee80211_unregister_hw(wl->hw);
1305 1390
1306 wl12xx_debugfs_exit(wl); 1391 wl1251_debugfs_exit(wl);
1307 1392
1308 free_irq(wl->irq, wl); 1393 free_irq(wl->irq, wl);
1309 kfree(wl->target_mem_map); 1394 kfree(wl->target_mem_map);
@@ -1312,30 +1397,35 @@ static int __devexit wl12xx_remove(struct spi_device *spi)
1312 wl->fw = NULL; 1397 wl->fw = NULL;
1313 kfree(wl->nvs); 1398 kfree(wl->nvs);
1314 wl->nvs = NULL; 1399 wl->nvs = NULL;
1400
1401 kfree(wl->rx_descriptor);
1402 wl->rx_descriptor = NULL;
1403
1315 ieee80211_free_hw(wl->hw); 1404 ieee80211_free_hw(wl->hw);
1316 1405
1317 return 0; 1406 return 0;
1318} 1407}
1319 1408
1320 1409
1321static struct spi_driver wl12xx_spi_driver = { 1410static struct spi_driver wl1251_spi_driver = {
1322 .driver = { 1411 .driver = {
1412 /* FIXME: use wl12xx name to not break the user space */
1323 .name = "wl12xx", 1413 .name = "wl12xx",
1324 .bus = &spi_bus_type, 1414 .bus = &spi_bus_type,
1325 .owner = THIS_MODULE, 1415 .owner = THIS_MODULE,
1326 }, 1416 },
1327 1417
1328 .probe = wl12xx_probe, 1418 .probe = wl1251_probe,
1329 .remove = __devexit_p(wl12xx_remove), 1419 .remove = __devexit_p(wl1251_remove),
1330}; 1420};
1331 1421
1332static int __init wl12xx_init(void) 1422static int __init wl1251_init(void)
1333{ 1423{
1334 int ret; 1424 int ret;
1335 1425
1336 ret = spi_register_driver(&wl12xx_spi_driver); 1426 ret = spi_register_driver(&wl1251_spi_driver);
1337 if (ret < 0) { 1427 if (ret < 0) {
1338 wl12xx_error("failed to register spi driver: %d", ret); 1428 wl1251_error("failed to register spi driver: %d", ret);
1339 goto out; 1429 goto out;
1340 } 1430 }
1341 1431
@@ -1343,15 +1433,15 @@ out:
1343 return ret; 1433 return ret;
1344} 1434}
1345 1435
1346static void __exit wl12xx_exit(void) 1436static void __exit wl1251_exit(void)
1347{ 1437{
1348 spi_unregister_driver(&wl12xx_spi_driver); 1438 spi_unregister_driver(&wl1251_spi_driver);
1349 1439
1350 wl12xx_notice("unloaded"); 1440 wl1251_notice("unloaded");
1351} 1441}
1352 1442
1353module_init(wl12xx_init); 1443module_init(wl1251_init);
1354module_exit(wl12xx_exit); 1444module_exit(wl1251_exit);
1355 1445
1356MODULE_LICENSE("GPL"); 1446MODULE_LICENSE("GPL");
1357MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>, " 1447MODULE_AUTHOR("Kalle Valo <Kalle.Valo@nokia.com>, "
diff --git a/drivers/net/wireless/wl12xx/wl1251_netlink.c b/drivers/net/wireless/wl12xx/wl1251_netlink.c
new file mode 100644
index 000000000000..67d3d5a3b519
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1251_netlink.c
@@ -0,0 +1,679 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23#include "wl1251_netlink.h"
24
25#include <linux/mutex.h>
26#include <linux/socket.h>
27#include <net/net_namespace.h>
28#include <net/sock.h>
29#include <net/genetlink.h>
30#include <net/wireless.h>
31#include <net/mac80211.h>
32
33#include "wl1251.h"
34#include "wl1251_spi.h"
35#include "wl1251_acx.h"
36
37/* FIXME: this should be changed as soon as user space catches up */
38#define WL1251_NL_NAME "wl1251"
39#define WL1251_NL_VERSION 1
40
41#define WL1251_MAX_TEST_LENGTH 1024
42#define WL1251_MAX_NVS_LENGTH 1024
43
44enum wl1251_nl_commands {
45 WL1251_NL_CMD_UNSPEC,
46 WL1251_NL_CMD_TEST,
47 WL1251_NL_CMD_INTERROGATE,
48 WL1251_NL_CMD_CONFIGURE,
49 WL1251_NL_CMD_PHY_REG_READ,
50 WL1251_NL_CMD_NVS_PUSH,
51 WL1251_NL_CMD_REG_WRITE,
52 WL1251_NL_CMD_REG_READ,
53 WL1251_NL_CMD_SET_PLT_MODE,
54
55 __WL1251_NL_CMD_AFTER_LAST
56};
57#define WL1251_NL_CMD_MAX (__WL1251_NL_CMD_AFTER_LAST - 1)
58
59enum wl1251_nl_attrs {
60 WL1251_NL_ATTR_UNSPEC,
61 WL1251_NL_ATTR_IFNAME,
62 WL1251_NL_ATTR_CMD_TEST_PARAM,
63 WL1251_NL_ATTR_CMD_TEST_ANSWER,
64 WL1251_NL_ATTR_CMD_IE,
65 WL1251_NL_ATTR_CMD_IE_LEN,
66 WL1251_NL_ATTR_CMD_IE_BUFFER,
67 WL1251_NL_ATTR_CMD_IE_ANSWER,
68 WL1251_NL_ATTR_REG_ADDR,
69 WL1251_NL_ATTR_REG_VAL,
70 WL1251_NL_ATTR_NVS_BUFFER,
71 WL1251_NL_ATTR_NVS_LEN,
72 WL1251_NL_ATTR_PLT_MODE,
73
74 __WL1251_NL_ATTR_AFTER_LAST
75};
76#define WL1251_NL_ATTR_MAX (__WL1251_NL_ATTR_AFTER_LAST - 1)
77
78static struct genl_family wl1251_nl_family = {
79 .id = GENL_ID_GENERATE,
80 .name = WL1251_NL_NAME,
81 .hdrsize = 0,
82 .version = WL1251_NL_VERSION,
83 .maxattr = WL1251_NL_ATTR_MAX,
84};
85
86static struct net_device *ifname_to_netdev(struct net *net,
87 struct genl_info *info)
88{
89 char *ifname;
90
91 if (!info->attrs[WL1251_NL_ATTR_IFNAME])
92 return NULL;
93
94 ifname = nla_data(info->attrs[WL1251_NL_ATTR_IFNAME]);
95
96 wl1251_debug(DEBUG_NETLINK, "Looking for %s", ifname);
97
98 return dev_get_by_name(net, ifname);
99}
100
101static struct wl1251 *ifname_to_wl1251(struct net *net, struct genl_info *info)
102{
103 struct net_device *netdev;
104 struct wireless_dev *wdev;
105 struct wiphy *wiphy;
106 struct ieee80211_hw *hw;
107
108 netdev = ifname_to_netdev(net, info);
109 if (netdev == NULL) {
110 wl1251_error("Wrong interface");
111 return NULL;
112 }
113
114 wdev = netdev->ieee80211_ptr;
115 if (wdev == NULL) {
116 wl1251_error("ieee80211_ptr is NULL");
117 return NULL;
118 }
119
120 wiphy = wdev->wiphy;
121 if (wiphy == NULL) {
122 wl1251_error("wiphy is NULL");
123 return NULL;
124 }
125
126 hw = wiphy_priv(wiphy);
127 if (hw == NULL) {
128 wl1251_error("hw is NULL");
129 return NULL;
130 }
131
132 dev_put(netdev);
133
134 return hw->priv;
135}
136
137static int wl1251_nl_test_cmd(struct sk_buff *skb, struct genl_info *info)
138{
139 struct wl1251 *wl;
140 struct wl1251_command *cmd;
141 char *buf;
142 int buf_len, ret, cmd_len;
143 u8 answer;
144
145 if (!info->attrs[WL1251_NL_ATTR_CMD_TEST_PARAM])
146 return -EINVAL;
147
148 wl = ifname_to_wl1251(&init_net, info);
149 if (wl == NULL) {
150 wl1251_error("wl1251 not found");
151 return -EINVAL;
152 }
153
154 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
155 if (!cmd)
156 return -ENOMEM;
157
158 buf = nla_data(info->attrs[WL1251_NL_ATTR_CMD_TEST_PARAM]);
159 buf_len = nla_len(info->attrs[WL1251_NL_ATTR_CMD_TEST_PARAM]);
160 answer = nla_get_u8(info->attrs[WL1251_NL_ATTR_CMD_TEST_ANSWER]);
161
162 cmd->header.id = CMD_TEST;
163 memcpy(cmd->parameters, buf, buf_len);
164 cmd_len = sizeof(struct wl1251_cmd_header) + buf_len;
165
166 mutex_lock(&wl->mutex);
167 ret = wl1251_cmd_test(wl, cmd, cmd_len, answer);
168 mutex_unlock(&wl->mutex);
169
170 if (ret < 0) {
171 wl1251_error("%s() failed", __func__);
172 goto out;
173 }
174
175 if (answer) {
176 struct sk_buff *msg;
177 void *hdr;
178
179 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
180 if (!msg) {
181 ret = -ENOMEM;
182 goto out;
183 }
184
185 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
186 &wl1251_nl_family, 0, WL1251_NL_CMD_TEST);
187 if (IS_ERR(hdr)) {
188 ret = PTR_ERR(hdr);
189 goto nla_put_failure;
190 }
191
192 NLA_PUT_STRING(msg, WL1251_NL_ATTR_IFNAME,
193 nla_data(info->attrs[WL1251_NL_ATTR_IFNAME]));
194 NLA_PUT(msg, WL1251_NL_ATTR_CMD_TEST_ANSWER,
195 sizeof(*cmd), cmd);
196
197 ret = genlmsg_end(msg, hdr);
198 if (ret < 0) {
199 wl1251_error("%s() failed", __func__);
200 goto nla_put_failure;
201 }
202
203 wl1251_debug(DEBUG_NETLINK, "TEST cmd sent, answer");
204 ret = genlmsg_reply(msg, info);
205 goto out;
206
207 nla_put_failure:
208 nlmsg_free(msg);
209 } else
210 wl1251_debug(DEBUG_NETLINK, "TEST cmd sent");
211
212out:
213 kfree(cmd);
214 return ret;
215}
216
217static int wl1251_nl_interrogate(struct sk_buff *skb, struct genl_info *info)
218{
219 struct wl1251 *wl;
220 struct sk_buff *msg;
221 int ret = -ENOBUFS, cmd_ie, cmd_ie_len;
222 struct wl1251_command *cmd;
223 void *hdr;
224
225 if (!info->attrs[WL1251_NL_ATTR_CMD_IE])
226 return -EINVAL;
227
228 if (!info->attrs[WL1251_NL_ATTR_CMD_IE_LEN])
229 return -EINVAL;
230
231 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
232 if (!cmd)
233 return -ENOMEM;
234
235 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
236 if (!msg)
237 return -ENOMEM;
238
239 wl = ifname_to_wl1251(&init_net, info);
240 if (wl == NULL) {
241 wl1251_error("wl1251 not found");
242 ret = -EINVAL;
243 goto nla_put_failure;
244 }
245
246 /* acx id */
247 cmd_ie = nla_get_u32(info->attrs[WL1251_NL_ATTR_CMD_IE]);
248
249 /* maximum length of acx, including all headers */
250 cmd_ie_len = nla_get_u32(info->attrs[WL1251_NL_ATTR_CMD_IE_LEN]);
251
252 wl1251_debug(DEBUG_NETLINK, "Getting IE 0x%x (len %d)",
253 cmd_ie, cmd_ie_len);
254
255 mutex_lock(&wl->mutex);
256 ret = wl1251_cmd_interrogate(wl, cmd_ie, cmd, cmd_ie_len);
257 mutex_unlock(&wl->mutex);
258
259 if (ret < 0) {
260 wl1251_error("%s() failed", __func__);
261 goto nla_put_failure;
262 }
263
264 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
265 &wl1251_nl_family, 0, WL1251_NL_CMD_INTERROGATE);
266 if (IS_ERR(hdr)) {
267 ret = PTR_ERR(hdr);
268 goto nla_put_failure;
269 }
270
271 NLA_PUT_STRING(msg, WL1251_NL_ATTR_IFNAME,
272 nla_data(info->attrs[WL1251_NL_ATTR_IFNAME]));
273 NLA_PUT(msg, WL1251_NL_ATTR_CMD_IE_ANSWER, cmd_ie_len, cmd);
274
275 ret = genlmsg_end(msg, hdr);
276 if (ret < 0) {
277 wl1251_error("%s() failed", __func__);
278 goto nla_put_failure;
279 }
280
281 kfree(cmd);
282 return genlmsg_reply(msg, info);
283
284 nla_put_failure:
285 kfree(cmd);
286 nlmsg_free(msg);
287
288 return ret;
289}
290
291static int wl1251_nl_configure(struct sk_buff *skb, struct genl_info *info)
292{
293 int ret = 0, cmd_ie_len, acx_len;
294 struct acx_header *acx = NULL;
295 struct sk_buff *msg;
296 struct wl1251 *wl;
297 void *cmd_ie;
298 u16 *id;
299
300 if (!info->attrs[WL1251_NL_ATTR_CMD_IE_BUFFER])
301 return -EINVAL;
302
303 if (!info->attrs[WL1251_NL_ATTR_CMD_IE_LEN])
304 return -EINVAL;
305
306 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
307 if (!msg)
308 return -ENOMEM;
309
310 wl = ifname_to_wl1251(&init_net, info);
311 if (wl == NULL) {
312 wl1251_error("wl1251 not found");
313 ret = -EINVAL;
314 goto nla_put_failure;
315 }
316
317 /* contains the acx header but not the cmd header */
318 cmd_ie = nla_data(info->attrs[WL1251_NL_ATTR_CMD_IE_BUFFER]);
319
320 cmd_ie_len = nla_get_u32(info->attrs[WL1251_NL_ATTR_CMD_IE_LEN]);
321
322 /* acx id is in the first two bytes */
323 id = cmd_ie;
324
325 /* need to add acx_header before cmd_ie, so create a new command */
326 acx_len = sizeof(struct acx_header) + cmd_ie_len;
327 acx = kzalloc(acx_len, GFP_KERNEL);
328 if (!acx) {
329 ret = -ENOMEM;
330 goto nla_put_failure;
331 }
332
333 /* copy the acx header and the payload */
334 memcpy(&acx->id, cmd_ie, cmd_ie_len);
335
336 mutex_lock(&wl->mutex);
337 ret = wl1251_cmd_configure(wl, *id, acx, acx_len);
338 mutex_unlock(&wl->mutex);
339
340 if (ret < 0) {
341 wl1251_error("%s() failed", __func__);
342 goto nla_put_failure;
343 }
344
345 wl1251_debug(DEBUG_NETLINK, "CONFIGURE cmd sent");
346
347 nla_put_failure:
348 kfree(acx);
349 nlmsg_free(msg);
350
351 return ret;
352}
353
354static int wl1251_nl_phy_reg_read(struct sk_buff *skb, struct genl_info *info)
355{
356 struct wl1251 *wl;
357 struct sk_buff *msg;
358 u32 reg_addr, *reg_value = NULL;
359 int ret = 0;
360 void *hdr;
361
362 if (!info->attrs[WL1251_NL_ATTR_REG_ADDR])
363 return -EINVAL;
364
365 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
366 if (!msg)
367 return -ENOMEM;
368
369 wl = ifname_to_wl1251(&init_net, info);
370 if (wl == NULL) {
371 wl1251_error("wl1251 not found");
372 ret = -EINVAL;
373 goto nla_put_failure;
374 }
375
376 reg_value = kmalloc(sizeof(*reg_value), GFP_KERNEL);
377 if (!reg_value) {
378 ret = -ENOMEM;
379 goto nla_put_failure;
380 }
381
382 reg_addr = nla_get_u32(info->attrs[WL1251_NL_ATTR_REG_ADDR]);
383
384 wl1251_debug(DEBUG_NETLINK, "Reading PHY reg 0x%x", reg_addr);
385
386 mutex_lock(&wl->mutex);
387 ret = wl1251_cmd_read_memory(wl, reg_addr, reg_value,
388 sizeof(*reg_value));
389 mutex_unlock(&wl->mutex);
390
391 if (ret < 0) {
392 wl1251_error("%s() failed", __func__);
393 goto nla_put_failure;
394 }
395
396
397 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
398 &wl1251_nl_family, 0, WL1251_NL_CMD_PHY_REG_READ);
399 if (IS_ERR(hdr)) {
400 ret = PTR_ERR(hdr);
401 goto nla_put_failure;
402 }
403
404 NLA_PUT_STRING(msg, WL1251_NL_ATTR_IFNAME,
405 nla_data(info->attrs[WL1251_NL_ATTR_IFNAME]));
406
407 NLA_PUT_U32(msg, WL1251_NL_ATTR_REG_VAL, *reg_value);
408
409 ret = genlmsg_end(msg, hdr);
410 if (ret < 0) {
411 wl1251_error("%s() failed", __func__);
412 goto nla_put_failure;
413 }
414
415 kfree(reg_value);
416
417 return genlmsg_reply(msg, info);
418
419 nla_put_failure:
420 nlmsg_free(msg);
421 kfree(reg_value);
422
423 return ret;
424}
425
426static int wl1251_nl_nvs_push(struct sk_buff *skb, struct genl_info *info)
427{
428 struct wl1251 *wl;
429 int ret = 0;
430
431 if (!info->attrs[WL1251_NL_ATTR_NVS_BUFFER])
432 return -EINVAL;
433
434 if (!info->attrs[WL1251_NL_ATTR_NVS_LEN])
435 return -EINVAL;
436
437 wl = ifname_to_wl1251(&init_net, info);
438 if (wl == NULL) {
439 wl1251_error("wl1251 not found");
440 return -EINVAL;
441 }
442
443 mutex_lock(&wl->mutex);
444 wl->nvs_len = nla_get_u32(info->attrs[WL1251_NL_ATTR_NVS_LEN]);
445 if (wl->nvs_len % 4) {
446 wl1251_error("NVS size is not multiple of 32: %d", wl->nvs_len);
447 ret = -EILSEQ;
448 goto out;
449 }
450
451 /* If we already have an NVS, we should free it */
452 kfree(wl->nvs);
453
454 wl->nvs = kzalloc(wl->nvs_len, GFP_KERNEL);
455 if (wl->nvs == NULL) {
456 wl1251_error("Can't allocate NVS");
457 ret = -ENOMEM;
458 goto out;
459 }
460
461 memcpy(wl->nvs,
462 nla_data(info->attrs[WL1251_NL_ATTR_NVS_BUFFER]),
463 wl->nvs_len);
464
465 wl1251_debug(DEBUG_NETLINK, "got NVS from userspace, %d bytes",
466 wl->nvs_len);
467
468out:
469 mutex_unlock(&wl->mutex);
470
471 return ret;
472}
473
474static int wl1251_nl_reg_read(struct sk_buff *skb, struct genl_info *info)
475{
476 struct wl1251 *wl;
477 u32 addr, val;
478 int ret = 0;
479 struct sk_buff *msg;
480 void *hdr;
481
482 if (!info->attrs[WL1251_NL_ATTR_REG_ADDR])
483 return -EINVAL;
484
485 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
486 if (!msg)
487 return -ENOMEM;
488
489 wl = ifname_to_wl1251(&init_net, info);
490 if (wl == NULL) {
491 wl1251_error("wl1251 not found");
492 return -EINVAL;
493 }
494
495 addr = nla_get_u32(info->attrs[WL1251_NL_ATTR_REG_ADDR]);
496
497 mutex_lock(&wl->mutex);
498 val = wl1251_reg_read32(wl, addr);
499 mutex_unlock(&wl->mutex);
500
501 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
502 &wl1251_nl_family, 0, WL1251_NL_CMD_PHY_REG_READ);
503 if (IS_ERR(hdr)) {
504 ret = PTR_ERR(hdr);
505 goto nla_put_failure;
506 }
507
508 NLA_PUT_STRING(msg, WL1251_NL_ATTR_IFNAME,
509 nla_data(info->attrs[WL1251_NL_ATTR_IFNAME]));
510
511 NLA_PUT_U32(msg, WL1251_NL_ATTR_REG_VAL, val);
512
513 ret = genlmsg_end(msg, hdr);
514 if (ret < 0) {
515 wl1251_error("%s() failed", __func__);
516 goto nla_put_failure;
517 }
518
519 return genlmsg_reply(msg, info);
520
521 nla_put_failure:
522 nlmsg_free(msg);
523
524 return ret;
525}
526
527static int wl1251_nl_reg_write(struct sk_buff *skb, struct genl_info *info)
528{
529 struct wl1251 *wl;
530 u32 addr, val;
531
532 if (!info->attrs[WL1251_NL_ATTR_REG_ADDR])
533 return -EINVAL;
534
535 if (!info->attrs[WL1251_NL_ATTR_REG_VAL])
536 return -EINVAL;
537
538 wl = ifname_to_wl1251(&init_net, info);
539 if (wl == NULL) {
540 wl1251_error("wl1251 not found");
541 return -EINVAL;
542 }
543
544 addr = nla_get_u32(info->attrs[WL1251_NL_ATTR_REG_ADDR]);
545 val = nla_get_u32(info->attrs[WL1251_NL_ATTR_REG_VAL]);
546
547 mutex_lock(&wl->mutex);
548 wl1251_reg_write32(wl, addr, val);
549 mutex_unlock(&wl->mutex);
550
551 return 0;
552}
553
554static int wl1251_nl_set_plt_mode(struct sk_buff *skb, struct genl_info *info)
555{
556 struct wl1251 *wl;
557 u32 val;
558 int ret;
559
560 if (!info->attrs[WL1251_NL_ATTR_PLT_MODE])
561 return -EINVAL;
562
563 wl = ifname_to_wl1251(&init_net, info);
564 if (wl == NULL) {
565 wl1251_error("wl1251 not found");
566 return -EINVAL;
567 }
568
569 val = nla_get_u32(info->attrs[WL1251_NL_ATTR_PLT_MODE]);
570
571 switch (val) {
572 case 0:
573 ret = wl1251_plt_stop(wl);
574 break;
575 case 1:
576 ret = wl1251_plt_start(wl);
577 break;
578 default:
579 ret = -EINVAL;
580 break;
581 }
582
583 return ret;
584}
585
586static struct nla_policy wl1251_nl_policy[WL1251_NL_ATTR_MAX + 1] = {
587 [WL1251_NL_ATTR_IFNAME] = { .type = NLA_NUL_STRING,
588 .len = IFNAMSIZ-1 },
589 [WL1251_NL_ATTR_CMD_TEST_PARAM] = { .type = NLA_BINARY,
590 .len = WL1251_MAX_TEST_LENGTH },
591 [WL1251_NL_ATTR_CMD_TEST_ANSWER] = { .type = NLA_U8 },
592 [WL1251_NL_ATTR_CMD_IE] = { .type = NLA_U32 },
593 [WL1251_NL_ATTR_CMD_IE_LEN] = { .type = NLA_U32 },
594 [WL1251_NL_ATTR_CMD_IE_BUFFER] = { .type = NLA_BINARY,
595 .len = WL1251_MAX_TEST_LENGTH },
596 [WL1251_NL_ATTR_CMD_IE_ANSWER] = { .type = NLA_BINARY,
597 .len = WL1251_MAX_TEST_LENGTH },
598 [WL1251_NL_ATTR_REG_ADDR] = { .type = NLA_U32 },
599 [WL1251_NL_ATTR_REG_VAL] = { .type = NLA_U32 },
600 [WL1251_NL_ATTR_NVS_BUFFER] = { .type = NLA_BINARY,
601 .len = WL1251_MAX_NVS_LENGTH },
602 [WL1251_NL_ATTR_NVS_LEN] = { .type = NLA_U32 },
603 [WL1251_NL_ATTR_PLT_MODE] = { .type = NLA_U32 },
604};
605
606static struct genl_ops wl1251_nl_ops[] = {
607 {
608 .cmd = WL1251_NL_CMD_TEST,
609 .doit = wl1251_nl_test_cmd,
610 .policy = wl1251_nl_policy,
611 .flags = GENL_ADMIN_PERM,
612 },
613 {
614 .cmd = WL1251_NL_CMD_INTERROGATE,
615 .doit = wl1251_nl_interrogate,
616 .policy = wl1251_nl_policy,
617 .flags = GENL_ADMIN_PERM,
618 },
619 {
620 .cmd = WL1251_NL_CMD_CONFIGURE,
621 .doit = wl1251_nl_configure,
622 .policy = wl1251_nl_policy,
623 .flags = GENL_ADMIN_PERM,
624 },
625 {
626 .cmd = WL1251_NL_CMD_PHY_REG_READ,
627 .doit = wl1251_nl_phy_reg_read,
628 .policy = wl1251_nl_policy,
629 .flags = GENL_ADMIN_PERM,
630 },
631 {
632 .cmd = WL1251_NL_CMD_NVS_PUSH,
633 .doit = wl1251_nl_nvs_push,
634 .policy = wl1251_nl_policy,
635 .flags = GENL_ADMIN_PERM,
636 },
637 {
638 .cmd = WL1251_NL_CMD_REG_WRITE,
639 .doit = wl1251_nl_reg_write,
640 .policy = wl1251_nl_policy,
641 .flags = GENL_ADMIN_PERM,
642 },
643 {
644 .cmd = WL1251_NL_CMD_REG_READ,
645 .doit = wl1251_nl_reg_read,
646 .policy = wl1251_nl_policy,
647 .flags = GENL_ADMIN_PERM,
648 },
649 {
650 .cmd = WL1251_NL_CMD_SET_PLT_MODE,
651 .doit = wl1251_nl_set_plt_mode,
652 .policy = wl1251_nl_policy,
653 .flags = GENL_ADMIN_PERM,
654 },
655};
656
657int wl1251_nl_register(void)
658{
659 int err, i;
660
661 err = genl_register_family(&wl1251_nl_family);
662 if (err)
663 return err;
664
665 for (i = 0; i < ARRAY_SIZE(wl1251_nl_ops); i++) {
666 err = genl_register_ops(&wl1251_nl_family, &wl1251_nl_ops[i]);
667 if (err)
668 goto err_out;
669 }
670 return 0;
671 err_out:
672 genl_unregister_family(&wl1251_nl_family);
673 return err;
674}
675
676void wl1251_nl_unregister(void)
677{
678 genl_unregister_family(&wl1251_nl_family);
679}
diff --git a/drivers/net/wireless/wl12xx/wl1251_netlink.h b/drivers/net/wireless/wl12xx/wl1251_netlink.h
new file mode 100644
index 000000000000..ee36695e134e
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1251_netlink.h
@@ -0,0 +1,30 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#ifndef __WL1251_NETLINK_H__
25#define __WL1251_NETLINK_H__
26
27int wl1251_nl_register(void);
28void wl1251_nl_unregister(void);
29
30#endif /* __WL1251_NETLINK_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1251.c b/drivers/net/wireless/wl12xx/wl1251_ops.c
index ce1561a41fa4..96a45f595297 100644
--- a/drivers/net/wireless/wl12xx/wl1251.c
+++ b/drivers/net/wireless/wl12xx/wl1251_ops.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2008-2009 Nokia Corporation 4 * Copyright (C) 2008-2009 Nokia Corporation
5 * 5 *
@@ -24,18 +24,18 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/module.h> 25#include <linux/module.h>
26 26
27#include "wl1251.h" 27#include "wl1251_ops.h"
28#include "reg.h" 28#include "reg.h"
29#include "spi.h" 29#include "wl1251_spi.h"
30#include "boot.h" 30#include "wl1251_boot.h"
31#include "event.h" 31#include "wl1251_event.h"
32#include "acx.h" 32#include "wl1251_acx.h"
33#include "tx.h" 33#include "wl1251_tx.h"
34#include "rx.h" 34#include "wl1251_rx.h"
35#include "ps.h" 35#include "wl1251_ps.h"
36#include "init.h" 36#include "wl1251_init.h"
37 37
38static struct wl12xx_partition_set wl1251_part_table[PART_TABLE_LEN] = { 38static struct wl1251_partition_set wl1251_part_table[PART_TABLE_LEN] = {
39 [PART_DOWN] = { 39 [PART_DOWN] = {
40 .mem = { 40 .mem = {
41 .start = 0x00000000, 41 .start = 0x00000000,
@@ -75,31 +75,31 @@ static enum wl12xx_acx_int_reg wl1251_acx_reg_table[ACX_REG_TABLE_LEN] = {
75 [ACX_REG_ECPU_CONTROL] = (REGISTERS_BASE + 0x0804) 75 [ACX_REG_ECPU_CONTROL] = (REGISTERS_BASE + 0x0804)
76}; 76};
77 77
78static int wl1251_upload_firmware(struct wl12xx *wl) 78static int wl1251_upload_firmware(struct wl1251 *wl)
79{ 79{
80 struct wl12xx_partition_set *p_table = wl->chip.p_table; 80 struct wl1251_partition_set *p_table = wl->chip.p_table;
81 int addr, chunk_num, partition_limit; 81 int addr, chunk_num, partition_limit;
82 size_t fw_data_len; 82 size_t fw_data_len;
83 u8 *p; 83 u8 *p;
84 84
85 /* whal_FwCtrl_LoadFwImageSm() */ 85 /* whal_FwCtrl_LoadFwImageSm() */
86 86
87 wl12xx_debug(DEBUG_BOOT, "chip id before fw upload: 0x%x", 87 wl1251_debug(DEBUG_BOOT, "chip id before fw upload: 0x%x",
88 wl12xx_reg_read32(wl, CHIP_ID_B)); 88 wl1251_reg_read32(wl, CHIP_ID_B));
89 89
90 /* 10.0 check firmware length and set partition */ 90 /* 10.0 check firmware length and set partition */
91 fw_data_len = (wl->fw[4] << 24) | (wl->fw[5] << 16) | 91 fw_data_len = (wl->fw[4] << 24) | (wl->fw[5] << 16) |
92 (wl->fw[6] << 8) | (wl->fw[7]); 92 (wl->fw[6] << 8) | (wl->fw[7]);
93 93
94 wl12xx_debug(DEBUG_BOOT, "fw_data_len %zu chunk_size %d", fw_data_len, 94 wl1251_debug(DEBUG_BOOT, "fw_data_len %zu chunk_size %d", fw_data_len,
95 CHUNK_SIZE); 95 CHUNK_SIZE);
96 96
97 if ((fw_data_len % 4) != 0) { 97 if ((fw_data_len % 4) != 0) {
98 wl12xx_error("firmware length not multiple of four"); 98 wl1251_error("firmware length not multiple of four");
99 return -EIO; 99 return -EIO;
100 } 100 }
101 101
102 wl12xx_set_partition(wl, 102 wl1251_set_partition(wl,
103 p_table[PART_DOWN].mem.start, 103 p_table[PART_DOWN].mem.start,
104 p_table[PART_DOWN].mem.size, 104 p_table[PART_DOWN].mem.size,
105 p_table[PART_DOWN].reg.start, 105 p_table[PART_DOWN].reg.start,
@@ -118,7 +118,7 @@ static int wl1251_upload_firmware(struct wl12xx *wl)
118 chunk_num * CHUNK_SIZE; 118 chunk_num * CHUNK_SIZE;
119 partition_limit = chunk_num * CHUNK_SIZE + 119 partition_limit = chunk_num * CHUNK_SIZE +
120 p_table[PART_DOWN].mem.size; 120 p_table[PART_DOWN].mem.size;
121 wl12xx_set_partition(wl, 121 wl1251_set_partition(wl,
122 addr, 122 addr,
123 p_table[PART_DOWN].mem.size, 123 p_table[PART_DOWN].mem.size,
124 p_table[PART_DOWN].reg.start, 124 p_table[PART_DOWN].reg.start,
@@ -128,9 +128,9 @@ static int wl1251_upload_firmware(struct wl12xx *wl)
128 /* 10.3 upload the chunk */ 128 /* 10.3 upload the chunk */
129 addr = p_table[PART_DOWN].mem.start + chunk_num * CHUNK_SIZE; 129 addr = p_table[PART_DOWN].mem.start + chunk_num * CHUNK_SIZE;
130 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE; 130 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
131 wl12xx_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x", 131 wl1251_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
132 p, addr); 132 p, addr);
133 wl12xx_spi_mem_write(wl, addr, p, CHUNK_SIZE); 133 wl1251_spi_mem_write(wl, addr, p, CHUNK_SIZE);
134 134
135 chunk_num++; 135 chunk_num++;
136 } 136 }
@@ -138,14 +138,14 @@ static int wl1251_upload_firmware(struct wl12xx *wl)
138 /* 10.4 upload the last chunk */ 138 /* 10.4 upload the last chunk */
139 addr = p_table[PART_DOWN].mem.start + chunk_num * CHUNK_SIZE; 139 addr = p_table[PART_DOWN].mem.start + chunk_num * CHUNK_SIZE;
140 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE; 140 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
141 wl12xx_debug(DEBUG_BOOT, "uploading fw last chunk (%zu B) 0x%p to 0x%x", 141 wl1251_debug(DEBUG_BOOT, "uploading fw last chunk (%zu B) 0x%p to 0x%x",
142 fw_data_len % CHUNK_SIZE, p, addr); 142 fw_data_len % CHUNK_SIZE, p, addr);
143 wl12xx_spi_mem_write(wl, addr, p, fw_data_len % CHUNK_SIZE); 143 wl1251_spi_mem_write(wl, addr, p, fw_data_len % CHUNK_SIZE);
144 144
145 return 0; 145 return 0;
146} 146}
147 147
148static int wl1251_upload_nvs(struct wl12xx *wl) 148static int wl1251_upload_nvs(struct wl1251 *wl)
149{ 149{
150 size_t nvs_len, nvs_bytes_written, burst_len; 150 size_t nvs_len, nvs_bytes_written, burst_len;
151 int nvs_start, i; 151 int nvs_start, i;
@@ -181,10 +181,10 @@ static int wl1251_upload_nvs(struct wl12xx *wl)
181 val = (nvs_ptr[0] | (nvs_ptr[1] << 8) 181 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
182 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24)); 182 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
183 183
184 wl12xx_debug(DEBUG_BOOT, 184 wl1251_debug(DEBUG_BOOT,
185 "nvs burst write 0x%x: 0x%x", 185 "nvs burst write 0x%x: 0x%x",
186 dest_addr, val); 186 dest_addr, val);
187 wl12xx_mem_write32(wl, dest_addr, val); 187 wl1251_mem_write32(wl, dest_addr, val);
188 188
189 nvs_ptr += 4; 189 nvs_ptr += 4;
190 dest_addr += 4; 190 dest_addr += 4;
@@ -200,7 +200,7 @@ static int wl1251_upload_nvs(struct wl12xx *wl)
200 nvs_len = ALIGN(nvs_len, 4); 200 nvs_len = ALIGN(nvs_len, 4);
201 201
202 /* Now we must set the partition correctly */ 202 /* Now we must set the partition correctly */
203 wl12xx_set_partition(wl, nvs_start, 203 wl1251_set_partition(wl, nvs_start,
204 wl->chip.p_table[PART_DOWN].mem.size, 204 wl->chip.p_table[PART_DOWN].mem.size,
205 wl->chip.p_table[PART_DOWN].reg.start, 205 wl->chip.p_table[PART_DOWN].reg.start,
206 wl->chip.p_table[PART_DOWN].reg.size); 206 wl->chip.p_table[PART_DOWN].reg.size);
@@ -213,10 +213,10 @@ static int wl1251_upload_nvs(struct wl12xx *wl)
213 213
214 val = cpu_to_le32(val); 214 val = cpu_to_le32(val);
215 215
216 wl12xx_debug(DEBUG_BOOT, 216 wl1251_debug(DEBUG_BOOT,
217 "nvs write table 0x%x: 0x%x", 217 "nvs write table 0x%x: 0x%x",
218 nvs_start, val); 218 nvs_start, val);
219 wl12xx_mem_write32(wl, nvs_start, val); 219 wl1251_mem_write32(wl, nvs_start, val);
220 220
221 nvs_ptr += 4; 221 nvs_ptr += 4;
222 nvs_bytes_written += 4; 222 nvs_bytes_written += 4;
@@ -226,12 +226,12 @@ static int wl1251_upload_nvs(struct wl12xx *wl)
226 return 0; 226 return 0;
227} 227}
228 228
229static int wl1251_boot(struct wl12xx *wl) 229static int wl1251_boot(struct wl1251 *wl)
230{ 230{
231 int ret = 0, minor_minor_e2_ver; 231 int ret = 0, minor_minor_e2_ver;
232 u32 tmp, boot_data; 232 u32 tmp, boot_data;
233 233
234 ret = wl12xx_boot_soft_reset(wl); 234 ret = wl1251_boot_soft_reset(wl);
235 if (ret < 0) 235 if (ret < 0)
236 goto out; 236 goto out;
237 237
@@ -242,39 +242,39 @@ static int wl1251_boot(struct wl12xx *wl)
242 242
243 /* write firmware's last address (ie. it's length) to 243 /* write firmware's last address (ie. it's length) to
244 * ACX_EEPROMLESS_IND_REG */ 244 * ACX_EEPROMLESS_IND_REG */
245 wl12xx_reg_write32(wl, ACX_EEPROMLESS_IND_REG, wl->fw_len); 245 wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, wl->fw_len);
246 246
247 /* 6. read the EEPROM parameters */ 247 /* 6. read the EEPROM parameters */
248 tmp = wl12xx_reg_read32(wl, SCR_PAD2); 248 tmp = wl1251_reg_read32(wl, SCR_PAD2);
249 249
250 /* 7. read bootdata */ 250 /* 7. read bootdata */
251 wl->boot_attr.radio_type = (tmp & 0x0000FF00) >> 8; 251 wl->boot_attr.radio_type = (tmp & 0x0000FF00) >> 8;
252 wl->boot_attr.major = (tmp & 0x00FF0000) >> 16; 252 wl->boot_attr.major = (tmp & 0x00FF0000) >> 16;
253 tmp = wl12xx_reg_read32(wl, SCR_PAD3); 253 tmp = wl1251_reg_read32(wl, SCR_PAD3);
254 254
255 /* 8. check bootdata and call restart sequence */ 255 /* 8. check bootdata and call restart sequence */
256 wl->boot_attr.minor = (tmp & 0x00FF0000) >> 16; 256 wl->boot_attr.minor = (tmp & 0x00FF0000) >> 16;
257 minor_minor_e2_ver = (tmp & 0xFF000000) >> 24; 257 minor_minor_e2_ver = (tmp & 0xFF000000) >> 24;
258 258
259 wl12xx_debug(DEBUG_BOOT, "radioType 0x%x majorE2Ver 0x%x " 259 wl1251_debug(DEBUG_BOOT, "radioType 0x%x majorE2Ver 0x%x "
260 "minorE2Ver 0x%x minor_minor_e2_ver 0x%x", 260 "minorE2Ver 0x%x minor_minor_e2_ver 0x%x",
261 wl->boot_attr.radio_type, wl->boot_attr.major, 261 wl->boot_attr.radio_type, wl->boot_attr.major,
262 wl->boot_attr.minor, minor_minor_e2_ver); 262 wl->boot_attr.minor, minor_minor_e2_ver);
263 263
264 ret = wl12xx_boot_init_seq(wl); 264 ret = wl1251_boot_init_seq(wl);
265 if (ret < 0) 265 if (ret < 0)
266 goto out; 266 goto out;
267 267
268 /* 9. NVS processing done */ 268 /* 9. NVS processing done */
269 boot_data = wl12xx_reg_read32(wl, ACX_REG_ECPU_CONTROL); 269 boot_data = wl1251_reg_read32(wl, ACX_REG_ECPU_CONTROL);
270 270
271 wl12xx_debug(DEBUG_BOOT, "halt boot_data 0x%x", boot_data); 271 wl1251_debug(DEBUG_BOOT, "halt boot_data 0x%x", boot_data);
272 272
273 /* 10. check that ECPU_CONTROL_HALT bits are set in 273 /* 10. check that ECPU_CONTROL_HALT bits are set in
274 * pWhalBus->uBootData and start uploading firmware 274 * pWhalBus->uBootData and start uploading firmware
275 */ 275 */
276 if ((boot_data & ECPU_CONTROL_HALT) == 0) { 276 if ((boot_data & ECPU_CONTROL_HALT) == 0) {
277 wl12xx_error("boot failed, ECPU_CONTROL_HALT not set"); 277 wl1251_error("boot failed, ECPU_CONTROL_HALT not set");
278 ret = -EIO; 278 ret = -EIO;
279 goto out; 279 goto out;
280 } 280 }
@@ -284,62 +284,62 @@ static int wl1251_boot(struct wl12xx *wl)
284 goto out; 284 goto out;
285 285
286 /* 10.5 start firmware */ 286 /* 10.5 start firmware */
287 ret = wl12xx_boot_run_firmware(wl); 287 ret = wl1251_boot_run_firmware(wl);
288 if (ret < 0) 288 if (ret < 0)
289 goto out; 289 goto out;
290 290
291 /* Get and save the firmware version */
292 wl12xx_acx_fw_version(wl, wl->chip.fw_ver, sizeof(wl->chip.fw_ver));
293
294out: 291out:
295 return ret; 292 return ret;
296} 293}
297 294
298static int wl1251_mem_cfg(struct wl12xx *wl) 295static int wl1251_mem_cfg(struct wl1251 *wl)
299{ 296{
300 struct wl1251_acx_config_memory mem_conf; 297 struct wl1251_acx_config_memory *mem_conf;
301 int ret, i; 298 int ret, i;
302 299
303 wl12xx_debug(DEBUG_ACX, "wl1251 mem cfg"); 300 wl1251_debug(DEBUG_ACX, "wl1251 mem cfg");
301
302 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
303 if (!mem_conf) {
304 ret = -ENOMEM;
305 goto out;
306 }
304 307
305 /* memory config */ 308 /* memory config */
306 mem_conf.mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS); 309 mem_conf->mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
307 mem_conf.mem_config.rx_mem_block_num = 35; 310 mem_conf->mem_config.rx_mem_block_num = 35;
308 mem_conf.mem_config.tx_min_mem_block_num = 64; 311 mem_conf->mem_config.tx_min_mem_block_num = 64;
309 mem_conf.mem_config.num_tx_queues = MAX_TX_QUEUES; 312 mem_conf->mem_config.num_tx_queues = MAX_TX_QUEUES;
310 mem_conf.mem_config.host_if_options = HOSTIF_PKT_RING; 313 mem_conf->mem_config.host_if_options = HOSTIF_PKT_RING;
311 mem_conf.mem_config.num_ssid_profiles = 1; 314 mem_conf->mem_config.num_ssid_profiles = 1;
312 mem_conf.mem_config.debug_buffer_size = 315 mem_conf->mem_config.debug_buffer_size =
313 cpu_to_le16(TRACE_BUFFER_MAX_SIZE); 316 cpu_to_le16(TRACE_BUFFER_MAX_SIZE);
314 317
315 /* RX queue config */ 318 /* RX queue config */
316 mem_conf.rx_queue_config.dma_address = 0; 319 mem_conf->rx_queue_config.dma_address = 0;
317 mem_conf.rx_queue_config.num_descs = ACX_RX_DESC_DEF; 320 mem_conf->rx_queue_config.num_descs = ACX_RX_DESC_DEF;
318 mem_conf.rx_queue_config.priority = DEFAULT_RXQ_PRIORITY; 321 mem_conf->rx_queue_config.priority = DEFAULT_RXQ_PRIORITY;
319 mem_conf.rx_queue_config.type = DEFAULT_RXQ_TYPE; 322 mem_conf->rx_queue_config.type = DEFAULT_RXQ_TYPE;
320 323
321 /* TX queue config */ 324 /* TX queue config */
322 for (i = 0; i < MAX_TX_QUEUES; i++) { 325 for (i = 0; i < MAX_TX_QUEUES; i++) {
323 mem_conf.tx_queue_config[i].num_descs = ACX_TX_DESC_DEF; 326 mem_conf->tx_queue_config[i].num_descs = ACX_TX_DESC_DEF;
324 mem_conf.tx_queue_config[i].attributes = i; 327 mem_conf->tx_queue_config[i].attributes = i;
325 } 328 }
326 329
327 mem_conf.header.id = ACX_MEM_CFG; 330 ret = wl1251_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
328 mem_conf.header.len = sizeof(struct wl1251_acx_config_memory) - 331 sizeof(*mem_conf));
329 sizeof(struct acx_header); 332 if (ret < 0) {
330 mem_conf.header.len -= 333 wl1251_warning("wl1251 mem config failed: %d", ret);
331 (MAX_TX_QUEUE_CONFIGS - mem_conf.mem_config.num_tx_queues) * 334 goto out;
332 sizeof(struct wl1251_acx_tx_queue_config); 335 }
333
334 ret = wl12xx_cmd_configure(wl, &mem_conf,
335 sizeof(struct wl1251_acx_config_memory));
336 if (ret < 0)
337 wl12xx_warning("wl1251 mem config failed: %d", ret);
338 336
337out:
338 kfree(mem_conf);
339 return ret; 339 return ret;
340} 340}
341 341
342static int wl1251_hw_init_mem_config(struct wl12xx *wl) 342static int wl1251_hw_init_mem_config(struct wl1251 *wl)
343{ 343{
344 int ret; 344 int ret;
345 345
@@ -350,15 +350,15 @@ static int wl1251_hw_init_mem_config(struct wl12xx *wl)
350 wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map), 350 wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
351 GFP_KERNEL); 351 GFP_KERNEL);
352 if (!wl->target_mem_map) { 352 if (!wl->target_mem_map) {
353 wl12xx_error("couldn't allocate target memory map"); 353 wl1251_error("couldn't allocate target memory map");
354 return -ENOMEM; 354 return -ENOMEM;
355 } 355 }
356 356
357 /* we now ask for the firmware built memory map */ 357 /* we now ask for the firmware built memory map */
358 ret = wl12xx_acx_mem_map(wl, wl->target_mem_map, 358 ret = wl1251_acx_mem_map(wl, wl->target_mem_map,
359 sizeof(struct wl1251_acx_mem_map)); 359 sizeof(struct wl1251_acx_mem_map));
360 if (ret < 0) { 360 if (ret < 0) {
361 wl12xx_error("couldn't retrieve firmware memory map"); 361 wl1251_error("couldn't retrieve firmware memory map");
362 kfree(wl->target_mem_map); 362 kfree(wl->target_mem_map);
363 wl->target_mem_map = NULL; 363 wl->target_mem_map = NULL;
364 return ret; 364 return ret;
@@ -367,19 +367,19 @@ static int wl1251_hw_init_mem_config(struct wl12xx *wl)
367 return 0; 367 return 0;
368} 368}
369 369
370static void wl1251_set_ecpu_ctrl(struct wl12xx *wl, u32 flag) 370static void wl1251_set_ecpu_ctrl(struct wl1251 *wl, u32 flag)
371{ 371{
372 u32 cpu_ctrl; 372 u32 cpu_ctrl;
373 373
374 /* 10.5.0 run the firmware (I) */ 374 /* 10.5.0 run the firmware (I) */
375 cpu_ctrl = wl12xx_reg_read32(wl, ACX_REG_ECPU_CONTROL); 375 cpu_ctrl = wl1251_reg_read32(wl, ACX_REG_ECPU_CONTROL);
376 376
377 /* 10.5.1 run the firmware (II) */ 377 /* 10.5.1 run the firmware (II) */
378 cpu_ctrl &= ~flag; 378 cpu_ctrl &= ~flag;
379 wl12xx_reg_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl); 379 wl1251_reg_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
380} 380}
381 381
382static void wl1251_target_enable_interrupts(struct wl12xx *wl) 382static void wl1251_target_enable_interrupts(struct wl1251 *wl)
383{ 383{
384 /* Enable target's interrupts */ 384 /* Enable target's interrupts */
385 wl->intr_mask = WL1251_ACX_INTR_RX0_DATA | 385 wl->intr_mask = WL1251_ACX_INTR_RX0_DATA |
@@ -388,52 +388,60 @@ static void wl1251_target_enable_interrupts(struct wl12xx *wl)
388 WL1251_ACX_INTR_EVENT_A | 388 WL1251_ACX_INTR_EVENT_A |
389 WL1251_ACX_INTR_EVENT_B | 389 WL1251_ACX_INTR_EVENT_B |
390 WL1251_ACX_INTR_INIT_COMPLETE; 390 WL1251_ACX_INTR_INIT_COMPLETE;
391 wl12xx_boot_target_enable_interrupts(wl); 391 wl1251_boot_target_enable_interrupts(wl);
392}
393
394static void wl1251_fw_version(struct wl1251 *wl)
395{
396 wl1251_acx_fw_version(wl, wl->chip.fw_ver, sizeof(wl->chip.fw_ver));
392} 397}
393 398
394static void wl1251_irq_work(struct work_struct *work) 399static void wl1251_irq_work(struct work_struct *work)
395{ 400{
396 u32 intr; 401 u32 intr;
397 struct wl12xx *wl = 402 struct wl1251 *wl =
398 container_of(work, struct wl12xx, irq_work); 403 container_of(work, struct wl1251, irq_work);
404 int ret;
399 405
400 mutex_lock(&wl->mutex); 406 mutex_lock(&wl->mutex);
401 407
402 wl12xx_debug(DEBUG_IRQ, "IRQ work"); 408 wl1251_debug(DEBUG_IRQ, "IRQ work");
403 409
404 if (wl->state == WL12XX_STATE_OFF) 410 if (wl->state == WL1251_STATE_OFF)
405 goto out; 411 goto out;
406 412
407 wl12xx_ps_elp_wakeup(wl); 413 ret = wl1251_ps_elp_wakeup(wl);
414 if (ret < 0)
415 goto out;
408 416
409 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1251_ACX_INTR_ALL); 417 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1251_ACX_INTR_ALL);
410 418
411 intr = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR); 419 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
412 wl12xx_debug(DEBUG_IRQ, "intr: 0x%x", intr); 420 wl1251_debug(DEBUG_IRQ, "intr: 0x%x", intr);
413 421
414 if (wl->data_path) { 422 if (wl->data_path) {
415 wl12xx_spi_mem_read(wl, wl->data_path->rx_control_addr, 423 wl->rx_counter =
416 &wl->rx_counter, sizeof(u32)); 424 wl1251_mem_read32(wl, wl->data_path->rx_control_addr);
417 425
418 /* We handle a frmware bug here */ 426 /* We handle a frmware bug here */
419 switch ((wl->rx_counter - wl->rx_handled) & 0xf) { 427 switch ((wl->rx_counter - wl->rx_handled) & 0xf) {
420 case 0: 428 case 0:
421 wl12xx_debug(DEBUG_IRQ, "RX: FW and host in sync"); 429 wl1251_debug(DEBUG_IRQ, "RX: FW and host in sync");
422 intr &= ~WL1251_ACX_INTR_RX0_DATA; 430 intr &= ~WL1251_ACX_INTR_RX0_DATA;
423 intr &= ~WL1251_ACX_INTR_RX1_DATA; 431 intr &= ~WL1251_ACX_INTR_RX1_DATA;
424 break; 432 break;
425 case 1: 433 case 1:
426 wl12xx_debug(DEBUG_IRQ, "RX: FW +1"); 434 wl1251_debug(DEBUG_IRQ, "RX: FW +1");
427 intr |= WL1251_ACX_INTR_RX0_DATA; 435 intr |= WL1251_ACX_INTR_RX0_DATA;
428 intr &= ~WL1251_ACX_INTR_RX1_DATA; 436 intr &= ~WL1251_ACX_INTR_RX1_DATA;
429 break; 437 break;
430 case 2: 438 case 2:
431 wl12xx_debug(DEBUG_IRQ, "RX: FW +2"); 439 wl1251_debug(DEBUG_IRQ, "RX: FW +2");
432 intr |= WL1251_ACX_INTR_RX0_DATA; 440 intr |= WL1251_ACX_INTR_RX0_DATA;
433 intr |= WL1251_ACX_INTR_RX1_DATA; 441 intr |= WL1251_ACX_INTR_RX1_DATA;
434 break; 442 break;
435 default: 443 default:
436 wl12xx_warning("RX: FW and host out of sync: %d", 444 wl1251_warning("RX: FW and host out of sync: %d",
437 wl->rx_counter - wl->rx_handled); 445 wl->rx_counter - wl->rx_handled);
438 break; 446 break;
439 } 447 }
@@ -441,49 +449,50 @@ static void wl1251_irq_work(struct work_struct *work)
441 wl->rx_handled = wl->rx_counter; 449 wl->rx_handled = wl->rx_counter;
442 450
443 451
444 wl12xx_debug(DEBUG_IRQ, "RX counter: %d", wl->rx_counter); 452 wl1251_debug(DEBUG_IRQ, "RX counter: %d", wl->rx_counter);
445 } 453 }
446 454
447 intr &= wl->intr_mask; 455 intr &= wl->intr_mask;
448 456
449 if (intr == 0) { 457 if (intr == 0) {
450 wl12xx_debug(DEBUG_IRQ, "INTR is 0"); 458 wl1251_debug(DEBUG_IRQ, "INTR is 0");
451 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK, 459 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK,
452 ~(wl->intr_mask)); 460 ~(wl->intr_mask));
453 461
454 goto out_sleep; 462 goto out_sleep;
455 } 463 }
456 464
457 if (intr & WL1251_ACX_INTR_RX0_DATA) { 465 if (intr & WL1251_ACX_INTR_RX0_DATA) {
458 wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA"); 466 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA");
459 wl12xx_rx(wl); 467 wl1251_rx(wl);
460 } 468 }
461 469
462 if (intr & WL1251_ACX_INTR_RX1_DATA) { 470 if (intr & WL1251_ACX_INTR_RX1_DATA) {
463 wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA"); 471 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA");
464 wl12xx_rx(wl); 472 wl1251_rx(wl);
465 } 473 }
466 474
467 if (intr & WL1251_ACX_INTR_TX_RESULT) { 475 if (intr & WL1251_ACX_INTR_TX_RESULT) {
468 wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT"); 476 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT");
469 wl12xx_tx_complete(wl); 477 wl1251_tx_complete(wl);
470 } 478 }
471 479
472 if (intr & (WL1251_ACX_INTR_EVENT_A | WL1251_ACX_INTR_EVENT_B)) { 480 if (intr & (WL1251_ACX_INTR_EVENT_A | WL1251_ACX_INTR_EVENT_B)) {
473 wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT (0x%x)", intr); 481 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT (0x%x)", intr);
474 if (intr & WL1251_ACX_INTR_EVENT_A) 482 if (intr & WL1251_ACX_INTR_EVENT_A)
475 wl12xx_event_handle(wl, 0); 483 wl1251_event_handle(wl, 0);
476 else 484 else
477 wl12xx_event_handle(wl, 1); 485 wl1251_event_handle(wl, 1);
478 } 486 }
479 487
480 if (intr & WL1251_ACX_INTR_INIT_COMPLETE) 488 if (intr & WL1251_ACX_INTR_INIT_COMPLETE)
481 wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_INIT_COMPLETE"); 489 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_INIT_COMPLETE");
482 490
483 wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask)); 491 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
484 492
485out_sleep: 493out_sleep:
486 wl12xx_ps_elp_sleep(wl); 494 wl1251_ps_elp_sleep(wl);
495
487out: 496out:
488 mutex_unlock(&wl->mutex); 497 mutex_unlock(&wl->mutex);
489} 498}
@@ -520,40 +529,45 @@ static int wl1251_hw_init_txq_fill(u8 qid,
520 (QOS_TX_LOW_VO_DEF * num_blocks) / 100; 529 (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
521 break; 530 break;
522 default: 531 default:
523 wl12xx_error("Invalid TX queue id: %d", qid); 532 wl1251_error("Invalid TX queue id: %d", qid);
524 return -EINVAL; 533 return -EINVAL;
525 } 534 }
526 535
527 return 0; 536 return 0;
528} 537}
529 538
530static int wl1251_hw_init_tx_queue_config(struct wl12xx *wl) 539static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
531{ 540{
532 struct acx_tx_queue_qos_config config; 541 struct acx_tx_queue_qos_config *config;
533 struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map; 542 struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
534 int ret, i; 543 int ret, i;
535 544
536 wl12xx_debug(DEBUG_ACX, "acx tx queue config"); 545 wl1251_debug(DEBUG_ACX, "acx tx queue config");
537 546
538 config.header.id = ACX_TX_QUEUE_CFG; 547 config = kzalloc(sizeof(*config), GFP_KERNEL);
539 config.header.len = sizeof(struct acx_tx_queue_qos_config) - 548 if (!config) {
540 sizeof(struct acx_header); 549 ret = -ENOMEM;
550 goto out;
551 }
541 552
542 for (i = 0; i < MAX_NUM_OF_AC; i++) { 553 for (i = 0; i < MAX_NUM_OF_AC; i++) {
543 ret = wl1251_hw_init_txq_fill(i, &config, 554 ret = wl1251_hw_init_txq_fill(i, config,
544 wl_mem_map->num_tx_mem_blocks); 555 wl_mem_map->num_tx_mem_blocks);
545 if (ret < 0) 556 if (ret < 0)
546 return ret; 557 goto out;
547 558
548 ret = wl12xx_cmd_configure(wl, &config, sizeof(config)); 559 ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
560 config, sizeof(*config));
549 if (ret < 0) 561 if (ret < 0)
550 return ret; 562 goto out;
551 } 563 }
552 564
553 return 0; 565out:
566 kfree(config);
567 return ret;
554} 568}
555 569
556static int wl1251_hw_init_data_path_config(struct wl12xx *wl) 570static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
557{ 571{
558 int ret; 572 int ret;
559 573
@@ -561,11 +575,11 @@ static int wl1251_hw_init_data_path_config(struct wl12xx *wl)
561 wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp), 575 wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
562 GFP_KERNEL); 576 GFP_KERNEL);
563 if (!wl->data_path) { 577 if (!wl->data_path) {
564 wl12xx_error("Couldnt allocate data path parameters"); 578 wl1251_error("Couldnt allocate data path parameters");
565 return -ENOMEM; 579 return -ENOMEM;
566 } 580 }
567 581
568 ret = wl12xx_acx_data_path_params(wl, wl->data_path); 582 ret = wl1251_acx_data_path_params(wl, wl->data_path);
569 if (ret < 0) { 583 if (ret < 0) {
570 kfree(wl->data_path); 584 kfree(wl->data_path);
571 wl->data_path = NULL; 585 wl->data_path = NULL;
@@ -575,17 +589,17 @@ static int wl1251_hw_init_data_path_config(struct wl12xx *wl)
575 return 0; 589 return 0;
576} 590}
577 591
578static int wl1251_hw_init(struct wl12xx *wl) 592static int wl1251_hw_init(struct wl1251 *wl)
579{ 593{
580 struct wl1251_acx_mem_map *wl_mem_map; 594 struct wl1251_acx_mem_map *wl_mem_map;
581 int ret; 595 int ret;
582 596
583 ret = wl12xx_hw_init_hwenc_config(wl); 597 ret = wl1251_hw_init_hwenc_config(wl);
584 if (ret < 0) 598 if (ret < 0)
585 return ret; 599 return ret;
586 600
587 /* Template settings */ 601 /* Template settings */
588 ret = wl12xx_hw_init_templates_config(wl); 602 ret = wl1251_hw_init_templates_config(wl);
589 if (ret < 0) 603 if (ret < 0)
590 return ret; 604 return ret;
591 605
@@ -600,7 +614,7 @@ static int wl1251_hw_init(struct wl12xx *wl)
600 goto out_free_memmap; 614 goto out_free_memmap;
601 615
602 /* RX config */ 616 /* RX config */
603 ret = wl12xx_hw_init_rx_config(wl, 617 ret = wl1251_hw_init_rx_config(wl,
604 RX_CFG_PROMISCUOUS | RX_CFG_TSF, 618 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
605 RX_FILTER_OPTION_DEF); 619 RX_FILTER_OPTION_DEF);
606 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS, 620 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
@@ -614,42 +628,42 @@ static int wl1251_hw_init(struct wl12xx *wl)
614 goto out_free_data_path; 628 goto out_free_data_path;
615 629
616 /* PHY layer config */ 630 /* PHY layer config */
617 ret = wl12xx_hw_init_phy_config(wl); 631 ret = wl1251_hw_init_phy_config(wl);
618 if (ret < 0) 632 if (ret < 0)
619 goto out_free_data_path; 633 goto out_free_data_path;
620 634
621 /* Beacon filtering */ 635 /* Beacon filtering */
622 ret = wl12xx_hw_init_beacon_filter(wl); 636 ret = wl1251_hw_init_beacon_filter(wl);
623 if (ret < 0) 637 if (ret < 0)
624 goto out_free_data_path; 638 goto out_free_data_path;
625 639
626 /* Bluetooth WLAN coexistence */ 640 /* Bluetooth WLAN coexistence */
627 ret = wl12xx_hw_init_pta(wl); 641 ret = wl1251_hw_init_pta(wl);
628 if (ret < 0) 642 if (ret < 0)
629 goto out_free_data_path; 643 goto out_free_data_path;
630 644
631 /* Energy detection */ 645 /* Energy detection */
632 ret = wl12xx_hw_init_energy_detection(wl); 646 ret = wl1251_hw_init_energy_detection(wl);
633 if (ret < 0) 647 if (ret < 0)
634 goto out_free_data_path; 648 goto out_free_data_path;
635 649
636 /* Beacons and boradcast settings */ 650 /* Beacons and boradcast settings */
637 ret = wl12xx_hw_init_beacon_broadcast(wl); 651 ret = wl1251_hw_init_beacon_broadcast(wl);
638 if (ret < 0) 652 if (ret < 0)
639 goto out_free_data_path; 653 goto out_free_data_path;
640 654
641 /* Enable data path */ 655 /* Enable data path */
642 ret = wl12xx_cmd_data_path(wl, wl->channel, 1); 656 ret = wl1251_cmd_data_path(wl, wl->channel, 1);
643 if (ret < 0) 657 if (ret < 0)
644 goto out_free_data_path; 658 goto out_free_data_path;
645 659
646 /* Default power state */ 660 /* Default power state */
647 ret = wl12xx_hw_init_power_auth(wl); 661 ret = wl1251_hw_init_power_auth(wl);
648 if (ret < 0) 662 if (ret < 0)
649 goto out_free_data_path; 663 goto out_free_data_path;
650 664
651 wl_mem_map = wl->target_mem_map; 665 wl_mem_map = wl->target_mem_map;
652 wl12xx_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x", 666 wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
653 wl_mem_map->num_tx_mem_blocks, 667 wl_mem_map->num_tx_mem_blocks,
654 wl->data_path->tx_control_addr, 668 wl->data_path->tx_control_addr,
655 wl_mem_map->num_rx_mem_blocks, 669 wl_mem_map->num_rx_mem_blocks,
@@ -666,7 +680,7 @@ static int wl1251_hw_init(struct wl12xx *wl)
666 return ret; 680 return ret;
667} 681}
668 682
669static int wl1251_plt_init(struct wl12xx *wl) 683static int wl1251_plt_init(struct wl1251 *wl)
670{ 684{
671 int ret; 685 int ret;
672 686
@@ -674,14 +688,14 @@ static int wl1251_plt_init(struct wl12xx *wl)
674 if (ret < 0) 688 if (ret < 0)
675 return ret; 689 return ret;
676 690
677 ret = wl12xx_cmd_data_path(wl, wl->channel, 1); 691 ret = wl1251_cmd_data_path(wl, wl->channel, 1);
678 if (ret < 0) 692 if (ret < 0)
679 return ret; 693 return ret;
680 694
681 return 0; 695 return 0;
682} 696}
683 697
684void wl1251_setup(struct wl12xx *wl) 698void wl1251_setup(struct wl1251 *wl)
685{ 699{
686 /* FIXME: Is it better to use strncpy here or is this ok? */ 700 /* FIXME: Is it better to use strncpy here or is this ok? */
687 wl->chip.fw_filename = WL1251_FW_NAME; 701 wl->chip.fw_filename = WL1251_FW_NAME;
@@ -701,9 +715,14 @@ void wl1251_setup(struct wl12xx *wl)
701 wl->chip.op_target_enable_interrupts = wl1251_target_enable_interrupts; 715 wl->chip.op_target_enable_interrupts = wl1251_target_enable_interrupts;
702 wl->chip.op_hw_init = wl1251_hw_init; 716 wl->chip.op_hw_init = wl1251_hw_init;
703 wl->chip.op_plt_init = wl1251_plt_init; 717 wl->chip.op_plt_init = wl1251_plt_init;
718 wl->chip.op_fw_version = wl1251_fw_version;
719 wl->chip.op_tx_flush = wl1251_tx_flush;
720 wl->chip.op_cmd_join = wl1251_cmd_join;
704 721
705 wl->chip.p_table = wl1251_part_table; 722 wl->chip.p_table = wl1251_part_table;
706 wl->chip.acx_reg_table = wl1251_acx_reg_table; 723 wl->chip.acx_reg_table = wl1251_acx_reg_table;
707 724
708 INIT_WORK(&wl->irq_work, wl1251_irq_work); 725 INIT_WORK(&wl->irq_work, wl1251_irq_work);
726 INIT_WORK(&wl->tx_work, wl1251_tx_work);
727
709} 728}
diff --git a/drivers/net/wireless/wl12xx/wl1251_ops.h b/drivers/net/wireless/wl12xx/wl1251_ops.h
new file mode 100644
index 000000000000..68183c472e43
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1251_ops.h
@@ -0,0 +1,165 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#ifndef __WL1251_OPS_H__
25#define __WL1251_OPS_H__
26
27#include <linux/bitops.h>
28
29#include "wl1251.h"
30#include "wl1251_acx.h"
31
32#define WL1251_FW_NAME "wl1251-fw.bin"
33#define WL1251_NVS_NAME "wl1251-nvs.bin"
34
35#define WL1251_POWER_ON_SLEEP 10 /* in miliseconds */
36
37void wl1251_setup(struct wl1251 *wl);
38
39
40struct wl1251_acx_memory {
41 __le16 num_stations; /* number of STAs to be supported. */
42 u16 reserved_1;
43
44 /*
45 * Nmber of memory buffers for the RX mem pool.
46 * The actual number may be less if there are
47 * not enough blocks left for the minimum num
48 * of TX ones.
49 */
50 u8 rx_mem_block_num;
51 u8 reserved_2;
52 u8 num_tx_queues; /* From 1 to 16 */
53 u8 host_if_options; /* HOST_IF* */
54 u8 tx_min_mem_block_num;
55 u8 num_ssid_profiles;
56 __le16 debug_buffer_size;
57} __attribute__ ((packed));
58
59
60#define ACX_RX_DESC_MIN 1
61#define ACX_RX_DESC_MAX 127
62#define ACX_RX_DESC_DEF 32
63struct wl1251_acx_rx_queue_config {
64 u8 num_descs;
65 u8 pad;
66 u8 type;
67 u8 priority;
68 __le32 dma_address;
69} __attribute__ ((packed));
70
71#define ACX_TX_DESC_MIN 1
72#define ACX_TX_DESC_MAX 127
73#define ACX_TX_DESC_DEF 16
74struct wl1251_acx_tx_queue_config {
75 u8 num_descs;
76 u8 pad[2];
77 u8 attributes;
78} __attribute__ ((packed));
79
80#define MAX_TX_QUEUE_CONFIGS 5
81#define MAX_TX_QUEUES 4
82struct wl1251_acx_config_memory {
83 struct acx_header header;
84
85 struct wl1251_acx_memory mem_config;
86 struct wl1251_acx_rx_queue_config rx_queue_config;
87 struct wl1251_acx_tx_queue_config tx_queue_config[MAX_TX_QUEUE_CONFIGS];
88} __attribute__ ((packed));
89
90struct wl1251_acx_mem_map {
91 struct acx_header header;
92
93 void *code_start;
94 void *code_end;
95
96 void *wep_defkey_start;
97 void *wep_defkey_end;
98
99 void *sta_table_start;
100 void *sta_table_end;
101
102 void *packet_template_start;
103 void *packet_template_end;
104
105 void *queue_memory_start;
106 void *queue_memory_end;
107
108 void *packet_memory_pool_start;
109 void *packet_memory_pool_end;
110
111 void *debug_buffer1_start;
112 void *debug_buffer1_end;
113
114 void *debug_buffer2_start;
115 void *debug_buffer2_end;
116
117 /* Number of blocks FW allocated for TX packets */
118 u32 num_tx_mem_blocks;
119
120 /* Number of blocks FW allocated for RX packets */
121 u32 num_rx_mem_blocks;
122} __attribute__ ((packed));
123
124/*************************************************************************
125
126 Host Interrupt Register (WiLink -> Host)
127
128**************************************************************************/
129
130/* RX packet is ready in Xfer buffer #0 */
131#define WL1251_ACX_INTR_RX0_DATA BIT(0)
132
133/* TX result(s) are in the TX complete buffer */
134#define WL1251_ACX_INTR_TX_RESULT BIT(1)
135
136/* OBSOLETE */
137#define WL1251_ACX_INTR_TX_XFR BIT(2)
138
139/* RX packet is ready in Xfer buffer #1 */
140#define WL1251_ACX_INTR_RX1_DATA BIT(3)
141
142/* Event was entered to Event MBOX #A */
143#define WL1251_ACX_INTR_EVENT_A BIT(4)
144
145/* Event was entered to Event MBOX #B */
146#define WL1251_ACX_INTR_EVENT_B BIT(5)
147
148/* OBSOLETE */
149#define WL1251_ACX_INTR_WAKE_ON_HOST BIT(6)
150
151/* Trace meassge on MBOX #A */
152#define WL1251_ACX_INTR_TRACE_A BIT(7)
153
154/* Trace meassge on MBOX #B */
155#define WL1251_ACX_INTR_TRACE_B BIT(8)
156
157/* Command processing completion */
158#define WL1251_ACX_INTR_CMD_COMPLETE BIT(9)
159
160/* Init sequence is done */
161#define WL1251_ACX_INTR_INIT_COMPLETE BIT(14)
162
163#define WL1251_ACX_INTR_ALL 0xFFFFFFFF
164
165#endif
diff --git a/drivers/net/wireless/wl12xx/ps.c b/drivers/net/wireless/wl12xx/wl1251_ps.c
index 83a10117330b..68ff7f1900ed 100644
--- a/drivers/net/wireless/wl12xx/ps.c
+++ b/drivers/net/wireless/wl12xx/wl1251_ps.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (C) 2008 Nokia Corporation
5 * 5 *
@@ -22,25 +22,25 @@
22 */ 22 */
23 23
24#include "reg.h" 24#include "reg.h"
25#include "ps.h" 25#include "wl1251_ps.h"
26#include "spi.h" 26#include "wl1251_spi.h"
27 27
28#define WL12XX_WAKEUP_TIMEOUT 2000 28#define WL1251_WAKEUP_TIMEOUT 2000
29 29
30/* Routines to toggle sleep mode while in ELP */ 30/* Routines to toggle sleep mode while in ELP */
31void wl12xx_ps_elp_sleep(struct wl12xx *wl) 31void wl1251_ps_elp_sleep(struct wl1251 *wl)
32{ 32{
33 if (wl->elp || !wl->psm) 33 if (wl->elp || !wl->psm)
34 return; 34 return;
35 35
36 wl12xx_debug(DEBUG_PSM, "chip to elp"); 36 wl1251_debug(DEBUG_PSM, "chip to elp");
37 37
38 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP); 38 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
39 39
40 wl->elp = true; 40 wl->elp = true;
41} 41}
42 42
43int wl12xx_ps_elp_wakeup(struct wl12xx *wl) 43int wl1251_ps_elp_wakeup(struct wl1251 *wl)
44{ 44{
45 unsigned long timeout; 45 unsigned long timeout;
46 u32 elp_reg; 46 u32 elp_reg;
@@ -48,13 +48,13 @@ int wl12xx_ps_elp_wakeup(struct wl12xx *wl)
48 if (!wl->elp) 48 if (!wl->elp)
49 return 0; 49 return 0;
50 50
51 wl12xx_debug(DEBUG_PSM, "waking up chip from elp"); 51 wl1251_debug(DEBUG_PSM, "waking up chip from elp");
52 52
53 timeout = jiffies + msecs_to_jiffies(WL12XX_WAKEUP_TIMEOUT); 53 timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT);
54 54
55 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP); 55 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
56 56
57 elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); 57 elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
58 58
59 /* 59 /*
60 * FIXME: we should wait for irq from chip but, as a temporary 60 * FIXME: we should wait for irq from chip but, as a temporary
@@ -62,40 +62,36 @@ int wl12xx_ps_elp_wakeup(struct wl12xx *wl)
62 */ 62 */
63 while (!(elp_reg & ELPCTRL_WLAN_READY)) { 63 while (!(elp_reg & ELPCTRL_WLAN_READY)) {
64 if (time_after(jiffies, timeout)) { 64 if (time_after(jiffies, timeout)) {
65 wl12xx_error("elp wakeup timeout"); 65 wl1251_error("elp wakeup timeout");
66 return -ETIMEDOUT; 66 return -ETIMEDOUT;
67 } 67 }
68 msleep(1); 68 msleep(1);
69 elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); 69 elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
70 } 70 }
71 71
72 wl12xx_debug(DEBUG_PSM, "wakeup time: %u ms", 72 wl1251_debug(DEBUG_PSM, "wakeup time: %u ms",
73 jiffies_to_msecs(jiffies) - 73 jiffies_to_msecs(jiffies) -
74 (jiffies_to_msecs(timeout) - WL12XX_WAKEUP_TIMEOUT)); 74 (jiffies_to_msecs(timeout) - WL1251_WAKEUP_TIMEOUT));
75 75
76 wl->elp = false; 76 wl->elp = false;
77 77
78 return 0; 78 return 0;
79} 79}
80 80
81static int wl12xx_ps_set_elp(struct wl12xx *wl, bool enable) 81static int wl1251_ps_set_elp(struct wl1251 *wl, bool enable)
82{ 82{
83 int ret; 83 int ret;
84 84
85 if (enable) { 85 if (enable) {
86 wl12xx_debug(DEBUG_PSM, "sleep auth psm/elp"); 86 wl1251_debug(DEBUG_PSM, "sleep auth psm/elp");
87 87
88 /* 88 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
89 * FIXME: we should PSM_ELP, but because of firmware wakeup
90 * problems let's use only PSM_PS
91 */
92 ret = wl12xx_acx_sleep_auth(wl, WL12XX_PSM_PS);
93 if (ret < 0) 89 if (ret < 0)
94 return ret; 90 return ret;
95 91
96 wl12xx_ps_elp_sleep(wl); 92 wl1251_ps_elp_sleep(wl);
97 } else { 93 } else {
98 wl12xx_debug(DEBUG_PSM, "sleep auth cam"); 94 wl1251_debug(DEBUG_PSM, "sleep auth cam");
99 95
100 /* 96 /*
101 * When the target is in ELP, we can only 97 * When the target is in ELP, we can only
@@ -104,9 +100,9 @@ static int wl12xx_ps_set_elp(struct wl12xx *wl, bool enable)
104 * changing the power authorization. 100 * changing the power authorization.
105 */ 101 */
106 102
107 wl12xx_ps_elp_wakeup(wl); 103 wl1251_ps_elp_wakeup(wl);
108 104
109 ret = wl12xx_acx_sleep_auth(wl, WL12XX_PSM_CAM); 105 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
110 if (ret < 0) 106 if (ret < 0)
111 return ret; 107 return ret;
112 } 108 }
@@ -114,18 +110,18 @@ static int wl12xx_ps_set_elp(struct wl12xx *wl, bool enable)
114 return 0; 110 return 0;
115} 111}
116 112
117int wl12xx_ps_set_mode(struct wl12xx *wl, enum acx_ps_mode mode) 113int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode)
118{ 114{
119 int ret; 115 int ret;
120 116
121 switch (mode) { 117 switch (mode) {
122 case STATION_POWER_SAVE_MODE: 118 case STATION_POWER_SAVE_MODE:
123 wl12xx_debug(DEBUG_PSM, "entering psm"); 119 wl1251_debug(DEBUG_PSM, "entering psm");
124 ret = wl12xx_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE); 120 ret = wl1251_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE);
125 if (ret < 0) 121 if (ret < 0)
126 return ret; 122 return ret;
127 123
128 ret = wl12xx_ps_set_elp(wl, true); 124 ret = wl1251_ps_set_elp(wl, true);
129 if (ret < 0) 125 if (ret < 0)
130 return ret; 126 return ret;
131 127
@@ -133,12 +129,12 @@ int wl12xx_ps_set_mode(struct wl12xx *wl, enum acx_ps_mode mode)
133 break; 129 break;
134 case STATION_ACTIVE_MODE: 130 case STATION_ACTIVE_MODE:
135 default: 131 default:
136 wl12xx_debug(DEBUG_PSM, "leaving psm"); 132 wl1251_debug(DEBUG_PSM, "leaving psm");
137 ret = wl12xx_ps_set_elp(wl, false); 133 ret = wl1251_ps_set_elp(wl, false);
138 if (ret < 0) 134 if (ret < 0)
139 return ret; 135 return ret;
140 136
141 ret = wl12xx_cmd_ps_mode(wl, STATION_ACTIVE_MODE); 137 ret = wl1251_cmd_ps_mode(wl, STATION_ACTIVE_MODE);
142 if (ret < 0) 138 if (ret < 0)
143 return ret; 139 return ret;
144 140
diff --git a/drivers/net/wireless/wl12xx/ps.h b/drivers/net/wireless/wl12xx/wl1251_ps.h
index 5d7c52553830..db036fe12f25 100644
--- a/drivers/net/wireless/wl12xx/ps.h
+++ b/drivers/net/wireless/wl12xx/wl1251_ps.h
@@ -1,8 +1,8 @@
1#ifndef __WL12XX_PS_H__ 1#ifndef __WL1251_PS_H__
2#define __WL12XX_PS_H__ 2#define __WL1251_PS_H__
3 3
4/* 4/*
5 * This file is part of wl12xx 5 * This file is part of wl1251
6 * 6 *
7 * Copyright (c) 1998-2007 Texas Instruments Incorporated 7 * Copyright (c) 1998-2007 Texas Instruments Incorporated
8 * Copyright (C) 2008 Nokia Corporation 8 * Copyright (C) 2008 Nokia Corporation
@@ -25,12 +25,12 @@
25 * 25 *
26 */ 26 */
27 27
28#include "wl12xx.h" 28#include "wl1251.h"
29#include "acx.h" 29#include "wl1251_acx.h"
30 30
31int wl12xx_ps_set_mode(struct wl12xx *wl, enum acx_ps_mode mode); 31int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode);
32void wl12xx_ps_elp_sleep(struct wl12xx *wl); 32void wl1251_ps_elp_sleep(struct wl1251 *wl);
33int wl12xx_ps_elp_wakeup(struct wl12xx *wl); 33int wl1251_ps_elp_wakeup(struct wl1251 *wl);
34 34
35 35
36#endif /* __WL12XX_PS_H__ */ 36#endif /* __WL1251_PS_H__ */
diff --git a/drivers/net/wireless/wl12xx/rx.c b/drivers/net/wireless/wl12xx/wl1251_rx.c
index 981ea259eb89..0dbb483a0973 100644
--- a/drivers/net/wireless/wl12xx/rx.c
+++ b/drivers/net/wireless/wl12xx/wl1251_rx.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated 4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation 5 * Copyright (C) 2008 Nokia Corporation
@@ -25,13 +25,14 @@
25#include <linux/skbuff.h> 25#include <linux/skbuff.h>
26#include <net/mac80211.h> 26#include <net/mac80211.h>
27 27
28#include "wl12xx.h" 28#include "wl1251.h"
29#include "reg.h" 29#include "reg.h"
30#include "spi.h" 30#include "wl1251_spi.h"
31#include "rx.h" 31#include "wl1251_rx.h"
32#include "wl1251_acx.h"
32 33
33static void wl12xx_rx_header(struct wl12xx *wl, 34static void wl1251_rx_header(struct wl1251 *wl,
34 struct wl12xx_rx_descriptor *desc) 35 struct wl1251_rx_descriptor *desc)
35{ 36{
36 u32 rx_packet_ring_addr; 37 u32 rx_packet_ring_addr;
37 38
@@ -39,15 +40,17 @@ static void wl12xx_rx_header(struct wl12xx *wl,
39 if (wl->rx_current_buffer) 40 if (wl->rx_current_buffer)
40 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size; 41 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
41 42
42 wl12xx_spi_mem_read(wl, rx_packet_ring_addr, desc, 43 wl1251_spi_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
43 sizeof(struct wl12xx_rx_descriptor));
44} 44}
45 45
46static void wl12xx_rx_status(struct wl12xx *wl, 46static void wl1251_rx_status(struct wl1251 *wl,
47 struct wl12xx_rx_descriptor *desc, 47 struct wl1251_rx_descriptor *desc,
48 struct ieee80211_rx_status *status, 48 struct ieee80211_rx_status *status,
49 u8 beacon) 49 u8 beacon)
50{ 50{
51 u64 mactime;
52 int ret;
53
51 memset(status, 0, sizeof(struct ieee80211_rx_status)); 54 memset(status, 0, sizeof(struct ieee80211_rx_status));
52 55
53 status->band = IEEE80211_BAND_2GHZ; 56 status->band = IEEE80211_BAND_2GHZ;
@@ -62,32 +65,14 @@ static void wl12xx_rx_status(struct wl12xx *wl,
62 * this one must be atomic, while our SPI routines can sleep. 65 * this one must be atomic, while our SPI routines can sleep.
63 */ 66 */
64 if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) { 67 if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
65 u64 mactime; 68 ret = wl1251_acx_tsf_info(wl, &mactime);
66 int ret; 69 if (ret == 0)
67 struct wl12xx_command cmd; 70 status->mactime = mactime;
68 struct acx_tsf_info *tsf_info;
69
70 memset(&cmd, 0, sizeof(cmd));
71
72 ret = wl12xx_cmd_interrogate(wl, ACX_TSF_INFO,
73 sizeof(struct acx_tsf_info),
74 &cmd);
75 if (ret < 0) {
76 wl12xx_warning("ACX_FW_REV interrogate failed");
77 return;
78 }
79
80 tsf_info = (struct acx_tsf_info *)&(cmd.parameters);
81
82 mactime = tsf_info->current_tsf_lsb |
83 (tsf_info->current_tsf_msb << 31);
84
85 status->mactime = mactime;
86 } 71 }
87 72
88 status->signal = desc->rssi; 73 status->signal = desc->rssi;
89 status->qual = (desc->rssi - WL12XX_RX_MIN_RSSI) * 100 / 74 status->qual = (desc->rssi - WL1251_RX_MIN_RSSI) * 100 /
90 (WL12XX_RX_MAX_RSSI - WL12XX_RX_MIN_RSSI); 75 (WL1251_RX_MAX_RSSI - WL1251_RX_MIN_RSSI);
91 status->qual = min(status->qual, 100); 76 status->qual = min(status->qual, 100);
92 status->qual = max(status->qual, 0); 77 status->qual = max(status->qual, 0);
93 78
@@ -118,8 +103,8 @@ static void wl12xx_rx_status(struct wl12xx *wl,
118 /* FIXME: set status->rate_idx */ 103 /* FIXME: set status->rate_idx */
119} 104}
120 105
121static void wl12xx_rx_body(struct wl12xx *wl, 106static void wl1251_rx_body(struct wl1251 *wl,
122 struct wl12xx_rx_descriptor *desc) 107 struct wl1251_rx_descriptor *desc)
123{ 108{
124 struct sk_buff *skb; 109 struct sk_buff *skb;
125 struct ieee80211_rx_status status; 110 struct ieee80211_rx_status status;
@@ -127,12 +112,12 @@ static void wl12xx_rx_body(struct wl12xx *wl,
127 u16 length, *fc; 112 u16 length, *fc;
128 u32 curr_id, last_id_inc, rx_packet_ring_addr; 113 u32 curr_id, last_id_inc, rx_packet_ring_addr;
129 114
130 length = WL12XX_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH); 115 length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
131 curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT; 116 curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
132 last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1); 117 last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
133 118
134 if (last_id_inc != curr_id) { 119 if (last_id_inc != curr_id) {
135 wl12xx_warning("curr ID:%d, last ID inc:%d", 120 wl1251_warning("curr ID:%d, last ID inc:%d",
136 curr_id, last_id_inc); 121 curr_id, last_id_inc);
137 wl->rx_last_id = curr_id; 122 wl->rx_last_id = curr_id;
138 } else { 123 } else {
@@ -140,18 +125,18 @@ static void wl12xx_rx_body(struct wl12xx *wl,
140 } 125 }
141 126
142 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr + 127 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
143 sizeof(struct wl12xx_rx_descriptor) + 20; 128 sizeof(struct wl1251_rx_descriptor) + 20;
144 if (wl->rx_current_buffer) 129 if (wl->rx_current_buffer)
145 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size; 130 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
146 131
147 skb = dev_alloc_skb(length); 132 skb = dev_alloc_skb(length);
148 if (!skb) { 133 if (!skb) {
149 wl12xx_error("Couldn't allocate RX frame"); 134 wl1251_error("Couldn't allocate RX frame");
150 return; 135 return;
151 } 136 }
152 137
153 rx_buffer = skb_put(skb, length); 138 rx_buffer = skb_put(skb, length);
154 wl12xx_spi_mem_read(wl, rx_packet_ring_addr, rx_buffer, length); 139 wl1251_spi_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
155 140
156 /* The actual lenght doesn't include the target's alignment */ 141 /* The actual lenght doesn't include the target's alignment */
157 skb->len = desc->length - PLCP_HEADER_LENGTH; 142 skb->len = desc->length - PLCP_HEADER_LENGTH;
@@ -161,15 +146,16 @@ static void wl12xx_rx_body(struct wl12xx *wl,
161 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) 146 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
162 beacon = 1; 147 beacon = 1;
163 148
164 wl12xx_rx_status(wl, desc, &status, beacon); 149 wl1251_rx_status(wl, desc, &status, beacon);
165 150
166 wl12xx_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len, 151 wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
167 beacon ? "beacon" : ""); 152 beacon ? "beacon" : "");
168 153
169 ieee80211_rx(wl->hw, skb, &status); 154 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
155 ieee80211_rx(wl->hw, skb);
170} 156}
171 157
172static void wl12xx_rx_ack(struct wl12xx *wl) 158static void wl1251_rx_ack(struct wl1251 *wl)
173{ 159{
174 u32 data, addr; 160 u32 data, addr;
175 161
@@ -181,28 +167,30 @@ static void wl12xx_rx_ack(struct wl12xx *wl)
181 data = INTR_TRIG_RX_PROC0; 167 data = INTR_TRIG_RX_PROC0;
182 } 168 }
183 169
184 wl12xx_reg_write32(wl, addr, data); 170 wl1251_reg_write32(wl, addr, data);
185 171
186 /* Toggle buffer ring */ 172 /* Toggle buffer ring */
187 wl->rx_current_buffer = !wl->rx_current_buffer; 173 wl->rx_current_buffer = !wl->rx_current_buffer;
188} 174}
189 175
190 176
191void wl12xx_rx(struct wl12xx *wl) 177void wl1251_rx(struct wl1251 *wl)
192{ 178{
193 struct wl12xx_rx_descriptor rx_desc; 179 struct wl1251_rx_descriptor *rx_desc;
194 180
195 if (wl->state != WL12XX_STATE_ON) 181 if (wl->state != WL1251_STATE_ON)
196 return; 182 return;
197 183
184 rx_desc = wl->rx_descriptor;
185
198 /* We first read the frame's header */ 186 /* We first read the frame's header */
199 wl12xx_rx_header(wl, &rx_desc); 187 wl1251_rx_header(wl, rx_desc);
200 188
201 /* Now we can read the body */ 189 /* Now we can read the body */
202 wl12xx_rx_body(wl, &rx_desc); 190 wl1251_rx_body(wl, rx_desc);
203 191
204 /* Finally, we need to ACK the RX */ 192 /* Finally, we need to ACK the RX */
205 wl12xx_rx_ack(wl); 193 wl1251_rx_ack(wl);
206 194
207 return; 195 return;
208} 196}
diff --git a/drivers/net/wireless/wl12xx/rx.h b/drivers/net/wireless/wl12xx/wl1251_rx.h
index 8a23fdea5016..81156b9c4758 100644
--- a/drivers/net/wireless/wl12xx/rx.h
+++ b/drivers/net/wireless/wl12xx/wl1251_rx.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated 4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation 5 * Copyright (C) 2008 Nokia Corporation
@@ -22,11 +22,13 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL12XX_RX_H__ 25#ifndef __WL1251_RX_H__
26#define __WL12XX_RX_H__ 26#define __WL1251_RX_H__
27 27
28#include <linux/bitops.h> 28#include <linux/bitops.h>
29 29
30#include "wl1251.h"
31
30/* 32/*
31 * RX PATH 33 * RX PATH
32 * 34 *
@@ -43,12 +45,12 @@
43 * 4) The target prepares the next RX packet. 45 * 4) The target prepares the next RX packet.
44 */ 46 */
45 47
46#define WL12XX_RX_MAX_RSSI -30 48#define WL1251_RX_MAX_RSSI -30
47#define WL12XX_RX_MIN_RSSI -95 49#define WL1251_RX_MIN_RSSI -95
48 50
49#define WL12XX_RX_ALIGN_TO 4 51#define WL1251_RX_ALIGN_TO 4
50#define WL12XX_RX_ALIGN(len) (((len) + WL12XX_RX_ALIGN_TO - 1) & \ 52#define WL1251_RX_ALIGN(len) (((len) + WL1251_RX_ALIGN_TO - 1) & \
51 ~(WL12XX_RX_ALIGN_TO - 1)) 53 ~(WL1251_RX_ALIGN_TO - 1))
52 54
53#define SHORT_PREAMBLE_BIT BIT(0) 55#define SHORT_PREAMBLE_BIT BIT(0)
54#define OFDM_RATE_BIT BIT(6) 56#define OFDM_RATE_BIT BIT(6)
@@ -72,7 +74,7 @@
72#define RX_DESC_MIC_FAIL 0x2000 74#define RX_DESC_MIC_FAIL 0x2000
73#define RX_DESC_DECRYPT_FAIL 0x4000 75#define RX_DESC_DECRYPT_FAIL 0x4000
74 76
75struct wl12xx_rx_descriptor { 77struct wl1251_rx_descriptor {
76 u32 timestamp; /* In microseconds */ 78 u32 timestamp; /* In microseconds */
77 u16 length; /* Paylod length, including headers */ 79 u16 length; /* Paylod length, including headers */
78 u16 flags; 80 u16 flags;
@@ -117,6 +119,6 @@ struct wl12xx_rx_descriptor {
117 u8 snr; /* in dB */ 119 u8 snr; /* in dB */
118} __attribute__ ((packed)); 120} __attribute__ ((packed));
119 121
120void wl12xx_rx(struct wl12xx *wl); 122void wl1251_rx(struct wl1251 *wl);
121 123
122#endif 124#endif
diff --git a/drivers/net/wireless/wl12xx/spi.c b/drivers/net/wireless/wl12xx/wl1251_spi.c
index abdf171a47e7..c5da79dbc49c 100644
--- a/drivers/net/wireless/wl12xx/spi.c
+++ b/drivers/net/wireless/wl12xx/wl1251_spi.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (C) 2008 Nokia Corporation
5 * 5 *
@@ -25,13 +25,11 @@
25#include <linux/crc7.h> 25#include <linux/crc7.h>
26#include <linux/spi/spi.h> 26#include <linux/spi/spi.h>
27 27
28#include "wl12xx.h" 28#include "wl1251.h"
29#include "wl12xx_80211.h"
30#include "reg.h" 29#include "reg.h"
31#include "spi.h" 30#include "wl1251_spi.h"
32#include "ps.h"
33 31
34static int wl12xx_translate_reg_addr(struct wl12xx *wl, int addr) 32static int wl1251_translate_reg_addr(struct wl1251 *wl, int addr)
35{ 33{
36 /* If the address is lower than REGISTERS_BASE, it means that this is 34 /* If the address is lower than REGISTERS_BASE, it means that this is
37 * a chip-specific register address, so look it up in the registers 35 * a chip-specific register address, so look it up in the registers
@@ -39,7 +37,7 @@ static int wl12xx_translate_reg_addr(struct wl12xx *wl, int addr)
39 if (addr < REGISTERS_BASE) { 37 if (addr < REGISTERS_BASE) {
40 /* Make sure we don't go over the table */ 38 /* Make sure we don't go over the table */
41 if (addr >= ACX_REG_TABLE_LEN) { 39 if (addr >= ACX_REG_TABLE_LEN) {
42 wl12xx_error("address out of range (%d)", addr); 40 wl1251_error("address out of range (%d)", addr);
43 return -EINVAL; 41 return -EINVAL;
44 } 42 }
45 addr = wl->chip.acx_reg_table[addr]; 43 addr = wl->chip.acx_reg_table[addr];
@@ -48,13 +46,13 @@ static int wl12xx_translate_reg_addr(struct wl12xx *wl, int addr)
48 return addr - wl->physical_reg_addr + wl->virtual_reg_addr; 46 return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
49} 47}
50 48
51static int wl12xx_translate_mem_addr(struct wl12xx *wl, int addr) 49static int wl1251_translate_mem_addr(struct wl1251 *wl, int addr)
52{ 50{
53 return addr - wl->physical_mem_addr + wl->virtual_mem_addr; 51 return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
54} 52}
55 53
56 54
57void wl12xx_spi_reset(struct wl12xx *wl) 55void wl1251_spi_reset(struct wl1251 *wl)
58{ 56{
59 u8 *cmd; 57 u8 *cmd;
60 struct spi_transfer t; 58 struct spi_transfer t;
@@ -62,7 +60,7 @@ void wl12xx_spi_reset(struct wl12xx *wl)
62 60
63 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); 61 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
64 if (!cmd) { 62 if (!cmd) {
65 wl12xx_error("could not allocate cmd for spi reset"); 63 wl1251_error("could not allocate cmd for spi reset");
66 return; 64 return;
67 } 65 }
68 66
@@ -77,10 +75,10 @@ void wl12xx_spi_reset(struct wl12xx *wl)
77 75
78 spi_sync(wl->spi, &m); 76 spi_sync(wl->spi, &m);
79 77
80 wl12xx_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); 78 wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
81} 79}
82 80
83void wl12xx_spi_init(struct wl12xx *wl) 81void wl1251_spi_init(struct wl1251 *wl)
84{ 82{
85 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; 83 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
86 struct spi_transfer t; 84 struct spi_transfer t;
@@ -88,7 +86,7 @@ void wl12xx_spi_init(struct wl12xx *wl)
88 86
89 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); 87 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
90 if (!cmd) { 88 if (!cmd) {
91 wl12xx_error("could not allocate cmd for spi init"); 89 wl1251_error("could not allocate cmd for spi init");
92 return; 90 return;
93 } 91 }
94 92
@@ -131,7 +129,7 @@ void wl12xx_spi_init(struct wl12xx *wl)
131 129
132 spi_sync(wl->spi, &m); 130 spi_sync(wl->spi, &m);
133 131
134 wl12xx_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN); 132 wl1251_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
135} 133}
136 134
137/* Set the SPI partitions to access the chip addresses 135/* Set the SPI partitions to access the chip addresses
@@ -167,45 +165,47 @@ void wl12xx_spi_init(struct wl12xx *wl)
167 * | | 165 * | |
168 * 166 *
169 */ 167 */
170void wl12xx_set_partition(struct wl12xx *wl, 168int wl1251_set_partition(struct wl1251 *wl,
171 u32 mem_start, u32 mem_size, 169 u32 mem_start, u32 mem_size,
172 u32 reg_start, u32 reg_size) 170 u32 reg_start, u32 reg_size)
173{ 171{
174 u8 tx_buf[sizeof(u32) + 2 * sizeof(struct wl12xx_partition)]; 172 struct wl1251_partition *partition;
175 struct wl12xx_partition *partition;
176 struct spi_transfer t; 173 struct spi_transfer t;
177 struct spi_message m; 174 struct spi_message m;
175 size_t len, cmd_len;
178 u32 *cmd; 176 u32 *cmd;
179 size_t len;
180 int addr; 177 int addr;
181 178
179 cmd_len = sizeof(u32) + 2 * sizeof(struct wl1251_partition);
180 cmd = kzalloc(cmd_len, GFP_KERNEL);
181 if (!cmd)
182 return -ENOMEM;
183
182 spi_message_init(&m); 184 spi_message_init(&m);
183 memset(&t, 0, sizeof(t)); 185 memset(&t, 0, sizeof(t));
184 memset(tx_buf, 0, sizeof(tx_buf));
185 186
186 cmd = (u32 *) tx_buf; 187 partition = (struct wl1251_partition *) (cmd + 1);
187 partition = (struct wl12xx_partition *) (tx_buf + sizeof(u32));
188 addr = HW_ACCESS_PART0_SIZE_ADDR; 188 addr = HW_ACCESS_PART0_SIZE_ADDR;
189 len = 2 * sizeof(struct wl12xx_partition); 189 len = 2 * sizeof(struct wl1251_partition);
190 190
191 *cmd |= WSPI_CMD_WRITE; 191 *cmd |= WSPI_CMD_WRITE;
192 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH; 192 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
193 *cmd |= addr & WSPI_CMD_BYTE_ADDR; 193 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
194 194
195 wl12xx_debug(DEBUG_SPI, "mem_start %08X mem_size %08X", 195 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
196 mem_start, mem_size); 196 mem_start, mem_size);
197 wl12xx_debug(DEBUG_SPI, "reg_start %08X reg_size %08X", 197 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
198 reg_start, reg_size); 198 reg_start, reg_size);
199 199
200 /* Make sure that the two partitions together don't exceed the 200 /* Make sure that the two partitions together don't exceed the
201 * address range */ 201 * address range */
202 if ((mem_size + reg_size) > HW_ACCESS_MEMORY_MAX_RANGE) { 202 if ((mem_size + reg_size) > HW_ACCESS_MEMORY_MAX_RANGE) {
203 wl12xx_debug(DEBUG_SPI, "Total size exceeds maximum virtual" 203 wl1251_debug(DEBUG_SPI, "Total size exceeds maximum virtual"
204 " address range. Truncating partition[0]."); 204 " address range. Truncating partition[0].");
205 mem_size = HW_ACCESS_MEMORY_MAX_RANGE - reg_size; 205 mem_size = HW_ACCESS_MEMORY_MAX_RANGE - reg_size;
206 wl12xx_debug(DEBUG_SPI, "mem_start %08X mem_size %08X", 206 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
207 mem_start, mem_size); 207 mem_start, mem_size);
208 wl12xx_debug(DEBUG_SPI, "reg_start %08X reg_size %08X", 208 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
209 reg_start, reg_size); 209 reg_start, reg_size);
210 } 210 }
211 211
@@ -213,23 +213,23 @@ void wl12xx_set_partition(struct wl12xx *wl,
213 ((mem_start + mem_size) > reg_start)) { 213 ((mem_start + mem_size) > reg_start)) {
214 /* Guarantee that the memory partition doesn't overlap the 214 /* Guarantee that the memory partition doesn't overlap the
215 * registers partition */ 215 * registers partition */
216 wl12xx_debug(DEBUG_SPI, "End of partition[0] is " 216 wl1251_debug(DEBUG_SPI, "End of partition[0] is "
217 "overlapping partition[1]. Adjusted."); 217 "overlapping partition[1]. Adjusted.");
218 mem_size = reg_start - mem_start; 218 mem_size = reg_start - mem_start;
219 wl12xx_debug(DEBUG_SPI, "mem_start %08X mem_size %08X", 219 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
220 mem_start, mem_size); 220 mem_start, mem_size);
221 wl12xx_debug(DEBUG_SPI, "reg_start %08X reg_size %08X", 221 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
222 reg_start, reg_size); 222 reg_start, reg_size);
223 } else if ((reg_start < mem_start) && 223 } else if ((reg_start < mem_start) &&
224 ((reg_start + reg_size) > mem_start)) { 224 ((reg_start + reg_size) > mem_start)) {
225 /* Guarantee that the register partition doesn't overlap the 225 /* Guarantee that the register partition doesn't overlap the
226 * memory partition */ 226 * memory partition */
227 wl12xx_debug(DEBUG_SPI, "End of partition[1] is" 227 wl1251_debug(DEBUG_SPI, "End of partition[1] is"
228 " overlapping partition[0]. Adjusted."); 228 " overlapping partition[0]. Adjusted.");
229 reg_size = mem_start - reg_start; 229 reg_size = mem_start - reg_start;
230 wl12xx_debug(DEBUG_SPI, "mem_start %08X mem_size %08X", 230 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
231 mem_start, mem_size); 231 mem_start, mem_size);
232 wl12xx_debug(DEBUG_SPI, "reg_start %08X reg_size %08X", 232 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
233 reg_start, reg_size); 233 reg_start, reg_size);
234 } 234 }
235 235
@@ -244,36 +244,46 @@ void wl12xx_set_partition(struct wl12xx *wl,
244 wl->virtual_mem_addr = 0; 244 wl->virtual_mem_addr = 0;
245 wl->virtual_reg_addr = mem_size; 245 wl->virtual_reg_addr = mem_size;
246 246
247 t.tx_buf = tx_buf; 247 t.tx_buf = cmd;
248 t.len = sizeof(tx_buf); 248 t.len = cmd_len;
249 spi_message_add_tail(&t, &m); 249 spi_message_add_tail(&t, &m);
250 250
251 spi_sync(wl->spi, &m); 251 spi_sync(wl->spi, &m);
252
253 kfree(cmd);
254
255 return 0;
252} 256}
253 257
254void wl12xx_spi_read(struct wl12xx *wl, int addr, void *buf, 258void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
255 size_t len) 259 size_t len, bool fixed)
256{ 260{
257 struct spi_transfer t[3]; 261 struct spi_transfer t[3];
258 struct spi_message m; 262 struct spi_message m;
259 char busy_buf[TNETWIF_READ_OFFSET_BYTES]; 263 u8 *busy_buf;
260 u32 cmd; 264 u32 *cmd;
265
266 cmd = &wl->buffer_cmd;
267 busy_buf = wl->buffer_busyword;
268
269 *cmd = 0;
270 *cmd |= WSPI_CMD_READ;
271 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
272 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
261 273
262 cmd = 0; 274 if (fixed)
263 cmd |= WSPI_CMD_READ; 275 *cmd |= WSPI_CMD_FIXED;
264 cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
265 cmd |= addr & WSPI_CMD_BYTE_ADDR;
266 276
267 spi_message_init(&m); 277 spi_message_init(&m);
268 memset(t, 0, sizeof(t)); 278 memset(t, 0, sizeof(t));
269 279
270 t[0].tx_buf = &cmd; 280 t[0].tx_buf = cmd;
271 t[0].len = 4; 281 t[0].len = 4;
272 spi_message_add_tail(&t[0], &m); 282 spi_message_add_tail(&t[0], &m);
273 283
274 /* Busy and non busy words read */ 284 /* Busy and non busy words read */
275 t[1].rx_buf = busy_buf; 285 t[1].rx_buf = busy_buf;
276 t[1].len = TNETWIF_READ_OFFSET_BYTES; 286 t[1].len = WL1251_BUSY_WORD_LEN;
277 spi_message_add_tail(&t[1], &m); 287 spi_message_add_tail(&t[1], &m);
278 288
279 t[2].rx_buf = buf; 289 t[2].rx_buf = buf;
@@ -284,27 +294,32 @@ void wl12xx_spi_read(struct wl12xx *wl, int addr, void *buf,
284 294
285 /* FIXME: check busy words */ 295 /* FIXME: check busy words */
286 296
287 wl12xx_dump(DEBUG_SPI, "spi_read cmd -> ", &cmd, sizeof(cmd)); 297 wl1251_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
288 wl12xx_dump(DEBUG_SPI, "spi_read buf <- ", buf, len); 298 wl1251_dump(DEBUG_SPI, "spi_read buf <- ", buf, len);
289} 299}
290 300
291void wl12xx_spi_write(struct wl12xx *wl, int addr, void *buf, 301void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf,
292 size_t len) 302 size_t len, bool fixed)
293{ 303{
294 struct spi_transfer t[2]; 304 struct spi_transfer t[2];
295 struct spi_message m; 305 struct spi_message m;
296 u32 cmd; 306 u32 *cmd;
307
308 cmd = &wl->buffer_cmd;
297 309
298 cmd = 0; 310 *cmd = 0;
299 cmd |= WSPI_CMD_WRITE; 311 *cmd |= WSPI_CMD_WRITE;
300 cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH; 312 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
301 cmd |= addr & WSPI_CMD_BYTE_ADDR; 313 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
314
315 if (fixed)
316 *cmd |= WSPI_CMD_FIXED;
302 317
303 spi_message_init(&m); 318 spi_message_init(&m);
304 memset(t, 0, sizeof(t)); 319 memset(t, 0, sizeof(t));
305 320
306 t[0].tx_buf = &cmd; 321 t[0].tx_buf = cmd;
307 t[0].len = sizeof(cmd); 322 t[0].len = sizeof(*cmd);
308 spi_message_add_tail(&t[0], &m); 323 spi_message_add_tail(&t[0], &m);
309 324
310 t[1].tx_buf = buf; 325 t[1].tx_buf = buf;
@@ -313,46 +328,66 @@ void wl12xx_spi_write(struct wl12xx *wl, int addr, void *buf,
313 328
314 spi_sync(wl->spi, &m); 329 spi_sync(wl->spi, &m);
315 330
316 wl12xx_dump(DEBUG_SPI, "spi_write cmd -> ", &cmd, sizeof(cmd)); 331 wl1251_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
317 wl12xx_dump(DEBUG_SPI, "spi_write buf -> ", buf, len); 332 wl1251_dump(DEBUG_SPI, "spi_write buf -> ", buf, len);
318} 333}
319 334
320void wl12xx_spi_mem_read(struct wl12xx *wl, int addr, void *buf, 335void wl1251_spi_mem_read(struct wl1251 *wl, int addr, void *buf,
321 size_t len) 336 size_t len)
322{ 337{
323 int physical; 338 int physical;
324 339
325 physical = wl12xx_translate_mem_addr(wl, addr); 340 physical = wl1251_translate_mem_addr(wl, addr);
326 341
327 wl12xx_spi_read(wl, physical, buf, len); 342 wl1251_spi_read(wl, physical, buf, len, false);
328} 343}
329 344
330void wl12xx_spi_mem_write(struct wl12xx *wl, int addr, void *buf, 345void wl1251_spi_mem_write(struct wl1251 *wl, int addr, void *buf,
331 size_t len) 346 size_t len)
332{ 347{
333 int physical; 348 int physical;
334 349
335 physical = wl12xx_translate_mem_addr(wl, addr); 350 physical = wl1251_translate_mem_addr(wl, addr);
351
352 wl1251_spi_write(wl, physical, buf, len, false);
353}
354
355void wl1251_spi_reg_read(struct wl1251 *wl, int addr, void *buf, size_t len,
356 bool fixed)
357{
358 int physical;
359
360 physical = wl1251_translate_reg_addr(wl, addr);
361
362 wl1251_spi_read(wl, physical, buf, len, fixed);
363}
364
365void wl1251_spi_reg_write(struct wl1251 *wl, int addr, void *buf, size_t len,
366 bool fixed)
367{
368 int physical;
369
370 physical = wl1251_translate_reg_addr(wl, addr);
336 371
337 wl12xx_spi_write(wl, physical, buf, len); 372 wl1251_spi_write(wl, physical, buf, len, fixed);
338} 373}
339 374
340u32 wl12xx_mem_read32(struct wl12xx *wl, int addr) 375u32 wl1251_mem_read32(struct wl1251 *wl, int addr)
341{ 376{
342 return wl12xx_read32(wl, wl12xx_translate_mem_addr(wl, addr)); 377 return wl1251_read32(wl, wl1251_translate_mem_addr(wl, addr));
343} 378}
344 379
345void wl12xx_mem_write32(struct wl12xx *wl, int addr, u32 val) 380void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val)
346{ 381{
347 wl12xx_write32(wl, wl12xx_translate_mem_addr(wl, addr), val); 382 wl1251_write32(wl, wl1251_translate_mem_addr(wl, addr), val);
348} 383}
349 384
350u32 wl12xx_reg_read32(struct wl12xx *wl, int addr) 385u32 wl1251_reg_read32(struct wl1251 *wl, int addr)
351{ 386{
352 return wl12xx_read32(wl, wl12xx_translate_reg_addr(wl, addr)); 387 return wl1251_read32(wl, wl1251_translate_reg_addr(wl, addr));
353} 388}
354 389
355void wl12xx_reg_write32(struct wl12xx *wl, int addr, u32 val) 390void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val)
356{ 391{
357 wl12xx_write32(wl, wl12xx_translate_reg_addr(wl, addr), val); 392 wl1251_write32(wl, wl1251_translate_reg_addr(wl, addr), val);
358} 393}
diff --git a/drivers/net/wireless/wl12xx/spi.h b/drivers/net/wireless/wl12xx/wl1251_spi.h
index fd3227e904a8..6e8daf4e1085 100644
--- a/drivers/net/wireless/wl12xx/spi.h
+++ b/drivers/net/wireless/wl12xx/wl1251_spi.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated 4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation 5 * Copyright (C) 2008 Nokia Corporation
@@ -22,11 +22,11 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL12XX_SPI_H__ 25#ifndef __WL1251_SPI_H__
26#define __WL12XX_SPI_H__ 26#define __WL1251_SPI_H__
27 27
28#include "cmd.h" 28#include "wl1251_cmd.h"
29#include "acx.h" 29#include "wl1251_acx.h"
30#include "reg.h" 30#include "reg.h"
31 31
32#define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0 32#define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0
@@ -65,45 +65,51 @@
65 65
66#define WSPI_INIT_CMD_LEN 8 66#define WSPI_INIT_CMD_LEN 8
67 67
68#define TNETWIF_READ_OFFSET_BYTES 8
69#define HW_ACCESS_WSPI_FIXED_BUSY_LEN \ 68#define HW_ACCESS_WSPI_FIXED_BUSY_LEN \
70 ((TNETWIF_READ_OFFSET_BYTES - 4) / sizeof(u32)) 69 ((WL1251_BUSY_WORD_LEN - 4) / sizeof(u32))
71#define HW_ACCESS_WSPI_INIT_CMD_MASK 0 70#define HW_ACCESS_WSPI_INIT_CMD_MASK 0
72 71
73 72
74/* Raw target IO, address is not translated */ 73/* Raw target IO, address is not translated */
75void wl12xx_spi_read(struct wl12xx *wl, int addr, void *buf, size_t len); 74void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf,
76void wl12xx_spi_write(struct wl12xx *wl, int addr, void *buf, size_t len); 75 size_t len, bool fixed);
76void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
77 size_t len, bool fixed);
77 78
78/* Memory target IO, address is tranlated to partition 0 */ 79/* Memory target IO, address is tranlated to partition 0 */
79void wl12xx_spi_mem_read(struct wl12xx *wl, int addr, void *buf, size_t len); 80void wl1251_spi_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len);
80void wl12xx_spi_mem_write(struct wl12xx *wl, int addr, void *buf, size_t len); 81void wl1251_spi_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len);
81u32 wl12xx_mem_read32(struct wl12xx *wl, int addr); 82u32 wl1251_mem_read32(struct wl1251 *wl, int addr);
82void wl12xx_mem_write32(struct wl12xx *wl, int addr, u32 val); 83void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val);
83 84
84/* Registers IO */ 85/* Registers IO */
85u32 wl12xx_reg_read32(struct wl12xx *wl, int addr); 86void wl1251_spi_reg_read(struct wl1251 *wl, int addr, void *buf, size_t len,
86void wl12xx_reg_write32(struct wl12xx *wl, int addr, u32 val); 87 bool fixed);
88void wl1251_spi_reg_write(struct wl1251 *wl, int addr, void *buf, size_t len,
89 bool fixed);
90u32 wl1251_reg_read32(struct wl1251 *wl, int addr);
91void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val);
87 92
88/* INIT and RESET words */ 93/* INIT and RESET words */
89void wl12xx_spi_reset(struct wl12xx *wl); 94void wl1251_spi_reset(struct wl1251 *wl);
90void wl12xx_spi_init(struct wl12xx *wl); 95void wl1251_spi_init(struct wl1251 *wl);
91void wl12xx_set_partition(struct wl12xx *wl, 96int wl1251_set_partition(struct wl1251 *wl,
92 u32 part_start, u32 part_size, 97 u32 part_start, u32 part_size,
93 u32 reg_start, u32 reg_size); 98 u32 reg_start, u32 reg_size);
94 99
95static inline u32 wl12xx_read32(struct wl12xx *wl, int addr) 100static inline u32 wl1251_read32(struct wl1251 *wl, int addr)
96{ 101{
97 u32 response; 102 wl1251_spi_read(wl, addr, &wl->buffer_32,
103 sizeof(wl->buffer_32), false);
98 104
99 wl12xx_spi_read(wl, addr, &response, sizeof(u32)); 105 return wl->buffer_32;
100
101 return response;
102} 106}
103 107
104static inline void wl12xx_write32(struct wl12xx *wl, int addr, u32 val) 108static inline void wl1251_write32(struct wl1251 *wl, int addr, u32 val)
105{ 109{
106 wl12xx_spi_write(wl, addr, &val, sizeof(u32)); 110 wl->buffer_32 = val;
111 wl1251_spi_write(wl, addr, &wl->buffer_32,
112 sizeof(wl->buffer_32), false);
107} 113}
108 114
109#endif /* __WL12XX_SPI_H__ */ 115#endif /* __WL1251_SPI_H__ */
diff --git a/drivers/net/wireless/wl12xx/tx.c b/drivers/net/wireless/wl12xx/wl1251_tx.c
index 62145e205a8c..2652a222383a 100644
--- a/drivers/net/wireless/wl12xx/tx.c
+++ b/drivers/net/wireless/wl12xx/wl1251_tx.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated 4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation 5 * Copyright (C) 2008 Nokia Corporation
@@ -25,13 +25,13 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/module.h> 26#include <linux/module.h>
27 27
28#include "wl12xx.h" 28#include "wl1251.h"
29#include "reg.h" 29#include "reg.h"
30#include "spi.h" 30#include "wl1251_spi.h"
31#include "tx.h" 31#include "wl1251_tx.h"
32#include "ps.h" 32#include "wl1251_ps.h"
33 33
34static bool wl12xx_tx_double_buffer_busy(struct wl12xx *wl, u32 data_out_count) 34static bool wl1251_tx_double_buffer_busy(struct wl1251 *wl, u32 data_out_count)
35{ 35{
36 int used, data_in_count; 36 int used, data_in_count;
37 37
@@ -52,15 +52,15 @@ static bool wl12xx_tx_double_buffer_busy(struct wl12xx *wl, u32 data_out_count)
52 return false; 52 return false;
53} 53}
54 54
55static int wl12xx_tx_path_status(struct wl12xx *wl) 55static int wl1251_tx_path_status(struct wl1251 *wl)
56{ 56{
57 u32 status, addr, data_out_count; 57 u32 status, addr, data_out_count;
58 bool busy; 58 bool busy;
59 59
60 addr = wl->data_path->tx_control_addr; 60 addr = wl->data_path->tx_control_addr;
61 status = wl12xx_mem_read32(wl, addr); 61 status = wl1251_mem_read32(wl, addr);
62 data_out_count = status & TX_STATUS_DATA_OUT_COUNT_MASK; 62 data_out_count = status & TX_STATUS_DATA_OUT_COUNT_MASK;
63 busy = wl12xx_tx_double_buffer_busy(wl, data_out_count); 63 busy = wl1251_tx_double_buffer_busy(wl, data_out_count);
64 64
65 if (busy) 65 if (busy)
66 return -EBUSY; 66 return -EBUSY;
@@ -68,7 +68,7 @@ static int wl12xx_tx_path_status(struct wl12xx *wl)
68 return 0; 68 return 0;
69} 69}
70 70
71static int wl12xx_tx_id(struct wl12xx *wl, struct sk_buff *skb) 71static int wl1251_tx_id(struct wl1251 *wl, struct sk_buff *skb)
72{ 72{
73 int i; 73 int i;
74 74
@@ -81,7 +81,7 @@ static int wl12xx_tx_id(struct wl12xx *wl, struct sk_buff *skb)
81 return -EBUSY; 81 return -EBUSY;
82} 82}
83 83
84static void wl12xx_tx_control(struct tx_double_buffer_desc *tx_hdr, 84static void wl1251_tx_control(struct tx_double_buffer_desc *tx_hdr,
85 struct ieee80211_tx_info *control, u16 fc) 85 struct ieee80211_tx_info *control, u16 fc)
86{ 86{
87 *(u16 *)&tx_hdr->control = 0; 87 *(u16 *)&tx_hdr->control = 0;
@@ -109,7 +109,7 @@ static void wl12xx_tx_control(struct tx_double_buffer_desc *tx_hdr,
109#define MAX_MPDU_HEADER_AND_SECURITY (MAX_MPDU_SECURITY_LENGTH + \ 109#define MAX_MPDU_HEADER_AND_SECURITY (MAX_MPDU_SECURITY_LENGTH + \
110 WLAN_QOS_HDR_LEN) 110 WLAN_QOS_HDR_LEN)
111#define HW_BLOCK_SIZE 252 111#define HW_BLOCK_SIZE 252
112static void wl12xx_tx_frag_block_num(struct tx_double_buffer_desc *tx_hdr) 112static void wl1251_tx_frag_block_num(struct tx_double_buffer_desc *tx_hdr)
113{ 113{
114 u16 payload_len, frag_threshold, mem_blocks; 114 u16 payload_len, frag_threshold, mem_blocks;
115 u16 num_mpdus, mem_blocks_per_frag; 115 u16 num_mpdus, mem_blocks_per_frag;
@@ -142,7 +142,7 @@ static void wl12xx_tx_frag_block_num(struct tx_double_buffer_desc *tx_hdr)
142 tx_hdr->num_mem_blocks = mem_blocks; 142 tx_hdr->num_mem_blocks = mem_blocks;
143} 143}
144 144
145static int wl12xx_tx_fill_hdr(struct wl12xx *wl, struct sk_buff *skb, 145static int wl1251_tx_fill_hdr(struct wl1251 *wl, struct sk_buff *skb,
146 struct ieee80211_tx_info *control) 146 struct ieee80211_tx_info *control)
147{ 147{
148 struct tx_double_buffer_desc *tx_hdr; 148 struct tx_double_buffer_desc *tx_hdr;
@@ -153,7 +153,7 @@ static int wl12xx_tx_fill_hdr(struct wl12xx *wl, struct sk_buff *skb,
153 if (!skb) 153 if (!skb)
154 return -EINVAL; 154 return -EINVAL;
155 155
156 id = wl12xx_tx_id(wl, skb); 156 id = wl1251_tx_id(wl, skb);
157 if (id < 0) 157 if (id < 0)
158 return id; 158 return id;
159 159
@@ -170,14 +170,14 @@ static int wl12xx_tx_fill_hdr(struct wl12xx *wl, struct sk_buff *skb,
170 /* FIXME: how to get the correct queue id? */ 170 /* FIXME: how to get the correct queue id? */
171 tx_hdr->xmit_queue = 0; 171 tx_hdr->xmit_queue = 0;
172 172
173 wl12xx_tx_control(tx_hdr, control, fc); 173 wl1251_tx_control(tx_hdr, control, fc);
174 wl12xx_tx_frag_block_num(tx_hdr); 174 wl1251_tx_frag_block_num(tx_hdr);
175 175
176 return 0; 176 return 0;
177} 177}
178 178
179/* We copy the packet to the target */ 179/* We copy the packet to the target */
180static int wl12xx_tx_send_packet(struct wl12xx *wl, struct sk_buff *skb, 180static int wl1251_tx_send_packet(struct wl1251 *wl, struct sk_buff *skb,
181 struct ieee80211_tx_info *control) 181 struct ieee80211_tx_info *control)
182{ 182{
183 struct tx_double_buffer_desc *tx_hdr; 183 struct tx_double_buffer_desc *tx_hdr;
@@ -196,12 +196,12 @@ static int wl12xx_tx_send_packet(struct wl12xx *wl, struct sk_buff *skb,
196 u8 *pos; 196 u8 *pos;
197 197
198 fc = *(u16 *)(skb->data + sizeof(*tx_hdr)); 198 fc = *(u16 *)(skb->data + sizeof(*tx_hdr));
199 tx_hdr->length += WL12XX_TKIP_IV_SPACE; 199 tx_hdr->length += WL1251_TKIP_IV_SPACE;
200 200
201 hdrlen = ieee80211_hdrlen(fc); 201 hdrlen = ieee80211_hdrlen(fc);
202 202
203 pos = skb_push(skb, WL12XX_TKIP_IV_SPACE); 203 pos = skb_push(skb, WL1251_TKIP_IV_SPACE);
204 memmove(pos, pos + WL12XX_TKIP_IV_SPACE, 204 memmove(pos, pos + WL1251_TKIP_IV_SPACE,
205 sizeof(*tx_hdr) + hdrlen); 205 sizeof(*tx_hdr) + hdrlen);
206 } 206 }
207 207
@@ -211,7 +211,7 @@ static int wl12xx_tx_send_packet(struct wl12xx *wl, struct sk_buff *skb,
211 */ 211 */
212 if (unlikely((long)skb->data & 0x03)) { 212 if (unlikely((long)skb->data & 0x03)) {
213 int offset = (4 - (long)skb->data) & 0x03; 213 int offset = (4 - (long)skb->data) & 0x03;
214 wl12xx_debug(DEBUG_TX, "skb offset %d", offset); 214 wl1251_debug(DEBUG_TX, "skb offset %d", offset);
215 215
216 /* check whether the current skb can be used */ 216 /* check whether the current skb can be used */
217 if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) { 217 if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) {
@@ -221,13 +221,13 @@ static int wl12xx_tx_send_packet(struct wl12xx *wl, struct sk_buff *skb,
221 skb_reserve(skb, offset); 221 skb_reserve(skb, offset);
222 memmove(skb->data, src, skb->len); 222 memmove(skb->data, src, skb->len);
223 } else { 223 } else {
224 wl12xx_info("No handler, fixme!"); 224 wl1251_info("No handler, fixme!");
225 return -EINVAL; 225 return -EINVAL;
226 } 226 }
227 } 227 }
228 228
229 /* Our skb->data at this point includes the HW header */ 229 /* Our skb->data at this point includes the HW header */
230 len = WL12XX_TX_ALIGN(skb->len); 230 len = WL1251_TX_ALIGN(skb->len);
231 231
232 if (wl->data_in_count & 0x1) 232 if (wl->data_in_count & 0x1)
233 addr = wl->data_path->tx_packet_ring_addr + 233 addr = wl->data_path->tx_packet_ring_addr +
@@ -235,15 +235,15 @@ static int wl12xx_tx_send_packet(struct wl12xx *wl, struct sk_buff *skb,
235 else 235 else
236 addr = wl->data_path->tx_packet_ring_addr; 236 addr = wl->data_path->tx_packet_ring_addr;
237 237
238 wl12xx_spi_mem_write(wl, addr, skb->data, len); 238 wl1251_spi_mem_write(wl, addr, skb->data, len);
239 239
240 wl12xx_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u rate 0x%x", 240 wl1251_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u rate 0x%x",
241 tx_hdr->id, skb, tx_hdr->length, tx_hdr->rate); 241 tx_hdr->id, skb, tx_hdr->length, tx_hdr->rate);
242 242
243 return 0; 243 return 0;
244} 244}
245 245
246static void wl12xx_tx_trigger(struct wl12xx *wl) 246static void wl1251_tx_trigger(struct wl1251 *wl)
247{ 247{
248 u32 data, addr; 248 u32 data, addr;
249 249
@@ -255,7 +255,7 @@ static void wl12xx_tx_trigger(struct wl12xx *wl)
255 data = INTR_TRIG_TX_PROC0; 255 data = INTR_TRIG_TX_PROC0;
256 } 256 }
257 257
258 wl12xx_reg_write32(wl, addr, data); 258 wl1251_reg_write32(wl, addr, data);
259 259
260 /* Bumping data in */ 260 /* Bumping data in */
261 wl->data_in_count = (wl->data_in_count + 1) & 261 wl->data_in_count = (wl->data_in_count + 1) &
@@ -263,7 +263,7 @@ static void wl12xx_tx_trigger(struct wl12xx *wl)
263} 263}
264 264
265/* caller must hold wl->mutex */ 265/* caller must hold wl->mutex */
266static int wl12xx_tx_frame(struct wl12xx *wl, struct sk_buff *skb) 266static int wl1251_tx_frame(struct wl1251 *wl, struct sk_buff *skb)
267{ 267{
268 struct ieee80211_tx_info *info; 268 struct ieee80211_tx_info *info;
269 int ret = 0; 269 int ret = 0;
@@ -274,51 +274,53 @@ static int wl12xx_tx_frame(struct wl12xx *wl, struct sk_buff *skb)
274 if (info->control.hw_key) { 274 if (info->control.hw_key) {
275 idx = info->control.hw_key->hw_key_idx; 275 idx = info->control.hw_key->hw_key_idx;
276 if (unlikely(wl->default_key != idx)) { 276 if (unlikely(wl->default_key != idx)) {
277 ret = wl12xx_acx_default_key(wl, idx); 277 ret = wl1251_acx_default_key(wl, idx);
278 if (ret < 0) 278 if (ret < 0)
279 return ret; 279 return ret;
280 } 280 }
281 } 281 }
282 282
283 ret = wl12xx_tx_path_status(wl); 283 ret = wl1251_tx_path_status(wl);
284 if (ret < 0) 284 if (ret < 0)
285 return ret; 285 return ret;
286 286
287 ret = wl12xx_tx_fill_hdr(wl, skb, info); 287 ret = wl1251_tx_fill_hdr(wl, skb, info);
288 if (ret < 0) 288 if (ret < 0)
289 return ret; 289 return ret;
290 290
291 ret = wl12xx_tx_send_packet(wl, skb, info); 291 ret = wl1251_tx_send_packet(wl, skb, info);
292 if (ret < 0) 292 if (ret < 0)
293 return ret; 293 return ret;
294 294
295 wl12xx_tx_trigger(wl); 295 wl1251_tx_trigger(wl);
296 296
297 return ret; 297 return ret;
298} 298}
299 299
300void wl12xx_tx_work(struct work_struct *work) 300void wl1251_tx_work(struct work_struct *work)
301{ 301{
302 struct wl12xx *wl = container_of(work, struct wl12xx, tx_work); 302 struct wl1251 *wl = container_of(work, struct wl1251, tx_work);
303 struct sk_buff *skb; 303 struct sk_buff *skb;
304 bool woken_up = false; 304 bool woken_up = false;
305 int ret; 305 int ret;
306 306
307 mutex_lock(&wl->mutex); 307 mutex_lock(&wl->mutex);
308 308
309 if (unlikely(wl->state == WL12XX_STATE_OFF)) 309 if (unlikely(wl->state == WL1251_STATE_OFF))
310 goto out; 310 goto out;
311 311
312 while ((skb = skb_dequeue(&wl->tx_queue))) { 312 while ((skb = skb_dequeue(&wl->tx_queue))) {
313 if (!woken_up) { 313 if (!woken_up) {
314 wl12xx_ps_elp_wakeup(wl); 314 ret = wl1251_ps_elp_wakeup(wl);
315 if (ret < 0)
316 goto out;
315 woken_up = true; 317 woken_up = true;
316 } 318 }
317 319
318 ret = wl12xx_tx_frame(wl, skb); 320 ret = wl1251_tx_frame(wl, skb);
319 if (ret == -EBUSY) { 321 if (ret == -EBUSY) {
320 /* firmware buffer is full, stop queues */ 322 /* firmware buffer is full, stop queues */
321 wl12xx_debug(DEBUG_TX, "tx_work: fw buffer full, " 323 wl1251_debug(DEBUG_TX, "tx_work: fw buffer full, "
322 "stop queues"); 324 "stop queues");
323 ieee80211_stop_queues(wl->hw); 325 ieee80211_stop_queues(wl->hw);
324 wl->tx_queue_stopped = true; 326 wl->tx_queue_stopped = true;
@@ -332,12 +334,12 @@ void wl12xx_tx_work(struct work_struct *work)
332 334
333out: 335out:
334 if (woken_up) 336 if (woken_up)
335 wl12xx_ps_elp_sleep(wl); 337 wl1251_ps_elp_sleep(wl);
336 338
337 mutex_unlock(&wl->mutex); 339 mutex_unlock(&wl->mutex);
338} 340}
339 341
340static const char *wl12xx_tx_parse_status(u8 status) 342static const char *wl1251_tx_parse_status(u8 status)
341{ 343{
342 /* 8 bit status field, one character per bit plus null */ 344 /* 8 bit status field, one character per bit plus null */
343 static char buf[9]; 345 static char buf[9];
@@ -365,7 +367,7 @@ static const char *wl12xx_tx_parse_status(u8 status)
365 return buf; 367 return buf;
366} 368}
367 369
368static void wl12xx_tx_packet_cb(struct wl12xx *wl, 370static void wl1251_tx_packet_cb(struct wl1251 *wl,
369 struct tx_result *result) 371 struct tx_result *result)
370{ 372{
371 struct ieee80211_tx_info *info; 373 struct ieee80211_tx_info *info;
@@ -375,7 +377,7 @@ static void wl12xx_tx_packet_cb(struct wl12xx *wl,
375 377
376 skb = wl->tx_frames[result->id]; 378 skb = wl->tx_frames[result->id];
377 if (skb == NULL) { 379 if (skb == NULL) {
378 wl12xx_error("SKB for packet %d is NULL", result->id); 380 wl1251_error("SKB for packet %d is NULL", result->id);
379 return; 381 return;
380 } 382 }
381 383
@@ -396,14 +398,14 @@ static void wl12xx_tx_packet_cb(struct wl12xx *wl,
396 if (info->control.hw_key && 398 if (info->control.hw_key &&
397 info->control.hw_key->alg == ALG_TKIP) { 399 info->control.hw_key->alg == ALG_TKIP) {
398 hdrlen = ieee80211_get_hdrlen_from_skb(skb); 400 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
399 memmove(frame + WL12XX_TKIP_IV_SPACE, frame, hdrlen); 401 memmove(frame + WL1251_TKIP_IV_SPACE, frame, hdrlen);
400 skb_pull(skb, WL12XX_TKIP_IV_SPACE); 402 skb_pull(skb, WL1251_TKIP_IV_SPACE);
401 } 403 }
402 404
403 wl12xx_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x" 405 wl1251_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
404 " status 0x%x (%s)", 406 " status 0x%x (%s)",
405 result->id, skb, result->ack_failures, result->rate, 407 result->id, skb, result->ack_failures, result->rate,
406 result->status, wl12xx_tx_parse_status(result->status)); 408 result->status, wl1251_tx_parse_status(result->status));
407 409
408 410
409 ieee80211_tx_status(wl->hw, skb); 411 ieee80211_tx_status(wl->hw, skb);
@@ -411,7 +413,7 @@ static void wl12xx_tx_packet_cb(struct wl12xx *wl,
411 wl->tx_frames[result->id] = NULL; 413 wl->tx_frames[result->id] = NULL;
412 414
413 if (wl->tx_queue_stopped) { 415 if (wl->tx_queue_stopped) {
414 wl12xx_debug(DEBUG_TX, "cb: queue was stopped"); 416 wl1251_debug(DEBUG_TX, "cb: queue was stopped");
415 417
416 skb = skb_dequeue(&wl->tx_queue); 418 skb = skb_dequeue(&wl->tx_queue);
417 419
@@ -420,10 +422,10 @@ static void wl12xx_tx_packet_cb(struct wl12xx *wl,
420 queue empty */ 422 queue empty */
421 423
422 if (skb) { 424 if (skb) {
423 ret = wl12xx_tx_frame(wl, skb); 425 ret = wl1251_tx_frame(wl, skb);
424 if (ret == -EBUSY) { 426 if (ret == -EBUSY) {
425 /* firmware buffer is still full */ 427 /* firmware buffer is still full */
426 wl12xx_debug(DEBUG_TX, "cb: fw buffer " 428 wl1251_debug(DEBUG_TX, "cb: fw buffer "
427 "still full"); 429 "still full");
428 skb_queue_head(&wl->tx_queue, skb); 430 skb_queue_head(&wl->tx_queue, skb);
429 return; 431 return;
@@ -433,23 +435,23 @@ static void wl12xx_tx_packet_cb(struct wl12xx *wl,
433 } 435 }
434 } 436 }
435 437
436 wl12xx_debug(DEBUG_TX, "cb: waking queues"); 438 wl1251_debug(DEBUG_TX, "cb: waking queues");
437 ieee80211_wake_queues(wl->hw); 439 ieee80211_wake_queues(wl->hw);
438 wl->tx_queue_stopped = false; 440 wl->tx_queue_stopped = false;
439 } 441 }
440} 442}
441 443
442/* Called upon reception of a TX complete interrupt */ 444/* Called upon reception of a TX complete interrupt */
443void wl12xx_tx_complete(struct wl12xx *wl) 445void wl1251_tx_complete(struct wl1251 *wl)
444{ 446{
445 int i, result_index, num_complete = 0; 447 int i, result_index, num_complete = 0;
446 struct tx_result result[FW_TX_CMPLT_BLOCK_SIZE], *result_ptr; 448 struct tx_result result[FW_TX_CMPLT_BLOCK_SIZE], *result_ptr;
447 449
448 if (unlikely(wl->state != WL12XX_STATE_ON)) 450 if (unlikely(wl->state != WL1251_STATE_ON))
449 return; 451 return;
450 452
451 /* First we read the result */ 453 /* First we read the result */
452 wl12xx_spi_mem_read(wl, wl->data_path->tx_complete_addr, 454 wl1251_spi_mem_read(wl, wl->data_path->tx_complete_addr,
453 result, sizeof(result)); 455 result, sizeof(result));
454 456
455 result_index = wl->next_tx_complete; 457 result_index = wl->next_tx_complete;
@@ -459,7 +461,7 @@ void wl12xx_tx_complete(struct wl12xx *wl)
459 461
460 if (result_ptr->done_1 == 1 && 462 if (result_ptr->done_1 == 1 &&
461 result_ptr->done_2 == 1) { 463 result_ptr->done_2 == 1) {
462 wl12xx_tx_packet_cb(wl, result_ptr); 464 wl1251_tx_packet_cb(wl, result_ptr);
463 465
464 result_ptr->done_1 = 0; 466 result_ptr->done_1 = 0;
465 result_ptr->done_2 = 0; 467 result_ptr->done_2 = 0;
@@ -480,7 +482,7 @@ void wl12xx_tx_complete(struct wl12xx *wl)
480 */ 482 */
481 if (result_index > wl->next_tx_complete) { 483 if (result_index > wl->next_tx_complete) {
482 /* Only 1 write is needed */ 484 /* Only 1 write is needed */
483 wl12xx_spi_mem_write(wl, 485 wl1251_spi_mem_write(wl,
484 wl->data_path->tx_complete_addr + 486 wl->data_path->tx_complete_addr +
485 (wl->next_tx_complete * 487 (wl->next_tx_complete *
486 sizeof(struct tx_result)), 488 sizeof(struct tx_result)),
@@ -491,7 +493,7 @@ void wl12xx_tx_complete(struct wl12xx *wl)
491 493
492 } else if (result_index < wl->next_tx_complete) { 494 } else if (result_index < wl->next_tx_complete) {
493 /* 2 writes are needed */ 495 /* 2 writes are needed */
494 wl12xx_spi_mem_write(wl, 496 wl1251_spi_mem_write(wl,
495 wl->data_path->tx_complete_addr + 497 wl->data_path->tx_complete_addr +
496 (wl->next_tx_complete * 498 (wl->next_tx_complete *
497 sizeof(struct tx_result)), 499 sizeof(struct tx_result)),
@@ -500,7 +502,7 @@ void wl12xx_tx_complete(struct wl12xx *wl)
500 wl->next_tx_complete) * 502 wl->next_tx_complete) *
501 sizeof(struct tx_result)); 503 sizeof(struct tx_result));
502 504
503 wl12xx_spi_mem_write(wl, 505 wl1251_spi_mem_write(wl,
504 wl->data_path->tx_complete_addr, 506 wl->data_path->tx_complete_addr,
505 result, 507 result,
506 (num_complete - 508 (num_complete -
@@ -510,7 +512,7 @@ void wl12xx_tx_complete(struct wl12xx *wl)
510 512
511 } else { 513 } else {
512 /* We have to write the whole array */ 514 /* We have to write the whole array */
513 wl12xx_spi_mem_write(wl, 515 wl1251_spi_mem_write(wl,
514 wl->data_path->tx_complete_addr, 516 wl->data_path->tx_complete_addr,
515 result, 517 result,
516 FW_TX_CMPLT_BLOCK_SIZE * 518 FW_TX_CMPLT_BLOCK_SIZE *
@@ -523,7 +525,7 @@ void wl12xx_tx_complete(struct wl12xx *wl)
523} 525}
524 526
525/* caller must hold wl->mutex */ 527/* caller must hold wl->mutex */
526void wl12xx_tx_flush(struct wl12xx *wl) 528void wl1251_tx_flush(struct wl1251 *wl)
527{ 529{
528 int i; 530 int i;
529 struct sk_buff *skb; 531 struct sk_buff *skb;
@@ -535,7 +537,7 @@ void wl12xx_tx_flush(struct wl12xx *wl)
535 while ((skb = skb_dequeue(&wl->tx_queue))) { 537 while ((skb = skb_dequeue(&wl->tx_queue))) {
536 info = IEEE80211_SKB_CB(skb); 538 info = IEEE80211_SKB_CB(skb);
537 539
538 wl12xx_debug(DEBUG_TX, "flushing skb 0x%p", skb); 540 wl1251_debug(DEBUG_TX, "flushing skb 0x%p", skb);
539 541
540 if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)) 542 if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
541 continue; 543 continue;
diff --git a/drivers/net/wireless/wl12xx/tx.h b/drivers/net/wireless/wl12xx/wl1251_tx.h
index dc82691f4c14..7c1c1665c810 100644
--- a/drivers/net/wireless/wl12xx/tx.h
+++ b/drivers/net/wireless/wl12xx/wl1251_tx.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * This file is part of wl12xx 2 * This file is part of wl1251
3 * 3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated 4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation 5 * Copyright (C) 2008 Nokia Corporation
@@ -22,8 +22,8 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL12XX_TX_H__ 25#ifndef __WL1251_TX_H__
26#define __WL12XX_TX_H__ 26#define __WL1251_TX_H__
27 27
28#include <linux/bitops.h> 28#include <linux/bitops.h>
29 29
@@ -73,10 +73,11 @@
73 73
74#define TX_COMPLETE_REQUIRED_BIT 0x80 74#define TX_COMPLETE_REQUIRED_BIT 0x80
75#define TX_STATUS_DATA_OUT_COUNT_MASK 0xf 75#define TX_STATUS_DATA_OUT_COUNT_MASK 0xf
76#define WL12XX_TX_ALIGN_TO 4 76
77#define WL12XX_TX_ALIGN(len) (((len) + WL12XX_TX_ALIGN_TO - 1) & \ 77#define WL1251_TX_ALIGN_TO 4
78 ~(WL12XX_TX_ALIGN_TO - 1)) 78#define WL1251_TX_ALIGN(len) (((len) + WL1251_TX_ALIGN_TO - 1) & \
79#define WL12XX_TKIP_IV_SPACE 4 79 ~(WL1251_TX_ALIGN_TO - 1))
80#define WL1251_TKIP_IV_SPACE 4
80 81
81struct tx_control { 82struct tx_control {
82 /* Rate Policy (class) index */ 83 /* Rate Policy (class) index */
@@ -208,8 +209,8 @@ struct tx_result {
208 u8 done_2; 209 u8 done_2;
209} __attribute__ ((packed)); 210} __attribute__ ((packed));
210 211
211void wl12xx_tx_work(struct work_struct *work); 212void wl1251_tx_work(struct work_struct *work);
212void wl12xx_tx_complete(struct wl12xx *wl); 213void wl1251_tx_complete(struct wl1251 *wl);
213void wl12xx_tx_flush(struct wl12xx *wl); 214void wl1251_tx_flush(struct wl1251 *wl);
214 215
215#endif 216#endif
diff --git a/drivers/net/wireless/wl12xx/wl12xx.h b/drivers/net/wireless/wl12xx/wl12xx.h
deleted file mode 100644
index 48641437414b..000000000000
--- a/drivers/net/wireless/wl12xx/wl12xx.h
+++ /dev/null
@@ -1,409 +0,0 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008-2009 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL12XX_H__
26#define __WL12XX_H__
27
28#include <linux/mutex.h>
29#include <linux/list.h>
30#include <linux/bitops.h>
31#include <net/mac80211.h>
32
33#define DRIVER_NAME "wl12xx"
34#define DRIVER_PREFIX DRIVER_NAME ": "
35
36enum {
37 DEBUG_NONE = 0,
38 DEBUG_IRQ = BIT(0),
39 DEBUG_SPI = BIT(1),
40 DEBUG_BOOT = BIT(2),
41 DEBUG_MAILBOX = BIT(3),
42 DEBUG_NETLINK = BIT(4),
43 DEBUG_EVENT = BIT(5),
44 DEBUG_TX = BIT(6),
45 DEBUG_RX = BIT(7),
46 DEBUG_SCAN = BIT(8),
47 DEBUG_CRYPT = BIT(9),
48 DEBUG_PSM = BIT(10),
49 DEBUG_MAC80211 = BIT(11),
50 DEBUG_CMD = BIT(12),
51 DEBUG_ACX = BIT(13),
52 DEBUG_ALL = ~0,
53};
54
55#define DEBUG_LEVEL (DEBUG_NONE)
56
57#define DEBUG_DUMP_LIMIT 1024
58
59#define wl12xx_error(fmt, arg...) \
60 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
61
62#define wl12xx_warning(fmt, arg...) \
63 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
64
65#define wl12xx_notice(fmt, arg...) \
66 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
67
68#define wl12xx_info(fmt, arg...) \
69 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
70
71#define wl12xx_debug(level, fmt, arg...) \
72 do { \
73 if (level & DEBUG_LEVEL) \
74 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
75 } while (0)
76
77#define wl12xx_dump(level, prefix, buf, len) \
78 do { \
79 if (level & DEBUG_LEVEL) \
80 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
81 DUMP_PREFIX_OFFSET, 16, 1, \
82 buf, \
83 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
84 0); \
85 } while (0)
86
87#define wl12xx_dump_ascii(level, prefix, buf, len) \
88 do { \
89 if (level & DEBUG_LEVEL) \
90 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
91 DUMP_PREFIX_OFFSET, 16, 1, \
92 buf, \
93 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
94 true); \
95 } while (0)
96
97#define WL12XX_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
98 CFG_BSSID_FILTER_EN)
99
100#define WL12XX_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN | \
101 CFG_RX_MGMT_EN | \
102 CFG_RX_DATA_EN | \
103 CFG_RX_CTL_EN | \
104 CFG_RX_BCN_EN | \
105 CFG_RX_AUTH_EN | \
106 CFG_RX_ASSOC_EN)
107
108
109struct boot_attr {
110 u32 radio_type;
111 u8 mac_clock;
112 u8 arm_clock;
113 int firmware_debug;
114 u32 minor;
115 u32 major;
116 u32 bugfix;
117};
118
119enum wl12xx_state {
120 WL12XX_STATE_OFF,
121 WL12XX_STATE_ON,
122 WL12XX_STATE_PLT,
123};
124
125enum wl12xx_partition_type {
126 PART_DOWN,
127 PART_WORK,
128 PART_DRPW,
129
130 PART_TABLE_LEN
131};
132
133struct wl12xx_partition {
134 u32 size;
135 u32 start;
136};
137
138struct wl12xx_partition_set {
139 struct wl12xx_partition mem;
140 struct wl12xx_partition reg;
141};
142
143struct wl12xx;
144
145/* FIXME: I'm not sure about this structure name */
146struct wl12xx_chip {
147 u32 id;
148
149 const char *fw_filename;
150 const char *nvs_filename;
151
152 char fw_ver[21];
153
154 unsigned int power_on_sleep;
155 int intr_cmd_complete;
156 int intr_init_complete;
157
158 int (*op_upload_fw)(struct wl12xx *wl);
159 int (*op_upload_nvs)(struct wl12xx *wl);
160 int (*op_boot)(struct wl12xx *wl);
161 void (*op_set_ecpu_ctrl)(struct wl12xx *wl, u32 flag);
162 void (*op_target_enable_interrupts)(struct wl12xx *wl);
163 int (*op_hw_init)(struct wl12xx *wl);
164 int (*op_plt_init)(struct wl12xx *wl);
165
166 struct wl12xx_partition_set *p_table;
167 enum wl12xx_acx_int_reg *acx_reg_table;
168};
169
170struct wl12xx_stats {
171 struct acx_statistics *fw_stats;
172 unsigned long fw_stats_update;
173
174 unsigned int retry_count;
175 unsigned int excessive_retries;
176};
177
178struct wl12xx_debugfs {
179 struct dentry *rootdir;
180 struct dentry *fw_statistics;
181
182 struct dentry *tx_internal_desc_overflow;
183
184 struct dentry *rx_out_of_mem;
185 struct dentry *rx_hdr_overflow;
186 struct dentry *rx_hw_stuck;
187 struct dentry *rx_dropped;
188 struct dentry *rx_fcs_err;
189 struct dentry *rx_xfr_hint_trig;
190 struct dentry *rx_path_reset;
191 struct dentry *rx_reset_counter;
192
193 struct dentry *dma_rx_requested;
194 struct dentry *dma_rx_errors;
195 struct dentry *dma_tx_requested;
196 struct dentry *dma_tx_errors;
197
198 struct dentry *isr_cmd_cmplt;
199 struct dentry *isr_fiqs;
200 struct dentry *isr_rx_headers;
201 struct dentry *isr_rx_mem_overflow;
202 struct dentry *isr_rx_rdys;
203 struct dentry *isr_irqs;
204 struct dentry *isr_tx_procs;
205 struct dentry *isr_decrypt_done;
206 struct dentry *isr_dma0_done;
207 struct dentry *isr_dma1_done;
208 struct dentry *isr_tx_exch_complete;
209 struct dentry *isr_commands;
210 struct dentry *isr_rx_procs;
211 struct dentry *isr_hw_pm_mode_changes;
212 struct dentry *isr_host_acknowledges;
213 struct dentry *isr_pci_pm;
214 struct dentry *isr_wakeups;
215 struct dentry *isr_low_rssi;
216
217 struct dentry *wep_addr_key_count;
218 struct dentry *wep_default_key_count;
219 /* skipping wep.reserved */
220 struct dentry *wep_key_not_found;
221 struct dentry *wep_decrypt_fail;
222 struct dentry *wep_packets;
223 struct dentry *wep_interrupt;
224
225 struct dentry *pwr_ps_enter;
226 struct dentry *pwr_elp_enter;
227 struct dentry *pwr_missing_bcns;
228 struct dentry *pwr_wake_on_host;
229 struct dentry *pwr_wake_on_timer_exp;
230 struct dentry *pwr_tx_with_ps;
231 struct dentry *pwr_tx_without_ps;
232 struct dentry *pwr_rcvd_beacons;
233 struct dentry *pwr_power_save_off;
234 struct dentry *pwr_enable_ps;
235 struct dentry *pwr_disable_ps;
236 struct dentry *pwr_fix_tsf_ps;
237 /* skipping cont_miss_bcns_spread for now */
238 struct dentry *pwr_rcvd_awake_beacons;
239
240 struct dentry *mic_rx_pkts;
241 struct dentry *mic_calc_failure;
242
243 struct dentry *aes_encrypt_fail;
244 struct dentry *aes_decrypt_fail;
245 struct dentry *aes_encrypt_packets;
246 struct dentry *aes_decrypt_packets;
247 struct dentry *aes_encrypt_interrupt;
248 struct dentry *aes_decrypt_interrupt;
249
250 struct dentry *event_heart_beat;
251 struct dentry *event_calibration;
252 struct dentry *event_rx_mismatch;
253 struct dentry *event_rx_mem_empty;
254 struct dentry *event_rx_pool;
255 struct dentry *event_oom_late;
256 struct dentry *event_phy_transmit_error;
257 struct dentry *event_tx_stuck;
258
259 struct dentry *ps_pspoll_timeouts;
260 struct dentry *ps_upsd_timeouts;
261 struct dentry *ps_upsd_max_sptime;
262 struct dentry *ps_upsd_max_apturn;
263 struct dentry *ps_pspoll_max_apturn;
264 struct dentry *ps_pspoll_utilization;
265 struct dentry *ps_upsd_utilization;
266
267 struct dentry *rxpipe_rx_prep_beacon_drop;
268 struct dentry *rxpipe_descr_host_int_trig_rx_data;
269 struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
270 struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
271 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
272
273 struct dentry *tx_queue_len;
274
275 struct dentry *retry_count;
276 struct dentry *excessive_retries;
277};
278
279struct wl12xx {
280 struct ieee80211_hw *hw;
281 bool mac80211_registered;
282
283 struct spi_device *spi;
284
285 void (*set_power)(bool enable);
286 int irq;
287
288 enum wl12xx_state state;
289 struct mutex mutex;
290
291 int physical_mem_addr;
292 int physical_reg_addr;
293 int virtual_mem_addr;
294 int virtual_reg_addr;
295
296 struct wl12xx_chip chip;
297
298 int cmd_box_addr;
299 int event_box_addr;
300 struct boot_attr boot_attr;
301
302 u8 *fw;
303 size_t fw_len;
304 u8 *nvs;
305 size_t nvs_len;
306
307 u8 bssid[ETH_ALEN];
308 u8 mac_addr[ETH_ALEN];
309 u8 bss_type;
310 u8 listen_int;
311 int channel;
312
313 void *target_mem_map;
314 struct acx_data_path_params_resp *data_path;
315
316 /* Number of TX packets transferred to the FW, modulo 16 */
317 u32 data_in_count;
318
319 /* Frames scheduled for transmission, not handled yet */
320 struct sk_buff_head tx_queue;
321 bool tx_queue_stopped;
322
323 struct work_struct tx_work;
324 struct work_struct filter_work;
325
326 /* Pending TX frames */
327 struct sk_buff *tx_frames[16];
328
329 /*
330 * Index pointing to the next TX complete entry
331 * in the cyclic XT complete array we get from
332 * the FW.
333 */
334 u32 next_tx_complete;
335
336 /* FW Rx counter */
337 u32 rx_counter;
338
339 /* Rx frames handled */
340 u32 rx_handled;
341
342 /* Current double buffer */
343 u32 rx_current_buffer;
344 u32 rx_last_id;
345
346 /* The target interrupt mask */
347 u32 intr_mask;
348 struct work_struct irq_work;
349
350 /* The mbox event mask */
351 u32 event_mask;
352
353 /* Mailbox pointers */
354 u32 mbox_ptr[2];
355
356 /* Are we currently scanning */
357 bool scanning;
358
359 /* Our association ID */
360 u16 aid;
361
362 /* Default key (for WEP) */
363 u32 default_key;
364
365 unsigned int tx_mgmt_frm_rate;
366 unsigned int tx_mgmt_frm_mod;
367
368 unsigned int rx_config;
369 unsigned int rx_filter;
370
371 /* is firmware in elp mode */
372 bool elp;
373
374 /* we can be in psm, but not in elp, we have to differentiate */
375 bool psm;
376
377 /* PSM mode requested */
378 bool psm_requested;
379
380 /* in dBm */
381 int power_level;
382
383 struct wl12xx_stats stats;
384 struct wl12xx_debugfs debugfs;
385};
386
387int wl12xx_plt_start(struct wl12xx *wl);
388int wl12xx_plt_stop(struct wl12xx *wl);
389
390#define DEFAULT_HW_GEN_MODULATION_TYPE CCK_LONG /* Long Preamble */
391#define DEFAULT_HW_GEN_TX_RATE RATE_2MBPS
392#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
393
394#define WL12XX_DEFAULT_POWER_LEVEL 20
395
396#define WL12XX_TX_QUEUE_MAX_LENGTH 20
397
398/* Different chips need different sleep times after power on. WL1271 needs
399 * 200ms, WL1251 needs only 10ms. By default we use 200ms, but as soon as we
400 * know the chip ID, we change the sleep value in the wl12xx chip structure,
401 * so in subsequent power ons, we don't waste more time then needed. */
402#define WL12XX_DEFAULT_POWER_ON_SLEEP 200
403
404#define CHIP_ID_1251_PG10 (0x7010101)
405#define CHIP_ID_1251_PG11 (0x7020101)
406#define CHIP_ID_1251_PG12 (0x7030101)
407#define CHIP_ID_1271_PG10 (0x4030101)
408
409#endif
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index e3e96bb2c246..a83a5621ec44 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -1348,7 +1348,6 @@ static int wl3501_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1348 if (rc) { 1348 if (rc) {
1349 ++dev->stats.tx_dropped; 1349 ++dev->stats.tx_dropped;
1350 netif_stop_queue(dev); 1350 netif_stop_queue(dev);
1351 rc = NETDEV_TX_OK;
1352 } else { 1351 } else {
1353 ++dev->stats.tx_packets; 1352 ++dev->stats.tx_packets;
1354 dev->stats.tx_bytes += skb->len; 1353 dev->stats.tx_bytes += skb->len;
@@ -1358,7 +1357,7 @@ static int wl3501_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1358 netif_stop_queue(dev); 1357 netif_stop_queue(dev);
1359 } 1358 }
1360 spin_unlock_irqrestore(&this->lock, flags); 1359 spin_unlock_irqrestore(&this->lock, flags);
1361 return rc; 1360 return NETDEV_TX_OK;
1362} 1361}
1363 1362
1364static int wl3501_open(struct net_device *dev) 1363static int wl3501_open(struct net_device *dev)
diff --git a/drivers/net/wireless/zd1201.c b/drivers/net/wireless/zd1201.c
index 4430b8d92e21..dae1bfb7655e 100644
--- a/drivers/net/wireless/zd1201.c
+++ b/drivers/net/wireless/zd1201.c
@@ -789,7 +789,7 @@ static int zd1201_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
789 if (!zd->mac_enabled || zd->monitor) { 789 if (!zd->mac_enabled || zd->monitor) {
790 dev->stats.tx_dropped++; 790 dev->stats.tx_dropped++;
791 kfree_skb(skb); 791 kfree_skb(skb);
792 return 0; 792 return NETDEV_TX_OK;
793 } 793 }
794 netif_stop_queue(dev); 794 netif_stop_queue(dev);
795 795
@@ -826,7 +826,7 @@ static int zd1201_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
826 } 826 }
827 kfree_skb(skb); 827 kfree_skb(skb);
828 828
829 return 0; 829 return NETDEV_TX_OK;
830} 830}
831 831
832static void zd1201_tx_timeout(struct net_device *dev) 832static void zd1201_tx_timeout(struct net_device *dev)
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index 40b07b988224..9600b72495da 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -711,7 +711,8 @@ int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length)
711 711
712 memcpy(skb_put(skb, length), buffer, length); 712 memcpy(skb_put(skb, length), buffer, length);
713 713
714 ieee80211_rx_irqsafe(hw, skb, &stats); 714 memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
715 ieee80211_rx_irqsafe(hw, skb);
715 return 0; 716 return 0;
716} 717}
717 718
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index 0e6e44689cc6..07d7ab674a0f 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -36,58 +36,59 @@
36 36
37static struct usb_device_id usb_ids[] = { 37static struct usb_device_id usb_ids[] = {
38 /* ZD1211 */ 38 /* ZD1211 */
39 { USB_DEVICE(0x0105, 0x145f), .driver_info = DEVICE_ZD1211 },
40 { USB_DEVICE(0x0586, 0x3401), .driver_info = DEVICE_ZD1211 },
41 { USB_DEVICE(0x0586, 0x3402), .driver_info = DEVICE_ZD1211 },
42 { USB_DEVICE(0x0586, 0x3407), .driver_info = DEVICE_ZD1211 },
43 { USB_DEVICE(0x0586, 0x3409), .driver_info = DEVICE_ZD1211 },
44 { USB_DEVICE(0x079b, 0x004a), .driver_info = DEVICE_ZD1211 },
45 { USB_DEVICE(0x07b8, 0x6001), .driver_info = DEVICE_ZD1211 },
39 { USB_DEVICE(0x0ace, 0x1211), .driver_info = DEVICE_ZD1211 }, 46 { USB_DEVICE(0x0ace, 0x1211), .driver_info = DEVICE_ZD1211 },
40 { USB_DEVICE(0x0ace, 0xa211), .driver_info = DEVICE_ZD1211 }, 47 { USB_DEVICE(0x0ace, 0xa211), .driver_info = DEVICE_ZD1211 },
41 { USB_DEVICE(0x126f, 0xa006), .driver_info = DEVICE_ZD1211 }, 48 { USB_DEVICE(0x0b05, 0x170c), .driver_info = DEVICE_ZD1211 },
42 { USB_DEVICE(0x6891, 0xa727), .driver_info = DEVICE_ZD1211 }, 49 { USB_DEVICE(0x0b3b, 0x1630), .driver_info = DEVICE_ZD1211 },
50 { USB_DEVICE(0x0b3b, 0x5630), .driver_info = DEVICE_ZD1211 },
43 { USB_DEVICE(0x0df6, 0x9071), .driver_info = DEVICE_ZD1211 }, 51 { USB_DEVICE(0x0df6, 0x9071), .driver_info = DEVICE_ZD1211 },
44 { USB_DEVICE(0x0df6, 0x9075), .driver_info = DEVICE_ZD1211 }, 52 { USB_DEVICE(0x0df6, 0x9075), .driver_info = DEVICE_ZD1211 },
45 { USB_DEVICE(0x157e, 0x300b), .driver_info = DEVICE_ZD1211 }, 53 { USB_DEVICE(0x126f, 0xa006), .driver_info = DEVICE_ZD1211 },
46 { USB_DEVICE(0x079b, 0x004a), .driver_info = DEVICE_ZD1211 }, 54 { USB_DEVICE(0x129b, 0x1666), .driver_info = DEVICE_ZD1211 },
47 { USB_DEVICE(0x1740, 0x2000), .driver_info = DEVICE_ZD1211 }, 55 { USB_DEVICE(0x13b1, 0x001e), .driver_info = DEVICE_ZD1211 },
48 { USB_DEVICE(0x157e, 0x3204), .driver_info = DEVICE_ZD1211 },
49 { USB_DEVICE(0x0586, 0x3402), .driver_info = DEVICE_ZD1211 },
50 { USB_DEVICE(0x0b3b, 0x5630), .driver_info = DEVICE_ZD1211 },
51 { USB_DEVICE(0x0b05, 0x170c), .driver_info = DEVICE_ZD1211 },
52 { USB_DEVICE(0x1435, 0x0711), .driver_info = DEVICE_ZD1211 }, 56 { USB_DEVICE(0x1435, 0x0711), .driver_info = DEVICE_ZD1211 },
53 { USB_DEVICE(0x0586, 0x3409), .driver_info = DEVICE_ZD1211 },
54 { USB_DEVICE(0x0b3b, 0x1630), .driver_info = DEVICE_ZD1211 },
55 { USB_DEVICE(0x0586, 0x3401), .driver_info = DEVICE_ZD1211 },
56 { USB_DEVICE(0x14ea, 0xab13), .driver_info = DEVICE_ZD1211 }, 57 { USB_DEVICE(0x14ea, 0xab13), .driver_info = DEVICE_ZD1211 },
57 { USB_DEVICE(0x13b1, 0x001e), .driver_info = DEVICE_ZD1211 },
58 { USB_DEVICE(0x0586, 0x3407), .driver_info = DEVICE_ZD1211 },
59 { USB_DEVICE(0x129b, 0x1666), .driver_info = DEVICE_ZD1211 },
60 { USB_DEVICE(0x157e, 0x300a), .driver_info = DEVICE_ZD1211 }, 58 { USB_DEVICE(0x157e, 0x300a), .driver_info = DEVICE_ZD1211 },
61 { USB_DEVICE(0x0105, 0x145f), .driver_info = DEVICE_ZD1211 }, 59 { USB_DEVICE(0x157e, 0x300b), .driver_info = DEVICE_ZD1211 },
60 { USB_DEVICE(0x157e, 0x3204), .driver_info = DEVICE_ZD1211 },
61 { USB_DEVICE(0x1740, 0x2000), .driver_info = DEVICE_ZD1211 },
62 { USB_DEVICE(0x6891, 0xa727), .driver_info = DEVICE_ZD1211 },
62 /* ZD1211B */ 63 /* ZD1211B */
64 { USB_DEVICE(0x0053, 0x5301), .driver_info = DEVICE_ZD1211B },
65 { USB_DEVICE(0x0411, 0x00da), .driver_info = DEVICE_ZD1211B },
66 { USB_DEVICE(0x0471, 0x1236), .driver_info = DEVICE_ZD1211B },
67 { USB_DEVICE(0x0471, 0x1237), .driver_info = DEVICE_ZD1211B },
68 { USB_DEVICE(0x050d, 0x705c), .driver_info = DEVICE_ZD1211B },
63 { USB_DEVICE(0x054c, 0x0257), .driver_info = DEVICE_ZD1211B }, 69 { USB_DEVICE(0x054c, 0x0257), .driver_info = DEVICE_ZD1211B },
64 { USB_DEVICE(0x0ace, 0x1215), .driver_info = DEVICE_ZD1211B }, 70 { USB_DEVICE(0x0586, 0x340a), .driver_info = DEVICE_ZD1211B },
65 { USB_DEVICE(0x0ace, 0xb215), .driver_info = DEVICE_ZD1211B }, 71 { USB_DEVICE(0x0586, 0x340f), .driver_info = DEVICE_ZD1211B },
66 { USB_DEVICE(0x157e, 0x300d), .driver_info = DEVICE_ZD1211B }, 72 { USB_DEVICE(0x0586, 0x3410), .driver_info = DEVICE_ZD1211B },
73 { USB_DEVICE(0x0586, 0x3412), .driver_info = DEVICE_ZD1211B },
74 { USB_DEVICE(0x0586, 0x3413), .driver_info = DEVICE_ZD1211B },
67 { USB_DEVICE(0x079b, 0x0062), .driver_info = DEVICE_ZD1211B }, 75 { USB_DEVICE(0x079b, 0x0062), .driver_info = DEVICE_ZD1211B },
68 { USB_DEVICE(0x1582, 0x6003), .driver_info = DEVICE_ZD1211B }, 76 { USB_DEVICE(0x07b8, 0x6001), .driver_info = DEVICE_ZD1211B },
69 { USB_DEVICE(0x050d, 0x705c), .driver_info = DEVICE_ZD1211B }, 77 { USB_DEVICE(0x07fa, 0x1196), .driver_info = DEVICE_ZD1211B },
78 { USB_DEVICE(0x083a, 0x4505), .driver_info = DEVICE_ZD1211B },
70 { USB_DEVICE(0x083a, 0xe503), .driver_info = DEVICE_ZD1211B }, 79 { USB_DEVICE(0x083a, 0xe503), .driver_info = DEVICE_ZD1211B },
71 { USB_DEVICE(0x083a, 0xe506), .driver_info = DEVICE_ZD1211B }, 80 { USB_DEVICE(0x083a, 0xe506), .driver_info = DEVICE_ZD1211B },
72 { USB_DEVICE(0x083a, 0x4505), .driver_info = DEVICE_ZD1211B }, 81 { USB_DEVICE(0x0ace, 0x1215), .driver_info = DEVICE_ZD1211B },
73 { USB_DEVICE(0x0471, 0x1236), .driver_info = DEVICE_ZD1211B }, 82 { USB_DEVICE(0x0ace, 0xb215), .driver_info = DEVICE_ZD1211B },
74 { USB_DEVICE(0x13b1, 0x0024), .driver_info = DEVICE_ZD1211B },
75 { USB_DEVICE(0x0586, 0x340f), .driver_info = DEVICE_ZD1211B },
76 { USB_DEVICE(0x0b05, 0x171b), .driver_info = DEVICE_ZD1211B }, 83 { USB_DEVICE(0x0b05, 0x171b), .driver_info = DEVICE_ZD1211B },
77 { USB_DEVICE(0x0586, 0x3410), .driver_info = DEVICE_ZD1211B },
78 { USB_DEVICE(0x0baf, 0x0121), .driver_info = DEVICE_ZD1211B }, 84 { USB_DEVICE(0x0baf, 0x0121), .driver_info = DEVICE_ZD1211B },
79 { USB_DEVICE(0x0586, 0x3412), .driver_info = DEVICE_ZD1211B },
80 { USB_DEVICE(0x0586, 0x3413), .driver_info = DEVICE_ZD1211B },
81 { USB_DEVICE(0x0053, 0x5301), .driver_info = DEVICE_ZD1211B },
82 { USB_DEVICE(0x0411, 0x00da), .driver_info = DEVICE_ZD1211B },
83 { USB_DEVICE(0x2019, 0x5303), .driver_info = DEVICE_ZD1211B },
84 { USB_DEVICE(0x129b, 0x1667), .driver_info = DEVICE_ZD1211B },
85 { USB_DEVICE(0x0cde, 0x001a), .driver_info = DEVICE_ZD1211B }, 85 { USB_DEVICE(0x0cde, 0x001a), .driver_info = DEVICE_ZD1211B },
86 { USB_DEVICE(0x0586, 0x340a), .driver_info = DEVICE_ZD1211B },
87 { USB_DEVICE(0x0471, 0x1237), .driver_info = DEVICE_ZD1211B },
88 { USB_DEVICE(0x07fa, 0x1196), .driver_info = DEVICE_ZD1211B },
89 { USB_DEVICE(0x0df6, 0x0036), .driver_info = DEVICE_ZD1211B }, 86 { USB_DEVICE(0x0df6, 0x0036), .driver_info = DEVICE_ZD1211B },
90 { USB_DEVICE(0x07b8, 0x6001), .driver_info = DEVICE_ZD1211B }, 87 { USB_DEVICE(0x129b, 0x1667), .driver_info = DEVICE_ZD1211B },
88 { USB_DEVICE(0x13b1, 0x0024), .driver_info = DEVICE_ZD1211B },
89 { USB_DEVICE(0x157e, 0x300d), .driver_info = DEVICE_ZD1211B },
90 { USB_DEVICE(0x1582, 0x6003), .driver_info = DEVICE_ZD1211B },
91 { USB_DEVICE(0x2019, 0x5303), .driver_info = DEVICE_ZD1211B },
91 /* "Driverless" devices that need ejecting */ 92 /* "Driverless" devices that need ejecting */
92 { USB_DEVICE(0x0ace, 0x2011), .driver_info = DEVICE_INSTALLER }, 93 { USB_DEVICE(0x0ace, 0x2011), .driver_info = DEVICE_INSTALLER },
93 { USB_DEVICE(0x0ace, 0x20ff), .driver_info = DEVICE_INSTALLER }, 94 { USB_DEVICE(0x0ace, 0x20ff), .driver_info = DEVICE_INSTALLER },
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 8d88daeed0c6..3700c49d76ca 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -558,12 +558,12 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
558 558
559 spin_unlock_irq(&np->tx_lock); 559 spin_unlock_irq(&np->tx_lock);
560 560
561 return 0; 561 return NETDEV_TX_OK;
562 562
563 drop: 563 drop:
564 dev->stats.tx_dropped++; 564 dev->stats.tx_dropped++;
565 dev_kfree_skb(skb); 565 dev_kfree_skb(skb);
566 return 0; 566 return NETDEV_TX_OK;
567} 567}
568 568
569static int xennet_close(struct net_device *dev) 569static int xennet_close(struct net_device *dev)
diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c
index 3c7a5053f1da..c3722b40a651 100644
--- a/drivers/net/yellowfin.c
+++ b/drivers/net/yellowfin.c
@@ -827,7 +827,7 @@ static int yellowfin_start_xmit(struct sk_buff *skb, struct net_device *dev)
827 if (skb_padto(skb, len)) { 827 if (skb_padto(skb, len)) {
828 yp->tx_skbuff[entry] = NULL; 828 yp->tx_skbuff[entry] = NULL;
829 netif_wake_queue(dev); 829 netif_wake_queue(dev);
830 return 0; 830 return NETDEV_TX_OK;
831 } 831 }
832 } 832 }
833 } 833 }
@@ -881,7 +881,7 @@ static int yellowfin_start_xmit(struct sk_buff *skb, struct net_device *dev)
881 printk(KERN_DEBUG "%s: Yellowfin transmit frame #%d queued in slot %d.\n", 881 printk(KERN_DEBUG "%s: Yellowfin transmit frame #%d queued in slot %d.\n",
882 dev->name, yp->cur_tx, entry); 882 dev->name, yp->cur_tx, entry);
883 } 883 }
884 return 0; 884 return NETDEV_TX_OK;
885} 885}
886 886
887/* The interrupt handler does all of the Rx thread work and cleans up 887/* The interrupt handler does all of the Rx thread work and cleans up
diff --git a/drivers/net/znet.c b/drivers/net/znet.c
index 0a6992d8611b..7f9e14131a5c 100644
--- a/drivers/net/znet.c
+++ b/drivers/net/znet.c
@@ -546,7 +546,7 @@ static int znet_send_packet(struct sk_buff *skb, struct net_device *dev)
546 546
547 if (length < ETH_ZLEN) { 547 if (length < ETH_ZLEN) {
548 if (skb_padto(skb, ETH_ZLEN)) 548 if (skb_padto(skb, ETH_ZLEN))
549 return 0; 549 return NETDEV_TX_OK;
550 length = ETH_ZLEN; 550 length = ETH_ZLEN;
551 } 551 }
552 552
@@ -600,7 +600,7 @@ static int znet_send_packet(struct sk_buff *skb, struct net_device *dev)
600 printk(KERN_DEBUG "%s: Transmitter queued, length %d.\n", dev->name, length); 600 printk(KERN_DEBUG "%s: Transmitter queued, length %d.\n", dev->name, length);
601 } 601 }
602 dev_kfree_skb(skb); 602 dev_kfree_skb(skb);
603 return 0; 603 return NETDEV_TX_OK;
604} 604}
605 605
606/* The ZNET interrupt handler. */ 606/* The ZNET interrupt handler. */
diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
index 5d610cbcfe80..0f0e0b919ef4 100644
--- a/drivers/parisc/ccio-dma.c
+++ b/drivers/parisc/ccio-dma.c
@@ -1134,7 +1134,7 @@ static const struct file_operations ccio_proc_bitmap_fops = {
1134 .llseek = seq_lseek, 1134 .llseek = seq_lseek,
1135 .release = single_release, 1135 .release = single_release,
1136}; 1136};
1137#endif 1137#endif /* CONFIG_PROC_FS */
1138 1138
1139/** 1139/**
1140 * ccio_find_ioc - Find the ioc in the ioc_list 1140 * ccio_find_ioc - Find the ioc in the ioc_list
@@ -1568,14 +1568,15 @@ static int __init ccio_probe(struct parisc_device *dev)
1568 /* if this fails, no I/O cards will work, so may as well bug */ 1568 /* if this fails, no I/O cards will work, so may as well bug */
1569 BUG_ON(dev->dev.platform_data == NULL); 1569 BUG_ON(dev->dev.platform_data == NULL);
1570 HBA_DATA(dev->dev.platform_data)->iommu = ioc; 1570 HBA_DATA(dev->dev.platform_data)->iommu = ioc;
1571 1571
1572#ifdef CONFIG_PROC_FS
1572 if (ioc_count == 0) { 1573 if (ioc_count == 0) {
1573 proc_create(MODULE_NAME, 0, proc_runway_root, 1574 proc_create(MODULE_NAME, 0, proc_runway_root,
1574 &ccio_proc_info_fops); 1575 &ccio_proc_info_fops);
1575 proc_create(MODULE_NAME"-bitmap", 0, proc_runway_root, 1576 proc_create(MODULE_NAME"-bitmap", 0, proc_runway_root,
1576 &ccio_proc_bitmap_fops); 1577 &ccio_proc_bitmap_fops);
1577 } 1578 }
1578 1579#endif
1579 ioc_count++; 1580 ioc_count++;
1580 1581
1581 parisc_has_iommu(); 1582 parisc_has_iommu();
diff --git a/drivers/parisc/dino.c b/drivers/parisc/dino.c
index 52ae0b1d470c..c590974e9815 100644
--- a/drivers/parisc/dino.c
+++ b/drivers/parisc/dino.c
@@ -353,7 +353,7 @@ static unsigned int dino_startup_irq(unsigned int irq)
353 return 0; 353 return 0;
354} 354}
355 355
356static struct hw_interrupt_type dino_interrupt_type = { 356static struct irq_chip dino_interrupt_type = {
357 .typename = "GSC-PCI", 357 .typename = "GSC-PCI",
358 .startup = dino_startup_irq, 358 .startup = dino_startup_irq,
359 .shutdown = dino_disable_irq, 359 .shutdown = dino_disable_irq,
@@ -1019,22 +1019,22 @@ static int __init dino_probe(struct parisc_device *dev)
1019 ** It's not used to avoid chicken/egg problems 1019 ** It's not used to avoid chicken/egg problems
1020 ** with configuration accessor functions. 1020 ** with configuration accessor functions.
1021 */ 1021 */
1022 bus = pci_scan_bus_parented(&dev->dev, dino_current_bus, 1022 dino_dev->hba.hba_bus = bus = pci_scan_bus_parented(&dev->dev,
1023 &dino_cfg_ops, NULL); 1023 dino_current_bus, &dino_cfg_ops, NULL);
1024
1024 if(bus) { 1025 if(bus) {
1025 pci_bus_add_devices(bus);
1026 /* This code *depends* on scanning being single threaded 1026 /* This code *depends* on scanning being single threaded
1027 * if it isn't, this global bus number count will fail 1027 * if it isn't, this global bus number count will fail
1028 */ 1028 */
1029 dino_current_bus = bus->subordinate + 1; 1029 dino_current_bus = bus->subordinate + 1;
1030 pci_bus_assign_resources(bus); 1030 pci_bus_assign_resources(bus);
1031 pci_bus_add_devices(bus);
1031 } else { 1032 } else {
1032 printk(KERN_ERR "ERROR: failed to scan PCI bus on %s (probably duplicate bus number %d)\n", 1033 printk(KERN_ERR "ERROR: failed to scan PCI bus on %s (duplicate bus number %d?)\n",
1033 dev_name(&dev->dev), dino_current_bus); 1034 dev_name(&dev->dev), dino_current_bus);
1034 /* increment the bus number in case of duplicates */ 1035 /* increment the bus number in case of duplicates */
1035 dino_current_bus++; 1036 dino_current_bus++;
1036 } 1037 }
1037 dino_dev->hba.hba_bus = bus;
1038 return 0; 1038 return 0;
1039} 1039}
1040 1040
diff --git a/drivers/parisc/eisa.c b/drivers/parisc/eisa.c
index 5b89f404e668..51220749cb65 100644
--- a/drivers/parisc/eisa.c
+++ b/drivers/parisc/eisa.c
@@ -188,7 +188,7 @@ static unsigned int eisa_startup_irq(unsigned int irq)
188 return 0; 188 return 0;
189} 189}
190 190
191static struct hw_interrupt_type eisa_interrupt_type = { 191static struct irq_chip eisa_interrupt_type = {
192 .typename = "EISA", 192 .typename = "EISA",
193 .startup = eisa_startup_irq, 193 .startup = eisa_startup_irq,
194 .shutdown = eisa_disable_irq, 194 .shutdown = eisa_disable_irq,
diff --git a/drivers/parisc/gsc.c b/drivers/parisc/gsc.c
index d33632917696..647adc9f85ad 100644
--- a/drivers/parisc/gsc.c
+++ b/drivers/parisc/gsc.c
@@ -148,7 +148,7 @@ static unsigned int gsc_asic_startup_irq(unsigned int irq)
148 return 0; 148 return 0;
149} 149}
150 150
151static struct hw_interrupt_type gsc_asic_interrupt_type = { 151static struct irq_chip gsc_asic_interrupt_type = {
152 .typename = "GSC-ASIC", 152 .typename = "GSC-ASIC",
153 .startup = gsc_asic_startup_irq, 153 .startup = gsc_asic_startup_irq,
154 .shutdown = gsc_asic_disable_irq, 154 .shutdown = gsc_asic_disable_irq,
@@ -158,7 +158,7 @@ static struct hw_interrupt_type gsc_asic_interrupt_type = {
158 .end = no_end_irq, 158 .end = no_end_irq,
159}; 159};
160 160
161int gsc_assign_irq(struct hw_interrupt_type *type, void *data) 161int gsc_assign_irq(struct irq_chip *type, void *data)
162{ 162{
163 static int irq = GSC_IRQ_BASE; 163 static int irq = GSC_IRQ_BASE;
164 struct irq_desc *desc; 164 struct irq_desc *desc;
diff --git a/drivers/parisc/gsc.h b/drivers/parisc/gsc.h
index 762a1babad60..b9d7bfb68e24 100644
--- a/drivers/parisc/gsc.h
+++ b/drivers/parisc/gsc.h
@@ -38,7 +38,7 @@ struct gsc_asic {
38int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic); 38int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic);
39int gsc_alloc_irq(struct gsc_irq *dev); /* dev needs an irq */ 39int gsc_alloc_irq(struct gsc_irq *dev); /* dev needs an irq */
40int gsc_claim_irq(struct gsc_irq *dev, int irq); /* dev needs this irq */ 40int gsc_claim_irq(struct gsc_irq *dev, int irq); /* dev needs this irq */
41int gsc_assign_irq(struct hw_interrupt_type *type, void *data); 41int gsc_assign_irq(struct irq_chip *type, void *data);
42int gsc_find_local_irq(unsigned int irq, int *global_irq, int limit); 42int gsc_find_local_irq(unsigned int irq, int *global_irq, int limit);
43void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl, 43void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
44 void (*choose)(struct parisc_device *child, void *ctrl)); 44 void (*choose)(struct parisc_device *child, void *ctrl));
diff --git a/drivers/parisc/iosapic.c b/drivers/parisc/iosapic.c
index 4a9cc92d4d18..88e333553212 100644
--- a/drivers/parisc/iosapic.c
+++ b/drivers/parisc/iosapic.c
@@ -729,7 +729,7 @@ static int iosapic_set_affinity_irq(unsigned int irq,
729} 729}
730#endif 730#endif
731 731
732static struct hw_interrupt_type iosapic_interrupt_type = { 732static struct irq_chip iosapic_interrupt_type = {
733 .typename = "IO-SAPIC-level", 733 .typename = "IO-SAPIC-level",
734 .startup = iosapic_startup_irq, 734 .startup = iosapic_startup_irq,
735 .shutdown = iosapic_disable_irq, 735 .shutdown = iosapic_disable_irq,
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index 59fbbf128365..ede614616f8e 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -980,28 +980,38 @@ static void
980lba_pat_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev) 980lba_pat_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
981{ 981{
982 unsigned long bytecnt; 982 unsigned long bytecnt;
983 pdc_pat_cell_mod_maddr_block_t pa_pdc_cell; /* PA_VIEW */
984 pdc_pat_cell_mod_maddr_block_t io_pdc_cell; /* IO_VIEW */
985 long io_count; 983 long io_count;
986 long status; /* PDC return status */ 984 long status; /* PDC return status */
987 long pa_count; 985 long pa_count;
986 pdc_pat_cell_mod_maddr_block_t *pa_pdc_cell; /* PA_VIEW */
987 pdc_pat_cell_mod_maddr_block_t *io_pdc_cell; /* IO_VIEW */
988 int i; 988 int i;
989 989
990 pa_pdc_cell = kzalloc(sizeof(pdc_pat_cell_mod_maddr_block_t), GFP_KERNEL);
991 if (!pa_pdc_cell)
992 return;
993
994 io_pdc_cell = kzalloc(sizeof(pdc_pat_cell_mod_maddr_block_t), GFP_KERNEL);
995 if (!pa_pdc_cell) {
996 kfree(pa_pdc_cell);
997 return;
998 }
999
990 /* return cell module (IO view) */ 1000 /* return cell module (IO view) */
991 status = pdc_pat_cell_module(&bytecnt, pa_dev->pcell_loc, pa_dev->mod_index, 1001 status = pdc_pat_cell_module(&bytecnt, pa_dev->pcell_loc, pa_dev->mod_index,
992 PA_VIEW, & pa_pdc_cell); 1002 PA_VIEW, pa_pdc_cell);
993 pa_count = pa_pdc_cell.mod[1]; 1003 pa_count = pa_pdc_cell->mod[1];
994 1004
995 status |= pdc_pat_cell_module(&bytecnt, pa_dev->pcell_loc, pa_dev->mod_index, 1005 status |= pdc_pat_cell_module(&bytecnt, pa_dev->pcell_loc, pa_dev->mod_index,
996 IO_VIEW, &io_pdc_cell); 1006 IO_VIEW, io_pdc_cell);
997 io_count = io_pdc_cell.mod[1]; 1007 io_count = io_pdc_cell->mod[1];
998 1008
999 /* We've already done this once for device discovery...*/ 1009 /* We've already done this once for device discovery...*/
1000 if (status != PDC_OK) { 1010 if (status != PDC_OK) {
1001 panic("pdc_pat_cell_module() call failed for LBA!\n"); 1011 panic("pdc_pat_cell_module() call failed for LBA!\n");
1002 } 1012 }
1003 1013
1004 if (PAT_GET_ENTITY(pa_pdc_cell.mod_info) != PAT_ENTITY_LBA) { 1014 if (PAT_GET_ENTITY(pa_pdc_cell->mod_info) != PAT_ENTITY_LBA) {
1005 panic("pdc_pat_cell_module() entity returned != PAT_ENTITY_LBA!\n"); 1015 panic("pdc_pat_cell_module() entity returned != PAT_ENTITY_LBA!\n");
1006 } 1016 }
1007 1017
@@ -1016,8 +1026,8 @@ lba_pat_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
1016 } *p, *io; 1026 } *p, *io;
1017 struct resource *r; 1027 struct resource *r;
1018 1028
1019 p = (void *) &(pa_pdc_cell.mod[2+i*3]); 1029 p = (void *) &(pa_pdc_cell->mod[2+i*3]);
1020 io = (void *) &(io_pdc_cell.mod[2+i*3]); 1030 io = (void *) &(io_pdc_cell->mod[2+i*3]);
1021 1031
1022 /* Convert the PAT range data to PCI "struct resource" */ 1032 /* Convert the PAT range data to PCI "struct resource" */
1023 switch(p->type & 0xff) { 1033 switch(p->type & 0xff) {
@@ -1096,6 +1106,9 @@ lba_pat_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
1096 break; 1106 break;
1097 } 1107 }
1098 } 1108 }
1109
1110 kfree(pa_pdc_cell);
1111 kfree(io_pdc_cell);
1099} 1112}
1100#else 1113#else
1101/* keep compiler from complaining about missing declarations */ 1114/* keep compiler from complaining about missing declarations */
@@ -1509,10 +1522,6 @@ lba_driver_probe(struct parisc_device *dev)
1509 lba_bus = lba_dev->hba.hba_bus = 1522 lba_bus = lba_dev->hba.hba_bus =
1510 pci_scan_bus_parented(&dev->dev, lba_dev->hba.bus_num.start, 1523 pci_scan_bus_parented(&dev->dev, lba_dev->hba.bus_num.start,
1511 cfg_ops, NULL); 1524 cfg_ops, NULL);
1512 if (lba_bus) {
1513 lba_next_bus = lba_bus->subordinate + 1;
1514 pci_bus_add_devices(lba_bus);
1515 }
1516 1525
1517 /* This is in lieu of calling pci_assign_unassigned_resources() */ 1526 /* This is in lieu of calling pci_assign_unassigned_resources() */
1518 if (is_pdc_pat()) { 1527 if (is_pdc_pat()) {
@@ -1533,7 +1542,6 @@ lba_driver_probe(struct parisc_device *dev)
1533 } 1542 }
1534 pci_enable_bridges(lba_bus); 1543 pci_enable_bridges(lba_bus);
1535 1544
1536
1537 /* 1545 /*
1538 ** Once PCI register ops has walked the bus, access to config 1546 ** Once PCI register ops has walked the bus, access to config
1539 ** space is restricted. Avoids master aborts on config cycles. 1547 ** space is restricted. Avoids master aborts on config cycles.
@@ -1543,6 +1551,11 @@ lba_driver_probe(struct parisc_device *dev)
1543 lba_dev->flags |= LBA_FLAG_SKIP_PROBE; 1551 lba_dev->flags |= LBA_FLAG_SKIP_PROBE;
1544 } 1552 }
1545 1553
1554 if (lba_bus) {
1555 lba_next_bus = lba_bus->subordinate + 1;
1556 pci_bus_add_devices(lba_bus);
1557 }
1558
1546 /* Whew! Finally done! Tell services we got this one covered. */ 1559 /* Whew! Finally done! Tell services we got this one covered. */
1547 return 0; 1560 return 0;
1548} 1561}
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index d46dd57450ac..123d8fe3427d 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -2057,6 +2057,7 @@ void sba_directed_lmmio(struct parisc_device *pci_hba, struct resource *r)
2057 r->start = (base & ~1UL) | PCI_F_EXTEND; 2057 r->start = (base & ~1UL) | PCI_F_EXTEND;
2058 size = ~ READ_REG32(reg + LMMIO_DIRECT0_MASK); 2058 size = ~ READ_REG32(reg + LMMIO_DIRECT0_MASK);
2059 r->end = r->start + size; 2059 r->end = r->start + size;
2060 r->flags = IORESOURCE_MEM;
2060 } 2061 }
2061} 2062}
2062 2063
@@ -2093,4 +2094,5 @@ void sba_distributed_lmmio(struct parisc_device *pci_hba, struct resource *r )
2093 size = (~READ_REG32(sba->sba_hpa + LMMIO_DIST_MASK)) / ROPES_PER_IOC; 2094 size = (~READ_REG32(sba->sba_hpa + LMMIO_DIST_MASK)) / ROPES_PER_IOC;
2094 r->start += rope * (size + 1); /* adjust base for this rope */ 2095 r->start += rope * (size + 1); /* adjust base for this rope */
2095 r->end = r->start + size; 2096 r->end = r->start + size;
2097 r->flags = IORESOURCE_MEM;
2096} 2098}
diff --git a/drivers/parisc/superio.c b/drivers/parisc/superio.c
index 33e5ade774ca..675f04e6597a 100644
--- a/drivers/parisc/superio.c
+++ b/drivers/parisc/superio.c
@@ -325,7 +325,7 @@ static unsigned int superio_startup_irq(unsigned int irq)
325 return 0; 325 return 0;
326} 326}
327 327
328static struct hw_interrupt_type superio_interrupt_type = { 328static struct irq_chip superio_interrupt_type = {
329 .typename = SUPERIO, 329 .typename = SUPERIO,
330 .startup = superio_startup_irq, 330 .startup = superio_startup_irq,
331 .shutdown = superio_disable_irq, 331 .shutdown = superio_disable_irq,
@@ -434,8 +434,8 @@ static void __init superio_parport_init(void)
434 0 /*base_hi*/, 434 0 /*base_hi*/,
435 PAR_IRQ, 435 PAR_IRQ,
436 PARPORT_DMA_NONE /* dma */, 436 PARPORT_DMA_NONE /* dma */,
437 NULL /*struct pci_dev* */), 437 NULL /*struct pci_dev* */,
438 0 /* shared irq flags */ ) 438 0 /* shared irq flags */))
439 439
440 printk(KERN_WARNING PFX "Probing parallel port failed.\n"); 440 printk(KERN_WARNING PFX "Probing parallel port failed.\n");
441#endif /* CONFIG_PARPORT_PC */ 441#endif /* CONFIG_PARPORT_PC */
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index 1032d5fdbd42..2597145a066e 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -2907,6 +2907,7 @@ enum parport_pc_pci_cards {
2907 netmos_9755, 2907 netmos_9755,
2908 netmos_9805, 2908 netmos_9805,
2909 netmos_9815, 2909 netmos_9815,
2910 netmos_9901,
2910 quatech_sppxp100, 2911 quatech_sppxp100,
2911}; 2912};
2912 2913
@@ -2987,7 +2988,7 @@ static struct parport_pc_pci {
2987 /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} }, 2988 /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} },
2988 /* netmos_9805 */ { 1, { { 0, -1 }, } }, 2989 /* netmos_9805 */ { 1, { { 0, -1 }, } },
2989 /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, 2990 /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } },
2990 2991 /* netmos_9901 */ { 1, { { 0, -1 }, } },
2991 /* quatech_sppxp100 */ { 1, { { 0, 1 }, } }, 2992 /* quatech_sppxp100 */ { 1, { { 0, 1 }, } },
2992}; 2993};
2993 2994
@@ -3089,6 +3090,8 @@ static const struct pci_device_id parport_pc_pci_tbl[] = {
3089 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 }, 3090 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 },
3090 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815, 3091 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815,
3091 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 }, 3092 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 },
3093 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9901,
3094 0xA000, 0x2000, 0, 0, netmos_9901 },
3092 /* Quatech SPPXP-100 Parallel port PCI ExpressCard */ 3095 /* Quatech SPPXP-100 Parallel port PCI ExpressCard */
3093 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_SPPXP_100, 3096 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_SPPXP_100,
3094 PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 }, 3097 PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 },
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index e53eacd75c8d..53075424a434 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -39,7 +39,6 @@
39#include <linux/sysdev.h> 39#include <linux/sysdev.h>
40#include <asm/cacheflush.h> 40#include <asm/cacheflush.h>
41#include <asm/iommu.h> 41#include <asm/iommu.h>
42#include <asm/e820.h>
43#include "pci.h" 42#include "pci.h"
44 43
45#define ROOT_SIZE VTD_PAGE_SIZE 44#define ROOT_SIZE VTD_PAGE_SIZE
@@ -57,14 +56,32 @@
57#define MAX_AGAW_WIDTH 64 56#define MAX_AGAW_WIDTH 64
58 57
59#define DOMAIN_MAX_ADDR(gaw) ((((u64)1) << gaw) - 1) 58#define DOMAIN_MAX_ADDR(gaw) ((((u64)1) << gaw) - 1)
59#define DOMAIN_MAX_PFN(gaw) ((((u64)1) << (gaw-VTD_PAGE_SHIFT)) - 1)
60 60
61#define IOVA_PFN(addr) ((addr) >> PAGE_SHIFT) 61#define IOVA_PFN(addr) ((addr) >> PAGE_SHIFT)
62#define DMA_32BIT_PFN IOVA_PFN(DMA_BIT_MASK(32)) 62#define DMA_32BIT_PFN IOVA_PFN(DMA_BIT_MASK(32))
63#define DMA_64BIT_PFN IOVA_PFN(DMA_BIT_MASK(64)) 63#define DMA_64BIT_PFN IOVA_PFN(DMA_BIT_MASK(64))
64 64
65#ifndef PHYSICAL_PAGE_MASK 65
66#define PHYSICAL_PAGE_MASK PAGE_MASK 66/* VT-d pages must always be _smaller_ than MM pages. Otherwise things
67#endif 67 are never going to work. */
68static inline unsigned long dma_to_mm_pfn(unsigned long dma_pfn)
69{
70 return dma_pfn >> (PAGE_SHIFT - VTD_PAGE_SHIFT);
71}
72
73static inline unsigned long mm_to_dma_pfn(unsigned long mm_pfn)
74{
75 return mm_pfn << (PAGE_SHIFT - VTD_PAGE_SHIFT);
76}
77static inline unsigned long page_to_dma_pfn(struct page *pg)
78{
79 return mm_to_dma_pfn(page_to_pfn(pg));
80}
81static inline unsigned long virt_to_dma_pfn(void *p)
82{
83 return page_to_dma_pfn(virt_to_page(p));
84}
68 85
69/* global iommu list, set NULL for ignored DMAR units */ 86/* global iommu list, set NULL for ignored DMAR units */
70static struct intel_iommu **g_iommus; 87static struct intel_iommu **g_iommus;
@@ -205,12 +222,17 @@ static inline void dma_set_pte_prot(struct dma_pte *pte, unsigned long prot)
205 222
206static inline u64 dma_pte_addr(struct dma_pte *pte) 223static inline u64 dma_pte_addr(struct dma_pte *pte)
207{ 224{
208 return (pte->val & VTD_PAGE_MASK); 225#ifdef CONFIG_64BIT
226 return pte->val & VTD_PAGE_MASK;
227#else
228 /* Must have a full atomic 64-bit read */
229 return __cmpxchg64(pte, 0ULL, 0ULL) & VTD_PAGE_MASK;
230#endif
209} 231}
210 232
211static inline void dma_set_pte_addr(struct dma_pte *pte, u64 addr) 233static inline void dma_set_pte_pfn(struct dma_pte *pte, unsigned long pfn)
212{ 234{
213 pte->val |= (addr & VTD_PAGE_MASK); 235 pte->val |= (uint64_t)pfn << VTD_PAGE_SHIFT;
214} 236}
215 237
216static inline bool dma_pte_present(struct dma_pte *pte) 238static inline bool dma_pte_present(struct dma_pte *pte)
@@ -218,6 +240,11 @@ static inline bool dma_pte_present(struct dma_pte *pte)
218 return (pte->val & 3) != 0; 240 return (pte->val & 3) != 0;
219} 241}
220 242
243static inline int first_pte_in_page(struct dma_pte *pte)
244{
245 return !((unsigned long)pte & ~VTD_PAGE_MASK);
246}
247
221/* 248/*
222 * This domain is a statically identity mapping domain. 249 * This domain is a statically identity mapping domain.
223 * 1. This domain creats a static 1:1 mapping to all usable memory. 250 * 1. This domain creats a static 1:1 mapping to all usable memory.
@@ -245,7 +272,6 @@ struct dmar_domain {
245 struct iova_domain iovad; /* iova's that belong to this domain */ 272 struct iova_domain iovad; /* iova's that belong to this domain */
246 273
247 struct dma_pte *pgd; /* virtual address */ 274 struct dma_pte *pgd; /* virtual address */
248 spinlock_t mapping_lock; /* page table lock */
249 int gaw; /* max guest address width */ 275 int gaw; /* max guest address width */
250 276
251 /* adjusted guest address width, 0 is level 2 30-bit */ 277 /* adjusted guest address width, 0 is level 2 30-bit */
@@ -649,80 +675,78 @@ static inline int width_to_agaw(int width)
649 675
650static inline unsigned int level_to_offset_bits(int level) 676static inline unsigned int level_to_offset_bits(int level)
651{ 677{
652 return (12 + (level - 1) * LEVEL_STRIDE); 678 return (level - 1) * LEVEL_STRIDE;
653} 679}
654 680
655static inline int address_level_offset(u64 addr, int level) 681static inline int pfn_level_offset(unsigned long pfn, int level)
656{ 682{
657 return ((addr >> level_to_offset_bits(level)) & LEVEL_MASK); 683 return (pfn >> level_to_offset_bits(level)) & LEVEL_MASK;
658} 684}
659 685
660static inline u64 level_mask(int level) 686static inline unsigned long level_mask(int level)
661{ 687{
662 return ((u64)-1 << level_to_offset_bits(level)); 688 return -1UL << level_to_offset_bits(level);
663} 689}
664 690
665static inline u64 level_size(int level) 691static inline unsigned long level_size(int level)
666{ 692{
667 return ((u64)1 << level_to_offset_bits(level)); 693 return 1UL << level_to_offset_bits(level);
668} 694}
669 695
670static inline u64 align_to_level(u64 addr, int level) 696static inline unsigned long align_to_level(unsigned long pfn, int level)
671{ 697{
672 return ((addr + level_size(level) - 1) & level_mask(level)); 698 return (pfn + level_size(level) - 1) & level_mask(level);
673} 699}
674 700
675static struct dma_pte * addr_to_dma_pte(struct dmar_domain *domain, u64 addr) 701static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain,
702 unsigned long pfn)
676{ 703{
677 int addr_width = agaw_to_width(domain->agaw); 704 int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT;
678 struct dma_pte *parent, *pte = NULL; 705 struct dma_pte *parent, *pte = NULL;
679 int level = agaw_to_level(domain->agaw); 706 int level = agaw_to_level(domain->agaw);
680 int offset; 707 int offset;
681 unsigned long flags;
682 708
683 BUG_ON(!domain->pgd); 709 BUG_ON(!domain->pgd);
684 710 BUG_ON(addr_width < BITS_PER_LONG && pfn >> addr_width);
685 addr &= (((u64)1) << addr_width) - 1;
686 parent = domain->pgd; 711 parent = domain->pgd;
687 712
688 spin_lock_irqsave(&domain->mapping_lock, flags);
689 while (level > 0) { 713 while (level > 0) {
690 void *tmp_page; 714 void *tmp_page;
691 715
692 offset = address_level_offset(addr, level); 716 offset = pfn_level_offset(pfn, level);
693 pte = &parent[offset]; 717 pte = &parent[offset];
694 if (level == 1) 718 if (level == 1)
695 break; 719 break;
696 720
697 if (!dma_pte_present(pte)) { 721 if (!dma_pte_present(pte)) {
722 uint64_t pteval;
723
698 tmp_page = alloc_pgtable_page(); 724 tmp_page = alloc_pgtable_page();
699 725
700 if (!tmp_page) { 726 if (!tmp_page)
701 spin_unlock_irqrestore(&domain->mapping_lock,
702 flags);
703 return NULL; 727 return NULL;
728
729 domain_flush_cache(domain, tmp_page, VTD_PAGE_SIZE);
730 pteval = (virt_to_dma_pfn(tmp_page) << VTD_PAGE_SHIFT) | DMA_PTE_READ | DMA_PTE_WRITE;
731 if (cmpxchg64(&pte->val, 0ULL, pteval)) {
732 /* Someone else set it while we were thinking; use theirs. */
733 free_pgtable_page(tmp_page);
734 } else {
735 dma_pte_addr(pte);
736 domain_flush_cache(domain, pte, sizeof(*pte));
704 } 737 }
705 domain_flush_cache(domain, tmp_page, PAGE_SIZE);
706 dma_set_pte_addr(pte, virt_to_phys(tmp_page));
707 /*
708 * high level table always sets r/w, last level page
709 * table control read/write
710 */
711 dma_set_pte_readable(pte);
712 dma_set_pte_writable(pte);
713 domain_flush_cache(domain, pte, sizeof(*pte));
714 } 738 }
715 parent = phys_to_virt(dma_pte_addr(pte)); 739 parent = phys_to_virt(dma_pte_addr(pte));
716 level--; 740 level--;
717 } 741 }
718 742
719 spin_unlock_irqrestore(&domain->mapping_lock, flags);
720 return pte; 743 return pte;
721} 744}
722 745
723/* return address's pte at specific level */ 746/* return address's pte at specific level */
724static struct dma_pte *dma_addr_level_pte(struct dmar_domain *domain, u64 addr, 747static struct dma_pte *dma_pfn_level_pte(struct dmar_domain *domain,
725 int level) 748 unsigned long pfn,
749 int level)
726{ 750{
727 struct dma_pte *parent, *pte = NULL; 751 struct dma_pte *parent, *pte = NULL;
728 int total = agaw_to_level(domain->agaw); 752 int total = agaw_to_level(domain->agaw);
@@ -730,7 +754,7 @@ static struct dma_pte *dma_addr_level_pte(struct dmar_domain *domain, u64 addr,
730 754
731 parent = domain->pgd; 755 parent = domain->pgd;
732 while (level <= total) { 756 while (level <= total) {
733 offset = address_level_offset(addr, total); 757 offset = pfn_level_offset(pfn, total);
734 pte = &parent[offset]; 758 pte = &parent[offset];
735 if (level == total) 759 if (level == total)
736 return pte; 760 return pte;
@@ -743,74 +767,82 @@ static struct dma_pte *dma_addr_level_pte(struct dmar_domain *domain, u64 addr,
743 return NULL; 767 return NULL;
744} 768}
745 769
746/* clear one page's page table */
747static void dma_pte_clear_one(struct dmar_domain *domain, u64 addr)
748{
749 struct dma_pte *pte = NULL;
750
751 /* get last level pte */
752 pte = dma_addr_level_pte(domain, addr, 1);
753
754 if (pte) {
755 dma_clear_pte(pte);
756 domain_flush_cache(domain, pte, sizeof(*pte));
757 }
758}
759
760/* clear last level pte, a tlb flush should be followed */ 770/* clear last level pte, a tlb flush should be followed */
761static void dma_pte_clear_range(struct dmar_domain *domain, u64 start, u64 end) 771static void dma_pte_clear_range(struct dmar_domain *domain,
772 unsigned long start_pfn,
773 unsigned long last_pfn)
762{ 774{
763 int addr_width = agaw_to_width(domain->agaw); 775 int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT;
764 int npages; 776 struct dma_pte *first_pte, *pte;
777
778 BUG_ON(addr_width < BITS_PER_LONG && start_pfn >> addr_width);
779 BUG_ON(addr_width < BITS_PER_LONG && last_pfn >> addr_width);
765 780
766 start &= (((u64)1) << addr_width) - 1; 781 /* we don't need lock here; nobody else touches the iova range */
767 end &= (((u64)1) << addr_width) - 1; 782 while (start_pfn <= last_pfn) {
768 /* in case it's partial page */ 783 first_pte = pte = dma_pfn_level_pte(domain, start_pfn, 1);
769 start &= PAGE_MASK; 784 if (!pte) {
770 end = PAGE_ALIGN(end); 785 start_pfn = align_to_level(start_pfn + 1, 2);
771 npages = (end - start) / VTD_PAGE_SIZE; 786 continue;
787 }
788 do {
789 dma_clear_pte(pte);
790 start_pfn++;
791 pte++;
792 } while (start_pfn <= last_pfn && !first_pte_in_page(pte));
772 793
773 /* we don't need lock here, nobody else touches the iova range */ 794 domain_flush_cache(domain, first_pte,
774 while (npages--) { 795 (void *)pte - (void *)first_pte);
775 dma_pte_clear_one(domain, start);
776 start += VTD_PAGE_SIZE;
777 } 796 }
778} 797}
779 798
780/* free page table pages. last level pte should already be cleared */ 799/* free page table pages. last level pte should already be cleared */
781static void dma_pte_free_pagetable(struct dmar_domain *domain, 800static void dma_pte_free_pagetable(struct dmar_domain *domain,
782 u64 start, u64 end) 801 unsigned long start_pfn,
802 unsigned long last_pfn)
783{ 803{
784 int addr_width = agaw_to_width(domain->agaw); 804 int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT;
785 struct dma_pte *pte; 805 struct dma_pte *first_pte, *pte;
786 int total = agaw_to_level(domain->agaw); 806 int total = agaw_to_level(domain->agaw);
787 int level; 807 int level;
788 u64 tmp; 808 unsigned long tmp;
789 809
790 start &= (((u64)1) << addr_width) - 1; 810 BUG_ON(addr_width < BITS_PER_LONG && start_pfn >> addr_width);
791 end &= (((u64)1) << addr_width) - 1; 811 BUG_ON(addr_width < BITS_PER_LONG && last_pfn >> addr_width);
792 812
793 /* we don't need lock here, nobody else touches the iova range */ 813 /* We don't need lock here; nobody else touches the iova range */
794 level = 2; 814 level = 2;
795 while (level <= total) { 815 while (level <= total) {
796 tmp = align_to_level(start, level); 816 tmp = align_to_level(start_pfn, level);
797 if (tmp >= end || (tmp + level_size(level) > end)) 817
818 /* If we can't even clear one PTE at this level, we're done */
819 if (tmp + level_size(level) - 1 > last_pfn)
798 return; 820 return;
799 821
800 while (tmp < end) { 822 while (tmp + level_size(level) - 1 <= last_pfn) {
801 pte = dma_addr_level_pte(domain, tmp, level); 823 first_pte = pte = dma_pfn_level_pte(domain, tmp, level);
802 if (pte) { 824 if (!pte) {
803 free_pgtable_page( 825 tmp = align_to_level(tmp + 1, level + 1);
804 phys_to_virt(dma_pte_addr(pte))); 826 continue;
805 dma_clear_pte(pte);
806 domain_flush_cache(domain, pte, sizeof(*pte));
807 } 827 }
808 tmp += level_size(level); 828 do {
829 if (dma_pte_present(pte)) {
830 free_pgtable_page(phys_to_virt(dma_pte_addr(pte)));
831 dma_clear_pte(pte);
832 }
833 pte++;
834 tmp += level_size(level);
835 } while (!first_pte_in_page(pte) &&
836 tmp + level_size(level) - 1 <= last_pfn);
837
838 domain_flush_cache(domain, first_pte,
839 (void *)pte - (void *)first_pte);
840
809 } 841 }
810 level++; 842 level++;
811 } 843 }
812 /* free pgd */ 844 /* free pgd */
813 if (start == 0 && end >= ((((u64)1) << addr_width) - 1)) { 845 if (start_pfn == 0 && last_pfn == DOMAIN_MAX_PFN(domain->gaw)) {
814 free_pgtable_page(domain->pgd); 846 free_pgtable_page(domain->pgd);
815 domain->pgd = NULL; 847 domain->pgd = NULL;
816 } 848 }
@@ -1036,11 +1068,11 @@ static void iommu_flush_dev_iotlb(struct dmar_domain *domain,
1036} 1068}
1037 1069
1038static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, u16 did, 1070static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, u16 did,
1039 u64 addr, unsigned int pages) 1071 unsigned long pfn, unsigned int pages)
1040{ 1072{
1041 unsigned int mask = ilog2(__roundup_pow_of_two(pages)); 1073 unsigned int mask = ilog2(__roundup_pow_of_two(pages));
1074 uint64_t addr = (uint64_t)pfn << VTD_PAGE_SHIFT;
1042 1075
1043 BUG_ON(addr & (~VTD_PAGE_MASK));
1044 BUG_ON(pages == 0); 1076 BUG_ON(pages == 0);
1045 1077
1046 /* 1078 /*
@@ -1055,7 +1087,12 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, u16 did,
1055 else 1087 else
1056 iommu->flush.flush_iotlb(iommu, did, addr, mask, 1088 iommu->flush.flush_iotlb(iommu, did, addr, mask,
1057 DMA_TLB_PSI_FLUSH); 1089 DMA_TLB_PSI_FLUSH);
1058 if (did) 1090
1091 /*
1092 * In caching mode, domain ID 0 is reserved for non-present to present
1093 * mapping flush. Device IOTLB doesn't need to be flushed in this case.
1094 */
1095 if (!cap_caching_mode(iommu->cap) || did)
1059 iommu_flush_dev_iotlb(iommu->domains[did], addr, mask); 1096 iommu_flush_dev_iotlb(iommu->domains[did], addr, mask);
1060} 1097}
1061 1098
@@ -1280,7 +1317,6 @@ static void dmar_init_reserved_ranges(void)
1280 struct pci_dev *pdev = NULL; 1317 struct pci_dev *pdev = NULL;
1281 struct iova *iova; 1318 struct iova *iova;
1282 int i; 1319 int i;
1283 u64 addr, size;
1284 1320
1285 init_iova_domain(&reserved_iova_list, DMA_32BIT_PFN); 1321 init_iova_domain(&reserved_iova_list, DMA_32BIT_PFN);
1286 1322
@@ -1303,12 +1339,9 @@ static void dmar_init_reserved_ranges(void)
1303 r = &pdev->resource[i]; 1339 r = &pdev->resource[i];
1304 if (!r->flags || !(r->flags & IORESOURCE_MEM)) 1340 if (!r->flags || !(r->flags & IORESOURCE_MEM))
1305 continue; 1341 continue;
1306 addr = r->start; 1342 iova = reserve_iova(&reserved_iova_list,
1307 addr &= PHYSICAL_PAGE_MASK; 1343 IOVA_PFN(r->start),
1308 size = r->end - addr; 1344 IOVA_PFN(r->end));
1309 size = PAGE_ALIGN(size);
1310 iova = reserve_iova(&reserved_iova_list, IOVA_PFN(addr),
1311 IOVA_PFN(size + addr) - 1);
1312 if (!iova) 1345 if (!iova)
1313 printk(KERN_ERR "Reserve iova failed\n"); 1346 printk(KERN_ERR "Reserve iova failed\n");
1314 } 1347 }
@@ -1342,7 +1375,6 @@ static int domain_init(struct dmar_domain *domain, int guest_width)
1342 unsigned long sagaw; 1375 unsigned long sagaw;
1343 1376
1344 init_iova_domain(&domain->iovad, DMA_32BIT_PFN); 1377 init_iova_domain(&domain->iovad, DMA_32BIT_PFN);
1345 spin_lock_init(&domain->mapping_lock);
1346 spin_lock_init(&domain->iommu_lock); 1378 spin_lock_init(&domain->iommu_lock);
1347 1379
1348 domain_reserve_special_ranges(domain); 1380 domain_reserve_special_ranges(domain);
@@ -1389,7 +1421,6 @@ static void domain_exit(struct dmar_domain *domain)
1389{ 1421{
1390 struct dmar_drhd_unit *drhd; 1422 struct dmar_drhd_unit *drhd;
1391 struct intel_iommu *iommu; 1423 struct intel_iommu *iommu;
1392 u64 end;
1393 1424
1394 /* Domain 0 is reserved, so dont process it */ 1425 /* Domain 0 is reserved, so dont process it */
1395 if (!domain) 1426 if (!domain)
@@ -1398,14 +1429,12 @@ static void domain_exit(struct dmar_domain *domain)
1398 domain_remove_dev_info(domain); 1429 domain_remove_dev_info(domain);
1399 /* destroy iovas */ 1430 /* destroy iovas */
1400 put_iova_domain(&domain->iovad); 1431 put_iova_domain(&domain->iovad);
1401 end = DOMAIN_MAX_ADDR(domain->gaw);
1402 end = end & (~PAGE_MASK);
1403 1432
1404 /* clear ptes */ 1433 /* clear ptes */
1405 dma_pte_clear_range(domain, 0, end); 1434 dma_pte_clear_range(domain, 0, DOMAIN_MAX_PFN(domain->gaw));
1406 1435
1407 /* free page tables */ 1436 /* free page tables */
1408 dma_pte_free_pagetable(domain, 0, end); 1437 dma_pte_free_pagetable(domain, 0, DOMAIN_MAX_PFN(domain->gaw));
1409 1438
1410 for_each_active_iommu(iommu, drhd) 1439 for_each_active_iommu(iommu, drhd)
1411 if (test_bit(iommu->seq_id, &domain->iommu_bmp)) 1440 if (test_bit(iommu->seq_id, &domain->iommu_bmp))
@@ -1619,42 +1648,86 @@ static int domain_context_mapped(struct pci_dev *pdev)
1619 tmp->devfn); 1648 tmp->devfn);
1620} 1649}
1621 1650
1622static int 1651static int __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
1623domain_page_mapping(struct dmar_domain *domain, dma_addr_t iova, 1652 struct scatterlist *sg, unsigned long phys_pfn,
1624 u64 hpa, size_t size, int prot) 1653 unsigned long nr_pages, int prot)
1625{ 1654{
1626 u64 start_pfn, end_pfn; 1655 struct dma_pte *first_pte = NULL, *pte = NULL;
1627 struct dma_pte *pte; 1656 phys_addr_t uninitialized_var(pteval);
1628 int index; 1657 int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT;
1629 int addr_width = agaw_to_width(domain->agaw); 1658 unsigned long sg_res;
1630 1659
1631 hpa &= (((u64)1) << addr_width) - 1; 1660 BUG_ON(addr_width < BITS_PER_LONG && (iov_pfn + nr_pages - 1) >> addr_width);
1632 1661
1633 if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) == 0) 1662 if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) == 0)
1634 return -EINVAL; 1663 return -EINVAL;
1635 iova &= PAGE_MASK; 1664
1636 start_pfn = ((u64)hpa) >> VTD_PAGE_SHIFT; 1665 prot &= DMA_PTE_READ | DMA_PTE_WRITE | DMA_PTE_SNP;
1637 end_pfn = (VTD_PAGE_ALIGN(((u64)hpa) + size)) >> VTD_PAGE_SHIFT; 1666
1638 index = 0; 1667 if (sg)
1639 while (start_pfn < end_pfn) { 1668 sg_res = 0;
1640 pte = addr_to_dma_pte(domain, iova + VTD_PAGE_SIZE * index); 1669 else {
1641 if (!pte) 1670 sg_res = nr_pages + 1;
1642 return -ENOMEM; 1671 pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | prot;
1672 }
1673
1674 while (nr_pages--) {
1675 uint64_t tmp;
1676
1677 if (!sg_res) {
1678 sg_res = (sg->offset + sg->length + VTD_PAGE_SIZE - 1) >> VTD_PAGE_SHIFT;
1679 sg->dma_address = ((dma_addr_t)iov_pfn << VTD_PAGE_SHIFT) + sg->offset;
1680 sg->dma_length = sg->length;
1681 pteval = page_to_phys(sg_page(sg)) | prot;
1682 }
1683 if (!pte) {
1684 first_pte = pte = pfn_to_dma_pte(domain, iov_pfn);
1685 if (!pte)
1686 return -ENOMEM;
1687 }
1643 /* We don't need lock here, nobody else 1688 /* We don't need lock here, nobody else
1644 * touches the iova range 1689 * touches the iova range
1645 */ 1690 */
1646 BUG_ON(dma_pte_addr(pte)); 1691 tmp = cmpxchg64_local(&pte->val, 0ULL, pteval);
1647 dma_set_pte_addr(pte, start_pfn << VTD_PAGE_SHIFT); 1692 if (tmp) {
1648 dma_set_pte_prot(pte, prot); 1693 static int dumps = 5;
1649 if (prot & DMA_PTE_SNP) 1694 printk(KERN_CRIT "ERROR: DMA PTE for vPFN 0x%lx already set (to %llx not %llx)\n",
1650 dma_set_pte_snp(pte); 1695 iov_pfn, tmp, (unsigned long long)pteval);
1651 domain_flush_cache(domain, pte, sizeof(*pte)); 1696 if (dumps) {
1652 start_pfn++; 1697 dumps--;
1653 index++; 1698 debug_dma_dump_mappings(NULL);
1699 }
1700 WARN_ON(1);
1701 }
1702 pte++;
1703 if (!nr_pages || first_pte_in_page(pte)) {
1704 domain_flush_cache(domain, first_pte,
1705 (void *)pte - (void *)first_pte);
1706 pte = NULL;
1707 }
1708 iov_pfn++;
1709 pteval += VTD_PAGE_SIZE;
1710 sg_res--;
1711 if (!sg_res)
1712 sg = sg_next(sg);
1654 } 1713 }
1655 return 0; 1714 return 0;
1656} 1715}
1657 1716
1717static inline int domain_sg_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
1718 struct scatterlist *sg, unsigned long nr_pages,
1719 int prot)
1720{
1721 return __domain_mapping(domain, iov_pfn, sg, 0, nr_pages, prot);
1722}
1723
1724static inline int domain_pfn_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
1725 unsigned long phys_pfn, unsigned long nr_pages,
1726 int prot)
1727{
1728 return __domain_mapping(domain, iov_pfn, NULL, phys_pfn, nr_pages, prot);
1729}
1730
1658static void iommu_detach_dev(struct intel_iommu *iommu, u8 bus, u8 devfn) 1731static void iommu_detach_dev(struct intel_iommu *iommu, u8 bus, u8 devfn)
1659{ 1732{
1660 if (!iommu) 1733 if (!iommu)
@@ -1845,58 +1918,61 @@ error:
1845 1918
1846static int iommu_identity_mapping; 1919static int iommu_identity_mapping;
1847 1920
1921static int iommu_domain_identity_map(struct dmar_domain *domain,
1922 unsigned long long start,
1923 unsigned long long end)
1924{
1925 unsigned long first_vpfn = start >> VTD_PAGE_SHIFT;
1926 unsigned long last_vpfn = end >> VTD_PAGE_SHIFT;
1927
1928 if (!reserve_iova(&domain->iovad, dma_to_mm_pfn(first_vpfn),
1929 dma_to_mm_pfn(last_vpfn))) {
1930 printk(KERN_ERR "IOMMU: reserve iova failed\n");
1931 return -ENOMEM;
1932 }
1933
1934 pr_debug("Mapping reserved region %llx-%llx for domain %d\n",
1935 start, end, domain->id);
1936 /*
1937 * RMRR range might have overlap with physical memory range,
1938 * clear it first
1939 */
1940 dma_pte_clear_range(domain, first_vpfn, last_vpfn);
1941
1942 return domain_pfn_mapping(domain, first_vpfn, first_vpfn,
1943 last_vpfn - first_vpfn + 1,
1944 DMA_PTE_READ|DMA_PTE_WRITE);
1945}
1946
1848static int iommu_prepare_identity_map(struct pci_dev *pdev, 1947static int iommu_prepare_identity_map(struct pci_dev *pdev,
1849 unsigned long long start, 1948 unsigned long long start,
1850 unsigned long long end) 1949 unsigned long long end)
1851{ 1950{
1852 struct dmar_domain *domain; 1951 struct dmar_domain *domain;
1853 unsigned long size;
1854 unsigned long long base;
1855 int ret; 1952 int ret;
1856 1953
1857 printk(KERN_INFO 1954 printk(KERN_INFO
1858 "IOMMU: Setting identity map for device %s [0x%Lx - 0x%Lx]\n", 1955 "IOMMU: Setting identity map for device %s [0x%Lx - 0x%Lx]\n",
1859 pci_name(pdev), start, end); 1956 pci_name(pdev), start, end);
1860 if (iommu_identity_mapping) 1957
1861 domain = si_domain; 1958 domain = get_domain_for_dev(pdev, DEFAULT_DOMAIN_ADDRESS_WIDTH);
1862 else
1863 /* page table init */
1864 domain = get_domain_for_dev(pdev, DEFAULT_DOMAIN_ADDRESS_WIDTH);
1865 if (!domain) 1959 if (!domain)
1866 return -ENOMEM; 1960 return -ENOMEM;
1867 1961
1868 /* The address might not be aligned */ 1962 ret = iommu_domain_identity_map(domain, start, end);
1869 base = start & PAGE_MASK;
1870 size = end - base;
1871 size = PAGE_ALIGN(size);
1872 if (!reserve_iova(&domain->iovad, IOVA_PFN(base),
1873 IOVA_PFN(base + size) - 1)) {
1874 printk(KERN_ERR "IOMMU: reserve iova failed\n");
1875 ret = -ENOMEM;
1876 goto error;
1877 }
1878
1879 pr_debug("Mapping reserved region %lx@%llx for %s\n",
1880 size, base, pci_name(pdev));
1881 /*
1882 * RMRR range might have overlap with physical memory range,
1883 * clear it first
1884 */
1885 dma_pte_clear_range(domain, base, base + size);
1886
1887 ret = domain_page_mapping(domain, base, base, size,
1888 DMA_PTE_READ|DMA_PTE_WRITE);
1889 if (ret) 1963 if (ret)
1890 goto error; 1964 goto error;
1891 1965
1892 /* context entry init */ 1966 /* context entry init */
1893 ret = domain_context_mapping(domain, pdev, CONTEXT_TT_MULTI_LEVEL); 1967 ret = domain_context_mapping(domain, pdev, CONTEXT_TT_MULTI_LEVEL);
1894 if (!ret) 1968 if (ret)
1895 return 0; 1969 goto error;
1896error: 1970
1971 return 0;
1972
1973 error:
1897 domain_exit(domain); 1974 domain_exit(domain);
1898 return ret; 1975 return ret;
1899
1900} 1976}
1901 1977
1902static inline int iommu_prepare_rmrr_dev(struct dmar_rmrr_unit *rmrr, 1978static inline int iommu_prepare_rmrr_dev(struct dmar_rmrr_unit *rmrr,
@@ -1908,64 +1984,6 @@ static inline int iommu_prepare_rmrr_dev(struct dmar_rmrr_unit *rmrr,
1908 rmrr->end_address + 1); 1984 rmrr->end_address + 1);
1909} 1985}
1910 1986
1911#ifdef CONFIG_DMAR_GFX_WA
1912struct iommu_prepare_data {
1913 struct pci_dev *pdev;
1914 int ret;
1915};
1916
1917static int __init iommu_prepare_work_fn(unsigned long start_pfn,
1918 unsigned long end_pfn, void *datax)
1919{
1920 struct iommu_prepare_data *data;
1921
1922 data = (struct iommu_prepare_data *)datax;
1923
1924 data->ret = iommu_prepare_identity_map(data->pdev,
1925 start_pfn<<PAGE_SHIFT, end_pfn<<PAGE_SHIFT);
1926 return data->ret;
1927
1928}
1929
1930static int __init iommu_prepare_with_active_regions(struct pci_dev *pdev)
1931{
1932 int nid;
1933 struct iommu_prepare_data data;
1934
1935 data.pdev = pdev;
1936 data.ret = 0;
1937
1938 for_each_online_node(nid) {
1939 work_with_active_regions(nid, iommu_prepare_work_fn, &data);
1940 if (data.ret)
1941 return data.ret;
1942 }
1943 return data.ret;
1944}
1945
1946static void __init iommu_prepare_gfx_mapping(void)
1947{
1948 struct pci_dev *pdev = NULL;
1949 int ret;
1950
1951 for_each_pci_dev(pdev) {
1952 if (pdev->dev.archdata.iommu == DUMMY_DEVICE_DOMAIN_INFO ||
1953 !IS_GFX_DEVICE(pdev))
1954 continue;
1955 printk(KERN_INFO "IOMMU: gfx device %s 1-1 mapping\n",
1956 pci_name(pdev));
1957 ret = iommu_prepare_with_active_regions(pdev);
1958 if (ret)
1959 printk(KERN_ERR "IOMMU: mapping reserved region failed\n");
1960 }
1961}
1962#else /* !CONFIG_DMAR_GFX_WA */
1963static inline void iommu_prepare_gfx_mapping(void)
1964{
1965 return;
1966}
1967#endif
1968
1969#ifdef CONFIG_DMAR_FLOPPY_WA 1987#ifdef CONFIG_DMAR_FLOPPY_WA
1970static inline void iommu_prepare_isa(void) 1988static inline void iommu_prepare_isa(void)
1971{ 1989{
@@ -1976,12 +1994,12 @@ static inline void iommu_prepare_isa(void)
1976 if (!pdev) 1994 if (!pdev)
1977 return; 1995 return;
1978 1996
1979 printk(KERN_INFO "IOMMU: Prepare 0-16M unity mapping for LPC\n"); 1997 printk(KERN_INFO "IOMMU: Prepare 0-16MiB unity mapping for LPC\n");
1980 ret = iommu_prepare_identity_map(pdev, 0, 16*1024*1024); 1998 ret = iommu_prepare_identity_map(pdev, 0, 16*1024*1024);
1981 1999
1982 if (ret) 2000 if (ret)
1983 printk(KERN_ERR "IOMMU: Failed to create 0-64M identity map, " 2001 printk(KERN_ERR "IOMMU: Failed to create 0-16MiB identity map; "
1984 "floppy might not work\n"); 2002 "floppy might not work\n");
1985 2003
1986} 2004}
1987#else 2005#else
@@ -2009,16 +2027,30 @@ static int __init init_context_pass_through(void)
2009} 2027}
2010 2028
2011static int md_domain_init(struct dmar_domain *domain, int guest_width); 2029static int md_domain_init(struct dmar_domain *domain, int guest_width);
2030
2031static int __init si_domain_work_fn(unsigned long start_pfn,
2032 unsigned long end_pfn, void *datax)
2033{
2034 int *ret = datax;
2035
2036 *ret = iommu_domain_identity_map(si_domain,
2037 (uint64_t)start_pfn << PAGE_SHIFT,
2038 (uint64_t)end_pfn << PAGE_SHIFT);
2039 return *ret;
2040
2041}
2042
2012static int si_domain_init(void) 2043static int si_domain_init(void)
2013{ 2044{
2014 struct dmar_drhd_unit *drhd; 2045 struct dmar_drhd_unit *drhd;
2015 struct intel_iommu *iommu; 2046 struct intel_iommu *iommu;
2016 int ret = 0; 2047 int nid, ret = 0;
2017 2048
2018 si_domain = alloc_domain(); 2049 si_domain = alloc_domain();
2019 if (!si_domain) 2050 if (!si_domain)
2020 return -EFAULT; 2051 return -EFAULT;
2021 2052
2053 pr_debug("Identity mapping domain is domain %d\n", si_domain->id);
2022 2054
2023 for_each_active_iommu(iommu, drhd) { 2055 for_each_active_iommu(iommu, drhd) {
2024 ret = iommu_attach_domain(si_domain, iommu); 2056 ret = iommu_attach_domain(si_domain, iommu);
@@ -2035,6 +2067,12 @@ static int si_domain_init(void)
2035 2067
2036 si_domain->flags = DOMAIN_FLAG_STATIC_IDENTITY; 2068 si_domain->flags = DOMAIN_FLAG_STATIC_IDENTITY;
2037 2069
2070 for_each_online_node(nid) {
2071 work_with_active_regions(nid, si_domain_work_fn, &ret);
2072 if (ret)
2073 return ret;
2074 }
2075
2038 return 0; 2076 return 0;
2039} 2077}
2040 2078
@@ -2081,7 +2119,6 @@ static int domain_add_dev_info(struct dmar_domain *domain,
2081 2119
2082static int iommu_prepare_static_identity_mapping(void) 2120static int iommu_prepare_static_identity_mapping(void)
2083{ 2121{
2084 int i;
2085 struct pci_dev *pdev = NULL; 2122 struct pci_dev *pdev = NULL;
2086 int ret; 2123 int ret;
2087 2124
@@ -2089,20 +2126,14 @@ static int iommu_prepare_static_identity_mapping(void)
2089 if (ret) 2126 if (ret)
2090 return -EFAULT; 2127 return -EFAULT;
2091 2128
2092 printk(KERN_INFO "IOMMU: Setting identity map:\n");
2093 for_each_pci_dev(pdev) { 2129 for_each_pci_dev(pdev) {
2094 for (i = 0; i < e820.nr_map; i++) { 2130 printk(KERN_INFO "IOMMU: identity mapping for device %s\n",
2095 struct e820entry *ei = &e820.map[i]; 2131 pci_name(pdev));
2096 2132
2097 if (ei->type == E820_RAM) { 2133 ret = domain_context_mapping(si_domain, pdev,
2098 ret = iommu_prepare_identity_map(pdev, 2134 CONTEXT_TT_MULTI_LEVEL);
2099 ei->addr, ei->addr + ei->size); 2135 if (ret)
2100 if (ret) { 2136 return ret;
2101 printk(KERN_INFO "1:1 mapping to one domain failed.\n");
2102 return -EFAULT;
2103 }
2104 }
2105 }
2106 ret = domain_add_dev_info(si_domain, pdev); 2137 ret = domain_add_dev_info(si_domain, pdev);
2107 if (ret) 2138 if (ret)
2108 return ret; 2139 return ret;
@@ -2293,8 +2324,6 @@ int __init init_dmars(void)
2293 } 2324 }
2294 } 2325 }
2295 2326
2296 iommu_prepare_gfx_mapping();
2297
2298 iommu_prepare_isa(); 2327 iommu_prepare_isa();
2299 } 2328 }
2300 2329
@@ -2339,50 +2368,40 @@ error:
2339 return ret; 2368 return ret;
2340} 2369}
2341 2370
2342static inline u64 aligned_size(u64 host_addr, size_t size) 2371static inline unsigned long aligned_nrpages(unsigned long host_addr,
2343{ 2372 size_t size)
2344 u64 addr;
2345 addr = (host_addr & (~PAGE_MASK)) + size;
2346 return PAGE_ALIGN(addr);
2347}
2348
2349struct iova *
2350iommu_alloc_iova(struct dmar_domain *domain, size_t size, u64 end)
2351{ 2373{
2352 struct iova *piova; 2374 host_addr &= ~PAGE_MASK;
2375 host_addr += size + PAGE_SIZE - 1;
2353 2376
2354 /* Make sure it's in range */ 2377 return host_addr >> VTD_PAGE_SHIFT;
2355 end = min_t(u64, DOMAIN_MAX_ADDR(domain->gaw), end);
2356 if (!size || (IOVA_START_ADDR + size > end))
2357 return NULL;
2358
2359 piova = alloc_iova(&domain->iovad,
2360 size >> PAGE_SHIFT, IOVA_PFN(end), 1);
2361 return piova;
2362} 2378}
2363 2379
2364static struct iova * 2380static struct iova *intel_alloc_iova(struct device *dev,
2365__intel_alloc_iova(struct device *dev, struct dmar_domain *domain, 2381 struct dmar_domain *domain,
2366 size_t size, u64 dma_mask) 2382 unsigned long nrpages, uint64_t dma_mask)
2367{ 2383{
2368 struct pci_dev *pdev = to_pci_dev(dev); 2384 struct pci_dev *pdev = to_pci_dev(dev);
2369 struct iova *iova = NULL; 2385 struct iova *iova = NULL;
2370 2386
2371 if (dma_mask <= DMA_BIT_MASK(32) || dmar_forcedac) 2387 /* Restrict dma_mask to the width that the iommu can handle */
2372 iova = iommu_alloc_iova(domain, size, dma_mask); 2388 dma_mask = min_t(uint64_t, DOMAIN_MAX_ADDR(domain->gaw), dma_mask);
2373 else { 2389
2390 if (!dmar_forcedac && dma_mask > DMA_BIT_MASK(32)) {
2374 /* 2391 /*
2375 * First try to allocate an io virtual address in 2392 * First try to allocate an io virtual address in
2376 * DMA_BIT_MASK(32) and if that fails then try allocating 2393 * DMA_BIT_MASK(32) and if that fails then try allocating
2377 * from higher range 2394 * from higher range
2378 */ 2395 */
2379 iova = iommu_alloc_iova(domain, size, DMA_BIT_MASK(32)); 2396 iova = alloc_iova(&domain->iovad, nrpages,
2380 if (!iova) 2397 IOVA_PFN(DMA_BIT_MASK(32)), 1);
2381 iova = iommu_alloc_iova(domain, size, dma_mask); 2398 if (iova)
2382 } 2399 return iova;
2383 2400 }
2384 if (!iova) { 2401 iova = alloc_iova(&domain->iovad, nrpages, IOVA_PFN(dma_mask), 1);
2385 printk(KERN_ERR"Allocating iova for %s failed", pci_name(pdev)); 2402 if (unlikely(!iova)) {
2403 printk(KERN_ERR "Allocating %ld-page iova for %s failed",
2404 nrpages, pci_name(pdev));
2386 return NULL; 2405 return NULL;
2387 } 2406 }
2388 2407
@@ -2485,14 +2504,12 @@ static dma_addr_t __intel_map_single(struct device *hwdev, phys_addr_t paddr,
2485 return 0; 2504 return 0;
2486 2505
2487 iommu = domain_get_iommu(domain); 2506 iommu = domain_get_iommu(domain);
2488 size = aligned_size((u64)paddr, size); 2507 size = aligned_nrpages(paddr, size);
2489 2508
2490 iova = __intel_alloc_iova(hwdev, domain, size, pdev->dma_mask); 2509 iova = intel_alloc_iova(hwdev, domain, size, pdev->dma_mask);
2491 if (!iova) 2510 if (!iova)
2492 goto error; 2511 goto error;
2493 2512
2494 start_paddr = (phys_addr_t)iova->pfn_lo << PAGE_SHIFT;
2495
2496 /* 2513 /*
2497 * Check if DMAR supports zero-length reads on write only 2514 * Check if DMAR supports zero-length reads on write only
2498 * mappings.. 2515 * mappings..
@@ -2508,20 +2525,20 @@ static dma_addr_t __intel_map_single(struct device *hwdev, phys_addr_t paddr,
2508 * might have two guest_addr mapping to the same host paddr, but this 2525 * might have two guest_addr mapping to the same host paddr, but this
2509 * is not a big problem 2526 * is not a big problem
2510 */ 2527 */
2511 ret = domain_page_mapping(domain, start_paddr, 2528 ret = domain_pfn_mapping(domain, mm_to_dma_pfn(iova->pfn_lo),
2512 ((u64)paddr) & PHYSICAL_PAGE_MASK, 2529 paddr >> VTD_PAGE_SHIFT, size, prot);
2513 size, prot);
2514 if (ret) 2530 if (ret)
2515 goto error; 2531 goto error;
2516 2532
2517 /* it's a non-present to present mapping. Only flush if caching mode */ 2533 /* it's a non-present to present mapping. Only flush if caching mode */
2518 if (cap_caching_mode(iommu->cap)) 2534 if (cap_caching_mode(iommu->cap))
2519 iommu_flush_iotlb_psi(iommu, 0, start_paddr, 2535 iommu_flush_iotlb_psi(iommu, 0, mm_to_dma_pfn(iova->pfn_lo), size);
2520 size >> VTD_PAGE_SHIFT);
2521 else 2536 else
2522 iommu_flush_write_buffer(iommu); 2537 iommu_flush_write_buffer(iommu);
2523 2538
2524 return start_paddr + ((u64)paddr & (~PAGE_MASK)); 2539 start_paddr = (phys_addr_t)iova->pfn_lo << PAGE_SHIFT;
2540 start_paddr += paddr & ~PAGE_MASK;
2541 return start_paddr;
2525 2542
2526error: 2543error:
2527 if (iova) 2544 if (iova)
@@ -2614,7 +2631,7 @@ static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
2614{ 2631{
2615 struct pci_dev *pdev = to_pci_dev(dev); 2632 struct pci_dev *pdev = to_pci_dev(dev);
2616 struct dmar_domain *domain; 2633 struct dmar_domain *domain;
2617 unsigned long start_addr; 2634 unsigned long start_pfn, last_pfn;
2618 struct iova *iova; 2635 struct iova *iova;
2619 struct intel_iommu *iommu; 2636 struct intel_iommu *iommu;
2620 2637
@@ -2627,22 +2644,25 @@ static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
2627 iommu = domain_get_iommu(domain); 2644 iommu = domain_get_iommu(domain);
2628 2645
2629 iova = find_iova(&domain->iovad, IOVA_PFN(dev_addr)); 2646 iova = find_iova(&domain->iovad, IOVA_PFN(dev_addr));
2630 if (!iova) 2647 if (WARN_ONCE(!iova, "Driver unmaps unmatched page at PFN %llx\n",
2648 (unsigned long long)dev_addr))
2631 return; 2649 return;
2632 2650
2633 start_addr = iova->pfn_lo << PAGE_SHIFT; 2651 start_pfn = mm_to_dma_pfn(iova->pfn_lo);
2634 size = aligned_size((u64)dev_addr, size); 2652 last_pfn = mm_to_dma_pfn(iova->pfn_hi + 1) - 1;
2635 2653
2636 pr_debug("Device %s unmapping: %zx@%llx\n", 2654 pr_debug("Device %s unmapping: pfn %lx-%lx\n",
2637 pci_name(pdev), size, (unsigned long long)start_addr); 2655 pci_name(pdev), start_pfn, last_pfn);
2638 2656
2639 /* clear the whole page */ 2657 /* clear the whole page */
2640 dma_pte_clear_range(domain, start_addr, start_addr + size); 2658 dma_pte_clear_range(domain, start_pfn, last_pfn);
2659
2641 /* free page tables */ 2660 /* free page tables */
2642 dma_pte_free_pagetable(domain, start_addr, start_addr + size); 2661 dma_pte_free_pagetable(domain, start_pfn, last_pfn);
2662
2643 if (intel_iommu_strict) { 2663 if (intel_iommu_strict) {
2644 iommu_flush_iotlb_psi(iommu, domain->id, start_addr, 2664 iommu_flush_iotlb_psi(iommu, domain->id, start_pfn,
2645 size >> VTD_PAGE_SHIFT); 2665 last_pfn - start_pfn + 1);
2646 /* free iova */ 2666 /* free iova */
2647 __free_iova(&domain->iovad, iova); 2667 __free_iova(&domain->iovad, iova);
2648 } else { 2668 } else {
@@ -2700,14 +2720,10 @@ static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
2700 int nelems, enum dma_data_direction dir, 2720 int nelems, enum dma_data_direction dir,
2701 struct dma_attrs *attrs) 2721 struct dma_attrs *attrs)
2702{ 2722{
2703 int i;
2704 struct pci_dev *pdev = to_pci_dev(hwdev); 2723 struct pci_dev *pdev = to_pci_dev(hwdev);
2705 struct dmar_domain *domain; 2724 struct dmar_domain *domain;
2706 unsigned long start_addr; 2725 unsigned long start_pfn, last_pfn;
2707 struct iova *iova; 2726 struct iova *iova;
2708 size_t size = 0;
2709 phys_addr_t addr;
2710 struct scatterlist *sg;
2711 struct intel_iommu *iommu; 2727 struct intel_iommu *iommu;
2712 2728
2713 if (iommu_no_mapping(pdev)) 2729 if (iommu_no_mapping(pdev))
@@ -2719,22 +2735,21 @@ static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
2719 iommu = domain_get_iommu(domain); 2735 iommu = domain_get_iommu(domain);
2720 2736
2721 iova = find_iova(&domain->iovad, IOVA_PFN(sglist[0].dma_address)); 2737 iova = find_iova(&domain->iovad, IOVA_PFN(sglist[0].dma_address));
2722 if (!iova) 2738 if (WARN_ONCE(!iova, "Driver unmaps unmatched sglist at PFN %llx\n",
2739 (unsigned long long)sglist[0].dma_address))
2723 return; 2740 return;
2724 for_each_sg(sglist, sg, nelems, i) {
2725 addr = page_to_phys(sg_page(sg)) + sg->offset;
2726 size += aligned_size((u64)addr, sg->length);
2727 }
2728 2741
2729 start_addr = iova->pfn_lo << PAGE_SHIFT; 2742 start_pfn = mm_to_dma_pfn(iova->pfn_lo);
2743 last_pfn = mm_to_dma_pfn(iova->pfn_hi + 1) - 1;
2730 2744
2731 /* clear the whole page */ 2745 /* clear the whole page */
2732 dma_pte_clear_range(domain, start_addr, start_addr + size); 2746 dma_pte_clear_range(domain, start_pfn, last_pfn);
2747
2733 /* free page tables */ 2748 /* free page tables */
2734 dma_pte_free_pagetable(domain, start_addr, start_addr + size); 2749 dma_pte_free_pagetable(domain, start_pfn, last_pfn);
2735 2750
2736 iommu_flush_iotlb_psi(iommu, domain->id, start_addr, 2751 iommu_flush_iotlb_psi(iommu, domain->id, start_pfn,
2737 size >> VTD_PAGE_SHIFT); 2752 (last_pfn - start_pfn + 1));
2738 2753
2739 /* free iova */ 2754 /* free iova */
2740 __free_iova(&domain->iovad, iova); 2755 __free_iova(&domain->iovad, iova);
@@ -2757,17 +2772,16 @@ static int intel_nontranslate_map_sg(struct device *hddev,
2757static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, 2772static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
2758 enum dma_data_direction dir, struct dma_attrs *attrs) 2773 enum dma_data_direction dir, struct dma_attrs *attrs)
2759{ 2774{
2760 phys_addr_t addr;
2761 int i; 2775 int i;
2762 struct pci_dev *pdev = to_pci_dev(hwdev); 2776 struct pci_dev *pdev = to_pci_dev(hwdev);
2763 struct dmar_domain *domain; 2777 struct dmar_domain *domain;
2764 size_t size = 0; 2778 size_t size = 0;
2765 int prot = 0; 2779 int prot = 0;
2766 size_t offset = 0; 2780 size_t offset_pfn = 0;
2767 struct iova *iova = NULL; 2781 struct iova *iova = NULL;
2768 int ret; 2782 int ret;
2769 struct scatterlist *sg; 2783 struct scatterlist *sg;
2770 unsigned long start_addr; 2784 unsigned long start_vpfn;
2771 struct intel_iommu *iommu; 2785 struct intel_iommu *iommu;
2772 2786
2773 BUG_ON(dir == DMA_NONE); 2787 BUG_ON(dir == DMA_NONE);
@@ -2780,12 +2794,10 @@ static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int ne
2780 2794
2781 iommu = domain_get_iommu(domain); 2795 iommu = domain_get_iommu(domain);
2782 2796
2783 for_each_sg(sglist, sg, nelems, i) { 2797 for_each_sg(sglist, sg, nelems, i)
2784 addr = page_to_phys(sg_page(sg)) + sg->offset; 2798 size += aligned_nrpages(sg->offset, sg->length);
2785 size += aligned_size((u64)addr, sg->length);
2786 }
2787 2799
2788 iova = __intel_alloc_iova(hwdev, domain, size, pdev->dma_mask); 2800 iova = intel_alloc_iova(hwdev, domain, size, pdev->dma_mask);
2789 if (!iova) { 2801 if (!iova) {
2790 sglist->dma_length = 0; 2802 sglist->dma_length = 0;
2791 return 0; 2803 return 0;
@@ -2801,35 +2813,24 @@ static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int ne
2801 if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL) 2813 if (dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL)
2802 prot |= DMA_PTE_WRITE; 2814 prot |= DMA_PTE_WRITE;
2803 2815
2804 start_addr = iova->pfn_lo << PAGE_SHIFT; 2816 start_vpfn = mm_to_dma_pfn(iova->pfn_lo);
2805 offset = 0; 2817
2806 for_each_sg(sglist, sg, nelems, i) { 2818 ret = domain_sg_mapping(domain, start_vpfn, sglist, mm_to_dma_pfn(size), prot);
2807 addr = page_to_phys(sg_page(sg)) + sg->offset; 2819 if (unlikely(ret)) {
2808 size = aligned_size((u64)addr, sg->length); 2820 /* clear the page */
2809 ret = domain_page_mapping(domain, start_addr + offset, 2821 dma_pte_clear_range(domain, start_vpfn,
2810 ((u64)addr) & PHYSICAL_PAGE_MASK, 2822 start_vpfn + size - 1);
2811 size, prot); 2823 /* free page tables */
2812 if (ret) { 2824 dma_pte_free_pagetable(domain, start_vpfn,
2813 /* clear the page */ 2825 start_vpfn + size - 1);
2814 dma_pte_clear_range(domain, start_addr, 2826 /* free iova */
2815 start_addr + offset); 2827 __free_iova(&domain->iovad, iova);
2816 /* free page tables */ 2828 return 0;
2817 dma_pte_free_pagetable(domain, start_addr,
2818 start_addr + offset);
2819 /* free iova */
2820 __free_iova(&domain->iovad, iova);
2821 return 0;
2822 }
2823 sg->dma_address = start_addr + offset +
2824 ((u64)addr & (~PAGE_MASK));
2825 sg->dma_length = sg->length;
2826 offset += size;
2827 } 2829 }
2828 2830
2829 /* it's a non-present to present mapping. Only flush if caching mode */ 2831 /* it's a non-present to present mapping. Only flush if caching mode */
2830 if (cap_caching_mode(iommu->cap)) 2832 if (cap_caching_mode(iommu->cap))
2831 iommu_flush_iotlb_psi(iommu, 0, start_addr, 2833 iommu_flush_iotlb_psi(iommu, 0, start_vpfn, offset_pfn);
2832 offset >> VTD_PAGE_SHIFT);
2833 else 2834 else
2834 iommu_flush_write_buffer(iommu); 2835 iommu_flush_write_buffer(iommu);
2835 2836
@@ -3334,7 +3335,6 @@ static int md_domain_init(struct dmar_domain *domain, int guest_width)
3334 int adjust_width; 3335 int adjust_width;
3335 3336
3336 init_iova_domain(&domain->iovad, DMA_32BIT_PFN); 3337 init_iova_domain(&domain->iovad, DMA_32BIT_PFN);
3337 spin_lock_init(&domain->mapping_lock);
3338 spin_lock_init(&domain->iommu_lock); 3338 spin_lock_init(&domain->iommu_lock);
3339 3339
3340 domain_reserve_special_ranges(domain); 3340 domain_reserve_special_ranges(domain);
@@ -3388,8 +3388,6 @@ static void iommu_free_vm_domain(struct dmar_domain *domain)
3388 3388
3389static void vm_domain_exit(struct dmar_domain *domain) 3389static void vm_domain_exit(struct dmar_domain *domain)
3390{ 3390{
3391 u64 end;
3392
3393 /* Domain 0 is reserved, so dont process it */ 3391 /* Domain 0 is reserved, so dont process it */
3394 if (!domain) 3392 if (!domain)
3395 return; 3393 return;
@@ -3397,14 +3395,12 @@ static void vm_domain_exit(struct dmar_domain *domain)
3397 vm_domain_remove_all_dev_info(domain); 3395 vm_domain_remove_all_dev_info(domain);
3398 /* destroy iovas */ 3396 /* destroy iovas */
3399 put_iova_domain(&domain->iovad); 3397 put_iova_domain(&domain->iovad);
3400 end = DOMAIN_MAX_ADDR(domain->gaw);
3401 end = end & (~VTD_PAGE_MASK);
3402 3398
3403 /* clear ptes */ 3399 /* clear ptes */
3404 dma_pte_clear_range(domain, 0, end); 3400 dma_pte_clear_range(domain, 0, DOMAIN_MAX_PFN(domain->gaw));
3405 3401
3406 /* free page tables */ 3402 /* free page tables */
3407 dma_pte_free_pagetable(domain, 0, end); 3403 dma_pte_free_pagetable(domain, 0, DOMAIN_MAX_PFN(domain->gaw));
3408 3404
3409 iommu_free_vm_domain(domain); 3405 iommu_free_vm_domain(domain);
3410 free_domain_mem(domain); 3406 free_domain_mem(domain);
@@ -3513,7 +3509,7 @@ static int intel_iommu_map_range(struct iommu_domain *domain,
3513 if ((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping) 3509 if ((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping)
3514 prot |= DMA_PTE_SNP; 3510 prot |= DMA_PTE_SNP;
3515 3511
3516 max_addr = (iova & VTD_PAGE_MASK) + VTD_PAGE_ALIGN(size); 3512 max_addr = iova + size;
3517 if (dmar_domain->max_addr < max_addr) { 3513 if (dmar_domain->max_addr < max_addr) {
3518 int min_agaw; 3514 int min_agaw;
3519 u64 end; 3515 u64 end;
@@ -3531,8 +3527,11 @@ static int intel_iommu_map_range(struct iommu_domain *domain,
3531 } 3527 }
3532 dmar_domain->max_addr = max_addr; 3528 dmar_domain->max_addr = max_addr;
3533 } 3529 }
3534 3530 /* Round up size to next multiple of PAGE_SIZE, if it and
3535 ret = domain_page_mapping(dmar_domain, iova, hpa, size, prot); 3531 the low bits of hpa would take us onto the next page */
3532 size = aligned_nrpages(hpa, size);
3533 ret = domain_pfn_mapping(dmar_domain, iova >> VTD_PAGE_SHIFT,
3534 hpa >> VTD_PAGE_SHIFT, size, prot);
3536 return ret; 3535 return ret;
3537} 3536}
3538 3537
@@ -3540,15 +3539,12 @@ static void intel_iommu_unmap_range(struct iommu_domain *domain,
3540 unsigned long iova, size_t size) 3539 unsigned long iova, size_t size)
3541{ 3540{
3542 struct dmar_domain *dmar_domain = domain->priv; 3541 struct dmar_domain *dmar_domain = domain->priv;
3543 dma_addr_t base;
3544 3542
3545 /* The address might not be aligned */ 3543 dma_pte_clear_range(dmar_domain, iova >> VTD_PAGE_SHIFT,
3546 base = iova & VTD_PAGE_MASK; 3544 (iova + size - 1) >> VTD_PAGE_SHIFT);
3547 size = VTD_PAGE_ALIGN(size);
3548 dma_pte_clear_range(dmar_domain, base, base + size);
3549 3545
3550 if (dmar_domain->max_addr == base + size) 3546 if (dmar_domain->max_addr == iova + size)
3551 dmar_domain->max_addr = base; 3547 dmar_domain->max_addr = iova;
3552} 3548}
3553 3549
3554static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain, 3550static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain,
@@ -3558,7 +3554,7 @@ static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain,
3558 struct dma_pte *pte; 3554 struct dma_pte *pte;
3559 u64 phys = 0; 3555 u64 phys = 0;
3560 3556
3561 pte = addr_to_dma_pte(dmar_domain, iova); 3557 pte = pfn_to_dma_pte(dmar_domain, iova >> VTD_PAGE_SHIFT);
3562 if (pte) 3558 if (pte)
3563 phys = dma_pte_addr(pte); 3559 phys = dma_pte_addr(pte);
3564 3560
diff --git a/drivers/pci/iova.c b/drivers/pci/iova.c
index 2287116e9822..46dd440e2315 100644
--- a/drivers/pci/iova.c
+++ b/drivers/pci/iova.c
@@ -1,9 +1,19 @@
1/* 1/*
2 * Copyright (c) 2006, Intel Corporation. 2 * Copyright © 2006-2009, Intel Corporation.
3 * 3 *
4 * This file is released under the GPLv2. 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
5 * 16 *
6 * Copyright (C) 2006-2008 Intel Corporation
7 * Author: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> 17 * Author: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 */ 18 */
9 19
@@ -123,7 +133,15 @@ move_left:
123 /* Insert the new_iova into domain rbtree by holding writer lock */ 133 /* Insert the new_iova into domain rbtree by holding writer lock */
124 /* Add new node and rebalance tree. */ 134 /* Add new node and rebalance tree. */
125 { 135 {
126 struct rb_node **entry = &((prev)), *parent = NULL; 136 struct rb_node **entry, *parent = NULL;
137
138 /* If we have 'prev', it's a valid place to start the
139 insertion. Otherwise, start from the root. */
140 if (prev)
141 entry = &prev;
142 else
143 entry = &iovad->rbroot.rb_node;
144
127 /* Figure out where to put new node */ 145 /* Figure out where to put new node */
128 while (*entry) { 146 while (*entry) {
129 struct iova *this = container_of(*entry, 147 struct iova *this = container_of(*entry,
diff --git a/drivers/pcmcia/vrc4171_card.c b/drivers/pcmcia/vrc4171_card.c
index 659421d0ca46..d4ad50d737b0 100644
--- a/drivers/pcmcia/vrc4171_card.c
+++ b/drivers/pcmcia/vrc4171_card.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * vrc4171_card.c, NEC VRC4171 Card Controller driver for Socket Services. 2 * vrc4171_card.c, NEC VRC4171 Card Controller driver for Socket Services.
3 * 3 *
4 * Copyright (C) 2003-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2003-2005 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@
32#include "i82365.h" 32#include "i82365.h"
33 33
34MODULE_DESCRIPTION("NEC VRC4171 Card Controllers driver for Socket Services"); 34MODULE_DESCRIPTION("NEC VRC4171 Card Controllers driver for Socket Services");
35MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); 35MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
36MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
37 37
38#define CARD_MAX_SLOTS 2 38#define CARD_MAX_SLOTS 2
diff --git a/drivers/pcmcia/vrc4173_cardu.c b/drivers/pcmcia/vrc4173_cardu.c
index 812f038e9bda..9b3c15827e5c 100644
--- a/drivers/pcmcia/vrc4173_cardu.c
+++ b/drivers/pcmcia/vrc4173_cardu.c
@@ -6,7 +6,7 @@
6 * NEC VRC4173 CARDU driver for Socket Services 6 * NEC VRC4173 CARDU driver for Socket Services
7 * (This device doesn't support CardBus. it is supporting only 16bit PC Card.) 7 * (This device doesn't support CardBus. it is supporting only 16bit PC Card.)
8 * 8 *
9 * Copyright 2002,2003 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 9 * Copyright 2002,2003 Yoichi Yuasa <yuasa@linux-mips.org>
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify it 11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the 12 * under the terms of the GNU General Public License as published by the
@@ -41,7 +41,7 @@
41#include "vrc4173_cardu.h" 41#include "vrc4173_cardu.h"
42 42
43MODULE_DESCRIPTION("NEC VRC4173 CARDU driver for Socket Services"); 43MODULE_DESCRIPTION("NEC VRC4173 CARDU driver for Socket Services");
44MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); 44MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
45MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
46 46
47static int vrc4173_cardu_slots; 47static int vrc4173_cardu_slots;
diff --git a/drivers/pcmcia/vrc4173_cardu.h b/drivers/pcmcia/vrc4173_cardu.h
index 7d77c74120c1..a7d96018ed8d 100644
--- a/drivers/pcmcia/vrc4173_cardu.h
+++ b/drivers/pcmcia/vrc4173_cardu.h
@@ -5,7 +5,7 @@
5 * BRIEF MODULE DESCRIPTION 5 * BRIEF MODULE DESCRIPTION
6 * Include file for NEC VRC4173 CARDU. 6 * Include file for NEC VRC4173 CARDU.
7 * 7 *
8 * Copyright 2002 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 8 * Copyright 2002 Yoichi Yuasa <yuasa@linux-mips.org>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the 11 * under the terms of the GNU General Public License as published by the
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 7232fe7104aa..46dad12f952f 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -355,6 +355,7 @@ config EEEPC_LAPTOP
355 depends on INPUT 355 depends on INPUT
356 depends on EXPERIMENTAL 356 depends on EXPERIMENTAL
357 depends on RFKILL || RFKILL = n 357 depends on RFKILL || RFKILL = n
358 depends on HOTPLUG_PCI
358 select BACKLIGHT_CLASS_DEVICE 359 select BACKLIGHT_CLASS_DEVICE
359 select HWMON 360 select HWMON
360 ---help--- 361 ---help---
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index 4207b26ff990..ec560f16d720 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -16,6 +16,8 @@
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 */ 17 */
18 18
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
19#include <linux/kernel.h> 21#include <linux/kernel.h>
20#include <linux/module.h> 22#include <linux/module.h>
21#include <linux/init.h> 23#include <linux/init.h>
@@ -31,6 +33,7 @@
31#include <linux/input.h> 33#include <linux/input.h>
32#include <linux/rfkill.h> 34#include <linux/rfkill.h>
33#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/pci_hotplug.h>
34 37
35#define EEEPC_LAPTOP_VERSION "0.1" 38#define EEEPC_LAPTOP_VERSION "0.1"
36 39
@@ -40,11 +43,6 @@
40#define EEEPC_HOTK_DEVICE_NAME "Hotkey" 43#define EEEPC_HOTK_DEVICE_NAME "Hotkey"
41#define EEEPC_HOTK_HID "ASUS010" 44#define EEEPC_HOTK_HID "ASUS010"
42 45
43#define EEEPC_LOG EEEPC_HOTK_FILE ": "
44#define EEEPC_ERR KERN_ERR EEEPC_LOG
45#define EEEPC_WARNING KERN_WARNING EEEPC_LOG
46#define EEEPC_NOTICE KERN_NOTICE EEEPC_LOG
47#define EEEPC_INFO KERN_INFO EEEPC_LOG
48 46
49/* 47/*
50 * Definitions for Asus EeePC 48 * Definitions for Asus EeePC
@@ -141,8 +139,10 @@ struct eeepc_hotk {
141 u16 event_count[128]; /* count for each event */ 139 u16 event_count[128]; /* count for each event */
142 struct input_dev *inputdev; 140 struct input_dev *inputdev;
143 u16 *keycode_map; 141 u16 *keycode_map;
144 struct rfkill *eeepc_wlan_rfkill; 142 struct rfkill *wlan_rfkill;
145 struct rfkill *eeepc_bluetooth_rfkill; 143 struct rfkill *bluetooth_rfkill;
144 struct rfkill *wwan3g_rfkill;
145 struct hotplug_slot *hotplug_slot;
146}; 146};
147 147
148/* The actual device the driver binds to */ 148/* The actual device the driver binds to */
@@ -213,6 +213,15 @@ static struct acpi_driver eeepc_hotk_driver = {
213 }, 213 },
214}; 214};
215 215
216/* PCI hotplug ops */
217static int eeepc_get_adapter_status(struct hotplug_slot *slot, u8 *value);
218
219static struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
220 .owner = THIS_MODULE,
221 .get_adapter_status = eeepc_get_adapter_status,
222 .get_power_status = eeepc_get_adapter_status,
223};
224
216/* The backlight device /sys/class/backlight */ 225/* The backlight device /sys/class/backlight */
217static struct backlight_device *eeepc_backlight_device; 226static struct backlight_device *eeepc_backlight_device;
218 227
@@ -274,20 +283,20 @@ static int set_acpi(int cm, int value)
274 if (method == NULL) 283 if (method == NULL)
275 return -ENODEV; 284 return -ENODEV;
276 if (write_acpi_int(ehotk->handle, method, value, NULL)) 285 if (write_acpi_int(ehotk->handle, method, value, NULL))
277 printk(EEEPC_WARNING "Error writing %s\n", method); 286 pr_warning("Error writing %s\n", method);
278 } 287 }
279 return 0; 288 return 0;
280} 289}
281 290
282static int get_acpi(int cm) 291static int get_acpi(int cm)
283{ 292{
284 int value = -1; 293 int value = -ENODEV;
285 if ((ehotk->cm_supported & (0x1 << cm))) { 294 if ((ehotk->cm_supported & (0x1 << cm))) {
286 const char *method = cm_getv[cm]; 295 const char *method = cm_getv[cm];
287 if (method == NULL) 296 if (method == NULL)
288 return -ENODEV; 297 return -ENODEV;
289 if (read_acpi_int(ehotk->handle, method, &value)) 298 if (read_acpi_int(ehotk->handle, method, &value))
290 printk(EEEPC_WARNING "Error reading %s\n", method); 299 pr_warning("Error reading %s\n", method);
291 } 300 }
292 return value; 301 return value;
293} 302}
@@ -359,13 +368,19 @@ static ssize_t store_sys_acpi(int cm, const char *buf, size_t count)
359 368
360 rv = parse_arg(buf, count, &value); 369 rv = parse_arg(buf, count, &value);
361 if (rv > 0) 370 if (rv > 0)
362 set_acpi(cm, value); 371 value = set_acpi(cm, value);
372 if (value < 0)
373 return value;
363 return rv; 374 return rv;
364} 375}
365 376
366static ssize_t show_sys_acpi(int cm, char *buf) 377static ssize_t show_sys_acpi(int cm, char *buf)
367{ 378{
368 return sprintf(buf, "%d\n", get_acpi(cm)); 379 int value = get_acpi(cm);
380
381 if (value < 0)
382 return value;
383 return sprintf(buf, "%d\n", value);
369} 384}
370 385
371#define EEEPC_CREATE_DEVICE_ATTR(_name, _cm) \ 386#define EEEPC_CREATE_DEVICE_ATTR(_name, _cm) \
@@ -539,6 +554,28 @@ static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode)
539 return -EINVAL; 554 return -EINVAL;
540} 555}
541 556
557static void cmsg_quirk(int cm, const char *name)
558{
559 int dummy;
560
561 /* Some BIOSes do not report cm although it is avaliable.
562 Check if cm_getv[cm] works and, if yes, assume cm should be set. */
563 if (!(ehotk->cm_supported & (1 << cm))
564 && !read_acpi_int(ehotk->handle, cm_getv[cm], &dummy)) {
565 pr_info("%s (%x) not reported by BIOS,"
566 " enabling anyway\n", name, 1 << cm);
567 ehotk->cm_supported |= 1 << cm;
568 }
569}
570
571static void cmsg_quirks(void)
572{
573 cmsg_quirk(CM_ASL_LID, "LID");
574 cmsg_quirk(CM_ASL_TYPE, "TYPE");
575 cmsg_quirk(CM_ASL_PANELPOWER, "PANELPOWER");
576 cmsg_quirk(CM_ASL_TPD, "TPD");
577}
578
542static int eeepc_hotk_check(void) 579static int eeepc_hotk_check(void)
543{ 580{
544 const struct key_entry *key; 581 const struct key_entry *key;
@@ -551,26 +588,24 @@ static int eeepc_hotk_check(void)
551 if (ehotk->device->status.present) { 588 if (ehotk->device->status.present) {
552 if (write_acpi_int(ehotk->handle, "INIT", ehotk->init_flag, 589 if (write_acpi_int(ehotk->handle, "INIT", ehotk->init_flag,
553 &buffer)) { 590 &buffer)) {
554 printk(EEEPC_ERR "Hotkey initialization failed\n"); 591 pr_err("Hotkey initialization failed\n");
555 return -ENODEV; 592 return -ENODEV;
556 } else { 593 } else {
557 printk(EEEPC_NOTICE "Hotkey init flags 0x%x\n", 594 pr_notice("Hotkey init flags 0x%x\n", ehotk->init_flag);
558 ehotk->init_flag);
559 } 595 }
560 /* get control methods supported */ 596 /* get control methods supported */
561 if (read_acpi_int(ehotk->handle, "CMSG" 597 if (read_acpi_int(ehotk->handle, "CMSG"
562 , &ehotk->cm_supported)) { 598 , &ehotk->cm_supported)) {
563 printk(EEEPC_ERR 599 pr_err("Get control methods supported failed\n");
564 "Get control methods supported failed\n");
565 return -ENODEV; 600 return -ENODEV;
566 } else { 601 } else {
567 printk(EEEPC_INFO 602 cmsg_quirks();
568 "Get control methods supported: 0x%x\n", 603 pr_info("Get control methods supported: 0x%x\n",
569 ehotk->cm_supported); 604 ehotk->cm_supported);
570 } 605 }
571 ehotk->inputdev = input_allocate_device(); 606 ehotk->inputdev = input_allocate_device();
572 if (!ehotk->inputdev) { 607 if (!ehotk->inputdev) {
573 printk(EEEPC_INFO "Unable to allocate input device\n"); 608 pr_info("Unable to allocate input device\n");
574 return 0; 609 return 0;
575 } 610 }
576 ehotk->inputdev->name = "Asus EeePC extra buttons"; 611 ehotk->inputdev->name = "Asus EeePC extra buttons";
@@ -589,12 +624,12 @@ static int eeepc_hotk_check(void)
589 } 624 }
590 result = input_register_device(ehotk->inputdev); 625 result = input_register_device(ehotk->inputdev);
591 if (result) { 626 if (result) {
592 printk(EEEPC_INFO "Unable to register input device\n"); 627 pr_info("Unable to register input device\n");
593 input_free_device(ehotk->inputdev); 628 input_free_device(ehotk->inputdev);
594 return 0; 629 return 0;
595 } 630 }
596 } else { 631 } else {
597 printk(EEEPC_ERR "Hotkey device not present, aborting\n"); 632 pr_err("Hotkey device not present, aborting\n");
598 return -EINVAL; 633 return -EINVAL;
599 } 634 }
600 return 0; 635 return 0;
@@ -612,6 +647,19 @@ static int notify_brn(void)
612 return -1; 647 return -1;
613} 648}
614 649
650static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
651 u8 *value)
652{
653 int val = get_acpi(CM_ASL_WLAN);
654
655 if (val == 1 || val == 0)
656 *value = val;
657 else
658 return -EINVAL;
659
660 return 0;
661}
662
615static void eeepc_rfkill_hotplug(void) 663static void eeepc_rfkill_hotplug(void)
616{ 664{
617 struct pci_dev *dev; 665 struct pci_dev *dev;
@@ -619,7 +667,7 @@ static void eeepc_rfkill_hotplug(void)
619 bool blocked; 667 bool blocked;
620 668
621 if (!bus) { 669 if (!bus) {
622 printk(EEEPC_WARNING "Unable to find PCI bus 1?\n"); 670 pr_warning("Unable to find PCI bus 1?\n");
623 return; 671 return;
624 } 672 }
625 673
@@ -635,7 +683,7 @@ static void eeepc_rfkill_hotplug(void)
635 if (dev) { 683 if (dev) {
636 pci_bus_assign_resources(bus); 684 pci_bus_assign_resources(bus);
637 if (pci_bus_add_device(dev)) 685 if (pci_bus_add_device(dev))
638 printk(EEEPC_ERR "Unable to hotplug wifi\n"); 686 pr_err("Unable to hotplug wifi\n");
639 } 687 }
640 } else { 688 } else {
641 dev = pci_get_slot(bus, 0); 689 dev = pci_get_slot(bus, 0);
@@ -645,7 +693,7 @@ static void eeepc_rfkill_hotplug(void)
645 } 693 }
646 } 694 }
647 695
648 rfkill_set_sw_state(ehotk->eeepc_wlan_rfkill, blocked); 696 rfkill_set_sw_state(ehotk->wlan_rfkill, blocked);
649} 697}
650 698
651static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data) 699static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
@@ -718,8 +766,7 @@ static int eeepc_register_rfkill_notifier(char *node)
718 eeepc_rfkill_notify, 766 eeepc_rfkill_notify,
719 NULL); 767 NULL);
720 if (ACPI_FAILURE(status)) 768 if (ACPI_FAILURE(status))
721 printk(EEEPC_WARNING 769 pr_warning("Failed to register notify on %s\n", node);
722 "Failed to register notify on %s\n", node);
723 } else 770 } else
724 return -ENODEV; 771 return -ENODEV;
725 772
@@ -738,19 +785,66 @@ static void eeepc_unregister_rfkill_notifier(char *node)
738 ACPI_SYSTEM_NOTIFY, 785 ACPI_SYSTEM_NOTIFY,
739 eeepc_rfkill_notify); 786 eeepc_rfkill_notify);
740 if (ACPI_FAILURE(status)) 787 if (ACPI_FAILURE(status))
741 printk(EEEPC_ERR 788 pr_err("Error removing rfkill notify handler %s\n",
742 "Error removing rfkill notify handler %s\n",
743 node); 789 node);
744 } 790 }
745} 791}
746 792
793static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot)
794{
795 kfree(hotplug_slot->info);
796 kfree(hotplug_slot);
797}
798
799static int eeepc_setup_pci_hotplug(void)
800{
801 int ret = -ENOMEM;
802 struct pci_bus *bus = pci_find_bus(0, 1);
803
804 if (!bus) {
805 pr_err("Unable to find wifi PCI bus\n");
806 return -ENODEV;
807 }
808
809 ehotk->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
810 if (!ehotk->hotplug_slot)
811 goto error_slot;
812
813 ehotk->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
814 GFP_KERNEL);
815 if (!ehotk->hotplug_slot->info)
816 goto error_info;
817
818 ehotk->hotplug_slot->private = ehotk;
819 ehotk->hotplug_slot->release = &eeepc_cleanup_pci_hotplug;
820 ehotk->hotplug_slot->ops = &eeepc_hotplug_slot_ops;
821 eeepc_get_adapter_status(ehotk->hotplug_slot,
822 &ehotk->hotplug_slot->info->adapter_status);
823
824 ret = pci_hp_register(ehotk->hotplug_slot, bus, 0, "eeepc-wifi");
825 if (ret) {
826 pr_err("Unable to register hotplug slot - %d\n", ret);
827 goto error_register;
828 }
829
830 return 0;
831
832error_register:
833 kfree(ehotk->hotplug_slot->info);
834error_info:
835 kfree(ehotk->hotplug_slot);
836 ehotk->hotplug_slot = NULL;
837error_slot:
838 return ret;
839}
840
747static int eeepc_hotk_add(struct acpi_device *device) 841static int eeepc_hotk_add(struct acpi_device *device)
748{ 842{
749 int result; 843 int result;
750 844
751 if (!device) 845 if (!device)
752 return -EINVAL; 846 return -EINVAL;
753 printk(EEEPC_NOTICE EEEPC_HOTK_NAME "\n"); 847 pr_notice(EEEPC_HOTK_NAME "\n");
754 ehotk = kzalloc(sizeof(struct eeepc_hotk), GFP_KERNEL); 848 ehotk = kzalloc(sizeof(struct eeepc_hotk), GFP_KERNEL);
755 if (!ehotk) 849 if (!ehotk)
756 return -ENOMEM; 850 return -ENOMEM;
@@ -764,53 +858,8 @@ static int eeepc_hotk_add(struct acpi_device *device)
764 if (result) 858 if (result)
765 goto ehotk_fail; 859 goto ehotk_fail;
766 860
767 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
768 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
769
770 if (get_acpi(CM_ASL_WLAN) != -1) {
771 ehotk->eeepc_wlan_rfkill = rfkill_alloc("eeepc-wlan",
772 &device->dev,
773 RFKILL_TYPE_WLAN,
774 &eeepc_rfkill_ops,
775 (void *)CM_ASL_WLAN);
776
777 if (!ehotk->eeepc_wlan_rfkill)
778 goto wlan_fail;
779
780 rfkill_init_sw_state(ehotk->eeepc_wlan_rfkill,
781 get_acpi(CM_ASL_WLAN) != 1);
782 result = rfkill_register(ehotk->eeepc_wlan_rfkill);
783 if (result)
784 goto wlan_fail;
785 }
786
787 if (get_acpi(CM_ASL_BLUETOOTH) != -1) {
788 ehotk->eeepc_bluetooth_rfkill =
789 rfkill_alloc("eeepc-bluetooth",
790 &device->dev,
791 RFKILL_TYPE_BLUETOOTH,
792 &eeepc_rfkill_ops,
793 (void *)CM_ASL_BLUETOOTH);
794
795 if (!ehotk->eeepc_bluetooth_rfkill)
796 goto bluetooth_fail;
797
798 rfkill_init_sw_state(ehotk->eeepc_bluetooth_rfkill,
799 get_acpi(CM_ASL_BLUETOOTH) != 1);
800 result = rfkill_register(ehotk->eeepc_bluetooth_rfkill);
801 if (result)
802 goto bluetooth_fail;
803 }
804
805 return 0; 861 return 0;
806 862
807 bluetooth_fail:
808 rfkill_destroy(ehotk->eeepc_bluetooth_rfkill);
809 rfkill_unregister(ehotk->eeepc_wlan_rfkill);
810 wlan_fail:
811 rfkill_destroy(ehotk->eeepc_wlan_rfkill);
812 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
813 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
814 ehotk_fail: 863 ehotk_fail:
815 kfree(ehotk); 864 kfree(ehotk);
816 ehotk = NULL; 865 ehotk = NULL;
@@ -823,16 +872,13 @@ static int eeepc_hotk_remove(struct acpi_device *device, int type)
823 if (!device || !acpi_driver_data(device)) 872 if (!device || !acpi_driver_data(device))
824 return -EINVAL; 873 return -EINVAL;
825 874
826 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
827 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
828
829 kfree(ehotk); 875 kfree(ehotk);
830 return 0; 876 return 0;
831} 877}
832 878
833static int eeepc_hotk_resume(struct acpi_device *device) 879static int eeepc_hotk_resume(struct acpi_device *device)
834{ 880{
835 if (ehotk->eeepc_wlan_rfkill) { 881 if (ehotk->wlan_rfkill) {
836 bool wlan; 882 bool wlan;
837 883
838 /* Workaround - it seems that _PTS disables the wireless 884 /* Workaround - it seems that _PTS disables the wireless
@@ -844,14 +890,13 @@ static int eeepc_hotk_resume(struct acpi_device *device)
844 wlan = get_acpi(CM_ASL_WLAN); 890 wlan = get_acpi(CM_ASL_WLAN);
845 set_acpi(CM_ASL_WLAN, wlan); 891 set_acpi(CM_ASL_WLAN, wlan);
846 892
847 rfkill_set_sw_state(ehotk->eeepc_wlan_rfkill, 893 rfkill_set_sw_state(ehotk->wlan_rfkill, wlan != 1);
848 wlan != 1);
849 894
850 eeepc_rfkill_hotplug(); 895 eeepc_rfkill_hotplug();
851 } 896 }
852 897
853 if (ehotk->eeepc_bluetooth_rfkill) 898 if (ehotk->bluetooth_rfkill)
854 rfkill_set_sw_state(ehotk->eeepc_bluetooth_rfkill, 899 rfkill_set_sw_state(ehotk->bluetooth_rfkill,
855 get_acpi(CM_ASL_BLUETOOTH) != 1); 900 get_acpi(CM_ASL_BLUETOOTH) != 1);
856 901
857 return 0; 902 return 0;
@@ -973,10 +1018,16 @@ static void eeepc_backlight_exit(void)
973 1018
974static void eeepc_rfkill_exit(void) 1019static void eeepc_rfkill_exit(void)
975{ 1020{
976 if (ehotk->eeepc_wlan_rfkill) 1021 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
977 rfkill_unregister(ehotk->eeepc_wlan_rfkill); 1022 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
978 if (ehotk->eeepc_bluetooth_rfkill) 1023 if (ehotk->wlan_rfkill)
979 rfkill_unregister(ehotk->eeepc_bluetooth_rfkill); 1024 rfkill_unregister(ehotk->wlan_rfkill);
1025 if (ehotk->bluetooth_rfkill)
1026 rfkill_unregister(ehotk->bluetooth_rfkill);
1027 if (ehotk->wwan3g_rfkill)
1028 rfkill_unregister(ehotk->wwan3g_rfkill);
1029 if (ehotk->hotplug_slot)
1030 pci_hp_deregister(ehotk->hotplug_slot);
980} 1031}
981 1032
982static void eeepc_input_exit(void) 1033static void eeepc_input_exit(void)
@@ -1011,6 +1062,75 @@ static void __exit eeepc_laptop_exit(void)
1011 platform_driver_unregister(&platform_driver); 1062 platform_driver_unregister(&platform_driver);
1012} 1063}
1013 1064
1065static int eeepc_new_rfkill(struct rfkill **rfkill,
1066 const char *name, struct device *dev,
1067 enum rfkill_type type, int cm)
1068{
1069 int result;
1070
1071 result = get_acpi(cm);
1072 if (result < 0)
1073 return result;
1074
1075 *rfkill = rfkill_alloc(name, dev, type,
1076 &eeepc_rfkill_ops, (void *)(unsigned long)cm);
1077
1078 if (!*rfkill)
1079 return -EINVAL;
1080
1081 rfkill_init_sw_state(*rfkill, get_acpi(cm) != 1);
1082 result = rfkill_register(*rfkill);
1083 if (result) {
1084 rfkill_destroy(*rfkill);
1085 *rfkill = NULL;
1086 return result;
1087 }
1088 return 0;
1089}
1090
1091
1092static int eeepc_rfkill_init(struct device *dev)
1093{
1094 int result = 0;
1095
1096 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
1097 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
1098
1099 result = eeepc_new_rfkill(&ehotk->wlan_rfkill,
1100 "eeepc-wlan", dev,
1101 RFKILL_TYPE_WLAN, CM_ASL_WLAN);
1102
1103 if (result && result != -ENODEV)
1104 goto exit;
1105
1106 result = eeepc_new_rfkill(&ehotk->bluetooth_rfkill,
1107 "eeepc-bluetooth", dev,
1108 RFKILL_TYPE_BLUETOOTH, CM_ASL_BLUETOOTH);
1109
1110 if (result && result != -ENODEV)
1111 goto exit;
1112
1113 result = eeepc_new_rfkill(&ehotk->wwan3g_rfkill,
1114 "eeepc-wwan3g", dev,
1115 RFKILL_TYPE_WWAN, CM_ASL_3G);
1116
1117 if (result && result != -ENODEV)
1118 goto exit;
1119
1120 result = eeepc_setup_pci_hotplug();
1121 /*
1122 * If we get -EBUSY then something else is handling the PCI hotplug -
1123 * don't fail in this case
1124 */
1125 if (result == -EBUSY)
1126 result = 0;
1127
1128exit:
1129 if (result && result != -ENODEV)
1130 eeepc_rfkill_exit();
1131 return result;
1132}
1133
1014static int eeepc_backlight_init(struct device *dev) 1134static int eeepc_backlight_init(struct device *dev)
1015{ 1135{
1016 struct backlight_device *bd; 1136 struct backlight_device *bd;
@@ -1018,8 +1138,7 @@ static int eeepc_backlight_init(struct device *dev)
1018 bd = backlight_device_register(EEEPC_HOTK_FILE, dev, 1138 bd = backlight_device_register(EEEPC_HOTK_FILE, dev,
1019 NULL, &eeepcbl_ops); 1139 NULL, &eeepcbl_ops);
1020 if (IS_ERR(bd)) { 1140 if (IS_ERR(bd)) {
1021 printk(EEEPC_ERR 1141 pr_err("Could not register eeepc backlight device\n");
1022 "Could not register eeepc backlight device\n");
1023 eeepc_backlight_device = NULL; 1142 eeepc_backlight_device = NULL;
1024 return PTR_ERR(bd); 1143 return PTR_ERR(bd);
1025 } 1144 }
@@ -1038,8 +1157,7 @@ static int eeepc_hwmon_init(struct device *dev)
1038 1157
1039 hwmon = hwmon_device_register(dev); 1158 hwmon = hwmon_device_register(dev);
1040 if (IS_ERR(hwmon)) { 1159 if (IS_ERR(hwmon)) {
1041 printk(EEEPC_ERR 1160 pr_err("Could not register eeepc hwmon device\n");
1042 "Could not register eeepc hwmon device\n");
1043 eeepc_hwmon_device = NULL; 1161 eeepc_hwmon_device = NULL;
1044 return PTR_ERR(hwmon); 1162 return PTR_ERR(hwmon);
1045 } 1163 }
@@ -1065,19 +1183,6 @@ static int __init eeepc_laptop_init(void)
1065 acpi_bus_unregister_driver(&eeepc_hotk_driver); 1183 acpi_bus_unregister_driver(&eeepc_hotk_driver);
1066 return -ENODEV; 1184 return -ENODEV;
1067 } 1185 }
1068 dev = acpi_get_physical_device(ehotk->device->handle);
1069
1070 if (!acpi_video_backlight_support()) {
1071 result = eeepc_backlight_init(dev);
1072 if (result)
1073 goto fail_backlight;
1074 } else
1075 printk(EEEPC_INFO "Backlight controlled by ACPI video "
1076 "driver\n");
1077
1078 result = eeepc_hwmon_init(dev);
1079 if (result)
1080 goto fail_hwmon;
1081 1186
1082 eeepc_enable_camera(); 1187 eeepc_enable_camera();
1083 1188
@@ -1097,7 +1202,33 @@ static int __init eeepc_laptop_init(void)
1097 &platform_attribute_group); 1202 &platform_attribute_group);
1098 if (result) 1203 if (result)
1099 goto fail_sysfs; 1204 goto fail_sysfs;
1205
1206 dev = &platform_device->dev;
1207
1208 if (!acpi_video_backlight_support()) {
1209 result = eeepc_backlight_init(dev);
1210 if (result)
1211 goto fail_backlight;
1212 } else
1213 pr_info("Backlight controlled by ACPI video "
1214 "driver\n");
1215
1216 result = eeepc_hwmon_init(dev);
1217 if (result)
1218 goto fail_hwmon;
1219
1220 result = eeepc_rfkill_init(dev);
1221 if (result)
1222 goto fail_rfkill;
1223
1100 return 0; 1224 return 0;
1225fail_rfkill:
1226 eeepc_hwmon_exit();
1227fail_hwmon:
1228 eeepc_backlight_exit();
1229fail_backlight:
1230 sysfs_remove_group(&platform_device->dev.kobj,
1231 &platform_attribute_group);
1101fail_sysfs: 1232fail_sysfs:
1102 platform_device_del(platform_device); 1233 platform_device_del(platform_device);
1103fail_platform_device2: 1234fail_platform_device2:
@@ -1105,12 +1236,7 @@ fail_platform_device2:
1105fail_platform_device1: 1236fail_platform_device1:
1106 platform_driver_unregister(&platform_driver); 1237 platform_driver_unregister(&platform_driver);
1107fail_platform_driver: 1238fail_platform_driver:
1108 eeepc_hwmon_exit();
1109fail_hwmon:
1110 eeepc_backlight_exit();
1111fail_backlight:
1112 eeepc_input_exit(); 1239 eeepc_input_exit();
1113 eeepc_rfkill_exit();
1114 return result; 1240 return result;
1115} 1241}
1116 1242
diff --git a/drivers/rtc/rtc-bfin.c b/drivers/rtc/rtc-bfin.c
index aafd3e6ebb0d..a118eb0f1e67 100644
--- a/drivers/rtc/rtc-bfin.c
+++ b/drivers/rtc/rtc-bfin.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * Blackfin On-Chip Real Time Clock Driver 2 * Blackfin On-Chip Real Time Clock Driver
3 * Supports BF52[257]/BF53[123]/BF53[467]/BF54[24789] 3 * Supports BF51x/BF52x/BF53[123]/BF53[467]/BF54x
4 * 4 *
5 * Copyright 2004-2008 Analog Devices Inc. 5 * Copyright 2004-2009 Analog Devices Inc.
6 * 6 *
7 * Enter bugs at http://blackfin.uclinux.org/ 7 * Enter bugs at http://blackfin.uclinux.org/
8 * 8 *
@@ -363,7 +363,7 @@ static int __devinit bfin_rtc_probe(struct platform_device *pdev)
363 struct bfin_rtc *rtc; 363 struct bfin_rtc *rtc;
364 struct device *dev = &pdev->dev; 364 struct device *dev = &pdev->dev;
365 int ret = 0; 365 int ret = 0;
366 unsigned long timeout; 366 unsigned long timeout = jiffies + HZ;
367 367
368 dev_dbg_stamp(dev); 368 dev_dbg_stamp(dev);
369 369
@@ -374,32 +374,32 @@ static int __devinit bfin_rtc_probe(struct platform_device *pdev)
374 platform_set_drvdata(pdev, rtc); 374 platform_set_drvdata(pdev, rtc);
375 device_init_wakeup(dev, 1); 375 device_init_wakeup(dev, 1);
376 376
377 /* Register our RTC with the RTC framework */
378 rtc->rtc_dev = rtc_device_register(pdev->name, dev, &bfin_rtc_ops,
379 THIS_MODULE);
380 if (unlikely(IS_ERR(rtc->rtc_dev))) {
381 ret = PTR_ERR(rtc->rtc_dev);
382 goto err;
383 }
384
377 /* Grab the IRQ and init the hardware */ 385 /* Grab the IRQ and init the hardware */
378 ret = request_irq(IRQ_RTC, bfin_rtc_interrupt, IRQF_SHARED, pdev->name, dev); 386 ret = request_irq(IRQ_RTC, bfin_rtc_interrupt, IRQF_SHARED, pdev->name, dev);
379 if (unlikely(ret)) 387 if (unlikely(ret))
380 goto err; 388 goto err_reg;
381 /* sometimes the bootloader touched things, but the write complete was not 389 /* sometimes the bootloader touched things, but the write complete was not
382 * enabled, so let's just do a quick timeout here since the IRQ will not fire ... 390 * enabled, so let's just do a quick timeout here since the IRQ will not fire ...
383 */ 391 */
384 timeout = jiffies + HZ;
385 while (bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_PENDING) 392 while (bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_PENDING)
386 if (time_after(jiffies, timeout)) 393 if (time_after(jiffies, timeout))
387 break; 394 break;
388 bfin_rtc_reset(dev, RTC_ISTAT_WRITE_COMPLETE); 395 bfin_rtc_reset(dev, RTC_ISTAT_WRITE_COMPLETE);
389 bfin_write_RTC_SWCNT(0); 396 bfin_write_RTC_SWCNT(0);
390 397
391 /* Register our RTC with the RTC framework */
392 rtc->rtc_dev = rtc_device_register(pdev->name, dev, &bfin_rtc_ops, THIS_MODULE);
393 if (unlikely(IS_ERR(rtc->rtc_dev))) {
394 ret = PTR_ERR(rtc->rtc_dev);
395 goto err_irq;
396 }
397
398 return 0; 398 return 0;
399 399
400 err_irq: 400err_reg:
401 free_irq(IRQ_RTC, dev); 401 rtc_device_unregister(rtc->rtc_dev);
402 err: 402err:
403 kfree(rtc); 403 kfree(rtc);
404 return ret; 404 return ret;
405} 405}
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index f11297aff854..2c839d0d21bd 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for NEC VR4100 series Real Time Clock unit. 2 * Driver for NEC VR4100 series Real Time Clock unit.
3 * 3 *
4 * Copyright (C) 2003-2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2003-2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -33,7 +33,7 @@
33#include <asm/io.h> 33#include <asm/io.h>
34#include <asm/uaccess.h> 34#include <asm/uaccess.h>
35 35
36MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); 36MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
37MODULE_DESCRIPTION("NEC VR4100 series RTC driver"); 37MODULE_DESCRIPTION("NEC VR4100 series RTC driver");
38MODULE_LICENSE("GPL v2"); 38MODULE_LICENSE("GPL v2");
39 39
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index f370f8d460a7..c63babefb698 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -350,6 +350,8 @@ claw_tx(struct sk_buff *skb, struct net_device *dev)
350 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc); 350 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
351 if (rc) 351 if (rc)
352 rc = NETDEV_TX_BUSY; 352 rc = NETDEV_TX_BUSY;
353 else
354 rc = NETDEV_TX_OK;
353 return rc; 355 return rc;
354} /* end of claw_tx */ 356} /* end of claw_tx */
355 357
diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
index 222e47394437..38b5079f1599 100644
--- a/drivers/s390/net/ctcm_main.c
+++ b/drivers/s390/net/ctcm_main.c
@@ -880,7 +880,7 @@ static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
880 "%s(%s): NULL sk_buff passed", 880 "%s(%s): NULL sk_buff passed",
881 CTCM_FUNTAIL, dev->name); 881 CTCM_FUNTAIL, dev->name);
882 priv->stats.tx_dropped++; 882 priv->stats.tx_dropped++;
883 return 0; 883 return NETDEV_TX_OK;
884 } 884 }
885 if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) { 885 if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) {
886 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, 886 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
@@ -888,7 +888,7 @@ static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
888 CTCM_FUNTAIL, dev->name, LL_HEADER_LENGTH + 2); 888 CTCM_FUNTAIL, dev->name, LL_HEADER_LENGTH + 2);
889 dev_kfree_skb(skb); 889 dev_kfree_skb(skb);
890 priv->stats.tx_dropped++; 890 priv->stats.tx_dropped++;
891 return 0; 891 return NETDEV_TX_OK;
892 } 892 }
893 893
894 /* 894 /*
@@ -901,7 +901,7 @@ static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
901 priv->stats.tx_dropped++; 901 priv->stats.tx_dropped++;
902 priv->stats.tx_errors++; 902 priv->stats.tx_errors++;
903 priv->stats.tx_carrier_errors++; 903 priv->stats.tx_carrier_errors++;
904 return 0; 904 return NETDEV_TX_OK;
905 } 905 }
906 906
907 if (ctcm_test_and_set_busy(dev)) 907 if (ctcm_test_and_set_busy(dev))
@@ -910,7 +910,7 @@ static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
910 dev->trans_start = jiffies; 910 dev->trans_start = jiffies;
911 if (ctcm_transmit_skb(priv->channel[WRITE], skb) != 0) 911 if (ctcm_transmit_skb(priv->channel[WRITE], skb) != 0)
912 return NETDEV_TX_BUSY; 912 return NETDEV_TX_BUSY;
913 return 0; 913 return NETDEV_TX_OK;
914} 914}
915 915
916/* unmerged MPC variant of ctcm_tx */ 916/* unmerged MPC variant of ctcm_tx */
@@ -1008,7 +1008,7 @@ done:
1008 if (do_debug) 1008 if (do_debug)
1009 MPC_DBF_DEV_NAME(TRACE, dev, "exit"); 1009 MPC_DBF_DEV_NAME(TRACE, dev, "exit");
1010 1010
1011 return 0; /* handle freeing of skb here */ 1011 return NETDEV_TX_OK; /* handle freeing of skb here */
1012} 1012}
1013 1013
1014 1014
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index 8c675905448b..a70de9b4bf29 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -1553,24 +1553,24 @@ __lcs_start_xmit(struct lcs_card *card, struct sk_buff *skb,
1553 struct net_device *dev) 1553 struct net_device *dev)
1554{ 1554{
1555 struct lcs_header *header; 1555 struct lcs_header *header;
1556 int rc = 0; 1556 int rc = NETDEV_TX_OK;
1557 1557
1558 LCS_DBF_TEXT(5, trace, "hardxmit"); 1558 LCS_DBF_TEXT(5, trace, "hardxmit");
1559 if (skb == NULL) { 1559 if (skb == NULL) {
1560 card->stats.tx_dropped++; 1560 card->stats.tx_dropped++;
1561 card->stats.tx_errors++; 1561 card->stats.tx_errors++;
1562 return 0; 1562 return NETDEV_TX_OK;
1563 } 1563 }
1564 if (card->state != DEV_STATE_UP) { 1564 if (card->state != DEV_STATE_UP) {
1565 dev_kfree_skb(skb); 1565 dev_kfree_skb(skb);
1566 card->stats.tx_dropped++; 1566 card->stats.tx_dropped++;
1567 card->stats.tx_errors++; 1567 card->stats.tx_errors++;
1568 card->stats.tx_carrier_errors++; 1568 card->stats.tx_carrier_errors++;
1569 return 0; 1569 return NETDEV_TX_OK;
1570 } 1570 }
1571 if (skb->protocol == htons(ETH_P_IPV6)) { 1571 if (skb->protocol == htons(ETH_P_IPV6)) {
1572 dev_kfree_skb(skb); 1572 dev_kfree_skb(skb);
1573 return 0; 1573 return NETDEV_TX_OK;
1574 } 1574 }
1575 netif_stop_queue(card->dev); 1575 netif_stop_queue(card->dev);
1576 spin_lock(&card->lock); 1576 spin_lock(&card->lock);
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index 8c36eafcfbfe..bb1183a2ed66 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -1376,14 +1376,14 @@ static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
1376 if (skb == NULL) { 1376 if (skb == NULL) {
1377 IUCV_DBF_TEXT(data, 2, "netiucv_tx: skb is NULL\n"); 1377 IUCV_DBF_TEXT(data, 2, "netiucv_tx: skb is NULL\n");
1378 privptr->stats.tx_dropped++; 1378 privptr->stats.tx_dropped++;
1379 return 0; 1379 return NETDEV_TX_OK;
1380 } 1380 }
1381 if (skb_headroom(skb) < NETIUCV_HDRLEN) { 1381 if (skb_headroom(skb) < NETIUCV_HDRLEN) {
1382 IUCV_DBF_TEXT(data, 2, 1382 IUCV_DBF_TEXT(data, 2,
1383 "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n"); 1383 "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n");
1384 dev_kfree_skb(skb); 1384 dev_kfree_skb(skb);
1385 privptr->stats.tx_dropped++; 1385 privptr->stats.tx_dropped++;
1386 return 0; 1386 return NETDEV_TX_OK;
1387 } 1387 }
1388 1388
1389 /** 1389 /**
@@ -1395,7 +1395,7 @@ static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
1395 privptr->stats.tx_dropped++; 1395 privptr->stats.tx_dropped++;
1396 privptr->stats.tx_errors++; 1396 privptr->stats.tx_errors++;
1397 privptr->stats.tx_carrier_errors++; 1397 privptr->stats.tx_carrier_errors++;
1398 return 0; 1398 return NETDEV_TX_OK;
1399 } 1399 }
1400 1400
1401 if (netiucv_test_and_set_busy(dev)) { 1401 if (netiucv_test_and_set_busy(dev)) {
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 691cecd03b83..2cfc338c4625 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -744,6 +744,7 @@ static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
744 card->stats.tx_bytes += tx_bytes; 744 card->stats.tx_bytes += tx_bytes;
745 if (new_skb != skb) 745 if (new_skb != skb)
746 dev_kfree_skb_any(skb); 746 dev_kfree_skb_any(skb);
747 rc = NETDEV_TX_OK;
747 } else { 748 } else {
748 if (data_offset >= 0) 749 if (data_offset >= 0)
749 kmem_cache_free(qeth_core_header_cache, hdr); 750 kmem_cache_free(qeth_core_header_cache, hdr);
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index 54872406864e..048defaea81f 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -2793,6 +2793,7 @@ static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2793 card->perf_stats.sg_frags_sent += nr_frags + 1; 2793 card->perf_stats.sg_frags_sent += nr_frags + 1;
2794 } 2794 }
2795 } 2795 }
2796 rc = NETDEV_TX_OK;
2796 } else { 2797 } else {
2797 if (data_offset >= 0) 2798 if (data_offset >= 0)
2798 kmem_cache_free(qeth_core_header_cache, hdr); 2799 kmem_cache_free(qeth_core_header_cache, hdr);
diff --git a/drivers/scsi/cxgb3i/Kbuild b/drivers/scsi/cxgb3i/Kbuild
index 25a2032bfa26..70d060b7ff4f 100644
--- a/drivers/scsi/cxgb3i/Kbuild
+++ b/drivers/scsi/cxgb3i/Kbuild
@@ -1,4 +1,4 @@
1EXTRA_CFLAGS += -I$(TOPDIR)/drivers/net/cxgb3 1EXTRA_CFLAGS += -I$(srctree)/drivers/net/cxgb3
2 2
3cxgb3i-y := cxgb3i_init.o cxgb3i_iscsi.o cxgb3i_pdu.o cxgb3i_offload.o cxgb3i_ddp.o 3cxgb3i-y := cxgb3i_init.o cxgb3i_iscsi.o cxgb3i_pdu.o cxgb3i_offload.o cxgb3i_ddp.o
4obj-$(CONFIG_SCSI_CXGB3_ISCSI) += cxgb3i.o 4obj-$(CONFIG_SCSI_CXGB3_ISCSI) += cxgb3i.o
diff --git a/drivers/scsi/cxgb3i/cxgb3i_iscsi.c b/drivers/scsi/cxgb3i/cxgb3i_iscsi.c
index 74369a3f963b..c399f485aa7d 100644
--- a/drivers/scsi/cxgb3i/cxgb3i_iscsi.c
+++ b/drivers/scsi/cxgb3i/cxgb3i_iscsi.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/inet.h> 14#include <linux/inet.h>
15#include <linux/crypto.h> 15#include <linux/crypto.h>
16#include <linux/if_vlan.h>
16#include <net/dst.h> 17#include <net/dst.h>
17#include <net/tcp.h> 18#include <net/tcp.h>
18#include <scsi/scsi_cmnd.h> 19#include <scsi/scsi_cmnd.h>
@@ -184,6 +185,9 @@ static struct cxgb3i_hba *cxgb3i_hba_find_by_netdev(struct net_device *ndev)
184 struct cxgb3i_adapter *snic; 185 struct cxgb3i_adapter *snic;
185 int i; 186 int i;
186 187
188 if (ndev->priv_flags & IFF_802_1Q_VLAN)
189 ndev = vlan_dev_real_dev(ndev);
190
187 read_lock(&cxgb3i_snic_rwlock); 191 read_lock(&cxgb3i_snic_rwlock);
188 list_for_each_entry(snic, &cxgb3i_snic_list, list_head) { 192 list_for_each_entry(snic, &cxgb3i_snic_list, list_head) {
189 for (i = 0; i < snic->hba_cnt; i++) { 193 for (i = 0; i < snic->hba_cnt; i++) {
diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c
index a84072865fc2..2c266c01dc5a 100644
--- a/drivers/scsi/fnic/fnic_main.c
+++ b/drivers/scsi/fnic/fnic_main.c
@@ -473,16 +473,16 @@ static int __devinit fnic_probe(struct pci_dev *pdev,
473 * limitation for the device. Try 40-bit first, and 473 * limitation for the device. Try 40-bit first, and
474 * fail to 32-bit. 474 * fail to 32-bit.
475 */ 475 */
476 err = pci_set_dma_mask(pdev, DMA_40BIT_MASK); 476 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40));
477 if (err) { 477 if (err) {
478 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 478 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
479 if (err) { 479 if (err) {
480 shost_printk(KERN_ERR, fnic->lport->host, 480 shost_printk(KERN_ERR, fnic->lport->host,
481 "No usable DMA configuration " 481 "No usable DMA configuration "
482 "aborting\n"); 482 "aborting\n");
483 goto err_out_release_regions; 483 goto err_out_release_regions;
484 } 484 }
485 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 485 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
486 if (err) { 486 if (err) {
487 shost_printk(KERN_ERR, fnic->lport->host, 487 shost_printk(KERN_ERR, fnic->lport->host,
488 "Unable to obtain 32-bit DMA " 488 "Unable to obtain 32-bit DMA "
@@ -490,7 +490,7 @@ static int __devinit fnic_probe(struct pci_dev *pdev,
490 goto err_out_release_regions; 490 goto err_out_release_regions;
491 } 491 }
492 } else { 492 } else {
493 err = pci_set_consistent_dma_mask(pdev, DMA_40BIT_MASK); 493 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40));
494 if (err) { 494 if (err) {
495 shost_printk(KERN_ERR, fnic->lport->host, 495 shost_printk(KERN_ERR, fnic->lport->host,
496 "Unable to obtain 40-bit DMA " 496 "Unable to obtain 40-bit DMA "
diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
index eabf36502856..bfc996971b81 100644
--- a/drivers/scsi/fnic/fnic_scsi.c
+++ b/drivers/scsi/fnic/fnic_scsi.c
@@ -245,7 +245,7 @@ static inline int fnic_queue_wq_copy_desc(struct fnic *fnic,
245 struct vnic_wq_copy *wq, 245 struct vnic_wq_copy *wq,
246 struct fnic_io_req *io_req, 246 struct fnic_io_req *io_req,
247 struct scsi_cmnd *sc, 247 struct scsi_cmnd *sc,
248 u32 sg_count) 248 int sg_count)
249{ 249{
250 struct scatterlist *sg; 250 struct scatterlist *sg;
251 struct fc_rport *rport = starget_to_rport(scsi_target(sc->device)); 251 struct fc_rport *rport = starget_to_rport(scsi_target(sc->device));
@@ -260,9 +260,6 @@ static inline int fnic_queue_wq_copy_desc(struct fnic *fnic,
260 char msg[2]; 260 char msg[2];
261 261
262 if (sg_count) { 262 if (sg_count) {
263 BUG_ON(sg_count < 0);
264 BUG_ON(sg_count > FNIC_MAX_SG_DESC_CNT);
265
266 /* For each SGE, create a device desc entry */ 263 /* For each SGE, create a device desc entry */
267 desc = io_req->sgl_list; 264 desc = io_req->sgl_list;
268 for_each_sg(scsi_sglist(sc), sg, sg_count, i) { 265 for_each_sg(scsi_sglist(sc), sg, sg_count, i) {
@@ -344,7 +341,7 @@ int fnic_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
344 struct fnic *fnic; 341 struct fnic *fnic;
345 struct vnic_wq_copy *wq; 342 struct vnic_wq_copy *wq;
346 int ret; 343 int ret;
347 u32 sg_count; 344 int sg_count;
348 unsigned long flags; 345 unsigned long flags;
349 unsigned long ptr; 346 unsigned long ptr;
350 347
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 869a11bdccbd..9928704e235f 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -1095,9 +1095,14 @@ static void adapter_info_rsp(struct srp_event_struct *evt_struct)
1095 MAX_INDIRECT_BUFS); 1095 MAX_INDIRECT_BUFS);
1096 hostdata->host->sg_tablesize = MAX_INDIRECT_BUFS; 1096 hostdata->host->sg_tablesize = MAX_INDIRECT_BUFS;
1097 } 1097 }
1098
1099 if (hostdata->madapter_info.os_type == 3) {
1100 enable_fast_fail(hostdata);
1101 return;
1102 }
1098 } 1103 }
1099 1104
1100 enable_fast_fail(hostdata); 1105 send_srp_login(hostdata);
1101} 1106}
1102 1107
1103/** 1108/**
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 2eee9e6e4fe8..292c02f810d0 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3670,13 +3670,14 @@ static void
3670fc_bsg_goose_queue(struct fc_rport *rport) 3670fc_bsg_goose_queue(struct fc_rport *rport)
3671{ 3671{
3672 int flagset; 3672 int flagset;
3673 unsigned long flags;
3673 3674
3674 if (!rport->rqst_q) 3675 if (!rport->rqst_q)
3675 return; 3676 return;
3676 3677
3677 get_device(&rport->dev); 3678 get_device(&rport->dev);
3678 3679
3679 spin_lock(rport->rqst_q->queue_lock); 3680 spin_lock_irqsave(rport->rqst_q->queue_lock, flags);
3680 flagset = test_bit(QUEUE_FLAG_REENTER, &rport->rqst_q->queue_flags) && 3681 flagset = test_bit(QUEUE_FLAG_REENTER, &rport->rqst_q->queue_flags) &&
3681 !test_bit(QUEUE_FLAG_REENTER, &rport->rqst_q->queue_flags); 3682 !test_bit(QUEUE_FLAG_REENTER, &rport->rqst_q->queue_flags);
3682 if (flagset) 3683 if (flagset)
@@ -3684,7 +3685,7 @@ fc_bsg_goose_queue(struct fc_rport *rport)
3684 __blk_run_queue(rport->rqst_q); 3685 __blk_run_queue(rport->rqst_q);
3685 if (flagset) 3686 if (flagset)
3686 queue_flag_clear(QUEUE_FLAG_REENTER, rport->rqst_q); 3687 queue_flag_clear(QUEUE_FLAG_REENTER, rport->rqst_q);
3687 spin_unlock(rport->rqst_q->queue_lock); 3688 spin_unlock_irqrestore(rport->rqst_q->queue_lock, flags);
3688 3689
3689 put_device(&rport->dev); 3690 put_device(&rport->dev);
3690} 3691}
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 8201387b4daa..ef142fd47a83 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -210,13 +210,11 @@ static void sg_put_dev(Sg_device *sdp);
210static int sg_allow_access(struct file *filp, unsigned char *cmd) 210static int sg_allow_access(struct file *filp, unsigned char *cmd)
211{ 211{
212 struct sg_fd *sfp = (struct sg_fd *)filp->private_data; 212 struct sg_fd *sfp = (struct sg_fd *)filp->private_data;
213 struct request_queue *q = sfp->parentdp->device->request_queue;
214 213
215 if (sfp->parentdp->device->type == TYPE_SCANNER) 214 if (sfp->parentdp->device->type == TYPE_SCANNER)
216 return 0; 215 return 0;
217 216
218 return blk_verify_command(&q->cmd_filter, 217 return blk_verify_command(cmd, filp->f_mode & FMODE_WRITE);
219 cmd, filp->f_mode & FMODE_WRITE);
220} 218}
221 219
222static int 220static int
diff --git a/drivers/scsi/zalon.c b/drivers/scsi/zalon.c
index 97f3158fa7b5..27e84e4b1fa9 100644
--- a/drivers/scsi/zalon.c
+++ b/drivers/scsi/zalon.c
@@ -134,7 +134,7 @@ zalon_probe(struct parisc_device *dev)
134 134
135 host = ncr_attach(&zalon7xx_template, unit, &device); 135 host = ncr_attach(&zalon7xx_template, unit, &device);
136 if (!host) 136 if (!host)
137 goto fail; 137 return -ENODEV;
138 138
139 if (request_irq(dev->irq, ncr53c8xx_intr, IRQF_SHARED, "zalon", host)) { 139 if (request_irq(dev->irq, ncr53c8xx_intr, IRQF_SHARED, "zalon", host)) {
140 dev_printk(KERN_ERR, &dev->dev, "irq problem with %d, detaching\n ", 140 dev_printk(KERN_ERR, &dev->dev, "irq problem with %d, detaching\n ",
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index a07015d646dd..6160e03f410c 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -759,6 +759,8 @@ static int pci_netmos_init(struct pci_dev *dev)
759 /* subdevice 0x00PS means <P> parallel, <S> serial */ 759 /* subdevice 0x00PS means <P> parallel, <S> serial */
760 unsigned int num_serial = dev->subsystem_device & 0xf; 760 unsigned int num_serial = dev->subsystem_device & 0xf;
761 761
762 if (dev->device == PCI_DEVICE_ID_NETMOS_9901)
763 return 0;
762 if (dev->subsystem_vendor == PCI_VENDOR_ID_IBM && 764 if (dev->subsystem_vendor == PCI_VENDOR_ID_IBM &&
763 dev->subsystem_device == 0x0299) 765 dev->subsystem_device == 0x0299)
764 return 0; 766 return 0;
@@ -3557,6 +3559,10 @@ static struct pci_device_id serial_pci_tbl[] = {
3557 PCI_VENDOR_ID_IBM, 0x0299, 3559 PCI_VENDOR_ID_IBM, 0x0299,
3558 0, 0, pbn_b0_bt_2_115200 }, 3560 0, 0, pbn_b0_bt_2_115200 },
3559 3561
3562 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9901,
3563 0xA000, 0x1000,
3564 0, 0, pbn_b0_1_115200 },
3565
3560 /* 3566 /*
3561 * These entries match devices with class COMMUNICATION_SERIAL, 3567 * These entries match devices with class COMMUNICATION_SERIAL,
3562 * COMMUNICATION_MODEM or COMMUNICATION_MULTISERIAL 3568 * COMMUNICATION_MODEM or COMMUNICATION_MULTISERIAL
diff --git a/drivers/serial/vr41xx_siu.c b/drivers/serial/vr41xx_siu.c
index 0573f3b5175e..dac550e57c29 100644
--- a/drivers/serial/vr41xx_siu.c
+++ b/drivers/serial/vr41xx_siu.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for NEC VR4100 series Serial Interface Unit. 2 * Driver for NEC VR4100 series Serial Interface Unit.
3 * 3 *
4 * Copyright (C) 2004-2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2004-2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * Based on drivers/serial/8250.c, by Russell King. 6 * Based on drivers/serial/8250.c, by Russell King.
7 * 7 *
diff --git a/drivers/spi/omap_uwire.c b/drivers/spi/omap_uwire.c
index aa90ddb37066..8980a5640bd9 100644
--- a/drivers/spi/omap_uwire.c
+++ b/drivers/spi/omap_uwire.c
@@ -514,6 +514,8 @@ static int __init uwire_probe(struct platform_device *pdev)
514 /* the spi->mode bits understood by this driver: */ 514 /* the spi->mode bits understood by this driver: */
515 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 515 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
516 516
517 master->flags = SPI_MASTER_HALF_DUPLEX;
518
517 master->bus_num = 2; /* "official" */ 519 master->bus_num = 2; /* "official" */
518 master->num_chipselect = 4; 520 master->num_chipselect = 4;
519 master->setup = uwire_setup; 521 master->setup = uwire_setup;
diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c
index 2a5abc08e857..f1db395dd889 100644
--- a/drivers/spi/spi_bitbang.c
+++ b/drivers/spi/spi_bitbang.c
@@ -258,6 +258,11 @@ static void bitbang_work(struct work_struct *work)
258 struct spi_bitbang *bitbang = 258 struct spi_bitbang *bitbang =
259 container_of(work, struct spi_bitbang, work); 259 container_of(work, struct spi_bitbang, work);
260 unsigned long flags; 260 unsigned long flags;
261 int do_setup = -1;
262 int (*setup_transfer)(struct spi_device *,
263 struct spi_transfer *);
264
265 setup_transfer = bitbang->setup_transfer;
261 266
262 spin_lock_irqsave(&bitbang->lock, flags); 267 spin_lock_irqsave(&bitbang->lock, flags);
263 bitbang->busy = 1; 268 bitbang->busy = 1;
@@ -269,8 +274,6 @@ static void bitbang_work(struct work_struct *work)
269 unsigned tmp; 274 unsigned tmp;
270 unsigned cs_change; 275 unsigned cs_change;
271 int status; 276 int status;
272 int (*setup_transfer)(struct spi_device *,
273 struct spi_transfer *);
274 277
275 m = container_of(bitbang->queue.next, struct spi_message, 278 m = container_of(bitbang->queue.next, struct spi_message,
276 queue); 279 queue);
@@ -287,19 +290,19 @@ static void bitbang_work(struct work_struct *work)
287 tmp = 0; 290 tmp = 0;
288 cs_change = 1; 291 cs_change = 1;
289 status = 0; 292 status = 0;
290 setup_transfer = NULL;
291 293
292 list_for_each_entry (t, &m->transfers, transfer_list) { 294 list_for_each_entry (t, &m->transfers, transfer_list) {
293 295
294 /* override or restore speed and wordsize */ 296 /* override speed or wordsize? */
295 if (t->speed_hz || t->bits_per_word) { 297 if (t->speed_hz || t->bits_per_word)
296 setup_transfer = bitbang->setup_transfer; 298 do_setup = 1;
299
300 /* init (-1) or override (1) transfer params */
301 if (do_setup != 0) {
297 if (!setup_transfer) { 302 if (!setup_transfer) {
298 status = -ENOPROTOOPT; 303 status = -ENOPROTOOPT;
299 break; 304 break;
300 } 305 }
301 }
302 if (setup_transfer) {
303 status = setup_transfer(spi, t); 306 status = setup_transfer(spi, t);
304 if (status < 0) 307 if (status < 0)
305 break; 308 break;
@@ -363,9 +366,10 @@ static void bitbang_work(struct work_struct *work)
363 m->status = status; 366 m->status = status;
364 m->complete(m->context); 367 m->complete(m->context);
365 368
366 /* restore speed and wordsize */ 369 /* restore speed and wordsize if it was overridden */
367 if (setup_transfer) 370 if (do_setup == 1)
368 setup_transfer(spi, NULL); 371 setup_transfer(spi, NULL);
372 do_setup = 0;
369 373
370 /* normally deactivate chipselect ... unless no error and 374 /* normally deactivate chipselect ... unless no error and
371 * cs_change has hinted that the next message will probably 375 * cs_change has hinted that the next message will probably
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 5d869c4d3eb2..606e7a40a8da 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -58,15 +58,20 @@ static unsigned long minors[N_SPI_MINORS / BITS_PER_LONG];
58 58
59 59
60/* Bit masks for spi_device.mode management. Note that incorrect 60/* Bit masks for spi_device.mode management. Note that incorrect
61 * settings for CS_HIGH and 3WIRE can cause *lots* of trouble for other 61 * settings for some settings can cause *lots* of trouble for other
62 * devices on a shared bus: CS_HIGH, because this device will be 62 * devices on a shared bus:
63 * active when it shouldn't be; 3WIRE, because when active it won't
64 * behave as it should.
65 * 63 *
66 * REVISIT should changing those two modes be privileged? 64 * - CS_HIGH ... this device will be active when it shouldn't be
65 * - 3WIRE ... when active, it won't behave as it should
66 * - NO_CS ... there will be no explicit message boundaries; this
67 * is completely incompatible with the shared bus model
68 * - READY ... transfers may proceed when they shouldn't.
69 *
70 * REVISIT should changing those flags be privileged?
67 */ 71 */
68#define SPI_MODE_MASK (SPI_CPHA | SPI_CPOL | SPI_CS_HIGH \ 72#define SPI_MODE_MASK (SPI_CPHA | SPI_CPOL | SPI_CS_HIGH \
69 | SPI_LSB_FIRST | SPI_3WIRE | SPI_LOOP) 73 | SPI_LSB_FIRST | SPI_3WIRE | SPI_LOOP \
74 | SPI_NO_CS | SPI_READY)
70 75
71struct spidev_data { 76struct spidev_data {
72 dev_t devt; 77 dev_t devt;
diff --git a/drivers/ssb/driver_mipscore.c b/drivers/ssb/driver_mipscore.c
index 3fd3e3b412b6..3c6feed46f6e 100644
--- a/drivers/ssb/driver_mipscore.c
+++ b/drivers/ssb/driver_mipscore.c
@@ -49,29 +49,54 @@ static const u32 ipsflag_irq_shift[] = {
49 49
50static inline u32 ssb_irqflag(struct ssb_device *dev) 50static inline u32 ssb_irqflag(struct ssb_device *dev)
51{ 51{
52 return ssb_read32(dev, SSB_TPSFLAG) & SSB_TPSFLAG_BPFLAG; 52 u32 tpsflag = ssb_read32(dev, SSB_TPSFLAG);
53 if (tpsflag)
54 return ssb_read32(dev, SSB_TPSFLAG) & SSB_TPSFLAG_BPFLAG;
55 else
56 /* not irq supported */
57 return 0x3f;
58}
59
60static struct ssb_device *find_device(struct ssb_device *rdev, int irqflag)
61{
62 struct ssb_bus *bus = rdev->bus;
63 int i;
64 for (i = 0; i < bus->nr_devices; i++) {
65 struct ssb_device *dev;
66 dev = &(bus->devices[i]);
67 if (ssb_irqflag(dev) == irqflag)
68 return dev;
69 }
70 return NULL;
53} 71}
54 72
55/* Get the MIPS IRQ assignment for a specified device. 73/* Get the MIPS IRQ assignment for a specified device.
56 * If unassigned, 0 is returned. 74 * If unassigned, 0 is returned.
75 * If disabled, 5 is returned.
76 * If not supported, 6 is returned.
57 */ 77 */
58unsigned int ssb_mips_irq(struct ssb_device *dev) 78unsigned int ssb_mips_irq(struct ssb_device *dev)
59{ 79{
60 struct ssb_bus *bus = dev->bus; 80 struct ssb_bus *bus = dev->bus;
81 struct ssb_device *mdev = bus->mipscore.dev;
61 u32 irqflag; 82 u32 irqflag;
62 u32 ipsflag; 83 u32 ipsflag;
63 u32 tmp; 84 u32 tmp;
64 unsigned int irq; 85 unsigned int irq;
65 86
66 irqflag = ssb_irqflag(dev); 87 irqflag = ssb_irqflag(dev);
88 if (irqflag == 0x3f)
89 return 6;
67 ipsflag = ssb_read32(bus->mipscore.dev, SSB_IPSFLAG); 90 ipsflag = ssb_read32(bus->mipscore.dev, SSB_IPSFLAG);
68 for (irq = 1; irq <= 4; irq++) { 91 for (irq = 1; irq <= 4; irq++) {
69 tmp = ((ipsflag & ipsflag_irq_mask[irq]) >> ipsflag_irq_shift[irq]); 92 tmp = ((ipsflag & ipsflag_irq_mask[irq]) >> ipsflag_irq_shift[irq]);
70 if (tmp == irqflag) 93 if (tmp == irqflag)
71 break; 94 break;
72 } 95 }
73 if (irq == 5) 96 if (irq == 5) {
74 irq = 0; 97 if ((1 << irqflag) & ssb_read32(mdev, SSB_INTVEC))
98 irq = 0;
99 }
75 100
76 return irq; 101 return irq;
77} 102}
@@ -97,25 +122,56 @@ static void set_irq(struct ssb_device *dev, unsigned int irq)
97 struct ssb_device *mdev = bus->mipscore.dev; 122 struct ssb_device *mdev = bus->mipscore.dev;
98 u32 irqflag = ssb_irqflag(dev); 123 u32 irqflag = ssb_irqflag(dev);
99 124
125 BUG_ON(oldirq == 6);
126
100 dev->irq = irq + 2; 127 dev->irq = irq + 2;
101 128
102 ssb_dprintk(KERN_INFO PFX
103 "set_irq: core 0x%04x, irq %d => %d\n",
104 dev->id.coreid, oldirq, irq);
105 /* clear the old irq */ 129 /* clear the old irq */
106 if (oldirq == 0) 130 if (oldirq == 0)
107 ssb_write32(mdev, SSB_INTVEC, (~(1 << irqflag) & ssb_read32(mdev, SSB_INTVEC))); 131 ssb_write32(mdev, SSB_INTVEC, (~(1 << irqflag) & ssb_read32(mdev, SSB_INTVEC)));
108 else 132 else if (oldirq != 5)
109 clear_irq(bus, oldirq); 133 clear_irq(bus, oldirq);
110 134
111 /* assign the new one */ 135 /* assign the new one */
112 if (irq == 0) { 136 if (irq == 0) {
113 ssb_write32(mdev, SSB_INTVEC, ((1 << irqflag) | ssb_read32(mdev, SSB_INTVEC))); 137 ssb_write32(mdev, SSB_INTVEC, ((1 << irqflag) | ssb_read32(mdev, SSB_INTVEC)));
114 } else { 138 } else {
139 u32 ipsflag = ssb_read32(mdev, SSB_IPSFLAG);
140 if ((ipsflag & ipsflag_irq_mask[irq]) != ipsflag_irq_mask[irq]) {
141 u32 oldipsflag = (ipsflag & ipsflag_irq_mask[irq]) >> ipsflag_irq_shift[irq];
142 struct ssb_device *olddev = find_device(dev, oldipsflag);
143 if (olddev)
144 set_irq(olddev, 0);
145 }
115 irqflag <<= ipsflag_irq_shift[irq]; 146 irqflag <<= ipsflag_irq_shift[irq];
116 irqflag |= (ssb_read32(mdev, SSB_IPSFLAG) & ~ipsflag_irq_mask[irq]); 147 irqflag |= (ipsflag & ~ipsflag_irq_mask[irq]);
117 ssb_write32(mdev, SSB_IPSFLAG, irqflag); 148 ssb_write32(mdev, SSB_IPSFLAG, irqflag);
118 } 149 }
150 ssb_dprintk(KERN_INFO PFX
151 "set_irq: core 0x%04x, irq %d => %d\n",
152 dev->id.coreid, oldirq+2, irq+2);
153}
154
155static void print_irq(struct ssb_device *dev, unsigned int irq)
156{
157 int i;
158 static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
159 ssb_dprintk(KERN_INFO PFX
160 "core 0x%04x, irq :", dev->id.coreid);
161 for (i = 0; i <= 6; i++) {
162 ssb_dprintk(" %s%s", irq_name[i], i==irq?"*":" ");
163 }
164 ssb_dprintk("\n");
165}
166
167static void dump_irq(struct ssb_bus *bus)
168{
169 int i;
170 for (i = 0; i < bus->nr_devices; i++) {
171 struct ssb_device *dev;
172 dev = &(bus->devices[i]);
173 print_irq(dev, ssb_mips_irq(dev));
174 }
119} 175}
120 176
121static void ssb_mips_serial_init(struct ssb_mipscore *mcore) 177static void ssb_mips_serial_init(struct ssb_mipscore *mcore)
@@ -197,16 +253,23 @@ void ssb_mipscore_init(struct ssb_mipscore *mcore)
197 253
198 /* Assign IRQs to all cores on the bus, start with irq line 2, because serial usually takes 1 */ 254 /* Assign IRQs to all cores on the bus, start with irq line 2, because serial usually takes 1 */
199 for (irq = 2, i = 0; i < bus->nr_devices; i++) { 255 for (irq = 2, i = 0; i < bus->nr_devices; i++) {
256 int mips_irq;
200 dev = &(bus->devices[i]); 257 dev = &(bus->devices[i]);
201 dev->irq = ssb_mips_irq(dev) + 2; 258 mips_irq = ssb_mips_irq(dev);
259 if (mips_irq > 4)
260 dev->irq = 0;
261 else
262 dev->irq = mips_irq + 2;
263 if (dev->irq > 5)
264 continue;
202 switch (dev->id.coreid) { 265 switch (dev->id.coreid) {
203 case SSB_DEV_USB11_HOST: 266 case SSB_DEV_USB11_HOST:
204 /* shouldn't need a separate irq line for non-4710, most of them have a proper 267 /* shouldn't need a separate irq line for non-4710, most of them have a proper
205 * external usb controller on the pci */ 268 * external usb controller on the pci */
206 if ((bus->chip_id == 0x4710) && (irq <= 4)) { 269 if ((bus->chip_id == 0x4710) && (irq <= 4)) {
207 set_irq(dev, irq++); 270 set_irq(dev, irq++);
208 break;
209 } 271 }
272 break;
210 /* fallthrough */ 273 /* fallthrough */
211 case SSB_DEV_PCI: 274 case SSB_DEV_PCI:
212 case SSB_DEV_ETHERNET: 275 case SSB_DEV_ETHERNET:
@@ -220,6 +283,8 @@ void ssb_mipscore_init(struct ssb_mipscore *mcore)
220 } 283 }
221 } 284 }
222 } 285 }
286 ssb_dprintk(KERN_INFO PFX "after irq reconfiguration\n");
287 dump_irq(bus);
223 288
224 ssb_mips_serial_init(mcore); 289 ssb_mips_serial_init(mcore);
225 ssb_mips_flash_detect(mcore); 290 ssb_mips_flash_detect(mcore);
diff --git a/drivers/staging/agnx/xmit.c b/drivers/staging/agnx/xmit.c
index 0e034081f3a5..42db41070cf0 100644
--- a/drivers/staging/agnx/xmit.c
+++ b/drivers/staging/agnx/xmit.c
@@ -384,7 +384,8 @@ void handle_rx_irq(struct agnx_priv *priv)
384/* dump_ieee80211_hdr((struct ieee80211_hdr *)skb->data, "RX G"); */ 384/* dump_ieee80211_hdr((struct ieee80211_hdr *)skb->data, "RX G"); */
385 } else 385 } else
386 agnx_bug("Unknown packets type"); 386 agnx_bug("Unknown packets type");
387 ieee80211_rx_irqsafe(priv->hw, skb, &status); 387 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
388 ieee80211_rx_irqsafe(priv->hw, skb);
388 rx_desc_reinit(priv, i); 389 rx_desc_reinit(priv, i);
389 390
390 } while (priv->rx.idx++); 391 } while (priv->rx.idx++);
diff --git a/drivers/staging/at76_usb/at76_usb.c b/drivers/staging/at76_usb/at76_usb.c
index 3f303ae97b43..7b8aa5edf42f 100644
--- a/drivers/staging/at76_usb/at76_usb.c
+++ b/drivers/staging/at76_usb/at76_usb.c
@@ -3134,7 +3134,7 @@ static int at76_tx(struct sk_buff *skb, struct net_device *netdev)
3134 netdev->name, __func__); 3134 netdev->name, __func__);
3135 /* skip this packet */ 3135 /* skip this packet */
3136 dev_kfree_skb(skb); 3136 dev_kfree_skb(skb);
3137 return 0; 3137 return NETDEV_TX_OK;
3138 } 3138 }
3139 3139
3140 if (priv->tx_urb->status == -EINPROGRESS) { 3140 if (priv->tx_urb->status == -EINPROGRESS) {
@@ -3142,14 +3142,14 @@ static int at76_tx(struct sk_buff *skb, struct net_device *netdev)
3142 netdev->name, __func__); 3142 netdev->name, __func__);
3143 /* skip this packet */ 3143 /* skip this packet */
3144 dev_kfree_skb(skb); 3144 dev_kfree_skb(skb);
3145 return 0; 3145 return NETDEV_TX_OK;
3146 } 3146 }
3147 3147
3148 if (skb->len < ETH_HLEN) { 3148 if (skb->len < ETH_HLEN) {
3149 printk(KERN_ERR "%s: %s: skb too short (%d)\n", 3149 printk(KERN_ERR "%s: %s: skb too short (%d)\n",
3150 netdev->name, __func__, skb->len); 3150 netdev->name, __func__, skb->len);
3151 dev_kfree_skb(skb); 3151 dev_kfree_skb(skb);
3152 return 0; 3152 return NETDEV_TX_OK;
3153 } 3153 }
3154 3154
3155 at76_ledtrig_tx_activity(); /* tell ledtrigger we send a packet */ 3155 at76_ledtrig_tx_activity(); /* tell ledtrigger we send a packet */
@@ -3173,7 +3173,7 @@ static int at76_tx(struct sk_buff *skb, struct net_device *netdev)
3173 skb->data[ETH_HLEN + 1], 3173 skb->data[ETH_HLEN + 1],
3174 skb->data[ETH_HLEN + 2]); 3174 skb->data[ETH_HLEN + 2]);
3175 dev_kfree_skb(skb); 3175 dev_kfree_skb(skb);
3176 return 0; 3176 return NETDEV_TX_OK;
3177 } 3177 }
3178 } else { 3178 } else {
3179 /* add RFC 1042 header in front */ 3179 /* add RFC 1042 header in front */
diff --git a/drivers/staging/epl/VirtualEthernetLinux.c b/drivers/staging/epl/VirtualEthernetLinux.c
index 077724a556cc..7b7cce1b36e8 100644
--- a/drivers/staging/epl/VirtualEthernetLinux.c
+++ b/drivers/staging/epl/VirtualEthernetLinux.c
@@ -223,7 +223,7 @@ static int VEthXmit(struct sk_buff *pSkb_p, struct net_device *pNetDevice_p)
223 } 223 }
224 224
225 Exit: 225 Exit:
226 return 0; 226 return NETDEV_TX_OK;
227 227
228} 228}
229 229
diff --git a/drivers/staging/otus/usbdrv.c b/drivers/staging/otus/usbdrv.c
index 540cbbb826f9..7cd87caa6812 100644
--- a/drivers/staging/otus/usbdrv.c
+++ b/drivers/staging/otus/usbdrv.c
@@ -659,7 +659,7 @@ int usbdrv_xmit_frame(struct sk_buff *skb, struct net_device *dev)
659 netif_stop_queue(dev); 659 netif_stop_queue(dev);
660 } 660 }
661 661
662 return 0; 662 return NETDEV_TX_OK;
663} 663}
664 664
665 665
@@ -796,13 +796,13 @@ int zfLnxVapXmitFrame(struct sk_buff *skb, struct net_device *dev)
796 if (vapId >= ZM_VAP_PORT_NUMBER) 796 if (vapId >= ZM_VAP_PORT_NUMBER)
797 { 797 {
798 dev_kfree_skb_irq(skb); 798 dev_kfree_skb_irq(skb);
799 return 0; 799 return NETDEV_TX_OK;
800 } 800 }
801#if 1 801#if 1
802 if (vap[vapId].openFlag == 0) 802 if (vap[vapId].openFlag == 0)
803 { 803 {
804 dev_kfree_skb_irq(skb); 804 dev_kfree_skb_irq(skb);
805 return 0; 805 return NETDEV_TX_OK;
806 } 806 }
807#endif 807#endif
808 808
@@ -819,7 +819,7 @@ int zfLnxVapXmitFrame(struct sk_buff *skb, struct net_device *dev)
819 netif_stop_queue(dev); 819 netif_stop_queue(dev);
820 } 820 }
821 821
822 return 0; 822 return NETDEV_TX_OK;
823} 823}
824 824
825static const struct net_device_ops vap_netdev_ops = { 825static const struct net_device_ops vap_netdev_ops = {
diff --git a/drivers/staging/otus/wrap_pkt.c b/drivers/staging/otus/wrap_pkt.c
index 5db0004c8739..89a6b92f5972 100644
--- a/drivers/staging/otus/wrap_pkt.c
+++ b/drivers/staging/otus/wrap_pkt.c
@@ -156,10 +156,7 @@ void zfLnxRecvEth(zdev_t* dev, zbuf_t* buf, u16_t port)
156 switch(netif_rx(buf)) 156 switch(netif_rx(buf))
157#endif 157#endif
158 { 158 {
159 case NET_RX_BAD:
160 case NET_RX_DROP: 159 case NET_RX_DROP:
161 case NET_RX_CN_MOD:
162 case NET_RX_CN_HIGH:
163 break; 160 break;
164 default: 161 default:
165 macp->drv_stats.net_stats.rx_packets++; 162 macp->drv_stats.net_stats.rx_packets++;
diff --git a/drivers/staging/rt2860/rt_main_dev.c b/drivers/staging/rt2860/rt_main_dev.c
index f298b9bcec39..35c59d5aa99c 100644
--- a/drivers/staging/rt2860/rt_main_dev.c
+++ b/drivers/staging/rt2860/rt_main_dev.c
@@ -862,7 +862,7 @@ int rt28xx_packet_xmit(struct sk_buff *skb)
862{ 862{
863 struct net_device *net_dev = skb->dev; 863 struct net_device *net_dev = skb->dev;
864 PRTMP_ADAPTER pAd = net_dev->ml_priv; 864 PRTMP_ADAPTER pAd = net_dev->ml_priv;
865 int status = 0; 865 int status = NETDEV_TX_OK;
866 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb; 866 PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
867 867
868 { 868 {
@@ -892,7 +892,7 @@ int rt28xx_packet_xmit(struct sk_buff *skb)
892 892
893 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1); 893 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
894 894
895 status = 0; 895 status = NETDEV_TX_OK;
896done: 896done:
897 897
898 return status; 898 return status;
@@ -923,7 +923,7 @@ INT rt28xx_send_packets(
923 if (!(net_dev->flags & IFF_UP)) 923 if (!(net_dev->flags & IFF_UP))
924 { 924 {
925 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE); 925 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
926 return 0; 926 return NETDEV_TX_OK;
927 } 927 }
928 928
929 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15); 929 NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c
index 1294e05fcf13..1b774601b4a3 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c
@@ -802,13 +802,13 @@ int ieee80211_xmit(struct sk_buff *skb,
802 if ((*ieee->hard_start_xmit)(txb, dev) == 0) { 802 if ((*ieee->hard_start_xmit)(txb, dev) == 0) {
803 stats->tx_packets++; 803 stats->tx_packets++;
804 stats->tx_bytes += txb->payload_size; 804 stats->tx_bytes += txb->payload_size;
805 return 0; 805 return NETDEV_TX_OK;
806 } 806 }
807 ieee80211_txb_free(txb); 807 ieee80211_txb_free(txb);
808 } 808 }
809 } 809 }
810 810
811 return 0; 811 return NETDEV_TX_OK;
812 812
813 failed: 813 failed:
814 spin_unlock_irqrestore(&ieee->lock, flags); 814 spin_unlock_irqrestore(&ieee->lock, flags);
diff --git a/drivers/staging/rtl8187se/r8180_core.c b/drivers/staging/rtl8187se/r8180_core.c
index 7e2fecae813c..26a59118d34c 100644
--- a/drivers/staging/rtl8187se/r8180_core.c
+++ b/drivers/staging/rtl8187se/r8180_core.c
@@ -3040,7 +3040,7 @@ int rtl8180_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
3040 spin_unlock_irqrestore(&priv->tx_lock,flags); 3040 spin_unlock_irqrestore(&priv->tx_lock,flags);
3041 3041
3042 dev_kfree_skb_any(skb); 3042 dev_kfree_skb_any(skb);
3043 return 0; 3043 return NETDEV_TX_OK;
3044 } 3044 }
3045 3045
3046 rtl8180_tx(dev, skb->data, skb->len, priority, 3046 rtl8180_tx(dev, skb->data, skb->len, priority,
@@ -3051,7 +3051,7 @@ int rtl8180_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
3051 spin_unlock_irqrestore(&priv->tx_lock,flags); 3051 spin_unlock_irqrestore(&priv->tx_lock,flags);
3052 3052
3053 dev_kfree_skb_any(skb); 3053 dev_kfree_skb_any(skb);
3054 return 0; 3054 return NETDEV_TX_OK;
3055} 3055}
3056 3056
3057// longpre 144+48 shortpre 72+24 3057// longpre 144+48 shortpre 72+24
diff --git a/drivers/staging/slicoss/slicoss.c b/drivers/staging/slicoss/slicoss.c
index ed47db5ce5ff..b01a2822a8ee 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -845,7 +845,7 @@ static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
845 hcmd->paddrh, DONT_FLUSH); 845 hcmd->paddrh, DONT_FLUSH);
846 } 846 }
847xmit_done: 847xmit_done:
848 return 0; 848 return NETDEV_TX_OK;
849xmit_fail: 849xmit_fail:
850 slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status); 850 slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status);
851 goto xmit_done; 851 goto xmit_done;
diff --git a/drivers/staging/stlc45xx/stlc45xx.c b/drivers/staging/stlc45xx/stlc45xx.c
index cfdaac9b747e..52744faedbff 100644
--- a/drivers/staging/stlc45xx/stlc45xx.c
+++ b/drivers/staging/stlc45xx/stlc45xx.c
@@ -1429,7 +1429,8 @@ static int stlc45xx_rx_data(struct stlc45xx *stlc, struct sk_buff *skb)
1429 stlc45xx_debug(DEBUG_RX, "rx data 0x%p %d B", skb->data, skb->len); 1429 stlc45xx_debug(DEBUG_RX, "rx data 0x%p %d B", skb->data, skb->len);
1430 stlc45xx_dump(DEBUG_RX_CONTENT, skb->data, skb->len); 1430 stlc45xx_dump(DEBUG_RX_CONTENT, skb->data, skb->len);
1431 1431
1432 ieee80211_rx(stlc->hw, skb, &status); 1432 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
1433 ieee80211_rx(stlc->hw, skb);
1433 1434
1434 return 0; 1435 return 0;
1435} 1436}
diff --git a/drivers/staging/winbond/wb35rx.c b/drivers/staging/winbond/wb35rx.c
index 3e8cf08b87e6..b905e7b43a19 100644
--- a/drivers/staging/winbond/wb35rx.c
+++ b/drivers/staging/winbond/wb35rx.c
@@ -40,7 +40,8 @@ static void packet_came(struct ieee80211_hw *hw, char *pRxBufferAddress, int Pac
40 rx_status.phymode = MODE_IEEE80211B; 40 rx_status.phymode = MODE_IEEE80211B;
41*/ 41*/
42 42
43 ieee80211_rx_irqsafe(hw, skb, &rx_status); 43 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
44 ieee80211_rx_irqsafe(hw, skb);
44} 45}
45 46
46static void Wb35Rx_adjust(PDESCRIPTOR pRxDes) 47static void Wb35Rx_adjust(PDESCRIPTOR pRxDes)
diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
index 90f499e00dc5..c273c034a830 100644
--- a/drivers/staging/wlan-ng/p80211netdev.c
+++ b/drivers/staging/wlan-ng/p80211netdev.c
@@ -354,7 +354,7 @@ static int p80211knetdev_hard_start_xmit(struct sk_buff *skb,
354 p80211_metawep_t p80211_wep; 354 p80211_metawep_t p80211_wep;
355 355
356 if (skb == NULL) 356 if (skb == NULL)
357 return 0; 357 return NETDEV_TX_OK;
358 358
359 if (wlandev->state != WLAN_DEVICE_OPEN) { 359 if (wlandev->state != WLAN_DEVICE_OPEN) {
360 result = 1; 360 result = 1;
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 38bfdb0f6660..3f1045993474 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -550,7 +550,7 @@ static void acm_waker(struct work_struct *waker)
550static int acm_tty_open(struct tty_struct *tty, struct file *filp) 550static int acm_tty_open(struct tty_struct *tty, struct file *filp)
551{ 551{
552 struct acm *acm; 552 struct acm *acm;
553 int rv = -EINVAL; 553 int rv = -ENODEV;
554 int i; 554 int i;
555 dbg("Entering acm_tty_open."); 555 dbg("Entering acm_tty_open.");
556 556
@@ -677,7 +677,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
677 677
678 /* Perform the closing process and see if we need to do the hardware 678 /* Perform the closing process and see if we need to do the hardware
679 shutdown */ 679 shutdown */
680 if (tty_port_close_start(&acm->port, tty, filp) == 0) 680 if (!acm || tty_port_close_start(&acm->port, tty, filp) == 0)
681 return; 681 return;
682 acm_port_down(acm, 0); 682 acm_port_down(acm, 0);
683 tty_port_close_end(&acm->port, tty); 683 tty_port_close_end(&acm->port, tty);
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c
index 96fb118355b0..d17f1082df96 100644
--- a/drivers/usb/gadget/f_phonet.c
+++ b/drivers/usb/gadget/f_phonet.c
@@ -256,7 +256,7 @@ out:
256 dev_kfree_skb(skb); 256 dev_kfree_skb(skb);
257 dev->stats.tx_dropped++; 257 dev->stats.tx_dropped++;
258 } 258 }
259 return 0; 259 return NETDEV_TX_OK;
260} 260}
261 261
262static int pn_net_mtu(struct net_device *dev, int new_mtu) 262static int pn_net_mtu(struct net_device *dev, int new_mtu)
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 016f63b39028..aac69b591aeb 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -487,7 +487,7 @@ static int eth_start_xmit(struct sk_buff *skb, struct net_device *net)
487 487
488 if (!in) { 488 if (!in) {
489 dev_kfree_skb_any(skb); 489 dev_kfree_skb_any(skb);
490 return 0; 490 return NETDEV_TX_OK;
491 } 491 }
492 492
493 /* apply outgoing CDC or RNDIS filters */ 493 /* apply outgoing CDC or RNDIS filters */
@@ -506,7 +506,7 @@ static int eth_start_xmit(struct sk_buff *skb, struct net_device *net)
506 type = USB_CDC_PACKET_TYPE_ALL_MULTICAST; 506 type = USB_CDC_PACKET_TYPE_ALL_MULTICAST;
507 if (!(cdc_filter & type)) { 507 if (!(cdc_filter & type)) {
508 dev_kfree_skb_any(skb); 508 dev_kfree_skb_any(skb);
509 return 0; 509 return NETDEV_TX_OK;
510 } 510 }
511 } 511 }
512 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */ 512 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */
@@ -586,7 +586,7 @@ drop:
586 list_add(&req->list, &dev->tx_reqs); 586 list_add(&req->list, &dev->tx_reqs);
587 spin_unlock_irqrestore(&dev->req_lock, flags); 587 spin_unlock_irqrestore(&dev->req_lock, flags);
588 } 588 }
589 return 0; 589 return NETDEV_TX_OK;
590} 590}
591 591
592/*-------------------------------------------------------------------------*/ 592/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index d595aa5586a7..a84216464ca0 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -333,6 +333,9 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
333{ 333{
334 struct usb_serial_port *port = tty->driver_data; 334 struct usb_serial_port *port = tty->driver_data;
335 335
336 if (!port)
337 return;
338
336 dbg("%s - port %d", __func__, port->number); 339 dbg("%s - port %d", __func__, port->number);
337 340
338 341
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d6d65ef85f54..8afcf08eba98 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -616,6 +616,8 @@ config FB_STI
616 select FB_CFB_FILLRECT 616 select FB_CFB_FILLRECT
617 select FB_CFB_COPYAREA 617 select FB_CFB_COPYAREA
618 select FB_CFB_IMAGEBLIT 618 select FB_CFB_IMAGEBLIT
619 select STI_CONSOLE
620 select VT
619 default y 621 default y
620 ---help--- 622 ---help---
621 STI refers to the HP "Standard Text Interface" which is a set of 623 STI refers to the HP "Standard Text Interface" which is a set of
diff --git a/drivers/video/atafb.c b/drivers/video/atafb.c
index 018850c116c6..497ff8af03ed 100644
--- a/drivers/video/atafb.c
+++ b/drivers/video/atafb.c
@@ -2414,7 +2414,10 @@ static int atafb_get_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
2414 if (err) 2414 if (err)
2415 return err; 2415 return err;
2416 memset(fix, 0, sizeof(struct fb_fix_screeninfo)); 2416 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
2417 return fbhw->encode_fix(fix, &par); 2417 mutex_lock(&info->mm_lock);
2418 err = fbhw->encode_fix(fix, &par);
2419 mutex_unlock(&info->mm_lock);
2420 return err;
2418} 2421}
2419 2422
2420static int atafb_get_var(struct fb_var_screeninfo *var, struct fb_info *info) 2423static int atafb_get_var(struct fb_var_screeninfo *var, struct fb_info *info)
@@ -2743,7 +2746,9 @@ static int atafb_set_par(struct fb_info *info)
2743 2746
2744 /* Decode wanted screen parameters */ 2747 /* Decode wanted screen parameters */
2745 fbhw->decode_var(&info->var, par); 2748 fbhw->decode_var(&info->var, par);
2749 mutex_lock(&info->mm_lock);
2746 fbhw->encode_fix(&info->fix, par); 2750 fbhw->encode_fix(&info->fix, par);
2751 mutex_unlock(&info->mm_lock);
2747 2752
2748 /* Set new videomode */ 2753 /* Set new videomode */
2749 ata_set_par(par); 2754 ata_set_par(par);
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
index 5afd64482f55..cb88394ba995 100644
--- a/drivers/video/atmel_lcdfb.c
+++ b/drivers/video/atmel_lcdfb.c
@@ -270,7 +270,9 @@ static int atmel_lcdfb_alloc_video_memory(struct atmel_lcdfb_info *sinfo)
270 270
271 smem_len = (var->xres_virtual * var->yres_virtual 271 smem_len = (var->xres_virtual * var->yres_virtual
272 * ((var->bits_per_pixel + 7) / 8)); 272 * ((var->bits_per_pixel + 7) / 8));
273 mutex_lock(&info->mm_lock);
273 info->fix.smem_len = max(smem_len, sinfo->smem_len); 274 info->fix.smem_len = max(smem_len, sinfo->smem_len);
275 mutex_unlock(&info->mm_lock);
274 276
275 info->screen_base = dma_alloc_writecombine(info->device, info->fix.smem_len, 277 info->screen_base = dma_alloc_writecombine(info->device, info->fix.smem_len,
276 (dma_addr_t *)&info->fix.smem_start, GFP_KERNEL); 278 (dma_addr_t *)&info->fix.smem_start, GFP_KERNEL);
diff --git a/drivers/video/aty/atyfb.h b/drivers/video/aty/atyfb.h
index 7691e73823d3..1f39a62f899b 100644
--- a/drivers/video/aty/atyfb.h
+++ b/drivers/video/aty/atyfb.h
@@ -187,6 +187,8 @@ struct atyfb_par {
187 int mtrr_reg; 187 int mtrr_reg;
188#endif 188#endif
189 u32 mem_cntl; 189 u32 mem_cntl;
190 struct crtc saved_crtc;
191 union aty_pll saved_pll;
190}; 192};
191 193
192 /* 194 /*
@@ -217,6 +219,7 @@ struct atyfb_par {
217#define M64F_XL_DLL 0x00080000 219#define M64F_XL_DLL 0x00080000
218#define M64F_MFB_FORCE_4 0x00100000 220#define M64F_MFB_FORCE_4 0x00100000
219#define M64F_HW_TRIPLE 0x00200000 221#define M64F_HW_TRIPLE 0x00200000
222#define M64F_XL_MEM 0x00400000
220 /* 223 /*
221 * Register access 224 * Register access
222 */ 225 */
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 1207c208a30b..63d3739d43a8 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -66,6 +66,8 @@
66#include <linux/spinlock.h> 66#include <linux/spinlock.h>
67#include <linux/wait.h> 67#include <linux/wait.h>
68#include <linux/backlight.h> 68#include <linux/backlight.h>
69#include <linux/reboot.h>
70#include <linux/dmi.h>
69 71
70#include <asm/io.h> 72#include <asm/io.h>
71#include <linux/uaccess.h> 73#include <linux/uaccess.h>
@@ -249,8 +251,6 @@ static int aty_init(struct fb_info *info);
249static int store_video_par(char *videopar, unsigned char m64_num); 251static int store_video_par(char *videopar, unsigned char m64_num);
250#endif 252#endif
251 253
252static struct crtc saved_crtc;
253static union aty_pll saved_pll;
254static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc); 254static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc);
255 255
256static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc); 256static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc);
@@ -261,6 +261,8 @@ static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info);
261static int read_aty_sense(const struct atyfb_par *par); 261static int read_aty_sense(const struct atyfb_par *par);
262#endif 262#endif
263 263
264static DEFINE_MUTEX(reboot_lock);
265static struct fb_info *reboot_info;
264 266
265 /* 267 /*
266 * Interface used by the world 268 * Interface used by the world
@@ -361,8 +363,8 @@ static unsigned long phys_guiregbase[FB_MAX] __devinitdata = { 0, };
361#define ATI_CHIP_264GTPRO (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D) 363#define ATI_CHIP_264GTPRO (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D)
362#define ATI_CHIP_264LTPRO (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D) 364#define ATI_CHIP_264LTPRO (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D)
363 365
364#define ATI_CHIP_264XL (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4) 366#define ATI_CHIP_264XL (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4 | M64F_XL_MEM)
365#define ATI_CHIP_MOBILITY (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4 | M64F_MOBIL_BUS) 367#define ATI_CHIP_MOBILITY (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4 | M64F_XL_MEM | M64F_MOBIL_BUS)
366 368
367static struct { 369static struct {
368 u16 pci_id; 370 u16 pci_id;
@@ -539,6 +541,7 @@ static char ram_edo[] __devinitdata = "EDO";
539static char ram_sdram[] __devinitdata = "SDRAM (1:1)"; 541static char ram_sdram[] __devinitdata = "SDRAM (1:1)";
540static char ram_sgram[] __devinitdata = "SGRAM (1:1)"; 542static char ram_sgram[] __devinitdata = "SGRAM (1:1)";
541static char ram_sdram32[] __devinitdata = "SDRAM (2:1) (32-bit)"; 543static char ram_sdram32[] __devinitdata = "SDRAM (2:1) (32-bit)";
544static char ram_wram[] __devinitdata = "WRAM";
542static char ram_off[] __devinitdata = "OFF"; 545static char ram_off[] __devinitdata = "OFF";
543#endif /* CONFIG_FB_ATY_CT */ 546#endif /* CONFIG_FB_ATY_CT */
544 547
@@ -553,6 +556,10 @@ static char *aty_gx_ram[8] __devinitdata = {
553#ifdef CONFIG_FB_ATY_CT 556#ifdef CONFIG_FB_ATY_CT
554static char *aty_ct_ram[8] __devinitdata = { 557static char *aty_ct_ram[8] __devinitdata = {
555 ram_off, ram_dram, ram_edo, ram_edo, 558 ram_off, ram_dram, ram_edo, ram_edo,
559 ram_sdram, ram_sgram, ram_wram, ram_resv
560};
561static char *aty_xl_ram[8] __devinitdata = {
562 ram_off, ram_dram, ram_edo, ram_edo,
556 ram_sdram, ram_sgram, ram_sdram32, ram_resv 563 ram_sdram, ram_sgram, ram_sdram32, ram_resv
557}; 564};
558#endif /* CONFIG_FB_ATY_CT */ 565#endif /* CONFIG_FB_ATY_CT */
@@ -760,6 +767,17 @@ static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
760#endif /* CONFIG_FB_ATY_GENERIC_LCD */ 767#endif /* CONFIG_FB_ATY_GENERIC_LCD */
761} 768}
762 769
770static u32 calc_line_length(struct atyfb_par *par, u32 vxres, u32 bpp)
771{
772 u32 line_length = vxres * bpp / 8;
773
774 if (par->ram_type == SGRAM ||
775 (!M64_HAS(XL_MEM) && par->ram_type == WRAM))
776 line_length = (line_length + 63) & ~63;
777
778 return line_length;
779}
780
763static int aty_var_to_crtc(const struct fb_info *info, 781static int aty_var_to_crtc(const struct fb_info *info,
764 const struct fb_var_screeninfo *var, struct crtc *crtc) 782 const struct fb_var_screeninfo *var, struct crtc *crtc)
765{ 783{
@@ -769,13 +787,14 @@ static int aty_var_to_crtc(const struct fb_info *info,
769 u32 h_total, h_disp, h_sync_strt, h_sync_end, h_sync_dly, h_sync_wid, h_sync_pol; 787 u32 h_total, h_disp, h_sync_strt, h_sync_end, h_sync_dly, h_sync_wid, h_sync_pol;
770 u32 v_total, v_disp, v_sync_strt, v_sync_end, v_sync_wid, v_sync_pol, c_sync; 788 u32 v_total, v_disp, v_sync_strt, v_sync_end, v_sync_wid, v_sync_pol, c_sync;
771 u32 pix_width, dp_pix_width, dp_chain_mask; 789 u32 pix_width, dp_pix_width, dp_chain_mask;
790 u32 line_length;
772 791
773 /* input */ 792 /* input */
774 xres = var->xres; 793 xres = (var->xres + 7) & ~7;
775 yres = var->yres; 794 yres = var->yres;
776 vxres = var->xres_virtual; 795 vxres = (var->xres_virtual + 7) & ~7;
777 vyres = var->yres_virtual; 796 vyres = var->yres_virtual;
778 xoffset = var->xoffset; 797 xoffset = (var->xoffset + 7) & ~7;
779 yoffset = var->yoffset; 798 yoffset = var->yoffset;
780 bpp = var->bits_per_pixel; 799 bpp = var->bits_per_pixel;
781 if (bpp == 16) 800 if (bpp == 16)
@@ -827,7 +846,9 @@ static int aty_var_to_crtc(const struct fb_info *info,
827 } else 846 } else
828 FAIL("invalid bpp"); 847 FAIL("invalid bpp");
829 848
830 if (vxres * vyres * bpp / 8 > info->fix.smem_len) 849 line_length = calc_line_length(par, vxres, bpp);
850
851 if (vyres * line_length > info->fix.smem_len)
831 FAIL("not enough video RAM"); 852 FAIL("not enough video RAM");
832 853
833 h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1; 854 h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
@@ -969,7 +990,9 @@ static int aty_var_to_crtc(const struct fb_info *info,
969 crtc->xoffset = xoffset; 990 crtc->xoffset = xoffset;
970 crtc->yoffset = yoffset; 991 crtc->yoffset = yoffset;
971 crtc->bpp = bpp; 992 crtc->bpp = bpp;
972 crtc->off_pitch = ((yoffset*vxres+xoffset)*bpp/64) | (vxres<<19); 993 crtc->off_pitch =
994 ((yoffset * line_length + xoffset * bpp / 8) / 8) |
995 ((line_length / bpp) << 22);
973 crtc->vline_crnt_vline = 0; 996 crtc->vline_crnt_vline = 0;
974 997
975 crtc->h_tot_disp = h_total | (h_disp<<16); 998 crtc->h_tot_disp = h_total | (h_disp<<16);
@@ -1394,7 +1417,9 @@ static int atyfb_set_par(struct fb_info *info)
1394 } 1417 }
1395 aty_st_8(DAC_MASK, 0xff, par); 1418 aty_st_8(DAC_MASK, 0xff, par);
1396 1419
1397 info->fix.line_length = var->xres_virtual * var->bits_per_pixel/8; 1420 info->fix.line_length = calc_line_length(par, var->xres_virtual,
1421 var->bits_per_pixel);
1422
1398 info->fix.visual = var->bits_per_pixel <= 8 ? 1423 info->fix.visual = var->bits_per_pixel <= 8 ?
1399 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR; 1424 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
1400 1425
@@ -1505,10 +1530,12 @@ static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info)
1505{ 1530{
1506 u32 xoffset = info->var.xoffset; 1531 u32 xoffset = info->var.xoffset;
1507 u32 yoffset = info->var.yoffset; 1532 u32 yoffset = info->var.yoffset;
1508 u32 vxres = par->crtc.vxres; 1533 u32 line_length = info->fix.line_length;
1509 u32 bpp = info->var.bits_per_pixel; 1534 u32 bpp = info->var.bits_per_pixel;
1510 1535
1511 par->crtc.off_pitch = ((yoffset * vxres + xoffset) * bpp / 64) | (vxres << 19); 1536 par->crtc.off_pitch =
1537 ((yoffset * line_length + xoffset * bpp / 8) / 8) |
1538 ((line_length / bpp) << 22);
1512} 1539}
1513 1540
1514 1541
@@ -2201,7 +2228,7 @@ static void __devinit aty_calc_mem_refresh(struct atyfb_par *par, int xclk)
2201 const int *refresh_tbl; 2228 const int *refresh_tbl;
2202 int i, size; 2229 int i, size;
2203 2230
2204 if (IS_XL(par->pci_id) || IS_MOBILITY(par->pci_id)) { 2231 if (M64_HAS(XL_MEM)) {
2205 refresh_tbl = ragexl_tbl; 2232 refresh_tbl = ragexl_tbl;
2206 size = ARRAY_SIZE(ragexl_tbl); 2233 size = ARRAY_SIZE(ragexl_tbl);
2207 } else { 2234 } else {
@@ -2335,7 +2362,10 @@ static int __devinit aty_init(struct fb_info *info)
2335 par->pll_ops = &aty_pll_ct; 2362 par->pll_ops = &aty_pll_ct;
2336 par->bus_type = PCI; 2363 par->bus_type = PCI;
2337 par->ram_type = (aty_ld_le32(CNFG_STAT0, par) & 0x07); 2364 par->ram_type = (aty_ld_le32(CNFG_STAT0, par) & 0x07);
2338 ramname = aty_ct_ram[par->ram_type]; 2365 if (M64_HAS(XL_MEM))
2366 ramname = aty_xl_ram[par->ram_type];
2367 else
2368 ramname = aty_ct_ram[par->ram_type];
2339 /* for many chips, the mclk is 67 MHz for SDRAM, 63 MHz otherwise */ 2369 /* for many chips, the mclk is 67 MHz for SDRAM, 63 MHz otherwise */
2340 if (par->pll_limits.mclk == 67 && par->ram_type < SDRAM) 2370 if (par->pll_limits.mclk == 67 && par->ram_type < SDRAM)
2341 par->pll_limits.mclk = 63; 2371 par->pll_limits.mclk = 63;
@@ -2390,9 +2420,9 @@ static int __devinit aty_init(struct fb_info *info)
2390#endif /* CONFIG_FB_ATY_CT */ 2420#endif /* CONFIG_FB_ATY_CT */
2391 2421
2392 /* save previous video mode */ 2422 /* save previous video mode */
2393 aty_get_crtc(par, &saved_crtc); 2423 aty_get_crtc(par, &par->saved_crtc);
2394 if(par->pll_ops->get_pll) 2424 if(par->pll_ops->get_pll)
2395 par->pll_ops->get_pll(info, &saved_pll); 2425 par->pll_ops->get_pll(info, &par->saved_pll);
2396 2426
2397 par->mem_cntl = aty_ld_le32(MEM_CNTL, par); 2427 par->mem_cntl = aty_ld_le32(MEM_CNTL, par);
2398 gtb_memsize = M64_HAS(GTB_DSP); 2428 gtb_memsize = M64_HAS(GTB_DSP);
@@ -2667,8 +2697,8 @@ static int __devinit aty_init(struct fb_info *info)
2667 2697
2668aty_init_exit: 2698aty_init_exit:
2669 /* restore video mode */ 2699 /* restore video mode */
2670 aty_set_crtc(par, &saved_crtc); 2700 aty_set_crtc(par, &par->saved_crtc);
2671 par->pll_ops->set_pll(info, &saved_pll); 2701 par->pll_ops->set_pll(info, &par->saved_pll);
2672 2702
2673#ifdef CONFIG_MTRR 2703#ifdef CONFIG_MTRR
2674 if (par->mtrr_reg >= 0) { 2704 if (par->mtrr_reg >= 0) {
@@ -3502,6 +3532,11 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
3502 par->mmap_map[1].prot_flag = _PAGE_E; 3532 par->mmap_map[1].prot_flag = _PAGE_E;
3503#endif /* __sparc__ */ 3533#endif /* __sparc__ */
3504 3534
3535 mutex_lock(&reboot_lock);
3536 if (!reboot_info)
3537 reboot_info = info;
3538 mutex_unlock(&reboot_lock);
3539
3505 return 0; 3540 return 0;
3506 3541
3507err_release_io: 3542err_release_io:
@@ -3614,8 +3649,8 @@ static void __devexit atyfb_remove(struct fb_info *info)
3614 struct atyfb_par *par = (struct atyfb_par *) info->par; 3649 struct atyfb_par *par = (struct atyfb_par *) info->par;
3615 3650
3616 /* restore video mode */ 3651 /* restore video mode */
3617 aty_set_crtc(par, &saved_crtc); 3652 aty_set_crtc(par, &par->saved_crtc);
3618 par->pll_ops->set_pll(info, &saved_pll); 3653 par->pll_ops->set_pll(info, &par->saved_pll);
3619 3654
3620 unregister_framebuffer(info); 3655 unregister_framebuffer(info);
3621 3656
@@ -3661,6 +3696,11 @@ static void __devexit atyfb_pci_remove(struct pci_dev *pdev)
3661{ 3696{
3662 struct fb_info *info = pci_get_drvdata(pdev); 3697 struct fb_info *info = pci_get_drvdata(pdev);
3663 3698
3699 mutex_lock(&reboot_lock);
3700 if (reboot_info == info)
3701 reboot_info = NULL;
3702 mutex_unlock(&reboot_lock);
3703
3664 atyfb_remove(info); 3704 atyfb_remove(info);
3665} 3705}
3666 3706
@@ -3808,6 +3848,56 @@ static int __init atyfb_setup(char *options)
3808} 3848}
3809#endif /* MODULE */ 3849#endif /* MODULE */
3810 3850
3851static int atyfb_reboot_notify(struct notifier_block *nb,
3852 unsigned long code, void *unused)
3853{
3854 struct atyfb_par *par;
3855
3856 if (code != SYS_RESTART)
3857 return NOTIFY_DONE;
3858
3859 mutex_lock(&reboot_lock);
3860
3861 if (!reboot_info)
3862 goto out;
3863
3864 if (!lock_fb_info(reboot_info))
3865 goto out;
3866
3867 par = reboot_info->par;
3868
3869 /*
3870 * HP OmniBook 500's BIOS doesn't like the state of the
3871 * hardware after atyfb has been used. Restore the hardware
3872 * to the original state to allow successful reboots.
3873 */
3874 aty_set_crtc(par, &par->saved_crtc);
3875 par->pll_ops->set_pll(reboot_info, &par->saved_pll);
3876
3877 unlock_fb_info(reboot_info);
3878 out:
3879 mutex_unlock(&reboot_lock);
3880
3881 return NOTIFY_DONE;
3882}
3883
3884static struct notifier_block atyfb_reboot_notifier = {
3885 .notifier_call = atyfb_reboot_notify,
3886};
3887
3888static const struct dmi_system_id atyfb_reboot_ids[] = {
3889 {
3890 .ident = "HP OmniBook 500",
3891 .matches = {
3892 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
3893 DMI_MATCH(DMI_PRODUCT_NAME, "HP OmniBook PC"),
3894 DMI_MATCH(DMI_PRODUCT_VERSION, "HP OmniBook 500 FA"),
3895 },
3896 },
3897
3898 { }
3899};
3900
3811static int __init atyfb_init(void) 3901static int __init atyfb_init(void)
3812{ 3902{
3813 int err1 = 1, err2 = 1; 3903 int err1 = 1, err2 = 1;
@@ -3826,11 +3916,20 @@ static int __init atyfb_init(void)
3826 err2 = atyfb_atari_probe(); 3916 err2 = atyfb_atari_probe();
3827#endif 3917#endif
3828 3918
3829 return (err1 && err2) ? -ENODEV : 0; 3919 if (err1 && err2)
3920 return -ENODEV;
3921
3922 if (dmi_check_system(atyfb_reboot_ids))
3923 register_reboot_notifier(&atyfb_reboot_notifier);
3924
3925 return 0;
3830} 3926}
3831 3927
3832static void __exit atyfb_exit(void) 3928static void __exit atyfb_exit(void)
3833{ 3929{
3930 if (dmi_check_system(atyfb_reboot_ids))
3931 unregister_reboot_notifier(&atyfb_reboot_notifier);
3932
3834#ifdef CONFIG_PCI 3933#ifdef CONFIG_PCI
3835 pci_unregister_driver(&atyfb_driver); 3934 pci_unregister_driver(&atyfb_driver);
3836#endif 3935#endif
diff --git a/drivers/video/aty/mach64_accel.c b/drivers/video/aty/mach64_accel.c
index 0cc9724e61a2..51fcc0a2c94a 100644
--- a/drivers/video/aty/mach64_accel.c
+++ b/drivers/video/aty/mach64_accel.c
@@ -63,14 +63,17 @@ static void reset_GTC_3D_engine(const struct atyfb_par *par)
63void aty_init_engine(struct atyfb_par *par, struct fb_info *info) 63void aty_init_engine(struct atyfb_par *par, struct fb_info *info)
64{ 64{
65 u32 pitch_value; 65 u32 pitch_value;
66 u32 vxres;
66 67
67 /* determine modal information from global mode structure */ 68 /* determine modal information from global mode structure */
68 pitch_value = info->var.xres_virtual; 69 pitch_value = info->fix.line_length / (info->var.bits_per_pixel / 8);
70 vxres = info->var.xres_virtual;
69 71
70 if (info->var.bits_per_pixel == 24) { 72 if (info->var.bits_per_pixel == 24) {
71 /* In 24 bpp, the engine is in 8 bpp - this requires that all */ 73 /* In 24 bpp, the engine is in 8 bpp - this requires that all */
72 /* horizontal coordinates and widths must be adjusted */ 74 /* horizontal coordinates and widths must be adjusted */
73 pitch_value *= 3; 75 pitch_value *= 3;
76 vxres *= 3;
74 } 77 }
75 78
76 /* On GTC (RagePro), we need to reset the 3D engine before */ 79 /* On GTC (RagePro), we need to reset the 3D engine before */
@@ -133,7 +136,7 @@ void aty_init_engine(struct atyfb_par *par, struct fb_info *info)
133 aty_st_le32(SC_LEFT, 0, par); 136 aty_st_le32(SC_LEFT, 0, par);
134 aty_st_le32(SC_TOP, 0, par); 137 aty_st_le32(SC_TOP, 0, par);
135 aty_st_le32(SC_BOTTOM, par->crtc.vyres - 1, par); 138 aty_st_le32(SC_BOTTOM, par->crtc.vyres - 1, par);
136 aty_st_le32(SC_RIGHT, pitch_value - 1, par); 139 aty_st_le32(SC_RIGHT, vxres - 1, par);
137 140
138 /* set background color to minimum value (usually BLACK) */ 141 /* set background color to minimum value (usually BLACK) */
139 aty_st_le32(DP_BKGD_CLR, 0, par); 142 aty_st_le32(DP_BKGD_CLR, 0, par);
diff --git a/drivers/video/backlight/tdo24m.c b/drivers/video/backlight/tdo24m.c
index 1dae7f8f3c6b..51422fc4f606 100644
--- a/drivers/video/backlight/tdo24m.c
+++ b/drivers/video/backlight/tdo24m.c
@@ -356,7 +356,7 @@ static int __devinit tdo24m_probe(struct spi_device *spi)
356 lcd->power = FB_BLANK_POWERDOWN; 356 lcd->power = FB_BLANK_POWERDOWN;
357 lcd->mode = MODE_VGA; /* default to VGA */ 357 lcd->mode = MODE_VGA; /* default to VGA */
358 358
359 lcd->buf = kmalloc(TDO24M_SPI_BUFF_SIZE, sizeof(GFP_KERNEL)); 359 lcd->buf = kmalloc(TDO24M_SPI_BUFF_SIZE, GFP_KERNEL);
360 if (lcd->buf == NULL) { 360 if (lcd->buf == NULL) {
361 kfree(lcd); 361 kfree(lcd);
362 return -ENOMEM; 362 return -ENOMEM;
diff --git a/drivers/video/cobalt_lcdfb.c b/drivers/video/cobalt_lcdfb.c
index 7bad24ed04ef..108b89e09a80 100644
--- a/drivers/video/cobalt_lcdfb.c
+++ b/drivers/video/cobalt_lcdfb.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Cobalt server LCD frame buffer driver. 2 * Cobalt server LCD frame buffer driver.
3 * 3 *
4 * Copyright (C) 2008 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index f8a09bf8d0cd..53ea05645ff8 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -1310,8 +1310,6 @@ static long fb_compat_ioctl(struct file *file, unsigned int cmd,
1310 1310
1311static int 1311static int
1312fb_mmap(struct file *file, struct vm_area_struct * vma) 1312fb_mmap(struct file *file, struct vm_area_struct * vma)
1313__acquires(&info->lock)
1314__releases(&info->lock)
1315{ 1313{
1316 int fbidx = iminor(file->f_path.dentry->d_inode); 1314 int fbidx = iminor(file->f_path.dentry->d_inode);
1317 struct fb_info *info = registered_fb[fbidx]; 1315 struct fb_info *info = registered_fb[fbidx];
@@ -1325,16 +1323,14 @@ __releases(&info->lock)
1325 off = vma->vm_pgoff << PAGE_SHIFT; 1323 off = vma->vm_pgoff << PAGE_SHIFT;
1326 if (!fb) 1324 if (!fb)
1327 return -ENODEV; 1325 return -ENODEV;
1326 mutex_lock(&info->mm_lock);
1328 if (fb->fb_mmap) { 1327 if (fb->fb_mmap) {
1329 int res; 1328 int res;
1330 mutex_lock(&info->lock);
1331 res = fb->fb_mmap(info, vma); 1329 res = fb->fb_mmap(info, vma);
1332 mutex_unlock(&info->lock); 1330 mutex_unlock(&info->mm_lock);
1333 return res; 1331 return res;
1334 } 1332 }
1335 1333
1336 mutex_lock(&info->lock);
1337
1338 /* frame buffer memory */ 1334 /* frame buffer memory */
1339 start = info->fix.smem_start; 1335 start = info->fix.smem_start;
1340 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len); 1336 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len);
@@ -1342,13 +1338,13 @@ __releases(&info->lock)
1342 /* memory mapped io */ 1338 /* memory mapped io */
1343 off -= len; 1339 off -= len;
1344 if (info->var.accel_flags) { 1340 if (info->var.accel_flags) {
1345 mutex_unlock(&info->lock); 1341 mutex_unlock(&info->mm_lock);
1346 return -EINVAL; 1342 return -EINVAL;
1347 } 1343 }
1348 start = info->fix.mmio_start; 1344 start = info->fix.mmio_start;
1349 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len); 1345 len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
1350 } 1346 }
1351 mutex_unlock(&info->lock); 1347 mutex_unlock(&info->mm_lock);
1352 start &= PAGE_MASK; 1348 start &= PAGE_MASK;
1353 if ((vma->vm_end - vma->vm_start + off) > len) 1349 if ((vma->vm_end - vma->vm_start + off) > len)
1354 return -EINVAL; 1350 return -EINVAL;
@@ -1518,6 +1514,7 @@ register_framebuffer(struct fb_info *fb_info)
1518 break; 1514 break;
1519 fb_info->node = i; 1515 fb_info->node = i;
1520 mutex_init(&fb_info->lock); 1516 mutex_init(&fb_info->lock);
1517 mutex_init(&fb_info->mm_lock);
1521 1518
1522 fb_info->dev = device_create(fb_class, fb_info->device, 1519 fb_info->dev = device_create(fb_class, fb_info->device,
1523 MKDEV(FB_MAJOR, i), NULL, "fb%d", i); 1520 MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
diff --git a/drivers/video/fsl-diu-fb.c b/drivers/video/fsl-diu-fb.c
index f153c581cbd7..0bf2190928d0 100644
--- a/drivers/video/fsl-diu-fb.c
+++ b/drivers/video/fsl-diu-fb.c
@@ -750,24 +750,26 @@ static void update_lcdc(struct fb_info *info)
750static int map_video_memory(struct fb_info *info) 750static int map_video_memory(struct fb_info *info)
751{ 751{
752 phys_addr_t phys; 752 phys_addr_t phys;
753 u32 smem_len = info->fix.line_length * info->var.yres_virtual;
753 754
754 pr_debug("info->var.xres_virtual = %d\n", info->var.xres_virtual); 755 pr_debug("info->var.xres_virtual = %d\n", info->var.xres_virtual);
755 pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual); 756 pr_debug("info->var.yres_virtual = %d\n", info->var.yres_virtual);
756 pr_debug("info->fix.line_length = %d\n", info->fix.line_length); 757 pr_debug("info->fix.line_length = %d\n", info->fix.line_length);
758 pr_debug("MAP_VIDEO_MEMORY: smem_len = %u\n", smem_len);
757 759
758 info->fix.smem_len = info->fix.line_length * info->var.yres_virtual; 760 info->screen_base = fsl_diu_alloc(smem_len, &phys);
759 pr_debug("MAP_VIDEO_MEMORY: smem_len = %d\n", info->fix.smem_len);
760 info->screen_base = fsl_diu_alloc(info->fix.smem_len, &phys);
761 if (info->screen_base == NULL) { 761 if (info->screen_base == NULL) {
762 printk(KERN_ERR "Unable to allocate fb memory\n"); 762 printk(KERN_ERR "Unable to allocate fb memory\n");
763 return -ENOMEM; 763 return -ENOMEM;
764 } 764 }
765 mutex_lock(&info->mm_lock);
765 info->fix.smem_start = (unsigned long) phys; 766 info->fix.smem_start = (unsigned long) phys;
767 info->fix.smem_len = smem_len;
768 mutex_unlock(&info->mm_lock);
766 info->screen_size = info->fix.smem_len; 769 info->screen_size = info->fix.smem_len;
767 770
768 pr_debug("Allocated fb @ paddr=0x%08lx, size=%d.\n", 771 pr_debug("Allocated fb @ paddr=0x%08lx, size=%d.\n",
769 info->fix.smem_start, 772 info->fix.smem_start, info->fix.smem_len);
770 info->fix.smem_len);
771 pr_debug("screen base %p\n", info->screen_base); 773 pr_debug("screen base %p\n", info->screen_base);
772 774
773 return 0; 775 return 0;
@@ -776,9 +778,11 @@ static int map_video_memory(struct fb_info *info)
776static void unmap_video_memory(struct fb_info *info) 778static void unmap_video_memory(struct fb_info *info)
777{ 779{
778 fsl_diu_free(info->screen_base, info->fix.smem_len); 780 fsl_diu_free(info->screen_base, info->fix.smem_len);
781 mutex_lock(&info->mm_lock);
779 info->screen_base = NULL; 782 info->screen_base = NULL;
780 info->fix.smem_start = 0; 783 info->fix.smem_start = 0;
781 info->fix.smem_len = 0; 784 info->fix.smem_len = 0;
785 mutex_unlock(&info->mm_lock);
782} 786}
783 787
784/* 788/*
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index 2e940199fc89..71960672d721 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -1090,8 +1090,10 @@ static int encode_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
1090 memset(fix, 0, sizeof(struct fb_fix_screeninfo)); 1090 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
1091 1091
1092 strcpy(fix->id, "I810"); 1092 strcpy(fix->id, "I810");
1093 mutex_lock(&info->mm_lock);
1093 fix->smem_start = par->fb.physical; 1094 fix->smem_start = par->fb.physical;
1094 fix->smem_len = par->fb.size; 1095 fix->smem_len = par->fb.size;
1096 mutex_unlock(&info->mm_lock);
1095 fix->type = FB_TYPE_PACKED_PIXELS; 1097 fix->type = FB_TYPE_PACKED_PIXELS;
1096 fix->type_aux = 0; 1098 fix->type_aux = 0;
1097 fix->xpanstep = 8; 1099 fix->xpanstep = 8;
diff --git a/drivers/video/matrox/matroxfb_base.c b/drivers/video/matrox/matroxfb_base.c
index 8e7a275df50c..59c3a2e14913 100644
--- a/drivers/video/matrox/matroxfb_base.c
+++ b/drivers/video/matrox/matroxfb_base.c
@@ -724,8 +724,10 @@ static void matroxfb_update_fix(WPMINFO2)
724 struct fb_fix_screeninfo *fix = &ACCESS_FBINFO(fbcon).fix; 724 struct fb_fix_screeninfo *fix = &ACCESS_FBINFO(fbcon).fix;
725 DBG(__func__) 725 DBG(__func__)
726 726
727 mutex_lock(&ACCESS_FBINFO(fbcon).mm_lock);
727 fix->smem_start = ACCESS_FBINFO(video.base) + ACCESS_FBINFO(curr.ydstorg.bytes); 728 fix->smem_start = ACCESS_FBINFO(video.base) + ACCESS_FBINFO(curr.ydstorg.bytes);
728 fix->smem_len = ACCESS_FBINFO(video.len_usable) - ACCESS_FBINFO(curr.ydstorg.bytes); 729 fix->smem_len = ACCESS_FBINFO(video.len_usable) - ACCESS_FBINFO(curr.ydstorg.bytes);
730 mutex_unlock(&ACCESS_FBINFO(fbcon).mm_lock);
729} 731}
730 732
731static int matroxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 733static int matroxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
@@ -2081,6 +2083,7 @@ static int matroxfb_probe(struct pci_dev* pdev, const struct pci_device_id* dumm
2081 spin_lock_init(&ACCESS_FBINFO(lock.accel)); 2083 spin_lock_init(&ACCESS_FBINFO(lock.accel));
2082 init_rwsem(&ACCESS_FBINFO(crtc2.lock)); 2084 init_rwsem(&ACCESS_FBINFO(crtc2.lock));
2083 init_rwsem(&ACCESS_FBINFO(altout.lock)); 2085 init_rwsem(&ACCESS_FBINFO(altout.lock));
2086 mutex_init(&ACCESS_FBINFO(fbcon).mm_lock);
2084 ACCESS_FBINFO(irq_flags) = 0; 2087 ACCESS_FBINFO(irq_flags) = 0;
2085 init_waitqueue_head(&ACCESS_FBINFO(crtc1.vsync.wait)); 2088 init_waitqueue_head(&ACCESS_FBINFO(crtc1.vsync.wait));
2086 init_waitqueue_head(&ACCESS_FBINFO(crtc2.vsync.wait)); 2089 init_waitqueue_head(&ACCESS_FBINFO(crtc2.vsync.wait));
diff --git a/drivers/video/matrox/matroxfb_crtc2.c b/drivers/video/matrox/matroxfb_crtc2.c
index 7ac4c5f6145d..909e10a11898 100644
--- a/drivers/video/matrox/matroxfb_crtc2.c
+++ b/drivers/video/matrox/matroxfb_crtc2.c
@@ -289,13 +289,16 @@ static int matroxfb_dh_release(struct fb_info* info, int user) {
289#undef m2info 289#undef m2info
290} 290}
291 291
292static void matroxfb_dh_init_fix(struct matroxfb_dh_fb_info *m2info) { 292static void matroxfb_dh_init_fix(struct matroxfb_dh_fb_info *m2info)
293{
293 struct fb_fix_screeninfo *fix = &m2info->fbcon.fix; 294 struct fb_fix_screeninfo *fix = &m2info->fbcon.fix;
294 295
295 strcpy(fix->id, "MATROX DH"); 296 strcpy(fix->id, "MATROX DH");
296 297
298 mutex_lock(&m2info->fbcon.mm_lock);
297 fix->smem_start = m2info->video.base; 299 fix->smem_start = m2info->video.base;
298 fix->smem_len = m2info->video.len_usable; 300 fix->smem_len = m2info->video.len_usable;
301 mutex_unlock(&m2info->fbcon.mm_lock);
299 fix->ypanstep = 1; 302 fix->ypanstep = 1;
300 fix->ywrapstep = 0; 303 fix->ywrapstep = 0;
301 fix->xpanstep = 8; /* TBD */ 304 fix->xpanstep = 8; /* TBD */
diff --git a/drivers/video/mx3fb.c b/drivers/video/mx3fb.c
index b7af5256e887..567fb944bd2a 100644
--- a/drivers/video/mx3fb.c
+++ b/drivers/video/mx3fb.c
@@ -669,7 +669,7 @@ static uint32_t bpp_to_pixfmt(int bpp)
669} 669}
670 670
671static int mx3fb_blank(int blank, struct fb_info *fbi); 671static int mx3fb_blank(int blank, struct fb_info *fbi);
672static int mx3fb_map_video_memory(struct fb_info *fbi); 672static int mx3fb_map_video_memory(struct fb_info *fbi, unsigned int mem_len);
673static int mx3fb_unmap_video_memory(struct fb_info *fbi); 673static int mx3fb_unmap_video_memory(struct fb_info *fbi);
674 674
675/** 675/**
@@ -742,8 +742,7 @@ static int mx3fb_set_par(struct fb_info *fbi)
742 if (fbi->fix.smem_start) 742 if (fbi->fix.smem_start)
743 mx3fb_unmap_video_memory(fbi); 743 mx3fb_unmap_video_memory(fbi);
744 744
745 fbi->fix.smem_len = mem_len; 745 if (mx3fb_map_video_memory(fbi, mem_len) < 0) {
746 if (mx3fb_map_video_memory(fbi) < 0) {
747 mutex_unlock(&mx3_fbi->mutex); 746 mutex_unlock(&mx3_fbi->mutex);
748 return -ENOMEM; 747 return -ENOMEM;
749 } 748 }
@@ -1198,6 +1197,7 @@ static int mx3fb_resume(struct platform_device *pdev)
1198/** 1197/**
1199 * mx3fb_map_video_memory() - allocates the DRAM memory for the frame buffer. 1198 * mx3fb_map_video_memory() - allocates the DRAM memory for the frame buffer.
1200 * @fbi: framebuffer information pointer 1199 * @fbi: framebuffer information pointer
1200 * @mem_len: length of mapped memory
1201 * @return: Error code indicating success or failure 1201 * @return: Error code indicating success or failure
1202 * 1202 *
1203 * This buffer is remapped into a non-cached, non-buffered, memory region to 1203 * This buffer is remapped into a non-cached, non-buffered, memory region to
@@ -1205,23 +1205,26 @@ static int mx3fb_resume(struct platform_device *pdev)
1205 * area is remapped, all virtual memory access to the video memory should occur 1205 * area is remapped, all virtual memory access to the video memory should occur
1206 * at the new region. 1206 * at the new region.
1207 */ 1207 */
1208static int mx3fb_map_video_memory(struct fb_info *fbi) 1208static int mx3fb_map_video_memory(struct fb_info *fbi, unsigned int mem_len)
1209{ 1209{
1210 int retval = 0; 1210 int retval = 0;
1211 dma_addr_t addr; 1211 dma_addr_t addr;
1212 1212
1213 fbi->screen_base = dma_alloc_writecombine(fbi->device, 1213 fbi->screen_base = dma_alloc_writecombine(fbi->device,
1214 fbi->fix.smem_len, 1214 mem_len,
1215 &addr, GFP_DMA); 1215 &addr, GFP_DMA);
1216 1216
1217 if (!fbi->screen_base) { 1217 if (!fbi->screen_base) {
1218 dev_err(fbi->device, "Cannot allocate %u bytes framebuffer memory\n", 1218 dev_err(fbi->device, "Cannot allocate %u bytes framebuffer memory\n",
1219 fbi->fix.smem_len); 1219 mem_len);
1220 retval = -EBUSY; 1220 retval = -EBUSY;
1221 goto err0; 1221 goto err0;
1222 } 1222 }
1223 1223
1224 mutex_lock(&fbi->mm_lock);
1224 fbi->fix.smem_start = addr; 1225 fbi->fix.smem_start = addr;
1226 fbi->fix.smem_len = mem_len;
1227 mutex_unlock(&fbi->mm_lock);
1225 1228
1226 dev_dbg(fbi->device, "allocated fb @ p=0x%08x, v=0x%p, size=%d.\n", 1229 dev_dbg(fbi->device, "allocated fb @ p=0x%08x, v=0x%p, size=%d.\n",
1227 (uint32_t) fbi->fix.smem_start, fbi->screen_base, fbi->fix.smem_len); 1230 (uint32_t) fbi->fix.smem_start, fbi->screen_base, fbi->fix.smem_len);
@@ -1251,8 +1254,10 @@ static int mx3fb_unmap_video_memory(struct fb_info *fbi)
1251 fbi->screen_base, fbi->fix.smem_start); 1254 fbi->screen_base, fbi->fix.smem_start);
1252 1255
1253 fbi->screen_base = 0; 1256 fbi->screen_base = 0;
1257 mutex_lock(&fbi->mm_lock);
1254 fbi->fix.smem_start = 0; 1258 fbi->fix.smem_start = 0;
1255 fbi->fix.smem_len = 0; 1259 fbi->fix.smem_len = 0;
1260 mutex_unlock(&fbi->mm_lock);
1256 return 0; 1261 return 0;
1257} 1262}
1258 1263
diff --git a/drivers/video/omap/omapfb_main.c b/drivers/video/omap/omapfb_main.c
index 060d72fe57cb..4ea99bfc37b4 100644
--- a/drivers/video/omap/omapfb_main.c
+++ b/drivers/video/omap/omapfb_main.c
@@ -393,8 +393,10 @@ static void set_fb_fix(struct fb_info *fbi)
393 393
394 rg = &plane->fbdev->mem_desc.region[plane->idx]; 394 rg = &plane->fbdev->mem_desc.region[plane->idx];
395 fbi->screen_base = rg->vaddr; 395 fbi->screen_base = rg->vaddr;
396 mutex_lock(&fbi->mm_lock);
396 fix->smem_start = rg->paddr; 397 fix->smem_start = rg->paddr;
397 fix->smem_len = rg->size; 398 fix->smem_len = rg->size;
399 mutex_unlock(&fbi->mm_lock);
398 400
399 fix->type = FB_TYPE_PACKED_PIXELS; 401 fix->type = FB_TYPE_PACKED_PIXELS;
400 bpp = var->bits_per_pixel; 402 bpp = var->bits_per_pixel;
@@ -886,8 +888,10 @@ static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
886 * plane memory is dealloce'd, the other 888 * plane memory is dealloce'd, the other
887 * screen parameters in var / fix are invalid. 889 * screen parameters in var / fix are invalid.
888 */ 890 */
891 mutex_lock(&fbi->mm_lock);
889 fbi->fix.smem_start = 0; 892 fbi->fix.smem_start = 0;
890 fbi->fix.smem_len = 0; 893 fbi->fix.smem_len = 0;
894 mutex_unlock(&fbi->mm_lock);
891 } 895 }
892 } 896 }
893 } 897 }
diff --git a/drivers/video/platinumfb.c b/drivers/video/platinumfb.c
index 03b3670130a0..bacfabd9ce16 100644
--- a/drivers/video/platinumfb.c
+++ b/drivers/video/platinumfb.c
@@ -141,7 +141,9 @@ static int platinumfb_set_par (struct fb_info *info)
141 offset = 0x10; 141 offset = 0x10;
142 142
143 info->screen_base = pinfo->frame_buffer + init->fb_offset + offset; 143 info->screen_base = pinfo->frame_buffer + init->fb_offset + offset;
144 mutex_lock(&info->mm_lock);
144 info->fix.smem_start = (pinfo->frame_buffer_phys) + init->fb_offset + offset; 145 info->fix.smem_start = (pinfo->frame_buffer_phys) + init->fb_offset + offset;
146 mutex_unlock(&info->mm_lock);
145 info->fix.visual = (pinfo->cmode == CMODE_8) ? 147 info->fix.visual = (pinfo->cmode == CMODE_8) ?
146 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR; 148 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
147 info->fix.line_length = vmode_attrs[pinfo->vmode-1].hres * (1<<pinfo->cmode) 149 info->fix.line_length = vmode_attrs[pinfo->vmode-1].hres * (1<<pinfo->cmode)
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
index 0889d50c3288..6506117c134b 100644
--- a/drivers/video/pxafb.c
+++ b/drivers/video/pxafb.c
@@ -815,8 +815,10 @@ static int overlayfb_map_video_memory(struct pxafb_layer *ofb)
815 ofb->video_mem_phys = virt_to_phys(ofb->video_mem); 815 ofb->video_mem_phys = virt_to_phys(ofb->video_mem);
816 ofb->video_mem_size = size; 816 ofb->video_mem_size = size;
817 817
818 mutex_lock(&ofb->fb.mm_lock);
818 ofb->fb.fix.smem_start = ofb->video_mem_phys; 819 ofb->fb.fix.smem_start = ofb->video_mem_phys;
819 ofb->fb.fix.smem_len = ofb->fb.fix.line_length * var->yres_virtual; 820 ofb->fb.fix.smem_len = ofb->fb.fix.line_length * var->yres_virtual;
821 mutex_unlock(&ofb->fb.mm_lock);
820 ofb->fb.screen_base = ofb->video_mem; 822 ofb->fb.screen_base = ofb->video_mem;
821 return 0; 823 return 0;
822} 824}
diff --git a/drivers/video/sh7760fb.c b/drivers/video/sh7760fb.c
index 653bdfee3057..9f6d6e61f0cc 100644
--- a/drivers/video/sh7760fb.c
+++ b/drivers/video/sh7760fb.c
@@ -120,18 +120,6 @@ static int sh7760_setcolreg (u_int regno,
120 return 0; 120 return 0;
121} 121}
122 122
123static void encode_fix(struct fb_fix_screeninfo *fix, struct fb_info *info,
124 unsigned long stride)
125{
126 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
127 strcpy(fix->id, "sh7760-lcdc");
128
129 fix->smem_start = (unsigned long)info->screen_base;
130 fix->smem_len = info->screen_size;
131
132 fix->line_length = stride;
133}
134
135static int sh7760fb_get_color_info(struct device *dev, 123static int sh7760fb_get_color_info(struct device *dev,
136 u16 lddfr, int *bpp, int *gray) 124 u16 lddfr, int *bpp, int *gray)
137{ 125{
@@ -334,7 +322,8 @@ static int sh7760fb_set_par(struct fb_info *info)
334 322
335 iowrite32(ldsarl, par->base + LDSARL); /* mem for lower half of DSTN */ 323 iowrite32(ldsarl, par->base + LDSARL); /* mem for lower half of DSTN */
336 324
337 encode_fix(&info->fix, info, stride); 325 info->fix.line_length = stride;
326
338 sh7760fb_check_var(&info->var, info); 327 sh7760fb_check_var(&info->var, info);
339 328
340 sh7760fb_blank(FB_BLANK_UNBLANK, info); /* panel on! */ 329 sh7760fb_blank(FB_BLANK_UNBLANK, info); /* panel on! */
@@ -435,6 +424,8 @@ static int sh7760fb_alloc_mem(struct fb_info *info)
435 424
436 info->screen_base = fbmem; 425 info->screen_base = fbmem;
437 info->screen_size = vram; 426 info->screen_size = vram;
427 info->fix.smem_start = (unsigned long)info->screen_base;
428 info->fix.smem_len = info->screen_size;
438 429
439 return 0; 430 return 0;
440} 431}
@@ -520,6 +511,8 @@ static int __devinit sh7760fb_probe(struct platform_device *pdev)
520 info->var.transp.length = 0; 511 info->var.transp.length = 0;
521 info->var.transp.msb_right = 0; 512 info->var.transp.msb_right = 0;
522 513
514 strcpy(info->fix.id, "sh7760-lcdc");
515
523 /* set the DON2 bit now, before cmap allocation, as it will randomize 516 /* set the DON2 bit now, before cmap allocation, as it will randomize
524 * palette memory. 517 * palette memory.
525 */ 518 */
diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
index f10d2fbeda06..da983b720f08 100644
--- a/drivers/video/sh_mobile_lcdcfb.c
+++ b/drivers/video/sh_mobile_lcdcfb.c
@@ -17,6 +17,7 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/dma-mapping.h> 18#include <linux/dma-mapping.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/vmalloc.h>
20#include <video/sh_mobile_lcdc.h> 21#include <video/sh_mobile_lcdc.h>
21#include <asm/atomic.h> 22#include <asm/atomic.h>
22 23
@@ -33,6 +34,7 @@ struct sh_mobile_lcdc_chan {
33 struct fb_info info; 34 struct fb_info info;
34 dma_addr_t dma_handle; 35 dma_addr_t dma_handle;
35 struct fb_deferred_io defio; 36 struct fb_deferred_io defio;
37 struct scatterlist *sglist;
36 unsigned long frame_end; 38 unsigned long frame_end;
37 wait_queue_head_t frame_end_wait; 39 wait_queue_head_t frame_end_wait;
38}; 40};
@@ -206,16 +208,38 @@ static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv) {}
206static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv) {} 208static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv) {}
207#endif 209#endif
208 210
211static int sh_mobile_lcdc_sginit(struct fb_info *info,
212 struct list_head *pagelist)
213{
214 struct sh_mobile_lcdc_chan *ch = info->par;
215 unsigned int nr_pages_max = info->fix.smem_len >> PAGE_SHIFT;
216 struct page *page;
217 int nr_pages = 0;
218
219 sg_init_table(ch->sglist, nr_pages_max);
220
221 list_for_each_entry(page, pagelist, lru)
222 sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
223
224 return nr_pages;
225}
226
209static void sh_mobile_lcdc_deferred_io(struct fb_info *info, 227static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
210 struct list_head *pagelist) 228 struct list_head *pagelist)
211{ 229{
212 struct sh_mobile_lcdc_chan *ch = info->par; 230 struct sh_mobile_lcdc_chan *ch = info->par;
231 unsigned int nr_pages;
213 232
214 /* enable clocks before accessing hardware */ 233 /* enable clocks before accessing hardware */
215 sh_mobile_lcdc_clk_on(ch->lcdc); 234 sh_mobile_lcdc_clk_on(ch->lcdc);
216 235
236 nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
237 dma_map_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
238
217 /* trigger panel update */ 239 /* trigger panel update */
218 lcdc_write_chan(ch, LDSM2R, 1); 240 lcdc_write_chan(ch, LDSM2R, 1);
241
242 dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
219} 243}
220 244
221static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info) 245static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
@@ -846,21 +870,31 @@ static int __init sh_mobile_lcdc_probe(struct platform_device *pdev)
846 } 870 }
847 871
848 for (i = 0; i < j; i++) { 872 for (i = 0; i < j; i++) {
849 error = register_framebuffer(&priv->ch[i].info); 873 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
874
875 info = &ch->info;
876
877 if (info->fbdefio) {
878 priv->ch->sglist = vmalloc(sizeof(struct scatterlist) *
879 info->fix.smem_len >> PAGE_SHIFT);
880 if (!priv->ch->sglist) {
881 dev_err(&pdev->dev, "cannot allocate sglist\n");
882 goto err1;
883 }
884 }
885
886 error = register_framebuffer(info);
850 if (error < 0) 887 if (error < 0)
851 goto err1; 888 goto err1;
852 }
853 889
854 for (i = 0; i < j; i++) {
855 info = &priv->ch[i].info;
856 dev_info(info->dev, 890 dev_info(info->dev,
857 "registered %s/%s as %dx%d %dbpp.\n", 891 "registered %s/%s as %dx%d %dbpp.\n",
858 pdev->name, 892 pdev->name,
859 (priv->ch[i].cfg.chan == LCDC_CHAN_MAINLCD) ? 893 (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
860 "mainlcd" : "sublcd", 894 "mainlcd" : "sublcd",
861 (int) priv->ch[i].cfg.lcd_cfg.xres, 895 (int) ch->cfg.lcd_cfg.xres,
862 (int) priv->ch[i].cfg.lcd_cfg.yres, 896 (int) ch->cfg.lcd_cfg.yres,
863 priv->ch[i].cfg.bpp); 897 ch->cfg.bpp);
864 898
865 /* deferred io mode: disable clock to save power */ 899 /* deferred io mode: disable clock to save power */
866 if (info->fbdefio) 900 if (info->fbdefio)
@@ -892,6 +926,9 @@ static int sh_mobile_lcdc_remove(struct platform_device *pdev)
892 if (!info->device) 926 if (!info->device)
893 continue; 927 continue;
894 928
929 if (priv->ch[i].sglist)
930 vfree(priv->ch[i].sglist);
931
895 dma_free_coherent(&pdev->dev, info->fix.smem_len, 932 dma_free_coherent(&pdev->dev, info->fix.smem_len,
896 info->screen_base, priv->ch[i].dma_handle); 933 info->screen_base, priv->ch[i].dma_handle);
897 fb_dealloc_cmap(&info->cmap); 934 fb_dealloc_cmap(&info->cmap);
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index 7072d19080d5..fd33455389b8 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -1847,8 +1847,10 @@ sisfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
1847 1847
1848 strcpy(fix->id, ivideo->myid); 1848 strcpy(fix->id, ivideo->myid);
1849 1849
1850 mutex_lock(&info->mm_lock);
1850 fix->smem_start = ivideo->video_base + ivideo->video_offset; 1851 fix->smem_start = ivideo->video_base + ivideo->video_offset;
1851 fix->smem_len = ivideo->sisfb_mem; 1852 fix->smem_len = ivideo->sisfb_mem;
1853 mutex_unlock(&info->mm_lock);
1852 fix->type = FB_TYPE_PACKED_PIXELS; 1854 fix->type = FB_TYPE_PACKED_PIXELS;
1853 fix->type_aux = 0; 1855 fix->type_aux = 0;
1854 fix->visual = (ivideo->video_bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; 1856 fix->visual = (ivideo->video_bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
diff --git a/drivers/video/sm501fb.c b/drivers/video/sm501fb.c
index eb5d73a06702..16d4f4c7d52b 100644
--- a/drivers/video/sm501fb.c
+++ b/drivers/video/sm501fb.c
@@ -145,7 +145,7 @@ static inline void sm501fb_sync_regs(struct sm501fb_info *info)
145#define SM501_MEMF_ACCEL (8) 145#define SM501_MEMF_ACCEL (8)
146 146
147static int sm501_alloc_mem(struct sm501fb_info *inf, struct sm501_mem *mem, 147static int sm501_alloc_mem(struct sm501fb_info *inf, struct sm501_mem *mem,
148 unsigned int why, size_t size) 148 unsigned int why, size_t size, u32 smem_len)
149{ 149{
150 struct sm501fb_par *par; 150 struct sm501fb_par *par;
151 struct fb_info *fbi; 151 struct fb_info *fbi;
@@ -172,7 +172,7 @@ static int sm501_alloc_mem(struct sm501fb_info *inf, struct sm501_mem *mem,
172 if (ptr > 0) 172 if (ptr > 0)
173 ptr &= ~(PAGE_SIZE - 1); 173 ptr &= ~(PAGE_SIZE - 1);
174 174
175 if (fbi && ptr < fbi->fix.smem_len) 175 if (fbi && ptr < smem_len)
176 return -ENOMEM; 176 return -ENOMEM;
177 177
178 break; 178 break;
@@ -197,7 +197,7 @@ static int sm501_alloc_mem(struct sm501fb_info *inf, struct sm501_mem *mem,
197 197
198 case SM501_MEMF_ACCEL: 198 case SM501_MEMF_ACCEL:
199 fbi = inf->fb[HEAD_CRT]; 199 fbi = inf->fb[HEAD_CRT];
200 ptr = fbi ? fbi->fix.smem_len : 0; 200 ptr = fbi ? smem_len : 0;
201 201
202 fbi = inf->fb[HEAD_PANEL]; 202 fbi = inf->fb[HEAD_PANEL];
203 if (fbi) { 203 if (fbi) {
@@ -413,6 +413,7 @@ static int sm501fb_set_par_common(struct fb_info *info,
413 unsigned int mem_type; 413 unsigned int mem_type;
414 unsigned int clock_type; 414 unsigned int clock_type;
415 unsigned int head_addr; 415 unsigned int head_addr;
416 unsigned int smem_len;
416 417
417 dev_dbg(fbi->dev, "%s: %dx%d, bpp = %d, virtual %dx%d\n", 418 dev_dbg(fbi->dev, "%s: %dx%d, bpp = %d, virtual %dx%d\n",
418 __func__, var->xres, var->yres, var->bits_per_pixel, 419 __func__, var->xres, var->yres, var->bits_per_pixel,
@@ -453,18 +454,20 @@ static int sm501fb_set_par_common(struct fb_info *info,
453 454
454 /* allocate fb memory within 501 */ 455 /* allocate fb memory within 501 */
455 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel)/8; 456 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel)/8;
456 info->fix.smem_len = info->fix.line_length * var->yres_virtual; 457 smem_len = info->fix.line_length * var->yres_virtual;
457 458
458 dev_dbg(fbi->dev, "%s: line length = %u\n", __func__, 459 dev_dbg(fbi->dev, "%s: line length = %u\n", __func__,
459 info->fix.line_length); 460 info->fix.line_length);
460 461
461 if (sm501_alloc_mem(fbi, &par->screen, mem_type, 462 if (sm501_alloc_mem(fbi, &par->screen, mem_type, smem_len, smem_len)) {
462 info->fix.smem_len)) {
463 dev_err(fbi->dev, "no memory available\n"); 463 dev_err(fbi->dev, "no memory available\n");
464 return -ENOMEM; 464 return -ENOMEM;
465 } 465 }
466 466
467 mutex_lock(&info->mm_lock);
467 info->fix.smem_start = fbi->fbmem_res->start + par->screen.sm_addr; 468 info->fix.smem_start = fbi->fbmem_res->start + par->screen.sm_addr;
469 info->fix.smem_len = smem_len;
470 mutex_unlock(&info->mm_lock);
468 471
469 info->screen_base = fbi->fbmem + par->screen.sm_addr; 472 info->screen_base = fbi->fbmem + par->screen.sm_addr;
470 info->screen_size = info->fix.smem_len; 473 info->screen_size = info->fix.smem_len;
@@ -637,7 +640,8 @@ static int sm501fb_set_par_crt(struct fb_info *info)
637 if ((control & SM501_DC_CRT_CONTROL_SEL) == 0) { 640 if ((control & SM501_DC_CRT_CONTROL_SEL) == 0) {
638 /* the head is displaying panel data... */ 641 /* the head is displaying panel data... */
639 642
640 sm501_alloc_mem(fbi, &par->screen, SM501_MEMF_CRT, 0); 643 sm501_alloc_mem(fbi, &par->screen, SM501_MEMF_CRT, 0,
644 info->fix.smem_len);
641 goto out_update; 645 goto out_update;
642 } 646 }
643 647
@@ -1289,7 +1293,8 @@ static int sm501_init_cursor(struct fb_info *fbi, unsigned int reg_base)
1289 1293
1290 par->cursor_regs = info->regs + reg_base; 1294 par->cursor_regs = info->regs + reg_base;
1291 1295
1292 ret = sm501_alloc_mem(info, &par->cursor, SM501_MEMF_CURSOR, 1024); 1296 ret = sm501_alloc_mem(info, &par->cursor, SM501_MEMF_CURSOR, 1024,
1297 fbi->fix.smem_len);
1293 if (ret < 0) 1298 if (ret < 0)
1294 return ret; 1299 return ret;
1295 1300
@@ -1619,6 +1624,8 @@ static int __devinit sm501fb_start_one(struct sm501fb_info *info,
1619 if (!fbi) 1624 if (!fbi)
1620 return 0; 1625 return 0;
1621 1626
1627 mutex_init(&info->fb[head]->mm_lock);
1628
1622 ret = sm501fb_init_fb(info->fb[head], head, drvname); 1629 ret = sm501fb_init_fb(info->fb[head], head, drvname);
1623 if (ret) { 1630 if (ret) {
1624 dev_err(info->dev, "cannot initialise fb %s\n", drvname); 1631 dev_err(info->dev, "cannot initialise fb %s\n", drvname);
diff --git a/drivers/video/w100fb.c b/drivers/video/w100fb.c
index d0674f1e3f10..8a141c2c637b 100644
--- a/drivers/video/w100fb.c
+++ b/drivers/video/w100fb.c
@@ -523,6 +523,7 @@ static int w100fb_set_par(struct fb_info *info)
523 info->fix.ywrapstep = 0; 523 info->fix.ywrapstep = 0;
524 info->fix.line_length = par->xres * BITS_PER_PIXEL / 8; 524 info->fix.line_length = par->xres * BITS_PER_PIXEL / 8;
525 525
526 mutex_lock(&info->mm_lock);
526 if ((par->xres*par->yres*BITS_PER_PIXEL/8) > (MEM_INT_SIZE+1)) { 527 if ((par->xres*par->yres*BITS_PER_PIXEL/8) > (MEM_INT_SIZE+1)) {
527 par->extmem_active = 1; 528 par->extmem_active = 1;
528 info->fix.smem_len = par->mach->mem->size+1; 529 info->fix.smem_len = par->mach->mem->size+1;
@@ -530,6 +531,7 @@ static int w100fb_set_par(struct fb_info *info)
530 par->extmem_active = 0; 531 par->extmem_active = 0;
531 info->fix.smem_len = MEM_INT_SIZE+1; 532 info->fix.smem_len = MEM_INT_SIZE+1;
532 } 533 }
534 mutex_unlock(&info->mm_lock);
533 535
534 w100fb_activate_var(par); 536 w100fb_activate_var(par);
535 } 537 }
diff --git a/drivers/watchdog/wdrtas.c b/drivers/watchdog/wdrtas.c
index a4fe7a38d9b0..3bde56bce63a 100644
--- a/drivers/watchdog/wdrtas.c
+++ b/drivers/watchdog/wdrtas.c
@@ -218,16 +218,14 @@ static void wdrtas_timer_keepalive(void)
218 */ 218 */
219static int wdrtas_get_temperature(void) 219static int wdrtas_get_temperature(void)
220{ 220{
221 long result; 221 int result;
222 int temperature = 0; 222 int temperature = 0;
223 223
224 result = rtas_call(wdrtas_token_get_sensor_state, 2, 2, 224 result = rtas_get_sensor(WDRTAS_THERMAL_SENSOR, 0, &temperature);
225 (void *)__pa(&temperature),
226 WDRTAS_THERMAL_SENSOR, 0);
227 225
228 if (result < 0) 226 if (result < 0)
229 printk(KERN_WARNING "wdrtas: reading the thermal sensor " 227 printk(KERN_WARNING "wdrtas: reading the thermal sensor "
230 "faild: %li\n", result); 228 "failed: %i\n", result);
231 else 229 else
232 temperature = ((temperature * 9) / 5) + 32; /* fahrenheit */ 230 temperature = ((temperature * 9) / 5) + 32; /* fahrenheit */
233 231
diff --git a/firmware/Makefile b/firmware/Makefile
index 621de8e952f7..44313b25580f 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -41,7 +41,10 @@ fw-shipped-$(CONFIG_CASSINI) += sun/cassini.bin
41fw-shipped-$(CONFIG_COMPUTONE) += intelliport2.bin 41fw-shipped-$(CONFIG_COMPUTONE) += intelliport2.bin
42fw-shipped-$(CONFIG_CHELSIO_T3) += cxgb3/t3b_psram-1.1.0.bin \ 42fw-shipped-$(CONFIG_CHELSIO_T3) += cxgb3/t3b_psram-1.1.0.bin \
43 cxgb3/t3c_psram-1.1.0.bin \ 43 cxgb3/t3c_psram-1.1.0.bin \
44 cxgb3/t3fw-7.4.0.bin 44 cxgb3/t3fw-7.4.0.bin \
45 cxgb3/ael2005_opt_edc.bin \
46 cxgb3/ael2005_twx_edc.bin \
47 cxgb3/ael2020_twx_edc.bin
45fw-shipped-$(CONFIG_DVB_AV7110) += av7110/bootcode.bin 48fw-shipped-$(CONFIG_DVB_AV7110) += av7110/bootcode.bin
46fw-shipped-$(CONFIG_DVB_TTUSB_BUDGET) += ttusb-budget/dspbootcode.bin 49fw-shipped-$(CONFIG_DVB_TTUSB_BUDGET) += ttusb-budget/dspbootcode.bin
47fw-shipped-$(CONFIG_E100) += e100/d101m_ucode.bin e100/d101s_ucode.bin \ 50fw-shipped-$(CONFIG_E100) += e100/d101m_ucode.bin e100/d101s_ucode.bin \
diff --git a/firmware/WHENCE b/firmware/WHENCE
index 0f5649a08c0c..d9e3a94cb4df 100644
--- a/firmware/WHENCE
+++ b/firmware/WHENCE
@@ -418,6 +418,23 @@ License: GPLv2 or OpenIB.org BSD license, no source visible
418 418
419-------------------------------------------------------------------------- 419--------------------------------------------------------------------------
420 420
421Driver: cxgb3 - Chelsio Terminator 3 1G/10G Ethernet adapter
422
423File: cxgb3/ael2005_opt_edc.bin.ihex
424File: cxgb3/ael2005_twx_edc.bin.ihex
425File: cxgb3/ael2020_twx_edc.bin.ihex
426
427Licence:
428 * Copyright (c) 2007-2009 NetLogic Microsystems, Inc.
429 *
430 * Permission is hereby granted for the distribution of this firmware
431 * data in hexadecimal or equivalent format, provided this copyright
432 * notice is accompanying it.
433
434Found in hex form in kernel source.
435
436--------------------------------------------------------------------------
437
421Driver: e100 -- Intel PRO/100 Ethernet NIC 438Driver: e100 -- Intel PRO/100 Ethernet NIC
422 439
423File: e100/d101m_ucode.bin 440File: e100/d101m_ucode.bin
diff --git a/firmware/cxgb3/ael2005_opt_edc.bin.ihex b/firmware/cxgb3/ael2005_opt_edc.bin.ihex
new file mode 100644
index 000000000000..c1d6e5d3bea7
--- /dev/null
+++ b/firmware/cxgb3/ael2005_opt_edc.bin.ihex
@@ -0,0 +1,69 @@
1:10000000CC002FF4CC013CD4CC022015CC0331051C
2:10001000CC046524CC0527FFCC06300FCC072C8BF5
3:10002000CC08300BCC094009CC0A400ECC0B2F7207
4:10003000CC0C3002CC0D1002CC0E2172CC0F301241
5:10004000CC101002CC1125D2CC123012CC131002DD
6:10005000CC14D01ECC1527D2CC163012CC171002DF
7:10006000CC182004CC193C84CC1A6436CC1B200755
8:10007000CC1C3F87CC1D8676CC1E40B7CC1FA74634
9:10008000CC204047CC215673CC222982CC2330028D
10:10009000CC2413D2CC258BBDCC262862CC273012A1
11:1000A000CC281002CC292092CC2A3012CC2B100262
12:1000B000CC2C5CC3CC2D0314CC2E2942CC2F300287
13:1000C000CC301002CC31D019CC322032CC333012AB
14:1000D000CC341002CC352A04CC363C74CC37643591
15:1000E000CC382FA4CC393CD4CC3A6624CC3B5563D5
16:1000F000CC3C2D42CC3D3002CC3E13D2CC3F464DC1
17:10010000CC402862CC413012CC421002CC43203289
18:10011000CC443012CC451002CC462FB4CC473CD452
19:10012000CC486624CC495563CC4A2D42CC4B300296
20:10013000CC4C13D2CC4D2ED2CC4E3002CC4F100230
21:10014000CC502FD2CC513002CC521002CC530004F0
22:10015000CC542942CC553002CC561002CC572092B8
23:10016000CC583012CC591002CC5A5CC3CC5B03176C
24:10017000CC5C2F72CC5D3002CC5E1002CC5F294289
25:10018000CC603002CC611002CC6222CDCC63301D39
26:10019000CC642862CC653012CC661002CC672ED2BB
27:1001A000CC683002CC691002CC6A2D72CC6B300264
28:1001B000CC6C1002CC6D628FCC6E2112CC6F3012E1
29:1001C000CC701002CC715AA3CC722DC2CC73300209
30:1001D000CC741312CC756F72CC761002CC772807D2
31:1001E000CC7831A7CC7920C4CC7A3C24CC7B672452
32:1001F000CC7C1002CC7D2807CC7E3187CC7F20C4FC
33:10020000CC803C24CC816724CC821002CC83251482
34:10021000CC843C64CC856436CC86DFF4CC876436F1
35:10022000CC881002CC8940A4CC8A643CCC8B40168C
36:10023000CC8C8C6CCC8D2B24CC8E3C24CC8F643518
37:10024000CC901002CC912B24CC923C24CC93643AD9
38:10025000CC944025CC958A5ACC961002CC97273165
39:10026000CC983011CC991001CC9AC7A0CC9B01003E
40:10027000CC9CC502CC9D53ACCC9EC503CC9FD5D5A0
41:10028000CCA0C600CCA12A6DCCA2C601CCA32A4C1E
42:10029000CCA4C602CCA50111CCA6C60CCCA7590093
43:1002A000CCA8C710CCA90700CCAAC718CCAB0700B4
44:1002B000CCACC720CCAD4700CCAEC801CCAF7F5092
45:1002C000CCB0C802CCB17760CCB2C803CCB37FCE7F
46:1002D000CCB4C804CCB55700CCB6C805CCB75F11B8
47:1002E000CCB8C806CCB94751CCBAC807CCBB57E18B
48:1002F000CCBCC808CCBD2700CCBEC809CCBF000010
49:10030000CCC0C821CCC10002CCC2C822CCC30014CE
50:10031000CCC4C832CCC51186CCC6C847CCC71E02D7
51:10032000CCC8C013CCC9F341CCCAC01ACCCB04464C
52:10033000CCCCC024CCCD1000CCCEC025CCCF0A0074
53:10034000CCD0C026CCD10C0CCCD2C027CCD30C0C3A
54:10035000CCD4C029CCD500A0CCD6C030CCD70A0094
55:10036000CCD8C03CCCD9001CCCDAC005CCDB7A069A
56:10037000CCDC0000CCDD2731CCDE3011CCDF10012D
57:10038000CCE0C620CCE10000CCE2C621CCE3003FAB
58:10039000CCE4C622CCE50000CCE6C623CCE70000C6
59:1003A000CCE8C624CCE90000CCEAC625CCEB0000A2
60:1003B000CCECC627CCED0000CCEEC628CCEF00007C
61:1003C000CCF0C62CCCF10000CCF20000CCF3280617
62:1003D000CCF43CB6CCF5C161CCF66134CCF76135D8
63:1003E000CCF85443CCF90303CCFA6524CCFB000BC6
64:1003F000CCFC1002CCFD2104CCFE3C24CCFF21051A
65:10040000CD003805CD016524CD02DFF4CD034005D4
66:10041000CD046524CD051002CD065DD3CD070306BE
67:10042000CD082FF7CD0938F7CD0A60B7CD0BDFFD2A
68:10043000CD0C000ACD0D1002CD0E00007CC7AE59C8
69:00000001FF
diff --git a/firmware/cxgb3/ael2005_twx_edc.bin.ihex b/firmware/cxgb3/ael2005_twx_edc.bin.ihex
new file mode 100644
index 000000000000..9b5e9e51fcb7
--- /dev/null
+++ b/firmware/cxgb3/ael2005_twx_edc.bin.ihex
@@ -0,0 +1,93 @@
1:10000000CC004009CC0127FFCC02300FCC0340AA22
2:10001000CC04401CCC05401ECC062FF4CC073CD4AD
3:10002000CC082035CC093145CC0A6524CC0B26A25E
4:10003000CC0C3012CC0D1002CC0E29C2CC0F3002E9
5:10004000CC101002CC112072CC123012CC13100242
6:10005000CC1422CDCC15301DCC162E52CC1730121C
7:10006000CC181002CC1928E2CC1A3002CC1B10029A
8:10007000CC1C628FCC1D2AC2CC1E3012CC1F1002A9
9:10008000CC205553CC212AE2CC223002CC231302BF
10:10009000CC24401ECC252BE2CC263012CC271002DB
11:1000A000CC282DA2CC293012CC2A1002CC2B2BA28A
12:1000B000CC2C3002CC2D1002CC2E5EE3CC2F0305CD
13:1000C000CC30400ECC312BC2CC323002CC331002BB
14:1000D000CC342B82CC353012CC361002CC37566360
15:1000E000CC380302CC39401ECC3A6F72CC3B1002A4
16:1000F000CC3C628FCC3D2BE2CC3E3012CC3F100288
17:10010000CC4022CDCC41301DCC422E52CC433012BB
18:10011000CC441002CC452522CC463012CC471002EC
19:10012000CC482DA2CC493012CC4A1002CC4B2CA288
20:10013000CC4C3012CC4D1002CC4E2FA4CC4F3CD422
21:10014000CC506624CC51410BCC5256B3CC5303C493
22:10015000CC542FB2CC553002CC561002CC57220BC7
23:10016000CC58303BCC5956B3CC5A03C3CC5B866BCE
24:10017000CC5C400CCC5D23A2CC5E3012CC5F100274
25:10018000CC602DA2CC613012CC621002CC632CA2C8
26:10019000CC643012CC651002CC662FB4CC673CD452
27:1001A000CC686624CC6956B3CC6A03C3CC6B866B2F
28:1001B000CC6C401CCC6D2205CC6E3035CC6F5B53C3
29:1001C000CC702C52CC713002CC7213C2CC735CC395
30:1001D000CC740317CC752522CC763012CC77100264
31:1001E000CC782DA2CC793012CC7A1002CC7B2B8229
32:1001F000CC7C3012CC7D1002CC7E5663CC7F0303C6
33:10020000CC80401ECC810004CC822C42CC833012A6
34:10021000CC841002CC856F72CC861002CC87628FA2
35:10022000CC882304CC893C84CC8A6436CC8BDFF424
36:10023000CC8C6436CC8D2FF5CC8E3005CC8F865689
37:10024000CC90DFBACC9156A3CC92D05ACC9321C299
38:10025000CC943012CC951392CC96D05ACC9756A30E
39:10026000CC98DFBACC990383CC9A6F72CC9B1002E6
40:10027000CC9C28C5CC9D3005CC9E4178CC9F565354
41:10028000CCA00384CCA122B2CCA23012CCA3100209
42:10029000CCA42BE5CCA53005CCA641E8CCA7565381
43:1002A000CCA80382CCA90002CCAA4258CCAB2474BF
44:1002B000CCAC3C84CCAD6437CCAEDFF4CCAF64378F
45:1002C000CCB02FF5CCB13C05CCB28757CCB3B888B5
46:1002D000CCB49787CCB5DFF4CCB66724CCB7866AAC
47:1002E000CCB86F72CCB91002CCBA2D01CCBB301196
48:1002F000CCBC1001CCBDC620CCBE14E5CCBFC62101
49:10030000CCC0C53DCCC1C622CCC23CBECCC3C623EA
50:10031000CCC44452CCC5C624CCC6C5C5CCC7C625A2
51:10032000CCC8E01ECCC9C627CCCA0000CCCBC6289E
52:10033000CCCC0000CCCDC62BCCCE0000CCCFC62C74
53:10034000CCD00000CCD10000CCD22D01CCD33011C8
54:10035000CCD41001CCD5C620CCD60000CCD7C62139
55:10036000CCD80000CCD9C622CCDA00CECCDBC62358
56:10037000CCDC007FCCDDC624CCDE0032CCDFC62551
57:10038000CCE00000CCE1C627CCE20000CCE3C628DC
58:10039000CCE40000CCE5C62BCCE60000CCE7C62CB4
59:1003A000CCE80000CCE90000CCEA2D01CCEB301108
60:1003B000CCEC1001CCEDC502CCEE609FCCEFC600BA
61:1003C000CCF02A6ECCF1C601CCF22A2CCCF3C60CB0
62:1003D000CCF45400CCF5C710CCF60700CCF7C71806
63:1003E000CCF80700CCF9C720CCFA4700CCFBC728D3
64:1003F000CCFC0700CCFDC729CCFE1207CCFFC801FE
65:10040000CD007F50CD01C802CD027760CD03C80377
66:10041000CD047FCECD05C804CD06520ECD07C8054C
67:10042000CD085C11CD09C806CD0A3C51CD0BC807DB
68:10043000CD0C4061CD0DC808CD0E49C1CD0FC80906
69:10044000CD103840CD11C80ACD120000CD13C821FF
70:10045000CD140002CD15C822CD160046CD17C844D4
71:10046000CD18182FCD19C013CD1AF341CD1BC01ACA
72:10047000CD1C0446CD1DC024CD1E1000CD1FC025AF
73:10048000CD200A00CD21C026CD220C0CCD23C027C3
74:10049000CD240C0CCD25C029CD2600A0CD27C03001
75:1004A000CD280A00CD29C03CCD2A001CCD2B000050
76:1004B000CD2C2B84CD2D3C74CD2E6435CD2FDFF487
77:1004C000CD306435CD312806CD323006CD3385654B
78:1004D000CD342B24CD353C24CD366436CD371002B7
79:1004E000CD382B24CD393C24CD3A6436CD3B404524
80:1004F000CD3C8656CD3D1002CD3E2807CD3F31A7DD
81:10050000CD4020C4CD413C24CD426724CD431002D0
82:10051000CD442807CD453187CD4620C4CD473C2466
83:10052000CD486724CD491002CD4A2514CD4B3C64FB
84:10053000CD4C6436CD4DDFF4CD4E6436CD4F100238
85:10054000CD502806CD513CB6CD52C161CD5361345A
86:10055000CD546135CD555443CD560303CD57652455
87:10056000CD58000BCD591002CD5AD019CD5B2104C6
88:10057000CD5C3C24CD5D2105CD5E3805CD5F652485
89:10058000CD60DFF4CD614005CD626524CD632E8D55
90:10059000CD64303DCD655DD3CD660306CD672FF7C5
91:1005A000CD6838F7CD6960B7CD6ADFFDCD6B000A45
92:0C05B000CD6C1002CD6D000052A76B0E48
93:00000001FF
diff --git a/firmware/cxgb3/ael2020_twx_edc.bin.ihex b/firmware/cxgb3/ael2020_twx_edc.bin.ihex
new file mode 100644
index 000000000000..8b1337f4c329
--- /dev/null
+++ b/firmware/cxgb3/ael2020_twx_edc.bin.ihex
@@ -0,0 +1,100 @@
1:10000000D8004009D8012FFFD802300FD80340AAEA
2:10001000D804401CD805401ED8062FF4D8073DC48C
3:10002000D8082035D8093035D80A6524D80B2CB229
4:10003000D80C3012D80D1002D80E26E2D80F30227C
5:10004000D8101002D81127D2D8123022D81310029B
6:10005000D8142822D8153012D8161002D817249296
7:10006000D8183022D8191002D81A2772D81B30128B
8:10007000D81C1002D81D23D2D81E3022D81F10023F
9:10008000D82022CDD821301DD82227F2D8233022E3
10:10009000D8241002D8255553D8260307D82725225F
11:1000A000D8283022D8291002D82A2142D82B301241
12:1000B000D82C1002D82D4016D82E5E63D82F0344BA
13:1000C000D8302142D8313012D8321002D833400E05
14:1000D000D8342522D8353022D8361002D8372B52C2
15:1000E000D8383012D8391002D83A2742D83B3022BB
16:1000F000D83C1002D83D25E2D83E3022D83F10022D
17:10010000D8402FA4D8413DC4D8426624D843414B9F
18:10011000D84456B3D84503C6D846866BD847400C5A
19:10012000D8482712D8493012D84A1002D84B2C4B45
20:10013000D84C309BD84D56B3D84E03C3D84F866B9E
21:10014000D850400CD8512272D8523022D8531002C5
22:10015000D8542742D8553022D8561002D85725E215
23:10016000D8583022D8591002D85A2FB4D85B3DC481
24:10017000D85C6624D85D56B3D85E03C3D85F866B5F
25:10018000D860401CD8612C45D8623095D8635B5349
26:10019000D8642372D8653012D86613C2D8675CC39E
27:1001A000D8682712D8693012D86A1312D86B2B522C
28:1001B000D86C3012D86D1002D86E2742D86F30221A
29:1001C000D8701002D8712582D8723022D8731002EC
30:1001D000D8742142D8753012D8761002D877628F41
31:1001E000D8782985D87933A5D87A25E2D87B3022EA
32:1001F000D87C1002D87D5653D87E03D2D87F401EBB
33:10020000D8806F72D8811002D882628FD88323047D
34:10021000D8843C84D8856436D886DFF4D8876436A1
35:10022000D8882FF5D8893005D88A8656D88BDFBA7A
36:10023000D88C56A3D88DD05AD88E2972D88F301228
37:10024000D8901392D891D05AD89256A3D893DFBAA7
38:10025000D8940383D8956F72D8961002D8972B45FF
39:10026000D8983005D8994178D89A5653D89B0384AA
40:10027000D89C2A62D89D3012D89E1002D89F2F0594
41:10028000D8A03005D8A141C8D8A25653D8A303821C
42:10029000D8A40002D8A54218D8A62474D8A73C84B4
43:1002A000D8A86437D8A9DFF4D8AA6437D8AB2FF51B
44:1002B000D8AC3C05D8AD8757D8AEB888D8AF9787AB
45:1002C000D8B0DFF4D8B16724D8B2866AD8B36F72D9
46:1002D000D8B41002D8B52641D8B63021D8B710010D
47:1002E000D8B8C620D8B90000D8BAC621D8BB0000FB
48:1002F000D8BCC622D8BD00CED8BEC623D8BF007F8A
49:10030000D8C0C624D8C10032D8C2C625D8C3000080
50:10031000D8C4C627D8C50000D8C6C628D8C700008C
51:10032000D8C8C62CD8C90000D8CA0000D8CB2641EE
52:10033000D8CC3021D8CD1001D8CEC502D8CF53ACFF
53:10034000D8D0C503D8D12CD3D8D2C600D8D32A6EE2
54:10035000D8D4C601D8D52A2CD8D6C605D8D7555753
55:10036000D8D8C60CD8D95400D8DAC710D8DB0700C3
56:10037000D8DCC711D8DD0F06D8DEC718D8DF0700D4
57:10038000D8E0C719D8E10F06D8E2C720D8E3470064
58:10039000D8E4C721D8E50F06D8E6C728D8E7070074
59:1003A000D8E8C729D8E91207D8EAC801D8EB7F50A6
60:1003B000D8ECC802D8ED7760D8EEC803D8EF7FCE6E
61:1003C000D8F0C804D8F1520ED8F2C805D8F35C11A1
62:1003D000D8F4C806D8F53C51D8F6C807D8F740611C
63:1003E000D8F8C808D8F949C1D8FAC809D8FB3840A4
64:1003F000D8FCC80AD8FD0000D8FEC821D8FF0002EA
65:10040000D900C822D9010046D902C844D903182FFF
66:10041000D904C013D905F341D906C084D9070030E7
67:10042000D908C904D9091401D90ACB0CD90B000485
68:10043000D90CCB0ED90DA00AD90ECB0FD90FC0C045
69:10044000D910CB10D911C0C0D912CB11D91300A02B
70:10045000D914CB12D9150007D916C241D917A0005B
71:10046000D918C243D9197FE0D91AC604D91B000E86
72:10047000D91CC609D91D00F5D91EC611D91F000EF9
73:10048000D920C660D9219600D922C687D923000475
74:10049000D924C60AD92504F5D9260000D927264132
75:1004A000D9283021D9291001D92AC620D92B14E501
76:1004B000D92CC621D92DC53DD92EC622D92F3CBE57
77:1004C000D930C623D9314452D932C624D933C5C50F
78:1004D000D934C625D935E01ED936C627D93700000C
79:1004E000D938C628D9390000D93AC62CD93B0000E2
80:1004F000D93C0000D93D2B84D93E3C74D93F6435AA
81:10050000D940DFF4D9416435D9422806D9433006B1
82:10051000D9448565D9452B24D9463C24D94764362E
83:10052000D9481002D9492B24D94A3C24D94B6436E6
84:10053000D94C4045D94D8656D94E5663D94F030202
85:10054000D950401ED9511002D9522807D95331A78A
86:10055000D95420C4D9553C24D9566724D957100200
87:10056000D9582807D9593187D95A20C4D95B3C2496
88:10057000D95C6724D95D1002D95E24F4D95F3C644C
89:10058000D9606436D961DFF4D9626436D963100268
90:10059000D9642006D9653D76D966C161D9676134D1
91:1005A000D9686135D9695443D96A0303D96B652485
92:1005B000D96C00FBD96D1002D96E20D4D96F3C24C0
93:1005C000D9702025D9713005D9726524D9731002EC
94:1005D000D974D019D9752104D9763C24D97721054D
95:1005E000D9783805D9796524D97ADFF4D97B4005E3
96:1005F000D97C6524D97D2E8DD97E303DD97F2408C4
97:10060000D98035D8D9815DD3D9820307D98388872A
98:10061000D98463A7D9858887D98663A7D987DFFD61
99:10062000D98800F9D9891002D98A0000878C30D97D
100:00000001FF
diff --git a/fs/afs/flock.c b/fs/afs/flock.c
index 210acafe4a9b..3ff8bdd18fb3 100644
--- a/fs/afs/flock.c
+++ b/fs/afs/flock.c
@@ -432,7 +432,6 @@ vfs_rejected_lock:
432 list_del_init(&fl->fl_u.afs.link); 432 list_del_init(&fl->fl_u.afs.link);
433 if (list_empty(&vnode->granted_locks)) 433 if (list_empty(&vnode->granted_locks))
434 afs_defer_unlock(vnode, key); 434 afs_defer_unlock(vnode, key);
435 spin_unlock(&vnode->lock);
436 goto abort_attempt; 435 goto abort_attempt;
437} 436}
438 437
diff --git a/fs/aio.c b/fs/aio.c
index 76da12537956..d065b2c3273e 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -485,6 +485,8 @@ static inline void really_put_req(struct kioctx *ctx, struct kiocb *req)
485{ 485{
486 assert_spin_locked(&ctx->ctx_lock); 486 assert_spin_locked(&ctx->ctx_lock);
487 487
488 if (req->ki_eventfd != NULL)
489 eventfd_ctx_put(req->ki_eventfd);
488 if (req->ki_dtor) 490 if (req->ki_dtor)
489 req->ki_dtor(req); 491 req->ki_dtor(req);
490 if (req->ki_iovec != &req->ki_inline_vec) 492 if (req->ki_iovec != &req->ki_inline_vec)
@@ -509,8 +511,6 @@ static void aio_fput_routine(struct work_struct *data)
509 /* Complete the fput(s) */ 511 /* Complete the fput(s) */
510 if (req->ki_filp != NULL) 512 if (req->ki_filp != NULL)
511 __fput(req->ki_filp); 513 __fput(req->ki_filp);
512 if (req->ki_eventfd != NULL)
513 __fput(req->ki_eventfd);
514 514
515 /* Link the iocb into the context's free list */ 515 /* Link the iocb into the context's free list */
516 spin_lock_irq(&ctx->ctx_lock); 516 spin_lock_irq(&ctx->ctx_lock);
@@ -528,8 +528,6 @@ static void aio_fput_routine(struct work_struct *data)
528 */ 528 */
529static int __aio_put_req(struct kioctx *ctx, struct kiocb *req) 529static int __aio_put_req(struct kioctx *ctx, struct kiocb *req)
530{ 530{
531 int schedule_putreq = 0;
532
533 dprintk(KERN_DEBUG "aio_put(%p): f_count=%ld\n", 531 dprintk(KERN_DEBUG "aio_put(%p): f_count=%ld\n",
534 req, atomic_long_read(&req->ki_filp->f_count)); 532 req, atomic_long_read(&req->ki_filp->f_count));
535 533
@@ -549,24 +547,16 @@ static int __aio_put_req(struct kioctx *ctx, struct kiocb *req)
549 * we would not be holding the last reference to the file*, so 547 * we would not be holding the last reference to the file*, so
550 * this function will be executed w/out any aio kthread wakeup. 548 * this function will be executed w/out any aio kthread wakeup.
551 */ 549 */
552 if (unlikely(atomic_long_dec_and_test(&req->ki_filp->f_count))) 550 if (unlikely(atomic_long_dec_and_test(&req->ki_filp->f_count))) {
553 schedule_putreq++;
554 else
555 req->ki_filp = NULL;
556 if (req->ki_eventfd != NULL) {
557 if (unlikely(atomic_long_dec_and_test(&req->ki_eventfd->f_count)))
558 schedule_putreq++;
559 else
560 req->ki_eventfd = NULL;
561 }
562 if (unlikely(schedule_putreq)) {
563 get_ioctx(ctx); 551 get_ioctx(ctx);
564 spin_lock(&fput_lock); 552 spin_lock(&fput_lock);
565 list_add(&req->ki_list, &fput_head); 553 list_add(&req->ki_list, &fput_head);
566 spin_unlock(&fput_lock); 554 spin_unlock(&fput_lock);
567 queue_work(aio_wq, &fput_work); 555 queue_work(aio_wq, &fput_work);
568 } else 556 } else {
557 req->ki_filp = NULL;
569 really_put_req(ctx, req); 558 really_put_req(ctx, req);
559 }
570 return 1; 560 return 1;
571} 561}
572 562
@@ -1622,7 +1612,7 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
1622 * an eventfd() fd, and will be signaled for each completed 1612 * an eventfd() fd, and will be signaled for each completed
1623 * event using the eventfd_signal() function. 1613 * event using the eventfd_signal() function.
1624 */ 1614 */
1625 req->ki_eventfd = eventfd_fget((int) iocb->aio_resfd); 1615 req->ki_eventfd = eventfd_ctx_fdget((int) iocb->aio_resfd);
1626 if (IS_ERR(req->ki_eventfd)) { 1616 if (IS_ERR(req->ki_eventfd)) {
1627 ret = PTR_ERR(req->ki_eventfd); 1617 ret = PTR_ERR(req->ki_eventfd);
1628 req->ki_eventfd = NULL; 1618 req->ki_eventfd = NULL;
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 9fa212b014a5..b7c1603cd4bd 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1522,11 +1522,11 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
1522 info->thread = NULL; 1522 info->thread = NULL;
1523 1523
1524 psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL); 1524 psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL);
1525 fill_note(&info->psinfo, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);
1526
1527 if (psinfo == NULL) 1525 if (psinfo == NULL)
1528 return 0; 1526 return 0;
1529 1527
1528 fill_note(&info->psinfo, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo);
1529
1530 /* 1530 /*
1531 * Figure out how many notes we're going to need for each thread. 1531 * Figure out how many notes we're going to need for each thread.
1532 */ 1532 */
@@ -1929,7 +1929,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
1929 elf = kmalloc(sizeof(*elf), GFP_KERNEL); 1929 elf = kmalloc(sizeof(*elf), GFP_KERNEL);
1930 if (!elf) 1930 if (!elf)
1931 goto out; 1931 goto out;
1932 1932 /*
1933 * The number of segs are recored into ELF header as 16bit value.
1934 * Please check DEFAULT_MAX_MAP_COUNT definition when you modify here.
1935 */
1933 segs = current->mm->map_count; 1936 segs = current->mm->map_count;
1934#ifdef ELF_CORE_EXTRA_PHDRS 1937#ifdef ELF_CORE_EXTRA_PHDRS
1935 segs += ELF_CORE_EXTRA_PHDRS; 1938 segs += ELF_CORE_EXTRA_PHDRS;
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
index 31c46a241bac..49a34e7f7306 100644
--- a/fs/bio-integrity.c
+++ b/fs/bio-integrity.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * bio-integrity.c - bio data integrity extensions 2 * bio-integrity.c - bio data integrity extensions
3 * 3 *
4 * Copyright (C) 2007, 2008 Oracle Corporation 4 * Copyright (C) 2007, 2008, 2009 Oracle Corporation
5 * Written by: Martin K. Petersen <martin.petersen@oracle.com> 5 * Written by: Martin K. Petersen <martin.petersen@oracle.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
@@ -25,63 +25,121 @@
25#include <linux/bio.h> 25#include <linux/bio.h>
26#include <linux/workqueue.h> 26#include <linux/workqueue.h>
27 27
28static struct kmem_cache *bio_integrity_slab __read_mostly; 28struct integrity_slab {
29static mempool_t *bio_integrity_pool; 29 struct kmem_cache *slab;
30static struct bio_set *integrity_bio_set; 30 unsigned short nr_vecs;
31 char name[8];
32};
33
34#define IS(x) { .nr_vecs = x, .name = "bip-"__stringify(x) }
35struct integrity_slab bip_slab[BIOVEC_NR_POOLS] __read_mostly = {
36 IS(1), IS(4), IS(16), IS(64), IS(128), IS(BIO_MAX_PAGES),
37};
38#undef IS
39
31static struct workqueue_struct *kintegrityd_wq; 40static struct workqueue_struct *kintegrityd_wq;
32 41
42static inline unsigned int vecs_to_idx(unsigned int nr)
43{
44 switch (nr) {
45 case 1:
46 return 0;
47 case 2 ... 4:
48 return 1;
49 case 5 ... 16:
50 return 2;
51 case 17 ... 64:
52 return 3;
53 case 65 ... 128:
54 return 4;
55 case 129 ... BIO_MAX_PAGES:
56 return 5;
57 default:
58 BUG();
59 }
60}
61
62static inline int use_bip_pool(unsigned int idx)
63{
64 if (idx == BIOVEC_NR_POOLS)
65 return 1;
66
67 return 0;
68}
69
33/** 70/**
34 * bio_integrity_alloc - Allocate integrity payload and attach it to bio 71 * bio_integrity_alloc_bioset - Allocate integrity payload and attach it to bio
35 * @bio: bio to attach integrity metadata to 72 * @bio: bio to attach integrity metadata to
36 * @gfp_mask: Memory allocation mask 73 * @gfp_mask: Memory allocation mask
37 * @nr_vecs: Number of integrity metadata scatter-gather elements 74 * @nr_vecs: Number of integrity metadata scatter-gather elements
75 * @bs: bio_set to allocate from
38 * 76 *
39 * Description: This function prepares a bio for attaching integrity 77 * Description: This function prepares a bio for attaching integrity
40 * metadata. nr_vecs specifies the maximum number of pages containing 78 * metadata. nr_vecs specifies the maximum number of pages containing
41 * integrity metadata that can be attached. 79 * integrity metadata that can be attached.
42 */ 80 */
43struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, 81struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio,
44 gfp_t gfp_mask, 82 gfp_t gfp_mask,
45 unsigned int nr_vecs) 83 unsigned int nr_vecs,
84 struct bio_set *bs)
46{ 85{
47 struct bio_integrity_payload *bip; 86 struct bio_integrity_payload *bip;
48 struct bio_vec *iv; 87 unsigned int idx = vecs_to_idx(nr_vecs);
49 unsigned long idx;
50 88
51 BUG_ON(bio == NULL); 89 BUG_ON(bio == NULL);
90 bip = NULL;
52 91
53 bip = mempool_alloc(bio_integrity_pool, gfp_mask); 92 /* Lower order allocations come straight from slab */
54 if (unlikely(bip == NULL)) { 93 if (!use_bip_pool(idx))
55 printk(KERN_ERR "%s: could not alloc bip\n", __func__); 94 bip = kmem_cache_alloc(bip_slab[idx].slab, gfp_mask);
56 return NULL;
57 }
58 95
59 memset(bip, 0, sizeof(*bip)); 96 /* Use mempool if lower order alloc failed or max vecs were requested */
97 if (bip == NULL) {
98 bip = mempool_alloc(bs->bio_integrity_pool, gfp_mask);
60 99
61 iv = bvec_alloc_bs(gfp_mask, nr_vecs, &idx, integrity_bio_set); 100 if (unlikely(bip == NULL)) {
62 if (unlikely(iv == NULL)) { 101 printk(KERN_ERR "%s: could not alloc bip\n", __func__);
63 printk(KERN_ERR "%s: could not alloc bip_vec\n", __func__); 102 return NULL;
64 mempool_free(bip, bio_integrity_pool); 103 }
65 return NULL;
66 } 104 }
67 105
68 bip->bip_pool = idx; 106 memset(bip, 0, sizeof(*bip));
69 bip->bip_vec = iv; 107
108 bip->bip_slab = idx;
70 bip->bip_bio = bio; 109 bip->bip_bio = bio;
71 bio->bi_integrity = bip; 110 bio->bi_integrity = bip;
72 111
73 return bip; 112 return bip;
74} 113}
114EXPORT_SYMBOL(bio_integrity_alloc_bioset);
115
116/**
117 * bio_integrity_alloc - Allocate integrity payload and attach it to bio
118 * @bio: bio to attach integrity metadata to
119 * @gfp_mask: Memory allocation mask
120 * @nr_vecs: Number of integrity metadata scatter-gather elements
121 *
122 * Description: This function prepares a bio for attaching integrity
123 * metadata. nr_vecs specifies the maximum number of pages containing
124 * integrity metadata that can be attached.
125 */
126struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
127 gfp_t gfp_mask,
128 unsigned int nr_vecs)
129{
130 return bio_integrity_alloc_bioset(bio, gfp_mask, nr_vecs, fs_bio_set);
131}
75EXPORT_SYMBOL(bio_integrity_alloc); 132EXPORT_SYMBOL(bio_integrity_alloc);
76 133
77/** 134/**
78 * bio_integrity_free - Free bio integrity payload 135 * bio_integrity_free - Free bio integrity payload
79 * @bio: bio containing bip to be freed 136 * @bio: bio containing bip to be freed
137 * @bs: bio_set this bio was allocated from
80 * 138 *
81 * Description: Used to free the integrity portion of a bio. Usually 139 * Description: Used to free the integrity portion of a bio. Usually
82 * called from bio_free(). 140 * called from bio_free().
83 */ 141 */
84void bio_integrity_free(struct bio *bio) 142void bio_integrity_free(struct bio *bio, struct bio_set *bs)
85{ 143{
86 struct bio_integrity_payload *bip = bio->bi_integrity; 144 struct bio_integrity_payload *bip = bio->bi_integrity;
87 145
@@ -92,8 +150,10 @@ void bio_integrity_free(struct bio *bio)
92 && bip->bip_buf != NULL) 150 && bip->bip_buf != NULL)
93 kfree(bip->bip_buf); 151 kfree(bip->bip_buf);
94 152
95 bvec_free_bs(integrity_bio_set, bip->bip_vec, bip->bip_pool); 153 if (use_bip_pool(bip->bip_slab))
96 mempool_free(bip, bio_integrity_pool); 154 mempool_free(bip, bs->bio_integrity_pool);
155 else
156 kmem_cache_free(bip_slab[bip->bip_slab].slab, bip);
97 157
98 bio->bi_integrity = NULL; 158 bio->bi_integrity = NULL;
99} 159}
@@ -114,7 +174,7 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
114 struct bio_integrity_payload *bip = bio->bi_integrity; 174 struct bio_integrity_payload *bip = bio->bi_integrity;
115 struct bio_vec *iv; 175 struct bio_vec *iv;
116 176
117 if (bip->bip_vcnt >= bvec_nr_vecs(bip->bip_pool)) { 177 if (bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) {
118 printk(KERN_ERR "%s: bip_vec full\n", __func__); 178 printk(KERN_ERR "%s: bip_vec full\n", __func__);
119 return 0; 179 return 0;
120 } 180 }
@@ -647,8 +707,8 @@ void bio_integrity_split(struct bio *bio, struct bio_pair *bp, int sectors)
647 bp->iv1 = bip->bip_vec[0]; 707 bp->iv1 = bip->bip_vec[0];
648 bp->iv2 = bip->bip_vec[0]; 708 bp->iv2 = bip->bip_vec[0];
649 709
650 bp->bip1.bip_vec = &bp->iv1; 710 bp->bip1.bip_vec[0] = bp->iv1;
651 bp->bip2.bip_vec = &bp->iv2; 711 bp->bip2.bip_vec[0] = bp->iv2;
652 712
653 bp->iv1.bv_len = sectors * bi->tuple_size; 713 bp->iv1.bv_len = sectors * bi->tuple_size;
654 bp->iv2.bv_offset += sectors * bi->tuple_size; 714 bp->iv2.bv_offset += sectors * bi->tuple_size;
@@ -667,17 +727,19 @@ EXPORT_SYMBOL(bio_integrity_split);
667 * @bio: New bio 727 * @bio: New bio
668 * @bio_src: Original bio 728 * @bio_src: Original bio
669 * @gfp_mask: Memory allocation mask 729 * @gfp_mask: Memory allocation mask
730 * @bs: bio_set to allocate bip from
670 * 731 *
671 * Description: Called to allocate a bip when cloning a bio 732 * Description: Called to allocate a bip when cloning a bio
672 */ 733 */
673int bio_integrity_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp_mask) 734int bio_integrity_clone(struct bio *bio, struct bio *bio_src,
735 gfp_t gfp_mask, struct bio_set *bs)
674{ 736{
675 struct bio_integrity_payload *bip_src = bio_src->bi_integrity; 737 struct bio_integrity_payload *bip_src = bio_src->bi_integrity;
676 struct bio_integrity_payload *bip; 738 struct bio_integrity_payload *bip;
677 739
678 BUG_ON(bip_src == NULL); 740 BUG_ON(bip_src == NULL);
679 741
680 bip = bio_integrity_alloc(bio, gfp_mask, bip_src->bip_vcnt); 742 bip = bio_integrity_alloc_bioset(bio, gfp_mask, bip_src->bip_vcnt, bs);
681 743
682 if (bip == NULL) 744 if (bip == NULL)
683 return -EIO; 745 return -EIO;
@@ -693,25 +755,43 @@ int bio_integrity_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp_mask)
693} 755}
694EXPORT_SYMBOL(bio_integrity_clone); 756EXPORT_SYMBOL(bio_integrity_clone);
695 757
696static int __init bio_integrity_init(void) 758int bioset_integrity_create(struct bio_set *bs, int pool_size)
697{ 759{
698 kintegrityd_wq = create_workqueue("kintegrityd"); 760 unsigned int max_slab = vecs_to_idx(BIO_MAX_PAGES);
761
762 bs->bio_integrity_pool =
763 mempool_create_slab_pool(pool_size, bip_slab[max_slab].slab);
699 764
765 if (!bs->bio_integrity_pool)
766 return -1;
767
768 return 0;
769}
770EXPORT_SYMBOL(bioset_integrity_create);
771
772void bioset_integrity_free(struct bio_set *bs)
773{
774 if (bs->bio_integrity_pool)
775 mempool_destroy(bs->bio_integrity_pool);
776}
777EXPORT_SYMBOL(bioset_integrity_free);
778
779void __init bio_integrity_init(void)
780{
781 unsigned int i;
782
783 kintegrityd_wq = create_workqueue("kintegrityd");
700 if (!kintegrityd_wq) 784 if (!kintegrityd_wq)
701 panic("Failed to create kintegrityd\n"); 785 panic("Failed to create kintegrityd\n");
702 786
703 bio_integrity_slab = KMEM_CACHE(bio_integrity_payload, 787 for (i = 0 ; i < BIOVEC_NR_POOLS ; i++) {
704 SLAB_HWCACHE_ALIGN|SLAB_PANIC); 788 unsigned int size;
705 789
706 bio_integrity_pool = mempool_create_slab_pool(BIO_POOL_SIZE, 790 size = sizeof(struct bio_integrity_payload)
707 bio_integrity_slab); 791 + bip_slab[i].nr_vecs * sizeof(struct bio_vec);
708 if (!bio_integrity_pool)
709 panic("bio_integrity: can't allocate bip pool\n");
710 792
711 integrity_bio_set = bioset_create(BIO_POOL_SIZE, 0); 793 bip_slab[i].slab =
712 if (!integrity_bio_set) 794 kmem_cache_create(bip_slab[i].name, size, 0,
713 panic("bio_integrity: can't allocate bio_set\n"); 795 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
714 796 }
715 return 0;
716} 797}
717subsys_initcall(bio_integrity_init);
diff --git a/fs/bio.c b/fs/bio.c
index 24c914043532..1486b19fc431 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -238,7 +238,7 @@ void bio_free(struct bio *bio, struct bio_set *bs)
238 bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio)); 238 bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio));
239 239
240 if (bio_integrity(bio)) 240 if (bio_integrity(bio))
241 bio_integrity_free(bio); 241 bio_integrity_free(bio, bs);
242 242
243 /* 243 /*
244 * If we have front padding, adjust the bio pointer before freeing 244 * If we have front padding, adjust the bio pointer before freeing
@@ -341,7 +341,7 @@ struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs)
341static void bio_kmalloc_destructor(struct bio *bio) 341static void bio_kmalloc_destructor(struct bio *bio)
342{ 342{
343 if (bio_integrity(bio)) 343 if (bio_integrity(bio))
344 bio_integrity_free(bio); 344 bio_integrity_free(bio, fs_bio_set);
345 kfree(bio); 345 kfree(bio);
346} 346}
347 347
@@ -472,7 +472,7 @@ struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
472 if (bio_integrity(bio)) { 472 if (bio_integrity(bio)) {
473 int ret; 473 int ret;
474 474
475 ret = bio_integrity_clone(b, bio, gfp_mask); 475 ret = bio_integrity_clone(b, bio, gfp_mask, fs_bio_set);
476 476
477 if (ret < 0) { 477 if (ret < 0) {
478 bio_put(b); 478 bio_put(b);
@@ -1539,6 +1539,7 @@ void bioset_free(struct bio_set *bs)
1539 if (bs->bio_pool) 1539 if (bs->bio_pool)
1540 mempool_destroy(bs->bio_pool); 1540 mempool_destroy(bs->bio_pool);
1541 1541
1542 bioset_integrity_free(bs);
1542 biovec_free_pools(bs); 1543 biovec_free_pools(bs);
1543 bio_put_slab(bs); 1544 bio_put_slab(bs);
1544 1545
@@ -1579,6 +1580,9 @@ struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad)
1579 if (!bs->bio_pool) 1580 if (!bs->bio_pool)
1580 goto bad; 1581 goto bad;
1581 1582
1583 if (bioset_integrity_create(bs, pool_size))
1584 goto bad;
1585
1582 if (!biovec_create_pools(bs, pool_size)) 1586 if (!biovec_create_pools(bs, pool_size))
1583 return bs; 1587 return bs;
1584 1588
@@ -1616,6 +1620,7 @@ static int __init init_bio(void)
1616 if (!bio_slabs) 1620 if (!bio_slabs)
1617 panic("bio: can't allocate bios\n"); 1621 panic("bio: can't allocate bios\n");
1618 1622
1623 bio_integrity_init();
1619 biovec_init_slabs(); 1624 biovec_init_slabs();
1620 1625
1621 fs_bio_set = bioset_create(BIO_POOL_SIZE, 0); 1626 fs_bio_set = bioset_create(BIO_POOL_SIZE, 0);
diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 7f88628a1a72..6e4f6c50a120 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -299,8 +299,8 @@ int btrfs_start_workers(struct btrfs_workers *workers, int num_workers)
299 "btrfs-%s-%d", workers->name, 299 "btrfs-%s-%d", workers->name,
300 workers->num_workers + i); 300 workers->num_workers + i);
301 if (IS_ERR(worker->task)) { 301 if (IS_ERR(worker->task)) {
302 kfree(worker);
303 ret = PTR_ERR(worker->task); 302 ret = PTR_ERR(worker->task);
303 kfree(worker);
304 goto fail; 304 goto fail;
305 } 305 }
306 306
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 2779c2f5360a..98a873838717 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2074,8 +2074,7 @@ static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
2074int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); 2074int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
2075int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); 2075int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
2076int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf); 2076int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
2077int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root 2077int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref);
2078 *root);
2079int btrfs_drop_subtree(struct btrfs_trans_handle *trans, 2078int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
2080 struct btrfs_root *root, 2079 struct btrfs_root *root,
2081 struct extent_buffer *node, 2080 struct extent_buffer *node,
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index edc7d208c5ce..a5aca3997d42 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -990,15 +990,13 @@ static inline int extent_ref_type(u64 parent, u64 owner)
990 return type; 990 return type;
991} 991}
992 992
993static int find_next_key(struct btrfs_path *path, struct btrfs_key *key) 993static int find_next_key(struct btrfs_path *path, int level,
994 struct btrfs_key *key)
994 995
995{ 996{
996 int level; 997 for (; level < BTRFS_MAX_LEVEL; level++) {
997 BUG_ON(!path->keep_locks);
998 for (level = 0; level < BTRFS_MAX_LEVEL; level++) {
999 if (!path->nodes[level]) 998 if (!path->nodes[level])
1000 break; 999 break;
1001 btrfs_assert_tree_locked(path->nodes[level]);
1002 if (path->slots[level] + 1 >= 1000 if (path->slots[level] + 1 >=
1003 btrfs_header_nritems(path->nodes[level])) 1001 btrfs_header_nritems(path->nodes[level]))
1004 continue; 1002 continue;
@@ -1158,7 +1156,8 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
1158 * For simplicity, we just do not add new inline back 1156 * For simplicity, we just do not add new inline back
1159 * ref if there is any kind of item for this block 1157 * ref if there is any kind of item for this block
1160 */ 1158 */
1161 if (find_next_key(path, &key) == 0 && key.objectid == bytenr && 1159 if (find_next_key(path, 0, &key) == 0 &&
1160 key.objectid == bytenr &&
1162 key.type < BTRFS_BLOCK_GROUP_ITEM_KEY) { 1161 key.type < BTRFS_BLOCK_GROUP_ITEM_KEY) {
1163 err = -EAGAIN; 1162 err = -EAGAIN;
1164 goto out; 1163 goto out;
@@ -2697,7 +2696,7 @@ again:
2697 2696
2698 printk(KERN_ERR "no space left, need %llu, %llu delalloc bytes" 2697 printk(KERN_ERR "no space left, need %llu, %llu delalloc bytes"
2699 ", %llu bytes_used, %llu bytes_reserved, " 2698 ", %llu bytes_used, %llu bytes_reserved, "
2700 "%llu bytes_pinned, %llu bytes_readonly, %llu may use" 2699 "%llu bytes_pinned, %llu bytes_readonly, %llu may use "
2701 "%llu total\n", (unsigned long long)bytes, 2700 "%llu total\n", (unsigned long long)bytes,
2702 (unsigned long long)data_sinfo->bytes_delalloc, 2701 (unsigned long long)data_sinfo->bytes_delalloc,
2703 (unsigned long long)data_sinfo->bytes_used, 2702 (unsigned long long)data_sinfo->bytes_used,
@@ -4128,6 +4127,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
4128 return buf; 4127 return buf;
4129} 4128}
4130 4129
4130#if 0
4131int btrfs_drop_leaf_ref(struct btrfs_trans_handle *trans, 4131int btrfs_drop_leaf_ref(struct btrfs_trans_handle *trans,
4132 struct btrfs_root *root, struct extent_buffer *leaf) 4132 struct btrfs_root *root, struct extent_buffer *leaf)
4133{ 4133{
@@ -4171,8 +4171,6 @@ int btrfs_drop_leaf_ref(struct btrfs_trans_handle *trans,
4171 return 0; 4171 return 0;
4172} 4172}
4173 4173
4174#if 0
4175
4176static noinline int cache_drop_leaf_ref(struct btrfs_trans_handle *trans, 4174static noinline int cache_drop_leaf_ref(struct btrfs_trans_handle *trans,
4177 struct btrfs_root *root, 4175 struct btrfs_root *root,
4178 struct btrfs_leaf_ref *ref) 4176 struct btrfs_leaf_ref *ref)
@@ -4553,262 +4551,471 @@ out:
4553} 4551}
4554#endif 4552#endif
4555 4553
4554struct walk_control {
4555 u64 refs[BTRFS_MAX_LEVEL];
4556 u64 flags[BTRFS_MAX_LEVEL];
4557 struct btrfs_key update_progress;
4558 int stage;
4559 int level;
4560 int shared_level;
4561 int update_ref;
4562 int keep_locks;
4563};
4564
4565#define DROP_REFERENCE 1
4566#define UPDATE_BACKREF 2
4567
4556/* 4568/*
4557 * helper function for drop_subtree, this function is similar to 4569 * hepler to process tree block while walking down the tree.
4558 * walk_down_tree. The main difference is that it checks reference 4570 *
4559 * counts while tree blocks are locked. 4571 * when wc->stage == DROP_REFERENCE, this function checks
4572 * reference count of the block. if the block is shared and
4573 * we need update back refs for the subtree rooted at the
4574 * block, this function changes wc->stage to UPDATE_BACKREF
4575 *
4576 * when wc->stage == UPDATE_BACKREF, this function updates
4577 * back refs for pointers in the block.
4578 *
4579 * NOTE: return value 1 means we should stop walking down.
4560 */ 4580 */
4561static noinline int walk_down_tree(struct btrfs_trans_handle *trans, 4581static noinline int walk_down_proc(struct btrfs_trans_handle *trans,
4562 struct btrfs_root *root, 4582 struct btrfs_root *root,
4563 struct btrfs_path *path, int *level) 4583 struct btrfs_path *path,
4584 struct walk_control *wc)
4564{ 4585{
4565 struct extent_buffer *next; 4586 int level = wc->level;
4566 struct extent_buffer *cur; 4587 struct extent_buffer *eb = path->nodes[level];
4567 struct extent_buffer *parent; 4588 struct btrfs_key key;
4568 u64 bytenr; 4589 u64 flag = BTRFS_BLOCK_FLAG_FULL_BACKREF;
4569 u64 ptr_gen;
4570 u64 refs;
4571 u64 flags;
4572 u32 blocksize;
4573 int ret; 4590 int ret;
4574 4591
4575 cur = path->nodes[*level]; 4592 if (wc->stage == UPDATE_BACKREF &&
4576 ret = btrfs_lookup_extent_info(trans, root, cur->start, cur->len, 4593 btrfs_header_owner(eb) != root->root_key.objectid)
4577 &refs, &flags); 4594 return 1;
4578 BUG_ON(ret);
4579 if (refs > 1)
4580 goto out;
4581 4595
4582 BUG_ON(!(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)); 4596 /*
4597 * when reference count of tree block is 1, it won't increase
4598 * again. once full backref flag is set, we never clear it.
4599 */
4600 if ((wc->stage == DROP_REFERENCE && wc->refs[level] != 1) ||
4601 (wc->stage == UPDATE_BACKREF && !(wc->flags[level] & flag))) {
4602 BUG_ON(!path->locks[level]);
4603 ret = btrfs_lookup_extent_info(trans, root,
4604 eb->start, eb->len,
4605 &wc->refs[level],
4606 &wc->flags[level]);
4607 BUG_ON(ret);
4608 BUG_ON(wc->refs[level] == 0);
4609 }
4583 4610
4584 while (*level >= 0) { 4611 if (wc->stage == DROP_REFERENCE &&
4585 cur = path->nodes[*level]; 4612 wc->update_ref && wc->refs[level] > 1) {
4586 if (*level == 0) { 4613 BUG_ON(eb == root->node);
4587 ret = btrfs_drop_leaf_ref(trans, root, cur); 4614 BUG_ON(path->slots[level] > 0);
4588 BUG_ON(ret); 4615 if (level == 0)
4589 clean_tree_block(trans, root, cur); 4616 btrfs_item_key_to_cpu(eb, &key, path->slots[level]);
4590 break; 4617 else
4591 } 4618 btrfs_node_key_to_cpu(eb, &key, path->slots[level]);
4592 if (path->slots[*level] >= btrfs_header_nritems(cur)) { 4619 if (btrfs_header_owner(eb) == root->root_key.objectid &&
4593 clean_tree_block(trans, root, cur); 4620 btrfs_comp_cpu_keys(&key, &wc->update_progress) >= 0) {
4594 break; 4621 wc->stage = UPDATE_BACKREF;
4622 wc->shared_level = level;
4595 } 4623 }
4624 }
4596 4625
4597 bytenr = btrfs_node_blockptr(cur, path->slots[*level]); 4626 if (wc->stage == DROP_REFERENCE) {
4598 blocksize = btrfs_level_size(root, *level - 1); 4627 if (wc->refs[level] > 1)
4599 ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]); 4628 return 1;
4600 4629
4601 next = read_tree_block(root, bytenr, blocksize, ptr_gen); 4630 if (path->locks[level] && !wc->keep_locks) {
4602 btrfs_tree_lock(next); 4631 btrfs_tree_unlock(eb);
4603 btrfs_set_lock_blocking(next); 4632 path->locks[level] = 0;
4633 }
4634 return 0;
4635 }
4604 4636
4605 ret = btrfs_lookup_extent_info(trans, root, bytenr, blocksize, 4637 /* wc->stage == UPDATE_BACKREF */
4606 &refs, &flags); 4638 if (!(wc->flags[level] & flag)) {
4639 BUG_ON(!path->locks[level]);
4640 ret = btrfs_inc_ref(trans, root, eb, 1);
4607 BUG_ON(ret); 4641 BUG_ON(ret);
4608 if (refs > 1) { 4642 ret = btrfs_dec_ref(trans, root, eb, 0);
4609 parent = path->nodes[*level]; 4643 BUG_ON(ret);
4610 ret = btrfs_free_extent(trans, root, bytenr, 4644 ret = btrfs_set_disk_extent_flags(trans, root, eb->start,
4611 blocksize, parent->start, 4645 eb->len, flag, 0);
4612 btrfs_header_owner(parent), 4646 BUG_ON(ret);
4613 *level - 1, 0); 4647 wc->flags[level] |= flag;
4648 }
4649
4650 /*
4651 * the block is shared by multiple trees, so it's not good to
4652 * keep the tree lock
4653 */
4654 if (path->locks[level] && level > 0) {
4655 btrfs_tree_unlock(eb);
4656 path->locks[level] = 0;
4657 }
4658 return 0;
4659}
4660
4661/*
4662 * hepler to process tree block while walking up the tree.
4663 *
4664 * when wc->stage == DROP_REFERENCE, this function drops
4665 * reference count on the block.
4666 *
4667 * when wc->stage == UPDATE_BACKREF, this function changes
4668 * wc->stage back to DROP_REFERENCE if we changed wc->stage
4669 * to UPDATE_BACKREF previously while processing the block.
4670 *
4671 * NOTE: return value 1 means we should stop walking up.
4672 */
4673static noinline int walk_up_proc(struct btrfs_trans_handle *trans,
4674 struct btrfs_root *root,
4675 struct btrfs_path *path,
4676 struct walk_control *wc)
4677{
4678 int ret = 0;
4679 int level = wc->level;
4680 struct extent_buffer *eb = path->nodes[level];
4681 u64 parent = 0;
4682
4683 if (wc->stage == UPDATE_BACKREF) {
4684 BUG_ON(wc->shared_level < level);
4685 if (level < wc->shared_level)
4686 goto out;
4687
4688 BUG_ON(wc->refs[level] <= 1);
4689 ret = find_next_key(path, level + 1, &wc->update_progress);
4690 if (ret > 0)
4691 wc->update_ref = 0;
4692
4693 wc->stage = DROP_REFERENCE;
4694 wc->shared_level = -1;
4695 path->slots[level] = 0;
4696
4697 /*
4698 * check reference count again if the block isn't locked.
4699 * we should start walking down the tree again if reference
4700 * count is one.
4701 */
4702 if (!path->locks[level]) {
4703 BUG_ON(level == 0);
4704 btrfs_tree_lock(eb);
4705 btrfs_set_lock_blocking(eb);
4706 path->locks[level] = 1;
4707
4708 ret = btrfs_lookup_extent_info(trans, root,
4709 eb->start, eb->len,
4710 &wc->refs[level],
4711 &wc->flags[level]);
4614 BUG_ON(ret); 4712 BUG_ON(ret);
4615 path->slots[*level]++; 4713 BUG_ON(wc->refs[level] == 0);
4616 btrfs_tree_unlock(next); 4714 if (wc->refs[level] == 1) {
4617 free_extent_buffer(next); 4715 btrfs_tree_unlock(eb);
4618 continue; 4716 path->locks[level] = 0;
4717 return 1;
4718 }
4719 } else {
4720 BUG_ON(level != 0);
4619 } 4721 }
4722 }
4620 4723
4621 BUG_ON(!(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)); 4724 /* wc->stage == DROP_REFERENCE */
4725 BUG_ON(wc->refs[level] > 1 && !path->locks[level]);
4622 4726
4623 *level = btrfs_header_level(next); 4727 if (wc->refs[level] == 1) {
4624 path->nodes[*level] = next; 4728 if (level == 0) {
4625 path->slots[*level] = 0; 4729 if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF)
4626 path->locks[*level] = 1; 4730 ret = btrfs_dec_ref(trans, root, eb, 1);
4627 cond_resched(); 4731 else
4732 ret = btrfs_dec_ref(trans, root, eb, 0);
4733 BUG_ON(ret);
4734 }
4735 /* make block locked assertion in clean_tree_block happy */
4736 if (!path->locks[level] &&
4737 btrfs_header_generation(eb) == trans->transid) {
4738 btrfs_tree_lock(eb);
4739 btrfs_set_lock_blocking(eb);
4740 path->locks[level] = 1;
4741 }
4742 clean_tree_block(trans, root, eb);
4743 }
4744
4745 if (eb == root->node) {
4746 if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF)
4747 parent = eb->start;
4748 else
4749 BUG_ON(root->root_key.objectid !=
4750 btrfs_header_owner(eb));
4751 } else {
4752 if (wc->flags[level + 1] & BTRFS_BLOCK_FLAG_FULL_BACKREF)
4753 parent = path->nodes[level + 1]->start;
4754 else
4755 BUG_ON(root->root_key.objectid !=
4756 btrfs_header_owner(path->nodes[level + 1]));
4628 } 4757 }
4629out:
4630 if (path->nodes[*level] == root->node)
4631 parent = path->nodes[*level];
4632 else
4633 parent = path->nodes[*level + 1];
4634 bytenr = path->nodes[*level]->start;
4635 blocksize = path->nodes[*level]->len;
4636 4758
4637 ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent->start, 4759 ret = btrfs_free_extent(trans, root, eb->start, eb->len, parent,
4638 btrfs_header_owner(parent), *level, 0); 4760 root->root_key.objectid, level, 0);
4639 BUG_ON(ret); 4761 BUG_ON(ret);
4762out:
4763 wc->refs[level] = 0;
4764 wc->flags[level] = 0;
4765 return ret;
4766}
4767
4768static noinline int walk_down_tree(struct btrfs_trans_handle *trans,
4769 struct btrfs_root *root,
4770 struct btrfs_path *path,
4771 struct walk_control *wc)
4772{
4773 struct extent_buffer *next;
4774 struct extent_buffer *cur;
4775 u64 bytenr;
4776 u64 ptr_gen;
4777 u32 blocksize;
4778 int level = wc->level;
4779 int ret;
4780
4781 while (level >= 0) {
4782 cur = path->nodes[level];
4783 BUG_ON(path->slots[level] >= btrfs_header_nritems(cur));
4640 4784
4641 if (path->locks[*level]) { 4785 ret = walk_down_proc(trans, root, path, wc);
4642 btrfs_tree_unlock(path->nodes[*level]); 4786 if (ret > 0)
4643 path->locks[*level] = 0; 4787 break;
4788
4789 if (level == 0)
4790 break;
4791
4792 bytenr = btrfs_node_blockptr(cur, path->slots[level]);
4793 blocksize = btrfs_level_size(root, level - 1);
4794 ptr_gen = btrfs_node_ptr_generation(cur, path->slots[level]);
4795
4796 next = read_tree_block(root, bytenr, blocksize, ptr_gen);
4797 btrfs_tree_lock(next);
4798 btrfs_set_lock_blocking(next);
4799
4800 level--;
4801 BUG_ON(level != btrfs_header_level(next));
4802 path->nodes[level] = next;
4803 path->slots[level] = 0;
4804 path->locks[level] = 1;
4805 wc->level = level;
4644 } 4806 }
4645 free_extent_buffer(path->nodes[*level]);
4646 path->nodes[*level] = NULL;
4647 *level += 1;
4648 cond_resched();
4649 return 0; 4807 return 0;
4650} 4808}
4651 4809
4652/*
4653 * helper for dropping snapshots. This walks back up the tree in the path
4654 * to find the first node higher up where we haven't yet gone through
4655 * all the slots
4656 */
4657static noinline int walk_up_tree(struct btrfs_trans_handle *trans, 4810static noinline int walk_up_tree(struct btrfs_trans_handle *trans,
4658 struct btrfs_root *root, 4811 struct btrfs_root *root,
4659 struct btrfs_path *path, 4812 struct btrfs_path *path,
4660 int *level, int max_level) 4813 struct walk_control *wc, int max_level)
4661{ 4814{
4662 struct btrfs_root_item *root_item = &root->root_item; 4815 int level = wc->level;
4663 int i;
4664 int slot;
4665 int ret; 4816 int ret;
4666 4817
4667 for (i = *level; i < max_level && path->nodes[i]; i++) { 4818 path->slots[level] = btrfs_header_nritems(path->nodes[level]);
4668 slot = path->slots[i]; 4819 while (level < max_level && path->nodes[level]) {
4669 if (slot + 1 < btrfs_header_nritems(path->nodes[i])) { 4820 wc->level = level;
4670 /* 4821 if (path->slots[level] + 1 <
4671 * there is more work to do in this level. 4822 btrfs_header_nritems(path->nodes[level])) {
4672 * Update the drop_progress marker to reflect 4823 path->slots[level]++;
4673 * the work we've done so far, and then bump
4674 * the slot number
4675 */
4676 path->slots[i]++;
4677 WARN_ON(*level == 0);
4678 if (max_level == BTRFS_MAX_LEVEL) {
4679 btrfs_node_key(path->nodes[i],
4680 &root_item->drop_progress,
4681 path->slots[i]);
4682 root_item->drop_level = i;
4683 }
4684 *level = i;
4685 return 0; 4824 return 0;
4686 } else { 4825 } else {
4687 struct extent_buffer *parent; 4826 ret = walk_up_proc(trans, root, path, wc);
4688 4827 if (ret > 0)
4689 /* 4828 return 0;
4690 * this whole node is done, free our reference
4691 * on it and go up one level
4692 */
4693 if (path->nodes[*level] == root->node)
4694 parent = path->nodes[*level];
4695 else
4696 parent = path->nodes[*level + 1];
4697 4829
4698 clean_tree_block(trans, root, path->nodes[i]); 4830 if (path->locks[level]) {
4699 ret = btrfs_free_extent(trans, root, 4831 btrfs_tree_unlock(path->nodes[level]);
4700 path->nodes[i]->start, 4832 path->locks[level] = 0;
4701 path->nodes[i]->len,
4702 parent->start,
4703 btrfs_header_owner(parent),
4704 *level, 0);
4705 BUG_ON(ret);
4706 if (path->locks[*level]) {
4707 btrfs_tree_unlock(path->nodes[i]);
4708 path->locks[i] = 0;
4709 } 4833 }
4710 free_extent_buffer(path->nodes[i]); 4834 free_extent_buffer(path->nodes[level]);
4711 path->nodes[i] = NULL; 4835 path->nodes[level] = NULL;
4712 *level = i + 1; 4836 level++;
4713 } 4837 }
4714 } 4838 }
4715 return 1; 4839 return 1;
4716} 4840}
4717 4841
4718/* 4842/*
4719 * drop the reference count on the tree rooted at 'snap'. This traverses 4843 * drop a subvolume tree.
4720 * the tree freeing any blocks that have a ref count of zero after being 4844 *
4721 * decremented. 4845 * this function traverses the tree freeing any blocks that only
4846 * referenced by the tree.
4847 *
4848 * when a shared tree block is found. this function decreases its
4849 * reference count by one. if update_ref is true, this function
4850 * also make sure backrefs for the shared block and all lower level
4851 * blocks are properly updated.
4722 */ 4852 */
4723int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root 4853int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref)
4724 *root)
4725{ 4854{
4726 int ret = 0;
4727 int wret;
4728 int level;
4729 struct btrfs_path *path; 4855 struct btrfs_path *path;
4730 int update_count; 4856 struct btrfs_trans_handle *trans;
4857 struct btrfs_root *tree_root = root->fs_info->tree_root;
4731 struct btrfs_root_item *root_item = &root->root_item; 4858 struct btrfs_root_item *root_item = &root->root_item;
4859 struct walk_control *wc;
4860 struct btrfs_key key;
4861 int err = 0;
4862 int ret;
4863 int level;
4732 4864
4733 path = btrfs_alloc_path(); 4865 path = btrfs_alloc_path();
4734 BUG_ON(!path); 4866 BUG_ON(!path);
4735 4867
4736 level = btrfs_header_level(root->node); 4868 wc = kzalloc(sizeof(*wc), GFP_NOFS);
4869 BUG_ON(!wc);
4870
4871 trans = btrfs_start_transaction(tree_root, 1);
4872
4737 if (btrfs_disk_key_objectid(&root_item->drop_progress) == 0) { 4873 if (btrfs_disk_key_objectid(&root_item->drop_progress) == 0) {
4874 level = btrfs_header_level(root->node);
4738 path->nodes[level] = btrfs_lock_root_node(root); 4875 path->nodes[level] = btrfs_lock_root_node(root);
4739 btrfs_set_lock_blocking(path->nodes[level]); 4876 btrfs_set_lock_blocking(path->nodes[level]);
4740 path->slots[level] = 0; 4877 path->slots[level] = 0;
4741 path->locks[level] = 1; 4878 path->locks[level] = 1;
4879 memset(&wc->update_progress, 0,
4880 sizeof(wc->update_progress));
4742 } else { 4881 } else {
4743 struct btrfs_key key;
4744 struct btrfs_disk_key found_key;
4745 struct extent_buffer *node;
4746
4747 btrfs_disk_key_to_cpu(&key, &root_item->drop_progress); 4882 btrfs_disk_key_to_cpu(&key, &root_item->drop_progress);
4883 memcpy(&wc->update_progress, &key,
4884 sizeof(wc->update_progress));
4885
4748 level = root_item->drop_level; 4886 level = root_item->drop_level;
4887 BUG_ON(level == 0);
4749 path->lowest_level = level; 4888 path->lowest_level = level;
4750 wret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 4889 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
4751 if (wret < 0) { 4890 path->lowest_level = 0;
4752 ret = wret; 4891 if (ret < 0) {
4892 err = ret;
4753 goto out; 4893 goto out;
4754 } 4894 }
4755 node = path->nodes[level]; 4895 btrfs_node_key_to_cpu(path->nodes[level], &key,
4756 btrfs_node_key(node, &found_key, path->slots[level]); 4896 path->slots[level]);
4757 WARN_ON(memcmp(&found_key, &root_item->drop_progress, 4897 WARN_ON(memcmp(&key, &wc->update_progress, sizeof(key)));
4758 sizeof(found_key))); 4898
4759 /* 4899 /*
4760 * unlock our path, this is safe because only this 4900 * unlock our path, this is safe because only this
4761 * function is allowed to delete this snapshot 4901 * function is allowed to delete this snapshot
4762 */ 4902 */
4763 btrfs_unlock_up_safe(path, 0); 4903 btrfs_unlock_up_safe(path, 0);
4904
4905 level = btrfs_header_level(root->node);
4906 while (1) {
4907 btrfs_tree_lock(path->nodes[level]);
4908 btrfs_set_lock_blocking(path->nodes[level]);
4909
4910 ret = btrfs_lookup_extent_info(trans, root,
4911 path->nodes[level]->start,
4912 path->nodes[level]->len,
4913 &wc->refs[level],
4914 &wc->flags[level]);
4915 BUG_ON(ret);
4916 BUG_ON(wc->refs[level] == 0);
4917
4918 if (level == root_item->drop_level)
4919 break;
4920
4921 btrfs_tree_unlock(path->nodes[level]);
4922 WARN_ON(wc->refs[level] != 1);
4923 level--;
4924 }
4764 } 4925 }
4926
4927 wc->level = level;
4928 wc->shared_level = -1;
4929 wc->stage = DROP_REFERENCE;
4930 wc->update_ref = update_ref;
4931 wc->keep_locks = 0;
4932
4765 while (1) { 4933 while (1) {
4766 unsigned long update; 4934 ret = walk_down_tree(trans, root, path, wc);
4767 wret = walk_down_tree(trans, root, path, &level); 4935 if (ret < 0) {
4768 if (wret > 0) 4936 err = ret;
4769 break; 4937 break;
4770 if (wret < 0) 4938 }
4771 ret = wret;
4772 4939
4773 wret = walk_up_tree(trans, root, path, &level, 4940 ret = walk_up_tree(trans, root, path, wc, BTRFS_MAX_LEVEL);
4774 BTRFS_MAX_LEVEL); 4941 if (ret < 0) {
4775 if (wret > 0) 4942 err = ret;
4776 break; 4943 break;
4777 if (wret < 0) 4944 }
4778 ret = wret; 4945
4779 if (trans->transaction->in_commit || 4946 if (ret > 0) {
4780 trans->transaction->delayed_refs.flushing) { 4947 BUG_ON(wc->stage != DROP_REFERENCE);
4781 ret = -EAGAIN;
4782 break; 4948 break;
4783 } 4949 }
4784 for (update_count = 0; update_count < 16; update_count++) { 4950
4951 if (wc->stage == DROP_REFERENCE) {
4952 level = wc->level;
4953 btrfs_node_key(path->nodes[level],
4954 &root_item->drop_progress,
4955 path->slots[level]);
4956 root_item->drop_level = level;
4957 }
4958
4959 BUG_ON(wc->level == 0);
4960 if (trans->transaction->in_commit ||
4961 trans->transaction->delayed_refs.flushing) {
4962 ret = btrfs_update_root(trans, tree_root,
4963 &root->root_key,
4964 root_item);
4965 BUG_ON(ret);
4966
4967 btrfs_end_transaction(trans, tree_root);
4968 trans = btrfs_start_transaction(tree_root, 1);
4969 } else {
4970 unsigned long update;
4785 update = trans->delayed_ref_updates; 4971 update = trans->delayed_ref_updates;
4786 trans->delayed_ref_updates = 0; 4972 trans->delayed_ref_updates = 0;
4787 if (update) 4973 if (update)
4788 btrfs_run_delayed_refs(trans, root, update); 4974 btrfs_run_delayed_refs(trans, tree_root,
4789 else 4975 update);
4790 break;
4791 } 4976 }
4792 } 4977 }
4978 btrfs_release_path(root, path);
4979 BUG_ON(err);
4980
4981 ret = btrfs_del_root(trans, tree_root, &root->root_key);
4982 BUG_ON(ret);
4983
4984 free_extent_buffer(root->node);
4985 free_extent_buffer(root->commit_root);
4986 kfree(root);
4793out: 4987out:
4988 btrfs_end_transaction(trans, tree_root);
4989 kfree(wc);
4794 btrfs_free_path(path); 4990 btrfs_free_path(path);
4795 return ret; 4991 return err;
4796} 4992}
4797 4993
4994/*
4995 * drop subtree rooted at tree block 'node'.
4996 *
4997 * NOTE: this function will unlock and release tree block 'node'
4998 */
4798int btrfs_drop_subtree(struct btrfs_trans_handle *trans, 4999int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
4799 struct btrfs_root *root, 5000 struct btrfs_root *root,
4800 struct extent_buffer *node, 5001 struct extent_buffer *node,
4801 struct extent_buffer *parent) 5002 struct extent_buffer *parent)
4802{ 5003{
4803 struct btrfs_path *path; 5004 struct btrfs_path *path;
5005 struct walk_control *wc;
4804 int level; 5006 int level;
4805 int parent_level; 5007 int parent_level;
4806 int ret = 0; 5008 int ret = 0;
4807 int wret; 5009 int wret;
4808 5010
5011 BUG_ON(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID);
5012
4809 path = btrfs_alloc_path(); 5013 path = btrfs_alloc_path();
4810 BUG_ON(!path); 5014 BUG_ON(!path);
4811 5015
5016 wc = kzalloc(sizeof(*wc), GFP_NOFS);
5017 BUG_ON(!wc);
5018
4812 btrfs_assert_tree_locked(parent); 5019 btrfs_assert_tree_locked(parent);
4813 parent_level = btrfs_header_level(parent); 5020 parent_level = btrfs_header_level(parent);
4814 extent_buffer_get(parent); 5021 extent_buffer_get(parent);
@@ -4817,24 +5024,33 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
4817 5024
4818 btrfs_assert_tree_locked(node); 5025 btrfs_assert_tree_locked(node);
4819 level = btrfs_header_level(node); 5026 level = btrfs_header_level(node);
4820 extent_buffer_get(node);
4821 path->nodes[level] = node; 5027 path->nodes[level] = node;
4822 path->slots[level] = 0; 5028 path->slots[level] = 0;
5029 path->locks[level] = 1;
5030
5031 wc->refs[parent_level] = 1;
5032 wc->flags[parent_level] = BTRFS_BLOCK_FLAG_FULL_BACKREF;
5033 wc->level = level;
5034 wc->shared_level = -1;
5035 wc->stage = DROP_REFERENCE;
5036 wc->update_ref = 0;
5037 wc->keep_locks = 1;
4823 5038
4824 while (1) { 5039 while (1) {
4825 wret = walk_down_tree(trans, root, path, &level); 5040 wret = walk_down_tree(trans, root, path, wc);
4826 if (wret < 0) 5041 if (wret < 0) {
4827 ret = wret; 5042 ret = wret;
4828 if (wret != 0)
4829 break; 5043 break;
5044 }
4830 5045
4831 wret = walk_up_tree(trans, root, path, &level, parent_level); 5046 wret = walk_up_tree(trans, root, path, wc, parent_level);
4832 if (wret < 0) 5047 if (wret < 0)
4833 ret = wret; 5048 ret = wret;
4834 if (wret != 0) 5049 if (wret != 0)
4835 break; 5050 break;
4836 } 5051 }
4837 5052
5053 kfree(wc);
4838 btrfs_free_path(path); 5054 btrfs_free_path(path);
4839 return ret; 5055 return ret;
4840} 5056}
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 126477eaecf5..7c3cd248d8d6 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -151,7 +151,10 @@ static noinline int dirty_and_release_pages(struct btrfs_trans_handle *trans,
151 } 151 }
152 if (end_pos > isize) { 152 if (end_pos > isize) {
153 i_size_write(inode, end_pos); 153 i_size_write(inode, end_pos);
154 btrfs_update_inode(trans, root, inode); 154 /* we've only changed i_size in ram, and we haven't updated
155 * the disk i_size. There is no need to log the inode
156 * at this time.
157 */
155 } 158 }
156 err = btrfs_end_transaction(trans, root); 159 err = btrfs_end_transaction(trans, root);
157out_unlock: 160out_unlock:
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index dbe1aabf96cd..7ffa3d34ea19 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3580,12 +3580,6 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
3580 owner = 1; 3580 owner = 1;
3581 BTRFS_I(inode)->block_group = 3581 BTRFS_I(inode)->block_group =
3582 btrfs_find_block_group(root, 0, alloc_hint, owner); 3582 btrfs_find_block_group(root, 0, alloc_hint, owner);
3583 if ((mode & S_IFREG)) {
3584 if (btrfs_test_opt(root, NODATASUM))
3585 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
3586 if (btrfs_test_opt(root, NODATACOW))
3587 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
3588 }
3589 3583
3590 key[0].objectid = objectid; 3584 key[0].objectid = objectid;
3591 btrfs_set_key_type(&key[0], BTRFS_INODE_ITEM_KEY); 3585 btrfs_set_key_type(&key[0], BTRFS_INODE_ITEM_KEY);
@@ -3640,6 +3634,13 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
3640 3634
3641 btrfs_inherit_iflags(inode, dir); 3635 btrfs_inherit_iflags(inode, dir);
3642 3636
3637 if ((mode & S_IFREG)) {
3638 if (btrfs_test_opt(root, NODATASUM))
3639 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
3640 if (btrfs_test_opt(root, NODATACOW))
3641 BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
3642 }
3643
3643 insert_inode_hash(inode); 3644 insert_inode_hash(inode);
3644 inode_tree_add(inode); 3645 inode_tree_add(inode);
3645 return inode; 3646 return inode;
@@ -5082,6 +5083,7 @@ static long btrfs_fallocate(struct inode *inode, int mode,
5082 u64 mask = BTRFS_I(inode)->root->sectorsize - 1; 5083 u64 mask = BTRFS_I(inode)->root->sectorsize - 1;
5083 struct extent_map *em; 5084 struct extent_map *em;
5084 struct btrfs_trans_handle *trans; 5085 struct btrfs_trans_handle *trans;
5086 struct btrfs_root *root;
5085 int ret; 5087 int ret;
5086 5088
5087 alloc_start = offset & ~mask; 5089 alloc_start = offset & ~mask;
@@ -5100,6 +5102,13 @@ static long btrfs_fallocate(struct inode *inode, int mode,
5100 goto out; 5102 goto out;
5101 } 5103 }
5102 5104
5105 root = BTRFS_I(inode)->root;
5106
5107 ret = btrfs_check_data_free_space(root, inode,
5108 alloc_end - alloc_start);
5109 if (ret)
5110 goto out;
5111
5103 locked_end = alloc_end - 1; 5112 locked_end = alloc_end - 1;
5104 while (1) { 5113 while (1) {
5105 struct btrfs_ordered_extent *ordered; 5114 struct btrfs_ordered_extent *ordered;
@@ -5107,7 +5116,7 @@ static long btrfs_fallocate(struct inode *inode, int mode,
5107 trans = btrfs_start_transaction(BTRFS_I(inode)->root, 1); 5116 trans = btrfs_start_transaction(BTRFS_I(inode)->root, 1);
5108 if (!trans) { 5117 if (!trans) {
5109 ret = -EIO; 5118 ret = -EIO;
5110 goto out; 5119 goto out_free;
5111 } 5120 }
5112 5121
5113 /* the extent lock is ordered inside the running 5122 /* the extent lock is ordered inside the running
@@ -5168,6 +5177,8 @@ static long btrfs_fallocate(struct inode *inode, int mode,
5168 GFP_NOFS); 5177 GFP_NOFS);
5169 5178
5170 btrfs_end_transaction(trans, BTRFS_I(inode)->root); 5179 btrfs_end_transaction(trans, BTRFS_I(inode)->root);
5180out_free:
5181 btrfs_free_reserved_data_space(root, inode, alloc_end - alloc_start);
5171out: 5182out:
5172 mutex_unlock(&inode->i_mutex); 5183 mutex_unlock(&inode->i_mutex);
5173 return ret; 5184 return ret;
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index eff18f5b5362..9f4db848db10 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1028,7 +1028,8 @@ static long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
1028 struct btrfs_file_extent_item); 1028 struct btrfs_file_extent_item);
1029 comp = btrfs_file_extent_compression(leaf, extent); 1029 comp = btrfs_file_extent_compression(leaf, extent);
1030 type = btrfs_file_extent_type(leaf, extent); 1030 type = btrfs_file_extent_type(leaf, extent);
1031 if (type == BTRFS_FILE_EXTENT_REG) { 1031 if (type == BTRFS_FILE_EXTENT_REG ||
1032 type == BTRFS_FILE_EXTENT_PREALLOC) {
1032 disko = btrfs_file_extent_disk_bytenr(leaf, 1033 disko = btrfs_file_extent_disk_bytenr(leaf,
1033 extent); 1034 extent);
1034 diskl = btrfs_file_extent_disk_num_bytes(leaf, 1035 diskl = btrfs_file_extent_disk_num_bytes(leaf,
@@ -1051,7 +1052,8 @@ static long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
1051 new_key.objectid = inode->i_ino; 1052 new_key.objectid = inode->i_ino;
1052 new_key.offset = key.offset + destoff - off; 1053 new_key.offset = key.offset + destoff - off;
1053 1054
1054 if (type == BTRFS_FILE_EXTENT_REG) { 1055 if (type == BTRFS_FILE_EXTENT_REG ||
1056 type == BTRFS_FILE_EXTENT_PREALLOC) {
1055 ret = btrfs_insert_empty_item(trans, root, path, 1057 ret = btrfs_insert_empty_item(trans, root, path,
1056 &new_key, size); 1058 &new_key, size);
1057 if (ret) 1059 if (ret)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index b23dc209ae10..008397934778 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1788,7 +1788,7 @@ static void merge_func(struct btrfs_work *work)
1788 btrfs_end_transaction(trans, root); 1788 btrfs_end_transaction(trans, root);
1789 } 1789 }
1790 1790
1791 btrfs_drop_dead_root(reloc_root); 1791 btrfs_drop_snapshot(reloc_root, 0);
1792 1792
1793 if (atomic_dec_and_test(async->num_pending)) 1793 if (atomic_dec_and_test(async->num_pending))
1794 complete(async->done); 1794 complete(async->done);
@@ -2075,9 +2075,6 @@ static int do_relocation(struct btrfs_trans_handle *trans,
2075 2075
2076 ret = btrfs_drop_subtree(trans, root, eb, upper->eb); 2076 ret = btrfs_drop_subtree(trans, root, eb, upper->eb);
2077 BUG_ON(ret); 2077 BUG_ON(ret);
2078
2079 btrfs_tree_unlock(eb);
2080 free_extent_buffer(eb);
2081 } 2078 }
2082 if (!lowest) { 2079 if (!lowest) {
2083 btrfs_tree_unlock(upper->eb); 2080 btrfs_tree_unlock(upper->eb);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 4e83457ea253..2dbf1c1f56ee 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -593,6 +593,7 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly)
593 return 0; 593 return 0;
594} 594}
595 595
596#if 0
596/* 597/*
597 * when dropping snapshots, we generate a ton of delayed refs, and it makes 598 * when dropping snapshots, we generate a ton of delayed refs, and it makes
598 * sense not to join the transaction while it is trying to flush the current 599 * sense not to join the transaction while it is trying to flush the current
@@ -681,6 +682,7 @@ int btrfs_drop_dead_root(struct btrfs_root *root)
681 btrfs_btree_balance_dirty(tree_root, nr); 682 btrfs_btree_balance_dirty(tree_root, nr);
682 return ret; 683 return ret;
683} 684}
685#endif
684 686
685/* 687/*
686 * new snapshots need to be created at a very specific time in the 688 * new snapshots need to be created at a very specific time in the
@@ -1081,7 +1083,7 @@ int btrfs_clean_old_snapshots(struct btrfs_root *root)
1081 while (!list_empty(&list)) { 1083 while (!list_empty(&list)) {
1082 root = list_entry(list.next, struct btrfs_root, root_list); 1084 root = list_entry(list.next, struct btrfs_root, root_list);
1083 list_del_init(&root->root_list); 1085 list_del_init(&root->root_list);
1084 btrfs_drop_dead_root(root); 1086 btrfs_drop_snapshot(root, 0);
1085 } 1087 }
1086 return 0; 1088 return 0;
1087} 1089}
diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES
index b48689839428..3a9b7a58a51d 100644
--- a/fs/cifs/CHANGES
+++ b/fs/cifs/CHANGES
@@ -5,7 +5,7 @@ client generated ones by default (mount option "serverino" turned
5on by default if server supports it). Add forceuid and forcegid 5on by default if server supports it). Add forceuid and forcegid
6mount options (so that when negotiating unix extensions specifying 6mount options (so that when negotiating unix extensions specifying
7which uid mounted does not immediately force the server's reported 7which uid mounted does not immediately force the server's reported
8uids to be overridden). 8uids to be overridden). Add support for scope moutn parm.
9 9
10Version 1.58 10Version 1.58
11------------ 11------------
diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
index 1b09f1670061..20692fbfdb24 100644
--- a/fs/cifs/asn1.c
+++ b/fs/cifs/asn1.c
@@ -49,6 +49,7 @@
49#define ASN1_OJI 6 /* Object Identifier */ 49#define ASN1_OJI 6 /* Object Identifier */
50#define ASN1_OJD 7 /* Object Description */ 50#define ASN1_OJD 7 /* Object Description */
51#define ASN1_EXT 8 /* External */ 51#define ASN1_EXT 8 /* External */
52#define ASN1_ENUM 10 /* Enumerated */
52#define ASN1_SEQ 16 /* Sequence */ 53#define ASN1_SEQ 16 /* Sequence */
53#define ASN1_SET 17 /* Set */ 54#define ASN1_SET 17 /* Set */
54#define ASN1_NUMSTR 18 /* Numerical String */ 55#define ASN1_NUMSTR 18 /* Numerical String */
@@ -78,10 +79,12 @@
78#define SPNEGO_OID_LEN 7 79#define SPNEGO_OID_LEN 7
79#define NTLMSSP_OID_LEN 10 80#define NTLMSSP_OID_LEN 10
80#define KRB5_OID_LEN 7 81#define KRB5_OID_LEN 7
82#define KRB5U2U_OID_LEN 8
81#define MSKRB5_OID_LEN 7 83#define MSKRB5_OID_LEN 7
82static unsigned long SPNEGO_OID[7] = { 1, 3, 6, 1, 5, 5, 2 }; 84static unsigned long SPNEGO_OID[7] = { 1, 3, 6, 1, 5, 5, 2 };
83static unsigned long NTLMSSP_OID[10] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10 }; 85static unsigned long NTLMSSP_OID[10] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10 };
84static unsigned long KRB5_OID[7] = { 1, 2, 840, 113554, 1, 2, 2 }; 86static unsigned long KRB5_OID[7] = { 1, 2, 840, 113554, 1, 2, 2 };
87static unsigned long KRB5U2U_OID[8] = { 1, 2, 840, 113554, 1, 2, 2, 3 };
85static unsigned long MSKRB5_OID[7] = { 1, 2, 840, 48018, 1, 2, 2 }; 88static unsigned long MSKRB5_OID[7] = { 1, 2, 840, 48018, 1, 2, 2 };
86 89
87/* 90/*
@@ -122,6 +125,28 @@ asn1_octet_decode(struct asn1_ctx *ctx, unsigned char *ch)
122 return 1; 125 return 1;
123} 126}
124 127
128#if 0 /* will be needed later by spnego decoding/encoding of ntlmssp */
129static unsigned char
130asn1_enum_decode(struct asn1_ctx *ctx, __le32 *val)
131{
132 unsigned char ch;
133
134 if (ctx->pointer >= ctx->end) {
135 ctx->error = ASN1_ERR_DEC_EMPTY;
136 return 0;
137 }
138
139 ch = *(ctx->pointer)++; /* ch has 0xa, ptr points to lenght octet */
140 if ((ch) == ASN1_ENUM) /* if ch value is ENUM, 0xa */
141 *val = *(++(ctx->pointer)); /* value has enum value */
142 else
143 return 0;
144
145 ctx->pointer++;
146 return 1;
147}
148#endif
149
125static unsigned char 150static unsigned char
126asn1_tag_decode(struct asn1_ctx *ctx, unsigned int *tag) 151asn1_tag_decode(struct asn1_ctx *ctx, unsigned int *tag)
127{ 152{
@@ -476,10 +501,9 @@ decode_negTokenInit(unsigned char *security_blob, int length,
476 unsigned int cls, con, tag, oidlen, rc; 501 unsigned int cls, con, tag, oidlen, rc;
477 bool use_ntlmssp = false; 502 bool use_ntlmssp = false;
478 bool use_kerberos = false; 503 bool use_kerberos = false;
504 bool use_kerberosu2u = false;
479 bool use_mskerberos = false; 505 bool use_mskerberos = false;
480 506
481 *secType = NTLM; /* BB eventually make Kerberos or NLTMSSP the default*/
482
483 /* cifs_dump_mem(" Received SecBlob ", security_blob, length); */ 507 /* cifs_dump_mem(" Received SecBlob ", security_blob, length); */
484 508
485 asn1_open(&ctx, security_blob, length); 509 asn1_open(&ctx, security_blob, length);
@@ -515,6 +539,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
515 return 0; 539 return 0;
516 } 540 }
517 541
542 /* SPNEGO */
518 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 543 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
519 cFYI(1, ("Error decoding negTokenInit")); 544 cFYI(1, ("Error decoding negTokenInit"));
520 return 0; 545 return 0;
@@ -526,6 +551,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
526 return 0; 551 return 0;
527 } 552 }
528 553
554 /* negTokenInit */
529 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 555 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
530 cFYI(1, ("Error decoding negTokenInit")); 556 cFYI(1, ("Error decoding negTokenInit"));
531 return 0; 557 return 0;
@@ -537,6 +563,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
537 return 0; 563 return 0;
538 } 564 }
539 565
566 /* sequence */
540 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 567 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
541 cFYI(1, ("Error decoding 2nd part of negTokenInit")); 568 cFYI(1, ("Error decoding 2nd part of negTokenInit"));
542 return 0; 569 return 0;
@@ -548,6 +575,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
548 return 0; 575 return 0;
549 } 576 }
550 577
578 /* sequence of */
551 if (asn1_header_decode 579 if (asn1_header_decode
552 (&ctx, &sequence_end, &cls, &con, &tag) == 0) { 580 (&ctx, &sequence_end, &cls, &con, &tag) == 0) {
553 cFYI(1, ("Error decoding 2nd part of negTokenInit")); 581 cFYI(1, ("Error decoding 2nd part of negTokenInit"));
@@ -560,6 +588,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
560 return 0; 588 return 0;
561 } 589 }
562 590
591 /* list of security mechanisms */
563 while (!asn1_eoc_decode(&ctx, sequence_end)) { 592 while (!asn1_eoc_decode(&ctx, sequence_end)) {
564 rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag); 593 rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag);
565 if (!rc) { 594 if (!rc) {
@@ -576,11 +605,15 @@ decode_negTokenInit(unsigned char *security_blob, int length,
576 605
577 if (compare_oid(oid, oidlen, MSKRB5_OID, 606 if (compare_oid(oid, oidlen, MSKRB5_OID,
578 MSKRB5_OID_LEN) && 607 MSKRB5_OID_LEN) &&
579 !use_kerberos) 608 !use_mskerberos)
580 use_mskerberos = true; 609 use_mskerberos = true;
610 else if (compare_oid(oid, oidlen, KRB5U2U_OID,
611 KRB5U2U_OID_LEN) &&
612 !use_kerberosu2u)
613 use_kerberosu2u = true;
581 else if (compare_oid(oid, oidlen, KRB5_OID, 614 else if (compare_oid(oid, oidlen, KRB5_OID,
582 KRB5_OID_LEN) && 615 KRB5_OID_LEN) &&
583 !use_mskerberos) 616 !use_kerberos)
584 use_kerberos = true; 617 use_kerberos = true;
585 else if (compare_oid(oid, oidlen, NTLMSSP_OID, 618 else if (compare_oid(oid, oidlen, NTLMSSP_OID,
586 NTLMSSP_OID_LEN)) 619 NTLMSSP_OID_LEN))
@@ -593,7 +626,12 @@ decode_negTokenInit(unsigned char *security_blob, int length,
593 } 626 }
594 } 627 }
595 628
629 /* mechlistMIC */
596 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 630 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
631 /* Check if we have reached the end of the blob, but with
632 no mechListMic (e.g. NTLMSSP instead of KRB5) */
633 if (ctx.error == ASN1_ERR_DEC_EMPTY)
634 goto decode_negtoken_exit;
597 cFYI(1, ("Error decoding last part negTokenInit exit3")); 635 cFYI(1, ("Error decoding last part negTokenInit exit3"));
598 return 0; 636 return 0;
599 } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { 637 } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) {
@@ -602,6 +640,8 @@ decode_negTokenInit(unsigned char *security_blob, int length,
602 cls, con, tag, end, *end)); 640 cls, con, tag, end, *end));
603 return 0; 641 return 0;
604 } 642 }
643
644 /* sequence */
605 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 645 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
606 cFYI(1, ("Error decoding last part negTokenInit exit5")); 646 cFYI(1, ("Error decoding last part negTokenInit exit5"));
607 return 0; 647 return 0;
@@ -611,6 +651,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
611 cls, con, tag, end, *end)); 651 cls, con, tag, end, *end));
612 } 652 }
613 653
654 /* sequence of */
614 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 655 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
615 cFYI(1, ("Error decoding last part negTokenInit exit 7")); 656 cFYI(1, ("Error decoding last part negTokenInit exit 7"));
616 return 0; 657 return 0;
@@ -619,6 +660,8 @@ decode_negTokenInit(unsigned char *security_blob, int length,
619 cls, con, tag, end, *end)); 660 cls, con, tag, end, *end));
620 return 0; 661 return 0;
621 } 662 }
663
664 /* general string */
622 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 665 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
623 cFYI(1, ("Error decoding last part negTokenInit exit9")); 666 cFYI(1, ("Error decoding last part negTokenInit exit9"));
624 return 0; 667 return 0;
@@ -630,13 +673,13 @@ decode_negTokenInit(unsigned char *security_blob, int length,
630 } 673 }
631 cFYI(1, ("Need to call asn1_octets_decode() function for %s", 674 cFYI(1, ("Need to call asn1_octets_decode() function for %s",
632 ctx.pointer)); /* is this UTF-8 or ASCII? */ 675 ctx.pointer)); /* is this UTF-8 or ASCII? */
633 676decode_negtoken_exit:
634 if (use_kerberos) 677 if (use_kerberos)
635 *secType = Kerberos; 678 *secType = Kerberos;
636 else if (use_mskerberos) 679 else if (use_mskerberos)
637 *secType = MSKerberos; 680 *secType = MSKerberos;
638 else if (use_ntlmssp) 681 else if (use_ntlmssp)
639 *secType = NTLMSSP; 682 *secType = RawNTLMSSP;
640 683
641 return 1; 684 return 1;
642} 685}
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 0d92114195ab..9f669f982c4d 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -333,6 +333,27 @@ cifs_destroy_inode(struct inode *inode)
333 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode)); 333 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
334} 334}
335 335
336static void
337cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
338{
339 seq_printf(s, ",addr=");
340
341 switch (server->addr.sockAddr.sin_family) {
342 case AF_INET:
343 seq_printf(s, "%pI4", &server->addr.sockAddr.sin_addr.s_addr);
344 break;
345 case AF_INET6:
346 seq_printf(s, "%pI6",
347 &server->addr.sockAddr6.sin6_addr.s6_addr);
348 if (server->addr.sockAddr6.sin6_scope_id)
349 seq_printf(s, "%%%u",
350 server->addr.sockAddr6.sin6_scope_id);
351 break;
352 default:
353 seq_printf(s, "(unknown)");
354 }
355}
356
336/* 357/*
337 * cifs_show_options() is for displaying mount options in /proc/mounts. 358 * cifs_show_options() is for displaying mount options in /proc/mounts.
338 * Not all settable options are displayed but most of the important 359 * Not all settable options are displayed but most of the important
@@ -343,83 +364,64 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m)
343{ 364{
344 struct cifs_sb_info *cifs_sb; 365 struct cifs_sb_info *cifs_sb;
345 struct cifsTconInfo *tcon; 366 struct cifsTconInfo *tcon;
346 struct TCP_Server_Info *server;
347 367
348 cifs_sb = CIFS_SB(m->mnt_sb); 368 cifs_sb = CIFS_SB(m->mnt_sb);
369 tcon = cifs_sb->tcon;
349 370
350 if (cifs_sb) { 371 seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName);
351 tcon = cifs_sb->tcon; 372 if (tcon->ses->userName)
352 if (tcon) { 373 seq_printf(s, ",username=%s", tcon->ses->userName);
353 seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName); 374 if (tcon->ses->domainName)
354 if (tcon->ses) { 375 seq_printf(s, ",domain=%s", tcon->ses->domainName);
355 if (tcon->ses->userName) 376
356 seq_printf(s, ",username=%s", 377 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
357 tcon->ses->userName); 378 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
358 if (tcon->ses->domainName) 379 seq_printf(s, ",forceuid");
359 seq_printf(s, ",domain=%s", 380
360 tcon->ses->domainName); 381 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
361 server = tcon->ses->server; 382 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
362 if (server) { 383 seq_printf(s, ",forcegid");
363 seq_printf(s, ",addr="); 384
364 switch (server->addr.sockAddr6. 385 cifs_show_address(s, tcon->ses->server);
365 sin6_family) { 386
366 case AF_INET6: 387 if (!tcon->unix_ext)
367 seq_printf(s, "%pI6", 388 seq_printf(s, ",file_mode=0%o,dir_mode=0%o",
368 &server->addr.sockAddr6.sin6_addr);
369 break;
370 case AF_INET:
371 seq_printf(s, "%pI4",
372 &server->addr.sockAddr.sin_addr.s_addr);
373 break;
374 }
375 }
376 }
377 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) ||
378 !(tcon->unix_ext))
379 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
380 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) ||
381 !(tcon->unix_ext))
382 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
383 if (!tcon->unix_ext) {
384 seq_printf(s, ",file_mode=0%o,dir_mode=0%o",
385 cifs_sb->mnt_file_mode, 389 cifs_sb->mnt_file_mode,
386 cifs_sb->mnt_dir_mode); 390 cifs_sb->mnt_dir_mode);
387 } 391 if (tcon->seal)
388 if (tcon->seal) 392 seq_printf(s, ",seal");
389 seq_printf(s, ",seal"); 393 if (tcon->nocase)
390 if (tcon->nocase) 394 seq_printf(s, ",nocase");
391 seq_printf(s, ",nocase"); 395 if (tcon->retry)
392 if (tcon->retry) 396 seq_printf(s, ",hard");
393 seq_printf(s, ",hard"); 397 if (cifs_sb->prepath)
394 } 398 seq_printf(s, ",prepath=%s", cifs_sb->prepath);
395 if (cifs_sb->prepath) 399 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
396 seq_printf(s, ",prepath=%s", cifs_sb->prepath); 400 seq_printf(s, ",posixpaths");
397 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) 401 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
398 seq_printf(s, ",posixpaths"); 402 seq_printf(s, ",setuids");
399 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) 403 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
400 seq_printf(s, ",setuids"); 404 seq_printf(s, ",serverino");
401 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) 405 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
402 seq_printf(s, ",serverino"); 406 seq_printf(s, ",directio");
403 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) 407 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
404 seq_printf(s, ",directio"); 408 seq_printf(s, ",nouser_xattr");
405 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) 409 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
406 seq_printf(s, ",nouser_xattr"); 410 seq_printf(s, ",mapchars");
407 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR) 411 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
408 seq_printf(s, ",mapchars"); 412 seq_printf(s, ",sfu");
409 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) 413 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
410 seq_printf(s, ",sfu"); 414 seq_printf(s, ",nobrl");
411 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL) 415 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
412 seq_printf(s, ",nobrl"); 416 seq_printf(s, ",cifsacl");
413 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) 417 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
414 seq_printf(s, ",cifsacl"); 418 seq_printf(s, ",dynperm");
415 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) 419 if (m->mnt_sb->s_flags & MS_POSIXACL)
416 seq_printf(s, ",dynperm"); 420 seq_printf(s, ",acl");
417 if (m->mnt_sb->s_flags & MS_POSIXACL) 421
418 seq_printf(s, ",acl"); 422 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
419 423 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
420 seq_printf(s, ",rsize=%d", cifs_sb->rsize); 424
421 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
422 }
423 return 0; 425 return 0;
424} 426}
425 427
@@ -535,9 +537,14 @@ static void cifs_umount_begin(struct super_block *sb)
535 if (tcon == NULL) 537 if (tcon == NULL)
536 return; 538 return;
537 539
538 lock_kernel();
539 read_lock(&cifs_tcp_ses_lock); 540 read_lock(&cifs_tcp_ses_lock);
540 if (tcon->tc_count == 1) 541 if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
542 /* we have other mounts to same share or we have
543 already tried to force umount this and woken up
544 all waiting network requests, nothing to do */
545 read_unlock(&cifs_tcp_ses_lock);
546 return;
547 } else if (tcon->tc_count == 1)
541 tcon->tidStatus = CifsExiting; 548 tcon->tidStatus = CifsExiting;
542 read_unlock(&cifs_tcp_ses_lock); 549 read_unlock(&cifs_tcp_ses_lock);
543 550
@@ -552,9 +559,7 @@ static void cifs_umount_begin(struct super_block *sb)
552 wake_up_all(&tcon->ses->server->response_q); 559 wake_up_all(&tcon->ses->server->response_q);
553 msleep(1); 560 msleep(1);
554 } 561 }
555/* BB FIXME - finish add checks for tidStatus BB */
556 562
557 unlock_kernel();
558 return; 563 return;
559} 564}
560 565
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index a61ab772c6f6..e1225e6ded2f 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -83,7 +83,7 @@ enum securityEnum {
83 NTLM, /* Legacy NTLM012 auth with NTLM hash */ 83 NTLM, /* Legacy NTLM012 auth with NTLM hash */
84 NTLMv2, /* Legacy NTLM auth with NTLMv2 hash */ 84 NTLMv2, /* Legacy NTLM auth with NTLMv2 hash */
85 RawNTLMSSP, /* NTLMSSP without SPNEGO, NTLMv2 hash */ 85 RawNTLMSSP, /* NTLMSSP without SPNEGO, NTLMv2 hash */
86 NTLMSSP, /* NTLMSSP via SPNEGO, NTLMv2 hash */ 86/* NTLMSSP, */ /* can use rawNTLMSSP instead of NTLMSSP via SPNEGO */
87 Kerberos, /* Kerberos via SPNEGO */ 87 Kerberos, /* Kerberos via SPNEGO */
88 MSKerberos, /* MS Kerberos via SPNEGO */ 88 MSKerberos, /* MS Kerberos via SPNEGO */
89}; 89};
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index f9452329bcce..c419416a42ee 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -74,7 +74,7 @@ extern unsigned int smbCalcSize(struct smb_hdr *ptr);
74extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr); 74extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr);
75extern int decode_negTokenInit(unsigned char *security_blob, int length, 75extern int decode_negTokenInit(unsigned char *security_blob, int length,
76 enum securityEnum *secType); 76 enum securityEnum *secType);
77extern int cifs_inet_pton(const int, const char *source, void *dst); 77extern int cifs_convert_address(char *src, void *dst);
78extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr); 78extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr);
79extern void header_assemble(struct smb_hdr *, char /* command */ , 79extern void header_assemble(struct smb_hdr *, char /* command */ ,
80 const struct cifsTconInfo *, int /* length of 80 const struct cifsTconInfo *, int /* length of
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index b84c61d5bca4..61007c627497 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -594,7 +594,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
594 else if (secFlags & CIFSSEC_MAY_KRB5) 594 else if (secFlags & CIFSSEC_MAY_KRB5)
595 server->secType = Kerberos; 595 server->secType = Kerberos;
596 else if (secFlags & CIFSSEC_MAY_NTLMSSP) 596 else if (secFlags & CIFSSEC_MAY_NTLMSSP)
597 server->secType = NTLMSSP; 597 server->secType = RawNTLMSSP;
598 else if (secFlags & CIFSSEC_MAY_LANMAN) 598 else if (secFlags & CIFSSEC_MAY_LANMAN)
599 server->secType = LANMAN; 599 server->secType = LANMAN;
600/* #ifdef CONFIG_CIFS_EXPERIMENTAL 600/* #ifdef CONFIG_CIFS_EXPERIMENTAL
@@ -729,7 +729,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon)
729 * the tcon is no longer on the list, so no need to take lock before 729 * the tcon is no longer on the list, so no need to take lock before
730 * checking this. 730 * checking this.
731 */ 731 */
732 if (tcon->need_reconnect) 732 if ((tcon->need_reconnect) || (tcon->ses->need_reconnect))
733 return 0; 733 return 0;
734 734
735 rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, 735 rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon,
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 97f4311b9a8e..e16d7592116a 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -70,7 +70,6 @@ struct smb_vol {
70 mode_t file_mode; 70 mode_t file_mode;
71 mode_t dir_mode; 71 mode_t dir_mode;
72 unsigned secFlg; 72 unsigned secFlg;
73 bool rw:1;
74 bool retry:1; 73 bool retry:1;
75 bool intr:1; 74 bool intr:1;
76 bool setuids:1; 75 bool setuids:1;
@@ -832,7 +831,6 @@ cifs_parse_mount_options(char *options, const char *devname,
832 vol->dir_mode = vol->file_mode = S_IRUGO | S_IXUGO | S_IWUSR; 831 vol->dir_mode = vol->file_mode = S_IRUGO | S_IXUGO | S_IWUSR;
833 832
834 /* vol->retry default is 0 (i.e. "soft" limited retry not hard retry) */ 833 /* vol->retry default is 0 (i.e. "soft" limited retry not hard retry) */
835 vol->rw = true;
836 /* default is always to request posix paths. */ 834 /* default is always to request posix paths. */
837 vol->posix_paths = 1; 835 vol->posix_paths = 1;
838 /* default to using server inode numbers where available */ 836 /* default to using server inode numbers where available */
@@ -1199,7 +1197,9 @@ cifs_parse_mount_options(char *options, const char *devname,
1199 } else if (strnicmp(data, "guest", 5) == 0) { 1197 } else if (strnicmp(data, "guest", 5) == 0) {
1200 /* ignore */ 1198 /* ignore */
1201 } else if (strnicmp(data, "rw", 2) == 0) { 1199 } else if (strnicmp(data, "rw", 2) == 0) {
1202 vol->rw = true; 1200 /* ignore */
1201 } else if (strnicmp(data, "ro", 2) == 0) {
1202 /* ignore */
1203 } else if (strnicmp(data, "noblocksend", 11) == 0) { 1203 } else if (strnicmp(data, "noblocksend", 11) == 0) {
1204 vol->noblocksnd = 1; 1204 vol->noblocksnd = 1;
1205 } else if (strnicmp(data, "noautotune", 10) == 0) { 1205 } else if (strnicmp(data, "noautotune", 10) == 0) {
@@ -1218,8 +1218,6 @@ cifs_parse_mount_options(char *options, const char *devname,
1218 parse these options again and set anything and it 1218 parse these options again and set anything and it
1219 is ok to just ignore them */ 1219 is ok to just ignore them */
1220 continue; 1220 continue;
1221 } else if (strnicmp(data, "ro", 2) == 0) {
1222 vol->rw = false;
1223 } else if (strnicmp(data, "hard", 4) == 0) { 1221 } else if (strnicmp(data, "hard", 4) == 0) {
1224 vol->retry = 1; 1222 vol->retry = 1;
1225 } else if (strnicmp(data, "soft", 4) == 0) { 1223 } else if (strnicmp(data, "soft", 4) == 0) {
@@ -1386,8 +1384,10 @@ cifs_find_tcp_session(struct sockaddr_storage *addr)
1386 server->addr.sockAddr.sin_addr.s_addr)) 1384 server->addr.sockAddr.sin_addr.s_addr))
1387 continue; 1385 continue;
1388 else if (addr->ss_family == AF_INET6 && 1386 else if (addr->ss_family == AF_INET6 &&
1389 !ipv6_addr_equal(&server->addr.sockAddr6.sin6_addr, 1387 (!ipv6_addr_equal(&server->addr.sockAddr6.sin6_addr,
1390 &addr6->sin6_addr)) 1388 &addr6->sin6_addr) ||
1389 server->addr.sockAddr6.sin6_scope_id !=
1390 addr6->sin6_scope_id))
1391 continue; 1391 continue;
1392 1392
1393 ++server->srv_count; 1393 ++server->srv_count;
@@ -1433,28 +1433,15 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
1433 1433
1434 memset(&addr, 0, sizeof(struct sockaddr_storage)); 1434 memset(&addr, 0, sizeof(struct sockaddr_storage));
1435 1435
1436 if (volume_info->UNCip && volume_info->UNC) { 1436 cFYI(1, ("UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip));
1437 rc = cifs_inet_pton(AF_INET, volume_info->UNCip,
1438 &sin_server->sin_addr.s_addr);
1439
1440 if (rc <= 0) {
1441 /* not ipv4 address, try ipv6 */
1442 rc = cifs_inet_pton(AF_INET6, volume_info->UNCip,
1443 &sin_server6->sin6_addr.in6_u);
1444 if (rc > 0)
1445 addr.ss_family = AF_INET6;
1446 } else {
1447 addr.ss_family = AF_INET;
1448 }
1449 1437
1450 if (rc <= 0) { 1438 if (volume_info->UNCip && volume_info->UNC) {
1439 rc = cifs_convert_address(volume_info->UNCip, &addr);
1440 if (!rc) {
1451 /* we failed translating address */ 1441 /* we failed translating address */
1452 rc = -EINVAL; 1442 rc = -EINVAL;
1453 goto out_err; 1443 goto out_err;
1454 } 1444 }
1455
1456 cFYI(1, ("UNC: %s ip: %s", volume_info->UNC,
1457 volume_info->UNCip));
1458 } else if (volume_info->UNCip) { 1445 } else if (volume_info->UNCip) {
1459 /* BB using ip addr as tcp_ses name to connect to the 1446 /* BB using ip addr as tcp_ses name to connect to the
1460 DFS root below */ 1447 DFS root below */
@@ -1513,14 +1500,14 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
1513 cFYI(1, ("attempting ipv6 connect")); 1500 cFYI(1, ("attempting ipv6 connect"));
1514 /* BB should we allow ipv6 on port 139? */ 1501 /* BB should we allow ipv6 on port 139? */
1515 /* other OS never observed in Wild doing 139 with v6 */ 1502 /* other OS never observed in Wild doing 139 with v6 */
1503 sin_server6->sin6_port = htons(volume_info->port);
1516 memcpy(&tcp_ses->addr.sockAddr6, sin_server6, 1504 memcpy(&tcp_ses->addr.sockAddr6, sin_server6,
1517 sizeof(struct sockaddr_in6)); 1505 sizeof(struct sockaddr_in6));
1518 sin_server6->sin6_port = htons(volume_info->port);
1519 rc = ipv6_connect(tcp_ses); 1506 rc = ipv6_connect(tcp_ses);
1520 } else { 1507 } else {
1508 sin_server->sin_port = htons(volume_info->port);
1521 memcpy(&tcp_ses->addr.sockAddr, sin_server, 1509 memcpy(&tcp_ses->addr.sockAddr, sin_server,
1522 sizeof(struct sockaddr_in)); 1510 sizeof(struct sockaddr_in));
1523 sin_server->sin_port = htons(volume_info->port);
1524 rc = ipv4_connect(tcp_ses); 1511 rc = ipv4_connect(tcp_ses);
1525 } 1512 }
1526 if (rc < 0) { 1513 if (rc < 0) {
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 3758965d73d5..7dc6b74f9def 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -307,8 +307,9 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
307 307
308 full_path = build_path_from_dentry(direntry); 308 full_path = build_path_from_dentry(direntry);
309 if (full_path == NULL) { 309 if (full_path == NULL) {
310 rc = -ENOMEM;
310 FreeXid(xid); 311 FreeXid(xid);
311 return -ENOMEM; 312 return rc;
312 } 313 }
313 314
314 if (oplockEnabled) 315 if (oplockEnabled)
@@ -540,8 +541,9 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
540 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); 541 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
541 if (buf == NULL) { 542 if (buf == NULL) {
542 kfree(full_path); 543 kfree(full_path);
544 rc = -ENOMEM;
543 FreeXid(xid); 545 FreeXid(xid);
544 return -ENOMEM; 546 return rc;
545 } 547 }
546 548
547 rc = CIFSSMBOpen(xid, pTcon, full_path, 549 rc = CIFSSMBOpen(xid, pTcon, full_path,
diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c
index df4a306f697e..87948147d7ec 100644
--- a/fs/cifs/dns_resolve.c
+++ b/fs/cifs/dns_resolve.c
@@ -35,26 +35,11 @@
35 * 0 - name is not IP 35 * 0 - name is not IP
36 */ 36 */
37static int 37static int
38is_ip(const char *name) 38is_ip(char *name)
39{ 39{
40 int rc; 40 struct sockaddr_storage ss;
41 struct sockaddr_in sin_server; 41
42 struct sockaddr_in6 sin_server6; 42 return cifs_convert_address(name, &ss);
43
44 rc = cifs_inet_pton(AF_INET, name,
45 &sin_server.sin_addr.s_addr);
46
47 if (rc <= 0) {
48 /* not ipv4 address, try ipv6 */
49 rc = cifs_inet_pton(AF_INET6, name,
50 &sin_server6.sin6_addr.in6_u);
51 if (rc > 0)
52 return 1;
53 } else {
54 return 1;
55 }
56 /* we failed translating address */
57 return 0;
58} 43}
59 44
60static int 45static int
@@ -72,7 +57,7 @@ dns_resolver_instantiate(struct key *key, const void *data,
72 ip[datalen] = '\0'; 57 ip[datalen] = '\0';
73 58
74 /* make sure this looks like an address */ 59 /* make sure this looks like an address */
75 if (!is_ip((const char *) ip)) { 60 if (!is_ip(ip)) {
76 kfree(ip); 61 kfree(ip);
77 return -EINVAL; 62 return -EINVAL;
78 } 63 }
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 06866841b97f..97ce4bf89d15 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -300,14 +300,16 @@ int cifs_open(struct inode *inode, struct file *file)
300 pCifsInode = CIFS_I(file->f_path.dentry->d_inode); 300 pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
301 pCifsFile = cifs_fill_filedata(file); 301 pCifsFile = cifs_fill_filedata(file);
302 if (pCifsFile) { 302 if (pCifsFile) {
303 rc = 0;
303 FreeXid(xid); 304 FreeXid(xid);
304 return 0; 305 return rc;
305 } 306 }
306 307
307 full_path = build_path_from_dentry(file->f_path.dentry); 308 full_path = build_path_from_dentry(file->f_path.dentry);
308 if (full_path == NULL) { 309 if (full_path == NULL) {
310 rc = -ENOMEM;
309 FreeXid(xid); 311 FreeXid(xid);
310 return -ENOMEM; 312 return rc;
311 } 313 }
312 314
313 cFYI(1, ("inode = 0x%p file flags are 0x%x for %s", 315 cFYI(1, ("inode = 0x%p file flags are 0x%x for %s",
@@ -491,11 +493,12 @@ static int cifs_reopen_file(struct file *file, bool can_flush)
491 return -EBADF; 493 return -EBADF;
492 494
493 xid = GetXid(); 495 xid = GetXid();
494 mutex_unlock(&pCifsFile->fh_mutex); 496 mutex_lock(&pCifsFile->fh_mutex);
495 if (!pCifsFile->invalidHandle) { 497 if (!pCifsFile->invalidHandle) {
496 mutex_lock(&pCifsFile->fh_mutex); 498 mutex_unlock(&pCifsFile->fh_mutex);
499 rc = 0;
497 FreeXid(xid); 500 FreeXid(xid);
498 return 0; 501 return rc;
499 } 502 }
500 503
501 if (file->f_path.dentry == NULL) { 504 if (file->f_path.dentry == NULL) {
@@ -524,7 +527,7 @@ static int cifs_reopen_file(struct file *file, bool can_flush)
524 if (full_path == NULL) { 527 if (full_path == NULL) {
525 rc = -ENOMEM; 528 rc = -ENOMEM;
526reopen_error_exit: 529reopen_error_exit:
527 mutex_lock(&pCifsFile->fh_mutex); 530 mutex_unlock(&pCifsFile->fh_mutex);
528 FreeXid(xid); 531 FreeXid(xid);
529 return rc; 532 return rc;
530 } 533 }
@@ -566,14 +569,14 @@ reopen_error_exit:
566 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & 569 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
567 CIFS_MOUNT_MAP_SPECIAL_CHR); 570 CIFS_MOUNT_MAP_SPECIAL_CHR);
568 if (rc) { 571 if (rc) {
569 mutex_lock(&pCifsFile->fh_mutex); 572 mutex_unlock(&pCifsFile->fh_mutex);
570 cFYI(1, ("cifs_open returned 0x%x", rc)); 573 cFYI(1, ("cifs_open returned 0x%x", rc));
571 cFYI(1, ("oplock: %d", oplock)); 574 cFYI(1, ("oplock: %d", oplock));
572 } else { 575 } else {
573reopen_success: 576reopen_success:
574 pCifsFile->netfid = netfid; 577 pCifsFile->netfid = netfid;
575 pCifsFile->invalidHandle = false; 578 pCifsFile->invalidHandle = false;
576 mutex_lock(&pCifsFile->fh_mutex); 579 mutex_unlock(&pCifsFile->fh_mutex);
577 pCifsInode = CIFS_I(inode); 580 pCifsInode = CIFS_I(inode);
578 if (pCifsInode) { 581 if (pCifsInode) {
579 if (can_flush) { 582 if (can_flush) {
@@ -845,8 +848,9 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
845 tcon = cifs_sb->tcon; 848 tcon = cifs_sb->tcon;
846 849
847 if (file->private_data == NULL) { 850 if (file->private_data == NULL) {
851 rc = -EBADF;
848 FreeXid(xid); 852 FreeXid(xid);
849 return -EBADF; 853 return rc;
850 } 854 }
851 netfid = ((struct cifsFileInfo *)file->private_data)->netfid; 855 netfid = ((struct cifsFileInfo *)file->private_data)->netfid;
852 856
@@ -1805,8 +1809,9 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
1805 pTcon = cifs_sb->tcon; 1809 pTcon = cifs_sb->tcon;
1806 1810
1807 if (file->private_data == NULL) { 1811 if (file->private_data == NULL) {
1812 rc = -EBADF;
1808 FreeXid(xid); 1813 FreeXid(xid);
1809 return -EBADF; 1814 return rc;
1810 } 1815 }
1811 open_file = (struct cifsFileInfo *)file->private_data; 1816 open_file = (struct cifsFileInfo *)file->private_data;
1812 1817
@@ -1885,8 +1890,9 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
1885 pTcon = cifs_sb->tcon; 1890 pTcon = cifs_sb->tcon;
1886 1891
1887 if (file->private_data == NULL) { 1892 if (file->private_data == NULL) {
1893 rc = -EBADF;
1888 FreeXid(xid); 1894 FreeXid(xid);
1889 return -EBADF; 1895 return rc;
1890 } 1896 }
1891 open_file = (struct cifsFileInfo *)file->private_data; 1897 open_file = (struct cifsFileInfo *)file->private_data;
1892 1898
@@ -2019,8 +2025,9 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
2019 2025
2020 xid = GetXid(); 2026 xid = GetXid();
2021 if (file->private_data == NULL) { 2027 if (file->private_data == NULL) {
2028 rc = -EBADF;
2022 FreeXid(xid); 2029 FreeXid(xid);
2023 return -EBADF; 2030 return rc;
2024 } 2031 }
2025 open_file = (struct cifsFileInfo *)file->private_data; 2032 open_file = (struct cifsFileInfo *)file->private_data;
2026 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 2033 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
@@ -2185,8 +2192,9 @@ static int cifs_readpage(struct file *file, struct page *page)
2185 xid = GetXid(); 2192 xid = GetXid();
2186 2193
2187 if (file->private_data == NULL) { 2194 if (file->private_data == NULL) {
2195 rc = -EBADF;
2188 FreeXid(xid); 2196 FreeXid(xid);
2189 return -EBADF; 2197 return rc;
2190 } 2198 }
2191 2199
2192 cFYI(1, ("readpage %p at offset %d 0x%x\n", 2200 cFYI(1, ("readpage %p at offset %d 0x%x\n",
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index fad882b075ba..155c9e785d0c 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -988,8 +988,9 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
988 * sb->s_vfs_rename_mutex here */ 988 * sb->s_vfs_rename_mutex here */
989 full_path = build_path_from_dentry(dentry); 989 full_path = build_path_from_dentry(dentry);
990 if (full_path == NULL) { 990 if (full_path == NULL) {
991 rc = -ENOMEM;
991 FreeXid(xid); 992 FreeXid(xid);
992 return -ENOMEM; 993 return rc;
993 } 994 }
994 995
995 if ((tcon->ses->capabilities & CAP_UNIX) && 996 if ((tcon->ses->capabilities & CAP_UNIX) &&
@@ -1118,8 +1119,9 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
1118 1119
1119 full_path = build_path_from_dentry(direntry); 1120 full_path = build_path_from_dentry(direntry);
1120 if (full_path == NULL) { 1121 if (full_path == NULL) {
1122 rc = -ENOMEM;
1121 FreeXid(xid); 1123 FreeXid(xid);
1122 return -ENOMEM; 1124 return rc;
1123 } 1125 }
1124 1126
1125 if ((pTcon->ses->capabilities & CAP_UNIX) && 1127 if ((pTcon->ses->capabilities & CAP_UNIX) &&
@@ -1303,8 +1305,9 @@ int cifs_rmdir(struct inode *inode, struct dentry *direntry)
1303 1305
1304 full_path = build_path_from_dentry(direntry); 1306 full_path = build_path_from_dentry(direntry);
1305 if (full_path == NULL) { 1307 if (full_path == NULL) {
1308 rc = -ENOMEM;
1306 FreeXid(xid); 1309 FreeXid(xid);
1307 return -ENOMEM; 1310 return rc;
1308 } 1311 }
1309 1312
1310 rc = CIFSSMBRmDir(xid, pTcon, full_path, cifs_sb->local_nls, 1313 rc = CIFSSMBRmDir(xid, pTcon, full_path, cifs_sb->local_nls,
@@ -1508,8 +1511,9 @@ int cifs_revalidate(struct dentry *direntry)
1508 since that would deadlock */ 1511 since that would deadlock */
1509 full_path = build_path_from_dentry(direntry); 1512 full_path = build_path_from_dentry(direntry);
1510 if (full_path == NULL) { 1513 if (full_path == NULL) {
1514 rc = -ENOMEM;
1511 FreeXid(xid); 1515 FreeXid(xid);
1512 return -ENOMEM; 1516 return rc;
1513 } 1517 }
1514 cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld " 1518 cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld "
1515 "jiffies %ld", full_path, direntry->d_inode, 1519 "jiffies %ld", full_path, direntry->d_inode,
@@ -1911,8 +1915,9 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
1911 1915
1912 full_path = build_path_from_dentry(direntry); 1916 full_path = build_path_from_dentry(direntry);
1913 if (full_path == NULL) { 1917 if (full_path == NULL) {
1918 rc = -ENOMEM;
1914 FreeXid(xid); 1919 FreeXid(xid);
1915 return -ENOMEM; 1920 return rc;
1916 } 1921 }
1917 1922
1918 /* 1923 /*
diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index cd83c53fcbb5..fc1e0487eaee 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -172,8 +172,9 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
172 full_path = build_path_from_dentry(direntry); 172 full_path = build_path_from_dentry(direntry);
173 173
174 if (full_path == NULL) { 174 if (full_path == NULL) {
175 rc = -ENOMEM;
175 FreeXid(xid); 176 FreeXid(xid);
176 return -ENOMEM; 177 return rc;
177 } 178 }
178 179
179 cFYI(1, ("Full path: %s", full_path)); 180 cFYI(1, ("Full path: %s", full_path));
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index 32d6baa0a54f..bd6d6895730d 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -133,10 +133,12 @@ static const struct smb_to_posix_error mapping_table_ERRHRD[] = {
133 {0, 0} 133 {0, 0}
134}; 134};
135 135
136/* Convert string containing dotted ip address to binary form */ 136/*
137/* returns 0 if invalid address */ 137 * Convert a string containing text IPv4 or IPv6 address to binary form.
138 138 *
139int 139 * Returns 0 on failure.
140 */
141static int
140cifs_inet_pton(const int address_family, const char *cp, void *dst) 142cifs_inet_pton(const int address_family, const char *cp, void *dst)
141{ 143{
142 int ret = 0; 144 int ret = 0;
@@ -153,6 +155,52 @@ cifs_inet_pton(const int address_family, const char *cp, void *dst)
153 return ret; 155 return ret;
154} 156}
155 157
158/*
159 * Try to convert a string to an IPv4 address and then attempt to convert
160 * it to an IPv6 address if that fails. Set the family field if either
161 * succeeds. If it's an IPv6 address and it has a '%' sign in it, try to
162 * treat the part following it as a numeric sin6_scope_id.
163 *
164 * Returns 0 on failure.
165 */
166int
167cifs_convert_address(char *src, void *dst)
168{
169 int rc;
170 char *pct, *endp;
171 struct sockaddr_in *s4 = (struct sockaddr_in *) dst;
172 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) dst;
173
174 /* IPv4 address */
175 if (cifs_inet_pton(AF_INET, src, &s4->sin_addr.s_addr)) {
176 s4->sin_family = AF_INET;
177 return 1;
178 }
179
180 /* temporarily terminate string */
181 pct = strchr(src, '%');
182 if (pct)
183 *pct = '\0';
184
185 rc = cifs_inet_pton(AF_INET6, src, &s6->sin6_addr.s6_addr);
186
187 /* repair temp termination (if any) and make pct point to scopeid */
188 if (pct)
189 *pct++ = '%';
190
191 if (!rc)
192 return rc;
193
194 s6->sin6_family = AF_INET6;
195 if (pct) {
196 s6->sin6_scope_id = (u32) simple_strtoul(pct, &endp, 0);
197 if (!*pct || *endp)
198 return 0;
199 }
200
201 return rc;
202}
203
156/***************************************************************************** 204/*****************************************************************************
157convert a NT status code to a dos class/code 205convert a NT status code to a dos class/code
158 *****************************************************************************/ 206 *****************************************************************************/
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index 897a052270f9..7085a6275c4c 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -802,7 +802,7 @@ ssetup_ntlmssp_authenticate:
802#endif /* CONFIG_CIFS_UPCALL */ 802#endif /* CONFIG_CIFS_UPCALL */
803 } else { 803 } else {
804#ifdef CONFIG_CIFS_EXPERIMENTAL 804#ifdef CONFIG_CIFS_EXPERIMENTAL
805 if ((experimEnabled > 1) && (type == RawNTLMSSP)) { 805 if (type == RawNTLMSSP) {
806 if ((pSMB->req.hdr.Flags2 & SMBFLG2_UNICODE) == 0) { 806 if ((pSMB->req.hdr.Flags2 & SMBFLG2_UNICODE) == 0) {
807 cERROR(1, ("NTLMSSP requires Unicode support")); 807 cERROR(1, ("NTLMSSP requires Unicode support"));
808 rc = -ENOSYS; 808 rc = -ENOSYS;
diff --git a/fs/cifs/xattr.c b/fs/cifs/xattr.c
index e9527eedc639..a75afa3dd9e1 100644
--- a/fs/cifs/xattr.c
+++ b/fs/cifs/xattr.c
@@ -64,8 +64,9 @@ int cifs_removexattr(struct dentry *direntry, const char *ea_name)
64 64
65 full_path = build_path_from_dentry(direntry); 65 full_path = build_path_from_dentry(direntry);
66 if (full_path == NULL) { 66 if (full_path == NULL) {
67 rc = -ENOMEM;
67 FreeXid(xid); 68 FreeXid(xid);
68 return -ENOMEM; 69 return rc;
69 } 70 }
70 if (ea_name == NULL) { 71 if (ea_name == NULL) {
71 cFYI(1, ("Null xattr names not supported")); 72 cFYI(1, ("Null xattr names not supported"));
@@ -118,8 +119,9 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
118 119
119 full_path = build_path_from_dentry(direntry); 120 full_path = build_path_from_dentry(direntry);
120 if (full_path == NULL) { 121 if (full_path == NULL) {
122 rc = -ENOMEM;
121 FreeXid(xid); 123 FreeXid(xid);
122 return -ENOMEM; 124 return rc;
123 } 125 }
124 /* return dos attributes as pseudo xattr */ 126 /* return dos attributes as pseudo xattr */
125 /* return alt name if available as pseudo attr */ 127 /* return alt name if available as pseudo attr */
@@ -225,8 +227,9 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
225 227
226 full_path = build_path_from_dentry(direntry); 228 full_path = build_path_from_dentry(direntry);
227 if (full_path == NULL) { 229 if (full_path == NULL) {
230 rc = -ENOMEM;
228 FreeXid(xid); 231 FreeXid(xid);
229 return -ENOMEM; 232 return rc;
230 } 233 }
231 /* return dos attributes as pseudo xattr */ 234 /* return dos attributes as pseudo xattr */
232 /* return alt name if available as pseudo attr */ 235 /* return alt name if available as pseudo attr */
@@ -351,8 +354,9 @@ ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
351 354
352 full_path = build_path_from_dentry(direntry); 355 full_path = build_path_from_dentry(direntry);
353 if (full_path == NULL) { 356 if (full_path == NULL) {
357 rc = -ENOMEM;
354 FreeXid(xid); 358 FreeXid(xid);
355 return -ENOMEM; 359 return rc;
356 } 360 }
357 /* return dos attributes as pseudo xattr */ 361 /* return dos attributes as pseudo xattr */
358 /* return alt name if available as pseudo attr */ 362 /* return alt name if available as pseudo attr */
diff --git a/fs/dlm/netlink.c b/fs/dlm/netlink.c
index ccc9d62c462d..55ea369f43a9 100644
--- a/fs/dlm/netlink.c
+++ b/fs/dlm/netlink.c
@@ -63,7 +63,7 @@ static int send_data(struct sk_buff *skb)
63 return rv; 63 return rv;
64 } 64 }
65 65
66 return genlmsg_unicast(skb, listener_nlpid); 66 return genlmsg_unicast(&init_net, skb, listener_nlpid);
67} 67}
68 68
69static int user_cmd(struct sk_buff *skb, struct genl_info *info) 69static int user_cmd(struct sk_buff *skb, struct genl_info *info)
diff --git a/fs/eventfd.c b/fs/eventfd.c
index 3f0e1974abdc..31d12de83a2a 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -14,35 +14,44 @@
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/spinlock.h> 15#include <linux/spinlock.h>
16#include <linux/anon_inodes.h> 16#include <linux/anon_inodes.h>
17#include <linux/eventfd.h>
18#include <linux/syscalls.h> 17#include <linux/syscalls.h>
19#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/kref.h>
20#include <linux/eventfd.h>
20 21
21struct eventfd_ctx { 22struct eventfd_ctx {
23 struct kref kref;
22 wait_queue_head_t wqh; 24 wait_queue_head_t wqh;
23 /* 25 /*
24 * Every time that a write(2) is performed on an eventfd, the 26 * Every time that a write(2) is performed on an eventfd, the
25 * value of the __u64 being written is added to "count" and a 27 * value of the __u64 being written is added to "count" and a
26 * wakeup is performed on "wqh". A read(2) will return the "count" 28 * wakeup is performed on "wqh". A read(2) will return the "count"
27 * value to userspace, and will reset "count" to zero. The kernel 29 * value to userspace, and will reset "count" to zero. The kernel
28 * size eventfd_signal() also, adds to the "count" counter and 30 * side eventfd_signal() also, adds to the "count" counter and
29 * issue a wakeup. 31 * issue a wakeup.
30 */ 32 */
31 __u64 count; 33 __u64 count;
32 unsigned int flags; 34 unsigned int flags;
33}; 35};
34 36
35/* 37/**
36 * Adds "n" to the eventfd counter "count". Returns "n" in case of 38 * eventfd_signal - Adds @n to the eventfd counter.
37 * success, or a value lower then "n" in case of coutner overflow. 39 * @ctx: [in] Pointer to the eventfd context.
38 * This function is supposed to be called by the kernel in paths 40 * @n: [in] Value of the counter to be added to the eventfd internal counter.
39 * that do not allow sleeping. In this function we allow the counter 41 * The value cannot be negative.
40 * to reach the ULLONG_MAX value, and we signal this as overflow 42 *
41 * condition by returining a POLLERR to poll(2). 43 * This function is supposed to be called by the kernel in paths that do not
44 * allow sleeping. In this function we allow the counter to reach the ULLONG_MAX
45 * value, and we signal this as overflow condition by returining a POLLERR
46 * to poll(2).
47 *
48 * Returns @n in case of success, a non-negative number lower than @n in case
49 * of overflow, or the following error codes:
50 *
51 * -EINVAL : The value of @n is negative.
42 */ 52 */
43int eventfd_signal(struct file *file, int n) 53int eventfd_signal(struct eventfd_ctx *ctx, int n)
44{ 54{
45 struct eventfd_ctx *ctx = file->private_data;
46 unsigned long flags; 55 unsigned long flags;
47 56
48 if (n < 0) 57 if (n < 0)
@@ -59,9 +68,45 @@ int eventfd_signal(struct file *file, int n)
59} 68}
60EXPORT_SYMBOL_GPL(eventfd_signal); 69EXPORT_SYMBOL_GPL(eventfd_signal);
61 70
71static void eventfd_free(struct kref *kref)
72{
73 struct eventfd_ctx *ctx = container_of(kref, struct eventfd_ctx, kref);
74
75 kfree(ctx);
76}
77
78/**
79 * eventfd_ctx_get - Acquires a reference to the internal eventfd context.
80 * @ctx: [in] Pointer to the eventfd context.
81 *
82 * Returns: In case of success, returns a pointer to the eventfd context.
83 */
84struct eventfd_ctx *eventfd_ctx_get(struct eventfd_ctx *ctx)
85{
86 kref_get(&ctx->kref);
87 return ctx;
88}
89EXPORT_SYMBOL_GPL(eventfd_ctx_get);
90
91/**
92 * eventfd_ctx_put - Releases a reference to the internal eventfd context.
93 * @ctx: [in] Pointer to eventfd context.
94 *
95 * The eventfd context reference must have been previously acquired either
96 * with eventfd_ctx_get() or eventfd_ctx_fdget()).
97 */
98void eventfd_ctx_put(struct eventfd_ctx *ctx)
99{
100 kref_put(&ctx->kref, eventfd_free);
101}
102EXPORT_SYMBOL_GPL(eventfd_ctx_put);
103
62static int eventfd_release(struct inode *inode, struct file *file) 104static int eventfd_release(struct inode *inode, struct file *file)
63{ 105{
64 kfree(file->private_data); 106 struct eventfd_ctx *ctx = file->private_data;
107
108 wake_up_poll(&ctx->wqh, POLLHUP);
109 eventfd_ctx_put(ctx);
65 return 0; 110 return 0;
66} 111}
67 112
@@ -185,6 +230,16 @@ static const struct file_operations eventfd_fops = {
185 .write = eventfd_write, 230 .write = eventfd_write,
186}; 231};
187 232
233/**
234 * eventfd_fget - Acquire a reference of an eventfd file descriptor.
235 * @fd: [in] Eventfd file descriptor.
236 *
237 * Returns a pointer to the eventfd file structure in case of success, or the
238 * following error pointer:
239 *
240 * -EBADF : Invalid @fd file descriptor.
241 * -EINVAL : The @fd file descriptor is not an eventfd file.
242 */
188struct file *eventfd_fget(int fd) 243struct file *eventfd_fget(int fd)
189{ 244{
190 struct file *file; 245 struct file *file;
@@ -201,6 +256,48 @@ struct file *eventfd_fget(int fd)
201} 256}
202EXPORT_SYMBOL_GPL(eventfd_fget); 257EXPORT_SYMBOL_GPL(eventfd_fget);
203 258
259/**
260 * eventfd_ctx_fdget - Acquires a reference to the internal eventfd context.
261 * @fd: [in] Eventfd file descriptor.
262 *
263 * Returns a pointer to the internal eventfd context, otherwise the error
264 * pointers returned by the following functions:
265 *
266 * eventfd_fget
267 */
268struct eventfd_ctx *eventfd_ctx_fdget(int fd)
269{
270 struct file *file;
271 struct eventfd_ctx *ctx;
272
273 file = eventfd_fget(fd);
274 if (IS_ERR(file))
275 return (struct eventfd_ctx *) file;
276 ctx = eventfd_ctx_get(file->private_data);
277 fput(file);
278
279 return ctx;
280}
281EXPORT_SYMBOL_GPL(eventfd_ctx_fdget);
282
283/**
284 * eventfd_ctx_fileget - Acquires a reference to the internal eventfd context.
285 * @file: [in] Eventfd file pointer.
286 *
287 * Returns a pointer to the internal eventfd context, otherwise the error
288 * pointer:
289 *
290 * -EINVAL : The @fd file descriptor is not an eventfd file.
291 */
292struct eventfd_ctx *eventfd_ctx_fileget(struct file *file)
293{
294 if (file->f_op != &eventfd_fops)
295 return ERR_PTR(-EINVAL);
296
297 return eventfd_ctx_get(file->private_data);
298}
299EXPORT_SYMBOL_GPL(eventfd_ctx_fileget);
300
204SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags) 301SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags)
205{ 302{
206 int fd; 303 int fd;
@@ -217,6 +314,7 @@ SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags)
217 if (!ctx) 314 if (!ctx)
218 return -ENOMEM; 315 return -ENOMEM;
219 316
317 kref_init(&ctx->kref);
220 init_waitqueue_head(&ctx->wqh); 318 init_waitqueue_head(&ctx->wqh);
221 ctx->count = count; 319 ctx->count = count;
222 ctx->flags = flags; 320 ctx->flags = flags;
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index 6524ecaebb7a..e1dedb0f7873 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -66,8 +66,16 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, str
66 inode = NULL; 66 inode = NULL;
67 if (ino) { 67 if (ino) {
68 inode = ext2_iget(dir->i_sb, ino); 68 inode = ext2_iget(dir->i_sb, ino);
69 if (IS_ERR(inode)) 69 if (unlikely(IS_ERR(inode))) {
70 return ERR_CAST(inode); 70 if (PTR_ERR(inode) == -ESTALE) {
71 ext2_error(dir->i_sb, __func__,
72 "deleted inode referenced: %lu",
73 ino);
74 return ERR_PTR(-EIO);
75 } else {
76 return ERR_CAST(inode);
77 }
78 }
71 } 79 }
72 return d_splice_alias(inode, dentry); 80 return d_splice_alias(inode, dentry);
73} 81}
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 8fed2ed12f38..f58ecbc416c8 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -849,6 +849,81 @@ err:
849 return err; 849 return err;
850} 850}
851 851
852static int fuse_notify_inval_inode(struct fuse_conn *fc, unsigned int size,
853 struct fuse_copy_state *cs)
854{
855 struct fuse_notify_inval_inode_out outarg;
856 int err = -EINVAL;
857
858 if (size != sizeof(outarg))
859 goto err;
860
861 err = fuse_copy_one(cs, &outarg, sizeof(outarg));
862 if (err)
863 goto err;
864 fuse_copy_finish(cs);
865
866 down_read(&fc->killsb);
867 err = -ENOENT;
868 if (!fc->sb)
869 goto err_unlock;
870
871 err = fuse_reverse_inval_inode(fc->sb, outarg.ino,
872 outarg.off, outarg.len);
873
874err_unlock:
875 up_read(&fc->killsb);
876 return err;
877
878err:
879 fuse_copy_finish(cs);
880 return err;
881}
882
883static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
884 struct fuse_copy_state *cs)
885{
886 struct fuse_notify_inval_entry_out outarg;
887 int err = -EINVAL;
888 char buf[FUSE_NAME_MAX+1];
889 struct qstr name;
890
891 if (size < sizeof(outarg))
892 goto err;
893
894 err = fuse_copy_one(cs, &outarg, sizeof(outarg));
895 if (err)
896 goto err;
897
898 err = -ENAMETOOLONG;
899 if (outarg.namelen > FUSE_NAME_MAX)
900 goto err;
901
902 name.name = buf;
903 name.len = outarg.namelen;
904 err = fuse_copy_one(cs, buf, outarg.namelen + 1);
905 if (err)
906 goto err;
907 fuse_copy_finish(cs);
908 buf[outarg.namelen] = 0;
909 name.hash = full_name_hash(name.name, name.len);
910
911 down_read(&fc->killsb);
912 err = -ENOENT;
913 if (!fc->sb)
914 goto err_unlock;
915
916 err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
917
918err_unlock:
919 up_read(&fc->killsb);
920 return err;
921
922err:
923 fuse_copy_finish(cs);
924 return err;
925}
926
852static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code, 927static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
853 unsigned int size, struct fuse_copy_state *cs) 928 unsigned int size, struct fuse_copy_state *cs)
854{ 929{
@@ -856,6 +931,12 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
856 case FUSE_NOTIFY_POLL: 931 case FUSE_NOTIFY_POLL:
857 return fuse_notify_poll(fc, size, cs); 932 return fuse_notify_poll(fc, size, cs);
858 933
934 case FUSE_NOTIFY_INVAL_INODE:
935 return fuse_notify_inval_inode(fc, size, cs);
936
937 case FUSE_NOTIFY_INVAL_ENTRY:
938 return fuse_notify_inval_entry(fc, size, cs);
939
859 default: 940 default:
860 fuse_copy_finish(cs); 941 fuse_copy_finish(cs);
861 return -EINVAL; 942 return -EINVAL;
@@ -910,7 +991,7 @@ static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
910 unsigned long nr_segs, loff_t pos) 991 unsigned long nr_segs, loff_t pos)
911{ 992{
912 int err; 993 int err;
913 unsigned nbytes = iov_length(iov, nr_segs); 994 size_t nbytes = iov_length(iov, nr_segs);
914 struct fuse_req *req; 995 struct fuse_req *req;
915 struct fuse_out_header oh; 996 struct fuse_out_header oh;
916 struct fuse_copy_state cs; 997 struct fuse_copy_state cs;
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index b3089a083d30..e703654e7f40 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -375,7 +375,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
375 struct fuse_conn *fc = get_fuse_conn(dir); 375 struct fuse_conn *fc = get_fuse_conn(dir);
376 struct fuse_req *req; 376 struct fuse_req *req;
377 struct fuse_req *forget_req; 377 struct fuse_req *forget_req;
378 struct fuse_open_in inarg; 378 struct fuse_create_in inarg;
379 struct fuse_open_out outopen; 379 struct fuse_open_out outopen;
380 struct fuse_entry_out outentry; 380 struct fuse_entry_out outentry;
381 struct fuse_file *ff; 381 struct fuse_file *ff;
@@ -399,15 +399,20 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
399 if (!ff) 399 if (!ff)
400 goto out_put_request; 400 goto out_put_request;
401 401
402 if (!fc->dont_mask)
403 mode &= ~current_umask();
404
402 flags &= ~O_NOCTTY; 405 flags &= ~O_NOCTTY;
403 memset(&inarg, 0, sizeof(inarg)); 406 memset(&inarg, 0, sizeof(inarg));
404 memset(&outentry, 0, sizeof(outentry)); 407 memset(&outentry, 0, sizeof(outentry));
405 inarg.flags = flags; 408 inarg.flags = flags;
406 inarg.mode = mode; 409 inarg.mode = mode;
410 inarg.umask = current_umask();
407 req->in.h.opcode = FUSE_CREATE; 411 req->in.h.opcode = FUSE_CREATE;
408 req->in.h.nodeid = get_node_id(dir); 412 req->in.h.nodeid = get_node_id(dir);
409 req->in.numargs = 2; 413 req->in.numargs = 2;
410 req->in.args[0].size = sizeof(inarg); 414 req->in.args[0].size = fc->minor < 12 ? sizeof(struct fuse_open_in) :
415 sizeof(inarg);
411 req->in.args[0].value = &inarg; 416 req->in.args[0].value = &inarg;
412 req->in.args[1].size = entry->d_name.len + 1; 417 req->in.args[1].size = entry->d_name.len + 1;
413 req->in.args[1].value = entry->d_name.name; 418 req->in.args[1].value = entry->d_name.name;
@@ -546,12 +551,17 @@ static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode,
546 if (IS_ERR(req)) 551 if (IS_ERR(req))
547 return PTR_ERR(req); 552 return PTR_ERR(req);
548 553
554 if (!fc->dont_mask)
555 mode &= ~current_umask();
556
549 memset(&inarg, 0, sizeof(inarg)); 557 memset(&inarg, 0, sizeof(inarg));
550 inarg.mode = mode; 558 inarg.mode = mode;
551 inarg.rdev = new_encode_dev(rdev); 559 inarg.rdev = new_encode_dev(rdev);
560 inarg.umask = current_umask();
552 req->in.h.opcode = FUSE_MKNOD; 561 req->in.h.opcode = FUSE_MKNOD;
553 req->in.numargs = 2; 562 req->in.numargs = 2;
554 req->in.args[0].size = sizeof(inarg); 563 req->in.args[0].size = fc->minor < 12 ? FUSE_COMPAT_MKNOD_IN_SIZE :
564 sizeof(inarg);
555 req->in.args[0].value = &inarg; 565 req->in.args[0].value = &inarg;
556 req->in.args[1].size = entry->d_name.len + 1; 566 req->in.args[1].size = entry->d_name.len + 1;
557 req->in.args[1].value = entry->d_name.name; 567 req->in.args[1].value = entry->d_name.name;
@@ -578,8 +588,12 @@ static int fuse_mkdir(struct inode *dir, struct dentry *entry, int mode)
578 if (IS_ERR(req)) 588 if (IS_ERR(req))
579 return PTR_ERR(req); 589 return PTR_ERR(req);
580 590
591 if (!fc->dont_mask)
592 mode &= ~current_umask();
593
581 memset(&inarg, 0, sizeof(inarg)); 594 memset(&inarg, 0, sizeof(inarg));
582 inarg.mode = mode; 595 inarg.mode = mode;
596 inarg.umask = current_umask();
583 req->in.h.opcode = FUSE_MKDIR; 597 req->in.h.opcode = FUSE_MKDIR;
584 req->in.numargs = 2; 598 req->in.numargs = 2;
585 req->in.args[0].size = sizeof(inarg); 599 req->in.args[0].size = sizeof(inarg);
@@ -845,6 +859,43 @@ int fuse_update_attributes(struct inode *inode, struct kstat *stat,
845 return err; 859 return err;
846} 860}
847 861
862int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
863 struct qstr *name)
864{
865 int err = -ENOTDIR;
866 struct inode *parent;
867 struct dentry *dir;
868 struct dentry *entry;
869
870 parent = ilookup5(sb, parent_nodeid, fuse_inode_eq, &parent_nodeid);
871 if (!parent)
872 return -ENOENT;
873
874 mutex_lock(&parent->i_mutex);
875 if (!S_ISDIR(parent->i_mode))
876 goto unlock;
877
878 err = -ENOENT;
879 dir = d_find_alias(parent);
880 if (!dir)
881 goto unlock;
882
883 entry = d_lookup(dir, name);
884 dput(dir);
885 if (!entry)
886 goto unlock;
887
888 fuse_invalidate_attr(parent);
889 fuse_invalidate_entry(entry);
890 dput(entry);
891 err = 0;
892
893 unlock:
894 mutex_unlock(&parent->i_mutex);
895 iput(parent);
896 return err;
897}
898
848/* 899/*
849 * Calling into a user-controlled filesystem gives the filesystem 900 * Calling into a user-controlled filesystem gives the filesystem
850 * daemon ptrace-like capabilities over the requester process. This 901 * daemon ptrace-like capabilities over the requester process. This
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index fce6ce694fde..cbc464043b6f 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1922,7 +1922,7 @@ unsigned fuse_file_poll(struct file *file, poll_table *wait)
1922 1922
1923 req = fuse_get_req(fc); 1923 req = fuse_get_req(fc);
1924 if (IS_ERR(req)) 1924 if (IS_ERR(req))
1925 return PTR_ERR(req); 1925 return POLLERR;
1926 1926
1927 req->in.h.opcode = FUSE_POLL; 1927 req->in.h.opcode = FUSE_POLL;
1928 req->in.h.nodeid = ff->nodeid; 1928 req->in.h.nodeid = ff->nodeid;
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index aaf2f9ff970e..52b641fc0faf 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -446,6 +446,9 @@ struct fuse_conn {
446 /** Do multi-page cached writes */ 446 /** Do multi-page cached writes */
447 unsigned big_writes:1; 447 unsigned big_writes:1;
448 448
449 /** Don't apply umask to creation modes */
450 unsigned dont_mask:1;
451
449 /** The number of requests waiting for completion */ 452 /** The number of requests waiting for completion */
450 atomic_t num_waiting; 453 atomic_t num_waiting;
451 454
@@ -481,6 +484,12 @@ struct fuse_conn {
481 484
482 /** Called on final put */ 485 /** Called on final put */
483 void (*release)(struct fuse_conn *); 486 void (*release)(struct fuse_conn *);
487
488 /** Super block for this connection. */
489 struct super_block *sb;
490
491 /** Read/write semaphore to hold when accessing sb. */
492 struct rw_semaphore killsb;
484}; 493};
485 494
486static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 495static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
@@ -509,6 +518,11 @@ extern const struct file_operations fuse_dev_operations;
509extern const struct dentry_operations fuse_dentry_operations; 518extern const struct dentry_operations fuse_dentry_operations;
510 519
511/** 520/**
521 * Inode to nodeid comparison.
522 */
523int fuse_inode_eq(struct inode *inode, void *_nodeidp);
524
525/**
512 * Get a filled in inode 526 * Get a filled in inode
513 */ 527 */
514struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 528struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
@@ -708,6 +722,19 @@ void fuse_release_nowrite(struct inode *inode);
708 722
709u64 fuse_get_attr_version(struct fuse_conn *fc); 723u64 fuse_get_attr_version(struct fuse_conn *fc);
710 724
725/**
726 * File-system tells the kernel to invalidate cache for the given node id.
727 */
728int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
729 loff_t offset, loff_t len);
730
731/**
732 * File-system tells the kernel to invalidate parent attributes and
733 * the dentry matching parent/name.
734 */
735int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
736 struct qstr *name);
737
711int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 738int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
712 bool isdir); 739 bool isdir);
713ssize_t fuse_direct_io(struct file *file, const char __user *buf, 740ssize_t fuse_direct_io(struct file *file, const char __user *buf,
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index d8673ccf90b7..f91ccc4a189d 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -206,7 +206,7 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
206 BUG(); 206 BUG();
207} 207}
208 208
209static int fuse_inode_eq(struct inode *inode, void *_nodeidp) 209int fuse_inode_eq(struct inode *inode, void *_nodeidp)
210{ 210{
211 u64 nodeid = *(u64 *) _nodeidp; 211 u64 nodeid = *(u64 *) _nodeidp;
212 if (get_node_id(inode) == nodeid) 212 if (get_node_id(inode) == nodeid)
@@ -257,6 +257,31 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
257 return inode; 257 return inode;
258} 258}
259 259
260int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
261 loff_t offset, loff_t len)
262{
263 struct inode *inode;
264 pgoff_t pg_start;
265 pgoff_t pg_end;
266
267 inode = ilookup5(sb, nodeid, fuse_inode_eq, &nodeid);
268 if (!inode)
269 return -ENOENT;
270
271 fuse_invalidate_attr(inode);
272 if (offset >= 0) {
273 pg_start = offset >> PAGE_CACHE_SHIFT;
274 if (len <= 0)
275 pg_end = -1;
276 else
277 pg_end = (offset + len - 1) >> PAGE_CACHE_SHIFT;
278 invalidate_inode_pages2_range(inode->i_mapping,
279 pg_start, pg_end);
280 }
281 iput(inode);
282 return 0;
283}
284
260static void fuse_umount_begin(struct super_block *sb) 285static void fuse_umount_begin(struct super_block *sb)
261{ 286{
262 fuse_abort_conn(get_fuse_conn_super(sb)); 287 fuse_abort_conn(get_fuse_conn_super(sb));
@@ -480,6 +505,7 @@ void fuse_conn_init(struct fuse_conn *fc)
480 memset(fc, 0, sizeof(*fc)); 505 memset(fc, 0, sizeof(*fc));
481 spin_lock_init(&fc->lock); 506 spin_lock_init(&fc->lock);
482 mutex_init(&fc->inst_mutex); 507 mutex_init(&fc->inst_mutex);
508 init_rwsem(&fc->killsb);
483 atomic_set(&fc->count, 1); 509 atomic_set(&fc->count, 1);
484 init_waitqueue_head(&fc->waitq); 510 init_waitqueue_head(&fc->waitq);
485 init_waitqueue_head(&fc->blocked_waitq); 511 init_waitqueue_head(&fc->blocked_waitq);
@@ -725,6 +751,8 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
725 } 751 }
726 if (arg->flags & FUSE_BIG_WRITES) 752 if (arg->flags & FUSE_BIG_WRITES)
727 fc->big_writes = 1; 753 fc->big_writes = 1;
754 if (arg->flags & FUSE_DONT_MASK)
755 fc->dont_mask = 1;
728 } else { 756 } else {
729 ra_pages = fc->max_read / PAGE_CACHE_SIZE; 757 ra_pages = fc->max_read / PAGE_CACHE_SIZE;
730 fc->no_lock = 1; 758 fc->no_lock = 1;
@@ -748,7 +776,7 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req)
748 arg->minor = FUSE_KERNEL_MINOR_VERSION; 776 arg->minor = FUSE_KERNEL_MINOR_VERSION;
749 arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE; 777 arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE;
750 arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_ATOMIC_O_TRUNC | 778 arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_ATOMIC_O_TRUNC |
751 FUSE_EXPORT_SUPPORT | FUSE_BIG_WRITES; 779 FUSE_EXPORT_SUPPORT | FUSE_BIG_WRITES | FUSE_DONT_MASK;
752 req->in.h.opcode = FUSE_INIT; 780 req->in.h.opcode = FUSE_INIT;
753 req->in.numargs = 1; 781 req->in.numargs = 1;
754 req->in.args[0].size = sizeof(*arg); 782 req->in.args[0].size = sizeof(*arg);
@@ -860,10 +888,16 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
860 fuse_conn_init(fc); 888 fuse_conn_init(fc);
861 889
862 fc->dev = sb->s_dev; 890 fc->dev = sb->s_dev;
891 fc->sb = sb;
863 err = fuse_bdi_init(fc, sb); 892 err = fuse_bdi_init(fc, sb);
864 if (err) 893 if (err)
865 goto err_put_conn; 894 goto err_put_conn;
866 895
896 /* Handle umasking inside the fuse code */
897 if (sb->s_flags & MS_POSIXACL)
898 fc->dont_mask = 1;
899 sb->s_flags |= MS_POSIXACL;
900
867 fc->release = fuse_free_conn; 901 fc->release = fuse_free_conn;
868 fc->flags = d.flags; 902 fc->flags = d.flags;
869 fc->user_id = d.user_id; 903 fc->user_id = d.user_id;
@@ -941,12 +975,25 @@ static int fuse_get_sb(struct file_system_type *fs_type,
941 return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super, mnt); 975 return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super, mnt);
942} 976}
943 977
978static void fuse_kill_sb_anon(struct super_block *sb)
979{
980 struct fuse_conn *fc = get_fuse_conn_super(sb);
981
982 if (fc) {
983 down_write(&fc->killsb);
984 fc->sb = NULL;
985 up_write(&fc->killsb);
986 }
987
988 kill_anon_super(sb);
989}
990
944static struct file_system_type fuse_fs_type = { 991static struct file_system_type fuse_fs_type = {
945 .owner = THIS_MODULE, 992 .owner = THIS_MODULE,
946 .name = "fuse", 993 .name = "fuse",
947 .fs_flags = FS_HAS_SUBTYPE, 994 .fs_flags = FS_HAS_SUBTYPE,
948 .get_sb = fuse_get_sb, 995 .get_sb = fuse_get_sb,
949 .kill_sb = kill_anon_super, 996 .kill_sb = fuse_kill_sb_anon,
950}; 997};
951 998
952#ifdef CONFIG_BLOCK 999#ifdef CONFIG_BLOCK
@@ -958,11 +1005,24 @@ static int fuse_get_sb_blk(struct file_system_type *fs_type,
958 mnt); 1005 mnt);
959} 1006}
960 1007
1008static void fuse_kill_sb_blk(struct super_block *sb)
1009{
1010 struct fuse_conn *fc = get_fuse_conn_super(sb);
1011
1012 if (fc) {
1013 down_write(&fc->killsb);
1014 fc->sb = NULL;
1015 up_write(&fc->killsb);
1016 }
1017
1018 kill_block_super(sb);
1019}
1020
961static struct file_system_type fuseblk_fs_type = { 1021static struct file_system_type fuseblk_fs_type = {
962 .owner = THIS_MODULE, 1022 .owner = THIS_MODULE,
963 .name = "fuseblk", 1023 .name = "fuseblk",
964 .get_sb = fuse_get_sb_blk, 1024 .get_sb = fuse_get_sb_blk,
965 .kill_sb = kill_block_super, 1025 .kill_sb = fuse_kill_sb_blk,
966 .fs_flags = FS_REQUIRES_DEV | FS_HAS_SUBTYPE, 1026 .fs_flags = FS_REQUIRES_DEV | FS_HAS_SUBTYPE,
967}; 1027};
968 1028
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index fe02ad4740e7..032604e5ef2c 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -972,6 +972,7 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
972 sb->s_blocksize_bits = 10; 972 sb->s_blocksize_bits = 10;
973 sb->s_magic = HOSTFS_SUPER_MAGIC; 973 sb->s_magic = HOSTFS_SUPER_MAGIC;
974 sb->s_op = &hostfs_sbops; 974 sb->s_op = &hostfs_sbops;
975 sb->s_maxbytes = MAX_LFS_FILESIZE;
975 976
976 /* NULL is printed as <NULL> by sprintf: avoid that. */ 977 /* NULL is printed as <NULL> by sprintf: avoid that. */
977 if (req_root == NULL) 978 if (req_root == NULL)
diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c
index 7515e73e2bfb..696686cc206e 100644
--- a/fs/jffs2/scan.c
+++ b/fs/jffs2/scan.c
@@ -130,9 +130,9 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
130 if (jffs2_sum_active()) { 130 if (jffs2_sum_active()) {
131 s = kzalloc(sizeof(struct jffs2_summary), GFP_KERNEL); 131 s = kzalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
132 if (!s) { 132 if (!s) {
133 kfree(flashbuf);
134 JFFS2_WARNING("Can't allocate memory for summary\n"); 133 JFFS2_WARNING("Can't allocate memory for summary\n");
135 return -ENOMEM; 134 ret = -ENOMEM;
135 goto out;
136 } 136 }
137 } 137 }
138 138
diff --git a/fs/namei.c b/fs/namei.c
index 5b961eb71cbf..f3c5b278895a 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1761,6 +1761,10 @@ do_last:
1761 goto exit; 1761 goto exit;
1762 } 1762 }
1763 filp = nameidata_to_filp(&nd, open_flag); 1763 filp = nameidata_to_filp(&nd, open_flag);
1764 if (IS_ERR(filp))
1765 ima_counts_put(&nd.path,
1766 acc_mode & (MAY_READ | MAY_WRITE |
1767 MAY_EXEC));
1764 mnt_drop_write(nd.path.mnt); 1768 mnt_drop_write(nd.path.mnt);
1765 if (nd.root.mnt) 1769 if (nd.root.mnt)
1766 path_put(&nd.root); 1770 path_put(&nd.root);
@@ -1817,6 +1821,9 @@ ok:
1817 goto exit; 1821 goto exit;
1818 } 1822 }
1819 filp = nameidata_to_filp(&nd, open_flag); 1823 filp = nameidata_to_filp(&nd, open_flag);
1824 if (IS_ERR(filp))
1825 ima_counts_put(&nd.path,
1826 acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC));
1820 /* 1827 /*
1821 * It is now safe to drop the mnt write 1828 * It is now safe to drop the mnt write
1822 * because the filp has had a write taken 1829 * because the filp has had a write taken
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 4145083dcf88..23341c1063bc 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -678,7 +678,6 @@ __be32
678nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, 678nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
679 int access, struct file **filp) 679 int access, struct file **filp)
680{ 680{
681 const struct cred *cred = current_cred();
682 struct dentry *dentry; 681 struct dentry *dentry;
683 struct inode *inode; 682 struct inode *inode;
684 int flags = O_RDONLY|O_LARGEFILE; 683 int flags = O_RDONLY|O_LARGEFILE;
@@ -733,7 +732,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
733 vfs_dq_init(inode); 732 vfs_dq_init(inode);
734 } 733 }
735 *filp = dentry_open(dget(dentry), mntget(fhp->fh_export->ex_path.mnt), 734 *filp = dentry_open(dget(dentry), mntget(fhp->fh_export->ex_path.mnt),
736 flags, cred); 735 flags, current_cred());
737 if (IS_ERR(*filp)) 736 if (IS_ERR(*filp))
738 host_err = PTR_ERR(*filp); 737 host_err = PTR_ERR(*filp);
739 else 738 else
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index ff231ad23895..ff27a2965844 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -296,12 +296,15 @@ static int inotify_fasync(int fd, struct file *file, int on)
296static int inotify_release(struct inode *ignored, struct file *file) 296static int inotify_release(struct inode *ignored, struct file *file)
297{ 297{
298 struct fsnotify_group *group = file->private_data; 298 struct fsnotify_group *group = file->private_data;
299 struct user_struct *user = group->inotify_data.user;
299 300
300 fsnotify_clear_marks_by_group(group); 301 fsnotify_clear_marks_by_group(group);
301 302
302 /* free this group, matching get was inotify_init->fsnotify_obtain_group */ 303 /* free this group, matching get was inotify_init->fsnotify_obtain_group */
303 fsnotify_put_group(group); 304 fsnotify_put_group(group);
304 305
306 atomic_dec(&user->inotify_devs);
307
305 return 0; 308 return 0;
306} 309}
307 310
diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h
index d7d50d7ee51e..aa00800adacc 100644
--- a/include/asm-generic/percpu.h
+++ b/include/asm-generic/percpu.h
@@ -97,4 +97,8 @@ extern void setup_per_cpu_areas(void);
97#define PER_CPU_ATTRIBUTES 97#define PER_CPU_ATTRIBUTES
98#endif 98#endif
99 99
100#ifndef PER_CPU_DEF_ATTRIBUTES
101#define PER_CPU_DEF_ATTRIBUTES
102#endif
103
100#endif /* _ASM_GENERIC_PERCPU_H_ */ 104#endif /* _ASM_GENERIC_PERCPU_H_ */
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 92b73b6140ff..a553f1041cf1 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -191,7 +191,7 @@
191 . = ALIGN(align); \ 191 . = ALIGN(align); \
192 *(.data.cacheline_aligned) 192 *(.data.cacheline_aligned)
193 193
194#define INIT_TASK(align) \ 194#define INIT_TASK_DATA(align) \
195 . = ALIGN(align); \ 195 . = ALIGN(align); \
196 *(.data.init_task) 196 *(.data.init_task)
197 197
@@ -434,14 +434,15 @@
434/* 434/*
435 * Init task 435 * Init task
436 */ 436 */
437#define INIT_TASK_DATA(align) \ 437#define INIT_TASK_DATA_SECTION(align) \
438 . = ALIGN(align); \ 438 . = ALIGN(align); \
439 .data.init_task : { \ 439 .data.init_task : { \
440 INIT_TASK \ 440 INIT_TASK_DATA(align) \
441 } 441 }
442 442
443#ifdef CONFIG_CONSTRUCTORS 443#ifdef CONFIG_CONSTRUCTORS
444#define KERNEL_CTORS() VMLINUX_SYMBOL(__ctors_start) = .; \ 444#define KERNEL_CTORS() . = ALIGN(8); \
445 VMLINUX_SYMBOL(__ctors_start) = .; \
445 *(.ctors) \ 446 *(.ctors) \
446 VMLINUX_SYMBOL(__ctors_end) = .; 447 VMLINUX_SYMBOL(__ctors_end) = .;
447#else 448#else
@@ -704,15 +705,15 @@
704 * matches the requirment of PAGE_ALIGNED_DATA. 705 * matches the requirment of PAGE_ALIGNED_DATA.
705 * 706 *
706 * use 0 as page_align if page_aligned data is not used */ 707 * use 0 as page_align if page_aligned data is not used */
707#define RW_DATA_SECTION(cacheline, nosave, pagealigned, inittask) \ 708#define RW_DATA_SECTION(cacheline, pagealigned, inittask) \
708 . = ALIGN(PAGE_SIZE); \ 709 . = ALIGN(PAGE_SIZE); \
709 .data : AT(ADDR(.data) - LOAD_OFFSET) { \ 710 .data : AT(ADDR(.data) - LOAD_OFFSET) { \
710 INIT_TASK(inittask) \ 711 INIT_TASK_DATA(inittask) \
711 CACHELINE_ALIGNED_DATA(cacheline) \ 712 CACHELINE_ALIGNED_DATA(cacheline) \
712 READ_MOSTLY_DATA(cacheline) \ 713 READ_MOSTLY_DATA(cacheline) \
713 DATA_DATA \ 714 DATA_DATA \
714 CONSTRUCTORS \ 715 CONSTRUCTORS \
715 NOSAVE_DATA(nosave) \ 716 NOSAVE_DATA \
716 PAGE_ALIGNED_DATA(pagealigned) \ 717 PAGE_ALIGNED_DATA(pagealigned) \
717 } 718 }
718 719
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index c263e4d71754..7d6c9a2dfcbb 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -35,11 +35,11 @@ struct est_timings {
35} __attribute__((packed)); 35} __attribute__((packed));
36 36
37/* 00=16:10, 01=4:3, 10=5:4, 11=16:9 */ 37/* 00=16:10, 01=4:3, 10=5:4, 11=16:9 */
38#define EDID_TIMING_ASPECT_SHIFT 0 38#define EDID_TIMING_ASPECT_SHIFT 6
39#define EDID_TIMING_ASPECT_MASK (0x3 << EDID_TIMING_ASPECT_SHIFT) 39#define EDID_TIMING_ASPECT_MASK (0x3 << EDID_TIMING_ASPECT_SHIFT)
40 40
41/* need to add 60 */ 41/* need to add 60 */
42#define EDID_TIMING_VFREQ_SHIFT 2 42#define EDID_TIMING_VFREQ_SHIFT 0
43#define EDID_TIMING_VFREQ_MASK (0x3f << EDID_TIMING_VFREQ_SHIFT) 43#define EDID_TIMING_VFREQ_MASK (0x3f << EDID_TIMING_VFREQ_SHIFT)
44 44
45struct std_timing { 45struct std_timing {
@@ -47,11 +47,11 @@ struct std_timing {
47 u8 vfreq_aspect; 47 u8 vfreq_aspect;
48} __attribute__((packed)); 48} __attribute__((packed));
49 49
50#define DRM_EDID_PT_HSYNC_POSITIVE (1 << 6) 50#define DRM_EDID_PT_HSYNC_POSITIVE (1 << 1)
51#define DRM_EDID_PT_VSYNC_POSITIVE (1 << 5) 51#define DRM_EDID_PT_VSYNC_POSITIVE (1 << 2)
52#define DRM_EDID_PT_SEPARATE_SYNC (3 << 3) 52#define DRM_EDID_PT_SEPARATE_SYNC (3 << 3)
53#define DRM_EDID_PT_STEREO (1 << 2) 53#define DRM_EDID_PT_STEREO (1 << 5)
54#define DRM_EDID_PT_INTERLACED (1 << 1) 54#define DRM_EDID_PT_INTERLACED (1 << 7)
55 55
56/* If detailed data is pixel timing */ 56/* If detailed data is pixel timing */
57struct detailed_pixel_timing { 57struct detailed_pixel_timing {
@@ -93,7 +93,7 @@ struct detailed_data_monitor_range {
93} __attribute__((packed)); 93} __attribute__((packed));
94 94
95struct detailed_data_wpindex { 95struct detailed_data_wpindex {
96 u8 white_xy_lo; /* Upper 2 bits each */ 96 u8 white_yx_lo; /* Lower 2 bits each */
97 u8 white_x_hi; 97 u8 white_x_hi;
98 u8 white_y_hi; 98 u8 white_y_hi;
99 u8 gamma; /* need to divide by 100 then add 1 */ 99 u8 gamma; /* need to divide by 100 then add 1 */
@@ -135,21 +135,21 @@ struct detailed_timing {
135 } data; 135 } data;
136} __attribute__((packed)); 136} __attribute__((packed));
137 137
138#define DRM_EDID_INPUT_SERRATION_VSYNC (1 << 7) 138#define DRM_EDID_INPUT_SERRATION_VSYNC (1 << 0)
139#define DRM_EDID_INPUT_SYNC_ON_GREEN (1 << 5) 139#define DRM_EDID_INPUT_SYNC_ON_GREEN (1 << 1)
140#define DRM_EDID_INPUT_COMPOSITE_SYNC (1 << 4) 140#define DRM_EDID_INPUT_COMPOSITE_SYNC (1 << 2)
141#define DRM_EDID_INPUT_SEPARATE_SYNCS (1 << 3) 141#define DRM_EDID_INPUT_SEPARATE_SYNCS (1 << 3)
142#define DRM_EDID_INPUT_BLANK_TO_BLACK (1 << 2) 142#define DRM_EDID_INPUT_BLANK_TO_BLACK (1 << 4)
143#define DRM_EDID_INPUT_VIDEO_LEVEL (3 << 1) 143#define DRM_EDID_INPUT_VIDEO_LEVEL (3 << 5)
144#define DRM_EDID_INPUT_DIGITAL (1 << 0) /* bits above must be zero if set */ 144#define DRM_EDID_INPUT_DIGITAL (1 << 7) /* bits below must be zero if set */
145 145
146#define DRM_EDID_FEATURE_DEFAULT_GTF (1 << 7) 146#define DRM_EDID_FEATURE_DEFAULT_GTF (1 << 0)
147#define DRM_EDID_FEATURE_PREFERRED_TIMING (1 << 6) 147#define DRM_EDID_FEATURE_PREFERRED_TIMING (1 << 1)
148#define DRM_EDID_FEATURE_STANDARD_COLOR (1 << 5) 148#define DRM_EDID_FEATURE_STANDARD_COLOR (1 << 2)
149#define DRM_EDID_FEATURE_DISPLAY_TYPE (3 << 3) /* 00=mono, 01=rgb, 10=non-rgb, 11=unknown */ 149#define DRM_EDID_FEATURE_DISPLAY_TYPE (3 << 3) /* 00=mono, 01=rgb, 10=non-rgb, 11=unknown */
150#define DRM_EDID_FEATURE_PM_ACTIVE_OFF (1 << 2) 150#define DRM_EDID_FEATURE_PM_ACTIVE_OFF (1 << 5)
151#define DRM_EDID_FEATURE_PM_SUSPEND (1 << 1) 151#define DRM_EDID_FEATURE_PM_SUSPEND (1 << 6)
152#define DRM_EDID_FEATURE_PM_STANDBY (1 << 0) 152#define DRM_EDID_FEATURE_PM_STANDBY (1 << 7)
153 153
154struct edid { 154struct edid {
155 u8 header[8]; 155 u8 header[8];
diff --git a/include/linux/aio.h b/include/linux/aio.h
index b16a957030f8..47f7d932a01d 100644
--- a/include/linux/aio.h
+++ b/include/linux/aio.h
@@ -121,9 +121,9 @@ struct kiocb {
121 121
122 /* 122 /*
123 * If the aio_resfd field of the userspace iocb is not zero, 123 * If the aio_resfd field of the userspace iocb is not zero,
124 * this is the underlying file* to deliver event to. 124 * this is the underlying eventfd context to deliver events to.
125 */ 125 */
126 struct file *ki_eventfd; 126 struct eventfd_ctx *ki_eventfd;
127}; 127};
128 128
129#define is_sync_kiocb(iocb) ((iocb)->ki_key == KIOCB_SYNC_KEY) 129#define is_sync_kiocb(iocb) ((iocb)->ki_key == KIOCB_SYNC_KEY)
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 2a04eb54c0dd..2892b710771c 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -319,7 +319,6 @@ static inline int bio_has_allocated_vec(struct bio *bio)
319 */ 319 */
320struct bio_integrity_payload { 320struct bio_integrity_payload {
321 struct bio *bip_bio; /* parent bio */ 321 struct bio *bip_bio; /* parent bio */
322 struct bio_vec *bip_vec; /* integrity data vector */
323 322
324 sector_t bip_sector; /* virtual start sector */ 323 sector_t bip_sector; /* virtual start sector */
325 324
@@ -328,11 +327,12 @@ struct bio_integrity_payload {
328 327
329 unsigned int bip_size; 328 unsigned int bip_size;
330 329
331 unsigned short bip_pool; /* pool the ivec came from */ 330 unsigned short bip_slab; /* slab the bip came from */
332 unsigned short bip_vcnt; /* # of integrity bio_vecs */ 331 unsigned short bip_vcnt; /* # of integrity bio_vecs */
333 unsigned short bip_idx; /* current bip_vec index */ 332 unsigned short bip_idx; /* current bip_vec index */
334 333
335 struct work_struct bip_work; /* I/O completion */ 334 struct work_struct bip_work; /* I/O completion */
335 struct bio_vec bip_vec[0]; /* embedded bvec array */
336}; 336};
337#endif /* CONFIG_BLK_DEV_INTEGRITY */ 337#endif /* CONFIG_BLK_DEV_INTEGRITY */
338 338
@@ -430,6 +430,9 @@ struct bio_set {
430 unsigned int front_pad; 430 unsigned int front_pad;
431 431
432 mempool_t *bio_pool; 432 mempool_t *bio_pool;
433#if defined(CONFIG_BLK_DEV_INTEGRITY)
434 mempool_t *bio_integrity_pool;
435#endif
433 mempool_t *bvec_pool; 436 mempool_t *bvec_pool;
434}; 437};
435 438
@@ -634,8 +637,9 @@ static inline struct bio *bio_list_get(struct bio_list *bl)
634 637
635#define bio_integrity(bio) (bio->bi_integrity != NULL) 638#define bio_integrity(bio) (bio->bi_integrity != NULL)
636 639
640extern struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *, gfp_t, unsigned int, struct bio_set *);
637extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int); 641extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int);
638extern void bio_integrity_free(struct bio *); 642extern void bio_integrity_free(struct bio *, struct bio_set *);
639extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int); 643extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int);
640extern int bio_integrity_enabled(struct bio *bio); 644extern int bio_integrity_enabled(struct bio *bio);
641extern int bio_integrity_set_tag(struct bio *, void *, unsigned int); 645extern int bio_integrity_set_tag(struct bio *, void *, unsigned int);
@@ -645,21 +649,27 @@ extern void bio_integrity_endio(struct bio *, int);
645extern void bio_integrity_advance(struct bio *, unsigned int); 649extern void bio_integrity_advance(struct bio *, unsigned int);
646extern void bio_integrity_trim(struct bio *, unsigned int, unsigned int); 650extern void bio_integrity_trim(struct bio *, unsigned int, unsigned int);
647extern void bio_integrity_split(struct bio *, struct bio_pair *, int); 651extern void bio_integrity_split(struct bio *, struct bio_pair *, int);
648extern int bio_integrity_clone(struct bio *, struct bio *, gfp_t); 652extern int bio_integrity_clone(struct bio *, struct bio *, gfp_t, struct bio_set *);
653extern int bioset_integrity_create(struct bio_set *, int);
654extern void bioset_integrity_free(struct bio_set *);
655extern void bio_integrity_init(void);
649 656
650#else /* CONFIG_BLK_DEV_INTEGRITY */ 657#else /* CONFIG_BLK_DEV_INTEGRITY */
651 658
652#define bio_integrity(a) (0) 659#define bio_integrity(a) (0)
660#define bioset_integrity_create(a, b) (0)
653#define bio_integrity_prep(a) (0) 661#define bio_integrity_prep(a) (0)
654#define bio_integrity_enabled(a) (0) 662#define bio_integrity_enabled(a) (0)
655#define bio_integrity_clone(a, b, c) (0) 663#define bio_integrity_clone(a, b, c, d) (0)
656#define bio_integrity_free(a) do { } while (0) 664#define bioset_integrity_free(a) do { } while (0)
665#define bio_integrity_free(a, b) do { } while (0)
657#define bio_integrity_endio(a, b) do { } while (0) 666#define bio_integrity_endio(a, b) do { } while (0)
658#define bio_integrity_advance(a, b) do { } while (0) 667#define bio_integrity_advance(a, b) do { } while (0)
659#define bio_integrity_trim(a, b, c) do { } while (0) 668#define bio_integrity_trim(a, b, c) do { } while (0)
660#define bio_integrity_split(a, b, c) do { } while (0) 669#define bio_integrity_split(a, b, c) do { } while (0)
661#define bio_integrity_set_tag(a, b, c) do { } while (0) 670#define bio_integrity_set_tag(a, b, c) do { } while (0)
662#define bio_integrity_get_tag(a, b, c) do { } while (0) 671#define bio_integrity_get_tag(a, b, c) do { } while (0)
672#define bio_integrity_init(a) do { } while (0)
663 673
664#endif /* CONFIG_BLK_DEV_INTEGRITY */ 674#endif /* CONFIG_BLK_DEV_INTEGRITY */
665 675
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 8963d9149b5f..49ae07951d55 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -301,12 +301,6 @@ struct blk_queue_tag {
301#define BLK_SCSI_MAX_CMDS (256) 301#define BLK_SCSI_MAX_CMDS (256)
302#define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8)) 302#define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
303 303
304struct blk_cmd_filter {
305 unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
306 unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
307 struct kobject kobj;
308};
309
310struct queue_limits { 304struct queue_limits {
311 unsigned long bounce_pfn; 305 unsigned long bounce_pfn;
312 unsigned long seg_boundary_mask; 306 unsigned long seg_boundary_mask;
@@ -445,7 +439,6 @@ struct request_queue
445#if defined(CONFIG_BLK_DEV_BSG) 439#if defined(CONFIG_BLK_DEV_BSG)
446 struct bsg_class_device bsg_dev; 440 struct bsg_class_device bsg_dev;
447#endif 441#endif
448 struct blk_cmd_filter cmd_filter;
449}; 442};
450 443
451#define QUEUE_FLAG_CLUSTER 0 /* cluster several segments into 1 */ 444#define QUEUE_FLAG_CLUSTER 0 /* cluster several segments into 1 */
@@ -998,13 +991,7 @@ static inline int sb_issue_discard(struct super_block *sb,
998 return blkdev_issue_discard(sb->s_bdev, block, nr_blocks, GFP_KERNEL); 991 return blkdev_issue_discard(sb->s_bdev, block, nr_blocks, GFP_KERNEL);
999} 992}
1000 993
1001/* 994extern int blk_verify_command(unsigned char *cmd, fmode_t has_write_perm);
1002* command filter functions
1003*/
1004extern int blk_verify_command(struct blk_cmd_filter *filter,
1005 unsigned char *cmd, fmode_t has_write_perm);
1006extern void blk_unregister_filter(struct gendisk *disk);
1007extern void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter);
1008 995
1009#define MAX_PHYS_SEGMENTS 128 996#define MAX_PHYS_SEGMENTS 128
1010#define MAX_HW_SEGMENTS 128 997#define MAX_HW_SEGMENTS 128
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index f45a8ae5f828..3b85ba6479f4 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -8,10 +8,8 @@
8#ifndef _LINUX_EVENTFD_H 8#ifndef _LINUX_EVENTFD_H
9#define _LINUX_EVENTFD_H 9#define _LINUX_EVENTFD_H
10 10
11#ifdef CONFIG_EVENTFD
12
13/* For O_CLOEXEC and O_NONBLOCK */
14#include <linux/fcntl.h> 11#include <linux/fcntl.h>
12#include <linux/file.h>
15 13
16/* 14/*
17 * CAREFUL: Check include/asm-generic/fcntl.h when defining 15 * CAREFUL: Check include/asm-generic/fcntl.h when defining
@@ -27,16 +25,37 @@
27#define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK) 25#define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
28#define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE) 26#define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
29 27
28#ifdef CONFIG_EVENTFD
29
30struct eventfd_ctx *eventfd_ctx_get(struct eventfd_ctx *ctx);
31void eventfd_ctx_put(struct eventfd_ctx *ctx);
30struct file *eventfd_fget(int fd); 32struct file *eventfd_fget(int fd);
31int eventfd_signal(struct file *file, int n); 33struct eventfd_ctx *eventfd_ctx_fdget(int fd);
34struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
35int eventfd_signal(struct eventfd_ctx *ctx, int n);
32 36
33#else /* CONFIG_EVENTFD */ 37#else /* CONFIG_EVENTFD */
34 38
35#define eventfd_fget(fd) ERR_PTR(-ENOSYS) 39/*
36static inline int eventfd_signal(struct file *file, int n) 40 * Ugly ugly ugly error layer to support modules that uses eventfd but
37{ return 0; } 41 * pretend to work in !CONFIG_EVENTFD configurations. Namely, AIO.
42 */
43static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
44{
45 return ERR_PTR(-ENOSYS);
46}
47
48static inline int eventfd_signal(struct eventfd_ctx *ctx, int n)
49{
50 return -ENOSYS;
51}
52
53static inline void eventfd_ctx_put(struct eventfd_ctx *ctx)
54{
55
56}
38 57
39#endif /* CONFIG_EVENTFD */ 58#endif
40 59
41#endif /* _LINUX_EVENTFD_H */ 60#endif /* _LINUX_EVENTFD_H */
42 61
diff --git a/include/linux/fb.h b/include/linux/fb.h
index dd68358996b7..f847df9e99b6 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -819,6 +819,7 @@ struct fb_info {
819 int node; 819 int node;
820 int flags; 820 int flags;
821 struct mutex lock; /* Lock for open/release/ioctl funcs */ 821 struct mutex lock; /* Lock for open/release/ioctl funcs */
822 struct mutex mm_lock; /* Lock for fb_mmap and smem_* fields */
822 struct fb_var_screeninfo var; /* Current var */ 823 struct fb_var_screeninfo var; /* Current var */
823 struct fb_fix_screeninfo fix; /* Current fix */ 824 struct fb_fix_screeninfo fix; /* Current fix */
824 struct fb_monspecs monspecs; /* Current Monitor specs */ 825 struct fb_monspecs monspecs; /* Current Monitor specs */
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 44848aa830dc..6c3de999fb34 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -280,7 +280,7 @@ static inline void __fsnotify_update_dcache_flags(struct dentry *dentry)
280 assert_spin_locked(&dentry->d_lock); 280 assert_spin_locked(&dentry->d_lock);
281 281
282 parent = dentry->d_parent; 282 parent = dentry->d_parent;
283 if (fsnotify_inode_watches_children(parent->d_inode)) 283 if (parent->d_inode && fsnotify_inode_watches_children(parent->d_inode))
284 dentry->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED; 284 dentry->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED;
285 else 285 else
286 dentry->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED; 286 dentry->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED;
diff --git a/include/linux/fuse.h b/include/linux/fuse.h
index d41ed593f79f..cf593bf9fd32 100644
--- a/include/linux/fuse.h
+++ b/include/linux/fuse.h
@@ -25,6 +25,11 @@
25 * - add IOCTL message 25 * - add IOCTL message
26 * - add unsolicited notification support 26 * - add unsolicited notification support
27 * - add POLL message and NOTIFY_POLL notification 27 * - add POLL message and NOTIFY_POLL notification
28 *
29 * 7.12
30 * - add umask flag to input argument of open, mknod and mkdir
31 * - add notification messages for invalidation of inodes and
32 * directory entries
28 */ 33 */
29 34
30#ifndef _LINUX_FUSE_H 35#ifndef _LINUX_FUSE_H
@@ -36,7 +41,7 @@
36#define FUSE_KERNEL_VERSION 7 41#define FUSE_KERNEL_VERSION 7
37 42
38/** Minor version number of this interface */ 43/** Minor version number of this interface */
39#define FUSE_KERNEL_MINOR_VERSION 11 44#define FUSE_KERNEL_MINOR_VERSION 12
40 45
41/** The node ID of the root inode */ 46/** The node ID of the root inode */
42#define FUSE_ROOT_ID 1 47#define FUSE_ROOT_ID 1
@@ -112,6 +117,7 @@ struct fuse_file_lock {
112 * INIT request/reply flags 117 * INIT request/reply flags
113 * 118 *
114 * FUSE_EXPORT_SUPPORT: filesystem handles lookups of "." and ".." 119 * FUSE_EXPORT_SUPPORT: filesystem handles lookups of "." and ".."
120 * FUSE_DONT_MASK: don't apply umask to file mode on create operations
115 */ 121 */
116#define FUSE_ASYNC_READ (1 << 0) 122#define FUSE_ASYNC_READ (1 << 0)
117#define FUSE_POSIX_LOCKS (1 << 1) 123#define FUSE_POSIX_LOCKS (1 << 1)
@@ -119,6 +125,7 @@ struct fuse_file_lock {
119#define FUSE_ATOMIC_O_TRUNC (1 << 3) 125#define FUSE_ATOMIC_O_TRUNC (1 << 3)
120#define FUSE_EXPORT_SUPPORT (1 << 4) 126#define FUSE_EXPORT_SUPPORT (1 << 4)
121#define FUSE_BIG_WRITES (1 << 5) 127#define FUSE_BIG_WRITES (1 << 5)
128#define FUSE_DONT_MASK (1 << 6)
122 129
123/** 130/**
124 * CUSE INIT request/reply flags 131 * CUSE INIT request/reply flags
@@ -224,6 +231,8 @@ enum fuse_opcode {
224 231
225enum fuse_notify_code { 232enum fuse_notify_code {
226 FUSE_NOTIFY_POLL = 1, 233 FUSE_NOTIFY_POLL = 1,
234 FUSE_NOTIFY_INVAL_INODE = 2,
235 FUSE_NOTIFY_INVAL_ENTRY = 3,
227 FUSE_NOTIFY_CODE_MAX, 236 FUSE_NOTIFY_CODE_MAX,
228}; 237};
229 238
@@ -262,14 +271,18 @@ struct fuse_attr_out {
262 struct fuse_attr attr; 271 struct fuse_attr attr;
263}; 272};
264 273
274#define FUSE_COMPAT_MKNOD_IN_SIZE 8
275
265struct fuse_mknod_in { 276struct fuse_mknod_in {
266 __u32 mode; 277 __u32 mode;
267 __u32 rdev; 278 __u32 rdev;
279 __u32 umask;
280 __u32 padding;
268}; 281};
269 282
270struct fuse_mkdir_in { 283struct fuse_mkdir_in {
271 __u32 mode; 284 __u32 mode;
272 __u32 padding; 285 __u32 umask;
273}; 286};
274 287
275struct fuse_rename_in { 288struct fuse_rename_in {
@@ -301,7 +314,14 @@ struct fuse_setattr_in {
301 314
302struct fuse_open_in { 315struct fuse_open_in {
303 __u32 flags; 316 __u32 flags;
317 __u32 unused;
318};
319
320struct fuse_create_in {
321 __u32 flags;
304 __u32 mode; 322 __u32 mode;
323 __u32 umask;
324 __u32 padding;
305}; 325};
306 326
307struct fuse_open_out { 327struct fuse_open_out {
@@ -508,4 +528,16 @@ struct fuse_dirent {
508#define FUSE_DIRENT_SIZE(d) \ 528#define FUSE_DIRENT_SIZE(d) \
509 FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen) 529 FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
510 530
531struct fuse_notify_inval_inode_out {
532 __u64 ino;
533 __s64 off;
534 __s64 len;
535};
536
537struct fuse_notify_inval_entry_out {
538 __u64 parent;
539 __u32 namelen;
540 __u32 padding;
541};
542
511#endif /* _LINUX_FUSE_H */ 543#endif /* _LINUX_FUSE_H */
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 7400900de94a..54648e625efd 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -21,6 +21,7 @@
21#include <linux/list.h> 21#include <linux/list.h>
22#include <linux/wait.h> 22#include <linux/wait.h>
23#include <linux/percpu.h> 23#include <linux/percpu.h>
24#include <linux/timer.h>
24 25
25 26
26struct hrtimer_clock_base; 27struct hrtimer_clock_base;
@@ -447,6 +448,8 @@ extern void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
447 448
448static inline void timer_stats_account_hrtimer(struct hrtimer *timer) 449static inline void timer_stats_account_hrtimer(struct hrtimer *timer)
449{ 450{
451 if (likely(!timer->start_pid))
452 return;
450 timer_stats_update_stats(timer, timer->start_pid, timer->start_site, 453 timer_stats_update_stats(timer, timer->start_pid, timer->start_site,
451 timer->function, timer->start_comm, 0); 454 timer->function, timer->start_comm, 0);
452} 455}
@@ -456,6 +459,8 @@ extern void __timer_stats_hrtimer_set_start_info(struct hrtimer *timer,
456 459
457static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer) 460static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer)
458{ 461{
462 if (likely(!timer_stats_active))
463 return;
459 __timer_stats_hrtimer_set_start_info(timer, __builtin_return_address(0)); 464 __timer_stats_hrtimer_set_start_info(timer, __builtin_return_address(0));
460} 465}
461 466
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 95c6e00a72e8..edc93a6d931d 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -1062,7 +1062,6 @@ int generic_ide_ioctl(ide_drive_t *, struct block_device *, unsigned, unsigned l
1062extern int ide_vlb_clk; 1062extern int ide_vlb_clk;
1063extern int ide_pci_clk; 1063extern int ide_pci_clk;
1064 1064
1065unsigned int ide_rq_bytes(struct request *);
1066int ide_end_rq(ide_drive_t *, struct request *, int, unsigned int); 1065int ide_end_rq(ide_drive_t *, struct request *, int, unsigned int);
1067void ide_kill_rq(ide_drive_t *, struct request *); 1066void ide_kill_rq(ide_drive_t *, struct request *);
1068 1067
@@ -1361,7 +1360,6 @@ int ide_in_drive_list(u16 *, const struct drive_list_entry *);
1361#ifdef CONFIG_BLK_DEV_IDEDMA 1360#ifdef CONFIG_BLK_DEV_IDEDMA
1362int ide_dma_good_drive(ide_drive_t *); 1361int ide_dma_good_drive(ide_drive_t *);
1363int __ide_dma_bad_drive(ide_drive_t *); 1362int __ide_dma_bad_drive(ide_drive_t *);
1364int ide_id_dma_bug(ide_drive_t *);
1365 1363
1366u8 ide_find_dma_mode(ide_drive_t *, u8); 1364u8 ide_find_dma_mode(ide_drive_t *, u8);
1367 1365
@@ -1402,7 +1400,6 @@ void ide_dma_lost_irq(ide_drive_t *);
1402ide_startstop_t ide_dma_timeout_retry(ide_drive_t *, int); 1400ide_startstop_t ide_dma_timeout_retry(ide_drive_t *, int);
1403 1401
1404#else 1402#else
1405static inline int ide_id_dma_bug(ide_drive_t *drive) { return 0; }
1406static inline u8 ide_find_dma_mode(ide_drive_t *drive, u8 speed) { return 0; } 1403static inline u8 ide_find_dma_mode(ide_drive_t *drive, u8 speed) { return 0; }
1407static inline u8 ide_max_dma_mode(ide_drive_t *drive) { return 0; } 1404static inline u8 ide_max_dma_mode(ide_drive_t *drive) { return 0; }
1408static inline void ide_dma_off_quietly(ide_drive_t *drive) { ; } 1405static inline void ide_dma_off_quietly(ide_drive_t *drive) { ; }
@@ -1422,6 +1419,7 @@ static inline void ide_dma_unmap_sg(ide_drive_t *drive,
1422 1419
1423#ifdef CONFIG_BLK_DEV_IDEACPI 1420#ifdef CONFIG_BLK_DEV_IDEACPI
1424int ide_acpi_init(void); 1421int ide_acpi_init(void);
1422bool ide_port_acpi(ide_hwif_t *hwif);
1425extern int ide_acpi_exec_tfs(ide_drive_t *drive); 1423extern int ide_acpi_exec_tfs(ide_drive_t *drive);
1426extern void ide_acpi_get_timing(ide_hwif_t *hwif); 1424extern void ide_acpi_get_timing(ide_hwif_t *hwif);
1427extern void ide_acpi_push_timing(ide_hwif_t *hwif); 1425extern void ide_acpi_push_timing(ide_hwif_t *hwif);
@@ -1430,6 +1428,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *);
1430extern void ide_acpi_set_state(ide_hwif_t *hwif, int on); 1428extern void ide_acpi_set_state(ide_hwif_t *hwif, int on);
1431#else 1429#else
1432static inline int ide_acpi_init(void) { return 0; } 1430static inline int ide_acpi_init(void) { return 0; }
1431static inline bool ide_port_acpi(ide_hwif_t *hwif) { return 0; }
1433static inline int ide_acpi_exec_tfs(ide_drive_t *drive) { return 0; } 1432static inline int ide_acpi_exec_tfs(ide_drive_t *drive) { return 0; }
1434static inline void ide_acpi_get_timing(ide_hwif_t *hwif) { ; } 1433static inline void ide_acpi_get_timing(ide_hwif_t *hwif) { ; }
1435static inline void ide_acpi_push_timing(ide_hwif_t *hwif) { ; } 1434static inline void ide_acpi_push_timing(ide_hwif_t *hwif) { ; }
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index a9173d5434d1..23343ab0bb03 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -1196,6 +1196,10 @@ enum ieee80211_sa_query_action {
1196#define WLAN_CIPHER_SUITE_WEP104 0x000FAC05 1196#define WLAN_CIPHER_SUITE_WEP104 0x000FAC05
1197#define WLAN_CIPHER_SUITE_AES_CMAC 0x000FAC06 1197#define WLAN_CIPHER_SUITE_AES_CMAC 0x000FAC06
1198 1198
1199/* AKM suite selectors */
1200#define WLAN_AKM_SUITE_8021X 0x000FAC01
1201#define WLAN_AKM_SUITE_PSK 0x000FAC02
1202
1199#define WLAN_MAX_KEY_LEN 32 1203#define WLAN_MAX_KEY_LEN 32
1200 1204
1201/** 1205/**
diff --git a/include/linux/ima.h b/include/linux/ima.h
index b1b827d091a9..0e3f2a4c25f6 100644
--- a/include/linux/ima.h
+++ b/include/linux/ima.h
@@ -24,6 +24,7 @@ extern int ima_path_check(struct path *path, int mask, int update_counts);
24extern void ima_file_free(struct file *file); 24extern void ima_file_free(struct file *file);
25extern int ima_file_mmap(struct file *file, unsigned long prot); 25extern int ima_file_mmap(struct file *file, unsigned long prot);
26extern void ima_counts_get(struct file *file); 26extern void ima_counts_get(struct file *file);
27extern void ima_counts_put(struct path *path, int mask);
27 28
28#else 29#else
29static inline int ima_bprm_check(struct linux_binprm *bprm) 30static inline int ima_bprm_check(struct linux_binprm *bprm)
@@ -60,5 +61,10 @@ static inline void ima_counts_get(struct file *file)
60{ 61{
61 return; 62 return;
62} 63}
64
65static inline void ima_counts_put(struct path *path, int mask)
66{
67 return;
68}
63#endif /* CONFIG_IMA_H */ 69#endif /* CONFIG_IMA_H */
64#endif /* _LINUX_IMA_H */ 70#endif /* _LINUX_IMA_H */
diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index 5368fbdc7801..7fc01b13be43 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -183,5 +183,8 @@ extern struct cred init_cred;
183 LIST_HEAD_INIT(cpu_timers[2]), \ 183 LIST_HEAD_INIT(cpu_timers[2]), \
184} 184}
185 185
186/* Attach to the init_task data structure for proper alignment */
187#define __init_task_data __attribute__((__section__(".data.init_task")))
188
186 189
187#endif 190#endif
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index fac104e7186a..d6320a3e8def 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -303,6 +303,7 @@ extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in
303extern int panic_timeout; 303extern int panic_timeout;
304extern int panic_on_oops; 304extern int panic_on_oops;
305extern int panic_on_unrecovered_nmi; 305extern int panic_on_unrecovered_nmi;
306extern int panic_on_io_nmi;
306extern const char *print_tainted(void); 307extern const char *print_tainted(void);
307extern void add_taint(unsigned flag); 308extern void add_taint(unsigned flag);
308extern int test_taint(unsigned flag); 309extern int test_taint(unsigned flag);
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index aacc5449f586..16713dc672e4 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -125,6 +125,7 @@ struct kvm_kernel_irq_routing_entry {
125struct kvm { 125struct kvm {
126 struct mutex lock; /* protects the vcpus array and APIC accesses */ 126 struct mutex lock; /* protects the vcpus array and APIC accesses */
127 spinlock_t mmu_lock; 127 spinlock_t mmu_lock;
128 spinlock_t requests_lock;
128 struct rw_semaphore slots_lock; 129 struct rw_semaphore slots_lock;
129 struct mm_struct *mm; /* userspace tied to this vm */ 130 struct mm_struct *mm; /* userspace tied to this vm */
130 int nmemslots; 131 int nmemslots;
diff --git a/include/linux/leds-lp3944.h b/include/linux/leds-lp3944.h
new file mode 100644
index 000000000000..afc9f9fd70f5
--- /dev/null
+++ b/include/linux/leds-lp3944.h
@@ -0,0 +1,53 @@
1/*
2 * leds-lp3944.h - platform data structure for lp3944 led controller
3 *
4 * Copyright (C) 2009 Antonio Ospite <ospite@studenti.unina.it>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#ifndef __LINUX_LEDS_LP3944_H
13#define __LINUX_LEDS_LP3944_H
14
15#include <linux/leds.h>
16#include <linux/workqueue.h>
17
18#define LP3944_LED0 0
19#define LP3944_LED1 1
20#define LP3944_LED2 2
21#define LP3944_LED3 3
22#define LP3944_LED4 4
23#define LP3944_LED5 5
24#define LP3944_LED6 6
25#define LP3944_LED7 7
26#define LP3944_LEDS_MAX 8
27
28#define LP3944_LED_STATUS_MASK 0x03
29enum lp3944_status {
30 LP3944_LED_STATUS_OFF = 0x0,
31 LP3944_LED_STATUS_ON = 0x1,
32 LP3944_LED_STATUS_DIM0 = 0x2,
33 LP3944_LED_STATUS_DIM1 = 0x3
34};
35
36enum lp3944_type {
37 LP3944_LED_TYPE_NONE,
38 LP3944_LED_TYPE_LED,
39 LP3944_LED_TYPE_LED_INVERTED,
40};
41
42struct lp3944_led {
43 char *name;
44 enum lp3944_type type;
45 enum lp3944_status status;
46};
47
48struct lp3944_platform_data {
49 struct lp3944_led leds[LP3944_LEDS_MAX];
50 u8 leds_size;
51};
52
53#endif /* __LINUX_LEDS_LP3944_H */
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 376fe07732ea..d8bf9665e70c 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -45,7 +45,10 @@ struct led_classdev {
45 /* Get LED brightness level */ 45 /* Get LED brightness level */
46 enum led_brightness (*brightness_get)(struct led_classdev *led_cdev); 46 enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
47 47
48 /* Activate hardware accelerated blink */ 48 /* Activate hardware accelerated blink, delays are in
49 * miliseconds and if none is provided then a sensible default
50 * should be chosen. The call can adjust the timings if it can't
51 * match the values specified exactly. */
49 int (*blink_set)(struct led_classdev *led_cdev, 52 int (*blink_set)(struct led_classdev *led_cdev,
50 unsigned long *delay_on, 53 unsigned long *delay_on,
51 unsigned long *delay_off); 54 unsigned long *delay_off);
@@ -141,9 +144,14 @@ struct gpio_led {
141 const char *name; 144 const char *name;
142 const char *default_trigger; 145 const char *default_trigger;
143 unsigned gpio; 146 unsigned gpio;
144 u8 active_low : 1; 147 unsigned active_low : 1;
145 u8 retain_state_suspended : 1; 148 unsigned retain_state_suspended : 1;
149 unsigned default_state : 2;
150 /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
146}; 151};
152#define LEDS_GPIO_DEFSTATE_OFF 0
153#define LEDS_GPIO_DEFSTATE_ON 1
154#define LEDS_GPIO_DEFSTATE_KEEP 2
147 155
148struct gpio_led_platform_data { 156struct gpio_led_platform_data {
149 int num_leds; 157 int num_leds;
diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index fee9e59649c1..691f59171c6c 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -22,6 +22,15 @@
22#define __page_aligned_bss __section(.bss.page_aligned) __aligned(PAGE_SIZE) 22#define __page_aligned_bss __section(.bss.page_aligned) __aligned(PAGE_SIZE)
23 23
24/* 24/*
25 * For assembly routines.
26 *
27 * Note when using these that you must specify the appropriate
28 * alignment directives yourself
29 */
30#define __PAGE_ALIGNED_DATA .section ".data.page_aligned", "aw"
31#define __PAGE_ALIGNED_BSS .section ".bss.page_aligned", "aw"
32
33/*
25 * This is used by architectures to keep arguments on the stack 34 * This is used by architectures to keep arguments on the stack
26 * untouched by the compiler by keeping them live until the end. 35 * untouched by the compiler by keeping them live until the end.
27 * The argument stack may be owned by the assembly-language 36 * The argument stack may be owned by the assembly-language
diff --git a/include/linux/mm.h b/include/linux/mm.h
index d006e93d5c93..ba3a7cb1eaa0 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -826,7 +826,7 @@ extern int make_pages_present(unsigned long addr, unsigned long end);
826extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write); 826extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
827 827
828int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 828int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
829 unsigned long start, int len, int write, int force, 829 unsigned long start, int nr_pages, int write, int force,
830 struct page **pages, struct vm_area_struct **vmas); 830 struct page **pages, struct vm_area_struct **vmas);
831int get_user_pages_fast(unsigned long start, int nr_pages, int write, 831int get_user_pages_fast(unsigned long start, int nr_pages, int write,
832 struct page **pages); 832 struct page **pages);
diff --git a/include/linux/net_dropmon.h b/include/linux/net_dropmon.h
index 3ceb0cc1bc78..2a739462caeb 100644
--- a/include/linux/net_dropmon.h
+++ b/include/linux/net_dropmon.h
@@ -3,7 +3,6 @@
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5#include <linux/netlink.h> 5#include <linux/netlink.h>
6#include <linux/types.h>
7 6
8struct net_dm_drop_point { 7struct net_dm_drop_point {
9 __u8 pc[8]; 8 __u8 pc[8];
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index d4a4d9867794..9f25ab2899de 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -72,10 +72,6 @@ struct wireless_dev;
72/* Backlog congestion levels */ 72/* Backlog congestion levels */
73#define NET_RX_SUCCESS 0 /* keep 'em coming, baby */ 73#define NET_RX_SUCCESS 0 /* keep 'em coming, baby */
74#define NET_RX_DROP 1 /* packet dropped */ 74#define NET_RX_DROP 1 /* packet dropped */
75#define NET_RX_CN_LOW 2 /* storm alert, just in case */
76#define NET_RX_CN_MOD 3 /* Storm on its way! */
77#define NET_RX_CN_HIGH 4 /* The storm is here */
78#define NET_RX_BAD 5 /* packet dropped due to kernel error */
79 75
80/* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It 76/* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It
81 * indicates that the device will soon be dropping packets, or already drops 77 * indicates that the device will soon be dropping packets, or already drops
diff --git a/include/linux/nl80211.h b/include/linux/nl80211.h
index dbea93b694e5..e496a2daf7ef 100644
--- a/include/linux/nl80211.h
+++ b/include/linux/nl80211.h
@@ -242,6 +242,26 @@
242 * @NL80211_CMD_LEAVE_IBSS: Leave the IBSS -- no special arguments, the IBSS is 242 * @NL80211_CMD_LEAVE_IBSS: Leave the IBSS -- no special arguments, the IBSS is
243 * determined by the network interface. 243 * determined by the network interface.
244 * 244 *
245 * @NL80211_CMD_TESTMODE: testmode command, takes a wiphy (or ifindex) attribute
246 * to identify the device, and the TESTDATA blob attribute to pass through
247 * to the driver.
248 *
249 * @NL80211_CMD_CONNECT: connection request and notification; this command
250 * requests to connect to a specified network but without separating
251 * auth and assoc steps. For this, you need to specify the SSID in a
252 * %NL80211_ATTR_SSID attribute, and can optionally specify the association
253 * IEs in %NL80211_ATTR_IE, %NL80211_ATTR_AUTH_TYPE, %NL80211_ATTR_MAC,
254 * %NL80211_ATTR_WIPHY_FREQ and %NL80211_ATTR_CONTROL_PORT.
255 * It is also sent as an event, with the BSSID and response IEs when the
256 * connection is established or failed to be established. This can be
257 * determined by the STATUS_CODE attribute.
258 * @NL80211_CMD_ROAM: request that the card roam (currently not implemented),
259 * sent as an event when the card/driver roamed by itself.
260 * @NL80211_CMD_DISCONNECT: drop a given connection; also used to notify
261 * userspace that a connection was dropped by the AP or due to other
262 * reasons, for this the %NL80211_ATTR_DISCONNECTED_BY_AP and
263 * %NL80211_ATTR_REASON_CODE attributes are used.
264 *
245 * @NL80211_CMD_MAX: highest used command number 265 * @NL80211_CMD_MAX: highest used command number
246 * @__NL80211_CMD_AFTER_LAST: internal use 266 * @__NL80211_CMD_AFTER_LAST: internal use
247 */ 267 */
@@ -310,6 +330,12 @@ enum nl80211_commands {
310 NL80211_CMD_JOIN_IBSS, 330 NL80211_CMD_JOIN_IBSS,
311 NL80211_CMD_LEAVE_IBSS, 331 NL80211_CMD_LEAVE_IBSS,
312 332
333 NL80211_CMD_TESTMODE,
334
335 NL80211_CMD_CONNECT,
336 NL80211_CMD_ROAM,
337 NL80211_CMD_DISCONNECT,
338
313 /* add new commands above here */ 339 /* add new commands above here */
314 340
315 /* used to define NL80211_CMD_MAX below */ 341 /* used to define NL80211_CMD_MAX below */
@@ -511,6 +537,36 @@ enum nl80211_commands {
511 * authorized by user space. Otherwise, port is marked authorized by 537 * authorized by user space. Otherwise, port is marked authorized by
512 * default in station mode. 538 * default in station mode.
513 * 539 *
540 * @NL80211_ATTR_TESTDATA: Testmode data blob, passed through to the driver.
541 * We recommend using nested, driver-specific attributes within this.
542 *
543 * @NL80211_ATTR_DISCONNECTED_BY_AP: A flag indicating that the DISCONNECT
544 * event was due to the AP disconnecting the station, and not due to
545 * a local disconnect request.
546 * @NL80211_ATTR_STATUS_CODE: StatusCode for the %NL80211_CMD_CONNECT
547 * event (u16)
548 * @NL80211_ATTR_PRIVACY: Flag attribute, used with connect(), indicating
549 * that protected APs should be used.
550 *
551 * @NL80211_ATTR_CIPHERS_PAIRWISE: Used with CONNECT and ASSOCIATE to
552 * indicate which unicast key ciphers will be used with the connection
553 * (an array of u32).
554 * @NL80211_ATTR_CIPHER_GROUP: Used with CONNECT and ASSOCIATE to indicate
555 * which group key cipher will be used with the connection (a u32).
556 * @NL80211_ATTR_WPA_VERSIONS: Used with CONNECT and ASSOCIATE to indicate
557 * which WPA version(s) the AP we want to associate with is using
558 * (a u32 with flags from &enum nl80211_wpa_versions).
559 * @NL80211_ATTR_AKM_SUITES: Used with CONNECT and ASSOCIATE to indicate
560 * which key management algorithm(s) to use (an array of u32).
561 *
562 * @NL80211_ATTR_REQ_IE: (Re)association request information elements as
563 * sent out by the card, for ROAM and successful CONNECT events.
564 * @NL80211_ATTR_RESP_IE: (Re)association response information elements as
565 * sent by peer, for ROAM and successful CONNECT events.
566 *
567 * @NL80211_ATTR_PREV_BSSID: previous BSSID, to be used by in ASSOCIATE
568 * commands to specify using a reassociate frame
569 *
514 * @NL80211_ATTR_MAX: highest attribute number currently defined 570 * @NL80211_ATTR_MAX: highest attribute number currently defined
515 * @__NL80211_ATTR_AFTER_LAST: internal use 571 * @__NL80211_ATTR_AFTER_LAST: internal use
516 */ 572 */
@@ -619,6 +675,23 @@ enum nl80211_attrs {
619 675
620 NL80211_ATTR_CONTROL_PORT, 676 NL80211_ATTR_CONTROL_PORT,
621 677
678 NL80211_ATTR_TESTDATA,
679
680 NL80211_ATTR_PRIVACY,
681
682 NL80211_ATTR_DISCONNECTED_BY_AP,
683 NL80211_ATTR_STATUS_CODE,
684
685 NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
686 NL80211_ATTR_CIPHER_SUITE_GROUP,
687 NL80211_ATTR_WPA_VERSIONS,
688 NL80211_ATTR_AKM_SUITES,
689
690 NL80211_ATTR_REQ_IE,
691 NL80211_ATTR_RESP_IE,
692
693 NL80211_ATTR_PREV_BSSID,
694
622 /* add attributes here, update the policy in nl80211.c */ 695 /* add attributes here, update the policy in nl80211.c */
623 696
624 __NL80211_ATTR_AFTER_LAST, 697 __NL80211_ATTR_AFTER_LAST,
@@ -629,6 +702,7 @@ enum nl80211_attrs {
629 * Allow user space programs to use #ifdef on new attributes by defining them 702 * Allow user space programs to use #ifdef on new attributes by defining them
630 * here 703 * here
631 */ 704 */
705#define NL80211_CMD_CONNECT NL80211_CMD_CONNECT
632#define NL80211_ATTR_HT_CAPABILITY NL80211_ATTR_HT_CAPABILITY 706#define NL80211_ATTR_HT_CAPABILITY NL80211_ATTR_HT_CAPABILITY
633#define NL80211_ATTR_BSS_BASIC_RATES NL80211_ATTR_BSS_BASIC_RATES 707#define NL80211_ATTR_BSS_BASIC_RATES NL80211_ATTR_BSS_BASIC_RATES
634#define NL80211_ATTR_WIPHY_TXQ_PARAMS NL80211_ATTR_WIPHY_TXQ_PARAMS 708#define NL80211_ATTR_WIPHY_TXQ_PARAMS NL80211_ATTR_WIPHY_TXQ_PARAMS
@@ -642,6 +716,10 @@ enum nl80211_attrs {
642#define NL80211_ATTR_SSID NL80211_ATTR_SSID 716#define NL80211_ATTR_SSID NL80211_ATTR_SSID
643#define NL80211_ATTR_AUTH_TYPE NL80211_ATTR_AUTH_TYPE 717#define NL80211_ATTR_AUTH_TYPE NL80211_ATTR_AUTH_TYPE
644#define NL80211_ATTR_REASON_CODE NL80211_ATTR_REASON_CODE 718#define NL80211_ATTR_REASON_CODE NL80211_ATTR_REASON_CODE
719#define NL80211_ATTR_CIPHER_SUITES_PAIRWISE NL80211_ATTR_CIPHER_SUITES_PAIRWISE
720#define NL80211_ATTR_CIPHER_SUITE_GROUP NL80211_ATTR_CIPHER_SUITE_GROUP
721#define NL80211_ATTR_WPA_VERSIONS NL80211_ATTR_WPA_VERSIONS
722#define NL80211_ATTR_AKM_SUITES NL80211_ATTR_AKM_SUITES
645 723
646#define NL80211_MAX_SUPP_RATES 32 724#define NL80211_MAX_SUPP_RATES 32
647#define NL80211_MAX_SUPP_REG_RULES 32 725#define NL80211_MAX_SUPP_REG_RULES 32
@@ -650,6 +728,9 @@ enum nl80211_attrs {
650#define NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY 24 728#define NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY 24
651#define NL80211_HT_CAPABILITY_LEN 26 729#define NL80211_HT_CAPABILITY_LEN 26
652 730
731#define NL80211_MAX_NR_CIPHER_SUITES 5
732#define NL80211_MAX_NR_AKM_SUITES 2
733
653/** 734/**
654 * enum nl80211_iftype - (virtual) interface types 735 * enum nl80211_iftype - (virtual) interface types
655 * 736 *
@@ -1194,12 +1275,22 @@ enum nl80211_bss {
1194 * @NL80211_AUTHTYPE_SHARED_KEY: Shared Key authentication (WEP only) 1275 * @NL80211_AUTHTYPE_SHARED_KEY: Shared Key authentication (WEP only)
1195 * @NL80211_AUTHTYPE_FT: Fast BSS Transition (IEEE 802.11r) 1276 * @NL80211_AUTHTYPE_FT: Fast BSS Transition (IEEE 802.11r)
1196 * @NL80211_AUTHTYPE_NETWORK_EAP: Network EAP (some Cisco APs and mainly LEAP) 1277 * @NL80211_AUTHTYPE_NETWORK_EAP: Network EAP (some Cisco APs and mainly LEAP)
1278 * @__NL80211_AUTHTYPE_NUM: internal
1279 * @NL80211_AUTHTYPE_MAX: maximum valid auth algorithm
1280 * @NL80211_AUTHTYPE_AUTOMATIC: determine automatically (if necessary by
1281 * trying multiple times); this is invalid in netlink -- leave out
1282 * the attribute for this on CONNECT commands.
1197 */ 1283 */
1198enum nl80211_auth_type { 1284enum nl80211_auth_type {
1199 NL80211_AUTHTYPE_OPEN_SYSTEM, 1285 NL80211_AUTHTYPE_OPEN_SYSTEM,
1200 NL80211_AUTHTYPE_SHARED_KEY, 1286 NL80211_AUTHTYPE_SHARED_KEY,
1201 NL80211_AUTHTYPE_FT, 1287 NL80211_AUTHTYPE_FT,
1202 NL80211_AUTHTYPE_NETWORK_EAP, 1288 NL80211_AUTHTYPE_NETWORK_EAP,
1289
1290 /* keep last */
1291 __NL80211_AUTHTYPE_NUM,
1292 NL80211_AUTHTYPE_MAX = __NL80211_AUTHTYPE_NUM - 1,
1293 NL80211_AUTHTYPE_AUTOMATIC
1203}; 1294};
1204 1295
1205/** 1296/**
@@ -1224,4 +1315,9 @@ enum nl80211_mfp {
1224 NL80211_MFP_REQUIRED, 1315 NL80211_MFP_REQUIRED,
1225}; 1316};
1226 1317
1318enum nl80211_wpa_versions {
1319 NL80211_WPA_VERSION_1 = 1 << 0,
1320 NL80211_WPA_VERSION_2 = 1 << 1,
1321};
1322
1227#endif /* __LINUX_NL80211_H */ 1323#endif /* __LINUX_NL80211_H */
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index a3b000365795..73b46b6b904f 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -2645,6 +2645,7 @@
2645#define PCI_DEVICE_ID_NETMOS_9835 0x9835 2645#define PCI_DEVICE_ID_NETMOS_9835 0x9835
2646#define PCI_DEVICE_ID_NETMOS_9845 0x9845 2646#define PCI_DEVICE_ID_NETMOS_9845 0x9845
2647#define PCI_DEVICE_ID_NETMOS_9855 0x9855 2647#define PCI_DEVICE_ID_NETMOS_9855 0x9855
2648#define PCI_DEVICE_ID_NETMOS_9901 0x9901
2648 2649
2649#define PCI_VENDOR_ID_3COM_2 0xa727 2650#define PCI_VENDOR_ID_3COM_2 0xa727
2650 2651
diff --git a/include/linux/percpu-defs.h b/include/linux/percpu-defs.h
index 8f921d74f49f..68438e18fff4 100644
--- a/include/linux/percpu-defs.h
+++ b/include/linux/percpu-defs.h
@@ -24,7 +24,8 @@
24 24
25#define DEFINE_PER_CPU_SECTION(type, name, section) \ 25#define DEFINE_PER_CPU_SECTION(type, name, section) \
26 __attribute__((__section__(PER_CPU_BASE_SECTION section))) \ 26 __attribute__((__section__(PER_CPU_BASE_SECTION section))) \
27 PER_CPU_ATTRIBUTES __typeof__(type) per_cpu__##name 27 PER_CPU_ATTRIBUTES PER_CPU_DEF_ATTRIBUTES \
28 __typeof__(type) per_cpu__##name
28 29
29/* 30/*
30 * Variant on the per-CPU variable declaration/definition theme used for 31 * Variant on the per-CPU variable declaration/definition theme used for
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index 89698d8aba5c..5e970c7d3fd5 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -178,8 +178,10 @@ struct perf_counter_attr {
178 mmap : 1, /* include mmap data */ 178 mmap : 1, /* include mmap data */
179 comm : 1, /* include comm data */ 179 comm : 1, /* include comm data */
180 freq : 1, /* use freq, not period */ 180 freq : 1, /* use freq, not period */
181 inherit_stat : 1, /* per task counts */
182 enable_on_exec : 1, /* next exec enables */
181 183
182 __reserved_1 : 53; 184 __reserved_1 : 51;
183 185
184 __u32 wakeup_events; /* wakeup every n events */ 186 __u32 wakeup_events; /* wakeup every n events */
185 __u32 __reserved_2; 187 __u32 __reserved_2;
@@ -232,6 +234,14 @@ struct perf_counter_mmap_page {
232 __u32 lock; /* seqlock for synchronization */ 234 __u32 lock; /* seqlock for synchronization */
233 __u32 index; /* hardware counter identifier */ 235 __u32 index; /* hardware counter identifier */
234 __s64 offset; /* add to hardware counter value */ 236 __s64 offset; /* add to hardware counter value */
237 __u64 time_enabled; /* time counter active */
238 __u64 time_running; /* time counter on cpu */
239
240 /*
241 * Hole for extension of the self monitor capabilities
242 */
243
244 __u64 __reserved[123]; /* align to 1k */
235 245
236 /* 246 /*
237 * Control data for the mmap() data buffer. 247 * Control data for the mmap() data buffer.
@@ -253,7 +263,6 @@ struct perf_counter_mmap_page {
253#define PERF_EVENT_MISC_KERNEL (1 << 0) 263#define PERF_EVENT_MISC_KERNEL (1 << 0)
254#define PERF_EVENT_MISC_USER (2 << 0) 264#define PERF_EVENT_MISC_USER (2 << 0)
255#define PERF_EVENT_MISC_HYPERVISOR (3 << 0) 265#define PERF_EVENT_MISC_HYPERVISOR (3 << 0)
256#define PERF_EVENT_MISC_OVERFLOW (1 << 2)
257 266
258struct perf_event_header { 267struct perf_event_header {
259 __u32 type; 268 __u32 type;
@@ -327,9 +336,18 @@ enum perf_event_type {
327 PERF_EVENT_FORK = 7, 336 PERF_EVENT_FORK = 7,
328 337
329 /* 338 /*
330 * When header.misc & PERF_EVENT_MISC_OVERFLOW the event_type field 339 * struct {
331 * will be PERF_SAMPLE_* 340 * struct perf_event_header header;
332 * 341 * u32 pid, tid;
342 * u64 value;
343 * { u64 time_enabled; } && PERF_FORMAT_ENABLED
344 * { u64 time_running; } && PERF_FORMAT_RUNNING
345 * { u64 parent_id; } && PERF_FORMAT_ID
346 * };
347 */
348 PERF_EVENT_READ = 8,
349
350 /*
333 * struct { 351 * struct {
334 * struct perf_event_header header; 352 * struct perf_event_header header;
335 * 353 *
@@ -337,8 +355,9 @@ enum perf_event_type {
337 * { u32 pid, tid; } && PERF_SAMPLE_TID 355 * { u32 pid, tid; } && PERF_SAMPLE_TID
338 * { u64 time; } && PERF_SAMPLE_TIME 356 * { u64 time; } && PERF_SAMPLE_TIME
339 * { u64 addr; } && PERF_SAMPLE_ADDR 357 * { u64 addr; } && PERF_SAMPLE_ADDR
340 * { u64 config; } && PERF_SAMPLE_CONFIG 358 * { u64 id; } && PERF_SAMPLE_ID
341 * { u32 cpu, res; } && PERF_SAMPLE_CPU 359 * { u32 cpu, res; } && PERF_SAMPLE_CPU
360 * { u64 period; } && PERF_SAMPLE_PERIOD
342 * 361 *
343 * { u64 nr; 362 * { u64 nr;
344 * { u64 id, val; } cnt[nr]; } && PERF_SAMPLE_GROUP 363 * { u64 id, val; } cnt[nr]; } && PERF_SAMPLE_GROUP
@@ -347,6 +366,9 @@ enum perf_event_type {
347 * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN 366 * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
348 * }; 367 * };
349 */ 368 */
369 PERF_EVENT_SAMPLE = 9,
370
371 PERF_EVENT_MAX, /* non-ABI */
350}; 372};
351 373
352enum perf_callchain_context { 374enum perf_callchain_context {
@@ -582,6 +604,7 @@ struct perf_counter_context {
582 int nr_counters; 604 int nr_counters;
583 int nr_active; 605 int nr_active;
584 int is_active; 606 int is_active;
607 int nr_stat;
585 atomic_t refcount; 608 atomic_t refcount;
586 struct task_struct *task; 609 struct task_struct *task;
587 610
@@ -669,7 +692,16 @@ static inline int is_software_counter(struct perf_counter *counter)
669 (counter->attr.type != PERF_TYPE_HW_CACHE); 692 (counter->attr.type != PERF_TYPE_HW_CACHE);
670} 693}
671 694
672extern void perf_swcounter_event(u32, u64, int, struct pt_regs *, u64); 695extern atomic_t perf_swcounter_enabled[PERF_COUNT_SW_MAX];
696
697extern void __perf_swcounter_event(u32, u64, int, struct pt_regs *, u64);
698
699static inline void
700perf_swcounter_event(u32 event, u64 nr, int nmi, struct pt_regs *regs, u64 addr)
701{
702 if (atomic_read(&perf_swcounter_enabled[event]))
703 __perf_swcounter_event(event, nr, nmi, regs, addr);
704}
673 705
674extern void __perf_counter_mmap(struct vm_area_struct *vma); 706extern void __perf_counter_mmap(struct vm_area_struct *vma);
675 707
diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
index 2ce29831feb6..f3d5812693d6 100644
--- a/include/linux/rfkill.h
+++ b/include/linux/rfkill.h
@@ -82,6 +82,20 @@ struct rfkill_event {
82 __u8 soft, hard; 82 __u8 soft, hard;
83} __packed; 83} __packed;
84 84
85/*
86 * We are planning to be backward and forward compatible with changes
87 * to the event struct, by adding new, optional, members at the end.
88 * When reading an event (whether the kernel from userspace or vice
89 * versa) we need to accept anything that's at least as large as the
90 * version 1 event size, but might be able to accept other sizes in
91 * the future.
92 *
93 * One exception is the kernel -- we already have two event sizes in
94 * that we've made the 'hard' member optional since our only option
95 * is to ignore it anyway.
96 */
97#define RFKILL_EVENT_SIZE_V1 8
98
85/* ioctl for turning off rfkill-input (if present) */ 99/* ioctl for turning off rfkill-input (if present) */
86#define RFKILL_IOC_MAGIC 'R' 100#define RFKILL_IOC_MAGIC 'R'
87#define RFKILL_IOC_NOINPUT 1 101#define RFKILL_IOC_NOINPUT 1
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 4d0754269884..0085d758d645 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -349,8 +349,20 @@ extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
349struct nsproxy; 349struct nsproxy;
350struct user_namespace; 350struct user_namespace;
351 351
352/* Maximum number of active map areas.. This is a random (large) number */ 352/*
353#define DEFAULT_MAX_MAP_COUNT 65536 353 * Default maximum number of active map areas, this limits the number of vmas
354 * per mm struct. Users can overwrite this number by sysctl but there is a
355 * problem.
356 *
357 * When a program's coredump is generated as ELF format, a section is created
358 * per a vma. In ELF, the number of sections is represented in unsigned short.
359 * This means the number of sections should be smaller than 65535 at coredump.
360 * Because the kernel adds some informative sections to a image of program at
361 * generating coredump, we need some margin. The number of extra sections is
362 * 1-3 now and depends on arch. We use "5" as safe margin, here.
363 */
364#define MAPCOUNT_ELF_CORE_MARGIN (5)
365#define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
354 366
355extern int sysctl_max_map_count; 367extern int sysctl_max_map_count;
356 368
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 9c4cd27f4685..c47c4b4da97e 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -80,6 +80,8 @@ struct spi_device {
80#define SPI_LSB_FIRST 0x08 /* per-word bits-on-wire */ 80#define SPI_LSB_FIRST 0x08 /* per-word bits-on-wire */
81#define SPI_3WIRE 0x10 /* SI/SO signals shared */ 81#define SPI_3WIRE 0x10 /* SI/SO signals shared */
82#define SPI_LOOP 0x20 /* loopback mode */ 82#define SPI_LOOP 0x20 /* loopback mode */
83#define SPI_NO_CS 0x40 /* 1 dev/bus, no chipselect */
84#define SPI_READY 0x80 /* slave pulls low to pause */
83 u8 bits_per_word; 85 u8 bits_per_word;
84 int irq; 86 int irq;
85 void *controller_state; 87 void *controller_state;
@@ -248,6 +250,10 @@ struct spi_master {
248 /* spi_device.mode flags understood by this controller driver */ 250 /* spi_device.mode flags understood by this controller driver */
249 u16 mode_bits; 251 u16 mode_bits;
250 252
253 /* other constraints relevant to this driver */
254 u16 flags;
255#define SPI_MASTER_HALF_DUPLEX BIT(0) /* can't do full duplex */
256
251 /* Setup mode and clock, etc (spi driver may call many times). 257 /* Setup mode and clock, etc (spi driver may call many times).
252 * 258 *
253 * IMPORTANT: this may be called when transfers to another 259 * IMPORTANT: this may be called when transfers to another
diff --git a/include/linux/spi/spidev.h b/include/linux/spi/spidev.h
index 95251ccd5a07..bf0570a84f7a 100644
--- a/include/linux/spi/spidev.h
+++ b/include/linux/spi/spidev.h
@@ -40,6 +40,8 @@
40#define SPI_LSB_FIRST 0x08 40#define SPI_LSB_FIRST 0x08
41#define SPI_3WIRE 0x10 41#define SPI_3WIRE 0x10
42#define SPI_LOOP 0x20 42#define SPI_LOOP 0x20
43#define SPI_NO_CS 0x40
44#define SPI_READY 0x80
43 45
44/*---------------------------------------------------------------------------*/ 46/*---------------------------------------------------------------------------*/
45 47
diff --git a/include/linux/timer.h b/include/linux/timer.h
index ccf882eed8f8..be62ec2ebea5 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -190,6 +190,8 @@ extern unsigned long get_next_timer_interrupt(unsigned long now);
190 */ 190 */
191#ifdef CONFIG_TIMER_STATS 191#ifdef CONFIG_TIMER_STATS
192 192
193extern int timer_stats_active;
194
193#define TIMER_STATS_FLAG_DEFERRABLE 0x1 195#define TIMER_STATS_FLAG_DEFERRABLE 0x1
194 196
195extern void init_timer_stats(void); 197extern void init_timer_stats(void);
@@ -203,6 +205,8 @@ extern void __timer_stats_timer_set_start_info(struct timer_list *timer,
203 205
204static inline void timer_stats_timer_set_start_info(struct timer_list *timer) 206static inline void timer_stats_timer_set_start_info(struct timer_list *timer)
205{ 207{
208 if (likely(!timer_stats_active))
209 return;
206 __timer_stats_timer_set_start_info(timer, __builtin_return_address(0)); 210 __timer_stats_timer_set_start_info(timer, __builtin_return_address(0));
207} 211}
208 212
diff --git a/include/linux/tipc.h b/include/linux/tipc.h
index bea469455a0c..3d92396639de 100644
--- a/include/linux/tipc.h
+++ b/include/linux/tipc.h
@@ -209,5 +209,7 @@ struct sockaddr_tipc {
209#define TIPC_SRC_DROPPABLE 128 /* Default: 0 (resend congested msg) */ 209#define TIPC_SRC_DROPPABLE 128 /* Default: 0 (resend congested msg) */
210#define TIPC_DEST_DROPPABLE 129 /* Default: based on socket type */ 210#define TIPC_DEST_DROPPABLE 129 /* Default: based on socket type */
211#define TIPC_CONN_TIMEOUT 130 /* Default: 8000 (ms) */ 211#define TIPC_CONN_TIMEOUT 130 /* Default: 8000 (ms) */
212#define TIPC_NODE_RECVQ_DEPTH 131 /* Default: none (read only) */
213#define TIPC_SOCK_RECVQ_DEPTH 132 /* Default: none (read only) */
212 214
213#endif 215#endif
diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h
index 310e18a880ff..7c17b2efba86 100644
--- a/include/linux/usb/usbnet.h
+++ b/include/linux/usb/usbnet.h
@@ -97,6 +97,9 @@ struct driver_info {
97 /* reset device ... can sleep */ 97 /* reset device ... can sleep */
98 int (*reset)(struct usbnet *); 98 int (*reset)(struct usbnet *);
99 99
100 /* stop device ... can sleep */
101 int (*stop)(struct usbnet *);
102
100 /* see if peer is connected ... can sleep */ 103 /* see if peer is connected ... can sleep */
101 int (*check_connect)(struct usbnet *); 104 int (*check_connect)(struct usbnet *);
102 105
diff --git a/include/linux/wireless.h b/include/linux/wireless.h
index cb24204851f7..5b4c6c772a9b 100644
--- a/include/linux/wireless.h
+++ b/include/linux/wireless.h
@@ -1132,6 +1132,14 @@ struct __compat_iw_event {
1132}; 1132};
1133#define IW_EV_COMPAT_LCP_LEN offsetof(struct __compat_iw_event, pointer) 1133#define IW_EV_COMPAT_LCP_LEN offsetof(struct __compat_iw_event, pointer)
1134#define IW_EV_COMPAT_POINT_OFF offsetof(struct compat_iw_point, length) 1134#define IW_EV_COMPAT_POINT_OFF offsetof(struct compat_iw_point, length)
1135
1136/* Size of the various events for compat */
1137#define IW_EV_COMPAT_CHAR_LEN (IW_EV_COMPAT_LCP_LEN + IFNAMSIZ)
1138#define IW_EV_COMPAT_UINT_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(__u32))
1139#define IW_EV_COMPAT_FREQ_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct iw_freq))
1140#define IW_EV_COMPAT_PARAM_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct iw_param))
1141#define IW_EV_COMPAT_ADDR_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct sockaddr))
1142#define IW_EV_COMPAT_QUAL_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct iw_quality))
1135#define IW_EV_COMPAT_POINT_LEN \ 1143#define IW_EV_COMPAT_POINT_LEN \
1136 (IW_EV_COMPAT_LCP_LEN + sizeof(struct compat_iw_point) - \ 1144 (IW_EV_COMPAT_LCP_LEN + sizeof(struct compat_iw_point) - \
1137 IW_EV_COMPAT_POINT_OFF) 1145 IW_EV_COMPAT_POINT_OFF)
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 1a21895b732b..83c2c727d71e 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -555,6 +555,7 @@ struct cfg80211_scan_request {
555 /* internal */ 555 /* internal */
556 struct wiphy *wiphy; 556 struct wiphy *wiphy;
557 int ifidx; 557 int ifidx;
558 bool aborted;
558}; 559};
559 560
560/** 561/**
@@ -584,7 +585,6 @@ enum cfg80211_signal_type {
584 * is no guarantee that these are well-formed!) 585 * is no guarantee that these are well-formed!)
585 * @len_information_elements: total length of the information elements 586 * @len_information_elements: total length of the information elements
586 * @signal: signal strength value (type depends on the wiphy's signal_type) 587 * @signal: signal strength value (type depends on the wiphy's signal_type)
587 * @hold: BSS should not expire
588 * @free_priv: function pointer to free private data 588 * @free_priv: function pointer to free private data
589 * @priv: private area for driver use, has at least wiphy->bss_priv_size bytes 589 * @priv: private area for driver use, has at least wiphy->bss_priv_size bytes
590 */ 590 */
@@ -605,37 +605,54 @@ struct cfg80211_bss {
605}; 605};
606 606
607/** 607/**
608 * ieee80211_bss_get_ie - find IE with given ID
609 * @bss: the bss to search
610 * @ie: the IE ID
611 * Returns %NULL if not found.
612 */
613const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie);
614
615
616/**
617 * struct cfg80211_crypto_settings - Crypto settings
618 * @wpa_versions: indicates which, if any, WPA versions are enabled
619 * (from enum nl80211_wpa_versions)
620 * @cipher_group: group key cipher suite (or 0 if unset)
621 * @n_ciphers_pairwise: number of AP supported unicast ciphers
622 * @ciphers_pairwise: unicast key cipher suites
623 * @n_akm_suites: number of AKM suites
624 * @akm_suites: AKM suites
625 * @control_port: Whether user space controls IEEE 802.1X port, i.e.,
626 * sets/clears %NL80211_STA_FLAG_AUTHORIZED. If true, the driver is
627 * required to assume that the port is unauthorized until authorized by
628 * user space. Otherwise, port is marked authorized by default.
629 */
630struct cfg80211_crypto_settings {
631 u32 wpa_versions;
632 u32 cipher_group;
633 int n_ciphers_pairwise;
634 u32 ciphers_pairwise[NL80211_MAX_NR_CIPHER_SUITES];
635 int n_akm_suites;
636 u32 akm_suites[NL80211_MAX_NR_AKM_SUITES];
637 bool control_port;
638};
639
640/**
608 * struct cfg80211_auth_request - Authentication request data 641 * struct cfg80211_auth_request - Authentication request data
609 * 642 *
610 * This structure provides information needed to complete IEEE 802.11 643 * This structure provides information needed to complete IEEE 802.11
611 * authentication. 644 * authentication.
612 * NOTE: This structure will likely change when more code from mac80211 is 645 *
613 * moved into cfg80211 so that non-mac80211 drivers can benefit from it, too. 646 * @bss: The BSS to authenticate with.
614 * Before using this in a driver that does not use mac80211, it would be better
615 * to check the status of that work and better yet, volunteer to work on it.
616 *
617 * @chan: The channel to use or %NULL if not specified (auto-select based on
618 * scan results)
619 * @peer_addr: The address of the peer STA (AP BSSID in infrastructure case);
620 * this field is required to be present; if the driver wants to help with
621 * BSS selection, it should use (yet to be added) MLME event to allow user
622 * space SME to be notified of roaming candidate, so that the SME can then
623 * use the authentication request with the recommended BSSID and whatever
624 * other data may be needed for authentication/association
625 * @ssid: SSID or %NULL if not yet available
626 * @ssid_len: Length of ssid in octets
627 * @auth_type: Authentication type (algorithm) 647 * @auth_type: Authentication type (algorithm)
628 * @ie: Extra IEs to add to Authentication frame or %NULL 648 * @ie: Extra IEs to add to Authentication frame or %NULL
629 * @ie_len: Length of ie buffer in octets 649 * @ie_len: Length of ie buffer in octets
630 */ 650 */
631struct cfg80211_auth_request { 651struct cfg80211_auth_request {
632 struct ieee80211_channel *chan; 652 struct cfg80211_bss *bss;
633 u8 *peer_addr;
634 const u8 *ssid;
635 size_t ssid_len;
636 enum nl80211_auth_type auth_type;
637 const u8 *ie; 653 const u8 *ie;
638 size_t ie_len; 654 size_t ie_len;
655 enum nl80211_auth_type auth_type;
639}; 656};
640 657
641/** 658/**
@@ -643,35 +660,19 @@ struct cfg80211_auth_request {
643 * 660 *
644 * This structure provides information needed to complete IEEE 802.11 661 * This structure provides information needed to complete IEEE 802.11
645 * (re)association. 662 * (re)association.
646 * NOTE: This structure will likely change when more code from mac80211 is 663 * @bss: The BSS to associate with.
647 * moved into cfg80211 so that non-mac80211 drivers can benefit from it, too.
648 * Before using this in a driver that does not use mac80211, it would be better
649 * to check the status of that work and better yet, volunteer to work on it.
650 *
651 * @chan: The channel to use or %NULL if not specified (auto-select based on
652 * scan results)
653 * @peer_addr: The address of the peer STA (AP BSSID); this field is required
654 * to be present and the STA must be in State 2 (authenticated) with the
655 * peer STA
656 * @ssid: SSID
657 * @ssid_len: Length of ssid in octets
658 * @ie: Extra IEs to add to (Re)Association Request frame or %NULL 664 * @ie: Extra IEs to add to (Re)Association Request frame or %NULL
659 * @ie_len: Length of ie buffer in octets 665 * @ie_len: Length of ie buffer in octets
660 * @use_mfp: Use management frame protection (IEEE 802.11w) in this association 666 * @use_mfp: Use management frame protection (IEEE 802.11w) in this association
661 * @control_port: Whether user space controls IEEE 802.1X port, i.e., 667 * @crypto: crypto settings
662 * sets/clears %NL80211_STA_FLAG_AUTHORIZED. If true, the driver is 668 * @prev_bssid: previous BSSID, if not %NULL use reassociate frame
663 * required to assume that the port is unauthorized until authorized by
664 * user space. Otherwise, port is marked authorized by default.
665 */ 669 */
666struct cfg80211_assoc_request { 670struct cfg80211_assoc_request {
667 struct ieee80211_channel *chan; 671 struct cfg80211_bss *bss;
668 u8 *peer_addr; 672 const u8 *ie, *prev_bssid;
669 const u8 *ssid;
670 size_t ssid_len;
671 const u8 *ie;
672 size_t ie_len; 673 size_t ie_len;
674 struct cfg80211_crypto_settings crypto;
673 bool use_mfp; 675 bool use_mfp;
674 bool control_port;
675}; 676};
676 677
677/** 678/**
@@ -680,16 +681,16 @@ struct cfg80211_assoc_request {
680 * This structure provides information needed to complete IEEE 802.11 681 * This structure provides information needed to complete IEEE 802.11
681 * deauthentication. 682 * deauthentication.
682 * 683 *
683 * @peer_addr: The address of the peer STA (AP BSSID); this field is required 684 * @bss: the BSS to deauthenticate from
684 * to be present and the STA must be authenticated with the peer STA
685 * @ie: Extra IEs to add to Deauthentication frame or %NULL 685 * @ie: Extra IEs to add to Deauthentication frame or %NULL
686 * @ie_len: Length of ie buffer in octets 686 * @ie_len: Length of ie buffer in octets
687 * @reason_code: The reason code for the deauthentication
687 */ 688 */
688struct cfg80211_deauth_request { 689struct cfg80211_deauth_request {
689 u8 *peer_addr; 690 struct cfg80211_bss *bss;
690 u16 reason_code;
691 const u8 *ie; 691 const u8 *ie;
692 size_t ie_len; 692 size_t ie_len;
693 u16 reason_code;
693}; 694};
694 695
695/** 696/**
@@ -698,16 +699,16 @@ struct cfg80211_deauth_request {
698 * This structure provides information needed to complete IEEE 802.11 699 * This structure provides information needed to complete IEEE 802.11
699 * disassocation. 700 * disassocation.
700 * 701 *
701 * @peer_addr: The address of the peer STA (AP BSSID); this field is required 702 * @bss: the BSS to disassociate from
702 * to be present and the STA must be associated with the peer STA
703 * @ie: Extra IEs to add to Disassociation frame or %NULL 703 * @ie: Extra IEs to add to Disassociation frame or %NULL
704 * @ie_len: Length of ie buffer in octets 704 * @ie_len: Length of ie buffer in octets
705 * @reason_code: The reason code for the disassociation
705 */ 706 */
706struct cfg80211_disassoc_request { 707struct cfg80211_disassoc_request {
707 u8 *peer_addr; 708 struct cfg80211_bss *bss;
708 u16 reason_code;
709 const u8 *ie; 709 const u8 *ie;
710 size_t ie_len; 710 size_t ie_len;
711 u16 reason_code;
711}; 712};
712 713
713/** 714/**
@@ -738,6 +739,36 @@ struct cfg80211_ibss_params {
738}; 739};
739 740
740/** 741/**
742 * struct cfg80211_connect_params - Connection parameters
743 *
744 * This structure provides information needed to complete IEEE 802.11
745 * authentication and association.
746 *
747 * @channel: The channel to use or %NULL if not specified (auto-select based
748 * on scan results)
749 * @bssid: The AP BSSID or %NULL if not specified (auto-select based on scan
750 * results)
751 * @ssid: SSID
752 * @ssid_len: Length of ssid in octets
753 * @auth_type: Authentication type (algorithm)
754 * @assoc_ie: IEs for association request
755 * @assoc_ie_len: Length of assoc_ie in octets
756 * @privacy: indicates whether privacy-enabled APs should be used
757 * @crypto: crypto settings
758 */
759struct cfg80211_connect_params {
760 struct ieee80211_channel *channel;
761 u8 *bssid;
762 u8 *ssid;
763 size_t ssid_len;
764 enum nl80211_auth_type auth_type;
765 u8 *ie;
766 size_t ie_len;
767 bool privacy;
768 struct cfg80211_crypto_settings crypto;
769};
770
771/**
741 * enum wiphy_params_flags - set_wiphy_params bitfield values 772 * enum wiphy_params_flags - set_wiphy_params bitfield values
742 * WIPHY_PARAM_RETRY_SHORT: wiphy->retry_short has changed 773 * WIPHY_PARAM_RETRY_SHORT: wiphy->retry_short has changed
743 * WIPHY_PARAM_RETRY_LONG: wiphy->retry_long has changed 774 * WIPHY_PARAM_RETRY_LONG: wiphy->retry_long has changed
@@ -764,6 +795,26 @@ enum tx_power_setting {
764 TX_POWER_FIXED, 795 TX_POWER_FIXED,
765}; 796};
766 797
798/*
799 * cfg80211_bitrate_mask - masks for bitrate control
800 */
801struct cfg80211_bitrate_mask {
802/*
803 * As discussed in Berlin, this struct really
804 * should look like this:
805
806 struct {
807 u32 legacy;
808 u8 mcs[IEEE80211_HT_MCS_MASK_LEN];
809 } control[IEEE80211_NUM_BANDS];
810
811 * Since we can always fix in-kernel users, let's keep
812 * it simpler for now:
813 */
814 u32 fixed; /* fixed bitrate, 0 == not fixed */
815 u32 maxrate; /* in kbps, 0 == no limit */
816};
817
767/** 818/**
768 * struct cfg80211_ops - backend description for wireless configuration 819 * struct cfg80211_ops - backend description for wireless configuration
769 * 820 *
@@ -841,6 +892,12 @@ enum tx_power_setting {
841 * @deauth: Request to deauthenticate from the specified peer 892 * @deauth: Request to deauthenticate from the specified peer
842 * @disassoc: Request to disassociate from the specified peer 893 * @disassoc: Request to disassociate from the specified peer
843 * 894 *
895 * @connect: Connect to the ESS with the specified parameters. When connected,
896 * call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS.
897 * If the connection fails for some reason, call cfg80211_connect_result()
898 * with the status from the AP.
899 * @disconnect: Disconnect from the BSS/ESS.
900 *
844 * @join_ibss: Join the specified IBSS (or create if necessary). Once done, call 901 * @join_ibss: Join the specified IBSS (or create if necessary). Once done, call
845 * cfg80211_ibss_joined(), also call that function when changing BSSID due 902 * cfg80211_ibss_joined(), also call that function when changing BSSID due
846 * to a merge. 903 * to a merge.
@@ -857,6 +914,8 @@ enum tx_power_setting {
857 * 914 *
858 * @rfkill_poll: polls the hw rfkill line, use cfg80211 reporting 915 * @rfkill_poll: polls the hw rfkill line, use cfg80211 reporting
859 * functions to adjust rfkill hw state 916 * functions to adjust rfkill hw state
917 *
918 * @testmode_cmd: run a test mode command
860 */ 919 */
861struct cfg80211_ops { 920struct cfg80211_ops {
862 int (*suspend)(struct wiphy *wiphy); 921 int (*suspend)(struct wiphy *wiphy);
@@ -866,7 +925,8 @@ struct cfg80211_ops {
866 enum nl80211_iftype type, u32 *flags, 925 enum nl80211_iftype type, u32 *flags,
867 struct vif_params *params); 926 struct vif_params *params);
868 int (*del_virtual_intf)(struct wiphy *wiphy, int ifindex); 927 int (*del_virtual_intf)(struct wiphy *wiphy, int ifindex);
869 int (*change_virtual_intf)(struct wiphy *wiphy, int ifindex, 928 int (*change_virtual_intf)(struct wiphy *wiphy,
929 struct net_device *dev,
870 enum nl80211_iftype type, u32 *flags, 930 enum nl80211_iftype type, u32 *flags,
871 struct vif_params *params); 931 struct vif_params *params);
872 932
@@ -939,9 +999,16 @@ struct cfg80211_ops {
939 int (*assoc)(struct wiphy *wiphy, struct net_device *dev, 999 int (*assoc)(struct wiphy *wiphy, struct net_device *dev,
940 struct cfg80211_assoc_request *req); 1000 struct cfg80211_assoc_request *req);
941 int (*deauth)(struct wiphy *wiphy, struct net_device *dev, 1001 int (*deauth)(struct wiphy *wiphy, struct net_device *dev,
942 struct cfg80211_deauth_request *req); 1002 struct cfg80211_deauth_request *req,
1003 void *cookie);
943 int (*disassoc)(struct wiphy *wiphy, struct net_device *dev, 1004 int (*disassoc)(struct wiphy *wiphy, struct net_device *dev,
944 struct cfg80211_disassoc_request *req); 1005 struct cfg80211_disassoc_request *req,
1006 void *cookie);
1007
1008 int (*connect)(struct wiphy *wiphy, struct net_device *dev,
1009 struct cfg80211_connect_params *sme);
1010 int (*disconnect)(struct wiphy *wiphy, struct net_device *dev,
1011 u16 reason_code);
945 1012
946 int (*join_ibss)(struct wiphy *wiphy, struct net_device *dev, 1013 int (*join_ibss)(struct wiphy *wiphy, struct net_device *dev,
947 struct cfg80211_ibss_params *params); 1014 struct cfg80211_ibss_params *params);
@@ -953,7 +1020,23 @@ struct cfg80211_ops {
953 enum tx_power_setting type, int dbm); 1020 enum tx_power_setting type, int dbm);
954 int (*get_tx_power)(struct wiphy *wiphy, int *dbm); 1021 int (*get_tx_power)(struct wiphy *wiphy, int *dbm);
955 1022
1023 int (*set_wds_peer)(struct wiphy *wiphy, struct net_device *dev,
1024 u8 *addr);
1025
956 void (*rfkill_poll)(struct wiphy *wiphy); 1026 void (*rfkill_poll)(struct wiphy *wiphy);
1027
1028#ifdef CONFIG_NL80211_TESTMODE
1029 int (*testmode_cmd)(struct wiphy *wiphy, void *data, int len);
1030#endif
1031
1032 int (*set_bitrate_mask)(struct wiphy *wiphy,
1033 struct net_device *dev,
1034 const u8 *peer,
1035 const struct cfg80211_bitrate_mask *mask);
1036
1037 /* some temporary stuff to finish wext */
1038 int (*set_power_mgmt)(struct wiphy *wiphy, struct net_device *dev,
1039 bool enabled, int timeout);
957}; 1040};
958 1041
959/* 1042/*
@@ -1058,6 +1141,17 @@ static inline void *wiphy_priv(struct wiphy *wiphy)
1058} 1141}
1059 1142
1060/** 1143/**
1144 * priv_to_wiphy - return the wiphy containing the priv
1145 *
1146 * @priv: a pointer previously returned by wiphy_priv
1147 */
1148static inline struct wiphy *priv_to_wiphy(void *priv)
1149{
1150 BUG_ON(!priv);
1151 return container_of(priv, struct wiphy, priv);
1152}
1153
1154/**
1061 * set_wiphy_dev - set device pointer for wiphy 1155 * set_wiphy_dev - set device pointer for wiphy
1062 * 1156 *
1063 * @wiphy: The wiphy whose device to bind 1157 * @wiphy: The wiphy whose device to bind
@@ -1129,6 +1223,12 @@ extern void wiphy_unregister(struct wiphy *wiphy);
1129 */ 1223 */
1130extern void wiphy_free(struct wiphy *wiphy); 1224extern void wiphy_free(struct wiphy *wiphy);
1131 1225
1226/* internal struct */
1227struct cfg80211_conn;
1228struct cfg80211_internal_bss;
1229
1230#define MAX_AUTH_BSSES 4
1231
1132/** 1232/**
1133 * struct wireless_dev - wireless per-netdev state 1233 * struct wireless_dev - wireless per-netdev state
1134 * 1234 *
@@ -1152,22 +1252,41 @@ struct wireless_dev {
1152 struct wiphy *wiphy; 1252 struct wiphy *wiphy;
1153 enum nl80211_iftype iftype; 1253 enum nl80211_iftype iftype;
1154 1254
1155 /* private to the generic wireless code */ 1255 /* the remainder of this struct should be private to cfg80211 */
1156 struct list_head list; 1256 struct list_head list;
1157 struct net_device *netdev; 1257 struct net_device *netdev;
1158 1258
1159 /* currently used for IBSS - might be rearranged in the future */ 1259 struct mutex mtx;
1160 struct cfg80211_bss *current_bss; 1260
1161 u8 bssid[ETH_ALEN]; 1261 /* currently used for IBSS and SME - might be rearranged later */
1162 u8 ssid[IEEE80211_MAX_SSID_LEN]; 1262 u8 ssid[IEEE80211_MAX_SSID_LEN];
1163 u8 ssid_len; 1263 u8 ssid_len;
1264 enum {
1265 CFG80211_SME_IDLE,
1266 CFG80211_SME_CONNECTING,
1267 CFG80211_SME_CONNECTED,
1268 } sme_state;
1269 struct cfg80211_conn *conn;
1270
1271 struct list_head event_list;
1272 spinlock_t event_lock;
1273
1274 struct cfg80211_internal_bss *authtry_bsses[MAX_AUTH_BSSES];
1275 struct cfg80211_internal_bss *auth_bsses[MAX_AUTH_BSSES];
1276 struct cfg80211_internal_bss *current_bss; /* associated / joined */
1164 1277
1165#ifdef CONFIG_WIRELESS_EXT 1278#ifdef CONFIG_WIRELESS_EXT
1166 /* wext data */ 1279 /* wext data */
1167 struct { 1280 struct {
1168 struct cfg80211_ibss_params ibss; 1281 struct cfg80211_ibss_params ibss;
1282 struct cfg80211_connect_params connect;
1283 u8 *ie;
1284 size_t ie_len;
1169 u8 bssid[ETH_ALEN]; 1285 u8 bssid[ETH_ALEN];
1286 u8 ssid[IEEE80211_MAX_SSID_LEN];
1170 s8 default_key, default_mgmt_key; 1287 s8 default_key, default_mgmt_key;
1288 bool ps;
1289 int ps_timeout;
1171 } wext; 1290 } wext;
1172#endif 1291#endif
1173}; 1292};
@@ -1447,9 +1566,44 @@ int cfg80211_ibss_wext_giwap(struct net_device *dev,
1447 struct iw_request_info *info, 1566 struct iw_request_info *info,
1448 struct sockaddr *ap_addr, char *extra); 1567 struct sockaddr *ap_addr, char *extra);
1449 1568
1569int cfg80211_mgd_wext_siwfreq(struct net_device *dev,
1570 struct iw_request_info *info,
1571 struct iw_freq *freq, char *extra);
1572int cfg80211_mgd_wext_giwfreq(struct net_device *dev,
1573 struct iw_request_info *info,
1574 struct iw_freq *freq, char *extra);
1575int cfg80211_mgd_wext_siwessid(struct net_device *dev,
1576 struct iw_request_info *info,
1577 struct iw_point *data, char *ssid);
1578int cfg80211_mgd_wext_giwessid(struct net_device *dev,
1579 struct iw_request_info *info,
1580 struct iw_point *data, char *ssid);
1581int cfg80211_mgd_wext_siwap(struct net_device *dev,
1582 struct iw_request_info *info,
1583 struct sockaddr *ap_addr, char *extra);
1584int cfg80211_mgd_wext_giwap(struct net_device *dev,
1585 struct iw_request_info *info,
1586 struct sockaddr *ap_addr, char *extra);
1587int cfg80211_wext_siwgenie(struct net_device *dev,
1588 struct iw_request_info *info,
1589 struct iw_point *data, char *extra);
1590int cfg80211_wext_siwauth(struct net_device *dev,
1591 struct iw_request_info *info,
1592 struct iw_param *data, char *extra);
1593int cfg80211_wext_giwauth(struct net_device *dev,
1594 struct iw_request_info *info,
1595 struct iw_param *data, char *extra);
1596
1450struct ieee80211_channel *cfg80211_wext_freq(struct wiphy *wiphy, 1597struct ieee80211_channel *cfg80211_wext_freq(struct wiphy *wiphy,
1451 struct iw_freq *freq); 1598 struct iw_freq *freq);
1452 1599
1600int cfg80211_wext_siwrate(struct net_device *dev,
1601 struct iw_request_info *info,
1602 struct iw_param *rate, char *extra);
1603int cfg80211_wext_giwrate(struct net_device *dev,
1604 struct iw_request_info *info,
1605 struct iw_param *rate, char *extra);
1606
1453int cfg80211_wext_siwrts(struct net_device *dev, 1607int cfg80211_wext_siwrts(struct net_device *dev,
1454 struct iw_request_info *info, 1608 struct iw_request_info *info,
1455 struct iw_param *rts, char *extra); 1609 struct iw_param *rts, char *extra);
@@ -1483,6 +1637,21 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
1483int cfg80211_wext_giwtxpower(struct net_device *dev, 1637int cfg80211_wext_giwtxpower(struct net_device *dev,
1484 struct iw_request_info *info, 1638 struct iw_request_info *info,
1485 union iwreq_data *data, char *keybuf); 1639 union iwreq_data *data, char *keybuf);
1640struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev);
1641
1642int cfg80211_wext_siwpower(struct net_device *dev,
1643 struct iw_request_info *info,
1644 struct iw_param *wrq, char *extra);
1645int cfg80211_wext_giwpower(struct net_device *dev,
1646 struct iw_request_info *info,
1647 struct iw_param *wrq, char *extra);
1648
1649int cfg80211_wds_wext_siwap(struct net_device *dev,
1650 struct iw_request_info *info,
1651 struct sockaddr *addr, char *extra);
1652int cfg80211_wds_wext_giwap(struct net_device *dev,
1653 struct iw_request_info *info,
1654 struct sockaddr *addr, char *extra);
1486 1655
1487/* 1656/*
1488 * callbacks for asynchronous cfg80211 methods, notification 1657 * callbacks for asynchronous cfg80211 methods, notification
@@ -1564,7 +1733,7 @@ void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *bss);
1564 * This function is called whenever an authentication has been processed in 1733 * This function is called whenever an authentication has been processed in
1565 * station mode. The driver is required to call either this function or 1734 * station mode. The driver is required to call either this function or
1566 * cfg80211_send_auth_timeout() to indicate the result of cfg80211_ops::auth() 1735 * cfg80211_send_auth_timeout() to indicate the result of cfg80211_ops::auth()
1567 * call. 1736 * call. This function may sleep.
1568 */ 1737 */
1569void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len); 1738void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
1570 1739
@@ -1572,6 +1741,8 @@ void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
1572 * cfg80211_send_auth_timeout - notification of timed out authentication 1741 * cfg80211_send_auth_timeout - notification of timed out authentication
1573 * @dev: network device 1742 * @dev: network device
1574 * @addr: The MAC address of the device with which the authentication timed out 1743 * @addr: The MAC address of the device with which the authentication timed out
1744 *
1745 * This function may sleep.
1575 */ 1746 */
1576void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr); 1747void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr);
1577 1748
@@ -1584,7 +1755,7 @@ void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr);
1584 * This function is called whenever a (re)association response has been 1755 * This function is called whenever a (re)association response has been
1585 * processed in station mode. The driver is required to call either this 1756 * processed in station mode. The driver is required to call either this
1586 * function or cfg80211_send_assoc_timeout() to indicate the result of 1757 * function or cfg80211_send_assoc_timeout() to indicate the result of
1587 * cfg80211_ops::assoc() call. 1758 * cfg80211_ops::assoc() call. This function may sleep.
1588 */ 1759 */
1589void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len); 1760void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len);
1590 1761
@@ -1592,6 +1763,8 @@ void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len);
1592 * cfg80211_send_assoc_timeout - notification of timed out association 1763 * cfg80211_send_assoc_timeout - notification of timed out association
1593 * @dev: network device 1764 * @dev: network device
1594 * @addr: The MAC address of the device with which the association timed out 1765 * @addr: The MAC address of the device with which the association timed out
1766 *
1767 * This function may sleep.
1595 */ 1768 */
1596void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr); 1769void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr);
1597 1770
@@ -1600,41 +1773,30 @@ void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr);
1600 * @dev: network device 1773 * @dev: network device
1601 * @buf: deauthentication frame (header + body) 1774 * @buf: deauthentication frame (header + body)
1602 * @len: length of the frame data 1775 * @len: length of the frame data
1776 * @cookie: cookie from ->deauth if called within that callback,
1777 * %NULL otherwise
1603 * 1778 *
1604 * This function is called whenever deauthentication has been processed in 1779 * This function is called whenever deauthentication has been processed in
1605 * station mode. This includes both received deauthentication frames and 1780 * station mode. This includes both received deauthentication frames and
1606 * locally generated ones. 1781 * locally generated ones. This function may sleep.
1607 */ 1782 */
1608void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len); 1783void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len,
1784 void *cookie);
1609 1785
1610/** 1786/**
1611 * cfg80211_send_disassoc - notification of processed disassociation 1787 * cfg80211_send_disassoc - notification of processed disassociation
1612 * @dev: network device 1788 * @dev: network device
1613 * @buf: disassociation response frame (header + body) 1789 * @buf: disassociation response frame (header + body)
1614 * @len: length of the frame data 1790 * @len: length of the frame data
1791 * @cookie: cookie from ->disassoc if called within that callback,
1792 * %NULL otherwise
1615 * 1793 *
1616 * This function is called whenever disassociation has been processed in 1794 * This function is called whenever disassociation has been processed in
1617 * station mode. This includes both received disassociation frames and locally 1795 * station mode. This includes both received disassociation frames and locally
1618 * generated ones. 1796 * generated ones. This function may sleep.
1619 */ 1797 */
1620void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len); 1798void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len,
1621 1799 void *cookie);
1622/**
1623 * cfg80211_hold_bss - exclude bss from expiration
1624 * @bss: bss which should not expire
1625 *
1626 * In a case when the BSS is not updated but it shouldn't expire this
1627 * function can be used to mark the BSS to be excluded from expiration.
1628 */
1629void cfg80211_hold_bss(struct cfg80211_bss *bss);
1630
1631/**
1632 * cfg80211_unhold_bss - remove expiration exception from the BSS
1633 * @bss: bss which can expire again
1634 *
1635 * This function marks the BSS to be expirable again.
1636 */
1637void cfg80211_unhold_bss(struct cfg80211_bss *bss);
1638 1800
1639/** 1801/**
1640 * cfg80211_michael_mic_failure - notification of Michael MIC failure (TKIP) 1802 * cfg80211_michael_mic_failure - notification of Michael MIC failure (TKIP)
@@ -1643,6 +1805,7 @@ void cfg80211_unhold_bss(struct cfg80211_bss *bss);
1643 * @key_type: The key type that the received frame used 1805 * @key_type: The key type that the received frame used
1644 * @key_id: Key identifier (0..3) 1806 * @key_id: Key identifier (0..3)
1645 * @tsc: The TSC value of the frame that generated the MIC failure (6 octets) 1807 * @tsc: The TSC value of the frame that generated the MIC failure (6 octets)
1808 * @gfp: allocation flags
1646 * 1809 *
1647 * This function is called whenever the local MAC detects a MIC failure in a 1810 * This function is called whenever the local MAC detects a MIC failure in a
1648 * received frame. This matches with MLME-MICHAELMICFAILURE.indication() 1811 * received frame. This matches with MLME-MICHAELMICFAILURE.indication()
@@ -1650,7 +1813,7 @@ void cfg80211_unhold_bss(struct cfg80211_bss *bss);
1650 */ 1813 */
1651void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr, 1814void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
1652 enum nl80211_key_type key_type, int key_id, 1815 enum nl80211_key_type key_type, int key_id,
1653 const u8 *tsc); 1816 const u8 *tsc, gfp_t gfp);
1654 1817
1655/** 1818/**
1656 * cfg80211_ibss_joined - notify cfg80211 that device joined an IBSS 1819 * cfg80211_ibss_joined - notify cfg80211 that device joined an IBSS
@@ -1687,4 +1850,137 @@ void wiphy_rfkill_start_polling(struct wiphy *wiphy);
1687 */ 1850 */
1688void wiphy_rfkill_stop_polling(struct wiphy *wiphy); 1851void wiphy_rfkill_stop_polling(struct wiphy *wiphy);
1689 1852
1853#ifdef CONFIG_NL80211_TESTMODE
1854/**
1855 * cfg80211_testmode_alloc_reply_skb - allocate testmode reply
1856 * @wiphy: the wiphy
1857 * @approxlen: an upper bound of the length of the data that will
1858 * be put into the skb
1859 *
1860 * This function allocates and pre-fills an skb for a reply to
1861 * the testmode command. Since it is intended for a reply, calling
1862 * it outside of the @testmode_cmd operation is invalid.
1863 *
1864 * The returned skb (or %NULL if any errors happen) is pre-filled
1865 * with the wiphy index and set up in a way that any data that is
1866 * put into the skb (with skb_put(), nla_put() or similar) will end
1867 * up being within the %NL80211_ATTR_TESTDATA attribute, so all that
1868 * needs to be done with the skb is adding data for the corresponding
1869 * userspace tool which can then read that data out of the testdata
1870 * attribute. You must not modify the skb in any other way.
1871 *
1872 * When done, call cfg80211_testmode_reply() with the skb and return
1873 * its error code as the result of the @testmode_cmd operation.
1874 */
1875struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
1876 int approxlen);
1877
1878/**
1879 * cfg80211_testmode_reply - send the reply skb
1880 * @skb: The skb, must have been allocated with
1881 * cfg80211_testmode_alloc_reply_skb()
1882 *
1883 * Returns an error code or 0 on success, since calling this
1884 * function will usually be the last thing before returning
1885 * from the @testmode_cmd you should return the error code.
1886 * Note that this function consumes the skb regardless of the
1887 * return value.
1888 */
1889int cfg80211_testmode_reply(struct sk_buff *skb);
1890
1891/**
1892 * cfg80211_testmode_alloc_event_skb - allocate testmode event
1893 * @wiphy: the wiphy
1894 * @approxlen: an upper bound of the length of the data that will
1895 * be put into the skb
1896 * @gfp: allocation flags
1897 *
1898 * This function allocates and pre-fills an skb for an event on the
1899 * testmode multicast group.
1900 *
1901 * The returned skb (or %NULL if any errors happen) is set up in the
1902 * same way as with cfg80211_testmode_alloc_reply_skb() but prepared
1903 * for an event. As there, you should simply add data to it that will
1904 * then end up in the %NL80211_ATTR_TESTDATA attribute. Again, you must
1905 * not modify the skb in any other way.
1906 *
1907 * When done filling the skb, call cfg80211_testmode_event() with the
1908 * skb to send the event.
1909 */
1910struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
1911 int approxlen, gfp_t gfp);
1912
1913/**
1914 * cfg80211_testmode_event - send the event
1915 * @skb: The skb, must have been allocated with
1916 * cfg80211_testmode_alloc_event_skb()
1917 * @gfp: allocation flags
1918 *
1919 * This function sends the given @skb, which must have been allocated
1920 * by cfg80211_testmode_alloc_event_skb(), as an event. It always
1921 * consumes it.
1922 */
1923void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp);
1924
1925#define CFG80211_TESTMODE_CMD(cmd) .testmode_cmd = (cmd),
1926#else
1927#define CFG80211_TESTMODE_CMD(cmd)
1928#endif
1929
1930/**
1931 * cfg80211_connect_result - notify cfg80211 of connection result
1932 *
1933 * @dev: network device
1934 * @bssid: the BSSID of the AP
1935 * @req_ie: association request IEs (maybe be %NULL)
1936 * @req_ie_len: association request IEs length
1937 * @resp_ie: association response IEs (may be %NULL)
1938 * @resp_ie_len: assoc response IEs length
1939 * @status: status code, 0 for successful connection, use
1940 * %WLAN_STATUS_UNSPECIFIED_FAILURE if your device cannot give you
1941 * the real status code for failures.
1942 * @gfp: allocation flags
1943 *
1944 * It should be called by the underlying driver whenever connect() has
1945 * succeeded.
1946 */
1947void cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
1948 const u8 *req_ie, size_t req_ie_len,
1949 const u8 *resp_ie, size_t resp_ie_len,
1950 u16 status, gfp_t gfp);
1951
1952/**
1953 * cfg80211_roamed - notify cfg80211 of roaming
1954 *
1955 * @dev: network device
1956 * @bssid: the BSSID of the new AP
1957 * @req_ie: association request IEs (maybe be %NULL)
1958 * @req_ie_len: association request IEs length
1959 * @resp_ie: association response IEs (may be %NULL)
1960 * @resp_ie_len: assoc response IEs length
1961 * @gfp: allocation flags
1962 *
1963 * It should be called by the underlying driver whenever it roamed
1964 * from one AP to another while connected.
1965 */
1966void cfg80211_roamed(struct net_device *dev, const u8 *bssid,
1967 const u8 *req_ie, size_t req_ie_len,
1968 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp);
1969
1970/**
1971 * cfg80211_disconnected - notify cfg80211 that connection was dropped
1972 *
1973 * @dev: network device
1974 * @ie: information elements of the deauth/disassoc frame (may be %NULL)
1975 * @ie_len: length of IEs
1976 * @reason: reason code for the disconnection, set it to 0 if unknown
1977 * @gfp: allocation flags
1978 *
1979 * After it calls this function, the driver should enter an idle state
1980 * and not try to connect to any AP any more.
1981 */
1982void cfg80211_disconnected(struct net_device *dev, u16 reason,
1983 u8 *ie, size_t ie_len, gfp_t gfp);
1984
1985
1690#endif /* __NET_CFG80211_H */ 1986#endif /* __NET_CFG80211_H */
diff --git a/include/net/genetlink.h b/include/net/genetlink.h
index 1b0e3ee4ddd8..2a1c06874c42 100644
--- a/include/net/genetlink.h
+++ b/include/net/genetlink.h
@@ -3,6 +3,7 @@
3 3
4#include <linux/genetlink.h> 4#include <linux/genetlink.h>
5#include <net/netlink.h> 5#include <net/netlink.h>
6#include <net/net_namespace.h>
6 7
7/** 8/**
8 * struct genl_multicast_group - generic netlink multicast group 9 * struct genl_multicast_group - generic netlink multicast group
@@ -27,6 +28,8 @@ struct genl_multicast_group
27 * @name: name of family 28 * @name: name of family
28 * @version: protocol version 29 * @version: protocol version
29 * @maxattr: maximum number of attributes supported 30 * @maxattr: maximum number of attributes supported
31 * @netnsok: set to true if the family can handle network
32 * namespaces and should be presented in all of them
30 * @attrbuf: buffer to store parsed attributes 33 * @attrbuf: buffer to store parsed attributes
31 * @ops_list: list of all assigned operations 34 * @ops_list: list of all assigned operations
32 * @family_list: family list 35 * @family_list: family list
@@ -39,6 +42,7 @@ struct genl_family
39 char name[GENL_NAMSIZ]; 42 char name[GENL_NAMSIZ];
40 unsigned int version; 43 unsigned int version;
41 unsigned int maxattr; 44 unsigned int maxattr;
45 bool netnsok;
42 struct nlattr ** attrbuf; /* private */ 46 struct nlattr ** attrbuf; /* private */
43 struct list_head ops_list; /* private */ 47 struct list_head ops_list; /* private */
44 struct list_head family_list; /* private */ 48 struct list_head family_list; /* private */
@@ -62,8 +66,32 @@ struct genl_info
62 struct genlmsghdr * genlhdr; 66 struct genlmsghdr * genlhdr;
63 void * userhdr; 67 void * userhdr;
64 struct nlattr ** attrs; 68 struct nlattr ** attrs;
69#ifdef CONFIG_NET_NS
70 struct net * _net;
71#endif
65}; 72};
66 73
74#ifdef CONFIG_NET_NS
75static inline struct net *genl_info_net(struct genl_info *info)
76{
77 return info->_net;
78}
79
80static inline void genl_info_net_set(struct genl_info *info, struct net *net)
81{
82 info->_net = net;
83}
84#else
85static inline struct net *genl_info_net(struct genl_info *info)
86{
87 return &init_net;
88}
89
90static inline void genl_info_net_set(struct genl_info *info, struct net *net)
91{
92}
93#endif
94
67/** 95/**
68 * struct genl_ops - generic netlink operations 96 * struct genl_ops - generic netlink operations
69 * @cmd: command identifier 97 * @cmd: command identifier
@@ -98,8 +126,6 @@ extern int genl_register_mc_group(struct genl_family *family,
98extern void genl_unregister_mc_group(struct genl_family *family, 126extern void genl_unregister_mc_group(struct genl_family *family,
99 struct genl_multicast_group *grp); 127 struct genl_multicast_group *grp);
100 128
101extern struct sock *genl_sock;
102
103/** 129/**
104 * genlmsg_put - Add generic netlink header to netlink message 130 * genlmsg_put - Add generic netlink header to netlink message
105 * @skb: socket buffer holding the message 131 * @skb: socket buffer holding the message
@@ -170,7 +196,21 @@ static inline void genlmsg_cancel(struct sk_buff *skb, void *hdr)
170} 196}
171 197
172/** 198/**
173 * genlmsg_multicast - multicast a netlink message 199 * genlmsg_multicast_netns - multicast a netlink message to a specific netns
200 * @net: the net namespace
201 * @skb: netlink message as socket buffer
202 * @pid: own netlink pid to avoid sending to yourself
203 * @group: multicast group id
204 * @flags: allocation flags
205 */
206static inline int genlmsg_multicast_netns(struct net *net, struct sk_buff *skb,
207 u32 pid, unsigned int group, gfp_t flags)
208{
209 return nlmsg_multicast(net->genl_sock, skb, pid, group, flags);
210}
211
212/**
213 * genlmsg_multicast - multicast a netlink message to the default netns
174 * @skb: netlink message as socket buffer 214 * @skb: netlink message as socket buffer
175 * @pid: own netlink pid to avoid sending to yourself 215 * @pid: own netlink pid to avoid sending to yourself
176 * @group: multicast group id 216 * @group: multicast group id
@@ -179,17 +219,29 @@ static inline void genlmsg_cancel(struct sk_buff *skb, void *hdr)
179static inline int genlmsg_multicast(struct sk_buff *skb, u32 pid, 219static inline int genlmsg_multicast(struct sk_buff *skb, u32 pid,
180 unsigned int group, gfp_t flags) 220 unsigned int group, gfp_t flags)
181{ 221{
182 return nlmsg_multicast(genl_sock, skb, pid, group, flags); 222 return genlmsg_multicast_netns(&init_net, skb, pid, group, flags);
183} 223}
184 224
185/** 225/**
226 * genlmsg_multicast_allns - multicast a netlink message to all net namespaces
227 * @skb: netlink message as socket buffer
228 * @pid: own netlink pid to avoid sending to yourself
229 * @group: multicast group id
230 * @flags: allocation flags
231 *
232 * This function must hold the RTNL or rcu_read_lock().
233 */
234int genlmsg_multicast_allns(struct sk_buff *skb, u32 pid,
235 unsigned int group, gfp_t flags);
236
237/**
186 * genlmsg_unicast - unicast a netlink message 238 * genlmsg_unicast - unicast a netlink message
187 * @skb: netlink message as socket buffer 239 * @skb: netlink message as socket buffer
188 * @pid: netlink pid of the destination socket 240 * @pid: netlink pid of the destination socket
189 */ 241 */
190static inline int genlmsg_unicast(struct sk_buff *skb, u32 pid) 242static inline int genlmsg_unicast(struct net *net, struct sk_buff *skb, u32 pid)
191{ 243{
192 return nlmsg_unicast(genl_sock, skb, pid); 244 return nlmsg_unicast(net->genl_sock, skb, pid);
193} 245}
194 246
195/** 247/**
@@ -199,7 +251,7 @@ static inline int genlmsg_unicast(struct sk_buff *skb, u32 pid)
199 */ 251 */
200static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info) 252static inline int genlmsg_reply(struct sk_buff *skb, struct genl_info *info)
201{ 253{
202 return genlmsg_unicast(skb, info->snd_pid); 254 return genlmsg_unicast(genl_info_net(info), skb, info->snd_pid);
203} 255}
204 256
205/** 257/**
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index f27fd83d67d8..ad9a51130254 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -441,6 +441,18 @@ static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_add
441 return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr)); 441 return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr));
442} 442}
443 443
444static __inline__ void ipv6_select_ident(struct frag_hdr *fhdr)
445{
446 static u32 ipv6_fragmentation_id = 1;
447 static DEFINE_SPINLOCK(ip6_id_lock);
448
449 spin_lock_bh(&ip6_id_lock);
450 fhdr->identification = htonl(ipv6_fragmentation_id);
451 if (++ipv6_fragmentation_id == 0)
452 ipv6_fragmentation_id = 1;
453 spin_unlock_bh(&ip6_id_lock);
454}
455
444/* 456/*
445 * Prototypes exported by ipv6 457 * Prototypes exported by ipv6
446 */ 458 */
diff --git a/include/net/iw_handler.h b/include/net/iw_handler.h
index 51b9a37de991..2b3fbbb8669e 100644
--- a/include/net/iw_handler.h
+++ b/include/net/iw_handler.h
@@ -443,7 +443,7 @@ extern int dev_get_wireless_info(char * buffer, char **start, off_t offset,
443extern void wireless_send_event(struct net_device * dev, 443extern void wireless_send_event(struct net_device * dev,
444 unsigned int cmd, 444 unsigned int cmd,
445 union iwreq_data * wrqu, 445 union iwreq_data * wrqu,
446 char * extra); 446 const char * extra);
447 447
448/* We may need a function to send a stream of events to user space. 448/* We may need a function to send a stream of events to user space.
449 * More on that later... */ 449 * More on that later... */
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index c06104476973..ce7cb1b5d453 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -397,6 +397,11 @@ static inline struct ieee80211_tx_info *IEEE80211_SKB_CB(struct sk_buff *skb)
397 return (struct ieee80211_tx_info *)skb->cb; 397 return (struct ieee80211_tx_info *)skb->cb;
398} 398}
399 399
400static inline struct ieee80211_rx_status *IEEE80211_SKB_RXCB(struct sk_buff *skb)
401{
402 return (struct ieee80211_rx_status *)skb->cb;
403}
404
400/** 405/**
401 * ieee80211_tx_info_clear_status - clear TX status 406 * ieee80211_tx_info_clear_status - clear TX status
402 * 407 *
@@ -478,7 +483,7 @@ enum mac80211_rx_flags {
478 * 483 *
479 * The low-level driver should provide this information (the subset 484 * The low-level driver should provide this information (the subset
480 * supported by hardware) to the 802.11 code with each received 485 * supported by hardware) to the 802.11 code with each received
481 * frame. 486 * frame, in the skb's control buffer (cb).
482 * 487 *
483 * @mactime: value in microseconds of the 64-bit Time Synchronization Function 488 * @mactime: value in microseconds of the 64-bit Time Synchronization Function
484 * (TSF) timer when the first data symbol (MPDU) arrived at the hardware. 489 * (TSF) timer when the first data symbol (MPDU) arrived at the hardware.
@@ -1411,6 +1416,8 @@ enum ieee80211_ampdu_mlme_action {
1411 * @rfkill_poll: Poll rfkill hardware state. If you need this, you also 1416 * @rfkill_poll: Poll rfkill hardware state. If you need this, you also
1412 * need to set wiphy->rfkill_poll to %true before registration, 1417 * need to set wiphy->rfkill_poll to %true before registration,
1413 * and need to call wiphy_rfkill_set_hw_state() in the callback. 1418 * and need to call wiphy_rfkill_set_hw_state() in the callback.
1419 *
1420 * @testmode_cmd: Implement a cfg80211 test mode command.
1414 */ 1421 */
1415struct ieee80211_ops { 1422struct ieee80211_ops {
1416 int (*tx)(struct ieee80211_hw *hw, struct sk_buff *skb); 1423 int (*tx)(struct ieee80211_hw *hw, struct sk_buff *skb);
@@ -1461,6 +1468,9 @@ struct ieee80211_ops {
1461 struct ieee80211_sta *sta, u16 tid, u16 *ssn); 1468 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
1462 1469
1463 void (*rfkill_poll)(struct ieee80211_hw *hw); 1470 void (*rfkill_poll)(struct ieee80211_hw *hw);
1471#ifdef CONFIG_NL80211_TESTMODE
1472 int (*testmode_cmd)(struct ieee80211_hw *hw, void *data, int len);
1473#endif
1464}; 1474};
1465 1475
1466/** 1476/**
@@ -1606,9 +1616,11 @@ void ieee80211_free_hw(struct ieee80211_hw *hw);
1606 */ 1616 */
1607void ieee80211_restart_hw(struct ieee80211_hw *hw); 1617void ieee80211_restart_hw(struct ieee80211_hw *hw);
1608 1618
1609/* trick to avoid symbol clashes with the ieee80211 subsystem */ 1619/*
1610void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 1620 * trick to avoid symbol clashes with the ieee80211 subsystem,
1611 struct ieee80211_rx_status *status); 1621 * use the inline below instead
1622 */
1623void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb);
1612 1624
1613/** 1625/**
1614 * ieee80211_rx - receive frame 1626 * ieee80211_rx - receive frame
@@ -1624,13 +1636,10 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1624 * 1636 *
1625 * @hw: the hardware this frame came in on 1637 * @hw: the hardware this frame came in on
1626 * @skb: the buffer to receive, owned by mac80211 after this call 1638 * @skb: the buffer to receive, owned by mac80211 after this call
1627 * @status: status of this frame; the status pointer need not be valid
1628 * after this function returns
1629 */ 1639 */
1630static inline void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 1640static inline void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
1631 struct ieee80211_rx_status *status)
1632{ 1641{
1633 __ieee80211_rx(hw, skb, status); 1642 __ieee80211_rx(hw, skb);
1634} 1643}
1635 1644
1636/** 1645/**
@@ -1644,13 +1653,8 @@ static inline void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1644 * 1653 *
1645 * @hw: the hardware this frame came in on 1654 * @hw: the hardware this frame came in on
1646 * @skb: the buffer to receive, owned by mac80211 after this call 1655 * @skb: the buffer to receive, owned by mac80211 after this call
1647 * @status: status of this frame; the status pointer need not be valid
1648 * after this function returns and is not freed by mac80211,
1649 * it is recommended that it points to a stack area
1650 */ 1656 */
1651void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, 1657void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb);
1652 struct sk_buff *skb,
1653 struct ieee80211_rx_status *status);
1654 1658
1655/** 1659/**
1656 * ieee80211_tx_status - transmit status callback 1660 * ieee80211_tx_status - transmit status callback
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index ded434b032a4..5c5136fceea8 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -26,6 +26,7 @@ struct net_device;
26struct sock; 26struct sock;
27struct ctl_table_header; 27struct ctl_table_header;
28struct net_generic; 28struct net_generic;
29struct sock;
29 30
30struct net { 31struct net {
31 atomic_t count; /* To decided when the network 32 atomic_t count; /* To decided when the network
@@ -57,6 +58,7 @@ struct net {
57 spinlock_t rules_mod_lock; 58 spinlock_t rules_mod_lock;
58 59
59 struct sock *rtnl; /* rtnetlink socket */ 60 struct sock *rtnl; /* rtnetlink socket */
61 struct sock *genl_sock;
60 62
61 struct netns_core core; 63 struct netns_core core;
62 struct netns_mib mib; 64 struct netns_mib mib;
@@ -78,6 +80,9 @@ struct net {
78#ifdef CONFIG_XFRM 80#ifdef CONFIG_XFRM
79 struct netns_xfrm xfrm; 81 struct netns_xfrm xfrm;
80#endif 82#endif
83#ifdef CONFIG_WIRELESS_EXT
84 struct sk_buff_head wext_nlevents;
85#endif
81 struct net_generic *gen; 86 struct net_generic *gen;
82}; 87};
83 88
@@ -106,6 +111,8 @@ static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
106 111
107extern struct list_head net_namespace_list; 112extern struct list_head net_namespace_list;
108 113
114extern struct net *get_net_ns_by_pid(pid_t pid);
115
109#ifdef CONFIG_NET_NS 116#ifdef CONFIG_NET_NS
110extern void __put_net(struct net *net); 117extern void __put_net(struct net *net);
111 118
@@ -208,6 +215,9 @@ static inline struct net *read_pnet(struct net * const *pnet)
208#define for_each_net(VAR) \ 215#define for_each_net(VAR) \
209 list_for_each_entry(VAR, &net_namespace_list, list) 216 list_for_each_entry(VAR, &net_namespace_list, list)
210 217
218#define for_each_net_rcu(VAR) \
219 list_for_each_entry_rcu(VAR, &net_namespace_list, list)
220
211#ifdef CONFIG_NET_NS 221#ifdef CONFIG_NET_NS
212#define __net_init 222#define __net_init
213#define __net_exit 223#define __net_exit
diff --git a/include/net/netns/x_tables.h b/include/net/netns/x_tables.h
index 9554a644a8f8..591db7d657a3 100644
--- a/include/net/netns/x_tables.h
+++ b/include/net/netns/x_tables.h
@@ -8,8 +8,11 @@ struct ebt_table;
8 8
9struct netns_xt { 9struct netns_xt {
10 struct list_head tables[NFPROTO_NUMPROTO]; 10 struct list_head tables[NFPROTO_NUMPROTO];
11#if defined(CONFIG_BRIDGE_NF_EBTABLES) || \
12 defined(CONFIG_BRIDGE_NF_EBTABLES_MODULE)
11 struct ebt_table *broute_table; 13 struct ebt_table *broute_table;
12 struct ebt_table *frame_filter; 14 struct ebt_table *frame_filter;
13 struct ebt_table *frame_nat; 15 struct ebt_table *frame_nat;
16#endif
14}; 17};
15#endif 18#endif
diff --git a/include/net/scm.h b/include/net/scm.h
index f45bb6eca7d4..cf48c800e926 100644
--- a/include/net/scm.h
+++ b/include/net/scm.h
@@ -26,7 +26,6 @@ struct scm_cookie
26#ifdef CONFIG_SECURITY_NETWORK 26#ifdef CONFIG_SECURITY_NETWORK
27 u32 secid; /* Passed security ID */ 27 u32 secid; /* Passed security ID */
28#endif 28#endif
29 unsigned long seq; /* Connection seqno */
30}; 29};
31 30
32extern void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm); 31extern void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm);
@@ -59,7 +58,6 @@ static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
59 scm->creds.gid = current_gid(); 58 scm->creds.gid = current_gid();
60 scm->creds.pid = task_tgid_vnr(p); 59 scm->creds.pid = task_tgid_vnr(p);
61 scm->fp = NULL; 60 scm->fp = NULL;
62 scm->seq = 0;
63 unix_get_peersec_dgram(sock, scm); 61 unix_get_peersec_dgram(sock, scm);
64 if (msg->msg_controllen <= 0) 62 if (msg->msg_controllen <= 0)
65 return 0; 63 return 0;
diff --git a/include/net/udp.h b/include/net/udp.h
index 90e6ce56be65..5fb029f817a3 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -207,4 +207,7 @@ extern void udp4_proc_exit(void);
207#endif 207#endif
208 208
209extern void udp_init(void); 209extern void udp_init(void);
210
211extern int udp4_ufo_send_check(struct sk_buff *skb);
212extern struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb, int features);
210#endif /* _UDP_H */ 213#endif /* _UDP_H */
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index e35ba2c3a8d7..c5e68adc6732 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -32,6 +32,7 @@
32#include <linux/nsproxy.h> 32#include <linux/nsproxy.h>
33#include <linux/pid.h> 33#include <linux/pid.h>
34#include <linux/ipc_namespace.h> 34#include <linux/ipc_namespace.h>
35#include <linux/ima.h>
35 36
36#include <net/sock.h> 37#include <net/sock.h>
37#include "util.h" 38#include "util.h"
@@ -733,6 +734,7 @@ SYSCALL_DEFINE4(mq_open, const char __user *, u_name, int, oflag, mode_t, mode,
733 error = PTR_ERR(filp); 734 error = PTR_ERR(filp);
734 goto out_putfd; 735 goto out_putfd;
735 } 736 }
737 ima_counts_get(filp);
736 738
737 fd_install(fd, filp); 739 fd_install(fd, filp);
738 goto out_upsem; 740 goto out_upsem;
diff --git a/kernel/Makefile b/kernel/Makefile
index 780c8dcf4516..2093a691f1c2 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -96,6 +96,7 @@ obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += dma-coherent.o
96obj-$(CONFIG_FUNCTION_TRACER) += trace/ 96obj-$(CONFIG_FUNCTION_TRACER) += trace/
97obj-$(CONFIG_TRACING) += trace/ 97obj-$(CONFIG_TRACING) += trace/
98obj-$(CONFIG_X86_DS) += trace/ 98obj-$(CONFIG_X86_DS) += trace/
99obj-$(CONFIG_RING_BUFFER) += trace/
99obj-$(CONFIG_SMP) += sched_cpupri.o 100obj-$(CONFIG_SMP) += sched_cpupri.o
100obj-$(CONFIG_SLOW_WORK) += slow-work.o 101obj-$(CONFIG_SLOW_WORK) += slow-work.o
101obj-$(CONFIG_PERF_COUNTERS) += perf_counter.o 102obj-$(CONFIG_PERF_COUNTERS) += perf_counter.o
diff --git a/kernel/acct.c b/kernel/acct.c
index 7afa31564162..9f3391090b3e 100644
--- a/kernel/acct.c
+++ b/kernel/acct.c
@@ -215,6 +215,7 @@ static void acct_file_reopen(struct bsd_acct_struct *acct, struct file *file,
215static int acct_on(char *name) 215static int acct_on(char *name)
216{ 216{
217 struct file *file; 217 struct file *file;
218 struct vfsmount *mnt;
218 int error; 219 int error;
219 struct pid_namespace *ns; 220 struct pid_namespace *ns;
220 struct bsd_acct_struct *acct = NULL; 221 struct bsd_acct_struct *acct = NULL;
@@ -256,11 +257,12 @@ static int acct_on(char *name)
256 acct = NULL; 257 acct = NULL;
257 } 258 }
258 259
259 mnt_pin(file->f_path.mnt); 260 mnt = file->f_path.mnt;
261 mnt_pin(mnt);
260 acct_file_reopen(ns->bacct, file, ns); 262 acct_file_reopen(ns->bacct, file, ns);
261 spin_unlock(&acct_lock); 263 spin_unlock(&acct_lock);
262 264
263 mntput(file->f_path.mnt); /* it's pinned, now give up active reference */ 265 mntput(mnt); /* it's pinned, now give up active reference */
264 kfree(acct); 266 kfree(acct);
265 267
266 return 0; 268 return 0;
diff --git a/kernel/futex.c b/kernel/futex.c
index 1c337112335c..794c862125fe 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -299,7 +299,7 @@ void put_futex_key(int fshared, union futex_key *key)
299static int fault_in_user_writeable(u32 __user *uaddr) 299static int fault_in_user_writeable(u32 __user *uaddr)
300{ 300{
301 int ret = get_user_pages(current, current->mm, (unsigned long)uaddr, 301 int ret = get_user_pages(current, current->mm, (unsigned long)uaddr,
302 sizeof(*uaddr), 1, 0, NULL, NULL); 302 1, 1, 0, NULL, NULL);
303 return ret < 0 ? ret : 0; 303 return ret < 0 ? ret : 0;
304} 304}
305 305
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 1a933a221ea4..d55a50da2347 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -236,6 +236,8 @@ list_add_counter(struct perf_counter *counter, struct perf_counter_context *ctx)
236 236
237 list_add_rcu(&counter->event_entry, &ctx->event_list); 237 list_add_rcu(&counter->event_entry, &ctx->event_list);
238 ctx->nr_counters++; 238 ctx->nr_counters++;
239 if (counter->attr.inherit_stat)
240 ctx->nr_stat++;
239} 241}
240 242
241/* 243/*
@@ -250,6 +252,8 @@ list_del_counter(struct perf_counter *counter, struct perf_counter_context *ctx)
250 if (list_empty(&counter->list_entry)) 252 if (list_empty(&counter->list_entry))
251 return; 253 return;
252 ctx->nr_counters--; 254 ctx->nr_counters--;
255 if (counter->attr.inherit_stat)
256 ctx->nr_stat--;
253 257
254 list_del_init(&counter->list_entry); 258 list_del_init(&counter->list_entry);
255 list_del_rcu(&counter->event_entry); 259 list_del_rcu(&counter->event_entry);
@@ -1006,6 +1010,81 @@ static int context_equiv(struct perf_counter_context *ctx1,
1006 && !ctx1->pin_count && !ctx2->pin_count; 1010 && !ctx1->pin_count && !ctx2->pin_count;
1007} 1011}
1008 1012
1013static void __perf_counter_read(void *counter);
1014
1015static void __perf_counter_sync_stat(struct perf_counter *counter,
1016 struct perf_counter *next_counter)
1017{
1018 u64 value;
1019
1020 if (!counter->attr.inherit_stat)
1021 return;
1022
1023 /*
1024 * Update the counter value, we cannot use perf_counter_read()
1025 * because we're in the middle of a context switch and have IRQs
1026 * disabled, which upsets smp_call_function_single(), however
1027 * we know the counter must be on the current CPU, therefore we
1028 * don't need to use it.
1029 */
1030 switch (counter->state) {
1031 case PERF_COUNTER_STATE_ACTIVE:
1032 __perf_counter_read(counter);
1033 break;
1034
1035 case PERF_COUNTER_STATE_INACTIVE:
1036 update_counter_times(counter);
1037 break;
1038
1039 default:
1040 break;
1041 }
1042
1043 /*
1044 * In order to keep per-task stats reliable we need to flip the counter
1045 * values when we flip the contexts.
1046 */
1047 value = atomic64_read(&next_counter->count);
1048 value = atomic64_xchg(&counter->count, value);
1049 atomic64_set(&next_counter->count, value);
1050
1051 swap(counter->total_time_enabled, next_counter->total_time_enabled);
1052 swap(counter->total_time_running, next_counter->total_time_running);
1053
1054 /*
1055 * Since we swizzled the values, update the user visible data too.
1056 */
1057 perf_counter_update_userpage(counter);
1058 perf_counter_update_userpage(next_counter);
1059}
1060
1061#define list_next_entry(pos, member) \
1062 list_entry(pos->member.next, typeof(*pos), member)
1063
1064static void perf_counter_sync_stat(struct perf_counter_context *ctx,
1065 struct perf_counter_context *next_ctx)
1066{
1067 struct perf_counter *counter, *next_counter;
1068
1069 if (!ctx->nr_stat)
1070 return;
1071
1072 counter = list_first_entry(&ctx->event_list,
1073 struct perf_counter, event_entry);
1074
1075 next_counter = list_first_entry(&next_ctx->event_list,
1076 struct perf_counter, event_entry);
1077
1078 while (&counter->event_entry != &ctx->event_list &&
1079 &next_counter->event_entry != &next_ctx->event_list) {
1080
1081 __perf_counter_sync_stat(counter, next_counter);
1082
1083 counter = list_next_entry(counter, event_entry);
1084 next_counter = list_next_entry(counter, event_entry);
1085 }
1086}
1087
1009/* 1088/*
1010 * Called from scheduler to remove the counters of the current task, 1089 * Called from scheduler to remove the counters of the current task,
1011 * with interrupts disabled. 1090 * with interrupts disabled.
@@ -1061,6 +1140,8 @@ void perf_counter_task_sched_out(struct task_struct *task,
1061 ctx->task = next; 1140 ctx->task = next;
1062 next_ctx->task = task; 1141 next_ctx->task = task;
1063 do_switch = 0; 1142 do_switch = 0;
1143
1144 perf_counter_sync_stat(ctx, next_ctx);
1064 } 1145 }
1065 spin_unlock(&next_ctx->lock); 1146 spin_unlock(&next_ctx->lock);
1066 spin_unlock(&ctx->lock); 1147 spin_unlock(&ctx->lock);
@@ -1348,9 +1429,56 @@ void perf_counter_task_tick(struct task_struct *curr, int cpu)
1348} 1429}
1349 1430
1350/* 1431/*
1432 * Enable all of a task's counters that have been marked enable-on-exec.
1433 * This expects task == current.
1434 */
1435static void perf_counter_enable_on_exec(struct task_struct *task)
1436{
1437 struct perf_counter_context *ctx;
1438 struct perf_counter *counter;
1439 unsigned long flags;
1440 int enabled = 0;
1441
1442 local_irq_save(flags);
1443 ctx = task->perf_counter_ctxp;
1444 if (!ctx || !ctx->nr_counters)
1445 goto out;
1446
1447 __perf_counter_task_sched_out(ctx);
1448
1449 spin_lock(&ctx->lock);
1450
1451 list_for_each_entry(counter, &ctx->counter_list, list_entry) {
1452 if (!counter->attr.enable_on_exec)
1453 continue;
1454 counter->attr.enable_on_exec = 0;
1455 if (counter->state >= PERF_COUNTER_STATE_INACTIVE)
1456 continue;
1457 counter->state = PERF_COUNTER_STATE_INACTIVE;
1458 counter->tstamp_enabled =
1459 ctx->time - counter->total_time_enabled;
1460 enabled = 1;
1461 }
1462
1463 /*
1464 * Unclone this context if we enabled any counter.
1465 */
1466 if (enabled && ctx->parent_ctx) {
1467 put_ctx(ctx->parent_ctx);
1468 ctx->parent_ctx = NULL;
1469 }
1470
1471 spin_unlock(&ctx->lock);
1472
1473 perf_counter_task_sched_in(task, smp_processor_id());
1474 out:
1475 local_irq_restore(flags);
1476}
1477
1478/*
1351 * Cross CPU call to read the hardware counter 1479 * Cross CPU call to read the hardware counter
1352 */ 1480 */
1353static void __read(void *info) 1481static void __perf_counter_read(void *info)
1354{ 1482{
1355 struct perf_counter *counter = info; 1483 struct perf_counter *counter = info;
1356 struct perf_counter_context *ctx = counter->ctx; 1484 struct perf_counter_context *ctx = counter->ctx;
@@ -1372,7 +1500,7 @@ static u64 perf_counter_read(struct perf_counter *counter)
1372 */ 1500 */
1373 if (counter->state == PERF_COUNTER_STATE_ACTIVE) { 1501 if (counter->state == PERF_COUNTER_STATE_ACTIVE) {
1374 smp_call_function_single(counter->oncpu, 1502 smp_call_function_single(counter->oncpu,
1375 __read, counter, 1); 1503 __perf_counter_read, counter, 1);
1376 } else if (counter->state == PERF_COUNTER_STATE_INACTIVE) { 1504 } else if (counter->state == PERF_COUNTER_STATE_INACTIVE) {
1377 update_counter_times(counter); 1505 update_counter_times(counter);
1378 } 1506 }
@@ -1508,11 +1636,13 @@ static void free_counter(struct perf_counter *counter)
1508{ 1636{
1509 perf_pending_sync(counter); 1637 perf_pending_sync(counter);
1510 1638
1511 atomic_dec(&nr_counters); 1639 if (!counter->parent) {
1512 if (counter->attr.mmap) 1640 atomic_dec(&nr_counters);
1513 atomic_dec(&nr_mmap_counters); 1641 if (counter->attr.mmap)
1514 if (counter->attr.comm) 1642 atomic_dec(&nr_mmap_counters);
1515 atomic_dec(&nr_comm_counters); 1643 if (counter->attr.comm)
1644 atomic_dec(&nr_comm_counters);
1645 }
1516 1646
1517 if (counter->destroy) 1647 if (counter->destroy)
1518 counter->destroy(counter); 1648 counter->destroy(counter);
@@ -1751,6 +1881,14 @@ int perf_counter_task_disable(void)
1751 return 0; 1881 return 0;
1752} 1882}
1753 1883
1884static int perf_counter_index(struct perf_counter *counter)
1885{
1886 if (counter->state != PERF_COUNTER_STATE_ACTIVE)
1887 return 0;
1888
1889 return counter->hw.idx + 1 - PERF_COUNTER_INDEX_OFFSET;
1890}
1891
1754/* 1892/*
1755 * Callers need to ensure there can be no nesting of this function, otherwise 1893 * Callers need to ensure there can be no nesting of this function, otherwise
1756 * the seqlock logic goes bad. We can not serialize this because the arch 1894 * the seqlock logic goes bad. We can not serialize this because the arch
@@ -1775,11 +1913,17 @@ void perf_counter_update_userpage(struct perf_counter *counter)
1775 preempt_disable(); 1913 preempt_disable();
1776 ++userpg->lock; 1914 ++userpg->lock;
1777 barrier(); 1915 barrier();
1778 userpg->index = counter->hw.idx; 1916 userpg->index = perf_counter_index(counter);
1779 userpg->offset = atomic64_read(&counter->count); 1917 userpg->offset = atomic64_read(&counter->count);
1780 if (counter->state == PERF_COUNTER_STATE_ACTIVE) 1918 if (counter->state == PERF_COUNTER_STATE_ACTIVE)
1781 userpg->offset -= atomic64_read(&counter->hw.prev_count); 1919 userpg->offset -= atomic64_read(&counter->hw.prev_count);
1782 1920
1921 userpg->time_enabled = counter->total_time_enabled +
1922 atomic64_read(&counter->child_total_time_enabled);
1923
1924 userpg->time_running = counter->total_time_running +
1925 atomic64_read(&counter->child_total_time_running);
1926
1783 barrier(); 1927 barrier();
1784 ++userpg->lock; 1928 ++userpg->lock;
1785 preempt_enable(); 1929 preempt_enable();
@@ -2483,15 +2627,14 @@ static void perf_counter_output(struct perf_counter *counter, int nmi,
2483 u32 cpu, reserved; 2627 u32 cpu, reserved;
2484 } cpu_entry; 2628 } cpu_entry;
2485 2629
2486 header.type = 0; 2630 header.type = PERF_EVENT_SAMPLE;
2487 header.size = sizeof(header); 2631 header.size = sizeof(header);
2488 2632
2489 header.misc = PERF_EVENT_MISC_OVERFLOW; 2633 header.misc = 0;
2490 header.misc |= perf_misc_flags(data->regs); 2634 header.misc |= perf_misc_flags(data->regs);
2491 2635
2492 if (sample_type & PERF_SAMPLE_IP) { 2636 if (sample_type & PERF_SAMPLE_IP) {
2493 ip = perf_instruction_pointer(data->regs); 2637 ip = perf_instruction_pointer(data->regs);
2494 header.type |= PERF_SAMPLE_IP;
2495 header.size += sizeof(ip); 2638 header.size += sizeof(ip);
2496 } 2639 }
2497 2640
@@ -2500,7 +2643,6 @@ static void perf_counter_output(struct perf_counter *counter, int nmi,
2500 tid_entry.pid = perf_counter_pid(counter, current); 2643 tid_entry.pid = perf_counter_pid(counter, current);
2501 tid_entry.tid = perf_counter_tid(counter, current); 2644 tid_entry.tid = perf_counter_tid(counter, current);
2502 2645
2503 header.type |= PERF_SAMPLE_TID;
2504 header.size += sizeof(tid_entry); 2646 header.size += sizeof(tid_entry);
2505 } 2647 }
2506 2648
@@ -2510,34 +2652,25 @@ static void perf_counter_output(struct perf_counter *counter, int nmi,
2510 */ 2652 */
2511 time = sched_clock(); 2653 time = sched_clock();
2512 2654
2513 header.type |= PERF_SAMPLE_TIME;
2514 header.size += sizeof(u64); 2655 header.size += sizeof(u64);
2515 } 2656 }
2516 2657
2517 if (sample_type & PERF_SAMPLE_ADDR) { 2658 if (sample_type & PERF_SAMPLE_ADDR)
2518 header.type |= PERF_SAMPLE_ADDR;
2519 header.size += sizeof(u64); 2659 header.size += sizeof(u64);
2520 }
2521 2660
2522 if (sample_type & PERF_SAMPLE_ID) { 2661 if (sample_type & PERF_SAMPLE_ID)
2523 header.type |= PERF_SAMPLE_ID;
2524 header.size += sizeof(u64); 2662 header.size += sizeof(u64);
2525 }
2526 2663
2527 if (sample_type & PERF_SAMPLE_CPU) { 2664 if (sample_type & PERF_SAMPLE_CPU) {
2528 header.type |= PERF_SAMPLE_CPU;
2529 header.size += sizeof(cpu_entry); 2665 header.size += sizeof(cpu_entry);
2530 2666
2531 cpu_entry.cpu = raw_smp_processor_id(); 2667 cpu_entry.cpu = raw_smp_processor_id();
2532 } 2668 }
2533 2669
2534 if (sample_type & PERF_SAMPLE_PERIOD) { 2670 if (sample_type & PERF_SAMPLE_PERIOD)
2535 header.type |= PERF_SAMPLE_PERIOD;
2536 header.size += sizeof(u64); 2671 header.size += sizeof(u64);
2537 }
2538 2672
2539 if (sample_type & PERF_SAMPLE_GROUP) { 2673 if (sample_type & PERF_SAMPLE_GROUP) {
2540 header.type |= PERF_SAMPLE_GROUP;
2541 header.size += sizeof(u64) + 2674 header.size += sizeof(u64) +
2542 counter->nr_siblings * sizeof(group_entry); 2675 counter->nr_siblings * sizeof(group_entry);
2543 } 2676 }
@@ -2547,10 +2680,9 @@ static void perf_counter_output(struct perf_counter *counter, int nmi,
2547 2680
2548 if (callchain) { 2681 if (callchain) {
2549 callchain_size = (1 + callchain->nr) * sizeof(u64); 2682 callchain_size = (1 + callchain->nr) * sizeof(u64);
2550
2551 header.type |= PERF_SAMPLE_CALLCHAIN;
2552 header.size += callchain_size; 2683 header.size += callchain_size;
2553 } 2684 } else
2685 header.size += sizeof(u64);
2554 } 2686 }
2555 2687
2556 ret = perf_output_begin(&handle, counter, header.size, nmi, 1); 2688 ret = perf_output_begin(&handle, counter, header.size, nmi, 1);
@@ -2601,13 +2733,79 @@ static void perf_counter_output(struct perf_counter *counter, int nmi,
2601 } 2733 }
2602 } 2734 }
2603 2735
2604 if (callchain) 2736 if (sample_type & PERF_SAMPLE_CALLCHAIN) {
2605 perf_output_copy(&handle, callchain, callchain_size); 2737 if (callchain)
2738 perf_output_copy(&handle, callchain, callchain_size);
2739 else {
2740 u64 nr = 0;
2741 perf_output_put(&handle, nr);
2742 }
2743 }
2606 2744
2607 perf_output_end(&handle); 2745 perf_output_end(&handle);
2608} 2746}
2609 2747
2610/* 2748/*
2749 * read event
2750 */
2751
2752struct perf_read_event {
2753 struct perf_event_header header;
2754
2755 u32 pid;
2756 u32 tid;
2757 u64 value;
2758 u64 format[3];
2759};
2760
2761static void
2762perf_counter_read_event(struct perf_counter *counter,
2763 struct task_struct *task)
2764{
2765 struct perf_output_handle handle;
2766 struct perf_read_event event = {
2767 .header = {
2768 .type = PERF_EVENT_READ,
2769 .misc = 0,
2770 .size = sizeof(event) - sizeof(event.format),
2771 },
2772 .pid = perf_counter_pid(counter, task),
2773 .tid = perf_counter_tid(counter, task),
2774 .value = atomic64_read(&counter->count),
2775 };
2776 int ret, i = 0;
2777
2778 if (counter->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
2779 event.header.size += sizeof(u64);
2780 event.format[i++] = counter->total_time_enabled;
2781 }
2782
2783 if (counter->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
2784 event.header.size += sizeof(u64);
2785 event.format[i++] = counter->total_time_running;
2786 }
2787
2788 if (counter->attr.read_format & PERF_FORMAT_ID) {
2789 u64 id;
2790
2791 event.header.size += sizeof(u64);
2792 if (counter->parent)
2793 id = counter->parent->id;
2794 else
2795 id = counter->id;
2796
2797 event.format[i++] = id;
2798 }
2799
2800 ret = perf_output_begin(&handle, counter, event.header.size, 0, 0);
2801 if (ret)
2802 return;
2803
2804 perf_output_copy(&handle, &event, event.header.size);
2805 perf_output_end(&handle);
2806}
2807
2808/*
2611 * fork tracking 2809 * fork tracking
2612 */ 2810 */
2613 2811
@@ -2798,6 +2996,9 @@ void perf_counter_comm(struct task_struct *task)
2798{ 2996{
2799 struct perf_comm_event comm_event; 2997 struct perf_comm_event comm_event;
2800 2998
2999 if (task->perf_counter_ctxp)
3000 perf_counter_enable_on_exec(task);
3001
2801 if (!atomic_read(&nr_comm_counters)) 3002 if (!atomic_read(&nr_comm_counters))
2802 return; 3003 return;
2803 3004
@@ -3317,8 +3518,8 @@ out:
3317 put_cpu_var(perf_cpu_context); 3518 put_cpu_var(perf_cpu_context);
3318} 3519}
3319 3520
3320void 3521void __perf_swcounter_event(u32 event, u64 nr, int nmi,
3321perf_swcounter_event(u32 event, u64 nr, int nmi, struct pt_regs *regs, u64 addr) 3522 struct pt_regs *regs, u64 addr)
3322{ 3523{
3323 struct perf_sample_data data = { 3524 struct perf_sample_data data = {
3324 .regs = regs, 3525 .regs = regs,
@@ -3509,9 +3710,21 @@ static const struct pmu *tp_perf_counter_init(struct perf_counter *counter)
3509} 3710}
3510#endif 3711#endif
3511 3712
3713atomic_t perf_swcounter_enabled[PERF_COUNT_SW_MAX];
3714
3715static void sw_perf_counter_destroy(struct perf_counter *counter)
3716{
3717 u64 event = counter->attr.config;
3718
3719 WARN_ON(counter->parent);
3720
3721 atomic_dec(&perf_swcounter_enabled[event]);
3722}
3723
3512static const struct pmu *sw_perf_counter_init(struct perf_counter *counter) 3724static const struct pmu *sw_perf_counter_init(struct perf_counter *counter)
3513{ 3725{
3514 const struct pmu *pmu = NULL; 3726 const struct pmu *pmu = NULL;
3727 u64 event = counter->attr.config;
3515 3728
3516 /* 3729 /*
3517 * Software counters (currently) can't in general distinguish 3730 * Software counters (currently) can't in general distinguish
@@ -3520,7 +3733,7 @@ static const struct pmu *sw_perf_counter_init(struct perf_counter *counter)
3520 * to be kernel events, and page faults are never hypervisor 3733 * to be kernel events, and page faults are never hypervisor
3521 * events. 3734 * events.
3522 */ 3735 */
3523 switch (counter->attr.config) { 3736 switch (event) {
3524 case PERF_COUNT_SW_CPU_CLOCK: 3737 case PERF_COUNT_SW_CPU_CLOCK:
3525 pmu = &perf_ops_cpu_clock; 3738 pmu = &perf_ops_cpu_clock;
3526 3739
@@ -3541,6 +3754,10 @@ static const struct pmu *sw_perf_counter_init(struct perf_counter *counter)
3541 case PERF_COUNT_SW_PAGE_FAULTS_MAJ: 3754 case PERF_COUNT_SW_PAGE_FAULTS_MAJ:
3542 case PERF_COUNT_SW_CONTEXT_SWITCHES: 3755 case PERF_COUNT_SW_CONTEXT_SWITCHES:
3543 case PERF_COUNT_SW_CPU_MIGRATIONS: 3756 case PERF_COUNT_SW_CPU_MIGRATIONS:
3757 if (!counter->parent) {
3758 atomic_inc(&perf_swcounter_enabled[event]);
3759 counter->destroy = sw_perf_counter_destroy;
3760 }
3544 pmu = &perf_ops_generic; 3761 pmu = &perf_ops_generic;
3545 break; 3762 break;
3546 } 3763 }
@@ -3556,6 +3773,7 @@ perf_counter_alloc(struct perf_counter_attr *attr,
3556 int cpu, 3773 int cpu,
3557 struct perf_counter_context *ctx, 3774 struct perf_counter_context *ctx,
3558 struct perf_counter *group_leader, 3775 struct perf_counter *group_leader,
3776 struct perf_counter *parent_counter,
3559 gfp_t gfpflags) 3777 gfp_t gfpflags)
3560{ 3778{
3561 const struct pmu *pmu; 3779 const struct pmu *pmu;
@@ -3591,6 +3809,8 @@ perf_counter_alloc(struct perf_counter_attr *attr,
3591 counter->ctx = ctx; 3809 counter->ctx = ctx;
3592 counter->oncpu = -1; 3810 counter->oncpu = -1;
3593 3811
3812 counter->parent = parent_counter;
3813
3594 counter->ns = get_pid_ns(current->nsproxy->pid_ns); 3814 counter->ns = get_pid_ns(current->nsproxy->pid_ns);
3595 counter->id = atomic64_inc_return(&perf_counter_id); 3815 counter->id = atomic64_inc_return(&perf_counter_id);
3596 3816
@@ -3648,11 +3868,13 @@ done:
3648 3868
3649 counter->pmu = pmu; 3869 counter->pmu = pmu;
3650 3870
3651 atomic_inc(&nr_counters); 3871 if (!counter->parent) {
3652 if (counter->attr.mmap) 3872 atomic_inc(&nr_counters);
3653 atomic_inc(&nr_mmap_counters); 3873 if (counter->attr.mmap)
3654 if (counter->attr.comm) 3874 atomic_inc(&nr_mmap_counters);
3655 atomic_inc(&nr_comm_counters); 3875 if (counter->attr.comm)
3876 atomic_inc(&nr_comm_counters);
3877 }
3656 3878
3657 return counter; 3879 return counter;
3658} 3880}
@@ -3815,7 +4037,7 @@ SYSCALL_DEFINE5(perf_counter_open,
3815 } 4037 }
3816 4038
3817 counter = perf_counter_alloc(&attr, cpu, ctx, group_leader, 4039 counter = perf_counter_alloc(&attr, cpu, ctx, group_leader,
3818 GFP_KERNEL); 4040 NULL, GFP_KERNEL);
3819 ret = PTR_ERR(counter); 4041 ret = PTR_ERR(counter);
3820 if (IS_ERR(counter)) 4042 if (IS_ERR(counter))
3821 goto err_put_context; 4043 goto err_put_context;
@@ -3881,7 +4103,8 @@ inherit_counter(struct perf_counter *parent_counter,
3881 4103
3882 child_counter = perf_counter_alloc(&parent_counter->attr, 4104 child_counter = perf_counter_alloc(&parent_counter->attr,
3883 parent_counter->cpu, child_ctx, 4105 parent_counter->cpu, child_ctx,
3884 group_leader, GFP_KERNEL); 4106 group_leader, parent_counter,
4107 GFP_KERNEL);
3885 if (IS_ERR(child_counter)) 4108 if (IS_ERR(child_counter))
3886 return child_counter; 4109 return child_counter;
3887 get_ctx(child_ctx); 4110 get_ctx(child_ctx);
@@ -3904,12 +4127,6 @@ inherit_counter(struct perf_counter *parent_counter,
3904 */ 4127 */
3905 add_counter_to_ctx(child_counter, child_ctx); 4128 add_counter_to_ctx(child_counter, child_ctx);
3906 4129
3907 child_counter->parent = parent_counter;
3908 /*
3909 * inherit into child's child as well:
3910 */
3911 child_counter->attr.inherit = 1;
3912
3913 /* 4130 /*
3914 * Get a reference to the parent filp - we will fput it 4131 * Get a reference to the parent filp - we will fput it
3915 * when the child counter exits. This is safe to do because 4132 * when the child counter exits. This is safe to do because
@@ -3953,10 +4170,14 @@ static int inherit_group(struct perf_counter *parent_counter,
3953} 4170}
3954 4171
3955static void sync_child_counter(struct perf_counter *child_counter, 4172static void sync_child_counter(struct perf_counter *child_counter,
3956 struct perf_counter *parent_counter) 4173 struct task_struct *child)
3957{ 4174{
4175 struct perf_counter *parent_counter = child_counter->parent;
3958 u64 child_val; 4176 u64 child_val;
3959 4177
4178 if (child_counter->attr.inherit_stat)
4179 perf_counter_read_event(child_counter, child);
4180
3960 child_val = atomic64_read(&child_counter->count); 4181 child_val = atomic64_read(&child_counter->count);
3961 4182
3962 /* 4183 /*
@@ -3985,7 +4206,8 @@ static void sync_child_counter(struct perf_counter *child_counter,
3985 4206
3986static void 4207static void
3987__perf_counter_exit_task(struct perf_counter *child_counter, 4208__perf_counter_exit_task(struct perf_counter *child_counter,
3988 struct perf_counter_context *child_ctx) 4209 struct perf_counter_context *child_ctx,
4210 struct task_struct *child)
3989{ 4211{
3990 struct perf_counter *parent_counter; 4212 struct perf_counter *parent_counter;
3991 4213
@@ -3999,7 +4221,7 @@ __perf_counter_exit_task(struct perf_counter *child_counter,
3999 * counters need to be zapped - but otherwise linger. 4221 * counters need to be zapped - but otherwise linger.
4000 */ 4222 */
4001 if (parent_counter) { 4223 if (parent_counter) {
4002 sync_child_counter(child_counter, parent_counter); 4224 sync_child_counter(child_counter, child);
4003 free_counter(child_counter); 4225 free_counter(child_counter);
4004 } 4226 }
4005} 4227}
@@ -4061,7 +4283,7 @@ void perf_counter_exit_task(struct task_struct *child)
4061again: 4283again:
4062 list_for_each_entry_safe(child_counter, tmp, &child_ctx->counter_list, 4284 list_for_each_entry_safe(child_counter, tmp, &child_ctx->counter_list,
4063 list_entry) 4285 list_entry)
4064 __perf_counter_exit_task(child_counter, child_ctx); 4286 __perf_counter_exit_task(child_counter, child_ctx, child);
4065 4287
4066 /* 4288 /*
4067 * If the last counter was a group counter, it will have appended all 4289 * If the last counter was a group counter, it will have appended all
diff --git a/kernel/pid.c b/kernel/pid.c
index 31310b5d3f50..5fa1db48d8b7 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -36,6 +36,7 @@
36#include <linux/pid_namespace.h> 36#include <linux/pid_namespace.h>
37#include <linux/init_task.h> 37#include <linux/init_task.h>
38#include <linux/syscalls.h> 38#include <linux/syscalls.h>
39#include <linux/kmemleak.h>
39 40
40#define pid_hashfn(nr, ns) \ 41#define pid_hashfn(nr, ns) \
41 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift) 42 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
@@ -512,6 +513,12 @@ void __init pidhash_init(void)
512 pid_hash = alloc_bootmem(pidhash_size * sizeof(*(pid_hash))); 513 pid_hash = alloc_bootmem(pidhash_size * sizeof(*(pid_hash)));
513 if (!pid_hash) 514 if (!pid_hash)
514 panic("Could not alloc pidhash!\n"); 515 panic("Could not alloc pidhash!\n");
516 /*
517 * pid_hash contains references to allocated struct pid objects and it
518 * must be scanned by kmemleak to avoid false positives.
519 */
520 kmemleak_alloc(pid_hash, pidhash_size * sizeof(*(pid_hash)), 0,
521 GFP_KERNEL);
515 for (i = 0; i < pidhash_size; i++) 522 for (i = 0; i < pidhash_size; i++)
516 INIT_HLIST_HEAD(&pid_hash[i]); 523 INIT_HLIST_HEAD(&pid_hash[i]);
517} 524}
diff --git a/kernel/resource.c b/kernel/resource.c
index ac5f3a36923f..78b087221c15 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -787,7 +787,7 @@ static int __init reserve_setup(char *str)
787 static struct resource reserve[MAXRESERVE]; 787 static struct resource reserve[MAXRESERVE];
788 788
789 for (;;) { 789 for (;;) {
790 int io_start, io_num; 790 unsigned int io_start, io_num;
791 int x = reserved; 791 int x = reserved;
792 792
793 if (get_option (&str, &io_start) != 2) 793 if (get_option (&str, &io_start) != 2)
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 62e4ff9968b5..98e02328c67d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -335,7 +335,10 @@ static struct ctl_table kern_table[] = {
335 .data = &sysctl_timer_migration, 335 .data = &sysctl_timer_migration,
336 .maxlen = sizeof(unsigned int), 336 .maxlen = sizeof(unsigned int),
337 .mode = 0644, 337 .mode = 0644,
338 .proc_handler = &proc_dointvec, 338 .proc_handler = &proc_dointvec_minmax,
339 .strategy = &sysctl_intvec,
340 .extra1 = &zero,
341 .extra2 = &one,
339 }, 342 },
340#endif 343#endif
341 { 344 {
@@ -744,6 +747,14 @@ static struct ctl_table kern_table[] = {
744 .proc_handler = &proc_dointvec, 747 .proc_handler = &proc_dointvec,
745 }, 748 },
746 { 749 {
750 .ctl_name = CTL_UNNUMBERED,
751 .procname = "panic_on_io_nmi",
752 .data = &panic_on_io_nmi,
753 .maxlen = sizeof(int),
754 .mode = 0644,
755 .proc_handler = &proc_dointvec,
756 },
757 {
747 .ctl_name = KERN_BOOTLOADER_TYPE, 758 .ctl_name = KERN_BOOTLOADER_TYPE,
748 .procname = "bootloader_type", 759 .procname = "bootloader_type",
749 .data = &bootloader_type, 760 .data = &bootloader_type,
diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 888adbcca30c..ea8384d3caa7 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -108,7 +108,7 @@ static int prepare_reply(struct genl_info *info, u8 cmd, struct sk_buff **skbp,
108/* 108/*
109 * Send taskstats data in @skb to listener with nl_pid @pid 109 * Send taskstats data in @skb to listener with nl_pid @pid
110 */ 110 */
111static int send_reply(struct sk_buff *skb, pid_t pid) 111static int send_reply(struct sk_buff *skb, struct genl_info *info)
112{ 112{
113 struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb)); 113 struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
114 void *reply = genlmsg_data(genlhdr); 114 void *reply = genlmsg_data(genlhdr);
@@ -120,7 +120,7 @@ static int send_reply(struct sk_buff *skb, pid_t pid)
120 return rc; 120 return rc;
121 } 121 }
122 122
123 return genlmsg_unicast(skb, pid); 123 return genlmsg_reply(skb, info);
124} 124}
125 125
126/* 126/*
@@ -150,7 +150,7 @@ static void send_cpu_listeners(struct sk_buff *skb,
150 if (!skb_next) 150 if (!skb_next)
151 break; 151 break;
152 } 152 }
153 rc = genlmsg_unicast(skb_cur, s->pid); 153 rc = genlmsg_unicast(&init_net, skb_cur, s->pid);
154 if (rc == -ECONNREFUSED) { 154 if (rc == -ECONNREFUSED) {
155 s->valid = 0; 155 s->valid = 0;
156 delcount++; 156 delcount++;
@@ -418,7 +418,7 @@ static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
418 goto err; 418 goto err;
419 } 419 }
420 420
421 rc = send_reply(rep_skb, info->snd_pid); 421 rc = send_reply(rep_skb, info);
422 422
423err: 423err:
424 fput_light(file, fput_needed); 424 fput_light(file, fput_needed);
@@ -487,7 +487,7 @@ free_return_rc:
487 } else 487 } else
488 goto err; 488 goto err;
489 489
490 return send_reply(rep_skb, info->snd_pid); 490 return send_reply(rep_skb, info);
491err: 491err:
492 nlmsg_free(rep_skb); 492 nlmsg_free(rep_skb);
493 return rc; 493 return rc;
diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
index c994530d166d..4cde8b9c716f 100644
--- a/kernel/time/timer_stats.c
+++ b/kernel/time/timer_stats.c
@@ -96,7 +96,7 @@ static DEFINE_MUTEX(show_mutex);
96/* 96/*
97 * Collection status, active/inactive: 97 * Collection status, active/inactive:
98 */ 98 */
99static int __read_mostly active; 99int __read_mostly timer_stats_active;
100 100
101/* 101/*
102 * Beginning/end timestamps of measurement: 102 * Beginning/end timestamps of measurement:
@@ -242,7 +242,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
242 struct entry *entry, input; 242 struct entry *entry, input;
243 unsigned long flags; 243 unsigned long flags;
244 244
245 if (likely(!active)) 245 if (likely(!timer_stats_active))
246 return; 246 return;
247 247
248 lock = &per_cpu(lookup_lock, raw_smp_processor_id()); 248 lock = &per_cpu(lookup_lock, raw_smp_processor_id());
@@ -254,7 +254,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
254 input.timer_flag = timer_flag; 254 input.timer_flag = timer_flag;
255 255
256 spin_lock_irqsave(lock, flags); 256 spin_lock_irqsave(lock, flags);
257 if (!active) 257 if (!timer_stats_active)
258 goto out_unlock; 258 goto out_unlock;
259 259
260 entry = tstat_lookup(&input, comm); 260 entry = tstat_lookup(&input, comm);
@@ -290,7 +290,7 @@ static int tstats_show(struct seq_file *m, void *v)
290 /* 290 /*
291 * If still active then calculate up to now: 291 * If still active then calculate up to now:
292 */ 292 */
293 if (active) 293 if (timer_stats_active)
294 time_stop = ktime_get(); 294 time_stop = ktime_get();
295 295
296 time = ktime_sub(time_stop, time_start); 296 time = ktime_sub(time_stop, time_start);
@@ -368,18 +368,18 @@ static ssize_t tstats_write(struct file *file, const char __user *buf,
368 mutex_lock(&show_mutex); 368 mutex_lock(&show_mutex);
369 switch (ctl[0]) { 369 switch (ctl[0]) {
370 case '0': 370 case '0':
371 if (active) { 371 if (timer_stats_active) {
372 active = 0; 372 timer_stats_active = 0;
373 time_stop = ktime_get(); 373 time_stop = ktime_get();
374 sync_access(); 374 sync_access();
375 } 375 }
376 break; 376 break;
377 case '1': 377 case '1':
378 if (!active) { 378 if (!timer_stats_active) {
379 reset_entries(); 379 reset_entries();
380 time_start = ktime_get(); 380 time_start = ktime_get();
381 smp_mb(); 381 smp_mb();
382 active = 1; 382 timer_stats_active = 1;
383 } 383 }
384 break; 384 break;
385 default: 385 default:
diff --git a/kernel/timer.c b/kernel/timer.c
index 54d3912f8cad..0b36b9e5cc8b 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -380,6 +380,8 @@ static void timer_stats_account_timer(struct timer_list *timer)
380{ 380{
381 unsigned int flag = 0; 381 unsigned int flag = 0;
382 382
383 if (likely(!timer->start_site))
384 return;
383 if (unlikely(tbase_get_deferrable(timer->base))) 385 if (unlikely(tbase_get_deferrable(timer->base)))
384 flag |= TIMER_STATS_FLAG_DEFERRABLE; 386 flag |= TIMER_STATS_FLAG_DEFERRABLE;
385 387
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 3718d55fb4c3..f3716bf04df6 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -291,7 +291,9 @@ function_stat_next(void *v, int idx)
291 pg = (struct ftrace_profile_page *)((unsigned long)rec & PAGE_MASK); 291 pg = (struct ftrace_profile_page *)((unsigned long)rec & PAGE_MASK);
292 292
293 again: 293 again:
294 rec++; 294 if (idx != 0)
295 rec++;
296
295 if ((void *)rec >= (void *)&pg->records[pg->index]) { 297 if ((void *)rec >= (void *)&pg->records[pg->index]) {
296 pg = pg->next; 298 pg = pg->next;
297 if (!pg) 299 if (!pg)
@@ -1417,10 +1419,20 @@ static void *t_hash_start(struct seq_file *m, loff_t *pos)
1417{ 1419{
1418 struct ftrace_iterator *iter = m->private; 1420 struct ftrace_iterator *iter = m->private;
1419 void *p = NULL; 1421 void *p = NULL;
1422 loff_t l;
1423
1424 if (!(iter->flags & FTRACE_ITER_HASH))
1425 *pos = 0;
1420 1426
1421 iter->flags |= FTRACE_ITER_HASH; 1427 iter->flags |= FTRACE_ITER_HASH;
1422 1428
1423 return t_hash_next(m, p, pos); 1429 iter->hidx = 0;
1430 for (l = 0; l <= *pos; ) {
1431 p = t_hash_next(m, p, &l);
1432 if (!p)
1433 break;
1434 }
1435 return p;
1424} 1436}
1425 1437
1426static int t_hash_show(struct seq_file *m, void *v) 1438static int t_hash_show(struct seq_file *m, void *v)
@@ -1467,8 +1479,6 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
1467 iter->pg = iter->pg->next; 1479 iter->pg = iter->pg->next;
1468 iter->idx = 0; 1480 iter->idx = 0;
1469 goto retry; 1481 goto retry;
1470 } else {
1471 iter->idx = -1;
1472 } 1482 }
1473 } else { 1483 } else {
1474 rec = &iter->pg->records[iter->idx++]; 1484 rec = &iter->pg->records[iter->idx++];
@@ -1497,6 +1507,7 @@ static void *t_start(struct seq_file *m, loff_t *pos)
1497{ 1507{
1498 struct ftrace_iterator *iter = m->private; 1508 struct ftrace_iterator *iter = m->private;
1499 void *p = NULL; 1509 void *p = NULL;
1510 loff_t l;
1500 1511
1501 mutex_lock(&ftrace_lock); 1512 mutex_lock(&ftrace_lock);
1502 /* 1513 /*
@@ -1508,23 +1519,21 @@ static void *t_start(struct seq_file *m, loff_t *pos)
1508 if (*pos > 0) 1519 if (*pos > 0)
1509 return t_hash_start(m, pos); 1520 return t_hash_start(m, pos);
1510 iter->flags |= FTRACE_ITER_PRINTALL; 1521 iter->flags |= FTRACE_ITER_PRINTALL;
1511 (*pos)++;
1512 return iter; 1522 return iter;
1513 } 1523 }
1514 1524
1515 if (iter->flags & FTRACE_ITER_HASH) 1525 if (iter->flags & FTRACE_ITER_HASH)
1516 return t_hash_start(m, pos); 1526 return t_hash_start(m, pos);
1517 1527
1518 if (*pos > 0) { 1528 iter->pg = ftrace_pages_start;
1519 if (iter->idx < 0) 1529 iter->idx = 0;
1520 return p; 1530 for (l = 0; l <= *pos; ) {
1521 (*pos)--; 1531 p = t_next(m, p, &l);
1522 iter->idx--; 1532 if (!p)
1533 break;
1523 } 1534 }
1524 1535
1525 p = t_next(m, p, pos); 1536 if (!p && iter->flags & FTRACE_ITER_FILTER)
1526
1527 if (!p)
1528 return t_hash_start(m, pos); 1537 return t_hash_start(m, pos);
1529 1538
1530 return p; 1539 return p;
@@ -2500,32 +2509,31 @@ int ftrace_graph_count;
2500unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly; 2509unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly;
2501 2510
2502static void * 2511static void *
2503g_next(struct seq_file *m, void *v, loff_t *pos) 2512__g_next(struct seq_file *m, loff_t *pos)
2504{ 2513{
2505 unsigned long *array = m->private; 2514 unsigned long *array = m->private;
2506 int index = *pos;
2507 2515
2508 (*pos)++; 2516 if (*pos >= ftrace_graph_count)
2509
2510 if (index >= ftrace_graph_count)
2511 return NULL; 2517 return NULL;
2518 return &array[*pos];
2519}
2512 2520
2513 return &array[index]; 2521static void *
2522g_next(struct seq_file *m, void *v, loff_t *pos)
2523{
2524 (*pos)++;
2525 return __g_next(m, pos);
2514} 2526}
2515 2527
2516static void *g_start(struct seq_file *m, loff_t *pos) 2528static void *g_start(struct seq_file *m, loff_t *pos)
2517{ 2529{
2518 void *p = NULL;
2519
2520 mutex_lock(&graph_lock); 2530 mutex_lock(&graph_lock);
2521 2531
2522 /* Nothing, tell g_show to print all functions are enabled */ 2532 /* Nothing, tell g_show to print all functions are enabled */
2523 if (!ftrace_graph_count && !*pos) 2533 if (!ftrace_graph_count && !*pos)
2524 return (void *)1; 2534 return (void *)1;
2525 2535
2526 p = g_next(m, p, pos); 2536 return __g_next(m, pos);
2527
2528 return p;
2529} 2537}
2530 2538
2531static void g_stop(struct seq_file *m, void *p) 2539static void g_stop(struct seq_file *m, void *p)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 04dac2638258..bf27bb7a63e2 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -1563,6 +1563,8 @@ rb_reserve_next_event(struct ring_buffer_per_cpu *cpu_buffer,
1563 return NULL; 1563 return NULL;
1564} 1564}
1565 1565
1566#ifdef CONFIG_TRACING
1567
1566#define TRACE_RECURSIVE_DEPTH 16 1568#define TRACE_RECURSIVE_DEPTH 16
1567 1569
1568static int trace_recursive_lock(void) 1570static int trace_recursive_lock(void)
@@ -1593,6 +1595,13 @@ static void trace_recursive_unlock(void)
1593 current->trace_recursion--; 1595 current->trace_recursion--;
1594} 1596}
1595 1597
1598#else
1599
1600#define trace_recursive_lock() (0)
1601#define trace_recursive_unlock() do { } while (0)
1602
1603#endif
1604
1596static DEFINE_PER_CPU(int, rb_need_resched); 1605static DEFINE_PER_CPU(int, rb_need_resched);
1597 1606
1598/** 1607/**
@@ -3104,6 +3113,7 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
3104} 3113}
3105EXPORT_SYMBOL_GPL(ring_buffer_read_page); 3114EXPORT_SYMBOL_GPL(ring_buffer_read_page);
3106 3115
3116#ifdef CONFIG_TRACING
3107static ssize_t 3117static ssize_t
3108rb_simple_read(struct file *filp, char __user *ubuf, 3118rb_simple_read(struct file *filp, char __user *ubuf,
3109 size_t cnt, loff_t *ppos) 3119 size_t cnt, loff_t *ppos)
@@ -3171,6 +3181,7 @@ static __init int rb_init_debugfs(void)
3171} 3181}
3172 3182
3173fs_initcall(rb_init_debugfs); 3183fs_initcall(rb_init_debugfs);
3184#endif
3174 3185
3175#ifdef CONFIG_HOTPLUG_CPU 3186#ifdef CONFIG_HOTPLUG_CPU
3176static int rb_cpu_notify(struct notifier_block *self, 3187static int rb_cpu_notify(struct notifier_block *self,
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 076fa6f0ee48..3aa0a0dfdfa8 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -284,13 +284,12 @@ void trace_wake_up(void)
284static int __init set_buf_size(char *str) 284static int __init set_buf_size(char *str)
285{ 285{
286 unsigned long buf_size; 286 unsigned long buf_size;
287 int ret;
288 287
289 if (!str) 288 if (!str)
290 return 0; 289 return 0;
291 ret = strict_strtoul(str, 0, &buf_size); 290 buf_size = memparse(str, &str);
292 /* nr_entries can not be zero */ 291 /* nr_entries can not be zero */
293 if (ret < 0 || buf_size == 0) 292 if (buf_size == 0)
294 return 0; 293 return 0;
295 trace_buf_size = buf_size; 294 trace_buf_size = buf_size;
296 return 1; 295 return 1;
@@ -2053,25 +2052,23 @@ static int tracing_open(struct inode *inode, struct file *file)
2053static void * 2052static void *
2054t_next(struct seq_file *m, void *v, loff_t *pos) 2053t_next(struct seq_file *m, void *v, loff_t *pos)
2055{ 2054{
2056 struct tracer *t = m->private; 2055 struct tracer *t = v;
2057 2056
2058 (*pos)++; 2057 (*pos)++;
2059 2058
2060 if (t) 2059 if (t)
2061 t = t->next; 2060 t = t->next;
2062 2061
2063 m->private = t;
2064
2065 return t; 2062 return t;
2066} 2063}
2067 2064
2068static void *t_start(struct seq_file *m, loff_t *pos) 2065static void *t_start(struct seq_file *m, loff_t *pos)
2069{ 2066{
2070 struct tracer *t = m->private; 2067 struct tracer *t;
2071 loff_t l = 0; 2068 loff_t l = 0;
2072 2069
2073 mutex_lock(&trace_types_lock); 2070 mutex_lock(&trace_types_lock);
2074 for (; t && l < *pos; t = t_next(m, t, &l)) 2071 for (t = trace_types; t && l < *pos; t = t_next(m, t, &l))
2075 ; 2072 ;
2076 2073
2077 return t; 2074 return t;
@@ -2107,18 +2104,10 @@ static struct seq_operations show_traces_seq_ops = {
2107 2104
2108static int show_traces_open(struct inode *inode, struct file *file) 2105static int show_traces_open(struct inode *inode, struct file *file)
2109{ 2106{
2110 int ret;
2111
2112 if (tracing_disabled) 2107 if (tracing_disabled)
2113 return -ENODEV; 2108 return -ENODEV;
2114 2109
2115 ret = seq_open(file, &show_traces_seq_ops); 2110 return seq_open(file, &show_traces_seq_ops);
2116 if (!ret) {
2117 struct seq_file *m = file->private_data;
2118 m->private = trace_types;
2119 }
2120
2121 return ret;
2122} 2111}
2123 2112
2124static ssize_t 2113static ssize_t
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 6e735d4771f8..3548ae5cc780 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -597,6 +597,7 @@ print_graph_function(struct trace_iterator *iter)
597 597
598extern struct pid *ftrace_pid_trace; 598extern struct pid *ftrace_pid_trace;
599 599
600#ifdef CONFIG_FUNCTION_TRACER
600static inline int ftrace_trace_task(struct task_struct *task) 601static inline int ftrace_trace_task(struct task_struct *task)
601{ 602{
602 if (!ftrace_pid_trace) 603 if (!ftrace_pid_trace)
@@ -604,6 +605,12 @@ static inline int ftrace_trace_task(struct task_struct *task)
604 605
605 return test_tsk_trace_trace(task); 606 return test_tsk_trace_trace(task);
606} 607}
608#else
609static inline int ftrace_trace_task(struct task_struct *task)
610{
611 return 1;
612}
613#endif
607 614
608/* 615/*
609 * trace_iterator_flags is an enumeration that defines bit 616 * trace_iterator_flags is an enumeration that defines bit
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index aa08be69a1b6..53c8fd376a88 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -300,10 +300,18 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
300 300
301static void *t_start(struct seq_file *m, loff_t *pos) 301static void *t_start(struct seq_file *m, loff_t *pos)
302{ 302{
303 struct ftrace_event_call *call = NULL;
304 loff_t l;
305
303 mutex_lock(&event_mutex); 306 mutex_lock(&event_mutex);
304 if (*pos == 0) 307
305 m->private = ftrace_events.next; 308 m->private = ftrace_events.next;
306 return t_next(m, NULL, pos); 309 for (l = 0; l <= *pos; ) {
310 call = t_next(m, NULL, &l);
311 if (!call)
312 break;
313 }
314 return call;
307} 315}
308 316
309static void * 317static void *
@@ -332,10 +340,18 @@ s_next(struct seq_file *m, void *v, loff_t *pos)
332 340
333static void *s_start(struct seq_file *m, loff_t *pos) 341static void *s_start(struct seq_file *m, loff_t *pos)
334{ 342{
343 struct ftrace_event_call *call = NULL;
344 loff_t l;
345
335 mutex_lock(&event_mutex); 346 mutex_lock(&event_mutex);
336 if (*pos == 0) 347
337 m->private = ftrace_events.next; 348 m->private = ftrace_events.next;
338 return s_next(m, NULL, pos); 349 for (l = 0; l <= *pos; ) {
350 call = s_next(m, NULL, &l);
351 if (!call)
352 break;
353 }
354 return call;
339} 355}
340 356
341static int t_show(struct seq_file *m, void *v) 357static int t_show(struct seq_file *m, void *v)
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index 90f134764837..7402144bff21 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -302,8 +302,7 @@ ftrace_trace_onoff_print(struct seq_file *m, unsigned long ip,
302 if (count == -1) 302 if (count == -1)
303 seq_printf(m, ":unlimited\n"); 303 seq_printf(m, ":unlimited\n");
304 else 304 else
305 seq_printf(m, ":count=%ld", count); 305 seq_printf(m, ":count=%ld\n", count);
306 seq_putc(m, '\n');
307 306
308 return 0; 307 return 0;
309} 308}
diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c
index 9bece9687b62..7b6278110827 100644
--- a/kernel/trace/trace_printk.c
+++ b/kernel/trace/trace_printk.c
@@ -155,25 +155,19 @@ int __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap)
155EXPORT_SYMBOL_GPL(__ftrace_vprintk); 155EXPORT_SYMBOL_GPL(__ftrace_vprintk);
156 156
157static void * 157static void *
158t_next(struct seq_file *m, void *v, loff_t *pos) 158t_start(struct seq_file *m, loff_t *pos)
159{ 159{
160 const char **fmt = m->private; 160 const char **fmt = __start___trace_bprintk_fmt + *pos;
161 const char **next = fmt;
162
163 (*pos)++;
164 161
165 if ((unsigned long)fmt >= (unsigned long)__stop___trace_bprintk_fmt) 162 if ((unsigned long)fmt >= (unsigned long)__stop___trace_bprintk_fmt)
166 return NULL; 163 return NULL;
167
168 next = fmt;
169 m->private = ++next;
170
171 return fmt; 164 return fmt;
172} 165}
173 166
174static void *t_start(struct seq_file *m, loff_t *pos) 167static void *t_next(struct seq_file *m, void * v, loff_t *pos)
175{ 168{
176 return t_next(m, NULL, pos); 169 (*pos)++;
170 return t_start(m, pos);
177} 171}
178 172
179static int t_show(struct seq_file *m, void *v) 173static int t_show(struct seq_file *m, void *v)
@@ -224,15 +218,7 @@ static const struct seq_operations show_format_seq_ops = {
224static int 218static int
225ftrace_formats_open(struct inode *inode, struct file *file) 219ftrace_formats_open(struct inode *inode, struct file *file)
226{ 220{
227 int ret; 221 return seq_open(file, &show_format_seq_ops);
228
229 ret = seq_open(file, &show_format_seq_ops);
230 if (!ret) {
231 struct seq_file *m = file->private_data;
232
233 m->private = __start___trace_bprintk_fmt;
234 }
235 return ret;
236} 222}
237 223
238static const struct file_operations ftrace_formats_fops = { 224static const struct file_operations ftrace_formats_fops = {
diff --git a/kernel/trace/trace_stat.c b/kernel/trace/trace_stat.c
index c00643733f4c..e66f5e493342 100644
--- a/kernel/trace/trace_stat.c
+++ b/kernel/trace/trace_stat.c
@@ -199,17 +199,13 @@ static void *stat_seq_start(struct seq_file *s, loff_t *pos)
199 mutex_lock(&session->stat_mutex); 199 mutex_lock(&session->stat_mutex);
200 200
201 /* If we are in the beginning of the file, print the headers */ 201 /* If we are in the beginning of the file, print the headers */
202 if (!*pos && session->ts->stat_headers) { 202 if (!*pos && session->ts->stat_headers)
203 (*pos)++;
204 return SEQ_START_TOKEN; 203 return SEQ_START_TOKEN;
205 }
206 204
207 node = rb_first(&session->stat_root); 205 node = rb_first(&session->stat_root);
208 for (i = 0; node && i < *pos; i++) 206 for (i = 0; node && i < *pos; i++)
209 node = rb_next(node); 207 node = rb_next(node);
210 208
211 (*pos)++;
212
213 return node; 209 return node;
214} 210}
215 211
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 4c32b1a1a06e..12327b2bb785 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -359,6 +359,18 @@ config DEBUG_KMEMLEAK
359 In order to access the kmemleak file, debugfs needs to be 359 In order to access the kmemleak file, debugfs needs to be
360 mounted (usually at /sys/kernel/debug). 360 mounted (usually at /sys/kernel/debug).
361 361
362config DEBUG_KMEMLEAK_EARLY_LOG_SIZE
363 int "Maximum kmemleak early log entries"
364 depends on DEBUG_KMEMLEAK
365 range 200 2000
366 default 400
367 help
368 Kmemleak must track all the memory allocations to avoid
369 reporting false positives. Since memory may be allocated or
370 freed before kmemleak is initialised, an early log buffer is
371 used to store these actions. If kmemleak reports "early log
372 buffer exceeded", please increase this value.
373
362config DEBUG_KMEMLEAK_TEST 374config DEBUG_KMEMLEAK_TEST
363 tristate "Simple test for the kernel memory leak detector" 375 tristate "Simple test for the kernel memory leak detector"
364 depends on DEBUG_KMEMLEAK 376 depends on DEBUG_KMEMLEAK
diff --git a/mm/dmapool.c b/mm/dmapool.c
index b1f0885dda22..3df063706f53 100644
--- a/mm/dmapool.c
+++ b/mm/dmapool.c
@@ -86,10 +86,12 @@ show_pools(struct device *dev, struct device_attribute *attr, char *buf)
86 unsigned pages = 0; 86 unsigned pages = 0;
87 unsigned blocks = 0; 87 unsigned blocks = 0;
88 88
89 spin_lock_irq(&pool->lock);
89 list_for_each_entry(page, &pool->page_list, page_list) { 90 list_for_each_entry(page, &pool->page_list, page_list) {
90 pages++; 91 pages++;
91 blocks += page->in_use; 92 blocks += page->in_use;
92 } 93 }
94 spin_unlock_irq(&pool->lock);
93 95
94 /* per-pool info, no real statistics yet */ 96 /* per-pool info, no real statistics yet */
95 temp = scnprintf(next, size, "%-16s %4u %4Zu %4Zu %2u\n", 97 temp = scnprintf(next, size, "%-16s %4u %4Zu %4Zu %2u\n",
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index c96f2c8700aa..e766e1da09d2 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -48,10 +48,10 @@
48 * scanned. This list is only modified during a scanning episode when the 48 * scanned. This list is only modified during a scanning episode when the
49 * scan_mutex is held. At the end of a scan, the gray_list is always empty. 49 * scan_mutex is held. At the end of a scan, the gray_list is always empty.
50 * Note that the kmemleak_object.use_count is incremented when an object is 50 * Note that the kmemleak_object.use_count is incremented when an object is
51 * added to the gray_list and therefore cannot be freed 51 * added to the gray_list and therefore cannot be freed. This mutex also
52 * - kmemleak_mutex (mutex): prevents multiple users of the "kmemleak" debugfs 52 * prevents multiple users of the "kmemleak" debugfs file together with
53 * file together with modifications to the memory scanning parameters 53 * modifications to the memory scanning parameters including the scan_thread
54 * including the scan_thread pointer 54 * pointer
55 * 55 *
56 * The kmemleak_object structures have a use_count incremented or decremented 56 * The kmemleak_object structures have a use_count incremented or decremented
57 * using the get_object()/put_object() functions. When the use_count becomes 57 * using the get_object()/put_object() functions. When the use_count becomes
@@ -105,7 +105,6 @@
105#define MAX_TRACE 16 /* stack trace length */ 105#define MAX_TRACE 16 /* stack trace length */
106#define REPORTS_NR 50 /* maximum number of reported leaks */ 106#define REPORTS_NR 50 /* maximum number of reported leaks */
107#define MSECS_MIN_AGE 5000 /* minimum object age for reporting */ 107#define MSECS_MIN_AGE 5000 /* minimum object age for reporting */
108#define MSECS_SCAN_YIELD 10 /* CPU yielding period */
109#define SECS_FIRST_SCAN 60 /* delay before the first scan */ 108#define SECS_FIRST_SCAN 60 /* delay before the first scan */
110#define SECS_SCAN_WAIT 600 /* subsequent auto scanning delay */ 109#define SECS_SCAN_WAIT 600 /* subsequent auto scanning delay */
111 110
@@ -186,19 +185,16 @@ static atomic_t kmemleak_error = ATOMIC_INIT(0);
186static unsigned long min_addr = ULONG_MAX; 185static unsigned long min_addr = ULONG_MAX;
187static unsigned long max_addr; 186static unsigned long max_addr;
188 187
189/* used for yielding the CPU to other tasks during scanning */
190static unsigned long next_scan_yield;
191static struct task_struct *scan_thread; 188static struct task_struct *scan_thread;
192static unsigned long jiffies_scan_yield; 189/* used to avoid reporting of recently allocated objects */
193static unsigned long jiffies_min_age; 190static unsigned long jiffies_min_age;
191static unsigned long jiffies_last_scan;
194/* delay between automatic memory scannings */ 192/* delay between automatic memory scannings */
195static signed long jiffies_scan_wait; 193static signed long jiffies_scan_wait;
196/* enables or disables the task stacks scanning */ 194/* enables or disables the task stacks scanning */
197static int kmemleak_stack_scan; 195static int kmemleak_stack_scan = 1;
198/* mutex protecting the memory scanning */ 196/* protects the memory scanning, parameters and debug/kmemleak file access */
199static DEFINE_MUTEX(scan_mutex); 197static DEFINE_MUTEX(scan_mutex);
200/* mutex protecting the access to the /sys/kernel/debug/kmemleak file */
201static DEFINE_MUTEX(kmemleak_mutex);
202 198
203/* number of leaks reported (for limitation purposes) */ 199/* number of leaks reported (for limitation purposes) */
204static int reported_leaks; 200static int reported_leaks;
@@ -235,7 +231,7 @@ struct early_log {
235}; 231};
236 232
237/* early logging buffer and current position */ 233/* early logging buffer and current position */
238static struct early_log early_log[200]; 234static struct early_log early_log[CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE];
239static int crt_early_log; 235static int crt_early_log;
240 236
241static void kmemleak_disable(void); 237static void kmemleak_disable(void);
@@ -279,15 +275,6 @@ static int color_gray(const struct kmemleak_object *object)
279} 275}
280 276
281/* 277/*
282 * Objects are considered referenced if their color is gray and they have not
283 * been deleted.
284 */
285static int referenced_object(struct kmemleak_object *object)
286{
287 return (object->flags & OBJECT_ALLOCATED) && color_gray(object);
288}
289
290/*
291 * Objects are considered unreferenced only if their color is white, they have 278 * Objects are considered unreferenced only if their color is white, they have
292 * not be deleted and have a minimum age to avoid false positives caused by 279 * not be deleted and have a minimum age to avoid false positives caused by
293 * pointers temporarily stored in CPU registers. 280 * pointers temporarily stored in CPU registers.
@@ -295,42 +282,28 @@ static int referenced_object(struct kmemleak_object *object)
295static int unreferenced_object(struct kmemleak_object *object) 282static int unreferenced_object(struct kmemleak_object *object)
296{ 283{
297 return (object->flags & OBJECT_ALLOCATED) && color_white(object) && 284 return (object->flags & OBJECT_ALLOCATED) && color_white(object) &&
298 time_is_before_eq_jiffies(object->jiffies + jiffies_min_age); 285 time_before_eq(object->jiffies + jiffies_min_age,
286 jiffies_last_scan);
299} 287}
300 288
301/* 289/*
302 * Printing of the (un)referenced objects information, either to the seq file 290 * Printing of the unreferenced objects information to the seq file. The
303 * or to the kernel log. The print_referenced/print_unreferenced functions 291 * print_unreferenced function must be called with the object->lock held.
304 * must be called with the object->lock held.
305 */ 292 */
306#define print_helper(seq, x...) do { \
307 struct seq_file *s = (seq); \
308 if (s) \
309 seq_printf(s, x); \
310 else \
311 pr_info(x); \
312} while (0)
313
314static void print_referenced(struct kmemleak_object *object)
315{
316 pr_info("referenced object 0x%08lx (size %zu)\n",
317 object->pointer, object->size);
318}
319
320static void print_unreferenced(struct seq_file *seq, 293static void print_unreferenced(struct seq_file *seq,
321 struct kmemleak_object *object) 294 struct kmemleak_object *object)
322{ 295{
323 int i; 296 int i;
324 297
325 print_helper(seq, "unreferenced object 0x%08lx (size %zu):\n", 298 seq_printf(seq, "unreferenced object 0x%08lx (size %zu):\n",
326 object->pointer, object->size); 299 object->pointer, object->size);
327 print_helper(seq, " comm \"%s\", pid %d, jiffies %lu\n", 300 seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu\n",
328 object->comm, object->pid, object->jiffies); 301 object->comm, object->pid, object->jiffies);
329 print_helper(seq, " backtrace:\n"); 302 seq_printf(seq, " backtrace:\n");
330 303
331 for (i = 0; i < object->trace_len; i++) { 304 for (i = 0; i < object->trace_len; i++) {
332 void *ptr = (void *)object->trace[i]; 305 void *ptr = (void *)object->trace[i];
333 print_helper(seq, " [<%p>] %pS\n", ptr, ptr); 306 seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
334 } 307 }
335} 308}
336 309
@@ -554,8 +527,10 @@ static void delete_object(unsigned long ptr)
554 write_lock_irqsave(&kmemleak_lock, flags); 527 write_lock_irqsave(&kmemleak_lock, flags);
555 object = lookup_object(ptr, 0); 528 object = lookup_object(ptr, 0);
556 if (!object) { 529 if (!object) {
530#ifdef DEBUG
557 kmemleak_warn("Freeing unknown object at 0x%08lx\n", 531 kmemleak_warn("Freeing unknown object at 0x%08lx\n",
558 ptr); 532 ptr);
533#endif
559 write_unlock_irqrestore(&kmemleak_lock, flags); 534 write_unlock_irqrestore(&kmemleak_lock, flags);
560 return; 535 return;
561 } 536 }
@@ -571,8 +546,6 @@ static void delete_object(unsigned long ptr)
571 * cannot be freed when it is being scanned. 546 * cannot be freed when it is being scanned.
572 */ 547 */
573 spin_lock_irqsave(&object->lock, flags); 548 spin_lock_irqsave(&object->lock, flags);
574 if (object->flags & OBJECT_REPORTED)
575 print_referenced(object);
576 object->flags &= ~OBJECT_ALLOCATED; 549 object->flags &= ~OBJECT_ALLOCATED;
577 spin_unlock_irqrestore(&object->lock, flags); 550 spin_unlock_irqrestore(&object->lock, flags);
578 put_object(object); 551 put_object(object);
@@ -696,7 +669,8 @@ static void log_early(int op_type, const void *ptr, size_t size,
696 struct early_log *log; 669 struct early_log *log;
697 670
698 if (crt_early_log >= ARRAY_SIZE(early_log)) { 671 if (crt_early_log >= ARRAY_SIZE(early_log)) {
699 kmemleak_stop("Early log buffer exceeded\n"); 672 pr_warning("Early log buffer exceeded\n");
673 kmemleak_disable();
700 return; 674 return;
701 } 675 }
702 676
@@ -808,21 +782,6 @@ void kmemleak_no_scan(const void *ptr)
808EXPORT_SYMBOL(kmemleak_no_scan); 782EXPORT_SYMBOL(kmemleak_no_scan);
809 783
810/* 784/*
811 * Yield the CPU so that other tasks get a chance to run. The yielding is
812 * rate-limited to avoid excessive number of calls to the schedule() function
813 * during memory scanning.
814 */
815static void scan_yield(void)
816{
817 might_sleep();
818
819 if (time_is_before_eq_jiffies(next_scan_yield)) {
820 schedule();
821 next_scan_yield = jiffies + jiffies_scan_yield;
822 }
823}
824
825/*
826 * Memory scanning is a long process and it needs to be interruptable. This 785 * Memory scanning is a long process and it needs to be interruptable. This
827 * function checks whether such interrupt condition occured. 786 * function checks whether such interrupt condition occured.
828 */ 787 */
@@ -862,15 +821,6 @@ static void scan_block(void *_start, void *_end,
862 if (scan_should_stop()) 821 if (scan_should_stop())
863 break; 822 break;
864 823
865 /*
866 * When scanning a memory block with a corresponding
867 * kmemleak_object, the CPU yielding is handled in the calling
868 * code since it holds the object->lock to avoid the block
869 * freeing.
870 */
871 if (!scanned)
872 scan_yield();
873
874 object = find_and_get_object(pointer, 1); 824 object = find_and_get_object(pointer, 1);
875 if (!object) 825 if (!object)
876 continue; 826 continue;
@@ -952,6 +902,9 @@ static void kmemleak_scan(void)
952 struct kmemleak_object *object, *tmp; 902 struct kmemleak_object *object, *tmp;
953 struct task_struct *task; 903 struct task_struct *task;
954 int i; 904 int i;
905 int new_leaks = 0;
906
907 jiffies_last_scan = jiffies;
955 908
956 /* prepare the kmemleak_object's */ 909 /* prepare the kmemleak_object's */
957 rcu_read_lock(); 910 rcu_read_lock();
@@ -1033,7 +986,7 @@ static void kmemleak_scan(void)
1033 */ 986 */
1034 object = list_entry(gray_list.next, typeof(*object), gray_list); 987 object = list_entry(gray_list.next, typeof(*object), gray_list);
1035 while (&object->gray_list != &gray_list) { 988 while (&object->gray_list != &gray_list) {
1036 scan_yield(); 989 cond_resched();
1037 990
1038 /* may add new objects to the list */ 991 /* may add new objects to the list */
1039 if (!scan_should_stop()) 992 if (!scan_should_stop())
@@ -1049,6 +1002,32 @@ static void kmemleak_scan(void)
1049 object = tmp; 1002 object = tmp;
1050 } 1003 }
1051 WARN_ON(!list_empty(&gray_list)); 1004 WARN_ON(!list_empty(&gray_list));
1005
1006 /*
1007 * If scanning was stopped do not report any new unreferenced objects.
1008 */
1009 if (scan_should_stop())
1010 return;
1011
1012 /*
1013 * Scanning result reporting.
1014 */
1015 rcu_read_lock();
1016 list_for_each_entry_rcu(object, &object_list, object_list) {
1017 spin_lock_irqsave(&object->lock, flags);
1018 if (unreferenced_object(object) &&
1019 !(object->flags & OBJECT_REPORTED)) {
1020 object->flags |= OBJECT_REPORTED;
1021 new_leaks++;
1022 }
1023 spin_unlock_irqrestore(&object->lock, flags);
1024 }
1025 rcu_read_unlock();
1026
1027 if (new_leaks)
1028 pr_info("%d new suspected memory leaks (see "
1029 "/sys/kernel/debug/kmemleak)\n", new_leaks);
1030
1052} 1031}
1053 1032
1054/* 1033/*
@@ -1070,36 +1049,12 @@ static int kmemleak_scan_thread(void *arg)
1070 } 1049 }
1071 1050
1072 while (!kthread_should_stop()) { 1051 while (!kthread_should_stop()) {
1073 struct kmemleak_object *object;
1074 signed long timeout = jiffies_scan_wait; 1052 signed long timeout = jiffies_scan_wait;
1075 1053
1076 mutex_lock(&scan_mutex); 1054 mutex_lock(&scan_mutex);
1077
1078 kmemleak_scan(); 1055 kmemleak_scan();
1079 reported_leaks = 0;
1080
1081 rcu_read_lock();
1082 list_for_each_entry_rcu(object, &object_list, object_list) {
1083 unsigned long flags;
1084
1085 if (reported_leaks >= REPORTS_NR)
1086 break;
1087 spin_lock_irqsave(&object->lock, flags);
1088 if (!(object->flags & OBJECT_REPORTED) &&
1089 unreferenced_object(object)) {
1090 print_unreferenced(NULL, object);
1091 object->flags |= OBJECT_REPORTED;
1092 reported_leaks++;
1093 } else if ((object->flags & OBJECT_REPORTED) &&
1094 referenced_object(object)) {
1095 print_referenced(object);
1096 object->flags &= ~OBJECT_REPORTED;
1097 }
1098 spin_unlock_irqrestore(&object->lock, flags);
1099 }
1100 rcu_read_unlock();
1101
1102 mutex_unlock(&scan_mutex); 1056 mutex_unlock(&scan_mutex);
1057
1103 /* wait before the next scan */ 1058 /* wait before the next scan */
1104 while (timeout && !kthread_should_stop()) 1059 while (timeout && !kthread_should_stop())
1105 timeout = schedule_timeout_interruptible(timeout); 1060 timeout = schedule_timeout_interruptible(timeout);
@@ -1112,7 +1067,7 @@ static int kmemleak_scan_thread(void *arg)
1112 1067
1113/* 1068/*
1114 * Start the automatic memory scanning thread. This function must be called 1069 * Start the automatic memory scanning thread. This function must be called
1115 * with the kmemleak_mutex held. 1070 * with the scan_mutex held.
1116 */ 1071 */
1117void start_scan_thread(void) 1072void start_scan_thread(void)
1118{ 1073{
@@ -1127,7 +1082,7 @@ void start_scan_thread(void)
1127 1082
1128/* 1083/*
1129 * Stop the automatic memory scanning thread. This function must be called 1084 * Stop the automatic memory scanning thread. This function must be called
1130 * with the kmemleak_mutex held. 1085 * with the scan_mutex held.
1131 */ 1086 */
1132void stop_scan_thread(void) 1087void stop_scan_thread(void)
1133{ 1088{
@@ -1147,10 +1102,8 @@ static void *kmemleak_seq_start(struct seq_file *seq, loff_t *pos)
1147 struct kmemleak_object *object; 1102 struct kmemleak_object *object;
1148 loff_t n = *pos; 1103 loff_t n = *pos;
1149 1104
1150 if (!n) { 1105 if (!n)
1151 kmemleak_scan();
1152 reported_leaks = 0; 1106 reported_leaks = 0;
1153 }
1154 if (reported_leaks >= REPORTS_NR) 1107 if (reported_leaks >= REPORTS_NR)
1155 return NULL; 1108 return NULL;
1156 1109
@@ -1211,11 +1164,10 @@ static int kmemleak_seq_show(struct seq_file *seq, void *v)
1211 unsigned long flags; 1164 unsigned long flags;
1212 1165
1213 spin_lock_irqsave(&object->lock, flags); 1166 spin_lock_irqsave(&object->lock, flags);
1214 if (!unreferenced_object(object)) 1167 if ((object->flags & OBJECT_REPORTED) && unreferenced_object(object)) {
1215 goto out; 1168 print_unreferenced(seq, object);
1216 print_unreferenced(seq, object); 1169 reported_leaks++;
1217 reported_leaks++; 1170 }
1218out:
1219 spin_unlock_irqrestore(&object->lock, flags); 1171 spin_unlock_irqrestore(&object->lock, flags);
1220 return 0; 1172 return 0;
1221} 1173}
@@ -1234,13 +1186,10 @@ static int kmemleak_open(struct inode *inode, struct file *file)
1234 if (!atomic_read(&kmemleak_enabled)) 1186 if (!atomic_read(&kmemleak_enabled))
1235 return -EBUSY; 1187 return -EBUSY;
1236 1188
1237 ret = mutex_lock_interruptible(&kmemleak_mutex); 1189 ret = mutex_lock_interruptible(&scan_mutex);
1238 if (ret < 0) 1190 if (ret < 0)
1239 goto out; 1191 goto out;
1240 if (file->f_mode & FMODE_READ) { 1192 if (file->f_mode & FMODE_READ) {
1241 ret = mutex_lock_interruptible(&scan_mutex);
1242 if (ret < 0)
1243 goto kmemleak_unlock;
1244 ret = seq_open(file, &kmemleak_seq_ops); 1193 ret = seq_open(file, &kmemleak_seq_ops);
1245 if (ret < 0) 1194 if (ret < 0)
1246 goto scan_unlock; 1195 goto scan_unlock;
@@ -1249,8 +1198,6 @@ static int kmemleak_open(struct inode *inode, struct file *file)
1249 1198
1250scan_unlock: 1199scan_unlock:
1251 mutex_unlock(&scan_mutex); 1200 mutex_unlock(&scan_mutex);
1252kmemleak_unlock:
1253 mutex_unlock(&kmemleak_mutex);
1254out: 1201out:
1255 return ret; 1202 return ret;
1256} 1203}
@@ -1259,11 +1206,9 @@ static int kmemleak_release(struct inode *inode, struct file *file)
1259{ 1206{
1260 int ret = 0; 1207 int ret = 0;
1261 1208
1262 if (file->f_mode & FMODE_READ) { 1209 if (file->f_mode & FMODE_READ)
1263 seq_release(inode, file); 1210 seq_release(inode, file);
1264 mutex_unlock(&scan_mutex); 1211 mutex_unlock(&scan_mutex);
1265 }
1266 mutex_unlock(&kmemleak_mutex);
1267 1212
1268 return ret; 1213 return ret;
1269} 1214}
@@ -1278,6 +1223,7 @@ static int kmemleak_release(struct inode *inode, struct file *file)
1278 * scan=off - stop the automatic memory scanning thread 1223 * scan=off - stop the automatic memory scanning thread
1279 * scan=... - set the automatic memory scanning period in seconds (0 to 1224 * scan=... - set the automatic memory scanning period in seconds (0 to
1280 * disable it) 1225 * disable it)
1226 * scan - trigger a memory scan
1281 */ 1227 */
1282static ssize_t kmemleak_write(struct file *file, const char __user *user_buf, 1228static ssize_t kmemleak_write(struct file *file, const char __user *user_buf,
1283 size_t size, loff_t *ppos) 1229 size_t size, loff_t *ppos)
@@ -1315,7 +1261,9 @@ static ssize_t kmemleak_write(struct file *file, const char __user *user_buf,
1315 jiffies_scan_wait = msecs_to_jiffies(secs * 1000); 1261 jiffies_scan_wait = msecs_to_jiffies(secs * 1000);
1316 start_scan_thread(); 1262 start_scan_thread();
1317 } 1263 }
1318 } else 1264 } else if (strncmp(buf, "scan", 4) == 0)
1265 kmemleak_scan();
1266 else
1319 return -EINVAL; 1267 return -EINVAL;
1320 1268
1321 /* ignore the rest of the buffer, only one command at a time */ 1269 /* ignore the rest of the buffer, only one command at a time */
@@ -1340,11 +1288,9 @@ static int kmemleak_cleanup_thread(void *arg)
1340{ 1288{
1341 struct kmemleak_object *object; 1289 struct kmemleak_object *object;
1342 1290
1343 mutex_lock(&kmemleak_mutex); 1291 mutex_lock(&scan_mutex);
1344 stop_scan_thread(); 1292 stop_scan_thread();
1345 mutex_unlock(&kmemleak_mutex);
1346 1293
1347 mutex_lock(&scan_mutex);
1348 rcu_read_lock(); 1294 rcu_read_lock();
1349 list_for_each_entry_rcu(object, &object_list, object_list) 1295 list_for_each_entry_rcu(object, &object_list, object_list)
1350 delete_object(object->pointer); 1296 delete_object(object->pointer);
@@ -1411,7 +1357,6 @@ void __init kmemleak_init(void)
1411 int i; 1357 int i;
1412 unsigned long flags; 1358 unsigned long flags;
1413 1359
1414 jiffies_scan_yield = msecs_to_jiffies(MSECS_SCAN_YIELD);
1415 jiffies_min_age = msecs_to_jiffies(MSECS_MIN_AGE); 1360 jiffies_min_age = msecs_to_jiffies(MSECS_MIN_AGE);
1416 jiffies_scan_wait = msecs_to_jiffies(SECS_SCAN_WAIT * 1000); 1361 jiffies_scan_wait = msecs_to_jiffies(SECS_SCAN_WAIT * 1000);
1417 1362
@@ -1486,9 +1431,9 @@ static int __init kmemleak_late_init(void)
1486 &kmemleak_fops); 1431 &kmemleak_fops);
1487 if (!dentry) 1432 if (!dentry)
1488 pr_warning("Failed to create the debugfs kmemleak file\n"); 1433 pr_warning("Failed to create the debugfs kmemleak file\n");
1489 mutex_lock(&kmemleak_mutex); 1434 mutex_lock(&scan_mutex);
1490 start_scan_thread(); 1435 start_scan_thread();
1491 mutex_unlock(&kmemleak_mutex); 1436 mutex_unlock(&scan_mutex);
1492 1437
1493 pr_info("Kernel memory leak detector initialized\n"); 1438 pr_info("Kernel memory leak detector initialized\n");
1494 1439
diff --git a/mm/memory.c b/mm/memory.c
index f46ac18ba231..65216194eb8d 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1207,8 +1207,8 @@ static inline int use_zero_page(struct vm_area_struct *vma)
1207 1207
1208 1208
1209int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 1209int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1210 unsigned long start, int len, int flags, 1210 unsigned long start, int nr_pages, int flags,
1211 struct page **pages, struct vm_area_struct **vmas) 1211 struct page **pages, struct vm_area_struct **vmas)
1212{ 1212{
1213 int i; 1213 int i;
1214 unsigned int vm_flags = 0; 1214 unsigned int vm_flags = 0;
@@ -1217,7 +1217,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1217 int ignore = !!(flags & GUP_FLAGS_IGNORE_VMA_PERMISSIONS); 1217 int ignore = !!(flags & GUP_FLAGS_IGNORE_VMA_PERMISSIONS);
1218 int ignore_sigkill = !!(flags & GUP_FLAGS_IGNORE_SIGKILL); 1218 int ignore_sigkill = !!(flags & GUP_FLAGS_IGNORE_SIGKILL);
1219 1219
1220 if (len <= 0) 1220 if (nr_pages <= 0)
1221 return 0; 1221 return 0;
1222 /* 1222 /*
1223 * Require read or write permissions. 1223 * Require read or write permissions.
@@ -1269,7 +1269,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1269 vmas[i] = gate_vma; 1269 vmas[i] = gate_vma;
1270 i++; 1270 i++;
1271 start += PAGE_SIZE; 1271 start += PAGE_SIZE;
1272 len--; 1272 nr_pages--;
1273 continue; 1273 continue;
1274 } 1274 }
1275 1275
@@ -1280,7 +1280,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1280 1280
1281 if (is_vm_hugetlb_page(vma)) { 1281 if (is_vm_hugetlb_page(vma)) {
1282 i = follow_hugetlb_page(mm, vma, pages, vmas, 1282 i = follow_hugetlb_page(mm, vma, pages, vmas,
1283 &start, &len, i, write); 1283 &start, &nr_pages, i, write);
1284 continue; 1284 continue;
1285 } 1285 }
1286 1286
@@ -1357,9 +1357,9 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1357 vmas[i] = vma; 1357 vmas[i] = vma;
1358 i++; 1358 i++;
1359 start += PAGE_SIZE; 1359 start += PAGE_SIZE;
1360 len--; 1360 nr_pages--;
1361 } while (len && start < vma->vm_end); 1361 } while (nr_pages && start < vma->vm_end);
1362 } while (len); 1362 } while (nr_pages);
1363 return i; 1363 return i;
1364} 1364}
1365 1365
@@ -1368,7 +1368,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1368 * @tsk: task_struct of target task 1368 * @tsk: task_struct of target task
1369 * @mm: mm_struct of target mm 1369 * @mm: mm_struct of target mm
1370 * @start: starting user address 1370 * @start: starting user address
1371 * @len: number of pages from start to pin 1371 * @nr_pages: number of pages from start to pin
1372 * @write: whether pages will be written to by the caller 1372 * @write: whether pages will be written to by the caller
1373 * @force: whether to force write access even if user mapping is 1373 * @force: whether to force write access even if user mapping is
1374 * readonly. This will result in the page being COWed even 1374 * readonly. This will result in the page being COWed even
@@ -1380,7 +1380,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1380 * Or NULL if the caller does not require them. 1380 * Or NULL if the caller does not require them.
1381 * 1381 *
1382 * Returns number of pages pinned. This may be fewer than the number 1382 * Returns number of pages pinned. This may be fewer than the number
1383 * requested. If len is 0 or negative, returns 0. If no pages 1383 * requested. If nr_pages is 0 or negative, returns 0. If no pages
1384 * were pinned, returns -errno. Each page returned must be released 1384 * were pinned, returns -errno. Each page returned must be released
1385 * with a put_page() call when it is finished with. vmas will only 1385 * with a put_page() call when it is finished with. vmas will only
1386 * remain valid while mmap_sem is held. 1386 * remain valid while mmap_sem is held.
@@ -1414,7 +1414,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1414 * See also get_user_pages_fast, for performance critical applications. 1414 * See also get_user_pages_fast, for performance critical applications.
1415 */ 1415 */
1416int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 1416int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1417 unsigned long start, int len, int write, int force, 1417 unsigned long start, int nr_pages, int write, int force,
1418 struct page **pages, struct vm_area_struct **vmas) 1418 struct page **pages, struct vm_area_struct **vmas)
1419{ 1419{
1420 int flags = 0; 1420 int flags = 0;
@@ -1424,9 +1424,7 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
1424 if (force) 1424 if (force)
1425 flags |= GUP_FLAGS_FORCE; 1425 flags |= GUP_FLAGS_FORCE;
1426 1426
1427 return __get_user_pages(tsk, mm, 1427 return __get_user_pages(tsk, mm, start, nr_pages, flags, pages, vmas);
1428 start, len, flags,
1429 pages, vmas);
1430} 1428}
1431 1429
1432EXPORT_SYMBOL(get_user_pages); 1430EXPORT_SYMBOL(get_user_pages);
diff --git a/mm/nommu.c b/mm/nommu.c
index 2fd2ad5da98e..53cab10fece4 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -173,8 +173,8 @@ unsigned int kobjsize(const void *objp)
173} 173}
174 174
175int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 175int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
176 unsigned long start, int len, int flags, 176 unsigned long start, int nr_pages, int flags,
177 struct page **pages, struct vm_area_struct **vmas) 177 struct page **pages, struct vm_area_struct **vmas)
178{ 178{
179 struct vm_area_struct *vma; 179 struct vm_area_struct *vma;
180 unsigned long vm_flags; 180 unsigned long vm_flags;
@@ -189,7 +189,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
189 vm_flags = write ? (VM_WRITE | VM_MAYWRITE) : (VM_READ | VM_MAYREAD); 189 vm_flags = write ? (VM_WRITE | VM_MAYWRITE) : (VM_READ | VM_MAYREAD);
190 vm_flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE); 190 vm_flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
191 191
192 for (i = 0; i < len; i++) { 192 for (i = 0; i < nr_pages; i++) {
193 vma = find_vma(mm, start); 193 vma = find_vma(mm, start);
194 if (!vma) 194 if (!vma)
195 goto finish_or_fault; 195 goto finish_or_fault;
@@ -224,7 +224,7 @@ finish_or_fault:
224 * - don't permit access to VMAs that don't support it, such as I/O mappings 224 * - don't permit access to VMAs that don't support it, such as I/O mappings
225 */ 225 */
226int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, 226int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
227 unsigned long start, int len, int write, int force, 227 unsigned long start, int nr_pages, int write, int force,
228 struct page **pages, struct vm_area_struct **vmas) 228 struct page **pages, struct vm_area_struct **vmas)
229{ 229{
230 int flags = 0; 230 int flags = 0;
@@ -234,12 +234,31 @@ int get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
234 if (force) 234 if (force)
235 flags |= GUP_FLAGS_FORCE; 235 flags |= GUP_FLAGS_FORCE;
236 236
237 return __get_user_pages(tsk, mm, 237 return __get_user_pages(tsk, mm, start, nr_pages, flags, pages, vmas);
238 start, len, flags,
239 pages, vmas);
240} 238}
241EXPORT_SYMBOL(get_user_pages); 239EXPORT_SYMBOL(get_user_pages);
242 240
241/**
242 * follow_pfn - look up PFN at a user virtual address
243 * @vma: memory mapping
244 * @address: user virtual address
245 * @pfn: location to store found PFN
246 *
247 * Only IO mappings and raw PFN mappings are allowed.
248 *
249 * Returns zero and the pfn at @pfn on success, -ve otherwise.
250 */
251int follow_pfn(struct vm_area_struct *vma, unsigned long address,
252 unsigned long *pfn)
253{
254 if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
255 return -EINVAL;
256
257 *pfn = address >> PAGE_SHIFT;
258 return 0;
259}
260EXPORT_SYMBOL(follow_pfn);
261
243DEFINE_RWLOCK(vmlist_lock); 262DEFINE_RWLOCK(vmlist_lock);
244struct vm_struct *vmlist; 263struct vm_struct *vmlist;
245 264
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 7b0dcea4935b..7687879253b9 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -541,8 +541,11 @@ static void balance_dirty_pages(struct address_space *mapping)
541 * filesystems (i.e. NFS) in which data may have been 541 * filesystems (i.e. NFS) in which data may have been
542 * written to the server's write cache, but has not yet 542 * written to the server's write cache, but has not yet
543 * been flushed to permanent storage. 543 * been flushed to permanent storage.
544 * Only move pages to writeback if this bdi is over its
545 * threshold otherwise wait until the disk writes catch
546 * up.
544 */ 547 */
545 if (bdi_nr_reclaimable) { 548 if (bdi_nr_reclaimable > bdi_thresh) {
546 writeback_inodes(&wbc); 549 writeback_inodes(&wbc);
547 pages_written += write_chunk - wbc.nr_to_write; 550 pages_written += write_chunk - wbc.nr_to_write;
548 get_dirty_limits(&background_thresh, &dirty_thresh, 551 get_dirty_limits(&background_thresh, &dirty_thresh,
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 5d714f8fb303..e0f2cdf9d8b1 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4032,6 +4032,8 @@ static void __init find_zone_movable_pfns_for_nodes(unsigned long *movable_pfn)
4032 int i, nid; 4032 int i, nid;
4033 unsigned long usable_startpfn; 4033 unsigned long usable_startpfn;
4034 unsigned long kernelcore_node, kernelcore_remaining; 4034 unsigned long kernelcore_node, kernelcore_remaining;
4035 /* save the state before borrow the nodemask */
4036 nodemask_t saved_node_state = node_states[N_HIGH_MEMORY];
4035 unsigned long totalpages = early_calculate_totalpages(); 4037 unsigned long totalpages = early_calculate_totalpages();
4036 int usable_nodes = nodes_weight(node_states[N_HIGH_MEMORY]); 4038 int usable_nodes = nodes_weight(node_states[N_HIGH_MEMORY]);
4037 4039
@@ -4059,7 +4061,7 @@ static void __init find_zone_movable_pfns_for_nodes(unsigned long *movable_pfn)
4059 4061
4060 /* If kernelcore was not specified, there is no ZONE_MOVABLE */ 4062 /* If kernelcore was not specified, there is no ZONE_MOVABLE */
4061 if (!required_kernelcore) 4063 if (!required_kernelcore)
4062 return; 4064 goto out;
4063 4065
4064 /* usable_startpfn is the lowest possible pfn ZONE_MOVABLE can be at */ 4066 /* usable_startpfn is the lowest possible pfn ZONE_MOVABLE can be at */
4065 find_usable_zone_for_movable(); 4067 find_usable_zone_for_movable();
@@ -4158,6 +4160,10 @@ restart:
4158 for (nid = 0; nid < MAX_NUMNODES; nid++) 4160 for (nid = 0; nid < MAX_NUMNODES; nid++)
4159 zone_movable_pfn[nid] = 4161 zone_movable_pfn[nid] =
4160 roundup(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES); 4162 roundup(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
4163
4164out:
4165 /* restore the node_state */
4166 node_states[N_HIGH_MEMORY] = saved_node_state;
4161} 4167}
4162 4168
4163/* Any regular memory on that node ? */ 4169/* Any regular memory on that node ? */
@@ -4242,11 +4248,6 @@ void __init free_area_init_nodes(unsigned long *max_zone_pfn)
4242 early_node_map[i].start_pfn, 4248 early_node_map[i].start_pfn,
4243 early_node_map[i].end_pfn); 4249 early_node_map[i].end_pfn);
4244 4250
4245 /*
4246 * find_zone_movable_pfns_for_nodes/early_calculate_totalpages init
4247 * that node_mask, clear it at first
4248 */
4249 nodes_clear(node_states[N_HIGH_MEMORY]);
4250 /* Initialise every node */ 4251 /* Initialise every node */
4251 mminit_verify_pageflags_layout(); 4252 mminit_verify_pageflags_layout();
4252 setup_nr_node_ids(); 4253 setup_nr_node_ids();
diff --git a/mm/percpu.c b/mm/percpu.c
index c0b2c1a76e81..b70f2acd8853 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -549,14 +549,14 @@ static void pcpu_free_area(struct pcpu_chunk *chunk, int freeme)
549 * @chunk: chunk of interest 549 * @chunk: chunk of interest
550 * @page_start: page index of the first page to unmap 550 * @page_start: page index of the first page to unmap
551 * @page_end: page index of the last page to unmap + 1 551 * @page_end: page index of the last page to unmap + 1
552 * @flush: whether to flush cache and tlb or not 552 * @flush_tlb: whether to flush tlb or not
553 * 553 *
554 * For each cpu, unmap pages [@page_start,@page_end) out of @chunk. 554 * For each cpu, unmap pages [@page_start,@page_end) out of @chunk.
555 * If @flush is true, vcache is flushed before unmapping and tlb 555 * If @flush is true, vcache is flushed before unmapping and tlb
556 * after. 556 * after.
557 */ 557 */
558static void pcpu_unmap(struct pcpu_chunk *chunk, int page_start, int page_end, 558static void pcpu_unmap(struct pcpu_chunk *chunk, int page_start, int page_end,
559 bool flush) 559 bool flush_tlb)
560{ 560{
561 unsigned int last = num_possible_cpus() - 1; 561 unsigned int last = num_possible_cpus() - 1;
562 unsigned int cpu; 562 unsigned int cpu;
@@ -569,9 +569,8 @@ static void pcpu_unmap(struct pcpu_chunk *chunk, int page_start, int page_end,
569 * the whole region at once rather than doing it for each cpu. 569 * the whole region at once rather than doing it for each cpu.
570 * This could be an overkill but is more scalable. 570 * This could be an overkill but is more scalable.
571 */ 571 */
572 if (flush) 572 flush_cache_vunmap(pcpu_chunk_addr(chunk, 0, page_start),
573 flush_cache_vunmap(pcpu_chunk_addr(chunk, 0, page_start), 573 pcpu_chunk_addr(chunk, last, page_end));
574 pcpu_chunk_addr(chunk, last, page_end));
575 574
576 for_each_possible_cpu(cpu) 575 for_each_possible_cpu(cpu)
577 unmap_kernel_range_noflush( 576 unmap_kernel_range_noflush(
@@ -579,7 +578,7 @@ static void pcpu_unmap(struct pcpu_chunk *chunk, int page_start, int page_end,
579 (page_end - page_start) << PAGE_SHIFT); 578 (page_end - page_start) << PAGE_SHIFT);
580 579
581 /* ditto as flush_cache_vunmap() */ 580 /* ditto as flush_cache_vunmap() */
582 if (flush) 581 if (flush_tlb)
583 flush_tlb_kernel_range(pcpu_chunk_addr(chunk, 0, page_start), 582 flush_tlb_kernel_range(pcpu_chunk_addr(chunk, 0, page_start),
584 pcpu_chunk_addr(chunk, last, page_end)); 583 pcpu_chunk_addr(chunk, last, page_end));
585} 584}
@@ -1234,6 +1233,7 @@ static struct page * __init pcpue_get_page(unsigned int cpu, int pageno)
1234ssize_t __init pcpu_embed_first_chunk(size_t static_size, size_t reserved_size, 1233ssize_t __init pcpu_embed_first_chunk(size_t static_size, size_t reserved_size,
1235 ssize_t dyn_size, ssize_t unit_size) 1234 ssize_t dyn_size, ssize_t unit_size)
1236{ 1235{
1236 size_t chunk_size;
1237 unsigned int cpu; 1237 unsigned int cpu;
1238 1238
1239 /* determine parameters and allocate */ 1239 /* determine parameters and allocate */
@@ -1248,11 +1248,15 @@ ssize_t __init pcpu_embed_first_chunk(size_t static_size, size_t reserved_size,
1248 } else 1248 } else
1249 pcpue_unit_size = max_t(size_t, pcpue_size, PCPU_MIN_UNIT_SIZE); 1249 pcpue_unit_size = max_t(size_t, pcpue_size, PCPU_MIN_UNIT_SIZE);
1250 1250
1251 pcpue_ptr = __alloc_bootmem_nopanic( 1251 chunk_size = pcpue_unit_size * num_possible_cpus();
1252 num_possible_cpus() * pcpue_unit_size, 1252
1253 PAGE_SIZE, __pa(MAX_DMA_ADDRESS)); 1253 pcpue_ptr = __alloc_bootmem_nopanic(chunk_size, PAGE_SIZE,
1254 if (!pcpue_ptr) 1254 __pa(MAX_DMA_ADDRESS));
1255 if (!pcpue_ptr) {
1256 pr_warning("PERCPU: failed to allocate %zu bytes for "
1257 "embedding\n", chunk_size);
1255 return -ENOMEM; 1258 return -ENOMEM;
1259 }
1256 1260
1257 /* return the leftover and copy */ 1261 /* return the leftover and copy */
1258 for_each_possible_cpu(cpu) { 1262 for_each_possible_cpu(cpu) {
diff --git a/net/Kconfig b/net/Kconfig
index 7051b9710675..041c35edb763 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -23,6 +23,26 @@ menuconfig NET
23 23
24if NET 24if NET
25 25
26config WANT_COMPAT_NETLINK_MESSAGES
27 bool
28 help
29 This option can be selected by other options that need compat
30 netlink messages.
31
32config COMPAT_NETLINK_MESSAGES
33 def_bool y
34 depends on COMPAT
35 depends on WIRELESS_EXT || WANT_COMPAT_NETLINK_MESSAGES
36 help
37 This option makes it possible to send different netlink messages
38 to tasks depending on whether the task is a compat task or not. To
39 achieve this, you need to set skb_shinfo(skb)->frag_list to the
40 compat skb before sending the skb, the netlink code will sort out
41 which message to actually pass to the task.
42
43 Newly written code should NEVER need this option but do
44 compat-independent messages instead!
45
26menu "Networking options" 46menu "Networking options"
27 47
28source "net/packet/Kconfig" 48source "net/packet/Kconfig"
diff --git a/net/Makefile b/net/Makefile
index ba324aefda73..1542e7268a7b 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -24,7 +24,6 @@ obj-y += ipv6/
24endif 24endif
25obj-$(CONFIG_PACKET) += packet/ 25obj-$(CONFIG_PACKET) += packet/
26obj-$(CONFIG_NET_KEY) += key/ 26obj-$(CONFIG_NET_KEY) += key/
27obj-$(CONFIG_NET_SCHED) += sched/
28obj-$(CONFIG_BRIDGE) += bridge/ 27obj-$(CONFIG_BRIDGE) += bridge/
29obj-$(CONFIG_NET_DSA) += dsa/ 28obj-$(CONFIG_NET_DSA) += dsa/
30obj-$(CONFIG_IPX) += ipx/ 29obj-$(CONFIG_IPX) += ipx/
diff --git a/net/atm/br2684.c b/net/atm/br2684.c
index 2912665fc58c..848af113ba2a 100644
--- a/net/atm/br2684.c
+++ b/net/atm/br2684.c
@@ -238,7 +238,7 @@ static int br2684_start_xmit(struct sk_buff *skb, struct net_device *dev)
238 /* netif_stop_queue(dev); */ 238 /* netif_stop_queue(dev); */
239 dev_kfree_skb(skb); 239 dev_kfree_skb(skb);
240 read_unlock(&devs_lock); 240 read_unlock(&devs_lock);
241 return 0; 241 return NETDEV_TX_OK;
242 } 242 }
243 if (!br2684_xmit_vcc(skb, dev, brvcc)) { 243 if (!br2684_xmit_vcc(skb, dev, brvcc)) {
244 /* 244 /*
@@ -252,7 +252,7 @@ static int br2684_start_xmit(struct sk_buff *skb, struct net_device *dev)
252 dev->stats.tx_fifo_errors++; 252 dev->stats.tx_fifo_errors++;
253 } 253 }
254 read_unlock(&devs_lock); 254 read_unlock(&devs_lock);
255 return 0; 255 return NETDEV_TX_OK;
256} 256}
257 257
258/* 258/*
diff --git a/net/atm/clip.c b/net/atm/clip.c
index e65a3b1477f8..64910bb86089 100644
--- a/net/atm/clip.c
+++ b/net/atm/clip.c
@@ -373,7 +373,7 @@ static int clip_start_xmit(struct sk_buff *skb, struct net_device *dev)
373 printk(KERN_ERR "clip_start_xmit: skb_dst(skb) == NULL\n"); 373 printk(KERN_ERR "clip_start_xmit: skb_dst(skb) == NULL\n");
374 dev_kfree_skb(skb); 374 dev_kfree_skb(skb);
375 dev->stats.tx_dropped++; 375 dev->stats.tx_dropped++;
376 return 0; 376 return NETDEV_TX_OK;
377 } 377 }
378 if (!skb_dst(skb)->neighbour) { 378 if (!skb_dst(skb)->neighbour) {
379#if 0 379#if 0
@@ -387,7 +387,7 @@ static int clip_start_xmit(struct sk_buff *skb, struct net_device *dev)
387 printk(KERN_ERR "clip_start_xmit: NO NEIGHBOUR !\n"); 387 printk(KERN_ERR "clip_start_xmit: NO NEIGHBOUR !\n");
388 dev_kfree_skb(skb); 388 dev_kfree_skb(skb);
389 dev->stats.tx_dropped++; 389 dev->stats.tx_dropped++;
390 return 0; 390 return NETDEV_TX_OK;
391 } 391 }
392 entry = NEIGH2ENTRY(skb_dst(skb)->neighbour); 392 entry = NEIGH2ENTRY(skb_dst(skb)->neighbour);
393 if (!entry->vccs) { 393 if (!entry->vccs) {
@@ -402,7 +402,7 @@ static int clip_start_xmit(struct sk_buff *skb, struct net_device *dev)
402 dev_kfree_skb(skb); 402 dev_kfree_skb(skb);
403 dev->stats.tx_dropped++; 403 dev->stats.tx_dropped++;
404 } 404 }
405 return 0; 405 return NETDEV_TX_OK;
406 } 406 }
407 pr_debug("neigh %p, vccs %p\n", entry, entry->vccs); 407 pr_debug("neigh %p, vccs %p\n", entry, entry->vccs);
408 ATM_SKB(skb)->vcc = vcc = entry->vccs->vcc; 408 ATM_SKB(skb)->vcc = vcc = entry->vccs->vcc;
@@ -421,14 +421,14 @@ static int clip_start_xmit(struct sk_buff *skb, struct net_device *dev)
421 old = xchg(&entry->vccs->xoff, 1); /* assume XOFF ... */ 421 old = xchg(&entry->vccs->xoff, 1); /* assume XOFF ... */
422 if (old) { 422 if (old) {
423 printk(KERN_WARNING "clip_start_xmit: XOFF->XOFF transition\n"); 423 printk(KERN_WARNING "clip_start_xmit: XOFF->XOFF transition\n");
424 return 0; 424 return NETDEV_TX_OK;
425 } 425 }
426 dev->stats.tx_packets++; 426 dev->stats.tx_packets++;
427 dev->stats.tx_bytes += skb->len; 427 dev->stats.tx_bytes += skb->len;
428 vcc->send(vcc, skb); 428 vcc->send(vcc, skb);
429 if (atm_may_send(vcc, 0)) { 429 if (atm_may_send(vcc, 0)) {
430 entry->vccs->xoff = 0; 430 entry->vccs->xoff = 0;
431 return 0; 431 return NETDEV_TX_OK;
432 } 432 }
433 spin_lock_irqsave(&clip_priv->xoff_lock, flags); 433 spin_lock_irqsave(&clip_priv->xoff_lock, flags);
434 netif_stop_queue(dev); /* XOFF -> throttle immediately */ 434 netif_stop_queue(dev); /* XOFF -> throttle immediately */
@@ -440,7 +440,7 @@ static int clip_start_xmit(struct sk_buff *skb, struct net_device *dev)
440 of the brief netif_stop_queue. If this isn't true or if it 440 of the brief netif_stop_queue. If this isn't true or if it
441 changes, use netif_wake_queue instead. */ 441 changes, use netif_wake_queue instead. */
442 spin_unlock_irqrestore(&clip_priv->xoff_lock, flags); 442 spin_unlock_irqrestore(&clip_priv->xoff_lock, flags);
443 return 0; 443 return NETDEV_TX_OK;
444} 444}
445 445
446static int clip_mkip(struct atm_vcc *vcc, int timeout) 446static int clip_mkip(struct atm_vcc *vcc, int timeout)
diff --git a/net/atm/lec.c b/net/atm/lec.c
index ff2e594dca9b..c463868c993b 100644
--- a/net/atm/lec.c
+++ b/net/atm/lec.c
@@ -289,7 +289,7 @@ static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
289 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN); 289 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
290 kfree_skb(skb); 290 kfree_skb(skb);
291 if (skb2 == NULL) 291 if (skb2 == NULL)
292 return 0; 292 return NETDEV_TX_OK;
293 skb = skb2; 293 skb = skb2;
294 } 294 }
295 skb_push(skb, 2); 295 skb_push(skb, 2);
@@ -307,7 +307,7 @@ static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
307 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN); 307 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
308 kfree_skb(skb); 308 kfree_skb(skb);
309 if (skb2 == NULL) 309 if (skb2 == NULL)
310 return 0; 310 return NETDEV_TX_OK;
311 skb = skb2; 311 skb = skb2;
312 } 312 }
313#endif 313#endif
@@ -345,7 +345,7 @@ static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
345 dev_kfree_skb(skb); 345 dev_kfree_skb(skb);
346 if (skb2 == NULL) { 346 if (skb2 == NULL) {
347 dev->stats.tx_dropped++; 347 dev->stats.tx_dropped++;
348 return 0; 348 return NETDEV_TX_OK;
349 } 349 }
350 skb = skb2; 350 skb = skb2;
351 } 351 }
@@ -416,7 +416,7 @@ out:
416 if (entry) 416 if (entry)
417 lec_arp_put(entry); 417 lec_arp_put(entry);
418 dev->trans_start = jiffies; 418 dev->trans_start = jiffies;
419 return 0; 419 return NETDEV_TX_OK;
420} 420}
421 421
422/* The inverse routine to net_open(). */ 422/* The inverse routine to net_open(). */
diff --git a/net/atm/mpc.c b/net/atm/mpc.c
index e5bf11453a18..1ac4b94bf626 100644
--- a/net/atm/mpc.c
+++ b/net/atm/mpc.c
@@ -554,7 +554,7 @@ static int mpc_send_packet(struct sk_buff *skb, struct net_device *dev)
554 while (i < mpc->number_of_mps_macs) { 554 while (i < mpc->number_of_mps_macs) {
555 if (!compare_ether_addr(eth->h_dest, (mpc->mps_macs + i*ETH_ALEN))) 555 if (!compare_ether_addr(eth->h_dest, (mpc->mps_macs + i*ETH_ALEN)))
556 if ( send_via_shortcut(skb, mpc) == 0 ) /* try shortcut */ 556 if ( send_via_shortcut(skb, mpc) == 0 ) /* try shortcut */
557 return 0; /* success! */ 557 return NETDEV_TX_OK; /* success! */
558 i++; 558 i++;
559 } 559 }
560 560
diff --git a/net/bluetooth/bnep/netdev.c b/net/bluetooth/bnep/netdev.c
index d7a0e9722def..9c42990126a0 100644
--- a/net/bluetooth/bnep/netdev.c
+++ b/net/bluetooth/bnep/netdev.c
@@ -175,14 +175,14 @@ static int bnep_net_xmit(struct sk_buff *skb, struct net_device *dev)
175#ifdef CONFIG_BT_BNEP_MC_FILTER 175#ifdef CONFIG_BT_BNEP_MC_FILTER
176 if (bnep_net_mc_filter(skb, s)) { 176 if (bnep_net_mc_filter(skb, s)) {
177 kfree_skb(skb); 177 kfree_skb(skb);
178 return 0; 178 return NETDEV_TX_OK;
179 } 179 }
180#endif 180#endif
181 181
182#ifdef CONFIG_BT_BNEP_PROTO_FILTER 182#ifdef CONFIG_BT_BNEP_PROTO_FILTER
183 if (bnep_net_proto_filter(skb, s)) { 183 if (bnep_net_proto_filter(skb, s)) {
184 kfree_skb(skb); 184 kfree_skb(skb);
185 return 0; 185 return NETDEV_TX_OK;
186 } 186 }
187#endif 187#endif
188 188
@@ -203,7 +203,7 @@ static int bnep_net_xmit(struct sk_buff *skb, struct net_device *dev)
203 netif_stop_queue(dev); 203 netif_stop_queue(dev);
204 } 204 }
205 205
206 return 0; 206 return NETDEV_TX_OK;
207} 207}
208 208
209static const struct net_device_ops bnep_netdev_ops = { 209static const struct net_device_ops bnep_netdev_ops = {
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 18538d7460d7..15d43ba86b53 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -39,7 +39,7 @@ int br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
39 else 39 else
40 br_flood_deliver(br, skb); 40 br_flood_deliver(br, skb);
41 41
42 return 0; 42 return NETDEV_TX_OK;
43} 43}
44 44
45static int br_dev_open(struct net_device *dev) 45static int br_dev_open(struct net_device *dev)
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index d22f611e4004..4fde7425077d 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -905,46 +905,62 @@ static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff *skb,
905 * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because 905 * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
906 * ip_refrag() can return NF_STOLEN. */ 906 * ip_refrag() can return NF_STOLEN. */
907static struct nf_hook_ops br_nf_ops[] __read_mostly = { 907static struct nf_hook_ops br_nf_ops[] __read_mostly = {
908 { .hook = br_nf_pre_routing, 908 {
909 .owner = THIS_MODULE, 909 .hook = br_nf_pre_routing,
910 .pf = PF_BRIDGE, 910 .owner = THIS_MODULE,
911 .hooknum = NF_BR_PRE_ROUTING, 911 .pf = PF_BRIDGE,
912 .priority = NF_BR_PRI_BRNF, }, 912 .hooknum = NF_BR_PRE_ROUTING,
913 { .hook = br_nf_local_in, 913 .priority = NF_BR_PRI_BRNF,
914 .owner = THIS_MODULE, 914 },
915 .pf = PF_BRIDGE, 915 {
916 .hooknum = NF_BR_LOCAL_IN, 916 .hook = br_nf_local_in,
917 .priority = NF_BR_PRI_BRNF, }, 917 .owner = THIS_MODULE,
918 { .hook = br_nf_forward_ip, 918 .pf = PF_BRIDGE,
919 .owner = THIS_MODULE, 919 .hooknum = NF_BR_LOCAL_IN,
920 .pf = PF_BRIDGE, 920 .priority = NF_BR_PRI_BRNF,
921 .hooknum = NF_BR_FORWARD, 921 },
922 .priority = NF_BR_PRI_BRNF - 1, }, 922 {
923 { .hook = br_nf_forward_arp, 923 .hook = br_nf_forward_ip,
924 .owner = THIS_MODULE, 924 .owner = THIS_MODULE,
925 .pf = PF_BRIDGE, 925 .pf = PF_BRIDGE,
926 .hooknum = NF_BR_FORWARD, 926 .hooknum = NF_BR_FORWARD,
927 .priority = NF_BR_PRI_BRNF, }, 927 .priority = NF_BR_PRI_BRNF - 1,
928 { .hook = br_nf_local_out, 928 },
929 .owner = THIS_MODULE, 929 {
930 .pf = PF_BRIDGE, 930 .hook = br_nf_forward_arp,
931 .hooknum = NF_BR_LOCAL_OUT, 931 .owner = THIS_MODULE,
932 .priority = NF_BR_PRI_FIRST, }, 932 .pf = PF_BRIDGE,
933 { .hook = br_nf_post_routing, 933 .hooknum = NF_BR_FORWARD,
934 .owner = THIS_MODULE, 934 .priority = NF_BR_PRI_BRNF,
935 .pf = PF_BRIDGE, 935 },
936 .hooknum = NF_BR_POST_ROUTING, 936 {
937 .priority = NF_BR_PRI_LAST, }, 937 .hook = br_nf_local_out,
938 { .hook = ip_sabotage_in, 938 .owner = THIS_MODULE,
939 .owner = THIS_MODULE, 939 .pf = PF_BRIDGE,
940 .pf = PF_INET, 940 .hooknum = NF_BR_LOCAL_OUT,
941 .hooknum = NF_INET_PRE_ROUTING, 941 .priority = NF_BR_PRI_FIRST,
942 .priority = NF_IP_PRI_FIRST, }, 942 },
943 { .hook = ip_sabotage_in, 943 {
944 .owner = THIS_MODULE, 944 .hook = br_nf_post_routing,
945 .pf = PF_INET6, 945 .owner = THIS_MODULE,
946 .hooknum = NF_INET_PRE_ROUTING, 946 .pf = PF_BRIDGE,
947 .priority = NF_IP6_PRI_FIRST, }, 947 .hooknum = NF_BR_POST_ROUTING,
948 .priority = NF_BR_PRI_LAST,
949 },
950 {
951 .hook = ip_sabotage_in,
952 .owner = THIS_MODULE,
953 .pf = PF_INET,
954 .hooknum = NF_INET_PRE_ROUTING,
955 .priority = NF_IP_PRI_FIRST,
956 },
957 {
958 .hook = ip_sabotage_in,
959 .owner = THIS_MODULE,
960 .pf = PF_INET6,
961 .hooknum = NF_INET_PRE_ROUTING,
962 .priority = NF_IP6_PRI_FIRST,
963 },
948}; 964};
949 965
950#ifdef CONFIG_SYSCTL 966#ifdef CONFIG_SYSCTL
diff --git a/net/compat.c b/net/compat.c
index 8d739053afe4..12728b17a226 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -743,6 +743,18 @@ asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg, uns
743 return sys_recvmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT); 743 return sys_recvmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
744} 744}
745 745
746asmlinkage long compat_sys_recv(int fd, void __user *buf, size_t len, unsigned flags)
747{
748 return sys_recv(fd, buf, len, flags | MSG_CMSG_COMPAT);
749}
750
751asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, size_t len,
752 unsigned flags, struct sockaddr __user *addr,
753 int __user *addrlen)
754{
755 return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, addrlen);
756}
757
746asmlinkage long compat_sys_socketcall(int call, u32 __user *args) 758asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
747{ 759{
748 int ret; 760 int ret;
@@ -788,10 +800,11 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
788 ret = sys_sendto(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), a[5]); 800 ret = sys_sendto(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), a[5]);
789 break; 801 break;
790 case SYS_RECV: 802 case SYS_RECV:
791 ret = sys_recv(a0, compat_ptr(a1), a[2], a[3]); 803 ret = compat_sys_recv(a0, compat_ptr(a1), a[2], a[3]);
792 break; 804 break;
793 case SYS_RECVFROM: 805 case SYS_RECVFROM:
794 ret = sys_recvfrom(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), compat_ptr(a[5])); 806 ret = compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3],
807 compat_ptr(a[4]), compat_ptr(a[5]));
795 break; 808 break;
796 case SYS_SHUTDOWN: 809 case SYS_SHUTDOWN:
797 ret = sys_shutdown(a0,a1); 810 ret = sys_shutdown(a0,a1);
diff --git a/net/core/dev.c b/net/core/dev.c
index 70c27e0c7c32..dca8b5000d3b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1704,7 +1704,7 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
1704 skb_dst_drop(skb); 1704 skb_dst_drop(skb);
1705 1705
1706 rc = ops->ndo_start_xmit(skb, dev); 1706 rc = ops->ndo_start_xmit(skb, dev);
1707 if (rc == 0) 1707 if (rc == NETDEV_TX_OK)
1708 txq_trans_update(txq); 1708 txq_trans_update(txq);
1709 /* 1709 /*
1710 * TODO: if skb_orphan() was called by 1710 * TODO: if skb_orphan() was called by
@@ -1730,7 +1730,7 @@ gso:
1730 skb->next = nskb->next; 1730 skb->next = nskb->next;
1731 nskb->next = NULL; 1731 nskb->next = NULL;
1732 rc = ops->ndo_start_xmit(nskb, dev); 1732 rc = ops->ndo_start_xmit(nskb, dev);
1733 if (unlikely(rc)) { 1733 if (unlikely(rc != NETDEV_TX_OK)) {
1734 nskb->next = skb->next; 1734 nskb->next = skb->next;
1735 skb->next = nskb; 1735 skb->next = nskb;
1736 return rc; 1736 return rc;
@@ -1744,7 +1744,7 @@ gso:
1744 1744
1745out_kfree_skb: 1745out_kfree_skb:
1746 kfree_skb(skb); 1746 kfree_skb(skb);
1747 return 0; 1747 return NETDEV_TX_OK;
1748} 1748}
1749 1749
1750static u32 skb_tx_hashrnd; 1750static u32 skb_tx_hashrnd;
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 163b4f5b0365..c6f9ad8e4c7a 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1316,7 +1316,7 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
1316} 1316}
1317EXPORT_SYMBOL(pneigh_enqueue); 1317EXPORT_SYMBOL(pneigh_enqueue);
1318 1318
1319static inline struct neigh_parms *lookup_neigh_params(struct neigh_table *tbl, 1319static inline struct neigh_parms *lookup_neigh_parms(struct neigh_table *tbl,
1320 struct net *net, int ifindex) 1320 struct net *net, int ifindex)
1321{ 1321{
1322 struct neigh_parms *p; 1322 struct neigh_parms *p;
@@ -1337,7 +1337,7 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
1337 struct net *net = dev_net(dev); 1337 struct net *net = dev_net(dev);
1338 const struct net_device_ops *ops = dev->netdev_ops; 1338 const struct net_device_ops *ops = dev->netdev_ops;
1339 1339
1340 ref = lookup_neigh_params(tbl, net, 0); 1340 ref = lookup_neigh_parms(tbl, net, 0);
1341 if (!ref) 1341 if (!ref)
1342 return NULL; 1342 return NULL;
1343 1343
@@ -1906,7 +1906,7 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1906 if (tbp[NDTPA_IFINDEX]) 1906 if (tbp[NDTPA_IFINDEX])
1907 ifindex = nla_get_u32(tbp[NDTPA_IFINDEX]); 1907 ifindex = nla_get_u32(tbp[NDTPA_IFINDEX]);
1908 1908
1909 p = lookup_neigh_params(tbl, net, ifindex); 1909 p = lookup_neigh_parms(tbl, net, ifindex);
1910 if (p == NULL) { 1910 if (p == NULL) {
1911 err = -ENOENT; 1911 err = -ENOENT;
1912 goto errout_tbl_lock; 1912 goto errout_tbl_lock;
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index b7292a2719dc..ddd2cd2b1775 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -6,6 +6,8 @@
6#include <linux/delay.h> 6#include <linux/delay.h>
7#include <linux/sched.h> 7#include <linux/sched.h>
8#include <linux/idr.h> 8#include <linux/idr.h>
9#include <linux/rculist.h>
10#include <linux/nsproxy.h>
9#include <net/net_namespace.h> 11#include <net/net_namespace.h>
10#include <net/netns/generic.h> 12#include <net/netns/generic.h>
11 13
@@ -127,7 +129,7 @@ static struct net *net_create(void)
127 rv = setup_net(net); 129 rv = setup_net(net);
128 if (rv == 0) { 130 if (rv == 0) {
129 rtnl_lock(); 131 rtnl_lock();
130 list_add_tail(&net->list, &net_namespace_list); 132 list_add_tail_rcu(&net->list, &net_namespace_list);
131 rtnl_unlock(); 133 rtnl_unlock();
132 } 134 }
133 mutex_unlock(&net_mutex); 135 mutex_unlock(&net_mutex);
@@ -156,9 +158,16 @@ static void cleanup_net(struct work_struct *work)
156 158
157 /* Don't let anyone else find us. */ 159 /* Don't let anyone else find us. */
158 rtnl_lock(); 160 rtnl_lock();
159 list_del(&net->list); 161 list_del_rcu(&net->list);
160 rtnl_unlock(); 162 rtnl_unlock();
161 163
164 /*
165 * Another CPU might be rcu-iterating the list, wait for it.
166 * This needs to be before calling the exit() notifiers, so
167 * the rcu_barrier() below isn't sufficient alone.
168 */
169 synchronize_rcu();
170
162 /* Run all of the network namespace exit methods */ 171 /* Run all of the network namespace exit methods */
163 list_for_each_entry_reverse(ops, &pernet_list, list) { 172 list_for_each_entry_reverse(ops, &pernet_list, list) {
164 if (ops->exit) 173 if (ops->exit)
@@ -193,6 +202,26 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net)
193} 202}
194#endif 203#endif
195 204
205struct net *get_net_ns_by_pid(pid_t pid)
206{
207 struct task_struct *tsk;
208 struct net *net;
209
210 /* Lookup the network namespace */
211 net = ERR_PTR(-ESRCH);
212 rcu_read_lock();
213 tsk = find_task_by_vpid(pid);
214 if (tsk) {
215 struct nsproxy *nsproxy;
216 nsproxy = task_nsproxy(tsk);
217 if (nsproxy)
218 net = get_net(nsproxy->net_ns);
219 }
220 rcu_read_unlock();
221 return net;
222}
223EXPORT_SYMBOL_GPL(get_net_ns_by_pid);
224
196static int __init net_ns_init(void) 225static int __init net_ns_init(void)
197{ 226{
198 struct net_generic *ng; 227 struct net_generic *ng;
@@ -219,7 +248,7 @@ static int __init net_ns_init(void)
219 panic("Could not setup the initial network namespace"); 248 panic("Could not setup the initial network namespace");
220 249
221 rtnl_lock(); 250 rtnl_lock();
222 list_add_tail(&init_net.list, &net_namespace_list); 251 list_add_tail_rcu(&init_net.list, &net_namespace_list);
223 rtnl_unlock(); 252 rtnl_unlock();
224 253
225 mutex_unlock(&net_mutex); 254 mutex_unlock(&net_mutex);
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index df30feb2fc72..0ac309154b0d 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -9,6 +9,7 @@
9 * Copyright (C) 2002 Red Hat, Inc. 9 * Copyright (C) 2002 Red Hat, Inc.
10 */ 10 */
11 11
12#include <linux/moduleparam.h>
12#include <linux/netdevice.h> 13#include <linux/netdevice.h>
13#include <linux/etherdevice.h> 14#include <linux/etherdevice.h>
14#include <linux/string.h> 15#include <linux/string.h>
@@ -50,6 +51,9 @@ static atomic_t trapped;
50static void zap_completion_queue(void); 51static void zap_completion_queue(void);
51static void arp_reply(struct sk_buff *skb); 52static void arp_reply(struct sk_buff *skb);
52 53
54static unsigned int carrier_timeout = 4;
55module_param(carrier_timeout, uint, 0644);
56
53static void queue_process(struct work_struct *work) 57static void queue_process(struct work_struct *work)
54{ 58{
55 struct netpoll_info *npinfo = 59 struct netpoll_info *npinfo =
@@ -732,7 +736,7 @@ int netpoll_setup(struct netpoll *np)
732 } 736 }
733 737
734 atleast = jiffies + HZ/10; 738 atleast = jiffies + HZ/10;
735 atmost = jiffies + 4*HZ; 739 atmost = jiffies + carrier_timeout * HZ;
736 while (!netif_carrier_ok(ndev)) { 740 while (!netif_carrier_ok(ndev)) {
737 if (time_after(jiffies, atmost)) { 741 if (time_after(jiffies, atmost)) {
738 printk(KERN_NOTICE 742 printk(KERN_NOTICE
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index d78030f88bd0..b44775f9f2bf 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -35,7 +35,6 @@
35#include <linux/security.h> 35#include <linux/security.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/if_addr.h> 37#include <linux/if_addr.h>
38#include <linux/nsproxy.h>
39 38
40#include <asm/uaccess.h> 39#include <asm/uaccess.h>
41#include <asm/system.h> 40#include <asm/system.h>
@@ -52,6 +51,7 @@
52#include <net/pkt_sched.h> 51#include <net/pkt_sched.h>
53#include <net/fib_rules.h> 52#include <net/fib_rules.h>
54#include <net/rtnetlink.h> 53#include <net/rtnetlink.h>
54#include <net/net_namespace.h>
55 55
56struct rtnl_link 56struct rtnl_link
57{ 57{
@@ -725,25 +725,6 @@ static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
725 [IFLA_INFO_DATA] = { .type = NLA_NESTED }, 725 [IFLA_INFO_DATA] = { .type = NLA_NESTED },
726}; 726};
727 727
728static struct net *get_net_ns_by_pid(pid_t pid)
729{
730 struct task_struct *tsk;
731 struct net *net;
732
733 /* Lookup the network namespace */
734 net = ERR_PTR(-ESRCH);
735 rcu_read_lock();
736 tsk = find_task_by_vpid(pid);
737 if (tsk) {
738 struct nsproxy *nsproxy;
739 nsproxy = task_nsproxy(tsk);
740 if (nsproxy)
741 net = get_net(nsproxy->net_ns);
742 }
743 rcu_read_unlock();
744 return net;
745}
746
747static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[]) 728static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
748{ 729{
749 if (dev) { 730 if (dev) {
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 1d6ca8a98dc6..9383d3e5a1ab 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -774,7 +774,7 @@ static int dn_rt_bug(struct sk_buff *skb)
774 774
775 kfree_skb(skb); 775 kfree_skb(skb);
776 776
777 return NET_RX_BAD; 777 return NET_RX_DROP;
778} 778}
779 779
780static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res) 780static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
diff --git a/net/econet/af_econet.c b/net/econet/af_econet.c
index 2e1f836d4240..e114da7ca9b8 100644
--- a/net/econet/af_econet.c
+++ b/net/econet/af_econet.c
@@ -1072,7 +1072,7 @@ static int econet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet
1072 skb->protocol = htons(ETH_P_IP); 1072 skb->protocol = htons(ETH_P_IP);
1073 skb_pull(skb, sizeof(struct ec_framehdr)); 1073 skb_pull(skb, sizeof(struct ec_framehdr));
1074 netif_rx(skb); 1074 netif_rx(skb);
1075 return 0; 1075 return NET_RX_SUCCESS;
1076 } 1076 }
1077 1077
1078 sk = ec_listening_socket(hdr->port, hdr->src_stn, hdr->src_net); 1078 sk = ec_listening_socket(hdr->port, hdr->src_stn, hdr->src_net);
@@ -1083,7 +1083,7 @@ static int econet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet
1083 hdr->port)) 1083 hdr->port))
1084 goto drop; 1084 goto drop;
1085 1085
1086 return 0; 1086 return NET_RX_SUCCESS;
1087 1087
1088drop: 1088drop:
1089 kfree_skb(skb); 1089 kfree_skb(skb);
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 566ea6c4321d..197d024b2536 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1187,6 +1187,7 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb, int features)
1187 int proto; 1187 int proto;
1188 int ihl; 1188 int ihl;
1189 int id; 1189 int id;
1190 unsigned int offset = 0;
1190 1191
1191 if (!(features & NETIF_F_V4_CSUM)) 1192 if (!(features & NETIF_F_V4_CSUM))
1192 features &= ~NETIF_F_SG; 1193 features &= ~NETIF_F_SG;
@@ -1229,7 +1230,14 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb, int features)
1229 skb = segs; 1230 skb = segs;
1230 do { 1231 do {
1231 iph = ip_hdr(skb); 1232 iph = ip_hdr(skb);
1232 iph->id = htons(id++); 1233 if (proto == IPPROTO_UDP) {
1234 iph->id = htons(id);
1235 iph->frag_off = htons(offset >> 3);
1236 if (skb->next != NULL)
1237 iph->frag_off |= htons(IP_MF);
1238 offset += (skb->len - skb->mac_len - iph->ihl * 4);
1239 } else
1240 iph->id = htons(id++);
1233 iph->tot_len = htons(skb->len - skb->mac_len); 1241 iph->tot_len = htons(skb->len - skb->mac_len);
1234 iph->check = 0; 1242 iph->check = 0;
1235 iph->check = ip_fast_csum(skb_network_header(skb), iph->ihl); 1243 iph->check = ip_fast_csum(skb_network_header(skb), iph->ihl);
@@ -1425,6 +1433,8 @@ static struct net_protocol tcp_protocol = {
1425static struct net_protocol udp_protocol = { 1433static struct net_protocol udp_protocol = {
1426 .handler = udp_rcv, 1434 .handler = udp_rcv,
1427 .err_handler = udp_err, 1435 .err_handler = udp_err,
1436 .gso_send_check = udp4_ufo_send_check,
1437 .gso_segment = udp4_ufo_fragment,
1428 .no_policy = 1, 1438 .no_policy = 1,
1429 .netns_ok = 1, 1439 .netns_ok = 1,
1430}; 1440};
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index cb4a0f4bd5e5..b902ef55be7f 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -821,7 +821,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
821 stats->tx_dropped++; 821 stats->tx_dropped++;
822 dev_kfree_skb(skb); 822 dev_kfree_skb(skb);
823 tunnel->recursion--; 823 tunnel->recursion--;
824 return 0; 824 return NETDEV_TX_OK;
825 } 825 }
826 if (skb->sk) 826 if (skb->sk)
827 skb_set_owner_w(new_skb, skb->sk); 827 skb_set_owner_w(new_skb, skb->sk);
@@ -889,7 +889,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
889 889
890 IPTUNNEL_XMIT(); 890 IPTUNNEL_XMIT();
891 tunnel->recursion--; 891 tunnel->recursion--;
892 return 0; 892 return NETDEV_TX_OK;
893 893
894tx_error_icmp: 894tx_error_icmp:
895 dst_link_failure(skb); 895 dst_link_failure(skb);
@@ -898,7 +898,7 @@ tx_error:
898 stats->tx_errors++; 898 stats->tx_errors++;
899 dev_kfree_skb(skb); 899 dev_kfree_skb(skb);
900 tunnel->recursion--; 900 tunnel->recursion--;
901 return 0; 901 return NETDEV_TX_OK;
902} 902}
903 903
904static int ipgre_tunnel_bind_dev(struct net_device *dev) 904static int ipgre_tunnel_bind_dev(struct net_device *dev)
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 93e2b787da20..98075b6d619c 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -486,7 +486,7 @@ static int ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
486 stats->tx_dropped++; 486 stats->tx_dropped++;
487 dev_kfree_skb(skb); 487 dev_kfree_skb(skb);
488 tunnel->recursion--; 488 tunnel->recursion--;
489 return 0; 489 return NETDEV_TX_OK;
490 } 490 }
491 if (skb->sk) 491 if (skb->sk)
492 skb_set_owner_w(new_skb, skb->sk); 492 skb_set_owner_w(new_skb, skb->sk);
@@ -524,7 +524,7 @@ static int ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
524 524
525 IPTUNNEL_XMIT(); 525 IPTUNNEL_XMIT();
526 tunnel->recursion--; 526 tunnel->recursion--;
527 return 0; 527 return NETDEV_TX_OK;
528 528
529tx_error_icmp: 529tx_error_icmp:
530 dst_link_failure(skb); 530 dst_link_failure(skb);
@@ -532,7 +532,7 @@ tx_error:
532 stats->tx_errors++; 532 stats->tx_errors++;
533 dev_kfree_skb(skb); 533 dev_kfree_skb(skb);
534 tunnel->recursion--; 534 tunnel->recursion--;
535 return 0; 535 return NETDEV_TX_OK;
536} 536}
537 537
538static void ipip_tunnel_bind_dev(struct net_device *dev) 538static void ipip_tunnel_bind_dev(struct net_device *dev)
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 9a8da5ed92b7..06c33fb6b321 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -212,7 +212,7 @@ static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
212 IGMPMSG_WHOLEPKT); 212 IGMPMSG_WHOLEPKT);
213 read_unlock(&mrt_lock); 213 read_unlock(&mrt_lock);
214 kfree_skb(skb); 214 kfree_skb(skb);
215 return 0; 215 return NETDEV_TX_OK;
216} 216}
217 217
218static const struct net_device_ops reg_vif_netdev_ops = { 218static const struct net_device_ops reg_vif_netdev_ops = {
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 80e3812837ad..7bc2d082a49e 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1816,6 +1816,67 @@ void __init udp_init(void)
1816 sysctl_udp_wmem_min = SK_MEM_QUANTUM; 1816 sysctl_udp_wmem_min = SK_MEM_QUANTUM;
1817} 1817}
1818 1818
1819int udp4_ufo_send_check(struct sk_buff *skb)
1820{
1821 const struct iphdr *iph;
1822 struct udphdr *uh;
1823
1824 if (!pskb_may_pull(skb, sizeof(*uh)))
1825 return -EINVAL;
1826
1827 iph = ip_hdr(skb);
1828 uh = udp_hdr(skb);
1829
1830 uh->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, skb->len,
1831 IPPROTO_UDP, 0);
1832 skb->csum_start = skb_transport_header(skb) - skb->head;
1833 skb->csum_offset = offsetof(struct udphdr, check);
1834 skb->ip_summed = CHECKSUM_PARTIAL;
1835 return 0;
1836}
1837
1838struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb, int features)
1839{
1840 struct sk_buff *segs = ERR_PTR(-EINVAL);
1841 unsigned int mss;
1842 int offset;
1843 __wsum csum;
1844
1845 mss = skb_shinfo(skb)->gso_size;
1846 if (unlikely(skb->len <= mss))
1847 goto out;
1848
1849 if (skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) {
1850 /* Packet is from an untrusted source, reset gso_segs. */
1851 int type = skb_shinfo(skb)->gso_type;
1852
1853 if (unlikely(type & ~(SKB_GSO_UDP | SKB_GSO_DODGY) ||
1854 !(type & (SKB_GSO_UDP))))
1855 goto out;
1856
1857 skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss);
1858
1859 segs = NULL;
1860 goto out;
1861 }
1862
1863 /* Do software UFO. Complete and fill in the UDP checksum as HW cannot
1864 * do checksum of UDP packets sent as multiple IP fragments.
1865 */
1866 offset = skb->csum_start - skb_headroom(skb);
1867 csum = skb_checksum(skb, offset, skb->len- offset, 0);
1868 offset += skb->csum_offset;
1869 *(__sum16 *)(skb->data + offset) = csum_fold(csum);
1870 skb->ip_summed = CHECKSUM_NONE;
1871
1872 /* Fragment the skb. IP headers of the fragments are updated in
1873 * inet_gso_segment()
1874 */
1875 segs = skb_segment(skb, features);
1876out:
1877 return segs;
1878}
1879
1819EXPORT_SYMBOL(udp_disconnect); 1880EXPORT_SYMBOL(udp_disconnect);
1820EXPORT_SYMBOL(udp_ioctl); 1881EXPORT_SYMBOL(udp_ioctl);
1821EXPORT_SYMBOL(udp_prot); 1882EXPORT_SYMBOL(udp_prot);
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index caa0278d30a9..bf85d5f97032 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -772,6 +772,11 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features)
772 struct sk_buff *segs = ERR_PTR(-EINVAL); 772 struct sk_buff *segs = ERR_PTR(-EINVAL);
773 struct ipv6hdr *ipv6h; 773 struct ipv6hdr *ipv6h;
774 struct inet6_protocol *ops; 774 struct inet6_protocol *ops;
775 int proto;
776 struct frag_hdr *fptr;
777 unsigned int unfrag_ip6hlen;
778 u8 *prevhdr;
779 int offset = 0;
775 780
776 if (!(features & NETIF_F_V6_CSUM)) 781 if (!(features & NETIF_F_V6_CSUM))
777 features &= ~NETIF_F_SG; 782 features &= ~NETIF_F_SG;
@@ -791,10 +796,9 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features)
791 __skb_pull(skb, sizeof(*ipv6h)); 796 __skb_pull(skb, sizeof(*ipv6h));
792 segs = ERR_PTR(-EPROTONOSUPPORT); 797 segs = ERR_PTR(-EPROTONOSUPPORT);
793 798
799 proto = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr);
794 rcu_read_lock(); 800 rcu_read_lock();
795 ops = rcu_dereference(inet6_protos[ 801 ops = rcu_dereference(inet6_protos[proto]);
796 ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr)]);
797
798 if (likely(ops && ops->gso_segment)) { 802 if (likely(ops && ops->gso_segment)) {
799 skb_reset_transport_header(skb); 803 skb_reset_transport_header(skb);
800 segs = ops->gso_segment(skb, features); 804 segs = ops->gso_segment(skb, features);
@@ -808,6 +812,16 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features)
808 ipv6h = ipv6_hdr(skb); 812 ipv6h = ipv6_hdr(skb);
809 ipv6h->payload_len = htons(skb->len - skb->mac_len - 813 ipv6h->payload_len = htons(skb->len - skb->mac_len -
810 sizeof(*ipv6h)); 814 sizeof(*ipv6h));
815 if (proto == IPPROTO_UDP) {
816 unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr);
817 fptr = (struct frag_hdr *)(skb_network_header(skb) +
818 unfrag_ip6hlen);
819 fptr->frag_off = htons(offset);
820 if (skb->next != NULL)
821 fptr->frag_off |= htons(IP6_MF);
822 offset += (ntohs(ipv6h->payload_len) -
823 sizeof(struct frag_hdr));
824 }
811 } 825 }
812 826
813out: 827out:
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index 6d6a4277c677..2d9cbaa67edb 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -63,7 +63,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
63 63
64 if (skb->pkt_type == PACKET_OTHERHOST) { 64 if (skb->pkt_type == PACKET_OTHERHOST) {
65 kfree_skb(skb); 65 kfree_skb(skb);
66 return 0; 66 return NET_RX_DROP;
67 } 67 }
68 68
69 rcu_read_lock(); 69 rcu_read_lock();
@@ -133,7 +133,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
133 if (ipv6_parse_hopopts(skb) < 0) { 133 if (ipv6_parse_hopopts(skb) < 0) {
134 IP6_INC_STATS_BH(net, idev, IPSTATS_MIB_INHDRERRORS); 134 IP6_INC_STATS_BH(net, idev, IPSTATS_MIB_INHDRERRORS);
135 rcu_read_unlock(); 135 rcu_read_unlock();
136 return 0; 136 return NET_RX_DROP;
137 } 137 }
138 } 138 }
139 139
@@ -149,7 +149,7 @@ err:
149drop: 149drop:
150 rcu_read_unlock(); 150 rcu_read_unlock();
151 kfree_skb(skb); 151 kfree_skb(skb);
152 return 0; 152 return NET_RX_DROP;
153} 153}
154 154
155/* 155/*
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 87f8419a68fd..93beee944657 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -57,18 +57,6 @@
57 57
58static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)); 58static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *));
59 59
60static __inline__ void ipv6_select_ident(struct sk_buff *skb, struct frag_hdr *fhdr)
61{
62 static u32 ipv6_fragmentation_id = 1;
63 static DEFINE_SPINLOCK(ip6_id_lock);
64
65 spin_lock_bh(&ip6_id_lock);
66 fhdr->identification = htonl(ipv6_fragmentation_id);
67 if (++ipv6_fragmentation_id == 0)
68 ipv6_fragmentation_id = 1;
69 spin_unlock_bh(&ip6_id_lock);
70}
71
72int __ip6_local_out(struct sk_buff *skb) 60int __ip6_local_out(struct sk_buff *skb)
73{ 61{
74 int len; 62 int len;
@@ -706,7 +694,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
706 skb_reset_network_header(skb); 694 skb_reset_network_header(skb);
707 memcpy(skb_network_header(skb), tmp_hdr, hlen); 695 memcpy(skb_network_header(skb), tmp_hdr, hlen);
708 696
709 ipv6_select_ident(skb, fh); 697 ipv6_select_ident(fh);
710 fh->nexthdr = nexthdr; 698 fh->nexthdr = nexthdr;
711 fh->reserved = 0; 699 fh->reserved = 0;
712 fh->frag_off = htons(IP6_MF); 700 fh->frag_off = htons(IP6_MF);
@@ -844,7 +832,7 @@ slow_path:
844 fh->nexthdr = nexthdr; 832 fh->nexthdr = nexthdr;
845 fh->reserved = 0; 833 fh->reserved = 0;
846 if (!frag_id) { 834 if (!frag_id) {
847 ipv6_select_ident(skb, fh); 835 ipv6_select_ident(fh);
848 frag_id = fh->identification; 836 frag_id = fh->identification;
849 } else 837 } else
850 fh->identification = frag_id; 838 fh->identification = frag_id;
@@ -1087,11 +1075,13 @@ static inline int ip6_ufo_append_data(struct sock *sk,
1087 if (!err) { 1075 if (!err) {
1088 struct frag_hdr fhdr; 1076 struct frag_hdr fhdr;
1089 1077
1090 /* specify the length of each IP datagram fragment*/ 1078 /* Specify the length of each IPv6 datagram fragment.
1091 skb_shinfo(skb)->gso_size = mtu - fragheaderlen - 1079 * It has to be a multiple of 8.
1092 sizeof(struct frag_hdr); 1080 */
1081 skb_shinfo(skb)->gso_size = (mtu - fragheaderlen -
1082 sizeof(struct frag_hdr)) & ~7;
1093 skb_shinfo(skb)->gso_type = SKB_GSO_UDP; 1083 skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
1094 ipv6_select_ident(skb, &fhdr); 1084 ipv6_select_ident(&fhdr);
1095 skb_shinfo(skb)->ip6_frag_id = fhdr.identification; 1085 skb_shinfo(skb)->ip6_frag_id = fhdr.identification;
1096 __skb_queue_tail(&sk->sk_write_queue, skb); 1086 __skb_queue_tail(&sk->sk_write_queue, skb);
1097 1087
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 51f410e7775a..a1d6045c4694 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1063,14 +1063,14 @@ ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1063 goto tx_err; 1063 goto tx_err;
1064 1064
1065 t->recursion--; 1065 t->recursion--;
1066 return 0; 1066 return NETDEV_TX_OK;
1067 1067
1068tx_err: 1068tx_err:
1069 stats->tx_errors++; 1069 stats->tx_errors++;
1070 stats->tx_dropped++; 1070 stats->tx_dropped++;
1071 kfree_skb(skb); 1071 kfree_skb(skb);
1072 t->recursion--; 1072 t->recursion--;
1073 return 0; 1073 return NETDEV_TX_OK;
1074} 1074}
1075 1075
1076static void ip6_tnl_set_cap(struct ip6_tnl *t) 1076static void ip6_tnl_set_cap(struct ip6_tnl *t)
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index c769f155c698..07ded5075b33 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -427,7 +427,7 @@ static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
427 MRT6MSG_WHOLEPKT); 427 MRT6MSG_WHOLEPKT);
428 read_unlock(&mrt_lock); 428 read_unlock(&mrt_lock);
429 kfree_skb(skb); 429 kfree_skb(skb);
430 return 0; 430 return NETDEV_TX_OK;
431} 431}
432 432
433static const struct net_device_ops reg_vif_netdev_ops = { 433static const struct net_device_ops reg_vif_netdev_ops = {
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 98b7327d0949..d335a306a4db 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -753,7 +753,7 @@ static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
753 stats->tx_dropped++; 753 stats->tx_dropped++;
754 dev_kfree_skb(skb); 754 dev_kfree_skb(skb);
755 tunnel->recursion--; 755 tunnel->recursion--;
756 return 0; 756 return NETDEV_TX_OK;
757 } 757 }
758 if (skb->sk) 758 if (skb->sk)
759 skb_set_owner_w(new_skb, skb->sk); 759 skb_set_owner_w(new_skb, skb->sk);
@@ -794,7 +794,7 @@ static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
794 794
795 IPTUNNEL_XMIT(); 795 IPTUNNEL_XMIT();
796 tunnel->recursion--; 796 tunnel->recursion--;
797 return 0; 797 return NETDEV_TX_OK;
798 798
799tx_error_icmp: 799tx_error_icmp:
800 dst_link_failure(skb); 800 dst_link_failure(skb);
@@ -802,7 +802,7 @@ tx_error:
802 stats->tx_errors++; 802 stats->tx_errors++;
803 dev_kfree_skb(skb); 803 dev_kfree_skb(skb);
804 tunnel->recursion--; 804 tunnel->recursion--;
805 return 0; 805 return NETDEV_TX_OK;
806} 806}
807 807
808static void ipip6_tunnel_bind_dev(struct net_device *dev) 808static void ipip6_tunnel_bind_dev(struct net_device *dev)
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 33b59bd92c4d..d79fa6724451 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -638,6 +638,47 @@ static void udp_v6_flush_pending_frames(struct sock *sk)
638 } 638 }
639} 639}
640 640
641/**
642 * udp6_hwcsum_outgoing - handle outgoing HW checksumming
643 * @sk: socket we are sending on
644 * @skb: sk_buff containing the filled-in UDP header
645 * (checksum field must be zeroed out)
646 */
647static void udp6_hwcsum_outgoing(struct sock *sk, struct sk_buff *skb,
648 const struct in6_addr *saddr,
649 const struct in6_addr *daddr, int len)
650{
651 unsigned int offset;
652 struct udphdr *uh = udp_hdr(skb);
653 __wsum csum = 0;
654
655 if (skb_queue_len(&sk->sk_write_queue) == 1) {
656 /* Only one fragment on the socket. */
657 skb->csum_start = skb_transport_header(skb) - skb->head;
658 skb->csum_offset = offsetof(struct udphdr, check);
659 uh->check = ~csum_ipv6_magic(saddr, daddr, len, IPPROTO_UDP, 0);
660 } else {
661 /*
662 * HW-checksum won't work as there are two or more
663 * fragments on the socket so that all csums of sk_buffs
664 * should be together
665 */
666 offset = skb_transport_offset(skb);
667 skb->csum = skb_checksum(skb, offset, skb->len - offset, 0);
668
669 skb->ip_summed = CHECKSUM_NONE;
670
671 skb_queue_walk(&sk->sk_write_queue, skb) {
672 csum = csum_add(csum, skb->csum);
673 }
674
675 uh->check = csum_ipv6_magic(saddr, daddr, len, IPPROTO_UDP,
676 csum);
677 if (uh->check == 0)
678 uh->check = CSUM_MANGLED_0;
679 }
680}
681
641/* 682/*
642 * Sending 683 * Sending
643 */ 684 */
@@ -668,7 +709,11 @@ static int udp_v6_push_pending_frames(struct sock *sk)
668 709
669 if (is_udplite) 710 if (is_udplite)
670 csum = udplite_csum_outgoing(sk, skb); 711 csum = udplite_csum_outgoing(sk, skb);
671 else 712 else if (skb->ip_summed == CHECKSUM_PARTIAL) { /* UDP hardware csum */
713 udp6_hwcsum_outgoing(sk, skb, &fl->fl6_src, &fl->fl6_dst,
714 up->len);
715 goto send;
716 } else
672 csum = udp_csum_outgoing(sk, skb); 717 csum = udp_csum_outgoing(sk, skb);
673 718
674 /* add protocol-dependent pseudo-header */ 719 /* add protocol-dependent pseudo-header */
@@ -677,6 +722,7 @@ static int udp_v6_push_pending_frames(struct sock *sk)
677 if (uh->check == 0) 722 if (uh->check == 0)
678 uh->check = CSUM_MANGLED_0; 723 uh->check = CSUM_MANGLED_0;
679 724
725send:
680 err = ip6_push_pending_frames(sk); 726 err = ip6_push_pending_frames(sk);
681out: 727out:
682 up->len = 0; 728 up->len = 0;
@@ -1032,9 +1078,102 @@ int compat_udpv6_getsockopt(struct sock *sk, int level, int optname,
1032} 1078}
1033#endif 1079#endif
1034 1080
1081static int udp6_ufo_send_check(struct sk_buff *skb)
1082{
1083 struct ipv6hdr *ipv6h;
1084 struct udphdr *uh;
1085
1086 if (!pskb_may_pull(skb, sizeof(*uh)))
1087 return -EINVAL;
1088
1089 ipv6h = ipv6_hdr(skb);
1090 uh = udp_hdr(skb);
1091
1092 uh->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, skb->len,
1093 IPPROTO_UDP, 0);
1094 skb->csum_start = skb_transport_header(skb) - skb->head;
1095 skb->csum_offset = offsetof(struct udphdr, check);
1096 skb->ip_summed = CHECKSUM_PARTIAL;
1097 return 0;
1098}
1099
1100static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, int features)
1101{
1102 struct sk_buff *segs = ERR_PTR(-EINVAL);
1103 unsigned int mss;
1104 unsigned int unfrag_ip6hlen, unfrag_len;
1105 struct frag_hdr *fptr;
1106 u8 *mac_start, *prevhdr;
1107 u8 nexthdr;
1108 u8 frag_hdr_sz = sizeof(struct frag_hdr);
1109 int offset;
1110 __wsum csum;
1111
1112 mss = skb_shinfo(skb)->gso_size;
1113 if (unlikely(skb->len <= mss))
1114 goto out;
1115
1116 if (skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) {
1117 /* Packet is from an untrusted source, reset gso_segs. */
1118 int type = skb_shinfo(skb)->gso_type;
1119
1120 if (unlikely(type & ~(SKB_GSO_UDP | SKB_GSO_DODGY) ||
1121 !(type & (SKB_GSO_UDP))))
1122 goto out;
1123
1124 skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss);
1125
1126 segs = NULL;
1127 goto out;
1128 }
1129
1130 /* Do software UFO. Complete and fill in the UDP checksum as HW cannot
1131 * do checksum of UDP packets sent as multiple IP fragments.
1132 */
1133 offset = skb->csum_start - skb_headroom(skb);
1134 csum = skb_checksum(skb, offset, skb->len- offset, 0);
1135 offset += skb->csum_offset;
1136 *(__sum16 *)(skb->data + offset) = csum_fold(csum);
1137 skb->ip_summed = CHECKSUM_NONE;
1138
1139 /* Check if there is enough headroom to insert fragment header. */
1140 if ((skb_headroom(skb) < frag_hdr_sz) &&
1141 pskb_expand_head(skb, frag_hdr_sz, 0, GFP_ATOMIC))
1142 goto out;
1143
1144 /* Find the unfragmentable header and shift it left by frag_hdr_sz
1145 * bytes to insert fragment header.
1146 */
1147 unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr);
1148 nexthdr = *prevhdr;
1149 *prevhdr = NEXTHDR_FRAGMENT;
1150 unfrag_len = skb_network_header(skb) - skb_mac_header(skb) +
1151 unfrag_ip6hlen;
1152 mac_start = skb_mac_header(skb);
1153 memmove(mac_start-frag_hdr_sz, mac_start, unfrag_len);
1154
1155 skb->mac_header -= frag_hdr_sz;
1156 skb->network_header -= frag_hdr_sz;
1157
1158 fptr = (struct frag_hdr *)(skb_network_header(skb) + unfrag_ip6hlen);
1159 fptr->nexthdr = nexthdr;
1160 fptr->reserved = 0;
1161 ipv6_select_ident(fptr);
1162
1163 /* Fragment the skb. ipv6 header and the remaining fields of the
1164 * fragment header are updated in ipv6_gso_segment()
1165 */
1166 segs = skb_segment(skb, features);
1167
1168out:
1169 return segs;
1170}
1171
1035static struct inet6_protocol udpv6_protocol = { 1172static struct inet6_protocol udpv6_protocol = {
1036 .handler = udpv6_rcv, 1173 .handler = udpv6_rcv,
1037 .err_handler = udpv6_err, 1174 .err_handler = udpv6_err,
1175 .gso_send_check = udp6_ufo_send_check,
1176 .gso_segment = udp6_ufo_fragment,
1038 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, 1177 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
1039}; 1178};
1040 1179
diff --git a/net/irda/irlan/irlan_eth.c b/net/irda/irlan/irlan_eth.c
index 724bcf951b80..64230cffcfee 100644
--- a/net/irda/irlan/irlan_eth.c
+++ b/net/irda/irlan/irlan_eth.c
@@ -177,7 +177,7 @@ static int irlan_eth_xmit(struct sk_buff *skb, struct net_device *dev)
177 177
178 /* Did the realloc succeed? */ 178 /* Did the realloc succeed? */
179 if (new_skb == NULL) 179 if (new_skb == NULL)
180 return 0; 180 return NETDEV_TX_OK;
181 181
182 /* Use the new skb instead */ 182 /* Use the new skb instead */
183 skb = new_skb; 183 skb = new_skb;
@@ -209,7 +209,7 @@ static int irlan_eth_xmit(struct sk_buff *skb, struct net_device *dev)
209 self->stats.tx_bytes += skb->len; 209 self->stats.tx_bytes += skb->len;
210 } 210 }
211 211
212 return 0; 212 return NETDEV_TX_OK;
213} 213}
214 214
215/* 215/*
diff --git a/net/irda/irnetlink.c b/net/irda/irnetlink.c
index 8dd7ed7e7c1f..476b307bd801 100644
--- a/net/irda/irnetlink.c
+++ b/net/irda/irnetlink.c
@@ -115,7 +115,7 @@ static int irda_nl_get_mode(struct sk_buff *skb, struct genl_info *info)
115 115
116 genlmsg_end(msg, hdr); 116 genlmsg_end(msg, hdr);
117 117
118 return genlmsg_unicast(msg, info->snd_pid); 118 return genlmsg_reply(msg, info);
119 119
120 err_out: 120 err_out:
121 nlmsg_free(msg); 121 nlmsg_free(msg);
diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
index 2ba1bc4f3c3a..bda96d18fd98 100644
--- a/net/lapb/lapb_iface.c
+++ b/net/lapb/lapb_iface.c
@@ -407,7 +407,7 @@ int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
407 return lapb->callbacks.data_indication(lapb->dev, skb); 407 return lapb->callbacks.data_indication(lapb->dev, skb);
408 408
409 kfree_skb(skb); 409 kfree_skb(skb);
410 return NET_RX_CN_HIGH; /* For now; must be != NET_RX_DROP */ 410 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
411} 411}
412 412
413int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb) 413int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index ba2643a43c73..41a32cd919af 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -14,22 +14,6 @@ config MAC80211
14comment "CFG80211 needs to be enabled for MAC80211" 14comment "CFG80211 needs to be enabled for MAC80211"
15 depends on CFG80211=n 15 depends on CFG80211=n
16 16
17config MAC80211_DEFAULT_PS
18 bool "enable powersave by default"
19 depends on MAC80211
20 default y
21 help
22 This option enables powersave mode by default.
23
24 If this causes your applications to misbehave you should fix your
25 applications instead -- they need to register their network
26 latency requirement, see Documentation/power/pm_qos_interface.txt.
27
28config MAC80211_DEFAULT_PS_VALUE
29 int
30 default 1 if MAC80211_DEFAULT_PS
31 default 0
32
33menu "Rate control algorithm selection" 17menu "Rate control algorithm selection"
34 depends on MAC80211 != n 18 depends on MAC80211 != n
35 19
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 3f47276caeb8..36f8f245fa4c 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -74,19 +74,14 @@ static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
74 return 0; 74 return 0;
75} 75}
76 76
77static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex, 77static int ieee80211_change_iface(struct wiphy *wiphy,
78 struct net_device *dev,
78 enum nl80211_iftype type, u32 *flags, 79 enum nl80211_iftype type, u32 *flags,
79 struct vif_params *params) 80 struct vif_params *params)
80{ 81{
81 struct net_device *dev;
82 struct ieee80211_sub_if_data *sdata; 82 struct ieee80211_sub_if_data *sdata;
83 int ret; 83 int ret;
84 84
85 /* we're under RTNL */
86 dev = __dev_get_by_index(&init_net, ifindex);
87 if (!dev)
88 return -ENODEV;
89
90 if (!nl80211_type_check(type)) 85 if (!nl80211_type_check(type))
91 return -EINVAL; 86 return -EINVAL;
92 87
@@ -1177,123 +1172,29 @@ static int ieee80211_scan(struct wiphy *wiphy,
1177static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, 1172static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1178 struct cfg80211_auth_request *req) 1173 struct cfg80211_auth_request *req)
1179{ 1174{
1180 struct ieee80211_sub_if_data *sdata; 1175 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1181
1182 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1183
1184 switch (req->auth_type) {
1185 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1186 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN;
1187 break;
1188 case NL80211_AUTHTYPE_SHARED_KEY:
1189 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_SHARED_KEY;
1190 break;
1191 case NL80211_AUTHTYPE_FT:
1192 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_FT;
1193 break;
1194 case NL80211_AUTHTYPE_NETWORK_EAP:
1195 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_LEAP;
1196 break;
1197 default:
1198 return -EOPNOTSUPP;
1199 }
1200
1201 memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
1202 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
1203 sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
1204
1205 /* TODO: req->chan */
1206 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
1207
1208 if (req->ssid) {
1209 sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
1210 memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
1211 sdata->u.mgd.ssid_len = req->ssid_len;
1212 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
1213 }
1214
1215 kfree(sdata->u.mgd.sme_auth_ie);
1216 sdata->u.mgd.sme_auth_ie = NULL;
1217 sdata->u.mgd.sme_auth_ie_len = 0;
1218 if (req->ie) {
1219 sdata->u.mgd.sme_auth_ie = kmalloc(req->ie_len, GFP_KERNEL);
1220 if (sdata->u.mgd.sme_auth_ie == NULL)
1221 return -ENOMEM;
1222 memcpy(sdata->u.mgd.sme_auth_ie, req->ie, req->ie_len);
1223 sdata->u.mgd.sme_auth_ie_len = req->ie_len;
1224 }
1225
1226 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1227 sdata->u.mgd.state = IEEE80211_STA_MLME_DIRECT_PROBE;
1228 ieee80211_sta_req_auth(sdata);
1229 return 0;
1230} 1176}
1231 1177
1232static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, 1178static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1233 struct cfg80211_assoc_request *req) 1179 struct cfg80211_assoc_request *req)
1234{ 1180{
1235 struct ieee80211_sub_if_data *sdata; 1181 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1236 int ret;
1237
1238 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1239
1240 if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
1241 !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
1242 return -ENOLINK; /* not authenticated */
1243
1244 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
1245 sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
1246
1247 /* TODO: req->chan */
1248 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
1249
1250 if (req->ssid) {
1251 sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
1252 memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
1253 sdata->u.mgd.ssid_len = req->ssid_len;
1254 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
1255 } else
1256 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
1257
1258 ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
1259 if (ret && ret != -EALREADY)
1260 return ret;
1261
1262 if (req->use_mfp) {
1263 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
1264 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
1265 } else {
1266 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
1267 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
1268 }
1269
1270 if (req->control_port)
1271 sdata->u.mgd.flags |= IEEE80211_STA_CONTROL_PORT;
1272 else
1273 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
1274
1275 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1276 sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
1277 ieee80211_sta_req_auth(sdata);
1278 return 0;
1279} 1182}
1280 1183
1281static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, 1184static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1282 struct cfg80211_deauth_request *req) 1185 struct cfg80211_deauth_request *req,
1186 void *cookie)
1283{ 1187{
1284 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1188 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1285 1189 req, cookie);
1286 /* TODO: req->ie, req->peer_addr */
1287 return ieee80211_sta_deauthenticate(sdata, req->reason_code);
1288} 1190}
1289 1191
1290static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, 1192static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1291 struct cfg80211_disassoc_request *req) 1193 struct cfg80211_disassoc_request *req,
1194 void *cookie)
1292{ 1195{
1293 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1196 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1294 1197 req, cookie);
1295 /* TODO: req->ie, req->peer_addr */
1296 return ieee80211_sta_disassociate(sdata, req->reason_code);
1297} 1198}
1298 1199
1299static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, 1200static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
@@ -1374,6 +1275,16 @@ static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1374 return 0; 1275 return 0;
1375} 1276}
1376 1277
1278static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1279 u8 *addr)
1280{
1281 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1282
1283 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1284
1285 return 0;
1286}
1287
1377static void ieee80211_rfkill_poll(struct wiphy *wiphy) 1288static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1378{ 1289{
1379 struct ieee80211_local *local = wiphy_priv(wiphy); 1290 struct ieee80211_local *local = wiphy_priv(wiphy);
@@ -1381,6 +1292,85 @@ static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1381 drv_rfkill_poll(local); 1292 drv_rfkill_poll(local);
1382} 1293}
1383 1294
1295#ifdef CONFIG_NL80211_TESTMODE
1296int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1297{
1298 struct ieee80211_local *local = wiphy_priv(wiphy);
1299
1300 if (!local->ops->testmode_cmd)
1301 return -EOPNOTSUPP;
1302
1303 return local->ops->testmode_cmd(&local->hw, data, len);
1304}
1305#endif
1306
1307static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1308 bool enabled, int timeout)
1309{
1310 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1311 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1312 struct ieee80211_conf *conf = &local->hw.conf;
1313
1314 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1315 return -EOPNOTSUPP;
1316
1317 if (enabled == sdata->u.mgd.powersave &&
1318 timeout == conf->dynamic_ps_timeout)
1319 return 0;
1320
1321 sdata->u.mgd.powersave = enabled;
1322 conf->dynamic_ps_timeout = timeout;
1323
1324 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1325 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1326
1327 ieee80211_recalc_ps(local, -1);
1328
1329 return 0;
1330}
1331
1332static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1333 struct net_device *dev,
1334 const u8 *addr,
1335 const struct cfg80211_bitrate_mask *mask)
1336{
1337 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1338 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1339 int i, err = -EINVAL;
1340 u32 target_rate;
1341 struct ieee80211_supported_band *sband;
1342
1343 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1344
1345 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
1346 * target_rate = X, rate->fixed = 1 means only rate X
1347 * target_rate = X, rate->fixed = 0 means all rates <= X */
1348 sdata->max_ratectrl_rateidx = -1;
1349 sdata->force_unicast_rateidx = -1;
1350
1351 if (mask->fixed)
1352 target_rate = mask->fixed / 100;
1353 else if (mask->maxrate)
1354 target_rate = mask->maxrate / 100;
1355 else
1356 return 0;
1357
1358 for (i=0; i< sband->n_bitrates; i++) {
1359 struct ieee80211_rate *brate = &sband->bitrates[i];
1360 int this_rate = brate->bitrate;
1361
1362 if (target_rate == this_rate) {
1363 sdata->max_ratectrl_rateidx = i;
1364 if (mask->fixed)
1365 sdata->force_unicast_rateidx = i;
1366 err = 0;
1367 break;
1368 }
1369 }
1370
1371 return err;
1372}
1373
1384struct cfg80211_ops mac80211_config_ops = { 1374struct cfg80211_ops mac80211_config_ops = {
1385 .add_virtual_intf = ieee80211_add_iface, 1375 .add_virtual_intf = ieee80211_add_iface,
1386 .del_virtual_intf = ieee80211_del_iface, 1376 .del_virtual_intf = ieee80211_del_iface,
@@ -1422,5 +1412,9 @@ struct cfg80211_ops mac80211_config_ops = {
1422 .set_wiphy_params = ieee80211_set_wiphy_params, 1412 .set_wiphy_params = ieee80211_set_wiphy_params,
1423 .set_tx_power = ieee80211_set_tx_power, 1413 .set_tx_power = ieee80211_set_tx_power,
1424 .get_tx_power = ieee80211_get_tx_power, 1414 .get_tx_power = ieee80211_get_tx_power,
1415 .set_wds_peer = ieee80211_set_wds_peer,
1425 .rfkill_poll = ieee80211_rfkill_poll, 1416 .rfkill_poll = ieee80211_rfkill_poll,
1417 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
1418 .set_power_mgmt = ieee80211_set_power_mgmt,
1419 .set_bitrate_mask = ieee80211_set_bitrate_mask,
1426}; 1420};
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index e3420329f4e6..e9ec6cae2d39 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -95,33 +95,9 @@ IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC);
95IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC); 95IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC);
96 96
97/* STA attributes */ 97/* STA attributes */
98IEEE80211_IF_FILE(state, u.mgd.state, DEC);
99IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC); 98IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
100IEEE80211_IF_FILE(prev_bssid, u.mgd.prev_bssid, MAC);
101IEEE80211_IF_FILE(ssid_len, u.mgd.ssid_len, SIZE);
102IEEE80211_IF_FILE(aid, u.mgd.aid, DEC); 99IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
103IEEE80211_IF_FILE(ap_capab, u.mgd.ap_capab, HEX);
104IEEE80211_IF_FILE(capab, u.mgd.capab, HEX); 100IEEE80211_IF_FILE(capab, u.mgd.capab, HEX);
105IEEE80211_IF_FILE(extra_ie_len, u.mgd.extra_ie_len, SIZE);
106IEEE80211_IF_FILE(auth_tries, u.mgd.auth_tries, DEC);
107IEEE80211_IF_FILE(assoc_tries, u.mgd.assoc_tries, DEC);
108IEEE80211_IF_FILE(auth_algs, u.mgd.auth_algs, HEX);
109IEEE80211_IF_FILE(auth_alg, u.mgd.auth_alg, DEC);
110IEEE80211_IF_FILE(auth_transaction, u.mgd.auth_transaction, DEC);
111
112static ssize_t ieee80211_if_fmt_flags(
113 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
114{
115 return scnprintf(buf, buflen, "%s%s%s%s%s%s%s\n",
116 sdata->u.mgd.flags & IEEE80211_STA_SSID_SET ? "SSID\n" : "",
117 sdata->u.mgd.flags & IEEE80211_STA_BSSID_SET ? "BSSID\n" : "",
118 sdata->u.mgd.flags & IEEE80211_STA_PREV_BSSID_SET ? "prev BSSID\n" : "",
119 sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED ? "AUTH\n" : "",
120 sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED ? "ASSOC\n" : "",
121 sdata->u.mgd.flags & IEEE80211_STA_PROBEREQ_POLL ? "PROBEREQ POLL\n" : "",
122 sdata->vif.bss_conf.use_cts_prot ? "CTS prot\n" : "");
123}
124__IEEE80211_IF_FILE(flags);
125 101
126/* AP attributes */ 102/* AP attributes */
127IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC); 103IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
@@ -184,20 +160,9 @@ static void add_sta_files(struct ieee80211_sub_if_data *sdata)
184 DEBUGFS_ADD(force_unicast_rateidx, sta); 160 DEBUGFS_ADD(force_unicast_rateidx, sta);
185 DEBUGFS_ADD(max_ratectrl_rateidx, sta); 161 DEBUGFS_ADD(max_ratectrl_rateidx, sta);
186 162
187 DEBUGFS_ADD(state, sta);
188 DEBUGFS_ADD(bssid, sta); 163 DEBUGFS_ADD(bssid, sta);
189 DEBUGFS_ADD(prev_bssid, sta);
190 DEBUGFS_ADD(ssid_len, sta);
191 DEBUGFS_ADD(aid, sta); 164 DEBUGFS_ADD(aid, sta);
192 DEBUGFS_ADD(ap_capab, sta);
193 DEBUGFS_ADD(capab, sta); 165 DEBUGFS_ADD(capab, sta);
194 DEBUGFS_ADD(extra_ie_len, sta);
195 DEBUGFS_ADD(auth_tries, sta);
196 DEBUGFS_ADD(assoc_tries, sta);
197 DEBUGFS_ADD(auth_algs, sta);
198 DEBUGFS_ADD(auth_alg, sta);
199 DEBUGFS_ADD(auth_transaction, sta);
200 DEBUGFS_ADD(flags, sta);
201} 166}
202 167
203static void add_ap_files(struct ieee80211_sub_if_data *sdata) 168static void add_ap_files(struct ieee80211_sub_if_data *sdata)
@@ -317,20 +282,9 @@ static void del_sta_files(struct ieee80211_sub_if_data *sdata)
317 DEBUGFS_DEL(force_unicast_rateidx, sta); 282 DEBUGFS_DEL(force_unicast_rateidx, sta);
318 DEBUGFS_DEL(max_ratectrl_rateidx, sta); 283 DEBUGFS_DEL(max_ratectrl_rateidx, sta);
319 284
320 DEBUGFS_DEL(state, sta);
321 DEBUGFS_DEL(bssid, sta); 285 DEBUGFS_DEL(bssid, sta);
322 DEBUGFS_DEL(prev_bssid, sta);
323 DEBUGFS_DEL(ssid_len, sta);
324 DEBUGFS_DEL(aid, sta); 286 DEBUGFS_DEL(aid, sta);
325 DEBUGFS_DEL(ap_capab, sta);
326 DEBUGFS_DEL(capab, sta); 287 DEBUGFS_DEL(capab, sta);
327 DEBUGFS_DEL(extra_ie_len, sta);
328 DEBUGFS_DEL(auth_tries, sta);
329 DEBUGFS_DEL(assoc_tries, sta);
330 DEBUGFS_DEL(auth_algs, sta);
331 DEBUGFS_DEL(auth_alg, sta);
332 DEBUGFS_DEL(auth_transaction, sta);
333 DEBUGFS_DEL(flags, sta);
334} 288}
335 289
336static void del_ap_files(struct ieee80211_sub_if_data *sdata) 290static void del_ap_files(struct ieee80211_sub_if_data *sdata)
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index 90230c718b5b..33a2e892115b 100644
--- a/net/mac80211/debugfs_sta.c
+++ b/net/mac80211/debugfs_sta.c
@@ -120,45 +120,38 @@ STA_OPS(last_seq_ctrl);
120static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf, 120static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
121 size_t count, loff_t *ppos) 121 size_t count, loff_t *ppos)
122{ 122{
123 char buf[768], *p = buf; 123 char buf[30 + STA_TID_NUM * 70], *p = buf;
124 int i; 124 int i;
125 struct sta_info *sta = file->private_data; 125 struct sta_info *sta = file->private_data;
126 p += scnprintf(p, sizeof(buf)+buf-p, "Agg state for STA is:\n");
127 p += scnprintf(p, sizeof(buf)+buf-p, " STA next dialog_token is %d \n "
128 "TIDs info is: \n TID :",
129 (sta->ampdu_mlme.dialog_token_allocator + 1));
130 for (i = 0; i < STA_TID_NUM; i++)
131 p += scnprintf(p, sizeof(buf)+buf-p, "%5d", i);
132
133 p += scnprintf(p, sizeof(buf)+buf-p, "\n RX :");
134 for (i = 0; i < STA_TID_NUM; i++)
135 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
136 sta->ampdu_mlme.tid_state_rx[i]);
137
138 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
139 for (i = 0; i < STA_TID_NUM; i++)
140 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
141 sta->ampdu_mlme.tid_state_rx[i] ?
142 sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
143
144 p += scnprintf(p, sizeof(buf)+buf-p, "\n TX :");
145 for (i = 0; i < STA_TID_NUM; i++)
146 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
147 sta->ampdu_mlme.tid_state_tx[i]);
148
149 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
150 for (i = 0; i < STA_TID_NUM; i++)
151 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
152 sta->ampdu_mlme.tid_state_tx[i] ?
153 sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
154
155 p += scnprintf(p, sizeof(buf)+buf-p, "\n SSN :");
156 for (i = 0; i < STA_TID_NUM; i++)
157 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
158 sta->ampdu_mlme.tid_state_tx[i] ?
159 sta->ampdu_mlme.tid_tx[i]->ssn : 0);
160 126
161 p += scnprintf(p, sizeof(buf)+buf-p, "\n"); 127 spin_lock_bh(&sta->lock);
128 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
129 sta->ampdu_mlme.dialog_token_allocator + 1);
130 for (i = 0; i < STA_TID_NUM; i++) {
131 p += scnprintf(p, sizeof(buf)+buf-p, "TID %02d:", i);
132 p += scnprintf(p, sizeof(buf)+buf-p, " RX=%x",
133 sta->ampdu_mlme.tid_state_rx[i]);
134 p += scnprintf(p, sizeof(buf)+buf-p, "/DTKN=%#.2x",
135 sta->ampdu_mlme.tid_state_rx[i] ?
136 sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
137 p += scnprintf(p, sizeof(buf)+buf-p, "/SSN=%#.3x",
138 sta->ampdu_mlme.tid_state_rx[i] ?
139 sta->ampdu_mlme.tid_rx[i]->ssn : 0);
140
141 p += scnprintf(p, sizeof(buf)+buf-p, " TX=%x",
142 sta->ampdu_mlme.tid_state_tx[i]);
143 p += scnprintf(p, sizeof(buf)+buf-p, "/DTKN=%#.2x",
144 sta->ampdu_mlme.tid_state_tx[i] ?
145 sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
146 p += scnprintf(p, sizeof(buf)+buf-p, "/SSN=%#.3x",
147 sta->ampdu_mlme.tid_state_tx[i] ?
148 sta->ampdu_mlme.tid_tx[i]->ssn : 0);
149 p += scnprintf(p, sizeof(buf)+buf-p, "/pending=%03d",
150 sta->ampdu_mlme.tid_state_tx[i] ?
151 skb_queue_len(&sta->ampdu_mlme.tid_tx[i]->pending) : 0);
152 p += scnprintf(p, sizeof(buf)+buf-p, "\n");
153 }
154 spin_unlock_bh(&sta->lock);
162 155
163 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf); 156 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
164} 157}
@@ -203,6 +196,22 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)
203 DEBUGFS_ADD(inactive_ms); 196 DEBUGFS_ADD(inactive_ms);
204 DEBUGFS_ADD(last_seq_ctrl); 197 DEBUGFS_ADD(last_seq_ctrl);
205 DEBUGFS_ADD(agg_status); 198 DEBUGFS_ADD(agg_status);
199 DEBUGFS_ADD(dev);
200 DEBUGFS_ADD(rx_packets);
201 DEBUGFS_ADD(tx_packets);
202 DEBUGFS_ADD(rx_bytes);
203 DEBUGFS_ADD(tx_bytes);
204 DEBUGFS_ADD(rx_duplicates);
205 DEBUGFS_ADD(rx_fragments);
206 DEBUGFS_ADD(rx_dropped);
207 DEBUGFS_ADD(tx_fragments);
208 DEBUGFS_ADD(tx_filtered);
209 DEBUGFS_ADD(tx_retry_failed);
210 DEBUGFS_ADD(tx_retry_count);
211 DEBUGFS_ADD(last_signal);
212 DEBUGFS_ADD(last_qual);
213 DEBUGFS_ADD(last_noise);
214 DEBUGFS_ADD(wep_weak_iv_count);
206} 215}
207 216
208void ieee80211_sta_debugfs_remove(struct sta_info *sta) 217void ieee80211_sta_debugfs_remove(struct sta_info *sta)
@@ -212,6 +221,23 @@ void ieee80211_sta_debugfs_remove(struct sta_info *sta)
212 DEBUGFS_DEL(inactive_ms); 221 DEBUGFS_DEL(inactive_ms);
213 DEBUGFS_DEL(last_seq_ctrl); 222 DEBUGFS_DEL(last_seq_ctrl);
214 DEBUGFS_DEL(agg_status); 223 DEBUGFS_DEL(agg_status);
224 DEBUGFS_DEL(aid);
225 DEBUGFS_DEL(dev);
226 DEBUGFS_DEL(rx_packets);
227 DEBUGFS_DEL(tx_packets);
228 DEBUGFS_DEL(rx_bytes);
229 DEBUGFS_DEL(tx_bytes);
230 DEBUGFS_DEL(rx_duplicates);
231 DEBUGFS_DEL(rx_fragments);
232 DEBUGFS_DEL(rx_dropped);
233 DEBUGFS_DEL(tx_fragments);
234 DEBUGFS_DEL(tx_filtered);
235 DEBUGFS_DEL(tx_retry_failed);
236 DEBUGFS_DEL(tx_retry_count);
237 DEBUGFS_DEL(last_signal);
238 DEBUGFS_DEL(last_qual);
239 DEBUGFS_DEL(last_noise);
240 DEBUGFS_DEL(wep_weak_iv_count);
215 241
216 debugfs_remove(sta->debugfs.dir); 242 debugfs_remove(sta->debugfs.dir);
217 sta->debugfs.dir = NULL; 243 sta->debugfs.dir = NULL;
diff --git a/net/mac80211/event.c b/net/mac80211/event.c
index f288d01a6344..01ae759518f6 100644
--- a/net/mac80211/event.c
+++ b/net/mac80211/event.c
@@ -7,8 +7,7 @@
7 * 7 *
8 * mac80211 - events 8 * mac80211 - events
9 */ 9 */
10 10#include <net/cfg80211.h>
11#include <net/iw_handler.h>
12#include "ieee80211_i.h" 11#include "ieee80211_i.h"
13 12
14/* 13/*
@@ -17,26 +16,12 @@
17 * driver or is still in the frame), it should provide that information. 16 * driver or is still in the frame), it should provide that information.
18 */ 17 */
19void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 18void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
20 struct ieee80211_hdr *hdr, const u8 *tsc) 19 struct ieee80211_hdr *hdr, const u8 *tsc,
20 gfp_t gfp)
21{ 21{
22 union iwreq_data wrqu;
23 char *buf = kmalloc(128, GFP_ATOMIC);
24
25 if (buf) {
26 /* TODO: needed parameters: count, key type, TSC */
27 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
28 "keyid=%d %scast addr=%pM)",
29 keyidx, hdr->addr1[0] & 0x01 ? "broad" : "uni",
30 hdr->addr2);
31 memset(&wrqu, 0, sizeof(wrqu));
32 wrqu.data.length = strlen(buf);
33 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
34 kfree(buf);
35 }
36
37 cfg80211_michael_mic_failure(sdata->dev, hdr->addr2, 22 cfg80211_michael_mic_failure(sdata->dev, hdr->addr2,
38 (hdr->addr1[0] & 0x01) ? 23 (hdr->addr1[0] & 0x01) ?
39 NL80211_KEYTYPE_GROUP : 24 NL80211_KEYTYPE_GROUP :
40 NL80211_KEYTYPE_PAIRWISE, 25 NL80211_KEYTYPE_PAIRWISE,
41 keyidx, tsc); 26 keyidx, tsc, gfp);
42} 27}
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 0b30277eb366..15d5a53b59a8 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -705,7 +705,7 @@ static void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
705 struct ieee80211_mgmt *mgmt; 705 struct ieee80211_mgmt *mgmt;
706 u16 fc; 706 u16 fc;
707 707
708 rx_status = (struct ieee80211_rx_status *) skb->cb; 708 rx_status = IEEE80211_SKB_RXCB(skb);
709 mgmt = (struct ieee80211_mgmt *) skb->data; 709 mgmt = (struct ieee80211_mgmt *) skb->data;
710 fc = le16_to_cpu(mgmt->frame_control); 710 fc = le16_to_cpu(mgmt->frame_control);
711 711
@@ -836,8 +836,7 @@ void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
836} 836}
837 837
838ieee80211_rx_result 838ieee80211_rx_result
839ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 839ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
840 struct ieee80211_rx_status *rx_status)
841{ 840{
842 struct ieee80211_local *local = sdata->local; 841 struct ieee80211_local *local = sdata->local;
843 struct ieee80211_mgmt *mgmt; 842 struct ieee80211_mgmt *mgmt;
@@ -852,7 +851,6 @@ ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
852 switch (fc & IEEE80211_FCTL_STYPE) { 851 switch (fc & IEEE80211_FCTL_STYPE) {
853 case IEEE80211_STYPE_PROBE_RESP: 852 case IEEE80211_STYPE_PROBE_RESP:
854 case IEEE80211_STYPE_BEACON: 853 case IEEE80211_STYPE_BEACON:
855 memcpy(skb->cb, rx_status, sizeof(*rx_status));
856 case IEEE80211_STYPE_PROBE_REQ: 854 case IEEE80211_STYPE_PROBE_REQ:
857 case IEEE80211_STYPE_AUTH: 855 case IEEE80211_STYPE_AUTH:
858 skb_queue_tail(&sdata->u.ibss.skb_queue, skb); 856 skb_queue_tail(&sdata->u.ibss.skb_queue, skb);
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 68eb5052179a..327aabc07abe 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -227,35 +227,44 @@ struct mesh_preq_queue {
227 u8 flags; 227 u8 flags;
228}; 228};
229 229
230enum ieee80211_mgd_state {
231 IEEE80211_MGD_STATE_IDLE,
232 IEEE80211_MGD_STATE_PROBE,
233 IEEE80211_MGD_STATE_AUTH,
234 IEEE80211_MGD_STATE_ASSOC,
235};
236
237struct ieee80211_mgd_work {
238 struct list_head list;
239 struct ieee80211_bss *bss;
240 int ie_len;
241 u8 prev_bssid[ETH_ALEN];
242 u8 ssid[IEEE80211_MAX_SSID_LEN];
243 u8 ssid_len;
244 unsigned long timeout;
245 enum ieee80211_mgd_state state;
246 u16 auth_alg, auth_transaction;
247
248 int tries;
249
250 /* must be last */
251 u8 ie[0]; /* for auth or assoc frame, not probe */
252};
253
230/* flags used in struct ieee80211_if_managed.flags */ 254/* flags used in struct ieee80211_if_managed.flags */
231#define IEEE80211_STA_SSID_SET BIT(0) 255enum ieee80211_sta_flags {
232#define IEEE80211_STA_BSSID_SET BIT(1) 256 IEEE80211_STA_PROBEREQ_POLL = BIT(3),
233#define IEEE80211_STA_PREV_BSSID_SET BIT(2) 257 IEEE80211_STA_CONTROL_PORT = BIT(4),
234#define IEEE80211_STA_AUTHENTICATED BIT(3) 258 IEEE80211_STA_WMM_ENABLED = BIT(5),
235#define IEEE80211_STA_ASSOCIATED BIT(4) 259 IEEE80211_STA_DISABLE_11N = BIT(6),
236#define IEEE80211_STA_PROBEREQ_POLL BIT(5) 260 IEEE80211_STA_CSA_RECEIVED = BIT(7),
237#define IEEE80211_STA_CREATE_IBSS BIT(6) 261 IEEE80211_STA_MFP_ENABLED = BIT(8),
238#define IEEE80211_STA_CONTROL_PORT BIT(7) 262};
239#define IEEE80211_STA_WMM_ENABLED BIT(8)
240/* hole at 9, please re-use */
241#define IEEE80211_STA_AUTO_SSID_SEL BIT(10)
242#define IEEE80211_STA_AUTO_BSSID_SEL BIT(11)
243#define IEEE80211_STA_AUTO_CHANNEL_SEL BIT(12)
244#define IEEE80211_STA_PRIVACY_INVOKED BIT(13)
245#define IEEE80211_STA_TKIP_WEP_USED BIT(14)
246#define IEEE80211_STA_CSA_RECEIVED BIT(15)
247#define IEEE80211_STA_MFP_ENABLED BIT(16)
248#define IEEE80211_STA_EXT_SME BIT(17)
249/* flags for MLME request */
250#define IEEE80211_STA_REQ_SCAN 0
251#define IEEE80211_STA_REQ_AUTH 1
252#define IEEE80211_STA_REQ_RUN 2
253 263
254/* bitfield of allowed auth algs */ 264/* flags for MLME request */
255#define IEEE80211_AUTH_ALG_OPEN BIT(0) 265enum ieee80211_sta_request {
256#define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1) 266 IEEE80211_STA_REQ_SCAN,
257#define IEEE80211_AUTH_ALG_LEAP BIT(2) 267};
258#define IEEE80211_AUTH_ALG_FT BIT(3)
259 268
260struct ieee80211_if_managed { 269struct ieee80211_if_managed {
261 struct timer_list timer; 270 struct timer_list timer;
@@ -264,49 +273,26 @@ struct ieee80211_if_managed {
264 struct work_struct chswitch_work; 273 struct work_struct chswitch_work;
265 struct work_struct beacon_loss_work; 274 struct work_struct beacon_loss_work;
266 275
267 u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN]; 276 struct mutex mtx;
268 277 struct ieee80211_bss *associated;
269 u8 ssid[IEEE80211_MAX_SSID_LEN]; 278 struct list_head work_list;
270 size_t ssid_len;
271 279
272 enum { 280 u8 bssid[ETH_ALEN];
273 IEEE80211_STA_MLME_DISABLED,
274 IEEE80211_STA_MLME_DIRECT_PROBE,
275 IEEE80211_STA_MLME_AUTHENTICATE,
276 IEEE80211_STA_MLME_ASSOCIATE,
277 IEEE80211_STA_MLME_ASSOCIATED,
278 } state;
279 281
280 u16 aid; 282 u16 aid;
281 u16 ap_capab, capab; 283 u16 capab;
282 u8 *extra_ie; /* to be added to the end of AssocReq */
283 size_t extra_ie_len;
284
285 /* The last AssocReq/Resp IEs */
286 u8 *assocreq_ies, *assocresp_ies;
287 size_t assocreq_ies_len, assocresp_ies_len;
288 284
289 struct sk_buff_head skb_queue; 285 struct sk_buff_head skb_queue;
290 286
291 int assoc_scan_tries; /* number of scans done pre-association */
292 int direct_probe_tries; /* retries for direct probes */
293 int auth_tries; /* retries for auth req */
294 int assoc_tries; /* retries for assoc req */
295
296 unsigned long timers_running; /* used for quiesce/restart */ 287 unsigned long timers_running; /* used for quiesce/restart */
297 bool powersave; /* powersave requested for this iface */ 288 bool powersave; /* powersave requested for this iface */
298 289
299 unsigned long request; 290 unsigned long request;
300 291
301 unsigned long last_probe;
302 unsigned long last_beacon; 292 unsigned long last_beacon;
303 293
304 unsigned int flags; 294 unsigned int flags;
305 295
306 unsigned int auth_algs; /* bitfield of allowed auth algs */
307 int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
308 int auth_transaction;
309
310 u32 beacon_crc; 296 u32 beacon_crc;
311 297
312 enum { 298 enum {
@@ -316,10 +302,6 @@ struct ieee80211_if_managed {
316 } mfp; /* management frame protection */ 302 } mfp; /* management frame protection */
317 303
318 int wmm_last_param_set; 304 int wmm_last_param_set;
319
320 /* Extra IE data for management frames */
321 u8 *sme_auth_ie;
322 size_t sme_auth_ie_len;
323}; 305};
324 306
325enum ieee80211_ibss_request { 307enum ieee80211_ibss_request {
@@ -478,20 +460,9 @@ struct ieee80211_sub_if_data {
478 union { 460 union {
479 struct { 461 struct {
480 struct dentry *drop_unencrypted; 462 struct dentry *drop_unencrypted;
481 struct dentry *state;
482 struct dentry *bssid; 463 struct dentry *bssid;
483 struct dentry *prev_bssid;
484 struct dentry *ssid_len;
485 struct dentry *aid; 464 struct dentry *aid;
486 struct dentry *ap_capab;
487 struct dentry *capab; 465 struct dentry *capab;
488 struct dentry *extra_ie_len;
489 struct dentry *auth_tries;
490 struct dentry *assoc_tries;
491 struct dentry *auth_algs;
492 struct dentry *auth_alg;
493 struct dentry *auth_transaction;
494 struct dentry *flags;
495 struct dentry *force_unicast_rateidx; 466 struct dentry *force_unicast_rateidx;
496 struct dentry *max_ratectrl_rateidx; 467 struct dentry *max_ratectrl_rateidx;
497 } sta; 468 } sta;
@@ -942,16 +913,18 @@ extern const struct iw_handler_def ieee80211_iw_handler_def;
942 913
943/* STA code */ 914/* STA code */
944void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata); 915void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata);
916int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
917 struct cfg80211_auth_request *req);
918int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
919 struct cfg80211_assoc_request *req);
920int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
921 struct cfg80211_deauth_request *req,
922 void *cookie);
923int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
924 struct cfg80211_disassoc_request *req,
925 void *cookie);
945ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, 926ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
946 struct sk_buff *skb, 927 struct sk_buff *skb);
947 struct ieee80211_rx_status *rx_status);
948int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata);
949int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len);
950int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len);
951int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid);
952void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata);
953int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason);
954int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason);
955void ieee80211_send_pspoll(struct ieee80211_local *local, 928void ieee80211_send_pspoll(struct ieee80211_local *local,
956 struct ieee80211_sub_if_data *sdata); 929 struct ieee80211_sub_if_data *sdata);
957void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency); 930void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency);
@@ -967,8 +940,7 @@ void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata);
967void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local); 940void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local);
968void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata); 941void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata);
969ieee80211_rx_result 942ieee80211_rx_result
970ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 943ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
971 struct ieee80211_rx_status *rx_status);
972struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, 944struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
973 u8 *bssid, u8 *addr, u32 supp_rates); 945 u8 *bssid, u8 *addr, u32 supp_rates);
974int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, 946int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
@@ -983,16 +955,9 @@ int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
983 const u8 *ssid, u8 ssid_len); 955 const u8 *ssid, u8 ssid_len);
984int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, 956int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
985 struct cfg80211_scan_request *req); 957 struct cfg80211_scan_request *req);
986int ieee80211_scan_results(struct ieee80211_local *local,
987 struct iw_request_info *info,
988 char *buf, size_t len);
989void ieee80211_scan_cancel(struct ieee80211_local *local); 958void ieee80211_scan_cancel(struct ieee80211_local *local);
990ieee80211_rx_result 959ieee80211_rx_result
991ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, 960ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
992 struct sk_buff *skb,
993 struct ieee80211_rx_status *rx_status);
994int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
995 const char *ie, size_t len);
996 961
997void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local); 962void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local);
998struct ieee80211_bss * 963struct ieee80211_bss *
@@ -1008,8 +973,6 @@ ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
1008 u8 *ssid, u8 ssid_len); 973 u8 *ssid, u8 ssid_len);
1009void ieee80211_rx_bss_put(struct ieee80211_local *local, 974void ieee80211_rx_bss_put(struct ieee80211_local *local,
1010 struct ieee80211_bss *bss); 975 struct ieee80211_bss *bss);
1011void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid,
1012 int freq, u8 *ssid, u8 ssid_len);
1013 976
1014/* interface handling */ 977/* interface handling */
1015int ieee80211_if_add(struct ieee80211_local *local, const char *name, 978int ieee80211_if_add(struct ieee80211_local *local, const char *name,
@@ -1092,7 +1055,8 @@ u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
1092int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, 1055int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
1093 int rate, int erp, int short_preamble); 1056 int rate, int erp, int short_preamble);
1094void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 1057void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
1095 struct ieee80211_hdr *hdr, const u8 *tsc); 1058 struct ieee80211_hdr *hdr, const u8 *tsc,
1059 gfp_t gfp);
1096void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata); 1060void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata);
1097void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 1061void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
1098 int encrypt); 1062 int encrypt);
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index b7c8a4484298..4839a2d97a3b 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -233,9 +233,6 @@ static int ieee80211_open(struct net_device *dev)
233 ieee80211_configure_filter(local); 233 ieee80211_configure_filter(local);
234 netif_addr_unlock_bh(local->mdev); 234 netif_addr_unlock_bh(local->mdev);
235 break; 235 break;
236 case NL80211_IFTYPE_STATION:
237 sdata->u.mgd.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
238 /* fall through */
239 default: 236 default:
240 conf.vif = &sdata->vif; 237 conf.vif = &sdata->vif;
241 conf.type = sdata->vif.type; 238 conf.type = sdata->vif.type;
@@ -366,18 +363,6 @@ static int ieee80211_stop(struct net_device *dev)
366 rcu_read_unlock(); 363 rcu_read_unlock();
367 364
368 /* 365 /*
369 * Announce that we are leaving the network, in case we are a
370 * station interface type. This must be done before removing
371 * all stations associated with sta_info_flush, otherwise STA
372 * information will be gone and no announce being done.
373 */
374 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
375 if (sdata->u.mgd.state != IEEE80211_STA_MLME_DISABLED)
376 ieee80211_sta_deauthenticate(sdata,
377 WLAN_REASON_DEAUTH_LEAVING);
378 }
379
380 /*
381 * Remove all stations associated with this interface. 366 * Remove all stations associated with this interface.
382 * 367 *
383 * This must be done before calling ops->remove_interface() 368 * This must be done before calling ops->remove_interface()
@@ -462,7 +447,6 @@ static int ieee80211_stop(struct net_device *dev)
462 netif_addr_unlock_bh(local->mdev); 447 netif_addr_unlock_bh(local->mdev);
463 break; 448 break;
464 case NL80211_IFTYPE_STATION: 449 case NL80211_IFTYPE_STATION:
465 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
466 del_timer_sync(&sdata->u.mgd.chswitch_timer); 450 del_timer_sync(&sdata->u.mgd.chswitch_timer);
467 del_timer_sync(&sdata->u.mgd.timer); 451 del_timer_sync(&sdata->u.mgd.timer);
468 /* 452 /*
@@ -485,12 +469,6 @@ static int ieee80211_stop(struct net_device *dev)
485 */ 469 */
486 synchronize_rcu(); 470 synchronize_rcu();
487 skb_queue_purge(&sdata->u.mgd.skb_queue); 471 skb_queue_purge(&sdata->u.mgd.skb_queue);
488
489 sdata->u.mgd.flags &= ~(IEEE80211_STA_PRIVACY_INVOKED |
490 IEEE80211_STA_TKIP_WEP_USED);
491 kfree(sdata->u.mgd.extra_ie);
492 sdata->u.mgd.extra_ie = NULL;
493 sdata->u.mgd.extra_ie_len = 0;
494 /* fall through */ 472 /* fall through */
495 case NL80211_IFTYPE_ADHOC: 473 case NL80211_IFTYPE_ADHOC:
496 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 474 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
@@ -652,11 +630,6 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
652 kfree_skb(sdata->u.ibss.presp); 630 kfree_skb(sdata->u.ibss.presp);
653 break; 631 break;
654 case NL80211_IFTYPE_STATION: 632 case NL80211_IFTYPE_STATION:
655 kfree(sdata->u.mgd.extra_ie);
656 kfree(sdata->u.mgd.assocreq_ies);
657 kfree(sdata->u.mgd.assocresp_ies);
658 kfree(sdata->u.mgd.sme_auth_ie);
659 break;
660 case NL80211_IFTYPE_WDS: 633 case NL80211_IFTYPE_WDS:
661 case NL80211_IFTYPE_AP_VLAN: 634 case NL80211_IFTYPE_AP_VLAN:
662 case NL80211_IFTYPE_MONITOR: 635 case NL80211_IFTYPE_MONITOR:
@@ -939,7 +912,8 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
939 continue; 912 continue;
940 /* do not count disabled managed interfaces */ 913 /* do not count disabled managed interfaces */
941 if (sdata->vif.type == NL80211_IFTYPE_STATION && 914 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
942 sdata->u.mgd.state == IEEE80211_STA_MLME_DISABLED) 915 !sdata->u.mgd.associated &&
916 list_empty(&sdata->u.mgd.work_list))
943 continue; 917 continue;
944 /* do not count unused IBSS interfaces */ 918 /* do not count unused IBSS interfaces */
945 if (sdata->vif.type == NL80211_IFTYPE_ADHOC && 919 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index ce267565e180..659a42d529e3 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -67,6 +67,8 @@ static DECLARE_WORK(todo_work, key_todo);
67 * 67 *
68 * @key: key to add to do item for 68 * @key: key to add to do item for
69 * @flag: todo flag(s) 69 * @flag: todo flag(s)
70 *
71 * Must be called with IRQs or softirqs disabled.
70 */ 72 */
71static void add_todo(struct ieee80211_key *key, u32 flag) 73static void add_todo(struct ieee80211_key *key, u32 flag)
72{ 74{
@@ -140,9 +142,9 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
140 ret = drv_set_key(key->local, SET_KEY, &sdata->vif, sta, &key->conf); 142 ret = drv_set_key(key->local, SET_KEY, &sdata->vif, sta, &key->conf);
141 143
142 if (!ret) { 144 if (!ret) {
143 spin_lock(&todo_lock); 145 spin_lock_bh(&todo_lock);
144 key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE; 146 key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
145 spin_unlock(&todo_lock); 147 spin_unlock_bh(&todo_lock);
146 } 148 }
147 149
148 if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP) 150 if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP)
@@ -164,12 +166,12 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
164 if (!key || !key->local->ops->set_key) 166 if (!key || !key->local->ops->set_key)
165 return; 167 return;
166 168
167 spin_lock(&todo_lock); 169 spin_lock_bh(&todo_lock);
168 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) { 170 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
169 spin_unlock(&todo_lock); 171 spin_unlock_bh(&todo_lock);
170 return; 172 return;
171 } 173 }
172 spin_unlock(&todo_lock); 174 spin_unlock_bh(&todo_lock);
173 175
174 sta = get_sta_for_key(key); 176 sta = get_sta_for_key(key);
175 sdata = key->sdata; 177 sdata = key->sdata;
@@ -188,9 +190,9 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
188 wiphy_name(key->local->hw.wiphy), 190 wiphy_name(key->local->hw.wiphy),
189 key->conf.keyidx, sta ? sta->addr : bcast_addr, ret); 191 key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);
190 192
191 spin_lock(&todo_lock); 193 spin_lock_bh(&todo_lock);
192 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; 194 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
193 spin_unlock(&todo_lock); 195 spin_unlock_bh(&todo_lock);
194} 196}
195 197
196static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, 198static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata,
@@ -437,14 +439,14 @@ void ieee80211_key_link(struct ieee80211_key *key,
437 439
438 __ieee80211_key_replace(sdata, sta, old_key, key); 440 __ieee80211_key_replace(sdata, sta, old_key, key);
439 441
440 spin_unlock_irqrestore(&sdata->local->key_lock, flags);
441
442 /* free old key later */ 442 /* free old key later */
443 add_todo(old_key, KEY_FLAG_TODO_DELETE); 443 add_todo(old_key, KEY_FLAG_TODO_DELETE);
444 444
445 add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS); 445 add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS);
446 if (netif_running(sdata->dev)) 446 if (netif_running(sdata->dev))
447 add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD); 447 add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD);
448
449 spin_unlock_irqrestore(&sdata->local->key_lock, flags);
448} 450}
449 451
450static void __ieee80211_key_free(struct ieee80211_key *key) 452static void __ieee80211_key_free(struct ieee80211_key *key)
@@ -547,7 +549,7 @@ static void __ieee80211_key_todo(void)
547 */ 549 */
548 synchronize_rcu(); 550 synchronize_rcu();
549 551
550 spin_lock(&todo_lock); 552 spin_lock_bh(&todo_lock);
551 while (!list_empty(&todo_list)) { 553 while (!list_empty(&todo_list)) {
552 key = list_first_entry(&todo_list, struct ieee80211_key, todo); 554 key = list_first_entry(&todo_list, struct ieee80211_key, todo);
553 list_del_init(&key->todo); 555 list_del_init(&key->todo);
@@ -558,7 +560,7 @@ static void __ieee80211_key_todo(void)
558 KEY_FLAG_TODO_HWACCEL_REMOVE | 560 KEY_FLAG_TODO_HWACCEL_REMOVE |
559 KEY_FLAG_TODO_DELETE); 561 KEY_FLAG_TODO_DELETE);
560 key->flags &= ~todoflags; 562 key->flags &= ~todoflags;
561 spin_unlock(&todo_lock); 563 spin_unlock_bh(&todo_lock);
562 564
563 work_done = false; 565 work_done = false;
564 566
@@ -591,9 +593,9 @@ static void __ieee80211_key_todo(void)
591 593
592 WARN_ON(!work_done); 594 WARN_ON(!work_done);
593 595
594 spin_lock(&todo_lock); 596 spin_lock_bh(&todo_lock);
595 } 597 }
596 spin_unlock(&todo_lock); 598 spin_unlock_bh(&todo_lock);
597} 599}
598 600
599void ieee80211_key_todo(void) 601void ieee80211_key_todo(void)
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 092a017b237e..5b69f5f07299 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -330,19 +330,16 @@ static void ieee80211_tasklet_handler(unsigned long data)
330{ 330{
331 struct ieee80211_local *local = (struct ieee80211_local *) data; 331 struct ieee80211_local *local = (struct ieee80211_local *) data;
332 struct sk_buff *skb; 332 struct sk_buff *skb;
333 struct ieee80211_rx_status rx_status;
334 struct ieee80211_ra_tid *ra_tid; 333 struct ieee80211_ra_tid *ra_tid;
335 334
336 while ((skb = skb_dequeue(&local->skb_queue)) || 335 while ((skb = skb_dequeue(&local->skb_queue)) ||
337 (skb = skb_dequeue(&local->skb_queue_unreliable))) { 336 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
338 switch (skb->pkt_type) { 337 switch (skb->pkt_type) {
339 case IEEE80211_RX_MSG: 338 case IEEE80211_RX_MSG:
340 /* status is in skb->cb */
341 memcpy(&rx_status, skb->cb, sizeof(rx_status));
342 /* Clear skb->pkt_type in order to not confuse kernel 339 /* Clear skb->pkt_type in order to not confuse kernel
343 * netstack. */ 340 * netstack. */
344 skb->pkt_type = 0; 341 skb->pkt_type = 0;
345 __ieee80211_rx(local_to_hw(local), skb, &rx_status); 342 ieee80211_rx(local_to_hw(local), skb);
346 break; 343 break;
347 case IEEE80211_TX_STATUS_MSG: 344 case IEEE80211_TX_STATUS_MSG:
348 skb->pkt_type = 0; 345 skb->pkt_type = 0;
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 11cf45bce38a..542ea025494e 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -568,7 +568,7 @@ static void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
568 568
569 ifmsh = &sdata->u.mesh; 569 ifmsh = &sdata->u.mesh;
570 570
571 rx_status = (struct ieee80211_rx_status *) skb->cb; 571 rx_status = IEEE80211_SKB_RXCB(skb);
572 mgmt = (struct ieee80211_mgmt *) skb->data; 572 mgmt = (struct ieee80211_mgmt *) skb->data;
573 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; 573 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
574 574
@@ -671,8 +671,7 @@ void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
671} 671}
672 672
673ieee80211_rx_result 673ieee80211_rx_result
674ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 674ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
675 struct ieee80211_rx_status *rx_status)
676{ 675{
677 struct ieee80211_local *local = sdata->local; 676 struct ieee80211_local *local = sdata->local;
678 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 677 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
@@ -689,7 +688,6 @@ ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
689 case IEEE80211_STYPE_PROBE_RESP: 688 case IEEE80211_STYPE_PROBE_RESP:
690 case IEEE80211_STYPE_BEACON: 689 case IEEE80211_STYPE_BEACON:
691 case IEEE80211_STYPE_ACTION: 690 case IEEE80211_STYPE_ACTION:
692 memcpy(skb->cb, rx_status, sizeof(*rx_status));
693 skb_queue_tail(&ifmsh->skb_queue, skb); 691 skb_queue_tail(&ifmsh->skb_queue, skb);
694 queue_work(local->hw.workqueue, &ifmsh->work); 692 queue_work(local->hw.workqueue, &ifmsh->work);
695 return RX_QUEUED; 693 return RX_QUEUED;
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index c7d72819cdd2..2a2ed182cb7e 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -208,8 +208,7 @@ void ieee80211s_init(void);
208void ieee80211s_stop(void); 208void ieee80211s_stop(void);
209void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata); 209void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata);
210ieee80211_rx_result 210ieee80211_rx_result
211ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 211ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
212 struct ieee80211_rx_status *rx_status);
213void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata); 212void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata);
214void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata); 213void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata);
215 214
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index aca22b00b6a3..c9db9646025b 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -27,43 +27,54 @@
27#include "rate.h" 27#include "rate.h"
28#include "led.h" 28#include "led.h"
29 29
30#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
31#define IEEE80211_AUTH_TIMEOUT (HZ / 5) 30#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
32#define IEEE80211_AUTH_MAX_TRIES 3 31#define IEEE80211_AUTH_MAX_TRIES 3
33#define IEEE80211_ASSOC_TIMEOUT (HZ / 5) 32#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
34#define IEEE80211_ASSOC_MAX_TRIES 3 33#define IEEE80211_ASSOC_MAX_TRIES 3
35#define IEEE80211_MONITORING_INTERVAL (2 * HZ) 34#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
36#define IEEE80211_PROBE_WAIT (HZ / 5) 35#define IEEE80211_PROBE_WAIT (HZ / 5)
37#define IEEE80211_PROBE_IDLE_TIME (60 * HZ)
38#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
39 36
40#define TMR_RUNNING_TIMER 0 37#define TMR_RUNNING_TIMER 0
41#define TMR_RUNNING_CHANSW 1 38#define TMR_RUNNING_CHANSW 1
42 39
40/*
41 * All cfg80211 functions have to be called outside a locked
42 * section so that they can acquire a lock themselves... This
43 * is much simpler than queuing up things in cfg80211, but we
44 * do need some indirection for that here.
45 */
46enum rx_mgmt_action {
47 /* no action required */
48 RX_MGMT_NONE,
49
50 /* caller must call cfg80211_send_rx_auth() */
51 RX_MGMT_CFG80211_AUTH,
52
53 /* caller must call cfg80211_send_rx_assoc() */
54 RX_MGMT_CFG80211_ASSOC,
55
56 /* caller must call cfg80211_send_deauth() */
57 RX_MGMT_CFG80211_DEAUTH,
58
59 /* caller must call cfg80211_send_disassoc() */
60 RX_MGMT_CFG80211_DISASSOC,
61
62 /* caller must call cfg80211_auth_timeout() & free work */
63 RX_MGMT_CFG80211_AUTH_TO,
64
65 /* caller must call cfg80211_assoc_timeout() & free work */
66 RX_MGMT_CFG80211_ASSOC_TO,
67};
68
43/* utils */ 69/* utils */
44static int ecw2cw(int ecw) 70static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
45{ 71{
46 return (1 << ecw) - 1; 72 WARN_ON(!mutex_is_locked(&ifmgd->mtx));
47} 73}
48 74
49static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie) 75static int ecw2cw(int ecw)
50{ 76{
51 u8 *end, *pos; 77 return (1 << ecw) - 1;
52
53 pos = bss->cbss.information_elements;
54 if (pos == NULL)
55 return NULL;
56 end = pos + bss->cbss.len_information_elements;
57
58 while (pos + 1 < end) {
59 if (pos + 2 + pos[1] > end)
60 break;
61 if (pos[0] == ie)
62 return pos;
63 pos += 2 + pos[1];
64 }
65
66 return NULL;
67} 78}
68 79
69static int ieee80211_compatible_rates(struct ieee80211_bss *bss, 80static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
@@ -94,11 +105,10 @@ static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
94 */ 105 */
95static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata, 106static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
96 struct ieee80211_ht_info *hti, 107 struct ieee80211_ht_info *hti,
97 u16 ap_ht_cap_flags) 108 const u8 *bssid, u16 ap_ht_cap_flags)
98{ 109{
99 struct ieee80211_local *local = sdata->local; 110 struct ieee80211_local *local = sdata->local;
100 struct ieee80211_supported_band *sband; 111 struct ieee80211_supported_band *sband;
101 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
102 struct sta_info *sta; 112 struct sta_info *sta;
103 u32 changed = 0; 113 u32 changed = 0;
104 u16 ht_opmode; 114 u16 ht_opmode;
@@ -147,12 +157,10 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
147 ieee80211_hw_config(local, 0); 157 ieee80211_hw_config(local, 0);
148 158
149 rcu_read_lock(); 159 rcu_read_lock();
150 160 sta = sta_info_get(local, bssid);
151 sta = sta_info_get(local, ifmgd->bssid);
152 if (sta) 161 if (sta)
153 rate_control_rate_update(local, sband, sta, 162 rate_control_rate_update(local, sband, sta,
154 IEEE80211_RC_HT_CHANGED); 163 IEEE80211_RC_HT_CHANGED);
155
156 rcu_read_unlock(); 164 rcu_read_unlock();
157 } 165 }
158 166
@@ -175,23 +183,24 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
175 183
176/* frame sending functions */ 184/* frame sending functions */
177 185
178static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) 186static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
187 struct ieee80211_mgd_work *wk)
179{ 188{
180 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 189 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
181 struct ieee80211_local *local = sdata->local; 190 struct ieee80211_local *local = sdata->local;
182 struct sk_buff *skb; 191 struct sk_buff *skb;
183 struct ieee80211_mgmt *mgmt; 192 struct ieee80211_mgmt *mgmt;
184 u8 *pos, *ies, *ht_ie; 193 u8 *pos;
194 const u8 *ies, *ht_ie;
185 int i, len, count, rates_len, supp_rates_len; 195 int i, len, count, rates_len, supp_rates_len;
186 u16 capab; 196 u16 capab;
187 struct ieee80211_bss *bss;
188 int wmm = 0; 197 int wmm = 0;
189 struct ieee80211_supported_band *sband; 198 struct ieee80211_supported_band *sband;
190 u32 rates = 0; 199 u32 rates = 0;
191 200
192 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 201 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
193 sizeof(*mgmt) + 200 + ifmgd->extra_ie_len + 202 sizeof(*mgmt) + 200 + wk->ie_len +
194 ifmgd->ssid_len); 203 wk->ssid_len);
195 if (!skb) { 204 if (!skb) {
196 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc " 205 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
197 "frame\n", sdata->dev->name); 206 "frame\n", sdata->dev->name);
@@ -210,45 +219,35 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
210 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; 219 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
211 } 220 }
212 221
213 bss = ieee80211_rx_bss_get(local, ifmgd->bssid, 222 if (wk->bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
214 local->hw.conf.channel->center_freq, 223 capab |= WLAN_CAPABILITY_PRIVACY;
215 ifmgd->ssid, ifmgd->ssid_len); 224 if (wk->bss->wmm_used)
216 if (bss) { 225 wmm = 1;
217 if (bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
218 capab |= WLAN_CAPABILITY_PRIVACY;
219 if (bss->wmm_used)
220 wmm = 1;
221 226
222 /* get all rates supported by the device and the AP as 227 /* get all rates supported by the device and the AP as
223 * some APs don't like getting a superset of their rates 228 * some APs don't like getting a superset of their rates
224 * in the association request (e.g. D-Link DAP 1353 in 229 * in the association request (e.g. D-Link DAP 1353 in
225 * b-only mode) */ 230 * b-only mode) */
226 rates_len = ieee80211_compatible_rates(bss, sband, &rates); 231 rates_len = ieee80211_compatible_rates(wk->bss, sband, &rates);
227 232
228 if ((bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && 233 if ((wk->bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
229 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) 234 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
230 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; 235 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
231
232 ieee80211_rx_bss_put(local, bss);
233 } else {
234 rates = ~0;
235 rates_len = sband->n_bitrates;
236 }
237 236
238 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 237 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
239 memset(mgmt, 0, 24); 238 memset(mgmt, 0, 24);
240 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN); 239 memcpy(mgmt->da, wk->bss->cbss.bssid, ETH_ALEN);
241 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 240 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
242 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN); 241 memcpy(mgmt->bssid, wk->bss->cbss.bssid, ETH_ALEN);
243 242
244 if (ifmgd->flags & IEEE80211_STA_PREV_BSSID_SET) { 243 if (!is_zero_ether_addr(wk->prev_bssid)) {
245 skb_put(skb, 10); 244 skb_put(skb, 10);
246 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 245 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
247 IEEE80211_STYPE_REASSOC_REQ); 246 IEEE80211_STYPE_REASSOC_REQ);
248 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); 247 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
249 mgmt->u.reassoc_req.listen_interval = 248 mgmt->u.reassoc_req.listen_interval =
250 cpu_to_le16(local->hw.conf.listen_interval); 249 cpu_to_le16(local->hw.conf.listen_interval);
251 memcpy(mgmt->u.reassoc_req.current_ap, ifmgd->prev_bssid, 250 memcpy(mgmt->u.reassoc_req.current_ap, wk->prev_bssid,
252 ETH_ALEN); 251 ETH_ALEN);
253 } else { 252 } else {
254 skb_put(skb, 4); 253 skb_put(skb, 4);
@@ -260,10 +259,10 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
260 } 259 }
261 260
262 /* SSID */ 261 /* SSID */
263 ies = pos = skb_put(skb, 2 + ifmgd->ssid_len); 262 ies = pos = skb_put(skb, 2 + wk->ssid_len);
264 *pos++ = WLAN_EID_SSID; 263 *pos++ = WLAN_EID_SSID;
265 *pos++ = ifmgd->ssid_len; 264 *pos++ = wk->ssid_len;
266 memcpy(pos, ifmgd->ssid, ifmgd->ssid_len); 265 memcpy(pos, wk->ssid, wk->ssid_len);
267 266
268 /* add all rates which were marked to be used above */ 267 /* add all rates which were marked to be used above */
269 supp_rates_len = rates_len; 268 supp_rates_len = rates_len;
@@ -318,9 +317,9 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
318 } 317 }
319 } 318 }
320 319
321 if (ifmgd->extra_ie) { 320 if (wk->ie_len && wk->ie) {
322 pos = skb_put(skb, ifmgd->extra_ie_len); 321 pos = skb_put(skb, wk->ie_len);
323 memcpy(pos, ifmgd->extra_ie, ifmgd->extra_ie_len); 322 memcpy(pos, wk->ie, wk->ie_len);
324 } 323 }
325 324
326 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) { 325 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
@@ -345,9 +344,9 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
345 */ 344 */
346 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && 345 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
347 sband->ht_cap.ht_supported && 346 sband->ht_cap.ht_supported &&
348 (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) && 347 (ht_ie = ieee80211_bss_get_ie(&wk->bss->cbss, WLAN_EID_HT_INFORMATION)) &&
349 ht_ie[1] >= sizeof(struct ieee80211_ht_info) && 348 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
350 (!(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))) { 349 (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N))) {
351 struct ieee80211_ht_info *ht_info = 350 struct ieee80211_ht_info *ht_info =
352 (struct ieee80211_ht_info *)(ht_ie + 2); 351 (struct ieee80211_ht_info *)(ht_ie + 2);
353 u16 cap = sband->ht_cap.cap; 352 u16 cap = sband->ht_cap.cap;
@@ -382,18 +381,13 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
382 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs)); 381 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
383 } 382 }
384 383
385 kfree(ifmgd->assocreq_ies);
386 ifmgd->assocreq_ies_len = (skb->data + skb->len) - ies;
387 ifmgd->assocreq_ies = kmalloc(ifmgd->assocreq_ies_len, GFP_KERNEL);
388 if (ifmgd->assocreq_ies)
389 memcpy(ifmgd->assocreq_ies, ies, ifmgd->assocreq_ies_len);
390
391 ieee80211_tx_skb(sdata, skb, 0); 384 ieee80211_tx_skb(sdata, skb, 0);
392} 385}
393 386
394 387
395static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, 388static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
396 u16 stype, u16 reason) 389 const u8 *bssid, u16 stype, u16 reason,
390 void *cookie)
397{ 391{
398 struct ieee80211_local *local = sdata->local; 392 struct ieee80211_local *local = sdata->local;
399 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 393 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
@@ -410,18 +404,18 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
410 404
411 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 405 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
412 memset(mgmt, 0, 24); 406 memset(mgmt, 0, 24);
413 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN); 407 memcpy(mgmt->da, bssid, ETH_ALEN);
414 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 408 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
415 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN); 409 memcpy(mgmt->bssid, bssid, ETH_ALEN);
416 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); 410 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
417 skb_put(skb, 2); 411 skb_put(skb, 2);
418 /* u.deauth.reason_code == u.disassoc.reason_code */ 412 /* u.deauth.reason_code == u.disassoc.reason_code */
419 mgmt->u.deauth.reason_code = cpu_to_le16(reason); 413 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
420 414
421 if (stype == IEEE80211_STYPE_DEAUTH) 415 if (stype == IEEE80211_STYPE_DEAUTH)
422 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len); 416 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len, cookie);
423 else 417 else
424 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len); 418 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len, cookie);
425 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED); 419 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
426} 420}
427 421
@@ -494,28 +488,26 @@ static void ieee80211_chswitch_work(struct work_struct *work)
494{ 488{
495 struct ieee80211_sub_if_data *sdata = 489 struct ieee80211_sub_if_data *sdata =
496 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); 490 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
497 struct ieee80211_bss *bss;
498 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 491 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
499 492
500 if (!netif_running(sdata->dev)) 493 if (!netif_running(sdata->dev))
501 return; 494 return;
502 495
503 bss = ieee80211_rx_bss_get(sdata->local, ifmgd->bssid, 496 mutex_lock(&ifmgd->mtx);
504 sdata->local->hw.conf.channel->center_freq, 497 if (!ifmgd->associated)
505 ifmgd->ssid, ifmgd->ssid_len); 498 goto out;
506 if (!bss)
507 goto exit;
508 499
509 sdata->local->oper_channel = sdata->local->csa_channel; 500 sdata->local->oper_channel = sdata->local->csa_channel;
501 ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL);
502
510 /* XXX: shouldn't really modify cfg80211-owned data! */ 503 /* XXX: shouldn't really modify cfg80211-owned data! */
511 if (!ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL)) 504 ifmgd->associated->cbss.channel = sdata->local->oper_channel;
512 bss->cbss.channel = sdata->local->oper_channel;
513 505
514 ieee80211_rx_bss_put(sdata->local, bss);
515exit:
516 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
517 ieee80211_wake_queues_by_reason(&sdata->local->hw, 506 ieee80211_wake_queues_by_reason(&sdata->local->hw,
518 IEEE80211_QUEUE_STOP_REASON_CSA); 507 IEEE80211_QUEUE_STOP_REASON_CSA);
508 out:
509 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
510 mutex_unlock(&ifmgd->mtx);
519} 511}
520 512
521static void ieee80211_chswitch_timer(unsigned long data) 513static void ieee80211_chswitch_timer(unsigned long data)
@@ -540,7 +532,9 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
540 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 532 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
541 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num); 533 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
542 534
543 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATED) 535 ASSERT_MGD_MTX(ifmgd);
536
537 if (!ifmgd->associated)
544 return; 538 return;
545 539
546 if (sdata->local->sw_scanning || sdata->local->hw_scanning) 540 if (sdata->local->sw_scanning || sdata->local->hw_scanning)
@@ -651,7 +645,7 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
651 } 645 }
652 646
653 if (count == 1 && found->u.mgd.powersave && 647 if (count == 1 && found->u.mgd.powersave &&
654 (found->u.mgd.flags & IEEE80211_STA_ASSOCIATED) && 648 found->u.mgd.associated && list_empty(&found->u.mgd.work_list) &&
655 !(found->u.mgd.flags & IEEE80211_STA_PROBEREQ_POLL)) { 649 !(found->u.mgd.flags & IEEE80211_STA_PROBEREQ_POLL)) {
656 s32 beaconint_us; 650 s32 beaconint_us;
657 651
@@ -806,9 +800,6 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
806 u16 capab, bool erp_valid, u8 erp) 800 u16 capab, bool erp_valid, u8 erp)
807{ 801{
808 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; 802 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
809#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
810 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
811#endif
812 u32 changed = 0; 803 u32 changed = 0;
813 bool use_protection; 804 bool use_protection;
814 bool use_short_preamble; 805 bool use_short_preamble;
@@ -825,42 +816,16 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
825 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); 816 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
826 817
827 if (use_protection != bss_conf->use_cts_prot) { 818 if (use_protection != bss_conf->use_cts_prot) {
828#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
829 if (net_ratelimit()) {
830 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
831 sdata->dev->name,
832 use_protection ? "enabled" : "disabled",
833 ifmgd->bssid);
834 }
835#endif
836 bss_conf->use_cts_prot = use_protection; 819 bss_conf->use_cts_prot = use_protection;
837 changed |= BSS_CHANGED_ERP_CTS_PROT; 820 changed |= BSS_CHANGED_ERP_CTS_PROT;
838 } 821 }
839 822
840 if (use_short_preamble != bss_conf->use_short_preamble) { 823 if (use_short_preamble != bss_conf->use_short_preamble) {
841#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
842 if (net_ratelimit()) {
843 printk(KERN_DEBUG "%s: switched to %s barker preamble"
844 " (BSSID=%pM)\n",
845 sdata->dev->name,
846 use_short_preamble ? "short" : "long",
847 ifmgd->bssid);
848 }
849#endif
850 bss_conf->use_short_preamble = use_short_preamble; 824 bss_conf->use_short_preamble = use_short_preamble;
851 changed |= BSS_CHANGED_ERP_PREAMBLE; 825 changed |= BSS_CHANGED_ERP_PREAMBLE;
852 } 826 }
853 827
854 if (use_short_slot != bss_conf->use_short_slot) { 828 if (use_short_slot != bss_conf->use_short_slot) {
855#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
856 if (net_ratelimit()) {
857 printk(KERN_DEBUG "%s: switched to %s slot time"
858 " (BSSID=%pM)\n",
859 sdata->dev->name,
860 use_short_slot ? "short" : "long",
861 ifmgd->bssid);
862 }
863#endif
864 bss_conf->use_short_slot = use_short_slot; 829 bss_conf->use_short_slot = use_short_slot;
865 changed |= BSS_CHANGED_ERP_SLOT; 830 changed |= BSS_CHANGED_ERP_SLOT;
866 } 831 }
@@ -868,105 +833,25 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
868 return changed; 833 return changed;
869} 834}
870 835
871static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
872{
873 union iwreq_data wrqu;
874
875 memset(&wrqu, 0, sizeof(wrqu));
876 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
877 memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
878 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
879 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
880}
881
882static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
883{
884 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
885 char *buf;
886 size_t len;
887 int i;
888 union iwreq_data wrqu;
889
890 if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
891 return;
892
893 buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
894 ifmgd->assocresp_ies_len), GFP_KERNEL);
895 if (!buf)
896 return;
897
898 len = sprintf(buf, "ASSOCINFO(");
899 if (ifmgd->assocreq_ies) {
900 len += sprintf(buf + len, "ReqIEs=");
901 for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
902 len += sprintf(buf + len, "%02x",
903 ifmgd->assocreq_ies[i]);
904 }
905 }
906 if (ifmgd->assocresp_ies) {
907 if (ifmgd->assocreq_ies)
908 len += sprintf(buf + len, " ");
909 len += sprintf(buf + len, "RespIEs=");
910 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
911 len += sprintf(buf + len, "%02x",
912 ifmgd->assocresp_ies[i]);
913 }
914 }
915 len += sprintf(buf + len, ")");
916
917 if (len > IW_CUSTOM_MAX) {
918 len = sprintf(buf, "ASSOCRESPIE=");
919 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
920 len += sprintf(buf + len, "%02x",
921 ifmgd->assocresp_ies[i]);
922 }
923 }
924
925 if (len <= IW_CUSTOM_MAX) {
926 memset(&wrqu, 0, sizeof(wrqu));
927 wrqu.data.length = len;
928 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
929 }
930
931 kfree(buf);
932}
933
934
935static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, 836static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
837 struct ieee80211_bss *bss,
936 u32 bss_info_changed) 838 u32 bss_info_changed)
937{ 839{
938 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
939 struct ieee80211_local *local = sdata->local; 840 struct ieee80211_local *local = sdata->local;
940 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
941
942 struct ieee80211_bss *bss;
943 841
944 bss_info_changed |= BSS_CHANGED_ASSOC; 842 bss_info_changed |= BSS_CHANGED_ASSOC;
945 ifmgd->flags |= IEEE80211_STA_ASSOCIATED; 843 /* set timing information */
844 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
845 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
846 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
946 847
947 bss = ieee80211_rx_bss_get(local, ifmgd->bssid, 848 bss_info_changed |= BSS_CHANGED_BEACON_INT;
948 conf->channel->center_freq, 849 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
949 ifmgd->ssid, ifmgd->ssid_len); 850 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
950 if (bss) {
951 /* set timing information */
952 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
953 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
954 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
955 851
956 bss_info_changed |= BSS_CHANGED_BEACON_INT; 852 sdata->u.mgd.associated = bss;
957 bss_info_changed |= ieee80211_handle_bss_capability(sdata, 853 memcpy(sdata->u.mgd.bssid, bss->cbss.bssid, ETH_ALEN);
958 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
959 854
960 cfg80211_hold_bss(&bss->cbss);
961
962 ieee80211_rx_bss_put(local, bss);
963 }
964
965 ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
966 memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
967 ieee80211_sta_send_associnfo(sdata);
968
969 ifmgd->last_probe = jiffies;
970 ieee80211_led_assoc(local, 1); 855 ieee80211_led_assoc(local, 1);
971 856
972 sdata->vif.bss_conf.assoc = 1; 857 sdata->vif.bss_conf.assoc = 1;
@@ -991,167 +876,135 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
991 876
992 netif_tx_start_all_queues(sdata->dev); 877 netif_tx_start_all_queues(sdata->dev);
993 netif_carrier_on(sdata->dev); 878 netif_carrier_on(sdata->dev);
994
995 ieee80211_sta_send_apinfo(sdata);
996} 879}
997 880
998static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata) 881static enum rx_mgmt_action __must_check
882ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
883 struct ieee80211_mgd_work *wk)
999{ 884{
1000 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 885 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1001 struct ieee80211_local *local = sdata->local; 886 struct ieee80211_local *local = sdata->local;
1002 887
1003 ifmgd->direct_probe_tries++; 888 wk->tries++;
1004 if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) { 889 if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
1005 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n", 890 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
1006 sdata->dev->name, ifmgd->bssid); 891 sdata->dev->name, wk->bss->cbss.bssid);
1007 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1008 ieee80211_recalc_idle(local);
1009 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
1010 892
1011 /* 893 /*
1012 * Most likely AP is not in the range so remove the 894 * Most likely AP is not in the range so remove the
1013 * bss information associated to the AP 895 * bss struct for that AP.
1014 */ 896 */
1015 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 897 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
1016 sdata->local->hw.conf.channel->center_freq,
1017 ifmgd->ssid, ifmgd->ssid_len);
1018 898
1019 /* 899 /*
1020 * We might have a pending scan which had no chance to run yet 900 * We might have a pending scan which had no chance to run yet
1021 * due to state == IEEE80211_STA_MLME_DIRECT_PROBE. 901 * due to work needing to be done. Hence, queue the STAs work
1022 * Hence, queue the STAs work again 902 * again for that.
1023 */ 903 */
1024 queue_work(local->hw.workqueue, &ifmgd->work); 904 queue_work(local->hw.workqueue, &ifmgd->work);
1025 return; 905 return RX_MGMT_CFG80211_AUTH_TO;
1026 } 906 }
1027 907
1028 printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n", 908 printk(KERN_DEBUG "%s: direct probe to AP %pM (try %d)\n",
1029 sdata->dev->name, ifmgd->bssid, 909 sdata->dev->name, wk->bss->cbss.bssid,
1030 ifmgd->direct_probe_tries); 910 wk->tries);
1031
1032 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
1033 911
1034 /* Direct probe is sent to broadcast address as some APs 912 /*
913 * Direct probe is sent to broadcast address as some APs
1035 * will not answer to direct packet in unassociated state. 914 * will not answer to direct packet in unassociated state.
1036 */ 915 */
1037 ieee80211_send_probe_req(sdata, NULL, 916 ieee80211_send_probe_req(sdata, NULL, wk->ssid, wk->ssid_len, NULL, 0);
1038 ifmgd->ssid, ifmgd->ssid_len, NULL, 0); 917
918 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
919 mod_timer(&ifmgd->timer, wk->timeout);
1039 920
1040 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT); 921 return RX_MGMT_NONE;
1041} 922}
1042 923
1043 924
1044static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata) 925static enum rx_mgmt_action __must_check
926ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
927 struct ieee80211_mgd_work *wk)
1045{ 928{
1046 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 929 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1047 struct ieee80211_local *local = sdata->local; 930 struct ieee80211_local *local = sdata->local;
1048 u8 *ies;
1049 size_t ies_len;
1050 931
1051 ifmgd->auth_tries++; 932 wk->tries++;
1052 if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) { 933 if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
1053 printk(KERN_DEBUG "%s: authentication with AP %pM" 934 printk(KERN_DEBUG "%s: authentication with AP %pM"
1054 " timed out\n", 935 " timed out\n",
1055 sdata->dev->name, ifmgd->bssid); 936 sdata->dev->name, wk->bss->cbss.bssid);
1056 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 937
1057 ieee80211_recalc_idle(local); 938 /*
1058 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid); 939 * Most likely AP is not in the range so remove the
1059 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 940 * bss struct for that AP.
1060 sdata->local->hw.conf.channel->center_freq, 941 */
1061 ifmgd->ssid, ifmgd->ssid_len); 942 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
1062 943
1063 /* 944 /*
1064 * We might have a pending scan which had no chance to run yet 945 * We might have a pending scan which had no chance to run yet
1065 * due to state == IEEE80211_STA_MLME_AUTHENTICATE. 946 * due to work needing to be done. Hence, queue the STAs work
1066 * Hence, queue the STAs work again 947 * again for that.
1067 */ 948 */
1068 queue_work(local->hw.workqueue, &ifmgd->work); 949 queue_work(local->hw.workqueue, &ifmgd->work);
1069 return; 950 return RX_MGMT_CFG80211_AUTH_TO;
1070 } 951 }
1071 952
1072 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE; 953 printk(KERN_DEBUG "%s: authenticate with AP %pM (try %d)\n",
1073 printk(KERN_DEBUG "%s: authenticate with AP %pM\n", 954 sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
1074 sdata->dev->name, ifmgd->bssid);
1075 955
1076 if (ifmgd->flags & IEEE80211_STA_EXT_SME) { 956 ieee80211_send_auth(sdata, 1, wk->auth_alg, wk->ie, wk->ie_len,
1077 ies = ifmgd->sme_auth_ie; 957 wk->bss->cbss.bssid, 0);
1078 ies_len = ifmgd->sme_auth_ie_len; 958 wk->auth_transaction = 2;
1079 } else {
1080 ies = NULL;
1081 ies_len = 0;
1082 }
1083 ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len,
1084 ifmgd->bssid, 0);
1085 ifmgd->auth_transaction = 2;
1086 959
1087 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT); 960 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
961 mod_timer(&ifmgd->timer, wk->timeout);
962
963 return RX_MGMT_NONE;
1088} 964}
1089 965
1090/*
1091 * The disassoc 'reason' argument can be either our own reason
1092 * if self disconnected or a reason code from the AP.
1093 */
1094static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, 966static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1095 bool deauth, bool self_disconnected, 967 const u8 *bssid, bool deauth)
1096 u16 reason)
1097{ 968{
1098 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 969 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1099 struct ieee80211_local *local = sdata->local; 970 struct ieee80211_local *local = sdata->local;
1100 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
1101 struct ieee80211_bss *bss;
1102 struct sta_info *sta; 971 struct sta_info *sta;
1103 u32 changed = 0, config_changed = 0; 972 u32 changed = 0, config_changed = 0;
1104 973
1105 if (deauth) { 974 ASSERT_MGD_MTX(ifmgd);
1106 ifmgd->direct_probe_tries = 0; 975
1107 ifmgd->auth_tries = 0; 976 ifmgd->associated = NULL;
1108 } 977 memset(ifmgd->bssid, 0, ETH_ALEN);
1109 ifmgd->assoc_scan_tries = 0; 978
1110 ifmgd->assoc_tries = 0; 979 /*
980 * we need to commit the associated = NULL change because the
981 * scan code uses that to determine whether this iface should
982 * go to/wake up from powersave or not -- and could otherwise
983 * wake the queues erroneously.
984 */
985 smp_mb();
986
987 /*
988 * Thus, we can only afterwards stop the queues -- to account
989 * for the case where another CPU is finishing a scan at this
990 * time -- we don't want the scan code to enable queues.
991 */
1111 992
1112 netif_tx_stop_all_queues(sdata->dev); 993 netif_tx_stop_all_queues(sdata->dev);
1113 netif_carrier_off(sdata->dev); 994 netif_carrier_off(sdata->dev);
1114 995
1115 rcu_read_lock(); 996 rcu_read_lock();
1116 sta = sta_info_get(local, ifmgd->bssid); 997 sta = sta_info_get(local, bssid);
1117 if (sta) 998 if (sta)
1118 ieee80211_sta_tear_down_BA_sessions(sta); 999 ieee80211_sta_tear_down_BA_sessions(sta);
1119 rcu_read_unlock(); 1000 rcu_read_unlock();
1120 1001
1121 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
1122 conf->channel->center_freq,
1123 ifmgd->ssid, ifmgd->ssid_len);
1124
1125 if (bss) {
1126 cfg80211_unhold_bss(&bss->cbss);
1127 ieee80211_rx_bss_put(local, bss);
1128 }
1129
1130 if (self_disconnected) {
1131 if (deauth)
1132 ieee80211_send_deauth_disassoc(sdata,
1133 IEEE80211_STYPE_DEAUTH, reason);
1134 else
1135 ieee80211_send_deauth_disassoc(sdata,
1136 IEEE80211_STYPE_DISASSOC, reason);
1137 }
1138
1139 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
1140 changed |= ieee80211_reset_erp_info(sdata); 1002 changed |= ieee80211_reset_erp_info(sdata);
1141 1003
1142 ieee80211_led_assoc(local, 0); 1004 ieee80211_led_assoc(local, 0);
1143 changed |= BSS_CHANGED_ASSOC; 1005 changed |= BSS_CHANGED_ASSOC;
1144 sdata->vif.bss_conf.assoc = false; 1006 sdata->vif.bss_conf.assoc = false;
1145 1007
1146 ieee80211_sta_send_apinfo(sdata);
1147
1148 if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
1149 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1150 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
1151 sdata->local->hw.conf.channel->center_freq,
1152 ifmgd->ssid, ifmgd->ssid_len);
1153 }
1154
1155 ieee80211_set_wmm_default(sdata); 1008 ieee80211_set_wmm_default(sdata);
1156 1009
1157 ieee80211_recalc_idle(local); 1010 ieee80211_recalc_idle(local);
@@ -1180,7 +1033,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1180 1033
1181 rcu_read_lock(); 1034 rcu_read_lock();
1182 1035
1183 sta = sta_info_get(local, ifmgd->bssid); 1036 sta = sta_info_get(local, bssid);
1184 if (!sta) { 1037 if (!sta) {
1185 rcu_read_unlock(); 1038 rcu_read_unlock();
1186 return; 1039 return;
@@ -1193,83 +1046,42 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1193 sta_info_destroy(sta); 1046 sta_info_destroy(sta);
1194} 1047}
1195 1048
1196static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata) 1049static enum rx_mgmt_action __must_check
1197{ 1050ieee80211_associate(struct ieee80211_sub_if_data *sdata,
1198 if (!sdata || !sdata->default_key || 1051 struct ieee80211_mgd_work *wk)
1199 sdata->default_key->conf.alg != ALG_WEP)
1200 return 0;
1201 return 1;
1202}
1203
1204static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
1205{
1206 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1207 struct ieee80211_local *local = sdata->local;
1208 struct ieee80211_bss *bss;
1209 int bss_privacy;
1210 int wep_privacy;
1211 int privacy_invoked;
1212
1213 if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
1214 return 0;
1215
1216 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
1217 local->hw.conf.channel->center_freq,
1218 ifmgd->ssid, ifmgd->ssid_len);
1219 if (!bss)
1220 return 0;
1221
1222 bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
1223 wep_privacy = !!ieee80211_sta_wep_configured(sdata);
1224 privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
1225
1226 ieee80211_rx_bss_put(local, bss);
1227
1228 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
1229 return 0;
1230
1231 return 1;
1232}
1233
1234static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
1235{ 1052{
1236 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1053 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1237 struct ieee80211_local *local = sdata->local; 1054 struct ieee80211_local *local = sdata->local;
1238 1055
1239 ifmgd->assoc_tries++; 1056 wk->tries++;
1240 if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) { 1057 if (wk->tries > IEEE80211_ASSOC_MAX_TRIES) {
1241 printk(KERN_DEBUG "%s: association with AP %pM" 1058 printk(KERN_DEBUG "%s: association with AP %pM"
1242 " timed out\n", 1059 " timed out\n",
1243 sdata->dev->name, ifmgd->bssid); 1060 sdata->dev->name, wk->bss->cbss.bssid);
1244 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1061
1245 ieee80211_recalc_idle(local); 1062 /*
1246 cfg80211_send_assoc_timeout(sdata->dev, ifmgd->bssid); 1063 * Most likely AP is not in the range so remove the
1247 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 1064 * bss struct for that AP.
1248 sdata->local->hw.conf.channel->center_freq, 1065 */
1249 ifmgd->ssid, ifmgd->ssid_len); 1066 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
1067
1250 /* 1068 /*
1251 * We might have a pending scan which had no chance to run yet 1069 * We might have a pending scan which had no chance to run yet
1252 * due to state == IEEE80211_STA_MLME_ASSOCIATE. 1070 * due to work needing to be done. Hence, queue the STAs work
1253 * Hence, queue the STAs work again 1071 * again for that.
1254 */ 1072 */
1255 queue_work(local->hw.workqueue, &ifmgd->work); 1073 queue_work(local->hw.workqueue, &ifmgd->work);
1256 return; 1074 return RX_MGMT_CFG80211_ASSOC_TO;
1257 } 1075 }
1258 1076
1259 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE; 1077 printk(KERN_DEBUG "%s: associate with AP %pM (try %d)\n",
1260 printk(KERN_DEBUG "%s: associate with AP %pM\n", 1078 sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
1261 sdata->dev->name, ifmgd->bssid); 1079 ieee80211_send_assoc(sdata, wk);
1262 if (ieee80211_privacy_mismatch(sdata)) {
1263 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
1264 "mixed-cell disabled - abort association\n", sdata->dev->name);
1265 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1266 ieee80211_recalc_idle(local);
1267 return;
1268 }
1269 1080
1270 ieee80211_send_assoc(sdata); 1081 wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
1082 mod_timer(&ifmgd->timer, wk->timeout);
1271 1083
1272 mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT); 1084 return RX_MGMT_NONE;
1273} 1085}
1274 1086
1275void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, 1087void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
@@ -1294,6 +1106,7 @@ void ieee80211_beacon_loss_work(struct work_struct *work)
1294 container_of(work, struct ieee80211_sub_if_data, 1106 container_of(work, struct ieee80211_sub_if_data,
1295 u.mgd.beacon_loss_work); 1107 u.mgd.beacon_loss_work);
1296 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1108 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1109 const u8 *ssid;
1297 1110
1298 /* 1111 /*
1299 * The driver has already reported this event and we have 1112 * The driver has already reported this event and we have
@@ -1306,12 +1119,15 @@ void ieee80211_beacon_loss_work(struct work_struct *work)
1306 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) 1119 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1307 return; 1120 return;
1308 1121
1122 mutex_lock(&ifmgd->mtx);
1123
1124 if (!ifmgd->associated)
1125 goto out;
1126
1309#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1127#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1310 if (net_ratelimit()) { 1128 if (net_ratelimit())
1311 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM " 1129 printk(KERN_DEBUG "%s: driver reports beacon loss from AP "
1312 "- sending probe request\n", sdata->dev->name, 1130 "- sending probe request\n", sdata->dev->name);
1313 sdata->u.mgd.bssid);
1314 }
1315#endif 1131#endif
1316 1132
1317 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL; 1133 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
@@ -1320,10 +1136,13 @@ void ieee80211_beacon_loss_work(struct work_struct *work)
1320 ieee80211_recalc_ps(sdata->local, -1); 1136 ieee80211_recalc_ps(sdata->local, -1);
1321 mutex_unlock(&sdata->local->iflist_mtx); 1137 mutex_unlock(&sdata->local->iflist_mtx);
1322 1138
1323 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid, 1139 ssid = ieee80211_bss_get_ie(&ifmgd->associated->cbss, WLAN_EID_SSID);
1324 ifmgd->ssid_len, NULL, 0); 1140 ieee80211_send_probe_req(sdata, ifmgd->associated->cbss.bssid,
1141 ssid + 2, ssid[1], NULL, 0);
1325 1142
1326 mod_timer(&ifmgd->timer, jiffies + IEEE80211_PROBE_WAIT); 1143 mod_timer(&ifmgd->timer, jiffies + IEEE80211_PROBE_WAIT);
1144 out:
1145 mutex_unlock(&ifmgd->mtx);
1327} 1146}
1328 1147
1329void ieee80211_beacon_loss(struct ieee80211_vif *vif) 1148void ieee80211_beacon_loss(struct ieee80211_vif *vif)
@@ -1335,105 +1154,16 @@ void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1335} 1154}
1336EXPORT_SYMBOL(ieee80211_beacon_loss); 1155EXPORT_SYMBOL(ieee80211_beacon_loss);
1337 1156
1338static void ieee80211_associated(struct ieee80211_sub_if_data *sdata) 1157static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
1339{ 1158 struct ieee80211_mgd_work *wk)
1340 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1341 struct ieee80211_local *local = sdata->local;
1342 struct sta_info *sta;
1343 unsigned long last_rx;
1344 bool disassoc = false;
1345
1346 /* TODO: start monitoring current AP signal quality and number of
1347 * missed beacons. Scan other channels every now and then and search
1348 * for better APs. */
1349 /* TODO: remove expired BSSes */
1350
1351 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED;
1352
1353 rcu_read_lock();
1354
1355 sta = sta_info_get(local, ifmgd->bssid);
1356 if (!sta) {
1357 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
1358 sdata->dev->name, ifmgd->bssid);
1359 disassoc = true;
1360 rcu_read_unlock();
1361 goto out;
1362 }
1363
1364 last_rx = sta->last_rx;
1365 rcu_read_unlock();
1366
1367 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
1368 time_after(jiffies, last_rx + IEEE80211_PROBE_WAIT)) {
1369 printk(KERN_DEBUG "%s: no probe response from AP %pM "
1370 "- disassociating\n",
1371 sdata->dev->name, ifmgd->bssid);
1372 disassoc = true;
1373 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1374 goto out;
1375 }
1376
1377 /*
1378 * Beacon filtering is only enabled with power save and then the
1379 * stack should not check for beacon loss.
1380 */
1381 if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) &&
1382 (local->hw.conf.flags & IEEE80211_CONF_PS)) &&
1383 time_after(jiffies,
1384 ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
1385#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1386 if (net_ratelimit()) {
1387 printk(KERN_DEBUG "%s: beacon loss from AP %pM "
1388 "- sending probe request\n",
1389 sdata->dev->name, ifmgd->bssid);
1390 }
1391#endif
1392 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1393 mutex_lock(&local->iflist_mtx);
1394 ieee80211_recalc_ps(local, -1);
1395 mutex_unlock(&local->iflist_mtx);
1396 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1397 ifmgd->ssid_len, NULL, 0);
1398 mod_timer(&ifmgd->timer, jiffies + IEEE80211_PROBE_WAIT);
1399 goto out;
1400 }
1401
1402 if (time_after(jiffies, last_rx + IEEE80211_PROBE_IDLE_TIME)) {
1403 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1404 mutex_lock(&local->iflist_mtx);
1405 ieee80211_recalc_ps(local, -1);
1406 mutex_unlock(&local->iflist_mtx);
1407 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1408 ifmgd->ssid_len, NULL, 0);
1409 }
1410
1411 out:
1412 if (!disassoc)
1413 mod_timer(&ifmgd->timer,
1414 jiffies + IEEE80211_MONITORING_INTERVAL);
1415 else
1416 ieee80211_set_disassoc(sdata, true, true,
1417 WLAN_REASON_PREV_AUTH_NOT_VALID);
1418}
1419
1420
1421static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
1422{ 1159{
1423 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1160 wk->state = IEEE80211_MGD_STATE_IDLE;
1424
1425 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name); 1161 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
1426 ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
1427 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1428 /* Wait for SME to request association */
1429 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1430 ieee80211_recalc_idle(sdata->local);
1431 } else
1432 ieee80211_associate(sdata);
1433} 1162}
1434 1163
1435 1164
1436static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, 1165static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1166 struct ieee80211_mgd_work *wk,
1437 struct ieee80211_mgmt *mgmt, 1167 struct ieee80211_mgmt *mgmt,
1438 size_t len) 1168 size_t len)
1439{ 1169{
@@ -1444,161 +1174,132 @@ static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1444 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); 1174 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1445 if (!elems.challenge) 1175 if (!elems.challenge)
1446 return; 1176 return;
1447 ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg, 1177 ieee80211_send_auth(sdata, 3, wk->auth_alg,
1448 elems.challenge - 2, elems.challenge_len + 2, 1178 elems.challenge - 2, elems.challenge_len + 2,
1449 sdata->u.mgd.bssid, 1); 1179 wk->bss->cbss.bssid, 1);
1450 sdata->u.mgd.auth_transaction = 4; 1180 wk->auth_transaction = 4;
1451} 1181}
1452 1182
1453static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, 1183static enum rx_mgmt_action __must_check
1454 struct ieee80211_mgmt *mgmt, 1184ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1455 size_t len) 1185 struct ieee80211_mgd_work *wk,
1186 struct ieee80211_mgmt *mgmt, size_t len)
1456{ 1187{
1457 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1458 u16 auth_alg, auth_transaction, status_code; 1188 u16 auth_alg, auth_transaction, status_code;
1459 1189
1460 if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE) 1190 if (wk->state != IEEE80211_MGD_STATE_AUTH)
1461 return; 1191 return RX_MGMT_NONE;
1462 1192
1463 if (len < 24 + 6) 1193 if (len < 24 + 6)
1464 return; 1194 return RX_MGMT_NONE;
1465 1195
1466 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0) 1196 if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
1467 return; 1197 return RX_MGMT_NONE;
1468 1198
1469 if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0) 1199 if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
1470 return; 1200 return RX_MGMT_NONE;
1471 1201
1472 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); 1202 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1473 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); 1203 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1474 status_code = le16_to_cpu(mgmt->u.auth.status_code); 1204 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1475 1205
1476 if (auth_alg != ifmgd->auth_alg || 1206 if (auth_alg != wk->auth_alg ||
1477 auth_transaction != ifmgd->auth_transaction) 1207 auth_transaction != wk->auth_transaction)
1478 return; 1208 return RX_MGMT_NONE;
1479 1209
1480 if (status_code != WLAN_STATUS_SUCCESS) { 1210 if (status_code != WLAN_STATUS_SUCCESS) {
1481 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) { 1211 list_del(&wk->list);
1482 u8 algs[3]; 1212 kfree(wk);
1483 const int num_algs = ARRAY_SIZE(algs); 1213 return RX_MGMT_CFG80211_AUTH;
1484 int i, pos;
1485 algs[0] = algs[1] = algs[2] = 0xff;
1486 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1487 algs[0] = WLAN_AUTH_OPEN;
1488 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1489 algs[1] = WLAN_AUTH_SHARED_KEY;
1490 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1491 algs[2] = WLAN_AUTH_LEAP;
1492 if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
1493 pos = 0;
1494 else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
1495 pos = 1;
1496 else
1497 pos = 2;
1498 for (i = 0; i < num_algs; i++) {
1499 pos++;
1500 if (pos >= num_algs)
1501 pos = 0;
1502 if (algs[pos] == ifmgd->auth_alg ||
1503 algs[pos] == 0xff)
1504 continue;
1505 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1506 !ieee80211_sta_wep_configured(sdata))
1507 continue;
1508 ifmgd->auth_alg = algs[pos];
1509 break;
1510 }
1511 }
1512 return;
1513 } 1214 }
1514 1215
1515 switch (ifmgd->auth_alg) { 1216 switch (wk->auth_alg) {
1516 case WLAN_AUTH_OPEN: 1217 case WLAN_AUTH_OPEN:
1517 case WLAN_AUTH_LEAP: 1218 case WLAN_AUTH_LEAP:
1518 case WLAN_AUTH_FT: 1219 case WLAN_AUTH_FT:
1519 ieee80211_auth_completed(sdata); 1220 ieee80211_auth_completed(sdata, wk);
1520 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len); 1221 return RX_MGMT_CFG80211_AUTH;
1521 break;
1522 case WLAN_AUTH_SHARED_KEY: 1222 case WLAN_AUTH_SHARED_KEY:
1523 if (ifmgd->auth_transaction == 4) { 1223 if (wk->auth_transaction == 4) {
1524 ieee80211_auth_completed(sdata); 1224 ieee80211_auth_completed(sdata, wk);
1525 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len); 1225 return RX_MGMT_CFG80211_AUTH;
1526 } else 1226 } else
1527 ieee80211_auth_challenge(sdata, mgmt, len); 1227 ieee80211_auth_challenge(sdata, wk, mgmt, len);
1528 break; 1228 break;
1529 } 1229 }
1230
1231 return RX_MGMT_NONE;
1530} 1232}
1531 1233
1532 1234
1533static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, 1235static enum rx_mgmt_action __must_check
1534 struct ieee80211_mgmt *mgmt, 1236ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1535 size_t len) 1237 struct ieee80211_mgd_work *wk,
1238 struct ieee80211_mgmt *mgmt, size_t len)
1536{ 1239{
1537 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1240 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1241 const u8 *bssid = NULL;
1538 u16 reason_code; 1242 u16 reason_code;
1539 1243
1540 if (len < 24 + 2) 1244 if (len < 24 + 2)
1541 return; 1245 return RX_MGMT_NONE;
1542 1246
1543 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN)) 1247 ASSERT_MGD_MTX(ifmgd);
1544 return; 1248
1249 if (wk)
1250 bssid = wk->bss->cbss.bssid;
1251 else
1252 bssid = ifmgd->associated->cbss.bssid;
1545 1253
1546 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); 1254 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1547 1255
1548 if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED) 1256 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
1549 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n", 1257 sdata->dev->name, bssid, reason_code);
1550 sdata->dev->name, reason_code);
1551 1258
1552 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) && 1259 if (!wk) {
1553 (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE || 1260 ieee80211_set_disassoc(sdata, bssid, true);
1554 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE || 1261 } else {
1555 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) { 1262 list_del(&wk->list);
1556 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE; 1263 kfree(wk);
1557 mod_timer(&ifmgd->timer, jiffies +
1558 IEEE80211_RETRY_AUTH_INTERVAL);
1559 } 1264 }
1560 1265
1561 ieee80211_set_disassoc(sdata, true, false, 0); 1266 return RX_MGMT_CFG80211_DEAUTH;
1562 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
1563 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
1564} 1267}
1565 1268
1566 1269
1567static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, 1270static enum rx_mgmt_action __must_check
1568 struct ieee80211_mgmt *mgmt, 1271ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1569 size_t len) 1272 struct ieee80211_mgmt *mgmt, size_t len)
1570{ 1273{
1571 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1274 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1572 u16 reason_code; 1275 u16 reason_code;
1573 1276
1574 if (len < 24 + 2) 1277 if (len < 24 + 2)
1575 return; 1278 return RX_MGMT_NONE;
1576 1279
1577 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN)) 1280 ASSERT_MGD_MTX(ifmgd);
1578 return;
1579 1281
1580 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 1282 if (WARN_ON(!ifmgd->associated))
1283 return RX_MGMT_NONE;
1581 1284
1582 if (ifmgd->flags & IEEE80211_STA_ASSOCIATED) 1285 if (WARN_ON(memcmp(ifmgd->associated->cbss.bssid, mgmt->sa, ETH_ALEN)))
1583 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n", 1286 return RX_MGMT_NONE;
1584 sdata->dev->name, reason_code);
1585 1287
1586 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) && 1288 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1587 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) { 1289
1588 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE; 1290 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1589 mod_timer(&ifmgd->timer, jiffies + 1291 sdata->dev->name, reason_code);
1590 IEEE80211_RETRY_AUTH_INTERVAL);
1591 }
1592 1292
1593 ieee80211_set_disassoc(sdata, false, false, reason_code); 1293 ieee80211_set_disassoc(sdata, ifmgd->associated->cbss.bssid, false);
1594 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len); 1294 return RX_MGMT_CFG80211_DISASSOC;
1595} 1295}
1596 1296
1597 1297
1598static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, 1298static enum rx_mgmt_action __must_check
1599 struct ieee80211_mgmt *mgmt, 1299ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1600 size_t len, 1300 struct ieee80211_mgd_work *wk,
1601 int reassoc) 1301 struct ieee80211_mgmt *mgmt, size_t len,
1302 bool reassoc)
1602{ 1303{
1603 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1304 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1604 struct ieee80211_local *local = sdata->local; 1305 struct ieee80211_local *local = sdata->local;
@@ -1614,17 +1315,16 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1614 bool have_higher_than_11mbit = false, newsta = false; 1315 bool have_higher_than_11mbit = false, newsta = false;
1615 u16 ap_ht_cap_flags; 1316 u16 ap_ht_cap_flags;
1616 1317
1617 /* AssocResp and ReassocResp have identical structure, so process both 1318 /*
1618 * of them in this function. */ 1319 * AssocResp and ReassocResp have identical structure, so process both
1619 1320 * of them in this function.
1620 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE) 1321 */
1621 return;
1622 1322
1623 if (len < 24 + 6) 1323 if (len < 24 + 6)
1624 return; 1324 return RX_MGMT_NONE;
1625 1325
1626 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0) 1326 if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
1627 return; 1327 return RX_MGMT_NONE;
1628 1328
1629 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); 1329 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1630 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); 1330 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
@@ -1647,26 +1347,19 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1647 printk(KERN_DEBUG "%s: AP rejected association temporarily; " 1347 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1648 "comeback duration %u TU (%u ms)\n", 1348 "comeback duration %u TU (%u ms)\n",
1649 sdata->dev->name, tu, ms); 1349 sdata->dev->name, tu, ms);
1350 wk->timeout = jiffies + msecs_to_jiffies(ms);
1650 if (ms > IEEE80211_ASSOC_TIMEOUT) 1351 if (ms > IEEE80211_ASSOC_TIMEOUT)
1651 mod_timer(&ifmgd->timer, 1352 mod_timer(&ifmgd->timer,
1652 jiffies + msecs_to_jiffies(ms)); 1353 jiffies + msecs_to_jiffies(ms));
1653 return; 1354 return RX_MGMT_NONE;
1654 } 1355 }
1655 1356
1656 if (status_code != WLAN_STATUS_SUCCESS) { 1357 if (status_code != WLAN_STATUS_SUCCESS) {
1657 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", 1358 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1658 sdata->dev->name, status_code); 1359 sdata->dev->name, status_code);
1659 /* if this was a reassociation, ensure we try a "full" 1360 list_del(&wk->list);
1660 * association next time. This works around some broken APs 1361 kfree(wk);
1661 * which do not correctly reject reassociation requests. */ 1362 return RX_MGMT_CFG80211_ASSOC;
1662 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1663 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1664 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1665 /* Wait for SME to decide what to do next */
1666 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1667 ieee80211_recalc_idle(local);
1668 }
1669 return;
1670 } 1363 }
1671 1364
1672 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) 1365 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
@@ -1677,51 +1370,38 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1677 if (!elems.supp_rates) { 1370 if (!elems.supp_rates) {
1678 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", 1371 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1679 sdata->dev->name); 1372 sdata->dev->name);
1680 return; 1373 return RX_MGMT_NONE;
1681 } 1374 }
1682 1375
1683 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name); 1376 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
1684 ifmgd->aid = aid; 1377 ifmgd->aid = aid;
1685 ifmgd->ap_capab = capab_info;
1686
1687 kfree(ifmgd->assocresp_ies);
1688 ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1689 ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
1690 if (ifmgd->assocresp_ies)
1691 memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
1692 1378
1693 rcu_read_lock(); 1379 rcu_read_lock();
1694 1380
1695 /* Add STA entry for the AP */ 1381 /* Add STA entry for the AP */
1696 sta = sta_info_get(local, ifmgd->bssid); 1382 sta = sta_info_get(local, wk->bss->cbss.bssid);
1697 if (!sta) { 1383 if (!sta) {
1698 newsta = true; 1384 newsta = true;
1699 1385
1700 sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC); 1386 rcu_read_unlock();
1387
1388 sta = sta_info_alloc(sdata, wk->bss->cbss.bssid, GFP_KERNEL);
1701 if (!sta) { 1389 if (!sta) {
1702 printk(KERN_DEBUG "%s: failed to alloc STA entry for" 1390 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1703 " the AP\n", sdata->dev->name); 1391 " the AP\n", sdata->dev->name);
1704 rcu_read_unlock(); 1392 return RX_MGMT_NONE;
1705 return;
1706 } 1393 }
1707 1394
1708 /* update new sta with its last rx activity */ 1395 /* update new sta with its last rx activity */
1709 sta->last_rx = jiffies; 1396 sta->last_rx = jiffies;
1710 }
1711 1397
1712 /* 1398 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1713 * FIXME: Do we really need to update the sta_info's information here? 1399 WLAN_STA_ASSOC_AP);
1714 * We already know about the AP (we found it in our list) so it 1400 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1715 * should already be filled with the right info, no? 1401 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1716 * As is stands, all this is racy because typically we assume
1717 * the information that is filled in here (except flags) doesn't
1718 * change while a STA structure is alive. As such, it should move
1719 * to between the sta_info_alloc() and sta_info_insert() above.
1720 */
1721 1402
1722 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP); 1403 rcu_read_lock();
1723 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) 1404 }
1724 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1725 1405
1726 rates = 0; 1406 rates = 0;
1727 basic_rates = 0; 1407 basic_rates = 0;
@@ -1771,8 +1451,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1771 else 1451 else
1772 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; 1452 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
1773 1453
1774 /* If TKIP/WEP is used, no need to parse AP's HT capabilities */ 1454 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
1775 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
1776 ieee80211_ht_cap_ie_to_sta_ht_cap(sband, 1455 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1777 elems.ht_cap_elem, &sta->sta.ht_cap); 1456 elems.ht_cap_elem, &sta->sta.ht_cap);
1778 1457
@@ -1792,7 +1471,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1792 printk(KERN_DEBUG "%s: failed to insert STA entry for" 1471 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1793 " the AP (error %d)\n", sdata->dev->name, err); 1472 " the AP (error %d)\n", sdata->dev->name, err);
1794 rcu_read_unlock(); 1473 rcu_read_unlock();
1795 return; 1474 return RX_MGMT_NONE;
1796 } 1475 }
1797 } 1476 }
1798 1477
@@ -1806,15 +1485,16 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1806 1485
1807 if (elems.ht_info_elem && elems.wmm_param && 1486 if (elems.ht_info_elem && elems.wmm_param &&
1808 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && 1487 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
1809 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) 1488 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
1810 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, 1489 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1490 wk->bss->cbss.bssid,
1811 ap_ht_cap_flags); 1491 ap_ht_cap_flags);
1812 1492
1813 /* set AID and assoc capability, 1493 /* set AID and assoc capability,
1814 * ieee80211_set_associated() will tell the driver */ 1494 * ieee80211_set_associated() will tell the driver */
1815 bss_conf->aid = aid; 1495 bss_conf->aid = aid;
1816 bss_conf->assoc_capability = capab_info; 1496 bss_conf->assoc_capability = capab_info;
1817 ieee80211_set_associated(sdata, changed); 1497 ieee80211_set_associated(sdata, wk->bss, changed);
1818 1498
1819 /* 1499 /*
1820 * initialise the time of last beacon to be the association time, 1500 * initialise the time of last beacon to be the association time,
@@ -1822,8 +1502,9 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1822 */ 1502 */
1823 ifmgd->last_beacon = jiffies; 1503 ifmgd->last_beacon = jiffies;
1824 1504
1825 ieee80211_associated(sdata); 1505 list_del(&wk->list);
1826 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len); 1506 kfree(wk);
1507 return RX_MGMT_CFG80211_ASSOC;
1827} 1508}
1828 1509
1829 1510
@@ -1851,23 +1532,25 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1851 1532
1852 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, 1533 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
1853 channel, beacon); 1534 channel, beacon);
1854 if (!bss) 1535 if (bss)
1536 ieee80211_rx_bss_put(local, bss);
1537
1538 if (!sdata->u.mgd.associated)
1855 return; 1539 return;
1856 1540
1857 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) && 1541 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
1858 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) { 1542 (memcmp(mgmt->bssid, sdata->u.mgd.associated->cbss.bssid,
1543 ETH_ALEN) == 0)) {
1859 struct ieee80211_channel_sw_ie *sw_elem = 1544 struct ieee80211_channel_sw_ie *sw_elem =
1860 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem; 1545 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
1861 ieee80211_sta_process_chanswitch(sdata, sw_elem, bss); 1546 ieee80211_sta_process_chanswitch(sdata, sw_elem, bss);
1862 } 1547 }
1863
1864 ieee80211_rx_bss_put(local, bss);
1865} 1548}
1866 1549
1867 1550
1868static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, 1551static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1869 struct ieee80211_mgmt *mgmt, 1552 struct ieee80211_mgd_work *wk,
1870 size_t len, 1553 struct ieee80211_mgmt *mgmt, size_t len,
1871 struct ieee80211_rx_status *rx_status) 1554 struct ieee80211_rx_status *rx_status)
1872{ 1555{
1873 struct ieee80211_if_managed *ifmgd; 1556 struct ieee80211_if_managed *ifmgd;
@@ -1876,6 +1559,8 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1876 1559
1877 ifmgd = &sdata->u.mgd; 1560 ifmgd = &sdata->u.mgd;
1878 1561
1562 ASSERT_MGD_MTX(ifmgd);
1563
1879 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) 1564 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
1880 return; /* ignore ProbeResp to foreign address */ 1565 return; /* ignore ProbeResp to foreign address */
1881 1566
@@ -1889,13 +1574,17 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1889 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); 1574 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
1890 1575
1891 /* direct probe may be part of the association flow */ 1576 /* direct probe may be part of the association flow */
1892 if (ifmgd->state == IEEE80211_STA_MLME_DIRECT_PROBE) { 1577 if (wk && wk->state == IEEE80211_MGD_STATE_PROBE) {
1893 printk(KERN_DEBUG "%s direct probe responded\n", 1578 printk(KERN_DEBUG "%s direct probe responded\n",
1894 sdata->dev->name); 1579 sdata->dev->name);
1895 ieee80211_authenticate(sdata); 1580 wk->tries = 0;
1581 wk->state = IEEE80211_MGD_STATE_AUTH;
1582 WARN_ON(ieee80211_authenticate(sdata, wk) != RX_MGMT_NONE);
1896 } 1583 }
1897 1584
1898 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) { 1585 if (ifmgd->associated &&
1586 memcmp(mgmt->bssid, ifmgd->associated->cbss.bssid, ETH_ALEN) == 0 &&
1587 ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) {
1899 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL; 1588 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1900 mutex_lock(&sdata->local->iflist_mtx); 1589 mutex_lock(&sdata->local->iflist_mtx);
1901 ieee80211_recalc_ps(sdata->local, -1); 1590 ieee80211_recalc_ps(sdata->local, -1);
@@ -1937,6 +1626,9 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1937 bool erp_valid, directed_tim = false; 1626 bool erp_valid, directed_tim = false;
1938 u8 erp_value = 0; 1627 u8 erp_value = 0;
1939 u32 ncrc; 1628 u32 ncrc;
1629 u8 *bssid;
1630
1631 ASSERT_MGD_MTX(ifmgd);
1940 1632
1941 /* Process beacon from the current BSS */ 1633 /* Process beacon from the current BSS */
1942 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; 1634 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
@@ -1946,8 +1638,12 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1946 if (rx_status->freq != local->hw.conf.channel->center_freq) 1638 if (rx_status->freq != local->hw.conf.channel->center_freq)
1947 return; 1639 return;
1948 1640
1949 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) || 1641 if (WARN_ON(!ifmgd->associated))
1950 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0) 1642 return;
1643
1644 bssid = ifmgd->associated->cbss.bssid;
1645
1646 if (WARN_ON(memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0))
1951 return; 1647 return;
1952 1648
1953 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) { 1649 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) {
@@ -2019,15 +1715,15 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2019 1715
2020 1716
2021 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && 1717 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
2022 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) { 1718 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
2023 struct sta_info *sta; 1719 struct sta_info *sta;
2024 struct ieee80211_supported_band *sband; 1720 struct ieee80211_supported_band *sband;
2025 u16 ap_ht_cap_flags; 1721 u16 ap_ht_cap_flags;
2026 1722
2027 rcu_read_lock(); 1723 rcu_read_lock();
2028 1724
2029 sta = sta_info_get(local, ifmgd->bssid); 1725 sta = sta_info_get(local, bssid);
2030 if (!sta) { 1726 if (WARN_ON(!sta)) {
2031 rcu_read_unlock(); 1727 rcu_read_unlock();
2032 return; 1728 return;
2033 } 1729 }
@@ -2042,7 +1738,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2042 rcu_read_unlock(); 1738 rcu_read_unlock();
2043 1739
2044 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, 1740 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
2045 ap_ht_cap_flags); 1741 bssid, ap_ht_cap_flags);
2046 } 1742 }
2047 1743
2048 if (elems.country_elem) { 1744 if (elems.country_elem) {
@@ -2063,8 +1759,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2063} 1759}
2064 1760
2065ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, 1761ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
2066 struct sk_buff *skb, 1762 struct sk_buff *skb)
2067 struct ieee80211_rx_status *rx_status)
2068{ 1763{
2069 struct ieee80211_local *local = sdata->local; 1764 struct ieee80211_local *local = sdata->local;
2070 struct ieee80211_mgmt *mgmt; 1765 struct ieee80211_mgmt *mgmt;
@@ -2080,12 +1775,12 @@ ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
2080 case IEEE80211_STYPE_PROBE_REQ: 1775 case IEEE80211_STYPE_PROBE_REQ:
2081 case IEEE80211_STYPE_PROBE_RESP: 1776 case IEEE80211_STYPE_PROBE_RESP:
2082 case IEEE80211_STYPE_BEACON: 1777 case IEEE80211_STYPE_BEACON:
2083 memcpy(skb->cb, rx_status, sizeof(*rx_status));
2084 case IEEE80211_STYPE_AUTH: 1778 case IEEE80211_STYPE_AUTH:
2085 case IEEE80211_STYPE_ASSOC_RESP: 1779 case IEEE80211_STYPE_ASSOC_RESP:
2086 case IEEE80211_STYPE_REASSOC_RESP: 1780 case IEEE80211_STYPE_REASSOC_RESP:
2087 case IEEE80211_STYPE_DEAUTH: 1781 case IEEE80211_STYPE_DEAUTH:
2088 case IEEE80211_STYPE_DISASSOC: 1782 case IEEE80211_STYPE_DISASSOC:
1783 case IEEE80211_STYPE_ACTION:
2089 skb_queue_tail(&sdata->u.mgd.skb_queue, skb); 1784 skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
2090 queue_work(local->hw.workqueue, &sdata->u.mgd.work); 1785 queue_work(local->hw.workqueue, &sdata->u.mgd.work);
2091 return RX_QUEUED; 1786 return RX_QUEUED;
@@ -2097,40 +1792,116 @@ ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
2097static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, 1792static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
2098 struct sk_buff *skb) 1793 struct sk_buff *skb)
2099{ 1794{
1795 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2100 struct ieee80211_rx_status *rx_status; 1796 struct ieee80211_rx_status *rx_status;
2101 struct ieee80211_mgmt *mgmt; 1797 struct ieee80211_mgmt *mgmt;
1798 struct ieee80211_mgd_work *wk;
1799 enum rx_mgmt_action rma = RX_MGMT_NONE;
2102 u16 fc; 1800 u16 fc;
2103 1801
2104 rx_status = (struct ieee80211_rx_status *) skb->cb; 1802 rx_status = (struct ieee80211_rx_status *) skb->cb;
2105 mgmt = (struct ieee80211_mgmt *) skb->data; 1803 mgmt = (struct ieee80211_mgmt *) skb->data;
2106 fc = le16_to_cpu(mgmt->frame_control); 1804 fc = le16_to_cpu(mgmt->frame_control);
2107 1805
2108 switch (fc & IEEE80211_FCTL_STYPE) { 1806 mutex_lock(&ifmgd->mtx);
2109 case IEEE80211_STYPE_PROBE_RESP: 1807
2110 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, 1808 if (ifmgd->associated &&
2111 rx_status); 1809 memcmp(ifmgd->associated->cbss.bssid, mgmt->bssid,
2112 break; 1810 ETH_ALEN) == 0) {
2113 case IEEE80211_STYPE_BEACON: 1811 switch (fc & IEEE80211_FCTL_STYPE) {
2114 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, 1812 case IEEE80211_STYPE_BEACON:
2115 rx_status); 1813 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
2116 break; 1814 rx_status);
2117 case IEEE80211_STYPE_AUTH: 1815 break;
2118 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); 1816 case IEEE80211_STYPE_PROBE_RESP:
2119 break; 1817 ieee80211_rx_mgmt_probe_resp(sdata, NULL, mgmt,
2120 case IEEE80211_STYPE_ASSOC_RESP: 1818 skb->len, rx_status);
2121 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0); 1819 break;
1820 case IEEE80211_STYPE_DEAUTH:
1821 rma = ieee80211_rx_mgmt_deauth(sdata, NULL,
1822 mgmt, skb->len);
1823 break;
1824 case IEEE80211_STYPE_DISASSOC:
1825 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1826 break;
1827 case IEEE80211_STYPE_ACTION:
1828 /* XXX: differentiate, can only happen for CSA now! */
1829 ieee80211_sta_process_chanswitch(sdata,
1830 &mgmt->u.action.u.chan_switch.sw_elem,
1831 ifmgd->associated);
1832 break;
1833 }
1834 mutex_unlock(&ifmgd->mtx);
1835
1836 switch (rma) {
1837 case RX_MGMT_NONE:
1838 /* no action */
1839 break;
1840 case RX_MGMT_CFG80211_DEAUTH:
1841 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len,
1842 NULL);
1843 break;
1844 case RX_MGMT_CFG80211_DISASSOC:
1845 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len,
1846 NULL);
1847 break;
1848 default:
1849 WARN(1, "unexpected: %d", rma);
1850 }
1851 goto out;
1852 }
1853
1854 list_for_each_entry(wk, &ifmgd->work_list, list) {
1855 if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
1856 continue;
1857
1858 switch (fc & IEEE80211_FCTL_STYPE) {
1859 case IEEE80211_STYPE_PROBE_RESP:
1860 ieee80211_rx_mgmt_probe_resp(sdata, wk, mgmt, skb->len,
1861 rx_status);
1862 break;
1863 case IEEE80211_STYPE_AUTH:
1864 rma = ieee80211_rx_mgmt_auth(sdata, wk, mgmt, skb->len);
1865 break;
1866 case IEEE80211_STYPE_ASSOC_RESP:
1867 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
1868 skb->len, false);
1869 break;
1870 case IEEE80211_STYPE_REASSOC_RESP:
1871 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
1872 skb->len, true);
1873 break;
1874 case IEEE80211_STYPE_DEAUTH:
1875 rma = ieee80211_rx_mgmt_deauth(sdata, wk, mgmt,
1876 skb->len);
1877 break;
1878 }
1879 /*
1880 * We've processed this frame for that work, so it can't
1881 * belong to another work struct.
1882 * NB: this is also required for correctness because the
1883 * called functions can free 'wk', and for 'rma'!
1884 */
2122 break; 1885 break;
2123 case IEEE80211_STYPE_REASSOC_RESP: 1886 }
2124 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1); 1887
1888 mutex_unlock(&ifmgd->mtx);
1889
1890 switch (rma) {
1891 case RX_MGMT_NONE:
1892 /* no action */
2125 break; 1893 break;
2126 case IEEE80211_STYPE_DEAUTH: 1894 case RX_MGMT_CFG80211_AUTH:
2127 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); 1895 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, skb->len);
2128 break; 1896 break;
2129 case IEEE80211_STYPE_DISASSOC: 1897 case RX_MGMT_CFG80211_ASSOC:
2130 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); 1898 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, skb->len);
2131 break; 1899 break;
1900 default:
1901 WARN(1, "unexpected: %d", rma);
2132 } 1902 }
2133 1903
1904 out:
2134 kfree_skb(skb); 1905 kfree_skb(skb);
2135} 1906}
2136 1907
@@ -2146,125 +1917,9 @@ static void ieee80211_sta_timer(unsigned long data)
2146 return; 1917 return;
2147 } 1918 }
2148 1919
2149 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
2150 queue_work(local->hw.workqueue, &ifmgd->work); 1920 queue_work(local->hw.workqueue, &ifmgd->work);
2151} 1921}
2152 1922
2153static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
2154{
2155 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2156 struct ieee80211_local *local = sdata->local;
2157
2158 /* Reset own TSF to allow time synchronization work. */
2159 drv_reset_tsf(local);
2160
2161 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
2162
2163
2164 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
2165 ifmgd->auth_alg = WLAN_AUTH_OPEN;
2166 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
2167 ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY;
2168 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
2169 ifmgd->auth_alg = WLAN_AUTH_LEAP;
2170 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
2171 ifmgd->auth_alg = WLAN_AUTH_FT;
2172 else
2173 ifmgd->auth_alg = WLAN_AUTH_OPEN;
2174 ifmgd->auth_transaction = -1;
2175 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
2176 ifmgd->assoc_scan_tries = 0;
2177 ifmgd->direct_probe_tries = 0;
2178 ifmgd->auth_tries = 0;
2179 ifmgd->assoc_tries = 0;
2180 netif_tx_stop_all_queues(sdata->dev);
2181 netif_carrier_off(sdata->dev);
2182}
2183
2184static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
2185{
2186 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2187 struct ieee80211_local *local = sdata->local;
2188 struct ieee80211_bss *bss;
2189 u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
2190 u8 ssid_len = ifmgd->ssid_len;
2191 u16 capa_mask = WLAN_CAPABILITY_ESS;
2192 u16 capa_val = WLAN_CAPABILITY_ESS;
2193 struct ieee80211_channel *chan = local->oper_channel;
2194
2195 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
2196 ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
2197 IEEE80211_STA_AUTO_BSSID_SEL |
2198 IEEE80211_STA_AUTO_CHANNEL_SEL)) {
2199 capa_mask |= WLAN_CAPABILITY_PRIVACY;
2200 if (sdata->default_key)
2201 capa_val |= WLAN_CAPABILITY_PRIVACY;
2202 }
2203
2204 if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
2205 chan = NULL;
2206
2207 if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
2208 bssid = NULL;
2209
2210 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
2211 ssid = NULL;
2212 ssid_len = 0;
2213 }
2214
2215 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan,
2216 bssid, ssid, ssid_len,
2217 capa_mask, capa_val);
2218
2219 if (bss) {
2220 local->oper_channel = bss->cbss.channel;
2221 local->oper_channel_type = NL80211_CHAN_NO_HT;
2222 ieee80211_hw_config(local, 0);
2223
2224 if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
2225 ieee80211_sta_set_ssid(sdata, bss->ssid,
2226 bss->ssid_len);
2227 ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
2228 ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
2229 bss->supp_rates);
2230 if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
2231 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
2232 else
2233 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
2234
2235 /* Send out direct probe if no probe resp was received or
2236 * the one we have is outdated
2237 */
2238 if (!bss->last_probe_resp ||
2239 time_after(jiffies, bss->last_probe_resp
2240 + IEEE80211_SCAN_RESULT_EXPIRE))
2241 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
2242 else
2243 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
2244
2245 ieee80211_rx_bss_put(local, bss);
2246 ieee80211_sta_reset_auth(sdata);
2247 return 0;
2248 } else {
2249 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
2250
2251 ifmgd->assoc_scan_tries++;
2252
2253 ieee80211_request_internal_scan(sdata, ifmgd->ssid,
2254 ssid_len);
2255
2256 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
2257 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
2258 } else {
2259 ifmgd->assoc_scan_tries = 0;
2260 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
2261 ieee80211_recalc_idle(local);
2262 }
2263 }
2264 return -1;
2265}
2266
2267
2268static void ieee80211_sta_work(struct work_struct *work) 1923static void ieee80211_sta_work(struct work_struct *work)
2269{ 1924{
2270 struct ieee80211_sub_if_data *sdata = 1925 struct ieee80211_sub_if_data *sdata =
@@ -2272,6 +1927,10 @@ static void ieee80211_sta_work(struct work_struct *work)
2272 struct ieee80211_local *local = sdata->local; 1927 struct ieee80211_local *local = sdata->local;
2273 struct ieee80211_if_managed *ifmgd; 1928 struct ieee80211_if_managed *ifmgd;
2274 struct sk_buff *skb; 1929 struct sk_buff *skb;
1930 struct ieee80211_mgd_work *wk, *tmp;
1931 LIST_HEAD(free_work);
1932 enum rx_mgmt_action rma;
1933 bool anybusy = false;
2275 1934
2276 if (!netif_running(sdata->dev)) 1935 if (!netif_running(sdata->dev))
2277 return; 1936 return;
@@ -2294,54 +1953,91 @@ static void ieee80211_sta_work(struct work_struct *work)
2294 1953
2295 ifmgd = &sdata->u.mgd; 1954 ifmgd = &sdata->u.mgd;
2296 1955
1956 /* first process frames to avoid timing out while a frame is pending */
2297 while ((skb = skb_dequeue(&ifmgd->skb_queue))) 1957 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
2298 ieee80211_sta_rx_queued_mgmt(sdata, skb); 1958 ieee80211_sta_rx_queued_mgmt(sdata, skb);
2299 1959
2300 if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE && 1960 /* then process the rest of the work */
2301 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE && 1961 mutex_lock(&ifmgd->mtx);
2302 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE && 1962
2303 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) { 1963 list_for_each_entry(wk, &ifmgd->work_list, list) {
2304 queue_delayed_work(local->hw.workqueue, &local->scan_work, 1964 if (wk->state != IEEE80211_MGD_STATE_IDLE) {
2305 round_jiffies_relative(0)); 1965 anybusy = true;
2306 return; 1966 break;
1967 }
2307 } 1968 }
2308 1969
2309 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) { 1970 ieee80211_recalc_idle(local);
2310 if (ieee80211_sta_config_auth(sdata)) 1971
2311 return; 1972 if (!anybusy) {
2312 clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request); 1973 mutex_unlock(&ifmgd->mtx);
2313 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request)) 1974
1975 if (test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request))
1976 queue_delayed_work(local->hw.workqueue,
1977 &local->scan_work,
1978 round_jiffies_relative(0));
2314 return; 1979 return;
1980 }
2315 1981
2316 ieee80211_recalc_idle(local); 1982 list_for_each_entry_safe(wk, tmp, &ifmgd->work_list, list) {
1983 if (time_before(jiffies, wk->timeout))
1984 continue;
2317 1985
2318 switch (ifmgd->state) { 1986 switch (wk->state) {
2319 case IEEE80211_STA_MLME_DISABLED: 1987 default:
2320 break; 1988 WARN_ON(1);
2321 case IEEE80211_STA_MLME_DIRECT_PROBE: 1989 /* fall through */
2322 ieee80211_direct_probe(sdata); 1990 case IEEE80211_MGD_STATE_IDLE:
2323 break; 1991 /* nothing */
2324 case IEEE80211_STA_MLME_AUTHENTICATE: 1992 rma = RX_MGMT_NONE;
2325 ieee80211_authenticate(sdata); 1993 break;
2326 break; 1994 case IEEE80211_MGD_STATE_PROBE:
2327 case IEEE80211_STA_MLME_ASSOCIATE: 1995 rma = ieee80211_direct_probe(sdata, wk);
2328 ieee80211_associate(sdata); 1996 break;
2329 break; 1997 case IEEE80211_MGD_STATE_AUTH:
2330 case IEEE80211_STA_MLME_ASSOCIATED: 1998 rma = ieee80211_authenticate(sdata, wk);
2331 ieee80211_associated(sdata); 1999 break;
2332 break; 2000 case IEEE80211_MGD_STATE_ASSOC:
2333 default: 2001 rma = ieee80211_associate(sdata, wk);
2334 WARN_ON(1); 2002 break;
2335 break; 2003 }
2004
2005 switch (rma) {
2006 case RX_MGMT_NONE:
2007 /* no action required */
2008 break;
2009 case RX_MGMT_CFG80211_AUTH_TO:
2010 case RX_MGMT_CFG80211_ASSOC_TO:
2011 list_del(&wk->list);
2012 list_add(&wk->list, &free_work);
2013 wk->tries = rma; /* small abuse but only local */
2014 break;
2015 default:
2016 WARN(1, "unexpected: %d", rma);
2017 }
2336 } 2018 }
2337 2019
2338 if (ieee80211_privacy_mismatch(sdata)) { 2020 mutex_unlock(&ifmgd->mtx);
2339 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
2340 "mixed-cell disabled - disassociate\n", sdata->dev->name);
2341 2021
2342 ieee80211_set_disassoc(sdata, false, true, 2022 list_for_each_entry_safe(wk, tmp, &free_work, list) {
2343 WLAN_REASON_UNSPECIFIED); 2023 switch (wk->tries) {
2024 case RX_MGMT_CFG80211_AUTH_TO:
2025 cfg80211_send_auth_timeout(sdata->dev,
2026 wk->bss->cbss.bssid);
2027 break;
2028 case RX_MGMT_CFG80211_ASSOC_TO:
2029 cfg80211_send_assoc_timeout(sdata->dev,
2030 wk->bss->cbss.bssid);
2031 break;
2032 default:
2033 WARN(1, "unexpected: %d", wk->tries);
2034 }
2035
2036 list_del(&wk->list);
2037 kfree(wk);
2344 } 2038 }
2039
2040 ieee80211_recalc_idle(local);
2345} 2041}
2346 2042
2347static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) 2043static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
@@ -2353,7 +2049,6 @@ static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2353 */ 2049 */
2354 sdata->u.mgd.last_beacon = jiffies; 2050 sdata->u.mgd.last_beacon = jiffies;
2355 2051
2356
2357 queue_work(sdata->local->hw.workqueue, 2052 queue_work(sdata->local->hw.workqueue,
2358 &sdata->u.mgd.work); 2053 &sdata->u.mgd.work);
2359 } 2054 }
@@ -2395,7 +2090,6 @@ void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
2395void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) 2090void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2396{ 2091{
2397 struct ieee80211_if_managed *ifmgd; 2092 struct ieee80211_if_managed *ifmgd;
2398 u32 hw_flags;
2399 2093
2400 ifmgd = &sdata->u.mgd; 2094 ifmgd = &sdata->u.mgd;
2401 INIT_WORK(&ifmgd->work, ieee80211_sta_work); 2095 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
@@ -2407,198 +2101,243 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2407 (unsigned long) sdata); 2101 (unsigned long) sdata);
2408 skb_queue_head_init(&ifmgd->skb_queue); 2102 skb_queue_head_init(&ifmgd->skb_queue);
2409 2103
2104 INIT_LIST_HEAD(&ifmgd->work_list);
2105
2410 ifmgd->capab = WLAN_CAPABILITY_ESS; 2106 ifmgd->capab = WLAN_CAPABILITY_ESS;
2411 ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN | 2107 ifmgd->flags = 0;
2412 IEEE80211_AUTH_ALG_SHARED_KEY;
2413 ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
2414 IEEE80211_STA_AUTO_BSSID_SEL |
2415 IEEE80211_STA_AUTO_CHANNEL_SEL;
2416 if (sdata->local->hw.queues >= 4) 2108 if (sdata->local->hw.queues >= 4)
2417 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED; 2109 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
2418 2110
2419 hw_flags = sdata->local->hw.flags; 2111 mutex_init(&ifmgd->mtx);
2420
2421 if (hw_flags & IEEE80211_HW_SUPPORTS_PS) {
2422 ifmgd->powersave = CONFIG_MAC80211_DEFAULT_PS_VALUE;
2423 sdata->local->hw.conf.dynamic_ps_timeout = 500;
2424 }
2425} 2112}
2426 2113
2427/* configuration hooks */ 2114/* scan finished notification */
2428void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata) 2115void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2429{ 2116{
2430 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2117 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
2431 struct ieee80211_local *local = sdata->local;
2432
2433 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2434 return;
2435
2436 if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
2437 IEEE80211_STA_AUTO_BSSID_SEL)) &&
2438 (ifmgd->flags & (IEEE80211_STA_SSID_SET |
2439 IEEE80211_STA_AUTO_SSID_SEL))) {
2440
2441 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2442 ieee80211_set_disassoc(sdata, true, true,
2443 WLAN_REASON_DEAUTH_LEAVING);
2444
2445 if (ifmgd->ssid_len == 0) {
2446 /*
2447 * Only allow association to be started if a valid SSID
2448 * is configured.
2449 */
2450 return;
2451 }
2452 2118
2453 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) || 2119 /* Restart STA timers */
2454 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE) 2120 rcu_read_lock();
2455 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request); 2121 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2456 else if (ifmgd->flags & IEEE80211_STA_EXT_SME) 2122 ieee80211_restart_sta_timer(sdata);
2457 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request); 2123 rcu_read_unlock();
2458 queue_work(local->hw.workqueue, &ifmgd->work);
2459 }
2460} 2124}
2461 2125
2462int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata) 2126int ieee80211_max_network_latency(struct notifier_block *nb,
2127 unsigned long data, void *dummy)
2463{ 2128{
2464 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2129 s32 latency_usec = (s32) data;
2130 struct ieee80211_local *local =
2131 container_of(nb, struct ieee80211_local,
2132 network_latency_notifier);
2465 2133
2466 if (ifmgd->ssid_len) 2134 mutex_lock(&local->iflist_mtx);
2467 ifmgd->flags |= IEEE80211_STA_SSID_SET; 2135 ieee80211_recalc_ps(local, latency_usec);
2468 else 2136 mutex_unlock(&local->iflist_mtx);
2469 ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
2470 2137
2471 return 0; 2138 return 0;
2472} 2139}
2473 2140
2474int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len) 2141/* config hooks */
2142int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2143 struct cfg80211_auth_request *req)
2475{ 2144{
2476 struct ieee80211_if_managed *ifmgd; 2145 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2146 const u8 *ssid;
2147 struct ieee80211_mgd_work *wk;
2148 u16 auth_alg;
2477 2149
2478 if (len > IEEE80211_MAX_SSID_LEN) 2150 switch (req->auth_type) {
2479 return -EINVAL; 2151 case NL80211_AUTHTYPE_OPEN_SYSTEM:
2152 auth_alg = WLAN_AUTH_OPEN;
2153 break;
2154 case NL80211_AUTHTYPE_SHARED_KEY:
2155 auth_alg = WLAN_AUTH_SHARED_KEY;
2156 break;
2157 case NL80211_AUTHTYPE_FT:
2158 auth_alg = WLAN_AUTH_FT;
2159 break;
2160 case NL80211_AUTHTYPE_NETWORK_EAP:
2161 auth_alg = WLAN_AUTH_LEAP;
2162 break;
2163 default:
2164 return -EOPNOTSUPP;
2165 }
2480 2166
2481 ifmgd = &sdata->u.mgd; 2167 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
2168 if (!wk)
2169 return -ENOMEM;
2482 2170
2483 if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) { 2171 wk->bss = (void *)req->bss;
2484 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2485 ieee80211_set_disassoc(sdata, true, true,
2486 WLAN_REASON_DEAUTH_LEAVING);
2487 2172
2488 /* 2173 if (req->ie && req->ie_len) {
2489 * Do not use reassociation if SSID is changed (different ESS). 2174 memcpy(wk->ie, req->ie, req->ie_len);
2490 */ 2175 wk->ie_len = req->ie_len;
2491 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
2492 memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
2493 memcpy(ifmgd->ssid, ssid, len);
2494 ifmgd->ssid_len = len;
2495 } 2176 }
2496 2177
2497 return ieee80211_sta_commit(sdata); 2178 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
2498} 2179 memcpy(wk->ssid, ssid + 2, ssid[1]);
2180 wk->ssid_len = ssid[1];
2499 2181
2500int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len) 2182 wk->state = IEEE80211_MGD_STATE_PROBE;
2501{ 2183 wk->auth_alg = auth_alg;
2502 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2184
2503 memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len); 2185 /*
2504 *len = ifmgd->ssid_len; 2186 * XXX: if still associated need to tell AP that we're going
2187 * to sleep and then change channel etc.
2188 */
2189 sdata->local->oper_channel = req->bss->channel;
2190 ieee80211_hw_config(sdata->local, 0);
2191
2192 mutex_lock(&ifmgd->mtx);
2193 list_add(&wk->list, &sdata->u.mgd.work_list);
2194 mutex_unlock(&ifmgd->mtx);
2195
2196 queue_work(sdata->local->hw.workqueue, &sdata->u.mgd.work);
2505 return 0; 2197 return 0;
2506} 2198}
2507 2199
2508int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid) 2200int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2201 struct cfg80211_assoc_request *req)
2509{ 2202{
2510 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2203 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2204 struct ieee80211_mgd_work *wk, *found = NULL;
2205 int i, err;
2511 2206
2512 if (compare_ether_addr(bssid, ifmgd->bssid) != 0 && 2207 mutex_lock(&ifmgd->mtx);
2513 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2514 ieee80211_set_disassoc(sdata, true, true,
2515 WLAN_REASON_DEAUTH_LEAVING);
2516 2208
2517 if (is_valid_ether_addr(bssid)) { 2209 list_for_each_entry(wk, &ifmgd->work_list, list) {
2518 memcpy(ifmgd->bssid, bssid, ETH_ALEN); 2210 if (&wk->bss->cbss == req->bss &&
2519 ifmgd->flags |= IEEE80211_STA_BSSID_SET; 2211 wk->state == IEEE80211_MGD_STATE_IDLE) {
2520 } else { 2212 found = wk;
2521 memset(ifmgd->bssid, 0, ETH_ALEN); 2213 break;
2522 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET; 2214 }
2523 } 2215 }
2524 2216
2525 return ieee80211_sta_commit(sdata); 2217 if (!found) {
2526} 2218 err = -ENOLINK;
2219 goto out;
2220 }
2527 2221
2528int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, 2222 list_del(&found->list);
2529 const char *ie, size_t len)
2530{
2531 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2532 2223
2533 if (len == 0 && ifmgd->extra_ie_len == 0) 2224 wk = krealloc(found, sizeof(*wk) + req->ie_len, GFP_KERNEL);
2534 return -EALREADY; 2225 if (!wk) {
2226 list_add(&found->list, &ifmgd->work_list);
2227 err = -ENOMEM;
2228 goto out;
2229 }
2535 2230
2536 if (len == ifmgd->extra_ie_len && ifmgd->extra_ie && 2231 list_add(&wk->list, &ifmgd->work_list);
2537 memcmp(ifmgd->extra_ie, ie, len) == 0)
2538 return -EALREADY;
2539 2232
2540 kfree(ifmgd->extra_ie); 2233 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
2541 if (len == 0) { 2234
2542 ifmgd->extra_ie = NULL; 2235 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2543 ifmgd->extra_ie_len = 0; 2236 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
2544 return 0; 2237 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
2545 } 2238 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2546 ifmgd->extra_ie = kmalloc(len, GFP_KERNEL); 2239 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2547 if (!ifmgd->extra_ie) { 2240
2548 ifmgd->extra_ie_len = 0; 2241 sdata->local->oper_channel = req->bss->channel;
2549 return -ENOMEM; 2242 ieee80211_hw_config(sdata->local, 0);
2243
2244 if (req->ie && req->ie_len) {
2245 memcpy(wk->ie, req->ie, req->ie_len);
2246 wk->ie_len = req->ie_len;
2247 } else
2248 wk->ie_len = 0;
2249
2250 if (req->prev_bssid)
2251 memcpy(wk->prev_bssid, req->prev_bssid, ETH_ALEN);
2252
2253 wk->state = IEEE80211_MGD_STATE_ASSOC;
2254 wk->tries = 0;
2255
2256 if (req->use_mfp) {
2257 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
2258 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
2259 } else {
2260 ifmgd->mfp = IEEE80211_MFP_DISABLED;
2261 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
2550 } 2262 }
2551 memcpy(ifmgd->extra_ie, ie, len);
2552 ifmgd->extra_ie_len = len;
2553 return 0;
2554}
2555 2263
2556int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason) 2264 if (req->crypto.control_port)
2557{ 2265 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
2558 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n", 2266 else
2559 sdata->dev->name, reason); 2267 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2560 2268
2561 ieee80211_set_disassoc(sdata, true, true, reason); 2269 queue_work(sdata->local->hw.workqueue, &sdata->u.mgd.work);
2562 return 0; 2270
2271 err = 0;
2272
2273 out:
2274 mutex_unlock(&ifmgd->mtx);
2275 return err;
2563} 2276}
2564 2277
2565int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason) 2278int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
2279 struct cfg80211_deauth_request *req,
2280 void *cookie)
2566{ 2281{
2567 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2282 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2283 struct ieee80211_mgd_work *wk;
2284 const u8 *bssid = NULL;
2568 2285
2569 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n", 2286 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2570 sdata->dev->name, reason); 2287 sdata->dev->name, req->reason_code);
2288
2289 mutex_lock(&ifmgd->mtx);
2290
2291 if (ifmgd->associated && &ifmgd->associated->cbss == req->bss) {
2292 bssid = req->bss->bssid;
2293 ieee80211_set_disassoc(sdata, bssid, true);
2294 } else list_for_each_entry(wk, &ifmgd->work_list, list) {
2295 if (&wk->bss->cbss == req->bss) {
2296 bssid = req->bss->bssid;
2297 list_del(&wk->list);
2298 kfree(wk);
2299 break;
2300 }
2301 }
2571 2302
2572 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED)) 2303 /* cfg80211 should catch this... */
2304 if (WARN_ON(!bssid)) {
2305 mutex_unlock(&ifmgd->mtx);
2573 return -ENOLINK; 2306 return -ENOLINK;
2307 }
2308
2309 mutex_unlock(&ifmgd->mtx);
2310
2311 ieee80211_send_deauth_disassoc(sdata, bssid,
2312 IEEE80211_STYPE_DEAUTH, req->reason_code,
2313 cookie);
2574 2314
2575 ieee80211_set_disassoc(sdata, false, true, reason);
2576 return 0; 2315 return 0;
2577} 2316}
2578 2317
2579/* scan finished notification */ 2318int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
2580void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) 2319 struct cfg80211_disassoc_request *req,
2320 void *cookie)
2581{ 2321{
2582 struct ieee80211_sub_if_data *sdata = local->scan_sdata; 2322 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2583 2323
2584 /* Restart STA timers */ 2324 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2585 rcu_read_lock(); 2325 sdata->dev->name, req->reason_code);
2586 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2587 ieee80211_restart_sta_timer(sdata);
2588 rcu_read_unlock();
2589}
2590 2326
2591int ieee80211_max_network_latency(struct notifier_block *nb, 2327 mutex_lock(&ifmgd->mtx);
2592 unsigned long data, void *dummy)
2593{
2594 s32 latency_usec = (s32) data;
2595 struct ieee80211_local *local =
2596 container_of(nb, struct ieee80211_local,
2597 network_latency_notifier);
2598 2328
2599 mutex_lock(&local->iflist_mtx); 2329 /* cfg80211 should catch that */
2600 ieee80211_recalc_ps(local, latency_usec); 2330 if (WARN_ON(&ifmgd->associated->cbss != req->bss)) {
2601 mutex_unlock(&local->iflist_mtx); 2331 mutex_unlock(&ifmgd->mtx);
2332 return -ENOLINK;
2333 }
2334
2335 ieee80211_set_disassoc(sdata, req->bss->bssid, false);
2336
2337 mutex_unlock(&ifmgd->mtx);
2602 2338
2339 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
2340 IEEE80211_STYPE_DISASSOC, req->reason_code,
2341 cookie);
2603 return 0; 2342 return 0;
2604} 2343}
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index de5bba7f910a..fe6b99059531 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -30,7 +30,6 @@
30static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, 30static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
31 struct tid_ampdu_rx *tid_agg_rx, 31 struct tid_ampdu_rx *tid_agg_rx,
32 struct sk_buff *skb, 32 struct sk_buff *skb,
33 struct ieee80211_rx_status *status,
34 u16 mpdu_seq_num, 33 u16 mpdu_seq_num,
35 int bar_req); 34 int bar_req);
36/* 35/*
@@ -59,11 +58,11 @@ static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
59 return skb; 58 return skb;
60} 59}
61 60
62static inline int should_drop_frame(struct ieee80211_rx_status *status, 61static inline int should_drop_frame(struct sk_buff *skb,
63 struct sk_buff *skb,
64 int present_fcs_len, 62 int present_fcs_len,
65 int radiotap_len) 63 int radiotap_len)
66{ 64{
65 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
67 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 66 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
68 67
69 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) 68 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
@@ -111,10 +110,10 @@ ieee80211_rx_radiotap_len(struct ieee80211_local *local,
111static void 110static void
112ieee80211_add_rx_radiotap_header(struct ieee80211_local *local, 111ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
113 struct sk_buff *skb, 112 struct sk_buff *skb,
114 struct ieee80211_rx_status *status,
115 struct ieee80211_rate *rate, 113 struct ieee80211_rate *rate,
116 int rtap_len) 114 int rtap_len)
117{ 115{
116 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
118 struct ieee80211_radiotap_header *rthdr; 117 struct ieee80211_radiotap_header *rthdr;
119 unsigned char *pos; 118 unsigned char *pos;
120 119
@@ -220,9 +219,9 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
220 */ 219 */
221static struct sk_buff * 220static struct sk_buff *
222ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb, 221ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
223 struct ieee80211_rx_status *status,
224 struct ieee80211_rate *rate) 222 struct ieee80211_rate *rate)
225{ 223{
224 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
226 struct ieee80211_sub_if_data *sdata; 225 struct ieee80211_sub_if_data *sdata;
227 int needed_headroom = 0; 226 int needed_headroom = 0;
228 struct sk_buff *skb, *skb2; 227 struct sk_buff *skb, *skb2;
@@ -248,8 +247,7 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
248 present_fcs_len = FCS_LEN; 247 present_fcs_len = FCS_LEN;
249 248
250 if (!local->monitors) { 249 if (!local->monitors) {
251 if (should_drop_frame(status, origskb, present_fcs_len, 250 if (should_drop_frame(origskb, present_fcs_len, rtap_len)) {
252 rtap_len)) {
253 dev_kfree_skb(origskb); 251 dev_kfree_skb(origskb);
254 return NULL; 252 return NULL;
255 } 253 }
@@ -257,7 +255,7 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
257 return remove_monitor_info(local, origskb, rtap_len); 255 return remove_monitor_info(local, origskb, rtap_len);
258 } 256 }
259 257
260 if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) { 258 if (should_drop_frame(origskb, present_fcs_len, rtap_len)) {
261 /* only need to expand headroom if necessary */ 259 /* only need to expand headroom if necessary */
262 skb = origskb; 260 skb = origskb;
263 origskb = NULL; 261 origskb = NULL;
@@ -289,7 +287,7 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
289 287
290 /* if necessary, prepend radiotap information */ 288 /* if necessary, prepend radiotap information */
291 if (!(status->flag & RX_FLAG_RADIOTAP)) 289 if (!(status->flag & RX_FLAG_RADIOTAP))
292 ieee80211_add_rx_radiotap_header(local, skb, status, rate, 290 ieee80211_add_rx_radiotap_header(local, skb, rate,
293 needed_headroom); 291 needed_headroom);
294 292
295 skb_reset_mac_header(skb); 293 skb_reset_mac_header(skb);
@@ -421,12 +419,11 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
421 struct sk_buff *skb = rx->skb; 419 struct sk_buff *skb = rx->skb;
422 420
423 if (unlikely(local->hw_scanning)) 421 if (unlikely(local->hw_scanning))
424 return ieee80211_scan_rx(rx->sdata, skb, rx->status); 422 return ieee80211_scan_rx(rx->sdata, skb);
425 423
426 if (unlikely(local->sw_scanning)) { 424 if (unlikely(local->sw_scanning)) {
427 /* drop all the other packets during a software scan anyway */ 425 /* drop all the other packets during a software scan anyway */
428 if (ieee80211_scan_rx(rx->sdata, skb, rx->status) 426 if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
429 != RX_QUEUED)
430 dev_kfree_skb(skb); 427 dev_kfree_skb(skb);
431 return RX_QUEUED; 428 return RX_QUEUED;
432 } 429 }
@@ -1620,7 +1617,7 @@ ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
1620 /* manage reordering buffer according to requested */ 1617 /* manage reordering buffer according to requested */
1621 /* sequence number */ 1618 /* sequence number */
1622 rcu_read_lock(); 1619 rcu_read_lock();
1623 ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL, NULL, 1620 ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL,
1624 start_seq_num, 1); 1621 start_seq_num, 1);
1625 rcu_read_unlock(); 1622 rcu_read_unlock();
1626 return RX_DROP_UNUSABLE; 1623 return RX_DROP_UNUSABLE;
@@ -1644,12 +1641,7 @@ static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
1644 1641
1645 if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 || 1642 if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 ||
1646 compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) { 1643 compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) {
1647 /* Not from the current AP. */ 1644 /* Not from the current AP or not associated yet. */
1648 return;
1649 }
1650
1651 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATE) {
1652 /* Association in progress; ignore SA Query */
1653 return; 1645 return;
1654 } 1646 }
1655 1647
@@ -1686,7 +1678,6 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1686 struct ieee80211_local *local = rx->local; 1678 struct ieee80211_local *local = rx->local;
1687 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); 1679 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1688 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; 1680 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
1689 struct ieee80211_bss *bss;
1690 int len = rx->skb->len; 1681 int len = rx->skb->len;
1691 1682
1692 if (!ieee80211_is_action(mgmt->frame_control)) 1683 if (!ieee80211_is_action(mgmt->frame_control))
@@ -1764,17 +1755,7 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1764 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN)) 1755 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN))
1765 return RX_DROP_MONITOR; 1756 return RX_DROP_MONITOR;
1766 1757
1767 bss = ieee80211_rx_bss_get(local, sdata->u.mgd.bssid, 1758 return ieee80211_sta_rx_mgmt(sdata, rx->skb);
1768 local->hw.conf.channel->center_freq,
1769 sdata->u.mgd.ssid,
1770 sdata->u.mgd.ssid_len);
1771 if (!bss)
1772 return RX_DROP_MONITOR;
1773
1774 ieee80211_sta_process_chanswitch(sdata,
1775 &mgmt->u.action.u.chan_switch.sw_elem, bss);
1776 ieee80211_rx_bss_put(local, bss);
1777 break;
1778 } 1759 }
1779 break; 1760 break;
1780 case WLAN_CATEGORY_SA_QUERY: 1761 case WLAN_CATEGORY_SA_QUERY:
@@ -1817,13 +1798,13 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
1817 return RX_DROP_MONITOR; 1798 return RX_DROP_MONITOR;
1818 1799
1819 if (ieee80211_vif_is_mesh(&sdata->vif)) 1800 if (ieee80211_vif_is_mesh(&sdata->vif))
1820 return ieee80211_mesh_rx_mgmt(sdata, rx->skb, rx->status); 1801 return ieee80211_mesh_rx_mgmt(sdata, rx->skb);
1821 1802
1822 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 1803 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
1823 return ieee80211_ibss_rx_mgmt(sdata, rx->skb, rx->status); 1804 return ieee80211_ibss_rx_mgmt(sdata, rx->skb);
1824 1805
1825 if (sdata->vif.type == NL80211_IFTYPE_STATION) 1806 if (sdata->vif.type == NL80211_IFTYPE_STATION)
1826 return ieee80211_sta_rx_mgmt(sdata, rx->skb, rx->status); 1807 return ieee80211_sta_rx_mgmt(sdata, rx->skb);
1827 1808
1828 return RX_DROP_MONITOR; 1809 return RX_DROP_MONITOR;
1829} 1810}
@@ -1866,7 +1847,8 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1866 !ieee80211_is_auth(hdr->frame_control)) 1847 !ieee80211_is_auth(hdr->frame_control))
1867 goto ignore; 1848 goto ignore;
1868 1849
1869 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL); 1850 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL,
1851 GFP_ATOMIC);
1870 ignore: 1852 ignore:
1871 dev_kfree_skb(rx->skb); 1853 dev_kfree_skb(rx->skb);
1872 rx->skb = NULL; 1854 rx->skb = NULL;
@@ -2028,13 +2010,8 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
2028 case NL80211_IFTYPE_STATION: 2010 case NL80211_IFTYPE_STATION:
2029 if (!bssid) 2011 if (!bssid)
2030 return 0; 2012 return 0;
2031 if (!ieee80211_bssid_match(bssid, sdata->u.mgd.bssid)) { 2013 if (!multicast &&
2032 if (!(rx->flags & IEEE80211_RX_IN_SCAN)) 2014 compare_ether_addr(sdata->dev->dev_addr, hdr->addr1) != 0) {
2033 return 0;
2034 rx->flags &= ~IEEE80211_RX_RA_MATCH;
2035 } else if (!multicast &&
2036 compare_ether_addr(sdata->dev->dev_addr,
2037 hdr->addr1) != 0) {
2038 if (!(sdata->dev->flags & IFF_PROMISC)) 2015 if (!(sdata->dev->flags & IFF_PROMISC))
2039 return 0; 2016 return 0;
2040 rx->flags &= ~IEEE80211_RX_RA_MATCH; 2017 rx->flags &= ~IEEE80211_RX_RA_MATCH;
@@ -2114,9 +2091,9 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
2114 */ 2091 */
2115static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, 2092static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2116 struct sk_buff *skb, 2093 struct sk_buff *skb,
2117 struct ieee80211_rx_status *status,
2118 struct ieee80211_rate *rate) 2094 struct ieee80211_rate *rate)
2119{ 2095{
2096 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2120 struct ieee80211_local *local = hw_to_local(hw); 2097 struct ieee80211_local *local = hw_to_local(hw);
2121 struct ieee80211_sub_if_data *sdata; 2098 struct ieee80211_sub_if_data *sdata;
2122 struct ieee80211_hdr *hdr; 2099 struct ieee80211_hdr *hdr;
@@ -2227,20 +2204,21 @@ static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
2227{ 2204{
2228 struct ieee80211_supported_band *sband; 2205 struct ieee80211_supported_band *sband;
2229 struct ieee80211_rate *rate; 2206 struct ieee80211_rate *rate;
2230 struct ieee80211_rx_status status; 2207 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
2208 struct ieee80211_rx_status *status;
2231 2209
2232 if (!tid_agg_rx->reorder_buf[index]) 2210 if (!skb)
2233 goto no_frame; 2211 goto no_frame;
2234 2212
2213 status = IEEE80211_SKB_RXCB(skb);
2214
2235 /* release the reordered frames to stack */ 2215 /* release the reordered frames to stack */
2236 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, sizeof(status)); 2216 sband = hw->wiphy->bands[status->band];
2237 sband = hw->wiphy->bands[status.band]; 2217 if (status->flag & RX_FLAG_HT)
2238 if (status.flag & RX_FLAG_HT)
2239 rate = sband->bitrates; /* TODO: HT rates */ 2218 rate = sband->bitrates; /* TODO: HT rates */
2240 else 2219 else
2241 rate = &sband->bitrates[status.rate_idx]; 2220 rate = &sband->bitrates[status->rate_idx];
2242 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index], 2221 __ieee80211_rx_handle_packet(hw, skb, rate);
2243 &status, rate);
2244 tid_agg_rx->stored_mpdu_num--; 2222 tid_agg_rx->stored_mpdu_num--;
2245 tid_agg_rx->reorder_buf[index] = NULL; 2223 tid_agg_rx->reorder_buf[index] = NULL;
2246 2224
@@ -2265,7 +2243,6 @@ no_frame:
2265static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, 2243static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2266 struct tid_ampdu_rx *tid_agg_rx, 2244 struct tid_ampdu_rx *tid_agg_rx,
2267 struct sk_buff *skb, 2245 struct sk_buff *skb,
2268 struct ieee80211_rx_status *rxstatus,
2269 u16 mpdu_seq_num, 2246 u16 mpdu_seq_num,
2270 int bar_req) 2247 int bar_req)
2271{ 2248{
@@ -2324,8 +2301,6 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2324 /* put the frame in the reordering buffer */ 2301 /* put the frame in the reordering buffer */
2325 tid_agg_rx->reorder_buf[index] = skb; 2302 tid_agg_rx->reorder_buf[index] = skb;
2326 tid_agg_rx->reorder_time[index] = jiffies; 2303 tid_agg_rx->reorder_time[index] = jiffies;
2327 memcpy(tid_agg_rx->reorder_buf[index]->cb, rxstatus,
2328 sizeof(*rxstatus));
2329 tid_agg_rx->stored_mpdu_num++; 2304 tid_agg_rx->stored_mpdu_num++;
2330 /* release the buffer until next missing frame */ 2305 /* release the buffer until next missing frame */
2331 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) 2306 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn)
@@ -2374,8 +2349,7 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2374} 2349}
2375 2350
2376static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local, 2351static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
2377 struct sk_buff *skb, 2352 struct sk_buff *skb)
2378 struct ieee80211_rx_status *status)
2379{ 2353{
2380 struct ieee80211_hw *hw = &local->hw; 2354 struct ieee80211_hw *hw = &local->hw;
2381 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 2355 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
@@ -2424,7 +2398,7 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
2424 2398
2425 /* according to mpdu sequence number deal with reordering buffer */ 2399 /* according to mpdu sequence number deal with reordering buffer */
2426 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4; 2400 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
2427 ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb, status, 2401 ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb,
2428 mpdu_seq_num, 0); 2402 mpdu_seq_num, 0);
2429 end_reorder: 2403 end_reorder:
2430 return ret; 2404 return ret;
@@ -2434,12 +2408,12 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
2434 * This is the receive path handler. It is called by a low level driver when an 2408 * This is the receive path handler. It is called by a low level driver when an
2435 * 802.11 MPDU is received from the hardware. 2409 * 802.11 MPDU is received from the hardware.
2436 */ 2410 */
2437void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 2411void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
2438 struct ieee80211_rx_status *status)
2439{ 2412{
2440 struct ieee80211_local *local = hw_to_local(hw); 2413 struct ieee80211_local *local = hw_to_local(hw);
2441 struct ieee80211_rate *rate = NULL; 2414 struct ieee80211_rate *rate = NULL;
2442 struct ieee80211_supported_band *sband; 2415 struct ieee80211_supported_band *sband;
2416 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2443 2417
2444 if (status->band < 0 || 2418 if (status->band < 0 ||
2445 status->band >= IEEE80211_NUM_BANDS) { 2419 status->band >= IEEE80211_NUM_BANDS) {
@@ -2482,7 +2456,7 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2482 * if it was previously present. 2456 * if it was previously present.
2483 * Also, frames with less than 16 bytes are dropped. 2457 * Also, frames with less than 16 bytes are dropped.
2484 */ 2458 */
2485 skb = ieee80211_rx_monitor(local, skb, status, rate); 2459 skb = ieee80211_rx_monitor(local, skb, rate);
2486 if (!skb) { 2460 if (!skb) {
2487 rcu_read_unlock(); 2461 rcu_read_unlock();
2488 return; 2462 return;
@@ -2500,8 +2474,8 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2500 * frames from other than operational channel), but that should not 2474 * frames from other than operational channel), but that should not
2501 * happen in normal networks. 2475 * happen in normal networks.
2502 */ 2476 */
2503 if (!ieee80211_rx_reorder_ampdu(local, skb, status)) 2477 if (!ieee80211_rx_reorder_ampdu(local, skb))
2504 __ieee80211_rx_handle_packet(hw, skb, status, rate); 2478 __ieee80211_rx_handle_packet(hw, skb, rate);
2505 2479
2506 rcu_read_unlock(); 2480 rcu_read_unlock();
2507} 2481}
@@ -2509,16 +2483,13 @@ EXPORT_SYMBOL(__ieee80211_rx);
2509 2483
2510/* This is a version of the rx handler that can be called from hard irq 2484/* This is a version of the rx handler that can be called from hard irq
2511 * context. Post the skb on the queue and schedule the tasklet */ 2485 * context. Post the skb on the queue and schedule the tasklet */
2512void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb, 2486void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
2513 struct ieee80211_rx_status *status)
2514{ 2487{
2515 struct ieee80211_local *local = hw_to_local(hw); 2488 struct ieee80211_local *local = hw_to_local(hw);
2516 2489
2517 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb)); 2490 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
2518 2491
2519 skb->dev = local->mdev; 2492 skb->dev = local->mdev;
2520 /* copy status into skb->cb for use by tasklet */
2521 memcpy(skb->cb, status, sizeof(*status));
2522 skb->pkt_type = IEEE80211_RX_MSG; 2493 skb->pkt_type = IEEE80211_RX_MSG;
2523 skb_queue_tail(&local->skb_queue, skb); 2494 skb_queue_tail(&local->skb_queue, skb);
2524 tasklet_schedule(&local->tasklet); 2495 tasklet_schedule(&local->tasklet);
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 2a8d09ad17ff..5f4f7869d050 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -26,7 +26,7 @@
26 26
27#define IEEE80211_PROBE_DELAY (HZ / 33) 27#define IEEE80211_PROBE_DELAY (HZ / 33)
28#define IEEE80211_CHANNEL_TIME (HZ / 33) 28#define IEEE80211_CHANNEL_TIME (HZ / 33)
29#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) 29#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 8)
30 30
31struct ieee80211_bss * 31struct ieee80211_bss *
32ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, 32ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
@@ -121,23 +121,10 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
121 return bss; 121 return bss;
122} 122}
123 123
124void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid,
125 int freq, u8 *ssid, u8 ssid_len)
126{
127 struct ieee80211_bss *bss;
128 struct ieee80211_local *local = sdata->local;
129
130 bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len);
131 if (bss) {
132 cfg80211_unlink_bss(local->hw.wiphy, (void *)bss);
133 ieee80211_rx_bss_put(local, bss);
134 }
135}
136
137ieee80211_rx_result 124ieee80211_rx_result
138ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 125ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
139 struct ieee80211_rx_status *rx_status)
140{ 126{
127 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
141 struct ieee80211_mgmt *mgmt; 128 struct ieee80211_mgmt *mgmt;
142 struct ieee80211_bss *bss; 129 struct ieee80211_bss *bss;
143 u8 *elements; 130 u8 *elements;
@@ -327,7 +314,7 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
327 314
328 /* Tell AP we're back */ 315 /* Tell AP we're back */
329 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 316 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
330 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { 317 if (sdata->u.mgd.associated) {
331 ieee80211_scan_ps_disable(sdata); 318 ieee80211_scan_ps_disable(sdata);
332 netif_tx_wake_all_queues(sdata->dev); 319 netif_tx_wake_all_queues(sdata->dev);
333 } 320 }
@@ -383,7 +370,7 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local)
383 sdata, BSS_CHANGED_BEACON_ENABLED); 370 sdata, BSS_CHANGED_BEACON_ENABLED);
384 371
385 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 372 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
386 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { 373 if (sdata->u.mgd.associated) {
387 netif_tx_stop_all_queues(sdata->dev); 374 netif_tx_stop_all_queues(sdata->dev);
388 ieee80211_scan_ps_enable(sdata); 375 ieee80211_scan_ps_enable(sdata);
389 } 376 }
@@ -443,10 +430,8 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
443 430
444 if (req != &local->int_scan_req && 431 if (req != &local->int_scan_req &&
445 sdata->vif.type == NL80211_IFTYPE_STATION && 432 sdata->vif.type == NL80211_IFTYPE_STATION &&
446 (ifmgd->state == IEEE80211_STA_MLME_DIRECT_PROBE || 433 !list_empty(&ifmgd->work_list)) {
447 ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE || 434 /* actually wait for the work it's doing to finish/time out */
448 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE)) {
449 /* actually wait for the assoc to finish/time out */
450 set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request); 435 set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request);
451 return 0; 436 return 0;
452 } 437 }
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 49a1a1f76511..4ecf10a9bd00 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -308,6 +308,23 @@ struct sta_info {
308 struct dentry *inactive_ms; 308 struct dentry *inactive_ms;
309 struct dentry *last_seq_ctrl; 309 struct dentry *last_seq_ctrl;
310 struct dentry *agg_status; 310 struct dentry *agg_status;
311 struct dentry *aid;
312 struct dentry *dev;
313 struct dentry *rx_packets;
314 struct dentry *tx_packets;
315 struct dentry *rx_bytes;
316 struct dentry *tx_bytes;
317 struct dentry *rx_duplicates;
318 struct dentry *rx_fragments;
319 struct dentry *rx_dropped;
320 struct dentry *tx_fragments;
321 struct dentry *tx_filtered;
322 struct dentry *tx_retry_failed;
323 struct dentry *tx_retry_count;
324 struct dentry *last_signal;
325 struct dentry *last_qual;
326 struct dentry *last_noise;
327 struct dentry *wep_weak_iv_count;
311 bool add_has_run; 328 bool add_has_run;
312 } debugfs; 329 } debugfs;
313#endif 330#endif
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index d238a8939a09..2ffb35d3f566 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1627,7 +1627,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1627 u32 sta_flags = 0; 1627 u32 sta_flags = 0;
1628 1628
1629 if (unlikely(skb->len < ETH_HLEN)) { 1629 if (unlikely(skb->len < ETH_HLEN)) {
1630 ret = 0; 1630 ret = NETDEV_TX_OK;
1631 goto fail; 1631 goto fail;
1632 } 1632 }
1633 1633
@@ -1664,7 +1664,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1664 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) { 1664 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) {
1665 /* Do not send frames with mesh_ttl == 0 */ 1665 /* Do not send frames with mesh_ttl == 0 */
1666 sdata->u.mesh.mshstats.dropped_frames_ttl++; 1666 sdata->u.mesh.mshstats.dropped_frames_ttl++;
1667 ret = 0; 1667 ret = NETDEV_TX_OK;
1668 goto fail; 1668 goto fail;
1669 } 1669 }
1670 memset(&mesh_hdr, 0, sizeof(mesh_hdr)); 1670 memset(&mesh_hdr, 0, sizeof(mesh_hdr));
@@ -1724,7 +1724,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1724 hdrlen = 24; 1724 hdrlen = 24;
1725 break; 1725 break;
1726 default: 1726 default:
1727 ret = 0; 1727 ret = NETDEV_TX_OK;
1728 goto fail; 1728 goto fail;
1729 } 1729 }
1730 1730
@@ -1766,7 +1766,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1766 1766
1767 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); 1767 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
1768 1768
1769 ret = 0; 1769 ret = NETDEV_TX_OK;
1770 goto fail; 1770 goto fail;
1771 } 1771 }
1772 1772
@@ -1858,10 +1858,10 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1858 dev->trans_start = jiffies; 1858 dev->trans_start = jiffies;
1859 dev_queue_xmit(skb); 1859 dev_queue_xmit(skb);
1860 1860
1861 return 0; 1861 return NETDEV_TX_OK;
1862 1862
1863 fail: 1863 fail:
1864 if (!ret) 1864 if (ret == NETDEV_TX_OK)
1865 dev_kfree_skb(skb); 1865 dev_kfree_skb(skb);
1866 1866
1867 return ret; 1867 return ret;
diff --git a/net/mac80211/wep.c b/net/mac80211/wep.c
index ef73105b3061..4fafb2d27c84 100644
--- a/net/mac80211/wep.c
+++ b/net/mac80211/wep.c
@@ -67,10 +67,10 @@ static inline bool ieee80211_wep_weak_iv(u32 iv, int keylen)
67 67
68 68
69static void ieee80211_wep_get_iv(struct ieee80211_local *local, 69static void ieee80211_wep_get_iv(struct ieee80211_local *local,
70 struct ieee80211_key *key, u8 *iv) 70 int keylen, int keyidx, u8 *iv)
71{ 71{
72 local->wep_iv++; 72 local->wep_iv++;
73 if (ieee80211_wep_weak_iv(local->wep_iv, key->conf.keylen)) 73 if (ieee80211_wep_weak_iv(local->wep_iv, keylen))
74 local->wep_iv += 0x0100; 74 local->wep_iv += 0x0100;
75 75
76 if (!iv) 76 if (!iv)
@@ -79,13 +79,13 @@ static void ieee80211_wep_get_iv(struct ieee80211_local *local,
79 *iv++ = (local->wep_iv >> 16) & 0xff; 79 *iv++ = (local->wep_iv >> 16) & 0xff;
80 *iv++ = (local->wep_iv >> 8) & 0xff; 80 *iv++ = (local->wep_iv >> 8) & 0xff;
81 *iv++ = local->wep_iv & 0xff; 81 *iv++ = local->wep_iv & 0xff;
82 *iv++ = key->conf.keyidx << 6; 82 *iv++ = keyidx << 6;
83} 83}
84 84
85 85
86static u8 *ieee80211_wep_add_iv(struct ieee80211_local *local, 86static u8 *ieee80211_wep_add_iv(struct ieee80211_local *local,
87 struct sk_buff *skb, 87 struct sk_buff *skb,
88 struct ieee80211_key *key) 88 int keylen, int keyidx)
89{ 89{
90 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 90 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
91 unsigned int hdrlen; 91 unsigned int hdrlen;
@@ -100,7 +100,7 @@ static u8 *ieee80211_wep_add_iv(struct ieee80211_local *local,
100 hdrlen = ieee80211_hdrlen(hdr->frame_control); 100 hdrlen = ieee80211_hdrlen(hdr->frame_control);
101 newhdr = skb_push(skb, WEP_IV_LEN); 101 newhdr = skb_push(skb, WEP_IV_LEN);
102 memmove(newhdr, newhdr + WEP_IV_LEN, hdrlen); 102 memmove(newhdr, newhdr + WEP_IV_LEN, hdrlen);
103 ieee80211_wep_get_iv(local, key, newhdr + hdrlen); 103 ieee80211_wep_get_iv(local, keylen, keyidx, newhdr + hdrlen);
104 return newhdr + hdrlen; 104 return newhdr + hdrlen;
105} 105}
106 106
@@ -144,26 +144,17 @@ void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
144 * 144 *
145 * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data)) 145 * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data))
146 */ 146 */
147int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb, 147static int ieee80211_wep_encrypt(struct ieee80211_local *local,
148 struct ieee80211_key *key) 148 struct sk_buff *skb,
149 const u8 *key, int keylen, int keyidx)
149{ 150{
150 u32 klen; 151 u8 *iv;
151 u8 *rc4key, *iv;
152 size_t len; 152 size_t len;
153 u8 rc4key[3 + WLAN_KEY_LEN_WEP104];
153 154
154 if (!key || key->conf.alg != ALG_WEP) 155 iv = ieee80211_wep_add_iv(local, skb, keylen, keyidx);
155 return -1; 156 if (!iv)
156
157 klen = 3 + key->conf.keylen;
158 rc4key = kmalloc(klen, GFP_ATOMIC);
159 if (!rc4key)
160 return -1;
161
162 iv = ieee80211_wep_add_iv(local, skb, key);
163 if (!iv) {
164 kfree(rc4key);
165 return -1; 157 return -1;
166 }
167 158
168 len = skb->len - (iv + WEP_IV_LEN - skb->data); 159 len = skb->len - (iv + WEP_IV_LEN - skb->data);
169 160
@@ -171,16 +162,14 @@ int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
171 memcpy(rc4key, iv, 3); 162 memcpy(rc4key, iv, 3);
172 163
173 /* Copy rest of the WEP key (the secret part) */ 164 /* Copy rest of the WEP key (the secret part) */
174 memcpy(rc4key + 3, key->conf.key, key->conf.keylen); 165 memcpy(rc4key + 3, key, keylen);
175 166
176 /* Add room for ICV */ 167 /* Add room for ICV */
177 skb_put(skb, WEP_ICV_LEN); 168 skb_put(skb, WEP_ICV_LEN);
178 169
179 ieee80211_wep_encrypt_data(local->wep_tx_tfm, rc4key, klen, 170 ieee80211_wep_encrypt_data(local->wep_tx_tfm, rc4key, keylen + 3,
180 iv + WEP_IV_LEN, len); 171 iv + WEP_IV_LEN, len);
181 172
182 kfree(rc4key);
183
184 return 0; 173 return 0;
185} 174}
186 175
@@ -216,8 +205,9 @@ int ieee80211_wep_decrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
216 * failure. If frame is OK, IV and ICV will be removed, i.e., decrypted payload 205 * failure. If frame is OK, IV and ICV will be removed, i.e., decrypted payload
217 * is moved to the beginning of the skb and skb length will be reduced. 206 * is moved to the beginning of the skb and skb length will be reduced.
218 */ 207 */
219int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb, 208static int ieee80211_wep_decrypt(struct ieee80211_local *local,
220 struct ieee80211_key *key) 209 struct sk_buff *skb,
210 struct ieee80211_key *key)
221{ 211{
222 u32 klen; 212 u32 klen;
223 u8 *rc4key; 213 u8 *rc4key;
@@ -314,12 +304,16 @@ static int wep_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
314 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 304 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
315 305
316 if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) { 306 if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
317 if (ieee80211_wep_encrypt(tx->local, skb, tx->key)) 307 if (ieee80211_wep_encrypt(tx->local, skb, tx->key->conf.key,
308 tx->key->conf.keylen,
309 tx->key->conf.keyidx))
318 return -1; 310 return -1;
319 } else { 311 } else {
320 info->control.hw_key = &tx->key->conf; 312 info->control.hw_key = &tx->key->conf;
321 if (tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) { 313 if (tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) {
322 if (!ieee80211_wep_add_iv(tx->local, skb, tx->key)) 314 if (!ieee80211_wep_add_iv(tx->local, skb,
315 tx->key->conf.keylen,
316 tx->key->conf.keyidx))
323 return -1; 317 return -1;
324 } 318 }
325 } 319 }
diff --git a/net/mac80211/wep.h b/net/mac80211/wep.h
index d3f0db48314e..85219ded8703 100644
--- a/net/mac80211/wep.h
+++ b/net/mac80211/wep.h
@@ -22,10 +22,6 @@ void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
22 size_t klen, u8 *data, size_t data_len); 22 size_t klen, u8 *data, size_t data_len);
23int ieee80211_wep_decrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key, 23int ieee80211_wep_decrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
24 size_t klen, u8 *data, size_t data_len); 24 size_t klen, u8 *data, size_t data_len);
25int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
26 struct ieee80211_key *key);
27int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
28 struct ieee80211_key *key);
29bool ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key); 25bool ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key);
30 26
31ieee80211_rx_result 27ieee80211_rx_result
diff --git a/net/mac80211/wext.c b/net/mac80211/wext.c
index 1da81f456744..5acb8140ee58 100644
--- a/net/mac80211/wext.c
+++ b/net/mac80211/wext.c
@@ -27,29 +27,6 @@
27#include "aes_ccm.h" 27#include "aes_ccm.h"
28 28
29 29
30static int ieee80211_ioctl_siwgenie(struct net_device *dev,
31 struct iw_request_info *info,
32 struct iw_point *data, char *extra)
33{
34 struct ieee80211_sub_if_data *sdata;
35
36 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
37
38 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
39 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
40 if (ret && ret != -EALREADY)
41 return ret;
42 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
43 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
44 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
45 if (ret != -EALREADY)
46 ieee80211_sta_req_auth(sdata);
47 return 0;
48 }
49
50 return -EOPNOTSUPP;
51}
52
53static int ieee80211_ioctl_siwfreq(struct net_device *dev, 30static int ieee80211_ioctl_siwfreq(struct net_device *dev,
54 struct iw_request_info *info, 31 struct iw_request_info *info,
55 struct iw_freq *freq, char *extra) 32 struct iw_freq *freq, char *extra)
@@ -61,16 +38,13 @@ static int ieee80211_ioctl_siwfreq(struct net_device *dev,
61 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 38 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
62 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra); 39 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
63 else if (sdata->vif.type == NL80211_IFTYPE_STATION) 40 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
64 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; 41 return cfg80211_mgd_wext_siwfreq(dev, info, freq, extra);
65 42
66 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ 43 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
67 if (freq->e == 0) { 44 if (freq->e == 0) {
68 if (freq->m < 0) { 45 if (freq->m < 0)
69 if (sdata->vif.type == NL80211_IFTYPE_STATION) 46 return -EINVAL;
70 sdata->u.mgd.flags |= 47 else
71 IEEE80211_STA_AUTO_CHANNEL_SEL;
72 return 0;
73 } else
74 chan = ieee80211_get_channel(local->hw.wiphy, 48 chan = ieee80211_get_channel(local->hw.wiphy,
75 ieee80211_channel_to_frequency(freq->m)); 49 ieee80211_channel_to_frequency(freq->m));
76 } else { 50 } else {
@@ -95,9 +69,6 @@ static int ieee80211_ioctl_siwfreq(struct net_device *dev,
95 if (local->oper_channel == chan) 69 if (local->oper_channel == chan)
96 return 0; 70 return 0;
97 71
98 if (sdata->vif.type == NL80211_IFTYPE_STATION)
99 ieee80211_sta_req_auth(sdata);
100
101 local->oper_channel = chan; 72 local->oper_channel = chan;
102 local->oper_channel_type = NL80211_CHAN_NO_HT; 73 local->oper_channel_type = NL80211_CHAN_NO_HT;
103 ieee80211_hw_config(local, 0); 74 ieee80211_hw_config(local, 0);
@@ -115,6 +86,8 @@ static int ieee80211_ioctl_giwfreq(struct net_device *dev,
115 86
116 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 87 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
117 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra); 88 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
89 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
90 return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
118 91
119 freq->m = local->oper_channel->center_freq; 92 freq->m = local->oper_channel->center_freq;
120 freq->e = 6; 93 freq->e = 6;
@@ -128,31 +101,11 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
128 struct iw_point *data, char *ssid) 101 struct iw_point *data, char *ssid)
129{ 102{
130 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 103 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
131 size_t len = data->length;
132 int ret;
133 104
134 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 105 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
135 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid); 106 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
136 107 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
137 /* iwconfig uses nul termination in SSID.. */ 108 return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
138 if (len > 0 && ssid[len - 1] == '\0')
139 len--;
140
141 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
142 if (data->flags)
143 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
144 else
145 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
146
147 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
148 if (ret)
149 return ret;
150
151 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
152 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
153 ieee80211_sta_req_auth(sdata);
154 return 0;
155 }
156 109
157 return -EOPNOTSUPP; 110 return -EOPNOTSUPP;
158} 111}
@@ -162,23 +115,14 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
162 struct iw_request_info *info, 115 struct iw_request_info *info,
163 struct iw_point *data, char *ssid) 116 struct iw_point *data, char *ssid)
164{ 117{
165 size_t len;
166 struct ieee80211_sub_if_data *sdata; 118 struct ieee80211_sub_if_data *sdata;
167 119
168 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 120 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
169 121
170 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 122 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
171 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid); 123 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
172 124 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
173 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 125 return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
174 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
175 if (res == 0) {
176 data->length = len;
177 data->flags = 1;
178 } else
179 data->flags = 0;
180 return res;
181 }
182 126
183 return -EOPNOTSUPP; 127 return -EOPNOTSUPP;
184} 128}
@@ -193,40 +137,11 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
193 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 137 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
194 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); 138 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
195 139
196 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 140 if (sdata->vif.type == NL80211_IFTYPE_STATION)
197 int ret; 141 return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
198
199 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
200 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
201 IEEE80211_STA_AUTO_CHANNEL_SEL;
202 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
203 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
204 else
205 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
206 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
207 if (ret)
208 return ret;
209 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
210 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
211 ieee80211_sta_req_auth(sdata);
212 return 0;
213 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
214 /*
215 * If it is necessary to update the WDS peer address
216 * while the interface is running, then we need to do
217 * more work here, namely if it is running we need to
218 * add a new and remove the old STA entry, this is
219 * normally handled by _open() and _stop().
220 */
221 if (netif_running(dev))
222 return -EBUSY;
223
224 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
225 ETH_ALEN);
226
227 return 0;
228 }
229 142
143 if (sdata->vif.type == NL80211_IFTYPE_WDS)
144 return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
230 return -EOPNOTSUPP; 145 return -EOPNOTSUPP;
231} 146}
232 147
@@ -240,326 +155,13 @@ static int ieee80211_ioctl_giwap(struct net_device *dev,
240 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 155 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
241 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra); 156 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
242 157
243 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
244 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
245 ap_addr->sa_family = ARPHRD_ETHER;
246 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
247 } else
248 memset(&ap_addr->sa_data, 0, ETH_ALEN);
249 return 0;
250 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
251 ap_addr->sa_family = ARPHRD_ETHER;
252 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
253 return 0;
254 }
255
256 return -EOPNOTSUPP;
257}
258
259
260static int ieee80211_ioctl_siwrate(struct net_device *dev,
261 struct iw_request_info *info,
262 struct iw_param *rate, char *extra)
263{
264 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
265 int i, err = -EINVAL;
266 u32 target_rate = rate->value / 100000;
267 struct ieee80211_sub_if_data *sdata;
268 struct ieee80211_supported_band *sband;
269
270 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
271
272 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
273
274 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
275 * target_rate = X, rate->fixed = 1 means only rate X
276 * target_rate = X, rate->fixed = 0 means all rates <= X */
277 sdata->max_ratectrl_rateidx = -1;
278 sdata->force_unicast_rateidx = -1;
279 if (rate->value < 0)
280 return 0;
281
282 for (i=0; i< sband->n_bitrates; i++) {
283 struct ieee80211_rate *brate = &sband->bitrates[i];
284 int this_rate = brate->bitrate;
285
286 if (target_rate == this_rate) {
287 sdata->max_ratectrl_rateidx = i;
288 if (rate->fixed)
289 sdata->force_unicast_rateidx = i;
290 err = 0;
291 break;
292 }
293 }
294 return err;
295}
296
297static int ieee80211_ioctl_giwrate(struct net_device *dev,
298 struct iw_request_info *info,
299 struct iw_param *rate, char *extra)
300{
301 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
302 struct sta_info *sta;
303 struct ieee80211_sub_if_data *sdata;
304 struct ieee80211_supported_band *sband;
305
306 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
307
308 if (sdata->vif.type != NL80211_IFTYPE_STATION)
309 return -EOPNOTSUPP;
310
311 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
312
313 rcu_read_lock();
314
315 sta = sta_info_get(local, sdata->u.mgd.bssid);
316
317 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
318 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
319 else
320 rate->value = 0;
321
322 rcu_read_unlock();
323
324 if (!sta)
325 return -ENODEV;
326
327 rate->value *= 100000;
328
329 return 0;
330}
331
332static int ieee80211_ioctl_siwpower(struct net_device *dev,
333 struct iw_request_info *info,
334 struct iw_param *wrq,
335 char *extra)
336{
337 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
338 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
339 struct ieee80211_conf *conf = &local->hw.conf;
340 int timeout = 0;
341 bool ps;
342
343 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
344 return -EOPNOTSUPP;
345
346 if (sdata->vif.type != NL80211_IFTYPE_STATION)
347 return -EINVAL;
348
349 if (wrq->disabled) {
350 ps = false;
351 timeout = 0;
352 goto set;
353 }
354
355 switch (wrq->flags & IW_POWER_MODE) {
356 case IW_POWER_ON: /* If not specified */
357 case IW_POWER_MODE: /* If set all mask */
358 case IW_POWER_ALL_R: /* If explicitely state all */
359 ps = true;
360 break;
361 default: /* Otherwise we ignore */
362 return -EINVAL;
363 }
364
365 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
366 return -EINVAL;
367
368 if (wrq->flags & IW_POWER_TIMEOUT)
369 timeout = wrq->value / 1000;
370
371 set:
372 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
373 return 0;
374
375 sdata->u.mgd.powersave = ps;
376 conf->dynamic_ps_timeout = timeout;
377
378 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
379 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
380
381 ieee80211_recalc_ps(local, -1);
382
383 return 0;
384}
385
386static int ieee80211_ioctl_giwpower(struct net_device *dev,
387 struct iw_request_info *info,
388 union iwreq_data *wrqu,
389 char *extra)
390{
391 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
392
393 wrqu->power.disabled = !sdata->u.mgd.powersave;
394
395 return 0;
396}
397
398static int ieee80211_ioctl_siwauth(struct net_device *dev,
399 struct iw_request_info *info,
400 struct iw_param *data, char *extra)
401{
402 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
403 int ret = 0;
404
405 switch (data->flags & IW_AUTH_INDEX) {
406 case IW_AUTH_WPA_VERSION:
407 case IW_AUTH_CIPHER_GROUP:
408 case IW_AUTH_WPA_ENABLED:
409 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
410 case IW_AUTH_KEY_MGMT:
411 case IW_AUTH_CIPHER_GROUP_MGMT:
412 break;
413 case IW_AUTH_CIPHER_PAIRWISE:
414 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
415 if (data->value & (IW_AUTH_CIPHER_WEP40 |
416 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
417 sdata->u.mgd.flags |=
418 IEEE80211_STA_TKIP_WEP_USED;
419 else
420 sdata->u.mgd.flags &=
421 ~IEEE80211_STA_TKIP_WEP_USED;
422 }
423 break;
424 case IW_AUTH_DROP_UNENCRYPTED:
425 sdata->drop_unencrypted = !!data->value;
426 break;
427 case IW_AUTH_PRIVACY_INVOKED:
428 if (sdata->vif.type != NL80211_IFTYPE_STATION)
429 ret = -EINVAL;
430 else {
431 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
432 /*
433 * Privacy invoked by wpa_supplicant, store the
434 * value and allow associating to a protected
435 * network without having a key up front.
436 */
437 if (data->value)
438 sdata->u.mgd.flags |=
439 IEEE80211_STA_PRIVACY_INVOKED;
440 }
441 break;
442 case IW_AUTH_80211_AUTH_ALG:
443 if (sdata->vif.type == NL80211_IFTYPE_STATION)
444 sdata->u.mgd.auth_algs = data->value;
445 else
446 ret = -EOPNOTSUPP;
447 break;
448 case IW_AUTH_MFP:
449 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
450 ret = -EOPNOTSUPP;
451 break;
452 }
453 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
454 switch (data->value) {
455 case IW_AUTH_MFP_DISABLED:
456 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
457 break;
458 case IW_AUTH_MFP_OPTIONAL:
459 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
460 break;
461 case IW_AUTH_MFP_REQUIRED:
462 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
463 break;
464 default:
465 ret = -EINVAL;
466 }
467 } else
468 ret = -EOPNOTSUPP;
469 break;
470 default:
471 ret = -EOPNOTSUPP;
472 break;
473 }
474 return ret;
475}
476
477/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
478static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
479{
480 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
481 struct iw_statistics *wstats = &local->wstats;
482 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
483 struct sta_info *sta = NULL;
484
485 rcu_read_lock();
486
487 if (sdata->vif.type == NL80211_IFTYPE_STATION) 158 if (sdata->vif.type == NL80211_IFTYPE_STATION)
488 sta = sta_info_get(local, sdata->u.mgd.bssid); 159 return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
489
490 if (!sta) {
491 wstats->discard.fragment = 0;
492 wstats->discard.misc = 0;
493 wstats->qual.qual = 0;
494 wstats->qual.level = 0;
495 wstats->qual.noise = 0;
496 wstats->qual.updated = IW_QUAL_ALL_INVALID;
497 } else {
498 wstats->qual.updated = 0;
499 /*
500 * mirror what cfg80211 does for iwrange/scan results,
501 * otherwise userspace gets confused.
502 */
503 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
504 IEEE80211_HW_SIGNAL_DBM)) {
505 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
506 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
507 } else {
508 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
509 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
510 }
511
512 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
513 wstats->qual.level = sta->last_signal;
514 wstats->qual.qual = sta->last_signal;
515 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
516 int sig = sta->last_signal;
517
518 wstats->qual.updated |= IW_QUAL_DBM;
519 wstats->qual.level = sig;
520 if (sig < -110)
521 sig = -110;
522 else if (sig > -40)
523 sig = -40;
524 wstats->qual.qual = sig + 110;
525 }
526
527 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
528 /*
529 * This assumes that if driver reports noise, it also
530 * reports signal in dBm.
531 */
532 wstats->qual.noise = sta->last_noise;
533 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
534 } else {
535 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
536 }
537 }
538 160
539 rcu_read_unlock(); 161 if (sdata->vif.type == NL80211_IFTYPE_WDS)
540 162 return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
541 return wstats;
542}
543 163
544static int ieee80211_ioctl_giwauth(struct net_device *dev, 164 return -EOPNOTSUPP;
545 struct iw_request_info *info,
546 struct iw_param *data, char *extra)
547{
548 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
549 int ret = 0;
550
551 switch (data->flags & IW_AUTH_INDEX) {
552 case IW_AUTH_80211_AUTH_ALG:
553 if (sdata->vif.type == NL80211_IFTYPE_STATION)
554 data->value = sdata->u.mgd.auth_algs;
555 else
556 ret = -EOPNOTSUPP;
557 break;
558 default:
559 ret = -EOPNOTSUPP;
560 break;
561 }
562 return ret;
563} 165}
564 166
565 167
@@ -599,8 +201,8 @@ static const iw_handler ieee80211_handler[] =
599 (iw_handler) NULL, /* SIOCGIWNICKN */ 201 (iw_handler) NULL, /* SIOCGIWNICKN */
600 (iw_handler) NULL, /* -- hole -- */ 202 (iw_handler) NULL, /* -- hole -- */
601 (iw_handler) NULL, /* -- hole -- */ 203 (iw_handler) NULL, /* -- hole -- */
602 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ 204 (iw_handler) cfg80211_wext_siwrate, /* SIOCSIWRATE */
603 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ 205 (iw_handler) cfg80211_wext_giwrate, /* SIOCGIWRATE */
604 (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */ 206 (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */
605 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */ 207 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
606 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */ 208 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
@@ -611,14 +213,14 @@ static const iw_handler ieee80211_handler[] =
611 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */ 213 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */
612 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */ 214 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */
613 (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */ 215 (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */
614 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */ 216 (iw_handler) cfg80211_wext_siwpower, /* SIOCSIWPOWER */
615 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */ 217 (iw_handler) cfg80211_wext_giwpower, /* SIOCGIWPOWER */
616 (iw_handler) NULL, /* -- hole -- */ 218 (iw_handler) NULL, /* -- hole -- */
617 (iw_handler) NULL, /* -- hole -- */ 219 (iw_handler) NULL, /* -- hole -- */
618 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */ 220 (iw_handler) cfg80211_wext_siwgenie, /* SIOCSIWGENIE */
619 (iw_handler) NULL, /* SIOCGIWGENIE */ 221 (iw_handler) NULL, /* SIOCGIWGENIE */
620 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */ 222 (iw_handler) cfg80211_wext_siwauth, /* SIOCSIWAUTH */
621 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */ 223 (iw_handler) cfg80211_wext_giwauth, /* SIOCGIWAUTH */
622 (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */ 224 (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */
623 (iw_handler) NULL, /* SIOCGIWENCODEEXT */ 225 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
624 (iw_handler) NULL, /* SIOCSIWPMKSA */ 226 (iw_handler) NULL, /* SIOCSIWPMKSA */
@@ -629,5 +231,5 @@ const struct iw_handler_def ieee80211_iw_handler_def =
629{ 231{
630 .num_standard = ARRAY_SIZE(ieee80211_handler), 232 .num_standard = ARRAY_SIZE(ieee80211_handler),
631 .standard = (iw_handler *) ieee80211_handler, 233 .standard = (iw_handler *) ieee80211_handler,
632 .get_wireless_stats = ieee80211_get_wireless_stats, 234 .get_wireless_stats = cfg80211_wireless_stats,
633}; 235};
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index dcfae8884b86..70778694877b 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -122,7 +122,8 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
122 return RX_DROP_UNUSABLE; 122 return RX_DROP_UNUSABLE;
123 123
124 mac80211_ev_michael_mic_failure(rx->sdata, rx->key->conf.keyidx, 124 mac80211_ev_michael_mic_failure(rx->sdata, rx->key->conf.keyidx,
125 (void *) skb->data, NULL); 125 (void *) skb->data, NULL,
126 GFP_ATOMIC);
126 return RX_DROP_UNUSABLE; 127 return RX_DROP_UNUSABLE;
127 } 128 }
128 129
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 7c1333c67ff3..2d24d81474ce 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -3231,7 +3231,7 @@ static int ip_vs_genl_get_cmd(struct sk_buff *skb, struct genl_info *info)
3231 } 3231 }
3232 3232
3233 genlmsg_end(msg, reply); 3233 genlmsg_end(msg, reply);
3234 ret = genlmsg_unicast(msg, info->snd_pid); 3234 ret = genlmsg_reply(msg, info);
3235 goto out; 3235 goto out;
3236 3236
3237nla_put_failure: 3237nla_put_failure:
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 2936fa3b6dc8..da3163d15ef0 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -83,6 +83,11 @@ struct netlink_sock {
83 struct module *module; 83 struct module *module;
84}; 84};
85 85
86struct listeners_rcu_head {
87 struct rcu_head rcu_head;
88 void *ptr;
89};
90
86#define NETLINK_KERNEL_SOCKET 0x1 91#define NETLINK_KERNEL_SOCKET 0x1
87#define NETLINK_RECV_PKTINFO 0x2 92#define NETLINK_RECV_PKTINFO 0x2
88#define NETLINK_BROADCAST_SEND_ERROR 0x4 93#define NETLINK_BROADCAST_SEND_ERROR 0x4
@@ -1356,7 +1361,7 @@ static int netlink_recvmsg(struct kiocb *kiocb, struct socket *sock,
1356 struct netlink_sock *nlk = nlk_sk(sk); 1361 struct netlink_sock *nlk = nlk_sk(sk);
1357 int noblock = flags&MSG_DONTWAIT; 1362 int noblock = flags&MSG_DONTWAIT;
1358 size_t copied; 1363 size_t copied;
1359 struct sk_buff *skb; 1364 struct sk_buff *skb, *frag __maybe_unused = NULL;
1360 int err; 1365 int err;
1361 1366
1362 if (flags&MSG_OOB) 1367 if (flags&MSG_OOB)
@@ -1368,6 +1373,35 @@ static int netlink_recvmsg(struct kiocb *kiocb, struct socket *sock,
1368 if (skb == NULL) 1373 if (skb == NULL)
1369 goto out; 1374 goto out;
1370 1375
1376#ifdef CONFIG_COMPAT_NETLINK_MESSAGES
1377 if (unlikely(skb_shinfo(skb)->frag_list)) {
1378 bool need_compat = !!(flags & MSG_CMSG_COMPAT);
1379
1380 /*
1381 * If this skb has a frag_list, then here that means that
1382 * we will have to use the frag_list skb for compat tasks
1383 * and the regular skb for non-compat tasks.
1384 *
1385 * The skb might (and likely will) be cloned, so we can't
1386 * just reset frag_list and go on with things -- we need to
1387 * keep that. For the compat case that's easy -- simply get
1388 * a reference to the compat skb and free the regular one
1389 * including the frag. For the non-compat case, we need to
1390 * avoid sending the frag to the user -- so assign NULL but
1391 * restore it below before freeing the skb.
1392 */
1393 if (need_compat) {
1394 struct sk_buff *compskb = skb_shinfo(skb)->frag_list;
1395 skb_get(compskb);
1396 kfree_skb(skb);
1397 skb = compskb;
1398 } else {
1399 frag = skb_shinfo(skb)->frag_list;
1400 skb_shinfo(skb)->frag_list = NULL;
1401 }
1402 }
1403#endif
1404
1371 msg->msg_namelen = 0; 1405 msg->msg_namelen = 0;
1372 1406
1373 copied = skb->len; 1407 copied = skb->len;
@@ -1398,6 +1432,11 @@ static int netlink_recvmsg(struct kiocb *kiocb, struct socket *sock,
1398 siocb->scm->creds = *NETLINK_CREDS(skb); 1432 siocb->scm->creds = *NETLINK_CREDS(skb);
1399 if (flags & MSG_TRUNC) 1433 if (flags & MSG_TRUNC)
1400 copied = skb->len; 1434 copied = skb->len;
1435
1436#ifdef CONFIG_COMPAT_NETLINK_MESSAGES
1437 skb_shinfo(skb)->frag_list = frag;
1438#endif
1439
1401 skb_free_datagram(sk, skb); 1440 skb_free_datagram(sk, skb);
1402 1441
1403 if (nlk->cb && atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf / 2) 1442 if (nlk->cb && atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf / 2)
@@ -1453,7 +1492,8 @@ netlink_kernel_create(struct net *net, int unit, unsigned int groups,
1453 if (groups < 32) 1492 if (groups < 32)
1454 groups = 32; 1493 groups = 32;
1455 1494
1456 listeners = kzalloc(NLGRPSZ(groups), GFP_KERNEL); 1495 listeners = kzalloc(NLGRPSZ(groups) + sizeof(struct listeners_rcu_head),
1496 GFP_KERNEL);
1457 if (!listeners) 1497 if (!listeners)
1458 goto out_sock_release; 1498 goto out_sock_release;
1459 1499
@@ -1501,6 +1541,14 @@ netlink_kernel_release(struct sock *sk)
1501EXPORT_SYMBOL(netlink_kernel_release); 1541EXPORT_SYMBOL(netlink_kernel_release);
1502 1542
1503 1543
1544static void netlink_free_old_listeners(struct rcu_head *rcu_head)
1545{
1546 struct listeners_rcu_head *lrh;
1547
1548 lrh = container_of(rcu_head, struct listeners_rcu_head, rcu_head);
1549 kfree(lrh->ptr);
1550}
1551
1504/** 1552/**
1505 * netlink_change_ngroups - change number of multicast groups 1553 * netlink_change_ngroups - change number of multicast groups
1506 * 1554 *
@@ -1516,6 +1564,7 @@ EXPORT_SYMBOL(netlink_kernel_release);
1516int netlink_change_ngroups(struct sock *sk, unsigned int groups) 1564int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1517{ 1565{
1518 unsigned long *listeners, *old = NULL; 1566 unsigned long *listeners, *old = NULL;
1567 struct listeners_rcu_head *old_rcu_head;
1519 struct netlink_table *tbl = &nl_table[sk->sk_protocol]; 1568 struct netlink_table *tbl = &nl_table[sk->sk_protocol];
1520 int err = 0; 1569 int err = 0;
1521 1570
@@ -1524,7 +1573,9 @@ int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1524 1573
1525 netlink_table_grab(); 1574 netlink_table_grab();
1526 if (NLGRPSZ(tbl->groups) < NLGRPSZ(groups)) { 1575 if (NLGRPSZ(tbl->groups) < NLGRPSZ(groups)) {
1527 listeners = kzalloc(NLGRPSZ(groups), GFP_ATOMIC); 1576 listeners = kzalloc(NLGRPSZ(groups) +
1577 sizeof(struct listeners_rcu_head),
1578 GFP_ATOMIC);
1528 if (!listeners) { 1579 if (!listeners) {
1529 err = -ENOMEM; 1580 err = -ENOMEM;
1530 goto out_ungrab; 1581 goto out_ungrab;
@@ -1532,16 +1583,24 @@ int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1532 old = tbl->listeners; 1583 old = tbl->listeners;
1533 memcpy(listeners, old, NLGRPSZ(tbl->groups)); 1584 memcpy(listeners, old, NLGRPSZ(tbl->groups));
1534 rcu_assign_pointer(tbl->listeners, listeners); 1585 rcu_assign_pointer(tbl->listeners, listeners);
1586 /*
1587 * Free the old memory after an RCU grace period so we
1588 * don't leak it. We use call_rcu() here in order to be
1589 * able to call this function from atomic contexts. The
1590 * allocation of this memory will have reserved enough
1591 * space for struct listeners_rcu_head at the end.
1592 */
1593 old_rcu_head = (void *)(tbl->listeners +
1594 NLGRPLONGS(tbl->groups));
1595 old_rcu_head->ptr = old;
1596 call_rcu(&old_rcu_head->rcu_head, netlink_free_old_listeners);
1535 } 1597 }
1536 tbl->groups = groups; 1598 tbl->groups = groups;
1537 1599
1538 out_ungrab: 1600 out_ungrab:
1539 netlink_table_ungrab(); 1601 netlink_table_ungrab();
1540 synchronize_rcu();
1541 kfree(old);
1542 return err; 1602 return err;
1543} 1603}
1544EXPORT_SYMBOL(netlink_change_ngroups);
1545 1604
1546/** 1605/**
1547 * netlink_clear_multicast_users - kick off multicast listeners 1606 * netlink_clear_multicast_users - kick off multicast listeners
@@ -1564,7 +1623,6 @@ void netlink_clear_multicast_users(struct sock *ksk, unsigned int group)
1564 1623
1565 netlink_table_ungrab(); 1624 netlink_table_ungrab();
1566} 1625}
1567EXPORT_SYMBOL(netlink_clear_multicast_users);
1568 1626
1569void netlink_set_nonroot(int protocol, unsigned int flags) 1627void netlink_set_nonroot(int protocol, unsigned int flags)
1570{ 1628{
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index eed4c6a8afc0..575c64341508 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -18,8 +18,6 @@
18#include <net/sock.h> 18#include <net/sock.h>
19#include <net/genetlink.h> 19#include <net/genetlink.h>
20 20
21struct sock *genl_sock = NULL;
22
23static DEFINE_MUTEX(genl_mutex); /* serialization of message processing */ 21static DEFINE_MUTEX(genl_mutex); /* serialization of message processing */
24 22
25static inline void genl_lock(void) 23static inline void genl_lock(void)
@@ -175,10 +173,31 @@ int genl_register_mc_group(struct genl_family *family,
175 mc_groups_longs++; 173 mc_groups_longs++;
176 } 174 }
177 175
178 err = netlink_change_ngroups(genl_sock, 176 if (family->netnsok) {
179 mc_groups_longs * BITS_PER_LONG); 177 struct net *net;
180 if (err) 178
181 goto out; 179 rcu_read_lock();
180 for_each_net_rcu(net) {
181 err = netlink_change_ngroups(net->genl_sock,
182 mc_groups_longs * BITS_PER_LONG);
183 if (err) {
184 /*
185 * No need to roll back, can only fail if
186 * memory allocation fails and then the
187 * number of _possible_ groups has been
188 * increased on some sockets which is ok.
189 */
190 rcu_read_unlock();
191 goto out;
192 }
193 }
194 rcu_read_unlock();
195 } else {
196 err = netlink_change_ngroups(init_net.genl_sock,
197 mc_groups_longs * BITS_PER_LONG);
198 if (err)
199 goto out;
200 }
182 201
183 grp->id = id; 202 grp->id = id;
184 set_bit(id, mc_groups); 203 set_bit(id, mc_groups);
@@ -195,8 +214,14 @@ EXPORT_SYMBOL(genl_register_mc_group);
195static void __genl_unregister_mc_group(struct genl_family *family, 214static void __genl_unregister_mc_group(struct genl_family *family,
196 struct genl_multicast_group *grp) 215 struct genl_multicast_group *grp)
197{ 216{
217 struct net *net;
198 BUG_ON(grp->family != family); 218 BUG_ON(grp->family != family);
199 netlink_clear_multicast_users(genl_sock, grp->id); 219
220 rcu_read_lock();
221 for_each_net_rcu(net)
222 netlink_clear_multicast_users(net->genl_sock, grp->id);
223 rcu_read_unlock();
224
200 clear_bit(grp->id, mc_groups); 225 clear_bit(grp->id, mc_groups);
201 list_del(&grp->list); 226 list_del(&grp->list);
202 genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, grp); 227 genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, grp);
@@ -467,6 +492,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
467{ 492{
468 struct genl_ops *ops; 493 struct genl_ops *ops;
469 struct genl_family *family; 494 struct genl_family *family;
495 struct net *net = sock_net(skb->sk);
470 struct genl_info info; 496 struct genl_info info;
471 struct genlmsghdr *hdr = nlmsg_data(nlh); 497 struct genlmsghdr *hdr = nlmsg_data(nlh);
472 int hdrlen, err; 498 int hdrlen, err;
@@ -475,6 +501,10 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
475 if (family == NULL) 501 if (family == NULL)
476 return -ENOENT; 502 return -ENOENT;
477 503
504 /* this family doesn't exist in this netns */
505 if (!family->netnsok && !net_eq(net, &init_net))
506 return -ENOENT;
507
478 hdrlen = GENL_HDRLEN + family->hdrsize; 508 hdrlen = GENL_HDRLEN + family->hdrsize;
479 if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) 509 if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen))
480 return -EINVAL; 510 return -EINVAL;
@@ -492,7 +522,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
492 return -EOPNOTSUPP; 522 return -EOPNOTSUPP;
493 523
494 genl_unlock(); 524 genl_unlock();
495 err = netlink_dump_start(genl_sock, skb, nlh, 525 err = netlink_dump_start(net->genl_sock, skb, nlh,
496 ops->dumpit, ops->done); 526 ops->dumpit, ops->done);
497 genl_lock(); 527 genl_lock();
498 return err; 528 return err;
@@ -514,6 +544,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
514 info.genlhdr = nlmsg_data(nlh); 544 info.genlhdr = nlmsg_data(nlh);
515 info.userhdr = nlmsg_data(nlh) + GENL_HDRLEN; 545 info.userhdr = nlmsg_data(nlh) + GENL_HDRLEN;
516 info.attrs = family->attrbuf; 546 info.attrs = family->attrbuf;
547 genl_info_net_set(&info, net);
517 548
518 return ops->doit(skb, &info); 549 return ops->doit(skb, &info);
519} 550}
@@ -534,6 +565,7 @@ static struct genl_family genl_ctrl = {
534 .name = "nlctrl", 565 .name = "nlctrl",
535 .version = 0x2, 566 .version = 0x2,
536 .maxattr = CTRL_ATTR_MAX, 567 .maxattr = CTRL_ATTR_MAX,
568 .netnsok = true,
537}; 569};
538 570
539static int ctrl_fill_info(struct genl_family *family, u32 pid, u32 seq, 571static int ctrl_fill_info(struct genl_family *family, u32 pid, u32 seq,
@@ -650,6 +682,7 @@ static int ctrl_dumpfamily(struct sk_buff *skb, struct netlink_callback *cb)
650 682
651 int i, n = 0; 683 int i, n = 0;
652 struct genl_family *rt; 684 struct genl_family *rt;
685 struct net *net = sock_net(skb->sk);
653 int chains_to_skip = cb->args[0]; 686 int chains_to_skip = cb->args[0];
654 int fams_to_skip = cb->args[1]; 687 int fams_to_skip = cb->args[1];
655 688
@@ -658,6 +691,8 @@ static int ctrl_dumpfamily(struct sk_buff *skb, struct netlink_callback *cb)
658 continue; 691 continue;
659 n = 0; 692 n = 0;
660 list_for_each_entry(rt, genl_family_chain(i), family_list) { 693 list_for_each_entry(rt, genl_family_chain(i), family_list) {
694 if (!rt->netnsok && !net_eq(net, &init_net))
695 continue;
661 if (++n < fams_to_skip) 696 if (++n < fams_to_skip)
662 continue; 697 continue;
663 if (ctrl_fill_info(rt, NETLINK_CB(cb->skb).pid, 698 if (ctrl_fill_info(rt, NETLINK_CB(cb->skb).pid,
@@ -729,6 +764,7 @@ static int ctrl_getfamily(struct sk_buff *skb, struct genl_info *info)
729 if (info->attrs[CTRL_ATTR_FAMILY_ID]) { 764 if (info->attrs[CTRL_ATTR_FAMILY_ID]) {
730 u16 id = nla_get_u16(info->attrs[CTRL_ATTR_FAMILY_ID]); 765 u16 id = nla_get_u16(info->attrs[CTRL_ATTR_FAMILY_ID]);
731 res = genl_family_find_byid(id); 766 res = genl_family_find_byid(id);
767 err = -ENOENT;
732 } 768 }
733 769
734 if (info->attrs[CTRL_ATTR_FAMILY_NAME]) { 770 if (info->attrs[CTRL_ATTR_FAMILY_NAME]) {
@@ -736,49 +772,61 @@ static int ctrl_getfamily(struct sk_buff *skb, struct genl_info *info)
736 772
737 name = nla_data(info->attrs[CTRL_ATTR_FAMILY_NAME]); 773 name = nla_data(info->attrs[CTRL_ATTR_FAMILY_NAME]);
738 res = genl_family_find_byname(name); 774 res = genl_family_find_byname(name);
775 err = -ENOENT;
739 } 776 }
740 777
741 if (res == NULL) { 778 if (res == NULL)
742 err = -ENOENT; 779 return err;
743 goto errout; 780
781 if (!res->netnsok && !net_eq(genl_info_net(info), &init_net)) {
782 /* family doesn't exist here */
783 return -ENOENT;
744 } 784 }
745 785
746 msg = ctrl_build_family_msg(res, info->snd_pid, info->snd_seq, 786 msg = ctrl_build_family_msg(res, info->snd_pid, info->snd_seq,
747 CTRL_CMD_NEWFAMILY); 787 CTRL_CMD_NEWFAMILY);
748 if (IS_ERR(msg)) { 788 if (IS_ERR(msg))
749 err = PTR_ERR(msg); 789 return PTR_ERR(msg);
750 goto errout;
751 }
752 790
753 err = genlmsg_reply(msg, info); 791 return genlmsg_reply(msg, info);
754errout:
755 return err;
756} 792}
757 793
758static int genl_ctrl_event(int event, void *data) 794static int genl_ctrl_event(int event, void *data)
759{ 795{
760 struct sk_buff *msg; 796 struct sk_buff *msg;
797 struct genl_family *family;
798 struct genl_multicast_group *grp;
761 799
762 if (genl_sock == NULL) 800 /* genl is still initialising */
801 if (!init_net.genl_sock)
763 return 0; 802 return 0;
764 803
765 switch (event) { 804 switch (event) {
766 case CTRL_CMD_NEWFAMILY: 805 case CTRL_CMD_NEWFAMILY:
767 case CTRL_CMD_DELFAMILY: 806 case CTRL_CMD_DELFAMILY:
768 msg = ctrl_build_family_msg(data, 0, 0, event); 807 family = data;
769 if (IS_ERR(msg)) 808 msg = ctrl_build_family_msg(family, 0, 0, event);
770 return PTR_ERR(msg);
771
772 genlmsg_multicast(msg, 0, GENL_ID_CTRL, GFP_KERNEL);
773 break; 809 break;
774 case CTRL_CMD_NEWMCAST_GRP: 810 case CTRL_CMD_NEWMCAST_GRP:
775 case CTRL_CMD_DELMCAST_GRP: 811 case CTRL_CMD_DELMCAST_GRP:
812 grp = data;
813 family = grp->family;
776 msg = ctrl_build_mcgrp_msg(data, 0, 0, event); 814 msg = ctrl_build_mcgrp_msg(data, 0, 0, event);
777 if (IS_ERR(msg))
778 return PTR_ERR(msg);
779
780 genlmsg_multicast(msg, 0, GENL_ID_CTRL, GFP_KERNEL);
781 break; 815 break;
816 default:
817 return -EINVAL;
818 }
819
820 if (IS_ERR(msg))
821 return PTR_ERR(msg);
822
823 if (!family->netnsok) {
824 genlmsg_multicast_netns(&init_net, msg, 0,
825 GENL_ID_CTRL, GFP_KERNEL);
826 } else {
827 rcu_read_lock();
828 genlmsg_multicast_allns(msg, 0, GENL_ID_CTRL, GFP_ATOMIC);
829 rcu_read_unlock();
782 } 830 }
783 831
784 return 0; 832 return 0;
@@ -795,6 +843,33 @@ static struct genl_multicast_group notify_grp = {
795 .name = "notify", 843 .name = "notify",
796}; 844};
797 845
846static int __net_init genl_pernet_init(struct net *net)
847{
848 /* we'll bump the group number right afterwards */
849 net->genl_sock = netlink_kernel_create(net, NETLINK_GENERIC, 0,
850 genl_rcv, &genl_mutex,
851 THIS_MODULE);
852
853 if (!net->genl_sock && net_eq(net, &init_net))
854 panic("GENL: Cannot initialize generic netlink\n");
855
856 if (!net->genl_sock)
857 return -ENOMEM;
858
859 return 0;
860}
861
862static void __net_exit genl_pernet_exit(struct net *net)
863{
864 netlink_kernel_release(net->genl_sock);
865 net->genl_sock = NULL;
866}
867
868static struct pernet_operations genl_pernet_ops = {
869 .init = genl_pernet_init,
870 .exit = genl_pernet_exit,
871};
872
798static int __init genl_init(void) 873static int __init genl_init(void)
799{ 874{
800 int i, err; 875 int i, err;
@@ -804,36 +879,67 @@ static int __init genl_init(void)
804 879
805 err = genl_register_family(&genl_ctrl); 880 err = genl_register_family(&genl_ctrl);
806 if (err < 0) 881 if (err < 0)
807 goto errout; 882 goto problem;
808 883
809 err = genl_register_ops(&genl_ctrl, &genl_ctrl_ops); 884 err = genl_register_ops(&genl_ctrl, &genl_ctrl_ops);
810 if (err < 0) 885 if (err < 0)
811 goto errout_register; 886 goto problem;
812 887
813 netlink_set_nonroot(NETLINK_GENERIC, NL_NONROOT_RECV); 888 netlink_set_nonroot(NETLINK_GENERIC, NL_NONROOT_RECV);
814 889
815 /* we'll bump the group number right afterwards */ 890 err = register_pernet_subsys(&genl_pernet_ops);
816 genl_sock = netlink_kernel_create(&init_net, NETLINK_GENERIC, 0, 891 if (err)
817 genl_rcv, &genl_mutex, THIS_MODULE); 892 goto problem;
818 if (genl_sock == NULL)
819 panic("GENL: Cannot initialize generic netlink\n");
820 893
821 err = genl_register_mc_group(&genl_ctrl, &notify_grp); 894 err = genl_register_mc_group(&genl_ctrl, &notify_grp);
822 if (err < 0) 895 if (err < 0)
823 goto errout_register; 896 goto problem;
824 897
825 return 0; 898 return 0;
826 899
827errout_register: 900problem:
828 genl_unregister_family(&genl_ctrl);
829errout:
830 panic("GENL: Cannot register controller: %d\n", err); 901 panic("GENL: Cannot register controller: %d\n", err);
831} 902}
832 903
833subsys_initcall(genl_init); 904subsys_initcall(genl_init);
834 905
835EXPORT_SYMBOL(genl_sock);
836EXPORT_SYMBOL(genl_register_ops); 906EXPORT_SYMBOL(genl_register_ops);
837EXPORT_SYMBOL(genl_unregister_ops); 907EXPORT_SYMBOL(genl_unregister_ops);
838EXPORT_SYMBOL(genl_register_family); 908EXPORT_SYMBOL(genl_register_family);
839EXPORT_SYMBOL(genl_unregister_family); 909EXPORT_SYMBOL(genl_unregister_family);
910
911static int genlmsg_mcast(struct sk_buff *skb, u32 pid, unsigned long group,
912 gfp_t flags)
913{
914 struct sk_buff *tmp;
915 struct net *net, *prev = NULL;
916 int err;
917
918 for_each_net_rcu(net) {
919 if (prev) {
920 tmp = skb_clone(skb, flags);
921 if (!tmp) {
922 err = -ENOMEM;
923 goto error;
924 }
925 err = nlmsg_multicast(prev->genl_sock, tmp,
926 pid, group, flags);
927 if (err)
928 goto error;
929 }
930
931 prev = net;
932 }
933
934 return nlmsg_multicast(prev->genl_sock, skb, pid, group, flags);
935 error:
936 kfree_skb(skb);
937 return err;
938}
939
940int genlmsg_multicast_allns(struct sk_buff *skb, u32 pid, unsigned int group,
941 gfp_t flags)
942{
943 return genlmsg_mcast(skb, pid, group, flags);
944}
945EXPORT_SYMBOL(genlmsg_multicast_allns);
diff --git a/net/netrom/nr_dev.c b/net/netrom/nr_dev.c
index 351372463fed..c7b7838a0519 100644
--- a/net/netrom/nr_dev.c
+++ b/net/netrom/nr_dev.c
@@ -177,13 +177,13 @@ static int nr_xmit(struct sk_buff *skb, struct net_device *dev)
177 if (!nr_route_frame(skb, NULL)) { 177 if (!nr_route_frame(skb, NULL)) {
178 kfree_skb(skb); 178 kfree_skb(skb);
179 stats->tx_errors++; 179 stats->tx_errors++;
180 return 0; 180 return NETDEV_TX_OK;
181 } 181 }
182 182
183 stats->tx_packets++; 183 stats->tx_packets++;
184 stats->tx_bytes += len; 184 stats->tx_bytes += len;
185 185
186 return 0; 186 return NETDEV_TX_OK;
187} 187}
188 188
189static const struct header_ops nr_header_ops = { 189static const struct header_ops nr_header_ops = {
diff --git a/net/phonet/pep-gprs.c b/net/phonet/pep-gprs.c
index 480839dfc560..4667af51ed71 100644
--- a/net/phonet/pep-gprs.c
+++ b/net/phonet/pep-gprs.c
@@ -195,7 +195,7 @@ static int gprs_xmit(struct sk_buff *skb, struct net_device *dev)
195 break; 195 break;
196 default: 196 default:
197 dev_kfree_skb(skb); 197 dev_kfree_skb(skb);
198 return 0; 198 return NETDEV_TX_OK;
199 } 199 }
200 200
201 skb_orphan(skb); 201 skb_orphan(skb);
@@ -215,7 +215,7 @@ static int gprs_xmit(struct sk_buff *skb, struct net_device *dev)
215 netif_stop_queue(dev); 215 netif_stop_queue(dev);
216 if (pep_writeable(sk)) 216 if (pep_writeable(sk))
217 netif_wake_queue(dev); 217 netif_wake_queue(dev);
218 return 0; 218 return NETDEV_TX_OK;
219} 219}
220 220
221static int gprs_set_mtu(struct net_device *dev, int new_mtu) 221static int gprs_set_mtu(struct net_device *dev, int new_mtu)
diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index 79693fe2001e..47497c97c8d9 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -1076,10 +1076,16 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
1076 struct rfkill_event ev; 1076 struct rfkill_event ev;
1077 1077
1078 /* we don't need the 'hard' variable but accept it */ 1078 /* we don't need the 'hard' variable but accept it */
1079 if (count < sizeof(ev) - 1) 1079 if (count < RFKILL_EVENT_SIZE_V1 - 1)
1080 return -EINVAL; 1080 return -EINVAL;
1081 1081
1082 if (copy_from_user(&ev, buf, sizeof(ev) - 1)) 1082 /*
1083 * Copy as much data as we can accept into our 'ev' buffer,
1084 * but tell userspace how much we've copied so it can determine
1085 * our API version even in a write() call, if it cares.
1086 */
1087 count = min(count, sizeof(ev));
1088 if (copy_from_user(&ev, buf, count))
1083 return -EFAULT; 1089 return -EFAULT;
1084 1090
1085 if (ev.op != RFKILL_OP_CHANGE && ev.op != RFKILL_OP_CHANGE_ALL) 1091 if (ev.op != RFKILL_OP_CHANGE && ev.op != RFKILL_OP_CHANGE_ALL)
diff --git a/net/rose/rose_dev.c b/net/rose/rose_dev.c
index 389d6e0d7740..c711e2edf5ce 100644
--- a/net/rose/rose_dev.c
+++ b/net/rose/rose_dev.c
@@ -141,7 +141,7 @@ static int rose_xmit(struct sk_buff *skb, struct net_device *dev)
141 } 141 }
142 dev_kfree_skb(skb); 142 dev_kfree_skb(skb);
143 stats->tx_errors++; 143 stats->tx_errors++;
144 return 0; 144 return NETDEV_TX_OK;
145} 145}
146 146
147static const struct header_ops rose_header_ops = { 147static const struct header_ops rose_header_ops = {
diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c
index 9c002b6e0533..12434b6c2042 100644
--- a/net/sched/sch_teql.c
+++ b/net/sched/sch_teql.c
@@ -314,7 +314,7 @@ restart:
314 netif_wake_queue(dev); 314 netif_wake_queue(dev);
315 txq->tx_packets++; 315 txq->tx_packets++;
316 txq->tx_bytes += length; 316 txq->tx_bytes += length;
317 return 0; 317 return NETDEV_TX_OK;
318 } 318 }
319 __netif_tx_unlock(slave_txq); 319 __netif_tx_unlock(slave_txq);
320 } 320 }
@@ -323,7 +323,7 @@ restart:
323 break; 323 break;
324 case 1: 324 case 1:
325 master->slaves = NEXT_SLAVE(q); 325 master->slaves = NEXT_SLAVE(q);
326 return 0; 326 return NETDEV_TX_OK;
327 default: 327 default:
328 nores = 1; 328 nores = 1;
329 break; 329 break;
@@ -345,7 +345,7 @@ restart:
345drop: 345drop:
346 txq->tx_dropped++; 346 txq->tx_dropped++;
347 dev_kfree_skb(skb); 347 dev_kfree_skb(skb);
348 return 0; 348 return NETDEV_TX_OK;
349} 349}
350 350
351static int teql_master_open(struct net_device *dev) 351static int teql_master_open(struct net_device *dev)
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
index 3c57005e44d1..7bda8e3d1398 100644
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -62,7 +62,7 @@ static int handle_cmd(struct sk_buff *skb, struct genl_info *info)
62 rep_nlh = nlmsg_hdr(rep_buf); 62 rep_nlh = nlmsg_hdr(rep_buf);
63 memcpy(rep_nlh, req_nlh, hdr_space); 63 memcpy(rep_nlh, req_nlh, hdr_space);
64 rep_nlh->nlmsg_len = rep_buf->len; 64 rep_nlh->nlmsg_len = rep_buf->len;
65 genlmsg_unicast(rep_buf, NETLINK_CB(skb).pid); 65 genlmsg_unicast(&init_net, rep_buf, NETLINK_CB(skb).pid);
66 } 66 }
67 67
68 return 0; 68 return 0;
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 1848693ebb82..e8254e809b79 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1748,6 +1748,12 @@ static int getsockopt(struct socket *sock,
1748 value = jiffies_to_msecs(sk->sk_rcvtimeo); 1748 value = jiffies_to_msecs(sk->sk_rcvtimeo);
1749 /* no need to set "res", since already 0 at this point */ 1749 /* no need to set "res", since already 0 at this point */
1750 break; 1750 break;
1751 case TIPC_NODE_RECVQ_DEPTH:
1752 value = (u32)atomic_read(&tipc_queue_size);
1753 break;
1754 case TIPC_SOCK_RECVQ_DEPTH:
1755 value = skb_queue_len(&sk->sk_receive_queue);
1756 break;
1751 default: 1757 default:
1752 res = -EINVAL; 1758 res = -EINVAL;
1753 } 1759 }
diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig
index 4428dd5e911d..c6031d5b135f 100644
--- a/net/wireless/Kconfig
+++ b/net/wireless/Kconfig
@@ -2,6 +2,21 @@ config CFG80211
2 tristate "Improved wireless configuration API" 2 tristate "Improved wireless configuration API"
3 depends on RFKILL || !RFKILL 3 depends on RFKILL || !RFKILL
4 4
5config NL80211_TESTMODE
6 bool "nl80211 testmode command"
7 depends on CFG80211
8 help
9 The nl80211 testmode command helps implementing things like
10 factory calibration or validation tools for wireless chips.
11
12 Select this option ONLY for kernels that are specifically
13 built for such purposes.
14
15 Debugging tools that are supposed to end up in the hands of
16 users should better be implemented with debugfs.
17
18 Say N.
19
5config CFG80211_REG_DEBUG 20config CFG80211_REG_DEBUG
6 bool "cfg80211 regulatory debugging" 21 bool "cfg80211 regulatory debugging"
7 depends on CFG80211 22 depends on CFG80211
@@ -11,6 +26,22 @@ config CFG80211_REG_DEBUG
11 26
12 If unsure, say N. 27 If unsure, say N.
13 28
29config CFG80211_DEFAULT_PS
30 bool "enable powersave by default"
31 depends on CFG80211
32 default y
33 help
34 This option enables powersave mode by default.
35
36 If this causes your applications to misbehave you should fix your
37 applications instead -- they need to register their network
38 latency requirement, see Documentation/power/pm_qos_interface.txt.
39
40config CFG80211_DEFAULT_PS_VALUE
41 int
42 default 1 if CFG80211_DEFAULT_PS
43 default 0
44
14config CFG80211_DEBUGFS 45config CFG80211_DEBUGFS
15 bool "cfg80211 DebugFS entries" 46 bool "cfg80211 DebugFS entries"
16 depends on CFG80211 && DEBUG_FS 47 depends on CFG80211 && DEBUG_FS
@@ -35,19 +66,13 @@ config WIRELESS_OLD_REGULATORY
35 66
36config WIRELESS_EXT 67config WIRELESS_EXT
37 bool "Wireless extensions" 68 bool "Wireless extensions"
38 default n 69 default y
39 ---help--- 70 ---help---
40 This option enables the legacy wireless extensions 71 This option enables the legacy wireless extensions
41 (wireless network interface configuration via ioctls.) 72 (wireless network interface configuration via ioctls.)
42 73
43 Wireless extensions will be replaced by cfg80211 and 74 Say Y unless you've upgraded all your userspace to use
44 will be required only by legacy drivers that implement 75 nl80211 instead of wireless extensions.
45 wireless extension handlers. This option does not
46 affect the wireless-extension backward compatibility
47 code in cfg80211.
48
49 Say N (if you can) unless you know you need wireless
50 extensions for external modules.
51 76
52config WIRELESS_EXT_SYSFS 77config WIRELESS_EXT_SYSFS
53 bool "Wireless extensions sysfs files" 78 bool "Wireless extensions sysfs files"
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index f78c4832a9ca..d74cc77fa57a 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -5,8 +5,8 @@ obj-$(CONFIG_LIB80211_CRYPT_WEP) += lib80211_crypt_wep.o
5obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o 5obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o
6obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o 6obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o
7 7
8cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o mlme.o ibss.o 8cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o mlme.o ibss.o sme.o
9cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o 9cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o
10cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o 10cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o wext-sme.o
11 11
12ccflags-y += -D__CHECK_ENDIAN__ 12ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/wireless/core.c b/net/wireless/core.c
index d5850292b3df..1a78b3c70cf2 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -30,10 +30,10 @@ MODULE_DESCRIPTION("wireless configuration support");
30/* RCU might be appropriate here since we usually 30/* RCU might be appropriate here since we usually
31 * only read the list, and that can happen quite 31 * only read the list, and that can happen quite
32 * often because we need to do it for each command */ 32 * often because we need to do it for each command */
33LIST_HEAD(cfg80211_drv_list); 33LIST_HEAD(cfg80211_rdev_list);
34 34
35/* 35/*
36 * This is used to protect the cfg80211_drv_list, cfg80211_regdomain, 36 * This is used to protect the cfg80211_rdev_list, cfg80211_regdomain,
37 * country_ie_regdomain, the reg_beacon_list and the the last regulatory 37 * country_ie_regdomain, the reg_beacon_list and the the last regulatory
38 * request receipt (last_request). 38 * request receipt (last_request).
39 */ 39 */
@@ -43,18 +43,18 @@ DEFINE_MUTEX(cfg80211_mutex);
43static struct dentry *ieee80211_debugfs_dir; 43static struct dentry *ieee80211_debugfs_dir;
44 44
45/* requires cfg80211_mutex to be held! */ 45/* requires cfg80211_mutex to be held! */
46struct cfg80211_registered_device *cfg80211_drv_by_wiphy_idx(int wiphy_idx) 46struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx)
47{ 47{
48 struct cfg80211_registered_device *result = NULL, *drv; 48 struct cfg80211_registered_device *result = NULL, *rdev;
49 49
50 if (!wiphy_idx_valid(wiphy_idx)) 50 if (!wiphy_idx_valid(wiphy_idx))
51 return NULL; 51 return NULL;
52 52
53 assert_cfg80211_lock(); 53 assert_cfg80211_lock();
54 54
55 list_for_each_entry(drv, &cfg80211_drv_list, list) { 55 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
56 if (drv->wiphy_idx == wiphy_idx) { 56 if (rdev->wiphy_idx == wiphy_idx) {
57 result = drv; 57 result = rdev;
58 break; 58 break;
59 } 59 }
60 } 60 }
@@ -64,32 +64,32 @@ struct cfg80211_registered_device *cfg80211_drv_by_wiphy_idx(int wiphy_idx)
64 64
65int get_wiphy_idx(struct wiphy *wiphy) 65int get_wiphy_idx(struct wiphy *wiphy)
66{ 66{
67 struct cfg80211_registered_device *drv; 67 struct cfg80211_registered_device *rdev;
68 if (!wiphy) 68 if (!wiphy)
69 return WIPHY_IDX_STALE; 69 return WIPHY_IDX_STALE;
70 drv = wiphy_to_dev(wiphy); 70 rdev = wiphy_to_dev(wiphy);
71 return drv->wiphy_idx; 71 return rdev->wiphy_idx;
72} 72}
73 73
74/* requires cfg80211_drv_mutex to be held! */ 74/* requires cfg80211_rdev_mutex to be held! */
75struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx) 75struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx)
76{ 76{
77 struct cfg80211_registered_device *drv; 77 struct cfg80211_registered_device *rdev;
78 78
79 if (!wiphy_idx_valid(wiphy_idx)) 79 if (!wiphy_idx_valid(wiphy_idx))
80 return NULL; 80 return NULL;
81 81
82 assert_cfg80211_lock(); 82 assert_cfg80211_lock();
83 83
84 drv = cfg80211_drv_by_wiphy_idx(wiphy_idx); 84 rdev = cfg80211_rdev_by_wiphy_idx(wiphy_idx);
85 if (!drv) 85 if (!rdev)
86 return NULL; 86 return NULL;
87 return &drv->wiphy; 87 return &rdev->wiphy;
88} 88}
89 89
90/* requires cfg80211_mutex to be held! */ 90/* requires cfg80211_mutex to be held! */
91struct cfg80211_registered_device * 91struct cfg80211_registered_device *
92__cfg80211_drv_from_info(struct genl_info *info) 92__cfg80211_rdev_from_info(struct genl_info *info)
93{ 93{
94 int ifindex; 94 int ifindex;
95 struct cfg80211_registered_device *bywiphyidx = NULL, *byifidx = NULL; 95 struct cfg80211_registered_device *bywiphyidx = NULL, *byifidx = NULL;
@@ -99,7 +99,7 @@ __cfg80211_drv_from_info(struct genl_info *info)
99 assert_cfg80211_lock(); 99 assert_cfg80211_lock();
100 100
101 if (info->attrs[NL80211_ATTR_WIPHY]) { 101 if (info->attrs[NL80211_ATTR_WIPHY]) {
102 bywiphyidx = cfg80211_drv_by_wiphy_idx( 102 bywiphyidx = cfg80211_rdev_by_wiphy_idx(
103 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY])); 103 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY]));
104 err = -ENODEV; 104 err = -ENODEV;
105 } 105 }
@@ -134,26 +134,26 @@ __cfg80211_drv_from_info(struct genl_info *info)
134struct cfg80211_registered_device * 134struct cfg80211_registered_device *
135cfg80211_get_dev_from_info(struct genl_info *info) 135cfg80211_get_dev_from_info(struct genl_info *info)
136{ 136{
137 struct cfg80211_registered_device *drv; 137 struct cfg80211_registered_device *rdev;
138 138
139 mutex_lock(&cfg80211_mutex); 139 mutex_lock(&cfg80211_mutex);
140 drv = __cfg80211_drv_from_info(info); 140 rdev = __cfg80211_rdev_from_info(info);
141 141
142 /* if it is not an error we grab the lock on 142 /* if it is not an error we grab the lock on
143 * it to assure it won't be going away while 143 * it to assure it won't be going away while
144 * we operate on it */ 144 * we operate on it */
145 if (!IS_ERR(drv)) 145 if (!IS_ERR(rdev))
146 mutex_lock(&drv->mtx); 146 mutex_lock(&rdev->mtx);
147 147
148 mutex_unlock(&cfg80211_mutex); 148 mutex_unlock(&cfg80211_mutex);
149 149
150 return drv; 150 return rdev;
151} 151}
152 152
153struct cfg80211_registered_device * 153struct cfg80211_registered_device *
154cfg80211_get_dev_from_ifindex(int ifindex) 154cfg80211_get_dev_from_ifindex(int ifindex)
155{ 155{
156 struct cfg80211_registered_device *drv = ERR_PTR(-ENODEV); 156 struct cfg80211_registered_device *rdev = ERR_PTR(-ENODEV);
157 struct net_device *dev; 157 struct net_device *dev;
158 158
159 mutex_lock(&cfg80211_mutex); 159 mutex_lock(&cfg80211_mutex);
@@ -161,27 +161,21 @@ cfg80211_get_dev_from_ifindex(int ifindex)
161 if (!dev) 161 if (!dev)
162 goto out; 162 goto out;
163 if (dev->ieee80211_ptr) { 163 if (dev->ieee80211_ptr) {
164 drv = wiphy_to_dev(dev->ieee80211_ptr->wiphy); 164 rdev = wiphy_to_dev(dev->ieee80211_ptr->wiphy);
165 mutex_lock(&drv->mtx); 165 mutex_lock(&rdev->mtx);
166 } else 166 } else
167 drv = ERR_PTR(-ENODEV); 167 rdev = ERR_PTR(-ENODEV);
168 dev_put(dev); 168 dev_put(dev);
169 out: 169 out:
170 mutex_unlock(&cfg80211_mutex); 170 mutex_unlock(&cfg80211_mutex);
171 return drv; 171 return rdev;
172}
173
174void cfg80211_put_dev(struct cfg80211_registered_device *drv)
175{
176 BUG_ON(IS_ERR(drv));
177 mutex_unlock(&drv->mtx);
178} 172}
179 173
180/* requires cfg80211_mutex to be held */ 174/* requires cfg80211_mutex to be held */
181int cfg80211_dev_rename(struct cfg80211_registered_device *rdev, 175int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
182 char *newname) 176 char *newname)
183{ 177{
184 struct cfg80211_registered_device *drv; 178 struct cfg80211_registered_device *rdev2;
185 int wiphy_idx, taken = -1, result, digits; 179 int wiphy_idx, taken = -1, result, digits;
186 180
187 assert_cfg80211_lock(); 181 assert_cfg80211_lock();
@@ -207,8 +201,8 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
207 return 0; 201 return 0;
208 202
209 /* Ensure another device does not already have this name. */ 203 /* Ensure another device does not already have this name. */
210 list_for_each_entry(drv, &cfg80211_drv_list, list) 204 list_for_each_entry(rdev2, &cfg80211_rdev_list, list)
211 if (strcmp(newname, dev_name(&drv->wiphy.dev)) == 0) 205 if (strcmp(newname, dev_name(&rdev2->wiphy.dev)) == 0)
212 return -EINVAL; 206 return -EINVAL;
213 207
214 result = device_rename(&rdev->wiphy.dev, newname); 208 result = device_rename(&rdev->wiphy.dev, newname);
@@ -230,26 +224,26 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
230 224
231static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data) 225static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data)
232{ 226{
233 struct cfg80211_registered_device *drv = data; 227 struct cfg80211_registered_device *rdev = data;
234 228
235 drv->ops->rfkill_poll(&drv->wiphy); 229 rdev->ops->rfkill_poll(&rdev->wiphy);
236} 230}
237 231
238static int cfg80211_rfkill_set_block(void *data, bool blocked) 232static int cfg80211_rfkill_set_block(void *data, bool blocked)
239{ 233{
240 struct cfg80211_registered_device *drv = data; 234 struct cfg80211_registered_device *rdev = data;
241 struct wireless_dev *wdev; 235 struct wireless_dev *wdev;
242 236
243 if (!blocked) 237 if (!blocked)
244 return 0; 238 return 0;
245 239
246 rtnl_lock(); 240 rtnl_lock();
247 mutex_lock(&drv->devlist_mtx); 241 mutex_lock(&rdev->devlist_mtx);
248 242
249 list_for_each_entry(wdev, &drv->netdev_list, list) 243 list_for_each_entry(wdev, &rdev->netdev_list, list)
250 dev_close(wdev->netdev); 244 dev_close(wdev->netdev);
251 245
252 mutex_unlock(&drv->devlist_mtx); 246 mutex_unlock(&rdev->devlist_mtx);
253 rtnl_unlock(); 247 rtnl_unlock();
254 248
255 return 0; 249 return 0;
@@ -257,10 +251,75 @@ static int cfg80211_rfkill_set_block(void *data, bool blocked)
257 251
258static void cfg80211_rfkill_sync_work(struct work_struct *work) 252static void cfg80211_rfkill_sync_work(struct work_struct *work)
259{ 253{
260 struct cfg80211_registered_device *drv; 254 struct cfg80211_registered_device *rdev;
255
256 rdev = container_of(work, struct cfg80211_registered_device, rfkill_sync);
257 cfg80211_rfkill_set_block(rdev, rfkill_blocked(rdev->rfkill));
258}
259
260static void cfg80211_process_events(struct wireless_dev *wdev)
261{
262 struct cfg80211_event *ev;
263 unsigned long flags;
264
265 spin_lock_irqsave(&wdev->event_lock, flags);
266 while (!list_empty(&wdev->event_list)) {
267 ev = list_first_entry(&wdev->event_list,
268 struct cfg80211_event, list);
269 list_del(&ev->list);
270 spin_unlock_irqrestore(&wdev->event_lock, flags);
271
272 wdev_lock(wdev);
273 switch (ev->type) {
274 case EVENT_CONNECT_RESULT:
275 __cfg80211_connect_result(
276 wdev->netdev, ev->cr.bssid,
277 ev->cr.req_ie, ev->cr.req_ie_len,
278 ev->cr.resp_ie, ev->cr.resp_ie_len,
279 ev->cr.status,
280 ev->cr.status == WLAN_STATUS_SUCCESS);
281 break;
282 case EVENT_ROAMED:
283 __cfg80211_roamed(wdev, ev->rm.bssid,
284 ev->rm.req_ie, ev->rm.req_ie_len,
285 ev->rm.resp_ie, ev->rm.resp_ie_len);
286 break;
287 case EVENT_DISCONNECTED:
288 __cfg80211_disconnected(wdev->netdev,
289 ev->dc.ie, ev->dc.ie_len,
290 ev->dc.reason, true);
291 break;
292 case EVENT_IBSS_JOINED:
293 __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid);
294 break;
295 }
296 wdev_unlock(wdev);
297
298 kfree(ev);
261 299
262 drv = container_of(work, struct cfg80211_registered_device, rfkill_sync); 300 spin_lock_irqsave(&wdev->event_lock, flags);
263 cfg80211_rfkill_set_block(drv, rfkill_blocked(drv->rfkill)); 301 }
302 spin_unlock_irqrestore(&wdev->event_lock, flags);
303}
304
305static void cfg80211_event_work(struct work_struct *work)
306{
307 struct cfg80211_registered_device *rdev;
308 struct wireless_dev *wdev;
309
310 rdev = container_of(work, struct cfg80211_registered_device,
311 event_work);
312
313 rtnl_lock();
314 cfg80211_lock_rdev(rdev);
315 mutex_lock(&rdev->devlist_mtx);
316
317 list_for_each_entry(wdev, &rdev->netdev_list, list)
318 cfg80211_process_events(wdev);
319
320 mutex_unlock(&rdev->devlist_mtx);
321 cfg80211_unlock_rdev(rdev);
322 rtnl_unlock();
264} 323}
265 324
266/* exported functions */ 325/* exported functions */
@@ -269,76 +328,84 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
269{ 328{
270 static int wiphy_counter; 329 static int wiphy_counter;
271 330
272 struct cfg80211_registered_device *drv; 331 struct cfg80211_registered_device *rdev;
273 int alloc_size; 332 int alloc_size;
274 333
275 WARN_ON(!ops->add_key && ops->del_key); 334 WARN_ON(ops->add_key && (!ops->del_key || !ops->set_default_key));
276 WARN_ON(ops->add_key && !ops->del_key); 335 WARN_ON(ops->auth && (!ops->assoc || !ops->deauth || !ops->disassoc));
336 WARN_ON(ops->connect && !ops->disconnect);
337 WARN_ON(ops->join_ibss && !ops->leave_ibss);
338 WARN_ON(ops->add_virtual_intf && !ops->del_virtual_intf);
339 WARN_ON(ops->add_station && !ops->del_station);
340 WARN_ON(ops->add_mpath && !ops->del_mpath);
277 341
278 alloc_size = sizeof(*drv) + sizeof_priv; 342 alloc_size = sizeof(*rdev) + sizeof_priv;
279 343
280 drv = kzalloc(alloc_size, GFP_KERNEL); 344 rdev = kzalloc(alloc_size, GFP_KERNEL);
281 if (!drv) 345 if (!rdev)
282 return NULL; 346 return NULL;
283 347
284 drv->ops = ops; 348 rdev->ops = ops;
285 349
286 mutex_lock(&cfg80211_mutex); 350 mutex_lock(&cfg80211_mutex);
287 351
288 drv->wiphy_idx = wiphy_counter++; 352 rdev->wiphy_idx = wiphy_counter++;
289 353
290 if (unlikely(!wiphy_idx_valid(drv->wiphy_idx))) { 354 if (unlikely(!wiphy_idx_valid(rdev->wiphy_idx))) {
291 wiphy_counter--; 355 wiphy_counter--;
292 mutex_unlock(&cfg80211_mutex); 356 mutex_unlock(&cfg80211_mutex);
293 /* ugh, wrapped! */ 357 /* ugh, wrapped! */
294 kfree(drv); 358 kfree(rdev);
295 return NULL; 359 return NULL;
296 } 360 }
297 361
298 mutex_unlock(&cfg80211_mutex); 362 mutex_unlock(&cfg80211_mutex);
299 363
300 /* give it a proper name */ 364 /* give it a proper name */
301 dev_set_name(&drv->wiphy.dev, PHY_NAME "%d", drv->wiphy_idx); 365 dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx);
302 366
303 mutex_init(&drv->mtx); 367 mutex_init(&rdev->mtx);
304 mutex_init(&drv->devlist_mtx); 368 mutex_init(&rdev->devlist_mtx);
305 INIT_LIST_HEAD(&drv->netdev_list); 369 INIT_LIST_HEAD(&rdev->netdev_list);
306 spin_lock_init(&drv->bss_lock); 370 spin_lock_init(&rdev->bss_lock);
307 INIT_LIST_HEAD(&drv->bss_list); 371 INIT_LIST_HEAD(&rdev->bss_list);
308 372 INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done);
309 device_initialize(&drv->wiphy.dev); 373
310 drv->wiphy.dev.class = &ieee80211_class; 374 device_initialize(&rdev->wiphy.dev);
311 drv->wiphy.dev.platform_data = drv; 375 rdev->wiphy.dev.class = &ieee80211_class;
312 376 rdev->wiphy.dev.platform_data = rdev;
313 drv->rfkill_ops.set_block = cfg80211_rfkill_set_block; 377
314 drv->rfkill = rfkill_alloc(dev_name(&drv->wiphy.dev), 378 rdev->rfkill_ops.set_block = cfg80211_rfkill_set_block;
315 &drv->wiphy.dev, RFKILL_TYPE_WLAN, 379 rdev->rfkill = rfkill_alloc(dev_name(&rdev->wiphy.dev),
316 &drv->rfkill_ops, drv); 380 &rdev->wiphy.dev, RFKILL_TYPE_WLAN,
317 381 &rdev->rfkill_ops, rdev);
318 if (!drv->rfkill) { 382
319 kfree(drv); 383 if (!rdev->rfkill) {
384 kfree(rdev);
320 return NULL; 385 return NULL;
321 } 386 }
322 387
323 INIT_WORK(&drv->rfkill_sync, cfg80211_rfkill_sync_work); 388 INIT_WORK(&rdev->rfkill_sync, cfg80211_rfkill_sync_work);
389 INIT_WORK(&rdev->conn_work, cfg80211_conn_work);
390 INIT_WORK(&rdev->event_work, cfg80211_event_work);
324 391
325 /* 392 /*
326 * Initialize wiphy parameters to IEEE 802.11 MIB default values. 393 * Initialize wiphy parameters to IEEE 802.11 MIB default values.
327 * Fragmentation and RTS threshold are disabled by default with the 394 * Fragmentation and RTS threshold are disabled by default with the
328 * special -1 value. 395 * special -1 value.
329 */ 396 */
330 drv->wiphy.retry_short = 7; 397 rdev->wiphy.retry_short = 7;
331 drv->wiphy.retry_long = 4; 398 rdev->wiphy.retry_long = 4;
332 drv->wiphy.frag_threshold = (u32) -1; 399 rdev->wiphy.frag_threshold = (u32) -1;
333 drv->wiphy.rts_threshold = (u32) -1; 400 rdev->wiphy.rts_threshold = (u32) -1;
334 401
335 return &drv->wiphy; 402 return &rdev->wiphy;
336} 403}
337EXPORT_SYMBOL(wiphy_new); 404EXPORT_SYMBOL(wiphy_new);
338 405
339int wiphy_register(struct wiphy *wiphy) 406int wiphy_register(struct wiphy *wiphy)
340{ 407{
341 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 408 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
342 int res; 409 int res;
343 enum ieee80211_band band; 410 enum ieee80211_band band;
344 struct ieee80211_supported_band *sband; 411 struct ieee80211_supported_band *sband;
@@ -346,9 +413,6 @@ int wiphy_register(struct wiphy *wiphy)
346 int i; 413 int i;
347 u16 ifmodes = wiphy->interface_modes; 414 u16 ifmodes = wiphy->interface_modes;
348 415
349 if (WARN_ON(wiphy->max_scan_ssids < 1))
350 return -EINVAL;
351
352 /* sanity check ifmodes */ 416 /* sanity check ifmodes */
353 WARN_ON(!ifmodes); 417 WARN_ON(!ifmodes);
354 ifmodes &= ((1 << __NL80211_IFTYPE_AFTER_LAST) - 1) & ~1; 418 ifmodes &= ((1 << __NL80211_IFTYPE_AFTER_LAST) - 1) & ~1;
@@ -395,11 +459,11 @@ int wiphy_register(struct wiphy *wiphy)
395 /* check and set up bitrates */ 459 /* check and set up bitrates */
396 ieee80211_set_bitrate_flags(wiphy); 460 ieee80211_set_bitrate_flags(wiphy);
397 461
398 res = device_add(&drv->wiphy.dev); 462 res = device_add(&rdev->wiphy.dev);
399 if (res) 463 if (res)
400 return res; 464 return res;
401 465
402 res = rfkill_register(drv->rfkill); 466 res = rfkill_register(rdev->rfkill);
403 if (res) 467 if (res)
404 goto out_rm_dev; 468 goto out_rm_dev;
405 469
@@ -408,16 +472,16 @@ int wiphy_register(struct wiphy *wiphy)
408 /* set up regulatory info */ 472 /* set up regulatory info */
409 wiphy_update_regulatory(wiphy, NL80211_REGDOM_SET_BY_CORE); 473 wiphy_update_regulatory(wiphy, NL80211_REGDOM_SET_BY_CORE);
410 474
411 list_add(&drv->list, &cfg80211_drv_list); 475 list_add(&rdev->list, &cfg80211_rdev_list);
412 476
413 mutex_unlock(&cfg80211_mutex); 477 mutex_unlock(&cfg80211_mutex);
414 478
415 /* add to debugfs */ 479 /* add to debugfs */
416 drv->wiphy.debugfsdir = 480 rdev->wiphy.debugfsdir =
417 debugfs_create_dir(wiphy_name(&drv->wiphy), 481 debugfs_create_dir(wiphy_name(&rdev->wiphy),
418 ieee80211_debugfs_dir); 482 ieee80211_debugfs_dir);
419 if (IS_ERR(drv->wiphy.debugfsdir)) 483 if (IS_ERR(rdev->wiphy.debugfsdir))
420 drv->wiphy.debugfsdir = NULL; 484 rdev->wiphy.debugfsdir = NULL;
421 485
422 if (wiphy->custom_regulatory) { 486 if (wiphy->custom_regulatory) {
423 struct regulatory_request request; 487 struct regulatory_request request;
@@ -430,48 +494,48 @@ int wiphy_register(struct wiphy *wiphy)
430 nl80211_send_reg_change_event(&request); 494 nl80211_send_reg_change_event(&request);
431 } 495 }
432 496
433 cfg80211_debugfs_drv_add(drv); 497 cfg80211_debugfs_rdev_add(rdev);
434 498
435 return 0; 499 return 0;
436 500
437 out_rm_dev: 501 out_rm_dev:
438 device_del(&drv->wiphy.dev); 502 device_del(&rdev->wiphy.dev);
439 return res; 503 return res;
440} 504}
441EXPORT_SYMBOL(wiphy_register); 505EXPORT_SYMBOL(wiphy_register);
442 506
443void wiphy_rfkill_start_polling(struct wiphy *wiphy) 507void wiphy_rfkill_start_polling(struct wiphy *wiphy)
444{ 508{
445 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 509 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
446 510
447 if (!drv->ops->rfkill_poll) 511 if (!rdev->ops->rfkill_poll)
448 return; 512 return;
449 drv->rfkill_ops.poll = cfg80211_rfkill_poll; 513 rdev->rfkill_ops.poll = cfg80211_rfkill_poll;
450 rfkill_resume_polling(drv->rfkill); 514 rfkill_resume_polling(rdev->rfkill);
451} 515}
452EXPORT_SYMBOL(wiphy_rfkill_start_polling); 516EXPORT_SYMBOL(wiphy_rfkill_start_polling);
453 517
454void wiphy_rfkill_stop_polling(struct wiphy *wiphy) 518void wiphy_rfkill_stop_polling(struct wiphy *wiphy)
455{ 519{
456 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 520 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
457 521
458 rfkill_pause_polling(drv->rfkill); 522 rfkill_pause_polling(rdev->rfkill);
459} 523}
460EXPORT_SYMBOL(wiphy_rfkill_stop_polling); 524EXPORT_SYMBOL(wiphy_rfkill_stop_polling);
461 525
462void wiphy_unregister(struct wiphy *wiphy) 526void wiphy_unregister(struct wiphy *wiphy)
463{ 527{
464 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 528 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
465 529
466 rfkill_unregister(drv->rfkill); 530 rfkill_unregister(rdev->rfkill);
467 531
468 /* protect the device list */ 532 /* protect the device list */
469 mutex_lock(&cfg80211_mutex); 533 mutex_lock(&cfg80211_mutex);
470 534
471 BUG_ON(!list_empty(&drv->netdev_list)); 535 BUG_ON(!list_empty(&rdev->netdev_list));
472 536
473 /* 537 /*
474 * Try to grab drv->mtx. If a command is still in progress, 538 * Try to grab rdev->mtx. If a command is still in progress,
475 * hopefully the driver will refuse it since it's tearing 539 * hopefully the driver will refuse it since it's tearing
476 * down the device already. We wait for this command to complete 540 * down the device already. We wait for this command to complete
477 * before unlinking the item from the list. 541 * before unlinking the item from the list.
@@ -480,33 +544,38 @@ void wiphy_unregister(struct wiphy *wiphy)
480 * get to lock contention here if userspace issues a command 544 * get to lock contention here if userspace issues a command
481 * that identified the hardware by wiphy index. 545 * that identified the hardware by wiphy index.
482 */ 546 */
483 mutex_lock(&drv->mtx); 547 mutex_lock(&rdev->mtx);
484 /* unlock again before freeing */ 548 /* unlock again before freeing */
485 mutex_unlock(&drv->mtx); 549 mutex_unlock(&rdev->mtx);
486 550
487 cfg80211_debugfs_drv_del(drv); 551 cancel_work_sync(&rdev->conn_work);
552 cancel_work_sync(&rdev->scan_done_wk);
553 kfree(rdev->scan_req);
554 flush_work(&rdev->event_work);
555
556 cfg80211_debugfs_rdev_del(rdev);
488 557
489 /* If this device got a regulatory hint tell core its 558 /* If this device got a regulatory hint tell core its
490 * free to listen now to a new shiny device regulatory hint */ 559 * free to listen now to a new shiny device regulatory hint */
491 reg_device_remove(wiphy); 560 reg_device_remove(wiphy);
492 561
493 list_del(&drv->list); 562 list_del(&rdev->list);
494 device_del(&drv->wiphy.dev); 563 device_del(&rdev->wiphy.dev);
495 debugfs_remove(drv->wiphy.debugfsdir); 564 debugfs_remove(rdev->wiphy.debugfsdir);
496 565
497 mutex_unlock(&cfg80211_mutex); 566 mutex_unlock(&cfg80211_mutex);
498} 567}
499EXPORT_SYMBOL(wiphy_unregister); 568EXPORT_SYMBOL(wiphy_unregister);
500 569
501void cfg80211_dev_free(struct cfg80211_registered_device *drv) 570void cfg80211_dev_free(struct cfg80211_registered_device *rdev)
502{ 571{
503 struct cfg80211_internal_bss *scan, *tmp; 572 struct cfg80211_internal_bss *scan, *tmp;
504 rfkill_destroy(drv->rfkill); 573 rfkill_destroy(rdev->rfkill);
505 mutex_destroy(&drv->mtx); 574 mutex_destroy(&rdev->mtx);
506 mutex_destroy(&drv->devlist_mtx); 575 mutex_destroy(&rdev->devlist_mtx);
507 list_for_each_entry_safe(scan, tmp, &drv->bss_list, list) 576 list_for_each_entry_safe(scan, tmp, &rdev->bss_list, list)
508 cfg80211_put_bss(&scan->pub); 577 cfg80211_put_bss(&scan->pub);
509 kfree(drv); 578 kfree(rdev);
510} 579}
511 580
512void wiphy_free(struct wiphy *wiphy) 581void wiphy_free(struct wiphy *wiphy)
@@ -517,10 +586,10 @@ EXPORT_SYMBOL(wiphy_free);
517 586
518void wiphy_rfkill_set_hw_state(struct wiphy *wiphy, bool blocked) 587void wiphy_rfkill_set_hw_state(struct wiphy *wiphy, bool blocked)
519{ 588{
520 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 589 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
521 590
522 if (rfkill_set_hw_state(drv->rfkill, blocked)) 591 if (rfkill_set_hw_state(rdev->rfkill, blocked))
523 schedule_work(&drv->rfkill_sync); 592 schedule_work(&rdev->rfkill_sync);
524} 593}
525EXPORT_SYMBOL(wiphy_rfkill_set_hw_state); 594EXPORT_SYMBOL(wiphy_rfkill_set_hw_state);
526 595
@@ -529,56 +598,102 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
529 void *ndev) 598 void *ndev)
530{ 599{
531 struct net_device *dev = ndev; 600 struct net_device *dev = ndev;
601 struct wireless_dev *wdev = dev->ieee80211_ptr;
532 struct cfg80211_registered_device *rdev; 602 struct cfg80211_registered_device *rdev;
533 603
534 if (!dev->ieee80211_ptr) 604 if (!wdev)
535 return NOTIFY_DONE; 605 return NOTIFY_DONE;
536 606
537 rdev = wiphy_to_dev(dev->ieee80211_ptr->wiphy); 607 rdev = wiphy_to_dev(wdev->wiphy);
538 608
539 WARN_ON(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_UNSPECIFIED); 609 WARN_ON(wdev->iftype == NL80211_IFTYPE_UNSPECIFIED);
540 610
541 switch (state) { 611 switch (state) {
542 case NETDEV_REGISTER: 612 case NETDEV_REGISTER:
613 mutex_init(&wdev->mtx);
614 INIT_LIST_HEAD(&wdev->event_list);
615 spin_lock_init(&wdev->event_lock);
543 mutex_lock(&rdev->devlist_mtx); 616 mutex_lock(&rdev->devlist_mtx);
544 list_add(&dev->ieee80211_ptr->list, &rdev->netdev_list); 617 list_add(&wdev->list, &rdev->netdev_list);
545 if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj, 618 if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
546 "phy80211")) { 619 "phy80211")) {
547 printk(KERN_ERR "wireless: failed to add phy80211 " 620 printk(KERN_ERR "wireless: failed to add phy80211 "
548 "symlink to netdev!\n"); 621 "symlink to netdev!\n");
549 } 622 }
550 dev->ieee80211_ptr->netdev = dev; 623 wdev->netdev = dev;
624 wdev->sme_state = CFG80211_SME_IDLE;
625 mutex_unlock(&rdev->devlist_mtx);
551#ifdef CONFIG_WIRELESS_EXT 626#ifdef CONFIG_WIRELESS_EXT
552 dev->ieee80211_ptr->wext.default_key = -1; 627 wdev->wext.default_key = -1;
553 dev->ieee80211_ptr->wext.default_mgmt_key = -1; 628 wdev->wext.default_mgmt_key = -1;
629 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
630 wdev->wext.ps = CONFIG_CFG80211_DEFAULT_PS_VALUE;
631 wdev->wext.ps_timeout = 500;
632 if (rdev->ops->set_power_mgmt)
633 if (rdev->ops->set_power_mgmt(wdev->wiphy, dev,
634 wdev->wext.ps,
635 wdev->wext.ps_timeout)) {
636 /* assume this means it's off */
637 wdev->wext.ps = false;
638 }
554#endif 639#endif
555 mutex_unlock(&rdev->devlist_mtx);
556 break; 640 break;
557 case NETDEV_GOING_DOWN: 641 case NETDEV_GOING_DOWN:
558 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 642 switch (wdev->iftype) {
643 case NL80211_IFTYPE_ADHOC:
644 cfg80211_leave_ibss(rdev, dev, true);
645 break;
646 case NL80211_IFTYPE_STATION:
647 wdev_lock(wdev);
648#ifdef CONFIG_WIRELESS_EXT
649 kfree(wdev->wext.ie);
650 wdev->wext.ie = NULL;
651 wdev->wext.ie_len = 0;
652 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
653#endif
654 __cfg80211_disconnect(rdev, dev,
655 WLAN_REASON_DEAUTH_LEAVING, true);
656 cfg80211_mlme_down(rdev, dev);
657 wdev_unlock(wdev);
559 break; 658 break;
560 if (!dev->ieee80211_ptr->ssid_len) 659 default:
561 break; 660 break;
562 cfg80211_leave_ibss(rdev, dev, true); 661 }
563 break; 662 break;
564 case NETDEV_UP: 663 case NETDEV_UP:
565#ifdef CONFIG_WIRELESS_EXT 664#ifdef CONFIG_WIRELESS_EXT
566 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 665 cfg80211_lock_rdev(rdev);
666 wdev_lock(wdev);
667 switch (wdev->iftype) {
668 case NL80211_IFTYPE_ADHOC:
669 if (wdev->wext.ibss.ssid_len)
670 __cfg80211_join_ibss(rdev, dev,
671 &wdev->wext.ibss);
567 break; 672 break;
568 if (!dev->ieee80211_ptr->wext.ibss.ssid_len) 673 case NL80211_IFTYPE_STATION:
674 if (wdev->wext.connect.ssid_len)
675 __cfg80211_connect(rdev, dev,
676 &wdev->wext.connect);
569 break; 677 break;
570 cfg80211_join_ibss(rdev, dev, &dev->ieee80211_ptr->wext.ibss); 678 default:
571 break; 679 break;
680 }
681 wdev_unlock(wdev);
682 cfg80211_unlock_rdev(rdev);
572#endif 683#endif
684 break;
573 case NETDEV_UNREGISTER: 685 case NETDEV_UNREGISTER:
574 mutex_lock(&rdev->devlist_mtx); 686 mutex_lock(&rdev->devlist_mtx);
575 if (!list_empty(&dev->ieee80211_ptr->list)) { 687 if (!list_empty(&wdev->list)) {
576 sysfs_remove_link(&dev->dev.kobj, "phy80211"); 688 sysfs_remove_link(&dev->dev.kobj, "phy80211");
577 list_del_init(&dev->ieee80211_ptr->list); 689 list_del_init(&wdev->list);
578 } 690 }
579 mutex_unlock(&rdev->devlist_mtx); 691 mutex_unlock(&rdev->devlist_mtx);
692 mutex_destroy(&wdev->mtx);
580 break; 693 break;
581 case NETDEV_PRE_UP: 694 case NETDEV_PRE_UP:
695 if (!(wdev->wiphy->interface_modes & BIT(wdev->iftype)))
696 return notifier_from_errno(-EOPNOTSUPP);
582 if (rfkill_blocked(rdev->rfkill)) 697 if (rfkill_blocked(rdev->rfkill))
583 return notifier_from_errno(-ERFKILL); 698 return notifier_from_errno(-ERFKILL);
584 break; 699 break;
diff --git a/net/wireless/core.h b/net/wireless/core.h
index bfa340c7abb5..e46cd6eb61d7 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -57,6 +57,14 @@ struct cfg80211_registered_device {
57 u32 bss_generation; 57 u32 bss_generation;
58 struct cfg80211_scan_request *scan_req; /* protected by RTNL */ 58 struct cfg80211_scan_request *scan_req; /* protected by RTNL */
59 unsigned long suspend_at; 59 unsigned long suspend_at;
60 struct work_struct scan_done_wk;
61
62#ifdef CONFIG_NL80211_TESTMODE
63 struct genl_info *testmode_info;
64#endif
65
66 struct work_struct conn_work;
67 struct work_struct event_work;
60 68
61#ifdef CONFIG_CFG80211_DEBUGFS 69#ifdef CONFIG_CFG80211_DEBUGFS
62 /* Debugfs entries */ 70 /* Debugfs entries */
@@ -89,13 +97,13 @@ bool wiphy_idx_valid(int wiphy_idx)
89} 97}
90 98
91extern struct mutex cfg80211_mutex; 99extern struct mutex cfg80211_mutex;
92extern struct list_head cfg80211_drv_list; 100extern struct list_head cfg80211_rdev_list;
93 101
94#define assert_cfg80211_lock() WARN_ON(!mutex_is_locked(&cfg80211_mutex)) 102#define assert_cfg80211_lock() WARN_ON(!mutex_is_locked(&cfg80211_mutex))
95 103
96/* 104/*
97 * You can use this to mark a wiphy_idx as not having an associated wiphy. 105 * You can use this to mark a wiphy_idx as not having an associated wiphy.
98 * It guarantees cfg80211_drv_by_wiphy_idx(wiphy_idx) will return NULL 106 * It guarantees cfg80211_rdev_by_wiphy_idx(wiphy_idx) will return NULL
99 */ 107 */
100#define WIPHY_IDX_STALE -1 108#define WIPHY_IDX_STALE -1
101 109
@@ -104,17 +112,35 @@ struct cfg80211_internal_bss {
104 struct rb_node rbn; 112 struct rb_node rbn;
105 unsigned long ts; 113 unsigned long ts;
106 struct kref ref; 114 struct kref ref;
107 bool hold, ies_allocated; 115 atomic_t hold;
116 bool ies_allocated;
108 117
109 /* must be last because of priv member */ 118 /* must be last because of priv member */
110 struct cfg80211_bss pub; 119 struct cfg80211_bss pub;
111}; 120};
112 121
113struct cfg80211_registered_device *cfg80211_drv_by_wiphy_idx(int wiphy_idx); 122static inline struct cfg80211_internal_bss *bss_from_pub(struct cfg80211_bss *pub)
123{
124 return container_of(pub, struct cfg80211_internal_bss, pub);
125}
126
127static inline void cfg80211_hold_bss(struct cfg80211_internal_bss *bss)
128{
129 atomic_inc(&bss->hold);
130}
131
132static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
133{
134 int r = atomic_dec_return(&bss->hold);
135 WARN_ON(r < 0);
136}
137
138
139struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx);
114int get_wiphy_idx(struct wiphy *wiphy); 140int get_wiphy_idx(struct wiphy *wiphy);
115 141
116struct cfg80211_registered_device * 142struct cfg80211_registered_device *
117__cfg80211_drv_from_info(struct genl_info *info); 143__cfg80211_rdev_from_info(struct genl_info *info);
118 144
119/* 145/*
120 * This function returns a pointer to the driver 146 * This function returns a pointer to the driver
@@ -122,12 +148,12 @@ __cfg80211_drv_from_info(struct genl_info *info);
122 * If successful, it returns non-NULL and also locks 148 * If successful, it returns non-NULL and also locks
123 * the driver's mutex! 149 * the driver's mutex!
124 * 150 *
125 * This means that you need to call cfg80211_put_dev() 151 * This means that you need to call cfg80211_unlock_rdev()
126 * before being allowed to acquire &cfg80211_mutex! 152 * before being allowed to acquire &cfg80211_mutex!
127 * 153 *
128 * This is necessary because we need to lock the global 154 * This is necessary because we need to lock the global
129 * mutex to get an item off the list safely, and then 155 * mutex to get an item off the list safely, and then
130 * we lock the drv mutex so it doesn't go away under us. 156 * we lock the rdev mutex so it doesn't go away under us.
131 * 157 *
132 * We don't want to keep cfg80211_mutex locked 158 * We don't want to keep cfg80211_mutex locked
133 * for all the time in order to allow requests on 159 * for all the time in order to allow requests on
@@ -139,19 +165,84 @@ __cfg80211_drv_from_info(struct genl_info *info);
139extern struct cfg80211_registered_device * 165extern struct cfg80211_registered_device *
140cfg80211_get_dev_from_info(struct genl_info *info); 166cfg80211_get_dev_from_info(struct genl_info *info);
141 167
142/* requires cfg80211_drv_mutex to be held! */ 168/* requires cfg80211_rdev_mutex to be held! */
143struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx); 169struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
144 170
145/* identical to cfg80211_get_dev_from_info but only operate on ifindex */ 171/* identical to cfg80211_get_dev_from_info but only operate on ifindex */
146extern struct cfg80211_registered_device * 172extern struct cfg80211_registered_device *
147cfg80211_get_dev_from_ifindex(int ifindex); 173cfg80211_get_dev_from_ifindex(int ifindex);
148 174
149extern void cfg80211_put_dev(struct cfg80211_registered_device *drv); 175static inline void cfg80211_lock_rdev(struct cfg80211_registered_device *rdev)
176{
177 mutex_lock(&rdev->mtx);
178}
179
180static inline void cfg80211_unlock_rdev(struct cfg80211_registered_device *rdev)
181{
182 BUG_ON(IS_ERR(rdev) || !rdev);
183 mutex_unlock(&rdev->mtx);
184}
185
186static inline void wdev_lock(struct wireless_dev *wdev)
187 __acquires(wdev)
188{
189 mutex_lock(&wdev->mtx);
190 __acquire(wdev->mtx);
191}
192
193static inline void wdev_unlock(struct wireless_dev *wdev)
194 __releases(wdev)
195{
196 __release(wdev->mtx);
197 mutex_unlock(&wdev->mtx);
198}
199
200#define ASSERT_RDEV_LOCK(rdev) WARN_ON(!mutex_is_locked(&(rdev)->mtx));
201#define ASSERT_WDEV_LOCK(wdev) WARN_ON(!mutex_is_locked(&(wdev)->mtx));
202
203enum cfg80211_event_type {
204 EVENT_CONNECT_RESULT,
205 EVENT_ROAMED,
206 EVENT_DISCONNECTED,
207 EVENT_IBSS_JOINED,
208};
209
210struct cfg80211_event {
211 struct list_head list;
212 enum cfg80211_event_type type;
213
214 union {
215 struct {
216 u8 bssid[ETH_ALEN];
217 const u8 *req_ie;
218 const u8 *resp_ie;
219 size_t req_ie_len;
220 size_t resp_ie_len;
221 u16 status;
222 } cr;
223 struct {
224 u8 bssid[ETH_ALEN];
225 const u8 *req_ie;
226 const u8 *resp_ie;
227 size_t req_ie_len;
228 size_t resp_ie_len;
229 } rm;
230 struct {
231 const u8 *ie;
232 size_t ie_len;
233 u16 reason;
234 } dc;
235 struct {
236 u8 bssid[ETH_ALEN];
237 } ij;
238 };
239};
240
150 241
151/* free object */ 242/* free object */
152extern void cfg80211_dev_free(struct cfg80211_registered_device *drv); 243extern void cfg80211_dev_free(struct cfg80211_registered_device *rdev);
153 244
154extern int cfg80211_dev_rename(struct cfg80211_registered_device *drv, 245extern int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
155 char *newname); 246 char *newname);
156 247
157void ieee80211_set_bitrate_flags(struct wiphy *wiphy); 248void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
@@ -163,15 +254,86 @@ void cfg80211_bss_age(struct cfg80211_registered_device *dev,
163 unsigned long age_secs); 254 unsigned long age_secs);
164 255
165/* IBSS */ 256/* IBSS */
257int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
258 struct net_device *dev,
259 struct cfg80211_ibss_params *params);
166int cfg80211_join_ibss(struct cfg80211_registered_device *rdev, 260int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
167 struct net_device *dev, 261 struct net_device *dev,
168 struct cfg80211_ibss_params *params); 262 struct cfg80211_ibss_params *params);
169void cfg80211_clear_ibss(struct net_device *dev, bool nowext); 263void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
170int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev, 264int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
171 struct net_device *dev, bool nowext); 265 struct net_device *dev, bool nowext);
266void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid);
267
268/* MLME */
269int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
270 struct net_device *dev,
271 struct ieee80211_channel *chan,
272 enum nl80211_auth_type auth_type,
273 const u8 *bssid,
274 const u8 *ssid, int ssid_len,
275 const u8 *ie, int ie_len);
276int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
277 struct net_device *dev, struct ieee80211_channel *chan,
278 enum nl80211_auth_type auth_type, const u8 *bssid,
279 const u8 *ssid, int ssid_len,
280 const u8 *ie, int ie_len);
281int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
282 struct net_device *dev,
283 struct ieee80211_channel *chan,
284 const u8 *bssid, const u8 *prev_bssid,
285 const u8 *ssid, int ssid_len,
286 const u8 *ie, int ie_len, bool use_mfp,
287 struct cfg80211_crypto_settings *crypt);
288int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
289 struct net_device *dev, struct ieee80211_channel *chan,
290 const u8 *bssid, const u8 *prev_bssid,
291 const u8 *ssid, int ssid_len,
292 const u8 *ie, int ie_len, bool use_mfp,
293 struct cfg80211_crypto_settings *crypt);
294int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
295 struct net_device *dev, const u8 *bssid,
296 const u8 *ie, int ie_len, u16 reason);
297int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
298 struct net_device *dev, const u8 *bssid,
299 const u8 *ie, int ie_len, u16 reason);
300int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
301 struct net_device *dev, const u8 *bssid,
302 const u8 *ie, int ie_len, u16 reason);
303void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
304 struct net_device *dev);
305void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
306 const u8 *req_ie, size_t req_ie_len,
307 const u8 *resp_ie, size_t resp_ie_len,
308 u16 status, bool wextev);
309
310/* SME */
311int __cfg80211_connect(struct cfg80211_registered_device *rdev,
312 struct net_device *dev,
313 struct cfg80211_connect_params *connect);
314int cfg80211_connect(struct cfg80211_registered_device *rdev,
315 struct net_device *dev,
316 struct cfg80211_connect_params *connect);
317int __cfg80211_disconnect(struct cfg80211_registered_device *rdev,
318 struct net_device *dev, u16 reason,
319 bool wextev);
320int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
321 struct net_device *dev, u16 reason,
322 bool wextev);
323void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid,
324 const u8 *req_ie, size_t req_ie_len,
325 const u8 *resp_ie, size_t resp_ie_len);
326
327void cfg80211_conn_work(struct work_struct *work);
172 328
173/* internal helpers */ 329/* internal helpers */
174int cfg80211_validate_key_settings(struct key_params *params, int key_idx, 330int cfg80211_validate_key_settings(struct key_params *params, int key_idx,
175 const u8 *mac_addr); 331 const u8 *mac_addr);
332void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
333 size_t ie_len, u16 reason, bool from_ap);
334void cfg80211_sme_scan_done(struct net_device *dev);
335void cfg80211_sme_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
336void cfg80211_sme_disassoc(struct net_device *dev, int idx);
337void __cfg80211_scan_done(struct work_struct *wk);
176 338
177#endif /* __NET_WIRELESS_CORE_H */ 339#endif /* __NET_WIRELESS_CORE_H */
diff --git a/net/wireless/debugfs.c b/net/wireless/debugfs.c
index 679ddfcec1ee..13d93d84f902 100644
--- a/net/wireless/debugfs.c
+++ b/net/wireless/debugfs.c
@@ -104,15 +104,15 @@ static const struct file_operations ht40allow_map_ops = {
104}; 104};
105 105
106#define DEBUGFS_ADD(name) \ 106#define DEBUGFS_ADD(name) \
107 drv->debugfs.name = debugfs_create_file(#name, S_IRUGO, phyd, \ 107 rdev->debugfs.name = debugfs_create_file(#name, S_IRUGO, phyd, \
108 &drv->wiphy, &name## _ops); 108 &rdev->wiphy, &name## _ops);
109#define DEBUGFS_DEL(name) \ 109#define DEBUGFS_DEL(name) \
110 debugfs_remove(drv->debugfs.name); \ 110 debugfs_remove(rdev->debugfs.name); \
111 drv->debugfs.name = NULL; 111 rdev->debugfs.name = NULL;
112 112
113void cfg80211_debugfs_drv_add(struct cfg80211_registered_device *drv) 113void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev)
114{ 114{
115 struct dentry *phyd = drv->wiphy.debugfsdir; 115 struct dentry *phyd = rdev->wiphy.debugfsdir;
116 116
117 DEBUGFS_ADD(rts_threshold); 117 DEBUGFS_ADD(rts_threshold);
118 DEBUGFS_ADD(fragmentation_threshold); 118 DEBUGFS_ADD(fragmentation_threshold);
@@ -121,7 +121,7 @@ void cfg80211_debugfs_drv_add(struct cfg80211_registered_device *drv)
121 DEBUGFS_ADD(ht40allow_map); 121 DEBUGFS_ADD(ht40allow_map);
122} 122}
123 123
124void cfg80211_debugfs_drv_del(struct cfg80211_registered_device *drv) 124void cfg80211_debugfs_rdev_del(struct cfg80211_registered_device *rdev)
125{ 125{
126 DEBUGFS_DEL(rts_threshold); 126 DEBUGFS_DEL(rts_threshold);
127 DEBUGFS_DEL(fragmentation_threshold); 127 DEBUGFS_DEL(fragmentation_threshold);
diff --git a/net/wireless/debugfs.h b/net/wireless/debugfs.h
index c226983ae66b..6419b6d6ce3e 100644
--- a/net/wireless/debugfs.h
+++ b/net/wireless/debugfs.h
@@ -2,13 +2,13 @@
2#define __CFG80211_DEBUGFS_H 2#define __CFG80211_DEBUGFS_H
3 3
4#ifdef CONFIG_CFG80211_DEBUGFS 4#ifdef CONFIG_CFG80211_DEBUGFS
5void cfg80211_debugfs_drv_add(struct cfg80211_registered_device *drv); 5void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev);
6void cfg80211_debugfs_drv_del(struct cfg80211_registered_device *drv); 6void cfg80211_debugfs_rdev_del(struct cfg80211_registered_device *rdev);
7#else 7#else
8static inline 8static inline
9void cfg80211_debugfs_drv_add(struct cfg80211_registered_device *drv) {} 9void cfg80211_debugfs_rdev_add(struct cfg80211_registered_device *rdev) {}
10static inline 10static inline
11void cfg80211_debugfs_drv_del(struct cfg80211_registered_device *drv) {} 11void cfg80211_debugfs_rdev_del(struct cfg80211_registered_device *rdev) {}
12#endif 12#endif
13 13
14#endif /* __CFG80211_DEBUGFS_H */ 14#endif /* __CFG80211_DEBUGFS_H */
diff --git a/net/wireless/ibss.c b/net/wireless/ibss.c
index a4a1c3498ff2..99ef9364b7e8 100644
--- a/net/wireless/ibss.c
+++ b/net/wireless/ibss.c
@@ -10,7 +10,7 @@
10#include "nl80211.h" 10#include "nl80211.h"
11 11
12 12
13void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp) 13void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid)
14{ 14{
15 struct wireless_dev *wdev = dev->ieee80211_ptr; 15 struct wireless_dev *wdev = dev->ieee80211_ptr;
16 struct cfg80211_bss *bss; 16 struct cfg80211_bss *bss;
@@ -24,9 +24,6 @@ void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp)
24 if (WARN_ON(!wdev->ssid_len)) 24 if (WARN_ON(!wdev->ssid_len))
25 return; 25 return;
26 26
27 if (memcmp(bssid, wdev->bssid, ETH_ALEN) == 0)
28 return;
29
30 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, 27 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
31 wdev->ssid, wdev->ssid_len, 28 wdev->ssid, wdev->ssid_len,
32 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS); 29 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
@@ -36,29 +33,51 @@ void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp)
36 33
37 if (wdev->current_bss) { 34 if (wdev->current_bss) {
38 cfg80211_unhold_bss(wdev->current_bss); 35 cfg80211_unhold_bss(wdev->current_bss);
39 cfg80211_put_bss(wdev->current_bss); 36 cfg80211_put_bss(&wdev->current_bss->pub);
40 } 37 }
41 38
42 cfg80211_hold_bss(bss); 39 cfg80211_hold_bss(bss_from_pub(bss));
43 wdev->current_bss = bss; 40 wdev->current_bss = bss_from_pub(bss);
44 memcpy(wdev->bssid, bssid, ETH_ALEN);
45 41
46 nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid, gfp); 42 nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid,
43 GFP_KERNEL);
47#ifdef CONFIG_WIRELESS_EXT 44#ifdef CONFIG_WIRELESS_EXT
48 memset(&wrqu, 0, sizeof(wrqu)); 45 memset(&wrqu, 0, sizeof(wrqu));
49 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); 46 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
50 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); 47 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
51#endif 48#endif
52} 49}
50
51void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp)
52{
53 struct wireless_dev *wdev = dev->ieee80211_ptr;
54 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
55 struct cfg80211_event *ev;
56 unsigned long flags;
57
58 ev = kzalloc(sizeof(*ev), gfp);
59 if (!ev)
60 return;
61
62 ev->type = EVENT_IBSS_JOINED;
63 memcpy(ev->cr.bssid, bssid, ETH_ALEN);
64
65 spin_lock_irqsave(&wdev->event_lock, flags);
66 list_add_tail(&ev->list, &wdev->event_list);
67 spin_unlock_irqrestore(&wdev->event_lock, flags);
68 schedule_work(&rdev->event_work);
69}
53EXPORT_SYMBOL(cfg80211_ibss_joined); 70EXPORT_SYMBOL(cfg80211_ibss_joined);
54 71
55int cfg80211_join_ibss(struct cfg80211_registered_device *rdev, 72int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
56 struct net_device *dev, 73 struct net_device *dev,
57 struct cfg80211_ibss_params *params) 74 struct cfg80211_ibss_params *params)
58{ 75{
59 struct wireless_dev *wdev = dev->ieee80211_ptr; 76 struct wireless_dev *wdev = dev->ieee80211_ptr;
60 int err; 77 int err;
61 78
79 ASSERT_WDEV_LOCK(wdev);
80
62 if (wdev->ssid_len) 81 if (wdev->ssid_len)
63 return -EALREADY; 82 return -EALREADY;
64 83
@@ -76,39 +95,82 @@ int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
76 return 0; 95 return 0;
77} 96}
78 97
79void cfg80211_clear_ibss(struct net_device *dev, bool nowext) 98int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
99 struct net_device *dev,
100 struct cfg80211_ibss_params *params)
101{
102 struct wireless_dev *wdev = dev->ieee80211_ptr;
103 int err;
104
105 wdev_lock(wdev);
106 err = __cfg80211_join_ibss(rdev, dev, params);
107 wdev_unlock(wdev);
108
109 return err;
110}
111
112static void __cfg80211_clear_ibss(struct net_device *dev, bool nowext)
80{ 113{
81 struct wireless_dev *wdev = dev->ieee80211_ptr; 114 struct wireless_dev *wdev = dev->ieee80211_ptr;
82 115
116 ASSERT_WDEV_LOCK(wdev);
117
83 if (wdev->current_bss) { 118 if (wdev->current_bss) {
84 cfg80211_unhold_bss(wdev->current_bss); 119 cfg80211_unhold_bss(wdev->current_bss);
85 cfg80211_put_bss(wdev->current_bss); 120 cfg80211_put_bss(&wdev->current_bss->pub);
86 } 121 }
87 122
88 wdev->current_bss = NULL; 123 wdev->current_bss = NULL;
89 wdev->ssid_len = 0; 124 wdev->ssid_len = 0;
90 memset(wdev->bssid, 0, ETH_ALEN);
91#ifdef CONFIG_WIRELESS_EXT 125#ifdef CONFIG_WIRELESS_EXT
92 if (!nowext) 126 if (!nowext)
93 wdev->wext.ibss.ssid_len = 0; 127 wdev->wext.ibss.ssid_len = 0;
94#endif 128#endif
95} 129}
96 130
97int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev, 131void cfg80211_clear_ibss(struct net_device *dev, bool nowext)
98 struct net_device *dev, bool nowext)
99{ 132{
133 struct wireless_dev *wdev = dev->ieee80211_ptr;
134
135 wdev_lock(wdev);
136 __cfg80211_clear_ibss(dev, nowext);
137 wdev_unlock(wdev);
138}
139
140static int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
141 struct net_device *dev, bool nowext)
142{
143 struct wireless_dev *wdev = dev->ieee80211_ptr;
100 int err; 144 int err;
101 145
146 ASSERT_WDEV_LOCK(wdev);
147
148 if (!wdev->ssid_len)
149 return -ENOLINK;
150
102 err = rdev->ops->leave_ibss(&rdev->wiphy, dev); 151 err = rdev->ops->leave_ibss(&rdev->wiphy, dev);
103 152
104 if (err) 153 if (err)
105 return err; 154 return err;
106 155
107 cfg80211_clear_ibss(dev, nowext); 156 __cfg80211_clear_ibss(dev, nowext);
108 157
109 return 0; 158 return 0;
110} 159}
111 160
161int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
162 struct net_device *dev, bool nowext)
163{
164 struct wireless_dev *wdev = dev->ieee80211_ptr;
165 int err;
166
167 wdev_lock(wdev);
168 err = __cfg80211_leave_ibss(rdev, dev, nowext);
169 wdev_unlock(wdev);
170
171 return err;
172}
173
112#ifdef CONFIG_WIRELESS_EXT 174#ifdef CONFIG_WIRELESS_EXT
113static int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev, 175static int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
114 struct wireless_dev *wdev) 176 struct wireless_dev *wdev)
@@ -185,12 +247,15 @@ int cfg80211_ibss_wext_siwfreq(struct net_device *dev,
185 if (wdev->wext.ibss.channel == chan) 247 if (wdev->wext.ibss.channel == chan)
186 return 0; 248 return 0;
187 249
188 if (wdev->ssid_len) { 250 wdev_lock(wdev);
189 err = cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy), 251 err = 0;
190 dev, true); 252 if (wdev->ssid_len)
191 if (err) 253 err = __cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy),
192 return err; 254 dev, true);
193 } 255 wdev_unlock(wdev);
256
257 if (err)
258 return err;
194 259
195 if (chan) { 260 if (chan) {
196 wdev->wext.ibss.channel = chan; 261 wdev->wext.ibss.channel = chan;
@@ -216,10 +281,12 @@ int cfg80211_ibss_wext_giwfreq(struct net_device *dev,
216 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) 281 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
217 return -EINVAL; 282 return -EINVAL;
218 283
284 wdev_lock(wdev);
219 if (wdev->current_bss) 285 if (wdev->current_bss)
220 chan = wdev->current_bss->channel; 286 chan = wdev->current_bss->pub.channel;
221 else if (wdev->wext.ibss.channel) 287 else if (wdev->wext.ibss.channel)
222 chan = wdev->wext.ibss.channel; 288 chan = wdev->wext.ibss.channel;
289 wdev_unlock(wdev);
223 290
224 if (chan) { 291 if (chan) {
225 freq->m = chan->center_freq; 292 freq->m = chan->center_freq;
@@ -248,12 +315,15 @@ int cfg80211_ibss_wext_siwessid(struct net_device *dev,
248 if (!wiphy_to_dev(wdev->wiphy)->ops->join_ibss) 315 if (!wiphy_to_dev(wdev->wiphy)->ops->join_ibss)
249 return -EOPNOTSUPP; 316 return -EOPNOTSUPP;
250 317
251 if (wdev->ssid_len) { 318 wdev_lock(wdev);
252 err = cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy), 319 err = 0;
253 dev, true); 320 if (wdev->ssid_len)
254 if (err) 321 err = __cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy),
255 return err; 322 dev, true);
256 } 323 wdev_unlock(wdev);
324
325 if (err)
326 return err;
257 327
258 /* iwconfig uses nul termination in SSID.. */ 328 /* iwconfig uses nul termination in SSID.. */
259 if (len > 0 && ssid[len - 1] == '\0') 329 if (len > 0 && ssid[len - 1] == '\0')
@@ -280,6 +350,7 @@ int cfg80211_ibss_wext_giwessid(struct net_device *dev,
280 350
281 data->flags = 0; 351 data->flags = 0;
282 352
353 wdev_lock(wdev);
283 if (wdev->ssid_len) { 354 if (wdev->ssid_len) {
284 data->flags = 1; 355 data->flags = 1;
285 data->length = wdev->ssid_len; 356 data->length = wdev->ssid_len;
@@ -289,6 +360,7 @@ int cfg80211_ibss_wext_giwessid(struct net_device *dev,
289 data->length = wdev->wext.ibss.ssid_len; 360 data->length = wdev->wext.ibss.ssid_len;
290 memcpy(ssid, wdev->wext.ibss.ssid, data->length); 361 memcpy(ssid, wdev->wext.ibss.ssid, data->length);
291 } 362 }
363 wdev_unlock(wdev);
292 364
293 return 0; 365 return 0;
294} 366}
@@ -326,12 +398,15 @@ int cfg80211_ibss_wext_siwap(struct net_device *dev,
326 compare_ether_addr(bssid, wdev->wext.ibss.bssid) == 0) 398 compare_ether_addr(bssid, wdev->wext.ibss.bssid) == 0)
327 return 0; 399 return 0;
328 400
329 if (wdev->ssid_len) { 401 wdev_lock(wdev);
330 err = cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy), 402 err = 0;
331 dev, true); 403 if (wdev->ssid_len)
332 if (err) 404 err = __cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy),
333 return err; 405 dev, true);
334 } 406 wdev_unlock(wdev);
407
408 if (err)
409 return err;
335 410
336 if (bssid) { 411 if (bssid) {
337 memcpy(wdev->wext.bssid, bssid, ETH_ALEN); 412 memcpy(wdev->wext.bssid, bssid, ETH_ALEN);
@@ -356,12 +431,13 @@ int cfg80211_ibss_wext_giwap(struct net_device *dev,
356 431
357 ap_addr->sa_family = ARPHRD_ETHER; 432 ap_addr->sa_family = ARPHRD_ETHER;
358 433
359 if (wdev->wext.ibss.bssid) { 434 wdev_lock(wdev);
435 if (wdev->current_bss)
436 memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN);
437 else
360 memcpy(ap_addr->sa_data, wdev->wext.ibss.bssid, ETH_ALEN); 438 memcpy(ap_addr->sa_data, wdev->wext.ibss.bssid, ETH_ALEN);
361 return 0; 439 wdev_unlock(wdev);
362 }
363 440
364 memcpy(ap_addr->sa_data, wdev->bssid, ETH_ALEN);
365 return 0; 441 return 0;
366} 442}
367/* temporary symbol - mark GPL - in the future the handler won't be */ 443/* temporary symbol - mark GPL - in the future the handler won't be */
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
index 42184361a109..1b2ca1fea7a1 100644
--- a/net/wireless/mlme.c
+++ b/net/wireless/mlme.c
@@ -14,69 +14,600 @@
14 14
15void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len) 15void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len)
16{ 16{
17 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 17 struct wireless_dev *wdev = dev->ieee80211_ptr;
18 struct wiphy *wiphy = wdev->wiphy;
18 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 19 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
19 nl80211_send_rx_auth(rdev, dev, buf, len); 20 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
21 u8 *bssid = mgmt->bssid;
22 int i;
23 u16 status = le16_to_cpu(mgmt->u.auth.status_code);
24 bool done = false;
25
26 wdev_lock(wdev);
27
28 for (i = 0; i < MAX_AUTH_BSSES; i++) {
29 if (wdev->authtry_bsses[i] &&
30 memcmp(wdev->authtry_bsses[i]->pub.bssid, bssid,
31 ETH_ALEN) == 0) {
32 if (status == WLAN_STATUS_SUCCESS) {
33 wdev->auth_bsses[i] = wdev->authtry_bsses[i];
34 } else {
35 cfg80211_unhold_bss(wdev->authtry_bsses[i]);
36 cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
37 }
38 wdev->authtry_bsses[i] = NULL;
39 done = true;
40 break;
41 }
42 }
43
44 WARN_ON(!done);
45
46 nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL);
47 cfg80211_sme_rx_auth(dev, buf, len);
48
49 wdev_unlock(wdev);
20} 50}
21EXPORT_SYMBOL(cfg80211_send_rx_auth); 51EXPORT_SYMBOL(cfg80211_send_rx_auth);
22 52
23void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len) 53void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len)
24{ 54{
25 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 55 u16 status_code;
56 struct wireless_dev *wdev = dev->ieee80211_ptr;
57 struct wiphy *wiphy = wdev->wiphy;
26 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 58 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
27 nl80211_send_rx_assoc(rdev, dev, buf, len); 59 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
60 u8 *ie = mgmt->u.assoc_resp.variable;
61 int i, ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
62 bool done;
63
64 wdev_lock(wdev);
65
66 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
67
68 nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL);
69
70 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs,
71 status_code,
72 status_code == WLAN_STATUS_SUCCESS);
73
74 if (status_code == WLAN_STATUS_SUCCESS) {
75 for (i = 0; wdev->current_bss && i < MAX_AUTH_BSSES; i++) {
76 if (wdev->auth_bsses[i] == wdev->current_bss) {
77 cfg80211_unhold_bss(wdev->auth_bsses[i]);
78 cfg80211_put_bss(&wdev->auth_bsses[i]->pub);
79 wdev->auth_bsses[i] = NULL;
80 done = true;
81 break;
82 }
83 }
84
85 WARN_ON(!done);
86 }
87
88 wdev_unlock(wdev);
28} 89}
29EXPORT_SYMBOL(cfg80211_send_rx_assoc); 90EXPORT_SYMBOL(cfg80211_send_rx_assoc);
30 91
31void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len) 92static void __cfg80211_send_deauth(struct net_device *dev,
93 const u8 *buf, size_t len)
32{ 94{
33 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 95 struct wireless_dev *wdev = dev->ieee80211_ptr;
96 struct wiphy *wiphy = wdev->wiphy;
34 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 97 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
35 nl80211_send_deauth(rdev, dev, buf, len); 98 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
99 const u8 *bssid = mgmt->bssid;
100 int i;
101 bool done = false;
102
103 ASSERT_WDEV_LOCK(wdev);
104
105 nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
106
107 if (wdev->current_bss &&
108 memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) {
109 done = true;
110 cfg80211_unhold_bss(wdev->current_bss);
111 cfg80211_put_bss(&wdev->current_bss->pub);
112 wdev->current_bss = NULL;
113 } else for (i = 0; i < MAX_AUTH_BSSES; i++) {
114 if (wdev->auth_bsses[i] &&
115 memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) {
116 cfg80211_unhold_bss(wdev->auth_bsses[i]);
117 cfg80211_put_bss(&wdev->auth_bsses[i]->pub);
118 wdev->auth_bsses[i] = NULL;
119 done = true;
120 break;
121 }
122 if (wdev->authtry_bsses[i] &&
123 memcmp(wdev->authtry_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) {
124 cfg80211_unhold_bss(wdev->authtry_bsses[i]);
125 cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
126 wdev->authtry_bsses[i] = NULL;
127 done = true;
128 break;
129 }
130 }
131
132 WARN_ON(!done);
133
134 if (wdev->sme_state == CFG80211_SME_CONNECTED) {
135 u16 reason_code;
136 bool from_ap;
137
138 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
139
140 from_ap = memcmp(mgmt->da, dev->dev_addr, ETH_ALEN) == 0;
141 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
142 } else if (wdev->sme_state == CFG80211_SME_CONNECTING) {
143 __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0,
144 WLAN_STATUS_UNSPECIFIED_FAILURE,
145 false);
146 }
147}
148
149
150void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len,
151 void *cookie)
152{
153 struct wireless_dev *wdev = dev->ieee80211_ptr;
154
155 BUG_ON(cookie && wdev != cookie);
156
157 if (cookie) {
158 /* called within callback */
159 __cfg80211_send_deauth(dev, buf, len);
160 } else {
161 wdev_lock(wdev);
162 __cfg80211_send_deauth(dev, buf, len);
163 wdev_unlock(wdev);
164 }
36} 165}
37EXPORT_SYMBOL(cfg80211_send_deauth); 166EXPORT_SYMBOL(cfg80211_send_deauth);
38 167
39void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len) 168static void __cfg80211_send_disassoc(struct net_device *dev,
169 const u8 *buf, size_t len)
40{ 170{
41 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 171 struct wireless_dev *wdev = dev->ieee80211_ptr;
172 struct wiphy *wiphy = wdev->wiphy;
42 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 173 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
43 nl80211_send_disassoc(rdev, dev, buf, len); 174 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
175 const u8 *bssid = mgmt->bssid;
176 int i;
177 u16 reason_code;
178 bool from_ap;
179 bool done = false;
180
181 wdev_lock(wdev);
182
183 nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL);
184
185 if (!wdev->sme_state == CFG80211_SME_CONNECTED)
186 goto out;
187
188 if (wdev->current_bss &&
189 memcmp(wdev->current_bss, bssid, ETH_ALEN) == 0) {
190 for (i = 0; i < MAX_AUTH_BSSES; i++) {
191 if (wdev->authtry_bsses[i] || wdev->auth_bsses[i])
192 continue;
193 wdev->auth_bsses[i] = wdev->current_bss;
194 wdev->current_bss = NULL;
195 done = true;
196 cfg80211_sme_disassoc(dev, i);
197 break;
198 }
199 WARN_ON(!done);
200 } else
201 WARN_ON(1);
202
203
204 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
205
206 from_ap = memcmp(mgmt->da, dev->dev_addr, ETH_ALEN) == 0;
207 __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
208 out:
209 wdev_unlock(wdev);
44} 210}
45EXPORT_SYMBOL(cfg80211_send_disassoc);
46 211
47static void cfg80211_wext_disconnected(struct net_device *dev) 212void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len,
213 void *cookie)
48{ 214{
49#ifdef CONFIG_WIRELESS_EXT 215 struct wireless_dev *wdev = dev->ieee80211_ptr;
50 union iwreq_data wrqu; 216
51 memset(&wrqu, 0, sizeof(wrqu)); 217 BUG_ON(cookie && wdev != cookie);
52 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); 218
53#endif 219 if (cookie) {
220 /* called within callback */
221 __cfg80211_send_disassoc(dev, buf, len);
222 } else {
223 wdev_lock(wdev);
224 __cfg80211_send_disassoc(dev, buf, len);
225 wdev_unlock(wdev);
226 }
54} 227}
228EXPORT_SYMBOL(cfg80211_send_disassoc);
55 229
56void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr) 230void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr)
57{ 231{
58 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 232 struct wireless_dev *wdev = dev->ieee80211_ptr;
233 struct wiphy *wiphy = wdev->wiphy;
59 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 234 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
60 nl80211_send_auth_timeout(rdev, dev, addr); 235 int i;
61 cfg80211_wext_disconnected(dev); 236 bool done = false;
237
238 wdev_lock(wdev);
239
240 nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
241 if (wdev->sme_state == CFG80211_SME_CONNECTING)
242 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
243 WLAN_STATUS_UNSPECIFIED_FAILURE,
244 false);
245
246 for (i = 0; addr && i < MAX_AUTH_BSSES; i++) {
247 if (wdev->authtry_bsses[i] &&
248 memcmp(wdev->authtry_bsses[i]->pub.bssid,
249 addr, ETH_ALEN) == 0) {
250 cfg80211_unhold_bss(wdev->authtry_bsses[i]);
251 cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
252 wdev->authtry_bsses[i] = NULL;
253 done = true;
254 break;
255 }
256 }
257
258 WARN_ON(!done);
259
260 wdev_unlock(wdev);
62} 261}
63EXPORT_SYMBOL(cfg80211_send_auth_timeout); 262EXPORT_SYMBOL(cfg80211_send_auth_timeout);
64 263
65void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr) 264void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr)
66{ 265{
67 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 266 struct wireless_dev *wdev = dev->ieee80211_ptr;
267 struct wiphy *wiphy = wdev->wiphy;
68 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 268 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
69 nl80211_send_assoc_timeout(rdev, dev, addr); 269 int i;
70 cfg80211_wext_disconnected(dev); 270 bool done = false;
271
272 wdev_lock(wdev);
273
274 nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL);
275 if (wdev->sme_state == CFG80211_SME_CONNECTING)
276 __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
277 WLAN_STATUS_UNSPECIFIED_FAILURE,
278 false);
279
280 for (i = 0; addr && i < MAX_AUTH_BSSES; i++) {
281 if (wdev->auth_bsses[i] &&
282 memcmp(wdev->auth_bsses[i]->pub.bssid,
283 addr, ETH_ALEN) == 0) {
284 cfg80211_unhold_bss(wdev->auth_bsses[i]);
285 cfg80211_put_bss(&wdev->auth_bsses[i]->pub);
286 wdev->auth_bsses[i] = NULL;
287 done = true;
288 break;
289 }
290 }
291
292 WARN_ON(!done);
293
294 wdev_unlock(wdev);
71} 295}
72EXPORT_SYMBOL(cfg80211_send_assoc_timeout); 296EXPORT_SYMBOL(cfg80211_send_assoc_timeout);
73 297
74void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr, 298void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
75 enum nl80211_key_type key_type, int key_id, 299 enum nl80211_key_type key_type, int key_id,
76 const u8 *tsc) 300 const u8 *tsc, gfp_t gfp)
77{ 301{
78 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 302 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
79 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 303 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
80 nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc); 304#ifdef CONFIG_WIRELESS_EXT
305 union iwreq_data wrqu;
306 char *buf = kmalloc(128, gfp);
307
308 if (buf) {
309 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
310 "keyid=%d %scast addr=%pM)", key_id,
311 key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni",
312 addr);
313 memset(&wrqu, 0, sizeof(wrqu));
314 wrqu.data.length = strlen(buf);
315 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
316 kfree(buf);
317 }
318#endif
319
320 nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp);
81} 321}
82EXPORT_SYMBOL(cfg80211_michael_mic_failure); 322EXPORT_SYMBOL(cfg80211_michael_mic_failure);
323
324/* some MLME handling for userspace SME */
325int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
326 struct net_device *dev,
327 struct ieee80211_channel *chan,
328 enum nl80211_auth_type auth_type,
329 const u8 *bssid,
330 const u8 *ssid, int ssid_len,
331 const u8 *ie, int ie_len)
332{
333 struct wireless_dev *wdev = dev->ieee80211_ptr;
334 struct cfg80211_auth_request req;
335 struct cfg80211_internal_bss *bss;
336 int i, err, slot = -1, nfree = 0;
337
338 ASSERT_WDEV_LOCK(wdev);
339
340 if (wdev->current_bss &&
341 memcmp(bssid, wdev->current_bss->pub.bssid, ETH_ALEN) == 0)
342 return -EALREADY;
343
344 for (i = 0; i < MAX_AUTH_BSSES; i++) {
345 if (wdev->authtry_bsses[i] &&
346 memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid,
347 ETH_ALEN) == 0)
348 return -EALREADY;
349 if (wdev->auth_bsses[i] &&
350 memcmp(bssid, wdev->auth_bsses[i]->pub.bssid,
351 ETH_ALEN) == 0)
352 return -EALREADY;
353 }
354
355 memset(&req, 0, sizeof(req));
356
357 req.ie = ie;
358 req.ie_len = ie_len;
359 req.auth_type = auth_type;
360 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
361 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
362 if (!req.bss)
363 return -ENOENT;
364
365 bss = bss_from_pub(req.bss);
366
367 for (i = 0; i < MAX_AUTH_BSSES; i++) {
368 if (!wdev->auth_bsses[i] && !wdev->authtry_bsses[i]) {
369 slot = i;
370 nfree++;
371 }
372 }
373
374 /* we need one free slot for disassoc and one for this auth */
375 if (nfree < 2) {
376 err = -ENOSPC;
377 goto out;
378 }
379
380 wdev->authtry_bsses[slot] = bss;
381 cfg80211_hold_bss(bss);
382
383 err = rdev->ops->auth(&rdev->wiphy, dev, &req);
384 if (err) {
385 wdev->authtry_bsses[slot] = NULL;
386 cfg80211_unhold_bss(bss);
387 }
388
389 out:
390 if (err)
391 cfg80211_put_bss(req.bss);
392 return err;
393}
394
395int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
396 struct net_device *dev, struct ieee80211_channel *chan,
397 enum nl80211_auth_type auth_type, const u8 *bssid,
398 const u8 *ssid, int ssid_len,
399 const u8 *ie, int ie_len)
400{
401 int err;
402
403 wdev_lock(dev->ieee80211_ptr);
404 err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
405 ssid, ssid_len, ie, ie_len);
406 wdev_unlock(dev->ieee80211_ptr);
407
408 return err;
409}
410
411int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
412 struct net_device *dev,
413 struct ieee80211_channel *chan,
414 const u8 *bssid, const u8 *prev_bssid,
415 const u8 *ssid, int ssid_len,
416 const u8 *ie, int ie_len, bool use_mfp,
417 struct cfg80211_crypto_settings *crypt)
418{
419 struct wireless_dev *wdev = dev->ieee80211_ptr;
420 struct cfg80211_assoc_request req;
421 struct cfg80211_internal_bss *bss;
422 int i, err, slot = -1;
423
424 ASSERT_WDEV_LOCK(wdev);
425
426 memset(&req, 0, sizeof(req));
427
428 if (wdev->current_bss)
429 return -EALREADY;
430
431 req.ie = ie;
432 req.ie_len = ie_len;
433 memcpy(&req.crypto, crypt, sizeof(req.crypto));
434 req.use_mfp = use_mfp;
435 req.prev_bssid = prev_bssid;
436 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
437 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
438 if (!req.bss)
439 return -ENOENT;
440
441 bss = bss_from_pub(req.bss);
442
443 for (i = 0; i < MAX_AUTH_BSSES; i++) {
444 if (bss == wdev->auth_bsses[i]) {
445 slot = i;
446 break;
447 }
448 }
449
450 if (slot < 0) {
451 err = -ENOTCONN;
452 goto out;
453 }
454
455 err = rdev->ops->assoc(&rdev->wiphy, dev, &req);
456 out:
457 /* still a reference in wdev->auth_bsses[slot] */
458 cfg80211_put_bss(req.bss);
459 return err;
460}
461
462int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
463 struct net_device *dev,
464 struct ieee80211_channel *chan,
465 const u8 *bssid, const u8 *prev_bssid,
466 const u8 *ssid, int ssid_len,
467 const u8 *ie, int ie_len, bool use_mfp,
468 struct cfg80211_crypto_settings *crypt)
469{
470 struct wireless_dev *wdev = dev->ieee80211_ptr;
471 int err;
472
473 wdev_lock(wdev);
474 err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
475 ssid, ssid_len, ie, ie_len, use_mfp, crypt);
476 wdev_unlock(wdev);
477
478 return err;
479}
480
481int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
482 struct net_device *dev, const u8 *bssid,
483 const u8 *ie, int ie_len, u16 reason)
484{
485 struct wireless_dev *wdev = dev->ieee80211_ptr;
486 struct cfg80211_deauth_request req;
487 int i;
488
489 ASSERT_WDEV_LOCK(wdev);
490
491 memset(&req, 0, sizeof(req));
492 req.reason_code = reason;
493 req.ie = ie;
494 req.ie_len = ie_len;
495 if (wdev->current_bss &&
496 memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) {
497 req.bss = &wdev->current_bss->pub;
498 } else for (i = 0; i < MAX_AUTH_BSSES; i++) {
499 if (wdev->auth_bsses[i] &&
500 memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, ETH_ALEN) == 0) {
501 req.bss = &wdev->auth_bsses[i]->pub;
502 break;
503 }
504 if (wdev->authtry_bsses[i] &&
505 memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, ETH_ALEN) == 0) {
506 req.bss = &wdev->authtry_bsses[i]->pub;
507 break;
508 }
509 }
510
511 if (!req.bss)
512 return -ENOTCONN;
513
514 return rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
515}
516
517int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
518 struct net_device *dev, const u8 *bssid,
519 const u8 *ie, int ie_len, u16 reason)
520{
521 struct wireless_dev *wdev = dev->ieee80211_ptr;
522 int err;
523
524 wdev_lock(wdev);
525 err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason);
526 wdev_unlock(wdev);
527
528 return err;
529}
530
531static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
532 struct net_device *dev, const u8 *bssid,
533 const u8 *ie, int ie_len, u16 reason)
534{
535 struct wireless_dev *wdev = dev->ieee80211_ptr;
536 struct cfg80211_disassoc_request req;
537
538 ASSERT_WDEV_LOCK(wdev);
539
540 memset(&req, 0, sizeof(req));
541 req.reason_code = reason;
542 req.ie = ie;
543 req.ie_len = ie_len;
544 if (memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0)
545 req.bss = &wdev->current_bss->pub;
546 else
547 return -ENOTCONN;
548
549 return rdev->ops->disassoc(&rdev->wiphy, dev, &req, wdev);
550}
551
552int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
553 struct net_device *dev, const u8 *bssid,
554 const u8 *ie, int ie_len, u16 reason)
555{
556 struct wireless_dev *wdev = dev->ieee80211_ptr;
557 int err;
558
559 wdev_lock(wdev);
560 err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason);
561 wdev_unlock(wdev);
562
563 return err;
564}
565
566void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
567 struct net_device *dev)
568{
569 struct wireless_dev *wdev = dev->ieee80211_ptr;
570 struct cfg80211_deauth_request req;
571 int i;
572
573 ASSERT_WDEV_LOCK(wdev);
574
575 if (!rdev->ops->deauth)
576 return;
577
578 memset(&req, 0, sizeof(req));
579 req.reason_code = WLAN_REASON_DEAUTH_LEAVING;
580 req.ie = NULL;
581 req.ie_len = 0;
582
583 if (wdev->current_bss) {
584 req.bss = &wdev->current_bss->pub;
585 rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
586 if (wdev->current_bss) {
587 cfg80211_unhold_bss(wdev->current_bss);
588 cfg80211_put_bss(&wdev->current_bss->pub);
589 wdev->current_bss = NULL;
590 }
591 }
592
593 for (i = 0; i < MAX_AUTH_BSSES; i++) {
594 if (wdev->auth_bsses[i]) {
595 req.bss = &wdev->auth_bsses[i]->pub;
596 rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
597 if (wdev->auth_bsses[i]) {
598 cfg80211_unhold_bss(wdev->auth_bsses[i]);
599 cfg80211_put_bss(&wdev->auth_bsses[i]->pub);
600 wdev->auth_bsses[i] = NULL;
601 }
602 }
603 if (wdev->authtry_bsses[i]) {
604 req.bss = &wdev->authtry_bsses[i]->pub;
605 rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
606 if (wdev->authtry_bsses[i]) {
607 cfg80211_unhold_bss(wdev->authtry_bsses[i]);
608 cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
609 wdev->authtry_bsses[i] = NULL;
610 }
611 }
612 }
613}
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 43bdb1372cae..2a04beba4369 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -29,9 +29,9 @@ static struct genl_family nl80211_fam = {
29 .maxattr = NL80211_ATTR_MAX, 29 .maxattr = NL80211_ATTR_MAX,
30}; 30};
31 31
32/* internal helper: get drv and dev */ 32/* internal helper: get rdev and dev */
33static int get_drv_dev_by_info_ifindex(struct nlattr **attrs, 33static int get_rdev_dev_by_info_ifindex(struct nlattr **attrs,
34 struct cfg80211_registered_device **drv, 34 struct cfg80211_registered_device **rdev,
35 struct net_device **dev) 35 struct net_device **dev)
36{ 36{
37 int ifindex; 37 int ifindex;
@@ -44,10 +44,10 @@ static int get_drv_dev_by_info_ifindex(struct nlattr **attrs,
44 if (!*dev) 44 if (!*dev)
45 return -ENODEV; 45 return -ENODEV;
46 46
47 *drv = cfg80211_get_dev_from_ifindex(ifindex); 47 *rdev = cfg80211_get_dev_from_ifindex(ifindex);
48 if (IS_ERR(*drv)) { 48 if (IS_ERR(*rdev)) {
49 dev_put(*dev); 49 dev_put(*dev);
50 return PTR_ERR(*drv); 50 return PTR_ERR(*rdev);
51 } 51 }
52 52
53 return 0; 53 return 0;
@@ -71,6 +71,7 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
71 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, 71 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
72 72
73 [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, 73 [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN },
74 [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN },
74 75
75 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, 76 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
76 .len = WLAN_MAX_KEY_LEN }, 77 .len = WLAN_MAX_KEY_LEN },
@@ -128,6 +129,9 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
128 .len = sizeof(struct nl80211_sta_flag_update), 129 .len = sizeof(struct nl80211_sta_flag_update),
129 }, 130 },
130 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, 131 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
132 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
133 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
134 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
131}; 135};
132 136
133/* IE validation */ 137/* IE validation */
@@ -347,6 +351,17 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
347 CMD(join_ibss, JOIN_IBSS); 351 CMD(join_ibss, JOIN_IBSS);
348 352
349#undef CMD 353#undef CMD
354
355 if (dev->ops->connect || dev->ops->auth) {
356 i++;
357 NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
358 }
359
360 if (dev->ops->disconnect || dev->ops->deauth) {
361 i++;
362 NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
363 }
364
350 nla_nest_end(msg, nl_cmds); 365 nla_nest_end(msg, nl_cmds);
351 366
352 return genlmsg_end(msg, hdr); 367 return genlmsg_end(msg, hdr);
@@ -363,7 +378,7 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
363 struct cfg80211_registered_device *dev; 378 struct cfg80211_registered_device *dev;
364 379
365 mutex_lock(&cfg80211_mutex); 380 mutex_lock(&cfg80211_mutex);
366 list_for_each_entry(dev, &cfg80211_drv_list, list) { 381 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
367 if (++idx <= start) 382 if (++idx <= start)
368 continue; 383 continue;
369 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, 384 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
@@ -396,14 +411,14 @@ static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
396 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) 411 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0)
397 goto out_free; 412 goto out_free;
398 413
399 cfg80211_put_dev(dev); 414 cfg80211_unlock_rdev(dev);
400 415
401 return genlmsg_unicast(msg, info->snd_pid); 416 return genlmsg_reply(msg, info);
402 417
403 out_free: 418 out_free:
404 nlmsg_free(msg); 419 nlmsg_free(msg);
405 out_err: 420 out_err:
406 cfg80211_put_dev(dev); 421 cfg80211_unlock_rdev(dev);
407 return -ENOBUFS; 422 return -ENOBUFS;
408} 423}
409 424
@@ -445,7 +460,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
445 460
446 mutex_lock(&cfg80211_mutex); 461 mutex_lock(&cfg80211_mutex);
447 462
448 rdev = __cfg80211_drv_from_info(info); 463 rdev = __cfg80211_rdev_from_info(info);
449 if (IS_ERR(rdev)) { 464 if (IS_ERR(rdev)) {
450 mutex_unlock(&cfg80211_mutex); 465 mutex_unlock(&cfg80211_mutex);
451 result = PTR_ERR(rdev); 466 result = PTR_ERR(rdev);
@@ -668,7 +683,7 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *
668 struct wireless_dev *wdev; 683 struct wireless_dev *wdev;
669 684
670 mutex_lock(&cfg80211_mutex); 685 mutex_lock(&cfg80211_mutex);
671 list_for_each_entry(dev, &cfg80211_drv_list, list) { 686 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
672 if (wp_idx < wp_start) { 687 if (wp_idx < wp_start) {
673 wp_idx++; 688 wp_idx++;
674 continue; 689 continue;
@@ -709,7 +724,7 @@ static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
709 struct net_device *netdev; 724 struct net_device *netdev;
710 int err; 725 int err;
711 726
712 err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev); 727 err = get_rdev_dev_by_info_ifindex(info->attrs, &dev, &netdev);
713 if (err) 728 if (err)
714 return err; 729 return err;
715 730
@@ -722,15 +737,15 @@ static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
722 goto out_free; 737 goto out_free;
723 738
724 dev_put(netdev); 739 dev_put(netdev);
725 cfg80211_put_dev(dev); 740 cfg80211_unlock_rdev(dev);
726 741
727 return genlmsg_unicast(msg, info->snd_pid); 742 return genlmsg_reply(msg, info);
728 743
729 out_free: 744 out_free:
730 nlmsg_free(msg); 745 nlmsg_free(msg);
731 out_err: 746 out_err:
732 dev_put(netdev); 747 dev_put(netdev);
733 cfg80211_put_dev(dev); 748 cfg80211_unlock_rdev(dev);
734 return -ENOBUFS; 749 return -ENOBUFS;
735} 750}
736 751
@@ -765,9 +780,9 @@ static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
765 780
766static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) 781static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
767{ 782{
768 struct cfg80211_registered_device *drv; 783 struct cfg80211_registered_device *rdev;
769 struct vif_params params; 784 struct vif_params params;
770 int err, ifindex; 785 int err;
771 enum nl80211_iftype otype, ntype; 786 enum nl80211_iftype otype, ntype;
772 struct net_device *dev; 787 struct net_device *dev;
773 u32 _flags, *flags = NULL; 788 u32 _flags, *flags = NULL;
@@ -777,13 +792,11 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
777 792
778 rtnl_lock(); 793 rtnl_lock();
779 794
780 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 795 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
781 if (err) 796 if (err)
782 goto unlock_rtnl; 797 goto unlock_rtnl;
783 798
784 ifindex = dev->ifindex;
785 otype = ntype = dev->ieee80211_ptr->iftype; 799 otype = ntype = dev->ieee80211_ptr->iftype;
786 dev_put(dev);
787 800
788 if (info->attrs[NL80211_ATTR_IFTYPE]) { 801 if (info->attrs[NL80211_ATTR_IFTYPE]) {
789 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 802 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
@@ -795,8 +808,8 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
795 } 808 }
796 } 809 }
797 810
798 if (!drv->ops->change_virtual_intf || 811 if (!rdev->ops->change_virtual_intf ||
799 !(drv->wiphy.interface_modes & (1 << ntype))) { 812 !(rdev->wiphy.interface_modes & (1 << ntype))) {
800 err = -EOPNOTSUPP; 813 err = -EOPNOTSUPP;
801 goto unlock; 814 goto unlock;
802 } 815 }
@@ -826,21 +839,21 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
826 } 839 }
827 840
828 if (change) 841 if (change)
829 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex, 842 err = rdev->ops->change_virtual_intf(&rdev->wiphy, dev,
830 ntype, flags, &params); 843 ntype, flags, &params);
831 else 844 else
832 err = 0; 845 err = 0;
833 846
834 dev = __dev_get_by_index(&init_net, ifindex); 847 WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype);
835 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != ntype));
836 848
837 if (dev && !err && (ntype != otype)) { 849 if (!err && (ntype != otype)) {
838 if (otype == NL80211_IFTYPE_ADHOC) 850 if (otype == NL80211_IFTYPE_ADHOC)
839 cfg80211_clear_ibss(dev, false); 851 cfg80211_clear_ibss(dev, false);
840 } 852 }
841 853
842 unlock: 854 unlock:
843 cfg80211_put_dev(drv); 855 dev_put(dev);
856 cfg80211_unlock_rdev(rdev);
844 unlock_rtnl: 857 unlock_rtnl:
845 rtnl_unlock(); 858 rtnl_unlock();
846 return err; 859 return err;
@@ -848,7 +861,7 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
848 861
849static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 862static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
850{ 863{
851 struct cfg80211_registered_device *drv; 864 struct cfg80211_registered_device *rdev;
852 struct vif_params params; 865 struct vif_params params;
853 int err; 866 int err;
854 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; 867 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
@@ -867,14 +880,14 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
867 880
868 rtnl_lock(); 881 rtnl_lock();
869 882
870 drv = cfg80211_get_dev_from_info(info); 883 rdev = cfg80211_get_dev_from_info(info);
871 if (IS_ERR(drv)) { 884 if (IS_ERR(rdev)) {
872 err = PTR_ERR(drv); 885 err = PTR_ERR(rdev);
873 goto unlock_rtnl; 886 goto unlock_rtnl;
874 } 887 }
875 888
876 if (!drv->ops->add_virtual_intf || 889 if (!rdev->ops->add_virtual_intf ||
877 !(drv->wiphy.interface_modes & (1 << type))) { 890 !(rdev->wiphy.interface_modes & (1 << type))) {
878 err = -EOPNOTSUPP; 891 err = -EOPNOTSUPP;
879 goto unlock; 892 goto unlock;
880 } 893 }
@@ -888,12 +901,12 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
888 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? 901 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
889 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, 902 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
890 &flags); 903 &flags);
891 err = drv->ops->add_virtual_intf(&drv->wiphy, 904 err = rdev->ops->add_virtual_intf(&rdev->wiphy,
892 nla_data(info->attrs[NL80211_ATTR_IFNAME]), 905 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
893 type, err ? NULL : &flags, &params); 906 type, err ? NULL : &flags, &params);
894 907
895 unlock: 908 unlock:
896 cfg80211_put_dev(drv); 909 cfg80211_unlock_rdev(rdev);
897 unlock_rtnl: 910 unlock_rtnl:
898 rtnl_unlock(); 911 rtnl_unlock();
899 return err; 912 return err;
@@ -901,27 +914,27 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
901 914
902static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) 915static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
903{ 916{
904 struct cfg80211_registered_device *drv; 917 struct cfg80211_registered_device *rdev;
905 int ifindex, err; 918 int ifindex, err;
906 struct net_device *dev; 919 struct net_device *dev;
907 920
908 rtnl_lock(); 921 rtnl_lock();
909 922
910 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 923 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
911 if (err) 924 if (err)
912 goto unlock_rtnl; 925 goto unlock_rtnl;
913 ifindex = dev->ifindex; 926 ifindex = dev->ifindex;
914 dev_put(dev); 927 dev_put(dev);
915 928
916 if (!drv->ops->del_virtual_intf) { 929 if (!rdev->ops->del_virtual_intf) {
917 err = -EOPNOTSUPP; 930 err = -EOPNOTSUPP;
918 goto out; 931 goto out;
919 } 932 }
920 933
921 err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex); 934 err = rdev->ops->del_virtual_intf(&rdev->wiphy, ifindex);
922 935
923 out: 936 out:
924 cfg80211_put_dev(drv); 937 cfg80211_unlock_rdev(rdev);
925 unlock_rtnl: 938 unlock_rtnl:
926 rtnl_unlock(); 939 rtnl_unlock();
927 return err; 940 return err;
@@ -955,7 +968,7 @@ static void get_key_callback(void *c, struct key_params *params)
955 968
956static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) 969static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
957{ 970{
958 struct cfg80211_registered_device *drv; 971 struct cfg80211_registered_device *rdev;
959 int err; 972 int err;
960 struct net_device *dev; 973 struct net_device *dev;
961 u8 key_idx = 0; 974 u8 key_idx = 0;
@@ -977,11 +990,11 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
977 990
978 rtnl_lock(); 991 rtnl_lock();
979 992
980 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 993 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
981 if (err) 994 if (err)
982 goto unlock_rtnl; 995 goto unlock_rtnl;
983 996
984 if (!drv->ops->get_key) { 997 if (!rdev->ops->get_key) {
985 err = -EOPNOTSUPP; 998 err = -EOPNOTSUPP;
986 goto out; 999 goto out;
987 } 1000 }
@@ -1007,7 +1020,7 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1007 if (mac_addr) 1020 if (mac_addr)
1008 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); 1021 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1009 1022
1010 err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr, 1023 err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, mac_addr,
1011 &cookie, get_key_callback); 1024 &cookie, get_key_callback);
1012 1025
1013 if (err) 1026 if (err)
@@ -1017,14 +1030,14 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1017 goto nla_put_failure; 1030 goto nla_put_failure;
1018 1031
1019 genlmsg_end(msg, hdr); 1032 genlmsg_end(msg, hdr);
1020 err = genlmsg_unicast(msg, info->snd_pid); 1033 err = genlmsg_reply(msg, info);
1021 goto out; 1034 goto out;
1022 1035
1023 nla_put_failure: 1036 nla_put_failure:
1024 err = -ENOBUFS; 1037 err = -ENOBUFS;
1025 nlmsg_free(msg); 1038 nlmsg_free(msg);
1026 out: 1039 out:
1027 cfg80211_put_dev(drv); 1040 cfg80211_unlock_rdev(rdev);
1028 dev_put(dev); 1041 dev_put(dev);
1029 unlock_rtnl: 1042 unlock_rtnl:
1030 rtnl_unlock(); 1043 rtnl_unlock();
@@ -1034,7 +1047,7 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
1034 1047
1035static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) 1048static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1036{ 1049{
1037 struct cfg80211_registered_device *drv; 1050 struct cfg80211_registered_device *rdev;
1038 int err; 1051 int err;
1039 struct net_device *dev; 1052 struct net_device *dev;
1040 u8 key_idx; 1053 u8 key_idx;
@@ -1059,24 +1072,24 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1059 1072
1060 rtnl_lock(); 1073 rtnl_lock();
1061 1074
1062 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1075 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
1063 if (err) 1076 if (err)
1064 goto unlock_rtnl; 1077 goto unlock_rtnl;
1065 1078
1066 if (info->attrs[NL80211_ATTR_KEY_DEFAULT]) 1079 if (info->attrs[NL80211_ATTR_KEY_DEFAULT])
1067 func = drv->ops->set_default_key; 1080 func = rdev->ops->set_default_key;
1068 else 1081 else
1069 func = drv->ops->set_default_mgmt_key; 1082 func = rdev->ops->set_default_mgmt_key;
1070 1083
1071 if (!func) { 1084 if (!func) {
1072 err = -EOPNOTSUPP; 1085 err = -EOPNOTSUPP;
1073 goto out; 1086 goto out;
1074 } 1087 }
1075 1088
1076 err = func(&drv->wiphy, dev, key_idx); 1089 err = func(&rdev->wiphy, dev, key_idx);
1077#ifdef CONFIG_WIRELESS_EXT 1090#ifdef CONFIG_WIRELESS_EXT
1078 if (!err) { 1091 if (!err) {
1079 if (func == drv->ops->set_default_key) 1092 if (func == rdev->ops->set_default_key)
1080 dev->ieee80211_ptr->wext.default_key = key_idx; 1093 dev->ieee80211_ptr->wext.default_key = key_idx;
1081 else 1094 else
1082 dev->ieee80211_ptr->wext.default_mgmt_key = key_idx; 1095 dev->ieee80211_ptr->wext.default_mgmt_key = key_idx;
@@ -1084,7 +1097,7 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1084#endif 1097#endif
1085 1098
1086 out: 1099 out:
1087 cfg80211_put_dev(drv); 1100 cfg80211_unlock_rdev(rdev);
1088 dev_put(dev); 1101 dev_put(dev);
1089 1102
1090 unlock_rtnl: 1103 unlock_rtnl:
@@ -1095,7 +1108,7 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1095 1108
1096static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) 1109static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1097{ 1110{
1098 struct cfg80211_registered_device *drv; 1111 struct cfg80211_registered_device *rdev;
1099 int err, i; 1112 int err, i;
1100 struct net_device *dev; 1113 struct net_device *dev;
1101 struct key_params params; 1114 struct key_params params;
@@ -1130,27 +1143,27 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1130 1143
1131 rtnl_lock(); 1144 rtnl_lock();
1132 1145
1133 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1146 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
1134 if (err) 1147 if (err)
1135 goto unlock_rtnl; 1148 goto unlock_rtnl;
1136 1149
1137 for (i = 0; i < drv->wiphy.n_cipher_suites; i++) 1150 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++)
1138 if (params.cipher == drv->wiphy.cipher_suites[i]) 1151 if (params.cipher == rdev->wiphy.cipher_suites[i])
1139 break; 1152 break;
1140 if (i == drv->wiphy.n_cipher_suites) { 1153 if (i == rdev->wiphy.n_cipher_suites) {
1141 err = -EINVAL; 1154 err = -EINVAL;
1142 goto out; 1155 goto out;
1143 } 1156 }
1144 1157
1145 if (!drv->ops->add_key) { 1158 if (!rdev->ops->add_key) {
1146 err = -EOPNOTSUPP; 1159 err = -EOPNOTSUPP;
1147 goto out; 1160 goto out;
1148 } 1161 }
1149 1162
1150 err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, &params); 1163 err = rdev->ops->add_key(&rdev->wiphy, dev, key_idx, mac_addr, &params);
1151 1164
1152 out: 1165 out:
1153 cfg80211_put_dev(drv); 1166 cfg80211_unlock_rdev(rdev);
1154 dev_put(dev); 1167 dev_put(dev);
1155 unlock_rtnl: 1168 unlock_rtnl:
1156 rtnl_unlock(); 1169 rtnl_unlock();
@@ -1160,7 +1173,7 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1160 1173
1161static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) 1174static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1162{ 1175{
1163 struct cfg80211_registered_device *drv; 1176 struct cfg80211_registered_device *rdev;
1164 int err; 1177 int err;
1165 struct net_device *dev; 1178 struct net_device *dev;
1166 u8 key_idx = 0; 1179 u8 key_idx = 0;
@@ -1177,16 +1190,16 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1177 1190
1178 rtnl_lock(); 1191 rtnl_lock();
1179 1192
1180 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1193 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
1181 if (err) 1194 if (err)
1182 goto unlock_rtnl; 1195 goto unlock_rtnl;
1183 1196
1184 if (!drv->ops->del_key) { 1197 if (!rdev->ops->del_key) {
1185 err = -EOPNOTSUPP; 1198 err = -EOPNOTSUPP;
1186 goto out; 1199 goto out;
1187 } 1200 }
1188 1201
1189 err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr); 1202 err = rdev->ops->del_key(&rdev->wiphy, dev, key_idx, mac_addr);
1190 1203
1191#ifdef CONFIG_WIRELESS_EXT 1204#ifdef CONFIG_WIRELESS_EXT
1192 if (!err) { 1205 if (!err) {
@@ -1198,7 +1211,7 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1198#endif 1211#endif
1199 1212
1200 out: 1213 out:
1201 cfg80211_put_dev(drv); 1214 cfg80211_unlock_rdev(rdev);
1202 dev_put(dev); 1215 dev_put(dev);
1203 1216
1204 unlock_rtnl: 1217 unlock_rtnl:
@@ -1211,7 +1224,7 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1211{ 1224{
1212 int (*call)(struct wiphy *wiphy, struct net_device *dev, 1225 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1213 struct beacon_parameters *info); 1226 struct beacon_parameters *info);
1214 struct cfg80211_registered_device *drv; 1227 struct cfg80211_registered_device *rdev;
1215 int err; 1228 int err;
1216 struct net_device *dev; 1229 struct net_device *dev;
1217 struct beacon_parameters params; 1230 struct beacon_parameters params;
@@ -1222,7 +1235,7 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1222 1235
1223 rtnl_lock(); 1236 rtnl_lock();
1224 1237
1225 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1238 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
1226 if (err) 1239 if (err)
1227 goto unlock_rtnl; 1240 goto unlock_rtnl;
1228 1241
@@ -1241,10 +1254,10 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1241 goto out; 1254 goto out;
1242 } 1255 }
1243 1256
1244 call = drv->ops->add_beacon; 1257 call = rdev->ops->add_beacon;
1245 break; 1258 break;
1246 case NL80211_CMD_SET_BEACON: 1259 case NL80211_CMD_SET_BEACON:
1247 call = drv->ops->set_beacon; 1260 call = rdev->ops->set_beacon;
1248 break; 1261 break;
1249 default: 1262 default:
1250 WARN_ON(1); 1263 WARN_ON(1);
@@ -1290,10 +1303,10 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1290 goto out; 1303 goto out;
1291 } 1304 }
1292 1305
1293 err = call(&drv->wiphy, dev, &params); 1306 err = call(&rdev->wiphy, dev, &params);
1294 1307
1295 out: 1308 out:
1296 cfg80211_put_dev(drv); 1309 cfg80211_unlock_rdev(rdev);
1297 dev_put(dev); 1310 dev_put(dev);
1298 unlock_rtnl: 1311 unlock_rtnl:
1299 rtnl_unlock(); 1312 rtnl_unlock();
@@ -1303,17 +1316,17 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1303 1316
1304static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) 1317static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1305{ 1318{
1306 struct cfg80211_registered_device *drv; 1319 struct cfg80211_registered_device *rdev;
1307 int err; 1320 int err;
1308 struct net_device *dev; 1321 struct net_device *dev;
1309 1322
1310 rtnl_lock(); 1323 rtnl_lock();
1311 1324
1312 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1325 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
1313 if (err) 1326 if (err)
1314 goto unlock_rtnl; 1327 goto unlock_rtnl;
1315 1328
1316 if (!drv->ops->del_beacon) { 1329 if (!rdev->ops->del_beacon) {
1317 err = -EOPNOTSUPP; 1330 err = -EOPNOTSUPP;
1318 goto out; 1331 goto out;
1319 } 1332 }
@@ -1322,10 +1335,10 @@ static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1322 err = -EOPNOTSUPP; 1335 err = -EOPNOTSUPP;
1323 goto out; 1336 goto out;
1324 } 1337 }
1325 err = drv->ops->del_beacon(&drv->wiphy, dev); 1338 err = rdev->ops->del_beacon(&rdev->wiphy, dev);
1326 1339
1327 out: 1340 out:
1328 cfg80211_put_dev(drv); 1341 cfg80211_unlock_rdev(rdev);
1329 dev_put(dev); 1342 dev_put(dev);
1330 unlock_rtnl: 1343 unlock_rtnl:
1331 rtnl_unlock(); 1344 rtnl_unlock();
@@ -1559,7 +1572,7 @@ static int nl80211_dump_station(struct sk_buff *skb,
1559 cb->args[1] = sta_idx; 1572 cb->args[1] = sta_idx;
1560 err = skb->len; 1573 err = skb->len;
1561 out_err: 1574 out_err:
1562 cfg80211_put_dev(dev); 1575 cfg80211_unlock_rdev(dev);
1563 out_rtnl: 1576 out_rtnl:
1564 rtnl_unlock(); 1577 rtnl_unlock();
1565 1578
@@ -1568,7 +1581,7 @@ static int nl80211_dump_station(struct sk_buff *skb,
1568 1581
1569static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) 1582static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1570{ 1583{
1571 struct cfg80211_registered_device *drv; 1584 struct cfg80211_registered_device *rdev;
1572 int err; 1585 int err;
1573 struct net_device *dev; 1586 struct net_device *dev;
1574 struct station_info sinfo; 1587 struct station_info sinfo;
@@ -1584,16 +1597,16 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1584 1597
1585 rtnl_lock(); 1598 rtnl_lock();
1586 1599
1587 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1600 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
1588 if (err) 1601 if (err)
1589 goto out_rtnl; 1602 goto out_rtnl;
1590 1603
1591 if (!drv->ops->get_station) { 1604 if (!rdev->ops->get_station) {
1592 err = -EOPNOTSUPP; 1605 err = -EOPNOTSUPP;
1593 goto out; 1606 goto out;
1594 } 1607 }
1595 1608
1596 err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo); 1609 err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
1597 if (err) 1610 if (err)
1598 goto out; 1611 goto out;
1599 1612
@@ -1605,13 +1618,13 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1605 dev, mac_addr, &sinfo) < 0) 1618 dev, mac_addr, &sinfo) < 0)
1606 goto out_free; 1619 goto out_free;
1607 1620
1608 err = genlmsg_unicast(msg, info->snd_pid); 1621 err = genlmsg_reply(msg, info);
1609 goto out; 1622 goto out;
1610 1623
1611 out_free: 1624 out_free:
1612 nlmsg_free(msg); 1625 nlmsg_free(msg);
1613 out: 1626 out:
1614 cfg80211_put_dev(drv); 1627 cfg80211_unlock_rdev(rdev);
1615 dev_put(dev); 1628 dev_put(dev);
1616 out_rtnl: 1629 out_rtnl:
1617 rtnl_unlock(); 1630 rtnl_unlock();
@@ -1642,7 +1655,7 @@ static int get_vlan(struct nlattr *vlanattr,
1642 1655
1643static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) 1656static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1644{ 1657{
1645 struct cfg80211_registered_device *drv; 1658 struct cfg80211_registered_device *rdev;
1646 int err; 1659 int err;
1647 struct net_device *dev; 1660 struct net_device *dev;
1648 struct station_parameters params; 1661 struct station_parameters params;
@@ -1684,11 +1697,11 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1684 1697
1685 rtnl_lock(); 1698 rtnl_lock();
1686 1699
1687 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1700 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
1688 if (err) 1701 if (err)
1689 goto out_rtnl; 1702 goto out_rtnl;
1690 1703
1691 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan); 1704 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], rdev, &params.vlan);
1692 if (err) 1705 if (err)
1693 goto out; 1706 goto out;
1694 1707
@@ -1737,17 +1750,17 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1737 if (err) 1750 if (err)
1738 goto out; 1751 goto out;
1739 1752
1740 if (!drv->ops->change_station) { 1753 if (!rdev->ops->change_station) {
1741 err = -EOPNOTSUPP; 1754 err = -EOPNOTSUPP;
1742 goto out; 1755 goto out;
1743 } 1756 }
1744 1757
1745 err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, &params); 1758 err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
1746 1759
1747 out: 1760 out:
1748 if (params.vlan) 1761 if (params.vlan)
1749 dev_put(params.vlan); 1762 dev_put(params.vlan);
1750 cfg80211_put_dev(drv); 1763 cfg80211_unlock_rdev(rdev);
1751 dev_put(dev); 1764 dev_put(dev);
1752 out_rtnl: 1765 out_rtnl:
1753 rtnl_unlock(); 1766 rtnl_unlock();
@@ -1757,7 +1770,7 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1757 1770
1758static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) 1771static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1759{ 1772{
1760 struct cfg80211_registered_device *drv; 1773 struct cfg80211_registered_device *rdev;
1761 int err; 1774 int err;
1762 struct net_device *dev; 1775 struct net_device *dev;
1763 struct station_parameters params; 1776 struct station_parameters params;
@@ -1797,11 +1810,11 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1797 1810
1798 rtnl_lock(); 1811 rtnl_lock();
1799 1812
1800 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1813 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
1801 if (err) 1814 if (err)
1802 goto out_rtnl; 1815 goto out_rtnl;
1803 1816
1804 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan); 1817 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], rdev, &params.vlan);
1805 if (err) 1818 if (err)
1806 goto out; 1819 goto out;
1807 1820
@@ -1837,7 +1850,7 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1837 if (err) 1850 if (err)
1838 goto out; 1851 goto out;
1839 1852
1840 if (!drv->ops->add_station) { 1853 if (!rdev->ops->add_station) {
1841 err = -EOPNOTSUPP; 1854 err = -EOPNOTSUPP;
1842 goto out; 1855 goto out;
1843 } 1856 }
@@ -1847,12 +1860,12 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1847 goto out; 1860 goto out;
1848 } 1861 }
1849 1862
1850 err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, &params); 1863 err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
1851 1864
1852 out: 1865 out:
1853 if (params.vlan) 1866 if (params.vlan)
1854 dev_put(params.vlan); 1867 dev_put(params.vlan);
1855 cfg80211_put_dev(drv); 1868 cfg80211_unlock_rdev(rdev);
1856 dev_put(dev); 1869 dev_put(dev);
1857 out_rtnl: 1870 out_rtnl:
1858 rtnl_unlock(); 1871 rtnl_unlock();
@@ -1862,7 +1875,7 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1862 1875
1863static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) 1876static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1864{ 1877{
1865 struct cfg80211_registered_device *drv; 1878 struct cfg80211_registered_device *rdev;
1866 int err; 1879 int err;
1867 struct net_device *dev; 1880 struct net_device *dev;
1868 u8 *mac_addr = NULL; 1881 u8 *mac_addr = NULL;
@@ -1872,7 +1885,7 @@ static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1872 1885
1873 rtnl_lock(); 1886 rtnl_lock();
1874 1887
1875 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1888 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
1876 if (err) 1889 if (err)
1877 goto out_rtnl; 1890 goto out_rtnl;
1878 1891
@@ -1883,15 +1896,15 @@ static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1883 goto out; 1896 goto out;
1884 } 1897 }
1885 1898
1886 if (!drv->ops->del_station) { 1899 if (!rdev->ops->del_station) {
1887 err = -EOPNOTSUPP; 1900 err = -EOPNOTSUPP;
1888 goto out; 1901 goto out;
1889 } 1902 }
1890 1903
1891 err = drv->ops->del_station(&drv->wiphy, dev, mac_addr); 1904 err = rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
1892 1905
1893 out: 1906 out:
1894 cfg80211_put_dev(drv); 1907 cfg80211_unlock_rdev(rdev);
1895 dev_put(dev); 1908 dev_put(dev);
1896 out_rtnl: 1909 out_rtnl:
1897 rtnl_unlock(); 1910 rtnl_unlock();
@@ -2022,7 +2035,7 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
2022 cb->args[1] = path_idx; 2035 cb->args[1] = path_idx;
2023 err = skb->len; 2036 err = skb->len;
2024 out_err: 2037 out_err:
2025 cfg80211_put_dev(dev); 2038 cfg80211_unlock_rdev(dev);
2026 out_rtnl: 2039 out_rtnl:
2027 rtnl_unlock(); 2040 rtnl_unlock();
2028 2041
@@ -2031,7 +2044,7 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
2031 2044
2032static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) 2045static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2033{ 2046{
2034 struct cfg80211_registered_device *drv; 2047 struct cfg80211_registered_device *rdev;
2035 int err; 2048 int err;
2036 struct net_device *dev; 2049 struct net_device *dev;
2037 struct mpath_info pinfo; 2050 struct mpath_info pinfo;
@@ -2048,11 +2061,11 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2048 2061
2049 rtnl_lock(); 2062 rtnl_lock();
2050 2063
2051 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2064 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
2052 if (err) 2065 if (err)
2053 goto out_rtnl; 2066 goto out_rtnl;
2054 2067
2055 if (!drv->ops->get_mpath) { 2068 if (!rdev->ops->get_mpath) {
2056 err = -EOPNOTSUPP; 2069 err = -EOPNOTSUPP;
2057 goto out; 2070 goto out;
2058 } 2071 }
@@ -2062,7 +2075,7 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2062 goto out; 2075 goto out;
2063 } 2076 }
2064 2077
2065 err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo); 2078 err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
2066 if (err) 2079 if (err)
2067 goto out; 2080 goto out;
2068 2081
@@ -2074,13 +2087,13 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2074 dev, dst, next_hop, &pinfo) < 0) 2087 dev, dst, next_hop, &pinfo) < 0)
2075 goto out_free; 2088 goto out_free;
2076 2089
2077 err = genlmsg_unicast(msg, info->snd_pid); 2090 err = genlmsg_reply(msg, info);
2078 goto out; 2091 goto out;
2079 2092
2080 out_free: 2093 out_free:
2081 nlmsg_free(msg); 2094 nlmsg_free(msg);
2082 out: 2095 out:
2083 cfg80211_put_dev(drv); 2096 cfg80211_unlock_rdev(rdev);
2084 dev_put(dev); 2097 dev_put(dev);
2085 out_rtnl: 2098 out_rtnl:
2086 rtnl_unlock(); 2099 rtnl_unlock();
@@ -2090,7 +2103,7 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
2090 2103
2091static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) 2104static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2092{ 2105{
2093 struct cfg80211_registered_device *drv; 2106 struct cfg80211_registered_device *rdev;
2094 int err; 2107 int err;
2095 struct net_device *dev; 2108 struct net_device *dev;
2096 u8 *dst = NULL; 2109 u8 *dst = NULL;
@@ -2107,11 +2120,11 @@ static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2107 2120
2108 rtnl_lock(); 2121 rtnl_lock();
2109 2122
2110 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2123 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
2111 if (err) 2124 if (err)
2112 goto out_rtnl; 2125 goto out_rtnl;
2113 2126
2114 if (!drv->ops->change_mpath) { 2127 if (!rdev->ops->change_mpath) {
2115 err = -EOPNOTSUPP; 2128 err = -EOPNOTSUPP;
2116 goto out; 2129 goto out;
2117 } 2130 }
@@ -2126,10 +2139,10 @@ static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2126 goto out; 2139 goto out;
2127 } 2140 }
2128 2141
2129 err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop); 2142 err = rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
2130 2143
2131 out: 2144 out:
2132 cfg80211_put_dev(drv); 2145 cfg80211_unlock_rdev(rdev);
2133 dev_put(dev); 2146 dev_put(dev);
2134 out_rtnl: 2147 out_rtnl:
2135 rtnl_unlock(); 2148 rtnl_unlock();
@@ -2138,7 +2151,7 @@ static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2138} 2151}
2139static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) 2152static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2140{ 2153{
2141 struct cfg80211_registered_device *drv; 2154 struct cfg80211_registered_device *rdev;
2142 int err; 2155 int err;
2143 struct net_device *dev; 2156 struct net_device *dev;
2144 u8 *dst = NULL; 2157 u8 *dst = NULL;
@@ -2155,11 +2168,11 @@ static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2155 2168
2156 rtnl_lock(); 2169 rtnl_lock();
2157 2170
2158 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2171 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
2159 if (err) 2172 if (err)
2160 goto out_rtnl; 2173 goto out_rtnl;
2161 2174
2162 if (!drv->ops->add_mpath) { 2175 if (!rdev->ops->add_mpath) {
2163 err = -EOPNOTSUPP; 2176 err = -EOPNOTSUPP;
2164 goto out; 2177 goto out;
2165 } 2178 }
@@ -2174,10 +2187,10 @@ static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2174 goto out; 2187 goto out;
2175 } 2188 }
2176 2189
2177 err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop); 2190 err = rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
2178 2191
2179 out: 2192 out:
2180 cfg80211_put_dev(drv); 2193 cfg80211_unlock_rdev(rdev);
2181 dev_put(dev); 2194 dev_put(dev);
2182 out_rtnl: 2195 out_rtnl:
2183 rtnl_unlock(); 2196 rtnl_unlock();
@@ -2187,7 +2200,7 @@ static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2187 2200
2188static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) 2201static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2189{ 2202{
2190 struct cfg80211_registered_device *drv; 2203 struct cfg80211_registered_device *rdev;
2191 int err; 2204 int err;
2192 struct net_device *dev; 2205 struct net_device *dev;
2193 u8 *dst = NULL; 2206 u8 *dst = NULL;
@@ -2197,19 +2210,19 @@ static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2197 2210
2198 rtnl_lock(); 2211 rtnl_lock();
2199 2212
2200 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2213 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
2201 if (err) 2214 if (err)
2202 goto out_rtnl; 2215 goto out_rtnl;
2203 2216
2204 if (!drv->ops->del_mpath) { 2217 if (!rdev->ops->del_mpath) {
2205 err = -EOPNOTSUPP; 2218 err = -EOPNOTSUPP;
2206 goto out; 2219 goto out;
2207 } 2220 }
2208 2221
2209 err = drv->ops->del_mpath(&drv->wiphy, dev, dst); 2222 err = rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
2210 2223
2211 out: 2224 out:
2212 cfg80211_put_dev(drv); 2225 cfg80211_unlock_rdev(rdev);
2213 dev_put(dev); 2226 dev_put(dev);
2214 out_rtnl: 2227 out_rtnl:
2215 rtnl_unlock(); 2228 rtnl_unlock();
@@ -2219,7 +2232,7 @@ static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2219 2232
2220static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) 2233static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2221{ 2234{
2222 struct cfg80211_registered_device *drv; 2235 struct cfg80211_registered_device *rdev;
2223 int err; 2236 int err;
2224 struct net_device *dev; 2237 struct net_device *dev;
2225 struct bss_parameters params; 2238 struct bss_parameters params;
@@ -2248,11 +2261,11 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2248 2261
2249 rtnl_lock(); 2262 rtnl_lock();
2250 2263
2251 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2264 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
2252 if (err) 2265 if (err)
2253 goto out_rtnl; 2266 goto out_rtnl;
2254 2267
2255 if (!drv->ops->change_bss) { 2268 if (!rdev->ops->change_bss) {
2256 err = -EOPNOTSUPP; 2269 err = -EOPNOTSUPP;
2257 goto out; 2270 goto out;
2258 } 2271 }
@@ -2262,10 +2275,10 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2262 goto out; 2275 goto out;
2263 } 2276 }
2264 2277
2265 err = drv->ops->change_bss(&drv->wiphy, dev, &params); 2278 err = rdev->ops->change_bss(&rdev->wiphy, dev, &params);
2266 2279
2267 out: 2280 out:
2268 cfg80211_put_dev(drv); 2281 cfg80211_unlock_rdev(rdev);
2269 dev_put(dev); 2282 dev_put(dev);
2270 out_rtnl: 2283 out_rtnl:
2271 rtnl_unlock(); 2284 rtnl_unlock();
@@ -2356,7 +2369,7 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2356static int nl80211_get_mesh_params(struct sk_buff *skb, 2369static int nl80211_get_mesh_params(struct sk_buff *skb,
2357 struct genl_info *info) 2370 struct genl_info *info)
2358{ 2371{
2359 struct cfg80211_registered_device *drv; 2372 struct cfg80211_registered_device *rdev;
2360 struct mesh_config cur_params; 2373 struct mesh_config cur_params;
2361 int err; 2374 int err;
2362 struct net_device *dev; 2375 struct net_device *dev;
@@ -2367,17 +2380,17 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
2367 rtnl_lock(); 2380 rtnl_lock();
2368 2381
2369 /* Look up our device */ 2382 /* Look up our device */
2370 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2383 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
2371 if (err) 2384 if (err)
2372 goto out_rtnl; 2385 goto out_rtnl;
2373 2386
2374 if (!drv->ops->get_mesh_params) { 2387 if (!rdev->ops->get_mesh_params) {
2375 err = -EOPNOTSUPP; 2388 err = -EOPNOTSUPP;
2376 goto out; 2389 goto out;
2377 } 2390 }
2378 2391
2379 /* Get the mesh params */ 2392 /* Get the mesh params */
2380 err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params); 2393 err = rdev->ops->get_mesh_params(&rdev->wiphy, dev, &cur_params);
2381 if (err) 2394 if (err)
2382 goto out; 2395 goto out;
2383 2396
@@ -2423,7 +2436,7 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
2423 cur_params.dot11MeshHWMPnetDiameterTraversalTime); 2436 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
2424 nla_nest_end(msg, pinfoattr); 2437 nla_nest_end(msg, pinfoattr);
2425 genlmsg_end(msg, hdr); 2438 genlmsg_end(msg, hdr);
2426 err = genlmsg_unicast(msg, info->snd_pid); 2439 err = genlmsg_reply(msg, info);
2427 goto out; 2440 goto out;
2428 2441
2429 nla_put_failure: 2442 nla_put_failure:
@@ -2431,7 +2444,7 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
2431 err = -EMSGSIZE; 2444 err = -EMSGSIZE;
2432 out: 2445 out:
2433 /* Cleanup */ 2446 /* Cleanup */
2434 cfg80211_put_dev(drv); 2447 cfg80211_unlock_rdev(rdev);
2435 dev_put(dev); 2448 dev_put(dev);
2436 out_rtnl: 2449 out_rtnl:
2437 rtnl_unlock(); 2450 rtnl_unlock();
@@ -2469,7 +2482,7 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2469{ 2482{
2470 int err; 2483 int err;
2471 u32 mask; 2484 u32 mask;
2472 struct cfg80211_registered_device *drv; 2485 struct cfg80211_registered_device *rdev;
2473 struct net_device *dev; 2486 struct net_device *dev;
2474 struct mesh_config cfg; 2487 struct mesh_config cfg;
2475 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 2488 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
@@ -2484,11 +2497,11 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2484 2497
2485 rtnl_lock(); 2498 rtnl_lock();
2486 2499
2487 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2500 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
2488 if (err) 2501 if (err)
2489 goto out_rtnl; 2502 goto out_rtnl;
2490 2503
2491 if (!drv->ops->set_mesh_params) { 2504 if (!rdev->ops->set_mesh_params) {
2492 err = -EOPNOTSUPP; 2505 err = -EOPNOTSUPP;
2493 goto out; 2506 goto out;
2494 } 2507 }
@@ -2533,11 +2546,11 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2533 nla_get_u16); 2546 nla_get_u16);
2534 2547
2535 /* Apply changes */ 2548 /* Apply changes */
2536 err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask); 2549 err = rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask);
2537 2550
2538 out: 2551 out:
2539 /* cleanup */ 2552 /* cleanup */
2540 cfg80211_put_dev(drv); 2553 cfg80211_unlock_rdev(rdev);
2541 dev_put(dev); 2554 dev_put(dev);
2542 out_rtnl: 2555 out_rtnl:
2543 rtnl_unlock(); 2556 rtnl_unlock();
@@ -2611,7 +2624,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2611 nla_nest_end(msg, nl_reg_rules); 2624 nla_nest_end(msg, nl_reg_rules);
2612 2625
2613 genlmsg_end(msg, hdr); 2626 genlmsg_end(msg, hdr);
2614 err = genlmsg_unicast(msg, info->snd_pid); 2627 err = genlmsg_reply(msg, info);
2615 goto out; 2628 goto out;
2616 2629
2617nla_put_failure: 2630nla_put_failure:
@@ -2697,16 +2710,41 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2697 return r; 2710 return r;
2698} 2711}
2699 2712
2713static int validate_scan_freqs(struct nlattr *freqs)
2714{
2715 struct nlattr *attr1, *attr2;
2716 int n_channels = 0, tmp1, tmp2;
2717
2718 nla_for_each_nested(attr1, freqs, tmp1) {
2719 n_channels++;
2720 /*
2721 * Some hardware has a limited channel list for
2722 * scanning, and it is pretty much nonsensical
2723 * to scan for a channel twice, so disallow that
2724 * and don't require drivers to check that the
2725 * channel list they get isn't longer than what
2726 * they can scan, as long as they can scan all
2727 * the channels they registered at once.
2728 */
2729 nla_for_each_nested(attr2, freqs, tmp2)
2730 if (attr1 != attr2 &&
2731 nla_get_u32(attr1) == nla_get_u32(attr2))
2732 return 0;
2733 }
2734
2735 return n_channels;
2736}
2737
2700static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) 2738static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2701{ 2739{
2702 struct cfg80211_registered_device *drv; 2740 struct cfg80211_registered_device *rdev;
2703 struct net_device *dev; 2741 struct net_device *dev;
2704 struct cfg80211_scan_request *request; 2742 struct cfg80211_scan_request *request;
2705 struct cfg80211_ssid *ssid; 2743 struct cfg80211_ssid *ssid;
2706 struct ieee80211_channel *channel; 2744 struct ieee80211_channel *channel;
2707 struct nlattr *attr; 2745 struct nlattr *attr;
2708 struct wiphy *wiphy; 2746 struct wiphy *wiphy;
2709 int err, tmp, n_ssids = 0, n_channels = 0, i; 2747 int err, tmp, n_ssids = 0, n_channels, i;
2710 enum ieee80211_band band; 2748 enum ieee80211_band band;
2711 size_t ie_len; 2749 size_t ie_len;
2712 2750
@@ -2715,13 +2753,13 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2715 2753
2716 rtnl_lock(); 2754 rtnl_lock();
2717 2755
2718 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2756 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
2719 if (err) 2757 if (err)
2720 goto out_rtnl; 2758 goto out_rtnl;
2721 2759
2722 wiphy = &drv->wiphy; 2760 wiphy = &rdev->wiphy;
2723 2761
2724 if (!drv->ops->scan) { 2762 if (!rdev->ops->scan) {
2725 err = -EOPNOTSUPP; 2763 err = -EOPNOTSUPP;
2726 goto out; 2764 goto out;
2727 } 2765 }
@@ -2731,19 +2769,21 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2731 goto out; 2769 goto out;
2732 } 2770 }
2733 2771
2734 if (drv->scan_req) { 2772 if (rdev->scan_req) {
2735 err = -EBUSY; 2773 err = -EBUSY;
2736 goto out; 2774 goto out;
2737 } 2775 }
2738 2776
2739 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 2777 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2740 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) 2778 n_channels = validate_scan_freqs(
2741 n_channels++; 2779 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
2742 if (!n_channels) { 2780 if (!n_channels) {
2743 err = -EINVAL; 2781 err = -EINVAL;
2744 goto out; 2782 goto out;
2745 } 2783 }
2746 } else { 2784 } else {
2785 n_channels = 0;
2786
2747 for (band = 0; band < IEEE80211_NUM_BANDS; band++) 2787 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
2748 if (wiphy->bands[band]) 2788 if (wiphy->bands[band])
2749 n_channels += wiphy->bands[band]->n_channels; 2789 n_channels += wiphy->bands[band]->n_channels;
@@ -2836,18 +2876,21 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2836 } 2876 }
2837 2877
2838 request->ifidx = dev->ifindex; 2878 request->ifidx = dev->ifindex;
2839 request->wiphy = &drv->wiphy; 2879 request->wiphy = &rdev->wiphy;
2880
2881 rdev->scan_req = request;
2882 err = rdev->ops->scan(&rdev->wiphy, dev, request);
2840 2883
2841 drv->scan_req = request; 2884 if (!err)
2842 err = drv->ops->scan(&drv->wiphy, dev, request); 2885 nl80211_send_scan_start(rdev, dev);
2843 2886
2844 out_free: 2887 out_free:
2845 if (err) { 2888 if (err) {
2846 drv->scan_req = NULL; 2889 rdev->scan_req = NULL;
2847 kfree(request); 2890 kfree(request);
2848 } 2891 }
2849 out: 2892 out:
2850 cfg80211_put_dev(drv); 2893 cfg80211_unlock_rdev(rdev);
2851 dev_put(dev); 2894 dev_put(dev);
2852 out_rtnl: 2895 out_rtnl:
2853 rtnl_unlock(); 2896 rtnl_unlock();
@@ -2964,7 +3007,7 @@ static int nl80211_dump_scan(struct sk_buff *skb,
2964 3007
2965 cb->args[1] = idx; 3008 cb->args[1] = idx;
2966 err = skb->len; 3009 err = skb->len;
2967 cfg80211_put_dev(dev); 3010 cfg80211_unlock_rdev(dev);
2968 out_put_netdev: 3011 out_put_netdev:
2969 dev_put(netdev); 3012 dev_put(netdev);
2970 3013
@@ -2973,19 +3016,39 @@ static int nl80211_dump_scan(struct sk_buff *skb,
2973 3016
2974static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) 3017static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
2975{ 3018{
2976 return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM || 3019 return auth_type <= NL80211_AUTHTYPE_MAX;
2977 auth_type == NL80211_AUTHTYPE_SHARED_KEY || 3020}
2978 auth_type == NL80211_AUTHTYPE_FT || 3021
2979 auth_type == NL80211_AUTHTYPE_NETWORK_EAP; 3022static bool nl80211_valid_wpa_versions(u32 wpa_versions)
3023{
3024 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
3025 NL80211_WPA_VERSION_2));
3026}
3027
3028static bool nl80211_valid_akm_suite(u32 akm)
3029{
3030 return akm == WLAN_AKM_SUITE_8021X ||
3031 akm == WLAN_AKM_SUITE_PSK;
2980} 3032}
2981 3033
3034static bool nl80211_valid_cipher_suite(u32 cipher)
3035{
3036 return cipher == WLAN_CIPHER_SUITE_WEP40 ||
3037 cipher == WLAN_CIPHER_SUITE_WEP104 ||
3038 cipher == WLAN_CIPHER_SUITE_TKIP ||
3039 cipher == WLAN_CIPHER_SUITE_CCMP ||
3040 cipher == WLAN_CIPHER_SUITE_AES_CMAC;
3041}
3042
3043
2982static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) 3044static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2983{ 3045{
2984 struct cfg80211_registered_device *drv; 3046 struct cfg80211_registered_device *rdev;
2985 struct net_device *dev; 3047 struct net_device *dev;
2986 struct cfg80211_auth_request req; 3048 struct ieee80211_channel *chan;
2987 struct wiphy *wiphy; 3049 const u8 *bssid, *ssid, *ie = NULL;
2988 int err; 3050 int err, ssid_len, ie_len = 0;
3051 enum nl80211_auth_type auth_type;
2989 3052
2990 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) 3053 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2991 return -EINVAL; 3054 return -EINVAL;
@@ -2996,13 +3059,19 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2996 if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) 3059 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
2997 return -EINVAL; 3060 return -EINVAL;
2998 3061
3062 if (!info->attrs[NL80211_ATTR_SSID])
3063 return -EINVAL;
3064
3065 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
3066 return -EINVAL;
3067
2999 rtnl_lock(); 3068 rtnl_lock();
3000 3069
3001 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 3070 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
3002 if (err) 3071 if (err)
3003 goto unlock_rtnl; 3072 goto unlock_rtnl;
3004 3073
3005 if (!drv->ops->auth) { 3074 if (!rdev->ops->auth) {
3006 err = -EOPNOTSUPP; 3075 err = -EOPNOTSUPP;
3007 goto out; 3076 goto out;
3008 } 3077 }
@@ -3017,69 +3086,127 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
3017 goto out; 3086 goto out;
3018 } 3087 }
3019 3088
3020 wiphy = &drv->wiphy; 3089 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3021 memset(&req, 0, sizeof(req)); 3090 chan = ieee80211_get_channel(&rdev->wiphy,
3022 3091 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3023 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 3092 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) {
3024 3093 err = -EINVAL;
3025 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 3094 goto out;
3026 req.chan = ieee80211_get_channel(
3027 wiphy,
3028 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3029 if (!req.chan) {
3030 err = -EINVAL;
3031 goto out;
3032 }
3033 } 3095 }
3034 3096
3035 if (info->attrs[NL80211_ATTR_SSID]) { 3097 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3036 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 3098 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3037 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3038 }
3039 3099
3040 if (info->attrs[NL80211_ATTR_IE]) { 3100 if (info->attrs[NL80211_ATTR_IE]) {
3041 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 3101 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3042 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 3102 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3043 } 3103 }
3044 3104
3045 req.auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 3105 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
3046 if (!nl80211_valid_auth_type(req.auth_type)) { 3106 if (!nl80211_valid_auth_type(auth_type)) {
3047 err = -EINVAL; 3107 err = -EINVAL;
3048 goto out; 3108 goto out;
3049 } 3109 }
3050 3110
3051 err = drv->ops->auth(&drv->wiphy, dev, &req); 3111 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
3112 ssid, ssid_len, ie, ie_len);
3052 3113
3053out: 3114out:
3054 cfg80211_put_dev(drv); 3115 cfg80211_unlock_rdev(rdev);
3055 dev_put(dev); 3116 dev_put(dev);
3056unlock_rtnl: 3117unlock_rtnl:
3057 rtnl_unlock(); 3118 rtnl_unlock();
3058 return err; 3119 return err;
3059} 3120}
3060 3121
3122static int nl80211_crypto_settings(struct genl_info *info,
3123 struct cfg80211_crypto_settings *settings,
3124 int cipher_limit)
3125{
3126 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
3127
3128 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
3129 void *data;
3130 int len, i;
3131
3132 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
3133 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
3134 settings->n_ciphers_pairwise = len / sizeof(u32);
3135
3136 if (len % sizeof(u32))
3137 return -EINVAL;
3138
3139 if (settings->n_ciphers_pairwise > cipher_limit)
3140 return -EINVAL;
3141
3142 memcpy(settings->ciphers_pairwise, data, len);
3143
3144 for (i = 0; i < settings->n_ciphers_pairwise; i++)
3145 if (!nl80211_valid_cipher_suite(
3146 settings->ciphers_pairwise[i]))
3147 return -EINVAL;
3148 }
3149
3150 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
3151 settings->cipher_group =
3152 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
3153 if (!nl80211_valid_cipher_suite(settings->cipher_group))
3154 return -EINVAL;
3155 }
3156
3157 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
3158 settings->wpa_versions =
3159 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
3160 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
3161 return -EINVAL;
3162 }
3163
3164 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
3165 void *data;
3166 int len, i;
3167
3168 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
3169 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
3170 settings->n_akm_suites = len / sizeof(u32);
3171
3172 if (len % sizeof(u32))
3173 return -EINVAL;
3174
3175 memcpy(settings->akm_suites, data, len);
3176
3177 for (i = 0; i < settings->n_ciphers_pairwise; i++)
3178 if (!nl80211_valid_akm_suite(settings->akm_suites[i]))
3179 return -EINVAL;
3180 }
3181
3182 return 0;
3183}
3184
3061static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) 3185static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
3062{ 3186{
3063 struct cfg80211_registered_device *drv; 3187 struct cfg80211_registered_device *rdev;
3064 struct net_device *dev; 3188 struct net_device *dev;
3065 struct cfg80211_assoc_request req; 3189 struct cfg80211_crypto_settings crypto;
3066 struct wiphy *wiphy; 3190 struct ieee80211_channel *chan;
3067 int err; 3191 const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
3192 int err, ssid_len, ie_len = 0;
3193 bool use_mfp = false;
3068 3194
3069 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) 3195 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3070 return -EINVAL; 3196 return -EINVAL;
3071 3197
3072 if (!info->attrs[NL80211_ATTR_MAC] || 3198 if (!info->attrs[NL80211_ATTR_MAC] ||
3073 !info->attrs[NL80211_ATTR_SSID]) 3199 !info->attrs[NL80211_ATTR_SSID] ||
3200 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
3074 return -EINVAL; 3201 return -EINVAL;
3075 3202
3076 rtnl_lock(); 3203 rtnl_lock();
3077 3204
3078 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 3205 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
3079 if (err) 3206 if (err)
3080 goto unlock_rtnl; 3207 goto unlock_rtnl;
3081 3208
3082 if (!drv->ops->assoc) { 3209 if (!rdev->ops->assoc) {
3083 err = -EOPNOTSUPP; 3210 err = -EOPNOTSUPP;
3084 goto out; 3211 goto out;
3085 } 3212 }
@@ -3094,46 +3221,45 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
3094 goto out; 3221 goto out;
3095 } 3222 }
3096 3223
3097 wiphy = &drv->wiphy; 3224 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3098 memset(&req, 0, sizeof(req));
3099
3100 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3101 3225
3102 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 3226 chan = ieee80211_get_channel(&rdev->wiphy,
3103 req.chan = ieee80211_get_channel( 3227 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3104 wiphy, 3228 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) {
3105 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 3229 err = -EINVAL;
3106 if (!req.chan) { 3230 goto out;
3107 err = -EINVAL;
3108 goto out;
3109 }
3110 } 3231 }
3111 3232
3112 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 3233 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3113 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 3234 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3114 3235
3115 if (info->attrs[NL80211_ATTR_IE]) { 3236 if (info->attrs[NL80211_ATTR_IE]) {
3116 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 3237 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3117 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 3238 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3118 } 3239 }
3119 3240
3120 if (info->attrs[NL80211_ATTR_USE_MFP]) { 3241 if (info->attrs[NL80211_ATTR_USE_MFP]) {
3121 enum nl80211_mfp use_mfp = 3242 enum nl80211_mfp mfp =
3122 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 3243 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
3123 if (use_mfp == NL80211_MFP_REQUIRED) 3244 if (mfp == NL80211_MFP_REQUIRED)
3124 req.use_mfp = true; 3245 use_mfp = true;
3125 else if (use_mfp != NL80211_MFP_NO) { 3246 else if (mfp != NL80211_MFP_NO) {
3126 err = -EINVAL; 3247 err = -EINVAL;
3127 goto out; 3248 goto out;
3128 } 3249 }
3129 } 3250 }
3130 3251
3131 req.control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; 3252 if (info->attrs[NL80211_ATTR_PREV_BSSID])
3253 prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
3132 3254
3133 err = drv->ops->assoc(&drv->wiphy, dev, &req); 3255 err = nl80211_crypto_settings(info, &crypto, 1);
3256 if (!err)
3257 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
3258 ssid, ssid_len, ie, ie_len, use_mfp,
3259 &crypto);
3134 3260
3135out: 3261out:
3136 cfg80211_put_dev(drv); 3262 cfg80211_unlock_rdev(rdev);
3137 dev_put(dev); 3263 dev_put(dev);
3138unlock_rtnl: 3264unlock_rtnl:
3139 rtnl_unlock(); 3265 rtnl_unlock();
@@ -3142,11 +3268,11 @@ unlock_rtnl:
3142 3268
3143static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) 3269static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
3144{ 3270{
3145 struct cfg80211_registered_device *drv; 3271 struct cfg80211_registered_device *rdev;
3146 struct net_device *dev; 3272 struct net_device *dev;
3147 struct cfg80211_deauth_request req; 3273 const u8 *ie = NULL, *bssid;
3148 struct wiphy *wiphy; 3274 int err, ie_len = 0;
3149 int err; 3275 u16 reason_code;
3150 3276
3151 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) 3277 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3152 return -EINVAL; 3278 return -EINVAL;
@@ -3159,11 +3285,11 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
3159 3285
3160 rtnl_lock(); 3286 rtnl_lock();
3161 3287
3162 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 3288 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
3163 if (err) 3289 if (err)
3164 goto unlock_rtnl; 3290 goto unlock_rtnl;
3165 3291
3166 if (!drv->ops->deauth) { 3292 if (!rdev->ops->deauth) {
3167 err = -EOPNOTSUPP; 3293 err = -EOPNOTSUPP;
3168 goto out; 3294 goto out;
3169 } 3295 }
@@ -3178,27 +3304,24 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
3178 goto out; 3304 goto out;
3179 } 3305 }
3180 3306
3181 wiphy = &drv->wiphy; 3307 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3182 memset(&req, 0, sizeof(req));
3183
3184 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3185 3308
3186 req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 3309 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3187 if (req.reason_code == 0) { 3310 if (reason_code == 0) {
3188 /* Reason Code 0 is reserved */ 3311 /* Reason Code 0 is reserved */
3189 err = -EINVAL; 3312 err = -EINVAL;
3190 goto out; 3313 goto out;
3191 } 3314 }
3192 3315
3193 if (info->attrs[NL80211_ATTR_IE]) { 3316 if (info->attrs[NL80211_ATTR_IE]) {
3194 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 3317 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3195 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 3318 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3196 } 3319 }
3197 3320
3198 err = drv->ops->deauth(&drv->wiphy, dev, &req); 3321 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code);
3199 3322
3200out: 3323out:
3201 cfg80211_put_dev(drv); 3324 cfg80211_unlock_rdev(rdev);
3202 dev_put(dev); 3325 dev_put(dev);
3203unlock_rtnl: 3326unlock_rtnl:
3204 rtnl_unlock(); 3327 rtnl_unlock();
@@ -3207,11 +3330,11 @@ unlock_rtnl:
3207 3330
3208static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) 3331static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
3209{ 3332{
3210 struct cfg80211_registered_device *drv; 3333 struct cfg80211_registered_device *rdev;
3211 struct net_device *dev; 3334 struct net_device *dev;
3212 struct cfg80211_disassoc_request req; 3335 const u8 *ie = NULL, *bssid;
3213 struct wiphy *wiphy; 3336 int err, ie_len = 0;
3214 int err; 3337 u16 reason_code;
3215 3338
3216 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) 3339 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3217 return -EINVAL; 3340 return -EINVAL;
@@ -3224,11 +3347,11 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
3224 3347
3225 rtnl_lock(); 3348 rtnl_lock();
3226 3349
3227 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 3350 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
3228 if (err) 3351 if (err)
3229 goto unlock_rtnl; 3352 goto unlock_rtnl;
3230 3353
3231 if (!drv->ops->disassoc) { 3354 if (!rdev->ops->disassoc) {
3232 err = -EOPNOTSUPP; 3355 err = -EOPNOTSUPP;
3233 goto out; 3356 goto out;
3234 } 3357 }
@@ -3243,27 +3366,24 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
3243 goto out; 3366 goto out;
3244 } 3367 }
3245 3368
3246 wiphy = &drv->wiphy; 3369 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3247 memset(&req, 0, sizeof(req));
3248 3370
3249 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 3371 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3250 3372 if (reason_code == 0) {
3251 req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3252 if (req.reason_code == 0) {
3253 /* Reason Code 0 is reserved */ 3373 /* Reason Code 0 is reserved */
3254 err = -EINVAL; 3374 err = -EINVAL;
3255 goto out; 3375 goto out;
3256 } 3376 }
3257 3377
3258 if (info->attrs[NL80211_ATTR_IE]) { 3378 if (info->attrs[NL80211_ATTR_IE]) {
3259 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 3379 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3260 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 3380 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3261 } 3381 }
3262 3382
3263 err = drv->ops->disassoc(&drv->wiphy, dev, &req); 3383 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code);
3264 3384
3265out: 3385out:
3266 cfg80211_put_dev(drv); 3386 cfg80211_unlock_rdev(rdev);
3267 dev_put(dev); 3387 dev_put(dev);
3268unlock_rtnl: 3388unlock_rtnl:
3269 rtnl_unlock(); 3389 rtnl_unlock();
@@ -3272,7 +3392,7 @@ unlock_rtnl:
3272 3392
3273static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) 3393static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3274{ 3394{
3275 struct cfg80211_registered_device *drv; 3395 struct cfg80211_registered_device *rdev;
3276 struct net_device *dev; 3396 struct net_device *dev;
3277 struct cfg80211_ibss_params ibss; 3397 struct cfg80211_ibss_params ibss;
3278 struct wiphy *wiphy; 3398 struct wiphy *wiphy;
@@ -3299,11 +3419,11 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3299 3419
3300 rtnl_lock(); 3420 rtnl_lock();
3301 3421
3302 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 3422 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
3303 if (err) 3423 if (err)
3304 goto unlock_rtnl; 3424 goto unlock_rtnl;
3305 3425
3306 if (!drv->ops->join_ibss) { 3426 if (!rdev->ops->join_ibss) {
3307 err = -EOPNOTSUPP; 3427 err = -EOPNOTSUPP;
3308 goto out; 3428 goto out;
3309 } 3429 }
@@ -3318,7 +3438,7 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3318 goto out; 3438 goto out;
3319 } 3439 }
3320 3440
3321 wiphy = &drv->wiphy; 3441 wiphy = &rdev->wiphy;
3322 3442
3323 if (info->attrs[NL80211_ATTR_MAC]) 3443 if (info->attrs[NL80211_ATTR_MAC])
3324 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 3444 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
@@ -3341,10 +3461,10 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3341 3461
3342 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; 3462 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
3343 3463
3344 err = cfg80211_join_ibss(drv, dev, &ibss); 3464 err = cfg80211_join_ibss(rdev, dev, &ibss);
3345 3465
3346out: 3466out:
3347 cfg80211_put_dev(drv); 3467 cfg80211_unlock_rdev(rdev);
3348 dev_put(dev); 3468 dev_put(dev);
3349unlock_rtnl: 3469unlock_rtnl:
3350 rtnl_unlock(); 3470 rtnl_unlock();
@@ -3353,17 +3473,17 @@ unlock_rtnl:
3353 3473
3354static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) 3474static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
3355{ 3475{
3356 struct cfg80211_registered_device *drv; 3476 struct cfg80211_registered_device *rdev;
3357 struct net_device *dev; 3477 struct net_device *dev;
3358 int err; 3478 int err;
3359 3479
3360 rtnl_lock(); 3480 rtnl_lock();
3361 3481
3362 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 3482 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
3363 if (err) 3483 if (err)
3364 goto unlock_rtnl; 3484 goto unlock_rtnl;
3365 3485
3366 if (!drv->ops->leave_ibss) { 3486 if (!rdev->ops->leave_ibss) {
3367 err = -EOPNOTSUPP; 3487 err = -EOPNOTSUPP;
3368 goto out; 3488 goto out;
3369 } 3489 }
@@ -3378,10 +3498,257 @@ static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
3378 goto out; 3498 goto out;
3379 } 3499 }
3380 3500
3381 err = cfg80211_leave_ibss(drv, dev, false); 3501 err = cfg80211_leave_ibss(rdev, dev, false);
3502
3503out:
3504 cfg80211_unlock_rdev(rdev);
3505 dev_put(dev);
3506unlock_rtnl:
3507 rtnl_unlock();
3508 return err;
3509}
3510
3511#ifdef CONFIG_NL80211_TESTMODE
3512static struct genl_multicast_group nl80211_testmode_mcgrp = {
3513 .name = "testmode",
3514};
3515
3516static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
3517{
3518 struct cfg80211_registered_device *rdev;
3519 int err;
3520
3521 if (!info->attrs[NL80211_ATTR_TESTDATA])
3522 return -EINVAL;
3523
3524 rtnl_lock();
3525
3526 rdev = cfg80211_get_dev_from_info(info);
3527 if (IS_ERR(rdev)) {
3528 err = PTR_ERR(rdev);
3529 goto unlock_rtnl;
3530 }
3531
3532 err = -EOPNOTSUPP;
3533 if (rdev->ops->testmode_cmd) {
3534 rdev->testmode_info = info;
3535 err = rdev->ops->testmode_cmd(&rdev->wiphy,
3536 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
3537 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
3538 rdev->testmode_info = NULL;
3539 }
3540
3541 cfg80211_unlock_rdev(rdev);
3542
3543 unlock_rtnl:
3544 rtnl_unlock();
3545 return err;
3546}
3547
3548static struct sk_buff *
3549__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
3550 int approxlen, u32 pid, u32 seq, gfp_t gfp)
3551{
3552 struct sk_buff *skb;
3553 void *hdr;
3554 struct nlattr *data;
3555
3556 skb = nlmsg_new(approxlen + 100, gfp);
3557 if (!skb)
3558 return NULL;
3559
3560 hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
3561 if (!hdr) {
3562 kfree_skb(skb);
3563 return NULL;
3564 }
3565
3566 NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3567 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
3568
3569 ((void **)skb->cb)[0] = rdev;
3570 ((void **)skb->cb)[1] = hdr;
3571 ((void **)skb->cb)[2] = data;
3572
3573 return skb;
3574
3575 nla_put_failure:
3576 kfree_skb(skb);
3577 return NULL;
3578}
3579
3580struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
3581 int approxlen)
3582{
3583 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
3584
3585 if (WARN_ON(!rdev->testmode_info))
3586 return NULL;
3587
3588 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
3589 rdev->testmode_info->snd_pid,
3590 rdev->testmode_info->snd_seq,
3591 GFP_KERNEL);
3592}
3593EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
3594
3595int cfg80211_testmode_reply(struct sk_buff *skb)
3596{
3597 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
3598 void *hdr = ((void **)skb->cb)[1];
3599 struct nlattr *data = ((void **)skb->cb)[2];
3600
3601 if (WARN_ON(!rdev->testmode_info)) {
3602 kfree_skb(skb);
3603 return -EINVAL;
3604 }
3605
3606 nla_nest_end(skb, data);
3607 genlmsg_end(skb, hdr);
3608 return genlmsg_reply(skb, rdev->testmode_info);
3609}
3610EXPORT_SYMBOL(cfg80211_testmode_reply);
3611
3612struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
3613 int approxlen, gfp_t gfp)
3614{
3615 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
3616
3617 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
3618}
3619EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
3620
3621void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
3622{
3623 void *hdr = ((void **)skb->cb)[1];
3624 struct nlattr *data = ((void **)skb->cb)[2];
3625
3626 nla_nest_end(skb, data);
3627 genlmsg_end(skb, hdr);
3628 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
3629}
3630EXPORT_SYMBOL(cfg80211_testmode_event);
3631#endif
3632
3633static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
3634{
3635 struct cfg80211_registered_device *rdev;
3636 struct net_device *dev;
3637 struct cfg80211_connect_params connect;
3638 struct wiphy *wiphy;
3639 int err;
3640
3641 memset(&connect, 0, sizeof(connect));
3642
3643 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3644 return -EINVAL;
3645
3646 if (!info->attrs[NL80211_ATTR_SSID] ||
3647 !nla_len(info->attrs[NL80211_ATTR_SSID]))
3648 return -EINVAL;
3649
3650 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3651 connect.auth_type =
3652 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
3653 if (!nl80211_valid_auth_type(connect.auth_type))
3654 return -EINVAL;
3655 } else
3656 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3657
3658 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
3659
3660 err = nl80211_crypto_settings(info, &connect.crypto,
3661 NL80211_MAX_NR_CIPHER_SUITES);
3662 if (err)
3663 return err;
3664 rtnl_lock();
3665
3666 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
3667 if (err)
3668 goto unlock_rtnl;
3669
3670 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
3671 err = -EOPNOTSUPP;
3672 goto out;
3673 }
3674
3675 if (!netif_running(dev)) {
3676 err = -ENETDOWN;
3677 goto out;
3678 }
3679
3680 wiphy = &rdev->wiphy;
3681
3682 connect.bssid = NULL;
3683 connect.channel = NULL;
3684 connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
3685
3686 if (info->attrs[NL80211_ATTR_MAC])
3687 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3688 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3689 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3690
3691 if (info->attrs[NL80211_ATTR_IE]) {
3692 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3693 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3694 }
3695
3696 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
3697 connect.channel =
3698 ieee80211_get_channel(wiphy,
3699 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3700 if (!connect.channel ||
3701 connect.channel->flags & IEEE80211_CHAN_DISABLED) {
3702 err = -EINVAL;
3703 goto out;
3704 }
3705 }
3706
3707 err = cfg80211_connect(rdev, dev, &connect);
3382 3708
3383out: 3709out:
3384 cfg80211_put_dev(drv); 3710 cfg80211_unlock_rdev(rdev);
3711 dev_put(dev);
3712unlock_rtnl:
3713 rtnl_unlock();
3714 return err;
3715}
3716
3717static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
3718{
3719 struct cfg80211_registered_device *rdev;
3720 struct net_device *dev;
3721 int err;
3722 u16 reason;
3723
3724 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3725 reason = WLAN_REASON_DEAUTH_LEAVING;
3726 else
3727 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3728
3729 if (reason == 0)
3730 return -EINVAL;
3731
3732 rtnl_lock();
3733
3734 err = get_rdev_dev_by_info_ifindex(info->attrs, &rdev, &dev);
3735 if (err)
3736 goto unlock_rtnl;
3737
3738 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
3739 err = -EOPNOTSUPP;
3740 goto out;
3741 }
3742
3743 if (!netif_running(dev)) {
3744 err = -ENETDOWN;
3745 goto out;
3746 }
3747
3748 err = cfg80211_disconnect(rdev, dev, reason, true);
3749
3750out:
3751 cfg80211_unlock_rdev(rdev);
3385 dev_put(dev); 3752 dev_put(dev);
3386unlock_rtnl: 3753unlock_rtnl:
3387 rtnl_unlock(); 3754 rtnl_unlock();
@@ -3601,6 +3968,26 @@ static struct genl_ops nl80211_ops[] = {
3601 .policy = nl80211_policy, 3968 .policy = nl80211_policy,
3602 .flags = GENL_ADMIN_PERM, 3969 .flags = GENL_ADMIN_PERM,
3603 }, 3970 },
3971#ifdef CONFIG_NL80211_TESTMODE
3972 {
3973 .cmd = NL80211_CMD_TESTMODE,
3974 .doit = nl80211_testmode_do,
3975 .policy = nl80211_policy,
3976 .flags = GENL_ADMIN_PERM,
3977 },
3978#endif
3979 {
3980 .cmd = NL80211_CMD_CONNECT,
3981 .doit = nl80211_connect,
3982 .policy = nl80211_policy,
3983 .flags = GENL_ADMIN_PERM,
3984 },
3985 {
3986 .cmd = NL80211_CMD_DISCONNECT,
3987 .doit = nl80211_disconnect,
3988 .policy = nl80211_policy,
3989 .flags = GENL_ADMIN_PERM,
3990 },
3604}; 3991};
3605static struct genl_multicast_group nl80211_mlme_mcgrp = { 3992static struct genl_multicast_group nl80211_mlme_mcgrp = {
3606 .name = "mlme", 3993 .name = "mlme",
@@ -3642,6 +4029,8 @@ static int nl80211_add_scan_req(struct sk_buff *msg,
3642 struct nlattr *nest; 4029 struct nlattr *nest;
3643 int i; 4030 int i;
3644 4031
4032 ASSERT_RDEV_LOCK(rdev);
4033
3645 if (WARN_ON(!req)) 4034 if (WARN_ON(!req))
3646 return 0; 4035 return 0;
3647 4036
@@ -3667,11 +4056,11 @@ static int nl80211_add_scan_req(struct sk_buff *msg,
3667 return -ENOBUFS; 4056 return -ENOBUFS;
3668} 4057}
3669 4058
3670static int nl80211_send_scan_donemsg(struct sk_buff *msg, 4059static int nl80211_send_scan_msg(struct sk_buff *msg,
3671 struct cfg80211_registered_device *rdev, 4060 struct cfg80211_registered_device *rdev,
3672 struct net_device *netdev, 4061 struct net_device *netdev,
3673 u32 pid, u32 seq, int flags, 4062 u32 pid, u32 seq, int flags,
3674 u32 cmd) 4063 u32 cmd)
3675{ 4064{
3676 void *hdr; 4065 void *hdr;
3677 4066
@@ -3692,6 +4081,24 @@ static int nl80211_send_scan_donemsg(struct sk_buff *msg,
3692 return -EMSGSIZE; 4081 return -EMSGSIZE;
3693} 4082}
3694 4083
4084void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
4085 struct net_device *netdev)
4086{
4087 struct sk_buff *msg;
4088
4089 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
4090 if (!msg)
4091 return;
4092
4093 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
4094 NL80211_CMD_TRIGGER_SCAN) < 0) {
4095 nlmsg_free(msg);
4096 return;
4097 }
4098
4099 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
4100}
4101
3695void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, 4102void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
3696 struct net_device *netdev) 4103 struct net_device *netdev)
3697{ 4104{
@@ -3701,8 +4108,8 @@ void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
3701 if (!msg) 4108 if (!msg)
3702 return; 4109 return;
3703 4110
3704 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0, 4111 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
3705 NL80211_CMD_NEW_SCAN_RESULTS) < 0) { 4112 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
3706 nlmsg_free(msg); 4113 nlmsg_free(msg);
3707 return; 4114 return;
3708 } 4115 }
@@ -3719,8 +4126,8 @@ void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
3719 if (!msg) 4126 if (!msg)
3720 return; 4127 return;
3721 4128
3722 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0, 4129 if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
3723 NL80211_CMD_SCAN_ABORTED) < 0) { 4130 NL80211_CMD_SCAN_ABORTED) < 0) {
3724 nlmsg_free(msg); 4131 nlmsg_free(msg);
3725 return; 4132 return;
3726 } 4133 }
@@ -3786,12 +4193,12 @@ nla_put_failure:
3786static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, 4193static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
3787 struct net_device *netdev, 4194 struct net_device *netdev,
3788 const u8 *buf, size_t len, 4195 const u8 *buf, size_t len,
3789 enum nl80211_commands cmd) 4196 enum nl80211_commands cmd, gfp_t gfp)
3790{ 4197{
3791 struct sk_buff *msg; 4198 struct sk_buff *msg;
3792 void *hdr; 4199 void *hdr;
3793 4200
3794 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 4201 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
3795 if (!msg) 4202 if (!msg)
3796 return; 4203 return;
3797 4204
@@ -3810,7 +4217,7 @@ static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
3810 return; 4217 return;
3811 } 4218 }
3812 4219
3813 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC); 4220 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
3814 return; 4221 return;
3815 4222
3816 nla_put_failure: 4223 nla_put_failure:
@@ -3819,42 +4226,45 @@ static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
3819} 4226}
3820 4227
3821void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, 4228void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
3822 struct net_device *netdev, const u8 *buf, size_t len) 4229 struct net_device *netdev, const u8 *buf,
4230 size_t len, gfp_t gfp)
3823{ 4231{
3824 nl80211_send_mlme_event(rdev, netdev, buf, len, 4232 nl80211_send_mlme_event(rdev, netdev, buf, len,
3825 NL80211_CMD_AUTHENTICATE); 4233 NL80211_CMD_AUTHENTICATE, gfp);
3826} 4234}
3827 4235
3828void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, 4236void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
3829 struct net_device *netdev, const u8 *buf, 4237 struct net_device *netdev, const u8 *buf,
3830 size_t len) 4238 size_t len, gfp_t gfp)
3831{ 4239{
3832 nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE); 4240 nl80211_send_mlme_event(rdev, netdev, buf, len,
4241 NL80211_CMD_ASSOCIATE, gfp);
3833} 4242}
3834 4243
3835void nl80211_send_deauth(struct cfg80211_registered_device *rdev, 4244void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
3836 struct net_device *netdev, const u8 *buf, size_t len) 4245 struct net_device *netdev, const u8 *buf,
4246 size_t len, gfp_t gfp)
3837{ 4247{
3838 nl80211_send_mlme_event(rdev, netdev, buf, len, 4248 nl80211_send_mlme_event(rdev, netdev, buf, len,
3839 NL80211_CMD_DEAUTHENTICATE); 4249 NL80211_CMD_DEAUTHENTICATE, gfp);
3840} 4250}
3841 4251
3842void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, 4252void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
3843 struct net_device *netdev, const u8 *buf, 4253 struct net_device *netdev, const u8 *buf,
3844 size_t len) 4254 size_t len, gfp_t gfp)
3845{ 4255{
3846 nl80211_send_mlme_event(rdev, netdev, buf, len, 4256 nl80211_send_mlme_event(rdev, netdev, buf, len,
3847 NL80211_CMD_DISASSOCIATE); 4257 NL80211_CMD_DISASSOCIATE, gfp);
3848} 4258}
3849 4259
3850static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, 4260static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
3851 struct net_device *netdev, int cmd, 4261 struct net_device *netdev, int cmd,
3852 const u8 *addr) 4262 const u8 *addr, gfp_t gfp)
3853{ 4263{
3854 struct sk_buff *msg; 4264 struct sk_buff *msg;
3855 void *hdr; 4265 void *hdr;
3856 4266
3857 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 4267 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
3858 if (!msg) 4268 if (!msg)
3859 return; 4269 return;
3860 4270
@@ -3874,7 +4284,7 @@ static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
3874 return; 4284 return;
3875 } 4285 }
3876 4286
3877 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC); 4287 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
3878 return; 4288 return;
3879 4289
3880 nla_put_failure: 4290 nla_put_failure:
@@ -3883,16 +4293,142 @@ static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
3883} 4293}
3884 4294
3885void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, 4295void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
3886 struct net_device *netdev, const u8 *addr) 4296 struct net_device *netdev, const u8 *addr,
4297 gfp_t gfp)
3887{ 4298{
3888 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, 4299 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
3889 addr); 4300 addr, gfp);
3890} 4301}
3891 4302
3892void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, 4303void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
3893 struct net_device *netdev, const u8 *addr) 4304 struct net_device *netdev, const u8 *addr,
4305 gfp_t gfp)
3894{ 4306{
3895 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, addr); 4307 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
4308 addr, gfp);
4309}
4310
4311void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
4312 struct net_device *netdev, const u8 *bssid,
4313 const u8 *req_ie, size_t req_ie_len,
4314 const u8 *resp_ie, size_t resp_ie_len,
4315 u16 status, gfp_t gfp)
4316{
4317 struct sk_buff *msg;
4318 void *hdr;
4319
4320 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
4321 if (!msg)
4322 return;
4323
4324 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
4325 if (!hdr) {
4326 nlmsg_free(msg);
4327 return;
4328 }
4329
4330 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4331 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
4332 if (bssid)
4333 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
4334 NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
4335 if (req_ie)
4336 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
4337 if (resp_ie)
4338 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
4339
4340 if (genlmsg_end(msg, hdr) < 0) {
4341 nlmsg_free(msg);
4342 return;
4343 }
4344
4345 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
4346 return;
4347
4348 nla_put_failure:
4349 genlmsg_cancel(msg, hdr);
4350 nlmsg_free(msg);
4351
4352}
4353
4354void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
4355 struct net_device *netdev, const u8 *bssid,
4356 const u8 *req_ie, size_t req_ie_len,
4357 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
4358{
4359 struct sk_buff *msg;
4360 void *hdr;
4361
4362 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
4363 if (!msg)
4364 return;
4365
4366 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
4367 if (!hdr) {
4368 nlmsg_free(msg);
4369 return;
4370 }
4371
4372 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4373 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
4374 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
4375 if (req_ie)
4376 NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
4377 if (resp_ie)
4378 NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
4379
4380 if (genlmsg_end(msg, hdr) < 0) {
4381 nlmsg_free(msg);
4382 return;
4383 }
4384
4385 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
4386 return;
4387
4388 nla_put_failure:
4389 genlmsg_cancel(msg, hdr);
4390 nlmsg_free(msg);
4391
4392}
4393
4394void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
4395 struct net_device *netdev, u16 reason,
4396 const u8 *ie, size_t ie_len, bool from_ap)
4397{
4398 struct sk_buff *msg;
4399 void *hdr;
4400
4401 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
4402 if (!msg)
4403 return;
4404
4405 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
4406 if (!hdr) {
4407 nlmsg_free(msg);
4408 return;
4409 }
4410
4411 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
4412 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
4413 if (from_ap && reason)
4414 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
4415 if (from_ap)
4416 NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
4417 if (ie)
4418 NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
4419
4420 if (genlmsg_end(msg, hdr) < 0) {
4421 nlmsg_free(msg);
4422 return;
4423 }
4424
4425 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL);
4426 return;
4427
4428 nla_put_failure:
4429 genlmsg_cancel(msg, hdr);
4430 nlmsg_free(msg);
4431
3896} 4432}
3897 4433
3898void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, 4434void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
@@ -3932,12 +4468,12 @@ void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
3932void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, 4468void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
3933 struct net_device *netdev, const u8 *addr, 4469 struct net_device *netdev, const u8 *addr,
3934 enum nl80211_key_type key_type, int key_id, 4470 enum nl80211_key_type key_type, int key_id,
3935 const u8 *tsc) 4471 const u8 *tsc, gfp_t gfp)
3936{ 4472{
3937 struct sk_buff *msg; 4473 struct sk_buff *msg;
3938 void *hdr; 4474 void *hdr;
3939 4475
3940 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 4476 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
3941 if (!msg) 4477 if (!msg)
3942 return; 4478 return;
3943 4479
@@ -3961,7 +4497,7 @@ void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
3961 return; 4497 return;
3962 } 4498 }
3963 4499
3964 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC); 4500 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
3965 return; 4501 return;
3966 4502
3967 nla_put_failure: 4503 nla_put_failure:
@@ -4050,6 +4586,12 @@ int nl80211_init(void)
4050 if (err) 4586 if (err)
4051 goto err_out; 4587 goto err_out;
4052 4588
4589#ifdef CONFIG_NL80211_TESTMODE
4590 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
4591 if (err)
4592 goto err_out;
4593#endif
4594
4053 return 0; 4595 return 0;
4054 err_out: 4596 err_out:
4055 genl_unregister_family(&nl80211_fam); 4597 genl_unregister_family(&nl80211_fam);
diff --git a/net/wireless/nl80211.h b/net/wireless/nl80211.h
index 5c12ad13499b..44cc2a76a1b0 100644
--- a/net/wireless/nl80211.h
+++ b/net/wireless/nl80211.h
@@ -3,39 +3,54 @@
3 3
4#include "core.h" 4#include "core.h"
5 5
6extern int nl80211_init(void); 6int nl80211_init(void);
7extern void nl80211_exit(void); 7void nl80211_exit(void);
8extern void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev); 8void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev);
9extern void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, 9void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
10 struct net_device *netdev); 10 struct net_device *netdev);
11extern void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, 11void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
12 struct net_device *netdev); 12 struct net_device *netdev);
13extern void nl80211_send_reg_change_event(struct regulatory_request *request); 13void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
14extern void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, 14 struct net_device *netdev);
15 struct net_device *netdev, 15void nl80211_send_reg_change_event(struct regulatory_request *request);
16 const u8 *buf, size_t len); 16void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
17extern void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, 17 struct net_device *netdev,
18 struct net_device *netdev, 18 const u8 *buf, size_t len, gfp_t gfp);
19 const u8 *buf, size_t len); 19void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
20extern void nl80211_send_deauth(struct cfg80211_registered_device *rdev, 20 struct net_device *netdev,
21 const u8 *buf, size_t len, gfp_t gfp);
22void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
23 struct net_device *netdev,
24 const u8 *buf, size_t len, gfp_t gfp);
25void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
26 struct net_device *netdev,
27 const u8 *buf, size_t len, gfp_t gfp);
28void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
29 struct net_device *netdev,
30 const u8 *addr, gfp_t gfp);
31void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
21 struct net_device *netdev, 32 struct net_device *netdev,
22 const u8 *buf, size_t len); 33 const u8 *addr, gfp_t gfp);
23extern void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, 34void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
24 struct net_device *netdev, 35 struct net_device *netdev, const u8 *bssid,
25 const u8 *buf, size_t len); 36 const u8 *req_ie, size_t req_ie_len,
26extern void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, 37 const u8 *resp_ie, size_t resp_ie_len,
27 struct net_device *netdev, 38 u16 status, gfp_t gfp);
28 const u8 *addr); 39void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
29extern void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, 40 struct net_device *netdev, const u8 *bssid,
30 struct net_device *netdev, 41 const u8 *req_ie, size_t req_ie_len,
31 const u8 *addr); 42 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp);
32extern void 43void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
44 struct net_device *netdev, u16 reason,
45 const u8 *ie, size_t ie_len, bool from_ap);
46
47void
33nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, 48nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
34 struct net_device *netdev, const u8 *addr, 49 struct net_device *netdev, const u8 *addr,
35 enum nl80211_key_type key_type, 50 enum nl80211_key_type key_type,
36 int key_id, const u8 *tsc); 51 int key_id, const u8 *tsc, gfp_t gfp);
37 52
38extern void 53void
39nl80211_send_beacon_hint_event(struct wiphy *wiphy, 54nl80211_send_beacon_hint_event(struct wiphy *wiphy,
40 struct ieee80211_channel *channel_before, 55 struct ieee80211_channel *channel_before,
41 struct ieee80211_channel *channel_after); 56 struct ieee80211_channel *channel_after);
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 5e14371cda70..2b4a6c66f5ae 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1061,10 +1061,10 @@ static bool ignore_reg_update(struct wiphy *wiphy,
1061 1061
1062static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator) 1062static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
1063{ 1063{
1064 struct cfg80211_registered_device *drv; 1064 struct cfg80211_registered_device *rdev;
1065 1065
1066 list_for_each_entry(drv, &cfg80211_drv_list, list) 1066 list_for_each_entry(rdev, &cfg80211_rdev_list, list)
1067 wiphy_update_regulatory(&drv->wiphy, initiator); 1067 wiphy_update_regulatory(&rdev->wiphy, initiator);
1068} 1068}
1069 1069
1070static void handle_reg_beacon(struct wiphy *wiphy, 1070static void handle_reg_beacon(struct wiphy *wiphy,
@@ -1614,7 +1614,7 @@ static void reg_process_pending_hints(void)
1614/* Processes beacon hints -- this has nothing to do with country IEs */ 1614/* Processes beacon hints -- this has nothing to do with country IEs */
1615static void reg_process_pending_beacon_hints(void) 1615static void reg_process_pending_beacon_hints(void)
1616{ 1616{
1617 struct cfg80211_registered_device *drv; 1617 struct cfg80211_registered_device *rdev;
1618 struct reg_beacon *pending_beacon, *tmp; 1618 struct reg_beacon *pending_beacon, *tmp;
1619 1619
1620 mutex_lock(&cfg80211_mutex); 1620 mutex_lock(&cfg80211_mutex);
@@ -1633,8 +1633,8 @@ static void reg_process_pending_beacon_hints(void)
1633 list_del_init(&pending_beacon->list); 1633 list_del_init(&pending_beacon->list);
1634 1634
1635 /* Applies the beacon hint to current wiphys */ 1635 /* Applies the beacon hint to current wiphys */
1636 list_for_each_entry(drv, &cfg80211_drv_list, list) 1636 list_for_each_entry(rdev, &cfg80211_rdev_list, list)
1637 wiphy_update_new_beacon(&drv->wiphy, pending_beacon); 1637 wiphy_update_new_beacon(&rdev->wiphy, pending_beacon);
1638 1638
1639 /* Remembers the beacon hint for new wiphys or reg changes */ 1639 /* Remembers the beacon hint for new wiphys or reg changes */
1640 list_add_tail(&pending_beacon->list, &reg_beacon_list); 1640 list_add_tail(&pending_beacon->list, &reg_beacon_list);
@@ -1814,23 +1814,23 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1814 if (likely(last_request->initiator == 1814 if (likely(last_request->initiator ==
1815 NL80211_REGDOM_SET_BY_COUNTRY_IE && 1815 NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1816 wiphy_idx_valid(last_request->wiphy_idx))) { 1816 wiphy_idx_valid(last_request->wiphy_idx))) {
1817 struct cfg80211_registered_device *drv_last_ie; 1817 struct cfg80211_registered_device *rdev_last_ie;
1818 1818
1819 drv_last_ie = 1819 rdev_last_ie =
1820 cfg80211_drv_by_wiphy_idx(last_request->wiphy_idx); 1820 cfg80211_rdev_by_wiphy_idx(last_request->wiphy_idx);
1821 1821
1822 /* 1822 /*
1823 * Lets keep this simple -- we trust the first AP 1823 * Lets keep this simple -- we trust the first AP
1824 * after we intersect with CRDA 1824 * after we intersect with CRDA
1825 */ 1825 */
1826 if (likely(&drv_last_ie->wiphy == wiphy)) { 1826 if (likely(&rdev_last_ie->wiphy == wiphy)) {
1827 /* 1827 /*
1828 * Ignore IEs coming in on this wiphy with 1828 * Ignore IEs coming in on this wiphy with
1829 * the same alpha2 and environment cap 1829 * the same alpha2 and environment cap
1830 */ 1830 */
1831 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2, 1831 if (likely(alpha2_equal(rdev_last_ie->country_ie_alpha2,
1832 alpha2) && 1832 alpha2) &&
1833 env == drv_last_ie->env)) { 1833 env == rdev_last_ie->env)) {
1834 goto out; 1834 goto out;
1835 } 1835 }
1836 /* 1836 /*
@@ -1846,9 +1846,9 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1846 * Ignore IEs coming in on two separate wiphys with 1846 * Ignore IEs coming in on two separate wiphys with
1847 * the same alpha2 and environment cap 1847 * the same alpha2 and environment cap
1848 */ 1848 */
1849 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2, 1849 if (likely(alpha2_equal(rdev_last_ie->country_ie_alpha2,
1850 alpha2) && 1850 alpha2) &&
1851 env == drv_last_ie->env)) { 1851 env == rdev_last_ie->env)) {
1852 goto out; 1852 goto out;
1853 } 1853 }
1854 /* We could potentially intersect though */ 1854 /* We could potentially intersect though */
@@ -1995,14 +1995,14 @@ static void print_regdomain(const struct ieee80211_regdomain *rd)
1995 1995
1996 if (last_request->initiator == 1996 if (last_request->initiator ==
1997 NL80211_REGDOM_SET_BY_COUNTRY_IE) { 1997 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1998 struct cfg80211_registered_device *drv; 1998 struct cfg80211_registered_device *rdev;
1999 drv = cfg80211_drv_by_wiphy_idx( 1999 rdev = cfg80211_rdev_by_wiphy_idx(
2000 last_request->wiphy_idx); 2000 last_request->wiphy_idx);
2001 if (drv) { 2001 if (rdev) {
2002 printk(KERN_INFO "cfg80211: Current regulatory " 2002 printk(KERN_INFO "cfg80211: Current regulatory "
2003 "domain updated by AP to: %c%c\n", 2003 "domain updated by AP to: %c%c\n",
2004 drv->country_ie_alpha2[0], 2004 rdev->country_ie_alpha2[0],
2005 drv->country_ie_alpha2[1]); 2005 rdev->country_ie_alpha2[1]);
2006 } else 2006 } else
2007 printk(KERN_INFO "cfg80211: Current regulatory " 2007 printk(KERN_INFO "cfg80211: Current regulatory "
2008 "domain intersected: \n"); 2008 "domain intersected: \n");
@@ -2063,7 +2063,7 @@ static inline void reg_country_ie_process_debug(
2063static int __set_regdom(const struct ieee80211_regdomain *rd) 2063static int __set_regdom(const struct ieee80211_regdomain *rd)
2064{ 2064{
2065 const struct ieee80211_regdomain *intersected_rd = NULL; 2065 const struct ieee80211_regdomain *intersected_rd = NULL;
2066 struct cfg80211_registered_device *drv = NULL; 2066 struct cfg80211_registered_device *rdev = NULL;
2067 struct wiphy *request_wiphy; 2067 struct wiphy *request_wiphy;
2068 /* Some basic sanity checks first */ 2068 /* Some basic sanity checks first */
2069 2069
@@ -2202,11 +2202,11 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2202 if (!intersected_rd) 2202 if (!intersected_rd)
2203 return -EINVAL; 2203 return -EINVAL;
2204 2204
2205 drv = wiphy_to_dev(request_wiphy); 2205 rdev = wiphy_to_dev(request_wiphy);
2206 2206
2207 drv->country_ie_alpha2[0] = rd->alpha2[0]; 2207 rdev->country_ie_alpha2[0] = rd->alpha2[0];
2208 drv->country_ie_alpha2[1] = rd->alpha2[1]; 2208 rdev->country_ie_alpha2[1] = rd->alpha2[1];
2209 drv->env = last_request->country_ie_env; 2209 rdev->env = last_request->country_ie_env;
2210 2210
2211 BUG_ON(intersected_rd == rd); 2211 BUG_ON(intersected_rd == rd);
2212 2212
diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index f8e71b300001..4f552c3f29a3 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -17,20 +17,33 @@
17 17
18#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ) 18#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
19 19
20void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted) 20void __cfg80211_scan_done(struct work_struct *wk)
21{ 21{
22 struct cfg80211_registered_device *rdev;
23 struct cfg80211_scan_request *request;
22 struct net_device *dev; 24 struct net_device *dev;
23#ifdef CONFIG_WIRELESS_EXT 25#ifdef CONFIG_WIRELESS_EXT
24 union iwreq_data wrqu; 26 union iwreq_data wrqu;
25#endif 27#endif
26 28
29 rdev = container_of(wk, struct cfg80211_registered_device,
30 scan_done_wk);
31
32 mutex_lock(&rdev->mtx);
33 request = rdev->scan_req;
34
27 dev = dev_get_by_index(&init_net, request->ifidx); 35 dev = dev_get_by_index(&init_net, request->ifidx);
28 if (!dev) 36 if (!dev)
29 goto out; 37 goto out;
30 38
31 WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); 39 /*
40 * This must be before sending the other events!
41 * Otherwise, wpa_supplicant gets completely confused with
42 * wext events.
43 */
44 cfg80211_sme_scan_done(dev);
32 45
33 if (aborted) 46 if (request->aborted)
34 nl80211_send_scan_aborted(wiphy_to_dev(request->wiphy), dev); 47 nl80211_send_scan_aborted(wiphy_to_dev(request->wiphy), dev);
35 else 48 else
36 nl80211_send_scan_done(wiphy_to_dev(request->wiphy), dev); 49 nl80211_send_scan_done(wiphy_to_dev(request->wiphy), dev);
@@ -38,7 +51,7 @@ void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted)
38 wiphy_to_dev(request->wiphy)->scan_req = NULL; 51 wiphy_to_dev(request->wiphy)->scan_req = NULL;
39 52
40#ifdef CONFIG_WIRELESS_EXT 53#ifdef CONFIG_WIRELESS_EXT
41 if (!aborted) { 54 if (!request->aborted) {
42 memset(&wrqu, 0, sizeof(wrqu)); 55 memset(&wrqu, 0, sizeof(wrqu));
43 56
44 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL); 57 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
@@ -48,8 +61,24 @@ void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted)
48 dev_put(dev); 61 dev_put(dev);
49 62
50 out: 63 out:
64 cfg80211_unlock_rdev(rdev);
51 kfree(request); 65 kfree(request);
52} 66}
67
68void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted)
69{
70 struct net_device *dev = dev_get_by_index(&init_net, request->ifidx);
71 if (WARN_ON(!dev)) {
72 kfree(request);
73 return;
74 }
75
76 WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req);
77
78 request->aborted = aborted;
79 schedule_work(&wiphy_to_dev(request->wiphy)->scan_done_wk);
80 dev_put(dev);
81}
53EXPORT_SYMBOL(cfg80211_scan_done); 82EXPORT_SYMBOL(cfg80211_scan_done);
54 83
55static void bss_release(struct kref *ref) 84static void bss_release(struct kref *ref)
@@ -63,6 +92,8 @@ static void bss_release(struct kref *ref)
63 if (bss->ies_allocated) 92 if (bss->ies_allocated)
64 kfree(bss->pub.information_elements); 93 kfree(bss->pub.information_elements);
65 94
95 BUG_ON(atomic_read(&bss->hold));
96
66 kfree(bss); 97 kfree(bss);
67} 98}
68 99
@@ -85,8 +116,9 @@ void cfg80211_bss_expire(struct cfg80211_registered_device *dev)
85 bool expired = false; 116 bool expired = false;
86 117
87 list_for_each_entry_safe(bss, tmp, &dev->bss_list, list) { 118 list_for_each_entry_safe(bss, tmp, &dev->bss_list, list) {
88 if (bss->hold || 119 if (atomic_read(&bss->hold))
89 !time_after(jiffies, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE)) 120 continue;
121 if (!time_after(jiffies, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE))
90 continue; 122 continue;
91 list_del(&bss->list); 123 list_del(&bss->list);
92 rb_erase(&bss->rbn, &dev->bss_tree); 124 rb_erase(&bss->rbn, &dev->bss_tree);
@@ -546,30 +578,6 @@ void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
546} 578}
547EXPORT_SYMBOL(cfg80211_unlink_bss); 579EXPORT_SYMBOL(cfg80211_unlink_bss);
548 580
549void cfg80211_hold_bss(struct cfg80211_bss *pub)
550{
551 struct cfg80211_internal_bss *bss;
552
553 if (!pub)
554 return;
555
556 bss = container_of(pub, struct cfg80211_internal_bss, pub);
557 bss->hold = true;
558}
559EXPORT_SYMBOL(cfg80211_hold_bss);
560
561void cfg80211_unhold_bss(struct cfg80211_bss *pub)
562{
563 struct cfg80211_internal_bss *bss;
564
565 if (!pub)
566 return;
567
568 bss = container_of(pub, struct cfg80211_internal_bss, pub);
569 bss->hold = false;
570}
571EXPORT_SYMBOL(cfg80211_unhold_bss);
572
573#ifdef CONFIG_WIRELESS_EXT 581#ifdef CONFIG_WIRELESS_EXT
574int cfg80211_wext_siwscan(struct net_device *dev, 582int cfg80211_wext_siwscan(struct net_device *dev,
575 struct iw_request_info *info, 583 struct iw_request_info *info,
@@ -647,9 +655,10 @@ int cfg80211_wext_siwscan(struct net_device *dev,
647 if (err) { 655 if (err) {
648 rdev->scan_req = NULL; 656 rdev->scan_req = NULL;
649 kfree(creq); 657 kfree(creq);
650 } 658 } else
659 nl80211_send_scan_start(rdev, dev);
651 out: 660 out:
652 cfg80211_put_dev(rdev); 661 cfg80211_unlock_rdev(rdev);
653 return err; 662 return err;
654} 663}
655EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan); 664EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan);
@@ -958,7 +967,7 @@ int cfg80211_wext_giwscan(struct net_device *dev,
958 } 967 }
959 968
960 out: 969 out:
961 cfg80211_put_dev(rdev); 970 cfg80211_unlock_rdev(rdev);
962 return res; 971 return res;
963} 972}
964EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan); 973EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan);
diff --git a/net/wireless/sme.c b/net/wireless/sme.c
new file mode 100644
index 000000000000..df9173f73604
--- /dev/null
+++ b/net/wireless/sme.c
@@ -0,0 +1,792 @@
1/*
2 * SME code for cfg80211's connect emulation.
3 *
4 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright (C) 2009 Intel Corporation. All rights reserved.
6 */
7
8#include <linux/etherdevice.h>
9#include <linux/if_arp.h>
10#include <linux/workqueue.h>
11#include <net/cfg80211.h>
12#include <net/rtnetlink.h>
13#include "nl80211.h"
14
15struct cfg80211_conn {
16 struct cfg80211_connect_params params;
17 /* these are sub-states of the _CONNECTING sme_state */
18 enum {
19 CFG80211_CONN_IDLE,
20 CFG80211_CONN_SCANNING,
21 CFG80211_CONN_SCAN_AGAIN,
22 CFG80211_CONN_AUTHENTICATE_NEXT,
23 CFG80211_CONN_AUTHENTICATING,
24 CFG80211_CONN_ASSOCIATE_NEXT,
25 CFG80211_CONN_ASSOCIATING,
26 } state;
27 u8 bssid[ETH_ALEN];
28 u8 *ie;
29 size_t ie_len;
30 bool auto_auth;
31};
32
33
34static int cfg80211_conn_scan(struct wireless_dev *wdev)
35{
36 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
37 struct cfg80211_scan_request *request;
38 int n_channels, err;
39
40 ASSERT_RTNL();
41 ASSERT_RDEV_LOCK(rdev);
42 ASSERT_WDEV_LOCK(wdev);
43
44 if (rdev->scan_req)
45 return -EBUSY;
46
47 if (wdev->conn->params.channel) {
48 n_channels = 1;
49 } else {
50 enum ieee80211_band band;
51 n_channels = 0;
52
53 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
54 if (!wdev->wiphy->bands[band])
55 continue;
56 n_channels += wdev->wiphy->bands[band]->n_channels;
57 }
58 }
59 request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) +
60 sizeof(request->channels[0]) * n_channels,
61 GFP_KERNEL);
62 if (!request)
63 return -ENOMEM;
64
65 request->channels = (void *)((char *)request + sizeof(*request));
66 if (wdev->conn->params.channel)
67 request->channels[0] = wdev->conn->params.channel;
68 else {
69 int i = 0, j;
70 enum ieee80211_band band;
71
72 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
73 if (!wdev->wiphy->bands[band])
74 continue;
75 for (j = 0; j < wdev->wiphy->bands[band]->n_channels;
76 i++, j++)
77 request->channels[i] =
78 &wdev->wiphy->bands[band]->channels[j];
79 }
80 }
81 request->n_channels = n_channels;
82 request->ssids = (void *)(request->channels + n_channels);
83 request->n_ssids = 1;
84
85 memcpy(request->ssids[0].ssid, wdev->conn->params.ssid,
86 wdev->conn->params.ssid_len);
87 request->ssids[0].ssid_len = wdev->conn->params.ssid_len;
88
89 request->ifidx = wdev->netdev->ifindex;
90 request->wiphy = &rdev->wiphy;
91
92 rdev->scan_req = request;
93
94 err = rdev->ops->scan(wdev->wiphy, wdev->netdev, request);
95 if (!err) {
96 wdev->conn->state = CFG80211_CONN_SCANNING;
97 nl80211_send_scan_start(rdev, wdev->netdev);
98 } else {
99 rdev->scan_req = NULL;
100 kfree(request);
101 }
102 return err;
103}
104
105static int cfg80211_conn_do_work(struct wireless_dev *wdev)
106{
107 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
108 struct cfg80211_connect_params *params;
109 int err;
110
111 ASSERT_WDEV_LOCK(wdev);
112
113 if (!wdev->conn)
114 return 0;
115
116 params = &wdev->conn->params;
117
118 switch (wdev->conn->state) {
119 case CFG80211_CONN_SCAN_AGAIN:
120 return cfg80211_conn_scan(wdev);
121 case CFG80211_CONN_AUTHENTICATE_NEXT:
122 BUG_ON(!rdev->ops->auth);
123 wdev->conn->state = CFG80211_CONN_AUTHENTICATING;
124 return __cfg80211_mlme_auth(rdev, wdev->netdev,
125 params->channel, params->auth_type,
126 params->bssid,
127 params->ssid, params->ssid_len,
128 NULL, 0);
129 case CFG80211_CONN_ASSOCIATE_NEXT:
130 BUG_ON(!rdev->ops->assoc);
131 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
132 /*
133 * We could, later, implement roaming here and then actually
134 * set prev_bssid to non-NULL. But then we need to be aware
135 * that some APs don't like that -- so we'd need to retry
136 * the association.
137 */
138 err = __cfg80211_mlme_assoc(rdev, wdev->netdev,
139 params->channel, params->bssid,
140 NULL,
141 params->ssid, params->ssid_len,
142 params->ie, params->ie_len,
143 false, &params->crypto);
144 if (err)
145 __cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
146 NULL, 0,
147 WLAN_REASON_DEAUTH_LEAVING);
148 return err;
149 default:
150 return 0;
151 }
152}
153
154void cfg80211_conn_work(struct work_struct *work)
155{
156 struct cfg80211_registered_device *rdev =
157 container_of(work, struct cfg80211_registered_device, conn_work);
158 struct wireless_dev *wdev;
159
160 rtnl_lock();
161 cfg80211_lock_rdev(rdev);
162 mutex_lock(&rdev->devlist_mtx);
163
164 list_for_each_entry(wdev, &rdev->netdev_list, list) {
165 wdev_lock(wdev);
166 if (!netif_running(wdev->netdev)) {
167 wdev_unlock(wdev);
168 continue;
169 }
170 if (wdev->sme_state != CFG80211_SME_CONNECTING) {
171 wdev_unlock(wdev);
172 continue;
173 }
174 if (cfg80211_conn_do_work(wdev))
175 __cfg80211_connect_result(
176 wdev->netdev,
177 wdev->conn->params.bssid,
178 NULL, 0, NULL, 0,
179 WLAN_STATUS_UNSPECIFIED_FAILURE,
180 false);
181 wdev_unlock(wdev);
182 }
183
184 mutex_unlock(&rdev->devlist_mtx);
185 cfg80211_unlock_rdev(rdev);
186 rtnl_unlock();
187}
188
189static bool cfg80211_get_conn_bss(struct wireless_dev *wdev)
190{
191 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
192 struct cfg80211_bss *bss;
193 u16 capa = WLAN_CAPABILITY_ESS;
194
195 ASSERT_WDEV_LOCK(wdev);
196
197 if (wdev->conn->params.privacy)
198 capa |= WLAN_CAPABILITY_PRIVACY;
199
200 bss = cfg80211_get_bss(wdev->wiphy, NULL, wdev->conn->params.bssid,
201 wdev->conn->params.ssid,
202 wdev->conn->params.ssid_len,
203 WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY,
204 capa);
205 if (!bss)
206 return false;
207
208 memcpy(wdev->conn->bssid, bss->bssid, ETH_ALEN);
209 wdev->conn->params.bssid = wdev->conn->bssid;
210 wdev->conn->params.channel = bss->channel;
211 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
212 schedule_work(&rdev->conn_work);
213
214 cfg80211_put_bss(bss);
215 return true;
216}
217
218static void __cfg80211_sme_scan_done(struct net_device *dev)
219{
220 struct wireless_dev *wdev = dev->ieee80211_ptr;
221 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
222
223 ASSERT_WDEV_LOCK(wdev);
224
225 if (wdev->sme_state != CFG80211_SME_CONNECTING)
226 return;
227
228 if (WARN_ON(!wdev->conn))
229 return;
230
231 if (wdev->conn->state != CFG80211_CONN_SCANNING &&
232 wdev->conn->state != CFG80211_CONN_SCAN_AGAIN)
233 return;
234
235 if (!cfg80211_get_conn_bss(wdev)) {
236 /* not found */
237 if (wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)
238 schedule_work(&rdev->conn_work);
239 else
240 __cfg80211_connect_result(
241 wdev->netdev,
242 wdev->conn->params.bssid,
243 NULL, 0, NULL, 0,
244 WLAN_STATUS_UNSPECIFIED_FAILURE,
245 false);
246 }
247}
248
249void cfg80211_sme_scan_done(struct net_device *dev)
250{
251 struct wireless_dev *wdev = dev->ieee80211_ptr;
252
253 wdev_lock(wdev);
254 __cfg80211_sme_scan_done(dev);
255 wdev_unlock(wdev);
256}
257
258void cfg80211_sme_rx_auth(struct net_device *dev,
259 const u8 *buf, size_t len)
260{
261 struct wireless_dev *wdev = dev->ieee80211_ptr;
262 struct wiphy *wiphy = wdev->wiphy;
263 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
264 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
265 u16 status_code = le16_to_cpu(mgmt->u.auth.status_code);
266
267 ASSERT_WDEV_LOCK(wdev);
268
269 /* should only RX auth frames when connecting */
270 if (wdev->sme_state != CFG80211_SME_CONNECTING)
271 return;
272
273 if (WARN_ON(!wdev->conn))
274 return;
275
276 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
277 wdev->conn->auto_auth &&
278 wdev->conn->params.auth_type != NL80211_AUTHTYPE_NETWORK_EAP) {
279 /* select automatically between only open, shared, leap */
280 switch (wdev->conn->params.auth_type) {
281 case NL80211_AUTHTYPE_OPEN_SYSTEM:
282 wdev->conn->params.auth_type =
283 NL80211_AUTHTYPE_SHARED_KEY;
284 break;
285 case NL80211_AUTHTYPE_SHARED_KEY:
286 wdev->conn->params.auth_type =
287 NL80211_AUTHTYPE_NETWORK_EAP;
288 break;
289 default:
290 /* huh? */
291 wdev->conn->params.auth_type =
292 NL80211_AUTHTYPE_OPEN_SYSTEM;
293 break;
294 }
295 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
296 schedule_work(&rdev->conn_work);
297 } else if (status_code != WLAN_STATUS_SUCCESS) {
298 wdev->sme_state = CFG80211_SME_IDLE;
299 kfree(wdev->conn);
300 wdev->conn = NULL;
301 } else if (wdev->sme_state == CFG80211_SME_CONNECTING &&
302 wdev->conn->state == CFG80211_CONN_AUTHENTICATING) {
303 wdev->conn->state = CFG80211_CONN_ASSOCIATE_NEXT;
304 schedule_work(&rdev->conn_work);
305 }
306}
307
308void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
309 const u8 *req_ie, size_t req_ie_len,
310 const u8 *resp_ie, size_t resp_ie_len,
311 u16 status, bool wextev)
312{
313 struct wireless_dev *wdev = dev->ieee80211_ptr;
314 struct cfg80211_bss *bss;
315#ifdef CONFIG_WIRELESS_EXT
316 union iwreq_data wrqu;
317#endif
318
319 ASSERT_WDEV_LOCK(wdev);
320
321 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
322 return;
323
324 if (wdev->sme_state == CFG80211_SME_CONNECTED)
325 nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), dev,
326 bssid, req_ie, req_ie_len,
327 resp_ie, resp_ie_len, GFP_KERNEL);
328 else
329 nl80211_send_connect_result(wiphy_to_dev(wdev->wiphy), dev,
330 bssid, req_ie, req_ie_len,
331 resp_ie, resp_ie_len,
332 status, GFP_KERNEL);
333
334#ifdef CONFIG_WIRELESS_EXT
335 if (wextev) {
336 if (req_ie && status == WLAN_STATUS_SUCCESS) {
337 memset(&wrqu, 0, sizeof(wrqu));
338 wrqu.data.length = req_ie_len;
339 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, req_ie);
340 }
341
342 if (resp_ie && status == WLAN_STATUS_SUCCESS) {
343 memset(&wrqu, 0, sizeof(wrqu));
344 wrqu.data.length = resp_ie_len;
345 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, resp_ie);
346 }
347
348 memset(&wrqu, 0, sizeof(wrqu));
349 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
350 if (bssid && status == WLAN_STATUS_SUCCESS)
351 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
352 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
353 }
354#endif
355
356 if (status == WLAN_STATUS_SUCCESS &&
357 wdev->sme_state == CFG80211_SME_IDLE) {
358 wdev->sme_state = CFG80211_SME_CONNECTED;
359 return;
360 }
361
362 if (wdev->sme_state != CFG80211_SME_CONNECTING)
363 return;
364
365 if (wdev->current_bss) {
366 cfg80211_unhold_bss(wdev->current_bss);
367 cfg80211_put_bss(&wdev->current_bss->pub);
368 wdev->current_bss = NULL;
369 }
370
371 if (wdev->conn)
372 wdev->conn->state = CFG80211_CONN_IDLE;
373
374 if (status == WLAN_STATUS_SUCCESS) {
375 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
376 wdev->ssid, wdev->ssid_len,
377 WLAN_CAPABILITY_ESS,
378 WLAN_CAPABILITY_ESS);
379
380 if (WARN_ON(!bss))
381 return;
382
383 cfg80211_hold_bss(bss_from_pub(bss));
384 wdev->current_bss = bss_from_pub(bss);
385
386 wdev->sme_state = CFG80211_SME_CONNECTED;
387 } else {
388 wdev->sme_state = CFG80211_SME_IDLE;
389 kfree(wdev->conn);
390 wdev->conn = NULL;
391 }
392}
393
394void cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
395 const u8 *req_ie, size_t req_ie_len,
396 const u8 *resp_ie, size_t resp_ie_len,
397 u16 status, gfp_t gfp)
398{
399 struct wireless_dev *wdev = dev->ieee80211_ptr;
400 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
401 struct cfg80211_event *ev;
402 unsigned long flags;
403
404 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
405 if (!ev)
406 return;
407
408 ev->type = EVENT_CONNECT_RESULT;
409 memcpy(ev->cr.bssid, bssid, ETH_ALEN);
410 ev->cr.req_ie = ((u8 *)ev) + sizeof(*ev);
411 ev->cr.req_ie_len = req_ie_len;
412 memcpy((void *)ev->cr.req_ie, req_ie, req_ie_len);
413 ev->cr.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
414 ev->cr.resp_ie_len = resp_ie_len;
415 memcpy((void *)ev->cr.resp_ie, resp_ie, resp_ie_len);
416 ev->cr.status = status;
417
418 spin_lock_irqsave(&wdev->event_lock, flags);
419 list_add_tail(&ev->list, &wdev->event_list);
420 spin_unlock_irqrestore(&wdev->event_lock, flags);
421 schedule_work(&rdev->event_work);
422}
423EXPORT_SYMBOL(cfg80211_connect_result);
424
425void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid,
426 const u8 *req_ie, size_t req_ie_len,
427 const u8 *resp_ie, size_t resp_ie_len)
428{
429 struct cfg80211_bss *bss;
430#ifdef CONFIG_WIRELESS_EXT
431 union iwreq_data wrqu;
432#endif
433
434 ASSERT_WDEV_LOCK(wdev);
435
436 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
437 return;
438
439 if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED))
440 return;
441
442 /* internal error -- how did we get to CONNECTED w/o BSS? */
443 if (WARN_ON(!wdev->current_bss)) {
444 return;
445 }
446
447 cfg80211_unhold_bss(wdev->current_bss);
448 cfg80211_put_bss(&wdev->current_bss->pub);
449 wdev->current_bss = NULL;
450
451 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
452 wdev->ssid, wdev->ssid_len,
453 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
454
455 if (WARN_ON(!bss))
456 return;
457
458 cfg80211_hold_bss(bss_from_pub(bss));
459 wdev->current_bss = bss_from_pub(bss);
460
461 nl80211_send_roamed(wiphy_to_dev(wdev->wiphy), wdev->netdev, bssid,
462 req_ie, req_ie_len, resp_ie, resp_ie_len,
463 GFP_KERNEL);
464
465#ifdef CONFIG_WIRELESS_EXT
466 if (req_ie) {
467 memset(&wrqu, 0, sizeof(wrqu));
468 wrqu.data.length = req_ie_len;
469 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
470 &wrqu, req_ie);
471 }
472
473 if (resp_ie) {
474 memset(&wrqu, 0, sizeof(wrqu));
475 wrqu.data.length = resp_ie_len;
476 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE,
477 &wrqu, resp_ie);
478 }
479
480 memset(&wrqu, 0, sizeof(wrqu));
481 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
482 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
483 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL);
484#endif
485}
486
487void cfg80211_roamed(struct net_device *dev, const u8 *bssid,
488 const u8 *req_ie, size_t req_ie_len,
489 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
490{
491 struct wireless_dev *wdev = dev->ieee80211_ptr;
492 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
493 struct cfg80211_event *ev;
494 unsigned long flags;
495
496 ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp);
497 if (!ev)
498 return;
499
500 ev->type = EVENT_ROAMED;
501 memcpy(ev->rm.bssid, bssid, ETH_ALEN);
502 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev);
503 ev->rm.req_ie_len = req_ie_len;
504 memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len);
505 ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len;
506 ev->rm.resp_ie_len = resp_ie_len;
507 memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len);
508
509 spin_lock_irqsave(&wdev->event_lock, flags);
510 list_add_tail(&ev->list, &wdev->event_list);
511 spin_unlock_irqrestore(&wdev->event_lock, flags);
512 schedule_work(&rdev->event_work);
513}
514EXPORT_SYMBOL(cfg80211_roamed);
515
516void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
517 size_t ie_len, u16 reason, bool from_ap)
518{
519 struct wireless_dev *wdev = dev->ieee80211_ptr;
520#ifdef CONFIG_WIRELESS_EXT
521 union iwreq_data wrqu;
522#endif
523
524 ASSERT_WDEV_LOCK(wdev);
525
526 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
527 return;
528
529 if (WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTED))
530 return;
531
532 if (wdev->current_bss) {
533 cfg80211_unhold_bss(wdev->current_bss);
534 cfg80211_put_bss(&wdev->current_bss->pub);
535 }
536
537 wdev->current_bss = NULL;
538 wdev->sme_state = CFG80211_SME_IDLE;
539
540 if (wdev->conn) {
541 kfree(wdev->conn->ie);
542 wdev->conn->ie = NULL;
543 kfree(wdev->conn);
544 wdev->conn = NULL;
545 }
546
547 nl80211_send_disconnected(wiphy_to_dev(wdev->wiphy), dev,
548 reason, ie, ie_len, from_ap);
549
550#ifdef CONFIG_WIRELESS_EXT
551 memset(&wrqu, 0, sizeof(wrqu));
552 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
553 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
554#endif
555}
556
557void cfg80211_disconnected(struct net_device *dev, u16 reason,
558 u8 *ie, size_t ie_len, gfp_t gfp)
559{
560 struct wireless_dev *wdev = dev->ieee80211_ptr;
561 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
562 struct cfg80211_event *ev;
563 unsigned long flags;
564
565 ev = kzalloc(sizeof(*ev) + ie_len, gfp);
566 if (!ev)
567 return;
568
569 ev->type = EVENT_DISCONNECTED;
570 ev->dc.ie = ((u8 *)ev) + sizeof(*ev);
571 ev->dc.ie_len = ie_len;
572 memcpy((void *)ev->dc.ie, ie, ie_len);
573 ev->dc.reason = reason;
574
575 spin_lock_irqsave(&wdev->event_lock, flags);
576 list_add_tail(&ev->list, &wdev->event_list);
577 spin_unlock_irqrestore(&wdev->event_lock, flags);
578 schedule_work(&rdev->event_work);
579}
580EXPORT_SYMBOL(cfg80211_disconnected);
581
582int __cfg80211_connect(struct cfg80211_registered_device *rdev,
583 struct net_device *dev,
584 struct cfg80211_connect_params *connect)
585{
586 struct wireless_dev *wdev = dev->ieee80211_ptr;
587 int err;
588
589 ASSERT_WDEV_LOCK(wdev);
590
591 if (wdev->sme_state != CFG80211_SME_IDLE)
592 return -EALREADY;
593
594 if (!rdev->ops->connect) {
595 if (!rdev->ops->auth || !rdev->ops->assoc)
596 return -EOPNOTSUPP;
597
598 if (WARN_ON(wdev->conn))
599 return -EINPROGRESS;
600
601 wdev->conn = kzalloc(sizeof(*wdev->conn), GFP_KERNEL);
602 if (!wdev->conn)
603 return -ENOMEM;
604
605 /*
606 * Copy all parameters, and treat explicitly IEs, BSSID, SSID.
607 */
608 memcpy(&wdev->conn->params, connect, sizeof(*connect));
609 if (connect->bssid) {
610 wdev->conn->params.bssid = wdev->conn->bssid;
611 memcpy(wdev->conn->bssid, connect->bssid, ETH_ALEN);
612 }
613
614 if (connect->ie) {
615 wdev->conn->ie = kmemdup(connect->ie, connect->ie_len,
616 GFP_KERNEL);
617 wdev->conn->params.ie = wdev->conn->ie;
618 if (!wdev->conn->ie) {
619 kfree(wdev->conn);
620 wdev->conn = NULL;
621 return -ENOMEM;
622 }
623 }
624
625 if (connect->auth_type == NL80211_AUTHTYPE_AUTOMATIC) {
626 wdev->conn->auto_auth = true;
627 /* start with open system ... should mostly work */
628 wdev->conn->params.auth_type =
629 NL80211_AUTHTYPE_OPEN_SYSTEM;
630 } else {
631 wdev->conn->auto_auth = false;
632 }
633
634 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
635 wdev->ssid_len = connect->ssid_len;
636 wdev->conn->params.ssid = wdev->ssid;
637 wdev->conn->params.ssid_len = connect->ssid_len;
638
639 /* don't care about result -- but fill bssid & channel */
640 if (!wdev->conn->params.bssid || !wdev->conn->params.channel)
641 cfg80211_get_conn_bss(wdev);
642
643 wdev->sme_state = CFG80211_SME_CONNECTING;
644
645 /* we're good if we have both BSSID and channel */
646 if (wdev->conn->params.bssid && wdev->conn->params.channel) {
647 wdev->conn->state = CFG80211_CONN_AUTHENTICATE_NEXT;
648 err = cfg80211_conn_do_work(wdev);
649 } else {
650 /* otherwise we'll need to scan for the AP first */
651 err = cfg80211_conn_scan(wdev);
652 /*
653 * If we can't scan right now, then we need to scan again
654 * after the current scan finished, since the parameters
655 * changed (unless we find a good AP anyway).
656 */
657 if (err == -EBUSY) {
658 err = 0;
659 wdev->conn->state = CFG80211_CONN_SCAN_AGAIN;
660 }
661 }
662 if (err) {
663 kfree(wdev->conn);
664 wdev->conn = NULL;
665 wdev->sme_state = CFG80211_SME_IDLE;
666 }
667
668 return err;
669 } else {
670 wdev->sme_state = CFG80211_SME_CONNECTING;
671 err = rdev->ops->connect(&rdev->wiphy, dev, connect);
672 if (err) {
673 wdev->sme_state = CFG80211_SME_IDLE;
674 return err;
675 }
676
677 memcpy(wdev->ssid, connect->ssid, connect->ssid_len);
678 wdev->ssid_len = connect->ssid_len;
679
680 return 0;
681 }
682}
683
684int cfg80211_connect(struct cfg80211_registered_device *rdev,
685 struct net_device *dev,
686 struct cfg80211_connect_params *connect)
687{
688 int err;
689
690 wdev_lock(dev->ieee80211_ptr);
691 err = __cfg80211_connect(rdev, dev, connect);
692 wdev_unlock(dev->ieee80211_ptr);
693
694 return err;
695}
696
697int __cfg80211_disconnect(struct cfg80211_registered_device *rdev,
698 struct net_device *dev, u16 reason, bool wextev)
699{
700 struct wireless_dev *wdev = dev->ieee80211_ptr;
701 int err;
702
703 ASSERT_WDEV_LOCK(wdev);
704
705 if (wdev->sme_state == CFG80211_SME_IDLE)
706 return -EINVAL;
707
708 if (!rdev->ops->disconnect) {
709 if (!rdev->ops->deauth)
710 return -EOPNOTSUPP;
711
712 /* was it connected by userspace SME? */
713 if (!wdev->conn) {
714 cfg80211_mlme_down(rdev, dev);
715 return 0;
716 }
717
718 if (wdev->sme_state == CFG80211_SME_CONNECTING &&
719 (wdev->conn->state == CFG80211_CONN_SCANNING ||
720 wdev->conn->state == CFG80211_CONN_SCAN_AGAIN)) {
721 wdev->sme_state = CFG80211_SME_IDLE;
722 kfree(wdev->conn);
723 wdev->conn = NULL;
724 return 0;
725 }
726
727 /* wdev->conn->params.bssid must be set if > SCANNING */
728 err = __cfg80211_mlme_deauth(rdev, dev,
729 wdev->conn->params.bssid,
730 NULL, 0, reason);
731 if (err)
732 return err;
733 } else {
734 err = rdev->ops->disconnect(&rdev->wiphy, dev, reason);
735 if (err)
736 return err;
737 }
738
739 if (wdev->sme_state == CFG80211_SME_CONNECTED)
740 __cfg80211_disconnected(dev, NULL, 0, 0, false);
741 else if (wdev->sme_state == CFG80211_SME_CONNECTING)
742 __cfg80211_connect_result(dev, NULL, NULL, 0, NULL, 0,
743 WLAN_STATUS_UNSPECIFIED_FAILURE,
744 wextev);
745
746 return 0;
747}
748
749int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
750 struct net_device *dev,
751 u16 reason, bool wextev)
752{
753 int err;
754
755 wdev_lock(dev->ieee80211_ptr);
756 err = __cfg80211_disconnect(rdev, dev, reason, wextev);
757 wdev_unlock(dev->ieee80211_ptr);
758
759 return err;
760}
761
762void cfg80211_sme_disassoc(struct net_device *dev, int idx)
763{
764 struct wireless_dev *wdev = dev->ieee80211_ptr;
765 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
766 u8 bssid[ETH_ALEN];
767
768 ASSERT_WDEV_LOCK(wdev);
769
770 if (!wdev->conn)
771 return;
772
773 if (wdev->conn->state == CFG80211_CONN_IDLE)
774 return;
775
776 /*
777 * Ok, so the association was made by this SME -- we don't
778 * want it any more so deauthenticate too.
779 */
780
781 if (!wdev->auth_bsses[idx])
782 return;
783
784 memcpy(bssid, wdev->auth_bsses[idx]->pub.bssid, ETH_ALEN);
785 if (cfg80211_mlme_deauth(rdev, dev, bssid,
786 NULL, 0, WLAN_REASON_DEAUTH_LEAVING)) {
787 /* whatever -- assume gone anyway */
788 cfg80211_unhold_bss(wdev->auth_bsses[idx]);
789 cfg80211_put_bss(&wdev->auth_bsses[idx]->pub);
790 wdev->auth_bsses[idx] = NULL;
791 }
792}
diff --git a/net/wireless/util.c b/net/wireless/util.c
index 25550692dda6..28f8f96801d4 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -502,3 +502,24 @@ unsigned int cfg80211_classify8021d(struct sk_buff *skb)
502 return dscp >> 5; 502 return dscp >> 5;
503} 503}
504EXPORT_SYMBOL(cfg80211_classify8021d); 504EXPORT_SYMBOL(cfg80211_classify8021d);
505
506const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie)
507{
508 u8 *end, *pos;
509
510 pos = bss->information_elements;
511 if (pos == NULL)
512 return NULL;
513 end = pos + bss->len_information_elements;
514
515 while (pos + 1 < end) {
516 if (pos + 2 + pos[1] > end)
517 break;
518 if (pos[0] == ie)
519 return pos;
520 pos += 2 + pos[1];
521 }
522
523 return NULL;
524}
525EXPORT_SYMBOL(ieee80211_bss_get_ie);
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index d030c5315672..9d101d566bb1 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -103,7 +103,7 @@ int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
103 103
104 memset(&vifparams, 0, sizeof(vifparams)); 104 memset(&vifparams, 0, sizeof(vifparams));
105 105
106 ret = rdev->ops->change_virtual_intf(wdev->wiphy, dev->ifindex, type, 106 ret = rdev->ops->change_virtual_intf(wdev->wiphy, dev, type,
107 NULL, &vifparams); 107 NULL, &vifparams);
108 WARN_ON(!ret && wdev->iftype != type); 108 WARN_ON(!ret && wdev->iftype != type);
109 109
@@ -154,7 +154,7 @@ int cfg80211_wext_giwrange(struct net_device *dev,
154 struct wireless_dev *wdev = dev->ieee80211_ptr; 154 struct wireless_dev *wdev = dev->ieee80211_ptr;
155 struct iw_range *range = (struct iw_range *) extra; 155 struct iw_range *range = (struct iw_range *) extra;
156 enum ieee80211_band band; 156 enum ieee80211_band band;
157 int c = 0; 157 int i, c = 0;
158 158
159 if (!wdev) 159 if (!wdev)
160 return -EOPNOTSUPP; 160 return -EOPNOTSUPP;
@@ -173,9 +173,6 @@ int cfg80211_wext_giwrange(struct net_device *dev,
173 range->min_frag = 256; 173 range->min_frag = 256;
174 range->max_frag = 2346; 174 range->max_frag = 2346;
175 175
176 range->encoding_size[0] = 5;
177 range->encoding_size[1] = 13;
178 range->num_encoding_sizes = 2;
179 range->max_encoding_tokens = 4; 176 range->max_encoding_tokens = 4;
180 177
181 range->max_qual.updated = IW_QUAL_NOISE_INVALID; 178 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
@@ -204,11 +201,31 @@ int cfg80211_wext_giwrange(struct net_device *dev,
204 range->avg_qual.noise = range->max_qual.noise / 2; 201 range->avg_qual.noise = range->max_qual.noise / 2;
205 range->avg_qual.updated = range->max_qual.updated; 202 range->avg_qual.updated = range->max_qual.updated;
206 203
207 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | 204 for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
208 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; 205 switch (wdev->wiphy->cipher_suites[i]) {
206 case WLAN_CIPHER_SUITE_TKIP:
207 range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
208 IW_ENC_CAPA_WPA);
209 break;
210
211 case WLAN_CIPHER_SUITE_CCMP:
212 range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
213 IW_ENC_CAPA_WPA2);
214 break;
215
216 case WLAN_CIPHER_SUITE_WEP40:
217 range->encoding_size[range->num_encoding_sizes++] =
218 WLAN_KEY_LEN_WEP40;
219 break;
220
221 case WLAN_CIPHER_SUITE_WEP104:
222 range->encoding_size[range->num_encoding_sizes++] =
223 WLAN_KEY_LEN_WEP104;
224 break;
225 }
226 }
209 227
210 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) { 228 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
211 int i;
212 struct ieee80211_supported_band *sband; 229 struct ieee80211_supported_band *sband;
213 230
214 sband = wdev->wiphy->bands[band]; 231 sband = wdev->wiphy->bands[band];
@@ -236,56 +253,13 @@ int cfg80211_wext_giwrange(struct net_device *dev,
236 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); 253 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
237 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); 254 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
238 255
239 range->scan_capa |= IW_SCAN_CAPA_ESSID; 256 if (wdev->wiphy->max_scan_ssids > 0)
257 range->scan_capa |= IW_SCAN_CAPA_ESSID;
240 258
241 return 0; 259 return 0;
242} 260}
243EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange); 261EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange);
244 262
245int cfg80211_wext_siwmlme(struct net_device *dev,
246 struct iw_request_info *info,
247 struct iw_point *data, char *extra)
248{
249 struct wireless_dev *wdev = dev->ieee80211_ptr;
250 struct iw_mlme *mlme = (struct iw_mlme *)extra;
251 struct cfg80211_registered_device *rdev;
252 union {
253 struct cfg80211_disassoc_request disassoc;
254 struct cfg80211_deauth_request deauth;
255 } cmd;
256
257 if (!wdev)
258 return -EOPNOTSUPP;
259
260 rdev = wiphy_to_dev(wdev->wiphy);
261
262 if (wdev->iftype != NL80211_IFTYPE_STATION)
263 return -EINVAL;
264
265 if (mlme->addr.sa_family != ARPHRD_ETHER)
266 return -EINVAL;
267
268 memset(&cmd, 0, sizeof(cmd));
269
270 switch (mlme->cmd) {
271 case IW_MLME_DEAUTH:
272 if (!rdev->ops->deauth)
273 return -EOPNOTSUPP;
274 cmd.deauth.peer_addr = mlme->addr.sa_data;
275 cmd.deauth.reason_code = mlme->reason_code;
276 return rdev->ops->deauth(wdev->wiphy, dev, &cmd.deauth);
277 case IW_MLME_DISASSOC:
278 if (!rdev->ops->disassoc)
279 return -EOPNOTSUPP;
280 cmd.disassoc.peer_addr = mlme->addr.sa_data;
281 cmd.disassoc.reason_code = mlme->reason_code;
282 return rdev->ops->disassoc(wdev->wiphy, dev, &cmd.disassoc);
283 default:
284 return -EOPNOTSUPP;
285 }
286}
287EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme);
288
289 263
290/** 264/**
291 * cfg80211_wext_freq - get wext frequency for non-"auto" 265 * cfg80211_wext_freq - get wext frequency for non-"auto"
@@ -827,3 +801,419 @@ int cfg80211_wext_giwtxpower(struct net_device *dev,
827 return 0; 801 return 0;
828} 802}
829EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower); 803EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower);
804
805static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
806 s32 auth_alg)
807{
808 int nr_alg = 0;
809
810 if (!auth_alg)
811 return -EINVAL;
812
813 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
814 IW_AUTH_ALG_SHARED_KEY |
815 IW_AUTH_ALG_LEAP))
816 return -EINVAL;
817
818 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
819 nr_alg++;
820 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
821 }
822
823 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
824 nr_alg++;
825 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
826 }
827
828 if (auth_alg & IW_AUTH_ALG_LEAP) {
829 nr_alg++;
830 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
831 }
832
833 if (nr_alg > 1)
834 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
835
836 return 0;
837}
838
839static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
840{
841 wdev->wext.connect.crypto.wpa_versions = 0;
842
843 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
844 IW_AUTH_WPA_VERSION_WPA2))
845 return -EINVAL;
846
847 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
848 wdev->wext.connect.crypto.wpa_versions |=
849 NL80211_WPA_VERSION_1;
850
851 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
852 wdev->wext.connect.crypto.wpa_versions |=
853 NL80211_WPA_VERSION_2;
854
855 return 0;
856}
857
858static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
859{
860 wdev->wext.connect.crypto.cipher_group = 0;
861
862 if (cipher & IW_AUTH_CIPHER_WEP40)
863 wdev->wext.connect.crypto.cipher_group =
864 WLAN_CIPHER_SUITE_WEP40;
865 else if (cipher & IW_AUTH_CIPHER_WEP104)
866 wdev->wext.connect.crypto.cipher_group =
867 WLAN_CIPHER_SUITE_WEP104;
868 else if (cipher & IW_AUTH_CIPHER_TKIP)
869 wdev->wext.connect.crypto.cipher_group =
870 WLAN_CIPHER_SUITE_TKIP;
871 else if (cipher & IW_AUTH_CIPHER_CCMP)
872 wdev->wext.connect.crypto.cipher_group =
873 WLAN_CIPHER_SUITE_CCMP;
874 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
875 wdev->wext.connect.crypto.cipher_group =
876 WLAN_CIPHER_SUITE_AES_CMAC;
877 else
878 return -EINVAL;
879
880 return 0;
881}
882
883static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
884{
885 int nr_ciphers = 0;
886 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
887
888 if (cipher & IW_AUTH_CIPHER_WEP40) {
889 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
890 nr_ciphers++;
891 }
892
893 if (cipher & IW_AUTH_CIPHER_WEP104) {
894 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
895 nr_ciphers++;
896 }
897
898 if (cipher & IW_AUTH_CIPHER_TKIP) {
899 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
900 nr_ciphers++;
901 }
902
903 if (cipher & IW_AUTH_CIPHER_CCMP) {
904 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
905 nr_ciphers++;
906 }
907
908 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
909 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
910 nr_ciphers++;
911 }
912
913 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
914
915 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
916
917 return 0;
918}
919
920
921static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
922{
923 int nr_akm_suites = 0;
924
925 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
926 IW_AUTH_KEY_MGMT_PSK))
927 return -EINVAL;
928
929 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
930 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
931 WLAN_AKM_SUITE_8021X;
932 nr_akm_suites++;
933 }
934
935 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
936 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
937 WLAN_AKM_SUITE_PSK;
938 nr_akm_suites++;
939 }
940
941 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
942
943 return 0;
944}
945
946int cfg80211_wext_siwauth(struct net_device *dev,
947 struct iw_request_info *info,
948 struct iw_param *data, char *extra)
949{
950 struct wireless_dev *wdev = dev->ieee80211_ptr;
951
952 if (wdev->iftype != NL80211_IFTYPE_STATION)
953 return -EOPNOTSUPP;
954
955 switch (data->flags & IW_AUTH_INDEX) {
956 case IW_AUTH_PRIVACY_INVOKED:
957 wdev->wext.connect.privacy = data->value;
958 return 0;
959 case IW_AUTH_WPA_VERSION:
960 return cfg80211_set_wpa_version(wdev, data->value);
961 case IW_AUTH_CIPHER_GROUP:
962 return cfg80211_set_cipher_group(wdev, data->value);
963 case IW_AUTH_KEY_MGMT:
964 return cfg80211_set_key_mgt(wdev, data->value);
965 case IW_AUTH_CIPHER_PAIRWISE:
966 return cfg80211_set_cipher_pairwise(wdev, data->value);
967 case IW_AUTH_80211_AUTH_ALG:
968 return cfg80211_set_auth_alg(wdev, data->value);
969 case IW_AUTH_WPA_ENABLED:
970 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
971 case IW_AUTH_DROP_UNENCRYPTED:
972 case IW_AUTH_MFP:
973 return 0;
974 default:
975 return -EOPNOTSUPP;
976 }
977}
978EXPORT_SYMBOL_GPL(cfg80211_wext_siwauth);
979
980int cfg80211_wext_giwauth(struct net_device *dev,
981 struct iw_request_info *info,
982 struct iw_param *data, char *extra)
983{
984 /* XXX: what do we need? */
985
986 return -EOPNOTSUPP;
987}
988EXPORT_SYMBOL_GPL(cfg80211_wext_giwauth);
989
990int cfg80211_wext_siwpower(struct net_device *dev,
991 struct iw_request_info *info,
992 struct iw_param *wrq, char *extra)
993{
994 struct wireless_dev *wdev = dev->ieee80211_ptr;
995 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
996 bool ps = wdev->wext.ps;
997 int timeout = wdev->wext.ps_timeout;
998 int err;
999
1000 if (wdev->iftype != NL80211_IFTYPE_STATION)
1001 return -EINVAL;
1002
1003 if (!rdev->ops->set_power_mgmt)
1004 return -EOPNOTSUPP;
1005
1006 if (wrq->disabled) {
1007 ps = false;
1008 } else {
1009 switch (wrq->flags & IW_POWER_MODE) {
1010 case IW_POWER_ON: /* If not specified */
1011 case IW_POWER_MODE: /* If set all mask */
1012 case IW_POWER_ALL_R: /* If explicitely state all */
1013 ps = true;
1014 break;
1015 default: /* Otherwise we ignore */
1016 return -EINVAL;
1017 }
1018
1019 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
1020 return -EINVAL;
1021
1022 if (wrq->flags & IW_POWER_TIMEOUT)
1023 timeout = wrq->value / 1000;
1024 }
1025
1026 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, ps, timeout);
1027 if (err)
1028 return err;
1029
1030 wdev->wext.ps = ps;
1031 wdev->wext.ps_timeout = timeout;
1032
1033 return 0;
1034
1035}
1036EXPORT_SYMBOL_GPL(cfg80211_wext_siwpower);
1037
1038int cfg80211_wext_giwpower(struct net_device *dev,
1039 struct iw_request_info *info,
1040 struct iw_param *wrq, char *extra)
1041{
1042 struct wireless_dev *wdev = dev->ieee80211_ptr;
1043
1044 wrq->disabled = !wdev->wext.ps;
1045
1046 return 0;
1047}
1048EXPORT_SYMBOL_GPL(cfg80211_wext_giwpower);
1049
1050int cfg80211_wds_wext_siwap(struct net_device *dev,
1051 struct iw_request_info *info,
1052 struct sockaddr *addr, char *extra)
1053{
1054 struct wireless_dev *wdev = dev->ieee80211_ptr;
1055 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1056 int err;
1057
1058 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1059 return -EINVAL;
1060
1061 if (addr->sa_family != ARPHRD_ETHER)
1062 return -EINVAL;
1063
1064 if (netif_running(dev))
1065 return -EBUSY;
1066
1067 if (!rdev->ops->set_wds_peer)
1068 return -EOPNOTSUPP;
1069
1070 err = rdev->ops->set_wds_peer(wdev->wiphy, dev, (u8 *) &addr->sa_data);
1071 if (err)
1072 return err;
1073
1074 memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
1075
1076 return 0;
1077}
1078EXPORT_SYMBOL_GPL(cfg80211_wds_wext_siwap);
1079
1080int cfg80211_wds_wext_giwap(struct net_device *dev,
1081 struct iw_request_info *info,
1082 struct sockaddr *addr, char *extra)
1083{
1084 struct wireless_dev *wdev = dev->ieee80211_ptr;
1085
1086 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1087 return -EINVAL;
1088
1089 addr->sa_family = ARPHRD_ETHER;
1090 memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
1091
1092 return 0;
1093}
1094EXPORT_SYMBOL_GPL(cfg80211_wds_wext_giwap);
1095
1096int cfg80211_wext_siwrate(struct net_device *dev,
1097 struct iw_request_info *info,
1098 struct iw_param *rate, char *extra)
1099{
1100 struct wireless_dev *wdev = dev->ieee80211_ptr;
1101 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1102 struct cfg80211_bitrate_mask mask;
1103
1104 if (!rdev->ops->set_bitrate_mask)
1105 return -EOPNOTSUPP;
1106
1107 mask.fixed = 0;
1108 mask.maxrate = 0;
1109
1110 if (rate->value < 0) {
1111 /* nothing */
1112 } else if (rate->fixed) {
1113 mask.fixed = rate->value / 1000; /* kbps */
1114 } else {
1115 mask.maxrate = rate->value / 1000; /* kbps */
1116 }
1117
1118 return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask);
1119}
1120EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate);
1121
1122int cfg80211_wext_giwrate(struct net_device *dev,
1123 struct iw_request_info *info,
1124 struct iw_param *rate, char *extra)
1125{
1126 struct wireless_dev *wdev = dev->ieee80211_ptr;
1127 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1128 /* we are under RTNL - globally locked - so can use a static struct */
1129 static struct station_info sinfo;
1130 u8 *addr;
1131 int err;
1132
1133 if (wdev->iftype != NL80211_IFTYPE_STATION)
1134 return -EOPNOTSUPP;
1135
1136 if (!rdev->ops->get_station)
1137 return -EOPNOTSUPP;
1138
1139 if (wdev->current_bss)
1140 addr = wdev->current_bss->pub.bssid;
1141 else if (wdev->wext.connect.bssid)
1142 addr = wdev->wext.connect.bssid;
1143 else
1144 return -EOPNOTSUPP;
1145
1146 err = rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo);
1147 if (err)
1148 return err;
1149
1150 if (!(sinfo.filled & STATION_INFO_TX_BITRATE))
1151 return -EOPNOTSUPP;
1152
1153 rate->value = 0;
1154
1155 if (!(sinfo.txrate.flags & RATE_INFO_FLAGS_MCS))
1156 rate->value = 100000 * sinfo.txrate.legacy;
1157
1158 return 0;
1159}
1160EXPORT_SYMBOL_GPL(cfg80211_wext_giwrate);
1161
1162/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1163struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
1164{
1165 struct wireless_dev *wdev = dev->ieee80211_ptr;
1166 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1167 /* we are under RTNL - globally locked - so can use static structs */
1168 static struct iw_statistics wstats;
1169 static struct station_info sinfo;
1170 u8 *addr;
1171
1172 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1173 return NULL;
1174
1175 if (!rdev->ops->get_station)
1176 return NULL;
1177
1178 addr = wdev->wext.connect.bssid;
1179 if (!addr)
1180 return NULL;
1181
1182 if (rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo))
1183 return NULL;
1184
1185 memset(&wstats, 0, sizeof(wstats));
1186
1187 switch (rdev->wiphy.signal_type) {
1188 case CFG80211_SIGNAL_TYPE_MBM:
1189 if (sinfo.filled & STATION_INFO_SIGNAL) {
1190 int sig = sinfo.signal;
1191 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1192 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1193 wstats.qual.updated |= IW_QUAL_DBM;
1194 wstats.qual.level = sig;
1195 if (sig < -110)
1196 sig = -110;
1197 else if (sig > -40)
1198 sig = -40;
1199 wstats.qual.qual = sig + 110;
1200 break;
1201 }
1202 case CFG80211_SIGNAL_TYPE_UNSPEC:
1203 if (sinfo.filled & STATION_INFO_SIGNAL) {
1204 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1205 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1206 wstats.qual.level = sinfo.signal;
1207 wstats.qual.qual = sinfo.signal;
1208 break;
1209 }
1210 default:
1211 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1212 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1213 }
1214
1215 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
1216
1217 return &wstats;
1218}
1219EXPORT_SYMBOL_GPL(cfg80211_wireless_stats);
diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c
new file mode 100644
index 000000000000..6f75aaa7f795
--- /dev/null
+++ b/net/wireless/wext-sme.c
@@ -0,0 +1,380 @@
1/*
2 * cfg80211 wext compat for managed mode.
3 *
4 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright (C) 2009 Intel Corporation. All rights reserved.
6 */
7
8#include <linux/etherdevice.h>
9#include <linux/if_arp.h>
10#include <net/cfg80211.h>
11#include "nl80211.h"
12
13static int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
14 struct wireless_dev *wdev)
15{
16 int err;
17
18 ASSERT_RDEV_LOCK(rdev);
19 ASSERT_WDEV_LOCK(wdev);
20
21 if (!netif_running(wdev->netdev))
22 return 0;
23
24 wdev->wext.connect.ie = wdev->wext.ie;
25 wdev->wext.connect.ie_len = wdev->wext.ie_len;
26 wdev->wext.connect.privacy = wdev->wext.default_key != -1;
27
28 err = 0;
29 if (wdev->wext.connect.ssid_len != 0)
30 err = __cfg80211_connect(rdev, wdev->netdev,
31 &wdev->wext.connect);
32
33 return err;
34}
35
36int cfg80211_mgd_wext_siwfreq(struct net_device *dev,
37 struct iw_request_info *info,
38 struct iw_freq *freq, char *extra)
39{
40 struct wireless_dev *wdev = dev->ieee80211_ptr;
41 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
42 struct ieee80211_channel *chan;
43 int err;
44
45 /* call only for station! */
46 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
47 return -EINVAL;
48
49 chan = cfg80211_wext_freq(wdev->wiphy, freq);
50 if (chan && IS_ERR(chan))
51 return PTR_ERR(chan);
52
53 if (chan && (chan->flags & IEEE80211_CHAN_DISABLED))
54 return -EINVAL;
55
56 cfg80211_lock_rdev(rdev);
57 wdev_lock(wdev);
58
59 if (wdev->wext.connect.channel == chan) {
60 err = 0;
61 goto out;
62 }
63
64 if (wdev->sme_state != CFG80211_SME_IDLE) {
65 bool event = true;
66 /* if SSID set, we'll try right again, avoid event */
67 if (wdev->wext.connect.ssid_len)
68 event = false;
69 err = __cfg80211_disconnect(wiphy_to_dev(wdev->wiphy),
70 dev, WLAN_REASON_DEAUTH_LEAVING,
71 event);
72 if (err)
73 goto out;
74 }
75
76
77 wdev->wext.connect.channel = chan;
78
79 /* SSID is not set, we just want to switch channel */
80 if (wdev->wext.connect.ssid_len && chan) {
81 err = -EOPNOTSUPP;
82 if (rdev->ops->set_channel)
83 err = rdev->ops->set_channel(wdev->wiphy, chan,
84 NL80211_CHAN_NO_HT);
85 goto out;
86 }
87
88 err = cfg80211_mgd_wext_connect(wiphy_to_dev(wdev->wiphy), wdev);
89 out:
90 wdev_unlock(wdev);
91 cfg80211_unlock_rdev(rdev);
92 return err;
93}
94/* temporary symbol - mark GPL - in the future the handler won't be */
95EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_siwfreq);
96
97int cfg80211_mgd_wext_giwfreq(struct net_device *dev,
98 struct iw_request_info *info,
99 struct iw_freq *freq, char *extra)
100{
101 struct wireless_dev *wdev = dev->ieee80211_ptr;
102 struct ieee80211_channel *chan = NULL;
103
104 /* call only for station! */
105 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
106 return -EINVAL;
107
108 wdev_lock(wdev);
109 if (wdev->current_bss)
110 chan = wdev->current_bss->pub.channel;
111 else if (wdev->wext.connect.channel)
112 chan = wdev->wext.connect.channel;
113 wdev_unlock(wdev);
114
115 if (chan) {
116 freq->m = chan->center_freq;
117 freq->e = 6;
118 return 0;
119 }
120
121 /* no channel if not joining */
122 return -EINVAL;
123}
124/* temporary symbol - mark GPL - in the future the handler won't be */
125EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_giwfreq);
126
127int cfg80211_mgd_wext_siwessid(struct net_device *dev,
128 struct iw_request_info *info,
129 struct iw_point *data, char *ssid)
130{
131 struct wireless_dev *wdev = dev->ieee80211_ptr;
132 size_t len = data->length;
133 int err;
134
135 /* call only for station! */
136 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
137 return -EINVAL;
138
139 if (!data->flags)
140 len = 0;
141
142 /* iwconfig uses nul termination in SSID.. */
143 if (len > 0 && ssid[len - 1] == '\0')
144 len--;
145
146 cfg80211_lock_rdev(wiphy_to_dev(wdev->wiphy));
147 wdev_lock(wdev);
148
149 err = 0;
150
151 if (wdev->wext.connect.ssid && len &&
152 len == wdev->wext.connect.ssid_len &&
153 memcmp(wdev->wext.connect.ssid, ssid, len))
154 goto out;
155
156 if (wdev->sme_state != CFG80211_SME_IDLE) {
157 bool event = true;
158 /* if SSID set now, we'll try to connect, avoid event */
159 if (len)
160 event = false;
161 err = __cfg80211_disconnect(wiphy_to_dev(wdev->wiphy),
162 dev, WLAN_REASON_DEAUTH_LEAVING,
163 event);
164 if (err)
165 goto out;
166 }
167
168 wdev->wext.connect.ssid = wdev->wext.ssid;
169 memcpy(wdev->wext.ssid, ssid, len);
170 wdev->wext.connect.ssid_len = len;
171
172 wdev->wext.connect.crypto.control_port = false;
173
174 err = cfg80211_mgd_wext_connect(wiphy_to_dev(wdev->wiphy), wdev);
175 out:
176 wdev_unlock(wdev);
177 cfg80211_unlock_rdev(wiphy_to_dev(wdev->wiphy));
178 return err;
179}
180/* temporary symbol - mark GPL - in the future the handler won't be */
181EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_siwessid);
182
183int cfg80211_mgd_wext_giwessid(struct net_device *dev,
184 struct iw_request_info *info,
185 struct iw_point *data, char *ssid)
186{
187 struct wireless_dev *wdev = dev->ieee80211_ptr;
188
189 /* call only for station! */
190 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
191 return -EINVAL;
192
193 data->flags = 0;
194
195 wdev_lock(wdev);
196 if (wdev->ssid_len) {
197 data->flags = 1;
198 data->length = wdev->ssid_len;
199 memcpy(ssid, wdev->ssid, data->length);
200 } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) {
201 data->flags = 1;
202 data->length = wdev->wext.connect.ssid_len;
203 memcpy(ssid, wdev->wext.connect.ssid, data->length);
204 } else
205 data->flags = 0;
206 wdev_unlock(wdev);
207
208 return 0;
209}
210/* temporary symbol - mark GPL - in the future the handler won't be */
211EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_giwessid);
212
213int cfg80211_mgd_wext_siwap(struct net_device *dev,
214 struct iw_request_info *info,
215 struct sockaddr *ap_addr, char *extra)
216{
217 struct wireless_dev *wdev = dev->ieee80211_ptr;
218 u8 *bssid = ap_addr->sa_data;
219 int err;
220
221 /* call only for station! */
222 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
223 return -EINVAL;
224
225 if (ap_addr->sa_family != ARPHRD_ETHER)
226 return -EINVAL;
227
228 /* automatic mode */
229 if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid))
230 bssid = NULL;
231
232 cfg80211_lock_rdev(wiphy_to_dev(wdev->wiphy));
233 wdev_lock(wdev);
234
235 err = 0;
236 /* both automatic */
237 if (!bssid && !wdev->wext.connect.bssid)
238 goto out;
239
240 /* fixed already - and no change */
241 if (wdev->wext.connect.bssid && bssid &&
242 compare_ether_addr(bssid, wdev->wext.connect.bssid) == 0)
243 goto out;
244
245 if (wdev->sme_state != CFG80211_SME_IDLE) {
246 err = __cfg80211_disconnect(wiphy_to_dev(wdev->wiphy),
247 dev, WLAN_REASON_DEAUTH_LEAVING,
248 false);
249 if (err)
250 goto out;
251 }
252
253 if (bssid) {
254 memcpy(wdev->wext.bssid, bssid, ETH_ALEN);
255 wdev->wext.connect.bssid = wdev->wext.bssid;
256 } else
257 wdev->wext.connect.bssid = NULL;
258
259 err = cfg80211_mgd_wext_connect(wiphy_to_dev(wdev->wiphy), wdev);
260 out:
261 wdev_unlock(wdev);
262 cfg80211_unlock_rdev(wiphy_to_dev(wdev->wiphy));
263 return err;
264}
265/* temporary symbol - mark GPL - in the future the handler won't be */
266EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_siwap);
267
268int cfg80211_mgd_wext_giwap(struct net_device *dev,
269 struct iw_request_info *info,
270 struct sockaddr *ap_addr, char *extra)
271{
272 struct wireless_dev *wdev = dev->ieee80211_ptr;
273
274 /* call only for station! */
275 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
276 return -EINVAL;
277
278 ap_addr->sa_family = ARPHRD_ETHER;
279
280 wdev_lock(wdev);
281 if (wdev->current_bss)
282 memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN);
283 else if (wdev->wext.connect.bssid)
284 memcpy(ap_addr->sa_data, wdev->wext.connect.bssid, ETH_ALEN);
285 else
286 memset(ap_addr->sa_data, 0, ETH_ALEN);
287 wdev_unlock(wdev);
288
289 return 0;
290}
291/* temporary symbol - mark GPL - in the future the handler won't be */
292EXPORT_SYMBOL_GPL(cfg80211_mgd_wext_giwap);
293
294int cfg80211_wext_siwgenie(struct net_device *dev,
295 struct iw_request_info *info,
296 struct iw_point *data, char *extra)
297{
298 struct wireless_dev *wdev = dev->ieee80211_ptr;
299 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
300 u8 *ie = extra;
301 int ie_len = data->length, err;
302
303 if (wdev->iftype != NL80211_IFTYPE_STATION)
304 return -EOPNOTSUPP;
305
306 if (!ie_len)
307 ie = NULL;
308
309 wdev_lock(wdev);
310
311 /* no change */
312 err = 0;
313 if (wdev->wext.ie_len == ie_len &&
314 memcmp(wdev->wext.ie, ie, ie_len) == 0)
315 goto out;
316
317 if (ie_len) {
318 ie = kmemdup(extra, ie_len, GFP_KERNEL);
319 if (!ie) {
320 err = -ENOMEM;
321 goto out;
322 }
323 } else
324 ie = NULL;
325
326 kfree(wdev->wext.ie);
327 wdev->wext.ie = ie;
328 wdev->wext.ie_len = ie_len;
329
330 if (wdev->sme_state != CFG80211_SME_IDLE) {
331 err = __cfg80211_disconnect(rdev, dev,
332 WLAN_REASON_DEAUTH_LEAVING, false);
333 if (err)
334 goto out;
335 }
336
337 /* userspace better not think we'll reconnect */
338 err = 0;
339 out:
340 wdev_unlock(wdev);
341 return err;
342}
343EXPORT_SYMBOL_GPL(cfg80211_wext_siwgenie);
344
345int cfg80211_wext_siwmlme(struct net_device *dev,
346 struct iw_request_info *info,
347 struct iw_point *data, char *extra)
348{
349 struct wireless_dev *wdev = dev->ieee80211_ptr;
350 struct iw_mlme *mlme = (struct iw_mlme *)extra;
351 struct cfg80211_registered_device *rdev;
352 int err;
353
354 if (!wdev)
355 return -EOPNOTSUPP;
356
357 rdev = wiphy_to_dev(wdev->wiphy);
358
359 if (wdev->iftype != NL80211_IFTYPE_STATION)
360 return -EINVAL;
361
362 if (mlme->addr.sa_family != ARPHRD_ETHER)
363 return -EINVAL;
364
365 wdev_lock(wdev);
366 switch (mlme->cmd) {
367 case IW_MLME_DEAUTH:
368 case IW_MLME_DISASSOC:
369 err = __cfg80211_disconnect(rdev, dev, mlme->reason_code,
370 true);
371 break;
372 default:
373 err = -EOPNOTSUPP;
374 break;
375 }
376 wdev_unlock(wdev);
377
378 return err;
379}
380EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme);
diff --git a/net/wireless/wext.c b/net/wireless/wext.c
index 252c2010c2e2..3fe3c2c0ce11 100644
--- a/net/wireless/wext.c
+++ b/net/wireless/wext.c
@@ -417,6 +417,21 @@ static const int event_type_size[] = {
417 IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */ 417 IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
418}; 418};
419 419
420#ifdef CONFIG_COMPAT
421static const int compat_event_type_size[] = {
422 IW_EV_COMPAT_LCP_LEN, /* IW_HEADER_TYPE_NULL */
423 0,
424 IW_EV_COMPAT_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
425 0,
426 IW_EV_COMPAT_UINT_LEN, /* IW_HEADER_TYPE_UINT */
427 IW_EV_COMPAT_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
428 IW_EV_COMPAT_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
429 0,
430 IW_EV_COMPAT_POINT_LEN, /* Without variable payload */
431 IW_EV_COMPAT_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
432 IW_EV_COMPAT_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
433};
434#endif
420 435
421/************************ COMMON SUBROUTINES ************************/ 436/************************ COMMON SUBROUTINES ************************/
422/* 437/*
@@ -610,6 +625,11 @@ static void wireless_seq_printf_stats(struct seq_file *seq,
610{ 625{
611 /* Get stats from the driver */ 626 /* Get stats from the driver */
612 struct iw_statistics *stats = get_wireless_stats(dev); 627 struct iw_statistics *stats = get_wireless_stats(dev);
628 static struct iw_statistics nullstats = {};
629
630 /* show device if it's wireless regardless of current stats */
631 if (!stats && dev->wireless_handlers)
632 stats = &nullstats;
613 633
614 if (stats) { 634 if (stats) {
615 seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d " 635 seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
@@ -628,7 +648,9 @@ static void wireless_seq_printf_stats(struct seq_file *seq,
628 stats->discard.nwid, stats->discard.code, 648 stats->discard.nwid, stats->discard.code,
629 stats->discard.fragment, stats->discard.retries, 649 stats->discard.fragment, stats->discard.retries,
630 stats->discard.misc, stats->miss.beacon); 650 stats->discard.misc, stats->miss.beacon);
631 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED; 651
652 if (stats != &nullstats)
653 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
632 } 654 }
633} 655}
634 656
@@ -1250,65 +1272,58 @@ int compat_wext_handle_ioctl(struct net *net, unsigned int cmd,
1250} 1272}
1251#endif 1273#endif
1252 1274
1253/************************* EVENT PROCESSING *************************/ 1275static int __net_init wext_pernet_init(struct net *net)
1254/* 1276{
1255 * Process events generated by the wireless layer or the driver. 1277 skb_queue_head_init(&net->wext_nlevents);
1256 * Most often, the event will be propagated through rtnetlink 1278 return 0;
1257 */ 1279}
1258 1280
1259/* ---------------------------------------------------------------- */ 1281static void __net_exit wext_pernet_exit(struct net *net)
1260/* 1282{
1261 * Locking... 1283 skb_queue_purge(&net->wext_nlevents);
1262 * ---------- 1284}
1263 *
1264 * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing
1265 * the locking issue in here and implementing this code !
1266 *
1267 * The issue : wireless_send_event() is often called in interrupt context,
1268 * while the Netlink layer can never be called in interrupt context.
1269 * The fully formed RtNetlink events are queued, and then a tasklet is run
1270 * to feed those to Netlink.
1271 * The skb_queue is interrupt safe, and its lock is not held while calling
1272 * Netlink, so there is no possibility of dealock.
1273 * Jean II
1274 */
1275 1285
1276static struct sk_buff_head wireless_nlevent_queue; 1286static struct pernet_operations wext_pernet_ops = {
1287 .init = wext_pernet_init,
1288 .exit = wext_pernet_exit,
1289};
1277 1290
1278static int __init wireless_nlevent_init(void) 1291static int __init wireless_nlevent_init(void)
1279{ 1292{
1280 skb_queue_head_init(&wireless_nlevent_queue); 1293 return register_pernet_subsys(&wext_pernet_ops);
1281 return 0; 1294 return 0;
1282} 1295}
1283 1296
1284subsys_initcall(wireless_nlevent_init); 1297subsys_initcall(wireless_nlevent_init);
1285 1298
1286static void wireless_nlevent_process(unsigned long data) 1299/* Process events generated by the wireless layer or the driver. */
1300static void wireless_nlevent_process(struct work_struct *work)
1287{ 1301{
1288 struct sk_buff *skb; 1302 struct sk_buff *skb;
1303 struct net *net;
1304
1305 rtnl_lock();
1306
1307 for_each_net(net) {
1308 while ((skb = skb_dequeue(&net->wext_nlevents)))
1309 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL,
1310 GFP_KERNEL);
1311 }
1289 1312
1290 while ((skb = skb_dequeue(&wireless_nlevent_queue))) 1313 rtnl_unlock();
1291 rtnl_notify(skb, &init_net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
1292} 1314}
1293 1315
1294static DECLARE_TASKLET(wireless_nlevent_tasklet, wireless_nlevent_process, 0); 1316static DECLARE_WORK(wireless_nlevent_work, wireless_nlevent_process);
1295 1317
1296/* ---------------------------------------------------------------- */ 1318static struct nlmsghdr *rtnetlink_ifinfo_prep(struct net_device *dev,
1297/* 1319 struct sk_buff *skb)
1298 * Fill a rtnetlink message with our event data.
1299 * Note that we propage only the specified event and don't dump the
1300 * current wireless config. Dumping the wireless config is far too
1301 * expensive (for each parameter, the driver need to query the hardware).
1302 */
1303static int rtnetlink_fill_iwinfo(struct sk_buff *skb, struct net_device *dev,
1304 int type, char *event, int event_len)
1305{ 1320{
1306 struct ifinfomsg *r; 1321 struct ifinfomsg *r;
1307 struct nlmsghdr *nlh; 1322 struct nlmsghdr *nlh;
1308 1323
1309 nlh = nlmsg_put(skb, 0, 0, type, sizeof(*r), 0); 1324 nlh = nlmsg_put(skb, 0, 0, RTM_NEWLINK, sizeof(*r), 0);
1310 if (nlh == NULL) 1325 if (!nlh)
1311 return -EMSGSIZE; 1326 return NULL;
1312 1327
1313 r = nlmsg_data(nlh); 1328 r = nlmsg_data(nlh);
1314 r->ifi_family = AF_UNSPEC; 1329 r->ifi_family = AF_UNSPEC;
@@ -1319,48 +1334,14 @@ static int rtnetlink_fill_iwinfo(struct sk_buff *skb, struct net_device *dev,
1319 r->ifi_change = 0; /* Wireless changes don't affect those flags */ 1334 r->ifi_change = 0; /* Wireless changes don't affect those flags */
1320 1335
1321 NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name); 1336 NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name);
1322 /* Add the wireless events in the netlink packet */
1323 NLA_PUT(skb, IFLA_WIRELESS, event_len, event);
1324 1337
1325 return nlmsg_end(skb, nlh); 1338 return nlh;
1326 1339 nla_put_failure:
1327nla_put_failure:
1328 nlmsg_cancel(skb, nlh); 1340 nlmsg_cancel(skb, nlh);
1329 return -EMSGSIZE; 1341 return NULL;
1330} 1342}
1331 1343
1332/* ---------------------------------------------------------------- */
1333/*
1334 * Create and broadcast and send it on the standard rtnetlink socket
1335 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1336 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1337 * within a RTM_NEWLINK event.
1338 */
1339static void rtmsg_iwinfo(struct net_device *dev, char *event, int event_len)
1340{
1341 struct sk_buff *skb;
1342 int err;
1343
1344 if (!net_eq(dev_net(dev), &init_net))
1345 return;
1346
1347 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1348 if (!skb)
1349 return;
1350
1351 err = rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK, event, event_len);
1352 if (err < 0) {
1353 WARN_ON(err == -EMSGSIZE);
1354 kfree_skb(skb);
1355 return;
1356 }
1357
1358 NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
1359 skb_queue_tail(&wireless_nlevent_queue, skb);
1360 tasklet_schedule(&wireless_nlevent_tasklet);
1361}
1362 1344
1363/* ---------------------------------------------------------------- */
1364/* 1345/*
1365 * Main event dispatcher. Called from other parts and drivers. 1346 * Main event dispatcher. Called from other parts and drivers.
1366 * Send the event on the appropriate channels. 1347 * Send the event on the appropriate channels.
@@ -1369,7 +1350,7 @@ static void rtmsg_iwinfo(struct net_device *dev, char *event, int event_len)
1369void wireless_send_event(struct net_device * dev, 1350void wireless_send_event(struct net_device * dev,
1370 unsigned int cmd, 1351 unsigned int cmd,
1371 union iwreq_data * wrqu, 1352 union iwreq_data * wrqu,
1372 char * extra) 1353 const char * extra)
1373{ 1354{
1374 const struct iw_ioctl_description * descr = NULL; 1355 const struct iw_ioctl_description * descr = NULL;
1375 int extra_len = 0; 1356 int extra_len = 0;
@@ -1379,6 +1360,25 @@ void wireless_send_event(struct net_device * dev,
1379 int wrqu_off = 0; /* Offset in wrqu */ 1360 int wrqu_off = 0; /* Offset in wrqu */
1380 /* Don't "optimise" the following variable, it will crash */ 1361 /* Don't "optimise" the following variable, it will crash */
1381 unsigned cmd_index; /* *MUST* be unsigned */ 1362 unsigned cmd_index; /* *MUST* be unsigned */
1363 struct sk_buff *skb;
1364 struct nlmsghdr *nlh;
1365 struct nlattr *nla;
1366#ifdef CONFIG_COMPAT
1367 struct __compat_iw_event *compat_event;
1368 struct compat_iw_point compat_wrqu;
1369 struct sk_buff *compskb;
1370#endif
1371
1372 /*
1373 * Nothing in the kernel sends scan events with data, be safe.
1374 * This is necessary because we cannot fix up scan event data
1375 * for compat, due to being contained in 'extra', but normally
1376 * applications are required to retrieve the scan data anyway
1377 * and no data is included in the event, this codifies that
1378 * practice.
1379 */
1380 if (WARN_ON(cmd == SIOCGIWSCAN && extra))
1381 extra = NULL;
1382 1382
1383 /* Get the description of the Event */ 1383 /* Get the description of the Event */
1384 if (cmd <= SIOCIWLAST) { 1384 if (cmd <= SIOCIWLAST) {
@@ -1426,25 +1426,107 @@ void wireless_send_event(struct net_device * dev,
1426 hdr_len = event_type_size[descr->header_type]; 1426 hdr_len = event_type_size[descr->header_type];
1427 event_len = hdr_len + extra_len; 1427 event_len = hdr_len + extra_len;
1428 1428
1429 /* Create temporary buffer to hold the event */ 1429 /*
1430 event = kmalloc(event_len, GFP_ATOMIC); 1430 * The problem for 64/32 bit.
1431 if (event == NULL) 1431 *
1432 * On 64-bit, a regular event is laid out as follows:
1433 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
1434 * | event.len | event.cmd | p a d d i n g |
1435 * | wrqu data ... (with the correct size) |
1436 *
1437 * This padding exists because we manipulate event->u,
1438 * and 'event' is not packed.
1439 *
1440 * An iw_point event is laid out like this instead:
1441 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
1442 * | event.len | event.cmd | p a d d i n g |
1443 * | iwpnt.len | iwpnt.flg | p a d d i n g |
1444 * | extra data ...
1445 *
1446 * The second padding exists because struct iw_point is extended,
1447 * but this depends on the platform...
1448 *
1449 * On 32-bit, all the padding shouldn't be there.
1450 */
1451
1452 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1453 if (!skb)
1454 return;
1455
1456 /* Send via the RtNetlink event channel */
1457 nlh = rtnetlink_ifinfo_prep(dev, skb);
1458 if (WARN_ON(!nlh)) {
1459 kfree_skb(skb);
1460 return;
1461 }
1462
1463 /* Add the wireless events in the netlink packet */
1464 nla = nla_reserve(skb, IFLA_WIRELESS, event_len);
1465 if (!nla) {
1466 kfree_skb(skb);
1432 return; 1467 return;
1468 }
1469 event = nla_data(nla);
1433 1470
1434 /* Fill event */ 1471 /* Fill event - first clear to avoid data leaking */
1472 memset(event, 0, hdr_len);
1435 event->len = event_len; 1473 event->len = event_len;
1436 event->cmd = cmd; 1474 event->cmd = cmd;
1437 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN); 1475 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
1438 if (extra) 1476 if (extra_len)
1439 memcpy(((char *) event) + hdr_len, extra, extra_len); 1477 memcpy(((char *) event) + hdr_len, extra, extra_len);
1440 1478
1479 nlmsg_end(skb, nlh);
1480#ifdef CONFIG_COMPAT
1481 hdr_len = compat_event_type_size[descr->header_type];
1482 event_len = hdr_len + extra_len;
1483
1484 compskb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1485 if (!compskb) {
1486 kfree_skb(skb);
1487 return;
1488 }
1489
1441 /* Send via the RtNetlink event channel */ 1490 /* Send via the RtNetlink event channel */
1442 rtmsg_iwinfo(dev, (char *) event, event_len); 1491 nlh = rtnetlink_ifinfo_prep(dev, compskb);
1492 if (WARN_ON(!nlh)) {
1493 kfree_skb(skb);
1494 kfree_skb(compskb);
1495 return;
1496 }
1443 1497
1444 /* Cleanup */ 1498 /* Add the wireless events in the netlink packet */
1445 kfree(event); 1499 nla = nla_reserve(compskb, IFLA_WIRELESS, event_len);
1500 if (!nla) {
1501 kfree_skb(skb);
1502 kfree_skb(compskb);
1503 return;
1504 }
1505 compat_event = nla_data(nla);
1446 1506
1447 return; /* Always success, I guess ;-) */ 1507 compat_event->len = event_len;
1508 compat_event->cmd = cmd;
1509 if (descr->header_type == IW_HEADER_TYPE_POINT) {
1510 compat_wrqu.length = wrqu->data.length;
1511 compat_wrqu.flags = wrqu->data.flags;
1512 memcpy(&compat_event->pointer,
1513 ((char *) &compat_wrqu) + IW_EV_COMPAT_POINT_OFF,
1514 hdr_len - IW_EV_COMPAT_LCP_LEN);
1515 if (extra_len)
1516 memcpy(((char *) compat_event) + hdr_len,
1517 extra, extra_len);
1518 } else {
1519 /* extra_len must be zero, so no if (extra) needed */
1520 memcpy(&compat_event->pointer, wrqu,
1521 hdr_len - IW_EV_COMPAT_LCP_LEN);
1522 }
1523
1524 nlmsg_end(compskb, nlh);
1525
1526 skb_shinfo(skb)->frag_list = compskb;
1527#endif
1528 skb_queue_tail(&dev_net(dev)->wext_nlevents, skb);
1529 schedule_work(&wireless_nlevent_work);
1448} 1530}
1449EXPORT_SYMBOL(wireless_send_event); 1531EXPORT_SYMBOL(wireless_send_event);
1450 1532
diff --git a/scripts/.gitignore b/scripts/.gitignore
index b939fbd01195..52cab46ae35a 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -7,3 +7,4 @@ pnmtologo
7bin2c 7bin2c
8unifdef 8unifdef
9binoffset 9binoffset
10ihex2fw
diff --git a/scripts/dtc/.gitignore b/scripts/dtc/.gitignore
new file mode 100644
index 000000000000..095acb49a374
--- /dev/null
+++ b/scripts/dtc/.gitignore
@@ -0,0 +1,5 @@
1dtc
2dtc-lexer.lex.c
3dtc-parser.tab.c
4dtc-parser.tab.h
5
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index ed591e9b7d1d..b52d340d759d 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -1426,6 +1426,8 @@ sub dump_struct($$) {
1426 # strip comments: 1426 # strip comments:
1427 $members =~ s/\/\*.*?\*\///gos; 1427 $members =~ s/\/\*.*?\*\///gos;
1428 $nested =~ s/\/\*.*?\*\///gos; 1428 $nested =~ s/\/\*.*?\*\///gos;
1429 # strip kmemcheck_bitfield_{begin,end}.*;
1430 $members =~ s/kmemcheck_bitfield_.*?;//gos;
1429 1431
1430 create_parameterlist($members, ';', $file); 1432 create_parameterlist($members, ';', $file);
1431 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 1433 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
@@ -1468,8 +1470,6 @@ sub dump_enum($$) {
1468 } 1470 }
1469 1471
1470 } 1472 }
1471 # strip kmemcheck_bitfield_{begin,end}.*;
1472 $members =~ s/kmemcheck_bitfield_.*?;//gos;
1473 1473
1474 output_declaration($declaration_name, 1474 output_declaration($declaration_name,
1475 'enum', 1475 'enum',
diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 01c2d13dd020..b19f1f4962e3 100644
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -16,6 +16,8 @@ create_package() {
16 local pname="$1" pdir="$2" 16 local pname="$1" pdir="$2"
17 17
18 cp debian/copyright "$pdir/usr/share/doc/$pname/" 18 cp debian/copyright "$pdir/usr/share/doc/$pname/"
19 cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
20 gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
19 21
20 # Fix ownership and permissions 22 # Fix ownership and permissions
21 chown -R root:root "$pdir" 23 chown -R root:root "$pdir"
diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
index 64f5ddb09ea6..5c113123ed9f 100644
--- a/scripts/pnmtologo.c
+++ b/scripts/pnmtologo.c
@@ -237,7 +237,7 @@ static void write_header(void)
237 fprintf(out, " * Linux logo %s\n", logoname); 237 fprintf(out, " * Linux logo %s\n", logoname);
238 fputs(" */\n\n", out); 238 fputs(" */\n\n", out);
239 fputs("#include <linux/linux_logo.h>\n\n", out); 239 fputs("#include <linux/linux_logo.h>\n\n", out);
240 fprintf(out, "static const unsigned char %s_data[] __initconst = {\n", 240 fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
241 logoname); 241 logoname);
242} 242}
243 243
@@ -374,7 +374,7 @@ static void write_logo_clut224(void)
374 fputs("\n};\n\n", out); 374 fputs("\n};\n\n", out);
375 375
376 /* write logo clut */ 376 /* write logo clut */
377 fprintf(out, "static const unsigned char %s_clut[] __initconst = {\n", 377 fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
378 logoname); 378 logoname);
379 write_hex_cnt = 0; 379 write_hex_cnt = 0;
380 for (i = 0; i < logo_clutsize; i++) { 380 for (i = 0; i < logo_clutsize; i++) {
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index 6f611874d10e..101c512564ec 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -238,7 +238,34 @@ out:
238} 238}
239 239
240/* 240/*
241 * ima_opens_get - increment file counts 241 * ima_counts_put - decrement file counts
242 *
243 * File counts are incremented in ima_path_check. On file open
244 * error, such as ETXTBSY, decrement the counts to prevent
245 * unnecessary imbalance messages.
246 */
247void ima_counts_put(struct path *path, int mask)
248{
249 struct inode *inode = path->dentry->d_inode;
250 struct ima_iint_cache *iint;
251
252 if (!ima_initialized || !S_ISREG(inode->i_mode))
253 return;
254 iint = ima_iint_find_insert_get(inode);
255 if (!iint)
256 return;
257
258 mutex_lock(&iint->mutex);
259 iint->opencount--;
260 if ((mask & MAY_WRITE) || (mask == 0))
261 iint->writecount--;
262 else if (mask & (MAY_READ | MAY_EXEC))
263 iint->readcount--;
264 mutex_unlock(&iint->mutex);
265}
266
267/*
268 * ima_counts_get - increment file counts
242 * 269 *
243 * - for IPC shm and shmat file. 270 * - for IPC shm and shmat file.
244 * - for nfsd exported files. 271 * - for nfsd exported files.
diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
index 7ec94314ac0c..a0880e9c8e05 100644
--- a/security/integrity/ima/ima_queue.c
+++ b/security/integrity/ima/ima_queue.c
@@ -134,7 +134,8 @@ int ima_add_template_entry(struct ima_template_entry *entry, int violation,
134 } 134 }
135out: 135out:
136 mutex_unlock(&ima_extend_list_mutex); 136 mutex_unlock(&ima_extend_list_mutex);
137 integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode, entry->template_name, 137 integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode,
138 entry->template.file_name,
138 op, audit_cause, result, audit_info); 139 op, audit_cause, result, audit_info);
139 return result; 140 return result;
140} 141}
diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
index de83608719ea..3ee0269e5bd0 100644
--- a/sound/isa/cmi8330.c
+++ b/sound/isa/cmi8330.c
@@ -338,7 +338,7 @@ static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
338 return -EBUSY; 338 return -EBUSY;
339 339
340 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL); 340 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
341 if (acard->play == NULL) 341 if (acard->mpu == NULL)
342 return -EBUSY; 342 return -EBUSY;
343 343
344 pdev = acard->cap; 344 pdev = acard->cap;
diff --git a/sound/oss/kahlua.c b/sound/oss/kahlua.c
index c180598f1710..89466b056be7 100644
--- a/sound/oss/kahlua.c
+++ b/sound/oss/kahlua.c
@@ -199,7 +199,7 @@ MODULE_LICENSE("GPL");
199 */ 199 */
200 200
201static struct pci_device_id id_tbl[] = { 201static struct pci_device_id id_tbl[] = {
202 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 202 { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO), 0 },
203 { } 203 { }
204}; 204};
205 205
diff --git a/sound/oss/mpu401.c b/sound/oss/mpu401.c
index 6c0a770ed054..1b2316f35b1f 100644
--- a/sound/oss/mpu401.c
+++ b/sound/oss/mpu401.c
@@ -926,31 +926,21 @@ static struct midi_operations mpu401_midi_operations[MAX_MIDI_DEV];
926static void mpu401_chk_version(int n, struct mpu_config *devc) 926static void mpu401_chk_version(int n, struct mpu_config *devc)
927{ 927{
928 int tmp; 928 int tmp;
929 unsigned long flags;
930 929
931 devc->version = devc->revision = 0; 930 devc->version = devc->revision = 0;
932 931
933 spin_lock_irqsave(&devc->lock,flags); 932 tmp = mpu_cmd(n, 0xAC, 0);
934 if ((tmp = mpu_cmd(n, 0xAC, 0)) < 0) 933 if (tmp < 0)
935 {
936 spin_unlock_irqrestore(&devc->lock,flags);
937 return; 934 return;
938 }
939 if ((tmp & 0xf0) > 0x20) /* Why it's larger than 2.x ??? */ 935 if ((tmp & 0xf0) > 0x20) /* Why it's larger than 2.x ??? */
940 {
941 spin_unlock_irqrestore(&devc->lock,flags);
942 return; 936 return;
943 }
944 devc->version = tmp; 937 devc->version = tmp;
945 938
946 if ((tmp = mpu_cmd(n, 0xAD, 0)) < 0) 939 if ((tmp = mpu_cmd(n, 0xAD, 0)) < 0) {
947 {
948 devc->version = 0; 940 devc->version = 0;
949 spin_unlock_irqrestore(&devc->lock,flags);
950 return; 941 return;
951 } 942 }
952 devc->revision = tmp; 943 devc->revision = tmp;
953 spin_unlock_irqrestore(&devc->lock,flags);
954} 944}
955 945
956int attach_mpu401(struct address_info *hw_config, struct module *owner) 946int attach_mpu401(struct address_info *hw_config, struct module *owner)
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index 71515ddb4593..d6752dff2a44 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -287,10 +287,10 @@ struct atiixp {
287/* 287/*
288 */ 288 */
289static struct pci_device_id snd_atiixp_ids[] = { 289static struct pci_device_id snd_atiixp_ids[] = {
290 { 0x1002, 0x4341, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB200 */ 290 { PCI_VDEVICE(ATI, 0x4341), 0 }, /* SB200 */
291 { 0x1002, 0x4361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB300 */ 291 { PCI_VDEVICE(ATI, 0x4361), 0 }, /* SB300 */
292 { 0x1002, 0x4370, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB400 */ 292 { PCI_VDEVICE(ATI, 0x4370), 0 }, /* SB400 */
293 { 0x1002, 0x4382, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB600 */ 293 { PCI_VDEVICE(ATI, 0x4382), 0 }, /* SB600 */
294 { 0, } 294 { 0, }
295}; 295};
296 296
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index c3136cccc559..e7e147bf8eb2 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -262,8 +262,8 @@ struct atiixp_modem {
262/* 262/*
263 */ 263 */
264static struct pci_device_id snd_atiixp_ids[] = { 264static struct pci_device_id snd_atiixp_ids[] = {
265 { 0x1002, 0x434d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB200 */ 265 { PCI_VDEVICE(ATI, 0x434d), 0 }, /* SB200 */
266 { 0x1002, 0x4378, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB400 */ 266 { PCI_VDEVICE(ATI, 0x4378), 0 }, /* SB400 */
267 { 0, } 267 { 0, }
268}; 268};
269 269
diff --git a/sound/pci/au88x0/au8810.c b/sound/pci/au88x0/au8810.c
index fce22c7af0ea..c0e8c6b295cb 100644
--- a/sound/pci/au88x0/au8810.c
+++ b/sound/pci/au88x0/au8810.c
@@ -1,8 +1,7 @@
1#include "au8810.h" 1#include "au8810.h"
2#include "au88x0.h" 2#include "au88x0.h"
3static struct pci_device_id snd_vortex_ids[] = { 3static struct pci_device_id snd_vortex_ids[] = {
4 {PCI_VENDOR_ID_AUREAL, PCI_DEVICE_ID_AUREAL_ADVANTAGE, 4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_ADVANTAGE), 1,},
5 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1,},
6 {0,} 5 {0,}
7}; 6};
8 7
diff --git a/sound/pci/au88x0/au8820.c b/sound/pci/au88x0/au8820.c
index d1fbcce07257..a6527330df58 100644
--- a/sound/pci/au88x0/au8820.c
+++ b/sound/pci/au88x0/au8820.c
@@ -1,8 +1,7 @@
1#include "au8820.h" 1#include "au8820.h"
2#include "au88x0.h" 2#include "au88x0.h"
3static struct pci_device_id snd_vortex_ids[] = { 3static struct pci_device_id snd_vortex_ids[] = {
4 {PCI_VENDOR_ID_AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_1, 4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_1), 0,},
5 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
6 {0,} 5 {0,}
7}; 6};
8 7
diff --git a/sound/pci/au88x0/au8830.c b/sound/pci/au88x0/au8830.c
index d4f2717c14fb..6c702ad4352a 100644
--- a/sound/pci/au88x0/au8830.c
+++ b/sound/pci/au88x0/au8830.c
@@ -1,8 +1,7 @@
1#include "au8830.h" 1#include "au8830.h"
2#include "au88x0.h" 2#include "au88x0.h"
3static struct pci_device_id snd_vortex_ids[] = { 3static struct pci_device_id snd_vortex_ids[] = {
4 {PCI_VENDOR_ID_AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_2, 4 {PCI_VDEVICE(AUREAL, PCI_DEVICE_ID_AUREAL_VORTEX_2), 0,},
5 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
6 {0,} 5 {0,}
7}; 6};
8 7
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 57b992a5c057..f24bf1ecb36d 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -1876,7 +1876,7 @@ static int snd_ca0106_resume(struct pci_dev *pci)
1876 1876
1877// PCI IDs 1877// PCI IDs
1878static struct pci_device_id snd_ca0106_ids[] = { 1878static struct pci_device_id snd_ca0106_ids[] = {
1879 { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */ 1879 { PCI_VDEVICE(CREATIVE, 0x0007), 0 }, /* Audigy LS or Live 24bit */
1880 { 0, } 1880 { 0, }
1881}; 1881};
1882MODULE_DEVICE_TABLE(pci, snd_ca0106_ids); 1882MODULE_DEVICE_TABLE(pci, snd_ca0106_ids);
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 449fe02f666e..ddcd4a9fd7e6 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2797,11 +2797,11 @@ static inline void snd_cmipci_proc_init(struct cmipci *cm) {}
2797 2797
2798 2798
2799static struct pci_device_id snd_cmipci_ids[] = { 2799static struct pci_device_id snd_cmipci_ids[] = {
2800 {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2800 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A), 0},
2801 {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2801 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B), 0},
2802 {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2802 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738), 0},
2803 {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2803 {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738B), 0},
2804 {PCI_VENDOR_ID_AL, PCI_DEVICE_ID_CMEDIA_CM8738, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2804 {PCI_VDEVICE(AL, PCI_DEVICE_ID_CMEDIA_CM8738), 0},
2805 {0,}, 2805 {0,},
2806}; 2806};
2807 2807
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index f6286f84a221..e2e0359bb056 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -495,7 +495,7 @@ struct cs4281 {
495static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id); 495static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id);
496 496
497static struct pci_device_id snd_cs4281_ids[] = { 497static struct pci_device_id snd_cs4281_ids[] = {
498 { 0x1013, 0x6005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CS4281 */ 498 { PCI_VDEVICE(CIRRUS, 0x6005), 0, }, /* CS4281 */
499 { 0, } 499 { 0, }
500}; 500};
501 501
diff --git a/sound/pci/cs46xx/cs46xx.c b/sound/pci/cs46xx/cs46xx.c
index c9b3e3d48cbc..033aec430117 100644
--- a/sound/pci/cs46xx/cs46xx.c
+++ b/sound/pci/cs46xx/cs46xx.c
@@ -65,9 +65,9 @@ module_param_array(mmap_valid, bool, NULL, 0444);
65MODULE_PARM_DESC(mmap_valid, "Support OSS mmap."); 65MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
66 66
67static struct pci_device_id snd_cs46xx_ids[] = { 67static struct pci_device_id snd_cs46xx_ids[] = {
68 { 0x1013, 0x6001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CS4280 */ 68 { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */
69 { 0x1013, 0x6003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CS4612 */ 69 { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */
70 { 0x1013, 0x6004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CS4615 */ 70 { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */
71 { 0, } 71 { 0, }
72}; 72};
73 73
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c
index c7f3b994101c..168af67d938e 100644
--- a/sound/pci/emu10k1/emu10k1.c
+++ b/sound/pci/emu10k1/emu10k1.c
@@ -77,9 +77,9 @@ MODULE_PARM_DESC(subsystem, "Force card subsystem model.");
77 * Class 0401: 1102:0008 (rev 00) Subsystem: 1102:1001 -> Audigy2 Value Model:SB0400 77 * Class 0401: 1102:0008 (rev 00) Subsystem: 1102:1001 -> Audigy2 Value Model:SB0400
78 */ 78 */
79static struct pci_device_id snd_emu10k1_ids[] = { 79static struct pci_device_id snd_emu10k1_ids[] = {
80 { 0x1102, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* EMU10K1 */ 80 { PCI_VDEVICE(CREATIVE, 0x0002), 0 }, /* EMU10K1 */
81 { 0x1102, 0x0004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, /* Audigy */ 81 { PCI_VDEVICE(CREATIVE, 0x0004), 1 }, /* Audigy */
82 { 0x1102, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, /* Audigy 2 Value SB0400 */ 82 { PCI_VDEVICE(CREATIVE, 0x0008), 1 }, /* Audigy 2 Value SB0400 */
83 { 0, } 83 { 0, }
84}; 84};
85 85
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 4d3ad793e98f..36e08bd2b3cc 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -1607,7 +1607,7 @@ static void __devexit snd_emu10k1x_remove(struct pci_dev *pci)
1607 1607
1608// PCI IDs 1608// PCI IDs
1609static struct pci_device_id snd_emu10k1x_ids[] = { 1609static struct pci_device_id snd_emu10k1x_ids[] = {
1610 { 0x1102, 0x0006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Dell OEM version (EMU10K1) */ 1610 { PCI_VDEVICE(CREATIVE, 0x0006), 0 }, /* Dell OEM version (EMU10K1) */
1611 { 0, } 1611 { 0, }
1612}; 1612};
1613MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids); 1613MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids);
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index 18f4d1e98c46..2b82c5c723e1 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -445,12 +445,12 @@ static irqreturn_t snd_audiopci_interrupt(int irq, void *dev_id);
445 445
446static struct pci_device_id snd_audiopci_ids[] = { 446static struct pci_device_id snd_audiopci_ids[] = {
447#ifdef CHIP1370 447#ifdef CHIP1370
448 { 0x1274, 0x5000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1370 */ 448 { PCI_VDEVICE(ENSONIQ, 0x5000), 0, }, /* ES1370 */
449#endif 449#endif
450#ifdef CHIP1371 450#ifdef CHIP1371
451 { 0x1274, 0x1371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1371 */ 451 { PCI_VDEVICE(ENSONIQ, 0x1371), 0, }, /* ES1371 */
452 { 0x1274, 0x5880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1373 - CT5880 */ 452 { PCI_VDEVICE(ENSONIQ, 0x5880), 0, }, /* ES1373 - CT5880 */
453 { 0x1102, 0x8938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ectiva EV1938 */ 453 { PCI_VDEVICE(ECTIVA, 0x8938), 0, }, /* Ectiva EV1938 */
454#endif 454#endif
455 { 0, } 455 { 0, }
456}; 456};
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index fbd2ac09aa34..820318ee62c1 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -244,7 +244,7 @@ struct es1938 {
244static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id); 244static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id);
245 245
246static struct pci_device_id snd_es1938_ids[] = { 246static struct pci_device_id snd_es1938_ids[] = {
247 { 0x125d, 0x1969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Solo-1 */ 247 { PCI_VDEVICE(ESS, 0x1969), 0, }, /* Solo-1 */
248 { 0, } 248 { 0, }
249}; 249};
250 250
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 462e2cedaa6a..26d255de6beb 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -3470,10 +3470,16 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,
3470 } 3470 }
3471 mutex_lock(&codec->spdif_mutex); 3471 mutex_lock(&codec->spdif_mutex);
3472 if (mout->share_spdif) { 3472 if (mout->share_spdif) {
3473 runtime->hw.rates &= mout->spdif_rates; 3473 if ((runtime->hw.rates & mout->spdif_rates) &&
3474 runtime->hw.formats &= mout->spdif_formats; 3474 (runtime->hw.formats & mout->spdif_formats)) {
3475 if (mout->spdif_maxbps < hinfo->maxbps) 3475 runtime->hw.rates &= mout->spdif_rates;
3476 hinfo->maxbps = mout->spdif_maxbps; 3476 runtime->hw.formats &= mout->spdif_formats;
3477 if (mout->spdif_maxbps < hinfo->maxbps)
3478 hinfo->maxbps = mout->spdif_maxbps;
3479 } else {
3480 mout->share_spdif = 0;
3481 /* FIXME: need notify? */
3482 }
3477 } 3483 }
3478 mutex_unlock(&codec->spdif_mutex); 3484 mutex_unlock(&codec->spdif_mutex);
3479 } 3485 }
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 4e9ea7080270..1877d95d4aa6 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -1454,6 +1454,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1454 mutex_unlock(&chip->open_mutex); 1454 mutex_unlock(&chip->open_mutex);
1455 return err; 1455 return err;
1456 } 1456 }
1457 snd_pcm_limit_hw_rates(runtime);
1457 spin_lock_irqsave(&chip->reg_lock, flags); 1458 spin_lock_irqsave(&chip->reg_lock, flags);
1458 azx_dev->substream = substream; 1459 azx_dev->substream = substream;
1459 azx_dev->running = 0; 1460 azx_dev->running = 0;
@@ -1463,6 +1464,12 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1463 snd_pcm_set_sync(substream); 1464 snd_pcm_set_sync(substream);
1464 mutex_unlock(&chip->open_mutex); 1465 mutex_unlock(&chip->open_mutex);
1465 1466
1467 if (snd_BUG_ON(!runtime->hw.channels_min || !runtime->hw.channels_max))
1468 return -EINVAL;
1469 if (snd_BUG_ON(!runtime->hw.formats))
1470 return -EINVAL;
1471 if (snd_BUG_ON(!runtime->hw.rates))
1472 return -EINVAL;
1466 return 0; 1473 return 0;
1467} 1474}
1468 1475
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 84cc49ca9148..be7d25fa7f35 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -72,6 +72,7 @@ struct ad198x_spec {
72 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 72 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
73 73
74 unsigned int jack_present :1; 74 unsigned int jack_present :1;
75 unsigned int inv_jack_detect:1;
75 76
76#ifdef CONFIG_SND_HDA_POWER_SAVE 77#ifdef CONFIG_SND_HDA_POWER_SAVE
77 struct hda_loopback_check loopback; 78 struct hda_loopback_check loopback;
@@ -669,39 +670,13 @@ static struct hda_input_mux ad1986a_automic_capture_source = {
669 }, 670 },
670}; 671};
671 672
672static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = { 673static struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
673 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol), 674 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
674 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw), 675 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
675 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
676 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
677 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
678 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
679 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
680 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
681 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
682 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
683 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
684 {
685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
686 .name = "Capture Source",
687 .info = ad198x_mux_enum_info,
688 .get = ad198x_mux_enum_get,
689 .put = ad198x_mux_enum_put,
690 },
691 {
692 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
693 .name = "External Amplifier",
694 .info = ad198x_eapd_info,
695 .get = ad198x_eapd_get,
696 .put = ad198x_eapd_put,
697 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
698 },
699 { } /* end */ 676 { } /* end */
700}; 677};
701 678
702static struct snd_kcontrol_new ad1986a_samsung_mixers[] = { 679static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
703 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
704 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
705 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT), 680 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
706 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), 681 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
707 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 682 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
@@ -727,6 +702,12 @@ static struct snd_kcontrol_new ad1986a_samsung_mixers[] = {
727 { } /* end */ 702 { } /* end */
728}; 703};
729 704
705static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
706 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
707 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
708 { } /* end */
709};
710
730/* re-connect the mic boost input according to the jack sensing */ 711/* re-connect the mic boost input according to the jack sensing */
731static void ad1986a_automic(struct hda_codec *codec) 712static void ad1986a_automic(struct hda_codec *codec)
732{ 713{
@@ -776,8 +757,9 @@ static void ad1986a_hp_automute(struct hda_codec *codec)
776 unsigned int present; 757 unsigned int present;
777 758
778 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0); 759 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
779 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */ 760 spec->jack_present = !!(present & 0x80000000);
780 spec->jack_present = !(present & 0x80000000); 761 if (spec->inv_jack_detect)
762 spec->jack_present = !spec->jack_present;
781 ad1986a_update_hp(codec); 763 ad1986a_update_hp(codec);
782} 764}
783 765
@@ -816,7 +798,7 @@ static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
816 return change; 798 return change;
817} 799}
818 800
819static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = { 801static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
820 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol), 802 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
821 { 803 {
822 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -826,33 +808,10 @@ static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
826 .put = ad1986a_hp_master_sw_put, 808 .put = ad1986a_hp_master_sw_put,
827 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT), 809 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
828 }, 810 },
829 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
830 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
831 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
832 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
833 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
834 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
835 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
836 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
837 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
838 {
839 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
840 .name = "Capture Source",
841 .info = ad198x_mux_enum_info,
842 .get = ad198x_mux_enum_get,
843 .put = ad198x_mux_enum_put,
844 },
845 {
846 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
847 .name = "External Amplifier",
848 .info = ad198x_eapd_info,
849 .get = ad198x_eapd_get,
850 .put = ad198x_eapd_put,
851 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
852 },
853 { } /* end */ 811 { } /* end */
854}; 812};
855 813
814
856/* 815/*
857 * initialization verbs 816 * initialization verbs
858 */ 817 */
@@ -981,6 +940,27 @@ static struct hda_verb ad1986a_hp_init_verbs[] = {
981 {} 940 {}
982}; 941};
983 942
943static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
944 unsigned int res)
945{
946 switch (res >> 26) {
947 case AD1986A_HP_EVENT:
948 ad1986a_hp_automute(codec);
949 break;
950 case AD1986A_MIC_EVENT:
951 ad1986a_automic(codec);
952 break;
953 }
954}
955
956static int ad1986a_samsung_p50_init(struct hda_codec *codec)
957{
958 ad198x_init(codec);
959 ad1986a_hp_automute(codec);
960 ad1986a_automic(codec);
961 return 0;
962}
963
984 964
985/* models */ 965/* models */
986enum { 966enum {
@@ -991,6 +971,7 @@ enum {
991 AD1986A_LAPTOP_AUTOMUTE, 971 AD1986A_LAPTOP_AUTOMUTE,
992 AD1986A_ULTRA, 972 AD1986A_ULTRA,
993 AD1986A_SAMSUNG, 973 AD1986A_SAMSUNG,
974 AD1986A_SAMSUNG_P50,
994 AD1986A_MODELS 975 AD1986A_MODELS
995}; 976};
996 977
@@ -1002,6 +983,7 @@ static const char *ad1986a_models[AD1986A_MODELS] = {
1002 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute", 983 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
1003 [AD1986A_ULTRA] = "ultra", 984 [AD1986A_ULTRA] = "ultra",
1004 [AD1986A_SAMSUNG] = "samsung", 985 [AD1986A_SAMSUNG] = "samsung",
986 [AD1986A_SAMSUNG_P50] = "samsung-p50",
1005}; 987};
1006 988
1007static struct snd_pci_quirk ad1986a_cfg_tbl[] = { 989static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
@@ -1024,6 +1006,7 @@ static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
1024 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD), 1006 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
1025 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK), 1007 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
1026 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP), 1008 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
1009 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
1027 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA), 1010 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
1028 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG), 1011 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
1029 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK), 1012 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
@@ -1111,7 +1094,10 @@ static int patch_ad1986a(struct hda_codec *codec)
1111 spec->multiout.dac_nids = ad1986a_laptop_dac_nids; 1094 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1112 break; 1095 break;
1113 case AD1986A_LAPTOP_EAPD: 1096 case AD1986A_LAPTOP_EAPD:
1114 spec->mixers[0] = ad1986a_laptop_eapd_mixers; 1097 spec->num_mixers = 3;
1098 spec->mixers[0] = ad1986a_laptop_master_mixers;
1099 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1100 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
1115 spec->num_init_verbs = 2; 1101 spec->num_init_verbs = 2;
1116 spec->init_verbs[1] = ad1986a_eapd_init_verbs; 1102 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1117 spec->multiout.max_channels = 2; 1103 spec->multiout.max_channels = 2;
@@ -1122,7 +1108,9 @@ static int patch_ad1986a(struct hda_codec *codec)
1122 spec->input_mux = &ad1986a_laptop_eapd_capture_source; 1108 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1123 break; 1109 break;
1124 case AD1986A_SAMSUNG: 1110 case AD1986A_SAMSUNG:
1125 spec->mixers[0] = ad1986a_samsung_mixers; 1111 spec->num_mixers = 2;
1112 spec->mixers[0] = ad1986a_laptop_master_mixers;
1113 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1126 spec->num_init_verbs = 3; 1114 spec->num_init_verbs = 3;
1127 spec->init_verbs[1] = ad1986a_eapd_init_verbs; 1115 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1128 spec->init_verbs[2] = ad1986a_automic_verbs; 1116 spec->init_verbs[2] = ad1986a_automic_verbs;
@@ -1135,8 +1123,28 @@ static int patch_ad1986a(struct hda_codec *codec)
1135 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event; 1123 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1136 codec->patch_ops.init = ad1986a_automic_init; 1124 codec->patch_ops.init = ad1986a_automic_init;
1137 break; 1125 break;
1126 case AD1986A_SAMSUNG_P50:
1127 spec->num_mixers = 2;
1128 spec->mixers[0] = ad1986a_automute_master_mixers;
1129 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1130 spec->num_init_verbs = 4;
1131 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1132 spec->init_verbs[2] = ad1986a_automic_verbs;
1133 spec->init_verbs[3] = ad1986a_hp_init_verbs;
1134 spec->multiout.max_channels = 2;
1135 spec->multiout.num_dacs = 1;
1136 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1137 if (!is_jack_available(codec, 0x25))
1138 spec->multiout.dig_out_nid = 0;
1139 spec->input_mux = &ad1986a_automic_capture_source;
1140 codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
1141 codec->patch_ops.init = ad1986a_samsung_p50_init;
1142 break;
1138 case AD1986A_LAPTOP_AUTOMUTE: 1143 case AD1986A_LAPTOP_AUTOMUTE:
1139 spec->mixers[0] = ad1986a_laptop_automute_mixers; 1144 spec->num_mixers = 3;
1145 spec->mixers[0] = ad1986a_automute_master_mixers;
1146 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1147 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
1140 spec->num_init_verbs = 3; 1148 spec->num_init_verbs = 3;
1141 spec->init_verbs[1] = ad1986a_eapd_init_verbs; 1149 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1142 spec->init_verbs[2] = ad1986a_hp_init_verbs; 1150 spec->init_verbs[2] = ad1986a_hp_init_verbs;
@@ -1148,6 +1156,10 @@ static int patch_ad1986a(struct hda_codec *codec)
1148 spec->input_mux = &ad1986a_laptop_eapd_capture_source; 1156 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1149 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event; 1157 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1150 codec->patch_ops.init = ad1986a_hp_init; 1158 codec->patch_ops.init = ad1986a_hp_init;
1159 /* Lenovo N100 seems to report the reversed bit
1160 * for HP jack-sensing
1161 */
1162 spec->inv_jack_detect = 1;
1151 break; 1163 break;
1152 case AD1986A_ULTRA: 1164 case AD1986A_ULTRA:
1153 spec->mixers[0] = ad1986a_laptop_eapd_mixers; 1165 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
@@ -3734,9 +3746,30 @@ static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3734 { } /* end */ 3746 { } /* end */
3735}; 3747};
3736 3748
3749static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
3750 struct snd_ctl_elem_value *ucontrol)
3751{
3752 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3753 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3754 int mute = (!ucontrol->value.integer.value[0] &&
3755 !ucontrol->value.integer.value[1]);
3756 /* toggle GPIO1 according to the mute state */
3757 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3758 mute ? 0x02 : 0x0);
3759 return ret;
3760}
3761
3737static struct snd_kcontrol_new ad1884a_mobile_mixers[] = { 3762static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3738 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT), 3763 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3739 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT), 3764 /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
3765 {
3766 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3767 .name = "Master Playback Switch",
3768 .info = snd_hda_mixer_amp_switch_info,
3769 .get = snd_hda_mixer_amp_switch_get,
3770 .put = ad1884a_mobile_master_sw_put,
3771 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3772 },
3740 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT), 3773 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3741 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT), 3774 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3742 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT), 3775 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
@@ -3857,6 +3890,10 @@ static struct hda_verb ad1884a_mobile_verbs[] = {
3857 /* unsolicited event for pin-sense */ 3890 /* unsolicited event for pin-sense */
3858 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT}, 3891 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3859 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT}, 3892 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3893 /* allow to touch GPIO1 (for mute control) */
3894 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3895 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3896 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
3860 { } /* end */ 3897 { } /* end */
3861}; 3898};
3862 3899
@@ -3966,6 +4003,7 @@ static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3966 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP), 4003 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
3967 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE), 4004 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
3968 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE), 4005 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
4006 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
3969 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP), 4007 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
3970 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP), 4008 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
3971 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD), 4009 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c
index 392d108c3558..019ca7cb56d7 100644
--- a/sound/pci/hda/patch_ca0110.c
+++ b/sound/pci/hda/patch_ca0110.c
@@ -510,7 +510,7 @@ static int ca0110_parse_auto_config(struct hda_codec *codec)
510} 510}
511 511
512 512
513int patch_ca0110(struct hda_codec *codec) 513static int patch_ca0110(struct hda_codec *codec)
514{ 514{
515 struct ca0110_spec *spec; 515 struct ca0110_spec *spec;
516 int err; 516 int err;
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 334533197425..e661b21354be 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -945,12 +945,13 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
945static void alc_automute_pin(struct hda_codec *codec) 945static void alc_automute_pin(struct hda_codec *codec)
946{ 946{
947 struct alc_spec *spec = codec->spec; 947 struct alc_spec *spec = codec->spec;
948 unsigned int present; 948 unsigned int present, pincap;
949 unsigned int nid = spec->autocfg.hp_pins[0]; 949 unsigned int nid = spec->autocfg.hp_pins[0];
950 int i; 950 int i;
951 951
952 /* need to execute and sync at first */ 952 pincap = snd_hda_query_pin_caps(codec, nid);
953 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0); 953 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
954 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
954 present = snd_hda_codec_read(codec, nid, 0, 955 present = snd_hda_codec_read(codec, nid, 0,
955 AC_VERB_GET_PIN_SENSE, 0); 956 AC_VERB_GET_PIN_SENSE, 0);
956 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0; 957 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
@@ -1392,7 +1393,7 @@ static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1392static void alc_automute_amp(struct hda_codec *codec) 1393static void alc_automute_amp(struct hda_codec *codec)
1393{ 1394{
1394 struct alc_spec *spec = codec->spec; 1395 struct alc_spec *spec = codec->spec;
1395 unsigned int val, mute; 1396 unsigned int val, mute, pincap;
1396 hda_nid_t nid; 1397 hda_nid_t nid;
1397 int i; 1398 int i;
1398 1399
@@ -1401,6 +1402,10 @@ static void alc_automute_amp(struct hda_codec *codec)
1401 nid = spec->autocfg.hp_pins[i]; 1402 nid = spec->autocfg.hp_pins[i];
1402 if (!nid) 1403 if (!nid)
1403 break; 1404 break;
1405 pincap = snd_hda_query_pin_caps(codec, nid);
1406 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1407 snd_hda_codec_read(codec, nid, 0,
1408 AC_VERB_SET_PIN_SENSE, 0);
1404 val = snd_hda_codec_read(codec, nid, 0, 1409 val = snd_hda_codec_read(codec, nid, 0,
1405 AC_VERB_GET_PIN_SENSE, 0); 1410 AC_VERB_GET_PIN_SENSE, 0);
1406 if (val & AC_PINSENSE_PRESENCE) { 1411 if (val & AC_PINSENSE_PRESENCE) {
@@ -1471,6 +1476,10 @@ static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1471static struct hda_verb alc888_acer_aspire_6530g_verbs[] = { 1476static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1472/* Bias voltage on for external mic port */ 1477/* Bias voltage on for external mic port */
1473 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80}, 1478 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1479/* Front Mic: set to PIN_IN (empty by default) */
1480 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1481/* Unselect Front Mic by default in input mixer 3 */
1482 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1474/* Enable unsolicited event for HP jack */ 1483/* Enable unsolicited event for HP jack */
1475 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 1484 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1476/* Enable speaker output */ 1485/* Enable speaker output */
@@ -1560,18 +1569,22 @@ static struct hda_input_mux alc888_2_capture_sources[2] = {
1560static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = { 1569static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1561 /* Interal mic only available on one ADC */ 1570 /* Interal mic only available on one ADC */
1562 { 1571 {
1563 .num_items = 3, 1572 .num_items = 5,
1564 .items = { 1573 .items = {
1565 { "Ext Mic", 0x0 }, 1574 { "Ext Mic", 0x0 },
1575 { "Line In", 0x2 },
1566 { "CD", 0x4 }, 1576 { "CD", 0x4 },
1577 { "Input Mix", 0xa },
1567 { "Int Mic", 0xb }, 1578 { "Int Mic", 0xb },
1568 }, 1579 },
1569 }, 1580 },
1570 { 1581 {
1571 .num_items = 2, 1582 .num_items = 4,
1572 .items = { 1583 .items = {
1573 { "Ext Mic", 0x0 }, 1584 { "Ext Mic", 0x0 },
1585 { "Line In", 0x2 },
1574 { "CD", 0x4 }, 1586 { "CD", 0x4 },
1587 { "Input Mix", 0xa },
1575 }, 1588 },
1576 } 1589 }
1577}; 1590};
@@ -1639,6 +1652,17 @@ static void alc888_acer_aspire_4930g_init_hook(struct hda_codec *codec)
1639 alc_automute_amp(codec); 1652 alc_automute_amp(codec);
1640} 1653}
1641 1654
1655static void alc888_acer_aspire_6530g_init_hook(struct hda_codec *codec)
1656{
1657 struct alc_spec *spec = codec->spec;
1658
1659 spec->autocfg.hp_pins[0] = 0x15;
1660 spec->autocfg.speaker_pins[0] = 0x14;
1661 spec->autocfg.speaker_pins[1] = 0x16;
1662 spec->autocfg.speaker_pins[2] = 0x17;
1663 alc_automute_amp(codec);
1664}
1665
1642static void alc889_acer_aspire_8930g_init_hook(struct hda_codec *codec) 1666static void alc889_acer_aspire_8930g_init_hook(struct hda_codec *codec)
1643{ 1667{
1644 struct alc_spec *spec = codec->spec; 1668 struct alc_spec *spec = codec->spec;
@@ -8189,6 +8213,8 @@ static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8189 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 8213 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8190 HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 8214 HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8191 HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT), 8215 HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8216 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8217 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8192 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 8218 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8193 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 8219 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8194 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8220 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
@@ -9064,7 +9090,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
9064 SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC883_AUTO), 9090 SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC883_AUTO),
9065 SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC883_AUTO), 9091 SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC883_AUTO),
9066 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G", 9092 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
9067 ALC888_ACER_ASPIRE_4930G), 9093 ALC888_ACER_ASPIRE_6530G),
9068 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G", 9094 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
9069 ALC888_ACER_ASPIRE_6530G), 9095 ALC888_ACER_ASPIRE_6530G),
9070 /* default Acer -- disabled as it causes more problems. 9096 /* default Acer -- disabled as it causes more problems.
@@ -9317,7 +9343,7 @@ static struct alc_config_preset alc883_presets[] = {
9317 ARRAY_SIZE(alc888_2_capture_sources), 9343 ARRAY_SIZE(alc888_2_capture_sources),
9318 .input_mux = alc888_acer_aspire_6530_sources, 9344 .input_mux = alc888_acer_aspire_6530_sources,
9319 .unsol_event = alc_automute_amp_unsol_event, 9345 .unsol_event = alc_automute_amp_unsol_event,
9320 .init_hook = alc888_acer_aspire_4930g_init_hook, 9346 .init_hook = alc888_acer_aspire_6530g_init_hook,
9321 }, 9347 },
9322 [ALC888_ACER_ASPIRE_8930G] = { 9348 [ALC888_ACER_ASPIRE_8930G] = {
9323 .mixers = { alc888_base_mixer, 9349 .mixers = { alc888_base_mixer,
@@ -12437,6 +12463,8 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
12437 if (err < 0) 12463 if (err < 0)
12438 return err; 12464 return err;
12439 12465
12466 alc_ssid_check(codec, 0x15, 0x1b, 0x14);
12467
12440 return 1; 12468 return 1;
12441} 12469}
12442 12470
@@ -12848,20 +12876,11 @@ static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12848 { } 12876 { }
12849}; 12877};
12850 12878
12851/* bind volumes of both NID 0x0c and 0x0d */
12852static struct hda_bind_ctls alc269_epc_bind_vol = {
12853 .ops = &snd_hda_bind_vol,
12854 .values = {
12855 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12856 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12857 0
12858 },
12859};
12860
12861static struct snd_kcontrol_new alc269_eeepc_mixer[] = { 12879static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12862 HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT), 12880 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12863 HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol), 12881 HDA_CODEC_MUTE("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12864 HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT), 12882 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12883 HDA_CODEC_MUTE("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12865 { } /* end */ 12884 { } /* end */
12866}; 12885};
12867 12886
@@ -12874,12 +12893,7 @@ static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12874}; 12893};
12875 12894
12876/* FSC amilo */ 12895/* FSC amilo */
12877static struct snd_kcontrol_new alc269_fujitsu_mixer[] = { 12896#define alc269_fujitsu_mixer alc269_eeepc_mixer
12878 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12879 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12880 HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12881 { } /* end */
12882};
12883 12897
12884static struct hda_verb alc269_quanta_fl1_verbs[] = { 12898static struct hda_verb alc269_quanta_fl1_verbs[] = {
12885 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, 12899 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
@@ -13345,6 +13359,8 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
13345 if (!spec->cap_mixer && !spec->no_analog) 13359 if (!spec->cap_mixer && !spec->no_analog)
13346 set_capture_mixer(spec); 13360 set_capture_mixer(spec);
13347 13361
13362 alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13363
13348 return 1; 13364 return 1;
13349} 13365}
13350 13366
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 0d0cdbdb4486..cecf1ffeeaaa 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -107,7 +107,7 @@ MODULE_PARM_DESC(dxr_enable, "Enable DXR support for Terratec DMX6FIRE.");
107 107
108 108
109static const struct pci_device_id snd_ice1712_ids[] = { 109static const struct pci_device_id snd_ice1712_ids[] = {
110 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */ 110 { PCI_VDEVICE(ICE, PCI_DEVICE_ID_ICE_1712), 0 }, /* ICE1712 */
111 { 0, } 111 { 0, }
112}; 112};
113 113
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 36ade77cf371..cc84a831eb21 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -93,7 +93,7 @@ MODULE_PARM_DESC(model, "Use the given board model.");
93 93
94/* Both VT1720 and VT1724 have the same PCI IDs */ 94/* Both VT1720 and VT1724 have the same PCI IDs */
95static const struct pci_device_id snd_vt1724_ids[] = { 95static const struct pci_device_id snd_vt1724_ids[] = {
96 { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 96 { PCI_VDEVICE(ICE, PCI_DEVICE_ID_VT1724), 0 },
97 { 0, } 97 { 0, }
98}; 98};
99 99
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 8aa5687f392a..171ada535209 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -421,29 +421,29 @@ struct intel8x0 {
421}; 421};
422 422
423static struct pci_device_id snd_intel8x0_ids[] = { 423static struct pci_device_id snd_intel8x0_ids[] = {
424 { 0x8086, 0x2415, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801AA */ 424 { PCI_VDEVICE(INTEL, 0x2415), DEVICE_INTEL }, /* 82801AA */
425 { 0x8086, 0x2425, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82901AB */ 425 { PCI_VDEVICE(INTEL, 0x2425), DEVICE_INTEL }, /* 82901AB */
426 { 0x8086, 0x2445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801BA */ 426 { PCI_VDEVICE(INTEL, 0x2445), DEVICE_INTEL }, /* 82801BA */
427 { 0x8086, 0x2485, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH3 */ 427 { PCI_VDEVICE(INTEL, 0x2485), DEVICE_INTEL }, /* ICH3 */
428 { 0x8086, 0x24c5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH4 */ 428 { PCI_VDEVICE(INTEL, 0x24c5), DEVICE_INTEL_ICH4 }, /* ICH4 */
429 { 0x8086, 0x24d5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH5 */ 429 { PCI_VDEVICE(INTEL, 0x24d5), DEVICE_INTEL_ICH4 }, /* ICH5 */
430 { 0x8086, 0x25a6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ESB */ 430 { PCI_VDEVICE(INTEL, 0x25a6), DEVICE_INTEL_ICH4 }, /* ESB */
431 { 0x8086, 0x266e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH6 */ 431 { PCI_VDEVICE(INTEL, 0x266e), DEVICE_INTEL_ICH4 }, /* ICH6 */
432 { 0x8086, 0x27de, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ICH7 */ 432 { PCI_VDEVICE(INTEL, 0x27de), DEVICE_INTEL_ICH4 }, /* ICH7 */
433 { 0x8086, 0x2698, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL_ICH4 }, /* ESB2 */ 433 { PCI_VDEVICE(INTEL, 0x2698), DEVICE_INTEL_ICH4 }, /* ESB2 */
434 { 0x8086, 0x7195, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 440MX */ 434 { PCI_VDEVICE(INTEL, 0x7195), DEVICE_INTEL }, /* 440MX */
435 { 0x1039, 0x7012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_SIS }, /* SI7012 */ 435 { PCI_VDEVICE(SI, 0x7012), DEVICE_SIS }, /* SI7012 */
436 { 0x10de, 0x01b1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE */ 436 { PCI_VDEVICE(NVIDIA, 0x01b1), DEVICE_NFORCE }, /* NFORCE */
437 { 0x10de, 0x003a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* MCP04 */ 437 { PCI_VDEVICE(NVIDIA, 0x003a), DEVICE_NFORCE }, /* MCP04 */
438 { 0x10de, 0x006a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2 */ 438 { PCI_VDEVICE(NVIDIA, 0x006a), DEVICE_NFORCE }, /* NFORCE2 */
439 { 0x10de, 0x0059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK804 */ 439 { PCI_VDEVICE(NVIDIA, 0x0059), DEVICE_NFORCE }, /* CK804 */
440 { 0x10de, 0x008a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8 */ 440 { PCI_VDEVICE(NVIDIA, 0x008a), DEVICE_NFORCE }, /* CK8 */
441 { 0x10de, 0x00da, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE3 */ 441 { PCI_VDEVICE(NVIDIA, 0x00da), DEVICE_NFORCE }, /* NFORCE3 */
442 { 0x10de, 0x00ea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* CK8S */ 442 { PCI_VDEVICE(NVIDIA, 0x00ea), DEVICE_NFORCE }, /* CK8S */
443 { 0x10de, 0x026b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* MCP51 */ 443 { PCI_VDEVICE(NVIDIA, 0x026b), DEVICE_NFORCE }, /* MCP51 */
444 { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */ 444 { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
445 { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */ 445 { PCI_VDEVICE(AMD, 0x7445), DEVICE_INTEL }, /* AMD768 */
446 { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */ 446 { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
447 { 0, } 447 { 0, }
448}; 448};
449 449
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index 6ec0fc50d6be..9e7d12e7673f 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -220,24 +220,24 @@ struct intel8x0m {
220}; 220};
221 221
222static struct pci_device_id snd_intel8x0m_ids[] = { 222static struct pci_device_id snd_intel8x0m_ids[] = {
223 { 0x8086, 0x2416, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801AA */ 223 { PCI_VDEVICE(INTEL, 0x2416), DEVICE_INTEL }, /* 82801AA */
224 { 0x8086, 0x2426, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82901AB */ 224 { PCI_VDEVICE(INTEL, 0x2426), DEVICE_INTEL }, /* 82901AB */
225 { 0x8086, 0x2446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 82801BA */ 225 { PCI_VDEVICE(INTEL, 0x2446), DEVICE_INTEL }, /* 82801BA */
226 { 0x8086, 0x2486, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH3 */ 226 { PCI_VDEVICE(INTEL, 0x2486), DEVICE_INTEL }, /* ICH3 */
227 { 0x8086, 0x24c6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH4 */ 227 { PCI_VDEVICE(INTEL, 0x24c6), DEVICE_INTEL }, /* ICH4 */
228 { 0x8086, 0x24d6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH5 */ 228 { PCI_VDEVICE(INTEL, 0x24d6), DEVICE_INTEL }, /* ICH5 */
229 { 0x8086, 0x266d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH6 */ 229 { PCI_VDEVICE(INTEL, 0x266d), DEVICE_INTEL }, /* ICH6 */
230 { 0x8086, 0x27dd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* ICH7 */ 230 { PCI_VDEVICE(INTEL, 0x27dd), DEVICE_INTEL }, /* ICH7 */
231 { 0x8086, 0x7196, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* 440MX */ 231 { PCI_VDEVICE(INTEL, 0x7196), DEVICE_INTEL }, /* 440MX */
232 { 0x1022, 0x7446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */ 232 { PCI_VDEVICE(AMD, 0x7446), DEVICE_INTEL }, /* AMD768 */
233 { 0x1039, 0x7013, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_SIS }, /* SI7013 */ 233 { PCI_VDEVICE(SI, 0x7013), DEVICE_SIS }, /* SI7013 */
234 { 0x10de, 0x01c1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE */ 234 { PCI_VDEVICE(NVIDIA, 0x01c1), DEVICE_NFORCE }, /* NFORCE */
235 { 0x10de, 0x0069, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2 */ 235 { PCI_VDEVICE(NVIDIA, 0x0069), DEVICE_NFORCE }, /* NFORCE2 */
236 { 0x10de, 0x0089, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE2s */ 236 { PCI_VDEVICE(NVIDIA, 0x0089), DEVICE_NFORCE }, /* NFORCE2s */
237 { 0x10de, 0x00d9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_NFORCE }, /* NFORCE3 */ 237 { PCI_VDEVICE(NVIDIA, 0x00d9), DEVICE_NFORCE }, /* NFORCE3 */
238#if 0 238#if 0
239 { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */ 239 { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
240 { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */ 240 { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
241#endif 241#endif
242 { 0, } 242 { 0, }
243}; 243};
diff --git a/sound/pci/lx6464es/lx6464es.c b/sound/pci/lx6464es/lx6464es.c
index 18da2ef04d09..11b8c6514b3d 100644
--- a/sound/pci/lx6464es/lx6464es.c
+++ b/sound/pci/lx6464es/lx6464es.c
@@ -654,13 +654,12 @@ static int __devinit lx_init_ethersound_config(struct lx6464es *chip)
654 int i; 654 int i;
655 u32 orig_conf_es = lx_dsp_reg_read(chip, eReg_CONFES); 655 u32 orig_conf_es = lx_dsp_reg_read(chip, eReg_CONFES);
656 656
657 u32 default_conf_es = (64 << IOCR_OUTPUTS_OFFSET) | 657 /* configure 64 io channels */
658 u32 conf_es = (orig_conf_es & CONFES_READ_PART_MASK) |
658 (64 << IOCR_INPUTS_OFFSET) | 659 (64 << IOCR_INPUTS_OFFSET) |
660 (64 << IOCR_OUTPUTS_OFFSET) |
659 (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET); 661 (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET);
660 662
661 u32 conf_es = (orig_conf_es & CONFES_READ_PART_MASK)
662 | (default_conf_es & CONFES_WRITE_PART_MASK);
663
664 snd_printdd("->lx_init_ethersound\n"); 663 snd_printdd("->lx_init_ethersound\n");
665 664
666 chip->freq_ratio = FREQ_RATIO_SINGLE_MODE; 665 chip->freq_ratio = FREQ_RATIO_SINGLE_MODE;
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index 82bc5b9e7629..a83d1968a845 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -61,7 +61,7 @@ MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
61 */ 61 */
62 62
63static struct pci_device_id snd_mixart_ids[] = { 63static struct pci_device_id snd_mixart_ids[] = {
64 { 0x1057, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* MC8240 */ 64 { PCI_VDEVICE(MOTOROLA, 0x0003), 0, }, /* MC8240 */
65 { 0, } 65 { 0, }
66}; 66};
67 67
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 522a040855d4..97a0731331a1 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -263,9 +263,9 @@ struct nm256 {
263 * PCI ids 263 * PCI ids
264 */ 264 */
265static struct pci_device_id snd_nm256_ids[] = { 265static struct pci_device_id snd_nm256_ids[] = {
266 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 266 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO), 0},
267 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 267 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO), 0},
268 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 268 {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO), 0},
269 {0,}, 269 {0,},
270}; 270};
271 271
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 304da169bfdc..5401c547c4e3 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -575,8 +575,10 @@ static int ac97_switch_put(struct snd_kcontrol *ctl,
575static int ac97_volume_info(struct snd_kcontrol *ctl, 575static int ac97_volume_info(struct snd_kcontrol *ctl,
576 struct snd_ctl_elem_info *info) 576 struct snd_ctl_elem_info *info)
577{ 577{
578 int stereo = (ctl->private_value >> 16) & 1;
579
578 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 580 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
579 info->count = 2; 581 info->count = stereo ? 2 : 1;
580 info->value.integer.min = 0; 582 info->value.integer.min = 0;
581 info->value.integer.max = 0x1f; 583 info->value.integer.max = 0x1f;
582 return 0; 584 return 0;
@@ -587,6 +589,7 @@ static int ac97_volume_get(struct snd_kcontrol *ctl,
587{ 589{
588 struct oxygen *chip = ctl->private_data; 590 struct oxygen *chip = ctl->private_data;
589 unsigned int codec = (ctl->private_value >> 24) & 1; 591 unsigned int codec = (ctl->private_value >> 24) & 1;
592 int stereo = (ctl->private_value >> 16) & 1;
590 unsigned int index = ctl->private_value & 0xff; 593 unsigned int index = ctl->private_value & 0xff;
591 u16 reg; 594 u16 reg;
592 595
@@ -594,7 +597,8 @@ static int ac97_volume_get(struct snd_kcontrol *ctl,
594 reg = oxygen_read_ac97(chip, codec, index); 597 reg = oxygen_read_ac97(chip, codec, index);
595 mutex_unlock(&chip->mutex); 598 mutex_unlock(&chip->mutex);
596 value->value.integer.value[0] = 31 - (reg & 0x1f); 599 value->value.integer.value[0] = 31 - (reg & 0x1f);
597 value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f); 600 if (stereo)
601 value->value.integer.value[1] = 31 - ((reg >> 8) & 0x1f);
598 return 0; 602 return 0;
599} 603}
600 604
@@ -603,6 +607,7 @@ static int ac97_volume_put(struct snd_kcontrol *ctl,
603{ 607{
604 struct oxygen *chip = ctl->private_data; 608 struct oxygen *chip = ctl->private_data;
605 unsigned int codec = (ctl->private_value >> 24) & 1; 609 unsigned int codec = (ctl->private_value >> 24) & 1;
610 int stereo = (ctl->private_value >> 16) & 1;
606 unsigned int index = ctl->private_value & 0xff; 611 unsigned int index = ctl->private_value & 0xff;
607 u16 oldreg, newreg; 612 u16 oldreg, newreg;
608 int change; 613 int change;
@@ -612,8 +617,11 @@ static int ac97_volume_put(struct snd_kcontrol *ctl,
612 newreg = oldreg; 617 newreg = oldreg;
613 newreg = (newreg & ~0x1f) | 618 newreg = (newreg & ~0x1f) |
614 (31 - (value->value.integer.value[0] & 0x1f)); 619 (31 - (value->value.integer.value[0] & 0x1f));
615 newreg = (newreg & ~0x1f00) | 620 if (stereo)
616 ((31 - (value->value.integer.value[0] & 0x1f)) << 8); 621 newreg = (newreg & ~0x1f00) |
622 ((31 - (value->value.integer.value[1] & 0x1f)) << 8);
623 else
624 newreg = (newreg & ~0x1f00) | ((newreg & 0x1f) << 8);
617 change = newreg != oldreg; 625 change = newreg != oldreg;
618 if (change) 626 if (change)
619 oxygen_write_ac97(chip, codec, index, newreg); 627 oxygen_write_ac97(chip, codec, index, newreg);
@@ -673,7 +681,7 @@ static int ac97_fp_rec_volume_put(struct snd_kcontrol *ctl,
673 .private_value = ((codec) << 24) | ((invert) << 16) | \ 681 .private_value = ((codec) << 24) | ((invert) << 16) | \
674 ((bitnr) << 8) | (index), \ 682 ((bitnr) << 8) | (index), \
675 } 683 }
676#define AC97_VOLUME(xname, codec, index) { \ 684#define AC97_VOLUME(xname, codec, index, stereo) { \
677 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
678 .name = xname, \ 686 .name = xname, \
679 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ 687 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
@@ -682,7 +690,7 @@ static int ac97_fp_rec_volume_put(struct snd_kcontrol *ctl,
682 .get = ac97_volume_get, \ 690 .get = ac97_volume_get, \
683 .put = ac97_volume_put, \ 691 .put = ac97_volume_put, \
684 .tlv = { .p = ac97_db_scale, }, \ 692 .tlv = { .p = ac97_db_scale, }, \
685 .private_value = ((codec) << 24) | (index), \ 693 .private_value = ((codec) << 24) | ((stereo) << 16) | (index), \
686 } 694 }
687 695
688static DECLARE_TLV_DB_SCALE(monitor_db_scale, -1000, 1000, 0); 696static DECLARE_TLV_DB_SCALE(monitor_db_scale, -1000, 1000, 0);
@@ -882,18 +890,18 @@ static const struct {
882}; 890};
883 891
884static const struct snd_kcontrol_new ac97_controls[] = { 892static const struct snd_kcontrol_new ac97_controls[] = {
885 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC), 893 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC, 0),
886 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1), 894 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1),
887 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0), 895 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0),
888 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1), 896 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1),
889 AC97_VOLUME("CD Capture Volume", 0, AC97_CD), 897 AC97_VOLUME("CD Capture Volume", 0, AC97_CD, 1),
890 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1), 898 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1),
891 AC97_VOLUME("Aux Capture Volume", 0, AC97_AUX), 899 AC97_VOLUME("Aux Capture Volume", 0, AC97_AUX, 1),
892 AC97_SWITCH("Aux Capture Switch", 0, AC97_AUX, 15, 1), 900 AC97_SWITCH("Aux Capture Switch", 0, AC97_AUX, 15, 1),
893}; 901};
894 902
895static const struct snd_kcontrol_new ac97_fp_controls[] = { 903static const struct snd_kcontrol_new ac97_fp_controls[] = {
896 AC97_VOLUME("Front Panel Playback Volume", 1, AC97_HEADPHONE), 904 AC97_VOLUME("Front Panel Playback Volume", 1, AC97_HEADPHONE, 1),
897 AC97_SWITCH("Front Panel Playback Switch", 1, AC97_HEADPHONE, 15, 1), 905 AC97_SWITCH("Front Panel Playback Switch", 1, AC97_HEADPHONE, 15, 1),
898 { 906 {
899 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 907 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index bf971f7cfdc6..6ebcb6bdd712 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -635,6 +635,8 @@ static void xonar_d2_resume(struct oxygen *chip)
635 635
636static void xonar_d1_resume(struct oxygen *chip) 636static void xonar_d1_resume(struct oxygen *chip)
637{ 637{
638 oxygen_set_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
639 msleep(1);
638 cs43xx_init(chip); 640 cs43xx_init(chip);
639 xonar_enable_output(chip); 641 xonar_enable_output(chip);
640} 642}
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index d7b966e7c4cf..f977dba7cbd0 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -227,12 +227,9 @@ struct rme32 {
227}; 227};
228 228
229static struct pci_device_id snd_rme32_ids[] = { 229static struct pci_device_id snd_rme32_ids[] = {
230 {PCI_VENDOR_ID_XILINX_RME, PCI_DEVICE_ID_RME_DIGI32, 230 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32), 0,},
231 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,}, 231 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_8), 0,},
232 {PCI_VENDOR_ID_XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_8, 232 {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_PRO), 0,},
233 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
234 {PCI_VENDOR_ID_XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_PRO,
235 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
236 {0,} 233 {0,}
237}; 234};
238 235
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index 55fb1c131f58..2ba5c0fd55db 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -232,14 +232,10 @@ struct rme96 {
232}; 232};
233 233
234static struct pci_device_id snd_rme96_ids[] = { 234static struct pci_device_id snd_rme96_ids[] = {
235 { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96, 235 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96), 0, },
236 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 236 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96_8), 0, },
237 { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96_8, 237 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PRO), 0, },
238 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 238 { PCI_VDEVICE(XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST), 0, },
239 { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PRO,
240 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
241 { PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST,
242 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
243 { 0, } 239 { 0, }
244}; 240};
245 241
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index 7dc60ad4772e..1f6406c4534d 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -243,7 +243,7 @@ struct sonicvibes {
243}; 243};
244 244
245static struct pci_device_id snd_sonic_ids[] = { 245static struct pci_device_id snd_sonic_ids[] = {
246 { 0x5333, 0xca00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 246 { PCI_VDEVICE(S3, 0xca00), 0, },
247 { 0, } 247 { 0, }
248}; 248};
249 249
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 949fcaf6b70e..acfa4760da49 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -402,9 +402,9 @@ struct via82xx {
402 402
403static struct pci_device_id snd_via82xx_ids[] = { 403static struct pci_device_id snd_via82xx_ids[] = {
404 /* 0x1106, 0x3058 */ 404 /* 0x1106, 0x3058 */
405 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */ 405 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C686_5), TYPE_CARD_VIA686, }, /* 686A */
406 /* 0x1106, 0x3059 */ 406 /* 0x1106, 0x3059 */
407 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */ 407 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233_5), TYPE_CARD_VIA8233, }, /* VT8233 */
408 { 0, } 408 { 0, }
409}; 409};
410 410
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index 0d54e3503c1e..47eb61561dfc 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -261,7 +261,7 @@ struct via82xx_modem {
261}; 261};
262 262
263static struct pci_device_id snd_via82xx_modem_ids[] = { 263static struct pci_device_id snd_via82xx_modem_ids[] = {
264 { 0x1106, 0x3068, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA82XX_MODEM, }, 264 { PCI_VDEVICE(VIA, 0x3068), TYPE_CARD_VIA82XX_MODEM, },
265 { 0, } 265 { 0, }
266}; 266};
267 267
diff --git a/sound/pci/ymfpci/ymfpci.c b/sound/pci/ymfpci/ymfpci.c
index 4af66661f9b0..e6b18b90d451 100644
--- a/sound/pci/ymfpci/ymfpci.c
+++ b/sound/pci/ymfpci/ymfpci.c
@@ -67,12 +67,12 @@ module_param_array(rear_switch, bool, NULL, 0444);
67MODULE_PARM_DESC(rear_switch, "Enable shared rear/line-in switch"); 67MODULE_PARM_DESC(rear_switch, "Enable shared rear/line-in switch");
68 68
69static struct pci_device_id snd_ymfpci_ids[] = { 69static struct pci_device_id snd_ymfpci_ids[] = {
70 { 0x1073, 0x0004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF724 */ 70 { PCI_VDEVICE(YAMAHA, 0x0004), 0, }, /* YMF724 */
71 { 0x1073, 0x000d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF724F */ 71 { PCI_VDEVICE(YAMAHA, 0x000d), 0, }, /* YMF724F */
72 { 0x1073, 0x000a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF740 */ 72 { PCI_VDEVICE(YAMAHA, 0x000a), 0, }, /* YMF740 */
73 { 0x1073, 0x000c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF740C */ 73 { PCI_VDEVICE(YAMAHA, 0x000c), 0, }, /* YMF740C */
74 { 0x1073, 0x0010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF744 */ 74 { PCI_VDEVICE(YAMAHA, 0x0010), 0, }, /* YMF744 */
75 { 0x1073, 0x0012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* YMF754 */ 75 { PCI_VDEVICE(YAMAHA, 0x0012), 0, }, /* YMF754 */
76 { 0, } 76 { 0, }
77}; 77};
78 78
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 5dbebf82249c..8cb65ccad35f 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -33,7 +33,7 @@ config SND_SOC_MPC5200_I2S
33config SND_SOC_MPC5200_AC97 33config SND_SOC_MPC5200_AC97
34 tristate "Freescale MPC5200 PSC in AC97 mode driver" 34 tristate "Freescale MPC5200 PSC in AC97 mode driver"
35 depends on PPC_MPC52xx && PPC_BESTCOMM 35 depends on PPC_MPC52xx && PPC_BESTCOMM
36 select AC97_BUS 36 select SND_SOC_AC97_BUS
37 select SND_MPC52xx_DMA 37 select SND_MPC52xx_DMA
38 select PPC_BESTCOMM_GEN_BD 38 select PPC_BESTCOMM_GEN_BD
39 help 39 help
@@ -41,7 +41,7 @@ config SND_SOC_MPC5200_AC97
41 41
42config SND_MPC52xx_SOC_PCM030 42config SND_MPC52xx_SOC_PCM030
43 tristate "SoC AC97 Audio support for Phytec pcm030 and WM9712" 43 tristate "SoC AC97 Audio support for Phytec pcm030 and WM9712"
44 depends on PPC_MPC5200_SIMPLE && BROKEN 44 depends on PPC_MPC5200_SIMPLE
45 select SND_SOC_MPC5200_AC97 45 select SND_SOC_MPC5200_AC97
46 select SND_SOC_WM9712 46 select SND_SOC_WM9712
47 help 47 help
@@ -50,7 +50,7 @@ config SND_MPC52xx_SOC_PCM030
50 50
51config SND_MPC52xx_SOC_EFIKA 51config SND_MPC52xx_SOC_EFIKA
52 tristate "SoC AC97 Audio support for bbplan Efika and STAC9766" 52 tristate "SoC AC97 Audio support for bbplan Efika and STAC9766"
53 depends on PPC_EFIKA && BROKEN 53 depends on PPC_EFIKA
54 select SND_SOC_MPC5200_AC97 54 select SND_SOC_MPC5200_AC97
55 select SND_SOC_STAC9766 55 select SND_SOC_STAC9766
56 help 56 help
diff --git a/sound/soc/omap/omap-pcm.c b/sound/soc/omap/omap-pcm.c
index 6454e15f7d28..84a1950880eb 100644
--- a/sound/soc/omap/omap-pcm.c
+++ b/sound/soc/omap/omap-pcm.c
@@ -216,12 +216,15 @@ static snd_pcm_uframes_t omap_pcm_pointer(struct snd_pcm_substream *substream)
216 dma_addr_t ptr; 216 dma_addr_t ptr;
217 snd_pcm_uframes_t offset; 217 snd_pcm_uframes_t offset;
218 218
219 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 219 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
220 ptr = omap_get_dma_src_pos(prtd->dma_ch);
221 else
222 ptr = omap_get_dma_dst_pos(prtd->dma_ch); 220 ptr = omap_get_dma_dst_pos(prtd->dma_ch);
221 offset = bytes_to_frames(runtime, ptr - runtime->dma_addr);
222 } else if (!(cpu_is_omap1510())) {
223 ptr = omap_get_dma_src_pos(prtd->dma_ch);
224 offset = bytes_to_frames(runtime, ptr - runtime->dma_addr);
225 } else
226 offset = prtd->period_index * runtime->period_size;
223 227
224 offset = bytes_to_frames(runtime, ptr - runtime->dma_addr);
225 if (offset >= runtime->buffer_size) 228 if (offset >= runtime->buffer_size)
226 offset = 0; 229 offset = 0;
227 230
diff --git a/sound/soc/pxa/pxa2xx-i2s.c b/sound/soc/pxa/pxa2xx-i2s.c
index 4743e262895d..6b8f655d1ad8 100644
--- a/sound/soc/pxa/pxa2xx-i2s.c
+++ b/sound/soc/pxa/pxa2xx-i2s.c
@@ -167,6 +167,7 @@ static int pxa2xx_i2s_hw_params(struct snd_pcm_substream *substream,
167 167
168 BUG_ON(IS_ERR(clk_i2s)); 168 BUG_ON(IS_ERR(clk_i2s));
169 clk_enable(clk_i2s); 169 clk_enable(clk_i2s);
170 dai->private_data = dai;
170 pxa_i2s_wait(); 171 pxa_i2s_wait();
171 172
172 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 173 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -255,7 +256,10 @@ static void pxa2xx_i2s_shutdown(struct snd_pcm_substream *substream,
255 if ((SACR1 & (SACR1_DREC | SACR1_DRPL)) == (SACR1_DREC | SACR1_DRPL)) { 256 if ((SACR1 & (SACR1_DREC | SACR1_DRPL)) == (SACR1_DREC | SACR1_DRPL)) {
256 SACR0 &= ~SACR0_ENB; 257 SACR0 &= ~SACR0_ENB;
257 pxa_i2s_wait(); 258 pxa_i2s_wait();
258 clk_disable(clk_i2s); 259 if (dai->private_data != NULL) {
260 clk_disable(clk_i2s);
261 dai->private_data = NULL;
262 }
259 } 263 }
260} 264}
261 265
@@ -336,6 +340,7 @@ static int pxa2xx_i2s_probe(struct platform_device *dev)
336 return PTR_ERR(clk_i2s); 340 return PTR_ERR(clk_i2s);
337 341
338 pxa_i2s_dai.dev = &dev->dev; 342 pxa_i2s_dai.dev = &dev->dev;
343 pxa_i2s_dai.private_data = NULL;
339 ret = snd_soc_register_dai(&pxa_i2s_dai); 344 ret = snd_soc_register_dai(&pxa_i2s_dai);
340 if (ret != 0) 345 if (ret != 0)
341 clk_put(clk_i2s); 346 clk_put(clk_i2s);
diff --git a/sound/sound_core.c b/sound/sound_core.c
index 12522e6913d9..a41f8b127f49 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -10,6 +10,8 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/err.h> 12#include <linux/err.h>
13#include <linux/kdev_t.h>
14#include <linux/major.h>
13#include <sound/core.h> 15#include <sound/core.h>
14 16
15#ifdef CONFIG_SOUND_OSS_CORE 17#ifdef CONFIG_SOUND_OSS_CORE
@@ -29,6 +31,8 @@ MODULE_LICENSE("GPL");
29 31
30static char *sound_nodename(struct device *dev) 32static char *sound_nodename(struct device *dev)
31{ 33{
34 if (MAJOR(dev->devt) == SOUND_MAJOR)
35 return NULL;
32 return kasprintf(GFP_KERNEL, "snd/%s", dev_name(dev)); 36 return kasprintf(GFP_KERNEL, "snd/%s", dev_name(dev));
33} 37}
34 38
@@ -104,7 +108,6 @@ module_exit(cleanup_soundcore);
104#include <linux/types.h> 108#include <linux/types.h>
105#include <linux/kernel.h> 109#include <linux/kernel.h>
106#include <linux/sound.h> 110#include <linux/sound.h>
107#include <linux/major.h>
108#include <linux/kmod.h> 111#include <linux/kmod.h>
109 112
110#define SOUND_STEP 16 113#define SOUND_STEP 16
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index 0e5db719de24..de38108f0b28 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -35,7 +35,7 @@
35#include "input.h" 35#include "input.h"
36 36
37MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 37MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
38MODULE_DESCRIPTION("caiaq USB audio, version 1.3.17"); 38MODULE_DESCRIPTION("caiaq USB audio, version 1.3.18");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 40MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
41 "{Native Instruments, RigKontrol3}," 41 "{Native Instruments, RigKontrol3},"
@@ -349,7 +349,9 @@ static void __devinit setup_card(struct snd_usb_caiaqdev *dev)
349 log("Unable to set up control system (ret=%d)\n", ret); 349 log("Unable to set up control system (ret=%d)\n", ret);
350} 350}
351 351
352static int create_card(struct usb_device* usb_dev, struct snd_card **cardp) 352static int create_card(struct usb_device *usb_dev,
353 struct usb_interface *intf,
354 struct snd_card **cardp)
353{ 355{
354 int devnum; 356 int devnum;
355 int err; 357 int err;
@@ -374,7 +376,7 @@ static int create_card(struct usb_device* usb_dev, struct snd_card **cardp)
374 dev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor), 376 dev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor),
375 le16_to_cpu(usb_dev->descriptor.idProduct)); 377 le16_to_cpu(usb_dev->descriptor.idProduct));
376 spin_lock_init(&dev->spinlock); 378 spin_lock_init(&dev->spinlock);
377 snd_card_set_dev(card, &usb_dev->dev); 379 snd_card_set_dev(card, &intf->dev);
378 380
379 *cardp = card; 381 *cardp = card;
380 return 0; 382 return 0;
@@ -461,7 +463,7 @@ static int __devinit snd_probe(struct usb_interface *intf,
461 struct snd_card *card; 463 struct snd_card *card;
462 struct usb_device *device = interface_to_usbdev(intf); 464 struct usb_device *device = interface_to_usbdev(intf);
463 465
464 ret = create_card(device, &card); 466 ret = create_card(device, intf, &card);
465 467
466 if (ret < 0) 468 if (ret < 0)
467 return ret; 469 return ret;
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index a5aae9d67f31..fd44946ce4b3 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -514,7 +514,6 @@ static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
514 US122L(card)->chip.dev->bus->busnum, 514 US122L(card)->chip.dev->bus->busnum,
515 US122L(card)->chip.dev->devnum 515 US122L(card)->chip.dev->devnum
516 ); 516 );
517 snd_card_set_dev(card, &device->dev);
518 *cardp = card; 517 *cardp = card;
519 return 0; 518 return 0;
520} 519}
@@ -531,6 +530,7 @@ static int us122l_usb_probe(struct usb_interface *intf,
531 if (err < 0) 530 if (err < 0)
532 return err; 531 return err;
533 532
533 snd_card_set_dev(card, &intf->dev);
534 if (!us122l_create_card(card)) { 534 if (!us122l_create_card(card)) {
535 snd_card_free(card); 535 snd_card_free(card);
536 return -EINVAL; 536 return -EINVAL;
diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c
index 5ce0da23ee96..cb4bb8373ca2 100644
--- a/sound/usb/usx2y/usbusx2y.c
+++ b/sound/usb/usx2y/usbusx2y.c
@@ -364,7 +364,6 @@ static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp)
364 0,//us428(card)->usbmidi.ifnum, 364 0,//us428(card)->usbmidi.ifnum,
365 usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum 365 usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum
366 ); 366 );
367 snd_card_set_dev(card, &device->dev);
368 *cardp = card; 367 *cardp = card;
369 return 0; 368 return 0;
370} 369}
@@ -388,6 +387,7 @@ static int usX2Y_usb_probe(struct usb_device *device,
388 err = usX2Y_create_card(device, &card); 387 err = usX2Y_create_card(device, &card);
389 if (err < 0) 388 if (err < 0)
390 return err; 389 return err;
390 snd_card_set_dev(card, &intf->dev);
391 if ((err = usX2Y_hwdep_new(card, device)) < 0 || 391 if ((err = usX2Y_hwdep_new(card, device)) < 0 ||
392 (err = snd_card_register(card)) < 0) { 392 (err = snd_card_register(card)) < 0) {
393 snd_card_free(card); 393 snd_card_free(card);
diff --git a/tools/perf/CREDITS b/tools/perf/CREDITS
new file mode 100644
index 000000000000..c2ddcb3acbd0
--- /dev/null
+++ b/tools/perf/CREDITS
@@ -0,0 +1,30 @@
1Most of the infrastructure that 'perf' uses here has been reused
2from the Git project, as of version:
3
4 66996ec: Sync with 1.6.2.4
5
6Here is an (incomplete!) list of main contributors to those files
7in util/* and elsewhere:
8
9 Alex Riesen
10 Christian Couder
11 Dmitry Potapov
12 Jeff King
13 Johannes Schindelin
14 Johannes Sixt
15 Junio C Hamano
16 Linus Torvalds
17 Matthias Kestenholz
18 Michal Ostrowski
19 Miklos Vajna
20 Petr Baudis
21 Pierre Habouzit
22 René Scharfe
23 Samuel Tardieu
24 Shawn O. Pearce
25 Steffen Prohaska
26 Steve Haslam
27
28Thanks guys!
29
30The full history of the files can be found in the upstream Git commits.
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 52d3fc6846a9..8aa3f8c88707 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -13,13 +13,25 @@ SYNOPSIS
13DESCRIPTION 13DESCRIPTION
14----------- 14-----------
15This command displays the performance counter profile information recorded 15This command displays the performance counter profile information recorded
16via perf report. 16via perf record.
17 17
18OPTIONS 18OPTIONS
19------- 19-------
20-i:: 20-i::
21--input=:: 21--input=::
22 Input file name. (default: perf.data) 22 Input file name. (default: perf.data)
23-d::
24--dsos=::
25 Only consider symbols in these dsos. CSV that understands
26 file://filename entries.
27-C::
28--comms=::
29 Only consider symbols in these comms. CSV that understands
30 file://filename entries.
31-S::
32--symbols=::
33 Only consider these symbols. CSV that understands
34 file://filename entries.
23 35
24SEE ALSO 36SEE ALSO
25-------- 37--------
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index c368a72721d7..0d74346d21ab 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -8,8 +8,8 @@ perf-stat - Run a command and gather performance counter statistics
8SYNOPSIS 8SYNOPSIS
9-------- 9--------
10[verse] 10[verse]
11'perf stat' [-e <EVENT> | --event=EVENT] [-l] [-a] <command> 11'perf stat' [-e <EVENT> | --event=EVENT] [-S] [-a] <command>
12'perf stat' [-e <EVENT> | --event=EVENT] [-l] [-a] -- <command> [<options>] 12'perf stat' [-e <EVENT> | --event=EVENT] [-S] [-a] -- <command> [<options>]
13 13
14DESCRIPTION 14DESCRIPTION
15----------- 15-----------
@@ -40,7 +40,7 @@ OPTIONS
40-a:: 40-a::
41 system-wide collection 41 system-wide collection
42 42
43-l:: 43-S::
44 scale counter values 44 scale counter values
45 45
46EXAMPLES 46EXAMPLES
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 36d7eef49913..9c6d0ae3708e 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -290,7 +290,7 @@ LIB_FILE=libperf.a
290 290
291LIB_H += ../../include/linux/perf_counter.h 291LIB_H += ../../include/linux/perf_counter.h
292LIB_H += perf.h 292LIB_H += perf.h
293LIB_H += types.h 293LIB_H += util/types.h
294LIB_H += util/list.h 294LIB_H += util/list.h
295LIB_H += util/rbtree.h 295LIB_H += util/rbtree.h
296LIB_H += util/levenshtein.h 296LIB_H += util/levenshtein.h
@@ -301,6 +301,7 @@ LIB_H += util/util.h
301LIB_H += util/help.h 301LIB_H += util/help.h
302LIB_H += util/strbuf.h 302LIB_H += util/strbuf.h
303LIB_H += util/string.h 303LIB_H += util/string.h
304LIB_H += util/strlist.h
304LIB_H += util/run-command.h 305LIB_H += util/run-command.h
305LIB_H += util/sigchain.h 306LIB_H += util/sigchain.h
306LIB_H += util/symbol.h 307LIB_H += util/symbol.h
@@ -322,12 +323,15 @@ LIB_OBJS += util/run-command.o
322LIB_OBJS += util/quote.o 323LIB_OBJS += util/quote.o
323LIB_OBJS += util/strbuf.o 324LIB_OBJS += util/strbuf.o
324LIB_OBJS += util/string.o 325LIB_OBJS += util/string.o
326LIB_OBJS += util/strlist.o
325LIB_OBJS += util/usage.o 327LIB_OBJS += util/usage.o
326LIB_OBJS += util/wrapper.o 328LIB_OBJS += util/wrapper.o
327LIB_OBJS += util/sigchain.o 329LIB_OBJS += util/sigchain.o
328LIB_OBJS += util/symbol.o 330LIB_OBJS += util/symbol.o
329LIB_OBJS += util/color.o 331LIB_OBJS += util/color.o
330LIB_OBJS += util/pager.o 332LIB_OBJS += util/pager.o
333LIB_OBJS += util/header.o
334LIB_OBJS += util/callchain.o
331 335
332BUILTIN_OBJS += builtin-annotate.o 336BUILTIN_OBJS += builtin-annotate.o
333BUILTIN_OBJS += builtin-help.o 337BUILTIN_OBJS += builtin-help.o
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 7e58e3ad1508..722c0f54e549 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -855,7 +855,7 @@ static unsigned long total = 0,
855 total_unknown = 0; 855 total_unknown = 0;
856 856
857static int 857static int
858process_overflow_event(event_t *event, unsigned long offset, unsigned long head) 858process_sample_event(event_t *event, unsigned long offset, unsigned long head)
859{ 859{
860 char level; 860 char level;
861 int show = 0; 861 int show = 0;
@@ -1013,10 +1013,10 @@ process_period_event(event_t *event, unsigned long offset, unsigned long head)
1013static int 1013static int
1014process_event(event_t *event, unsigned long offset, unsigned long head) 1014process_event(event_t *event, unsigned long offset, unsigned long head)
1015{ 1015{
1016 if (event->header.misc & PERF_EVENT_MISC_OVERFLOW)
1017 return process_overflow_event(event, offset, head);
1018
1019 switch (event->header.type) { 1016 switch (event->header.type) {
1017 case PERF_EVENT_SAMPLE:
1018 return process_sample_event(event, offset, head);
1019
1020 case PERF_EVENT_MMAP: 1020 case PERF_EVENT_MMAP:
1021 return process_mmap_event(event, offset, head); 1021 return process_mmap_event(event, offset, head);
1022 1022
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d7ebbd757543..d18546f37d7c 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -14,6 +14,8 @@
14#include "util/parse-events.h" 14#include "util/parse-events.h"
15#include "util/string.h" 15#include "util/string.h"
16 16
17#include "util/header.h"
18
17#include <unistd.h> 19#include <unistd.h>
18#include <sched.h> 20#include <sched.h>
19 21
@@ -39,6 +41,8 @@ static int force = 0;
39static int append_file = 0; 41static int append_file = 0;
40static int call_graph = 0; 42static int call_graph = 0;
41static int verbose = 0; 43static int verbose = 0;
44static int inherit_stat = 0;
45static int no_samples = 0;
42 46
43static long samples; 47static long samples;
44static struct timeval last_read; 48static struct timeval last_read;
@@ -52,7 +56,8 @@ static int nr_poll;
52static int nr_cpu; 56static int nr_cpu;
53 57
54static int file_new = 1; 58static int file_new = 1;
55static struct perf_file_header file_header; 59
60struct perf_header *header;
56 61
57struct mmap_event { 62struct mmap_event {
58 struct perf_event_header header; 63 struct perf_event_header header;
@@ -306,12 +311,11 @@ static void pid_synthesize_mmap_samples(pid_t pid)
306 continue; 311 continue;
307 pbf += n + 3; 312 pbf += n + 3;
308 if (*pbf == 'x') { /* vm_exec */ 313 if (*pbf == 'x') { /* vm_exec */
309 char *execname = strrchr(bf, ' '); 314 char *execname = strchr(bf, '/');
310 315
311 if (execname == NULL || execname[1] != '/') 316 if (execname == NULL)
312 continue; 317 continue;
313 318
314 execname += 1;
315 size = strlen(execname); 319 size = strlen(execname);
316 execname[size - 1] = '\0'; /* Remove \n */ 320 execname[size - 1] = '\0'; /* Remove \n */
317 memcpy(mmap_ev.filename, execname, size); 321 memcpy(mmap_ev.filename, execname, size);
@@ -329,7 +333,7 @@ static void pid_synthesize_mmap_samples(pid_t pid)
329 fclose(fp); 333 fclose(fp);
330} 334}
331 335
332static void synthesize_samples(void) 336static void synthesize_all(void)
333{ 337{
334 DIR *proc; 338 DIR *proc;
335 struct dirent dirent, *next; 339 struct dirent dirent, *next;
@@ -353,10 +357,35 @@ static void synthesize_samples(void)
353 357
354static int group_fd; 358static int group_fd;
355 359
360static struct perf_header_attr *get_header_attr(struct perf_counter_attr *a, int nr)
361{
362 struct perf_header_attr *h_attr;
363
364 if (nr < header->attrs) {
365 h_attr = header->attr[nr];
366 } else {
367 h_attr = perf_header_attr__new(a);
368 perf_header__add_attr(header, h_attr);
369 }
370
371 return h_attr;
372}
373
356static void create_counter(int counter, int cpu, pid_t pid) 374static void create_counter(int counter, int cpu, pid_t pid)
357{ 375{
358 struct perf_counter_attr *attr = attrs + counter; 376 struct perf_counter_attr *attr = attrs + counter;
359 int track = 1; 377 struct perf_header_attr *h_attr;
378 int track = !counter; /* only the first counter needs these */
379 struct {
380 u64 count;
381 u64 time_enabled;
382 u64 time_running;
383 u64 id;
384 } read_data;
385
386 attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
387 PERF_FORMAT_TOTAL_TIME_RUNNING |
388 PERF_FORMAT_ID;
360 389
361 attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID; 390 attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID;
362 391
@@ -366,25 +395,20 @@ static void create_counter(int counter, int cpu, pid_t pid)
366 attr->sample_freq = freq; 395 attr->sample_freq = freq;
367 } 396 }
368 397
398 if (no_samples)
399 attr->sample_freq = 0;
400
401 if (inherit_stat)
402 attr->inherit_stat = 1;
403
369 if (call_graph) 404 if (call_graph)
370 attr->sample_type |= PERF_SAMPLE_CALLCHAIN; 405 attr->sample_type |= PERF_SAMPLE_CALLCHAIN;
371 406
372 if (file_new) {
373 file_header.sample_type = attr->sample_type;
374 } else {
375 if (file_header.sample_type != attr->sample_type) {
376 fprintf(stderr, "incompatible append\n");
377 exit(-1);
378 }
379 }
380
381 attr->mmap = track; 407 attr->mmap = track;
382 attr->comm = track; 408 attr->comm = track;
383 attr->inherit = (cpu < 0) && inherit; 409 attr->inherit = (cpu < 0) && inherit;
384 attr->disabled = 1; 410 attr->disabled = 1;
385 411
386 track = 0; /* only the first counter needs these */
387
388try_again: 412try_again:
389 fd[nr_cpu][counter] = sys_perf_counter_open(attr, pid, cpu, group_fd, 0); 413 fd[nr_cpu][counter] = sys_perf_counter_open(attr, pid, cpu, group_fd, 0);
390 414
@@ -415,6 +439,22 @@ try_again:
415 exit(-1); 439 exit(-1);
416 } 440 }
417 441
442 h_attr = get_header_attr(attr, counter);
443
444 if (!file_new) {
445 if (memcmp(&h_attr->attr, attr, sizeof(*attr))) {
446 fprintf(stderr, "incompatible append\n");
447 exit(-1);
448 }
449 }
450
451 if (read(fd[nr_cpu][counter], &read_data, sizeof(read_data)) == -1) {
452 perror("Unable to read perf file descriptor\n");
453 exit(-1);
454 }
455
456 perf_header_attr__add_id(h_attr, read_data.id);
457
418 assert(fd[nr_cpu][counter] >= 0); 458 assert(fd[nr_cpu][counter] >= 0);
419 fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK); 459 fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK);
420 460
@@ -445,11 +485,6 @@ static void open_counters(int cpu, pid_t pid)
445{ 485{
446 int counter; 486 int counter;
447 487
448 if (pid > 0) {
449 pid_synthesize_comm_event(pid, 0);
450 pid_synthesize_mmap_samples(pid);
451 }
452
453 group_fd = -1; 488 group_fd = -1;
454 for (counter = 0; counter < nr_counters; counter++) 489 for (counter = 0; counter < nr_counters; counter++)
455 create_counter(counter, cpu, pid); 490 create_counter(counter, cpu, pid);
@@ -459,17 +494,16 @@ static void open_counters(int cpu, pid_t pid)
459 494
460static void atexit_header(void) 495static void atexit_header(void)
461{ 496{
462 file_header.data_size += bytes_written; 497 header->data_size += bytes_written;
463 498
464 if (pwrite(output, &file_header, sizeof(file_header), 0) == -1) 499 perf_header__write(header, output);
465 perror("failed to write on file headers");
466} 500}
467 501
468static int __cmd_record(int argc, const char **argv) 502static int __cmd_record(int argc, const char **argv)
469{ 503{
470 int i, counter; 504 int i, counter;
471 struct stat st; 505 struct stat st;
472 pid_t pid; 506 pid_t pid = 0;
473 int flags; 507 int flags;
474 int ret; 508 int ret;
475 509
@@ -500,22 +534,31 @@ static int __cmd_record(int argc, const char **argv)
500 exit(-1); 534 exit(-1);
501 } 535 }
502 536
503 if (!file_new) { 537 if (!file_new)
504 if (read(output, &file_header, sizeof(file_header)) == -1) { 538 header = perf_header__read(output);
505 perror("failed to read file headers"); 539 else
506 exit(-1); 540 header = perf_header__new();
507 }
508
509 lseek(output, file_header.data_size, SEEK_CUR);
510 }
511 541
512 atexit(atexit_header); 542 atexit(atexit_header);
513 543
514 if (!system_wide) { 544 if (!system_wide) {
515 open_counters(-1, target_pid != -1 ? target_pid : getpid()); 545 pid = target_pid;
546 if (pid == -1)
547 pid = getpid();
548
549 open_counters(-1, pid);
516 } else for (i = 0; i < nr_cpus; i++) 550 } else for (i = 0; i < nr_cpus; i++)
517 open_counters(i, target_pid); 551 open_counters(i, target_pid);
518 552
553 if (file_new)
554 perf_header__write(header, output);
555
556 if (!system_wide) {
557 pid_synthesize_comm_event(pid, 0);
558 pid_synthesize_mmap_samples(pid);
559 } else
560 synthesize_all();
561
519 if (target_pid == -1 && argc) { 562 if (target_pid == -1 && argc) {
520 pid = fork(); 563 pid = fork();
521 if (pid < 0) 564 if (pid < 0)
@@ -539,10 +582,7 @@ static int __cmd_record(int argc, const char **argv)
539 } 582 }
540 } 583 }
541 584
542 if (system_wide) 585 for (;;) {
543 synthesize_samples();
544
545 while (!done) {
546 int hits = samples; 586 int hits = samples;
547 587
548 for (i = 0; i < nr_cpu; i++) { 588 for (i = 0; i < nr_cpu; i++) {
@@ -550,8 +590,11 @@ static int __cmd_record(int argc, const char **argv)
550 mmap_read(&mmap_array[i][counter]); 590 mmap_read(&mmap_array[i][counter]);
551 } 591 }
552 592
553 if (hits == samples) 593 if (hits == samples) {
594 if (done)
595 break;
554 ret = poll(event_array, nr_poll, 100); 596 ret = poll(event_array, nr_poll, 100);
597 }
555 } 598 }
556 599
557 /* 600 /*
@@ -600,6 +643,10 @@ static const struct option options[] = {
600 "do call-graph (stack chain/backtrace) recording"), 643 "do call-graph (stack chain/backtrace) recording"),
601 OPT_BOOLEAN('v', "verbose", &verbose, 644 OPT_BOOLEAN('v', "verbose", &verbose,
602 "be more verbose (show counter open errors, etc)"), 645 "be more verbose (show counter open errors, etc)"),
646 OPT_BOOLEAN('s', "stat", &inherit_stat,
647 "per thread counts"),
648 OPT_BOOLEAN('n', "no-samples", &no_samples,
649 "don't sample"),
603 OPT_END() 650 OPT_END()
604}; 651};
605 652
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 5eb5566f0c95..135b7837e6bf 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -15,8 +15,11 @@
15#include "util/rbtree.h" 15#include "util/rbtree.h"
16#include "util/symbol.h" 16#include "util/symbol.h"
17#include "util/string.h" 17#include "util/string.h"
18#include "util/callchain.h"
19#include "util/strlist.h"
18 20
19#include "perf.h" 21#include "perf.h"
22#include "util/header.h"
20 23
21#include "util/parse-options.h" 24#include "util/parse-options.h"
22#include "util/parse-events.h" 25#include "util/parse-events.h"
@@ -30,6 +33,8 @@ static char *vmlinux = NULL;
30 33
31static char default_sort_order[] = "comm,dso"; 34static char default_sort_order[] = "comm,dso";
32static char *sort_order = default_sort_order; 35static char *sort_order = default_sort_order;
36static char *dso_list_str, *comm_list_str, *sym_list_str;
37static struct strlist *dso_list, *comm_list, *sym_list;
33 38
34static int input; 39static int input;
35static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV; 40static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
@@ -51,6 +56,9 @@ static char *parent_pattern = default_parent_pattern;
51static regex_t parent_regex; 56static regex_t parent_regex;
52 57
53static int exclude_other = 1; 58static int exclude_other = 1;
59static int callchain;
60
61static u64 sample_type;
54 62
55struct ip_event { 63struct ip_event {
56 struct perf_event_header header; 64 struct perf_event_header header;
@@ -59,11 +67,6 @@ struct ip_event {
59 unsigned char __more_data[]; 67 unsigned char __more_data[];
60}; 68};
61 69
62struct ip_callchain {
63 u64 nr;
64 u64 ips[0];
65};
66
67struct mmap_event { 70struct mmap_event {
68 struct perf_event_header header; 71 struct perf_event_header header;
69 u32 pid, tid; 72 u32 pid, tid;
@@ -97,6 +100,13 @@ struct lost_event {
97 u64 lost; 100 u64 lost;
98}; 101};
99 102
103struct read_event {
104 struct perf_event_header header;
105 u32 pid,tid;
106 u64 value;
107 u64 format[3];
108};
109
100typedef union event_union { 110typedef union event_union {
101 struct perf_event_header header; 111 struct perf_event_header header;
102 struct ip_event ip; 112 struct ip_event ip;
@@ -105,6 +115,7 @@ typedef union event_union {
105 struct fork_event fork; 115 struct fork_event fork;
106 struct period_event period; 116 struct period_event period;
107 struct lost_event lost; 117 struct lost_event lost;
118 struct read_event read;
108} event_t; 119} event_t;
109 120
110static LIST_HEAD(dsos); 121static LIST_HEAD(dsos);
@@ -229,7 +240,7 @@ static u64 vdso__map_ip(struct map *map, u64 ip)
229 240
230static inline int is_anon_memory(const char *filename) 241static inline int is_anon_memory(const char *filename)
231{ 242{
232 return strcmp(filename, "//anon") == 0; 243 return strcmp(filename, "//anon") == 0;
233} 244}
234 245
235static struct map *map__new(struct mmap_event *event) 246static struct map *map__new(struct mmap_event *event)
@@ -400,9 +411,27 @@ static void thread__insert_map(struct thread *self, struct map *map)
400 411
401 list_for_each_entry_safe(pos, tmp, &self->maps, node) { 412 list_for_each_entry_safe(pos, tmp, &self->maps, node) {
402 if (map__overlap(pos, map)) { 413 if (map__overlap(pos, map)) {
403 list_del_init(&pos->node); 414 if (verbose >= 2) {
404 /* XXX leaks dsos */ 415 printf("overlapping maps:\n");
405 free(pos); 416 map__fprintf(map, stdout);
417 map__fprintf(pos, stdout);
418 }
419
420 if (map->start <= pos->start && map->end > pos->start)
421 pos->start = map->end;
422
423 if (map->end >= pos->end && map->start < pos->end)
424 pos->end = map->start;
425
426 if (verbose >= 2) {
427 printf("after collision:\n");
428 map__fprintf(pos, stdout);
429 }
430
431 if (pos->start >= pos->end) {
432 list_del_init(&pos->node);
433 free(pos);
434 }
406 } 435 }
407 } 436 }
408 437
@@ -464,17 +493,19 @@ static size_t threads__fprintf(FILE *fp)
464static struct rb_root hist; 493static struct rb_root hist;
465 494
466struct hist_entry { 495struct hist_entry {
467 struct rb_node rb_node; 496 struct rb_node rb_node;
468 497
469 struct thread *thread; 498 struct thread *thread;
470 struct map *map; 499 struct map *map;
471 struct dso *dso; 500 struct dso *dso;
472 struct symbol *sym; 501 struct symbol *sym;
473 struct symbol *parent; 502 struct symbol *parent;
474 u64 ip; 503 u64 ip;
475 char level; 504 char level;
476 505 struct callchain_node callchain;
477 u64 count; 506 struct rb_root sorted_chain;
507
508 u64 count;
478}; 509};
479 510
480/* 511/*
@@ -745,6 +776,48 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
745} 776}
746 777
747static size_t 778static size_t
779callchain__fprintf(FILE *fp, struct callchain_node *self, u64 total_samples)
780{
781 struct callchain_list *chain;
782 size_t ret = 0;
783
784 if (!self)
785 return 0;
786
787 ret += callchain__fprintf(fp, self->parent, total_samples);
788
789
790 list_for_each_entry(chain, &self->val, list)
791 ret += fprintf(fp, " %p\n", (void *)chain->ip);
792
793 return ret;
794}
795
796static size_t
797hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
798 u64 total_samples)
799{
800 struct rb_node *rb_node;
801 struct callchain_node *chain;
802 size_t ret = 0;
803
804 rb_node = rb_first(&self->sorted_chain);
805 while (rb_node) {
806 double percent;
807
808 chain = rb_entry(rb_node, struct callchain_node, rb_node);
809 percent = chain->hit * 100.0 / total_samples;
810 ret += fprintf(fp, " %6.2f%%\n", percent);
811 ret += callchain__fprintf(fp, chain, total_samples);
812 ret += fprintf(fp, "\n");
813 rb_node = rb_next(rb_node);
814 }
815
816 return ret;
817}
818
819
820static size_t
748hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples) 821hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples)
749{ 822{
750 struct sort_entry *se; 823 struct sort_entry *se;
@@ -784,6 +857,9 @@ hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples)
784 857
785 ret += fprintf(fp, "\n"); 858 ret += fprintf(fp, "\n");
786 859
860 if (callchain)
861 hist_entry_callchain__fprintf(fp, self, total_samples);
862
787 return ret; 863 return ret;
788} 864}
789 865
@@ -797,7 +873,7 @@ resolve_symbol(struct thread *thread, struct map **mapp,
797{ 873{
798 struct dso *dso = dsop ? *dsop : NULL; 874 struct dso *dso = dsop ? *dsop : NULL;
799 struct map *map = mapp ? *mapp : NULL; 875 struct map *map = mapp ? *mapp : NULL;
800 uint64_t ip = *ipp; 876 u64 ip = *ipp;
801 877
802 if (!thread) 878 if (!thread)
803 return NULL; 879 return NULL;
@@ -814,7 +890,6 @@ resolve_symbol(struct thread *thread, struct map **mapp,
814 *mapp = map; 890 *mapp = map;
815got_map: 891got_map:
816 ip = map->map_ip(map, ip); 892 ip = map->map_ip(map, ip);
817 *ipp = ip;
818 893
819 dso = map->dso; 894 dso = map->dso;
820 } else { 895 } else {
@@ -828,6 +903,8 @@ got_map:
828 dso = kernel_dso; 903 dso = kernel_dso;
829 } 904 }
830 dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>"); 905 dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>");
906 dprintf(" ...... map: %Lx -> %Lx\n", *ipp, ip);
907 *ipp = ip;
831 908
832 if (dsop) 909 if (dsop)
833 *dsop = dso; 910 *dsop = dso;
@@ -867,6 +944,7 @@ hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
867 .level = level, 944 .level = level,
868 .count = count, 945 .count = count,
869 .parent = NULL, 946 .parent = NULL,
947 .sorted_chain = RB_ROOT
870 }; 948 };
871 int cmp; 949 int cmp;
872 950
@@ -909,6 +987,8 @@ hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
909 987
910 if (!cmp) { 988 if (!cmp) {
911 he->count += count; 989 he->count += count;
990 if (callchain)
991 append_chain(&he->callchain, chain);
912 return 0; 992 return 0;
913 } 993 }
914 994
@@ -922,6 +1002,10 @@ hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
922 if (!he) 1002 if (!he)
923 return -ENOMEM; 1003 return -ENOMEM;
924 *he = entry; 1004 *he = entry;
1005 if (callchain) {
1006 callchain_init(&he->callchain);
1007 append_chain(&he->callchain, chain);
1008 }
925 rb_link_node(&he->rb_node, parent, p); 1009 rb_link_node(&he->rb_node, parent, p);
926 rb_insert_color(&he->rb_node, &hist); 1010 rb_insert_color(&he->rb_node, &hist);
927 1011
@@ -998,6 +1082,9 @@ static void output__insert_entry(struct hist_entry *he)
998 struct rb_node *parent = NULL; 1082 struct rb_node *parent = NULL;
999 struct hist_entry *iter; 1083 struct hist_entry *iter;
1000 1084
1085 if (callchain)
1086 sort_chain_to_rbtree(&he->sorted_chain, &he->callchain);
1087
1001 while (*p != NULL) { 1088 while (*p != NULL) {
1002 parent = *p; 1089 parent = *p;
1003 iter = rb_entry(parent, struct hist_entry, rb_node); 1090 iter = rb_entry(parent, struct hist_entry, rb_node);
@@ -1115,7 +1202,7 @@ static int validate_chain(struct ip_callchain *chain, event_t *event)
1115} 1202}
1116 1203
1117static int 1204static int
1118process_overflow_event(event_t *event, unsigned long offset, unsigned long head) 1205process_sample_event(event_t *event, unsigned long offset, unsigned long head)
1119{ 1206{
1120 char level; 1207 char level;
1121 int show = 0; 1208 int show = 0;
@@ -1127,12 +1214,12 @@ process_overflow_event(event_t *event, unsigned long offset, unsigned long head)
1127 void *more_data = event->ip.__more_data; 1214 void *more_data = event->ip.__more_data;
1128 struct ip_callchain *chain = NULL; 1215 struct ip_callchain *chain = NULL;
1129 1216
1130 if (event->header.type & PERF_SAMPLE_PERIOD) { 1217 if (sample_type & PERF_SAMPLE_PERIOD) {
1131 period = *(u64 *)more_data; 1218 period = *(u64 *)more_data;
1132 more_data += sizeof(u64); 1219 more_data += sizeof(u64);
1133 } 1220 }
1134 1221
1135 dprintf("%p [%p]: PERF_EVENT (IP, %d): %d: %p period: %Ld\n", 1222 dprintf("%p [%p]: PERF_EVENT_SAMPLE (IP, %d): %d: %p period: %Ld\n",
1136 (void *)(offset + head), 1223 (void *)(offset + head),
1137 (void *)(long)(event->header.size), 1224 (void *)(long)(event->header.size),
1138 event->header.misc, 1225 event->header.misc,
@@ -1140,7 +1227,7 @@ process_overflow_event(event_t *event, unsigned long offset, unsigned long head)
1140 (void *)(long)ip, 1227 (void *)(long)ip,
1141 (long long)period); 1228 (long long)period);
1142 1229
1143 if (event->header.type & PERF_SAMPLE_CALLCHAIN) { 1230 if (sample_type & PERF_SAMPLE_CALLCHAIN) {
1144 int i; 1231 int i;
1145 1232
1146 chain = (void *)more_data; 1233 chain = (void *)more_data;
@@ -1166,6 +1253,9 @@ process_overflow_event(event_t *event, unsigned long offset, unsigned long head)
1166 return -1; 1253 return -1;
1167 } 1254 }
1168 1255
1256 if (comm_list && !strlist__has_entry(comm_list, thread->comm))
1257 return 0;
1258
1169 if (event->header.misc & PERF_EVENT_MISC_KERNEL) { 1259 if (event->header.misc & PERF_EVENT_MISC_KERNEL) {
1170 show = SHOW_KERNEL; 1260 show = SHOW_KERNEL;
1171 level = 'k'; 1261 level = 'k';
@@ -1188,6 +1278,12 @@ process_overflow_event(event_t *event, unsigned long offset, unsigned long head)
1188 if (show & show_mask) { 1278 if (show & show_mask) {
1189 struct symbol *sym = resolve_symbol(thread, &map, &dso, &ip); 1279 struct symbol *sym = resolve_symbol(thread, &map, &dso, &ip);
1190 1280
1281 if (dso_list && dso && dso->name && !strlist__has_entry(dso_list, dso->name))
1282 return 0;
1283
1284 if (sym_list && sym && !strlist__has_entry(sym_list, sym->name))
1285 return 0;
1286
1191 if (hist_entry__add(thread, map, dso, sym, ip, chain, level, period)) { 1287 if (hist_entry__add(thread, map, dso, sym, ip, chain, level, period)) {
1192 eprintf("problem incrementing symbol count, skipping event\n"); 1288 eprintf("problem incrementing symbol count, skipping event\n");
1193 return -1; 1289 return -1;
@@ -1328,14 +1424,27 @@ static void trace_event(event_t *event)
1328} 1424}
1329 1425
1330static int 1426static int
1427process_read_event(event_t *event, unsigned long offset, unsigned long head)
1428{
1429 dprintf("%p [%p]: PERF_EVENT_READ: %d %d %Lu\n",
1430 (void *)(offset + head),
1431 (void *)(long)(event->header.size),
1432 event->read.pid,
1433 event->read.tid,
1434 event->read.value);
1435
1436 return 0;
1437}
1438
1439static int
1331process_event(event_t *event, unsigned long offset, unsigned long head) 1440process_event(event_t *event, unsigned long offset, unsigned long head)
1332{ 1441{
1333 trace_event(event); 1442 trace_event(event);
1334 1443
1335 if (event->header.misc & PERF_EVENT_MISC_OVERFLOW)
1336 return process_overflow_event(event, offset, head);
1337
1338 switch (event->header.type) { 1444 switch (event->header.type) {
1445 case PERF_EVENT_SAMPLE:
1446 return process_sample_event(event, offset, head);
1447
1339 case PERF_EVENT_MMAP: 1448 case PERF_EVENT_MMAP:
1340 return process_mmap_event(event, offset, head); 1449 return process_mmap_event(event, offset, head);
1341 1450
@@ -1351,6 +1460,9 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
1351 case PERF_EVENT_LOST: 1460 case PERF_EVENT_LOST:
1352 return process_lost_event(event, offset, head); 1461 return process_lost_event(event, offset, head);
1353 1462
1463 case PERF_EVENT_READ:
1464 return process_read_event(event, offset, head);
1465
1354 /* 1466 /*
1355 * We dont process them right now but they are fine: 1467 * We dont process them right now but they are fine:
1356 */ 1468 */
@@ -1366,13 +1478,30 @@ process_event(event_t *event, unsigned long offset, unsigned long head)
1366 return 0; 1478 return 0;
1367} 1479}
1368 1480
1369static struct perf_file_header file_header; 1481static struct perf_header *header;
1482
1483static u64 perf_header__sample_type(void)
1484{
1485 u64 sample_type = 0;
1486 int i;
1487
1488 for (i = 0; i < header->attrs; i++) {
1489 struct perf_header_attr *attr = header->attr[i];
1490
1491 if (!sample_type)
1492 sample_type = attr->attr.sample_type;
1493 else if (sample_type != attr->attr.sample_type)
1494 die("non matching sample_type");
1495 }
1496
1497 return sample_type;
1498}
1370 1499
1371static int __cmd_report(void) 1500static int __cmd_report(void)
1372{ 1501{
1373 int ret, rc = EXIT_FAILURE; 1502 int ret, rc = EXIT_FAILURE;
1374 unsigned long offset = 0; 1503 unsigned long offset = 0;
1375 unsigned long head = sizeof(file_header); 1504 unsigned long head, shift;
1376 struct stat stat; 1505 struct stat stat;
1377 event_t *event; 1506 event_t *event;
1378 uint32_t size; 1507 uint32_t size;
@@ -1400,13 +1529,12 @@ static int __cmd_report(void)
1400 exit(0); 1529 exit(0);
1401 } 1530 }
1402 1531
1403 if (read(input, &file_header, sizeof(file_header)) == -1) { 1532 header = perf_header__read(input);
1404 perror("failed to read file headers"); 1533 head = header->data_offset;
1405 exit(-1);
1406 }
1407 1534
1408 if (sort__has_parent && 1535 sample_type = perf_header__sample_type();
1409 !(file_header.sample_type & PERF_SAMPLE_CALLCHAIN)) { 1536
1537 if (sort__has_parent && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {
1410 fprintf(stderr, "selected --sort parent, but no callchain data\n"); 1538 fprintf(stderr, "selected --sort parent, but no callchain data\n");
1411 exit(-1); 1539 exit(-1);
1412 } 1540 }
@@ -1426,6 +1554,11 @@ static int __cmd_report(void)
1426 cwd = NULL; 1554 cwd = NULL;
1427 cwdlen = 0; 1555 cwdlen = 0;
1428 } 1556 }
1557
1558 shift = page_size * (head / page_size);
1559 offset += shift;
1560 head -= shift;
1561
1429remap: 1562remap:
1430 buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ, 1563 buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
1431 MAP_SHARED, input, offset); 1564 MAP_SHARED, input, offset);
@@ -1442,9 +1575,10 @@ more:
1442 size = 8; 1575 size = 8;
1443 1576
1444 if (head + event->header.size >= page_size * mmap_window) { 1577 if (head + event->header.size >= page_size * mmap_window) {
1445 unsigned long shift = page_size * (head / page_size);
1446 int ret; 1578 int ret;
1447 1579
1580 shift = page_size * (head / page_size);
1581
1448 ret = munmap(buf, page_size * mmap_window); 1582 ret = munmap(buf, page_size * mmap_window);
1449 assert(ret == 0); 1583 assert(ret == 0);
1450 1584
@@ -1482,7 +1616,7 @@ more:
1482 1616
1483 head += size; 1617 head += size;
1484 1618
1485 if (offset + head >= sizeof(file_header) + file_header.data_size) 1619 if (offset + head >= header->data_offset + header->data_size)
1486 goto done; 1620 goto done;
1487 1621
1488 if (offset + head < stat.st_size) 1622 if (offset + head < stat.st_size)
@@ -1536,6 +1670,13 @@ static const struct option options[] = {
1536 "regex filter to identify parent, see: '--sort parent'"), 1670 "regex filter to identify parent, see: '--sort parent'"),
1537 OPT_BOOLEAN('x', "exclude-other", &exclude_other, 1671 OPT_BOOLEAN('x', "exclude-other", &exclude_other,
1538 "Only display entries with parent-match"), 1672 "Only display entries with parent-match"),
1673 OPT_BOOLEAN('c', "callchain", &callchain, "Display callchains"),
1674 OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]",
1675 "only consider symbols in these dsos"),
1676 OPT_STRING('C', "comms", &comm_list_str, "comm[,comm...]",
1677 "only consider symbols in these comms"),
1678 OPT_STRING('S', "symbols", &sym_list_str, "symbol[,symbol...]",
1679 "only consider these symbols"),
1539 OPT_END() 1680 OPT_END()
1540}; 1681};
1541 1682
@@ -1554,6 +1695,19 @@ static void setup_sorting(void)
1554 free(str); 1695 free(str);
1555} 1696}
1556 1697
1698static void setup_list(struct strlist **list, const char *list_str,
1699 const char *list_name)
1700{
1701 if (list_str) {
1702 *list = strlist__new(true, list_str);
1703 if (!*list) {
1704 fprintf(stderr, "problems parsing %s list\n",
1705 list_name);
1706 exit(129);
1707 }
1708 }
1709}
1710
1557int cmd_report(int argc, const char **argv, const char *prefix) 1711int cmd_report(int argc, const char **argv, const char *prefix)
1558{ 1712{
1559 symbol__init(); 1713 symbol__init();
@@ -1575,6 +1729,10 @@ int cmd_report(int argc, const char **argv, const char *prefix)
1575 if (argc) 1729 if (argc)
1576 usage_with_options(report_usage, options); 1730 usage_with_options(report_usage, options);
1577 1731
1732 setup_list(&dso_list, dso_list_str, "dso");
1733 setup_list(&comm_list, comm_list_str, "comm");
1734 setup_list(&sym_list, sym_list_str, "symbol");
1735
1578 setup_pager(); 1736 setup_pager();
1579 1737
1580 return __cmd_report(); 1738 return __cmd_report();
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 6d3eeac1ea25..2e03524a1de0 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -32,6 +32,7 @@
32 * Wu Fengguang <fengguang.wu@intel.com> 32 * Wu Fengguang <fengguang.wu@intel.com>
33 * Mike Galbraith <efault@gmx.de> 33 * Mike Galbraith <efault@gmx.de>
34 * Paul Mackerras <paulus@samba.org> 34 * Paul Mackerras <paulus@samba.org>
35 * Jaswinder Singh Rajput <jaswinder@kernel.org>
35 * 36 *
36 * Released under the GPL v2. (and only v2, not any later version) 37 * Released under the GPL v2. (and only v2, not any later version)
37 */ 38 */
@@ -45,7 +46,7 @@
45#include <sys/prctl.h> 46#include <sys/prctl.h>
46#include <math.h> 47#include <math.h>
47 48
48static struct perf_counter_attr default_attrs[MAX_COUNTERS] = { 49static struct perf_counter_attr default_attrs[] = {
49 50
50 { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK }, 51 { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK },
51 { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES}, 52 { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES},
@@ -59,42 +60,28 @@ static struct perf_counter_attr default_attrs[MAX_COUNTERS] = {
59 60
60}; 61};
61 62
63#define MAX_RUN 100
64
62static int system_wide = 0; 65static int system_wide = 0;
63static int inherit = 1;
64static int verbose = 0; 66static int verbose = 0;
65
66static int fd[MAX_NR_CPUS][MAX_COUNTERS];
67
68static int target_pid = -1;
69static int nr_cpus = 0; 67static int nr_cpus = 0;
70static unsigned int page_size; 68static int run_idx = 0;
71 69
70static int run_count = 1;
71static int inherit = 1;
72static int scale = 1; 72static int scale = 1;
73static int target_pid = -1;
74static int null_run = 0;
73 75
74static const unsigned int default_count[] = { 76static int fd[MAX_NR_CPUS][MAX_COUNTERS];
75 1000000,
76 1000000,
77 10000,
78 10000,
79 1000000,
80 10000,
81};
82
83#define MAX_RUN 100
84
85static int run_count = 1;
86static int run_idx = 0;
87
88static u64 event_res[MAX_RUN][MAX_COUNTERS][3];
89static u64 event_scaled[MAX_RUN][MAX_COUNTERS];
90
91//static u64 event_hist[MAX_RUN][MAX_COUNTERS][3];
92
93 77
94static u64 runtime_nsecs[MAX_RUN]; 78static u64 runtime_nsecs[MAX_RUN];
95static u64 walltime_nsecs[MAX_RUN]; 79static u64 walltime_nsecs[MAX_RUN];
96static u64 runtime_cycles[MAX_RUN]; 80static u64 runtime_cycles[MAX_RUN];
97 81
82static u64 event_res[MAX_RUN][MAX_COUNTERS][3];
83static u64 event_scaled[MAX_RUN][MAX_COUNTERS];
84
98static u64 event_res_avg[MAX_COUNTERS][3]; 85static u64 event_res_avg[MAX_COUNTERS][3];
99static u64 event_res_noise[MAX_COUNTERS][3]; 86static u64 event_res_noise[MAX_COUNTERS][3];
100 87
@@ -109,7 +96,10 @@ static u64 walltime_nsecs_noise;
109static u64 runtime_cycles_avg; 96static u64 runtime_cycles_avg;
110static u64 runtime_cycles_noise; 97static u64 runtime_cycles_noise;
111 98
112static void create_perf_stat_counter(int counter) 99#define ERR_PERF_OPEN \
100"Error: counter %d, sys_perf_counter_open() syscall returned with %d (%s)\n"
101
102static void create_perf_stat_counter(int counter, int pid)
113{ 103{
114 struct perf_counter_attr *attr = attrs + counter; 104 struct perf_counter_attr *attr = attrs + counter;
115 105
@@ -119,20 +109,21 @@ static void create_perf_stat_counter(int counter)
119 109
120 if (system_wide) { 110 if (system_wide) {
121 int cpu; 111 int cpu;
122 for (cpu = 0; cpu < nr_cpus; cpu ++) { 112 for (cpu = 0; cpu < nr_cpus; cpu++) {
123 fd[cpu][counter] = sys_perf_counter_open(attr, -1, cpu, -1, 0); 113 fd[cpu][counter] = sys_perf_counter_open(attr, -1, cpu, -1, 0);
124 if (fd[cpu][counter] < 0 && verbose) { 114 if (fd[cpu][counter] < 0 && verbose)
125 printf("Error: counter %d, sys_perf_counter_open() syscall returned with %d (%s)\n", counter, fd[cpu][counter], strerror(errno)); 115 fprintf(stderr, ERR_PERF_OPEN, counter,
126 } 116 fd[cpu][counter], strerror(errno));
127 } 117 }
128 } else { 118 } else {
129 attr->inherit = inherit; 119 attr->inherit = inherit;
130 attr->disabled = 1; 120 attr->disabled = 1;
131 121 attr->enable_on_exec = 1;
132 fd[0][counter] = sys_perf_counter_open(attr, 0, -1, -1, 0); 122
133 if (fd[0][counter] < 0 && verbose) { 123 fd[0][counter] = sys_perf_counter_open(attr, pid, -1, -1, 0);
134 printf("Error: counter %d, sys_perf_counter_open() syscall returned with %d (%s)\n", counter, fd[0][counter], strerror(errno)); 124 if (fd[0][counter] < 0 && verbose)
135 } 125 fprintf(stderr, ERR_PERF_OPEN, counter,
126 fd[0][counter], strerror(errno));
136 } 127 }
137} 128}
138 129
@@ -168,7 +159,7 @@ static void read_counter(int counter)
168 count[0] = count[1] = count[2] = 0; 159 count[0] = count[1] = count[2] = 0;
169 160
170 nv = scale ? 3 : 1; 161 nv = scale ? 3 : 1;
171 for (cpu = 0; cpu < nr_cpus; cpu ++) { 162 for (cpu = 0; cpu < nr_cpus; cpu++) {
172 if (fd[cpu][counter] < 0) 163 if (fd[cpu][counter] < 0)
173 continue; 164 continue;
174 165
@@ -215,32 +206,67 @@ static int run_perf_stat(int argc, const char **argv)
215 int status = 0; 206 int status = 0;
216 int counter; 207 int counter;
217 int pid; 208 int pid;
209 int child_ready_pipe[2], go_pipe[2];
210 char buf;
218 211
219 if (!system_wide) 212 if (!system_wide)
220 nr_cpus = 1; 213 nr_cpus = 1;
221 214
222 for (counter = 0; counter < nr_counters; counter++) 215 if (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0) {
223 create_perf_stat_counter(counter); 216 perror("failed to create pipes");
224 217 exit(1);
225 /* 218 }
226 * Enable counters and exec the command:
227 */
228 t0 = rdclock();
229 prctl(PR_TASK_PERF_COUNTERS_ENABLE);
230 219
231 if ((pid = fork()) < 0) 220 if ((pid = fork()) < 0)
232 perror("failed to fork"); 221 perror("failed to fork");
233 222
234 if (!pid) { 223 if (!pid) {
235 if (execvp(argv[0], (char **)argv)) { 224 close(child_ready_pipe[0]);
236 perror(argv[0]); 225 close(go_pipe[1]);
237 exit(-1); 226 fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
238 } 227
228 /*
229 * Do a dummy execvp to get the PLT entry resolved,
230 * so we avoid the resolver overhead on the real
231 * execvp call.
232 */
233 execvp("", (char **)argv);
234
235 /*
236 * Tell the parent we're ready to go
237 */
238 close(child_ready_pipe[1]);
239
240 /*
241 * Wait until the parent tells us to go.
242 */
243 read(go_pipe[0], &buf, 1);
244
245 execvp(argv[0], (char **)argv);
246
247 perror(argv[0]);
248 exit(-1);
239 } 249 }
240 250
251 /*
252 * Wait for the child to be ready to exec.
253 */
254 close(child_ready_pipe[1]);
255 close(go_pipe[0]);
256 read(child_ready_pipe[0], &buf, 1);
257 close(child_ready_pipe[0]);
258
259 for (counter = 0; counter < nr_counters; counter++)
260 create_perf_stat_counter(counter, pid);
261
262 /*
263 * Enable counters and exec the command:
264 */
265 t0 = rdclock();
266
267 close(go_pipe[1]);
241 wait(&status); 268 wait(&status);
242 269
243 prctl(PR_TASK_PERF_COUNTERS_DISABLE);
244 t1 = rdclock(); 270 t1 = rdclock();
245 271
246 walltime_nsecs[run_idx] = t1 - t0; 272 walltime_nsecs[run_idx] = t1 - t0;
@@ -262,7 +288,7 @@ static void nsec_printout(int counter, u64 *count, u64 *noise)
262{ 288{
263 double msecs = (double)count[0] / 1000000; 289 double msecs = (double)count[0] / 1000000;
264 290
265 fprintf(stderr, " %14.6f %-20s", msecs, event_name(counter)); 291 fprintf(stderr, " %14.6f %-24s", msecs, event_name(counter));
266 292
267 if (attrs[counter].type == PERF_TYPE_SOFTWARE && 293 if (attrs[counter].type == PERF_TYPE_SOFTWARE &&
268 attrs[counter].config == PERF_COUNT_SW_TASK_CLOCK) { 294 attrs[counter].config == PERF_COUNT_SW_TASK_CLOCK) {
@@ -276,7 +302,7 @@ static void nsec_printout(int counter, u64 *count, u64 *noise)
276 302
277static void abs_printout(int counter, u64 *count, u64 *noise) 303static void abs_printout(int counter, u64 *count, u64 *noise)
278{ 304{
279 fprintf(stderr, " %14Ld %-20s", count[0], event_name(counter)); 305 fprintf(stderr, " %14Ld %-24s", count[0], event_name(counter));
280 306
281 if (runtime_cycles_avg && 307 if (runtime_cycles_avg &&
282 attrs[counter].type == PERF_TYPE_HARDWARE && 308 attrs[counter].type == PERF_TYPE_HARDWARE &&
@@ -306,7 +332,7 @@ static void print_counter(int counter)
306 scaled = event_scaled_avg[counter]; 332 scaled = event_scaled_avg[counter];
307 333
308 if (scaled == -1) { 334 if (scaled == -1) {
309 fprintf(stderr, " %14s %-20s\n", 335 fprintf(stderr, " %14s %-24s\n",
310 "<not counted>", event_name(counter)); 336 "<not counted>", event_name(counter));
311 return; 337 return;
312 } 338 }
@@ -364,8 +390,11 @@ static void calc_avg(void)
364 event_res_avg[j]+1, event_res[i][j]+1); 390 event_res_avg[j]+1, event_res[i][j]+1);
365 update_avg("counter/2", j, 391 update_avg("counter/2", j,
366 event_res_avg[j]+2, event_res[i][j]+2); 392 event_res_avg[j]+2, event_res[i][j]+2);
367 update_avg("scaled", j, 393 if (event_scaled[i][j] != -1)
368 event_scaled_avg + j, event_scaled[i]+j); 394 update_avg("scaled", j,
395 event_scaled_avg + j, event_scaled[i]+j);
396 else
397 event_scaled_avg[j] = -1;
369 } 398 }
370 } 399 }
371 runtime_nsecs_avg /= run_count; 400 runtime_nsecs_avg /= run_count;
@@ -429,11 +458,14 @@ static void print_stat(int argc, const char **argv)
429 for (counter = 0; counter < nr_counters; counter++) 458 for (counter = 0; counter < nr_counters; counter++)
430 print_counter(counter); 459 print_counter(counter);
431 460
432
433 fprintf(stderr, "\n"); 461 fprintf(stderr, "\n");
434 fprintf(stderr, " %14.9f seconds time elapsed.\n", 462 fprintf(stderr, " %14.9f seconds time elapsed",
435 (double)walltime_nsecs_avg/1e9); 463 (double)walltime_nsecs_avg/1e9);
436 fprintf(stderr, "\n"); 464 if (run_count > 1) {
465 fprintf(stderr, " ( +- %7.3f%% )",
466 100.0*(double)walltime_nsecs_noise/(double)walltime_nsecs_avg);
467 }
468 fprintf(stderr, "\n\n");
437} 469}
438 470
439static volatile int signr = -1; 471static volatile int signr = -1;
@@ -466,13 +498,15 @@ static const struct option options[] = {
466 OPT_INTEGER('p', "pid", &target_pid, 498 OPT_INTEGER('p', "pid", &target_pid,
467 "stat events on existing pid"), 499 "stat events on existing pid"),
468 OPT_BOOLEAN('a', "all-cpus", &system_wide, 500 OPT_BOOLEAN('a', "all-cpus", &system_wide,
469 "system-wide collection from all CPUs"), 501 "system-wide collection from all CPUs"),
470 OPT_BOOLEAN('S', "scale", &scale, 502 OPT_BOOLEAN('S', "scale", &scale,
471 "scale/normalize counters"), 503 "scale/normalize counters"),
472 OPT_BOOLEAN('v', "verbose", &verbose, 504 OPT_BOOLEAN('v', "verbose", &verbose,
473 "be more verbose (show counter open errors, etc)"), 505 "be more verbose (show counter open errors, etc)"),
474 OPT_INTEGER('r', "repeat", &run_count, 506 OPT_INTEGER('r', "repeat", &run_count,
475 "repeat command and print average + stddev (max: 100)"), 507 "repeat command and print average + stddev (max: 100)"),
508 OPT_BOOLEAN('n', "null", &null_run,
509 "null run - dont start any counters"),
476 OPT_END() 510 OPT_END()
477}; 511};
478 512
@@ -480,18 +514,17 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
480{ 514{
481 int status; 515 int status;
482 516
483 page_size = sysconf(_SC_PAGE_SIZE);
484
485 memcpy(attrs, default_attrs, sizeof(attrs));
486
487 argc = parse_options(argc, argv, options, stat_usage, 0); 517 argc = parse_options(argc, argv, options, stat_usage, 0);
488 if (!argc) 518 if (!argc)
489 usage_with_options(stat_usage, options); 519 usage_with_options(stat_usage, options);
490 if (run_count <= 0 || run_count > MAX_RUN) 520 if (run_count <= 0 || run_count > MAX_RUN)
491 usage_with_options(stat_usage, options); 521 usage_with_options(stat_usage, options);
492 522
493 if (!nr_counters) 523 /* Set attrs and nr_counters if no event is selected and !null_run */
494 nr_counters = 8; 524 if (!null_run && !nr_counters) {
525 memcpy(attrs, default_attrs, sizeof(default_attrs));
526 nr_counters = ARRAY_SIZE(default_attrs);
527 }
495 528
496 nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); 529 nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
497 assert(nr_cpus <= MAX_NR_CPUS); 530 assert(nr_cpus <= MAX_NR_CPUS);
@@ -511,7 +544,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
511 status = 0; 544 status = 0;
512 for (run_idx = 0; run_idx < run_count; run_idx++) { 545 for (run_idx = 0; run_idx < run_count; run_idx++) {
513 if (run_count != 1 && verbose) 546 if (run_count != 1 && verbose)
514 fprintf(stderr, "[ perf stat: executing run #%d ... ]\n", run_idx+1); 547 fprintf(stderr, "[ perf stat: executing run #%d ... ]\n", run_idx + 1);
515 status = run_perf_stat(argc, argv); 548 status = run_perf_stat(argc, argv);
516 } 549 }
517 550
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 5352b5e352ed..cf0d21f1ae10 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -392,11 +392,11 @@ static void record_ip(u64 ip, int counter)
392 samples--; 392 samples--;
393} 393}
394 394
395static void process_event(u64 ip, int counter) 395static void process_event(u64 ip, int counter, int user)
396{ 396{
397 samples++; 397 samples++;
398 398
399 if (ip < min_ip || ip > max_ip) { 399 if (user) {
400 userspace_samples++; 400 userspace_samples++;
401 return; 401 return;
402 } 402 }
@@ -509,9 +509,10 @@ static void mmap_read_counter(struct mmap_data *md)
509 509
510 old += size; 510 old += size;
511 511
512 if (event->header.misc & PERF_EVENT_MISC_OVERFLOW) { 512 if (event->header.type == PERF_EVENT_SAMPLE) {
513 if (event->header.type & PERF_SAMPLE_IP) 513 int user =
514 process_event(event->ip.ip, md->counter); 514 (event->header.misc & PERF_EVENT_MISC_CPUMODE_MASK) == PERF_EVENT_MISC_USER;
515 process_event(event->ip.ip, md->counter, user);
515 } 516 }
516 } 517 }
517 518
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index ceb68aa51f7f..d3042a6ba03d 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -19,13 +19,29 @@
19#define cpu_relax() asm volatile("" ::: "memory"); 19#define cpu_relax() asm volatile("" ::: "memory");
20#endif 20#endif
21 21
22#ifdef __sh__
23#include "../../arch/sh/include/asm/unistd.h"
24#if defined(__SH4A__) || defined(__SH5__)
25# define rmb() asm volatile("synco" ::: "memory")
26#else
27# define rmb() asm volatile("" ::: "memory")
28#endif
29#define cpu_relax() asm volatile("" ::: "memory")
30#endif
31
32#ifdef __hppa__
33#include "../../arch/parisc/include/asm/unistd.h"
34#define rmb() asm volatile("" ::: "memory")
35#define cpu_relax() asm volatile("" ::: "memory");
36#endif
37
22#include <time.h> 38#include <time.h>
23#include <unistd.h> 39#include <unistd.h>
24#include <sys/types.h> 40#include <sys/types.h>
25#include <sys/syscall.h> 41#include <sys/syscall.h>
26 42
27#include "../../include/linux/perf_counter.h" 43#include "../../include/linux/perf_counter.h"
28#include "types.h" 44#include "util/types.h"
29 45
30/* 46/*
31 * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all 47 * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
@@ -72,10 +88,9 @@ sys_perf_counter_open(struct perf_counter_attr *attr,
72#define MAX_COUNTERS 256 88#define MAX_COUNTERS 256
73#define MAX_NR_CPUS 256 89#define MAX_NR_CPUS 256
74 90
75struct perf_file_header { 91struct ip_callchain {
76 u64 version; 92 u64 nr;
77 u64 sample_type; 93 u64 ips[0];
78 u64 data_size;
79}; 94};
80 95
81#endif 96#endif
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
new file mode 100644
index 000000000000..ad3c28578961
--- /dev/null
+++ b/tools/perf/util/callchain.c
@@ -0,0 +1,174 @@
1/*
2 * Copyright (C) 2009, Frederic Weisbecker <fweisbec@gmail.com>
3 *
4 * Handle the callchains from the stream in an ad-hoc radix tree and then
5 * sort them in an rbtree.
6 *
7 */
8
9#include <stdlib.h>
10#include <stdio.h>
11#include <stdbool.h>
12#include <errno.h>
13
14#include "callchain.h"
15
16
17static void rb_insert_callchain(struct rb_root *root, struct callchain_node *chain)
18{
19 struct rb_node **p = &root->rb_node;
20 struct rb_node *parent = NULL;
21 struct callchain_node *rnode;
22
23 while (*p) {
24 parent = *p;
25 rnode = rb_entry(parent, struct callchain_node, rb_node);
26
27 if (rnode->hit < chain->hit)
28 p = &(*p)->rb_left;
29 else
30 p = &(*p)->rb_right;
31 }
32
33 rb_link_node(&chain->rb_node, parent, p);
34 rb_insert_color(&chain->rb_node, root);
35}
36
37/*
38 * Once we get every callchains from the stream, we can now
39 * sort them by hit
40 */
41void sort_chain_to_rbtree(struct rb_root *rb_root, struct callchain_node *node)
42{
43 struct callchain_node *child;
44
45 list_for_each_entry(child, &node->children, brothers)
46 sort_chain_to_rbtree(rb_root, child);
47
48 if (node->hit)
49 rb_insert_callchain(rb_root, node);
50}
51
52static struct callchain_node *create_child(struct callchain_node *parent)
53{
54 struct callchain_node *new;
55
56 new = malloc(sizeof(*new));
57 if (!new) {
58 perror("not enough memory to create child for code path tree");
59 return NULL;
60 }
61 new->parent = parent;
62 INIT_LIST_HEAD(&new->children);
63 INIT_LIST_HEAD(&new->val);
64 list_add_tail(&new->brothers, &parent->children);
65
66 return new;
67}
68
69static void
70fill_node(struct callchain_node *node, struct ip_callchain *chain, int start)
71{
72 int i;
73
74 for (i = start; i < chain->nr; i++) {
75 struct callchain_list *call;
76
77 call = malloc(sizeof(*chain));
78 if (!call) {
79 perror("not enough memory for the code path tree");
80 return;
81 }
82 call->ip = chain->ips[i];
83 list_add_tail(&call->list, &node->val);
84 }
85 node->val_nr = i - start;
86}
87
88static void add_child(struct callchain_node *parent, struct ip_callchain *chain)
89{
90 struct callchain_node *new;
91
92 new = create_child(parent);
93 fill_node(new, chain, parent->val_nr);
94
95 new->hit = 1;
96}
97
98static void
99split_add_child(struct callchain_node *parent, struct ip_callchain *chain,
100 struct callchain_list *to_split, int idx)
101{
102 struct callchain_node *new;
103
104 /* split */
105 new = create_child(parent);
106 list_move_tail(&to_split->list, &new->val);
107 new->hit = parent->hit;
108 parent->hit = 0;
109 parent->val_nr = idx;
110
111 /* create the new one */
112 add_child(parent, chain);
113}
114
115static int
116__append_chain(struct callchain_node *root, struct ip_callchain *chain,
117 int start);
118
119static int
120__append_chain_children(struct callchain_node *root, struct ip_callchain *chain)
121{
122 struct callchain_node *rnode;
123
124 /* lookup in childrens */
125 list_for_each_entry(rnode, &root->children, brothers) {
126 int ret = __append_chain(rnode, chain, root->val_nr);
127 if (!ret)
128 return 0;
129 }
130 return -1;
131}
132
133static int
134__append_chain(struct callchain_node *root, struct ip_callchain *chain,
135 int start)
136{
137 struct callchain_list *cnode;
138 int i = start;
139 bool found = false;
140
141 /* lookup in the current node */
142 list_for_each_entry(cnode, &root->val, list) {
143 if (cnode->ip != chain->ips[i++])
144 break;
145 if (!found)
146 found = true;
147 if (i == chain->nr)
148 break;
149 }
150
151 /* matches not, relay on the parent */
152 if (!found)
153 return -1;
154
155 /* we match only a part of the node. Split it and add the new chain */
156 if (i < root->val_nr) {
157 split_add_child(root, chain, cnode, i);
158 return 0;
159 }
160
161 /* we match 100% of the path, increment the hit */
162 if (i == root->val_nr) {
163 root->hit++;
164 return 0;
165 }
166
167 return __append_chain_children(root, chain);
168}
169
170void append_chain(struct callchain_node *root, struct ip_callchain *chain)
171{
172 if (__append_chain_children(root, chain) == -1)
173 add_child(root, chain);
174}
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
new file mode 100644
index 000000000000..fa1cd2f71fd3
--- /dev/null
+++ b/tools/perf/util/callchain.h
@@ -0,0 +1,33 @@
1#ifndef __PERF_CALLCHAIN_H
2#define __PERF_CALLCHAIN_H
3
4#include "../perf.h"
5#include "list.h"
6#include "rbtree.h"
7
8
9struct callchain_node {
10 struct callchain_node *parent;
11 struct list_head brothers;
12 struct list_head children;
13 struct list_head val;
14 struct rb_node rb_node;
15 int val_nr;
16 int hit;
17};
18
19struct callchain_list {
20 unsigned long ip;
21 struct list_head list;
22};
23
24static inline void callchain_init(struct callchain_node *node)
25{
26 INIT_LIST_HEAD(&node->brothers);
27 INIT_LIST_HEAD(&node->children);
28 INIT_LIST_HEAD(&node->val);
29}
30
31void append_chain(struct callchain_node *root, struct ip_callchain *chain);
32void sort_chain_to_rbtree(struct rb_root *rb_root, struct callchain_node *node);
33#endif
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
new file mode 100644
index 000000000000..450384b3bbe5
--- /dev/null
+++ b/tools/perf/util/header.c
@@ -0,0 +1,242 @@
1#include <sys/types.h>
2#include <unistd.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6#include "util.h"
7#include "header.h"
8
9/*
10 *
11 */
12
13struct perf_header_attr *perf_header_attr__new(struct perf_counter_attr *attr)
14{
15 struct perf_header_attr *self = malloc(sizeof(*self));
16
17 if (!self)
18 die("nomem");
19
20 self->attr = *attr;
21 self->ids = 0;
22 self->size = 1;
23 self->id = malloc(sizeof(u64));
24
25 if (!self->id)
26 die("nomem");
27
28 return self;
29}
30
31void perf_header_attr__add_id(struct perf_header_attr *self, u64 id)
32{
33 int pos = self->ids;
34
35 self->ids++;
36 if (self->ids > self->size) {
37 self->size *= 2;
38 self->id = realloc(self->id, self->size * sizeof(u64));
39 if (!self->id)
40 die("nomem");
41 }
42 self->id[pos] = id;
43}
44
45/*
46 *
47 */
48
49struct perf_header *perf_header__new(void)
50{
51 struct perf_header *self = malloc(sizeof(*self));
52
53 if (!self)
54 die("nomem");
55
56 self->frozen = 0;
57
58 self->attrs = 0;
59 self->size = 1;
60 self->attr = malloc(sizeof(void *));
61
62 if (!self->attr)
63 die("nomem");
64
65 self->data_offset = 0;
66 self->data_size = 0;
67
68 return self;
69}
70
71void perf_header__add_attr(struct perf_header *self,
72 struct perf_header_attr *attr)
73{
74 int pos = self->attrs;
75
76 if (self->frozen)
77 die("frozen");
78
79 self->attrs++;
80 if (self->attrs > self->size) {
81 self->size *= 2;
82 self->attr = realloc(self->attr, self->size * sizeof(void *));
83 if (!self->attr)
84 die("nomem");
85 }
86 self->attr[pos] = attr;
87}
88
89static const char *__perf_magic = "PERFFILE";
90
91#define PERF_MAGIC (*(u64 *)__perf_magic)
92
93struct perf_file_section {
94 u64 offset;
95 u64 size;
96};
97
98struct perf_file_attr {
99 struct perf_counter_attr attr;
100 struct perf_file_section ids;
101};
102
103struct perf_file_header {
104 u64 magic;
105 u64 size;
106 u64 attr_size;
107 struct perf_file_section attrs;
108 struct perf_file_section data;
109};
110
111static void do_write(int fd, void *buf, size_t size)
112{
113 while (size) {
114 int ret = write(fd, buf, size);
115
116 if (ret < 0)
117 die("failed to write");
118
119 size -= ret;
120 buf += ret;
121 }
122}
123
124void perf_header__write(struct perf_header *self, int fd)
125{
126 struct perf_file_header f_header;
127 struct perf_file_attr f_attr;
128 struct perf_header_attr *attr;
129 int i;
130
131 lseek(fd, sizeof(f_header), SEEK_SET);
132
133
134 for (i = 0; i < self->attrs; i++) {
135 attr = self->attr[i];
136
137 attr->id_offset = lseek(fd, 0, SEEK_CUR);
138 do_write(fd, attr->id, attr->ids * sizeof(u64));
139 }
140
141
142 self->attr_offset = lseek(fd, 0, SEEK_CUR);
143
144 for (i = 0; i < self->attrs; i++) {
145 attr = self->attr[i];
146
147 f_attr = (struct perf_file_attr){
148 .attr = attr->attr,
149 .ids = {
150 .offset = attr->id_offset,
151 .size = attr->ids * sizeof(u64),
152 }
153 };
154 do_write(fd, &f_attr, sizeof(f_attr));
155 }
156
157
158 self->data_offset = lseek(fd, 0, SEEK_CUR);
159
160 f_header = (struct perf_file_header){
161 .magic = PERF_MAGIC,
162 .size = sizeof(f_header),
163 .attr_size = sizeof(f_attr),
164 .attrs = {
165 .offset = self->attr_offset,
166 .size = self->attrs * sizeof(f_attr),
167 },
168 .data = {
169 .offset = self->data_offset,
170 .size = self->data_size,
171 },
172 };
173
174 lseek(fd, 0, SEEK_SET);
175 do_write(fd, &f_header, sizeof(f_header));
176 lseek(fd, self->data_offset + self->data_size, SEEK_SET);
177
178 self->frozen = 1;
179}
180
181static void do_read(int fd, void *buf, size_t size)
182{
183 while (size) {
184 int ret = read(fd, buf, size);
185
186 if (ret < 0)
187 die("failed to read");
188
189 size -= ret;
190 buf += ret;
191 }
192}
193
194struct perf_header *perf_header__read(int fd)
195{
196 struct perf_header *self = perf_header__new();
197 struct perf_file_header f_header;
198 struct perf_file_attr f_attr;
199 u64 f_id;
200
201 int nr_attrs, nr_ids, i, j;
202
203 lseek(fd, 0, SEEK_SET);
204 do_read(fd, &f_header, sizeof(f_header));
205
206 if (f_header.magic != PERF_MAGIC ||
207 f_header.size != sizeof(f_header) ||
208 f_header.attr_size != sizeof(f_attr))
209 die("incompatible file format");
210
211 nr_attrs = f_header.attrs.size / sizeof(f_attr);
212 lseek(fd, f_header.attrs.offset, SEEK_SET);
213
214 for (i = 0; i < nr_attrs; i++) {
215 struct perf_header_attr *attr;
216 off_t tmp = lseek(fd, 0, SEEK_CUR);
217
218 do_read(fd, &f_attr, sizeof(f_attr));
219
220 attr = perf_header_attr__new(&f_attr.attr);
221
222 nr_ids = f_attr.ids.size / sizeof(u64);
223 lseek(fd, f_attr.ids.offset, SEEK_SET);
224
225 for (j = 0; j < nr_ids; j++) {
226 do_read(fd, &f_id, sizeof(f_id));
227
228 perf_header_attr__add_id(attr, f_id);
229 }
230 perf_header__add_attr(self, attr);
231 lseek(fd, tmp, SEEK_SET);
232 }
233
234 self->data_offset = f_header.data.offset;
235 self->data_size = f_header.data.size;
236
237 lseek(fd, self->data_offset + self->data_size, SEEK_SET);
238
239 self->frozen = 1;
240
241 return self;
242}
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
new file mode 100644
index 000000000000..b5ef53ad4c7a
--- /dev/null
+++ b/tools/perf/util/header.h
@@ -0,0 +1,37 @@
1#ifndef _PERF_HEADER_H
2#define _PERF_HEADER_H
3
4#include "../../../include/linux/perf_counter.h"
5#include <sys/types.h>
6#include "types.h"
7
8struct perf_header_attr {
9 struct perf_counter_attr attr;
10 int ids, size;
11 u64 *id;
12 off_t id_offset;
13};
14
15struct perf_header {
16 int frozen;
17 int attrs, size;
18 struct perf_header_attr **attr;
19 off_t attr_offset;
20 u64 data_offset;
21 u64 data_size;
22};
23
24struct perf_header *perf_header__read(int fd);
25void perf_header__write(struct perf_header *self, int fd);
26
27void perf_header__add_attr(struct perf_header *self,
28 struct perf_header_attr *attr);
29
30struct perf_header_attr *
31perf_header_attr__new(struct perf_counter_attr *attr);
32void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
33
34
35struct perf_header *perf_header__new(void);
36
37#endif /* _PERF_HEADER_H */
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 6653f7dd1d78..17a00e0df2c4 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -126,21 +126,6 @@ static int is_executable(const char *name)
126 !S_ISREG(st.st_mode)) 126 !S_ISREG(st.st_mode))
127 return 0; 127 return 0;
128 128
129#ifdef __MINGW32__
130 /* cannot trust the executable bit, peek into the file instead */
131 char buf[3] = { 0 };
132 int n;
133 int fd = open(name, O_RDONLY);
134 st.st_mode &= ~S_IXUSR;
135 if (fd >= 0) {
136 n = read(fd, buf, 2);
137 if (n == 2)
138 /* DOS executables start with "MZ" */
139 if (!strcmp(buf, "#!") || !strcmp(buf, "MZ"))
140 st.st_mode |= S_IXUSR;
141 close(fd);
142 }
143#endif
144 return st.st_mode & S_IXUSR; 129 return st.st_mode & S_IXUSR;
145} 130}
146 131
diff --git a/tools/perf/util/pager.c b/tools/perf/util/pager.c
index a28bccae5458..1915de20dcac 100644
--- a/tools/perf/util/pager.c
+++ b/tools/perf/util/pager.c
@@ -9,7 +9,6 @@
9 9
10static int spawned_pager; 10static int spawned_pager;
11 11
12#ifndef __MINGW32__
13static void pager_preexec(void) 12static void pager_preexec(void)
14{ 13{
15 /* 14 /*
@@ -24,7 +23,6 @@ static void pager_preexec(void)
24 23
25 setenv("LESS", "FRSX", 0); 24 setenv("LESS", "FRSX", 0);
26} 25}
27#endif
28 26
29static const char *pager_argv[] = { "sh", "-c", NULL, NULL }; 27static const char *pager_argv[] = { "sh", "-c", NULL, NULL };
30static struct child_process pager_process; 28static struct child_process pager_process;
@@ -70,9 +68,8 @@ void setup_pager(void)
70 pager_argv[2] = pager; 68 pager_argv[2] = pager;
71 pager_process.argv = pager_argv; 69 pager_process.argv = pager_argv;
72 pager_process.in = -1; 70 pager_process.in = -1;
73#ifndef __MINGW32__
74 pager_process.preexec_cb = pager_preexec; 71 pager_process.preexec_cb = pager_preexec;
75#endif 72
76 if (start_command(&pager_process)) 73 if (start_command(&pager_process))
77 return; 74 return;
78 75
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 35d04da38d6a..4d042f104cdc 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -16,32 +16,28 @@ struct event_symbol {
16 u8 type; 16 u8 type;
17 u64 config; 17 u64 config;
18 char *symbol; 18 char *symbol;
19 char *alias;
19}; 20};
20 21
21#define C(x, y) .type = PERF_TYPE_##x, .config = PERF_COUNT_##y 22#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
22#define CR(x, y) .type = PERF_TYPE_##x, .config = y 23#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
23 24
24static struct event_symbol event_symbols[] = { 25static struct event_symbol event_symbols[] = {
25 { C(HARDWARE, HW_CPU_CYCLES), "cpu-cycles", }, 26 { CHW(CPU_CYCLES), "cpu-cycles", "cycles" },
26 { C(HARDWARE, HW_CPU_CYCLES), "cycles", }, 27 { CHW(INSTRUCTIONS), "instructions", "" },
27 { C(HARDWARE, HW_INSTRUCTIONS), "instructions", }, 28 { CHW(CACHE_REFERENCES), "cache-references", "" },
28 { C(HARDWARE, HW_CACHE_REFERENCES), "cache-references", }, 29 { CHW(CACHE_MISSES), "cache-misses", "" },
29 { C(HARDWARE, HW_CACHE_MISSES), "cache-misses", }, 30 { CHW(BRANCH_INSTRUCTIONS), "branch-instructions", "branches" },
30 { C(HARDWARE, HW_BRANCH_INSTRUCTIONS),"branch-instructions", }, 31 { CHW(BRANCH_MISSES), "branch-misses", "" },
31 { C(HARDWARE, HW_BRANCH_INSTRUCTIONS),"branches", }, 32 { CHW(BUS_CYCLES), "bus-cycles", "" },
32 { C(HARDWARE, HW_BRANCH_MISSES), "branch-misses", }, 33
33 { C(HARDWARE, HW_BUS_CYCLES), "bus-cycles", }, 34 { CSW(CPU_CLOCK), "cpu-clock", "" },
34 35 { CSW(TASK_CLOCK), "task-clock", "" },
35 { C(SOFTWARE, SW_CPU_CLOCK), "cpu-clock", }, 36 { CSW(PAGE_FAULTS), "page-faults", "faults" },
36 { C(SOFTWARE, SW_TASK_CLOCK), "task-clock", }, 37 { CSW(PAGE_FAULTS_MIN), "minor-faults", "" },
37 { C(SOFTWARE, SW_PAGE_FAULTS), "page-faults", }, 38 { CSW(PAGE_FAULTS_MAJ), "major-faults", "" },
38 { C(SOFTWARE, SW_PAGE_FAULTS), "faults", }, 39 { CSW(CONTEXT_SWITCHES), "context-switches", "cs" },
39 { C(SOFTWARE, SW_PAGE_FAULTS_MIN), "minor-faults", }, 40 { CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" },
40 { C(SOFTWARE, SW_PAGE_FAULTS_MAJ), "major-faults", },
41 { C(SOFTWARE, SW_CONTEXT_SWITCHES), "context-switches", },
42 { C(SOFTWARE, SW_CONTEXT_SWITCHES), "cs", },
43 { C(SOFTWARE, SW_CPU_MIGRATIONS), "cpu-migrations", },
44 { C(SOFTWARE, SW_CPU_MIGRATIONS), "migrations", },
45}; 41};
46 42
47#define __PERF_COUNTER_FIELD(config, name) \ 43#define __PERF_COUNTER_FIELD(config, name) \
@@ -74,26 +70,70 @@ static char *sw_event_names[] = {
74 70
75#define MAX_ALIASES 8 71#define MAX_ALIASES 8
76 72
77static char *hw_cache [][MAX_ALIASES] = { 73static char *hw_cache[][MAX_ALIASES] = {
78 { "L1-data" , "l1-d", "l1d" }, 74 { "L1-d$", "l1-d", "l1d", "L1-data", },
79 { "L1-instruction" , "l1-i", "l1i" }, 75 { "L1-i$", "l1-i", "l1i", "L1-instruction", },
80 { "L2" , "l2" }, 76 { "LLC", "L2" },
81 { "Data-TLB" , "dtlb", "d-tlb" }, 77 { "dTLB", "d-tlb", "Data-TLB", },
82 { "Instruction-TLB" , "itlb", "i-tlb" }, 78 { "iTLB", "i-tlb", "Instruction-TLB", },
83 { "Branch" , "bpu" , "btb", "bpc" }, 79 { "branch", "branches", "bpu", "btb", "bpc", },
84}; 80};
85 81
86static char *hw_cache_op [][MAX_ALIASES] = { 82static char *hw_cache_op[][MAX_ALIASES] = {
87 { "Load" , "read" }, 83 { "load", "loads", "read", },
88 { "Store" , "write" }, 84 { "store", "stores", "write", },
89 { "Prefetch" , "speculative-read", "speculative-load" }, 85 { "prefetch", "prefetches", "speculative-read", "speculative-load", },
90}; 86};
91 87
92static char *hw_cache_result [][MAX_ALIASES] = { 88static char *hw_cache_result[][MAX_ALIASES] = {
93 { "Reference" , "ops", "access" }, 89 { "refs", "Reference", "ops", "access", },
94 { "Miss" }, 90 { "misses", "miss", },
95}; 91};
96 92
93#define C(x) PERF_COUNT_HW_CACHE_##x
94#define CACHE_READ (1 << C(OP_READ))
95#define CACHE_WRITE (1 << C(OP_WRITE))
96#define CACHE_PREFETCH (1 << C(OP_PREFETCH))
97#define COP(x) (1 << x)
98
99/*
100 * cache operartion stat
101 * L1I : Read and prefetch only
102 * ITLB and BPU : Read-only
103 */
104static unsigned long hw_cache_stat[C(MAX)] = {
105 [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
106 [C(L1I)] = (CACHE_READ | CACHE_PREFETCH),
107 [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
108 [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
109 [C(ITLB)] = (CACHE_READ),
110 [C(BPU)] = (CACHE_READ),
111};
112
113static int is_cache_op_valid(u8 cache_type, u8 cache_op)
114{
115 if (hw_cache_stat[cache_type] & COP(cache_op))
116 return 1; /* valid */
117 else
118 return 0; /* invalid */
119}
120
121static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result)
122{
123 static char name[50];
124
125 if (cache_result) {
126 sprintf(name, "%s-%s-%s", hw_cache[cache_type][0],
127 hw_cache_op[cache_op][0],
128 hw_cache_result[cache_result][0]);
129 } else {
130 sprintf(name, "%s-%s", hw_cache[cache_type][0],
131 hw_cache_op[cache_op][1]);
132 }
133
134 return name;
135}
136
97char *event_name(int counter) 137char *event_name(int counter)
98{ 138{
99 u64 config = attrs[counter].config; 139 u64 config = attrs[counter].config;
@@ -113,7 +153,6 @@ char *event_name(int counter)
113 153
114 case PERF_TYPE_HW_CACHE: { 154 case PERF_TYPE_HW_CACHE: {
115 u8 cache_type, cache_op, cache_result; 155 u8 cache_type, cache_op, cache_result;
116 static char name[100];
117 156
118 cache_type = (config >> 0) & 0xff; 157 cache_type = (config >> 0) & 0xff;
119 if (cache_type > PERF_COUNT_HW_CACHE_MAX) 158 if (cache_type > PERF_COUNT_HW_CACHE_MAX)
@@ -127,12 +166,10 @@ char *event_name(int counter)
127 if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) 166 if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX)
128 return "unknown-ext-hardware-cache-result"; 167 return "unknown-ext-hardware-cache-result";
129 168
130 sprintf(name, "%s-Cache-%s-%ses", 169 if (!is_cache_op_valid(cache_type, cache_op))
131 hw_cache[cache_type][0], 170 return "invalid-cache";
132 hw_cache_op[cache_op][0],
133 hw_cache_result[cache_result][0]);
134 171
135 return name; 172 return event_cache_name(cache_type, cache_op, cache_result);
136 } 173 }
137 174
138 case PERF_TYPE_SOFTWARE: 175 case PERF_TYPE_SOFTWARE:
@@ -163,7 +200,8 @@ static int parse_aliases(const char *str, char *names[][MAX_ALIASES], int size)
163 return -1; 200 return -1;
164} 201}
165 202
166static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *attr) 203static int
204parse_generic_hw_symbols(const char *str, struct perf_counter_attr *attr)
167{ 205{
168 int cache_type = -1, cache_op = 0, cache_result = 0; 206 int cache_type = -1, cache_op = 0, cache_result = 0;
169 207
@@ -182,6 +220,9 @@ static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *a
182 if (cache_op == -1) 220 if (cache_op == -1)
183 cache_op = PERF_COUNT_HW_CACHE_OP_READ; 221 cache_op = PERF_COUNT_HW_CACHE_OP_READ;
184 222
223 if (!is_cache_op_valid(cache_type, cache_op))
224 return -EINVAL;
225
185 cache_result = parse_aliases(str, hw_cache_result, 226 cache_result = parse_aliases(str, hw_cache_result,
186 PERF_COUNT_HW_CACHE_RESULT_MAX); 227 PERF_COUNT_HW_CACHE_RESULT_MAX);
187 /* 228 /*
@@ -196,6 +237,19 @@ static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *a
196 return 0; 237 return 0;
197} 238}
198 239
240static int check_events(const char *str, unsigned int i)
241{
242 if (!strncmp(str, event_symbols[i].symbol,
243 strlen(event_symbols[i].symbol)))
244 return 1;
245
246 if (strlen(event_symbols[i].alias))
247 if (!strncmp(str, event_symbols[i].alias,
248 strlen(event_symbols[i].alias)))
249 return 1;
250 return 0;
251}
252
199/* 253/*
200 * Each event can have multiple symbolic names. 254 * Each event can have multiple symbolic names.
201 * Symbolic names are (almost) exactly matched. 255 * Symbolic names are (almost) exactly matched.
@@ -235,9 +289,7 @@ static int parse_event_symbols(const char *str, struct perf_counter_attr *attr)
235 } 289 }
236 290
237 for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { 291 for (i = 0; i < ARRAY_SIZE(event_symbols); i++) {
238 if (!strncmp(str, event_symbols[i].symbol, 292 if (check_events(str, i)) {
239 strlen(event_symbols[i].symbol))) {
240
241 attr->type = event_symbols[i].type; 293 attr->type = event_symbols[i].type;
242 attr->config = event_symbols[i].config; 294 attr->config = event_symbols[i].config;
243 295
@@ -289,6 +341,7 @@ void print_events(void)
289{ 341{
290 struct event_symbol *syms = event_symbols; 342 struct event_symbol *syms = event_symbols;
291 unsigned int i, type, prev_type = -1; 343 unsigned int i, type, prev_type = -1;
344 char name[40];
292 345
293 fprintf(stderr, "\n"); 346 fprintf(stderr, "\n");
294 fprintf(stderr, "List of pre-defined events (to be used in -e):\n"); 347 fprintf(stderr, "List of pre-defined events (to be used in -e):\n");
@@ -301,14 +354,18 @@ void print_events(void)
301 if (type != prev_type) 354 if (type != prev_type)
302 fprintf(stderr, "\n"); 355 fprintf(stderr, "\n");
303 356
304 fprintf(stderr, " %-30s [%s]\n", syms->symbol, 357 if (strlen(syms->alias))
358 sprintf(name, "%s OR %s", syms->symbol, syms->alias);
359 else
360 strcpy(name, syms->symbol);
361 fprintf(stderr, " %-40s [%s]\n", name,
305 event_type_descriptors[type]); 362 event_type_descriptors[type]);
306 363
307 prev_type = type; 364 prev_type = type;
308 } 365 }
309 366
310 fprintf(stderr, "\n"); 367 fprintf(stderr, "\n");
311 fprintf(stderr, " %-30s [raw hardware event descriptor]\n", 368 fprintf(stderr, " %-40s [raw hardware event descriptor]\n",
312 "rNNN"); 369 "rNNN");
313 fprintf(stderr, "\n"); 370 fprintf(stderr, "\n");
314 371
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c
index b2f5e854f40a..a3935343091a 100644
--- a/tools/perf/util/run-command.c
+++ b/tools/perf/util/run-command.c
@@ -65,7 +65,6 @@ int start_command(struct child_process *cmd)
65 cmd->err = fderr[0]; 65 cmd->err = fderr[0];
66 } 66 }
67 67
68#ifndef __MINGW32__
69 fflush(NULL); 68 fflush(NULL);
70 cmd->pid = fork(); 69 cmd->pid = fork();
71 if (!cmd->pid) { 70 if (!cmd->pid) {
@@ -118,71 +117,6 @@ int start_command(struct child_process *cmd)
118 } 117 }
119 exit(127); 118 exit(127);
120 } 119 }
121#else
122 int s0 = -1, s1 = -1, s2 = -1; /* backups of stdin, stdout, stderr */
123 const char **sargv = cmd->argv;
124 char **env = environ;
125
126 if (cmd->no_stdin) {
127 s0 = dup(0);
128 dup_devnull(0);
129 } else if (need_in) {
130 s0 = dup(0);
131 dup2(fdin[0], 0);
132 } else if (cmd->in) {
133 s0 = dup(0);
134 dup2(cmd->in, 0);
135 }
136
137 if (cmd->no_stderr) {
138 s2 = dup(2);
139 dup_devnull(2);
140 } else if (need_err) {
141 s2 = dup(2);
142 dup2(fderr[1], 2);
143 }
144
145 if (cmd->no_stdout) {
146 s1 = dup(1);
147 dup_devnull(1);
148 } else if (cmd->stdout_to_stderr) {
149 s1 = dup(1);
150 dup2(2, 1);
151 } else if (need_out) {
152 s1 = dup(1);
153 dup2(fdout[1], 1);
154 } else if (cmd->out > 1) {
155 s1 = dup(1);
156 dup2(cmd->out, 1);
157 }
158
159 if (cmd->dir)
160 die("chdir in start_command() not implemented");
161 if (cmd->env) {
162 env = copy_environ();
163 for (; *cmd->env; cmd->env++)
164 env = env_setenv(env, *cmd->env);
165 }
166
167 if (cmd->perf_cmd) {
168 cmd->argv = prepare_perf_cmd(cmd->argv);
169 }
170
171 cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env);
172
173 if (cmd->env)
174 free_environ(env);
175 if (cmd->perf_cmd)
176 free(cmd->argv);
177
178 cmd->argv = sargv;
179 if (s0 >= 0)
180 dup2(s0, 0), close(s0);
181 if (s1 >= 0)
182 dup2(s1, 1), close(s1);
183 if (s2 >= 0)
184 dup2(s2, 2), close(s2);
185#endif
186 120
187 if (cmd->pid < 0) { 121 if (cmd->pid < 0) {
188 int err = errno; 122 int err = errno;
@@ -288,14 +222,6 @@ int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const
288 return run_command(&cmd); 222 return run_command(&cmd);
289} 223}
290 224
291#ifdef __MINGW32__
292static __stdcall unsigned run_thread(void *data)
293{
294 struct async *async = data;
295 return async->proc(async->fd_for_proc, async->data);
296}
297#endif
298
299int start_async(struct async *async) 225int start_async(struct async *async)
300{ 226{
301 int pipe_out[2]; 227 int pipe_out[2];
@@ -304,7 +230,6 @@ int start_async(struct async *async)
304 return error("cannot create pipe: %s", strerror(errno)); 230 return error("cannot create pipe: %s", strerror(errno));
305 async->out = pipe_out[0]; 231 async->out = pipe_out[0];
306 232
307#ifndef __MINGW32__
308 /* Flush stdio before fork() to avoid cloning buffers */ 233 /* Flush stdio before fork() to avoid cloning buffers */
309 fflush(NULL); 234 fflush(NULL);
310 235
@@ -319,33 +244,17 @@ int start_async(struct async *async)
319 exit(!!async->proc(pipe_out[1], async->data)); 244 exit(!!async->proc(pipe_out[1], async->data));
320 } 245 }
321 close(pipe_out[1]); 246 close(pipe_out[1]);
322#else 247
323 async->fd_for_proc = pipe_out[1];
324 async->tid = (HANDLE) _beginthreadex(NULL, 0, run_thread, async, 0, NULL);
325 if (!async->tid) {
326 error("cannot create thread: %s", strerror(errno));
327 close_pair(pipe_out);
328 return -1;
329 }
330#endif
331 return 0; 248 return 0;
332} 249}
333 250
334int finish_async(struct async *async) 251int finish_async(struct async *async)
335{ 252{
336#ifndef __MINGW32__
337 int ret = 0; 253 int ret = 0;
338 254
339 if (wait_or_whine(async->pid)) 255 if (wait_or_whine(async->pid))
340 ret = error("waitpid (async) failed"); 256 ret = error("waitpid (async) failed");
341#else 257
342 DWORD ret = 0;
343 if (WaitForSingleObject(async->tid, INFINITE) != WAIT_OBJECT_0)
344 ret = error("waiting for thread failed: %lu", GetLastError());
345 else if (!GetExitCodeThread(async->tid, &ret))
346 ret = error("cannot get thread exit code: %lu", GetLastError());
347 CloseHandle(async->tid);
348#endif
349 return ret; 258 return ret;
350} 259}
351 260
diff --git a/tools/perf/util/run-command.h b/tools/perf/util/run-command.h
index 328289f23669..cc1837deba88 100644
--- a/tools/perf/util/run-command.h
+++ b/tools/perf/util/run-command.h
@@ -79,12 +79,7 @@ struct async {
79 int (*proc)(int fd, void *data); 79 int (*proc)(int fd, void *data);
80 void *data; 80 void *data;
81 int out; /* caller reads from here and closes it */ 81 int out; /* caller reads from here and closes it */
82#ifndef __MINGW32__
83 pid_t pid; 82 pid_t pid;
84#else
85 HANDLE tid;
86 int fd_for_proc;
87#endif
88}; 83};
89 84
90int start_async(struct async *async); 85int start_async(struct async *async);
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index eaba09306802..464e7ca898cf 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -259,7 +259,7 @@ size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f)
259 res = fread(sb->buf + sb->len, 1, size, f); 259 res = fread(sb->buf + sb->len, 1, size, f);
260 if (res > 0) 260 if (res > 0)
261 strbuf_setlen(sb, sb->len + res); 261 strbuf_setlen(sb, sb->len + res);
262 else if (res < 0 && oldalloc == 0) 262 else if (oldalloc == 0)
263 strbuf_release(sb); 263 strbuf_release(sb);
264 return res; 264 return res;
265} 265}
diff --git a/tools/perf/util/string.h b/tools/perf/util/string.h
index 37b03255b425..3dca2f654cd0 100644
--- a/tools/perf/util/string.h
+++ b/tools/perf/util/string.h
@@ -1,7 +1,7 @@
1#ifndef _PERF_STRING_H_ 1#ifndef _PERF_STRING_H_
2#define _PERF_STRING_H_ 2#define _PERF_STRING_H_
3 3
4#include "../types.h" 4#include "types.h"
5 5
6int hex2u64(const char *ptr, u64 *val); 6int hex2u64(const char *ptr, u64 *val);
7 7
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c
new file mode 100644
index 000000000000..025a78edfffe
--- /dev/null
+++ b/tools/perf/util/strlist.c
@@ -0,0 +1,184 @@
1/*
2 * (c) 2009 Arnaldo Carvalho de Melo <acme@redhat.com>
3 *
4 * Licensed under the GPLv2.
5 */
6
7#include "strlist.h"
8#include <errno.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13static struct str_node *str_node__new(const char *s, bool dupstr)
14{
15 struct str_node *self = malloc(sizeof(*self));
16
17 if (self != NULL) {
18 if (dupstr) {
19 s = strdup(s);
20 if (s == NULL)
21 goto out_delete;
22 }
23 self->s = s;
24 }
25
26 return self;
27
28out_delete:
29 free(self);
30 return NULL;
31}
32
33static void str_node__delete(struct str_node *self, bool dupstr)
34{
35 if (dupstr)
36 free((void *)self->s);
37 free(self);
38}
39
40int strlist__add(struct strlist *self, const char *new_entry)
41{
42 struct rb_node **p = &self->entries.rb_node;
43 struct rb_node *parent = NULL;
44 struct str_node *sn;
45
46 while (*p != NULL) {
47 int rc;
48
49 parent = *p;
50 sn = rb_entry(parent, struct str_node, rb_node);
51 rc = strcmp(sn->s, new_entry);
52
53 if (rc > 0)
54 p = &(*p)->rb_left;
55 else if (rc < 0)
56 p = &(*p)->rb_right;
57 else
58 return -EEXIST;
59 }
60
61 sn = str_node__new(new_entry, self->dupstr);
62 if (sn == NULL)
63 return -ENOMEM;
64
65 rb_link_node(&sn->rb_node, parent, p);
66 rb_insert_color(&sn->rb_node, &self->entries);
67
68 return 0;
69}
70
71int strlist__load(struct strlist *self, const char *filename)
72{
73 char entry[1024];
74 int err;
75 FILE *fp = fopen(filename, "r");
76
77 if (fp == NULL)
78 return errno;
79
80 while (fgets(entry, sizeof(entry), fp) != NULL) {
81 const size_t len = strlen(entry);
82
83 if (len == 0)
84 continue;
85 entry[len - 1] = '\0';
86
87 err = strlist__add(self, entry);
88 if (err != 0)
89 goto out;
90 }
91
92 err = 0;
93out:
94 fclose(fp);
95 return err;
96}
97
98void strlist__remove(struct strlist *self, struct str_node *sn)
99{
100 rb_erase(&sn->rb_node, &self->entries);
101 str_node__delete(sn, self->dupstr);
102}
103
104bool strlist__has_entry(struct strlist *self, const char *entry)
105{
106 struct rb_node **p = &self->entries.rb_node;
107 struct rb_node *parent = NULL;
108
109 while (*p != NULL) {
110 struct str_node *sn;
111 int rc;
112
113 parent = *p;
114 sn = rb_entry(parent, struct str_node, rb_node);
115 rc = strcmp(sn->s, entry);
116
117 if (rc > 0)
118 p = &(*p)->rb_left;
119 else if (rc < 0)
120 p = &(*p)->rb_right;
121 else
122 return true;
123 }
124
125 return false;
126}
127
128static int strlist__parse_list_entry(struct strlist *self, const char *s)
129{
130 if (strncmp(s, "file://", 7) == 0)
131 return strlist__load(self, s + 7);
132
133 return strlist__add(self, s);
134}
135
136int strlist__parse_list(struct strlist *self, const char *s)
137{
138 char *sep;
139 int err;
140
141 while ((sep = strchr(s, ',')) != NULL) {
142 *sep = '\0';
143 err = strlist__parse_list_entry(self, s);
144 *sep = ',';
145 if (err != 0)
146 return err;
147 s = sep + 1;
148 }
149
150 return *s ? strlist__parse_list_entry(self, s) : 0;
151}
152
153struct strlist *strlist__new(bool dupstr, const char *slist)
154{
155 struct strlist *self = malloc(sizeof(*self));
156
157 if (self != NULL) {
158 self->entries = RB_ROOT;
159 self->dupstr = dupstr;
160 if (slist && strlist__parse_list(self, slist) != 0)
161 goto out_error;
162 }
163
164 return self;
165out_error:
166 free(self);
167 return NULL;
168}
169
170void strlist__delete(struct strlist *self)
171{
172 if (self != NULL) {
173 struct str_node *pos;
174 struct rb_node *next = rb_first(&self->entries);
175
176 while (next) {
177 pos = rb_entry(next, struct str_node, rb_node);
178 next = rb_next(&pos->rb_node);
179 strlist__remove(self, pos);
180 }
181 self->entries = RB_ROOT;
182 free(self);
183 }
184}
diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h
new file mode 100644
index 000000000000..2fb117fb4b67
--- /dev/null
+++ b/tools/perf/util/strlist.h
@@ -0,0 +1,32 @@
1#ifndef STRLIST_H_
2#define STRLIST_H_
3
4#include "rbtree.h"
5#include <stdbool.h>
6
7struct str_node {
8 struct rb_node rb_node;
9 const char *s;
10};
11
12struct strlist {
13 struct rb_root entries;
14 bool dupstr;
15};
16
17struct strlist *strlist__new(bool dupstr, const char *slist);
18void strlist__delete(struct strlist *self);
19
20void strlist__remove(struct strlist *self, struct str_node *sn);
21int strlist__load(struct strlist *self, const char *filename);
22int strlist__add(struct strlist *self, const char *str);
23
24bool strlist__has_entry(struct strlist *self, const char *entry);
25
26static inline bool strlist__empty(const struct strlist *self)
27{
28 return rb_first(&self->entries) == NULL;
29}
30
31int strlist__parse_list(struct strlist *self, const char *s);
32#endif /* STRLIST_H_ */
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 86e14375e74e..78c2efde01b7 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -520,7 +520,9 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
520 nr_syms = shdr.sh_size / shdr.sh_entsize; 520 nr_syms = shdr.sh_size / shdr.sh_entsize;
521 521
522 memset(&sym, 0, sizeof(sym)); 522 memset(&sym, 0, sizeof(sym));
523 523 self->prelinked = elf_section_by_name(elf, &ehdr, &shdr,
524 ".gnu.prelink_undo",
525 NULL) != NULL;
524 elf_symtab__for_each_symbol(syms, nr_syms, index, sym) { 526 elf_symtab__for_each_symbol(syms, nr_syms, index, sym) {
525 struct symbol *f; 527 struct symbol *f;
526 u64 obj_start; 528 u64 obj_start;
@@ -535,7 +537,13 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
535 gelf_getshdr(sec, &shdr); 537 gelf_getshdr(sec, &shdr);
536 obj_start = sym.st_value; 538 obj_start = sym.st_value;
537 539
538 sym.st_value -= shdr.sh_addr - shdr.sh_offset; 540 if (self->prelinked) {
541 if (verbose >= 2)
542 printf("adjusting symbol: st_value: %Lx sh_addr: %Lx sh_offset: %Lx\n",
543 (u64)sym.st_value, (u64)shdr.sh_addr, (u64)shdr.sh_offset);
544
545 sym.st_value -= shdr.sh_addr - shdr.sh_offset;
546 }
539 547
540 f = symbol__new(sym.st_value, sym.st_size, 548 f = symbol__new(sym.st_value, sym.st_size,
541 elf_sym__name(&sym, symstrs), 549 elf_sym__name(&sym, symstrs),
@@ -569,6 +577,8 @@ int dso__load(struct dso *self, symbol_filter_t filter, int verbose)
569 if (!name) 577 if (!name)
570 return -1; 578 return -1;
571 579
580 self->prelinked = 0;
581
572 if (strncmp(self->name, "/tmp/perf-", 10) == 0) 582 if (strncmp(self->name, "/tmp/perf-", 10) == 0)
573 return dso__load_perf_map(self, filter, verbose); 583 return dso__load_perf_map(self, filter, verbose);
574 584
@@ -629,7 +639,7 @@ int dso__load_kernel(struct dso *self, const char *vmlinux,
629 if (vmlinux) 639 if (vmlinux)
630 err = dso__load_vmlinux(self, vmlinux, filter, verbose); 640 err = dso__load_vmlinux(self, vmlinux, filter, verbose);
631 641
632 if (err) 642 if (err < 0)
633 err = dso__load_kallsyms(self, filter, verbose); 643 err = dso__load_kallsyms(self, filter, verbose);
634 644
635 return err; 645 return err;
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index ea332e56e458..2c48ace8203b 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -2,7 +2,7 @@
2#define _PERF_SYMBOL_ 1 2#define _PERF_SYMBOL_ 1
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5#include "../types.h" 5#include "types.h"
6#include "list.h" 6#include "list.h"
7#include "rbtree.h" 7#include "rbtree.h"
8 8
@@ -20,8 +20,9 @@ struct symbol {
20struct dso { 20struct dso {
21 struct list_head node; 21 struct list_head node;
22 struct rb_root syms; 22 struct rb_root syms;
23 unsigned int sym_priv_size;
24 struct symbol *(*find_symbol)(struct dso *, u64 ip); 23 struct symbol *(*find_symbol)(struct dso *, u64 ip);
24 unsigned int sym_priv_size;
25 unsigned char prelinked;
25 char name[0]; 26 char name[0];
26}; 27};
27 28
diff --git a/tools/perf/types.h b/tools/perf/util/types.h
index 5e75f9005940..5e75f9005940 100644
--- a/tools/perf/types.h
+++ b/tools/perf/util/types.h
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index b8cfed776d81..b4be6071c105 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -67,7 +67,6 @@
67#include <assert.h> 67#include <assert.h>
68#include <regex.h> 68#include <regex.h>
69#include <utime.h> 69#include <utime.h>
70#ifndef __MINGW32__
71#include <sys/wait.h> 70#include <sys/wait.h>
72#include <sys/poll.h> 71#include <sys/poll.h>
73#include <sys/socket.h> 72#include <sys/socket.h>
@@ -81,20 +80,6 @@
81#include <netdb.h> 80#include <netdb.h>
82#include <pwd.h> 81#include <pwd.h>
83#include <inttypes.h> 82#include <inttypes.h>
84#if defined(__CYGWIN__)
85#undef _XOPEN_SOURCE
86#include <grp.h>
87#define _XOPEN_SOURCE 600
88#include "compat/cygwin.h"
89#else
90#undef _ALL_SOURCE /* AIX 5.3L defines a struct list with _ALL_SOURCE. */
91#include <grp.h>
92#define _ALL_SOURCE 1
93#endif
94#else /* __MINGW32__ */
95/* pull in Windows compatibility stuff */
96#include "compat/mingw.h"
97#endif /* __MINGW32__ */
98 83
99#ifndef NO_ICONV 84#ifndef NO_ICONV
100#include <iconv.h> 85#include <iconv.h>
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 764554350ed8..2884baf1d5f9 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -746,6 +746,7 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
746 cpumask_clear(cpus); 746 cpumask_clear(cpus);
747 747
748 me = get_cpu(); 748 me = get_cpu();
749 spin_lock(&kvm->requests_lock);
749 for (i = 0; i < KVM_MAX_VCPUS; ++i) { 750 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
750 vcpu = kvm->vcpus[i]; 751 vcpu = kvm->vcpus[i];
751 if (!vcpu) 752 if (!vcpu)
@@ -762,6 +763,7 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
762 smp_call_function_many(cpus, ack_flush, NULL, 1); 763 smp_call_function_many(cpus, ack_flush, NULL, 1);
763 else 764 else
764 called = false; 765 called = false;
766 spin_unlock(&kvm->requests_lock);
765 put_cpu(); 767 put_cpu();
766 free_cpumask_var(cpus); 768 free_cpumask_var(cpus);
767 return called; 769 return called;
@@ -982,6 +984,7 @@ static struct kvm *kvm_create_vm(void)
982 kvm->mm = current->mm; 984 kvm->mm = current->mm;
983 atomic_inc(&kvm->mm->mm_count); 985 atomic_inc(&kvm->mm->mm_count);
984 spin_lock_init(&kvm->mmu_lock); 986 spin_lock_init(&kvm->mmu_lock);
987 spin_lock_init(&kvm->requests_lock);
985 kvm_io_bus_init(&kvm->pio_bus); 988 kvm_io_bus_init(&kvm->pio_bus);
986 mutex_init(&kvm->lock); 989 mutex_init(&kvm->lock);
987 kvm_io_bus_init(&kvm->mmio_bus); 990 kvm_io_bus_init(&kvm->mmio_bus);
@@ -1194,6 +1197,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
1194 if (!new.dirty_bitmap) 1197 if (!new.dirty_bitmap)
1195 goto out_free; 1198 goto out_free;
1196 memset(new.dirty_bitmap, 0, dirty_bytes); 1199 memset(new.dirty_bitmap, 0, dirty_bytes);
1200 if (old.npages)
1201 kvm_arch_flush_shadow(kvm);
1197 } 1202 }
1198#endif /* not defined CONFIG_S390 */ 1203#endif /* not defined CONFIG_S390 */
1199 1204