aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/accounting/getdelays.c38
-rw-r--r--Documentation/cgroups/cgroups.txt14
-rw-r--r--Documentation/feature-removal-schedule.txt17
-rw-r--r--Documentation/filesystems/proc.txt17
-rw-r--r--Documentation/networking/phy.txt18
-rw-r--r--Documentation/sysctl/vm.txt12
-rw-r--r--arch/alpha/kernel/pci_iommu.c4
-rw-r--r--arch/alpha/kernel/ptrace.c7
-rw-r--r--arch/arm/kernel/ptrace.c28
-rw-r--r--arch/arm/mach-tegra/timer.c1
-rw-r--r--arch/arm/mm/highmem.c3
-rw-r--r--arch/arm/plat-nomadik/include/plat/ste_dma40.h1
-rw-r--r--arch/avr32/kernel/ptrace.c11
-rw-r--r--arch/blackfin/kernel/ptrace.c16
-rw-r--r--arch/cris/arch-v10/kernel/ptrace.c20
-rw-r--r--arch/cris/arch-v32/kernel/ptrace.c16
-rw-r--r--arch/frv/kernel/ptrace.c32
-rw-r--r--arch/frv/mm/highmem.c3
-rw-r--r--arch/h8300/kernel/ptrace.c33
-rw-r--r--arch/ia64/include/asm/cputime.h6
-rw-r--r--arch/ia64/kernel/ptrace.c3
-rw-r--r--arch/m32r/kernel/ptrace.c11
-rw-r--r--arch/m68k/kernel/ptrace.c51
-rw-r--r--arch/m68knommu/kernel/ptrace.c57
-rw-r--r--arch/microblaze/kernel/ptrace.c5
-rw-r--r--arch/mips/include/asm/pci/bridge.h2
-rw-r--r--arch/mips/kernel/ptrace.c25
-rw-r--r--arch/mips/mm/highmem.c3
-rw-r--r--arch/mn10300/include/asm/highmem.h4
-rw-r--r--arch/mn10300/kernel/ptrace.c20
-rw-r--r--arch/parisc/kernel/ptrace.c13
-rw-r--r--arch/powerpc/include/asm/cputime.h12
-rw-r--r--arch/powerpc/kernel/ptrace.c66
-rw-r--r--arch/powerpc/mm/highmem.c4
-rw-r--r--arch/powerpc/sysdev/fsl_rio.c76
-rw-r--r--arch/s390/include/asm/cputime.h10
-rw-r--r--arch/s390/kernel/ptrace.c3
-rw-r--r--arch/score/kernel/ptrace.c7
-rw-r--r--arch/sh/kernel/ptrace_32.c45
-rw-r--r--arch/sh/kernel/ptrace_64.c25
-rw-r--r--arch/sparc/include/asm/io_32.h31
-rw-r--r--arch/sparc/include/asm/io_64.h31
-rw-r--r--arch/sparc/include/asm/pci_64.h2
-rw-r--r--arch/sparc/kernel/ptrace_32.c57
-rw-r--r--arch/sparc/kernel/ptrace_64.c15
-rw-r--r--arch/sparc/mm/highmem.c4
-rw-r--r--arch/tile/Kconfig3
-rw-r--r--arch/tile/kernel/ptrace.c13
-rw-r--r--arch/tile/kernel/setup.c2
-rw-r--r--arch/tile/mm/highmem.c3
-rw-r--r--arch/um/kernel/ptrace.c23
-rw-r--r--arch/um/sys-i386/ptrace.c4
-rw-r--r--arch/um/sys-x86_64/ptrace.c11
-rw-r--r--arch/x86/Kconfig1
-rw-r--r--arch/x86/include/asm/irq.h2
-rw-r--r--arch/x86/include/asm/msr-index.h1
-rw-r--r--arch/x86/include/asm/perf_event.h19
-rw-r--r--arch/x86/include/asm/smp.h9
-rw-r--r--arch/x86/kernel/cpu/perf_event.c21
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_ds.c216
-rw-r--r--arch/x86/kernel/dumpstack_32.c6
-rw-r--r--arch/x86/kernel/dumpstack_64.c8
-rw-r--r--arch/x86/kernel/irq_32.c12
-rw-r--r--arch/x86/kernel/ptrace.c17
-rw-r--r--arch/x86/kernel/reboot.c2
-rw-r--r--arch/x86/kernel/smp.c15
-rw-r--r--arch/x86/kernel/smpboot.c1
-rw-r--r--arch/x86/mm/highmem_32.c3
-rw-r--r--arch/x86/mm/init_64.c1
-rw-r--r--arch/x86/mm/iomap_32.c3
-rw-r--r--arch/x86/oprofile/nmi_int.c6
-rw-r--r--arch/x86/oprofile/op_model_amd.c146
-rw-r--r--arch/x86/xen/enlighten.c3
-rw-r--r--arch/x86/xen/smp.c6
-rw-r--r--arch/xtensa/kernel/ptrace.c14
-rw-r--r--drivers/atm/eni.c7
-rw-r--r--drivers/char/applicom.c1
-rw-r--r--drivers/char/hvc_console.c1
-rw-r--r--drivers/char/ip2/Makefile2
-rw-r--r--drivers/char/ipmi/Makefile2
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c4
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c4
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c14
-rw-r--r--drivers/char/mmtimer.c60
-rw-r--r--drivers/char/mwave/Makefile4
-rw-r--r--drivers/char/mxser.c4
-rw-r--r--drivers/char/pcmcia/ipwireless/Makefile2
-rw-r--r--drivers/char/ppdev.c1
-rw-r--r--drivers/char/ramoops.c30
-rw-r--r--drivers/char/rio/Makefile2
-rw-r--r--drivers/char/rocket.c5
-rw-r--r--drivers/char/synclink_gt.c142
-rw-r--r--drivers/char/vt_ioctl.c11
-rw-r--r--drivers/connector/cn_queue.c75
-rw-r--r--drivers/connector/connector.c9
-rw-r--r--drivers/dma/pch_dma.c1
-rw-r--r--drivers/firmware/dmi_scan.c32
-rw-r--r--drivers/gpio/74x164.c182
-rw-r--r--drivers/gpio/Kconfig28
-rw-r--r--drivers/gpio/Makefile3
-rw-r--r--drivers/gpio/adp5588-gpio.c277
-rw-r--r--drivers/gpio/basic_mmio_gpio.c297
-rw-r--r--drivers/gpio/langwell_gpio.c89
-rw-r--r--drivers/gpio/pch_gpio.c312
-rw-r--r--drivers/gpio/timbgpio.c21
-rw-r--r--drivers/i2c/busses/scx200_acb.c3
-rw-r--r--drivers/isdn/hardware/mISDN/mISDNinfineon.c2
-rw-r--r--drivers/isdn/hisax/l3_1tr6.c6
-rw-r--r--drivers/media/IR/lirc_dev.c1
-rw-r--r--drivers/net/atl1c/atl1c.h2
-rw-r--r--drivers/net/atl1c/atl1c_main.c6
-rw-r--r--drivers/net/atlx/atl1.c12
-rw-r--r--drivers/net/atlx/atl1.h9
-rw-r--r--drivers/net/atlx/atlx.c4
-rw-r--r--drivers/net/benet/be_cmds.c36
-rw-r--r--drivers/net/benet/be_cmds.h2
-rw-r--r--drivers/net/benet/be_main.c49
-rw-r--r--drivers/net/bnx2x/bnx2x.h5
-rw-r--r--drivers/net/bnx2x/bnx2x_cmn.c3
-rw-r--r--drivers/net/bnx2x/bnx2x_cmn.h55
-rw-r--r--drivers/net/bnx2x/bnx2x_init_ops.h34
-rw-r--r--drivers/net/bnx2x/bnx2x_link.c137
-rw-r--r--drivers/net/bnx2x/bnx2x_link.h15
-rw-r--r--drivers/net/bnx2x/bnx2x_main.c55
-rw-r--r--drivers/net/bonding/bond_main.c4
-rw-r--r--drivers/net/caif/Kconfig7
-rw-r--r--drivers/net/caif/Makefile4
-rw-r--r--drivers/net/caif/caif_shm_u5500.c129
-rw-r--r--drivers/net/caif/caif_shmcore.c744
-rw-r--r--drivers/net/can/Kconfig8
-rw-r--r--drivers/net/can/Makefile1
-rw-r--r--drivers/net/can/at91_can.c95
-rw-r--r--drivers/net/can/flexcan.c3
-rw-r--r--drivers/net/can/mcp251x.c3
-rw-r--r--drivers/net/can/pch_can.c1463
-rw-r--r--drivers/net/can/sja1000/Kconfig12
-rw-r--r--drivers/net/can/sja1000/Makefile1
-rw-r--r--drivers/net/can/sja1000/tscan1.c216
-rw-r--r--drivers/net/cxgb3/cxgb3_main.c8
-rw-r--r--drivers/net/cxgb4/cxgb4.h1
-rw-r--r--drivers/net/cxgb4/cxgb4_main.c33
-rw-r--r--drivers/net/cxgb4/sge.c23
-rw-r--r--drivers/net/e1000/e1000_main.c2
-rw-r--r--drivers/net/ehea/ehea.h2
-rw-r--r--drivers/net/ehea/ehea_main.c42
-rw-r--r--drivers/net/gianfar.c6
-rw-r--r--drivers/net/jme.c45
-rw-r--r--drivers/net/macb.c27
-rw-r--r--drivers/net/mlx4/icm.c28
-rw-r--r--drivers/net/mlx4/icm.h2
-rw-r--r--drivers/net/mlx4/port.c11
-rw-r--r--drivers/net/phy/phy.c13
-rw-r--r--drivers/net/phy/phy_device.c19
-rw-r--r--drivers/net/qlcnic/qlcnic.h7
-rw-r--r--drivers/net/qlcnic/qlcnic_ethtool.c23
-rw-r--r--drivers/net/qlcnic/qlcnic_main.c19
-rw-r--r--drivers/net/qlge/qlge.h12
-rw-r--r--drivers/net/qlge/qlge_main.c24
-rw-r--r--drivers/net/qlge/qlge_mpi.c6
-rw-r--r--drivers/net/sb1000.c6
-rw-r--r--drivers/net/sgiseeq.c2
-rw-r--r--drivers/net/slhc.c15
-rw-r--r--drivers/net/tg3.c10
-rw-r--r--drivers/net/tokenring/tms380tr.c2
-rw-r--r--drivers/net/typhoon.c92
-rw-r--r--drivers/net/vmxnet3/upt1_defs.h8
-rw-r--r--drivers/net/vmxnet3/vmxnet3_defs.h6
-rw-r--r--drivers/net/vmxnet3/vmxnet3_drv.c22
-rw-r--r--drivers/net/vmxnet3/vmxnet3_ethtool.c14
-rw-r--r--drivers/net/vmxnet3/vmxnet3_int.h19
-rw-r--r--drivers/net/vxge/vxge-config.c332
-rw-r--r--drivers/net/vxge/vxge-config.h227
-rw-r--r--drivers/net/vxge/vxge-ethtool.c2
-rw-r--r--drivers/net/vxge/vxge-main.c64
-rw-r--r--drivers/net/vxge/vxge-main.h59
-rw-r--r--drivers/net/vxge/vxge-traffic.c101
-rw-r--r--drivers/net/vxge/vxge-traffic.h134
-rw-r--r--drivers/net/wireless/ath/ath5k/base.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_2p2_initvals.h191
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_paprd.c14
-rw-r--r--drivers/net/wireless/ath/ath9k/beacon.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c7
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c8
-rw-r--r--drivers/net/wireless/ath/carl9170/cmd.h51
-rw-r--r--drivers/net/wireless/ath/carl9170/main.c2
-rw-r--r--drivers/net/wireless/ath/carl9170/usb.c25
-rw-r--r--drivers/net/wireless/b43/phy_n.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-tx.c3
-rw-r--r--drivers/net/wireless/wl1251/Makefile8
-rw-r--r--drivers/pci/proc.c3
-rw-r--r--drivers/platform/x86/intel_pmic_gpio.c1
-rw-r--r--drivers/rapidio/rio-driver.c2
-rw-r--r--drivers/rapidio/rio-scan.c187
-rw-r--r--drivers/rapidio/rio-sysfs.c26
-rw-r--r--drivers/rapidio/rio.c330
-rw-r--r--drivers/rapidio/rio.h5
-rw-r--r--drivers/rapidio/switches/Kconfig7
-rw-r--r--drivers/rapidio/switches/Makefile1
-rw-r--r--drivers/rapidio/switches/idt_gen2.c447
-rw-r--r--drivers/rapidio/switches/idtcps.c10
-rw-r--r--drivers/rapidio/switches/tsi568.c15
-rw-r--r--drivers/rapidio/switches/tsi57x.c7
-rw-r--r--drivers/rtc/Kconfig12
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/class.c4
-rw-r--r--drivers/rtc/rtc-bfin.c43
-rw-r--r--drivers/rtc/rtc-ds3232.c181
-rw-r--r--drivers/rtc/rtc-jz4740.c45
-rw-r--r--drivers/rtc/rtc-lpc32xx.c414
-rw-r--r--drivers/rtc/rtc-omap.c12
-rw-r--r--drivers/rtc/rtc-s3c.c92
-rw-r--r--drivers/video/fbmem.c60
-rw-r--r--drivers/video/gbefb.c6
-rw-r--r--drivers/video/matrox/matroxfb_DAC1064.c5
-rw-r--r--drivers/video/matrox/matroxfb_maven.c2
-rw-r--r--drivers/video/omap/blizzard.c2
-rw-r--r--drivers/video/savage/savagefb-i2c.c9
-rw-r--r--drivers/w1/w1.c8
-rw-r--r--fs/Kconfig1
-rw-r--r--fs/Kconfig.binfmt4
-rw-r--r--fs/eventpoll.c35
-rw-r--r--fs/exec.c168
-rw-r--r--fs/fcntl.c62
-rw-r--r--fs/fuse/dev.c7
-rw-r--r--fs/isofs/inode.c40
-rw-r--r--fs/lockd/svc.c11
-rw-r--r--fs/lockd/svclock.c6
-rw-r--r--fs/lockd/svcsubs.c9
-rw-r--r--fs/locks.c57
-rw-r--r--fs/nfs/Kconfig1
-rw-r--r--fs/nfsd/Kconfig1
-rw-r--r--fs/nfsd/nfs4state.c26
-rw-r--r--fs/proc/base.c8
-rw-r--r--fs/proc/softirqs.c4
-rw-r--r--fs/proc/stat.c14
-rw-r--r--fs/proc/task_mmu.c6
-rw-r--r--fs/select.c6
-rw-r--r--include/asm-generic/cputime.h6
-rw-r--r--include/asm-generic/gpio.h4
-rw-r--r--include/linux/basic_mmio_gpio.h20
-rw-r--r--include/linux/cgroup.h4
-rw-r--r--include/linux/connector.h8
-rw-r--r--include/linux/fb.h6
-rw-r--r--include/linux/fs.h6
-rw-r--r--include/linux/highmem.h51
-rw-r--r--include/linux/i2c/adp5588.h21
-rw-r--r--include/linux/init_task.h4
-rw-r--r--include/linux/interrupt.h2
-rw-r--r--include/linux/kernel_stat.h18
-rw-r--r--include/linux/kfifo.h33
-rw-r--r--include/linux/netdevice.h18
-rw-r--r--include/linux/percpu-defs.h12
-rw-r--r--include/linux/phy.h12
-rw-r--r--include/linux/poll.h2
-rw-r--r--include/linux/ptrace.h12
-rw-r--r--include/linux/ramoops.h15
-rw-r--r--include/linux/ring_buffer.h12
-rw-r--r--include/linux/rio.h17
-rw-r--r--include/linux/rio_ids.h2
-rw-r--r--include/linux/rio_regs.h18
-rw-r--r--include/linux/sched.h16
-rw-r--r--include/linux/spi/74x164.h11
-rw-r--r--include/linux/synclink.h5
-rw-r--r--include/linux/syscalls.h3
-rw-r--r--include/linux/tracehook.h2
-rw-r--r--include/linux/virtio_9p.h1
-rw-r--r--include/net/caif/caif_shm.h26
-rw-r--r--include/net/dst.h2
-rw-r--r--include/net/fib_rules.h2
-rw-r--r--include/net/garp.h2
-rw-r--r--include/net/inetpeer.h2
-rw-r--r--include/net/ip.h4
-rw-r--r--include/net/ip6_tunnel.h2
-rw-r--r--include/net/ipip.h6
-rw-r--r--include/net/net_namespace.h2
-rw-r--r--include/net/protocol.h4
-rw-r--r--include/net/sock.h2
-rw-r--r--include/net/xfrm.h4
-rw-r--r--include/trace/events/irq.h54
-rw-r--r--init/Kconfig117
-rw-r--r--ipc/compat.c6
-rw-r--r--ipc/compat_mq.c5
-rw-r--r--ipc/shm.c63
-rw-r--r--kernel/cgroup.c129
-rw-r--r--kernel/cgroup_freezer.c72
-rw-r--r--kernel/cred.c4
-rw-r--r--kernel/exit.c2
-rw-r--r--kernel/fork.c2
-rw-r--r--kernel/irq/irqdesc.c15
-rw-r--r--kernel/kprobes.c7
-rw-r--r--kernel/module.c2
-rw-r--r--kernel/ns_cgroup.c8
-rw-r--r--kernel/perf_event.c94
-rw-r--r--kernel/ptrace.c36
-rw-r--r--kernel/resource.c2
-rw-r--r--kernel/signal.c5
-rw-r--r--kernel/softirq.c16
-rw-r--r--kernel/taskstats.c172
-rw-r--r--kernel/trace/ring_buffer.c335
-rw-r--r--kernel/trace/trace.c8
-rw-r--r--kernel/trace/trace_kprobe.c1
-rw-r--r--kernel/tsacct.c10
-rw-r--r--mm/highmem.c6
-rw-r--r--mm/memcontrol.c406
-rw-r--r--mm/swap.c1
-rw-r--r--net/802/garp.c18
-rw-r--r--net/802/stp.c4
-rw-r--r--net/8021q/vlan.c6
-rw-r--r--net/core/dev.c38
-rw-r--r--net/core/fib_rules.c21
-rw-r--r--net/core/filter.c4
-rw-r--r--net/core/net-sysfs.c20
-rw-r--r--net/core/net_namespace.c4
-rw-r--r--net/core/pktgen.c30
-rw-r--r--net/core/sock.c2
-rw-r--r--net/core/sysctl_net_core.c3
-rw-r--r--net/ipv4/fib_hash.c36
-rw-r--r--net/ipv4/gre.c5
-rw-r--r--net/ipv4/inetpeer.c138
-rw-r--r--net/ipv4/ip_gre.c1
-rw-r--r--net/ipv4/ip_sockglue.c10
-rw-r--r--net/ipv4/ipip.c1
-rw-r--r--net/ipv4/protocol.c8
-rw-r--r--net/ipv4/route.c75
-rw-r--r--net/ipv4/tunnel4.c29
-rw-r--r--net/ipv4/udp.c2
-rw-r--r--net/ipv6/addrconf.c16
-rw-r--r--net/ipv6/ip6_tunnel.c2
-rw-r--r--net/ipv6/ipv6_sockglue.c4
-rw-r--r--net/ipv6/netfilter/Kconfig5
-rw-r--r--net/ipv6/netfilter/Makefile5
-rw-r--r--net/ipv6/netfilter/nf_conntrack_reasm.c5
-rw-r--r--net/ipv6/protocol.c8
-rw-r--r--net/ipv6/raw.c2
-rw-r--r--net/ipv6/sit.c1
-rw-r--r--net/ipv6/tunnel6.c24
-rw-r--r--net/ipv6/udp.c2
-rw-r--r--net/l2tp/l2tp_core.c53
-rw-r--r--net/l2tp/l2tp_core.h33
-rw-r--r--net/l2tp/l2tp_ip.c2
-rw-r--r--net/mac80211/ibss.c1
-rw-r--r--net/mac80211/main.c8
-rw-r--r--net/mac80211/rate.c3
-rw-r--r--net/netfilter/Kconfig2
-rw-r--r--net/netfilter/xt_TPROXY.c10
-rw-r--r--net/netfilter/xt_socket.c12
-rw-r--r--net/netlink/af_netlink.c65
-rw-r--r--net/wireless/reg.c2
-rw-r--r--sound/oss/sb_ess.c1
-rw-r--r--sound/pci/hda/patch_sigmatel.c78
-rw-r--r--sound/soc/codecs/ad73311.c2
-rw-r--r--sound/soc/codecs/max98088.c2
-rw-r--r--sound/soc/codecs/wm9090.c2
-rw-r--r--sound/soc/fsl/pcm030-audio-fabric.c3
-rw-r--r--sound/usb/card.h2
-rw-r--r--sound/usb/pcm.c2
-rw-r--r--sound/usb/proc.c5
-rw-r--r--sound/usb/urb.c170
-rw-r--r--tools/perf/Documentation/perf-list.txt17
-rw-r--r--tools/perf/Documentation/perf-probe.txt18
-rw-r--r--tools/perf/Documentation/perf-record.txt4
-rw-r--r--tools/perf/builtin-probe.c78
-rw-r--r--tools/perf/builtin-record.c8
-rw-r--r--tools/perf/builtin-trace.c17
-rw-r--r--tools/perf/scripts/perl/bin/failed-syscalls-report2
-rw-r--r--tools/perf/scripts/perl/bin/rw-by-file-report2
-rw-r--r--tools/perf/scripts/perl/bin/rw-by-pid-report2
-rw-r--r--tools/perf/scripts/perl/bin/rwtop-report2
-rw-r--r--tools/perf/scripts/perl/bin/wakeup-latency-report2
-rw-r--r--tools/perf/scripts/perl/bin/workqueue-stats-report2
-rw-r--r--tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py58
-rw-r--r--tools/perf/scripts/python/bin/failed-syscalls-by-pid-report2
-rw-r--r--tools/perf/scripts/python/bin/futex-contention-record2
-rw-r--r--tools/perf/scripts/python/bin/futex-contention-report4
-rw-r--r--tools/perf/scripts/python/bin/netdev-times-report2
-rw-r--r--tools/perf/scripts/python/bin/sched-migration-report2
-rw-r--r--tools/perf/scripts/python/bin/sctop-report2
-rw-r--r--tools/perf/scripts/python/bin/syscall-counts-by-pid-report2
-rw-r--r--tools/perf/scripts/python/bin/syscall-counts-report2
-rw-r--r--tools/perf/scripts/python/failed-syscalls-by-pid.py21
-rw-r--r--tools/perf/scripts/python/futex-contention.py50
-rw-r--r--tools/perf/scripts/python/sctop.py9
-rw-r--r--tools/perf/scripts/python/syscall-counts-by-pid.py21
-rw-r--r--tools/perf/scripts/python/syscall-counts.py5
-rw-r--r--tools/perf/util/debug.c4
-rw-r--r--tools/perf/util/debug.h2
-rw-r--r--tools/perf/util/map.h10
-rw-r--r--tools/perf/util/probe-event.c189
-rw-r--r--tools/perf/util/probe-event.h16
-rw-r--r--tools/perf/util/probe-finder.c645
-rw-r--r--tools/perf/util/probe-finder.h31
-rw-r--r--tools/perf/util/ui/browser.c1
393 files changed, 10563 insertions, 4019 deletions
diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c
index 6e25c2659e0a..a2976a6de033 100644
--- a/Documentation/accounting/getdelays.c
+++ b/Documentation/accounting/getdelays.c
@@ -21,6 +21,7 @@
21#include <sys/types.h> 21#include <sys/types.h>
22#include <sys/stat.h> 22#include <sys/stat.h>
23#include <sys/socket.h> 23#include <sys/socket.h>
24#include <sys/wait.h>
24#include <signal.h> 25#include <signal.h>
25 26
26#include <linux/genetlink.h> 27#include <linux/genetlink.h>
@@ -266,11 +267,13 @@ int main(int argc, char *argv[])
266 int containerset = 0; 267 int containerset = 0;
267 char containerpath[1024]; 268 char containerpath[1024];
268 int cfd = 0; 269 int cfd = 0;
270 int forking = 0;
271 sigset_t sigset;
269 272
270 struct msgtemplate msg; 273 struct msgtemplate msg;
271 274
272 while (1) { 275 while (!forking) {
273 c = getopt(argc, argv, "qdiw:r:m:t:p:vlC:"); 276 c = getopt(argc, argv, "qdiw:r:m:t:p:vlC:c:");
274 if (c < 0) 277 if (c < 0)
275 break; 278 break;
276 279
@@ -319,6 +322,28 @@ int main(int argc, char *argv[])
319 err(1, "Invalid pid\n"); 322 err(1, "Invalid pid\n");
320 cmd_type = TASKSTATS_CMD_ATTR_PID; 323 cmd_type = TASKSTATS_CMD_ATTR_PID;
321 break; 324 break;
325 case 'c':
326
327 /* Block SIGCHLD for sigwait() later */
328 if (sigemptyset(&sigset) == -1)
329 err(1, "Failed to empty sigset");
330 if (sigaddset(&sigset, SIGCHLD))
331 err(1, "Failed to set sigchld in sigset");
332 sigprocmask(SIG_BLOCK, &sigset, NULL);
333
334 /* fork/exec a child */
335 tid = fork();
336 if (tid < 0)
337 err(1, "Fork failed\n");
338 if (tid == 0)
339 if (execvp(argv[optind - 1],
340 &argv[optind - 1]) < 0)
341 exit(-1);
342
343 /* Set the command type and avoid further processing */
344 cmd_type = TASKSTATS_CMD_ATTR_PID;
345 forking = 1;
346 break;
322 case 'v': 347 case 'v':
323 printf("debug on\n"); 348 printf("debug on\n");
324 dbg = 1; 349 dbg = 1;
@@ -370,6 +395,15 @@ int main(int argc, char *argv[])
370 goto err; 395 goto err;
371 } 396 }
372 397
398 /*
399 * If we forked a child, wait for it to exit. Cannot use waitpid()
400 * as all the delicious data would be reaped as part of the wait
401 */
402 if (tid && forking) {
403 int sig_received;
404 sigwait(&sigset, &sig_received);
405 }
406
373 if (tid) { 407 if (tid) {
374 rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET, 408 rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
375 cmd_type, &tid, sizeof(__u32)); 409 cmd_type, &tid, sizeof(__u32));
diff --git a/Documentation/cgroups/cgroups.txt b/Documentation/cgroups/cgroups.txt
index b34823ff1646..190018b0c649 100644
--- a/Documentation/cgroups/cgroups.txt
+++ b/Documentation/cgroups/cgroups.txt
@@ -18,7 +18,8 @@ CONTENTS:
18 1.2 Why are cgroups needed ? 18 1.2 Why are cgroups needed ?
19 1.3 How are cgroups implemented ? 19 1.3 How are cgroups implemented ?
20 1.4 What does notify_on_release do ? 20 1.4 What does notify_on_release do ?
21 1.5 How do I use cgroups ? 21 1.5 What does clone_children do ?
22 1.6 How do I use cgroups ?
222. Usage Examples and Syntax 232. Usage Examples and Syntax
23 2.1 Basic Usage 24 2.1 Basic Usage
24 2.2 Attaching processes 25 2.2 Attaching processes
@@ -293,7 +294,16 @@ notify_on_release in the root cgroup at system boot is disabled
293value of their parents notify_on_release setting. The default value of 294value of their parents notify_on_release setting. The default value of
294a cgroup hierarchy's release_agent path is empty. 295a cgroup hierarchy's release_agent path is empty.
295 296
2961.5 How do I use cgroups ? 2971.5 What does clone_children do ?
298---------------------------------
299
300If the clone_children flag is enabled (1) in a cgroup, then all
301cgroups created beneath will call the post_clone callbacks for each
302subsystem of the newly created cgroup. Usually when this callback is
303implemented for a subsystem, it copies the values of the parent
304subsystem, this is the case for the cpuset.
305
3061.6 How do I use cgroups ?
297-------------------------- 307--------------------------
298 308
299To start a new job that is to be contained within a cgroup, using 309To start a new job that is to be contained within a cgroup, using
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index d2af87ba96e1..f3da8c0a3af2 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -526,6 +526,23 @@ Who: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
526 526
527---------------------------- 527----------------------------
528 528
529What: namespace cgroup (ns_cgroup)
530When: 2.6.38
531Why: The ns_cgroup leads to some problems:
532 * cgroup creation is out-of-control
533 * cgroup name can conflict when pids are looping
534 * it is not possible to have a single process handling
535 a lot of namespaces without falling in a exponential creation time
536 * we may want to create a namespace without creating a cgroup
537
538 The ns_cgroup is replaced by a compatibility flag 'clone_children',
539 where a newly created cgroup will copy the parent cgroup values.
540 The userspace has to manually create a cgroup and add a task to
541 the 'tasks' file.
542Who: Daniel Lezcano <daniel.lezcano@free.fr>
543
544----------------------------
545
529What: iwlwifi disable_hw_scan module parameters 546What: iwlwifi disable_hw_scan module parameters
530When: 2.6.40 547When: 2.6.40
531Why: Hareware scan is the prefer method for iwlwifi devices for 548Why: Hareware scan is the prefer method for iwlwifi devices for
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index a563b74c7aef..e73df2722ff3 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -136,6 +136,7 @@ Table 1-1: Process specific entries in /proc
136 statm Process memory status information 136 statm Process memory status information
137 status Process status in human readable form 137 status Process status in human readable form
138 wchan If CONFIG_KALLSYMS is set, a pre-decoded wchan 138 wchan If CONFIG_KALLSYMS is set, a pre-decoded wchan
139 pagemap Page table
139 stack Report full stack trace, enable via CONFIG_STACKTRACE 140 stack Report full stack trace, enable via CONFIG_STACKTRACE
140 smaps a extension based on maps, showing the memory consumption of 141 smaps a extension based on maps, showing the memory consumption of
141 each mapping 142 each mapping
@@ -370,6 +371,7 @@ Shared_Dirty: 0 kB
370Private_Clean: 0 kB 371Private_Clean: 0 kB
371Private_Dirty: 0 kB 372Private_Dirty: 0 kB
372Referenced: 892 kB 373Referenced: 892 kB
374Anonymous: 0 kB
373Swap: 0 kB 375Swap: 0 kB
374KernelPageSize: 4 kB 376KernelPageSize: 4 kB
375MMUPageSize: 4 kB 377MMUPageSize: 4 kB
@@ -378,9 +380,15 @@ The first of these lines shows the same information as is displayed for the
378mapping in /proc/PID/maps. The remaining lines show the size of the mapping 380mapping in /proc/PID/maps. The remaining lines show the size of the mapping
379(size), the amount of the mapping that is currently resident in RAM (RSS), the 381(size), the amount of the mapping that is currently resident in RAM (RSS), the
380process' proportional share of this mapping (PSS), the number of clean and 382process' proportional share of this mapping (PSS), the number of clean and
381dirty shared pages in the mapping, and the number of clean and dirty private 383dirty private pages in the mapping. Note that even a page which is part of a
382pages in the mapping. The "Referenced" indicates the amount of memory 384MAP_SHARED mapping, but has only a single pte mapped, i.e. is currently used
383currently marked as referenced or accessed. 385by only one process, is accounted as private and not as shared. "Referenced"
386indicates the amount of memory currently marked as referenced or accessed.
387"Anonymous" shows the amount of memory that does not belong to any file. Even
388a mapping associated with a file may contain anonymous pages: when MAP_PRIVATE
389and a page is modified, the file page is replaced by a private anonymous copy.
390"Swap" shows how much would-be-anonymous memory is also used, but out on
391swap.
384 392
385This file is only present if the CONFIG_MMU kernel configuration option is 393This file is only present if the CONFIG_MMU kernel configuration option is
386enabled. 394enabled.
@@ -397,6 +405,9 @@ To clear the bits for the file mapped pages associated with the process
397 > echo 3 > /proc/PID/clear_refs 405 > echo 3 > /proc/PID/clear_refs
398Any other value written to /proc/PID/clear_refs will have no effect. 406Any other value written to /proc/PID/clear_refs will have no effect.
399 407
408The /proc/pid/pagemap gives the PFN, which can be used to find the pageflags
409using /proc/kpageflags and number of times a page is mapped using
410/proc/kpagecount. For detailed explanation, see Documentation/vm/pagemap.txt.
400 411
4011.2 Kernel data 4121.2 Kernel data
402--------------- 413---------------
diff --git a/Documentation/networking/phy.txt b/Documentation/networking/phy.txt
index 88bb71b46da4..9eb1ba52013d 100644
--- a/Documentation/networking/phy.txt
+++ b/Documentation/networking/phy.txt
@@ -177,18 +177,6 @@ Doing it all yourself
177 177
178 A convenience function to print out the PHY status neatly. 178 A convenience function to print out the PHY status neatly.
179 179
180 int phy_clear_interrupt(struct phy_device *phydev);
181 int phy_config_interrupt(struct phy_device *phydev, u32 interrupts);
182
183 Clear the PHY's interrupt, and configure which ones are allowed,
184 respectively. Currently only supports all on, or all off.
185
186 int phy_enable_interrupts(struct phy_device *phydev);
187 int phy_disable_interrupts(struct phy_device *phydev);
188
189 Functions which enable/disable PHY interrupts, clearing them
190 before and after, respectively.
191
192 int phy_start_interrupts(struct phy_device *phydev); 180 int phy_start_interrupts(struct phy_device *phydev);
193 int phy_stop_interrupts(struct phy_device *phydev); 181 int phy_stop_interrupts(struct phy_device *phydev);
194 182
@@ -213,12 +201,6 @@ Doing it all yourself
213 Fills the phydev structure with up-to-date information about the current 201 Fills the phydev structure with up-to-date information about the current
214 settings in the PHY. 202 settings in the PHY.
215 203
216 void phy_sanitize_settings(struct phy_device *phydev)
217
218 Resolves differences between currently desired settings, and
219 supported settings for the given PHY device. Does not make
220 the changes in the hardware, though.
221
222 int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd); 204 int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd);
223 int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd); 205 int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd);
224 206
diff --git a/Documentation/sysctl/vm.txt b/Documentation/sysctl/vm.txt
index b606c2c4dd37..30289fab86eb 100644
--- a/Documentation/sysctl/vm.txt
+++ b/Documentation/sysctl/vm.txt
@@ -80,8 +80,10 @@ dirty_background_bytes
80Contains the amount of dirty memory at which the pdflush background writeback 80Contains the amount of dirty memory at which the pdflush background writeback
81daemon will start writeback. 81daemon will start writeback.
82 82
83If dirty_background_bytes is written, dirty_background_ratio becomes a function 83Note: dirty_background_bytes is the counterpart of dirty_background_ratio. Only
84of its value (dirty_background_bytes / the amount of dirtyable system memory). 84one of them may be specified at a time. When one sysctl is written it is
85immediately taken into account to evaluate the dirty memory limits and the
86other appears as 0 when read.
85 87
86============================================================== 88==============================================================
87 89
@@ -97,8 +99,10 @@ dirty_bytes
97Contains the amount of dirty memory at which a process generating disk writes 99Contains the amount of dirty memory at which a process generating disk writes
98will itself start writeback. 100will itself start writeback.
99 101
100If dirty_bytes is written, dirty_ratio becomes a function of its value 102Note: dirty_bytes is the counterpart of dirty_ratio. Only one of them may be
101(dirty_bytes / the amount of dirtyable system memory). 103specified at a time. When one sysctl is written it is immediately taken into
104account to evaluate the dirty memory limits and the other appears as 0 when
105read.
102 106
103Note: the minimum value allowed for dirty_bytes is two pages (in bytes); any 107Note: the minimum value allowed for dirty_bytes is two pages (in bytes); any
104value lower than this limit will be ignored and the old configuration will be 108value lower than this limit will be ignored and the old configuration will be
diff --git a/arch/alpha/kernel/pci_iommu.c b/arch/alpha/kernel/pci_iommu.c
index d1dbd9acd1df..022c2748fa41 100644
--- a/arch/alpha/kernel/pci_iommu.c
+++ b/arch/alpha/kernel/pci_iommu.c
@@ -223,7 +223,7 @@ iommu_arena_free(struct pci_iommu_arena *arena, long ofs, long n)
223 */ 223 */
224static int pci_dac_dma_supported(struct pci_dev *dev, u64 mask) 224static int pci_dac_dma_supported(struct pci_dev *dev, u64 mask)
225{ 225{
226 dma64_addr_t dac_offset = alpha_mv.pci_dac_offset; 226 dma_addr_t dac_offset = alpha_mv.pci_dac_offset;
227 int ok = 1; 227 int ok = 1;
228 228
229 /* If this is not set, the machine doesn't support DAC at all. */ 229 /* If this is not set, the machine doesn't support DAC at all. */
@@ -756,7 +756,7 @@ static void alpha_pci_unmap_sg(struct device *dev, struct scatterlist *sg,
756 spin_lock_irqsave(&arena->lock, flags); 756 spin_lock_irqsave(&arena->lock, flags);
757 757
758 for (end = sg + nents; sg < end; ++sg) { 758 for (end = sg + nents; sg < end; ++sg) {
759 dma64_addr_t addr; 759 dma_addr_t addr;
760 size_t size; 760 size_t size;
761 long npages, ofs; 761 long npages, ofs;
762 dma_addr_t tend; 762 dma_addr_t tend;
diff --git a/arch/alpha/kernel/ptrace.c b/arch/alpha/kernel/ptrace.c
index baa903602f6a..e2af5eb59bb4 100644
--- a/arch/alpha/kernel/ptrace.c
+++ b/arch/alpha/kernel/ptrace.c
@@ -269,7 +269,8 @@ void ptrace_disable(struct task_struct *child)
269 user_disable_single_step(child); 269 user_disable_single_step(child);
270} 270}
271 271
272long arch_ptrace(struct task_struct *child, long request, long addr, long data) 272long arch_ptrace(struct task_struct *child, long request,
273 unsigned long addr, unsigned long data)
273{ 274{
274 unsigned long tmp; 275 unsigned long tmp;
275 size_t copied; 276 size_t copied;
@@ -292,7 +293,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
292 case PTRACE_PEEKUSR: 293 case PTRACE_PEEKUSR:
293 force_successful_syscall_return(); 294 force_successful_syscall_return();
294 ret = get_reg(child, addr); 295 ret = get_reg(child, addr);
295 DBG(DBG_MEM, ("peek $%ld->%#lx\n", addr, ret)); 296 DBG(DBG_MEM, ("peek $%lu->%#lx\n", addr, ret));
296 break; 297 break;
297 298
298 /* When I and D space are separate, this will have to be fixed. */ 299 /* When I and D space are separate, this will have to be fixed. */
@@ -302,7 +303,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
302 break; 303 break;
303 304
304 case PTRACE_POKEUSR: /* write the specified register */ 305 case PTRACE_POKEUSR: /* write the specified register */
305 DBG(DBG_MEM, ("poke $%ld<-%#lx\n", addr, data)); 306 DBG(DBG_MEM, ("poke $%lu<-%#lx\n", addr, data));
306 ret = put_reg(child, addr, data); 307 ret = put_reg(child, addr, data);
307 break; 308 break;
308 default: 309 default:
diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index e0cb6370ed14..3e97483abcf0 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -1075,13 +1075,15 @@ out:
1075} 1075}
1076#endif 1076#endif
1077 1077
1078long arch_ptrace(struct task_struct *child, long request, long addr, long data) 1078long arch_ptrace(struct task_struct *child, long request,
1079 unsigned long addr, unsigned long data)
1079{ 1080{
1080 int ret; 1081 int ret;
1082 unsigned long __user *datap = (unsigned long __user *) data;
1081 1083
1082 switch (request) { 1084 switch (request) {
1083 case PTRACE_PEEKUSR: 1085 case PTRACE_PEEKUSR:
1084 ret = ptrace_read_user(child, addr, (unsigned long __user *)data); 1086 ret = ptrace_read_user(child, addr, datap);
1085 break; 1087 break;
1086 1088
1087 case PTRACE_POKEUSR: 1089 case PTRACE_POKEUSR:
@@ -1089,34 +1091,34 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1089 break; 1091 break;
1090 1092
1091 case PTRACE_GETREGS: 1093 case PTRACE_GETREGS:
1092 ret = ptrace_getregs(child, (void __user *)data); 1094 ret = ptrace_getregs(child, datap);
1093 break; 1095 break;
1094 1096
1095 case PTRACE_SETREGS: 1097 case PTRACE_SETREGS:
1096 ret = ptrace_setregs(child, (void __user *)data); 1098 ret = ptrace_setregs(child, datap);
1097 break; 1099 break;
1098 1100
1099 case PTRACE_GETFPREGS: 1101 case PTRACE_GETFPREGS:
1100 ret = ptrace_getfpregs(child, (void __user *)data); 1102 ret = ptrace_getfpregs(child, datap);
1101 break; 1103 break;
1102 1104
1103 case PTRACE_SETFPREGS: 1105 case PTRACE_SETFPREGS:
1104 ret = ptrace_setfpregs(child, (void __user *)data); 1106 ret = ptrace_setfpregs(child, datap);
1105 break; 1107 break;
1106 1108
1107#ifdef CONFIG_IWMMXT 1109#ifdef CONFIG_IWMMXT
1108 case PTRACE_GETWMMXREGS: 1110 case PTRACE_GETWMMXREGS:
1109 ret = ptrace_getwmmxregs(child, (void __user *)data); 1111 ret = ptrace_getwmmxregs(child, datap);
1110 break; 1112 break;
1111 1113
1112 case PTRACE_SETWMMXREGS: 1114 case PTRACE_SETWMMXREGS:
1113 ret = ptrace_setwmmxregs(child, (void __user *)data); 1115 ret = ptrace_setwmmxregs(child, datap);
1114 break; 1116 break;
1115#endif 1117#endif
1116 1118
1117 case PTRACE_GET_THREAD_AREA: 1119 case PTRACE_GET_THREAD_AREA:
1118 ret = put_user(task_thread_info(child)->tp_value, 1120 ret = put_user(task_thread_info(child)->tp_value,
1119 (unsigned long __user *) data); 1121 datap);
1120 break; 1122 break;
1121 1123
1122 case PTRACE_SET_SYSCALL: 1124 case PTRACE_SET_SYSCALL:
@@ -1126,21 +1128,21 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1126 1128
1127#ifdef CONFIG_CRUNCH 1129#ifdef CONFIG_CRUNCH
1128 case PTRACE_GETCRUNCHREGS: 1130 case PTRACE_GETCRUNCHREGS:
1129 ret = ptrace_getcrunchregs(child, (void __user *)data); 1131 ret = ptrace_getcrunchregs(child, datap);
1130 break; 1132 break;
1131 1133
1132 case PTRACE_SETCRUNCHREGS: 1134 case PTRACE_SETCRUNCHREGS:
1133 ret = ptrace_setcrunchregs(child, (void __user *)data); 1135 ret = ptrace_setcrunchregs(child, datap);
1134 break; 1136 break;
1135#endif 1137#endif
1136 1138
1137#ifdef CONFIG_VFP 1139#ifdef CONFIG_VFP
1138 case PTRACE_GETVFPREGS: 1140 case PTRACE_GETVFPREGS:
1139 ret = ptrace_getvfpregs(child, (void __user *)data); 1141 ret = ptrace_getvfpregs(child, datap);
1140 break; 1142 break;
1141 1143
1142 case PTRACE_SETVFPREGS: 1144 case PTRACE_SETVFPREGS:
1143 ret = ptrace_setvfpregs(child, (void __user *)data); 1145 ret = ptrace_setvfpregs(child, datap);
1144 break; 1146 break;
1145#endif 1147#endif
1146 1148
diff --git a/arch/arm/mach-tegra/timer.c b/arch/arm/mach-tegra/timer.c
index 2f420210d406..9057d6fd1d31 100644
--- a/arch/arm/mach-tegra/timer.c
+++ b/arch/arm/mach-tegra/timer.c
@@ -28,7 +28,6 @@
28#include <linux/cnt32_to_63.h> 28#include <linux/cnt32_to_63.h>
29 29
30#include <asm/mach/time.h> 30#include <asm/mach/time.h>
31#include <asm/mach/time.h>
32#include <asm/localtimer.h> 31#include <asm/localtimer.h>
33 32
34#include <mach/iomap.h> 33#include <mach/iomap.h>
diff --git a/arch/arm/mm/highmem.c b/arch/arm/mm/highmem.c
index c00f119babbf..c435fd9e1da9 100644
--- a/arch/arm/mm/highmem.c
+++ b/arch/arm/mm/highmem.c
@@ -89,7 +89,7 @@ void __kunmap_atomic(void *kvaddr)
89 int idx, type; 89 int idx, type;
90 90
91 if (kvaddr >= (void *)FIXADDR_START) { 91 if (kvaddr >= (void *)FIXADDR_START) {
92 type = kmap_atomic_idx_pop(); 92 type = kmap_atomic_idx();
93 idx = type + KM_TYPE_NR * smp_processor_id(); 93 idx = type + KM_TYPE_NR * smp_processor_id();
94 94
95 if (cache_is_vivt()) 95 if (cache_is_vivt())
@@ -101,6 +101,7 @@ void __kunmap_atomic(void *kvaddr)
101#else 101#else
102 (void) idx; /* to kill a warning */ 102 (void) idx; /* to kill a warning */
103#endif 103#endif
104 kmap_atomic_idx_pop();
104 } else if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) { 105 } else if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
105 /* this address was obtained through kmap_high_get() */ 106 /* this address was obtained through kmap_high_get() */
106 kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)])); 107 kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
diff --git a/arch/arm/plat-nomadik/include/plat/ste_dma40.h b/arch/arm/plat-nomadik/include/plat/ste_dma40.h
index 5fbde4b8dc12..93a812672d9a 100644
--- a/arch/arm/plat-nomadik/include/plat/ste_dma40.h
+++ b/arch/arm/plat-nomadik/include/plat/ste_dma40.h
@@ -14,7 +14,6 @@
14#include <linux/dmaengine.h> 14#include <linux/dmaengine.h>
15#include <linux/workqueue.h> 15#include <linux/workqueue.h>
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/dmaengine.h>
18 17
19/* dev types for memcpy */ 18/* dev types for memcpy */
20#define STEDMA40_DEV_DST_MEMORY (-1) 19#define STEDMA40_DEV_DST_MEMORY (-1)
diff --git a/arch/avr32/kernel/ptrace.c b/arch/avr32/kernel/ptrace.c
index 5e73c25f8f85..4aedcab7cd4b 100644
--- a/arch/avr32/kernel/ptrace.c
+++ b/arch/avr32/kernel/ptrace.c
@@ -146,9 +146,11 @@ static int ptrace_setregs(struct task_struct *tsk, const void __user *uregs)
146 return ret; 146 return ret;
147} 147}
148 148
149long arch_ptrace(struct task_struct *child, long request, long addr, long data) 149long arch_ptrace(struct task_struct *child, long request,
150 unsigned long addr, unsigned long data)
150{ 151{
151 int ret; 152 int ret;
153 void __user *datap = (void __user *) data;
152 154
153 switch (request) { 155 switch (request) {
154 /* Read the word at location addr in the child process */ 156 /* Read the word at location addr in the child process */
@@ -158,8 +160,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
158 break; 160 break;
159 161
160 case PTRACE_PEEKUSR: 162 case PTRACE_PEEKUSR:
161 ret = ptrace_read_user(child, addr, 163 ret = ptrace_read_user(child, addr, datap);
162 (unsigned long __user *)data);
163 break; 164 break;
164 165
165 /* Write the word in data at location addr */ 166 /* Write the word in data at location addr */
@@ -173,11 +174,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
173 break; 174 break;
174 175
175 case PTRACE_GETREGS: 176 case PTRACE_GETREGS:
176 ret = ptrace_getregs(child, (void __user *)data); 177 ret = ptrace_getregs(child, datap);
177 break; 178 break;
178 179
179 case PTRACE_SETREGS: 180 case PTRACE_SETREGS:
180 ret = ptrace_setregs(child, (const void __user *)data); 181 ret = ptrace_setregs(child, datap);
181 break; 182 break;
182 183
183 default: 184 default:
diff --git a/arch/blackfin/kernel/ptrace.c b/arch/blackfin/kernel/ptrace.c
index b35839354130..75089f80855d 100644
--- a/arch/blackfin/kernel/ptrace.c
+++ b/arch/blackfin/kernel/ptrace.c
@@ -38,12 +38,13 @@
38 * Get contents of register REGNO in task TASK. 38 * Get contents of register REGNO in task TASK.
39 */ 39 */
40static inline long 40static inline long
41get_reg(struct task_struct *task, long regno, unsigned long __user *datap) 41get_reg(struct task_struct *task, unsigned long regno,
42 unsigned long __user *datap)
42{ 43{
43 long tmp; 44 long tmp;
44 struct pt_regs *regs = task_pt_regs(task); 45 struct pt_regs *regs = task_pt_regs(task);
45 46
46 if (regno & 3 || regno > PT_LAST_PSEUDO || regno < 0) 47 if (regno & 3 || regno > PT_LAST_PSEUDO)
47 return -EIO; 48 return -EIO;
48 49
49 switch (regno) { 50 switch (regno) {
@@ -74,11 +75,11 @@ get_reg(struct task_struct *task, long regno, unsigned long __user *datap)
74 * Write contents of register REGNO in task TASK. 75 * Write contents of register REGNO in task TASK.
75 */ 76 */
76static inline int 77static inline int
77put_reg(struct task_struct *task, long regno, unsigned long data) 78put_reg(struct task_struct *task, unsigned long regno, unsigned long data)
78{ 79{
79 struct pt_regs *regs = task_pt_regs(task); 80 struct pt_regs *regs = task_pt_regs(task);
80 81
81 if (regno & 3 || regno > PT_LAST_PSEUDO || regno < 0) 82 if (regno & 3 || regno > PT_LAST_PSEUDO)
82 return -EIO; 83 return -EIO;
83 84
84 switch (regno) { 85 switch (regno) {
@@ -240,7 +241,8 @@ void user_disable_single_step(struct task_struct *child)
240 clear_tsk_thread_flag(child, TIF_SINGLESTEP); 241 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
241} 242}
242 243
243long arch_ptrace(struct task_struct *child, long request, long addr, long data) 244long arch_ptrace(struct task_struct *child, long request,
245 unsigned long addr, unsigned long data)
244{ 246{
245 int ret; 247 int ret;
246 unsigned long __user *datap = (unsigned long __user *)data; 248 unsigned long __user *datap = (unsigned long __user *)data;
@@ -368,14 +370,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
368 return copy_regset_to_user(child, &user_bfin_native_view, 370 return copy_regset_to_user(child, &user_bfin_native_view,
369 REGSET_GENERAL, 371 REGSET_GENERAL,
370 0, sizeof(struct pt_regs), 372 0, sizeof(struct pt_regs),
371 (void __user *)data); 373 datap);
372 374
373 case PTRACE_SETREGS: 375 case PTRACE_SETREGS:
374 pr_debug("ptrace: PTRACE_SETREGS\n"); 376 pr_debug("ptrace: PTRACE_SETREGS\n");
375 return copy_regset_from_user(child, &user_bfin_native_view, 377 return copy_regset_from_user(child, &user_bfin_native_view,
376 REGSET_GENERAL, 378 REGSET_GENERAL,
377 0, sizeof(struct pt_regs), 379 0, sizeof(struct pt_regs),
378 (const void __user *)data); 380 datap);
379 381
380 case_default: 382 case_default:
381 default: 383 default:
diff --git a/arch/cris/arch-v10/kernel/ptrace.c b/arch/cris/arch-v10/kernel/ptrace.c
index e70c804e9377..320065f3cbe5 100644
--- a/arch/cris/arch-v10/kernel/ptrace.c
+++ b/arch/cris/arch-v10/kernel/ptrace.c
@@ -76,9 +76,11 @@ ptrace_disable(struct task_struct *child)
76 * (in user space) where the result of the ptrace call is written (instead of 76 * (in user space) where the result of the ptrace call is written (instead of
77 * being returned). 77 * being returned).
78 */ 78 */
79long arch_ptrace(struct task_struct *child, long request, long addr, long data) 79long arch_ptrace(struct task_struct *child, long request,
80 unsigned long addr, unsigned long data)
80{ 81{
81 int ret; 82 int ret;
83 unsigned int regno = addr >> 2;
82 unsigned long __user *datap = (unsigned long __user *)data; 84 unsigned long __user *datap = (unsigned long __user *)data;
83 85
84 switch (request) { 86 switch (request) {
@@ -93,10 +95,10 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
93 unsigned long tmp; 95 unsigned long tmp;
94 96
95 ret = -EIO; 97 ret = -EIO;
96 if ((addr & 3) || addr < 0 || addr > PT_MAX << 2) 98 if ((addr & 3) || regno > PT_MAX)
97 break; 99 break;
98 100
99 tmp = get_reg(child, addr >> 2); 101 tmp = get_reg(child, regno);
100 ret = put_user(tmp, datap); 102 ret = put_user(tmp, datap);
101 break; 103 break;
102 } 104 }
@@ -110,19 +112,17 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
110 /* Write the word at location address in the USER area. */ 112 /* Write the word at location address in the USER area. */
111 case PTRACE_POKEUSR: 113 case PTRACE_POKEUSR:
112 ret = -EIO; 114 ret = -EIO;
113 if ((addr & 3) || addr < 0 || addr > PT_MAX << 2) 115 if ((addr & 3) || regno > PT_MAX)
114 break; 116 break;
115 117
116 addr >>= 2; 118 if (regno == PT_DCCR) {
117
118 if (addr == PT_DCCR) {
119 /* don't allow the tracing process to change stuff like 119 /* don't allow the tracing process to change stuff like
120 * interrupt enable, kernel/user bit, dma enables etc. 120 * interrupt enable, kernel/user bit, dma enables etc.
121 */ 121 */
122 data &= DCCR_MASK; 122 data &= DCCR_MASK;
123 data |= get_reg(child, PT_DCCR) & ~DCCR_MASK; 123 data |= get_reg(child, PT_DCCR) & ~DCCR_MASK;
124 } 124 }
125 if (put_reg(child, addr, data)) 125 if (put_reg(child, regno, data))
126 break; 126 break;
127 ret = 0; 127 ret = 0;
128 break; 128 break;
@@ -141,7 +141,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
141 break; 141 break;
142 } 142 }
143 143
144 data += sizeof(long); 144 datap++;
145 } 145 }
146 146
147 break; 147 break;
@@ -165,7 +165,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
165 } 165 }
166 166
167 put_reg(child, i, tmp); 167 put_reg(child, i, tmp);
168 data += sizeof(long); 168 datap++;
169 } 169 }
170 170
171 break; 171 break;
diff --git a/arch/cris/arch-v32/kernel/ptrace.c b/arch/cris/arch-v32/kernel/ptrace.c
index f4ebd1e7d0f5..511ece94a574 100644
--- a/arch/cris/arch-v32/kernel/ptrace.c
+++ b/arch/cris/arch-v32/kernel/ptrace.c
@@ -126,9 +126,11 @@ ptrace_disable(struct task_struct *child)
126} 126}
127 127
128 128
129long arch_ptrace(struct task_struct *child, long request, long addr, long data) 129long arch_ptrace(struct task_struct *child, long request,
130 unsigned long addr, unsigned long data)
130{ 131{
131 int ret; 132 int ret;
133 unsigned int regno = addr >> 2;
132 unsigned long __user *datap = (unsigned long __user *)data; 134 unsigned long __user *datap = (unsigned long __user *)data;
133 135
134 switch (request) { 136 switch (request) {
@@ -163,10 +165,10 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
163 unsigned long tmp; 165 unsigned long tmp;
164 166
165 ret = -EIO; 167 ret = -EIO;
166 if ((addr & 3) || addr < 0 || addr > PT_MAX << 2) 168 if ((addr & 3) || regno > PT_MAX)
167 break; 169 break;
168 170
169 tmp = get_reg(child, addr >> 2); 171 tmp = get_reg(child, regno);
170 ret = put_user(tmp, datap); 172 ret = put_user(tmp, datap);
171 break; 173 break;
172 } 174 }
@@ -180,19 +182,17 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
180 /* Write the word at location address in the USER area. */ 182 /* Write the word at location address in the USER area. */
181 case PTRACE_POKEUSR: 183 case PTRACE_POKEUSR:
182 ret = -EIO; 184 ret = -EIO;
183 if ((addr & 3) || addr < 0 || addr > PT_MAX << 2) 185 if ((addr & 3) || regno > PT_MAX)
184 break; 186 break;
185 187
186 addr >>= 2; 188 if (regno == PT_CCS) {
187
188 if (addr == PT_CCS) {
189 /* don't allow the tracing process to change stuff like 189 /* don't allow the tracing process to change stuff like
190 * interrupt enable, kernel/user bit, dma enables etc. 190 * interrupt enable, kernel/user bit, dma enables etc.
191 */ 191 */
192 data &= CCS_MASK; 192 data &= CCS_MASK;
193 data |= get_reg(child, PT_CCS) & ~CCS_MASK; 193 data |= get_reg(child, PT_CCS) & ~CCS_MASK;
194 } 194 }
195 if (put_reg(child, addr, data)) 195 if (put_reg(child, regno, data))
196 break; 196 break;
197 ret = 0; 197 ret = 0;
198 break; 198 break;
diff --git a/arch/frv/kernel/ptrace.c b/arch/frv/kernel/ptrace.c
index fac028936a04..9d68f7fac730 100644
--- a/arch/frv/kernel/ptrace.c
+++ b/arch/frv/kernel/ptrace.c
@@ -254,23 +254,26 @@ void ptrace_disable(struct task_struct *child)
254 user_disable_single_step(child); 254 user_disable_single_step(child);
255} 255}
256 256
257long arch_ptrace(struct task_struct *child, long request, long addr, long data) 257long arch_ptrace(struct task_struct *child, long request,
258 unsigned long addr, unsigned long data)
258{ 259{
259 unsigned long tmp; 260 unsigned long tmp;
260 int ret; 261 int ret;
262 int regno = addr >> 2;
263 unsigned long __user *datap = (unsigned long __user *) data;
261 264
262 switch (request) { 265 switch (request) {
263 /* read the word at location addr in the USER area. */ 266 /* read the word at location addr in the USER area. */
264 case PTRACE_PEEKUSR: { 267 case PTRACE_PEEKUSR: {
265 tmp = 0; 268 tmp = 0;
266 ret = -EIO; 269 ret = -EIO;
267 if ((addr & 3) || addr < 0) 270 if (addr & 3)
268 break; 271 break;
269 272
270 ret = 0; 273 ret = 0;
271 switch (addr >> 2) { 274 switch (regno) {
272 case 0 ... PT__END - 1: 275 case 0 ... PT__END - 1:
273 tmp = get_reg(child, addr >> 2); 276 tmp = get_reg(child, regno);
274 break; 277 break;
275 278
276 case PT__END + 0: 279 case PT__END + 0:
@@ -299,23 +302,18 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
299 } 302 }
300 303
301 if (ret == 0) 304 if (ret == 0)
302 ret = put_user(tmp, (unsigned long *) data); 305 ret = put_user(tmp, datap);
303 break; 306 break;
304 } 307 }
305 308
306 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ 309 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
307 ret = -EIO; 310 ret = -EIO;
308 if ((addr & 3) || addr < 0) 311 if (addr & 3)
309 break; 312 break;
310 313
311 ret = 0; 314 switch (regno) {
312 switch (addr >> 2) {
313 case 0 ... PT__END - 1: 315 case 0 ... PT__END - 1:
314 ret = put_reg(child, addr >> 2, data); 316 ret = put_reg(child, regno, data);
315 break;
316
317 default:
318 ret = -EIO;
319 break; 317 break;
320 } 318 }
321 break; 319 break;
@@ -324,25 +322,25 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
324 return copy_regset_to_user(child, &user_frv_native_view, 322 return copy_regset_to_user(child, &user_frv_native_view,
325 REGSET_GENERAL, 323 REGSET_GENERAL,
326 0, sizeof(child->thread.user->i), 324 0, sizeof(child->thread.user->i),
327 (void __user *)data); 325 datap);
328 326
329 case PTRACE_SETREGS: /* Set all integer regs in the child. */ 327 case PTRACE_SETREGS: /* Set all integer regs in the child. */
330 return copy_regset_from_user(child, &user_frv_native_view, 328 return copy_regset_from_user(child, &user_frv_native_view,
331 REGSET_GENERAL, 329 REGSET_GENERAL,
332 0, sizeof(child->thread.user->i), 330 0, sizeof(child->thread.user->i),
333 (const void __user *)data); 331 datap);
334 332
335 case PTRACE_GETFPREGS: /* Get the child FP/Media state. */ 333 case PTRACE_GETFPREGS: /* Get the child FP/Media state. */
336 return copy_regset_to_user(child, &user_frv_native_view, 334 return copy_regset_to_user(child, &user_frv_native_view,
337 REGSET_FPMEDIA, 335 REGSET_FPMEDIA,
338 0, sizeof(child->thread.user->f), 336 0, sizeof(child->thread.user->f),
339 (void __user *)data); 337 datap);
340 338
341 case PTRACE_SETFPREGS: /* Set the child FP/Media state. */ 339 case PTRACE_SETFPREGS: /* Set the child FP/Media state. */
342 return copy_regset_from_user(child, &user_frv_native_view, 340 return copy_regset_from_user(child, &user_frv_native_view,
343 REGSET_FPMEDIA, 341 REGSET_FPMEDIA,
344 0, sizeof(child->thread.user->f), 342 0, sizeof(child->thread.user->f),
345 (const void __user *)data); 343 datap);
346 344
347 default: 345 default:
348 ret = ptrace_request(child, request, addr, data); 346 ret = ptrace_request(child, request, addr, data);
diff --git a/arch/frv/mm/highmem.c b/arch/frv/mm/highmem.c
index 61088dcc1594..fd7fcd4c2e33 100644
--- a/arch/frv/mm/highmem.c
+++ b/arch/frv/mm/highmem.c
@@ -68,7 +68,7 @@ EXPORT_SYMBOL(__kmap_atomic);
68 68
69void __kunmap_atomic(void *kvaddr) 69void __kunmap_atomic(void *kvaddr)
70{ 70{
71 int type = kmap_atomic_idx_pop(); 71 int type = kmap_atomic_idx();
72 switch (type) { 72 switch (type) {
73 case 0: __kunmap_atomic_primary(4, 6); break; 73 case 0: __kunmap_atomic_primary(4, 6); break;
74 case 1: __kunmap_atomic_primary(5, 7); break; 74 case 1: __kunmap_atomic_primary(5, 7); break;
@@ -83,6 +83,7 @@ void __kunmap_atomic(void *kvaddr)
83 default: 83 default:
84 BUG(); 84 BUG();
85 } 85 }
86 kmap_atomic_idx_pop();
86 pagefault_enable(); 87 pagefault_enable();
87} 88}
88EXPORT_SYMBOL(__kunmap_atomic); 89EXPORT_SYMBOL(__kunmap_atomic);
diff --git a/arch/h8300/kernel/ptrace.c b/arch/h8300/kernel/ptrace.c
index df114122ebdf..497fa89b5df4 100644
--- a/arch/h8300/kernel/ptrace.c
+++ b/arch/h8300/kernel/ptrace.c
@@ -50,27 +50,29 @@ void ptrace_disable(struct task_struct *child)
50 user_disable_single_step(child); 50 user_disable_single_step(child);
51} 51}
52 52
53long arch_ptrace(struct task_struct *child, long request, long addr, long data) 53long arch_ptrace(struct task_struct *child, long request,
54 unsigned long addr, unsigned long data)
54{ 55{
55 int ret; 56 int ret;
57 int regno = addr >> 2;
58 unsigned long __user *datap = (unsigned long __user *) data;
56 59
57 switch (request) { 60 switch (request) {
58 /* read the word at location addr in the USER area. */ 61 /* read the word at location addr in the USER area. */
59 case PTRACE_PEEKUSR: { 62 case PTRACE_PEEKUSR: {
60 unsigned long tmp = 0; 63 unsigned long tmp = 0;
61 64
62 if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) { 65 if ((addr & 3) || addr >= sizeof(struct user)) {
63 ret = -EIO; 66 ret = -EIO;
64 break ; 67 break ;
65 } 68 }
66 69
67 ret = 0; /* Default return condition */ 70 ret = 0; /* Default return condition */
68 addr = addr >> 2; /* temporary hack. */
69 71
70 if (addr < H8300_REGS_NO) 72 if (regno < H8300_REGS_NO)
71 tmp = h8300_get_reg(child, addr); 73 tmp = h8300_get_reg(child, regno);
72 else { 74 else {
73 switch(addr) { 75 switch (regno) {
74 case 49: 76 case 49:
75 tmp = child->mm->start_code; 77 tmp = child->mm->start_code;
76 break ; 78 break ;
@@ -88,24 +90,23 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
88 } 90 }
89 } 91 }
90 if (!ret) 92 if (!ret)
91 ret = put_user(tmp,(unsigned long *) data); 93 ret = put_user(tmp, datap);
92 break ; 94 break ;
93 } 95 }
94 96
95 /* when I and D space are separate, this will have to be fixed. */ 97 /* when I and D space are separate, this will have to be fixed. */
96 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ 98 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
97 if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) { 99 if ((addr & 3) || addr >= sizeof(struct user)) {
98 ret = -EIO; 100 ret = -EIO;
99 break ; 101 break ;
100 } 102 }
101 addr = addr >> 2; /* temporary hack. */
102 103
103 if (addr == PT_ORIG_ER0) { 104 if (regno == PT_ORIG_ER0) {
104 ret = -EIO; 105 ret = -EIO;
105 break ; 106 break ;
106 } 107 }
107 if (addr < H8300_REGS_NO) { 108 if (regno < H8300_REGS_NO) {
108 ret = h8300_put_reg(child, addr, data); 109 ret = h8300_put_reg(child, regno, data);
109 break ; 110 break ;
110 } 111 }
111 ret = -EIO; 112 ret = -EIO;
@@ -116,11 +117,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
116 unsigned long tmp; 117 unsigned long tmp;
117 for (i = 0; i < H8300_REGS_NO; i++) { 118 for (i = 0; i < H8300_REGS_NO; i++) {
118 tmp = h8300_get_reg(child, i); 119 tmp = h8300_get_reg(child, i);
119 if (put_user(tmp, (unsigned long *) data)) { 120 if (put_user(tmp, datap)) {
120 ret = -EFAULT; 121 ret = -EFAULT;
121 break; 122 break;
122 } 123 }
123 data += sizeof(long); 124 datap++;
124 } 125 }
125 ret = 0; 126 ret = 0;
126 break; 127 break;
@@ -130,12 +131,12 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
130 int i; 131 int i;
131 unsigned long tmp; 132 unsigned long tmp;
132 for (i = 0; i < H8300_REGS_NO; i++) { 133 for (i = 0; i < H8300_REGS_NO; i++) {
133 if (get_user(tmp, (unsigned long *) data)) { 134 if (get_user(tmp, datap)) {
134 ret = -EFAULT; 135 ret = -EFAULT;
135 break; 136 break;
136 } 137 }
137 h8300_put_reg(child, i, tmp); 138 h8300_put_reg(child, i, tmp);
138 data += sizeof(long); 139 datap++;
139 } 140 }
140 ret = 0; 141 ret = 0;
141 break; 142 break;
diff --git a/arch/ia64/include/asm/cputime.h b/arch/ia64/include/asm/cputime.h
index 7fa8a8594660..6073b187528a 100644
--- a/arch/ia64/include/asm/cputime.h
+++ b/arch/ia64/include/asm/cputime.h
@@ -56,10 +56,10 @@ typedef u64 cputime64_t;
56#define jiffies64_to_cputime64(__jif) ((__jif) * (NSEC_PER_SEC / HZ)) 56#define jiffies64_to_cputime64(__jif) ((__jif) * (NSEC_PER_SEC / HZ))
57 57
58/* 58/*
59 * Convert cputime <-> milliseconds 59 * Convert cputime <-> microseconds
60 */ 60 */
61#define cputime_to_msecs(__ct) ((__ct) / NSEC_PER_MSEC) 61#define cputime_to_usecs(__ct) ((__ct) / NSEC_PER_USEC)
62#define msecs_to_cputime(__msecs) ((__msecs) * NSEC_PER_MSEC) 62#define usecs_to_cputime(__usecs) ((__usecs) * NSEC_PER_USEC)
63 63
64/* 64/*
65 * Convert cputime <-> seconds 65 * Convert cputime <-> seconds
diff --git a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c
index 7c7909f9bc93..8848f43d819e 100644
--- a/arch/ia64/kernel/ptrace.c
+++ b/arch/ia64/kernel/ptrace.c
@@ -1177,7 +1177,8 @@ ptrace_disable (struct task_struct *child)
1177} 1177}
1178 1178
1179long 1179long
1180arch_ptrace (struct task_struct *child, long request, long addr, long data) 1180arch_ptrace (struct task_struct *child, long request,
1181 unsigned long addr, unsigned long data)
1181{ 1182{
1182 switch (request) { 1183 switch (request) {
1183 case PTRACE_PEEKTEXT: 1184 case PTRACE_PEEKTEXT:
diff --git a/arch/m32r/kernel/ptrace.c b/arch/m32r/kernel/ptrace.c
index 0021ade4cba8..20743754f2b2 100644
--- a/arch/m32r/kernel/ptrace.c
+++ b/arch/m32r/kernel/ptrace.c
@@ -622,9 +622,11 @@ void ptrace_disable(struct task_struct *child)
622} 622}
623 623
624long 624long
625arch_ptrace(struct task_struct *child, long request, long addr, long data) 625arch_ptrace(struct task_struct *child, long request,
626 unsigned long addr, unsigned long data)
626{ 627{
627 int ret; 628 int ret;
629 unsigned long __user *datap = (unsigned long __user *) data;
628 630
629 switch (request) { 631 switch (request) {
630 /* 632 /*
@@ -639,8 +641,7 @@ arch_ptrace(struct task_struct *child, long request, long addr, long data)
639 * read the word at location addr in the USER area. 641 * read the word at location addr in the USER area.
640 */ 642 */
641 case PTRACE_PEEKUSR: 643 case PTRACE_PEEKUSR:
642 ret = ptrace_read_user(child, addr, 644 ret = ptrace_read_user(child, addr, datap);
643 (unsigned long __user *)data);
644 break; 645 break;
645 646
646 /* 647 /*
@@ -661,11 +662,11 @@ arch_ptrace(struct task_struct *child, long request, long addr, long data)
661 break; 662 break;
662 663
663 case PTRACE_GETREGS: 664 case PTRACE_GETREGS:
664 ret = ptrace_getregs(child, (void __user *)data); 665 ret = ptrace_getregs(child, datap);
665 break; 666 break;
666 667
667 case PTRACE_SETREGS: 668 case PTRACE_SETREGS:
668 ret = ptrace_setregs(child, (void __user *)data); 669 ret = ptrace_setregs(child, datap);
669 break; 670 break;
670 671
671 default: 672 default:
diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index 616e59752c29..0b252683cefb 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -156,55 +156,57 @@ void user_disable_single_step(struct task_struct *child)
156 singlestep_disable(child); 156 singlestep_disable(child);
157} 157}
158 158
159long arch_ptrace(struct task_struct *child, long request, long addr, long data) 159long arch_ptrace(struct task_struct *child, long request,
160 unsigned long addr, unsigned long data)
160{ 161{
161 unsigned long tmp; 162 unsigned long tmp;
162 int i, ret = 0; 163 int i, ret = 0;
164 int regno = addr >> 2; /* temporary hack. */
165 unsigned long __user *datap = (unsigned long __user *) data;
163 166
164 switch (request) { 167 switch (request) {
165 /* read the word at location addr in the USER area. */ 168 /* read the word at location addr in the USER area. */
166 case PTRACE_PEEKUSR: 169 case PTRACE_PEEKUSR:
167 if (addr & 3) 170 if (addr & 3)
168 goto out_eio; 171 goto out_eio;
169 addr >>= 2; /* temporary hack. */
170 172
171 if (addr >= 0 && addr < 19) { 173 if (regno >= 0 && regno < 19) {
172 tmp = get_reg(child, addr); 174 tmp = get_reg(child, regno);
173 } else if (addr >= 21 && addr < 49) { 175 } else if (regno >= 21 && regno < 49) {
174 tmp = child->thread.fp[addr - 21]; 176 tmp = child->thread.fp[regno - 21];
175 /* Convert internal fpu reg representation 177 /* Convert internal fpu reg representation
176 * into long double format 178 * into long double format
177 */ 179 */
178 if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) 180 if (FPU_IS_EMU && (regno < 45) && !(regno % 3))
179 tmp = ((tmp & 0xffff0000) << 15) | 181 tmp = ((tmp & 0xffff0000) << 15) |
180 ((tmp & 0x0000ffff) << 16); 182 ((tmp & 0x0000ffff) << 16);
181 } else 183 } else
182 goto out_eio; 184 goto out_eio;
183 ret = put_user(tmp, (unsigned long *)data); 185 ret = put_user(tmp, datap);
184 break; 186 break;
185 187
186 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ 188 case PTRACE_POKEUSR:
189 /* write the word at location addr in the USER area */
187 if (addr & 3) 190 if (addr & 3)
188 goto out_eio; 191 goto out_eio;
189 addr >>= 2; /* temporary hack. */
190 192
191 if (addr == PT_SR) { 193 if (regno == PT_SR) {
192 data &= SR_MASK; 194 data &= SR_MASK;
193 data |= get_reg(child, PT_SR) & ~SR_MASK; 195 data |= get_reg(child, PT_SR) & ~SR_MASK;
194 } 196 }
195 if (addr >= 0 && addr < 19) { 197 if (regno >= 0 && regno < 19) {
196 if (put_reg(child, addr, data)) 198 if (put_reg(child, regno, data))
197 goto out_eio; 199 goto out_eio;
198 } else if (addr >= 21 && addr < 48) { 200 } else if (regno >= 21 && regno < 48) {
199 /* Convert long double format 201 /* Convert long double format
200 * into internal fpu reg representation 202 * into internal fpu reg representation
201 */ 203 */
202 if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) { 204 if (FPU_IS_EMU && (regno < 45) && !(regno % 3)) {
203 data = (unsigned long)data << 15; 205 data <<= 15;
204 data = (data & 0xffff0000) | 206 data = (data & 0xffff0000) |
205 ((data & 0x0000ffff) >> 1); 207 ((data & 0x0000ffff) >> 1);
206 } 208 }
207 child->thread.fp[addr - 21] = data; 209 child->thread.fp[regno - 21] = data;
208 } else 210 } else
209 goto out_eio; 211 goto out_eio;
210 break; 212 break;
@@ -212,16 +214,16 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
212 case PTRACE_GETREGS: /* Get all gp regs from the child. */ 214 case PTRACE_GETREGS: /* Get all gp regs from the child. */
213 for (i = 0; i < 19; i++) { 215 for (i = 0; i < 19; i++) {
214 tmp = get_reg(child, i); 216 tmp = get_reg(child, i);
215 ret = put_user(tmp, (unsigned long *)data); 217 ret = put_user(tmp, datap);
216 if (ret) 218 if (ret)
217 break; 219 break;
218 data += sizeof(long); 220 datap++;
219 } 221 }
220 break; 222 break;
221 223
222 case PTRACE_SETREGS: /* Set all gp regs in the child. */ 224 case PTRACE_SETREGS: /* Set all gp regs in the child. */
223 for (i = 0; i < 19; i++) { 225 for (i = 0; i < 19; i++) {
224 ret = get_user(tmp, (unsigned long *)data); 226 ret = get_user(tmp, datap);
225 if (ret) 227 if (ret)
226 break; 228 break;
227 if (i == PT_SR) { 229 if (i == PT_SR) {
@@ -229,25 +231,24 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
229 tmp |= get_reg(child, PT_SR) & ~SR_MASK; 231 tmp |= get_reg(child, PT_SR) & ~SR_MASK;
230 } 232 }
231 put_reg(child, i, tmp); 233 put_reg(child, i, tmp);
232 data += sizeof(long); 234 datap++;
233 } 235 }
234 break; 236 break;
235 237
236 case PTRACE_GETFPREGS: /* Get the child FPU state. */ 238 case PTRACE_GETFPREGS: /* Get the child FPU state. */
237 if (copy_to_user((void *)data, &child->thread.fp, 239 if (copy_to_user(datap, &child->thread.fp,
238 sizeof(struct user_m68kfp_struct))) 240 sizeof(struct user_m68kfp_struct)))
239 ret = -EFAULT; 241 ret = -EFAULT;
240 break; 242 break;
241 243
242 case PTRACE_SETFPREGS: /* Set the child FPU state. */ 244 case PTRACE_SETFPREGS: /* Set the child FPU state. */
243 if (copy_from_user(&child->thread.fp, (void *)data, 245 if (copy_from_user(&child->thread.fp, datap,
244 sizeof(struct user_m68kfp_struct))) 246 sizeof(struct user_m68kfp_struct)))
245 ret = -EFAULT; 247 ret = -EFAULT;
246 break; 248 break;
247 249
248 case PTRACE_GET_THREAD_AREA: 250 case PTRACE_GET_THREAD_AREA:
249 ret = put_user(task_thread_info(child)->tp_value, 251 ret = put_user(task_thread_info(child)->tp_value, datap);
250 (unsigned long __user *)data);
251 break; 252 break;
252 253
253 default: 254 default:
diff --git a/arch/m68knommu/kernel/ptrace.c b/arch/m68knommu/kernel/ptrace.c
index 6fe7c38cd556..6709fb707335 100644
--- a/arch/m68knommu/kernel/ptrace.c
+++ b/arch/m68knommu/kernel/ptrace.c
@@ -112,9 +112,12 @@ void ptrace_disable(struct task_struct *child)
112 user_disable_single_step(child); 112 user_disable_single_step(child);
113} 113}
114 114
115long arch_ptrace(struct task_struct *child, long request, long addr, long data) 115long arch_ptrace(struct task_struct *child, long request,
116 unsigned long addr, unsigned long data)
116{ 117{
117 int ret; 118 int ret;
119 int regno = addr >> 2;
120 unsigned long __user *datap = (unsigned long __user *) data;
118 121
119 switch (request) { 122 switch (request) {
120 /* read the word at location addr in the USER area. */ 123 /* read the word at location addr in the USER area. */
@@ -122,53 +125,48 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
122 unsigned long tmp; 125 unsigned long tmp;
123 126
124 ret = -EIO; 127 ret = -EIO;
125 if ((addr & 3) || addr < 0 || 128 if ((addr & 3) || addr > sizeof(struct user) - 3)
126 addr > sizeof(struct user) - 3)
127 break; 129 break;
128 130
129 tmp = 0; /* Default return condition */ 131 tmp = 0; /* Default return condition */
130 addr = addr >> 2; /* temporary hack. */
131 ret = -EIO; 132 ret = -EIO;
132 if (addr < 19) { 133 if (regno < 19) {
133 tmp = get_reg(child, addr); 134 tmp = get_reg(child, regno);
134 if (addr == PT_SR) 135 if (regno == PT_SR)
135 tmp >>= 16; 136 tmp >>= 16;
136 } else if (addr >= 21 && addr < 49) { 137 } else if (regno >= 21 && regno < 49) {
137 tmp = child->thread.fp[addr - 21]; 138 tmp = child->thread.fp[regno - 21];
138 } else if (addr == 49) { 139 } else if (regno == 49) {
139 tmp = child->mm->start_code; 140 tmp = child->mm->start_code;
140 } else if (addr == 50) { 141 } else if (regno == 50) {
141 tmp = child->mm->start_data; 142 tmp = child->mm->start_data;
142 } else if (addr == 51) { 143 } else if (regno == 51) {
143 tmp = child->mm->end_code; 144 tmp = child->mm->end_code;
144 } else 145 } else
145 break; 146 break;
146 ret = put_user(tmp,(unsigned long *) data); 147 ret = put_user(tmp, datap);
147 break; 148 break;
148 } 149 }
149 150
150 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ 151 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
151 ret = -EIO; 152 ret = -EIO;
152 if ((addr & 3) || addr < 0 || 153 if ((addr & 3) || addr > sizeof(struct user) - 3)
153 addr > sizeof(struct user) - 3)
154 break; 154 break;
155 155
156 addr = addr >> 2; /* temporary hack. */ 156 if (regno == PT_SR) {
157
158 if (addr == PT_SR) {
159 data &= SR_MASK; 157 data &= SR_MASK;
160 data <<= 16; 158 data <<= 16;
161 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16); 159 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
162 } 160 }
163 if (addr < 19) { 161 if (regno < 19) {
164 if (put_reg(child, addr, data)) 162 if (put_reg(child, regno, data))
165 break; 163 break;
166 ret = 0; 164 ret = 0;
167 break; 165 break;
168 } 166 }
169 if (addr >= 21 && addr < 48) 167 if (regno >= 21 && regno < 48)
170 { 168 {
171 child->thread.fp[addr - 21] = data; 169 child->thread.fp[regno - 21] = data;
172 ret = 0; 170 ret = 0;
173 } 171 }
174 break; 172 break;
@@ -180,11 +178,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
180 tmp = get_reg(child, i); 178 tmp = get_reg(child, i);
181 if (i == PT_SR) 179 if (i == PT_SR)
182 tmp >>= 16; 180 tmp >>= 16;
183 if (put_user(tmp, (unsigned long *) data)) { 181 if (put_user(tmp, datap)) {
184 ret = -EFAULT; 182 ret = -EFAULT;
185 break; 183 break;
186 } 184 }
187 data += sizeof(long); 185 datap++;
188 } 186 }
189 ret = 0; 187 ret = 0;
190 break; 188 break;
@@ -194,7 +192,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
194 int i; 192 int i;
195 unsigned long tmp; 193 unsigned long tmp;
196 for (i = 0; i < 19; i++) { 194 for (i = 0; i < 19; i++) {
197 if (get_user(tmp, (unsigned long *) data)) { 195 if (get_user(tmp, datap)) {
198 ret = -EFAULT; 196 ret = -EFAULT;
199 break; 197 break;
200 } 198 }
@@ -204,7 +202,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
204 tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16); 202 tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
205 } 203 }
206 put_reg(child, i, tmp); 204 put_reg(child, i, tmp);
207 data += sizeof(long); 205 datap++;
208 } 206 }
209 ret = 0; 207 ret = 0;
210 break; 208 break;
@@ -213,7 +211,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
213#ifdef PTRACE_GETFPREGS 211#ifdef PTRACE_GETFPREGS
214 case PTRACE_GETFPREGS: { /* Get the child FPU state. */ 212 case PTRACE_GETFPREGS: { /* Get the child FPU state. */
215 ret = 0; 213 ret = 0;
216 if (copy_to_user((void *)data, &child->thread.fp, 214 if (copy_to_user(datap, &child->thread.fp,
217 sizeof(struct user_m68kfp_struct))) 215 sizeof(struct user_m68kfp_struct)))
218 ret = -EFAULT; 216 ret = -EFAULT;
219 break; 217 break;
@@ -223,7 +221,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
223#ifdef PTRACE_SETFPREGS 221#ifdef PTRACE_SETFPREGS
224 case PTRACE_SETFPREGS: { /* Set the child FPU state. */ 222 case PTRACE_SETFPREGS: { /* Set the child FPU state. */
225 ret = 0; 223 ret = 0;
226 if (copy_from_user(&child->thread.fp, (void *)data, 224 if (copy_from_user(&child->thread.fp, datap,
227 sizeof(struct user_m68kfp_struct))) 225 sizeof(struct user_m68kfp_struct)))
228 ret = -EFAULT; 226 ret = -EFAULT;
229 break; 227 break;
@@ -231,8 +229,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
231#endif 229#endif
232 230
233 case PTRACE_GET_THREAD_AREA: 231 case PTRACE_GET_THREAD_AREA:
234 ret = put_user(task_thread_info(child)->tp_value, 232 ret = put_user(task_thread_info(child)->tp_value, datap);
235 (unsigned long __user *)data);
236 break; 233 break;
237 234
238 default: 235 default:
diff --git a/arch/microblaze/kernel/ptrace.c b/arch/microblaze/kernel/ptrace.c
index dc03ffc8174a..05ac8cc975d5 100644
--- a/arch/microblaze/kernel/ptrace.c
+++ b/arch/microblaze/kernel/ptrace.c
@@ -73,7 +73,8 @@ static microblaze_reg_t *reg_save_addr(unsigned reg_offs,
73 return (microblaze_reg_t *)((char *)regs + reg_offs); 73 return (microblaze_reg_t *)((char *)regs + reg_offs);
74} 74}
75 75
76long arch_ptrace(struct task_struct *child, long request, long addr, long data) 76long arch_ptrace(struct task_struct *child, long request,
77 unsigned long addr, unsigned long data)
77{ 78{
78 int rval; 79 int rval;
79 unsigned long val = 0; 80 unsigned long val = 0;
@@ -99,7 +100,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
99 } else { 100 } else {
100 rval = -EIO; 101 rval = -EIO;
101 } 102 }
102 } else if (addr >= 0 && addr < PT_SIZE && (addr & 0x3) == 0) { 103 } else if (addr < PT_SIZE && (addr & 0x3) == 0) {
103 microblaze_reg_t *reg_addr = reg_save_addr(addr, child); 104 microblaze_reg_t *reg_addr = reg_save_addr(addr, child);
104 if (request == PTRACE_PEEKUSR) 105 if (request == PTRACE_PEEKUSR)
105 val = *reg_addr; 106 val = *reg_addr;
diff --git a/arch/mips/include/asm/pci/bridge.h b/arch/mips/include/asm/pci/bridge.h
index 5f4b9d4e4114..f1f508e4f971 100644
--- a/arch/mips/include/asm/pci/bridge.h
+++ b/arch/mips/include/asm/pci/bridge.h
@@ -839,7 +839,7 @@ struct bridge_controller {
839 nasid_t nasid; 839 nasid_t nasid;
840 unsigned int widget_id; 840 unsigned int widget_id;
841 unsigned int irq_cpu; 841 unsigned int irq_cpu;
842 dma64_addr_t baddr; 842 u64 baddr;
843 unsigned int pci_int[8]; 843 unsigned int pci_int[8];
844}; 844};
845 845
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index c8777333e198..d21c388c0116 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -255,9 +255,13 @@ int ptrace_set_watch_regs(struct task_struct *child,
255 return 0; 255 return 0;
256} 256}
257 257
258long arch_ptrace(struct task_struct *child, long request, long addr, long data) 258long arch_ptrace(struct task_struct *child, long request,
259 unsigned long addr, unsigned long data)
259{ 260{
260 int ret; 261 int ret;
262 void __user *addrp = (void __user *) addr;
263 void __user *datavp = (void __user *) data;
264 unsigned long __user *datalp = (void __user *) data;
261 265
262 switch (request) { 266 switch (request) {
263 /* when I and D space are separate, these will need to be fixed. */ 267 /* when I and D space are separate, these will need to be fixed. */
@@ -386,7 +390,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
386 ret = -EIO; 390 ret = -EIO;
387 goto out; 391 goto out;
388 } 392 }
389 ret = put_user(tmp, (unsigned long __user *) data); 393 ret = put_user(tmp, datalp);
390 break; 394 break;
391 } 395 }
392 396
@@ -478,34 +482,31 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
478 } 482 }
479 483
480 case PTRACE_GETREGS: 484 case PTRACE_GETREGS:
481 ret = ptrace_getregs(child, (__s64 __user *) data); 485 ret = ptrace_getregs(child, datavp);
482 break; 486 break;
483 487
484 case PTRACE_SETREGS: 488 case PTRACE_SETREGS:
485 ret = ptrace_setregs(child, (__s64 __user *) data); 489 ret = ptrace_setregs(child, datavp);
486 break; 490 break;
487 491
488 case PTRACE_GETFPREGS: 492 case PTRACE_GETFPREGS:
489 ret = ptrace_getfpregs(child, (__u32 __user *) data); 493 ret = ptrace_getfpregs(child, datavp);
490 break; 494 break;
491 495
492 case PTRACE_SETFPREGS: 496 case PTRACE_SETFPREGS:
493 ret = ptrace_setfpregs(child, (__u32 __user *) data); 497 ret = ptrace_setfpregs(child, datavp);
494 break; 498 break;
495 499
496 case PTRACE_GET_THREAD_AREA: 500 case PTRACE_GET_THREAD_AREA:
497 ret = put_user(task_thread_info(child)->tp_value, 501 ret = put_user(task_thread_info(child)->tp_value, datalp);
498 (unsigned long __user *) data);
499 break; 502 break;
500 503
501 case PTRACE_GET_WATCH_REGS: 504 case PTRACE_GET_WATCH_REGS:
502 ret = ptrace_get_watch_regs(child, 505 ret = ptrace_get_watch_regs(child, addrp);
503 (struct pt_watch_regs __user *) addr);
504 break; 506 break;
505 507
506 case PTRACE_SET_WATCH_REGS: 508 case PTRACE_SET_WATCH_REGS:
507 ret = ptrace_set_watch_regs(child, 509 ret = ptrace_set_watch_regs(child, addrp);
508 (struct pt_watch_regs __user *) addr);
509 break; 510 break;
510 511
511 default: 512 default:
diff --git a/arch/mips/mm/highmem.c b/arch/mips/mm/highmem.c
index 1e69b1fb4b85..3634c7ea06ac 100644
--- a/arch/mips/mm/highmem.c
+++ b/arch/mips/mm/highmem.c
@@ -74,7 +74,7 @@ void __kunmap_atomic(void *kvaddr)
74 return; 74 return;
75 } 75 }
76 76
77 type = kmap_atomic_idx_pop(); 77 type = kmap_atomic_idx();
78#ifdef CONFIG_DEBUG_HIGHMEM 78#ifdef CONFIG_DEBUG_HIGHMEM
79 { 79 {
80 int idx = type + KM_TYPE_NR * smp_processor_id(); 80 int idx = type + KM_TYPE_NR * smp_processor_id();
@@ -89,6 +89,7 @@ void __kunmap_atomic(void *kvaddr)
89 local_flush_tlb_one(vaddr); 89 local_flush_tlb_one(vaddr);
90 } 90 }
91#endif 91#endif
92 kmap_atomic_idx_pop();
92 pagefault_enable(); 93 pagefault_enable();
93} 94}
94EXPORT_SYMBOL(__kunmap_atomic); 95EXPORT_SYMBOL(__kunmap_atomic);
diff --git a/arch/mn10300/include/asm/highmem.h b/arch/mn10300/include/asm/highmem.h
index 3817d9f34e72..bfe2d88604d9 100644
--- a/arch/mn10300/include/asm/highmem.h
+++ b/arch/mn10300/include/asm/highmem.h
@@ -101,7 +101,7 @@ static inline void __kunmap_atomic(unsigned long vaddr)
101 return; 101 return;
102 } 102 }
103 103
104 type = kmap_atomic_idx_pop(); 104 type = kmap_atomic_idx();
105 105
106#if HIGHMEM_DEBUG 106#if HIGHMEM_DEBUG
107 { 107 {
@@ -119,6 +119,8 @@ static inline void __kunmap_atomic(unsigned long vaddr)
119 local_flush_tlb_one(vaddr); 119 local_flush_tlb_one(vaddr);
120 } 120 }
121#endif 121#endif
122
123 kmap_atomic_idx_pop();
122 pagefault_enable(); 124 pagefault_enable();
123} 125}
124#endif /* __KERNEL__ */ 126#endif /* __KERNEL__ */
diff --git a/arch/mn10300/kernel/ptrace.c b/arch/mn10300/kernel/ptrace.c
index cf847dabc1bd..5c0b07e61006 100644
--- a/arch/mn10300/kernel/ptrace.c
+++ b/arch/mn10300/kernel/ptrace.c
@@ -295,31 +295,31 @@ void ptrace_disable(struct task_struct *child)
295/* 295/*
296 * handle the arch-specific side of process tracing 296 * handle the arch-specific side of process tracing
297 */ 297 */
298long arch_ptrace(struct task_struct *child, long request, long addr, long data) 298long arch_ptrace(struct task_struct *child, long request,
299 unsigned long addr, unsigned long data)
299{ 300{
300 unsigned long tmp; 301 unsigned long tmp;
301 int ret; 302 int ret;
303 unsigned long __user *datap = (unsigned long __user *) data;
302 304
303 switch (request) { 305 switch (request) {
304 /* read the word at location addr in the USER area. */ 306 /* read the word at location addr in the USER area. */
305 case PTRACE_PEEKUSR: 307 case PTRACE_PEEKUSR:
306 ret = -EIO; 308 ret = -EIO;
307 if ((addr & 3) || addr < 0 || 309 if ((addr & 3) || addr > sizeof(struct user) - 3)
308 addr > sizeof(struct user) - 3)
309 break; 310 break;
310 311
311 tmp = 0; /* Default return condition */ 312 tmp = 0; /* Default return condition */
312 if (addr < NR_PTREGS << 2) 313 if (addr < NR_PTREGS << 2)
313 tmp = get_stack_long(child, 314 tmp = get_stack_long(child,
314 ptrace_regid_to_frame[addr]); 315 ptrace_regid_to_frame[addr]);
315 ret = put_user(tmp, (unsigned long *) data); 316 ret = put_user(tmp, datap);
316 break; 317 break;
317 318
318 /* write the word at location addr in the USER area */ 319 /* write the word at location addr in the USER area */
319 case PTRACE_POKEUSR: 320 case PTRACE_POKEUSR:
320 ret = -EIO; 321 ret = -EIO;
321 if ((addr & 3) || addr < 0 || 322 if ((addr & 3) || addr > sizeof(struct user) - 3)
322 addr > sizeof(struct user) - 3)
323 break; 323 break;
324 324
325 ret = 0; 325 ret = 0;
@@ -332,25 +332,25 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
332 return copy_regset_to_user(child, &user_mn10300_native_view, 332 return copy_regset_to_user(child, &user_mn10300_native_view,
333 REGSET_GENERAL, 333 REGSET_GENERAL,
334 0, NR_PTREGS * sizeof(long), 334 0, NR_PTREGS * sizeof(long),
335 (void __user *)data); 335 datap);
336 336
337 case PTRACE_SETREGS: /* Set all integer regs in the child. */ 337 case PTRACE_SETREGS: /* Set all integer regs in the child. */
338 return copy_regset_from_user(child, &user_mn10300_native_view, 338 return copy_regset_from_user(child, &user_mn10300_native_view,
339 REGSET_GENERAL, 339 REGSET_GENERAL,
340 0, NR_PTREGS * sizeof(long), 340 0, NR_PTREGS * sizeof(long),
341 (const void __user *)data); 341 datap);
342 342
343 case PTRACE_GETFPREGS: /* Get the child FPU state. */ 343 case PTRACE_GETFPREGS: /* Get the child FPU state. */
344 return copy_regset_to_user(child, &user_mn10300_native_view, 344 return copy_regset_to_user(child, &user_mn10300_native_view,
345 REGSET_FPU, 345 REGSET_FPU,
346 0, sizeof(struct fpu_state_struct), 346 0, sizeof(struct fpu_state_struct),
347 (void __user *)data); 347 datap);
348 348
349 case PTRACE_SETFPREGS: /* Set the child FPU state. */ 349 case PTRACE_SETFPREGS: /* Set the child FPU state. */
350 return copy_regset_from_user(child, &user_mn10300_native_view, 350 return copy_regset_from_user(child, &user_mn10300_native_view,
351 REGSET_FPU, 351 REGSET_FPU,
352 0, sizeof(struct fpu_state_struct), 352 0, sizeof(struct fpu_state_struct),
353 (const void __user *)data); 353 datap);
354 354
355 default: 355 default:
356 ret = ptrace_request(child, request, addr, data); 356 ret = ptrace_request(child, request, addr, data);
diff --git a/arch/parisc/kernel/ptrace.c b/arch/parisc/kernel/ptrace.c
index c4f49e45129d..2905b1f52d30 100644
--- a/arch/parisc/kernel/ptrace.c
+++ b/arch/parisc/kernel/ptrace.c
@@ -110,7 +110,8 @@ void user_enable_block_step(struct task_struct *task)
110 pa_psw(task)->l = 0; 110 pa_psw(task)->l = 0;
111} 111}
112 112
113long arch_ptrace(struct task_struct *child, long request, long addr, long data) 113long arch_ptrace(struct task_struct *child, long request,
114 unsigned long addr, unsigned long data)
114{ 115{
115 unsigned long tmp; 116 unsigned long tmp;
116 long ret = -EIO; 117 long ret = -EIO;
@@ -120,11 +121,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
120 /* Read the word at location addr in the USER area. For ptraced 121 /* Read the word at location addr in the USER area. For ptraced
121 processes, the kernel saves all regs on a syscall. */ 122 processes, the kernel saves all regs on a syscall. */
122 case PTRACE_PEEKUSR: 123 case PTRACE_PEEKUSR:
123 if ((addr & (sizeof(long)-1)) || 124 if ((addr & (sizeof(unsigned long)-1)) ||
124 (unsigned long) addr >= sizeof(struct pt_regs)) 125 addr >= sizeof(struct pt_regs))
125 break; 126 break;
126 tmp = *(unsigned long *) ((char *) task_regs(child) + addr); 127 tmp = *(unsigned long *) ((char *) task_regs(child) + addr);
127 ret = put_user(tmp, (unsigned long *) data); 128 ret = put_user(tmp, (unsigned long __user *) data);
128 break; 129 break;
129 130
130 /* Write the word at location addr in the USER area. This will need 131 /* Write the word at location addr in the USER area. This will need
@@ -151,8 +152,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
151 break; 152 break;
152 } 153 }
153 154
154 if ((addr & (sizeof(long)-1)) || 155 if ((addr & (sizeof(unsigned long)-1)) ||
155 (unsigned long) addr >= sizeof(struct pt_regs)) 156 addr >= sizeof(struct pt_regs))
156 break; 157 break;
157 if ((addr >= PT_GR1 && addr <= PT_GR31) || 158 if ((addr >= PT_GR1 && addr <= PT_GR31) ||
158 addr == PT_IAOQ0 || addr == PT_IAOQ1 || 159 addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h
index 8bdc6a9e5773..1cf20bdfbeca 100644
--- a/arch/powerpc/include/asm/cputime.h
+++ b/arch/powerpc/include/asm/cputime.h
@@ -124,23 +124,23 @@ static inline u64 cputime64_to_jiffies64(const cputime_t ct)
124} 124}
125 125
126/* 126/*
127 * Convert cputime <-> milliseconds 127 * Convert cputime <-> microseconds
128 */ 128 */
129extern u64 __cputime_msec_factor; 129extern u64 __cputime_msec_factor;
130 130
131static inline unsigned long cputime_to_msecs(const cputime_t ct) 131static inline unsigned long cputime_to_usecs(const cputime_t ct)
132{ 132{
133 return mulhdu(ct, __cputime_msec_factor); 133 return mulhdu(ct, __cputime_msec_factor) * USEC_PER_MSEC;
134} 134}
135 135
136static inline cputime_t msecs_to_cputime(const unsigned long ms) 136static inline cputime_t usecs_to_cputime(const unsigned long us)
137{ 137{
138 cputime_t ct; 138 cputime_t ct;
139 unsigned long sec; 139 unsigned long sec;
140 140
141 /* have to be a little careful about overflow */ 141 /* have to be a little careful about overflow */
142 ct = ms % 1000; 142 ct = us % 1000000;
143 sec = ms / 1000; 143 sec = us / 1000000;
144 if (ct) { 144 if (ct) {
145 ct *= tb_ticks_per_sec; 145 ct *= tb_ticks_per_sec;
146 do_div(ct, 1000); 146 do_div(ct, 1000);
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 286d9783d93f..a9b32967cff6 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -1406,37 +1406,42 @@ static long ppc_del_hwdebug(struct task_struct *child, long addr, long data)
1406 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls, 1406 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
1407 * we mark them as obsolete now, they will be removed in a future version 1407 * we mark them as obsolete now, they will be removed in a future version
1408 */ 1408 */
1409static long arch_ptrace_old(struct task_struct *child, long request, long addr, 1409static long arch_ptrace_old(struct task_struct *child, long request,
1410 long data) 1410 unsigned long addr, unsigned long data)
1411{ 1411{
1412 void __user *datavp = (void __user *) data;
1413
1412 switch (request) { 1414 switch (request) {
1413 case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */ 1415 case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
1414 return copy_regset_to_user(child, &user_ppc_native_view, 1416 return copy_regset_to_user(child, &user_ppc_native_view,
1415 REGSET_GPR, 0, 32 * sizeof(long), 1417 REGSET_GPR, 0, 32 * sizeof(long),
1416 (void __user *) data); 1418 datavp);
1417 1419
1418 case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */ 1420 case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
1419 return copy_regset_from_user(child, &user_ppc_native_view, 1421 return copy_regset_from_user(child, &user_ppc_native_view,
1420 REGSET_GPR, 0, 32 * sizeof(long), 1422 REGSET_GPR, 0, 32 * sizeof(long),
1421 (const void __user *) data); 1423 datavp);
1422 1424
1423 case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */ 1425 case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
1424 return copy_regset_to_user(child, &user_ppc_native_view, 1426 return copy_regset_to_user(child, &user_ppc_native_view,
1425 REGSET_FPR, 0, 32 * sizeof(double), 1427 REGSET_FPR, 0, 32 * sizeof(double),
1426 (void __user *) data); 1428 datavp);
1427 1429
1428 case PPC_PTRACE_SETFPREGS: /* Set FPRs 0 - 31. */ 1430 case PPC_PTRACE_SETFPREGS: /* Set FPRs 0 - 31. */
1429 return copy_regset_from_user(child, &user_ppc_native_view, 1431 return copy_regset_from_user(child, &user_ppc_native_view,
1430 REGSET_FPR, 0, 32 * sizeof(double), 1432 REGSET_FPR, 0, 32 * sizeof(double),
1431 (const void __user *) data); 1433 datavp);
1432 } 1434 }
1433 1435
1434 return -EPERM; 1436 return -EPERM;
1435} 1437}
1436 1438
1437long arch_ptrace(struct task_struct *child, long request, long addr, long data) 1439long arch_ptrace(struct task_struct *child, long request,
1440 unsigned long addr, unsigned long data)
1438{ 1441{
1439 int ret = -EPERM; 1442 int ret = -EPERM;
1443 void __user *datavp = (void __user *) data;
1444 unsigned long __user *datalp = datavp;
1440 1445
1441 switch (request) { 1446 switch (request) {
1442 /* read the word at location addr in the USER area. */ 1447 /* read the word at location addr in the USER area. */
@@ -1446,11 +1451,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1446 ret = -EIO; 1451 ret = -EIO;
1447 /* convert to index and check */ 1452 /* convert to index and check */
1448#ifdef CONFIG_PPC32 1453#ifdef CONFIG_PPC32
1449 index = (unsigned long) addr >> 2; 1454 index = addr >> 2;
1450 if ((addr & 3) || (index > PT_FPSCR) 1455 if ((addr & 3) || (index > PT_FPSCR)
1451 || (child->thread.regs == NULL)) 1456 || (child->thread.regs == NULL))
1452#else 1457#else
1453 index = (unsigned long) addr >> 3; 1458 index = addr >> 3;
1454 if ((addr & 7) || (index > PT_FPSCR)) 1459 if ((addr & 7) || (index > PT_FPSCR))
1455#endif 1460#endif
1456 break; 1461 break;
@@ -1463,7 +1468,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1463 tmp = ((unsigned long *)child->thread.fpr) 1468 tmp = ((unsigned long *)child->thread.fpr)
1464 [TS_FPRWIDTH * (index - PT_FPR0)]; 1469 [TS_FPRWIDTH * (index - PT_FPR0)];
1465 } 1470 }
1466 ret = put_user(tmp,(unsigned long __user *) data); 1471 ret = put_user(tmp, datalp);
1467 break; 1472 break;
1468 } 1473 }
1469 1474
@@ -1474,11 +1479,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1474 ret = -EIO; 1479 ret = -EIO;
1475 /* convert to index and check */ 1480 /* convert to index and check */
1476#ifdef CONFIG_PPC32 1481#ifdef CONFIG_PPC32
1477 index = (unsigned long) addr >> 2; 1482 index = addr >> 2;
1478 if ((addr & 3) || (index > PT_FPSCR) 1483 if ((addr & 3) || (index > PT_FPSCR)
1479 || (child->thread.regs == NULL)) 1484 || (child->thread.regs == NULL))
1480#else 1485#else
1481 index = (unsigned long) addr >> 3; 1486 index = addr >> 3;
1482 if ((addr & 7) || (index > PT_FPSCR)) 1487 if ((addr & 7) || (index > PT_FPSCR))
1483#endif 1488#endif
1484 break; 1489 break;
@@ -1525,11 +1530,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1525 dbginfo.features = 0; 1530 dbginfo.features = 0;
1526#endif /* CONFIG_PPC_ADV_DEBUG_REGS */ 1531#endif /* CONFIG_PPC_ADV_DEBUG_REGS */
1527 1532
1528 if (!access_ok(VERIFY_WRITE, data, 1533 if (!access_ok(VERIFY_WRITE, datavp,
1529 sizeof(struct ppc_debug_info))) 1534 sizeof(struct ppc_debug_info)))
1530 return -EFAULT; 1535 return -EFAULT;
1531 ret = __copy_to_user((struct ppc_debug_info __user *)data, 1536 ret = __copy_to_user(datavp, &dbginfo,
1532 &dbginfo, sizeof(struct ppc_debug_info)) ? 1537 sizeof(struct ppc_debug_info)) ?
1533 -EFAULT : 0; 1538 -EFAULT : 0;
1534 break; 1539 break;
1535 } 1540 }
@@ -1537,11 +1542,10 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1537 case PPC_PTRACE_SETHWDEBUG: { 1542 case PPC_PTRACE_SETHWDEBUG: {
1538 struct ppc_hw_breakpoint bp_info; 1543 struct ppc_hw_breakpoint bp_info;
1539 1544
1540 if (!access_ok(VERIFY_READ, data, 1545 if (!access_ok(VERIFY_READ, datavp,
1541 sizeof(struct ppc_hw_breakpoint))) 1546 sizeof(struct ppc_hw_breakpoint)))
1542 return -EFAULT; 1547 return -EFAULT;
1543 ret = __copy_from_user(&bp_info, 1548 ret = __copy_from_user(&bp_info, datavp,
1544 (struct ppc_hw_breakpoint __user *)data,
1545 sizeof(struct ppc_hw_breakpoint)) ? 1549 sizeof(struct ppc_hw_breakpoint)) ?
1546 -EFAULT : 0; 1550 -EFAULT : 0;
1547 if (!ret) 1551 if (!ret)
@@ -1560,11 +1564,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1560 if (addr > 0) 1564 if (addr > 0)
1561 break; 1565 break;
1562#ifdef CONFIG_PPC_ADV_DEBUG_REGS 1566#ifdef CONFIG_PPC_ADV_DEBUG_REGS
1563 ret = put_user(child->thread.dac1, 1567 ret = put_user(child->thread.dac1, datalp);
1564 (unsigned long __user *)data);
1565#else 1568#else
1566 ret = put_user(child->thread.dabr, 1569 ret = put_user(child->thread.dabr, datalp);
1567 (unsigned long __user *)data);
1568#endif 1570#endif
1569 break; 1571 break;
1570 } 1572 }
@@ -1580,7 +1582,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1580 return copy_regset_to_user(child, &user_ppc_native_view, 1582 return copy_regset_to_user(child, &user_ppc_native_view,
1581 REGSET_GPR, 1583 REGSET_GPR,
1582 0, sizeof(struct pt_regs), 1584 0, sizeof(struct pt_regs),
1583 (void __user *) data); 1585 datavp);
1584 1586
1585#ifdef CONFIG_PPC64 1587#ifdef CONFIG_PPC64
1586 case PTRACE_SETREGS64: 1588 case PTRACE_SETREGS64:
@@ -1589,19 +1591,19 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1589 return copy_regset_from_user(child, &user_ppc_native_view, 1591 return copy_regset_from_user(child, &user_ppc_native_view,
1590 REGSET_GPR, 1592 REGSET_GPR,
1591 0, sizeof(struct pt_regs), 1593 0, sizeof(struct pt_regs),
1592 (const void __user *) data); 1594 datavp);
1593 1595
1594 case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */ 1596 case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
1595 return copy_regset_to_user(child, &user_ppc_native_view, 1597 return copy_regset_to_user(child, &user_ppc_native_view,
1596 REGSET_FPR, 1598 REGSET_FPR,
1597 0, sizeof(elf_fpregset_t), 1599 0, sizeof(elf_fpregset_t),
1598 (void __user *) data); 1600 datavp);
1599 1601
1600 case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */ 1602 case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
1601 return copy_regset_from_user(child, &user_ppc_native_view, 1603 return copy_regset_from_user(child, &user_ppc_native_view,
1602 REGSET_FPR, 1604 REGSET_FPR,
1603 0, sizeof(elf_fpregset_t), 1605 0, sizeof(elf_fpregset_t),
1604 (const void __user *) data); 1606 datavp);
1605 1607
1606#ifdef CONFIG_ALTIVEC 1608#ifdef CONFIG_ALTIVEC
1607 case PTRACE_GETVRREGS: 1609 case PTRACE_GETVRREGS:
@@ -1609,40 +1611,40 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1609 REGSET_VMX, 1611 REGSET_VMX,
1610 0, (33 * sizeof(vector128) + 1612 0, (33 * sizeof(vector128) +
1611 sizeof(u32)), 1613 sizeof(u32)),
1612 (void __user *) data); 1614 datavp);
1613 1615
1614 case PTRACE_SETVRREGS: 1616 case PTRACE_SETVRREGS:
1615 return copy_regset_from_user(child, &user_ppc_native_view, 1617 return copy_regset_from_user(child, &user_ppc_native_view,
1616 REGSET_VMX, 1618 REGSET_VMX,
1617 0, (33 * sizeof(vector128) + 1619 0, (33 * sizeof(vector128) +
1618 sizeof(u32)), 1620 sizeof(u32)),
1619 (const void __user *) data); 1621 datavp);
1620#endif 1622#endif
1621#ifdef CONFIG_VSX 1623#ifdef CONFIG_VSX
1622 case PTRACE_GETVSRREGS: 1624 case PTRACE_GETVSRREGS:
1623 return copy_regset_to_user(child, &user_ppc_native_view, 1625 return copy_regset_to_user(child, &user_ppc_native_view,
1624 REGSET_VSX, 1626 REGSET_VSX,
1625 0, 32 * sizeof(double), 1627 0, 32 * sizeof(double),
1626 (void __user *) data); 1628 datavp);
1627 1629
1628 case PTRACE_SETVSRREGS: 1630 case PTRACE_SETVSRREGS:
1629 return copy_regset_from_user(child, &user_ppc_native_view, 1631 return copy_regset_from_user(child, &user_ppc_native_view,
1630 REGSET_VSX, 1632 REGSET_VSX,
1631 0, 32 * sizeof(double), 1633 0, 32 * sizeof(double),
1632 (const void __user *) data); 1634 datavp);
1633#endif 1635#endif
1634#ifdef CONFIG_SPE 1636#ifdef CONFIG_SPE
1635 case PTRACE_GETEVRREGS: 1637 case PTRACE_GETEVRREGS:
1636 /* Get the child spe register state. */ 1638 /* Get the child spe register state. */
1637 return copy_regset_to_user(child, &user_ppc_native_view, 1639 return copy_regset_to_user(child, &user_ppc_native_view,
1638 REGSET_SPE, 0, 35 * sizeof(u32), 1640 REGSET_SPE, 0, 35 * sizeof(u32),
1639 (void __user *) data); 1641 datavp);
1640 1642
1641 case PTRACE_SETEVRREGS: 1643 case PTRACE_SETEVRREGS:
1642 /* Set the child spe register state. */ 1644 /* Set the child spe register state. */
1643 return copy_regset_from_user(child, &user_ppc_native_view, 1645 return copy_regset_from_user(child, &user_ppc_native_view,
1644 REGSET_SPE, 0, 35 * sizeof(u32), 1646 REGSET_SPE, 0, 35 * sizeof(u32),
1645 (const void __user *) data); 1647 datavp);
1646#endif 1648#endif
1647 1649
1648 /* Old reverse args ptrace callss */ 1650 /* Old reverse args ptrace callss */
diff --git a/arch/powerpc/mm/highmem.c b/arch/powerpc/mm/highmem.c
index b0848b462bbc..e7450bdbe83a 100644
--- a/arch/powerpc/mm/highmem.c
+++ b/arch/powerpc/mm/highmem.c
@@ -62,7 +62,7 @@ void __kunmap_atomic(void *kvaddr)
62 return; 62 return;
63 } 63 }
64 64
65 type = kmap_atomic_idx_pop(); 65 type = kmap_atomic_idx();
66 66
67#ifdef CONFIG_DEBUG_HIGHMEM 67#ifdef CONFIG_DEBUG_HIGHMEM
68 { 68 {
@@ -79,6 +79,8 @@ void __kunmap_atomic(void *kvaddr)
79 local_flush_tlb_page(NULL, vaddr); 79 local_flush_tlb_page(NULL, vaddr);
80 } 80 }
81#endif 81#endif
82
83 kmap_atomic_idx_pop();
82 pagefault_enable(); 84 pagefault_enable();
83} 85}
84EXPORT_SYMBOL(__kunmap_atomic); 86EXPORT_SYMBOL(__kunmap_atomic);
diff --git a/arch/powerpc/sysdev/fsl_rio.c b/arch/powerpc/sysdev/fsl_rio.c
index 412763672d23..9725369d432a 100644
--- a/arch/powerpc/sysdev/fsl_rio.c
+++ b/arch/powerpc/sysdev/fsl_rio.c
@@ -50,6 +50,7 @@
50#define RIO_ATMU_REGS_OFFSET 0x10c00 50#define RIO_ATMU_REGS_OFFSET 0x10c00
51#define RIO_P_MSG_REGS_OFFSET 0x11000 51#define RIO_P_MSG_REGS_OFFSET 0x11000
52#define RIO_S_MSG_REGS_OFFSET 0x13000 52#define RIO_S_MSG_REGS_OFFSET 0x13000
53#define RIO_GCCSR 0x13c
53#define RIO_ESCSR 0x158 54#define RIO_ESCSR 0x158
54#define RIO_CCSR 0x15c 55#define RIO_CCSR 0x15c
55#define RIO_LTLEDCSR 0x0608 56#define RIO_LTLEDCSR 0x0608
@@ -87,6 +88,9 @@
87#define RIO_IPWSR_PWD 0x00000008 88#define RIO_IPWSR_PWD 0x00000008
88#define RIO_IPWSR_PWB 0x00000004 89#define RIO_IPWSR_PWB 0x00000004
89 90
91#define RIO_EPWISR_PINT 0x80000000
92#define RIO_EPWISR_PW 0x00000001
93
90#define RIO_MSG_DESC_SIZE 32 94#define RIO_MSG_DESC_SIZE 32
91#define RIO_MSG_BUFFER_SIZE 4096 95#define RIO_MSG_BUFFER_SIZE 4096
92#define RIO_MIN_TX_RING_SIZE 2 96#define RIO_MIN_TX_RING_SIZE 2
@@ -1082,18 +1086,12 @@ fsl_rio_port_write_handler(int irq, void *dev_instance)
1082 struct rio_priv *priv = port->priv; 1086 struct rio_priv *priv = port->priv;
1083 u32 epwisr, tmp; 1087 u32 epwisr, tmp;
1084 1088
1085 ipwmr = in_be32(&priv->msg_regs->pwmr);
1086 ipwsr = in_be32(&priv->msg_regs->pwsr);
1087
1088 epwisr = in_be32(priv->regs_win + RIO_EPWISR); 1089 epwisr = in_be32(priv->regs_win + RIO_EPWISR);
1089 if (epwisr & 0x80000000) { 1090 if (!(epwisr & RIO_EPWISR_PW))
1090 tmp = in_be32(priv->regs_win + RIO_LTLEDCSR); 1091 goto pw_done;
1091 pr_info("RIO_LTLEDCSR = 0x%x\n", tmp);
1092 out_be32(priv->regs_win + RIO_LTLEDCSR, 0);
1093 }
1094 1092
1095 if (!(epwisr & 0x00000001)) 1093 ipwmr = in_be32(&priv->msg_regs->pwmr);
1096 return IRQ_HANDLED; 1094 ipwsr = in_be32(&priv->msg_regs->pwsr);
1097 1095
1098#ifdef DEBUG_PW 1096#ifdef DEBUG_PW
1099 pr_debug("PW Int->IPWMR: 0x%08x IPWSR: 0x%08x (", ipwmr, ipwsr); 1097 pr_debug("PW Int->IPWMR: 0x%08x IPWSR: 0x%08x (", ipwmr, ipwsr);
@@ -1109,20 +1107,6 @@ fsl_rio_port_write_handler(int irq, void *dev_instance)
1109 pr_debug(" PWB"); 1107 pr_debug(" PWB");
1110 pr_debug(" )\n"); 1108 pr_debug(" )\n");
1111#endif 1109#endif
1112 out_be32(&priv->msg_regs->pwsr,
1113 ipwsr & (RIO_IPWSR_TE | RIO_IPWSR_QFI | RIO_IPWSR_PWD));
1114
1115 if ((ipwmr & RIO_IPWMR_EIE) && (ipwsr & RIO_IPWSR_TE)) {
1116 priv->port_write_msg.err_count++;
1117 pr_info("RIO: Port-Write Transaction Err (%d)\n",
1118 priv->port_write_msg.err_count);
1119 }
1120 if (ipwsr & RIO_IPWSR_PWD) {
1121 priv->port_write_msg.discard_count++;
1122 pr_info("RIO: Port Discarded Port-Write Msg(s) (%d)\n",
1123 priv->port_write_msg.discard_count);
1124 }
1125
1126 /* Schedule deferred processing if PW was received */ 1110 /* Schedule deferred processing if PW was received */
1127 if (ipwsr & RIO_IPWSR_QFI) { 1111 if (ipwsr & RIO_IPWSR_QFI) {
1128 /* Save PW message (if there is room in FIFO), 1112 /* Save PW message (if there is room in FIFO),
@@ -1134,16 +1118,43 @@ fsl_rio_port_write_handler(int irq, void *dev_instance)
1134 RIO_PW_MSG_SIZE); 1118 RIO_PW_MSG_SIZE);
1135 } else { 1119 } else {
1136 priv->port_write_msg.discard_count++; 1120 priv->port_write_msg.discard_count++;
1137 pr_info("RIO: ISR Discarded Port-Write Msg(s) (%d)\n", 1121 pr_debug("RIO: ISR Discarded Port-Write Msg(s) (%d)\n",
1138 priv->port_write_msg.discard_count); 1122 priv->port_write_msg.discard_count);
1139 } 1123 }
1124 /* Clear interrupt and issue Clear Queue command. This allows
1125 * another port-write to be received.
1126 */
1127 out_be32(&priv->msg_regs->pwsr, RIO_IPWSR_QFI);
1128 out_be32(&priv->msg_regs->pwmr, ipwmr | RIO_IPWMR_CQ);
1129
1140 schedule_work(&priv->pw_work); 1130 schedule_work(&priv->pw_work);
1141 } 1131 }
1142 1132
1143 /* Issue Clear Queue command. This allows another 1133 if ((ipwmr & RIO_IPWMR_EIE) && (ipwsr & RIO_IPWSR_TE)) {
1144 * port-write to be received. 1134 priv->port_write_msg.err_count++;
1145 */ 1135 pr_debug("RIO: Port-Write Transaction Err (%d)\n",
1146 out_be32(&priv->msg_regs->pwmr, ipwmr | RIO_IPWMR_CQ); 1136 priv->port_write_msg.err_count);
1137 /* Clear Transaction Error: port-write controller should be
1138 * disabled when clearing this error
1139 */
1140 out_be32(&priv->msg_regs->pwmr, ipwmr & ~RIO_IPWMR_PWE);
1141 out_be32(&priv->msg_regs->pwsr, RIO_IPWSR_TE);
1142 out_be32(&priv->msg_regs->pwmr, ipwmr);
1143 }
1144
1145 if (ipwsr & RIO_IPWSR_PWD) {
1146 priv->port_write_msg.discard_count++;
1147 pr_debug("RIO: Port Discarded Port-Write Msg(s) (%d)\n",
1148 priv->port_write_msg.discard_count);
1149 out_be32(&priv->msg_regs->pwsr, RIO_IPWSR_PWD);
1150 }
1151
1152pw_done:
1153 if (epwisr & RIO_EPWISR_PINT) {
1154 tmp = in_be32(priv->regs_win + RIO_LTLEDCSR);
1155 pr_debug("RIO_LTLEDCSR = 0x%x\n", tmp);
1156 out_be32(priv->regs_win + RIO_LTLEDCSR, 0);
1157 }
1147 1158
1148 return IRQ_HANDLED; 1159 return IRQ_HANDLED;
1149} 1160}
@@ -1461,6 +1472,7 @@ int fsl_rio_setup(struct platform_device *dev)
1461 port->host_deviceid = fsl_rio_get_hdid(port->id); 1472 port->host_deviceid = fsl_rio_get_hdid(port->id);
1462 1473
1463 port->priv = priv; 1474 port->priv = priv;
1475 port->phys_efptr = 0x100;
1464 rio_register_mport(port); 1476 rio_register_mport(port);
1465 1477
1466 priv->regs_win = ioremap(regs.start, regs.end - regs.start + 1); 1478 priv->regs_win = ioremap(regs.start, regs.end - regs.start + 1);
@@ -1508,6 +1520,12 @@ int fsl_rio_setup(struct platform_device *dev)
1508 dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n", 1520 dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n",
1509 port->sys_size ? 65536 : 256); 1521 port->sys_size ? 65536 : 256);
1510 1522
1523 if (port->host_deviceid >= 0)
1524 out_be32(priv->regs_win + RIO_GCCSR, RIO_PORT_GEN_HOST |
1525 RIO_PORT_GEN_MASTER | RIO_PORT_GEN_DISCOVERED);
1526 else
1527 out_be32(priv->regs_win + RIO_GCCSR, 0x00000000);
1528
1511 priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win 1529 priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win
1512 + RIO_ATMU_REGS_OFFSET); 1530 + RIO_ATMU_REGS_OFFSET);
1513 priv->maint_atmu_regs = priv->atmu_regs + 1; 1531 priv->maint_atmu_regs = priv->atmu_regs + 1;
diff --git a/arch/s390/include/asm/cputime.h b/arch/s390/include/asm/cputime.h
index 8b1a52a137c5..40e2ab0fa3f0 100644
--- a/arch/s390/include/asm/cputime.h
+++ b/arch/s390/include/asm/cputime.h
@@ -73,18 +73,18 @@ cputime64_to_jiffies64(cputime64_t cputime)
73} 73}
74 74
75/* 75/*
76 * Convert cputime to milliseconds and back. 76 * Convert cputime to microseconds and back.
77 */ 77 */
78static inline unsigned int 78static inline unsigned int
79cputime_to_msecs(const cputime_t cputime) 79cputime_to_usecs(const cputime_t cputime)
80{ 80{
81 return cputime_div(cputime, 4096000); 81 return cputime_div(cputime, 4096);
82} 82}
83 83
84static inline cputime_t 84static inline cputime_t
85msecs_to_cputime(const unsigned int m) 85usecs_to_cputime(const unsigned int m)
86{ 86{
87 return (cputime_t) m * 4096000; 87 return (cputime_t) m * 4096;
88} 88}
89 89
90/* 90/*
diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c
index 83339d33c4b1..019bb714db49 100644
--- a/arch/s390/kernel/ptrace.c
+++ b/arch/s390/kernel/ptrace.c
@@ -343,7 +343,8 @@ poke_user(struct task_struct *child, addr_t addr, addr_t data)
343 return __poke_user(child, addr, data); 343 return __poke_user(child, addr, data);
344} 344}
345 345
346long arch_ptrace(struct task_struct *child, long request, long addr, long data) 346long arch_ptrace(struct task_struct *child, long request,
347 unsigned long addr, unsigned long data)
347{ 348{
348 ptrace_area parea; 349 ptrace_area parea;
349 int copied, ret; 350 int copied, ret;
diff --git a/arch/score/kernel/ptrace.c b/arch/score/kernel/ptrace.c
index 174c6422b096..55836188b217 100644
--- a/arch/score/kernel/ptrace.c
+++ b/arch/score/kernel/ptrace.c
@@ -325,7 +325,8 @@ void ptrace_disable(struct task_struct *child)
325} 325}
326 326
327long 327long
328arch_ptrace(struct task_struct *child, long request, long addr, long data) 328arch_ptrace(struct task_struct *child, long request,
329 unsigned long addr, unsigned long data)
329{ 330{
330 int ret; 331 int ret;
331 unsigned long __user *datap = (void __user *)data; 332 unsigned long __user *datap = (void __user *)data;
@@ -335,14 +336,14 @@ arch_ptrace(struct task_struct *child, long request, long addr, long data)
335 ret = copy_regset_to_user(child, &user_score_native_view, 336 ret = copy_regset_to_user(child, &user_score_native_view,
336 REGSET_GENERAL, 337 REGSET_GENERAL,
337 0, sizeof(struct pt_regs), 338 0, sizeof(struct pt_regs),
338 (void __user *)datap); 339 datap);
339 break; 340 break;
340 341
341 case PTRACE_SETREGS: 342 case PTRACE_SETREGS:
342 ret = copy_regset_from_user(child, &user_score_native_view, 343 ret = copy_regset_from_user(child, &user_score_native_view,
343 REGSET_GENERAL, 344 REGSET_GENERAL,
344 0, sizeof(struct pt_regs), 345 0, sizeof(struct pt_regs),
345 (const void __user *)datap); 346 datap);
346 break; 347 break;
347 348
348 default: 349 default:
diff --git a/arch/sh/kernel/ptrace_32.c b/arch/sh/kernel/ptrace_32.c
index 2cd42b58cb20..90a15d29feeb 100644
--- a/arch/sh/kernel/ptrace_32.c
+++ b/arch/sh/kernel/ptrace_32.c
@@ -365,9 +365,9 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
365 return &user_sh_native_view; 365 return &user_sh_native_view;
366} 366}
367 367
368long arch_ptrace(struct task_struct *child, long request, long addr, long data) 368long arch_ptrace(struct task_struct *child, long request,
369 unsigned long addr, unsigned long data)
369{ 370{
370 struct user * dummy = NULL;
371 unsigned long __user *datap = (unsigned long __user *)data; 371 unsigned long __user *datap = (unsigned long __user *)data;
372 int ret; 372 int ret;
373 373
@@ -383,17 +383,20 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
383 383
384 if (addr < sizeof(struct pt_regs)) 384 if (addr < sizeof(struct pt_regs))
385 tmp = get_stack_long(child, addr); 385 tmp = get_stack_long(child, addr);
386 else if (addr >= (long) &dummy->fpu && 386 else if (addr >= offsetof(struct user, fpu) &&
387 addr < (long) &dummy->u_fpvalid) { 387 addr < offsetof(struct user, u_fpvalid)) {
388 if (!tsk_used_math(child)) { 388 if (!tsk_used_math(child)) {
389 if (addr == (long)&dummy->fpu.fpscr) 389 if (addr == offsetof(struct user, fpu.fpscr))
390 tmp = FPSCR_INIT; 390 tmp = FPSCR_INIT;
391 else 391 else
392 tmp = 0; 392 tmp = 0;
393 } else 393 } else {
394 tmp = ((long *)child->thread.xstate) 394 unsigned long index;
395 [(addr - (long)&dummy->fpu) >> 2]; 395 index = addr - offsetof(struct user, fpu);
396 } else if (addr == (long) &dummy->u_fpvalid) 396 tmp = ((unsigned long *)child->thread.xstate)
397 [index >> 2];
398 }
399 } else if (addr == offsetof(struct user, u_fpvalid))
397 tmp = !!tsk_used_math(child); 400 tmp = !!tsk_used_math(child);
398 else if (addr == PT_TEXT_ADDR) 401 else if (addr == PT_TEXT_ADDR)
399 tmp = child->mm->start_code; 402 tmp = child->mm->start_code;
@@ -417,13 +420,15 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
417 420
418 if (addr < sizeof(struct pt_regs)) 421 if (addr < sizeof(struct pt_regs))
419 ret = put_stack_long(child, addr, data); 422 ret = put_stack_long(child, addr, data);
420 else if (addr >= (long) &dummy->fpu && 423 else if (addr >= offsetof(struct user, fpu) &&
421 addr < (long) &dummy->u_fpvalid) { 424 addr < offsetof(struct user, u_fpvalid)) {
425 unsigned long index;
426 index = addr - offsetof(struct user, fpu);
422 set_stopped_child_used_math(child); 427 set_stopped_child_used_math(child);
423 ((long *)child->thread.xstate) 428 ((unsigned long *)child->thread.xstate)
424 [(addr - (long)&dummy->fpu) >> 2] = data; 429 [index >> 2] = data;
425 ret = 0; 430 ret = 0;
426 } else if (addr == (long) &dummy->u_fpvalid) { 431 } else if (addr == offsetof(struct user, u_fpvalid)) {
427 conditional_stopped_child_used_math(data, child); 432 conditional_stopped_child_used_math(data, child);
428 ret = 0; 433 ret = 0;
429 } 434 }
@@ -433,35 +438,35 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
433 return copy_regset_to_user(child, &user_sh_native_view, 438 return copy_regset_to_user(child, &user_sh_native_view,
434 REGSET_GENERAL, 439 REGSET_GENERAL,
435 0, sizeof(struct pt_regs), 440 0, sizeof(struct pt_regs),
436 (void __user *)data); 441 datap);
437 case PTRACE_SETREGS: 442 case PTRACE_SETREGS:
438 return copy_regset_from_user(child, &user_sh_native_view, 443 return copy_regset_from_user(child, &user_sh_native_view,
439 REGSET_GENERAL, 444 REGSET_GENERAL,
440 0, sizeof(struct pt_regs), 445 0, sizeof(struct pt_regs),
441 (const void __user *)data); 446 datap);
442#ifdef CONFIG_SH_FPU 447#ifdef CONFIG_SH_FPU
443 case PTRACE_GETFPREGS: 448 case PTRACE_GETFPREGS:
444 return copy_regset_to_user(child, &user_sh_native_view, 449 return copy_regset_to_user(child, &user_sh_native_view,
445 REGSET_FPU, 450 REGSET_FPU,
446 0, sizeof(struct user_fpu_struct), 451 0, sizeof(struct user_fpu_struct),
447 (void __user *)data); 452 datap);
448 case PTRACE_SETFPREGS: 453 case PTRACE_SETFPREGS:
449 return copy_regset_from_user(child, &user_sh_native_view, 454 return copy_regset_from_user(child, &user_sh_native_view,
450 REGSET_FPU, 455 REGSET_FPU,
451 0, sizeof(struct user_fpu_struct), 456 0, sizeof(struct user_fpu_struct),
452 (const void __user *)data); 457 datap);
453#endif 458#endif
454#ifdef CONFIG_SH_DSP 459#ifdef CONFIG_SH_DSP
455 case PTRACE_GETDSPREGS: 460 case PTRACE_GETDSPREGS:
456 return copy_regset_to_user(child, &user_sh_native_view, 461 return copy_regset_to_user(child, &user_sh_native_view,
457 REGSET_DSP, 462 REGSET_DSP,
458 0, sizeof(struct pt_dspregs), 463 0, sizeof(struct pt_dspregs),
459 (void __user *)data); 464 datap);
460 case PTRACE_SETDSPREGS: 465 case PTRACE_SETDSPREGS:
461 return copy_regset_from_user(child, &user_sh_native_view, 466 return copy_regset_from_user(child, &user_sh_native_view,
462 REGSET_DSP, 467 REGSET_DSP,
463 0, sizeof(struct pt_dspregs), 468 0, sizeof(struct pt_dspregs),
464 (const void __user *)data); 469 datap);
465#endif 470#endif
466 default: 471 default:
467 ret = ptrace_request(child, request, addr, data); 472 ret = ptrace_request(child, request, addr, data);
diff --git a/arch/sh/kernel/ptrace_64.c b/arch/sh/kernel/ptrace_64.c
index e0fb065914aa..4436eacddb15 100644
--- a/arch/sh/kernel/ptrace_64.c
+++ b/arch/sh/kernel/ptrace_64.c
@@ -383,9 +383,11 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
383 return &user_sh64_native_view; 383 return &user_sh64_native_view;
384} 384}
385 385
386long arch_ptrace(struct task_struct *child, long request, long addr, long data) 386long arch_ptrace(struct task_struct *child, long request,
387 unsigned long addr, unsigned long data)
387{ 388{
388 int ret; 389 int ret;
390 unsigned long __user *datap = (unsigned long __user *) data;
389 391
390 switch (request) { 392 switch (request) {
391 /* read the word at location addr in the USER area. */ 393 /* read the word at location addr in the USER area. */
@@ -400,13 +402,15 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
400 tmp = get_stack_long(child, addr); 402 tmp = get_stack_long(child, addr);
401 else if ((addr >= offsetof(struct user, fpu)) && 403 else if ((addr >= offsetof(struct user, fpu)) &&
402 (addr < offsetof(struct user, u_fpvalid))) { 404 (addr < offsetof(struct user, u_fpvalid))) {
403 tmp = get_fpu_long(child, addr - offsetof(struct user, fpu)); 405 unsigned long index;
406 index = addr - offsetof(struct user, fpu);
407 tmp = get_fpu_long(child, index);
404 } else if (addr == offsetof(struct user, u_fpvalid)) { 408 } else if (addr == offsetof(struct user, u_fpvalid)) {
405 tmp = !!tsk_used_math(child); 409 tmp = !!tsk_used_math(child);
406 } else { 410 } else {
407 break; 411 break;
408 } 412 }
409 ret = put_user(tmp, (unsigned long *)data); 413 ret = put_user(tmp, datap);
410 break; 414 break;
411 } 415 }
412 416
@@ -437,7 +441,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
437 } 441 }
438 else if ((addr >= offsetof(struct user, fpu)) && 442 else if ((addr >= offsetof(struct user, fpu)) &&
439 (addr < offsetof(struct user, u_fpvalid))) { 443 (addr < offsetof(struct user, u_fpvalid))) {
440 ret = put_fpu_long(child, addr - offsetof(struct user, fpu), data); 444 unsigned long index;
445 index = addr - offsetof(struct user, fpu);
446 ret = put_fpu_long(child, index, data);
441 } 447 }
442 break; 448 break;
443 449
@@ -445,23 +451,23 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
445 return copy_regset_to_user(child, &user_sh64_native_view, 451 return copy_regset_to_user(child, &user_sh64_native_view,
446 REGSET_GENERAL, 452 REGSET_GENERAL,
447 0, sizeof(struct pt_regs), 453 0, sizeof(struct pt_regs),
448 (void __user *)data); 454 datap);
449 case PTRACE_SETREGS: 455 case PTRACE_SETREGS:
450 return copy_regset_from_user(child, &user_sh64_native_view, 456 return copy_regset_from_user(child, &user_sh64_native_view,
451 REGSET_GENERAL, 457 REGSET_GENERAL,
452 0, sizeof(struct pt_regs), 458 0, sizeof(struct pt_regs),
453 (const void __user *)data); 459 datap);
454#ifdef CONFIG_SH_FPU 460#ifdef CONFIG_SH_FPU
455 case PTRACE_GETFPREGS: 461 case PTRACE_GETFPREGS:
456 return copy_regset_to_user(child, &user_sh64_native_view, 462 return copy_regset_to_user(child, &user_sh64_native_view,
457 REGSET_FPU, 463 REGSET_FPU,
458 0, sizeof(struct user_fpu_struct), 464 0, sizeof(struct user_fpu_struct),
459 (void __user *)data); 465 datap);
460 case PTRACE_SETFPREGS: 466 case PTRACE_SETFPREGS:
461 return copy_regset_from_user(child, &user_sh64_native_view, 467 return copy_regset_from_user(child, &user_sh64_native_view,
462 REGSET_FPU, 468 REGSET_FPU,
463 0, sizeof(struct user_fpu_struct), 469 0, sizeof(struct user_fpu_struct),
464 (const void __user *)data); 470 datap);
465#endif 471#endif
466 default: 472 default:
467 ret = ptrace_request(child, request, addr, data); 473 ret = ptrace_request(child, request, addr, data);
@@ -471,7 +477,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
471 return ret; 477 return ret;
472} 478}
473 479
474asmlinkage int sh64_ptrace(long request, long pid, long addr, long data) 480asmlinkage int sh64_ptrace(long request, long pid,
481 unsigned long addr, unsigned long data)
475{ 482{
476#define WPC_DBRMODE 0x0d104008 483#define WPC_DBRMODE 0x0d104008
477 static unsigned long first_call; 484 static unsigned long first_call;
diff --git a/arch/sparc/include/asm/io_32.h b/arch/sparc/include/asm/io_32.h
index 2889574608db..c2ced21c9dc1 100644
--- a/arch/sparc/include/asm/io_32.h
+++ b/arch/sparc/include/asm/io_32.h
@@ -208,6 +208,21 @@ _memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
208#define memset_io(d,c,sz) _memset_io(d,c,sz) 208#define memset_io(d,c,sz) _memset_io(d,c,sz)
209 209
210static inline void 210static inline void
211_sbus_memcpy_fromio(void *dst, const volatile void __iomem *src,
212 __kernel_size_t n)
213{
214 char *d = dst;
215
216 while (n--) {
217 char tmp = sbus_readb(src);
218 *d++ = tmp;
219 src++;
220 }
221}
222
223#define sbus_memcpy_fromio(d, s, sz) _sbus_memcpy_fromio(d, s, sz)
224
225static inline void
211_memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n) 226_memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
212{ 227{
213 char *d = dst; 228 char *d = dst;
@@ -222,6 +237,22 @@ _memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
222#define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz) 237#define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
223 238
224static inline void 239static inline void
240_sbus_memcpy_toio(volatile void __iomem *dst, const void *src,
241 __kernel_size_t n)
242{
243 const char *s = src;
244 volatile void __iomem *d = dst;
245
246 while (n--) {
247 char tmp = *s++;
248 sbus_writeb(tmp, d);
249 d++;
250 }
251}
252
253#define sbus_memcpy_toio(d, s, sz) _sbus_memcpy_toio(d, s, sz)
254
255static inline void
225_memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n) 256_memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n)
226{ 257{
227 const char *s = src; 258 const char *s = src;
diff --git a/arch/sparc/include/asm/io_64.h b/arch/sparc/include/asm/io_64.h
index 9517d063c79c..9c8965415f0a 100644
--- a/arch/sparc/include/asm/io_64.h
+++ b/arch/sparc/include/asm/io_64.h
@@ -419,6 +419,21 @@ _memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
419#define memset_io(d,c,sz) _memset_io(d,c,sz) 419#define memset_io(d,c,sz) _memset_io(d,c,sz)
420 420
421static inline void 421static inline void
422_sbus_memcpy_fromio(void *dst, const volatile void __iomem *src,
423 __kernel_size_t n)
424{
425 char *d = dst;
426
427 while (n--) {
428 char tmp = sbus_readb(src);
429 *d++ = tmp;
430 src++;
431 }
432}
433
434#define sbus_memcpy_fromio(d, s, sz) _sbus_memcpy_fromio(d, s, sz)
435
436static inline void
422_memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n) 437_memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
423{ 438{
424 char *d = dst; 439 char *d = dst;
@@ -433,6 +448,22 @@ _memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
433#define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz) 448#define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
434 449
435static inline void 450static inline void
451_sbus_memcpy_toio(volatile void __iomem *dst, const void *src,
452 __kernel_size_t n)
453{
454 const char *s = src;
455 volatile void __iomem *d = dst;
456
457 while (n--) {
458 char tmp = *s++;
459 sbus_writeb(tmp, d);
460 d++;
461 }
462}
463
464#define sbus_memcpy_toio(d, s, sz) _sbus_memcpy_toio(d, s, sz)
465
466static inline void
436_memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n) 467_memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n)
437{ 468{
438 const char *s = src; 469 const char *s = src;
diff --git a/arch/sparc/include/asm/pci_64.h b/arch/sparc/include/asm/pci_64.h
index 5312782f0b5e..948b686ec089 100644
--- a/arch/sparc/include/asm/pci_64.h
+++ b/arch/sparc/include/asm/pci_64.h
@@ -38,7 +38,7 @@ static inline void pcibios_penalize_isa_irq(int irq, int active)
38 * types on sparc64. However, it requires that the device 38 * types on sparc64. However, it requires that the device
39 * can drive enough of the 64 bits. 39 * can drive enough of the 64 bits.
40 */ 40 */
41#define PCI64_REQUIRED_MASK (~(dma64_addr_t)0) 41#define PCI64_REQUIRED_MASK (~(u64)0)
42#define PCI64_ADDR_BASE 0xfffc000000000000UL 42#define PCI64_ADDR_BASE 0xfffc000000000000UL
43 43
44#ifdef CONFIG_PCI 44#ifdef CONFIG_PCI
diff --git a/arch/sparc/kernel/ptrace_32.c b/arch/sparc/kernel/ptrace_32.c
index e608f397e11f..27b9e93d0121 100644
--- a/arch/sparc/kernel/ptrace_32.c
+++ b/arch/sparc/kernel/ptrace_32.c
@@ -323,18 +323,35 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
323 return &user_sparc32_view; 323 return &user_sparc32_view;
324} 324}
325 325
326long arch_ptrace(struct task_struct *child, long request, long addr, long data) 326struct fps {
327 unsigned long regs[32];
328 unsigned long fsr;
329 unsigned long flags;
330 unsigned long extra;
331 unsigned long fpqd;
332 struct fq {
333 unsigned long *insnaddr;
334 unsigned long insn;
335 } fpq[16];
336};
337
338long arch_ptrace(struct task_struct *child, long request,
339 unsigned long addr, unsigned long data)
327{ 340{
328 unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4]; 341 unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4];
342 void __user *addr2p;
329 const struct user_regset_view *view; 343 const struct user_regset_view *view;
344 struct pt_regs __user *pregs;
345 struct fps __user *fps;
330 int ret; 346 int ret;
331 347
332 view = task_user_regset_view(current); 348 view = task_user_regset_view(current);
349 addr2p = (void __user *) addr2;
350 pregs = (struct pt_regs __user *) addr;
351 fps = (struct fps __user *) addr;
333 352
334 switch(request) { 353 switch(request) {
335 case PTRACE_GETREGS: { 354 case PTRACE_GETREGS: {
336 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
337
338 ret = copy_regset_to_user(child, view, REGSET_GENERAL, 355 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
339 32 * sizeof(u32), 356 32 * sizeof(u32),
340 4 * sizeof(u32), 357 4 * sizeof(u32),
@@ -348,8 +365,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
348 } 365 }
349 366
350 case PTRACE_SETREGS: { 367 case PTRACE_SETREGS: {
351 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
352
353 ret = copy_regset_from_user(child, view, REGSET_GENERAL, 368 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
354 32 * sizeof(u32), 369 32 * sizeof(u32),
355 4 * sizeof(u32), 370 4 * sizeof(u32),
@@ -363,19 +378,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
363 } 378 }
364 379
365 case PTRACE_GETFPREGS: { 380 case PTRACE_GETFPREGS: {
366 struct fps {
367 unsigned long regs[32];
368 unsigned long fsr;
369 unsigned long flags;
370 unsigned long extra;
371 unsigned long fpqd;
372 struct fq {
373 unsigned long *insnaddr;
374 unsigned long insn;
375 } fpq[16];
376 };
377 struct fps __user *fps = (struct fps __user *) addr;
378
379 ret = copy_regset_to_user(child, view, REGSET_FP, 381 ret = copy_regset_to_user(child, view, REGSET_FP,
380 0 * sizeof(u32), 382 0 * sizeof(u32),
381 32 * sizeof(u32), 383 32 * sizeof(u32),
@@ -397,19 +399,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
397 } 399 }
398 400
399 case PTRACE_SETFPREGS: { 401 case PTRACE_SETFPREGS: {
400 struct fps {
401 unsigned long regs[32];
402 unsigned long fsr;
403 unsigned long flags;
404 unsigned long extra;
405 unsigned long fpqd;
406 struct fq {
407 unsigned long *insnaddr;
408 unsigned long insn;
409 } fpq[16];
410 };
411 struct fps __user *fps = (struct fps __user *) addr;
412
413 ret = copy_regset_from_user(child, view, REGSET_FP, 402 ret = copy_regset_from_user(child, view, REGSET_FP,
414 0 * sizeof(u32), 403 0 * sizeof(u32),
415 32 * sizeof(u32), 404 32 * sizeof(u32),
@@ -424,8 +413,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
424 413
425 case PTRACE_READTEXT: 414 case PTRACE_READTEXT:
426 case PTRACE_READDATA: 415 case PTRACE_READDATA:
427 ret = ptrace_readdata(child, addr, 416 ret = ptrace_readdata(child, addr, addr2p, data);
428 (void __user *) addr2, data);
429 417
430 if (ret == data) 418 if (ret == data)
431 ret = 0; 419 ret = 0;
@@ -435,8 +423,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
435 423
436 case PTRACE_WRITETEXT: 424 case PTRACE_WRITETEXT:
437 case PTRACE_WRITEDATA: 425 case PTRACE_WRITEDATA:
438 ret = ptrace_writedata(child, (void __user *) addr2, 426 ret = ptrace_writedata(child, addr2p, addr, data);
439 addr, data);
440 427
441 if (ret == data) 428 if (ret == data)
442 ret = 0; 429 ret = 0;
diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
index aa90da08bf61..9ccc812bc09e 100644
--- a/arch/sparc/kernel/ptrace_64.c
+++ b/arch/sparc/kernel/ptrace_64.c
@@ -969,16 +969,19 @@ struct fps {
969 unsigned long fsr; 969 unsigned long fsr;
970}; 970};
971 971
972long arch_ptrace(struct task_struct *child, long request, long addr, long data) 972long arch_ptrace(struct task_struct *child, long request,
973 unsigned long addr, unsigned long data)
973{ 974{
974 const struct user_regset_view *view = task_user_regset_view(current); 975 const struct user_regset_view *view = task_user_regset_view(current);
975 unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4]; 976 unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
976 struct pt_regs __user *pregs; 977 struct pt_regs __user *pregs;
977 struct fps __user *fps; 978 struct fps __user *fps;
979 void __user *addr2p;
978 int ret; 980 int ret;
979 981
980 pregs = (struct pt_regs __user *) (unsigned long) addr; 982 pregs = (struct pt_regs __user *) addr;
981 fps = (struct fps __user *) (unsigned long) addr; 983 fps = (struct fps __user *) addr;
984 addr2p = (void __user *) addr2;
982 985
983 switch (request) { 986 switch (request) {
984 case PTRACE_PEEKUSR: 987 case PTRACE_PEEKUSR:
@@ -1029,8 +1032,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1029 1032
1030 case PTRACE_READTEXT: 1033 case PTRACE_READTEXT:
1031 case PTRACE_READDATA: 1034 case PTRACE_READDATA:
1032 ret = ptrace_readdata(child, addr, 1035 ret = ptrace_readdata(child, addr, addr2p, data);
1033 (char __user *)addr2, data);
1034 if (ret == data) 1036 if (ret == data)
1035 ret = 0; 1037 ret = 0;
1036 else if (ret >= 0) 1038 else if (ret >= 0)
@@ -1039,8 +1041,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1039 1041
1040 case PTRACE_WRITETEXT: 1042 case PTRACE_WRITETEXT:
1041 case PTRACE_WRITEDATA: 1043 case PTRACE_WRITEDATA:
1042 ret = ptrace_writedata(child, (char __user *) addr2, 1044 ret = ptrace_writedata(child, addr2p, addr, data);
1043 addr, data);
1044 if (ret == data) 1045 if (ret == data)
1045 ret = 0; 1046 ret = 0;
1046 else if (ret >= 0) 1047 else if (ret >= 0)
diff --git a/arch/sparc/mm/highmem.c b/arch/sparc/mm/highmem.c
index 5e50c09b7dce..4730eac0747b 100644
--- a/arch/sparc/mm/highmem.c
+++ b/arch/sparc/mm/highmem.c
@@ -75,7 +75,7 @@ void __kunmap_atomic(void *kvaddr)
75 return; 75 return;
76 } 76 }
77 77
78 type = kmap_atomic_idx_pop(); 78 type = kmap_atomic_idx();
79 79
80#ifdef CONFIG_DEBUG_HIGHMEM 80#ifdef CONFIG_DEBUG_HIGHMEM
81 { 81 {
@@ -104,6 +104,8 @@ void __kunmap_atomic(void *kvaddr)
104#endif 104#endif
105 } 105 }
106#endif 106#endif
107
108 kmap_atomic_idx_pop();
107 pagefault_enable(); 109 pagefault_enable();
108} 110}
109EXPORT_SYMBOL(__kunmap_atomic); 111EXPORT_SYMBOL(__kunmap_atomic);
diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
index 89cfee07efa9..7e8c2844e093 100644
--- a/arch/tile/Kconfig
+++ b/arch/tile/Kconfig
@@ -58,6 +58,9 @@ config ARCH_SUPPORTS_OPTIMIZED_INLINING
58config ARCH_PHYS_ADDR_T_64BIT 58config ARCH_PHYS_ADDR_T_64BIT
59 def_bool y 59 def_bool y
60 60
61config ARCH_DMA_ADDR_T_64BIT
62 def_bool y
63
61config LOCKDEP_SUPPORT 64config LOCKDEP_SUPPORT
62 def_bool y 65 def_bool y
63 66
diff --git a/arch/tile/kernel/ptrace.c b/arch/tile/kernel/ptrace.c
index 5b20c2874d51..9cd29884c09f 100644
--- a/arch/tile/kernel/ptrace.c
+++ b/arch/tile/kernel/ptrace.c
@@ -45,7 +45,8 @@ void ptrace_disable(struct task_struct *child)
45 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); 45 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
46} 46}
47 47
48long arch_ptrace(struct task_struct *child, long request, long addr, long data) 48long arch_ptrace(struct task_struct *child, long request,
49 unsigned long addr, unsigned long data)
49{ 50{
50 unsigned long __user *datap = (long __user __force *)data; 51 unsigned long __user *datap = (long __user __force *)data;
51 unsigned long tmp; 52 unsigned long tmp;
@@ -57,7 +58,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
57 switch (request) { 58 switch (request) {
58 59
59 case PTRACE_PEEKUSR: /* Read register from pt_regs. */ 60 case PTRACE_PEEKUSR: /* Read register from pt_regs. */
60 if (addr < 0 || addr >= PTREGS_SIZE) 61 if (addr >= PTREGS_SIZE)
61 break; 62 break;
62 childreg = (char *)task_pt_regs(child) + addr; 63 childreg = (char *)task_pt_regs(child) + addr;
63#ifdef CONFIG_COMPAT 64#ifdef CONFIG_COMPAT
@@ -76,7 +77,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
76 break; 77 break;
77 78
78 case PTRACE_POKEUSR: /* Write register in pt_regs. */ 79 case PTRACE_POKEUSR: /* Write register in pt_regs. */
79 if (addr < 0 || addr >= PTREGS_SIZE) 80 if (addr >= PTREGS_SIZE)
80 break; 81 break;
81 childreg = (char *)task_pt_regs(child) + addr; 82 childreg = (char *)task_pt_regs(child) + addr;
82#ifdef CONFIG_COMPAT 83#ifdef CONFIG_COMPAT
@@ -98,7 +99,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
98 if (!access_ok(VERIFY_WRITE, datap, PTREGS_SIZE)) 99 if (!access_ok(VERIFY_WRITE, datap, PTREGS_SIZE))
99 break; 100 break;
100 childregs = (long *)task_pt_regs(child); 101 childregs = (long *)task_pt_regs(child);
101 for (i = 0; i < sizeof(struct pt_regs)/sizeof(long); ++i) { 102 for (i = 0; i < sizeof(struct pt_regs)/sizeof(unsigned long);
103 ++i) {
102 ret = __put_user(childregs[i], &datap[i]); 104 ret = __put_user(childregs[i], &datap[i]);
103 if (ret != 0) 105 if (ret != 0)
104 break; 106 break;
@@ -109,7 +111,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
109 if (!access_ok(VERIFY_READ, datap, PTREGS_SIZE)) 111 if (!access_ok(VERIFY_READ, datap, PTREGS_SIZE))
110 break; 112 break;
111 childregs = (long *)task_pt_regs(child); 113 childregs = (long *)task_pt_regs(child);
112 for (i = 0; i < sizeof(struct pt_regs)/sizeof(long); ++i) { 114 for (i = 0; i < sizeof(struct pt_regs)/sizeof(unsigned long);
115 ++i) {
113 ret = __get_user(childregs[i], &datap[i]); 116 ret = __get_user(childregs[i], &datap[i]);
114 if (ret != 0) 117 if (ret != 0)
115 break; 118 break;
diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
index f3a50e74f9a4..ae51cad12da0 100644
--- a/arch/tile/kernel/setup.c
+++ b/arch/tile/kernel/setup.c
@@ -30,8 +30,6 @@
30#include <linux/timex.h> 30#include <linux/timex.h>
31#include <asm/setup.h> 31#include <asm/setup.h>
32#include <asm/sections.h> 32#include <asm/sections.h>
33#include <asm/sections.h>
34#include <asm/cacheflush.h>
35#include <asm/cacheflush.h> 33#include <asm/cacheflush.h>
36#include <asm/pgalloc.h> 34#include <asm/pgalloc.h>
37#include <asm/mmu_context.h> 35#include <asm/mmu_context.h>
diff --git a/arch/tile/mm/highmem.c b/arch/tile/mm/highmem.c
index 8ef6595e162c..abb57331cf6e 100644
--- a/arch/tile/mm/highmem.c
+++ b/arch/tile/mm/highmem.c
@@ -241,7 +241,7 @@ void __kunmap_atomic(void *kvaddr)
241 pte_t pteval = *pte; 241 pte_t pteval = *pte;
242 int idx, type; 242 int idx, type;
243 243
244 type = kmap_atomic_idx_pop(); 244 type = kmap_atomic_idx();
245 idx = type + KM_TYPE_NR*smp_processor_id(); 245 idx = type + KM_TYPE_NR*smp_processor_id();
246 246
247 /* 247 /*
@@ -252,6 +252,7 @@ void __kunmap_atomic(void *kvaddr)
252 BUG_ON(!pte_present(pteval) && !pte_migrating(pteval)); 252 BUG_ON(!pte_present(pteval) && !pte_migrating(pteval));
253 kmap_atomic_unregister(pte_page(pteval), vaddr); 253 kmap_atomic_unregister(pte_page(pteval), vaddr);
254 kpte_clear_flush(pte, vaddr); 254 kpte_clear_flush(pte, vaddr);
255 kmap_atomic_idx_pop();
255 } else { 256 } else {
256 /* Must be a lowmem page */ 257 /* Must be a lowmem page */
257 BUG_ON(vaddr < PAGE_OFFSET); 258 BUG_ON(vaddr < PAGE_OFFSET);
diff --git a/arch/um/kernel/ptrace.c b/arch/um/kernel/ptrace.c
index e0510496596c..a5e33f29bbeb 100644
--- a/arch/um/kernel/ptrace.c
+++ b/arch/um/kernel/ptrace.c
@@ -42,10 +42,12 @@ void ptrace_disable(struct task_struct *child)
42extern int peek_user(struct task_struct * child, long addr, long data); 42extern int peek_user(struct task_struct * child, long addr, long data);
43extern int poke_user(struct task_struct * child, long addr, long data); 43extern int poke_user(struct task_struct * child, long addr, long data);
44 44
45long arch_ptrace(struct task_struct *child, long request, long addr, long data) 45long arch_ptrace(struct task_struct *child, long request,
46 unsigned long addr, unsigned long data)
46{ 47{
47 int i, ret; 48 int i, ret;
48 unsigned long __user *p = (void __user *)(unsigned long)data; 49 unsigned long __user *p = (void __user *)data;
50 void __user *vp = p;
49 51
50 switch (request) { 52 switch (request) {
51 /* read word at location addr. */ 53 /* read word at location addr. */
@@ -107,24 +109,20 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
107#endif 109#endif
108#ifdef PTRACE_GETFPREGS 110#ifdef PTRACE_GETFPREGS
109 case PTRACE_GETFPREGS: /* Get the child FPU state. */ 111 case PTRACE_GETFPREGS: /* Get the child FPU state. */
110 ret = get_fpregs((struct user_i387_struct __user *) data, 112 ret = get_fpregs(vp, child);
111 child);
112 break; 113 break;
113#endif 114#endif
114#ifdef PTRACE_SETFPREGS 115#ifdef PTRACE_SETFPREGS
115 case PTRACE_SETFPREGS: /* Set the child FPU state. */ 116 case PTRACE_SETFPREGS: /* Set the child FPU state. */
116 ret = set_fpregs((struct user_i387_struct __user *) data, 117 ret = set_fpregs(vp, child);
117 child);
118 break; 118 break;
119#endif 119#endif
120 case PTRACE_GET_THREAD_AREA: 120 case PTRACE_GET_THREAD_AREA:
121 ret = ptrace_get_thread_area(child, addr, 121 ret = ptrace_get_thread_area(child, addr, vp);
122 (struct user_desc __user *) data);
123 break; 122 break;
124 123
125 case PTRACE_SET_THREAD_AREA: 124 case PTRACE_SET_THREAD_AREA:
126 ret = ptrace_set_thread_area(child, addr, 125 ret = ptrace_set_thread_area(child, addr, datavp);
127 (struct user_desc __user *) data);
128 break; 126 break;
129 127
130 case PTRACE_FAULTINFO: { 128 case PTRACE_FAULTINFO: {
@@ -134,7 +132,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
134 * On i386, ptrace_faultinfo is smaller! 132 * On i386, ptrace_faultinfo is smaller!
135 */ 133 */
136 ret = copy_to_user(p, &child->thread.arch.faultinfo, 134 ret = copy_to_user(p, &child->thread.arch.faultinfo,
137 sizeof(struct ptrace_faultinfo)); 135 sizeof(struct ptrace_faultinfo)) ?
136 -EIO : 0;
138 break; 137 break;
139 } 138 }
140 139
@@ -158,7 +157,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
158#ifdef PTRACE_ARCH_PRCTL 157#ifdef PTRACE_ARCH_PRCTL
159 case PTRACE_ARCH_PRCTL: 158 case PTRACE_ARCH_PRCTL:
160 /* XXX Calls ptrace on the host - needs some SMP thinking */ 159 /* XXX Calls ptrace on the host - needs some SMP thinking */
161 ret = arch_prctl(child, data, (void *) addr); 160 ret = arch_prctl(child, data, (void __user *) addr);
162 break; 161 break;
163#endif 162#endif
164 default: 163 default:
diff --git a/arch/um/sys-i386/ptrace.c b/arch/um/sys-i386/ptrace.c
index c9b176534d65..d23b2d3ea384 100644
--- a/arch/um/sys-i386/ptrace.c
+++ b/arch/um/sys-i386/ptrace.c
@@ -203,8 +203,8 @@ int set_fpxregs(struct user_fxsr_struct __user *buf, struct task_struct *child)
203 (unsigned long *) &fpregs); 203 (unsigned long *) &fpregs);
204} 204}
205 205
206long subarch_ptrace(struct task_struct *child, long request, long addr, 206long subarch_ptrace(struct task_struct *child, long request,
207 long data) 207 unsigned long addr, unsigned long data)
208{ 208{
209 return -EIO; 209 return -EIO;
210} 210}
diff --git a/arch/um/sys-x86_64/ptrace.c b/arch/um/sys-x86_64/ptrace.c
index f3458d7d1c5a..f43613643cdb 100644
--- a/arch/um/sys-x86_64/ptrace.c
+++ b/arch/um/sys-x86_64/ptrace.c
@@ -175,19 +175,18 @@ int set_fpregs(struct user_i387_struct __user *buf, struct task_struct *child)
175 return restore_fp_registers(userspace_pid[cpu], fpregs); 175 return restore_fp_registers(userspace_pid[cpu], fpregs);
176} 176}
177 177
178long subarch_ptrace(struct task_struct *child, long request, long addr, 178long subarch_ptrace(struct task_struct *child, long request,
179 long data) 179 unsigned long addr, unsigned long data)
180{ 180{
181 int ret = -EIO; 181 int ret = -EIO;
182 void __user *datap = (void __user *) data;
182 183
183 switch (request) { 184 switch (request) {
184 case PTRACE_GETFPXREGS: /* Get the child FPU state. */ 185 case PTRACE_GETFPXREGS: /* Get the child FPU state. */
185 ret = get_fpregs((struct user_i387_struct __user *) data, 186 ret = get_fpregs(datap, child);
186 child);
187 break; 187 break;
188 case PTRACE_SETFPXREGS: /* Set the child FPU state. */ 188 case PTRACE_SETFPXREGS: /* Set the child FPU state. */
189 ret = set_fpregs((struct user_i387_struct __user *) data, 189 ret = set_fpregs(datap, child);
190 child);
191 break; 190 break;
192 } 191 }
193 192
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index dfabfefc21c4..299fbc86f570 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -347,6 +347,7 @@ endif
347 347
348config X86_VSMP 348config X86_VSMP
349 bool "ScaleMP vSMP" 349 bool "ScaleMP vSMP"
350 select PARAVIRT_GUEST
350 select PARAVIRT 351 select PARAVIRT
351 depends on X86_64 && PCI 352 depends on X86_64 && PCI
352 depends on X86_EXTENDED_PLATFORM 353 depends on X86_EXTENDED_PLATFORM
diff --git a/arch/x86/include/asm/irq.h b/arch/x86/include/asm/irq.h
index 0bf5b0083650..13b0ebaa512f 100644
--- a/arch/x86/include/asm/irq.h
+++ b/arch/x86/include/asm/irq.h
@@ -21,10 +21,8 @@ static inline int irq_canonicalize(int irq)
21 21
22#ifdef CONFIG_X86_32 22#ifdef CONFIG_X86_32
23extern void irq_ctx_init(int cpu); 23extern void irq_ctx_init(int cpu);
24extern void irq_ctx_exit(int cpu);
25#else 24#else
26# define irq_ctx_init(cpu) do { } while (0) 25# define irq_ctx_init(cpu) do { } while (0)
27# define irq_ctx_exit(cpu) do { } while (0)
28#endif 26#endif
29 27
30#define __ARCH_HAS_DO_SOFTIRQ 28#define __ARCH_HAS_DO_SOFTIRQ
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 83c4bb1d917d..3ea3dc487047 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -121,6 +121,7 @@
121#define MSR_AMD64_IBSDCLINAD 0xc0011038 121#define MSR_AMD64_IBSDCLINAD 0xc0011038
122#define MSR_AMD64_IBSDCPHYSAD 0xc0011039 122#define MSR_AMD64_IBSDCPHYSAD 0xc0011039
123#define MSR_AMD64_IBSCTL 0xc001103a 123#define MSR_AMD64_IBSCTL 0xc001103a
124#define MSR_AMD64_IBSBRTARGET 0xc001103b
124 125
125/* Fam 10h MSRs */ 126/* Fam 10h MSRs */
126#define MSR_FAM10H_MMIO_CONF_BASE 0xc0010058 127#define MSR_FAM10H_MMIO_CONF_BASE 0xc0010058
diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h
index 6e742cc4251b..550e26b1dbb3 100644
--- a/arch/x86/include/asm/perf_event.h
+++ b/arch/x86/include/asm/perf_event.h
@@ -111,17 +111,18 @@ union cpuid10_edx {
111#define X86_PMC_IDX_FIXED_BTS (X86_PMC_IDX_FIXED + 16) 111#define X86_PMC_IDX_FIXED_BTS (X86_PMC_IDX_FIXED + 16)
112 112
113/* IbsFetchCtl bits/masks */ 113/* IbsFetchCtl bits/masks */
114#define IBS_FETCH_RAND_EN (1ULL<<57) 114#define IBS_FETCH_RAND_EN (1ULL<<57)
115#define IBS_FETCH_VAL (1ULL<<49) 115#define IBS_FETCH_VAL (1ULL<<49)
116#define IBS_FETCH_ENABLE (1ULL<<48) 116#define IBS_FETCH_ENABLE (1ULL<<48)
117#define IBS_FETCH_CNT 0xFFFF0000ULL 117#define IBS_FETCH_CNT 0xFFFF0000ULL
118#define IBS_FETCH_MAX_CNT 0x0000FFFFULL 118#define IBS_FETCH_MAX_CNT 0x0000FFFFULL
119 119
120/* IbsOpCtl bits */ 120/* IbsOpCtl bits */
121#define IBS_OP_CNT_CTL (1ULL<<19) 121#define IBS_OP_CNT_CTL (1ULL<<19)
122#define IBS_OP_VAL (1ULL<<18) 122#define IBS_OP_VAL (1ULL<<18)
123#define IBS_OP_ENABLE (1ULL<<17) 123#define IBS_OP_ENABLE (1ULL<<17)
124#define IBS_OP_MAX_CNT 0x0000FFFFULL 124#define IBS_OP_MAX_CNT 0x0000FFFFULL
125#define IBS_OP_MAX_CNT_EXT 0x007FFFFFULL /* not a register bit mask */
125 126
126#ifdef CONFIG_PERF_EVENTS 127#ifdef CONFIG_PERF_EVENTS
127extern void init_hw_perf_events(void); 128extern void init_hw_perf_events(void);
diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index 4cfc90824068..4c2f63c7fc1b 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -50,7 +50,7 @@ struct smp_ops {
50 void (*smp_prepare_cpus)(unsigned max_cpus); 50 void (*smp_prepare_cpus)(unsigned max_cpus);
51 void (*smp_cpus_done)(unsigned max_cpus); 51 void (*smp_cpus_done)(unsigned max_cpus);
52 52
53 void (*smp_send_stop)(void); 53 void (*stop_other_cpus)(int wait);
54 void (*smp_send_reschedule)(int cpu); 54 void (*smp_send_reschedule)(int cpu);
55 55
56 int (*cpu_up)(unsigned cpu); 56 int (*cpu_up)(unsigned cpu);
@@ -73,7 +73,12 @@ extern struct smp_ops smp_ops;
73 73
74static inline void smp_send_stop(void) 74static inline void smp_send_stop(void)
75{ 75{
76 smp_ops.smp_send_stop(); 76 smp_ops.stop_other_cpus(0);
77}
78
79static inline void stop_other_cpus(void)
80{
81 smp_ops.stop_other_cpus(1);
77} 82}
78 83
79static inline void smp_prepare_boot_cpu(void) 84static inline void smp_prepare_boot_cpu(void)
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index c1e8c7a51164..ed6310183efb 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -237,6 +237,7 @@ struct x86_pmu {
237 * Intel DebugStore bits 237 * Intel DebugStore bits
238 */ 238 */
239 int bts, pebs; 239 int bts, pebs;
240 int bts_active, pebs_active;
240 int pebs_record_size; 241 int pebs_record_size;
241 void (*drain_pebs)(struct pt_regs *regs); 242 void (*drain_pebs)(struct pt_regs *regs);
242 struct event_constraint *pebs_constraints; 243 struct event_constraint *pebs_constraints;
@@ -380,7 +381,7 @@ static void release_pmc_hardware(void) {}
380 381
381#endif 382#endif
382 383
383static int reserve_ds_buffers(void); 384static void reserve_ds_buffers(void);
384static void release_ds_buffers(void); 385static void release_ds_buffers(void);
385 386
386static void hw_perf_event_destroy(struct perf_event *event) 387static void hw_perf_event_destroy(struct perf_event *event)
@@ -477,7 +478,7 @@ static int x86_setup_perfctr(struct perf_event *event)
477 if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) && 478 if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
478 (hwc->sample_period == 1)) { 479 (hwc->sample_period == 1)) {
479 /* BTS is not supported by this architecture. */ 480 /* BTS is not supported by this architecture. */
480 if (!x86_pmu.bts) 481 if (!x86_pmu.bts_active)
481 return -EOPNOTSUPP; 482 return -EOPNOTSUPP;
482 483
483 /* BTS is currently only allowed for user-mode. */ 484 /* BTS is currently only allowed for user-mode. */
@@ -496,12 +497,13 @@ static int x86_pmu_hw_config(struct perf_event *event)
496 int precise = 0; 497 int precise = 0;
497 498
498 /* Support for constant skid */ 499 /* Support for constant skid */
499 if (x86_pmu.pebs) 500 if (x86_pmu.pebs_active) {
500 precise++; 501 precise++;
501 502
502 /* Support for IP fixup */ 503 /* Support for IP fixup */
503 if (x86_pmu.lbr_nr) 504 if (x86_pmu.lbr_nr)
504 precise++; 505 precise++;
506 }
505 507
506 if (event->attr.precise_ip > precise) 508 if (event->attr.precise_ip > precise)
507 return -EOPNOTSUPP; 509 return -EOPNOTSUPP;
@@ -543,11 +545,8 @@ static int __x86_pmu_event_init(struct perf_event *event)
543 if (atomic_read(&active_events) == 0) { 545 if (atomic_read(&active_events) == 0) {
544 if (!reserve_pmc_hardware()) 546 if (!reserve_pmc_hardware())
545 err = -EBUSY; 547 err = -EBUSY;
546 else { 548 else
547 err = reserve_ds_buffers(); 549 reserve_ds_buffers();
548 if (err)
549 release_pmc_hardware();
550 }
551 } 550 }
552 if (!err) 551 if (!err)
553 atomic_inc(&active_events); 552 atomic_inc(&active_events);
diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c
index 4977f9c400e5..b7dcd9f2b8a0 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -74,6 +74,107 @@ static void fini_debug_store_on_cpu(int cpu)
74 wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0); 74 wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0);
75} 75}
76 76
77static int alloc_pebs_buffer(int cpu)
78{
79 struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
80 int node = cpu_to_node(cpu);
81 int max, thresh = 1; /* always use a single PEBS record */
82 void *buffer;
83
84 if (!x86_pmu.pebs)
85 return 0;
86
87 buffer = kmalloc_node(PEBS_BUFFER_SIZE, GFP_KERNEL | __GFP_ZERO, node);
88 if (unlikely(!buffer))
89 return -ENOMEM;
90
91 max = PEBS_BUFFER_SIZE / x86_pmu.pebs_record_size;
92
93 ds->pebs_buffer_base = (u64)(unsigned long)buffer;
94 ds->pebs_index = ds->pebs_buffer_base;
95 ds->pebs_absolute_maximum = ds->pebs_buffer_base +
96 max * x86_pmu.pebs_record_size;
97
98 ds->pebs_interrupt_threshold = ds->pebs_buffer_base +
99 thresh * x86_pmu.pebs_record_size;
100
101 return 0;
102}
103
104static void release_pebs_buffer(int cpu)
105{
106 struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
107
108 if (!ds || !x86_pmu.pebs)
109 return;
110
111 kfree((void *)(unsigned long)ds->pebs_buffer_base);
112 ds->pebs_buffer_base = 0;
113}
114
115static int alloc_bts_buffer(int cpu)
116{
117 struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
118 int node = cpu_to_node(cpu);
119 int max, thresh;
120 void *buffer;
121
122 if (!x86_pmu.bts)
123 return 0;
124
125 buffer = kmalloc_node(BTS_BUFFER_SIZE, GFP_KERNEL | __GFP_ZERO, node);
126 if (unlikely(!buffer))
127 return -ENOMEM;
128
129 max = BTS_BUFFER_SIZE / BTS_RECORD_SIZE;
130 thresh = max / 16;
131
132 ds->bts_buffer_base = (u64)(unsigned long)buffer;
133 ds->bts_index = ds->bts_buffer_base;
134 ds->bts_absolute_maximum = ds->bts_buffer_base +
135 max * BTS_RECORD_SIZE;
136 ds->bts_interrupt_threshold = ds->bts_absolute_maximum -
137 thresh * BTS_RECORD_SIZE;
138
139 return 0;
140}
141
142static void release_bts_buffer(int cpu)
143{
144 struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
145
146 if (!ds || !x86_pmu.bts)
147 return;
148
149 kfree((void *)(unsigned long)ds->bts_buffer_base);
150 ds->bts_buffer_base = 0;
151}
152
153static int alloc_ds_buffer(int cpu)
154{
155 int node = cpu_to_node(cpu);
156 struct debug_store *ds;
157
158 ds = kmalloc_node(sizeof(*ds), GFP_KERNEL | __GFP_ZERO, node);
159 if (unlikely(!ds))
160 return -ENOMEM;
161
162 per_cpu(cpu_hw_events, cpu).ds = ds;
163
164 return 0;
165}
166
167static void release_ds_buffer(int cpu)
168{
169 struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
170
171 if (!ds)
172 return;
173
174 per_cpu(cpu_hw_events, cpu).ds = NULL;
175 kfree(ds);
176}
177
77static void release_ds_buffers(void) 178static void release_ds_buffers(void)
78{ 179{
79 int cpu; 180 int cpu;
@@ -82,93 +183,77 @@ static void release_ds_buffers(void)
82 return; 183 return;
83 184
84 get_online_cpus(); 185 get_online_cpus();
85
86 for_each_online_cpu(cpu) 186 for_each_online_cpu(cpu)
87 fini_debug_store_on_cpu(cpu); 187 fini_debug_store_on_cpu(cpu);
88 188
89 for_each_possible_cpu(cpu) { 189 for_each_possible_cpu(cpu) {
90 struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; 190 release_pebs_buffer(cpu);
91 191 release_bts_buffer(cpu);
92 if (!ds) 192 release_ds_buffer(cpu);
93 continue;
94
95 per_cpu(cpu_hw_events, cpu).ds = NULL;
96
97 kfree((void *)(unsigned long)ds->pebs_buffer_base);
98 kfree((void *)(unsigned long)ds->bts_buffer_base);
99 kfree(ds);
100 } 193 }
101
102 put_online_cpus(); 194 put_online_cpus();
103} 195}
104 196
105static int reserve_ds_buffers(void) 197static void reserve_ds_buffers(void)
106{ 198{
107 int cpu, err = 0; 199 int bts_err = 0, pebs_err = 0;
200 int cpu;
201
202 x86_pmu.bts_active = 0;
203 x86_pmu.pebs_active = 0;
108 204
109 if (!x86_pmu.bts && !x86_pmu.pebs) 205 if (!x86_pmu.bts && !x86_pmu.pebs)
110 return 0; 206 return;
207
208 if (!x86_pmu.bts)
209 bts_err = 1;
210
211 if (!x86_pmu.pebs)
212 pebs_err = 1;
111 213
112 get_online_cpus(); 214 get_online_cpus();
113 215
114 for_each_possible_cpu(cpu) { 216 for_each_possible_cpu(cpu) {
115 struct debug_store *ds; 217 if (alloc_ds_buffer(cpu)) {
116 void *buffer; 218 bts_err = 1;
117 int max, thresh; 219 pebs_err = 1;
220 }
221
222 if (!bts_err && alloc_bts_buffer(cpu))
223 bts_err = 1;
118 224
119 err = -ENOMEM; 225 if (!pebs_err && alloc_pebs_buffer(cpu))
120 ds = kzalloc(sizeof(*ds), GFP_KERNEL); 226 pebs_err = 1;
121 if (unlikely(!ds)) 227
228 if (bts_err && pebs_err)
122 break; 229 break;
123 per_cpu(cpu_hw_events, cpu).ds = ds; 230 }
124
125 if (x86_pmu.bts) {
126 buffer = kzalloc(BTS_BUFFER_SIZE, GFP_KERNEL);
127 if (unlikely(!buffer))
128 break;
129
130 max = BTS_BUFFER_SIZE / BTS_RECORD_SIZE;
131 thresh = max / 16;
132
133 ds->bts_buffer_base = (u64)(unsigned long)buffer;
134 ds->bts_index = ds->bts_buffer_base;
135 ds->bts_absolute_maximum = ds->bts_buffer_base +
136 max * BTS_RECORD_SIZE;
137 ds->bts_interrupt_threshold = ds->bts_absolute_maximum -
138 thresh * BTS_RECORD_SIZE;
139 }
140 231
141 if (x86_pmu.pebs) { 232 if (bts_err) {
142 buffer = kzalloc(PEBS_BUFFER_SIZE, GFP_KERNEL); 233 for_each_possible_cpu(cpu)
143 if (unlikely(!buffer)) 234 release_bts_buffer(cpu);
144 break; 235 }
145
146 max = PEBS_BUFFER_SIZE / x86_pmu.pebs_record_size;
147
148 ds->pebs_buffer_base = (u64)(unsigned long)buffer;
149 ds->pebs_index = ds->pebs_buffer_base;
150 ds->pebs_absolute_maximum = ds->pebs_buffer_base +
151 max * x86_pmu.pebs_record_size;
152 /*
153 * Always use single record PEBS
154 */
155 ds->pebs_interrupt_threshold = ds->pebs_buffer_base +
156 x86_pmu.pebs_record_size;
157 }
158 236
159 err = 0; 237 if (pebs_err) {
238 for_each_possible_cpu(cpu)
239 release_pebs_buffer(cpu);
160 } 240 }
161 241
162 if (err) 242 if (bts_err && pebs_err) {
163 release_ds_buffers(); 243 for_each_possible_cpu(cpu)
164 else { 244 release_ds_buffer(cpu);
245 } else {
246 if (x86_pmu.bts && !bts_err)
247 x86_pmu.bts_active = 1;
248
249 if (x86_pmu.pebs && !pebs_err)
250 x86_pmu.pebs_active = 1;
251
165 for_each_online_cpu(cpu) 252 for_each_online_cpu(cpu)
166 init_debug_store_on_cpu(cpu); 253 init_debug_store_on_cpu(cpu);
167 } 254 }
168 255
169 put_online_cpus(); 256 put_online_cpus();
170
171 return err;
172} 257}
173 258
174/* 259/*
@@ -233,7 +318,7 @@ static int intel_pmu_drain_bts_buffer(void)
233 if (!event) 318 if (!event)
234 return 0; 319 return 0;
235 320
236 if (!ds) 321 if (!x86_pmu.bts_active)
237 return 0; 322 return 0;
238 323
239 at = (struct bts_record *)(unsigned long)ds->bts_buffer_base; 324 at = (struct bts_record *)(unsigned long)ds->bts_buffer_base;
@@ -503,7 +588,7 @@ static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
503 struct pebs_record_core *at, *top; 588 struct pebs_record_core *at, *top;
504 int n; 589 int n;
505 590
506 if (!ds || !x86_pmu.pebs) 591 if (!x86_pmu.pebs_active)
507 return; 592 return;
508 593
509 at = (struct pebs_record_core *)(unsigned long)ds->pebs_buffer_base; 594 at = (struct pebs_record_core *)(unsigned long)ds->pebs_buffer_base;
@@ -545,7 +630,7 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
545 u64 status = 0; 630 u64 status = 0;
546 int bit, n; 631 int bit, n;
547 632
548 if (!ds || !x86_pmu.pebs) 633 if (!x86_pmu.pebs_active)
549 return; 634 return;
550 635
551 at = (struct pebs_record_nhm *)(unsigned long)ds->pebs_buffer_base; 636 at = (struct pebs_record_nhm *)(unsigned long)ds->pebs_buffer_base;
@@ -630,9 +715,8 @@ static void intel_ds_init(void)
630 715
631#else /* CONFIG_CPU_SUP_INTEL */ 716#else /* CONFIG_CPU_SUP_INTEL */
632 717
633static int reserve_ds_buffers(void) 718static void reserve_ds_buffers(void)
634{ 719{
635 return 0;
636} 720}
637 721
638static void release_ds_buffers(void) 722static void release_ds_buffers(void)
diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
index 0f6376ffa2d9..1bc7f75a5bda 100644
--- a/arch/x86/kernel/dumpstack_32.c
+++ b/arch/x86/kernel/dumpstack_32.c
@@ -82,11 +82,11 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
82 if (kstack_end(stack)) 82 if (kstack_end(stack))
83 break; 83 break;
84 if (i && ((i % STACKSLOTS_PER_LINE) == 0)) 84 if (i && ((i % STACKSLOTS_PER_LINE) == 0))
85 printk("\n%s", log_lvl); 85 printk(KERN_CONT "\n");
86 printk(" %08lx", *stack++); 86 printk(KERN_CONT " %08lx", *stack++);
87 touch_nmi_watchdog(); 87 touch_nmi_watchdog();
88 } 88 }
89 printk("\n"); 89 printk(KERN_CONT "\n");
90 show_trace_log_lvl(task, regs, sp, bp, log_lvl); 90 show_trace_log_lvl(task, regs, sp, bp, log_lvl);
91} 91}
92 92
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
index 57a21f11c791..6a340485249a 100644
--- a/arch/x86/kernel/dumpstack_64.c
+++ b/arch/x86/kernel/dumpstack_64.c
@@ -265,20 +265,20 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
265 if (stack >= irq_stack && stack <= irq_stack_end) { 265 if (stack >= irq_stack && stack <= irq_stack_end) {
266 if (stack == irq_stack_end) { 266 if (stack == irq_stack_end) {
267 stack = (unsigned long *) (irq_stack_end[-1]); 267 stack = (unsigned long *) (irq_stack_end[-1]);
268 printk(" <EOI> "); 268 printk(KERN_CONT " <EOI> ");
269 } 269 }
270 } else { 270 } else {
271 if (((long) stack & (THREAD_SIZE-1)) == 0) 271 if (((long) stack & (THREAD_SIZE-1)) == 0)
272 break; 272 break;
273 } 273 }
274 if (i && ((i % STACKSLOTS_PER_LINE) == 0)) 274 if (i && ((i % STACKSLOTS_PER_LINE) == 0))
275 printk("\n%s", log_lvl); 275 printk(KERN_CONT "\n");
276 printk(" %016lx", *stack++); 276 printk(KERN_CONT " %016lx", *stack++);
277 touch_nmi_watchdog(); 277 touch_nmi_watchdog();
278 } 278 }
279 preempt_enable(); 279 preempt_enable();
280 280
281 printk("\n"); 281 printk(KERN_CONT "\n");
282 show_trace_log_lvl(task, regs, sp, bp, log_lvl); 282 show_trace_log_lvl(task, regs, sp, bp, log_lvl);
283} 283}
284 284
diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
index 50fbbe60e507..64668dbf00a4 100644
--- a/arch/x86/kernel/irq_32.c
+++ b/arch/x86/kernel/irq_32.c
@@ -60,9 +60,6 @@ union irq_ctx {
60static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx); 60static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
61static DEFINE_PER_CPU(union irq_ctx *, softirq_ctx); 61static DEFINE_PER_CPU(union irq_ctx *, softirq_ctx);
62 62
63static DEFINE_PER_CPU_MULTIPAGE_ALIGNED(union irq_ctx, hardirq_stack, THREAD_SIZE);
64static DEFINE_PER_CPU_MULTIPAGE_ALIGNED(union irq_ctx, softirq_stack, THREAD_SIZE);
65
66static void call_on_stack(void *func, void *stack) 63static void call_on_stack(void *func, void *stack)
67{ 64{
68 asm volatile("xchgl %%ebx,%%esp \n" 65 asm volatile("xchgl %%ebx,%%esp \n"
@@ -128,7 +125,7 @@ void __cpuinit irq_ctx_init(int cpu)
128 if (per_cpu(hardirq_ctx, cpu)) 125 if (per_cpu(hardirq_ctx, cpu))
129 return; 126 return;
130 127
131 irqctx = &per_cpu(hardirq_stack, cpu); 128 irqctx = (union irq_ctx *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER);
132 irqctx->tinfo.task = NULL; 129 irqctx->tinfo.task = NULL;
133 irqctx->tinfo.exec_domain = NULL; 130 irqctx->tinfo.exec_domain = NULL;
134 irqctx->tinfo.cpu = cpu; 131 irqctx->tinfo.cpu = cpu;
@@ -137,7 +134,7 @@ void __cpuinit irq_ctx_init(int cpu)
137 134
138 per_cpu(hardirq_ctx, cpu) = irqctx; 135 per_cpu(hardirq_ctx, cpu) = irqctx;
139 136
140 irqctx = &per_cpu(softirq_stack, cpu); 137 irqctx = (union irq_ctx *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER);
141 irqctx->tinfo.task = NULL; 138 irqctx->tinfo.task = NULL;
142 irqctx->tinfo.exec_domain = NULL; 139 irqctx->tinfo.exec_domain = NULL;
143 irqctx->tinfo.cpu = cpu; 140 irqctx->tinfo.cpu = cpu;
@@ -150,11 +147,6 @@ void __cpuinit irq_ctx_init(int cpu)
150 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu)); 147 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
151} 148}
152 149
153void irq_ctx_exit(int cpu)
154{
155 per_cpu(hardirq_ctx, cpu) = NULL;
156}
157
158asmlinkage void do_softirq(void) 150asmlinkage void do_softirq(void)
159{ 151{
160 unsigned long flags; 152 unsigned long flags;
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index 70c4872cd8aa..45892dc4b72a 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -801,7 +801,8 @@ void ptrace_disable(struct task_struct *child)
801static const struct user_regset_view user_x86_32_view; /* Initialized below. */ 801static const struct user_regset_view user_x86_32_view; /* Initialized below. */
802#endif 802#endif
803 803
804long arch_ptrace(struct task_struct *child, long request, long addr, long data) 804long arch_ptrace(struct task_struct *child, long request,
805 unsigned long addr, unsigned long data)
805{ 806{
806 int ret; 807 int ret;
807 unsigned long __user *datap = (unsigned long __user *)data; 808 unsigned long __user *datap = (unsigned long __user *)data;
@@ -812,8 +813,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
812 unsigned long tmp; 813 unsigned long tmp;
813 814
814 ret = -EIO; 815 ret = -EIO;
815 if ((addr & (sizeof(data) - 1)) || addr < 0 || 816 if ((addr & (sizeof(data) - 1)) || addr >= sizeof(struct user))
816 addr >= sizeof(struct user))
817 break; 817 break;
818 818
819 tmp = 0; /* Default return condition */ 819 tmp = 0; /* Default return condition */
@@ -830,8 +830,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
830 830
831 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ 831 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
832 ret = -EIO; 832 ret = -EIO;
833 if ((addr & (sizeof(data) - 1)) || addr < 0 || 833 if ((addr & (sizeof(data) - 1)) || addr >= sizeof(struct user))
834 addr >= sizeof(struct user))
835 break; 834 break;
836 835
837 if (addr < sizeof(struct user_regs_struct)) 836 if (addr < sizeof(struct user_regs_struct))
@@ -888,17 +887,17 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
888 887
889#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION 888#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
890 case PTRACE_GET_THREAD_AREA: 889 case PTRACE_GET_THREAD_AREA:
891 if (addr < 0) 890 if ((int) addr < 0)
892 return -EIO; 891 return -EIO;
893 ret = do_get_thread_area(child, addr, 892 ret = do_get_thread_area(child, addr,
894 (struct user_desc __user *) data); 893 (struct user_desc __user *)data);
895 break; 894 break;
896 895
897 case PTRACE_SET_THREAD_AREA: 896 case PTRACE_SET_THREAD_AREA:
898 if (addr < 0) 897 if ((int) addr < 0)
899 return -EIO; 898 return -EIO;
900 ret = do_set_thread_area(child, addr, 899 ret = do_set_thread_area(child, addr,
901 (struct user_desc __user *) data, 0); 900 (struct user_desc __user *)data, 0);
902 break; 901 break;
903#endif 902#endif
904 903
diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index f7f53dcd3e0a..c495aa8d4815 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -635,7 +635,7 @@ void native_machine_shutdown(void)
635 /* O.K Now that I'm on the appropriate processor, 635 /* O.K Now that I'm on the appropriate processor,
636 * stop all of the others. 636 * stop all of the others.
637 */ 637 */
638 smp_send_stop(); 638 stop_other_cpus();
639#endif 639#endif
640 640
641 lapic_shutdown(); 641 lapic_shutdown();
diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
index d801210945d6..513deac7228d 100644
--- a/arch/x86/kernel/smp.c
+++ b/arch/x86/kernel/smp.c
@@ -159,10 +159,10 @@ asmlinkage void smp_reboot_interrupt(void)
159 irq_exit(); 159 irq_exit();
160} 160}
161 161
162static void native_smp_send_stop(void) 162static void native_stop_other_cpus(int wait)
163{ 163{
164 unsigned long flags; 164 unsigned long flags;
165 unsigned long wait; 165 unsigned long timeout;
166 166
167 if (reboot_force) 167 if (reboot_force)
168 return; 168 return;
@@ -179,9 +179,12 @@ static void native_smp_send_stop(void)
179 if (num_online_cpus() > 1) { 179 if (num_online_cpus() > 1) {
180 apic->send_IPI_allbutself(REBOOT_VECTOR); 180 apic->send_IPI_allbutself(REBOOT_VECTOR);
181 181
182 /* Don't wait longer than a second */ 182 /*
183 wait = USEC_PER_SEC; 183 * Don't wait longer than a second if the caller
184 while (num_online_cpus() > 1 && wait--) 184 * didn't ask us to wait.
185 */
186 timeout = USEC_PER_SEC;
187 while (num_online_cpus() > 1 && (wait || timeout--))
185 udelay(1); 188 udelay(1);
186 } 189 }
187 190
@@ -227,7 +230,7 @@ struct smp_ops smp_ops = {
227 .smp_prepare_cpus = native_smp_prepare_cpus, 230 .smp_prepare_cpus = native_smp_prepare_cpus,
228 .smp_cpus_done = native_smp_cpus_done, 231 .smp_cpus_done = native_smp_cpus_done,
229 232
230 .smp_send_stop = native_smp_send_stop, 233 .stop_other_cpus = native_stop_other_cpus,
231 .smp_send_reschedule = native_smp_send_reschedule, 234 .smp_send_reschedule = native_smp_send_reschedule,
232 235
233 .cpu_up = native_cpu_up, 236 .cpu_up = native_cpu_up,
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 6c7faecd9e4a..083e99d1b7df 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1373,7 +1373,6 @@ void play_dead_common(void)
1373{ 1373{
1374 idle_task_exit(); 1374 idle_task_exit();
1375 reset_lazy_tlbstate(); 1375 reset_lazy_tlbstate();
1376 irq_ctx_exit(raw_smp_processor_id());
1377 c1e_remove_cpu(raw_smp_processor_id()); 1376 c1e_remove_cpu(raw_smp_processor_id());
1378 1377
1379 mb(); 1378 mb();
diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
index d723e369003c..b49962662101 100644
--- a/arch/x86/mm/highmem_32.c
+++ b/arch/x86/mm/highmem_32.c
@@ -74,7 +74,7 @@ void __kunmap_atomic(void *kvaddr)
74 vaddr <= __fix_to_virt(FIX_KMAP_BEGIN)) { 74 vaddr <= __fix_to_virt(FIX_KMAP_BEGIN)) {
75 int idx, type; 75 int idx, type;
76 76
77 type = kmap_atomic_idx_pop(); 77 type = kmap_atomic_idx();
78 idx = type + KM_TYPE_NR * smp_processor_id(); 78 idx = type + KM_TYPE_NR * smp_processor_id();
79 79
80#ifdef CONFIG_DEBUG_HIGHMEM 80#ifdef CONFIG_DEBUG_HIGHMEM
@@ -87,6 +87,7 @@ void __kunmap_atomic(void *kvaddr)
87 * attributes or becomes a protected page in a hypervisor. 87 * attributes or becomes a protected page in a hypervisor.
88 */ 88 */
89 kpte_clear_flush(kmap_pte-idx, vaddr); 89 kpte_clear_flush(kmap_pte-idx, vaddr);
90 kmap_atomic_idx_pop();
90 } 91 }
91#ifdef CONFIG_DEBUG_HIGHMEM 92#ifdef CONFIG_DEBUG_HIGHMEM
92 else { 93 else {
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 84346200e783..71a59296af80 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -51,7 +51,6 @@
51#include <asm/numa.h> 51#include <asm/numa.h>
52#include <asm/cacheflush.h> 52#include <asm/cacheflush.h>
53#include <asm/init.h> 53#include <asm/init.h>
54#include <linux/bootmem.h>
55 54
56static int __init parse_direct_gbpages_off(char *arg) 55static int __init parse_direct_gbpages_off(char *arg)
57{ 56{
diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
index 75a3d7f24a2c..7b179b499fa3 100644
--- a/arch/x86/mm/iomap_32.c
+++ b/arch/x86/mm/iomap_32.c
@@ -98,7 +98,7 @@ iounmap_atomic(void __iomem *kvaddr)
98 vaddr <= __fix_to_virt(FIX_KMAP_BEGIN)) { 98 vaddr <= __fix_to_virt(FIX_KMAP_BEGIN)) {
99 int idx, type; 99 int idx, type;
100 100
101 type = kmap_atomic_idx_pop(); 101 type = kmap_atomic_idx();
102 idx = type + KM_TYPE_NR * smp_processor_id(); 102 idx = type + KM_TYPE_NR * smp_processor_id();
103 103
104#ifdef CONFIG_DEBUG_HIGHMEM 104#ifdef CONFIG_DEBUG_HIGHMEM
@@ -111,6 +111,7 @@ iounmap_atomic(void __iomem *kvaddr)
111 * attributes or becomes a protected page in a hypervisor. 111 * attributes or becomes a protected page in a hypervisor.
112 */ 112 */
113 kpte_clear_flush(kmap_pte-idx, vaddr); 113 kpte_clear_flush(kmap_pte-idx, vaddr);
114 kmap_atomic_idx_pop();
114 } 115 }
115 116
116 pagefault_enable(); 117 pagefault_enable();
diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index bd1489c3ce09..4e8baad36d37 100644
--- a/arch/x86/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
@@ -726,6 +726,12 @@ int __init op_nmi_init(struct oprofile_operations *ops)
726 case 0x11: 726 case 0x11:
727 cpu_type = "x86-64/family11h"; 727 cpu_type = "x86-64/family11h";
728 break; 728 break;
729 case 0x12:
730 cpu_type = "x86-64/family12h";
731 break;
732 case 0x14:
733 cpu_type = "x86-64/family14h";
734 break;
729 default: 735 default:
730 return -ENODEV; 736 return -ENODEV;
731 } 737 }
diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
index 42fb46f83883..a011bcc0f943 100644
--- a/arch/x86/oprofile/op_model_amd.c
+++ b/arch/x86/oprofile/op_model_amd.c
@@ -48,17 +48,24 @@ static unsigned long reset_value[NUM_VIRT_COUNTERS];
48 48
49static u32 ibs_caps; 49static u32 ibs_caps;
50 50
51struct op_ibs_config { 51struct ibs_config {
52 unsigned long op_enabled; 52 unsigned long op_enabled;
53 unsigned long fetch_enabled; 53 unsigned long fetch_enabled;
54 unsigned long max_cnt_fetch; 54 unsigned long max_cnt_fetch;
55 unsigned long max_cnt_op; 55 unsigned long max_cnt_op;
56 unsigned long rand_en; 56 unsigned long rand_en;
57 unsigned long dispatched_ops; 57 unsigned long dispatched_ops;
58 unsigned long branch_target;
58}; 59};
59 60
60static struct op_ibs_config ibs_config; 61struct ibs_state {
61static u64 ibs_op_ctl; 62 u64 ibs_op_ctl;
63 int branch_target;
64 unsigned long sample_size;
65};
66
67static struct ibs_config ibs_config;
68static struct ibs_state ibs_state;
62 69
63/* 70/*
64 * IBS cpuid feature detection 71 * IBS cpuid feature detection
@@ -71,8 +78,16 @@ static u64 ibs_op_ctl;
71 * bit 0 is used to indicate the existence of IBS. 78 * bit 0 is used to indicate the existence of IBS.
72 */ 79 */
73#define IBS_CAPS_AVAIL (1U<<0) 80#define IBS_CAPS_AVAIL (1U<<0)
81#define IBS_CAPS_FETCHSAM (1U<<1)
82#define IBS_CAPS_OPSAM (1U<<2)
74#define IBS_CAPS_RDWROPCNT (1U<<3) 83#define IBS_CAPS_RDWROPCNT (1U<<3)
75#define IBS_CAPS_OPCNT (1U<<4) 84#define IBS_CAPS_OPCNT (1U<<4)
85#define IBS_CAPS_BRNTRGT (1U<<5)
86#define IBS_CAPS_OPCNTEXT (1U<<6)
87
88#define IBS_CAPS_DEFAULT (IBS_CAPS_AVAIL \
89 | IBS_CAPS_FETCHSAM \
90 | IBS_CAPS_OPSAM)
76 91
77/* 92/*
78 * IBS APIC setup 93 * IBS APIC setup
@@ -99,12 +114,12 @@ static u32 get_ibs_caps(void)
99 /* check IBS cpuid feature flags */ 114 /* check IBS cpuid feature flags */
100 max_level = cpuid_eax(0x80000000); 115 max_level = cpuid_eax(0x80000000);
101 if (max_level < IBS_CPUID_FEATURES) 116 if (max_level < IBS_CPUID_FEATURES)
102 return IBS_CAPS_AVAIL; 117 return IBS_CAPS_DEFAULT;
103 118
104 ibs_caps = cpuid_eax(IBS_CPUID_FEATURES); 119 ibs_caps = cpuid_eax(IBS_CPUID_FEATURES);
105 if (!(ibs_caps & IBS_CAPS_AVAIL)) 120 if (!(ibs_caps & IBS_CAPS_AVAIL))
106 /* cpuid flags not valid */ 121 /* cpuid flags not valid */
107 return IBS_CAPS_AVAIL; 122 return IBS_CAPS_DEFAULT;
108 123
109 return ibs_caps; 124 return ibs_caps;
110} 125}
@@ -197,8 +212,8 @@ op_amd_handle_ibs(struct pt_regs * const regs,
197 rdmsrl(MSR_AMD64_IBSOPCTL, ctl); 212 rdmsrl(MSR_AMD64_IBSOPCTL, ctl);
198 if (ctl & IBS_OP_VAL) { 213 if (ctl & IBS_OP_VAL) {
199 rdmsrl(MSR_AMD64_IBSOPRIP, val); 214 rdmsrl(MSR_AMD64_IBSOPRIP, val);
200 oprofile_write_reserve(&entry, regs, val, 215 oprofile_write_reserve(&entry, regs, val, IBS_OP_CODE,
201 IBS_OP_CODE, IBS_OP_SIZE); 216 ibs_state.sample_size);
202 oprofile_add_data64(&entry, val); 217 oprofile_add_data64(&entry, val);
203 rdmsrl(MSR_AMD64_IBSOPDATA, val); 218 rdmsrl(MSR_AMD64_IBSOPDATA, val);
204 oprofile_add_data64(&entry, val); 219 oprofile_add_data64(&entry, val);
@@ -210,10 +225,14 @@ op_amd_handle_ibs(struct pt_regs * const regs,
210 oprofile_add_data64(&entry, val); 225 oprofile_add_data64(&entry, val);
211 rdmsrl(MSR_AMD64_IBSDCPHYSAD, val); 226 rdmsrl(MSR_AMD64_IBSDCPHYSAD, val);
212 oprofile_add_data64(&entry, val); 227 oprofile_add_data64(&entry, val);
228 if (ibs_state.branch_target) {
229 rdmsrl(MSR_AMD64_IBSBRTARGET, val);
230 oprofile_add_data(&entry, (unsigned long)val);
231 }
213 oprofile_write_commit(&entry); 232 oprofile_write_commit(&entry);
214 233
215 /* reenable the IRQ */ 234 /* reenable the IRQ */
216 ctl = op_amd_randomize_ibs_op(ibs_op_ctl); 235 ctl = op_amd_randomize_ibs_op(ibs_state.ibs_op_ctl);
217 wrmsrl(MSR_AMD64_IBSOPCTL, ctl); 236 wrmsrl(MSR_AMD64_IBSOPCTL, ctl);
218 } 237 }
219 } 238 }
@@ -226,21 +245,32 @@ static inline void op_amd_start_ibs(void)
226 if (!ibs_caps) 245 if (!ibs_caps)
227 return; 246 return;
228 247
248 memset(&ibs_state, 0, sizeof(ibs_state));
249
250 /*
251 * Note: Since the max count settings may out of range we
252 * write back the actual used values so that userland can read
253 * it.
254 */
255
229 if (ibs_config.fetch_enabled) { 256 if (ibs_config.fetch_enabled) {
230 val = (ibs_config.max_cnt_fetch >> 4) & IBS_FETCH_MAX_CNT; 257 val = ibs_config.max_cnt_fetch >> 4;
258 val = min(val, IBS_FETCH_MAX_CNT);
259 ibs_config.max_cnt_fetch = val << 4;
231 val |= ibs_config.rand_en ? IBS_FETCH_RAND_EN : 0; 260 val |= ibs_config.rand_en ? IBS_FETCH_RAND_EN : 0;
232 val |= IBS_FETCH_ENABLE; 261 val |= IBS_FETCH_ENABLE;
233 wrmsrl(MSR_AMD64_IBSFETCHCTL, val); 262 wrmsrl(MSR_AMD64_IBSFETCHCTL, val);
234 } 263 }
235 264
236 if (ibs_config.op_enabled) { 265 if (ibs_config.op_enabled) {
237 ibs_op_ctl = ibs_config.max_cnt_op >> 4; 266 val = ibs_config.max_cnt_op >> 4;
238 if (!(ibs_caps & IBS_CAPS_RDWROPCNT)) { 267 if (!(ibs_caps & IBS_CAPS_RDWROPCNT)) {
239 /* 268 /*
240 * IbsOpCurCnt not supported. See 269 * IbsOpCurCnt not supported. See
241 * op_amd_randomize_ibs_op() for details. 270 * op_amd_randomize_ibs_op() for details.
242 */ 271 */
243 ibs_op_ctl = clamp(ibs_op_ctl, 0x0081ULL, 0xFF80ULL); 272 val = clamp(val, 0x0081ULL, 0xFF80ULL);
273 ibs_config.max_cnt_op = val << 4;
244 } else { 274 } else {
245 /* 275 /*
246 * The start value is randomized with a 276 * The start value is randomized with a
@@ -248,13 +278,24 @@ static inline void op_amd_start_ibs(void)
248 * with the half of the randomized range. Also 278 * with the half of the randomized range. Also
249 * avoid underflows. 279 * avoid underflows.
250 */ 280 */
251 ibs_op_ctl = min(ibs_op_ctl + IBS_RANDOM_MAXCNT_OFFSET, 281 val += IBS_RANDOM_MAXCNT_OFFSET;
252 IBS_OP_MAX_CNT); 282 if (ibs_caps & IBS_CAPS_OPCNTEXT)
283 val = min(val, IBS_OP_MAX_CNT_EXT);
284 else
285 val = min(val, IBS_OP_MAX_CNT);
286 ibs_config.max_cnt_op =
287 (val - IBS_RANDOM_MAXCNT_OFFSET) << 4;
288 }
289 val = ((val & ~IBS_OP_MAX_CNT) << 4) | (val & IBS_OP_MAX_CNT);
290 val |= ibs_config.dispatched_ops ? IBS_OP_CNT_CTL : 0;
291 val |= IBS_OP_ENABLE;
292 ibs_state.ibs_op_ctl = val;
293 ibs_state.sample_size = IBS_OP_SIZE;
294 if (ibs_config.branch_target) {
295 ibs_state.branch_target = 1;
296 ibs_state.sample_size++;
253 } 297 }
254 if (ibs_caps & IBS_CAPS_OPCNT && ibs_config.dispatched_ops) 298 val = op_amd_randomize_ibs_op(ibs_state.ibs_op_ctl);
255 ibs_op_ctl |= IBS_OP_CNT_CTL;
256 ibs_op_ctl |= IBS_OP_ENABLE;
257 val = op_amd_randomize_ibs_op(ibs_op_ctl);
258 wrmsrl(MSR_AMD64_IBSOPCTL, val); 299 wrmsrl(MSR_AMD64_IBSOPCTL, val);
259 } 300 }
260} 301}
@@ -281,29 +322,25 @@ static inline int eilvt_is_available(int offset)
281 322
282static inline int ibs_eilvt_valid(void) 323static inline int ibs_eilvt_valid(void)
283{ 324{
284 u64 val;
285 int offset; 325 int offset;
326 u64 val;
286 327
287 rdmsrl(MSR_AMD64_IBSCTL, val); 328 rdmsrl(MSR_AMD64_IBSCTL, val);
329 offset = val & IBSCTL_LVT_OFFSET_MASK;
330
288 if (!(val & IBSCTL_LVT_OFFSET_VALID)) { 331 if (!(val & IBSCTL_LVT_OFFSET_VALID)) {
289 pr_err(FW_BUG "cpu %d, invalid IBS " 332 pr_err(FW_BUG "cpu %d, invalid IBS interrupt offset %d (MSR%08X=0x%016llx)\n",
290 "interrupt offset %d (MSR%08X=0x%016llx)", 333 smp_processor_id(), offset, MSR_AMD64_IBSCTL, val);
291 smp_processor_id(), offset,
292 MSR_AMD64_IBSCTL, val);
293 return 0; 334 return 0;
294 } 335 }
295 336
296 offset = val & IBSCTL_LVT_OFFSET_MASK; 337 if (!eilvt_is_available(offset)) {
297 338 pr_err(FW_BUG "cpu %d, IBS interrupt offset %d not available (MSR%08X=0x%016llx)\n",
298 if (eilvt_is_available(offset)) 339 smp_processor_id(), offset, MSR_AMD64_IBSCTL, val);
299 return !0; 340 return 0;
300 341 }
301 pr_err(FW_BUG "cpu %d, IBS interrupt offset %d "
302 "not available (MSR%08X=0x%016llx)",
303 smp_processor_id(), offset,
304 MSR_AMD64_IBSCTL, val);
305 342
306 return 0; 343 return 1;
307} 344}
308 345
309static inline int get_ibs_offset(void) 346static inline int get_ibs_offset(void)
@@ -630,28 +667,33 @@ static int setup_ibs_files(struct super_block *sb, struct dentry *root)
630 /* model specific files */ 667 /* model specific files */
631 668
632 /* setup some reasonable defaults */ 669 /* setup some reasonable defaults */
670 memset(&ibs_config, 0, sizeof(ibs_config));
633 ibs_config.max_cnt_fetch = 250000; 671 ibs_config.max_cnt_fetch = 250000;
634 ibs_config.fetch_enabled = 0;
635 ibs_config.max_cnt_op = 250000; 672 ibs_config.max_cnt_op = 250000;
636 ibs_config.op_enabled = 0; 673
637 ibs_config.dispatched_ops = 0; 674 if (ibs_caps & IBS_CAPS_FETCHSAM) {
638 675 dir = oprofilefs_mkdir(sb, root, "ibs_fetch");
639 dir = oprofilefs_mkdir(sb, root, "ibs_fetch"); 676 oprofilefs_create_ulong(sb, dir, "enable",
640 oprofilefs_create_ulong(sb, dir, "enable", 677 &ibs_config.fetch_enabled);
641 &ibs_config.fetch_enabled); 678 oprofilefs_create_ulong(sb, dir, "max_count",
642 oprofilefs_create_ulong(sb, dir, "max_count", 679 &ibs_config.max_cnt_fetch);
643 &ibs_config.max_cnt_fetch); 680 oprofilefs_create_ulong(sb, dir, "rand_enable",
644 oprofilefs_create_ulong(sb, dir, "rand_enable", 681 &ibs_config.rand_en);
645 &ibs_config.rand_en); 682 }
646 683
647 dir = oprofilefs_mkdir(sb, root, "ibs_op"); 684 if (ibs_caps & IBS_CAPS_OPSAM) {
648 oprofilefs_create_ulong(sb, dir, "enable", 685 dir = oprofilefs_mkdir(sb, root, "ibs_op");
649 &ibs_config.op_enabled); 686 oprofilefs_create_ulong(sb, dir, "enable",
650 oprofilefs_create_ulong(sb, dir, "max_count", 687 &ibs_config.op_enabled);
651 &ibs_config.max_cnt_op); 688 oprofilefs_create_ulong(sb, dir, "max_count",
652 if (ibs_caps & IBS_CAPS_OPCNT) 689 &ibs_config.max_cnt_op);
653 oprofilefs_create_ulong(sb, dir, "dispatched_ops", 690 if (ibs_caps & IBS_CAPS_OPCNT)
654 &ibs_config.dispatched_ops); 691 oprofilefs_create_ulong(sb, dir, "dispatched_ops",
692 &ibs_config.dispatched_ops);
693 if (ibs_caps & IBS_CAPS_BRNTRGT)
694 oprofilefs_create_ulong(sb, dir, "branch_target",
695 &ibs_config.branch_target);
696 }
655 697
656 return 0; 698 return 0;
657} 699}
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 44ab12dc2a12..70ddeaeb1ef3 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -59,7 +59,6 @@
59#include <asm/pgtable.h> 59#include <asm/pgtable.h>
60#include <asm/tlbflush.h> 60#include <asm/tlbflush.h>
61#include <asm/reboot.h> 61#include <asm/reboot.h>
62#include <asm/setup.h>
63#include <asm/stackprotector.h> 62#include <asm/stackprotector.h>
64#include <asm/hypervisor.h> 63#include <asm/hypervisor.h>
65 64
@@ -1016,7 +1015,7 @@ static void xen_reboot(int reason)
1016 struct sched_shutdown r = { .reason = reason }; 1015 struct sched_shutdown r = { .reason = reason };
1017 1016
1018#ifdef CONFIG_SMP 1017#ifdef CONFIG_SMP
1019 smp_send_stop(); 1018 stop_other_cpus();
1020#endif 1019#endif
1021 1020
1022 if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r)) 1021 if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 25f232b18a82..f4d010031465 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -400,9 +400,9 @@ static void stop_self(void *v)
400 BUG(); 400 BUG();
401} 401}
402 402
403static void xen_smp_send_stop(void) 403static void xen_stop_other_cpus(int wait)
404{ 404{
405 smp_call_function(stop_self, NULL, 0); 405 smp_call_function(stop_self, NULL, wait);
406} 406}
407 407
408static void xen_smp_send_reschedule(int cpu) 408static void xen_smp_send_reschedule(int cpu)
@@ -470,7 +470,7 @@ static const struct smp_ops xen_smp_ops __initdata = {
470 .cpu_disable = xen_cpu_disable, 470 .cpu_disable = xen_cpu_disable,
471 .play_dead = xen_play_dead, 471 .play_dead = xen_play_dead,
472 472
473 .smp_send_stop = xen_smp_send_stop, 473 .stop_other_cpus = xen_stop_other_cpus,
474 .smp_send_reschedule = xen_smp_send_reschedule, 474 .smp_send_reschedule = xen_smp_send_reschedule,
475 475
476 .send_call_func_ipi = xen_smp_send_call_function_ipi, 476 .send_call_func_ipi = xen_smp_send_call_function_ipi,
diff --git a/arch/xtensa/kernel/ptrace.c b/arch/xtensa/kernel/ptrace.c
index 9d4e1ceb3f09..c72c9473ef99 100644
--- a/arch/xtensa/kernel/ptrace.c
+++ b/arch/xtensa/kernel/ptrace.c
@@ -256,9 +256,11 @@ int ptrace_pokeusr(struct task_struct *child, long regno, long val)
256 return 0; 256 return 0;
257} 257}
258 258
259long arch_ptrace(struct task_struct *child, long request, long addr, long data) 259long arch_ptrace(struct task_struct *child, long request,
260 unsigned long addr, unsigned long data)
260{ 261{
261 int ret = -EPERM; 262 int ret = -EPERM;
263 void __user *datap = (void __user *) data;
262 264
263 switch (request) { 265 switch (request) {
264 case PTRACE_PEEKTEXT: /* read word at location addr. */ 266 case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -267,7 +269,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
267 break; 269 break;
268 270
269 case PTRACE_PEEKUSR: /* read register specified by addr. */ 271 case PTRACE_PEEKUSR: /* read register specified by addr. */
270 ret = ptrace_peekusr(child, addr, (void __user *) data); 272 ret = ptrace_peekusr(child, addr, datap);
271 break; 273 break;
272 274
273 case PTRACE_POKETEXT: /* write the word at location addr. */ 275 case PTRACE_POKETEXT: /* write the word at location addr. */
@@ -280,19 +282,19 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
280 break; 282 break;
281 283
282 case PTRACE_GETREGS: 284 case PTRACE_GETREGS:
283 ret = ptrace_getregs(child, (void __user *) data); 285 ret = ptrace_getregs(child, datap);
284 break; 286 break;
285 287
286 case PTRACE_SETREGS: 288 case PTRACE_SETREGS:
287 ret = ptrace_setregs(child, (void __user *) data); 289 ret = ptrace_setregs(child, datap);
288 break; 290 break;
289 291
290 case PTRACE_GETXTREGS: 292 case PTRACE_GETXTREGS:
291 ret = ptrace_getxregs(child, (void __user *) data); 293 ret = ptrace_getxregs(child, datap);
292 break; 294 break;
293 295
294 case PTRACE_SETXTREGS: 296 case PTRACE_SETXTREGS:
295 ret = ptrace_setxregs(child, (void __user *) data); 297 ret = ptrace_setxregs(child, datap);
296 break; 298 break;
297 299
298 default: 300 default:
diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
index 80f9f3659e4d..97c5898cd76e 100644
--- a/drivers/atm/eni.c
+++ b/drivers/atm/eni.c
@@ -1736,9 +1736,10 @@ static int __devinit eni_do_init(struct atm_dev *dev)
1736 eprom = (base+EPROM_SIZE-sizeof(struct midway_eprom)); 1736 eprom = (base+EPROM_SIZE-sizeof(struct midway_eprom));
1737 if (readl(&eprom->magic) != ENI155_MAGIC) { 1737 if (readl(&eprom->magic) != ENI155_MAGIC) {
1738 printk("\n"); 1738 printk("\n");
1739 printk(KERN_ERR KERN_ERR DEV_LABEL "(itf %d): bad " 1739 printk(KERN_ERR DEV_LABEL
1740 "magic - expected 0x%x, got 0x%x\n",dev->number, 1740 "(itf %d): bad magic - expected 0x%x, got 0x%x\n",
1741 ENI155_MAGIC,(unsigned) readl(&eprom->magic)); 1741 dev->number, ENI155_MAGIC,
1742 (unsigned)readl(&eprom->magic));
1742 error = -EINVAL; 1743 error = -EINVAL;
1743 goto unmap; 1744 goto unmap;
1744 } 1745 }
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index e7ba774beda6..25373df1dcf8 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -566,6 +566,7 @@ static ssize_t ac_read (struct file *filp, char __user *buf, size_t count, loff_
566 struct mailbox mailbox; 566 struct mailbox mailbox;
567 567
568 /* Got a packet for us */ 568 /* Got a packet for us */
569 memset(&st_loc, 0, sizeof(st_loc));
569 ret = do_ac_read(i, buf, &st_loc, &mailbox); 570 ret = do_ac_read(i, buf, &st_loc, &mailbox);
570 spin_unlock_irqrestore(&apbs[i].mutex, flags); 571 spin_unlock_irqrestore(&apbs[i].mutex, flags);
571 set_current_state(TASK_RUNNING); 572 set_current_state(TASK_RUNNING);
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index 3afd62e856eb..e9cba13ee800 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -713,7 +713,6 @@ static int khvcd(void *unused)
713 struct hvc_struct *hp; 713 struct hvc_struct *hp;
714 714
715 set_freezable(); 715 set_freezable();
716 __set_current_state(TASK_RUNNING);
717 do { 716 do {
718 poll_mask = 0; 717 poll_mask = 0;
719 hvc_kicked = 0; 718 hvc_kicked = 0;
diff --git a/drivers/char/ip2/Makefile b/drivers/char/ip2/Makefile
index bc397d92b499..7b78e0dfc5b0 100644
--- a/drivers/char/ip2/Makefile
+++ b/drivers/char/ip2/Makefile
@@ -4,5 +4,5 @@
4 4
5obj-$(CONFIG_COMPUTONE) += ip2.o 5obj-$(CONFIG_COMPUTONE) += ip2.o
6 6
7ip2-objs := ip2main.o 7ip2-y := ip2main.o
8 8
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index eb8a1a8c188e..16a93648d54e 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -2,7 +2,7 @@
2# Makefile for the ipmi drivers. 2# Makefile for the ipmi drivers.
3# 3#
4 4
5ipmi_si-objs := ipmi_si_intf.o ipmi_kcs_sm.o ipmi_smic_sm.o ipmi_bt_sm.o 5ipmi_si-y := ipmi_si_intf.o ipmi_kcs_sm.o ipmi_smic_sm.o ipmi_bt_sm.o
6 6
7obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o 7obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o
8obj-$(CONFIG_IPMI_DEVICE_INTERFACE) += ipmi_devintf.o 8obj-$(CONFIG_IPMI_DEVICE_INTERFACE) += ipmi_devintf.o
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 1fc8876af1f5..2aa3977aae5e 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -916,7 +916,7 @@ static struct ipmi_smi_watcher smi_watcher =
916 .smi_gone = ipmi_smi_gone, 916 .smi_gone = ipmi_smi_gone,
917}; 917};
918 918
919static __init int init_ipmi_devintf(void) 919static int __init init_ipmi_devintf(void)
920{ 920{
921 int rv; 921 int rv;
922 922
@@ -954,7 +954,7 @@ static __init int init_ipmi_devintf(void)
954} 954}
955module_init(init_ipmi_devintf); 955module_init(init_ipmi_devintf);
956 956
957static __exit void cleanup_ipmi(void) 957static void __exit cleanup_ipmi(void)
958{ 958{
959 struct ipmi_reg_list *entry, *entry2; 959 struct ipmi_reg_list *entry, *entry2;
960 mutex_lock(&reg_list_mutex); 960 mutex_lock(&reg_list_mutex);
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 4f3f8c9ec262..2fe72f8edf44 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -4442,13 +4442,13 @@ static int ipmi_init_msghandler(void)
4442 return 0; 4442 return 0;
4443} 4443}
4444 4444
4445static __init int ipmi_init_msghandler_mod(void) 4445static int __init ipmi_init_msghandler_mod(void)
4446{ 4446{
4447 ipmi_init_msghandler(); 4447 ipmi_init_msghandler();
4448 return 0; 4448 return 0;
4449} 4449}
4450 4450
4451static __exit void cleanup_ipmi(void) 4451static void __exit cleanup_ipmi(void)
4452{ 4452{
4453 int count; 4453 int count;
4454 4454
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index b293d57d30a7..035da9e64a17 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -1846,7 +1846,7 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
1846 return rv; 1846 return rv;
1847} 1847}
1848 1848
1849static __devinit void hardcode_find_bmc(void) 1849static void __devinit hardcode_find_bmc(void)
1850{ 1850{
1851 int i; 1851 int i;
1852 struct smi_info *info; 1852 struct smi_info *info;
@@ -2029,7 +2029,7 @@ struct SPMITable {
2029 s8 spmi_id[1]; /* A '\0' terminated array starts here. */ 2029 s8 spmi_id[1]; /* A '\0' terminated array starts here. */
2030}; 2030};
2031 2031
2032static __devinit int try_init_spmi(struct SPMITable *spmi) 2032static int __devinit try_init_spmi(struct SPMITable *spmi)
2033{ 2033{
2034 struct smi_info *info; 2034 struct smi_info *info;
2035 2035
@@ -2112,7 +2112,7 @@ static __devinit int try_init_spmi(struct SPMITable *spmi)
2112 return 0; 2112 return 0;
2113} 2113}
2114 2114
2115static __devinit void spmi_find_bmc(void) 2115static void __devinit spmi_find_bmc(void)
2116{ 2116{
2117 acpi_status status; 2117 acpi_status status;
2118 struct SPMITable *spmi; 2118 struct SPMITable *spmi;
@@ -2325,7 +2325,7 @@ static int __devinit decode_dmi(const struct dmi_header *dm,
2325 return 0; 2325 return 0;
2326} 2326}
2327 2327
2328static __devinit void try_init_dmi(struct dmi_ipmi_data *ipmi_data) 2328static void __devinit try_init_dmi(struct dmi_ipmi_data *ipmi_data)
2329{ 2329{
2330 struct smi_info *info; 2330 struct smi_info *info;
2331 2331
@@ -3012,7 +3012,7 @@ static __devinitdata struct ipmi_default_vals
3012 { .port = 0 } 3012 { .port = 0 }
3013}; 3013};
3014 3014
3015static __devinit void default_find_bmc(void) 3015static void __devinit default_find_bmc(void)
3016{ 3016{
3017 struct smi_info *info; 3017 struct smi_info *info;
3018 int i; 3018 int i;
@@ -3312,7 +3312,7 @@ static int try_smi_init(struct smi_info *new_smi)
3312 return rv; 3312 return rv;
3313} 3313}
3314 3314
3315static __devinit int init_ipmi_si(void) 3315static int __devinit init_ipmi_si(void)
3316{ 3316{
3317 int i; 3317 int i;
3318 char *str; 3318 char *str;
@@ -3525,7 +3525,7 @@ static void cleanup_one_si(struct smi_info *to_clean)
3525 kfree(to_clean); 3525 kfree(to_clean);
3526} 3526}
3527 3527
3528static __exit void cleanup_ipmi_si(void) 3528static void __exit cleanup_ipmi_si(void)
3529{ 3529{
3530 struct smi_info *e, *tmp_e; 3530 struct smi_info *e, *tmp_e;
3531 3531
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index c070b53984e4..e6d75627c6c8 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -176,9 +176,9 @@ static void mmtimer_setup_int_2(int cpu, u64 expires)
176 * in order to insure that the setup succeeds in a deterministic time frame. 176 * in order to insure that the setup succeeds in a deterministic time frame.
177 * It will check if the interrupt setup succeeded. 177 * It will check if the interrupt setup succeeded.
178 */ 178 */
179static int mmtimer_setup(int cpu, int comparator, unsigned long expires) 179static int mmtimer_setup(int cpu, int comparator, unsigned long expires,
180 u64 *set_completion_time)
180{ 181{
181
182 switch (comparator) { 182 switch (comparator) {
183 case 0: 183 case 0:
184 mmtimer_setup_int_0(cpu, expires); 184 mmtimer_setup_int_0(cpu, expires);
@@ -191,7 +191,8 @@ static int mmtimer_setup(int cpu, int comparator, unsigned long expires)
191 break; 191 break;
192 } 192 }
193 /* We might've missed our expiration time */ 193 /* We might've missed our expiration time */
194 if (rtc_time() <= expires) 194 *set_completion_time = rtc_time();
195 if (*set_completion_time <= expires)
195 return 1; 196 return 1;
196 197
197 /* 198 /*
@@ -227,6 +228,8 @@ static int mmtimer_disable_int(long nasid, int comparator)
227#define TIMER_OFF 0xbadcabLL /* Timer is not setup */ 228#define TIMER_OFF 0xbadcabLL /* Timer is not setup */
228#define TIMER_SET 0 /* Comparator is set for this timer */ 229#define TIMER_SET 0 /* Comparator is set for this timer */
229 230
231#define MMTIMER_INTERVAL_RETRY_INCREMENT_DEFAULT 40
232
230/* There is one of these for each timer */ 233/* There is one of these for each timer */
231struct mmtimer { 234struct mmtimer {
232 struct rb_node list; 235 struct rb_node list;
@@ -242,6 +245,11 @@ struct mmtimer_node {
242}; 245};
243static struct mmtimer_node *timers; 246static struct mmtimer_node *timers;
244 247
248static unsigned mmtimer_interval_retry_increment =
249 MMTIMER_INTERVAL_RETRY_INCREMENT_DEFAULT;
250module_param(mmtimer_interval_retry_increment, uint, 0644);
251MODULE_PARM_DESC(mmtimer_interval_retry_increment,
252 "RTC ticks to add to expiration on interval retry (default 40)");
245 253
246/* 254/*
247 * Add a new mmtimer struct to the node's mmtimer list. 255 * Add a new mmtimer struct to the node's mmtimer list.
@@ -289,7 +297,8 @@ static void mmtimer_set_next_timer(int nodeid)
289 struct mmtimer_node *n = &timers[nodeid]; 297 struct mmtimer_node *n = &timers[nodeid];
290 struct mmtimer *x; 298 struct mmtimer *x;
291 struct k_itimer *t; 299 struct k_itimer *t;
292 int o; 300 u64 expires, exp, set_completion_time;
301 int i;
293 302
294restart: 303restart:
295 if (n->next == NULL) 304 if (n->next == NULL)
@@ -300,7 +309,8 @@ restart:
300 if (!t->it.mmtimer.incr) { 309 if (!t->it.mmtimer.incr) {
301 /* Not an interval timer */ 310 /* Not an interval timer */
302 if (!mmtimer_setup(x->cpu, COMPARATOR, 311 if (!mmtimer_setup(x->cpu, COMPARATOR,
303 t->it.mmtimer.expires)) { 312 t->it.mmtimer.expires,
313 &set_completion_time)) {
304 /* Late setup, fire now */ 314 /* Late setup, fire now */
305 tasklet_schedule(&n->tasklet); 315 tasklet_schedule(&n->tasklet);
306 } 316 }
@@ -308,14 +318,23 @@ restart:
308 } 318 }
309 319
310 /* Interval timer */ 320 /* Interval timer */
311 o = 0; 321 i = 0;
312 while (!mmtimer_setup(x->cpu, COMPARATOR, t->it.mmtimer.expires)) { 322 expires = exp = t->it.mmtimer.expires;
313 unsigned long e, e1; 323 while (!mmtimer_setup(x->cpu, COMPARATOR, expires,
314 struct rb_node *next; 324 &set_completion_time)) {
315 t->it.mmtimer.expires += t->it.mmtimer.incr << o; 325 int to;
316 t->it_overrun += 1 << o; 326
317 o++; 327 i++;
318 if (o > 20) { 328 expires = set_completion_time +
329 mmtimer_interval_retry_increment + (1 << i);
330 /* Calculate overruns as we go. */
331 to = ((u64)(expires - exp) / t->it.mmtimer.incr);
332 if (to) {
333 t->it_overrun += to;
334 t->it.mmtimer.expires += t->it.mmtimer.incr * to;
335 exp = t->it.mmtimer.expires;
336 }
337 if (i > 20) {
319 printk(KERN_ALERT "mmtimer: cannot reschedule timer\n"); 338 printk(KERN_ALERT "mmtimer: cannot reschedule timer\n");
320 t->it.mmtimer.clock = TIMER_OFF; 339 t->it.mmtimer.clock = TIMER_OFF;
321 n->next = rb_next(&x->list); 340 n->next = rb_next(&x->list);
@@ -323,21 +342,6 @@ restart:
323 kfree(x); 342 kfree(x);
324 goto restart; 343 goto restart;
325 } 344 }
326
327 e = t->it.mmtimer.expires;
328 next = rb_next(&x->list);
329
330 if (next == NULL)
331 continue;
332
333 e1 = rb_entry(next, struct mmtimer, list)->
334 timer->it.mmtimer.expires;
335 if (e > e1) {
336 n->next = next;
337 rb_erase(&x->list, &n->timer_head);
338 mmtimer_add_list(x);
339 goto restart;
340 }
341 } 345 }
342} 346}
343 347
diff --git a/drivers/char/mwave/Makefile b/drivers/char/mwave/Makefile
index 754c9e2058ed..26b4fce217b6 100644
--- a/drivers/char/mwave/Makefile
+++ b/drivers/char/mwave/Makefile
@@ -6,10 +6,10 @@
6 6
7obj-$(CONFIG_MWAVE) += mwave.o 7obj-$(CONFIG_MWAVE) += mwave.o
8 8
9mwave-objs := mwavedd.o smapi.o tp3780i.o 3780i.o 9mwave-y := mwavedd.o smapi.o tp3780i.o 3780i.o
10 10
11# To have the mwave driver disable other uarts if necessary 11# To have the mwave driver disable other uarts if necessary
12# EXTRA_CFLAGS += -DMWAVE_FUTZ_WITH_OTHER_DEVICES 12# EXTRA_CFLAGS += -DMWAVE_FUTZ_WITH_OTHER_DEVICES
13 13
14# To compile in lots (~20 KiB) of run-time enablable printk()s for debugging: 14# To compile in lots (~20 KiB) of run-time enablable printk()s for debugging:
15EXTRA_CFLAGS += -DMW_TRACE 15ccflags-y := -DMW_TRACE
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 463df27494bd..dd9d75351cd6 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -303,6 +303,7 @@ static void mxser_enable_must_enchance_mode(unsigned long baseio)
303 outb(oldlcr, baseio + UART_LCR); 303 outb(oldlcr, baseio + UART_LCR);
304} 304}
305 305
306#ifdef CONFIG_PCI
306static void mxser_disable_must_enchance_mode(unsigned long baseio) 307static void mxser_disable_must_enchance_mode(unsigned long baseio)
307{ 308{
308 u8 oldlcr; 309 u8 oldlcr;
@@ -317,6 +318,7 @@ static void mxser_disable_must_enchance_mode(unsigned long baseio)
317 outb(efr, baseio + MOXA_MUST_EFR_REGISTER); 318 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
318 outb(oldlcr, baseio + UART_LCR); 319 outb(oldlcr, baseio + UART_LCR);
319} 320}
321#endif
320 322
321static void mxser_set_must_xon1_value(unsigned long baseio, u8 value) 323static void mxser_set_must_xon1_value(unsigned long baseio, u8 value)
322{ 324{
@@ -388,6 +390,7 @@ static void mxser_set_must_enum_value(unsigned long baseio, u8 value)
388 outb(oldlcr, baseio + UART_LCR); 390 outb(oldlcr, baseio + UART_LCR);
389} 391}
390 392
393#ifdef CONFIG_PCI
391static void mxser_get_must_hardware_id(unsigned long baseio, u8 *pId) 394static void mxser_get_must_hardware_id(unsigned long baseio, u8 *pId)
392{ 395{
393 u8 oldlcr; 396 u8 oldlcr;
@@ -404,6 +407,7 @@ static void mxser_get_must_hardware_id(unsigned long baseio, u8 *pId)
404 *pId = inb(baseio + MOXA_MUST_HWID_REGISTER); 407 *pId = inb(baseio + MOXA_MUST_HWID_REGISTER);
405 outb(oldlcr, baseio + UART_LCR); 408 outb(oldlcr, baseio + UART_LCR);
406} 409}
410#endif
407 411
408static void SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(unsigned long baseio) 412static void SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(unsigned long baseio)
409{ 413{
diff --git a/drivers/char/pcmcia/ipwireless/Makefile b/drivers/char/pcmcia/ipwireless/Makefile
index b71eb593643d..db80873d7f20 100644
--- a/drivers/char/pcmcia/ipwireless/Makefile
+++ b/drivers/char/pcmcia/ipwireless/Makefile
@@ -6,5 +6,5 @@
6 6
7obj-$(CONFIG_IPWIRELESS) += ipwireless.o 7obj-$(CONFIG_IPWIRELESS) += ipwireless.o
8 8
9ipwireless-objs := hardware.o main.o network.o tty.o 9ipwireless-y := hardware.o main.o network.o tty.o
10 10
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 723152d978a9..f176dbaeb15a 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -613,6 +613,7 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
613 613
614 case PPGETTIME: 614 case PPGETTIME:
615 to_jiffies = pp->pdev->timeout; 615 to_jiffies = pp->pdev->timeout;
616 memset(&par_timeout, 0, sizeof(par_timeout));
616 par_timeout.tv_sec = to_jiffies / HZ; 617 par_timeout.tv_sec = to_jiffies / HZ;
617 par_timeout.tv_usec = (to_jiffies % (long)HZ) * (1000000/HZ); 618 par_timeout.tv_usec = (to_jiffies % (long)HZ) * (1000000/HZ);
618 if (copy_to_user (argp, &par_timeout, sizeof(struct timeval))) 619 if (copy_to_user (argp, &par_timeout, sizeof(struct timeval)))
diff --git a/drivers/char/ramoops.c b/drivers/char/ramoops.c
index 74f00b5ffa36..73dcb0ee41fd 100644
--- a/drivers/char/ramoops.c
+++ b/drivers/char/ramoops.c
@@ -25,6 +25,8 @@
25#include <linux/time.h> 25#include <linux/time.h>
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/ioport.h> 27#include <linux/ioport.h>
28#include <linux/platform_device.h>
29#include <linux/ramoops.h>
28 30
29#define RAMOOPS_KERNMSG_HDR "====" 31#define RAMOOPS_KERNMSG_HDR "===="
30#define RAMOOPS_HEADER_SIZE (5 + sizeof(struct timeval)) 32#define RAMOOPS_HEADER_SIZE (5 + sizeof(struct timeval))
@@ -91,11 +93,17 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper,
91 cxt->count = (cxt->count + 1) % cxt->max_count; 93 cxt->count = (cxt->count + 1) % cxt->max_count;
92} 94}
93 95
94static int __init ramoops_init(void) 96static int __init ramoops_probe(struct platform_device *pdev)
95{ 97{
98 struct ramoops_platform_data *pdata = pdev->dev.platform_data;
96 struct ramoops_context *cxt = &oops_cxt; 99 struct ramoops_context *cxt = &oops_cxt;
97 int err = -EINVAL; 100 int err = -EINVAL;
98 101
102 if (pdata) {
103 mem_size = pdata->mem_size;
104 mem_address = pdata->mem_address;
105 }
106
99 if (!mem_size) { 107 if (!mem_size) {
100 printk(KERN_ERR "ramoops: invalid size specification"); 108 printk(KERN_ERR "ramoops: invalid size specification");
101 goto fail3; 109 goto fail3;
@@ -142,7 +150,7 @@ fail3:
142 return err; 150 return err;
143} 151}
144 152
145static void __exit ramoops_exit(void) 153static int __exit ramoops_remove(struct platform_device *pdev)
146{ 154{
147 struct ramoops_context *cxt = &oops_cxt; 155 struct ramoops_context *cxt = &oops_cxt;
148 156
@@ -151,8 +159,26 @@ static void __exit ramoops_exit(void)
151 159
152 iounmap(cxt->virt_addr); 160 iounmap(cxt->virt_addr);
153 release_mem_region(cxt->phys_addr, cxt->size); 161 release_mem_region(cxt->phys_addr, cxt->size);
162 return 0;
154} 163}
155 164
165static struct platform_driver ramoops_driver = {
166 .remove = __exit_p(ramoops_remove),
167 .driver = {
168 .name = "ramoops",
169 .owner = THIS_MODULE,
170 },
171};
172
173static int __init ramoops_init(void)
174{
175 return platform_driver_probe(&ramoops_driver, ramoops_probe);
176}
177
178static void __exit ramoops_exit(void)
179{
180 platform_driver_unregister(&ramoops_driver);
181}
156 182
157module_init(ramoops_init); 183module_init(ramoops_init);
158module_exit(ramoops_exit); 184module_exit(ramoops_exit);
diff --git a/drivers/char/rio/Makefile b/drivers/char/rio/Makefile
index 2d1c5a7cba7d..1661875883fb 100644
--- a/drivers/char/rio/Makefile
+++ b/drivers/char/rio/Makefile
@@ -8,5 +8,5 @@
8 8
9obj-$(CONFIG_RIO) += rio.o 9obj-$(CONFIG_RIO) += rio.o
10 10
11rio-objs := rio_linux.o rioinit.o rioboot.o riocmd.o rioctrl.o riointr.o \ 11rio-y := rio_linux.o rioinit.o rioboot.o riocmd.o rioctrl.o riointr.o \
12 rioparam.o rioroute.o riotable.o riotty.o 12 rioparam.o rioroute.o riotable.o riotty.o
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index 7c79d243acc9..86308830ac42 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -2345,7 +2345,7 @@ static int __init rp_init(void)
2345 ret = tty_register_driver(rocket_driver); 2345 ret = tty_register_driver(rocket_driver);
2346 if (ret < 0) { 2346 if (ret < 0) {
2347 printk(KERN_ERR "Couldn't install tty RocketPort driver\n"); 2347 printk(KERN_ERR "Couldn't install tty RocketPort driver\n");
2348 goto err_tty; 2348 goto err_controller;
2349 } 2349 }
2350 2350
2351#ifdef ROCKET_DEBUG_OPEN 2351#ifdef ROCKET_DEBUG_OPEN
@@ -2380,6 +2380,9 @@ static int __init rp_init(void)
2380 return 0; 2380 return 0;
2381err_ttyu: 2381err_ttyu:
2382 tty_unregister_driver(rocket_driver); 2382 tty_unregister_driver(rocket_driver);
2383err_controller:
2384 if (controller)
2385 release_region(controller, 4);
2383err_tty: 2386err_tty:
2384 put_tty_driver(rocket_driver); 2387 put_tty_driver(rocket_driver);
2385err: 2388err:
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 1746d91205f7..d01fffeac951 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -301,6 +301,8 @@ struct slgt_info {
301 unsigned int rx_pio; 301 unsigned int rx_pio;
302 unsigned int if_mode; 302 unsigned int if_mode;
303 unsigned int base_clock; 303 unsigned int base_clock;
304 unsigned int xsync;
305 unsigned int xctrl;
304 306
305 /* device status */ 307 /* device status */
306 308
@@ -405,6 +407,8 @@ static MGSL_PARAMS default_params = {
405#define TDCSR 0x94 /* tx DMA control/status */ 407#define TDCSR 0x94 /* tx DMA control/status */
406#define RDDAR 0x98 /* rx DMA descriptor address */ 408#define RDDAR 0x98 /* rx DMA descriptor address */
407#define TDDAR 0x9c /* tx DMA descriptor address */ 409#define TDDAR 0x9c /* tx DMA descriptor address */
410#define XSR 0x40 /* extended sync pattern */
411#define XCR 0x44 /* extended control */
408 412
409#define RXIDLE BIT14 413#define RXIDLE BIT14
410#define RXBREAK BIT14 414#define RXBREAK BIT14
@@ -517,6 +521,10 @@ static int set_interface(struct slgt_info *info, int if_mode);
517static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio); 521static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
518static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio); 522static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
519static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio); 523static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
524static int get_xsync(struct slgt_info *info, int __user *if_mode);
525static int set_xsync(struct slgt_info *info, int if_mode);
526static int get_xctrl(struct slgt_info *info, int __user *if_mode);
527static int set_xctrl(struct slgt_info *info, int if_mode);
520 528
521/* 529/*
522 * driver functions 530 * driver functions
@@ -1056,6 +1064,14 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1056 return get_gpio(info, argp); 1064 return get_gpio(info, argp);
1057 case MGSL_IOCWAITGPIO: 1065 case MGSL_IOCWAITGPIO:
1058 return wait_gpio(info, argp); 1066 return wait_gpio(info, argp);
1067 case MGSL_IOCGXSYNC:
1068 return get_xsync(info, argp);
1069 case MGSL_IOCSXSYNC:
1070 return set_xsync(info, (int)arg);
1071 case MGSL_IOCGXCTRL:
1072 return get_xctrl(info, argp);
1073 case MGSL_IOCSXCTRL:
1074 return set_xctrl(info, (int)arg);
1059 } 1075 }
1060 mutex_lock(&info->port.mutex); 1076 mutex_lock(&info->port.mutex);
1061 switch (cmd) { 1077 switch (cmd) {
@@ -1132,6 +1148,7 @@ static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *us
1132 struct MGSL_PARAMS32 tmp_params; 1148 struct MGSL_PARAMS32 tmp_params;
1133 1149
1134 DBGINFO(("%s get_params32\n", info->device_name)); 1150 DBGINFO(("%s get_params32\n", info->device_name));
1151 memset(&tmp_params, 0, sizeof(tmp_params));
1135 tmp_params.mode = (compat_ulong_t)info->params.mode; 1152 tmp_params.mode = (compat_ulong_t)info->params.mode;
1136 tmp_params.loopback = info->params.loopback; 1153 tmp_params.loopback = info->params.loopback;
1137 tmp_params.flags = info->params.flags; 1154 tmp_params.flags = info->params.flags;
@@ -1212,12 +1229,16 @@ static long slgt_compat_ioctl(struct tty_struct *tty, struct file *file,
1212 case MGSL_IOCSGPIO: 1229 case MGSL_IOCSGPIO:
1213 case MGSL_IOCGGPIO: 1230 case MGSL_IOCGGPIO:
1214 case MGSL_IOCWAITGPIO: 1231 case MGSL_IOCWAITGPIO:
1232 case MGSL_IOCGXSYNC:
1233 case MGSL_IOCGXCTRL:
1215 case MGSL_IOCSTXIDLE: 1234 case MGSL_IOCSTXIDLE:
1216 case MGSL_IOCTXENABLE: 1235 case MGSL_IOCTXENABLE:
1217 case MGSL_IOCRXENABLE: 1236 case MGSL_IOCRXENABLE:
1218 case MGSL_IOCTXABORT: 1237 case MGSL_IOCTXABORT:
1219 case TIOCMIWAIT: 1238 case TIOCMIWAIT:
1220 case MGSL_IOCSIF: 1239 case MGSL_IOCSIF:
1240 case MGSL_IOCSXSYNC:
1241 case MGSL_IOCSXCTRL:
1221 rc = ioctl(tty, file, cmd, arg); 1242 rc = ioctl(tty, file, cmd, arg);
1222 break; 1243 break;
1223 } 1244 }
@@ -1617,6 +1638,8 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1617 if (cmd != SIOCWANDEV) 1638 if (cmd != SIOCWANDEV)
1618 return hdlc_ioctl(dev, ifr, cmd); 1639 return hdlc_ioctl(dev, ifr, cmd);
1619 1640
1641 memset(&new_line, 0, sizeof(new_line));
1642
1620 switch(ifr->ifr_settings.type) { 1643 switch(ifr->ifr_settings.type) {
1621 case IF_GET_IFACE: /* return current sync_serial_settings */ 1644 case IF_GET_IFACE: /* return current sync_serial_settings */
1622 1645
@@ -1958,6 +1981,7 @@ static void bh_handler(struct work_struct *work)
1958 case MGSL_MODE_RAW: 1981 case MGSL_MODE_RAW:
1959 case MGSL_MODE_MONOSYNC: 1982 case MGSL_MODE_MONOSYNC:
1960 case MGSL_MODE_BISYNC: 1983 case MGSL_MODE_BISYNC:
1984 case MGSL_MODE_XSYNC:
1961 while(rx_get_buf(info)); 1985 while(rx_get_buf(info));
1962 break; 1986 break;
1963 } 1987 }
@@ -2357,26 +2381,27 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
2357 2381
2358 DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level)); 2382 DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level));
2359 2383
2360 spin_lock(&info->lock);
2361
2362 while((gsr = rd_reg32(info, GSR) & 0xffffff00)) { 2384 while((gsr = rd_reg32(info, GSR) & 0xffffff00)) {
2363 DBGISR(("%s gsr=%08x\n", info->device_name, gsr)); 2385 DBGISR(("%s gsr=%08x\n", info->device_name, gsr));
2364 info->irq_occurred = true; 2386 info->irq_occurred = true;
2365 for(i=0; i < info->port_count ; i++) { 2387 for(i=0; i < info->port_count ; i++) {
2366 if (info->port_array[i] == NULL) 2388 if (info->port_array[i] == NULL)
2367 continue; 2389 continue;
2390 spin_lock(&info->port_array[i]->lock);
2368 if (gsr & (BIT8 << i)) 2391 if (gsr & (BIT8 << i))
2369 isr_serial(info->port_array[i]); 2392 isr_serial(info->port_array[i]);
2370 if (gsr & (BIT16 << (i*2))) 2393 if (gsr & (BIT16 << (i*2)))
2371 isr_rdma(info->port_array[i]); 2394 isr_rdma(info->port_array[i]);
2372 if (gsr & (BIT17 << (i*2))) 2395 if (gsr & (BIT17 << (i*2)))
2373 isr_tdma(info->port_array[i]); 2396 isr_tdma(info->port_array[i]);
2397 spin_unlock(&info->port_array[i]->lock);
2374 } 2398 }
2375 } 2399 }
2376 2400
2377 if (info->gpio_present) { 2401 if (info->gpio_present) {
2378 unsigned int state; 2402 unsigned int state;
2379 unsigned int changed; 2403 unsigned int changed;
2404 spin_lock(&info->lock);
2380 while ((changed = rd_reg32(info, IOSR)) != 0) { 2405 while ((changed = rd_reg32(info, IOSR)) != 0) {
2381 DBGISR(("%s iosr=%08x\n", info->device_name, changed)); 2406 DBGISR(("%s iosr=%08x\n", info->device_name, changed));
2382 /* read latched state of GPIO signals */ 2407 /* read latched state of GPIO signals */
@@ -2388,22 +2413,24 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
2388 isr_gpio(info->port_array[i], changed, state); 2413 isr_gpio(info->port_array[i], changed, state);
2389 } 2414 }
2390 } 2415 }
2416 spin_unlock(&info->lock);
2391 } 2417 }
2392 2418
2393 for(i=0; i < info->port_count ; i++) { 2419 for(i=0; i < info->port_count ; i++) {
2394 struct slgt_info *port = info->port_array[i]; 2420 struct slgt_info *port = info->port_array[i];
2395 2421 if (port == NULL)
2396 if (port && (port->port.count || port->netcount) && 2422 continue;
2423 spin_lock(&port->lock);
2424 if ((port->port.count || port->netcount) &&
2397 port->pending_bh && !port->bh_running && 2425 port->pending_bh && !port->bh_running &&
2398 !port->bh_requested) { 2426 !port->bh_requested) {
2399 DBGISR(("%s bh queued\n", port->device_name)); 2427 DBGISR(("%s bh queued\n", port->device_name));
2400 schedule_work(&port->task); 2428 schedule_work(&port->task);
2401 port->bh_requested = true; 2429 port->bh_requested = true;
2402 } 2430 }
2431 spin_unlock(&port->lock);
2403 } 2432 }
2404 2433
2405 spin_unlock(&info->lock);
2406
2407 DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level)); 2434 DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level));
2408 return IRQ_HANDLED; 2435 return IRQ_HANDLED;
2409} 2436}
@@ -2883,6 +2910,69 @@ static int set_interface(struct slgt_info *info, int if_mode)
2883 return 0; 2910 return 0;
2884} 2911}
2885 2912
2913static int get_xsync(struct slgt_info *info, int __user *xsync)
2914{
2915 DBGINFO(("%s get_xsync=%x\n", info->device_name, info->xsync));
2916 if (put_user(info->xsync, xsync))
2917 return -EFAULT;
2918 return 0;
2919}
2920
2921/*
2922 * set extended sync pattern (1 to 4 bytes) for extended sync mode
2923 *
2924 * sync pattern is contained in least significant bytes of value
2925 * most significant byte of sync pattern is oldest (1st sent/detected)
2926 */
2927static int set_xsync(struct slgt_info *info, int xsync)
2928{
2929 unsigned long flags;
2930
2931 DBGINFO(("%s set_xsync=%x)\n", info->device_name, xsync));
2932 spin_lock_irqsave(&info->lock, flags);
2933 info->xsync = xsync;
2934 wr_reg32(info, XSR, xsync);
2935 spin_unlock_irqrestore(&info->lock, flags);
2936 return 0;
2937}
2938
2939static int get_xctrl(struct slgt_info *info, int __user *xctrl)
2940{
2941 DBGINFO(("%s get_xctrl=%x\n", info->device_name, info->xctrl));
2942 if (put_user(info->xctrl, xctrl))
2943 return -EFAULT;
2944 return 0;
2945}
2946
2947/*
2948 * set extended control options
2949 *
2950 * xctrl[31:19] reserved, must be zero
2951 * xctrl[18:17] extended sync pattern length in bytes
2952 * 00 = 1 byte in xsr[7:0]
2953 * 01 = 2 bytes in xsr[15:0]
2954 * 10 = 3 bytes in xsr[23:0]
2955 * 11 = 4 bytes in xsr[31:0]
2956 * xctrl[16] 1 = enable terminal count, 0=disabled
2957 * xctrl[15:0] receive terminal count for fixed length packets
2958 * value is count minus one (0 = 1 byte packet)
2959 * when terminal count is reached, receiver
2960 * automatically returns to hunt mode and receive
2961 * FIFO contents are flushed to DMA buffers with
2962 * end of frame (EOF) status
2963 */
2964static int set_xctrl(struct slgt_info *info, int xctrl)
2965{
2966 unsigned long flags;
2967
2968 DBGINFO(("%s set_xctrl=%x)\n", info->device_name, xctrl));
2969 spin_lock_irqsave(&info->lock, flags);
2970 info->xctrl = xctrl;
2971 wr_reg32(info, XCR, xctrl);
2972 spin_unlock_irqrestore(&info->lock, flags);
2973 return 0;
2974}
2975
2886/* 2976/*
2887 * set general purpose IO pin state and direction 2977 * set general purpose IO pin state and direction
2888 * 2978 *
@@ -2906,7 +2996,7 @@ static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
2906 info->device_name, gpio.state, gpio.smask, 2996 info->device_name, gpio.state, gpio.smask,
2907 gpio.dir, gpio.dmask)); 2997 gpio.dir, gpio.dmask));
2908 2998
2909 spin_lock_irqsave(&info->lock,flags); 2999 spin_lock_irqsave(&info->port_array[0]->lock, flags);
2910 if (gpio.dmask) { 3000 if (gpio.dmask) {
2911 data = rd_reg32(info, IODR); 3001 data = rd_reg32(info, IODR);
2912 data |= gpio.dmask & gpio.dir; 3002 data |= gpio.dmask & gpio.dir;
@@ -2919,7 +3009,7 @@ static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
2919 data &= ~(gpio.smask & ~gpio.state); 3009 data &= ~(gpio.smask & ~gpio.state);
2920 wr_reg32(info, IOVR, data); 3010 wr_reg32(info, IOVR, data);
2921 } 3011 }
2922 spin_unlock_irqrestore(&info->lock,flags); 3012 spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
2923 3013
2924 return 0; 3014 return 0;
2925} 3015}
@@ -3020,7 +3110,7 @@ static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
3020 return -EINVAL; 3110 return -EINVAL;
3021 init_cond_wait(&wait, gpio.smask); 3111 init_cond_wait(&wait, gpio.smask);
3022 3112
3023 spin_lock_irqsave(&info->lock, flags); 3113 spin_lock_irqsave(&info->port_array[0]->lock, flags);
3024 /* enable interrupts for watched pins */ 3114 /* enable interrupts for watched pins */
3025 wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask); 3115 wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask);
3026 /* get current pin states */ 3116 /* get current pin states */
@@ -3032,20 +3122,20 @@ static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
3032 } else { 3122 } else {
3033 /* wait for target state */ 3123 /* wait for target state */
3034 add_cond_wait(&info->gpio_wait_q, &wait); 3124 add_cond_wait(&info->gpio_wait_q, &wait);
3035 spin_unlock_irqrestore(&info->lock, flags); 3125 spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
3036 schedule(); 3126 schedule();
3037 if (signal_pending(current)) 3127 if (signal_pending(current))
3038 rc = -ERESTARTSYS; 3128 rc = -ERESTARTSYS;
3039 else 3129 else
3040 gpio.state = wait.data; 3130 gpio.state = wait.data;
3041 spin_lock_irqsave(&info->lock, flags); 3131 spin_lock_irqsave(&info->port_array[0]->lock, flags);
3042 remove_cond_wait(&info->gpio_wait_q, &wait); 3132 remove_cond_wait(&info->gpio_wait_q, &wait);
3043 } 3133 }
3044 3134
3045 /* disable all GPIO interrupts if no waiting processes */ 3135 /* disable all GPIO interrupts if no waiting processes */
3046 if (info->gpio_wait_q == NULL) 3136 if (info->gpio_wait_q == NULL)
3047 wr_reg32(info, IOER, 0); 3137 wr_reg32(info, IOER, 0);
3048 spin_unlock_irqrestore(&info->lock,flags); 3138 spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
3049 3139
3050 if ((rc == 0) && copy_to_user(user_gpio, &gpio, sizeof(gpio))) 3140 if ((rc == 0) && copy_to_user(user_gpio, &gpio, sizeof(gpio)))
3051 rc = -EFAULT; 3141 rc = -EFAULT;
@@ -3578,7 +3668,6 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
3578 3668
3579 /* copy resource information from first port to others */ 3669 /* copy resource information from first port to others */
3580 for (i = 1; i < port_count; ++i) { 3670 for (i = 1; i < port_count; ++i) {
3581 port_array[i]->lock = port_array[0]->lock;
3582 port_array[i]->irq_level = port_array[0]->irq_level; 3671 port_array[i]->irq_level = port_array[0]->irq_level;
3583 port_array[i]->reg_addr = port_array[0]->reg_addr; 3672 port_array[i]->reg_addr = port_array[0]->reg_addr;
3584 alloc_dma_bufs(port_array[i]); 3673 alloc_dma_bufs(port_array[i]);
@@ -3763,7 +3852,9 @@ module_exit(slgt_exit);
3763#define CALC_REGADDR() \ 3852#define CALC_REGADDR() \
3764 unsigned long reg_addr = ((unsigned long)info->reg_addr) + addr; \ 3853 unsigned long reg_addr = ((unsigned long)info->reg_addr) + addr; \
3765 if (addr >= 0x80) \ 3854 if (addr >= 0x80) \
3766 reg_addr += (info->port_num) * 32; 3855 reg_addr += (info->port_num) * 32; \
3856 else if (addr >= 0x40) \
3857 reg_addr += (info->port_num) * 16;
3767 3858
3768static __u8 rd_reg8(struct slgt_info *info, unsigned int addr) 3859static __u8 rd_reg8(struct slgt_info *info, unsigned int addr)
3769{ 3860{
@@ -4182,7 +4273,13 @@ static void sync_mode(struct slgt_info *info)
4182 4273
4183 /* TCR (tx control) 4274 /* TCR (tx control)
4184 * 4275 *
4185 * 15..13 mode, 000=HDLC 001=raw 010=async 011=monosync 100=bisync 4276 * 15..13 mode
4277 * 000=HDLC/SDLC
4278 * 001=raw bit synchronous
4279 * 010=asynchronous/isochronous
4280 * 011=monosync byte synchronous
4281 * 100=bisync byte synchronous
4282 * 101=xsync byte synchronous
4186 * 12..10 encoding 4283 * 12..10 encoding
4187 * 09 CRC enable 4284 * 09 CRC enable
4188 * 08 CRC32 4285 * 08 CRC32
@@ -4197,6 +4294,9 @@ static void sync_mode(struct slgt_info *info)
4197 val = BIT2; 4294 val = BIT2;
4198 4295
4199 switch(info->params.mode) { 4296 switch(info->params.mode) {
4297 case MGSL_MODE_XSYNC:
4298 val |= BIT15 + BIT13;
4299 break;
4200 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break; 4300 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
4201 case MGSL_MODE_BISYNC: val |= BIT15; break; 4301 case MGSL_MODE_BISYNC: val |= BIT15; break;
4202 case MGSL_MODE_RAW: val |= BIT13; break; 4302 case MGSL_MODE_RAW: val |= BIT13; break;
@@ -4251,7 +4351,13 @@ static void sync_mode(struct slgt_info *info)
4251 4351
4252 /* RCR (rx control) 4352 /* RCR (rx control)
4253 * 4353 *
4254 * 15..13 mode, 000=HDLC 001=raw 010=async 011=monosync 100=bisync 4354 * 15..13 mode
4355 * 000=HDLC/SDLC
4356 * 001=raw bit synchronous
4357 * 010=asynchronous/isochronous
4358 * 011=monosync byte synchronous
4359 * 100=bisync byte synchronous
4360 * 101=xsync byte synchronous
4255 * 12..10 encoding 4361 * 12..10 encoding
4256 * 09 CRC enable 4362 * 09 CRC enable
4257 * 08 CRC32 4363 * 08 CRC32
@@ -4263,6 +4369,9 @@ static void sync_mode(struct slgt_info *info)
4263 val = 0; 4369 val = 0;
4264 4370
4265 switch(info->params.mode) { 4371 switch(info->params.mode) {
4372 case MGSL_MODE_XSYNC:
4373 val |= BIT15 + BIT13;
4374 break;
4266 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break; 4375 case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
4267 case MGSL_MODE_BISYNC: val |= BIT15; break; 4376 case MGSL_MODE_BISYNC: val |= BIT15; break;
4268 case MGSL_MODE_RAW: val |= BIT13; break; 4377 case MGSL_MODE_RAW: val |= BIT13; break;
@@ -4679,6 +4788,7 @@ static bool rx_get_buf(struct slgt_info *info)
4679 switch(info->params.mode) { 4788 switch(info->params.mode) {
4680 case MGSL_MODE_MONOSYNC: 4789 case MGSL_MODE_MONOSYNC:
4681 case MGSL_MODE_BISYNC: 4790 case MGSL_MODE_BISYNC:
4791 case MGSL_MODE_XSYNC:
4682 /* ignore residue in byte synchronous modes */ 4792 /* ignore residue in byte synchronous modes */
4683 if (desc_residue(info->rbufs[i])) 4793 if (desc_residue(info->rbufs[i]))
4684 count--; 4794 count--;
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index 38df8c19e74c..6b68a0fb4611 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -503,6 +503,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
503 struct kbd_struct * kbd; 503 struct kbd_struct * kbd;
504 unsigned int console; 504 unsigned int console;
505 unsigned char ucval; 505 unsigned char ucval;
506 unsigned int uival;
506 void __user *up = (void __user *)arg; 507 void __user *up = (void __user *)arg;
507 int i, perm; 508 int i, perm;
508 int ret = 0; 509 int ret = 0;
@@ -657,7 +658,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
657 break; 658 break;
658 659
659 case KDGETMODE: 660 case KDGETMODE:
660 ucval = vc->vc_mode; 661 uival = vc->vc_mode;
661 goto setint; 662 goto setint;
662 663
663 case KDMAPDISP: 664 case KDMAPDISP:
@@ -695,7 +696,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
695 break; 696 break;
696 697
697 case KDGKBMODE: 698 case KDGKBMODE:
698 ucval = ((kbd->kbdmode == VC_RAW) ? K_RAW : 699 uival = ((kbd->kbdmode == VC_RAW) ? K_RAW :
699 (kbd->kbdmode == VC_MEDIUMRAW) ? K_MEDIUMRAW : 700 (kbd->kbdmode == VC_MEDIUMRAW) ? K_MEDIUMRAW :
700 (kbd->kbdmode == VC_UNICODE) ? K_UNICODE : 701 (kbd->kbdmode == VC_UNICODE) ? K_UNICODE :
701 K_XLATE); 702 K_XLATE);
@@ -717,9 +718,9 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
717 break; 718 break;
718 719
719 case KDGKBMETA: 720 case KDGKBMETA:
720 ucval = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT); 721 uival = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT);
721 setint: 722 setint:
722 ret = put_user(ucval, (int __user *)arg); 723 ret = put_user(uival, (int __user *)arg);
723 break; 724 break;
724 725
725 case KDGETKEYCODE: 726 case KDGETKEYCODE:
@@ -949,7 +950,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
949 for (i = 0; i < MAX_NR_CONSOLES; ++i) 950 for (i = 0; i < MAX_NR_CONSOLES; ++i)
950 if (! VT_IS_IN_USE(i)) 951 if (! VT_IS_IN_USE(i))
951 break; 952 break;
952 ucval = i < MAX_NR_CONSOLES ? (i+1) : -1; 953 uival = i < MAX_NR_CONSOLES ? (i+1) : -1;
953 goto setint; 954 goto setint;
954 955
955 /* 956 /*
diff --git a/drivers/connector/cn_queue.c b/drivers/connector/cn_queue.c
index 210338ea222f..81270d221e5a 100644
--- a/drivers/connector/cn_queue.c
+++ b/drivers/connector/cn_queue.c
@@ -31,48 +31,6 @@
31#include <linux/connector.h> 31#include <linux/connector.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33 33
34
35/*
36 * This job is sent to the kevent workqueue.
37 * While no event is once sent to any callback, the connector workqueue
38 * is not created to avoid a useless waiting kernel task.
39 * Once the first event is received, we create this dedicated workqueue which
40 * is necessary because the flow of data can be high and we don't want
41 * to encumber keventd with that.
42 */
43static void cn_queue_create(struct work_struct *work)
44{
45 struct cn_queue_dev *dev;
46
47 dev = container_of(work, struct cn_queue_dev, wq_creation);
48
49 dev->cn_queue = create_singlethread_workqueue(dev->name);
50 /* If we fail, we will use keventd for all following connector jobs */
51 WARN_ON(!dev->cn_queue);
52}
53
54/*
55 * Queue a data sent to a callback.
56 * If the connector workqueue is already created, we queue the job on it.
57 * Otherwise, we queue the job to kevent and queue the connector workqueue
58 * creation too.
59 */
60int queue_cn_work(struct cn_callback_entry *cbq, struct work_struct *work)
61{
62 struct cn_queue_dev *pdev = cbq->pdev;
63
64 if (likely(pdev->cn_queue))
65 return queue_work(pdev->cn_queue, work);
66
67 /* Don't create the connector workqueue twice */
68 if (atomic_inc_return(&pdev->wq_requested) == 1)
69 schedule_work(&pdev->wq_creation);
70 else
71 atomic_dec(&pdev->wq_requested);
72
73 return schedule_work(work);
74}
75
76void cn_queue_wrapper(struct work_struct *work) 34void cn_queue_wrapper(struct work_struct *work)
77{ 35{
78 struct cn_callback_entry *cbq = 36 struct cn_callback_entry *cbq =
@@ -111,11 +69,7 @@ cn_queue_alloc_callback_entry(char *name, struct cb_id *id,
111 69
112static void cn_queue_free_callback(struct cn_callback_entry *cbq) 70static void cn_queue_free_callback(struct cn_callback_entry *cbq)
113{ 71{
114 /* The first jobs have been sent to kevent, flush them too */ 72 flush_workqueue(cbq->pdev->cn_queue);
115 flush_scheduled_work();
116 if (cbq->pdev->cn_queue)
117 flush_workqueue(cbq->pdev->cn_queue);
118
119 kfree(cbq); 73 kfree(cbq);
120} 74}
121 75
@@ -193,11 +147,14 @@ struct cn_queue_dev *cn_queue_alloc_dev(char *name, struct sock *nls)
193 atomic_set(&dev->refcnt, 0); 147 atomic_set(&dev->refcnt, 0);
194 INIT_LIST_HEAD(&dev->queue_list); 148 INIT_LIST_HEAD(&dev->queue_list);
195 spin_lock_init(&dev->queue_lock); 149 spin_lock_init(&dev->queue_lock);
196 init_waitqueue_head(&dev->wq_created);
197 150
198 dev->nls = nls; 151 dev->nls = nls;
199 152
200 INIT_WORK(&dev->wq_creation, cn_queue_create); 153 dev->cn_queue = alloc_ordered_workqueue(dev->name, 0);
154 if (!dev->cn_queue) {
155 kfree(dev);
156 return NULL;
157 }
201 158
202 return dev; 159 return dev;
203} 160}
@@ -205,25 +162,9 @@ struct cn_queue_dev *cn_queue_alloc_dev(char *name, struct sock *nls)
205void cn_queue_free_dev(struct cn_queue_dev *dev) 162void cn_queue_free_dev(struct cn_queue_dev *dev)
206{ 163{
207 struct cn_callback_entry *cbq, *n; 164 struct cn_callback_entry *cbq, *n;
208 long timeout;
209 DEFINE_WAIT(wait);
210
211 /* Flush the first pending jobs queued on kevent */
212 flush_scheduled_work();
213
214 /* If the connector workqueue creation is still pending, wait for it */
215 prepare_to_wait(&dev->wq_created, &wait, TASK_UNINTERRUPTIBLE);
216 if (atomic_read(&dev->wq_requested) && !dev->cn_queue) {
217 timeout = schedule_timeout(HZ * 2);
218 if (!timeout && !dev->cn_queue)
219 WARN_ON(1);
220 }
221 finish_wait(&dev->wq_created, &wait);
222 165
223 if (dev->cn_queue) { 166 flush_workqueue(dev->cn_queue);
224 flush_workqueue(dev->cn_queue); 167 destroy_workqueue(dev->cn_queue);
225 destroy_workqueue(dev->cn_queue);
226 }
227 168
228 spin_lock_bh(&dev->queue_lock); 169 spin_lock_bh(&dev->queue_lock);
229 list_for_each_entry_safe(cbq, n, &dev->queue_list, callback_entry) 170 list_for_each_entry_safe(cbq, n, &dev->queue_list, callback_entry)
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index 1d48f40342cb..e16c3fa8d2e3 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -133,7 +133,8 @@ static int cn_call_callback(struct sk_buff *skb)
133 __cbq->data.skb == NULL)) { 133 __cbq->data.skb == NULL)) {
134 __cbq->data.skb = skb; 134 __cbq->data.skb = skb;
135 135
136 if (queue_cn_work(__cbq, &__cbq->work)) 136 if (queue_work(dev->cbdev->cn_queue,
137 &__cbq->work))
137 err = 0; 138 err = 0;
138 else 139 else
139 err = -EINVAL; 140 err = -EINVAL;
@@ -148,13 +149,11 @@ static int cn_call_callback(struct sk_buff *skb)
148 d->callback = __cbq->data.callback; 149 d->callback = __cbq->data.callback;
149 d->free = __new_cbq; 150 d->free = __new_cbq;
150 151
151 __new_cbq->pdev = __cbq->pdev;
152
153 INIT_WORK(&__new_cbq->work, 152 INIT_WORK(&__new_cbq->work,
154 &cn_queue_wrapper); 153 &cn_queue_wrapper);
155 154
156 if (queue_cn_work(__new_cbq, 155 if (queue_work(dev->cbdev->cn_queue,
157 &__new_cbq->work)) 156 &__new_cbq->work))
158 err = 0; 157 err = 0;
159 else { 158 else {
160 kfree(__new_cbq); 159 kfree(__new_cbq);
diff --git a/drivers/dma/pch_dma.c b/drivers/dma/pch_dma.c
index 3533948b88ba..92b679024fed 100644
--- a/drivers/dma/pch_dma.c
+++ b/drivers/dma/pch_dma.c
@@ -926,6 +926,7 @@ static void __devexit pch_dma_remove(struct pci_dev *pdev)
926static const struct pci_device_id pch_dma_id_table[] = { 926static const struct pci_device_id pch_dma_id_table[] = {
927 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_DMA_8CH), 8 }, 927 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_DMA_8CH), 8 },
928 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_DMA_4CH), 4 }, 928 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_DMA_4CH), 4 },
929 { 0, },
929}; 930};
930 931
931static struct pci_driver pch_dma_driver = { 932static struct pci_driver pch_dma_driver = {
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index b3d22d659990..e28e41668177 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -2,6 +2,7 @@
2#include <linux/string.h> 2#include <linux/string.h>
3#include <linux/init.h> 3#include <linux/init.h>
4#include <linux/module.h> 4#include <linux/module.h>
5#include <linux/ctype.h>
5#include <linux/dmi.h> 6#include <linux/dmi.h>
6#include <linux/efi.h> 7#include <linux/efi.h>
7#include <linux/bootmem.h> 8#include <linux/bootmem.h>
@@ -361,6 +362,33 @@ static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
361 } 362 }
362} 363}
363 364
365static void __init print_filtered(const char *info)
366{
367 const char *p;
368
369 if (!info)
370 return;
371
372 for (p = info; *p; p++)
373 if (isprint(*p))
374 printk(KERN_CONT "%c", *p);
375 else
376 printk(KERN_CONT "\\x%02x", *p & 0xff);
377}
378
379static void __init dmi_dump_ids(void)
380{
381 printk(KERN_DEBUG "DMI: ");
382 print_filtered(dmi_get_system_info(DMI_BOARD_NAME));
383 printk(KERN_CONT "/");
384 print_filtered(dmi_get_system_info(DMI_PRODUCT_NAME));
385 printk(KERN_CONT ", BIOS ");
386 print_filtered(dmi_get_system_info(DMI_BIOS_VERSION));
387 printk(KERN_CONT " ");
388 print_filtered(dmi_get_system_info(DMI_BIOS_DATE));
389 printk(KERN_CONT "\n");
390}
391
364static int __init dmi_present(const char __iomem *p) 392static int __init dmi_present(const char __iomem *p)
365{ 393{
366 u8 buf[15]; 394 u8 buf[15];
@@ -381,8 +409,10 @@ static int __init dmi_present(const char __iomem *p)
381 buf[14] >> 4, buf[14] & 0xF); 409 buf[14] >> 4, buf[14] & 0xF);
382 else 410 else
383 printk(KERN_INFO "DMI present.\n"); 411 printk(KERN_INFO "DMI present.\n");
384 if (dmi_walk_early(dmi_decode) == 0) 412 if (dmi_walk_early(dmi_decode) == 0) {
413 dmi_dump_ids();
385 return 0; 414 return 0;
415 }
386 } 416 }
387 return 1; 417 return 1;
388} 418}
diff --git a/drivers/gpio/74x164.c b/drivers/gpio/74x164.c
new file mode 100644
index 000000000000..d91ff4c282e9
--- /dev/null
+++ b/drivers/gpio/74x164.c
@@ -0,0 +1,182 @@
1/*
2 * 74Hx164 - Generic serial-in/parallel-out 8-bits shift register GPIO driver
3 *
4 * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2010 Miguel Gaio <miguel.gaio@efixo.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/init.h>
13#include <linux/mutex.h>
14#include <linux/spi/spi.h>
15#include <linux/spi/74x164.h>
16#include <linux/gpio.h>
17#include <linux/slab.h>
18
19#define GEN_74X164_GPIO_COUNT 8
20
21
22struct gen_74x164_chip {
23 struct spi_device *spi;
24 struct gpio_chip gpio_chip;
25 struct mutex lock;
26 u8 port_config;
27};
28
29static void gen_74x164_set_value(struct gpio_chip *, unsigned, int);
30
31static struct gen_74x164_chip *gpio_to_chip(struct gpio_chip *gc)
32{
33 return container_of(gc, struct gen_74x164_chip, gpio_chip);
34}
35
36static int __gen_74x164_write_config(struct gen_74x164_chip *chip)
37{
38 return spi_write(chip->spi,
39 &chip->port_config, sizeof(chip->port_config));
40}
41
42static int gen_74x164_direction_output(struct gpio_chip *gc,
43 unsigned offset, int val)
44{
45 gen_74x164_set_value(gc, offset, val);
46 return 0;
47}
48
49static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset)
50{
51 struct gen_74x164_chip *chip = gpio_to_chip(gc);
52 int ret;
53
54 mutex_lock(&chip->lock);
55 ret = (chip->port_config >> offset) & 0x1;
56 mutex_unlock(&chip->lock);
57
58 return ret;
59}
60
61static void gen_74x164_set_value(struct gpio_chip *gc,
62 unsigned offset, int val)
63{
64 struct gen_74x164_chip *chip = gpio_to_chip(gc);
65
66 mutex_lock(&chip->lock);
67 if (val)
68 chip->port_config |= (1 << offset);
69 else
70 chip->port_config &= ~(1 << offset);
71
72 __gen_74x164_write_config(chip);
73 mutex_unlock(&chip->lock);
74}
75
76static int __devinit gen_74x164_probe(struct spi_device *spi)
77{
78 struct gen_74x164_chip *chip;
79 struct gen_74x164_chip_platform_data *pdata;
80 int ret;
81
82 pdata = spi->dev.platform_data;
83 if (!pdata || !pdata->base) {
84 dev_dbg(&spi->dev, "incorrect or missing platform data\n");
85 return -EINVAL;
86 }
87
88 /*
89 * bits_per_word cannot be configured in platform data
90 */
91 spi->bits_per_word = 8;
92
93 ret = spi_setup(spi);
94 if (ret < 0)
95 return ret;
96
97 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
98 if (!chip)
99 return -ENOMEM;
100
101 mutex_init(&chip->lock);
102
103 dev_set_drvdata(&spi->dev, chip);
104
105 chip->spi = spi;
106
107 chip->gpio_chip.label = GEN_74X164_DRIVER_NAME,
108 chip->gpio_chip.direction_output = gen_74x164_direction_output;
109 chip->gpio_chip.get = gen_74x164_get_value;
110 chip->gpio_chip.set = gen_74x164_set_value;
111 chip->gpio_chip.base = pdata->base;
112 chip->gpio_chip.ngpio = GEN_74X164_GPIO_COUNT;
113 chip->gpio_chip.can_sleep = 1;
114 chip->gpio_chip.dev = &spi->dev;
115 chip->gpio_chip.owner = THIS_MODULE;
116
117 ret = __gen_74x164_write_config(chip);
118 if (ret) {
119 dev_err(&spi->dev, "Failed writing: %d\n", ret);
120 goto exit_destroy;
121 }
122
123 ret = gpiochip_add(&chip->gpio_chip);
124 if (ret)
125 goto exit_destroy;
126
127 return ret;
128
129exit_destroy:
130 dev_set_drvdata(&spi->dev, NULL);
131 mutex_destroy(&chip->lock);
132 kfree(chip);
133 return ret;
134}
135
136static int gen_74x164_remove(struct spi_device *spi)
137{
138 struct gen_74x164_chip *chip;
139 int ret;
140
141 chip = dev_get_drvdata(&spi->dev);
142 if (chip == NULL)
143 return -ENODEV;
144
145 dev_set_drvdata(&spi->dev, NULL);
146
147 ret = gpiochip_remove(&chip->gpio_chip);
148 if (!ret) {
149 mutex_destroy(&chip->lock);
150 kfree(chip);
151 } else
152 dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n",
153 ret);
154
155 return ret;
156}
157
158static struct spi_driver gen_74x164_driver = {
159 .driver = {
160 .name = GEN_74X164_DRIVER_NAME,
161 .owner = THIS_MODULE,
162 },
163 .probe = gen_74x164_probe,
164 .remove = __devexit_p(gen_74x164_remove),
165};
166
167static int __init gen_74x164_init(void)
168{
169 return spi_register_driver(&gen_74x164_driver);
170}
171subsys_initcall(gen_74x164_init);
172
173static void __exit gen_74x164_exit(void)
174{
175 spi_unregister_driver(&gen_74x164_driver);
176}
177module_exit(gen_74x164_exit);
178
179MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
180MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>");
181MODULE_DESCRIPTION("GPIO expander driver for 74X164 8-bits shift register");
182MODULE_LICENSE("GPL v2");
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 510aa2054544..dd9b4ba8d32d 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -70,6 +70,11 @@ config GPIO_MAX730X
70 70
71comment "Memory mapped GPIO expanders:" 71comment "Memory mapped GPIO expanders:"
72 72
73config GPIO_BASIC_MMIO
74 tristate "Basic memory-mapped GPIO controllers support"
75 help
76 Say yes here to support basic memory-mapped GPIO controllers.
77
73config GPIO_IT8761E 78config GPIO_IT8761E
74 tristate "IT8761E GPIO support" 79 tristate "IT8761E GPIO support"
75 depends on GPIOLIB 80 depends on GPIOLIB
@@ -267,6 +272,13 @@ config GPIO_ADP5588
267 To compile this driver as a module, choose M here: the module will be 272 To compile this driver as a module, choose M here: the module will be
268 called adp5588-gpio. 273 called adp5588-gpio.
269 274
275config GPIO_ADP5588_IRQ
276 bool "Interrupt controller support for ADP5588"
277 depends on GPIO_ADP5588=y
278 help
279 Say yes here to enable the adp5588 to be used as an interrupt
280 controller. It requires the driver to be built in the kernel.
281
270comment "PCI GPIO expanders:" 282comment "PCI GPIO expanders:"
271 283
272config GPIO_CS5535 284config GPIO_CS5535
@@ -301,6 +313,14 @@ config GPIO_LANGWELL
301 help 313 help
302 Say Y here to support Intel Langwell/Penwell GPIO. 314 Say Y here to support Intel Langwell/Penwell GPIO.
303 315
316config GPIO_PCH
317 tristate "PCH GPIO of Intel Topcliff"
318 depends on PCI
319 help
320 This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff
321 which is an IOH(Input/Output Hub) for x86 embedded processor.
322 This driver can access PCH GPIO device.
323
304config GPIO_TIMBERDALE 324config GPIO_TIMBERDALE
305 bool "Support for timberdale GPIO IP" 325 bool "Support for timberdale GPIO IP"
306 depends on MFD_TIMBERDALE && GPIOLIB && HAS_IOMEM 326 depends on MFD_TIMBERDALE && GPIOLIB && HAS_IOMEM
@@ -339,6 +359,14 @@ config GPIO_MC33880
339 SPI driver for Freescale MC33880 high-side/low-side switch. 359 SPI driver for Freescale MC33880 high-side/low-side switch.
340 This provides GPIO interface supporting inputs and outputs. 360 This provides GPIO interface supporting inputs and outputs.
341 361
362config GPIO_74X164
363 tristate "74x164 serial-in/parallel-out 8-bits shift register"
364 depends on SPI_MASTER
365 help
366 Platform driver for 74x164 compatible serial-in/parallel-out
367 8-outputs shift registers. This driver can be used to provide access
368 to more gpio outputs.
369
342comment "AC97 GPIO expanders:" 370comment "AC97 GPIO expanders:"
343 371
344config GPIO_UCB1400 372config GPIO_UCB1400
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index fc6019d93720..da2ecde5abdd 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_GPIOLIB) += gpiolib.o
10 10
11obj-$(CONFIG_GPIO_ADP5520) += adp5520-gpio.o 11obj-$(CONFIG_GPIO_ADP5520) += adp5520-gpio.o
12obj-$(CONFIG_GPIO_ADP5588) += adp5588-gpio.o 12obj-$(CONFIG_GPIO_ADP5588) += adp5588-gpio.o
13obj-$(CONFIG_GPIO_BASIC_MMIO) += basic_mmio_gpio.o
13obj-$(CONFIG_GPIO_LANGWELL) += langwell_gpio.o 14obj-$(CONFIG_GPIO_LANGWELL) += langwell_gpio.o
14obj-$(CONFIG_GPIO_MAX730X) += max730x.o 15obj-$(CONFIG_GPIO_MAX730X) += max730x.o
15obj-$(CONFIG_GPIO_MAX7300) += max7300.o 16obj-$(CONFIG_GPIO_MAX7300) += max7300.o
@@ -17,8 +18,10 @@ obj-$(CONFIG_GPIO_MAX7301) += max7301.o
17obj-$(CONFIG_GPIO_MAX732X) += max732x.o 18obj-$(CONFIG_GPIO_MAX732X) += max732x.o
18obj-$(CONFIG_GPIO_MC33880) += mc33880.o 19obj-$(CONFIG_GPIO_MC33880) += mc33880.o
19obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o 20obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
21obj-$(CONFIG_GPIO_74X164) += 74x164.o
20obj-$(CONFIG_GPIO_PCA953X) += pca953x.o 22obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
21obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o 23obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
24obj-$(CONFIG_GPIO_PCH) += pch_gpio.o
22obj-$(CONFIG_GPIO_PL061) += pl061.o 25obj-$(CONFIG_GPIO_PL061) += pl061.o
23obj-$(CONFIG_GPIO_STMPE) += stmpe-gpio.o 26obj-$(CONFIG_GPIO_STMPE) += stmpe-gpio.o
24obj-$(CONFIG_GPIO_TC35892) += tc35892-gpio.o 27obj-$(CONFIG_GPIO_TC35892) += tc35892-gpio.o
diff --git a/drivers/gpio/adp5588-gpio.c b/drivers/gpio/adp5588-gpio.c
index 2e8e9e24f887..0871f78af593 100644
--- a/drivers/gpio/adp5588-gpio.c
+++ b/drivers/gpio/adp5588-gpio.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * GPIO Chip driver for Analog Devices 2 * GPIO Chip driver for Analog Devices
3 * ADP5588 I/O Expander and QWERTY Keypad Controller 3 * ADP5588/ADP5587 I/O Expander and QWERTY Keypad Controller
4 * 4 *
5 * Copyright 2009 Analog Devices Inc. 5 * Copyright 2009-2010 Analog Devices Inc.
6 * 6 *
7 * Licensed under the GPL-2 or later. 7 * Licensed under the GPL-2 or later.
8 */ 8 */
@@ -13,21 +13,34 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/gpio.h> 15#include <linux/gpio.h>
16#include <linux/interrupt.h>
17#include <linux/irq.h>
16 18
17#include <linux/i2c/adp5588.h> 19#include <linux/i2c/adp5588.h>
18 20
19#define DRV_NAME "adp5588-gpio" 21#define DRV_NAME "adp5588-gpio"
20#define MAXGPIO 18 22
21#define ADP_BANK(offs) ((offs) >> 3) 23/*
22#define ADP_BIT(offs) (1u << ((offs) & 0x7)) 24 * Early pre 4.0 Silicon required to delay readout by at least 25ms,
25 * since the Event Counter Register updated 25ms after the interrupt
26 * asserted.
27 */
28#define WA_DELAYED_READOUT_REVID(rev) ((rev) < 4)
23 29
24struct adp5588_gpio { 30struct adp5588_gpio {
25 struct i2c_client *client; 31 struct i2c_client *client;
26 struct gpio_chip gpio_chip; 32 struct gpio_chip gpio_chip;
27 struct mutex lock; /* protect cached dir, dat_out */ 33 struct mutex lock; /* protect cached dir, dat_out */
34 /* protect serialized access to the interrupt controller bus */
35 struct mutex irq_lock;
28 unsigned gpio_start; 36 unsigned gpio_start;
37 unsigned irq_base;
29 uint8_t dat_out[3]; 38 uint8_t dat_out[3];
30 uint8_t dir[3]; 39 uint8_t dir[3];
40 uint8_t int_lvl[3];
41 uint8_t int_en[3];
42 uint8_t irq_mask[3];
43 uint8_t irq_stat[3];
31}; 44};
32 45
33static int adp5588_gpio_read(struct i2c_client *client, u8 reg) 46static int adp5588_gpio_read(struct i2c_client *client, u8 reg)
@@ -55,8 +68,8 @@ static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
55 struct adp5588_gpio *dev = 68 struct adp5588_gpio *dev =
56 container_of(chip, struct adp5588_gpio, gpio_chip); 69 container_of(chip, struct adp5588_gpio, gpio_chip);
57 70
58 return !!(adp5588_gpio_read(dev->client, GPIO_DAT_STAT1 + ADP_BANK(off)) 71 return !!(adp5588_gpio_read(dev->client,
59 & ADP_BIT(off)); 72 GPIO_DAT_STAT1 + ADP5588_BANK(off)) & ADP5588_BIT(off));
60} 73}
61 74
62static void adp5588_gpio_set_value(struct gpio_chip *chip, 75static void adp5588_gpio_set_value(struct gpio_chip *chip,
@@ -66,8 +79,8 @@ static void adp5588_gpio_set_value(struct gpio_chip *chip,
66 struct adp5588_gpio *dev = 79 struct adp5588_gpio *dev =
67 container_of(chip, struct adp5588_gpio, gpio_chip); 80 container_of(chip, struct adp5588_gpio, gpio_chip);
68 81
69 bank = ADP_BANK(off); 82 bank = ADP5588_BANK(off);
70 bit = ADP_BIT(off); 83 bit = ADP5588_BIT(off);
71 84
72 mutex_lock(&dev->lock); 85 mutex_lock(&dev->lock);
73 if (val) 86 if (val)
@@ -87,10 +100,10 @@ static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off)
87 struct adp5588_gpio *dev = 100 struct adp5588_gpio *dev =
88 container_of(chip, struct adp5588_gpio, gpio_chip); 101 container_of(chip, struct adp5588_gpio, gpio_chip);
89 102
90 bank = ADP_BANK(off); 103 bank = ADP5588_BANK(off);
91 104
92 mutex_lock(&dev->lock); 105 mutex_lock(&dev->lock);
93 dev->dir[bank] &= ~ADP_BIT(off); 106 dev->dir[bank] &= ~ADP5588_BIT(off);
94 ret = adp5588_gpio_write(dev->client, GPIO_DIR1 + bank, dev->dir[bank]); 107 ret = adp5588_gpio_write(dev->client, GPIO_DIR1 + bank, dev->dir[bank]);
95 mutex_unlock(&dev->lock); 108 mutex_unlock(&dev->lock);
96 109
@@ -105,8 +118,8 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
105 struct adp5588_gpio *dev = 118 struct adp5588_gpio *dev =
106 container_of(chip, struct adp5588_gpio, gpio_chip); 119 container_of(chip, struct adp5588_gpio, gpio_chip);
107 120
108 bank = ADP_BANK(off); 121 bank = ADP5588_BANK(off);
109 bit = ADP_BIT(off); 122 bit = ADP5588_BIT(off);
110 123
111 mutex_lock(&dev->lock); 124 mutex_lock(&dev->lock);
112 dev->dir[bank] |= bit; 125 dev->dir[bank] |= bit;
@@ -125,6 +138,213 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
125 return ret; 138 return ret;
126} 139}
127 140
141#ifdef CONFIG_GPIO_ADP5588_IRQ
142static int adp5588_gpio_to_irq(struct gpio_chip *chip, unsigned off)
143{
144 struct adp5588_gpio *dev =
145 container_of(chip, struct adp5588_gpio, gpio_chip);
146 return dev->irq_base + off;
147}
148
149static void adp5588_irq_bus_lock(unsigned int irq)
150{
151 struct adp5588_gpio *dev = get_irq_chip_data(irq);
152 mutex_lock(&dev->irq_lock);
153}
154
155 /*
156 * genirq core code can issue chip->mask/unmask from atomic context.
157 * This doesn't work for slow busses where an access needs to sleep.
158 * bus_sync_unlock() is therefore called outside the atomic context,
159 * syncs the current irq mask state with the slow external controller
160 * and unlocks the bus.
161 */
162
163static void adp5588_irq_bus_sync_unlock(unsigned int irq)
164{
165 struct adp5588_gpio *dev = get_irq_chip_data(irq);
166 int i;
167
168 for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++)
169 if (dev->int_en[i] ^ dev->irq_mask[i]) {
170 dev->int_en[i] = dev->irq_mask[i];
171 adp5588_gpio_write(dev->client, GPIO_INT_EN1 + i,
172 dev->int_en[i]);
173 }
174
175 mutex_unlock(&dev->irq_lock);
176}
177
178static void adp5588_irq_mask(unsigned int irq)
179{
180 struct adp5588_gpio *dev = get_irq_chip_data(irq);
181 unsigned gpio = irq - dev->irq_base;
182
183 dev->irq_mask[ADP5588_BANK(gpio)] &= ~ADP5588_BIT(gpio);
184}
185
186static void adp5588_irq_unmask(unsigned int irq)
187{
188 struct adp5588_gpio *dev = get_irq_chip_data(irq);
189 unsigned gpio = irq - dev->irq_base;
190
191 dev->irq_mask[ADP5588_BANK(gpio)] |= ADP5588_BIT(gpio);
192}
193
194static int adp5588_irq_set_type(unsigned int irq, unsigned int type)
195{
196 struct adp5588_gpio *dev = get_irq_chip_data(irq);
197 uint16_t gpio = irq - dev->irq_base;
198 unsigned bank, bit;
199
200 if ((type & IRQ_TYPE_EDGE_BOTH)) {
201 dev_err(&dev->client->dev, "irq %d: unsupported type %d\n",
202 irq, type);
203 return -EINVAL;
204 }
205
206 bank = ADP5588_BANK(gpio);
207 bit = ADP5588_BIT(gpio);
208
209 if (type & IRQ_TYPE_LEVEL_HIGH)
210 dev->int_lvl[bank] |= bit;
211 else if (type & IRQ_TYPE_LEVEL_LOW)
212 dev->int_lvl[bank] &= ~bit;
213 else
214 return -EINVAL;
215
216 adp5588_gpio_direction_input(&dev->gpio_chip, gpio);
217 adp5588_gpio_write(dev->client, GPIO_INT_LVL1 + bank,
218 dev->int_lvl[bank]);
219
220 return 0;
221}
222
223static struct irq_chip adp5588_irq_chip = {
224 .name = "adp5588",
225 .mask = adp5588_irq_mask,
226 .unmask = adp5588_irq_unmask,
227 .bus_lock = adp5588_irq_bus_lock,
228 .bus_sync_unlock = adp5588_irq_bus_sync_unlock,
229 .set_type = adp5588_irq_set_type,
230};
231
232static int adp5588_gpio_read_intstat(struct i2c_client *client, u8 *buf)
233{
234 int ret = i2c_smbus_read_i2c_block_data(client, GPIO_INT_STAT1, 3, buf);
235
236 if (ret < 0)
237 dev_err(&client->dev, "Read INT_STAT Error\n");
238
239 return ret;
240}
241
242static irqreturn_t adp5588_irq_handler(int irq, void *devid)
243{
244 struct adp5588_gpio *dev = devid;
245 unsigned status, bank, bit, pending;
246 int ret;
247 status = adp5588_gpio_read(dev->client, INT_STAT);
248
249 if (status & ADP5588_GPI_INT) {
250 ret = adp5588_gpio_read_intstat(dev->client, dev->irq_stat);
251 if (ret < 0)
252 memset(dev->irq_stat, 0, ARRAY_SIZE(dev->irq_stat));
253
254 for (bank = 0; bank <= ADP5588_BANK(ADP5588_MAXGPIO);
255 bank++, bit = 0) {
256 pending = dev->irq_stat[bank] & dev->irq_mask[bank];
257
258 while (pending) {
259 if (pending & (1 << bit)) {
260 handle_nested_irq(dev->irq_base +
261 (bank << 3) + bit);
262 pending &= ~(1 << bit);
263
264 }
265 bit++;
266 }
267 }
268 }
269
270 adp5588_gpio_write(dev->client, INT_STAT, status); /* Status is W1C */
271
272 return IRQ_HANDLED;
273}
274
275static int adp5588_irq_setup(struct adp5588_gpio *dev)
276{
277 struct i2c_client *client = dev->client;
278 struct adp5588_gpio_platform_data *pdata = client->dev.platform_data;
279 unsigned gpio;
280 int ret;
281
282 adp5588_gpio_write(client, CFG, ADP5588_AUTO_INC);
283 adp5588_gpio_write(client, INT_STAT, -1); /* status is W1C */
284 adp5588_gpio_read_intstat(client, dev->irq_stat); /* read to clear */
285
286 dev->irq_base = pdata->irq_base;
287 mutex_init(&dev->irq_lock);
288
289 for (gpio = 0; gpio < dev->gpio_chip.ngpio; gpio++) {
290 int irq = gpio + dev->irq_base;
291 set_irq_chip_data(irq, dev);
292 set_irq_chip_and_handler(irq, &adp5588_irq_chip,
293 handle_level_irq);
294 set_irq_nested_thread(irq, 1);
295#ifdef CONFIG_ARM
296 /*
297 * ARM needs us to explicitly flag the IRQ as VALID,
298 * once we do so, it will also set the noprobe.
299 */
300 set_irq_flags(irq, IRQF_VALID);
301#else
302 set_irq_noprobe(irq);
303#endif
304 }
305
306 ret = request_threaded_irq(client->irq,
307 NULL,
308 adp5588_irq_handler,
309 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
310 dev_name(&client->dev), dev);
311 if (ret) {
312 dev_err(&client->dev, "failed to request irq %d\n",
313 client->irq);
314 goto out;
315 }
316
317 dev->gpio_chip.to_irq = adp5588_gpio_to_irq;
318 adp5588_gpio_write(client, CFG,
319 ADP5588_AUTO_INC | ADP5588_INT_CFG | ADP5588_GPI_INT);
320
321 return 0;
322
323out:
324 dev->irq_base = 0;
325 return ret;
326}
327
328static void adp5588_irq_teardown(struct adp5588_gpio *dev)
329{
330 if (dev->irq_base)
331 free_irq(dev->client->irq, dev);
332}
333
334#else
335static int adp5588_irq_setup(struct adp5588_gpio *dev)
336{
337 struct i2c_client *client = dev->client;
338 dev_warn(&client->dev, "interrupt support not compiled in\n");
339
340 return 0;
341}
342
343static void adp5588_irq_teardown(struct adp5588_gpio *dev)
344{
345}
346#endif /* CONFIG_GPIO_ADP5588_IRQ */
347
128static int __devinit adp5588_gpio_probe(struct i2c_client *client, 348static int __devinit adp5588_gpio_probe(struct i2c_client *client,
129 const struct i2c_device_id *id) 349 const struct i2c_device_id *id)
130{ 350{
@@ -160,37 +380,46 @@ static int __devinit adp5588_gpio_probe(struct i2c_client *client,
160 gc->can_sleep = 1; 380 gc->can_sleep = 1;
161 381
162 gc->base = pdata->gpio_start; 382 gc->base = pdata->gpio_start;
163 gc->ngpio = MAXGPIO; 383 gc->ngpio = ADP5588_MAXGPIO;
164 gc->label = client->name; 384 gc->label = client->name;
165 gc->owner = THIS_MODULE; 385 gc->owner = THIS_MODULE;
166 386
167 mutex_init(&dev->lock); 387 mutex_init(&dev->lock);
168 388
169
170 ret = adp5588_gpio_read(dev->client, DEV_ID); 389 ret = adp5588_gpio_read(dev->client, DEV_ID);
171 if (ret < 0) 390 if (ret < 0)
172 goto err; 391 goto err;
173 392
174 revid = ret & ADP5588_DEVICE_ID_MASK; 393 revid = ret & ADP5588_DEVICE_ID_MASK;
175 394
176 for (i = 0, ret = 0; i <= ADP_BANK(MAXGPIO); i++) { 395 for (i = 0, ret = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
177 dev->dat_out[i] = adp5588_gpio_read(client, GPIO_DAT_OUT1 + i); 396 dev->dat_out[i] = adp5588_gpio_read(client, GPIO_DAT_OUT1 + i);
178 dev->dir[i] = adp5588_gpio_read(client, GPIO_DIR1 + i); 397 dev->dir[i] = adp5588_gpio_read(client, GPIO_DIR1 + i);
179 ret |= adp5588_gpio_write(client, KP_GPIO1 + i, 0); 398 ret |= adp5588_gpio_write(client, KP_GPIO1 + i, 0);
180 ret |= adp5588_gpio_write(client, GPIO_PULL1 + i, 399 ret |= adp5588_gpio_write(client, GPIO_PULL1 + i,
181 (pdata->pullup_dis_mask >> (8 * i)) & 0xFF); 400 (pdata->pullup_dis_mask >> (8 * i)) & 0xFF);
182 401 ret |= adp5588_gpio_write(client, GPIO_INT_EN1 + i, 0);
183 if (ret) 402 if (ret)
184 goto err; 403 goto err;
185 } 404 }
186 405
406 if (pdata->irq_base) {
407 if (WA_DELAYED_READOUT_REVID(revid)) {
408 dev_warn(&client->dev, "GPIO int not supported\n");
409 } else {
410 ret = adp5588_irq_setup(dev);
411 if (ret)
412 goto err;
413 }
414 }
415
187 ret = gpiochip_add(&dev->gpio_chip); 416 ret = gpiochip_add(&dev->gpio_chip);
188 if (ret) 417 if (ret)
189 goto err; 418 goto err_irq;
190 419
191 dev_info(&client->dev, "gpios %d..%d on a %s Rev. %d\n", 420 dev_info(&client->dev, "gpios %d..%d (IRQ Base %d) on a %s Rev. %d\n",
192 gc->base, gc->base + gc->ngpio - 1, 421 gc->base, gc->base + gc->ngpio - 1,
193 client->name, revid); 422 pdata->irq_base, client->name, revid);
194 423
195 if (pdata->setup) { 424 if (pdata->setup) {
196 ret = pdata->setup(client, gc->base, gc->ngpio, pdata->context); 425 ret = pdata->setup(client, gc->base, gc->ngpio, pdata->context);
@@ -199,8 +428,11 @@ static int __devinit adp5588_gpio_probe(struct i2c_client *client,
199 } 428 }
200 429
201 i2c_set_clientdata(client, dev); 430 i2c_set_clientdata(client, dev);
431
202 return 0; 432 return 0;
203 433
434err_irq:
435 adp5588_irq_teardown(dev);
204err: 436err:
205 kfree(dev); 437 kfree(dev);
206 return ret; 438 return ret;
@@ -222,6 +454,9 @@ static int __devexit adp5588_gpio_remove(struct i2c_client *client)
222 } 454 }
223 } 455 }
224 456
457 if (dev->irq_base)
458 free_irq(dev->client->irq, dev);
459
225 ret = gpiochip_remove(&dev->gpio_chip); 460 ret = gpiochip_remove(&dev->gpio_chip);
226 if (ret) { 461 if (ret) {
227 dev_err(&client->dev, "gpiochip_remove failed %d\n", ret); 462 dev_err(&client->dev, "gpiochip_remove failed %d\n", ret);
diff --git a/drivers/gpio/basic_mmio_gpio.c b/drivers/gpio/basic_mmio_gpio.c
new file mode 100644
index 000000000000..3addea65894e
--- /dev/null
+++ b/drivers/gpio/basic_mmio_gpio.c
@@ -0,0 +1,297 @@
1/*
2 * Driver for basic memory-mapped GPIO controllers.
3 *
4 * Copyright 2008 MontaVista Software, Inc.
5 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * ....``.```~~~~````.`.`.`.`.```````'',,,.........`````......`.......
13 * ...`` ```````..
14 * ..The simplest form of a GPIO controller that the driver supports is``
15 * `.just a single "data" register, where GPIO state can be read and/or `
16 * `,..written. ,,..``~~~~ .....``.`.`.~~.```.`.........``````.```````
17 * `````````
18 ___
19_/~~|___/~| . ```~~~~~~ ___/___\___ ,~.`.`.`.`````.~~...,,,,...
20__________|~$@~~~ %~ /o*o*o*o*o*o\ .. Implementing such a GPIO .
21o ` ~~~~\___/~~~~ ` controller in FPGA is ,.`
22 `....trivial..'~`.```.```
23 * ```````
24 * .```````~~~~`..`.``.``.
25 * . The driver supports `... ,..```.`~~~```````````````....````.``,,
26 * . big-endian notation, just`. .. A bit more sophisticated controllers ,
27 * . register the device with -be`. .with a pair of set/clear-bit registers ,
28 * `.. suffix. ```~~`````....`.` . affecting the data register and the .`
29 * ``.`.``...``` ```.. output pins are also supported.`
30 * ^^ `````.`````````.,``~``~``~~``````
31 * . ^^
32 * ,..`.`.`...````````````......`.`.`.`.`.`..`.`.`..
33 * .. The expectation is that in at least some cases . ,-~~~-,
34 * .this will be used with roll-your-own ASIC/FPGA .` \ /
35 * .logic in Verilog or VHDL. ~~~`````````..`````~~` \ /
36 * ..````````......``````````` \o_
37 * |
38 * ^^ / \
39 *
40 * ...`````~~`.....``.`..........``````.`.``.```........``.
41 * ` 8, 16, 32 and 64 bits registers are supported, and``.
42 * . the number of GPIOs is determined by the width of ~
43 * .. the registers. ,............```.`.`..`.`.~~~.`.`.`~
44 * `.......````.```
45 */
46
47#include <linux/init.h>
48#include <linux/bug.h>
49#include <linux/kernel.h>
50#include <linux/module.h>
51#include <linux/spinlock.h>
52#include <linux/compiler.h>
53#include <linux/types.h>
54#include <linux/errno.h>
55#include <linux/log2.h>
56#include <linux/ioport.h>
57#include <linux/io.h>
58#include <linux/gpio.h>
59#include <linux/slab.h>
60#include <linux/platform_device.h>
61#include <linux/mod_devicetable.h>
62#include <linux/basic_mmio_gpio.h>
63
64struct bgpio_chip {
65 struct gpio_chip gc;
66 void __iomem *reg_dat;
67 void __iomem *reg_set;
68 void __iomem *reg_clr;
69
70 /* Number of bits (GPIOs): <register width> * 8. */
71 int bits;
72
73 /*
74 * Some GPIO controllers work with the big-endian bits notation,
75 * e.g. in a 8-bits register, GPIO7 is the least significant bit.
76 */
77 int big_endian_bits;
78
79 /*
80 * Used to lock bgpio_chip->data. Also, this is needed to keep
81 * shadowed and real data registers writes together.
82 */
83 spinlock_t lock;
84
85 /* Shadowed data register to clear/set bits safely. */
86 unsigned long data;
87};
88
89static struct bgpio_chip *to_bgpio_chip(struct gpio_chip *gc)
90{
91 return container_of(gc, struct bgpio_chip, gc);
92}
93
94static unsigned long bgpio_in(struct bgpio_chip *bgc)
95{
96 switch (bgc->bits) {
97 case 8:
98 return __raw_readb(bgc->reg_dat);
99 case 16:
100 return __raw_readw(bgc->reg_dat);
101 case 32:
102 return __raw_readl(bgc->reg_dat);
103#if BITS_PER_LONG >= 64
104 case 64:
105 return __raw_readq(bgc->reg_dat);
106#endif
107 }
108 return -EINVAL;
109}
110
111static void bgpio_out(struct bgpio_chip *bgc, void __iomem *reg,
112 unsigned long data)
113{
114 switch (bgc->bits) {
115 case 8:
116 __raw_writeb(data, reg);
117 return;
118 case 16:
119 __raw_writew(data, reg);
120 return;
121 case 32:
122 __raw_writel(data, reg);
123 return;
124#if BITS_PER_LONG >= 64
125 case 64:
126 __raw_writeq(data, reg);
127 return;
128#endif
129 }
130}
131
132static unsigned long bgpio_pin2mask(struct bgpio_chip *bgc, unsigned int pin)
133{
134 if (bgc->big_endian_bits)
135 return 1 << (bgc->bits - 1 - pin);
136 else
137 return 1 << pin;
138}
139
140static int bgpio_get(struct gpio_chip *gc, unsigned int gpio)
141{
142 struct bgpio_chip *bgc = to_bgpio_chip(gc);
143
144 return bgpio_in(bgc) & bgpio_pin2mask(bgc, gpio);
145}
146
147static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
148{
149 struct bgpio_chip *bgc = to_bgpio_chip(gc);
150 unsigned long mask = bgpio_pin2mask(bgc, gpio);
151 unsigned long flags;
152
153 if (bgc->reg_set) {
154 if (val)
155 bgpio_out(bgc, bgc->reg_set, mask);
156 else
157 bgpio_out(bgc, bgc->reg_clr, mask);
158 return;
159 }
160
161 spin_lock_irqsave(&bgc->lock, flags);
162
163 if (val)
164 bgc->data |= mask;
165 else
166 bgc->data &= ~mask;
167
168 bgpio_out(bgc, bgc->reg_dat, bgc->data);
169
170 spin_unlock_irqrestore(&bgc->lock, flags);
171}
172
173static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
174{
175 return 0;
176}
177
178static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
179{
180 bgpio_set(gc, gpio, val);
181 return 0;
182}
183
184static int __devinit bgpio_probe(struct platform_device *pdev)
185{
186 const struct platform_device_id *platid = platform_get_device_id(pdev);
187 struct device *dev = &pdev->dev;
188 struct bgpio_pdata *pdata = dev_get_platdata(dev);
189 struct bgpio_chip *bgc;
190 struct resource *res_dat;
191 struct resource *res_set;
192 struct resource *res_clr;
193 resource_size_t dat_sz;
194 int bits;
195 int ret;
196
197 res_dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
198 if (!res_dat)
199 return -EINVAL;
200
201 dat_sz = resource_size(res_dat);
202 if (!is_power_of_2(dat_sz))
203 return -EINVAL;
204
205 bits = dat_sz * 8;
206 if (bits > BITS_PER_LONG)
207 return -EINVAL;
208
209 bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
210 if (!bgc)
211 return -ENOMEM;
212
213 bgc->reg_dat = devm_ioremap(dev, res_dat->start, dat_sz);
214 if (!bgc->reg_dat)
215 return -ENOMEM;
216
217 res_set = platform_get_resource_byname(pdev, IORESOURCE_MEM, "set");
218 res_clr = platform_get_resource_byname(pdev, IORESOURCE_MEM, "clr");
219 if (res_set && res_clr) {
220 if (resource_size(res_set) != resource_size(res_clr) ||
221 resource_size(res_set) != dat_sz)
222 return -EINVAL;
223
224 bgc->reg_set = devm_ioremap(dev, res_set->start, dat_sz);
225 bgc->reg_clr = devm_ioremap(dev, res_clr->start, dat_sz);
226 if (!bgc->reg_set || !bgc->reg_clr)
227 return -ENOMEM;
228 } else if (res_set || res_clr) {
229 return -EINVAL;
230 }
231
232 spin_lock_init(&bgc->lock);
233
234 bgc->bits = bits;
235 bgc->big_endian_bits = !strcmp(platid->name, "basic-mmio-gpio-be");
236 bgc->data = bgpio_in(bgc);
237
238 bgc->gc.ngpio = bits;
239 bgc->gc.direction_input = bgpio_dir_in;
240 bgc->gc.direction_output = bgpio_dir_out;
241 bgc->gc.get = bgpio_get;
242 bgc->gc.set = bgpio_set;
243 bgc->gc.dev = dev;
244 bgc->gc.label = dev_name(dev);
245
246 if (pdata)
247 bgc->gc.base = pdata->base;
248 else
249 bgc->gc.base = -1;
250
251 dev_set_drvdata(dev, bgc);
252
253 ret = gpiochip_add(&bgc->gc);
254 if (ret)
255 dev_err(dev, "gpiochip_add() failed: %d\n", ret);
256
257 return ret;
258}
259
260static int __devexit bgpio_remove(struct platform_device *pdev)
261{
262 struct bgpio_chip *bgc = dev_get_drvdata(&pdev->dev);
263
264 return gpiochip_remove(&bgc->gc);
265}
266
267static const struct platform_device_id bgpio_id_table[] = {
268 { "basic-mmio-gpio", },
269 { "basic-mmio-gpio-be", },
270 {},
271};
272MODULE_DEVICE_TABLE(platform, bgpio_id_table);
273
274static struct platform_driver bgpio_driver = {
275 .driver = {
276 .name = "basic-mmio-gpio",
277 },
278 .id_table = bgpio_id_table,
279 .probe = bgpio_probe,
280 .remove = __devexit_p(bgpio_remove),
281};
282
283static int __init bgpio_init(void)
284{
285 return platform_driver_register(&bgpio_driver);
286}
287module_init(bgpio_init);
288
289static void __exit bgpio_exit(void)
290{
291 platform_driver_unregister(&bgpio_driver);
292}
293module_exit(bgpio_exit);
294
295MODULE_DESCRIPTION("Driver for basic memory-mapped GPIO controllers");
296MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
297MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/langwell_gpio.c b/drivers/gpio/langwell_gpio.c
index 8383a8d7f994..64db9dc3a275 100644
--- a/drivers/gpio/langwell_gpio.c
+++ b/drivers/gpio/langwell_gpio.c
@@ -18,10 +18,12 @@
18/* Supports: 18/* Supports:
19 * Moorestown platform Langwell chip. 19 * Moorestown platform Langwell chip.
20 * Medfield platform Penwell chip. 20 * Medfield platform Penwell chip.
21 * Whitney point.
21 */ 22 */
22 23
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/pci.h> 25#include <linux/pci.h>
26#include <linux/platform_device.h>
25#include <linux/kernel.h> 27#include <linux/kernel.h>
26#include <linux/delay.h> 28#include <linux/delay.h>
27#include <linux/stddef.h> 29#include <linux/stddef.h>
@@ -158,15 +160,15 @@ static int lnw_irq_type(unsigned irq, unsigned type)
158 spin_unlock_irqrestore(&lnw->lock, flags); 160 spin_unlock_irqrestore(&lnw->lock, flags);
159 161
160 return 0; 162 return 0;
161}; 163}
162 164
163static void lnw_irq_unmask(unsigned irq) 165static void lnw_irq_unmask(unsigned irq)
164{ 166{
165}; 167}
166 168
167static void lnw_irq_mask(unsigned irq) 169static void lnw_irq_mask(unsigned irq)
168{ 170{
169}; 171}
170 172
171static struct irq_chip lnw_irqchip = { 173static struct irq_chip lnw_irqchip = {
172 .name = "LNW-GPIO", 174 .name = "LNW-GPIO",
@@ -300,9 +302,88 @@ static struct pci_driver lnw_gpio_driver = {
300 .probe = lnw_gpio_probe, 302 .probe = lnw_gpio_probe,
301}; 303};
302 304
305
306static int __devinit wp_gpio_probe(struct platform_device *pdev)
307{
308 struct lnw_gpio *lnw;
309 struct gpio_chip *gc;
310 struct resource *rc;
311 int retval = 0;
312
313 rc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
314 if (!rc)
315 return -EINVAL;
316
317 lnw = kzalloc(sizeof(struct lnw_gpio), GFP_KERNEL);
318 if (!lnw) {
319 dev_err(&pdev->dev,
320 "can't allocate whitneypoint_gpio chip data\n");
321 return -ENOMEM;
322 }
323 lnw->reg_base = ioremap_nocache(rc->start, resource_size(rc));
324 if (lnw->reg_base == NULL) {
325 retval = -EINVAL;
326 goto err_kmalloc;
327 }
328 spin_lock_init(&lnw->lock);
329 gc = &lnw->chip;
330 gc->label = dev_name(&pdev->dev);
331 gc->owner = THIS_MODULE;
332 gc->direction_input = lnw_gpio_direction_input;
333 gc->direction_output = lnw_gpio_direction_output;
334 gc->get = lnw_gpio_get;
335 gc->set = lnw_gpio_set;
336 gc->to_irq = NULL;
337 gc->base = 0;
338 gc->ngpio = 64;
339 gc->can_sleep = 0;
340 retval = gpiochip_add(gc);
341 if (retval) {
342 dev_err(&pdev->dev, "whitneypoint gpiochip_add error %d\n",
343 retval);
344 goto err_ioremap;
345 }
346 platform_set_drvdata(pdev, lnw);
347 return 0;
348err_ioremap:
349 iounmap(lnw->reg_base);
350err_kmalloc:
351 kfree(lnw);
352 return retval;
353}
354
355static int __devexit wp_gpio_remove(struct platform_device *pdev)
356{
357 struct lnw_gpio *lnw = platform_get_drvdata(pdev);
358 int err;
359 err = gpiochip_remove(&lnw->chip);
360 if (err)
361 dev_err(&pdev->dev, "failed to remove gpio_chip.\n");
362 iounmap(lnw->reg_base);
363 kfree(lnw);
364 platform_set_drvdata(pdev, NULL);
365 return 0;
366}
367
368static struct platform_driver wp_gpio_driver = {
369 .probe = wp_gpio_probe,
370 .remove = __devexit_p(wp_gpio_remove),
371 .driver = {
372 .name = "wp_gpio",
373 .owner = THIS_MODULE,
374 },
375};
376
303static int __init lnw_gpio_init(void) 377static int __init lnw_gpio_init(void)
304{ 378{
305 return pci_register_driver(&lnw_gpio_driver); 379 int ret;
380 ret = pci_register_driver(&lnw_gpio_driver);
381 if (ret < 0)
382 return ret;
383 ret = platform_driver_register(&wp_gpio_driver);
384 if (ret < 0)
385 pci_unregister_driver(&lnw_gpio_driver);
386 return ret;
306} 387}
307 388
308device_initcall(lnw_gpio_init); 389device_initcall(lnw_gpio_init);
diff --git a/drivers/gpio/pch_gpio.c b/drivers/gpio/pch_gpio.c
new file mode 100644
index 000000000000..0eba0a75c804
--- /dev/null
+++ b/drivers/gpio/pch_gpio.c
@@ -0,0 +1,312 @@
1/*
2 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
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; version 2 of the License.
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 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */
17#include <linux/kernel.h>
18#include <linux/pci.h>
19#include <linux/gpio.h>
20
21#define PCH_GPIO_ALL_PINS 0xfff /* Mask for GPIO pins 0 to 11 */
22#define GPIO_NUM_PINS 12 /* Specifies number of GPIO PINS GPIO0-GPIO11 */
23
24struct pch_regs {
25 u32 ien;
26 u32 istatus;
27 u32 idisp;
28 u32 iclr;
29 u32 imask;
30 u32 imaskclr;
31 u32 po;
32 u32 pi;
33 u32 pm;
34 u32 im0;
35 u32 im1;
36 u32 reserved[4];
37 u32 reset;
38};
39
40/**
41 * struct pch_gpio_reg_data - The register store data.
42 * @po_reg: To store contents of PO register.
43 * @pm_reg: To store contents of PM register.
44 */
45struct pch_gpio_reg_data {
46 u32 po_reg;
47 u32 pm_reg;
48};
49
50/**
51 * struct pch_gpio - GPIO private data structure.
52 * @base: PCI base address of Memory mapped I/O register.
53 * @reg: Memory mapped PCH GPIO register list.
54 * @dev: Pointer to device structure.
55 * @gpio: Data for GPIO infrastructure.
56 * @pch_gpio_reg: Memory mapped Register data is saved here
57 * when suspend.
58 */
59struct pch_gpio {
60 void __iomem *base;
61 struct pch_regs __iomem *reg;
62 struct device *dev;
63 struct gpio_chip gpio;
64 struct pch_gpio_reg_data pch_gpio_reg;
65 struct mutex lock;
66};
67
68static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
69{
70 u32 reg_val;
71 struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio);
72
73 mutex_lock(&chip->lock);
74 reg_val = ioread32(&chip->reg->po);
75 if (val)
76 reg_val |= (1 << nr);
77 else
78 reg_val &= ~(1 << nr);
79
80 iowrite32(reg_val, &chip->reg->po);
81 mutex_unlock(&chip->lock);
82}
83
84static int pch_gpio_get(struct gpio_chip *gpio, unsigned nr)
85{
86 struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio);
87
88 return ioread32(&chip->reg->pi) & (1 << nr);
89}
90
91static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
92 int val)
93{
94 struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio);
95 u32 pm;
96 u32 reg_val;
97
98 mutex_lock(&chip->lock);
99 pm = ioread32(&chip->reg->pm) & PCH_GPIO_ALL_PINS;
100 pm |= (1 << nr);
101 iowrite32(pm, &chip->reg->pm);
102
103 reg_val = ioread32(&chip->reg->po);
104 if (val)
105 reg_val |= (1 << nr);
106 else
107 reg_val &= ~(1 << nr);
108
109 mutex_unlock(&chip->lock);
110
111 return 0;
112}
113
114static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
115{
116 struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio);
117 u32 pm;
118
119 mutex_lock(&chip->lock);
120 pm = ioread32(&chip->reg->pm) & PCH_GPIO_ALL_PINS; /*bits 0-11*/
121 pm &= ~(1 << nr);
122 iowrite32(pm, &chip->reg->pm);
123 mutex_unlock(&chip->lock);
124
125 return 0;
126}
127
128/*
129 * Save register configuration and disable interrupts.
130 */
131static void pch_gpio_save_reg_conf(struct pch_gpio *chip)
132{
133 chip->pch_gpio_reg.po_reg = ioread32(&chip->reg->po);
134 chip->pch_gpio_reg.pm_reg = ioread32(&chip->reg->pm);
135}
136
137/*
138 * This function restores the register configuration of the GPIO device.
139 */
140static void pch_gpio_restore_reg_conf(struct pch_gpio *chip)
141{
142 /* to store contents of PO register */
143 iowrite32(chip->pch_gpio_reg.po_reg, &chip->reg->po);
144 /* to store contents of PM register */
145 iowrite32(chip->pch_gpio_reg.pm_reg, &chip->reg->pm);
146}
147
148static void pch_gpio_setup(struct pch_gpio *chip)
149{
150 struct gpio_chip *gpio = &chip->gpio;
151
152 gpio->label = dev_name(chip->dev);
153 gpio->owner = THIS_MODULE;
154 gpio->direction_input = pch_gpio_direction_input;
155 gpio->get = pch_gpio_get;
156 gpio->direction_output = pch_gpio_direction_output;
157 gpio->set = pch_gpio_set;
158 gpio->dbg_show = NULL;
159 gpio->base = -1;
160 gpio->ngpio = GPIO_NUM_PINS;
161 gpio->can_sleep = 0;
162}
163
164static int __devinit pch_gpio_probe(struct pci_dev *pdev,
165 const struct pci_device_id *id)
166{
167 s32 ret;
168 struct pch_gpio *chip;
169
170 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
171 if (chip == NULL)
172 return -ENOMEM;
173
174 chip->dev = &pdev->dev;
175 ret = pci_enable_device(pdev);
176 if (ret) {
177 dev_err(&pdev->dev, "%s : pci_enable_device FAILED", __func__);
178 goto err_pci_enable;
179 }
180
181 ret = pci_request_regions(pdev, KBUILD_MODNAME);
182 if (ret) {
183 dev_err(&pdev->dev, "pci_request_regions FAILED-%d", ret);
184 goto err_request_regions;
185 }
186
187 chip->base = pci_iomap(pdev, 1, 0);
188 if (chip->base == 0) {
189 dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__);
190 ret = -ENOMEM;
191 goto err_iomap;
192 }
193
194 chip->reg = chip->base;
195 pci_set_drvdata(pdev, chip);
196 mutex_init(&chip->lock);
197 pch_gpio_setup(chip);
198 ret = gpiochip_add(&chip->gpio);
199 if (ret) {
200 dev_err(&pdev->dev, "PCH gpio: Failed to register GPIO\n");
201 goto err_gpiochip_add;
202 }
203
204 return 0;
205
206err_gpiochip_add:
207 pci_iounmap(pdev, chip->base);
208
209err_iomap:
210 pci_release_regions(pdev);
211
212err_request_regions:
213 pci_disable_device(pdev);
214
215err_pci_enable:
216 kfree(chip);
217 dev_err(&pdev->dev, "%s Failed returns %d\n", __func__, ret);
218 return ret;
219}
220
221static void __devexit pch_gpio_remove(struct pci_dev *pdev)
222{
223 int err;
224 struct pch_gpio *chip = pci_get_drvdata(pdev);
225
226 err = gpiochip_remove(&chip->gpio);
227 if (err)
228 dev_err(&pdev->dev, "Failed gpiochip_remove\n");
229
230 pci_iounmap(pdev, chip->base);
231 pci_release_regions(pdev);
232 pci_disable_device(pdev);
233 kfree(chip);
234}
235
236#ifdef CONFIG_PM
237static int pch_gpio_suspend(struct pci_dev *pdev, pm_message_t state)
238{
239 s32 ret;
240 struct pch_gpio *chip = pci_get_drvdata(pdev);
241
242 pch_gpio_save_reg_conf(chip);
243 pch_gpio_restore_reg_conf(chip);
244
245 ret = pci_save_state(pdev);
246 if (ret) {
247 dev_err(&pdev->dev, "pci_save_state Failed-%d\n", ret);
248 return ret;
249 }
250 pci_disable_device(pdev);
251 pci_set_power_state(pdev, PCI_D0);
252 ret = pci_enable_wake(pdev, PCI_D0, 1);
253 if (ret)
254 dev_err(&pdev->dev, "pci_enable_wake Failed -%d\n", ret);
255
256 return 0;
257}
258
259static int pch_gpio_resume(struct pci_dev *pdev)
260{
261 s32 ret;
262 struct pch_gpio *chip = pci_get_drvdata(pdev);
263
264 ret = pci_enable_wake(pdev, PCI_D0, 0);
265
266 pci_set_power_state(pdev, PCI_D0);
267 ret = pci_enable_device(pdev);
268 if (ret) {
269 dev_err(&pdev->dev, "pci_enable_device Failed-%d ", ret);
270 return ret;
271 }
272 pci_restore_state(pdev);
273
274 iowrite32(0x01, &chip->reg->reset);
275 iowrite32(0x00, &chip->reg->reset);
276 pch_gpio_restore_reg_conf(chip);
277
278 return 0;
279}
280#else
281#define pch_gpio_suspend NULL
282#define pch_gpio_resume NULL
283#endif
284
285static DEFINE_PCI_DEVICE_TABLE(pch_gpio_pcidev_id) = {
286 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8803) },
287 { 0, }
288};
289
290static struct pci_driver pch_gpio_driver = {
291 .name = "pch_gpio",
292 .id_table = pch_gpio_pcidev_id,
293 .probe = pch_gpio_probe,
294 .remove = __devexit_p(pch_gpio_remove),
295 .suspend = pch_gpio_suspend,
296 .resume = pch_gpio_resume
297};
298
299static int __init pch_gpio_pci_init(void)
300{
301 return pci_register_driver(&pch_gpio_driver);
302}
303module_init(pch_gpio_pci_init);
304
305static void __exit pch_gpio_pci_exit(void)
306{
307 pci_unregister_driver(&pch_gpio_driver);
308}
309module_exit(pch_gpio_pci_exit);
310
311MODULE_DESCRIPTION("PCH GPIO PCI Driver");
312MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/timbgpio.c b/drivers/gpio/timbgpio.c
index ddd053108a13..45293662e950 100644
--- a/drivers/gpio/timbgpio.c
+++ b/drivers/gpio/timbgpio.c
@@ -47,6 +47,7 @@ struct timbgpio {
47 spinlock_t lock; /* mutual exclusion */ 47 spinlock_t lock; /* mutual exclusion */
48 struct gpio_chip gpio; 48 struct gpio_chip gpio;
49 int irq_base; 49 int irq_base;
50 unsigned long last_ier;
50}; 51};
51 52
52static int timbgpio_update_bit(struct gpio_chip *gpio, unsigned index, 53static int timbgpio_update_bit(struct gpio_chip *gpio, unsigned index,
@@ -112,16 +113,24 @@ static void timbgpio_irq_disable(unsigned irq)
112{ 113{
113 struct timbgpio *tgpio = get_irq_chip_data(irq); 114 struct timbgpio *tgpio = get_irq_chip_data(irq);
114 int offset = irq - tgpio->irq_base; 115 int offset = irq - tgpio->irq_base;
116 unsigned long flags;
115 117
116 timbgpio_update_bit(&tgpio->gpio, offset, TGPIO_IER, 0); 118 spin_lock_irqsave(&tgpio->lock, flags);
119 tgpio->last_ier &= ~(1 << offset);
120 iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER);
121 spin_unlock_irqrestore(&tgpio->lock, flags);
117} 122}
118 123
119static void timbgpio_irq_enable(unsigned irq) 124static void timbgpio_irq_enable(unsigned irq)
120{ 125{
121 struct timbgpio *tgpio = get_irq_chip_data(irq); 126 struct timbgpio *tgpio = get_irq_chip_data(irq);
122 int offset = irq - tgpio->irq_base; 127 int offset = irq - tgpio->irq_base;
128 unsigned long flags;
123 129
124 timbgpio_update_bit(&tgpio->gpio, offset, TGPIO_IER, 1); 130 spin_lock_irqsave(&tgpio->lock, flags);
131 tgpio->last_ier |= 1 << offset;
132 iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER);
133 spin_unlock_irqrestore(&tgpio->lock, flags);
125} 134}
126 135
127static int timbgpio_irq_type(unsigned irq, unsigned trigger) 136static int timbgpio_irq_type(unsigned irq, unsigned trigger)
@@ -194,8 +203,16 @@ static void timbgpio_irq(unsigned int irq, struct irq_desc *desc)
194 ipr = ioread32(tgpio->membase + TGPIO_IPR); 203 ipr = ioread32(tgpio->membase + TGPIO_IPR);
195 iowrite32(ipr, tgpio->membase + TGPIO_ICR); 204 iowrite32(ipr, tgpio->membase + TGPIO_ICR);
196 205
206 /*
207 * Some versions of the hardware trash the IER register if more than
208 * one interrupt is received simultaneously.
209 */
210 iowrite32(0, tgpio->membase + TGPIO_IER);
211
197 for_each_set_bit(offset, &ipr, tgpio->gpio.ngpio) 212 for_each_set_bit(offset, &ipr, tgpio->gpio.ngpio)
198 generic_handle_irq(timbgpio_to_irq(&tgpio->gpio, offset)); 213 generic_handle_irq(timbgpio_to_irq(&tgpio->gpio, offset));
214
215 iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER);
199} 216}
200 217
201static struct irq_chip timbgpio_irqchip = { 218static struct irq_chip timbgpio_irqchip = {
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 4cb4bb009950..53fab518b3da 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -560,7 +560,8 @@ static const struct pci_device_id scx200_pci[] __initconst = {
560 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA), 560 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA),
561 .driver_data = 1 }, 561 .driver_data = 1 },
562 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA), 562 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA),
563 .driver_data = 2 } 563 .driver_data = 2 },
564 { 0, }
564}; 565};
565 566
566static struct { 567static struct {
diff --git a/drivers/isdn/hardware/mISDN/mISDNinfineon.c b/drivers/isdn/hardware/mISDN/mISDNinfineon.c
index af25e1f3efd4..e90db8870b6c 100644
--- a/drivers/isdn/hardware/mISDN/mISDNinfineon.c
+++ b/drivers/isdn/hardware/mISDN/mISDNinfineon.c
@@ -563,7 +563,7 @@ reset_inf(struct inf_hw *hw)
563 mdelay(10); 563 mdelay(10);
564 hw->ipac.isac.adf2 = 0x87; 564 hw->ipac.isac.adf2 = 0x87;
565 hw->ipac.hscx[0].slot = 0x1f; 565 hw->ipac.hscx[0].slot = 0x1f;
566 hw->ipac.hscx[0].slot = 0x23; 566 hw->ipac.hscx[1].slot = 0x23;
567 break; 567 break;
568 case INF_GAZEL_R753: 568 case INF_GAZEL_R753:
569 val = inl((u32)hw->cfg.start + GAZEL_CNTRL); 569 val = inl((u32)hw->cfg.start + GAZEL_CNTRL);
diff --git a/drivers/isdn/hisax/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
index b0554f80bfb3..ee4dae1382e0 100644
--- a/drivers/isdn/hisax/l3_1tr6.c
+++ b/drivers/isdn/hisax/l3_1tr6.c
@@ -164,11 +164,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
164 char tmp[80]; 164 char tmp[80];
165 struct sk_buff *skb = arg; 165 struct sk_buff *skb = arg;
166 166
167 p = skb->data;
168
169 /* Channel Identification */ 167 /* Channel Identification */
170 p = skb->data; 168 p = findie(skb->data, skb->len, WE0_chanID, 0);
171 if ((p = findie(p, skb->len, WE0_chanID, 0))) { 169 if (p) {
172 if (p[1] != 1) { 170 if (p[1] != 1) {
173 l3_1tr6_error(pc, "setup wrong chanID len", skb); 171 l3_1tr6_error(pc, "setup wrong chanID len", skb);
174 return; 172 return;
diff --git a/drivers/media/IR/lirc_dev.c b/drivers/media/IR/lirc_dev.c
index 0acf6396e068..202581808bdc 100644
--- a/drivers/media/IR/lirc_dev.c
+++ b/drivers/media/IR/lirc_dev.c
@@ -27,7 +27,6 @@
27#include <linux/fs.h> 27#include <linux/fs.h>
28#include <linux/poll.h> 28#include <linux/poll.h>
29#include <linux/completion.h> 29#include <linux/completion.h>
30#include <linux/errno.h>
31#include <linux/mutex.h> 30#include <linux/mutex.h>
32#include <linux/wait.h> 31#include <linux/wait.h>
33#include <linux/unistd.h> 32#include <linux/unistd.h>
diff --git a/drivers/net/atl1c/atl1c.h b/drivers/net/atl1c/atl1c.h
index ef4115b897bf..9ab58097fa2e 100644
--- a/drivers/net/atl1c/atl1c.h
+++ b/drivers/net/atl1c/atl1c.h
@@ -631,8 +631,6 @@ struct atl1c_adapter {
631extern char atl1c_driver_name[]; 631extern char atl1c_driver_name[];
632extern char atl1c_driver_version[]; 632extern char atl1c_driver_version[];
633 633
634extern int atl1c_up(struct atl1c_adapter *adapter);
635extern void atl1c_down(struct atl1c_adapter *adapter);
636extern void atl1c_reinit_locked(struct atl1c_adapter *adapter); 634extern void atl1c_reinit_locked(struct atl1c_adapter *adapter);
637extern s32 atl1c_reset_hw(struct atl1c_hw *hw); 635extern s32 atl1c_reset_hw(struct atl1c_hw *hw);
638extern void atl1c_set_ethtool_ops(struct net_device *netdev); 636extern void atl1c_set_ethtool_ops(struct net_device *netdev);
diff --git a/drivers/net/atl1c/atl1c_main.c b/drivers/net/atl1c/atl1c_main.c
index 99ffcf667d1f..09b099bfab2b 100644
--- a/drivers/net/atl1c/atl1c_main.c
+++ b/drivers/net/atl1c/atl1c_main.c
@@ -66,6 +66,8 @@ static void atl1c_set_aspm(struct atl1c_hw *hw, bool linkup);
66static void atl1c_setup_mac_ctrl(struct atl1c_adapter *adapter); 66static void atl1c_setup_mac_ctrl(struct atl1c_adapter *adapter);
67static void atl1c_clean_rx_irq(struct atl1c_adapter *adapter, u8 que, 67static void atl1c_clean_rx_irq(struct atl1c_adapter *adapter, u8 que,
68 int *work_done, int work_to_do); 68 int *work_done, int work_to_do);
69static int atl1c_up(struct atl1c_adapter *adapter);
70static void atl1c_down(struct atl1c_adapter *adapter);
69 71
70static const u16 atl1c_pay_load_size[] = { 72static const u16 atl1c_pay_load_size[] = {
71 128, 256, 512, 1024, 2048, 4096, 73 128, 256, 512, 1024, 2048, 4096,
@@ -2309,7 +2311,7 @@ static int atl1c_request_irq(struct atl1c_adapter *adapter)
2309 return err; 2311 return err;
2310} 2312}
2311 2313
2312int atl1c_up(struct atl1c_adapter *adapter) 2314static int atl1c_up(struct atl1c_adapter *adapter)
2313{ 2315{
2314 struct net_device *netdev = adapter->netdev; 2316 struct net_device *netdev = adapter->netdev;
2315 int num; 2317 int num;
@@ -2351,7 +2353,7 @@ err_alloc_rx:
2351 return err; 2353 return err;
2352} 2354}
2353 2355
2354void atl1c_down(struct atl1c_adapter *adapter) 2356static void atl1c_down(struct atl1c_adapter *adapter)
2355{ 2357{
2356 struct net_device *netdev = adapter->netdev; 2358 struct net_device *netdev = adapter->netdev;
2357 2359
diff --git a/drivers/net/atlx/atl1.c b/drivers/net/atlx/atl1.c
index dbd27b8e66bd..43579b3b24ac 100644
--- a/drivers/net/atlx/atl1.c
+++ b/drivers/net/atlx/atl1.c
@@ -91,6 +91,8 @@ MODULE_VERSION(ATLX_DRIVER_VERSION);
91/* Temporary hack for merging atl1 and atl2 */ 91/* Temporary hack for merging atl1 and atl2 */
92#include "atlx.c" 92#include "atlx.c"
93 93
94static const struct ethtool_ops atl1_ethtool_ops;
95
94/* 96/*
95 * This is the only thing that needs to be changed to adjust the 97 * This is the only thing that needs to be changed to adjust the
96 * maximum number of ports that the driver can manage. 98 * maximum number of ports that the driver can manage.
@@ -353,7 +355,7 @@ static bool atl1_read_eeprom(struct atl1_hw *hw, u32 offset, u32 *p_value)
353 * hw - Struct containing variables accessed by shared code 355 * hw - Struct containing variables accessed by shared code
354 * reg_addr - address of the PHY register to read 356 * reg_addr - address of the PHY register to read
355 */ 357 */
356s32 atl1_read_phy_reg(struct atl1_hw *hw, u16 reg_addr, u16 *phy_data) 358static s32 atl1_read_phy_reg(struct atl1_hw *hw, u16 reg_addr, u16 *phy_data)
357{ 359{
358 u32 val; 360 u32 val;
359 int i; 361 int i;
@@ -553,7 +555,7 @@ static s32 atl1_read_mac_addr(struct atl1_hw *hw)
553 * 1. calcu 32bit CRC for multicast address 555 * 1. calcu 32bit CRC for multicast address
554 * 2. reverse crc with MSB to LSB 556 * 2. reverse crc with MSB to LSB
555 */ 557 */
556u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr) 558static u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr)
557{ 559{
558 u32 crc32, value = 0; 560 u32 crc32, value = 0;
559 int i; 561 int i;
@@ -570,7 +572,7 @@ u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr)
570 * hw - Struct containing variables accessed by shared code 572 * hw - Struct containing variables accessed by shared code
571 * hash_value - Multicast address hash value 573 * hash_value - Multicast address hash value
572 */ 574 */
573void atl1_hash_set(struct atl1_hw *hw, u32 hash_value) 575static void atl1_hash_set(struct atl1_hw *hw, u32 hash_value)
574{ 576{
575 u32 hash_bit, hash_reg; 577 u32 hash_bit, hash_reg;
576 u32 mta; 578 u32 mta;
@@ -914,7 +916,7 @@ static s32 atl1_get_speed_and_duplex(struct atl1_hw *hw, u16 *speed, u16 *duplex
914 return 0; 916 return 0;
915} 917}
916 918
917void atl1_set_mac_addr(struct atl1_hw *hw) 919static void atl1_set_mac_addr(struct atl1_hw *hw)
918{ 920{
919 u32 value; 921 u32 value;
920 /* 922 /*
@@ -3658,7 +3660,7 @@ static int atl1_nway_reset(struct net_device *netdev)
3658 return 0; 3660 return 0;
3659} 3661}
3660 3662
3661const struct ethtool_ops atl1_ethtool_ops = { 3663static const struct ethtool_ops atl1_ethtool_ops = {
3662 .get_settings = atl1_get_settings, 3664 .get_settings = atl1_get_settings,
3663 .set_settings = atl1_set_settings, 3665 .set_settings = atl1_set_settings,
3664 .get_drvinfo = atl1_get_drvinfo, 3666 .get_drvinfo = atl1_get_drvinfo,
diff --git a/drivers/net/atlx/atl1.h b/drivers/net/atlx/atl1.h
index 9c0ddb273ac8..68de8cbfb3ec 100644
--- a/drivers/net/atlx/atl1.h
+++ b/drivers/net/atlx/atl1.h
@@ -56,16 +56,13 @@ struct atl1_adapter;
56struct atl1_hw; 56struct atl1_hw;
57 57
58/* function prototypes needed by multiple files */ 58/* function prototypes needed by multiple files */
59u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr); 59static u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr);
60void atl1_hash_set(struct atl1_hw *hw, u32 hash_value); 60static void atl1_hash_set(struct atl1_hw *hw, u32 hash_value);
61s32 atl1_read_phy_reg(struct atl1_hw *hw, u16 reg_addr, u16 *phy_data); 61static void atl1_set_mac_addr(struct atl1_hw *hw);
62void atl1_set_mac_addr(struct atl1_hw *hw);
63static int atl1_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, 62static int atl1_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
64 int cmd); 63 int cmd);
65static u32 atl1_check_link(struct atl1_adapter *adapter); 64static u32 atl1_check_link(struct atl1_adapter *adapter);
66 65
67extern const struct ethtool_ops atl1_ethtool_ops;
68
69/* hardware definitions specific to L1 */ 66/* hardware definitions specific to L1 */
70 67
71/* Block IDLE Status Register */ 68/* Block IDLE Status Register */
diff --git a/drivers/net/atlx/atlx.c b/drivers/net/atlx/atlx.c
index f979ea2d6d3c..afb7f7dd1bb1 100644
--- a/drivers/net/atlx/atlx.c
+++ b/drivers/net/atlx/atlx.c
@@ -41,6 +41,10 @@
41 41
42#include "atlx.h" 42#include "atlx.h"
43 43
44static s32 atlx_read_phy_reg(struct atl1_hw *hw, u16 reg_addr, u16 *phy_data);
45static u32 atlx_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr);
46static void atlx_set_mac_addr(struct atl1_hw *hw);
47
44static struct atlx_spi_flash_dev flash_table[] = { 48static struct atlx_spi_flash_dev flash_table[] = {
45/* MFR_NAME WRSR READ PRGM WREN WRDI RDSR RDID SEC_ERS CHIP_ERS */ 49/* MFR_NAME WRSR READ PRGM WREN WRDI RDSR RDID SEC_ERS CHIP_ERS */
46 {"Atmel", 0x00, 0x03, 0x02, 0x06, 0x04, 0x05, 0x15, 0x52, 0x62}, 50 {"Atmel", 0x00, 0x03, 0x02, 0x06, 0x04, 0x05, 0x15, 0x52, 0x62},
diff --git a/drivers/net/benet/be_cmds.c b/drivers/net/benet/be_cmds.c
index 1e7f305ed00b..36eca1ce75d4 100644
--- a/drivers/net/benet/be_cmds.c
+++ b/drivers/net/benet/be_cmds.c
@@ -1471,42 +1471,6 @@ err:
1471 return status; 1471 return status;
1472} 1472}
1473 1473
1474/* Uses sync mcc */
1475int be_cmd_read_port_type(struct be_adapter *adapter, u32 port,
1476 u8 *connector)
1477{
1478 struct be_mcc_wrb *wrb;
1479 struct be_cmd_req_port_type *req;
1480 int status;
1481
1482 spin_lock_bh(&adapter->mcc_lock);
1483
1484 wrb = wrb_from_mccq(adapter);
1485 if (!wrb) {
1486 status = -EBUSY;
1487 goto err;
1488 }
1489 req = embedded_payload(wrb);
1490
1491 be_wrb_hdr_prepare(wrb, sizeof(struct be_cmd_resp_port_type), true, 0,
1492 OPCODE_COMMON_READ_TRANSRECV_DATA);
1493
1494 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1495 OPCODE_COMMON_READ_TRANSRECV_DATA, sizeof(*req));
1496
1497 req->port = cpu_to_le32(port);
1498 req->page_num = cpu_to_le32(TR_PAGE_A0);
1499 status = be_mcc_notify_wait(adapter);
1500 if (!status) {
1501 struct be_cmd_resp_port_type *resp = embedded_payload(wrb);
1502 *connector = resp->data.connector;
1503 }
1504
1505err:
1506 spin_unlock_bh(&adapter->mcc_lock);
1507 return status;
1508}
1509
1510int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd, 1474int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
1511 u32 flash_type, u32 flash_opcode, u32 buf_size) 1475 u32 flash_type, u32 flash_opcode, u32 buf_size)
1512{ 1476{
diff --git a/drivers/net/benet/be_cmds.h b/drivers/net/benet/be_cmds.h
index c7f6cdfe1c73..8469ff061f30 100644
--- a/drivers/net/benet/be_cmds.h
+++ b/drivers/net/benet/be_cmds.h
@@ -1022,8 +1022,6 @@ extern int be_cmd_set_beacon_state(struct be_adapter *adapter,
1022 u8 port_num, u8 beacon, u8 status, u8 state); 1022 u8 port_num, u8 beacon, u8 status, u8 state);
1023extern int be_cmd_get_beacon_state(struct be_adapter *adapter, 1023extern int be_cmd_get_beacon_state(struct be_adapter *adapter,
1024 u8 port_num, u32 *state); 1024 u8 port_num, u32 *state);
1025extern int be_cmd_read_port_type(struct be_adapter *adapter, u32 port,
1026 u8 *connector);
1027extern int be_cmd_write_flashrom(struct be_adapter *adapter, 1025extern int be_cmd_write_flashrom(struct be_adapter *adapter,
1028 struct be_dma_mem *cmd, u32 flash_oper, 1026 struct be_dma_mem *cmd, u32 flash_oper,
1029 u32 flash_opcode, u32 buf_size); 1027 u32 flash_opcode, u32 buf_size);
diff --git a/drivers/net/benet/be_main.c b/drivers/net/benet/be_main.c
index 45b1f6635282..c36cd2ffbadc 100644
--- a/drivers/net/benet/be_main.c
+++ b/drivers/net/benet/be_main.c
@@ -849,20 +849,16 @@ static void be_rx_stats_update(struct be_rx_obj *rxo,
849 stats->rx_mcast_pkts++; 849 stats->rx_mcast_pkts++;
850} 850}
851 851
852static inline bool do_pkt_csum(struct be_eth_rx_compl *rxcp, bool cso) 852static inline bool csum_passed(struct be_eth_rx_compl *rxcp)
853{ 853{
854 u8 l4_cksm, ip_version, ipcksm, tcpf = 0, udpf = 0, ipv6_chk; 854 u8 l4_cksm, ipv6, ipcksm;
855 855
856 l4_cksm = AMAP_GET_BITS(struct amap_eth_rx_compl, l4_cksm, rxcp); 856 l4_cksm = AMAP_GET_BITS(struct amap_eth_rx_compl, l4_cksm, rxcp);
857 ipcksm = AMAP_GET_BITS(struct amap_eth_rx_compl, ipcksm, rxcp); 857 ipcksm = AMAP_GET_BITS(struct amap_eth_rx_compl, ipcksm, rxcp);
858 ip_version = AMAP_GET_BITS(struct amap_eth_rx_compl, ip_version, rxcp); 858 ipv6 = AMAP_GET_BITS(struct amap_eth_rx_compl, ip_version, rxcp);
859 if (ip_version) {
860 tcpf = AMAP_GET_BITS(struct amap_eth_rx_compl, tcpf, rxcp);
861 udpf = AMAP_GET_BITS(struct amap_eth_rx_compl, udpf, rxcp);
862 }
863 ipv6_chk = (ip_version && (tcpf || udpf));
864 859
865 return ((l4_cksm && ipv6_chk && ipcksm) && cso) ? false : true; 860 /* Ignore ipcksm for ipv6 pkts */
861 return l4_cksm && (ipcksm || ipv6);
866} 862}
867 863
868static struct be_rx_page_info * 864static struct be_rx_page_info *
@@ -1017,10 +1013,10 @@ static void be_rx_compl_process(struct be_adapter *adapter,
1017 1013
1018 skb_fill_rx_data(adapter, rxo, skb, rxcp, num_rcvd); 1014 skb_fill_rx_data(adapter, rxo, skb, rxcp, num_rcvd);
1019 1015
1020 if (do_pkt_csum(rxcp, adapter->rx_csum)) 1016 if (likely(adapter->rx_csum && csum_passed(rxcp)))
1021 skb_checksum_none_assert(skb);
1022 else
1023 skb->ip_summed = CHECKSUM_UNNECESSARY; 1017 skb->ip_summed = CHECKSUM_UNNECESSARY;
1018 else
1019 skb_checksum_none_assert(skb);
1024 1020
1025 skb->truesize = skb->len + sizeof(struct sk_buff); 1021 skb->truesize = skb->len + sizeof(struct sk_buff);
1026 skb->protocol = eth_type_trans(skb, adapter->netdev); 1022 skb->protocol = eth_type_trans(skb, adapter->netdev);
@@ -1674,7 +1670,7 @@ static inline bool do_gro(struct be_adapter *adapter, struct be_rx_obj *rxo,
1674 return (tcp_frame && !err) ? true : false; 1670 return (tcp_frame && !err) ? true : false;
1675} 1671}
1676 1672
1677int be_poll_rx(struct napi_struct *napi, int budget) 1673static int be_poll_rx(struct napi_struct *napi, int budget)
1678{ 1674{
1679 struct be_eq_obj *rx_eq = container_of(napi, struct be_eq_obj, napi); 1675 struct be_eq_obj *rx_eq = container_of(napi, struct be_eq_obj, napi);
1680 struct be_rx_obj *rxo = container_of(rx_eq, struct be_rx_obj, rx_eq); 1676 struct be_rx_obj *rxo = container_of(rx_eq, struct be_rx_obj, rx_eq);
@@ -1806,6 +1802,20 @@ static void be_worker(struct work_struct *work)
1806 struct be_rx_obj *rxo; 1802 struct be_rx_obj *rxo;
1807 int i; 1803 int i;
1808 1804
1805 /* when interrupts are not yet enabled, just reap any pending
1806 * mcc completions */
1807 if (!netif_running(adapter->netdev)) {
1808 int mcc_compl, status = 0;
1809
1810 mcc_compl = be_process_mcc(adapter, &status);
1811
1812 if (mcc_compl) {
1813 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
1814 be_cq_notify(adapter, mcc_obj->cq.id, false, mcc_compl);
1815 }
1816 goto reschedule;
1817 }
1818
1809 if (!adapter->stats_ioctl_sent) 1819 if (!adapter->stats_ioctl_sent)
1810 be_cmd_get_stats(adapter, &adapter->stats_cmd); 1820 be_cmd_get_stats(adapter, &adapter->stats_cmd);
1811 1821
@@ -1824,6 +1834,7 @@ static void be_worker(struct work_struct *work)
1824 if (!adapter->ue_detected) 1834 if (!adapter->ue_detected)
1825 be_detect_dump_ue(adapter); 1835 be_detect_dump_ue(adapter);
1826 1836
1837reschedule:
1827 schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000)); 1838 schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000));
1828} 1839}
1829 1840
@@ -2019,8 +2030,6 @@ static int be_close(struct net_device *netdev)
2019 struct be_eq_obj *tx_eq = &adapter->tx_eq; 2030 struct be_eq_obj *tx_eq = &adapter->tx_eq;
2020 int vec, i; 2031 int vec, i;
2021 2032
2022 cancel_delayed_work_sync(&adapter->work);
2023
2024 be_async_mcc_disable(adapter); 2033 be_async_mcc_disable(adapter);
2025 2034
2026 netif_stop_queue(netdev); 2035 netif_stop_queue(netdev);
@@ -2085,8 +2094,6 @@ static int be_open(struct net_device *netdev)
2085 /* Now that interrupts are on we can process async mcc */ 2094 /* Now that interrupts are on we can process async mcc */
2086 be_async_mcc_enable(adapter); 2095 be_async_mcc_enable(adapter);
2087 2096
2088 schedule_delayed_work(&adapter->work, msecs_to_jiffies(100));
2089
2090 status = be_cmd_link_status_query(adapter, &link_up, &mac_speed, 2097 status = be_cmd_link_status_query(adapter, &link_up, &mac_speed,
2091 &link_speed); 2098 &link_speed);
2092 if (status) 2099 if (status)
@@ -2299,9 +2306,6 @@ static int be_clear(struct be_adapter *adapter)
2299 2306
2300 2307
2301#define FW_FILE_HDR_SIGN "ServerEngines Corp. " 2308#define FW_FILE_HDR_SIGN "ServerEngines Corp. "
2302char flash_cookie[2][16] = {"*** SE FLAS",
2303 "H DIRECTORY *** "};
2304
2305static bool be_flash_redboot(struct be_adapter *adapter, 2309static bool be_flash_redboot(struct be_adapter *adapter,
2306 const u8 *p, u32 img_start, int image_size, 2310 const u8 *p, u32 img_start, int image_size,
2307 int hdr_size) 2311 int hdr_size)
@@ -2559,7 +2563,6 @@ static void be_netdev_init(struct net_device *netdev)
2559 netif_napi_add(netdev, &adapter->tx_eq.napi, be_poll_tx_mcc, 2563 netif_napi_add(netdev, &adapter->tx_eq.napi, be_poll_tx_mcc,
2560 BE_NAPI_WEIGHT); 2564 BE_NAPI_WEIGHT);
2561 2565
2562 netif_carrier_off(netdev);
2563 netif_stop_queue(netdev); 2566 netif_stop_queue(netdev);
2564} 2567}
2565 2568
@@ -2715,6 +2718,8 @@ static void __devexit be_remove(struct pci_dev *pdev)
2715 if (!adapter) 2718 if (!adapter)
2716 return; 2719 return;
2717 2720
2721 cancel_delayed_work_sync(&adapter->work);
2722
2718 unregister_netdev(adapter->netdev); 2723 unregister_netdev(adapter->netdev);
2719 2724
2720 be_clear(adapter); 2725 be_clear(adapter);
@@ -2868,8 +2873,10 @@ static int __devinit be_probe(struct pci_dev *pdev,
2868 status = register_netdev(netdev); 2873 status = register_netdev(netdev);
2869 if (status != 0) 2874 if (status != 0)
2870 goto unsetup; 2875 goto unsetup;
2876 netif_carrier_off(netdev);
2871 2877
2872 dev_info(&pdev->dev, "%s port %d\n", nic_name(pdev), adapter->port_num); 2878 dev_info(&pdev->dev, "%s port %d\n", nic_name(pdev), adapter->port_num);
2879 schedule_delayed_work(&adapter->work, msecs_to_jiffies(100));
2873 return 0; 2880 return 0;
2874 2881
2875unsetup: 2882unsetup:
diff --git a/drivers/net/bnx2x/bnx2x.h b/drivers/net/bnx2x/bnx2x.h
index 9571ecf48f35..9eea225decaf 100644
--- a/drivers/net/bnx2x/bnx2x.h
+++ b/drivers/net/bnx2x/bnx2x.h
@@ -1288,15 +1288,11 @@ struct bnx2x_func_init_params {
1288 1288
1289#define WAIT_RAMROD_POLL 0x01 1289#define WAIT_RAMROD_POLL 0x01
1290#define WAIT_RAMROD_COMMON 0x02 1290#define WAIT_RAMROD_COMMON 0x02
1291int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx,
1292 int *state_p, int flags);
1293 1291
1294/* dmae */ 1292/* dmae */
1295void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32); 1293void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32);
1296void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr, 1294void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
1297 u32 len32); 1295 u32 len32);
1298void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
1299 u32 addr, u32 len);
1300void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx); 1296void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx);
1301u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type); 1297u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type);
1302u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode); 1298u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode);
@@ -1307,7 +1303,6 @@ int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port);
1307int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port); 1303int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
1308int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port); 1304int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port);
1309u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param); 1305u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param);
1310void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val);
1311 1306
1312void bnx2x_calc_fc_adv(struct bnx2x *bp); 1307void bnx2x_calc_fc_adv(struct bnx2x *bp);
1313int bnx2x_sp_post(struct bnx2x *bp, int command, int cid, 1308int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
diff --git a/drivers/net/bnx2x/bnx2x_cmn.c b/drivers/net/bnx2x/bnx2x_cmn.c
index bc5837514074..459614d2d7bc 100644
--- a/drivers/net/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/bnx2x/bnx2x_cmn.c
@@ -25,6 +25,7 @@
25 25
26#include "bnx2x_init.h" 26#include "bnx2x_init.h"
27 27
28static int bnx2x_setup_irqs(struct bnx2x *bp);
28 29
29/* free skb in the packet ring at pos idx 30/* free skb in the packet ring at pos idx
30 * return idx of last bd freed 31 * return idx of last bd freed
@@ -2187,7 +2188,7 @@ int bnx2x_change_mac_addr(struct net_device *dev, void *p)
2187} 2188}
2188 2189
2189 2190
2190int bnx2x_setup_irqs(struct bnx2x *bp) 2191static int bnx2x_setup_irqs(struct bnx2x *bp)
2191{ 2192{
2192 int rc = 0; 2193 int rc = 0;
2193 if (bp->flags & USING_MSIX_FLAG) { 2194 if (bp->flags & USING_MSIX_FLAG) {
diff --git a/drivers/net/bnx2x/bnx2x_cmn.h b/drivers/net/bnx2x/bnx2x_cmn.h
index 5bfe0ab1d2d4..6b28739c5302 100644
--- a/drivers/net/bnx2x/bnx2x_cmn.h
+++ b/drivers/net/bnx2x/bnx2x_cmn.h
@@ -117,13 +117,6 @@ void bnx2x_setup_cnic_irq_info(struct bnx2x *bp);
117void bnx2x_int_enable(struct bnx2x *bp); 117void bnx2x_int_enable(struct bnx2x *bp);
118 118
119/** 119/**
120 * Disable HW interrupts.
121 *
122 * @param bp
123 */
124void bnx2x_int_disable(struct bnx2x *bp);
125
126/**
127 * Disable interrupts. This function ensures that there are no 120 * Disable interrupts. This function ensures that there are no
128 * ISRs or SP DPCs (sp_task) are running after it returns. 121 * ISRs or SP DPCs (sp_task) are running after it returns.
129 * 122 *
@@ -192,17 +185,6 @@ int bnx2x_setup_client(struct bnx2x *bp, struct bnx2x_fastpath *fp,
192 int is_leading); 185 int is_leading);
193 186
194/** 187/**
195 * Bring down an eth client.
196 *
197 * @param bp
198 * @param p
199 *
200 * @return int
201 */
202int bnx2x_stop_fw_client(struct bnx2x *bp,
203 struct bnx2x_client_ramrod_params *p);
204
205/**
206 * Set number of queues according to mode 188 * Set number of queues according to mode
207 * 189 *
208 * @param bp 190 * @param bp
@@ -250,34 +232,6 @@ int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource);
250 */ 232 */
251void bnx2x_set_eth_mac(struct bnx2x *bp, int set); 233void bnx2x_set_eth_mac(struct bnx2x *bp, int set);
252 234
253#ifdef BCM_CNIC
254/**
255 * Set iSCSI MAC(s) at the next enties in the CAM after the ETH
256 * MAC(s). The function will wait until the ramrod completion
257 * returns.
258 *
259 * @param bp driver handle
260 * @param set set or clear the CAM entry
261 *
262 * @return 0 if cussess, -ENODEV if ramrod doesn't return.
263 */
264int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp, int set);
265#endif
266
267/**
268 * Initialize status block in FW and HW
269 *
270 * @param bp driver handle
271 * @param dma_addr_t mapping
272 * @param int sb_id
273 * @param int vfid
274 * @param u8 vf_valid
275 * @param int fw_sb_id
276 * @param int igu_sb_id
277 */
278void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
279 u8 vf_valid, int fw_sb_id, int igu_sb_id);
280
281/** 235/**
282 * Set MAC filtering configurations. 236 * Set MAC filtering configurations.
283 * 237 *
@@ -326,7 +280,6 @@ void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe);
326 * @return int 280 * @return int
327 */ 281 */
328int bnx2x_func_start(struct bnx2x *bp); 282int bnx2x_func_start(struct bnx2x *bp);
329int bnx2x_func_stop(struct bnx2x *bp);
330 283
331/** 284/**
332 * Prepare ILT configurations according to current driver 285 * Prepare ILT configurations according to current driver
@@ -396,14 +349,6 @@ int bnx2x_enable_msix(struct bnx2x *bp);
396int bnx2x_enable_msi(struct bnx2x *bp); 349int bnx2x_enable_msi(struct bnx2x *bp);
397 350
398/** 351/**
399 * Request IRQ vectors from OS.
400 *
401 * @param bp
402 *
403 * @return int
404 */
405int bnx2x_setup_irqs(struct bnx2x *bp);
406/**
407 * NAPI callback 352 * NAPI callback
408 * 353 *
409 * @param napi 354 * @param napi
diff --git a/drivers/net/bnx2x/bnx2x_init_ops.h b/drivers/net/bnx2x/bnx2x_init_ops.h
index e65de784182c..a306b0e46b61 100644
--- a/drivers/net/bnx2x/bnx2x_init_ops.h
+++ b/drivers/net/bnx2x/bnx2x_init_ops.h
@@ -16,7 +16,9 @@
16#define BNX2X_INIT_OPS_H 16#define BNX2X_INIT_OPS_H
17 17
18static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len); 18static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len);
19 19static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val);
20static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
21 u32 addr, u32 len);
20 22
21static void bnx2x_init_str_wr(struct bnx2x *bp, u32 addr, const u32 *data, 23static void bnx2x_init_str_wr(struct bnx2x *bp, u32 addr, const u32 *data,
22 u32 len) 24 u32 len)
@@ -589,7 +591,7 @@ static int bnx2x_ilt_client_mem_op(struct bnx2x *bp, int cli_num, u8 memop)
589 return rc; 591 return rc;
590} 592}
591 593
592int bnx2x_ilt_mem_op(struct bnx2x *bp, u8 memop) 594static int bnx2x_ilt_mem_op(struct bnx2x *bp, u8 memop)
593{ 595{
594 int rc = bnx2x_ilt_client_mem_op(bp, ILT_CLIENT_CDU, memop); 596 int rc = bnx2x_ilt_client_mem_op(bp, ILT_CLIENT_CDU, memop);
595 if (!rc) 597 if (!rc)
@@ -635,7 +637,7 @@ static void bnx2x_ilt_line_init_op(struct bnx2x *bp, struct bnx2x_ilt *ilt,
635 } 637 }
636} 638}
637 639
638void bnx2x_ilt_boundry_init_op(struct bnx2x *bp, 640static void bnx2x_ilt_boundry_init_op(struct bnx2x *bp,
639 struct ilt_client_info *ilt_cli, 641 struct ilt_client_info *ilt_cli,
640 u32 ilt_start, u8 initop) 642 u32 ilt_start, u8 initop)
641{ 643{
@@ -688,8 +690,10 @@ void bnx2x_ilt_boundry_init_op(struct bnx2x *bp,
688 } 690 }
689} 691}
690 692
691void bnx2x_ilt_client_init_op_ilt(struct bnx2x *bp, struct bnx2x_ilt *ilt, 693static void bnx2x_ilt_client_init_op_ilt(struct bnx2x *bp,
692 struct ilt_client_info *ilt_cli, u8 initop) 694 struct bnx2x_ilt *ilt,
695 struct ilt_client_info *ilt_cli,
696 u8 initop)
693{ 697{
694 int i; 698 int i;
695 699
@@ -703,8 +707,8 @@ void bnx2x_ilt_client_init_op_ilt(struct bnx2x *bp, struct bnx2x_ilt *ilt,
703 bnx2x_ilt_boundry_init_op(bp, ilt_cli, ilt->start_line, initop); 707 bnx2x_ilt_boundry_init_op(bp, ilt_cli, ilt->start_line, initop);
704} 708}
705 709
706void bnx2x_ilt_client_init_op(struct bnx2x *bp, 710static void bnx2x_ilt_client_init_op(struct bnx2x *bp,
707 struct ilt_client_info *ilt_cli, u8 initop) 711 struct ilt_client_info *ilt_cli, u8 initop)
708{ 712{
709 struct bnx2x_ilt *ilt = BP_ILT(bp); 713 struct bnx2x_ilt *ilt = BP_ILT(bp);
710 714
@@ -720,7 +724,7 @@ static void bnx2x_ilt_client_id_init_op(struct bnx2x *bp,
720 bnx2x_ilt_client_init_op(bp, ilt_cli, initop); 724 bnx2x_ilt_client_init_op(bp, ilt_cli, initop);
721} 725}
722 726
723void bnx2x_ilt_init_op(struct bnx2x *bp, u8 initop) 727static void bnx2x_ilt_init_op(struct bnx2x *bp, u8 initop)
724{ 728{
725 bnx2x_ilt_client_id_init_op(bp, ILT_CLIENT_CDU, initop); 729 bnx2x_ilt_client_id_init_op(bp, ILT_CLIENT_CDU, initop);
726 bnx2x_ilt_client_id_init_op(bp, ILT_CLIENT_QM, initop); 730 bnx2x_ilt_client_id_init_op(bp, ILT_CLIENT_QM, initop);
@@ -752,7 +756,7 @@ static void bnx2x_ilt_init_client_psz(struct bnx2x *bp, int cli_num,
752 * called during init common stage, ilt clients should be initialized 756 * called during init common stage, ilt clients should be initialized
753 * prioir to calling this function 757 * prioir to calling this function
754 */ 758 */
755void bnx2x_ilt_init_page_size(struct bnx2x *bp, u8 initop) 759static void bnx2x_ilt_init_page_size(struct bnx2x *bp, u8 initop)
756{ 760{
757 bnx2x_ilt_init_client_psz(bp, ILT_CLIENT_CDU, 761 bnx2x_ilt_init_client_psz(bp, ILT_CLIENT_CDU,
758 PXP2_REG_RQ_CDU_P_SIZE, initop); 762 PXP2_REG_RQ_CDU_P_SIZE, initop);
@@ -772,8 +776,8 @@ void bnx2x_ilt_init_page_size(struct bnx2x *bp, u8 initop)
772#define QM_INIT(cid_cnt) (cid_cnt > QM_INIT_MIN_CID_COUNT) 776#define QM_INIT(cid_cnt) (cid_cnt > QM_INIT_MIN_CID_COUNT)
773 777
774/* called during init port stage */ 778/* called during init port stage */
775void bnx2x_qm_init_cid_count(struct bnx2x *bp, int qm_cid_count, 779static void bnx2x_qm_init_cid_count(struct bnx2x *bp, int qm_cid_count,
776 u8 initop) 780 u8 initop)
777{ 781{
778 int port = BP_PORT(bp); 782 int port = BP_PORT(bp);
779 783
@@ -814,8 +818,8 @@ static void bnx2x_qm_set_ptr_table(struct bnx2x *bp, int qm_cid_count)
814} 818}
815 819
816/* called during init common stage */ 820/* called during init common stage */
817void bnx2x_qm_init_ptr_table(struct bnx2x *bp, int qm_cid_count, 821static void bnx2x_qm_init_ptr_table(struct bnx2x *bp, int qm_cid_count,
818 u8 initop) 822 u8 initop)
819{ 823{
820 if (!QM_INIT(qm_cid_count)) 824 if (!QM_INIT(qm_cid_count))
821 return; 825 return;
@@ -836,8 +840,8 @@ void bnx2x_qm_init_ptr_table(struct bnx2x *bp, int qm_cid_count,
836****************************************************************************/ 840****************************************************************************/
837 841
838/* called during init func stage */ 842/* called during init func stage */
839void bnx2x_src_init_t2(struct bnx2x *bp, struct src_ent *t2, 843static void bnx2x_src_init_t2(struct bnx2x *bp, struct src_ent *t2,
840 dma_addr_t t2_mapping, int src_cid_count) 844 dma_addr_t t2_mapping, int src_cid_count)
841{ 845{
842 int i; 846 int i;
843 int port = BP_PORT(bp); 847 int port = BP_PORT(bp);
diff --git a/drivers/net/bnx2x/bnx2x_link.c b/drivers/net/bnx2x/bnx2x_link.c
index 3e99bf9c42b9..2326774df843 100644
--- a/drivers/net/bnx2x/bnx2x_link.c
+++ b/drivers/net/bnx2x/bnx2x_link.c
@@ -181,6 +181,12 @@
181 (_bank + (_addr & 0xf)), \ 181 (_bank + (_addr & 0xf)), \
182 _val) 182 _val)
183 183
184static u8 bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
185 u8 devad, u16 reg, u16 *ret_val);
186
187static u8 bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
188 u8 devad, u16 reg, u16 val);
189
184static u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits) 190static u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits)
185{ 191{
186 u32 val = REG_RD(bp, reg); 192 u32 val = REG_RD(bp, reg);
@@ -594,7 +600,7 @@ static u8 bnx2x_bmac2_enable(struct link_params *params,
594 return 0; 600 return 0;
595} 601}
596 602
597u8 bnx2x_bmac_enable(struct link_params *params, 603static u8 bnx2x_bmac_enable(struct link_params *params,
598 struct link_vars *vars, 604 struct link_vars *vars,
599 u8 is_lb) 605 u8 is_lb)
600{ 606{
@@ -2537,122 +2543,6 @@ static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
2537 } 2543 }
2538} 2544}
2539 2545
2540/*
2541 *------------------------------------------------------------------------
2542 * bnx2x_override_led_value -
2543 *
2544 * Override the led value of the requested led
2545 *
2546 *------------------------------------------------------------------------
2547 */
2548u8 bnx2x_override_led_value(struct bnx2x *bp, u8 port,
2549 u32 led_idx, u32 value)
2550{
2551 u32 reg_val;
2552
2553 /* If port 0 then use EMAC0, else use EMAC1*/
2554 u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
2555
2556 DP(NETIF_MSG_LINK,
2557 "bnx2x_override_led_value() port %x led_idx %d value %d\n",
2558 port, led_idx, value);
2559
2560 switch (led_idx) {
2561 case 0: /* 10MB led */
2562 /* Read the current value of the LED register in
2563 the EMAC block */
2564 reg_val = REG_RD(bp, emac_base + EMAC_REG_EMAC_LED);
2565 /* Set the OVERRIDE bit to 1 */
2566 reg_val |= EMAC_LED_OVERRIDE;
2567 /* If value is 1, set the 10M_OVERRIDE bit,
2568 otherwise reset it.*/
2569 reg_val = (value == 1) ? (reg_val | EMAC_LED_10MB_OVERRIDE) :
2570 (reg_val & ~EMAC_LED_10MB_OVERRIDE);
2571 REG_WR(bp, emac_base + EMAC_REG_EMAC_LED, reg_val);
2572 break;
2573 case 1: /*100MB led */
2574 /*Read the current value of the LED register in
2575 the EMAC block */
2576 reg_val = REG_RD(bp, emac_base + EMAC_REG_EMAC_LED);
2577 /* Set the OVERRIDE bit to 1 */
2578 reg_val |= EMAC_LED_OVERRIDE;
2579 /* If value is 1, set the 100M_OVERRIDE bit,
2580 otherwise reset it.*/
2581 reg_val = (value == 1) ? (reg_val | EMAC_LED_100MB_OVERRIDE) :
2582 (reg_val & ~EMAC_LED_100MB_OVERRIDE);
2583 REG_WR(bp, emac_base + EMAC_REG_EMAC_LED, reg_val);
2584 break;
2585 case 2: /* 1000MB led */
2586 /* Read the current value of the LED register in the
2587 EMAC block */
2588 reg_val = REG_RD(bp, emac_base + EMAC_REG_EMAC_LED);
2589 /* Set the OVERRIDE bit to 1 */
2590 reg_val |= EMAC_LED_OVERRIDE;
2591 /* If value is 1, set the 1000M_OVERRIDE bit, otherwise
2592 reset it. */
2593 reg_val = (value == 1) ? (reg_val | EMAC_LED_1000MB_OVERRIDE) :
2594 (reg_val & ~EMAC_LED_1000MB_OVERRIDE);
2595 REG_WR(bp, emac_base + EMAC_REG_EMAC_LED, reg_val);
2596 break;
2597 case 3: /* 2500MB led */
2598 /* Read the current value of the LED register in the
2599 EMAC block*/
2600 reg_val = REG_RD(bp, emac_base + EMAC_REG_EMAC_LED);
2601 /* Set the OVERRIDE bit to 1 */
2602 reg_val |= EMAC_LED_OVERRIDE;
2603 /* If value is 1, set the 2500M_OVERRIDE bit, otherwise
2604 reset it.*/
2605 reg_val = (value == 1) ? (reg_val | EMAC_LED_2500MB_OVERRIDE) :
2606 (reg_val & ~EMAC_LED_2500MB_OVERRIDE);
2607 REG_WR(bp, emac_base + EMAC_REG_EMAC_LED, reg_val);
2608 break;
2609 case 4: /*10G led */
2610 if (port == 0) {
2611 REG_WR(bp, NIG_REG_LED_10G_P0,
2612 value);
2613 } else {
2614 REG_WR(bp, NIG_REG_LED_10G_P1,
2615 value);
2616 }
2617 break;
2618 case 5: /* TRAFFIC led */
2619 /* Find if the traffic control is via BMAC or EMAC */
2620 if (port == 0)
2621 reg_val = REG_RD(bp, NIG_REG_NIG_EMAC0_EN);
2622 else
2623 reg_val = REG_RD(bp, NIG_REG_NIG_EMAC1_EN);
2624
2625 /* Override the traffic led in the EMAC:*/
2626 if (reg_val == 1) {
2627 /* Read the current value of the LED register in
2628 the EMAC block */
2629 reg_val = REG_RD(bp, emac_base +
2630 EMAC_REG_EMAC_LED);
2631 /* Set the TRAFFIC_OVERRIDE bit to 1 */
2632 reg_val |= EMAC_LED_OVERRIDE;
2633 /* If value is 1, set the TRAFFIC bit, otherwise
2634 reset it.*/
2635 reg_val = (value == 1) ? (reg_val | EMAC_LED_TRAFFIC) :
2636 (reg_val & ~EMAC_LED_TRAFFIC);
2637 REG_WR(bp, emac_base + EMAC_REG_EMAC_LED, reg_val);
2638 } else { /* Override the traffic led in the BMAC: */
2639 REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
2640 + port*4, 1);
2641 REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 + port*4,
2642 value);
2643 }
2644 break;
2645 default:
2646 DP(NETIF_MSG_LINK,
2647 "bnx2x_override_led_value() unknown led index %d "
2648 "(should be 0-5)\n", led_idx);
2649 return -EINVAL;
2650 }
2651
2652 return 0;
2653}
2654
2655
2656u8 bnx2x_set_led(struct link_params *params, 2546u8 bnx2x_set_led(struct link_params *params,
2657 struct link_vars *vars, u8 mode, u32 speed) 2547 struct link_vars *vars, u8 mode, u32 speed)
2658{ 2548{
@@ -4099,9 +3989,9 @@ static u8 bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4099 return -EINVAL; 3989 return -EINVAL;
4100} 3990}
4101 3991
4102u8 bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy, 3992static u8 bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
4103 struct link_params *params, u16 addr, 3993 struct link_params *params, u16 addr,
4104 u8 byte_cnt, u8 *o_buf) 3994 u8 byte_cnt, u8 *o_buf)
4105{ 3995{
4106 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) 3996 if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726)
4107 return bnx2x_8726_read_sfp_module_eeprom(phy, params, addr, 3997 return bnx2x_8726_read_sfp_module_eeprom(phy, params, addr,
@@ -6819,13 +6709,6 @@ u8 bnx2x_phy_probe(struct link_params *params)
6819 return 0; 6709 return 0;
6820} 6710}
6821 6711
6822u32 bnx2x_supported_attr(struct link_params *params, u8 phy_idx)
6823{
6824 if (phy_idx < params->num_phys)
6825 return params->phy[phy_idx].supported;
6826 return 0;
6827}
6828
6829static void set_phy_vars(struct link_params *params) 6712static void set_phy_vars(struct link_params *params)
6830{ 6713{
6831 struct bnx2x *bp = params->bp; 6714 struct bnx2x *bp = params->bp;
diff --git a/drivers/net/bnx2x/bnx2x_link.h b/drivers/net/bnx2x/bnx2x_link.h
index 58a4c7199276..171abf8097ee 100644
--- a/drivers/net/bnx2x/bnx2x_link.h
+++ b/drivers/net/bnx2x/bnx2x_link.h
@@ -279,12 +279,6 @@ u8 bnx2x_phy_read(struct link_params *params, u8 phy_addr,
279 279
280u8 bnx2x_phy_write(struct link_params *params, u8 phy_addr, 280u8 bnx2x_phy_write(struct link_params *params, u8 phy_addr,
281 u8 devad, u16 reg, u16 val); 281 u8 devad, u16 reg, u16 val);
282
283u8 bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
284 u8 devad, u16 reg, u16 *ret_val);
285
286u8 bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
287 u8 devad, u16 reg, u16 val);
288/* Reads the link_status from the shmem, 282/* Reads the link_status from the shmem,
289 and update the link vars accordingly */ 283 and update the link vars accordingly */
290void bnx2x_link_status_update(struct link_params *input, 284void bnx2x_link_status_update(struct link_params *input,
@@ -304,8 +298,6 @@ u8 bnx2x_set_led(struct link_params *params, struct link_vars *vars,
304#define LED_MODE_OPER 2 298#define LED_MODE_OPER 2
305#define LED_MODE_FRONT_PANEL_OFF 3 299#define LED_MODE_FRONT_PANEL_OFF 3
306 300
307u8 bnx2x_override_led_value(struct bnx2x *bp, u8 port, u32 led_idx, u32 value);
308
309/* bnx2x_handle_module_detect_int should be called upon module detection 301/* bnx2x_handle_module_detect_int should be called upon module detection
310 interrupt */ 302 interrupt */
311void bnx2x_handle_module_detect_int(struct link_params *params); 303void bnx2x_handle_module_detect_int(struct link_params *params);
@@ -325,19 +317,12 @@ void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port);
325/* Reset the external of SFX7101 */ 317/* Reset the external of SFX7101 */
326void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy); 318void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy);
327 319
328u8 bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
329 struct link_params *params, u16 addr,
330 u8 byte_cnt, u8 *o_buf);
331
332void bnx2x_hw_reset_phy(struct link_params *params); 320void bnx2x_hw_reset_phy(struct link_params *params);
333 321
334/* Checks if HW lock is required for this phy/board type */ 322/* Checks if HW lock is required for this phy/board type */
335u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base, 323u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base,
336 u32 shmem2_base); 324 u32 shmem2_base);
337 325
338/* Returns the aggregative supported attributes of the phys on board */
339u32 bnx2x_supported_attr(struct link_params *params, u8 phy_idx);
340
341/* Check swap bit and adjust PHY order */ 326/* Check swap bit and adjust PHY order */
342u32 bnx2x_phy_selection(struct link_params *params); 327u32 bnx2x_phy_selection(struct link_params *params);
343 328
diff --git a/drivers/net/bnx2x/bnx2x_main.c b/drivers/net/bnx2x/bnx2x_main.c
index ff99a2fc0426..e9ad16f00b56 100644
--- a/drivers/net/bnx2x/bnx2x_main.c
+++ b/drivers/net/bnx2x/bnx2x_main.c
@@ -403,7 +403,7 @@ static inline void storm_memset_hc_disable(struct bnx2x *bp, u8 port,
403/* used only at init 403/* used only at init
404 * locking is done by mcp 404 * locking is done by mcp
405 */ 405 */
406void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val) 406static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
407{ 407{
408 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); 408 pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
409 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val); 409 pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
@@ -429,7 +429,8 @@ static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
429#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]" 429#define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
430#define DMAE_DP_DST_NONE "dst_addr [none]" 430#define DMAE_DP_DST_NONE "dst_addr [none]"
431 431
432void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl) 432static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae,
433 int msglvl)
433{ 434{
434 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC; 435 u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
435 436
@@ -551,8 +552,9 @@ u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
551 return opcode; 552 return opcode;
552} 553}
553 554
554void bnx2x_prep_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae, 555static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
555 u8 src_type, u8 dst_type) 556 struct dmae_command *dmae,
557 u8 src_type, u8 dst_type)
556{ 558{
557 memset(dmae, 0, sizeof(struct dmae_command)); 559 memset(dmae, 0, sizeof(struct dmae_command));
558 560
@@ -567,7 +569,8 @@ void bnx2x_prep_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
567} 569}
568 570
569/* issue a dmae command over the init-channel and wailt for completion */ 571/* issue a dmae command over the init-channel and wailt for completion */
570int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae) 572static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
573 struct dmae_command *dmae)
571{ 574{
572 u32 *wb_comp = bnx2x_sp(bp, wb_comp); 575 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
573 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 40; 576 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 40;
@@ -674,8 +677,8 @@ void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
674 bnx2x_issue_dmae_with_comp(bp, &dmae); 677 bnx2x_issue_dmae_with_comp(bp, &dmae);
675} 678}
676 679
677void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr, 680static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
678 u32 addr, u32 len) 681 u32 addr, u32 len)
679{ 682{
680 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp); 683 int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
681 int offset = 0; 684 int offset = 0;
@@ -1267,7 +1270,7 @@ static void bnx2x_igu_int_disable(struct bnx2x *bp)
1267 BNX2X_ERR("BUG! proper val not read from IGU!\n"); 1270 BNX2X_ERR("BUG! proper val not read from IGU!\n");
1268} 1271}
1269 1272
1270void bnx2x_int_disable(struct bnx2x *bp) 1273static void bnx2x_int_disable(struct bnx2x *bp)
1271{ 1274{
1272 if (bp->common.int_block == INT_BLOCK_HC) 1275 if (bp->common.int_block == INT_BLOCK_HC)
1273 bnx2x_hc_int_disable(bp); 1276 bnx2x_hc_int_disable(bp);
@@ -2236,7 +2239,7 @@ u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
2236} 2239}
2237 2240
2238/* must be called under rtnl_lock */ 2241/* must be called under rtnl_lock */
2239void bnx2x_rxq_set_mac_filters(struct bnx2x *bp, u16 cl_id, u32 filters) 2242static void bnx2x_rxq_set_mac_filters(struct bnx2x *bp, u16 cl_id, u32 filters)
2240{ 2243{
2241 u32 mask = (1 << cl_id); 2244 u32 mask = (1 << cl_id);
2242 2245
@@ -2303,7 +2306,7 @@ void bnx2x_rxq_set_mac_filters(struct bnx2x *bp, u16 cl_id, u32 filters)
2303 bp->mac_filters.unmatched_unicast & ~mask; 2306 bp->mac_filters.unmatched_unicast & ~mask;
2304} 2307}
2305 2308
2306void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p) 2309static void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
2307{ 2310{
2308 struct tstorm_eth_function_common_config tcfg = {0}; 2311 struct tstorm_eth_function_common_config tcfg = {0};
2309 u16 rss_flgs; 2312 u16 rss_flgs;
@@ -2460,7 +2463,7 @@ static void bnx2x_pf_tx_cl_prep(struct bnx2x *bp,
2460 txq_init->hc_rate = bp->tx_ticks ? (1000000 / bp->tx_ticks) : 0; 2463 txq_init->hc_rate = bp->tx_ticks ? (1000000 / bp->tx_ticks) : 0;
2461} 2464}
2462 2465
2463void bnx2x_pf_init(struct bnx2x *bp) 2466static void bnx2x_pf_init(struct bnx2x *bp)
2464{ 2467{
2465 struct bnx2x_func_init_params func_init = {0}; 2468 struct bnx2x_func_init_params func_init = {0};
2466 struct bnx2x_rss_params rss = {0}; 2469 struct bnx2x_rss_params rss = {0};
@@ -3928,7 +3931,7 @@ void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
3928 hc_sm->time_to_expire = 0xFFFFFFFF; 3931 hc_sm->time_to_expire = 0xFFFFFFFF;
3929} 3932}
3930 3933
3931void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid, 3934static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
3932 u8 vf_valid, int fw_sb_id, int igu_sb_id) 3935 u8 vf_valid, int fw_sb_id, int igu_sb_id)
3933{ 3936{
3934 int igu_seg_id; 3937 int igu_seg_id;
@@ -6021,6 +6024,9 @@ alloc_mem_err:
6021/* 6024/*
6022 * Init service functions 6025 * Init service functions
6023 */ 6026 */
6027static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx,
6028 int *state_p, int flags);
6029
6024int bnx2x_func_start(struct bnx2x *bp) 6030int bnx2x_func_start(struct bnx2x *bp)
6025{ 6031{
6026 bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_START, 0, 0, 0, 1); 6032 bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_START, 0, 0, 0, 1);
@@ -6030,7 +6036,7 @@ int bnx2x_func_start(struct bnx2x *bp)
6030 WAIT_RAMROD_COMMON); 6036 WAIT_RAMROD_COMMON);
6031} 6037}
6032 6038
6033int bnx2x_func_stop(struct bnx2x *bp) 6039static int bnx2x_func_stop(struct bnx2x *bp)
6034{ 6040{
6035 bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_STOP, 0, 0, 0, 1); 6041 bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_STOP, 0, 0, 0, 1);
6036 6042
@@ -6103,8 +6109,8 @@ static void bnx2x_set_mac_addr_gen(struct bnx2x *bp, int set, u8 *mac,
6103 bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, ramrod_flags); 6109 bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, ramrod_flags);
6104} 6110}
6105 6111
6106int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx, 6112static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx,
6107 int *state_p, int flags) 6113 int *state_p, int flags)
6108{ 6114{
6109 /* can take a while if any port is running */ 6115 /* can take a while if any port is running */
6110 int cnt = 5000; 6116 int cnt = 5000;
@@ -6154,7 +6160,7 @@ int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx,
6154 return -EBUSY; 6160 return -EBUSY;
6155} 6161}
6156 6162
6157u8 bnx2x_e1h_cam_offset(struct bnx2x *bp, u8 rel_offset) 6163static u8 bnx2x_e1h_cam_offset(struct bnx2x *bp, u8 rel_offset)
6158{ 6164{
6159 if (CHIP_IS_E1H(bp)) 6165 if (CHIP_IS_E1H(bp))
6160 return E1H_FUNC_MAX * rel_offset + BP_FUNC(bp); 6166 return E1H_FUNC_MAX * rel_offset + BP_FUNC(bp);
@@ -6273,7 +6279,7 @@ static void bnx2x_invlidate_e1_mc_list(struct bnx2x *bp)
6273 * 6279 *
6274 * @return 0 if cussess, -ENODEV if ramrod doesn't return. 6280 * @return 0 if cussess, -ENODEV if ramrod doesn't return.
6275 */ 6281 */
6276int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp, int set) 6282static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp, int set)
6277{ 6283{
6278 u8 cam_offset = (CHIP_IS_E1(bp) ? ((BP_PORT(bp) ? 32 : 0) + 2) : 6284 u8 cam_offset = (CHIP_IS_E1(bp) ? ((BP_PORT(bp) ? 32 : 0) + 2) :
6279 bnx2x_e1h_cam_offset(bp, CAM_ISCSI_ETH_LINE)); 6285 bnx2x_e1h_cam_offset(bp, CAM_ISCSI_ETH_LINE));
@@ -6383,11 +6389,11 @@ static inline void bnx2x_set_ctx_validation(struct eth_context *cxt, u32 cid)
6383 ETH_CONNECTION_TYPE); 6389 ETH_CONNECTION_TYPE);
6384} 6390}
6385 6391
6386int bnx2x_setup_fw_client(struct bnx2x *bp, 6392static int bnx2x_setup_fw_client(struct bnx2x *bp,
6387 struct bnx2x_client_init_params *params, 6393 struct bnx2x_client_init_params *params,
6388 u8 activate, 6394 u8 activate,
6389 struct client_init_ramrod_data *data, 6395 struct client_init_ramrod_data *data,
6390 dma_addr_t data_mapping) 6396 dma_addr_t data_mapping)
6391{ 6397{
6392 u16 hc_usec; 6398 u16 hc_usec;
6393 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP; 6399 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
@@ -6633,7 +6639,8 @@ int bnx2x_setup_client(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6633 return rc; 6639 return rc;
6634} 6640}
6635 6641
6636int bnx2x_stop_fw_client(struct bnx2x *bp, struct bnx2x_client_ramrod_params *p) 6642static int bnx2x_stop_fw_client(struct bnx2x *bp,
6643 struct bnx2x_client_ramrod_params *p)
6637{ 6644{
6638 int rc; 6645 int rc;
6639 6646
@@ -7440,7 +7447,7 @@ reset_task_exit:
7440 * Init service functions 7447 * Init service functions
7441 */ 7448 */
7442 7449
7443u32 bnx2x_get_pretend_reg(struct bnx2x *bp) 7450static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
7444{ 7451{
7445 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0; 7452 u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
7446 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base; 7453 u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index beb3b7cecd52..bdb68a600382 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -493,9 +493,9 @@ static void bond_vlan_rx_register(struct net_device *bond_dev,
493 struct slave *slave; 493 struct slave *slave;
494 int i; 494 int i;
495 495
496 write_lock(&bond->lock); 496 write_lock_bh(&bond->lock);
497 bond->vlgrp = grp; 497 bond->vlgrp = grp;
498 write_unlock(&bond->lock); 498 write_unlock_bh(&bond->lock);
499 499
500 bond_for_each_slave(bond, slave, i) { 500 bond_for_each_slave(bond, slave, i) {
501 struct net_device *slave_dev = slave->dev; 501 struct net_device *slave_dev = slave->dev;
diff --git a/drivers/net/caif/Kconfig b/drivers/net/caif/Kconfig
index 75bfc3a9d95f..09ed3f42d673 100644
--- a/drivers/net/caif/Kconfig
+++ b/drivers/net/caif/Kconfig
@@ -31,3 +31,10 @@ config CAIF_SPI_SYNC
31 Putting the next command and length in the start of the frame can 31 Putting the next command and length in the start of the frame can
32 help to synchronize to the next transfer in case of over or under-runs. 32 help to synchronize to the next transfer in case of over or under-runs.
33 This option also needs to be enabled on the modem. 33 This option also needs to be enabled on the modem.
34
35config CAIF_SHM
36 tristate "CAIF shared memory protocol driver"
37 depends on CAIF && U5500_MBOX
38 default n
39 ---help---
40 The CAIF shared memory protocol driver for the STE UX5500 platform.
diff --git a/drivers/net/caif/Makefile b/drivers/net/caif/Makefile
index 3a11d619452b..b38d987da67d 100644
--- a/drivers/net/caif/Makefile
+++ b/drivers/net/caif/Makefile
@@ -8,3 +8,7 @@ obj-$(CONFIG_CAIF_TTY) += caif_serial.o
8# SPI slave physical interfaces module 8# SPI slave physical interfaces module
9cfspi_slave-objs := caif_spi.o caif_spi_slave.o 9cfspi_slave-objs := caif_spi.o caif_spi_slave.o
10obj-$(CONFIG_CAIF_SPI_SLAVE) += cfspi_slave.o 10obj-$(CONFIG_CAIF_SPI_SLAVE) += cfspi_slave.o
11
12# Shared memory
13caif_shm-objs := caif_shmcore.o caif_shm_u5500.o
14obj-$(CONFIG_CAIF_SHM) += caif_shm.o
diff --git a/drivers/net/caif/caif_shm_u5500.c b/drivers/net/caif/caif_shm_u5500.c
new file mode 100644
index 000000000000..1cd90da86f13
--- /dev/null
+++ b/drivers/net/caif/caif_shm_u5500.c
@@ -0,0 +1,129 @@
1/*
2 * Copyright (C) ST-Ericsson AB 2010
3 * Contact: Sjur Brendeland / sjur.brandeland@stericsson.com
4 * Author: Amarnath Revanna / amarnath.bangalore.revanna@stericsson.com
5 * License terms: GNU General Public License (GPL) version 2
6 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ":" __func__ "():" fmt
9
10#include <linux/version.h>
11#include <linux/init.h>
12#include <linux/module.h>
13#include <linux/netdevice.h>
14#include <mach/mbox.h>
15#include <net/caif/caif_shm.h>
16
17MODULE_LICENSE("GPL");
18MODULE_DESCRIPTION("CAIF Shared Memory protocol driver");
19
20#define MAX_SHM_INSTANCES 1
21
22enum {
23 MBX_ACC0,
24 MBX_ACC1,
25 MBX_DSP
26};
27
28static struct shmdev_layer shmdev_lyr[MAX_SHM_INSTANCES];
29
30static unsigned int shm_start;
31static unsigned int shm_size;
32
33module_param(shm_size, uint , 0440);
34MODULE_PARM_DESC(shm_total_size, "Start of SHM shared memory");
35
36module_param(shm_start, uint , 0440);
37MODULE_PARM_DESC(shm_total_start, "Total Size of SHM shared memory");
38
39static int shmdev_send_msg(u32 dev_id, u32 mbx_msg)
40{
41 /* Always block until msg is written successfully */
42 mbox_send(shmdev_lyr[dev_id].hmbx, mbx_msg, true);
43 return 0;
44}
45
46static int shmdev_mbx_setup(void *pshmdrv_cb, struct shmdev_layer *pshm_dev,
47 void *pshm_drv)
48{
49 /*
50 * For UX5500, we have only 1 SHM instance which uses MBX0
51 * for communication with the peer modem
52 */
53 pshm_dev->hmbx = mbox_setup(MBX_ACC0, pshmdrv_cb, pshm_drv);
54
55 if (!pshm_dev->hmbx)
56 return -ENODEV;
57 else
58 return 0;
59}
60
61static int __init caif_shmdev_init(void)
62{
63 int i, result;
64
65 /* Loop is currently overkill, there is only one instance */
66 for (i = 0; i < MAX_SHM_INSTANCES; i++) {
67
68 shmdev_lyr[i].shm_base_addr = shm_start;
69 shmdev_lyr[i].shm_total_sz = shm_size;
70
71 if (((char *)shmdev_lyr[i].shm_base_addr == NULL)
72 || (shmdev_lyr[i].shm_total_sz <= 0)) {
73 pr_warn("ERROR,"
74 "Shared memory Address and/or Size incorrect"
75 ", Bailing out ...\n");
76 result = -EINVAL;
77 goto clean;
78 }
79
80 pr_info("SHM AREA (instance %d) STARTS"
81 " AT %p\n", i, (char *)shmdev_lyr[i].shm_base_addr);
82
83 shmdev_lyr[i].shm_id = i;
84 shmdev_lyr[i].pshmdev_mbxsend = shmdev_send_msg;
85 shmdev_lyr[i].pshmdev_mbxsetup = shmdev_mbx_setup;
86
87 /*
88 * Finally, CAIF core module is called with details in place:
89 * 1. SHM base address
90 * 2. SHM size
91 * 3. MBX handle
92 */
93 result = caif_shmcore_probe(&shmdev_lyr[i]);
94 if (result) {
95 pr_warn("ERROR[%d],"
96 "Could not probe SHM core (instance %d)"
97 " Bailing out ...\n", result, i);
98 goto clean;
99 }
100 }
101
102 return 0;
103
104clean:
105 /*
106 * For now, we assume that even if one instance of SHM fails, we bail
107 * out of the driver support completely. For this, we need to release
108 * any memory allocated and unregister any instance of SHM net device.
109 */
110 for (i = 0; i < MAX_SHM_INSTANCES; i++) {
111 if (shmdev_lyr[i].pshm_netdev)
112 unregister_netdev(shmdev_lyr[i].pshm_netdev);
113 }
114 return result;
115}
116
117static void __exit caif_shmdev_exit(void)
118{
119 int i;
120
121 for (i = 0; i < MAX_SHM_INSTANCES; i++) {
122 caif_shmcore_remove(shmdev_lyr[i].pshm_netdev);
123 kfree((void *)shmdev_lyr[i].shm_base_addr);
124 }
125
126}
127
128module_init(caif_shmdev_init);
129module_exit(caif_shmdev_exit);
diff --git a/drivers/net/caif/caif_shmcore.c b/drivers/net/caif/caif_shmcore.c
new file mode 100644
index 000000000000..19f9c0656667
--- /dev/null
+++ b/drivers/net/caif/caif_shmcore.c
@@ -0,0 +1,744 @@
1/*
2 * Copyright (C) ST-Ericsson AB 2010
3 * Contact: Sjur Brendeland / sjur.brandeland@stericsson.com
4 * Authors: Amarnath Revanna / amarnath.bangalore.revanna@stericsson.com,
5 * Daniel Martensson / daniel.martensson@stericsson.com
6 * License terms: GNU General Public License (GPL) version 2
7 */
8
9#define pr_fmt(fmt) KBUILD_MODNAME ":" __func__ "():" fmt
10
11#include <linux/spinlock.h>
12#include <linux/sched.h>
13#include <linux/list.h>
14#include <linux/netdevice.h>
15#include <linux/if_arp.h>
16
17#include <net/caif/caif_device.h>
18#include <net/caif/caif_shm.h>
19
20#define NR_TX_BUF 6
21#define NR_RX_BUF 6
22#define TX_BUF_SZ 0x2000
23#define RX_BUF_SZ 0x2000
24
25#define CAIF_NEEDED_HEADROOM 32
26
27#define CAIF_FLOW_ON 1
28#define CAIF_FLOW_OFF 0
29
30#define LOW_WATERMARK 3
31#define HIGH_WATERMARK 4
32
33/* Maximum number of CAIF buffers per shared memory buffer. */
34#define SHM_MAX_FRMS_PER_BUF 10
35
36/*
37 * Size in bytes of the descriptor area
38 * (With end of descriptor signalling)
39 */
40#define SHM_CAIF_DESC_SIZE ((SHM_MAX_FRMS_PER_BUF + 1) * \
41 sizeof(struct shm_pck_desc))
42
43/*
44 * Offset to the first CAIF frame within a shared memory buffer.
45 * Aligned on 32 bytes.
46 */
47#define SHM_CAIF_FRM_OFS (SHM_CAIF_DESC_SIZE + (SHM_CAIF_DESC_SIZE % 32))
48
49/* Number of bytes for CAIF shared memory header. */
50#define SHM_HDR_LEN 1
51
52/* Number of padding bytes for the complete CAIF frame. */
53#define SHM_FRM_PAD_LEN 4
54
55#define CAIF_MAX_MTU 4096
56
57#define SHM_SET_FULL(x) (((x+1) & 0x0F) << 0)
58#define SHM_GET_FULL(x) (((x >> 0) & 0x0F) - 1)
59
60#define SHM_SET_EMPTY(x) (((x+1) & 0x0F) << 4)
61#define SHM_GET_EMPTY(x) (((x >> 4) & 0x0F) - 1)
62
63#define SHM_FULL_MASK (0x0F << 0)
64#define SHM_EMPTY_MASK (0x0F << 4)
65
66struct shm_pck_desc {
67 /*
68 * Offset from start of shared memory area to start of
69 * shared memory CAIF frame.
70 */
71 u32 frm_ofs;
72 u32 frm_len;
73};
74
75struct buf_list {
76 unsigned char *desc_vptr;
77 u32 phy_addr;
78 u32 index;
79 u32 len;
80 u32 frames;
81 u32 frm_ofs;
82 struct list_head list;
83};
84
85struct shm_caif_frm {
86 /* Number of bytes of padding before the CAIF frame. */
87 u8 hdr_ofs;
88};
89
90struct shmdrv_layer {
91 /* caif_dev_common must always be first in the structure*/
92 struct caif_dev_common cfdev;
93
94 u32 shm_tx_addr;
95 u32 shm_rx_addr;
96 u32 shm_base_addr;
97 u32 tx_empty_available;
98 spinlock_t lock;
99
100 struct list_head tx_empty_list;
101 struct list_head tx_pend_list;
102 struct list_head tx_full_list;
103 struct list_head rx_empty_list;
104 struct list_head rx_pend_list;
105 struct list_head rx_full_list;
106
107 struct workqueue_struct *pshm_tx_workqueue;
108 struct workqueue_struct *pshm_rx_workqueue;
109
110 struct work_struct shm_tx_work;
111 struct work_struct shm_rx_work;
112
113 struct sk_buff_head sk_qhead;
114 struct shmdev_layer *pshm_dev;
115};
116
117static int shm_netdev_open(struct net_device *shm_netdev)
118{
119 netif_wake_queue(shm_netdev);
120 return 0;
121}
122
123static int shm_netdev_close(struct net_device *shm_netdev)
124{
125 netif_stop_queue(shm_netdev);
126 return 0;
127}
128
129int caif_shmdrv_rx_cb(u32 mbx_msg, void *priv)
130{
131 struct buf_list *pbuf;
132 struct shmdrv_layer *pshm_drv;
133 struct list_head *pos;
134 u32 avail_emptybuff = 0;
135 unsigned long flags = 0;
136
137 pshm_drv = (struct shmdrv_layer *)priv;
138
139 /* Check for received buffers. */
140 if (mbx_msg & SHM_FULL_MASK) {
141 int idx;
142
143 spin_lock_irqsave(&pshm_drv->lock, flags);
144
145 /* Check whether we have any outstanding buffers. */
146 if (list_empty(&pshm_drv->rx_empty_list)) {
147
148 /* Release spin lock. */
149 spin_unlock_irqrestore(&pshm_drv->lock, flags);
150
151 /* We print even in IRQ context... */
152 pr_warn("No empty Rx buffers to fill: "
153 "mbx_msg:%x\n", mbx_msg);
154
155 /* Bail out. */
156 goto err_sync;
157 }
158
159 pbuf =
160 list_entry(pshm_drv->rx_empty_list.next,
161 struct buf_list, list);
162 idx = pbuf->index;
163
164 /* Check buffer synchronization. */
165 if (idx != SHM_GET_FULL(mbx_msg)) {
166
167 /* We print even in IRQ context... */
168 pr_warn(
169 "phyif_shm_mbx_msg_cb: RX full out of sync:"
170 " idx:%d, msg:%x SHM_GET_FULL(mbx_msg):%x\n",
171 idx, mbx_msg, SHM_GET_FULL(mbx_msg));
172
173 spin_unlock_irqrestore(&pshm_drv->lock, flags);
174
175 /* Bail out. */
176 goto err_sync;
177 }
178
179 list_del_init(&pbuf->list);
180 list_add_tail(&pbuf->list, &pshm_drv->rx_full_list);
181
182 spin_unlock_irqrestore(&pshm_drv->lock, flags);
183
184 /* Schedule RX work queue. */
185 if (!work_pending(&pshm_drv->shm_rx_work))
186 queue_work(pshm_drv->pshm_rx_workqueue,
187 &pshm_drv->shm_rx_work);
188 }
189
190 /* Check for emptied buffers. */
191 if (mbx_msg & SHM_EMPTY_MASK) {
192 int idx;
193
194 spin_lock_irqsave(&pshm_drv->lock, flags);
195
196 /* Check whether we have any outstanding buffers. */
197 if (list_empty(&pshm_drv->tx_full_list)) {
198
199 /* We print even in IRQ context... */
200 pr_warn("No TX to empty: msg:%x\n", mbx_msg);
201
202 spin_unlock_irqrestore(&pshm_drv->lock, flags);
203
204 /* Bail out. */
205 goto err_sync;
206 }
207
208 pbuf =
209 list_entry(pshm_drv->tx_full_list.next,
210 struct buf_list, list);
211 idx = pbuf->index;
212
213 /* Check buffer synchronization. */
214 if (idx != SHM_GET_EMPTY(mbx_msg)) {
215
216 spin_unlock_irqrestore(&pshm_drv->lock, flags);
217
218 /* We print even in IRQ context... */
219 pr_warn("TX empty "
220 "out of sync:idx:%d, msg:%x\n", idx, mbx_msg);
221
222 /* Bail out. */
223 goto err_sync;
224 }
225 list_del_init(&pbuf->list);
226
227 /* Reset buffer parameters. */
228 pbuf->frames = 0;
229 pbuf->frm_ofs = SHM_CAIF_FRM_OFS;
230
231 list_add_tail(&pbuf->list, &pshm_drv->tx_empty_list);
232
233 /* Check the available no. of buffers in the empty list */
234 list_for_each(pos, &pshm_drv->tx_empty_list)
235 avail_emptybuff++;
236
237 /* Check whether we have to wake up the transmitter. */
238 if ((avail_emptybuff > HIGH_WATERMARK) &&
239 (!pshm_drv->tx_empty_available)) {
240 pshm_drv->tx_empty_available = 1;
241 pshm_drv->cfdev.flowctrl
242 (pshm_drv->pshm_dev->pshm_netdev,
243 CAIF_FLOW_ON);
244
245 spin_unlock_irqrestore(&pshm_drv->lock, flags);
246
247 /* Schedule the work queue. if required */
248 if (!work_pending(&pshm_drv->shm_tx_work))
249 queue_work(pshm_drv->pshm_tx_workqueue,
250 &pshm_drv->shm_tx_work);
251 } else
252 spin_unlock_irqrestore(&pshm_drv->lock, flags);
253 }
254
255 return 0;
256
257err_sync:
258 return -EIO;
259}
260
261static void shm_rx_work_func(struct work_struct *rx_work)
262{
263 struct shmdrv_layer *pshm_drv;
264 struct buf_list *pbuf;
265 unsigned long flags = 0;
266 struct sk_buff *skb;
267 char *p;
268 int ret;
269
270 pshm_drv = container_of(rx_work, struct shmdrv_layer, shm_rx_work);
271
272 while (1) {
273
274 struct shm_pck_desc *pck_desc;
275
276 spin_lock_irqsave(&pshm_drv->lock, flags);
277
278 /* Check for received buffers. */
279 if (list_empty(&pshm_drv->rx_full_list)) {
280 spin_unlock_irqrestore(&pshm_drv->lock, flags);
281 break;
282 }
283
284 pbuf =
285 list_entry(pshm_drv->rx_full_list.next, struct buf_list,
286 list);
287 list_del_init(&pbuf->list);
288
289 /* Retrieve pointer to start of the packet descriptor area. */
290 pck_desc = (struct shm_pck_desc *) pbuf->desc_vptr;
291
292 /*
293 * Check whether descriptor contains a CAIF shared memory
294 * frame.
295 */
296 while (pck_desc->frm_ofs) {
297 unsigned int frm_buf_ofs;
298 unsigned int frm_pck_ofs;
299 unsigned int frm_pck_len;
300 /*
301 * Check whether offset is within buffer limits
302 * (lower).
303 */
304 if (pck_desc->frm_ofs <
305 (pbuf->phy_addr - pshm_drv->shm_base_addr))
306 break;
307 /*
308 * Check whether offset is within buffer limits
309 * (higher).
310 */
311 if (pck_desc->frm_ofs >
312 ((pbuf->phy_addr - pshm_drv->shm_base_addr) +
313 pbuf->len))
314 break;
315
316 /* Calculate offset from start of buffer. */
317 frm_buf_ofs =
318 pck_desc->frm_ofs - (pbuf->phy_addr -
319 pshm_drv->shm_base_addr);
320
321 /*
322 * Calculate offset and length of CAIF packet while
323 * taking care of the shared memory header.
324 */
325 frm_pck_ofs =
326 frm_buf_ofs + SHM_HDR_LEN +
327 (*(pbuf->desc_vptr + frm_buf_ofs));
328 frm_pck_len =
329 (pck_desc->frm_len - SHM_HDR_LEN -
330 (*(pbuf->desc_vptr + frm_buf_ofs)));
331
332 /* Check whether CAIF packet is within buffer limits */
333 if ((frm_pck_ofs + pck_desc->frm_len) > pbuf->len)
334 break;
335
336 /* Get a suitable CAIF packet and copy in data. */
337 skb = netdev_alloc_skb(pshm_drv->pshm_dev->pshm_netdev,
338 frm_pck_len + 1);
339 BUG_ON(skb == NULL);
340
341 p = skb_put(skb, frm_pck_len);
342 memcpy(p, pbuf->desc_vptr + frm_pck_ofs, frm_pck_len);
343
344 skb->protocol = htons(ETH_P_CAIF);
345 skb_reset_mac_header(skb);
346 skb->dev = pshm_drv->pshm_dev->pshm_netdev;
347
348 /* Push received packet up the stack. */
349 ret = netif_rx_ni(skb);
350
351 if (!ret) {
352 pshm_drv->pshm_dev->pshm_netdev->stats.
353 rx_packets++;
354 pshm_drv->pshm_dev->pshm_netdev->stats.
355 rx_bytes += pck_desc->frm_len;
356 } else
357 ++pshm_drv->pshm_dev->pshm_netdev->stats.
358 rx_dropped;
359 /* Move to next packet descriptor. */
360 pck_desc++;
361 }
362
363 list_add_tail(&pbuf->list, &pshm_drv->rx_pend_list);
364
365 spin_unlock_irqrestore(&pshm_drv->lock, flags);
366
367 }
368
369 /* Schedule the work queue. if required */
370 if (!work_pending(&pshm_drv->shm_tx_work))
371 queue_work(pshm_drv->pshm_tx_workqueue, &pshm_drv->shm_tx_work);
372
373}
374
375static void shm_tx_work_func(struct work_struct *tx_work)
376{
377 u32 mbox_msg;
378 unsigned int frmlen, avail_emptybuff, append = 0;
379 unsigned long flags = 0;
380 struct buf_list *pbuf = NULL;
381 struct shmdrv_layer *pshm_drv;
382 struct shm_caif_frm *frm;
383 struct sk_buff *skb;
384 struct shm_pck_desc *pck_desc;
385 struct list_head *pos;
386
387 pshm_drv = container_of(tx_work, struct shmdrv_layer, shm_tx_work);
388
389 do {
390 /* Initialize mailbox message. */
391 mbox_msg = 0x00;
392 avail_emptybuff = 0;
393
394 spin_lock_irqsave(&pshm_drv->lock, flags);
395
396 /* Check for pending receive buffers. */
397 if (!list_empty(&pshm_drv->rx_pend_list)) {
398
399 pbuf = list_entry(pshm_drv->rx_pend_list.next,
400 struct buf_list, list);
401
402 list_del_init(&pbuf->list);
403 list_add_tail(&pbuf->list, &pshm_drv->rx_empty_list);
404 /*
405 * Value index is never changed,
406 * so read access should be safe.
407 */
408 mbox_msg |= SHM_SET_EMPTY(pbuf->index);
409 }
410
411 skb = skb_peek(&pshm_drv->sk_qhead);
412
413 if (skb == NULL)
414 goto send_msg;
415
416 /* Check the available no. of buffers in the empty list */
417 list_for_each(pos, &pshm_drv->tx_empty_list)
418 avail_emptybuff++;
419
420 if ((avail_emptybuff < LOW_WATERMARK) &&
421 pshm_drv->tx_empty_available) {
422 /* Update blocking condition. */
423 pshm_drv->tx_empty_available = 0;
424 pshm_drv->cfdev.flowctrl
425 (pshm_drv->pshm_dev->pshm_netdev,
426 CAIF_FLOW_OFF);
427 }
428 /*
429 * We simply return back to the caller if we do not have space
430 * either in Tx pending list or Tx empty list. In this case,
431 * we hold the received skb in the skb list, waiting to
432 * be transmitted once Tx buffers become available
433 */
434 if (list_empty(&pshm_drv->tx_empty_list))
435 goto send_msg;
436
437 /* Get the first free Tx buffer. */
438 pbuf = list_entry(pshm_drv->tx_empty_list.next,
439 struct buf_list, list);
440 do {
441 if (append) {
442 skb = skb_peek(&pshm_drv->sk_qhead);
443 if (skb == NULL)
444 break;
445 }
446
447 frm = (struct shm_caif_frm *)
448 (pbuf->desc_vptr + pbuf->frm_ofs);
449
450 frm->hdr_ofs = 0;
451 frmlen = 0;
452 frmlen += SHM_HDR_LEN + frm->hdr_ofs + skb->len;
453
454 /* Add tail padding if needed. */
455 if (frmlen % SHM_FRM_PAD_LEN)
456 frmlen += SHM_FRM_PAD_LEN -
457 (frmlen % SHM_FRM_PAD_LEN);
458
459 /*
460 * Verify that packet, header and additional padding
461 * can fit within the buffer frame area.
462 */
463 if (frmlen >= (pbuf->len - pbuf->frm_ofs))
464 break;
465
466 if (!append) {
467 list_del_init(&pbuf->list);
468 append = 1;
469 }
470
471 skb = skb_dequeue(&pshm_drv->sk_qhead);
472 /* Copy in CAIF frame. */
473 skb_copy_bits(skb, 0, pbuf->desc_vptr +
474 pbuf->frm_ofs + SHM_HDR_LEN +
475 frm->hdr_ofs, skb->len);
476
477 pshm_drv->pshm_dev->pshm_netdev->stats.tx_packets++;
478 pshm_drv->pshm_dev->pshm_netdev->stats.tx_bytes +=
479 frmlen;
480 dev_kfree_skb(skb);
481
482 /* Fill in the shared memory packet descriptor area. */
483 pck_desc = (struct shm_pck_desc *) (pbuf->desc_vptr);
484 /* Forward to current frame. */
485 pck_desc += pbuf->frames;
486 pck_desc->frm_ofs = (pbuf->phy_addr -
487 pshm_drv->shm_base_addr) +
488 pbuf->frm_ofs;
489 pck_desc->frm_len = frmlen;
490 /* Terminate packet descriptor area. */
491 pck_desc++;
492 pck_desc->frm_ofs = 0;
493 /* Update buffer parameters. */
494 pbuf->frames++;
495 pbuf->frm_ofs += frmlen + (frmlen % 32);
496
497 } while (pbuf->frames < SHM_MAX_FRMS_PER_BUF);
498
499 /* Assign buffer as full. */
500 list_add_tail(&pbuf->list, &pshm_drv->tx_full_list);
501 append = 0;
502 mbox_msg |= SHM_SET_FULL(pbuf->index);
503send_msg:
504 spin_unlock_irqrestore(&pshm_drv->lock, flags);
505
506 if (mbox_msg)
507 pshm_drv->pshm_dev->pshmdev_mbxsend
508 (pshm_drv->pshm_dev->shm_id, mbox_msg);
509 } while (mbox_msg);
510}
511
512static int shm_netdev_tx(struct sk_buff *skb, struct net_device *shm_netdev)
513{
514 struct shmdrv_layer *pshm_drv;
515 unsigned long flags = 0;
516
517 pshm_drv = netdev_priv(shm_netdev);
518
519 spin_lock_irqsave(&pshm_drv->lock, flags);
520
521 skb_queue_tail(&pshm_drv->sk_qhead, skb);
522
523 spin_unlock_irqrestore(&pshm_drv->lock, flags);
524
525 /* Schedule Tx work queue. for deferred processing of skbs*/
526 if (!work_pending(&pshm_drv->shm_tx_work))
527 queue_work(pshm_drv->pshm_tx_workqueue, &pshm_drv->shm_tx_work);
528
529 return 0;
530}
531
532static const struct net_device_ops netdev_ops = {
533 .ndo_open = shm_netdev_open,
534 .ndo_stop = shm_netdev_close,
535 .ndo_start_xmit = shm_netdev_tx,
536};
537
538static void shm_netdev_setup(struct net_device *pshm_netdev)
539{
540 struct shmdrv_layer *pshm_drv;
541 pshm_netdev->netdev_ops = &netdev_ops;
542
543 pshm_netdev->mtu = CAIF_MAX_MTU;
544 pshm_netdev->type = ARPHRD_CAIF;
545 pshm_netdev->hard_header_len = CAIF_NEEDED_HEADROOM;
546 pshm_netdev->tx_queue_len = 0;
547 pshm_netdev->destructor = free_netdev;
548
549 pshm_drv = netdev_priv(pshm_netdev);
550
551 /* Initialize structures in a clean state. */
552 memset(pshm_drv, 0, sizeof(struct shmdrv_layer));
553
554 pshm_drv->cfdev.link_select = CAIF_LINK_LOW_LATENCY;
555}
556
557int caif_shmcore_probe(struct shmdev_layer *pshm_dev)
558{
559 int result, j;
560 struct shmdrv_layer *pshm_drv = NULL;
561
562 pshm_dev->pshm_netdev = alloc_netdev(sizeof(struct shmdrv_layer),
563 "cfshm%d", shm_netdev_setup);
564 if (!pshm_dev->pshm_netdev)
565 return -ENOMEM;
566
567 pshm_drv = netdev_priv(pshm_dev->pshm_netdev);
568 pshm_drv->pshm_dev = pshm_dev;
569
570 /*
571 * Initialization starts with the verification of the
572 * availability of MBX driver by calling its setup function.
573 * MBX driver must be available by this time for proper
574 * functioning of SHM driver.
575 */
576 if ((pshm_dev->pshmdev_mbxsetup
577 (caif_shmdrv_rx_cb, pshm_dev, pshm_drv)) != 0) {
578 pr_warn("Could not config. SHM Mailbox,"
579 " Bailing out.....\n");
580 free_netdev(pshm_dev->pshm_netdev);
581 return -ENODEV;
582 }
583
584 skb_queue_head_init(&pshm_drv->sk_qhead);
585
586 pr_info("SHM DEVICE[%d] PROBED BY DRIVER, NEW SHM DRIVER"
587 " INSTANCE AT pshm_drv =0x%p\n",
588 pshm_drv->pshm_dev->shm_id, pshm_drv);
589
590 if (pshm_dev->shm_total_sz <
591 (NR_TX_BUF * TX_BUF_SZ + NR_RX_BUF * RX_BUF_SZ)) {
592
593 pr_warn("ERROR, Amount of available"
594 " Phys. SHM cannot accomodate current SHM "
595 "driver configuration, Bailing out ...\n");
596 free_netdev(pshm_dev->pshm_netdev);
597 return -ENOMEM;
598 }
599
600 pshm_drv->shm_base_addr = pshm_dev->shm_base_addr;
601 pshm_drv->shm_tx_addr = pshm_drv->shm_base_addr;
602
603 if (pshm_dev->shm_loopback)
604 pshm_drv->shm_rx_addr = pshm_drv->shm_tx_addr;
605 else
606 pshm_drv->shm_rx_addr = pshm_dev->shm_base_addr +
607 (NR_TX_BUF * TX_BUF_SZ);
608
609 INIT_LIST_HEAD(&pshm_drv->tx_empty_list);
610 INIT_LIST_HEAD(&pshm_drv->tx_pend_list);
611 INIT_LIST_HEAD(&pshm_drv->tx_full_list);
612
613 INIT_LIST_HEAD(&pshm_drv->rx_empty_list);
614 INIT_LIST_HEAD(&pshm_drv->rx_pend_list);
615 INIT_LIST_HEAD(&pshm_drv->rx_full_list);
616
617 INIT_WORK(&pshm_drv->shm_tx_work, shm_tx_work_func);
618 INIT_WORK(&pshm_drv->shm_rx_work, shm_rx_work_func);
619
620 pshm_drv->pshm_tx_workqueue =
621 create_singlethread_workqueue("shm_tx_work");
622 pshm_drv->pshm_rx_workqueue =
623 create_singlethread_workqueue("shm_rx_work");
624
625 for (j = 0; j < NR_TX_BUF; j++) {
626 struct buf_list *tx_buf =
627 kmalloc(sizeof(struct buf_list), GFP_KERNEL);
628
629 if (tx_buf == NULL) {
630 pr_warn("ERROR, Could not"
631 " allocate dynamic mem. for tx_buf,"
632 " Bailing out ...\n");
633 free_netdev(pshm_dev->pshm_netdev);
634 return -ENOMEM;
635 }
636 tx_buf->index = j;
637 tx_buf->phy_addr = pshm_drv->shm_tx_addr + (TX_BUF_SZ * j);
638 tx_buf->len = TX_BUF_SZ;
639 tx_buf->frames = 0;
640 tx_buf->frm_ofs = SHM_CAIF_FRM_OFS;
641
642 if (pshm_dev->shm_loopback)
643 tx_buf->desc_vptr = (char *)tx_buf->phy_addr;
644 else
645 tx_buf->desc_vptr =
646 ioremap(tx_buf->phy_addr, TX_BUF_SZ);
647
648 list_add_tail(&tx_buf->list, &pshm_drv->tx_empty_list);
649 }
650
651 for (j = 0; j < NR_RX_BUF; j++) {
652 struct buf_list *rx_buf =
653 kmalloc(sizeof(struct buf_list), GFP_KERNEL);
654
655 if (rx_buf == NULL) {
656 pr_warn("ERROR, Could not"
657 " allocate dynamic mem.for rx_buf,"
658 " Bailing out ...\n");
659 free_netdev(pshm_dev->pshm_netdev);
660 return -ENOMEM;
661 }
662 rx_buf->index = j;
663 rx_buf->phy_addr = pshm_drv->shm_rx_addr + (RX_BUF_SZ * j);
664 rx_buf->len = RX_BUF_SZ;
665
666 if (pshm_dev->shm_loopback)
667 rx_buf->desc_vptr = (char *)rx_buf->phy_addr;
668 else
669 rx_buf->desc_vptr =
670 ioremap(rx_buf->phy_addr, RX_BUF_SZ);
671 list_add_tail(&rx_buf->list, &pshm_drv->rx_empty_list);
672 }
673
674 pshm_drv->tx_empty_available = 1;
675 result = register_netdev(pshm_dev->pshm_netdev);
676 if (result)
677 pr_warn("ERROR[%d], SHM could not, "
678 "register with NW FRMWK Bailing out ...\n", result);
679
680 return result;
681}
682
683void caif_shmcore_remove(struct net_device *pshm_netdev)
684{
685 struct buf_list *pbuf;
686 struct shmdrv_layer *pshm_drv = NULL;
687
688 pshm_drv = netdev_priv(pshm_netdev);
689
690 while (!(list_empty(&pshm_drv->tx_pend_list))) {
691 pbuf =
692 list_entry(pshm_drv->tx_pend_list.next,
693 struct buf_list, list);
694
695 list_del(&pbuf->list);
696 kfree(pbuf);
697 }
698
699 while (!(list_empty(&pshm_drv->tx_full_list))) {
700 pbuf =
701 list_entry(pshm_drv->tx_full_list.next,
702 struct buf_list, list);
703 list_del(&pbuf->list);
704 kfree(pbuf);
705 }
706
707 while (!(list_empty(&pshm_drv->tx_empty_list))) {
708 pbuf =
709 list_entry(pshm_drv->tx_empty_list.next,
710 struct buf_list, list);
711 list_del(&pbuf->list);
712 kfree(pbuf);
713 }
714
715 while (!(list_empty(&pshm_drv->rx_full_list))) {
716 pbuf =
717 list_entry(pshm_drv->tx_full_list.next,
718 struct buf_list, list);
719 list_del(&pbuf->list);
720 kfree(pbuf);
721 }
722
723 while (!(list_empty(&pshm_drv->rx_pend_list))) {
724 pbuf =
725 list_entry(pshm_drv->tx_pend_list.next,
726 struct buf_list, list);
727 list_del(&pbuf->list);
728 kfree(pbuf);
729 }
730
731 while (!(list_empty(&pshm_drv->rx_empty_list))) {
732 pbuf =
733 list_entry(pshm_drv->rx_empty_list.next,
734 struct buf_list, list);
735 list_del(&pbuf->list);
736 kfree(pbuf);
737 }
738
739 /* Destroy work queues. */
740 destroy_workqueue(pshm_drv->pshm_tx_workqueue);
741 destroy_workqueue(pshm_drv->pshm_rx_workqueue);
742
743 unregister_netdev(pshm_netdev);
744}
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index 9d9e45394433..080574b0fff0 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -82,6 +82,14 @@ config CAN_FLEXCAN
82 ---help--- 82 ---help---
83 Say Y here if you want to support for Freescale FlexCAN. 83 Say Y here if you want to support for Freescale FlexCAN.
84 84
85config PCH_CAN
86 tristate "PCH CAN"
87 depends on CAN_DEV && PCI
88 ---help---
89 This driver is for PCH CAN of Topcliff which is an IOH for x86
90 embedded processor.
91 This driver can access CAN bus.
92
85source "drivers/net/can/mscan/Kconfig" 93source "drivers/net/can/mscan/Kconfig"
86 94
87source "drivers/net/can/sja1000/Kconfig" 95source "drivers/net/can/sja1000/Kconfig"
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
index 00575373bbd0..90af15a4f106 100644
--- a/drivers/net/can/Makefile
+++ b/drivers/net/can/Makefile
@@ -17,5 +17,6 @@ obj-$(CONFIG_CAN_MCP251X) += mcp251x.o
17obj-$(CONFIG_CAN_BFIN) += bfin_can.o 17obj-$(CONFIG_CAN_BFIN) += bfin_can.o
18obj-$(CONFIG_CAN_JANZ_ICAN3) += janz-ican3.o 18obj-$(CONFIG_CAN_JANZ_ICAN3) += janz-ican3.o
19obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o 19obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o
20obj-$(CONFIG_PCH_CAN) += pch_can.o
20 21
21ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG 22ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c
index 2d8bd86bc5e2..cee98fa668bd 100644
--- a/drivers/net/can/at91_can.c
+++ b/drivers/net/can/at91_can.c
@@ -2,7 +2,7 @@
2 * at91_can.c - CAN network driver for AT91 SoC CAN controller 2 * at91_can.c - CAN network driver for AT91 SoC CAN controller
3 * 3 *
4 * (C) 2007 by Hans J. Koch <hjk@linutronix.de> 4 * (C) 2007 by Hans J. Koch <hjk@linutronix.de>
5 * (C) 2008, 2009 by Marc Kleine-Budde <kernel@pengutronix.de> 5 * (C) 2008, 2009, 2010 by Marc Kleine-Budde <kernel@pengutronix.de>
6 * 6 *
7 * This software may be distributed under the terms of the GNU General 7 * This software may be distributed under the terms of the GNU General
8 * Public License ("GPL") version 2 as distributed in the 'COPYING' 8 * Public License ("GPL") version 2 as distributed in the 'COPYING'
@@ -40,7 +40,6 @@
40 40
41#include <mach/board.h> 41#include <mach/board.h>
42 42
43#define DRV_NAME "at91_can"
44#define AT91_NAPI_WEIGHT 12 43#define AT91_NAPI_WEIGHT 12
45 44
46/* 45/*
@@ -172,6 +171,7 @@ struct at91_priv {
172}; 171};
173 172
174static struct can_bittiming_const at91_bittiming_const = { 173static struct can_bittiming_const at91_bittiming_const = {
174 .name = KBUILD_MODNAME,
175 .tseg1_min = 4, 175 .tseg1_min = 4,
176 .tseg1_max = 16, 176 .tseg1_max = 16,
177 .tseg2_min = 2, 177 .tseg2_min = 2,
@@ -199,13 +199,13 @@ static inline int get_tx_echo_mb(const struct at91_priv *priv)
199 199
200static inline u32 at91_read(const struct at91_priv *priv, enum at91_reg reg) 200static inline u32 at91_read(const struct at91_priv *priv, enum at91_reg reg)
201{ 201{
202 return readl(priv->reg_base + reg); 202 return __raw_readl(priv->reg_base + reg);
203} 203}
204 204
205static inline void at91_write(const struct at91_priv *priv, enum at91_reg reg, 205static inline void at91_write(const struct at91_priv *priv, enum at91_reg reg,
206 u32 value) 206 u32 value)
207{ 207{
208 writel(value, priv->reg_base + reg); 208 __raw_writel(value, priv->reg_base + reg);
209} 209}
210 210
211static inline void set_mb_mode_prio(const struct at91_priv *priv, 211static inline void set_mb_mode_prio(const struct at91_priv *priv,
@@ -243,6 +243,12 @@ static void at91_setup_mailboxes(struct net_device *dev)
243 set_mb_mode(priv, i, AT91_MB_MODE_RX); 243 set_mb_mode(priv, i, AT91_MB_MODE_RX);
244 set_mb_mode(priv, AT91_MB_RX_LAST, AT91_MB_MODE_RX_OVRWR); 244 set_mb_mode(priv, AT91_MB_RX_LAST, AT91_MB_MODE_RX_OVRWR);
245 245
246 /* reset acceptance mask and id register */
247 for (i = AT91_MB_RX_FIRST; i <= AT91_MB_RX_LAST; i++) {
248 at91_write(priv, AT91_MAM(i), 0x0 );
249 at91_write(priv, AT91_MID(i), AT91_MID_MIDE);
250 }
251
246 /* The last 4 mailboxes are used for transmitting. */ 252 /* The last 4 mailboxes are used for transmitting. */
247 for (i = AT91_MB_TX_FIRST; i <= AT91_MB_TX_LAST; i++) 253 for (i = AT91_MB_TX_FIRST; i <= AT91_MB_TX_LAST; i++)
248 set_mb_mode_prio(priv, i, AT91_MB_MODE_TX, 0); 254 set_mb_mode_prio(priv, i, AT91_MB_MODE_TX, 0);
@@ -257,18 +263,30 @@ static int at91_set_bittiming(struct net_device *dev)
257 const struct can_bittiming *bt = &priv->can.bittiming; 263 const struct can_bittiming *bt = &priv->can.bittiming;
258 u32 reg_br; 264 u32 reg_br;
259 265
260 reg_br = ((priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) << 24) | 266 reg_br = ((priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) ? 1 << 24 : 0) |
261 ((bt->brp - 1) << 16) | ((bt->sjw - 1) << 12) | 267 ((bt->brp - 1) << 16) | ((bt->sjw - 1) << 12) |
262 ((bt->prop_seg - 1) << 8) | ((bt->phase_seg1 - 1) << 4) | 268 ((bt->prop_seg - 1) << 8) | ((bt->phase_seg1 - 1) << 4) |
263 ((bt->phase_seg2 - 1) << 0); 269 ((bt->phase_seg2 - 1) << 0);
264 270
265 dev_info(dev->dev.parent, "writing AT91_BR: 0x%08x\n", reg_br); 271 netdev_info(dev, "writing AT91_BR: 0x%08x\n", reg_br);
266 272
267 at91_write(priv, AT91_BR, reg_br); 273 at91_write(priv, AT91_BR, reg_br);
268 274
269 return 0; 275 return 0;
270} 276}
271 277
278static int at91_get_berr_counter(const struct net_device *dev,
279 struct can_berr_counter *bec)
280{
281 const struct at91_priv *priv = netdev_priv(dev);
282 u32 reg_ecr = at91_read(priv, AT91_ECR);
283
284 bec->rxerr = reg_ecr & 0xff;
285 bec->txerr = reg_ecr >> 16;
286
287 return 0;
288}
289
272static void at91_chip_start(struct net_device *dev) 290static void at91_chip_start(struct net_device *dev)
273{ 291{
274 struct at91_priv *priv = netdev_priv(dev); 292 struct at91_priv *priv = netdev_priv(dev);
@@ -281,6 +299,7 @@ static void at91_chip_start(struct net_device *dev)
281 reg_mr = at91_read(priv, AT91_MR); 299 reg_mr = at91_read(priv, AT91_MR);
282 at91_write(priv, AT91_MR, reg_mr & ~AT91_MR_CANEN); 300 at91_write(priv, AT91_MR, reg_mr & ~AT91_MR_CANEN);
283 301
302 at91_set_bittiming(dev);
284 at91_setup_mailboxes(dev); 303 at91_setup_mailboxes(dev);
285 at91_transceiver_switch(priv, 1); 304 at91_transceiver_switch(priv, 1);
286 305
@@ -350,8 +369,7 @@ static netdev_tx_t at91_start_xmit(struct sk_buff *skb, struct net_device *dev)
350 if (unlikely(!(at91_read(priv, AT91_MSR(mb)) & AT91_MSR_MRDY))) { 369 if (unlikely(!(at91_read(priv, AT91_MSR(mb)) & AT91_MSR_MRDY))) {
351 netif_stop_queue(dev); 370 netif_stop_queue(dev);
352 371
353 dev_err(dev->dev.parent, 372 netdev_err(dev, "BUG! TX buffer full when queue awake!\n");
354 "BUG! TX buffer full when queue awake!\n");
355 return NETDEV_TX_BUSY; 373 return NETDEV_TX_BUSY;
356 } 374 }
357 375
@@ -435,7 +453,7 @@ static void at91_rx_overflow_err(struct net_device *dev)
435 struct sk_buff *skb; 453 struct sk_buff *skb;
436 struct can_frame *cf; 454 struct can_frame *cf;
437 455
438 dev_dbg(dev->dev.parent, "RX buffer overflow\n"); 456 netdev_dbg(dev, "RX buffer overflow\n");
439 stats->rx_over_errors++; 457 stats->rx_over_errors++;
440 stats->rx_errors++; 458 stats->rx_errors++;
441 459
@@ -480,6 +498,9 @@ static void at91_read_mb(struct net_device *dev, unsigned int mb,
480 *(u32 *)(cf->data + 0) = at91_read(priv, AT91_MDL(mb)); 498 *(u32 *)(cf->data + 0) = at91_read(priv, AT91_MDL(mb));
481 *(u32 *)(cf->data + 4) = at91_read(priv, AT91_MDH(mb)); 499 *(u32 *)(cf->data + 4) = at91_read(priv, AT91_MDH(mb));
482 500
501 /* allow RX of extended frames */
502 at91_write(priv, AT91_MID(mb), AT91_MID_MIDE);
503
483 if (unlikely(mb == AT91_MB_RX_LAST && reg_msr & AT91_MSR_MMI)) 504 if (unlikely(mb == AT91_MB_RX_LAST && reg_msr & AT91_MSR_MMI))
484 at91_rx_overflow_err(dev); 505 at91_rx_overflow_err(dev);
485} 506}
@@ -565,8 +586,8 @@ static int at91_poll_rx(struct net_device *dev, int quota)
565 586
566 if (priv->rx_next > AT91_MB_RX_LOW_LAST && 587 if (priv->rx_next > AT91_MB_RX_LOW_LAST &&
567 reg_sr & AT91_MB_RX_LOW_MASK) 588 reg_sr & AT91_MB_RX_LOW_MASK)
568 dev_info(dev->dev.parent, 589 netdev_info(dev,
569 "order of incoming frames cannot be guaranteed\n"); 590 "order of incoming frames cannot be guaranteed\n");
570 591
571 again: 592 again:
572 for (mb = find_next_bit(addr, AT91_MB_RX_NUM, priv->rx_next); 593 for (mb = find_next_bit(addr, AT91_MB_RX_NUM, priv->rx_next);
@@ -604,7 +625,7 @@ static void at91_poll_err_frame(struct net_device *dev,
604 625
605 /* CRC error */ 626 /* CRC error */
606 if (reg_sr & AT91_IRQ_CERR) { 627 if (reg_sr & AT91_IRQ_CERR) {
607 dev_dbg(dev->dev.parent, "CERR irq\n"); 628 netdev_dbg(dev, "CERR irq\n");
608 dev->stats.rx_errors++; 629 dev->stats.rx_errors++;
609 priv->can.can_stats.bus_error++; 630 priv->can.can_stats.bus_error++;
610 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; 631 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
@@ -612,7 +633,7 @@ static void at91_poll_err_frame(struct net_device *dev,
612 633
613 /* Stuffing Error */ 634 /* Stuffing Error */
614 if (reg_sr & AT91_IRQ_SERR) { 635 if (reg_sr & AT91_IRQ_SERR) {
615 dev_dbg(dev->dev.parent, "SERR irq\n"); 636 netdev_dbg(dev, "SERR irq\n");
616 dev->stats.rx_errors++; 637 dev->stats.rx_errors++;
617 priv->can.can_stats.bus_error++; 638 priv->can.can_stats.bus_error++;
618 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; 639 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
@@ -621,14 +642,14 @@ static void at91_poll_err_frame(struct net_device *dev,
621 642
622 /* Acknowledgement Error */ 643 /* Acknowledgement Error */
623 if (reg_sr & AT91_IRQ_AERR) { 644 if (reg_sr & AT91_IRQ_AERR) {
624 dev_dbg(dev->dev.parent, "AERR irq\n"); 645 netdev_dbg(dev, "AERR irq\n");
625 dev->stats.tx_errors++; 646 dev->stats.tx_errors++;
626 cf->can_id |= CAN_ERR_ACK; 647 cf->can_id |= CAN_ERR_ACK;
627 } 648 }
628 649
629 /* Form error */ 650 /* Form error */
630 if (reg_sr & AT91_IRQ_FERR) { 651 if (reg_sr & AT91_IRQ_FERR) {
631 dev_dbg(dev->dev.parent, "FERR irq\n"); 652 netdev_dbg(dev, "FERR irq\n");
632 dev->stats.rx_errors++; 653 dev->stats.rx_errors++;
633 priv->can.can_stats.bus_error++; 654 priv->can.can_stats.bus_error++;
634 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; 655 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
@@ -637,7 +658,7 @@ static void at91_poll_err_frame(struct net_device *dev,
637 658
638 /* Bit Error */ 659 /* Bit Error */
639 if (reg_sr & AT91_IRQ_BERR) { 660 if (reg_sr & AT91_IRQ_BERR) {
640 dev_dbg(dev->dev.parent, "BERR irq\n"); 661 netdev_dbg(dev, "BERR irq\n");
641 dev->stats.tx_errors++; 662 dev->stats.tx_errors++;
642 priv->can.can_stats.bus_error++; 663 priv->can.can_stats.bus_error++;
643 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; 664 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
@@ -755,12 +776,10 @@ static void at91_irq_err_state(struct net_device *dev,
755 struct can_frame *cf, enum can_state new_state) 776 struct can_frame *cf, enum can_state new_state)
756{ 777{
757 struct at91_priv *priv = netdev_priv(dev); 778 struct at91_priv *priv = netdev_priv(dev);
758 u32 reg_idr, reg_ier, reg_ecr; 779 u32 reg_idr = 0, reg_ier = 0;
759 u8 tec, rec; 780 struct can_berr_counter bec;
760 781
761 reg_ecr = at91_read(priv, AT91_ECR); 782 at91_get_berr_counter(dev, &bec);
762 rec = reg_ecr & 0xff;
763 tec = reg_ecr >> 16;
764 783
765 switch (priv->can.state) { 784 switch (priv->can.state) {
766 case CAN_STATE_ERROR_ACTIVE: 785 case CAN_STATE_ERROR_ACTIVE:
@@ -771,11 +790,11 @@ static void at91_irq_err_state(struct net_device *dev,
771 */ 790 */
772 if (new_state >= CAN_STATE_ERROR_WARNING && 791 if (new_state >= CAN_STATE_ERROR_WARNING &&
773 new_state <= CAN_STATE_BUS_OFF) { 792 new_state <= CAN_STATE_BUS_OFF) {
774 dev_dbg(dev->dev.parent, "Error Warning IRQ\n"); 793 netdev_dbg(dev, "Error Warning IRQ\n");
775 priv->can.can_stats.error_warning++; 794 priv->can.can_stats.error_warning++;
776 795
777 cf->can_id |= CAN_ERR_CRTL; 796 cf->can_id |= CAN_ERR_CRTL;
778 cf->data[1] = (tec > rec) ? 797 cf->data[1] = (bec.txerr > bec.rxerr) ?
779 CAN_ERR_CRTL_TX_WARNING : 798 CAN_ERR_CRTL_TX_WARNING :
780 CAN_ERR_CRTL_RX_WARNING; 799 CAN_ERR_CRTL_RX_WARNING;
781 } 800 }
@@ -787,11 +806,11 @@ static void at91_irq_err_state(struct net_device *dev,
787 */ 806 */
788 if (new_state >= CAN_STATE_ERROR_PASSIVE && 807 if (new_state >= CAN_STATE_ERROR_PASSIVE &&
789 new_state <= CAN_STATE_BUS_OFF) { 808 new_state <= CAN_STATE_BUS_OFF) {
790 dev_dbg(dev->dev.parent, "Error Passive IRQ\n"); 809 netdev_dbg(dev, "Error Passive IRQ\n");
791 priv->can.can_stats.error_passive++; 810 priv->can.can_stats.error_passive++;
792 811
793 cf->can_id |= CAN_ERR_CRTL; 812 cf->can_id |= CAN_ERR_CRTL;
794 cf->data[1] = (tec > rec) ? 813 cf->data[1] = (bec.txerr > bec.rxerr) ?
795 CAN_ERR_CRTL_TX_PASSIVE : 814 CAN_ERR_CRTL_TX_PASSIVE :
796 CAN_ERR_CRTL_RX_PASSIVE; 815 CAN_ERR_CRTL_RX_PASSIVE;
797 } 816 }
@@ -804,7 +823,7 @@ static void at91_irq_err_state(struct net_device *dev,
804 if (new_state <= CAN_STATE_ERROR_PASSIVE) { 823 if (new_state <= CAN_STATE_ERROR_PASSIVE) {
805 cf->can_id |= CAN_ERR_RESTARTED; 824 cf->can_id |= CAN_ERR_RESTARTED;
806 825
807 dev_dbg(dev->dev.parent, "restarted\n"); 826 netdev_dbg(dev, "restarted\n");
808 priv->can.can_stats.restarts++; 827 priv->can.can_stats.restarts++;
809 828
810 netif_carrier_on(dev); 829 netif_carrier_on(dev);
@@ -825,7 +844,7 @@ static void at91_irq_err_state(struct net_device *dev,
825 * circumstances. so just enable AT91_IRQ_ERRP, thus 844 * circumstances. so just enable AT91_IRQ_ERRP, thus
826 * the "fallthrough" 845 * the "fallthrough"
827 */ 846 */
828 dev_dbg(dev->dev.parent, "Error Active\n"); 847 netdev_dbg(dev, "Error Active\n");
829 cf->can_id |= CAN_ERR_PROT; 848 cf->can_id |= CAN_ERR_PROT;
830 cf->data[2] = CAN_ERR_PROT_ACTIVE; 849 cf->data[2] = CAN_ERR_PROT_ACTIVE;
831 case CAN_STATE_ERROR_WARNING: /* fallthrough */ 850 case CAN_STATE_ERROR_WARNING: /* fallthrough */
@@ -843,7 +862,7 @@ static void at91_irq_err_state(struct net_device *dev,
843 862
844 cf->can_id |= CAN_ERR_BUSOFF; 863 cf->can_id |= CAN_ERR_BUSOFF;
845 864
846 dev_dbg(dev->dev.parent, "bus-off\n"); 865 netdev_dbg(dev, "bus-off\n");
847 netif_carrier_off(dev); 866 netif_carrier_off(dev);
848 priv->can.can_stats.bus_off++; 867 priv->can.can_stats.bus_off++;
849 868
@@ -881,7 +900,7 @@ static void at91_irq_err(struct net_device *dev)
881 else if (likely(reg_sr & AT91_IRQ_ERRA)) 900 else if (likely(reg_sr & AT91_IRQ_ERRA))
882 new_state = CAN_STATE_ERROR_ACTIVE; 901 new_state = CAN_STATE_ERROR_ACTIVE;
883 else { 902 else {
884 dev_err(dev->dev.parent, "BUG! hardware in undefined state\n"); 903 netdev_err(dev, "BUG! hardware in undefined state\n");
885 return; 904 return;
886 } 905 }
887 906
@@ -1018,7 +1037,7 @@ static const struct net_device_ops at91_netdev_ops = {
1018 .ndo_start_xmit = at91_start_xmit, 1037 .ndo_start_xmit = at91_start_xmit,
1019}; 1038};
1020 1039
1021static int __init at91_can_probe(struct platform_device *pdev) 1040static int __devinit at91_can_probe(struct platform_device *pdev)
1022{ 1041{
1023 struct net_device *dev; 1042 struct net_device *dev;
1024 struct at91_priv *priv; 1043 struct at91_priv *priv;
@@ -1067,8 +1086,8 @@ static int __init at91_can_probe(struct platform_device *pdev)
1067 priv = netdev_priv(dev); 1086 priv = netdev_priv(dev);
1068 priv->can.clock.freq = clk_get_rate(clk); 1087 priv->can.clock.freq = clk_get_rate(clk);
1069 priv->can.bittiming_const = &at91_bittiming_const; 1088 priv->can.bittiming_const = &at91_bittiming_const;
1070 priv->can.do_set_bittiming = at91_set_bittiming;
1071 priv->can.do_set_mode = at91_set_mode; 1089 priv->can.do_set_mode = at91_set_mode;
1090 priv->can.do_get_berr_counter = at91_get_berr_counter;
1072 priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES; 1091 priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES;
1073 priv->reg_base = addr; 1092 priv->reg_base = addr;
1074 priv->dev = dev; 1093 priv->dev = dev;
@@ -1092,7 +1111,7 @@ static int __init at91_can_probe(struct platform_device *pdev)
1092 return 0; 1111 return 0;
1093 1112
1094 exit_free: 1113 exit_free:
1095 free_netdev(dev); 1114 free_candev(dev);
1096 exit_iounmap: 1115 exit_iounmap:
1097 iounmap(addr); 1116 iounmap(addr);
1098 exit_release: 1117 exit_release:
@@ -1113,8 +1132,6 @@ static int __devexit at91_can_remove(struct platform_device *pdev)
1113 1132
1114 platform_set_drvdata(pdev, NULL); 1133 platform_set_drvdata(pdev, NULL);
1115 1134
1116 free_netdev(dev);
1117
1118 iounmap(priv->reg_base); 1135 iounmap(priv->reg_base);
1119 1136
1120 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1137 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1122,6 +1139,8 @@ static int __devexit at91_can_remove(struct platform_device *pdev)
1122 1139
1123 clk_put(priv->clk); 1140 clk_put(priv->clk);
1124 1141
1142 free_candev(dev);
1143
1125 return 0; 1144 return 0;
1126} 1145}
1127 1146
@@ -1129,21 +1148,19 @@ static struct platform_driver at91_can_driver = {
1129 .probe = at91_can_probe, 1148 .probe = at91_can_probe,
1130 .remove = __devexit_p(at91_can_remove), 1149 .remove = __devexit_p(at91_can_remove),
1131 .driver = { 1150 .driver = {
1132 .name = DRV_NAME, 1151 .name = KBUILD_MODNAME,
1133 .owner = THIS_MODULE, 1152 .owner = THIS_MODULE,
1134 }, 1153 },
1135}; 1154};
1136 1155
1137static int __init at91_can_module_init(void) 1156static int __init at91_can_module_init(void)
1138{ 1157{
1139 printk(KERN_INFO "%s netdevice driver\n", DRV_NAME);
1140 return platform_driver_register(&at91_can_driver); 1158 return platform_driver_register(&at91_can_driver);
1141} 1159}
1142 1160
1143static void __exit at91_can_module_exit(void) 1161static void __exit at91_can_module_exit(void)
1144{ 1162{
1145 platform_driver_unregister(&at91_can_driver); 1163 platform_driver_unregister(&at91_can_driver);
1146 printk(KERN_INFO "%s: driver removed\n", DRV_NAME);
1147} 1164}
1148 1165
1149module_init(at91_can_module_init); 1166module_init(at91_can_module_init);
@@ -1151,4 +1168,4 @@ module_exit(at91_can_module_exit);
1151 1168
1152MODULE_AUTHOR("Marc Kleine-Budde <mkl@pengutronix.de>"); 1169MODULE_AUTHOR("Marc Kleine-Budde <mkl@pengutronix.de>");
1153MODULE_LICENSE("GPL v2"); 1170MODULE_LICENSE("GPL v2");
1154MODULE_DESCRIPTION(DRV_NAME " CAN netdevice driver"); 1171MODULE_DESCRIPTION(KBUILD_MODNAME " CAN netdevice driver");
diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index ef443a090ba7..d4990568baee 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -992,7 +992,6 @@ static int __devexit flexcan_remove(struct platform_device *pdev)
992 992
993 unregister_flexcandev(dev); 993 unregister_flexcandev(dev);
994 platform_set_drvdata(pdev, NULL); 994 platform_set_drvdata(pdev, NULL);
995 free_candev(dev);
996 iounmap(priv->base); 995 iounmap(priv->base);
997 996
998 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 997 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1000,6 +999,8 @@ static int __devexit flexcan_remove(struct platform_device *pdev)
1000 999
1001 clk_put(priv->clk); 1000 clk_put(priv->clk);
1002 1001
1002 free_candev(dev);
1003
1003 return 0; 1004 return 0;
1004} 1005}
1005 1006
diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index 6aadc3e32bd5..7ab534aee452 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -169,6 +169,7 @@
169# define RXBSIDH_SHIFT 3 169# define RXBSIDH_SHIFT 3
170#define RXBSIDL(n) (((n) * 0x10) + 0x60 + RXBSIDL_OFF) 170#define RXBSIDL(n) (((n) * 0x10) + 0x60 + RXBSIDL_OFF)
171# define RXBSIDL_IDE 0x08 171# define RXBSIDL_IDE 0x08
172# define RXBSIDL_SRR 0x10
172# define RXBSIDL_EID 3 173# define RXBSIDL_EID 3
173# define RXBSIDL_SHIFT 5 174# define RXBSIDL_SHIFT 5
174#define RXBEID8(n) (((n) * 0x10) + 0x60 + RXBEID8_OFF) 175#define RXBEID8(n) (((n) * 0x10) + 0x60 + RXBEID8_OFF)
@@ -475,6 +476,8 @@ static void mcp251x_hw_rx(struct spi_device *spi, int buf_idx)
475 frame->can_id = 476 frame->can_id =
476 (buf[RXBSIDH_OFF] << RXBSIDH_SHIFT) | 477 (buf[RXBSIDH_OFF] << RXBSIDH_SHIFT) |
477 (buf[RXBSIDL_OFF] >> RXBSIDL_SHIFT); 478 (buf[RXBSIDL_OFF] >> RXBSIDL_SHIFT);
479 if (buf[RXBSIDL_OFF] & RXBSIDL_SRR)
480 frame->can_id |= CAN_RTR_FLAG;
478 } 481 }
479 /* Data length */ 482 /* Data length */
480 frame->can_dlc = get_can_dlc(buf[RXBDLC_OFF] & RXBDLC_LEN_MASK); 483 frame->can_dlc = get_can_dlc(buf[RXBDLC_OFF] & RXBDLC_LEN_MASK);
diff --git a/drivers/net/can/pch_can.c b/drivers/net/can/pch_can.c
new file mode 100644
index 000000000000..55ec324caaf4
--- /dev/null
+++ b/drivers/net/can/pch_can.c
@@ -0,0 +1,1463 @@
1/*
2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
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; version 2 of the License.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#include <linux/interrupt.h>
20#include <linux/delay.h>
21#include <linux/io.h>
22#include <linux/module.h>
23#include <linux/sched.h>
24#include <linux/pci.h>
25#include <linux/init.h>
26#include <linux/kernel.h>
27#include <linux/types.h>
28#include <linux/errno.h>
29#include <linux/netdevice.h>
30#include <linux/skbuff.h>
31#include <linux/can.h>
32#include <linux/can/dev.h>
33#include <linux/can/error.h>
34
35#define MAX_MSG_OBJ 32
36#define MSG_OBJ_RX 0 /* The receive message object flag. */
37#define MSG_OBJ_TX 1 /* The transmit message object flag. */
38
39#define ENABLE 1 /* The enable flag */
40#define DISABLE 0 /* The disable flag */
41#define CAN_CTRL_INIT 0x0001 /* The INIT bit of CANCONT register. */
42#define CAN_CTRL_IE 0x0002 /* The IE bit of CAN control register */
43#define CAN_CTRL_IE_SIE_EIE 0x000e
44#define CAN_CTRL_CCE 0x0040
45#define CAN_CTRL_OPT 0x0080 /* The OPT bit of CANCONT register. */
46#define CAN_OPT_SILENT 0x0008 /* The Silent bit of CANOPT reg. */
47#define CAN_OPT_LBACK 0x0010 /* The LoopBack bit of CANOPT reg. */
48#define CAN_CMASK_RX_TX_SET 0x00f3
49#define CAN_CMASK_RX_TX_GET 0x0073
50#define CAN_CMASK_ALL 0xff
51#define CAN_CMASK_RDWR 0x80
52#define CAN_CMASK_ARB 0x20
53#define CAN_CMASK_CTRL 0x10
54#define CAN_CMASK_MASK 0x40
55#define CAN_CMASK_NEWDAT 0x04
56#define CAN_CMASK_CLRINTPND 0x08
57
58#define CAN_IF_MCONT_NEWDAT 0x8000
59#define CAN_IF_MCONT_INTPND 0x2000
60#define CAN_IF_MCONT_UMASK 0x1000
61#define CAN_IF_MCONT_TXIE 0x0800
62#define CAN_IF_MCONT_RXIE 0x0400
63#define CAN_IF_MCONT_RMTEN 0x0200
64#define CAN_IF_MCONT_TXRQXT 0x0100
65#define CAN_IF_MCONT_EOB 0x0080
66#define CAN_IF_MCONT_DLC 0x000f
67#define CAN_IF_MCONT_MSGLOST 0x4000
68#define CAN_MASK2_MDIR_MXTD 0xc000
69#define CAN_ID2_DIR 0x2000
70#define CAN_ID_MSGVAL 0x8000
71
72#define CAN_STATUS_INT 0x8000
73#define CAN_IF_CREQ_BUSY 0x8000
74#define CAN_ID2_XTD 0x4000
75
76#define CAN_REC 0x00007f00
77#define CAN_TEC 0x000000ff
78
79#define PCH_RX_OK 0x00000010
80#define PCH_TX_OK 0x00000008
81#define PCH_BUS_OFF 0x00000080
82#define PCH_EWARN 0x00000040
83#define PCH_EPASSIV 0x00000020
84#define PCH_LEC0 0x00000001
85#define PCH_LEC1 0x00000002
86#define PCH_LEC2 0x00000004
87#define PCH_LEC_ALL (PCH_LEC0 | PCH_LEC1 | PCH_LEC2)
88#define PCH_STUF_ERR PCH_LEC0
89#define PCH_FORM_ERR PCH_LEC1
90#define PCH_ACK_ERR (PCH_LEC0 | PCH_LEC1)
91#define PCH_BIT1_ERR PCH_LEC2
92#define PCH_BIT0_ERR (PCH_LEC0 | PCH_LEC2)
93#define PCH_CRC_ERR (PCH_LEC1 | PCH_LEC2)
94
95/* bit position of certain controller bits. */
96#define BIT_BITT_BRP 0
97#define BIT_BITT_SJW 6
98#define BIT_BITT_TSEG1 8
99#define BIT_BITT_TSEG2 12
100#define BIT_IF1_MCONT_RXIE 10
101#define BIT_IF2_MCONT_TXIE 11
102#define BIT_BRPE_BRPE 6
103#define BIT_ES_TXERRCNT 0
104#define BIT_ES_RXERRCNT 8
105#define MSK_BITT_BRP 0x3f
106#define MSK_BITT_SJW 0xc0
107#define MSK_BITT_TSEG1 0xf00
108#define MSK_BITT_TSEG2 0x7000
109#define MSK_BRPE_BRPE 0x3c0
110#define MSK_BRPE_GET 0x0f
111#define MSK_CTRL_IE_SIE_EIE 0x07
112#define MSK_MCONT_TXIE 0x08
113#define MSK_MCONT_RXIE 0x10
114#define PCH_CAN_NO_TX_BUFF 1
115#define COUNTER_LIMIT 10
116
117#define PCH_CAN_CLK 50000000 /* 50MHz */
118
119/* Define the number of message object.
120 * PCH CAN communications are done via Message RAM.
121 * The Message RAM consists of 32 message objects. */
122#define PCH_RX_OBJ_NUM 26 /* 1~ PCH_RX_OBJ_NUM is Rx*/
123#define PCH_TX_OBJ_NUM 6 /* PCH_RX_OBJ_NUM is RX ~ Tx*/
124#define PCH_OBJ_NUM (PCH_TX_OBJ_NUM + PCH_RX_OBJ_NUM)
125
126#define PCH_FIFO_THRESH 16
127
128enum pch_can_mode {
129 PCH_CAN_ENABLE,
130 PCH_CAN_DISABLE,
131 PCH_CAN_ALL,
132 PCH_CAN_NONE,
133 PCH_CAN_STOP,
134 PCH_CAN_RUN
135};
136
137struct pch_can_regs {
138 u32 cont;
139 u32 stat;
140 u32 errc;
141 u32 bitt;
142 u32 intr;
143 u32 opt;
144 u32 brpe;
145 u32 reserve1;
146 u32 if1_creq;
147 u32 if1_cmask;
148 u32 if1_mask1;
149 u32 if1_mask2;
150 u32 if1_id1;
151 u32 if1_id2;
152 u32 if1_mcont;
153 u32 if1_dataa1;
154 u32 if1_dataa2;
155 u32 if1_datab1;
156 u32 if1_datab2;
157 u32 reserve2;
158 u32 reserve3[12];
159 u32 if2_creq;
160 u32 if2_cmask;
161 u32 if2_mask1;
162 u32 if2_mask2;
163 u32 if2_id1;
164 u32 if2_id2;
165 u32 if2_mcont;
166 u32 if2_dataa1;
167 u32 if2_dataa2;
168 u32 if2_datab1;
169 u32 if2_datab2;
170 u32 reserve4;
171 u32 reserve5[20];
172 u32 treq1;
173 u32 treq2;
174 u32 reserve6[2];
175 u32 reserve7[56];
176 u32 reserve8[3];
177 u32 srst;
178};
179
180struct pch_can_priv {
181 struct can_priv can;
182 unsigned int can_num;
183 struct pci_dev *dev;
184 unsigned int tx_enable[MAX_MSG_OBJ];
185 unsigned int rx_enable[MAX_MSG_OBJ];
186 unsigned int rx_link[MAX_MSG_OBJ];
187 unsigned int int_enables;
188 unsigned int int_stat;
189 struct net_device *ndev;
190 spinlock_t msgif_reg_lock; /* Message Interface Registers Access Lock*/
191 unsigned int msg_obj[MAX_MSG_OBJ];
192 struct pch_can_regs __iomem *regs;
193 struct napi_struct napi;
194 unsigned int tx_obj; /* Point next Tx Obj index */
195 unsigned int use_msi;
196};
197
198static struct can_bittiming_const pch_can_bittiming_const = {
199 .name = KBUILD_MODNAME,
200 .tseg1_min = 1,
201 .tseg1_max = 16,
202 .tseg2_min = 1,
203 .tseg2_max = 8,
204 .sjw_max = 4,
205 .brp_min = 1,
206 .brp_max = 1024, /* 6bit + extended 4bit */
207 .brp_inc = 1,
208};
209
210static DEFINE_PCI_DEVICE_TABLE(pch_pci_tbl) = {
211 {PCI_VENDOR_ID_INTEL, 0x8818, PCI_ANY_ID, PCI_ANY_ID,},
212 {0,}
213};
214MODULE_DEVICE_TABLE(pci, pch_pci_tbl);
215
216static inline void pch_can_bit_set(u32 *addr, u32 mask)
217{
218 iowrite32(ioread32(addr) | mask, addr);
219}
220
221static inline void pch_can_bit_clear(u32 *addr, u32 mask)
222{
223 iowrite32(ioread32(addr) & ~mask, addr);
224}
225
226static void pch_can_set_run_mode(struct pch_can_priv *priv,
227 enum pch_can_mode mode)
228{
229 switch (mode) {
230 case PCH_CAN_RUN:
231 pch_can_bit_clear(&priv->regs->cont, CAN_CTRL_INIT);
232 break;
233
234 case PCH_CAN_STOP:
235 pch_can_bit_set(&priv->regs->cont, CAN_CTRL_INIT);
236 break;
237
238 default:
239 dev_err(&priv->ndev->dev, "%s -> Invalid Mode.\n", __func__);
240 break;
241 }
242}
243
244static void pch_can_set_optmode(struct pch_can_priv *priv)
245{
246 u32 reg_val = ioread32(&priv->regs->opt);
247
248 if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
249 reg_val |= CAN_OPT_SILENT;
250
251 if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)
252 reg_val |= CAN_OPT_LBACK;
253
254 pch_can_bit_set(&priv->regs->cont, CAN_CTRL_OPT);
255 iowrite32(reg_val, &priv->regs->opt);
256}
257
258static void pch_can_set_int_custom(struct pch_can_priv *priv)
259{
260 /* Clearing the IE, SIE and EIE bits of Can control register. */
261 pch_can_bit_clear(&priv->regs->cont, CAN_CTRL_IE_SIE_EIE);
262
263 /* Appropriately setting them. */
264 pch_can_bit_set(&priv->regs->cont,
265 ((priv->int_enables & MSK_CTRL_IE_SIE_EIE) << 1));
266}
267
268/* This function retrieves interrupt enabled for the CAN device. */
269static void pch_can_get_int_enables(struct pch_can_priv *priv, u32 *enables)
270{
271 /* Obtaining the status of IE, SIE and EIE interrupt bits. */
272 *enables = ((ioread32(&priv->regs->cont) & CAN_CTRL_IE_SIE_EIE) >> 1);
273}
274
275static void pch_can_set_int_enables(struct pch_can_priv *priv,
276 enum pch_can_mode interrupt_no)
277{
278 switch (interrupt_no) {
279 case PCH_CAN_ENABLE:
280 pch_can_bit_set(&priv->regs->cont, CAN_CTRL_IE);
281 break;
282
283 case PCH_CAN_DISABLE:
284 pch_can_bit_clear(&priv->regs->cont, CAN_CTRL_IE);
285 break;
286
287 case PCH_CAN_ALL:
288 pch_can_bit_set(&priv->regs->cont, CAN_CTRL_IE_SIE_EIE);
289 break;
290
291 case PCH_CAN_NONE:
292 pch_can_bit_clear(&priv->regs->cont, CAN_CTRL_IE_SIE_EIE);
293 break;
294
295 default:
296 dev_err(&priv->ndev->dev, "Invalid interrupt number.\n");
297 break;
298 }
299}
300
301static void pch_can_check_if_busy(u32 __iomem *creq_addr, u32 num)
302{
303 u32 counter = COUNTER_LIMIT;
304 u32 ifx_creq;
305
306 iowrite32(num, creq_addr);
307 while (counter) {
308 ifx_creq = ioread32(creq_addr) & CAN_IF_CREQ_BUSY;
309 if (!ifx_creq)
310 break;
311 counter--;
312 udelay(1);
313 }
314 if (!counter)
315 pr_err("%s:IF1 BUSY Flag is set forever.\n", __func__);
316}
317
318static void pch_can_set_rx_enable(struct pch_can_priv *priv, u32 buff_num,
319 u32 set)
320{
321 unsigned long flags;
322
323 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
324 /* Reading the receive buffer data from RAM to Interface1 registers */
325 iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
326 pch_can_check_if_busy(&priv->regs->if1_creq, buff_num);
327
328 /* Setting the IF1MASK1 register to access MsgVal and RxIE bits */
329 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_ARB | CAN_CMASK_CTRL,
330 &priv->regs->if1_cmask);
331
332 if (set == ENABLE) {
333 /* Setting the MsgVal and RxIE bits */
334 pch_can_bit_set(&priv->regs->if1_mcont, CAN_IF_MCONT_RXIE);
335 pch_can_bit_set(&priv->regs->if1_id2, CAN_ID_MSGVAL);
336
337 } else if (set == DISABLE) {
338 /* Resetting the MsgVal and RxIE bits */
339 pch_can_bit_clear(&priv->regs->if1_mcont, CAN_IF_MCONT_RXIE);
340 pch_can_bit_clear(&priv->regs->if1_id2, CAN_ID_MSGVAL);
341 }
342
343 pch_can_check_if_busy(&priv->regs->if1_creq, buff_num);
344 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
345}
346
347static void pch_can_rx_enable_all(struct pch_can_priv *priv)
348{
349 int i;
350
351 /* Traversing to obtain the object configured as receivers. */
352 for (i = 0; i < PCH_OBJ_NUM; i++) {
353 if (priv->msg_obj[i] == MSG_OBJ_RX)
354 pch_can_set_rx_enable(priv, i + 1, ENABLE);
355 }
356}
357
358static void pch_can_rx_disable_all(struct pch_can_priv *priv)
359{
360 int i;
361
362 /* Traversing to obtain the object configured as receivers. */
363 for (i = 0; i < PCH_OBJ_NUM; i++) {
364 if (priv->msg_obj[i] == MSG_OBJ_RX)
365 pch_can_set_rx_enable(priv, i + 1, DISABLE);
366 }
367}
368
369static void pch_can_set_tx_enable(struct pch_can_priv *priv, u32 buff_num,
370 u32 set)
371{
372 unsigned long flags;
373
374 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
375 /* Reading the Msg buffer from Message RAM to Interface2 registers. */
376 iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
377 pch_can_check_if_busy(&priv->regs->if2_creq, buff_num);
378
379 /* Setting the IF2CMASK register for accessing the
380 MsgVal and TxIE bits */
381 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_ARB | CAN_CMASK_CTRL,
382 &priv->regs->if2_cmask);
383
384 if (set == ENABLE) {
385 /* Setting the MsgVal and TxIE bits */
386 pch_can_bit_set(&priv->regs->if2_mcont, CAN_IF_MCONT_TXIE);
387 pch_can_bit_set(&priv->regs->if2_id2, CAN_ID_MSGVAL);
388 } else if (set == DISABLE) {
389 /* Resetting the MsgVal and TxIE bits. */
390 pch_can_bit_clear(&priv->regs->if2_mcont, CAN_IF_MCONT_TXIE);
391 pch_can_bit_clear(&priv->regs->if2_id2, CAN_ID_MSGVAL);
392 }
393
394 pch_can_check_if_busy(&priv->regs->if2_creq, buff_num);
395 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
396}
397
398static void pch_can_tx_enable_all(struct pch_can_priv *priv)
399{
400 int i;
401
402 /* Traversing to obtain the object configured as transmit object. */
403 for (i = 0; i < PCH_OBJ_NUM; i++) {
404 if (priv->msg_obj[i] == MSG_OBJ_TX)
405 pch_can_set_tx_enable(priv, i + 1, ENABLE);
406 }
407}
408
409static void pch_can_tx_disable_all(struct pch_can_priv *priv)
410{
411 int i;
412
413 /* Traversing to obtain the object configured as transmit object. */
414 for (i = 0; i < PCH_OBJ_NUM; i++) {
415 if (priv->msg_obj[i] == MSG_OBJ_TX)
416 pch_can_set_tx_enable(priv, i + 1, DISABLE);
417 }
418}
419
420static void pch_can_get_rx_enable(struct pch_can_priv *priv, u32 buff_num,
421 u32 *enable)
422{
423 unsigned long flags;
424
425 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
426 iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
427 pch_can_check_if_busy(&priv->regs->if1_creq, buff_num);
428
429 if (((ioread32(&priv->regs->if1_id2)) & CAN_ID_MSGVAL) &&
430 ((ioread32(&priv->regs->if1_mcont)) &
431 CAN_IF_MCONT_RXIE))
432 *enable = ENABLE;
433 else
434 *enable = DISABLE;
435 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
436}
437
438static void pch_can_get_tx_enable(struct pch_can_priv *priv, u32 buff_num,
439 u32 *enable)
440{
441 unsigned long flags;
442
443 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
444 iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
445 pch_can_check_if_busy(&priv->regs->if2_creq, buff_num);
446
447 if (((ioread32(&priv->regs->if2_id2)) & CAN_ID_MSGVAL) &&
448 ((ioread32(&priv->regs->if2_mcont)) &
449 CAN_IF_MCONT_TXIE)) {
450 *enable = ENABLE;
451 } else {
452 *enable = DISABLE;
453 }
454 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
455}
456
457static int pch_can_int_pending(struct pch_can_priv *priv)
458{
459 return ioread32(&priv->regs->intr) & 0xffff;
460}
461
462static void pch_can_set_rx_buffer_link(struct pch_can_priv *priv,
463 u32 buffer_num, u32 set)
464{
465 unsigned long flags;
466
467 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
468 iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
469 pch_can_check_if_busy(&priv->regs->if1_creq, buffer_num);
470 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_CTRL, &priv->regs->if1_cmask);
471 if (set == ENABLE)
472 pch_can_bit_clear(&priv->regs->if1_mcont, CAN_IF_MCONT_EOB);
473 else
474 pch_can_bit_set(&priv->regs->if1_mcont, CAN_IF_MCONT_EOB);
475
476 pch_can_check_if_busy(&priv->regs->if1_creq, buffer_num);
477 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
478}
479
480static void pch_can_get_rx_buffer_link(struct pch_can_priv *priv,
481 u32 buffer_num, u32 *link)
482{
483 unsigned long flags;
484
485 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
486 iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
487 pch_can_check_if_busy(&priv->regs->if1_creq, buffer_num);
488
489 if (ioread32(&priv->regs->if1_mcont) & CAN_IF_MCONT_EOB)
490 *link = DISABLE;
491 else
492 *link = ENABLE;
493 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
494}
495
496static void pch_can_clear_buffers(struct pch_can_priv *priv)
497{
498 int i;
499
500 for (i = 0; i < PCH_RX_OBJ_NUM; i++) {
501 iowrite32(CAN_CMASK_RX_TX_SET, &priv->regs->if1_cmask);
502 iowrite32(0xffff, &priv->regs->if1_mask1);
503 iowrite32(0xffff, &priv->regs->if1_mask2);
504 iowrite32(0x0, &priv->regs->if1_id1);
505 iowrite32(0x0, &priv->regs->if1_id2);
506 iowrite32(0x0, &priv->regs->if1_mcont);
507 iowrite32(0x0, &priv->regs->if1_dataa1);
508 iowrite32(0x0, &priv->regs->if1_dataa2);
509 iowrite32(0x0, &priv->regs->if1_datab1);
510 iowrite32(0x0, &priv->regs->if1_datab2);
511 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_MASK |
512 CAN_CMASK_ARB | CAN_CMASK_CTRL,
513 &priv->regs->if1_cmask);
514 pch_can_check_if_busy(&priv->regs->if1_creq, i+1);
515 }
516
517 for (i = i; i < PCH_OBJ_NUM; i++) {
518 iowrite32(CAN_CMASK_RX_TX_SET, &priv->regs->if2_cmask);
519 iowrite32(0xffff, &priv->regs->if2_mask1);
520 iowrite32(0xffff, &priv->regs->if2_mask2);
521 iowrite32(0x0, &priv->regs->if2_id1);
522 iowrite32(0x0, &priv->regs->if2_id2);
523 iowrite32(0x0, &priv->regs->if2_mcont);
524 iowrite32(0x0, &priv->regs->if2_dataa1);
525 iowrite32(0x0, &priv->regs->if2_dataa2);
526 iowrite32(0x0, &priv->regs->if2_datab1);
527 iowrite32(0x0, &priv->regs->if2_datab2);
528 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_MASK |
529 CAN_CMASK_ARB | CAN_CMASK_CTRL,
530 &priv->regs->if2_cmask);
531 pch_can_check_if_busy(&priv->regs->if2_creq, i+1);
532 }
533}
534
535static void pch_can_config_rx_tx_buffers(struct pch_can_priv *priv)
536{
537 int i;
538 unsigned long flags;
539
540 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
541
542 for (i = 0; i < PCH_OBJ_NUM; i++) {
543 if (priv->msg_obj[i] == MSG_OBJ_RX) {
544 iowrite32(CAN_CMASK_RX_TX_GET,
545 &priv->regs->if1_cmask);
546 pch_can_check_if_busy(&priv->regs->if1_creq, i+1);
547
548 iowrite32(0x0, &priv->regs->if1_id1);
549 iowrite32(0x0, &priv->regs->if1_id2);
550
551 pch_can_bit_set(&priv->regs->if1_mcont,
552 CAN_IF_MCONT_UMASK);
553
554 /* Set FIFO mode set to 0 except last Rx Obj*/
555 pch_can_bit_clear(&priv->regs->if1_mcont,
556 CAN_IF_MCONT_EOB);
557 /* In case FIFO mode, Last EoB of Rx Obj must be 1 */
558 if (i == (PCH_RX_OBJ_NUM - 1))
559 pch_can_bit_set(&priv->regs->if1_mcont,
560 CAN_IF_MCONT_EOB);
561
562 iowrite32(0, &priv->regs->if1_mask1);
563 pch_can_bit_clear(&priv->regs->if1_mask2,
564 0x1fff | CAN_MASK2_MDIR_MXTD);
565
566 /* Setting CMASK for writing */
567 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_MASK |
568 CAN_CMASK_ARB | CAN_CMASK_CTRL,
569 &priv->regs->if1_cmask);
570
571 pch_can_check_if_busy(&priv->regs->if1_creq, i+1);
572 } else if (priv->msg_obj[i] == MSG_OBJ_TX) {
573 iowrite32(CAN_CMASK_RX_TX_GET,
574 &priv->regs->if2_cmask);
575 pch_can_check_if_busy(&priv->regs->if2_creq, i+1);
576
577 /* Resetting DIR bit for reception */
578 iowrite32(0x0, &priv->regs->if2_id1);
579 iowrite32(0x0, &priv->regs->if2_id2);
580 pch_can_bit_set(&priv->regs->if2_id2, CAN_ID2_DIR);
581
582 /* Setting EOB bit for transmitter */
583 iowrite32(CAN_IF_MCONT_EOB, &priv->regs->if2_mcont);
584
585 pch_can_bit_set(&priv->regs->if2_mcont,
586 CAN_IF_MCONT_UMASK);
587
588 iowrite32(0, &priv->regs->if2_mask1);
589 pch_can_bit_clear(&priv->regs->if2_mask2, 0x1fff);
590
591 /* Setting CMASK for writing */
592 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_MASK |
593 CAN_CMASK_ARB | CAN_CMASK_CTRL,
594 &priv->regs->if2_cmask);
595
596 pch_can_check_if_busy(&priv->regs->if2_creq, i+1);
597 }
598 }
599 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
600}
601
602static void pch_can_init(struct pch_can_priv *priv)
603{
604 /* Stopping the Can device. */
605 pch_can_set_run_mode(priv, PCH_CAN_STOP);
606
607 /* Clearing all the message object buffers. */
608 pch_can_clear_buffers(priv);
609
610 /* Configuring the respective message object as either rx/tx object. */
611 pch_can_config_rx_tx_buffers(priv);
612
613 /* Enabling the interrupts. */
614 pch_can_set_int_enables(priv, PCH_CAN_ALL);
615}
616
617static void pch_can_release(struct pch_can_priv *priv)
618{
619 /* Stooping the CAN device. */
620 pch_can_set_run_mode(priv, PCH_CAN_STOP);
621
622 /* Disabling the interrupts. */
623 pch_can_set_int_enables(priv, PCH_CAN_NONE);
624
625 /* Disabling all the receive object. */
626 pch_can_rx_disable_all(priv);
627
628 /* Disabling all the transmit object. */
629 pch_can_tx_disable_all(priv);
630}
631
632/* This function clears interrupt(s) from the CAN device. */
633static void pch_can_int_clr(struct pch_can_priv *priv, u32 mask)
634{
635 if (mask == CAN_STATUS_INT) {
636 ioread32(&priv->regs->stat);
637 return;
638 }
639
640 /* Clear interrupt for transmit object */
641 if (priv->msg_obj[mask - 1] == MSG_OBJ_TX) {
642 /* Setting CMASK for clearing interrupts for
643 frame transmission. */
644 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_CTRL | CAN_CMASK_ARB,
645 &priv->regs->if2_cmask);
646
647 /* Resetting the ID registers. */
648 pch_can_bit_set(&priv->regs->if2_id2,
649 CAN_ID2_DIR | (0x7ff << 2));
650 iowrite32(0x0, &priv->regs->if2_id1);
651
652 /* Claring NewDat, TxRqst & IntPnd */
653 pch_can_bit_clear(&priv->regs->if2_mcont,
654 CAN_IF_MCONT_NEWDAT | CAN_IF_MCONT_INTPND |
655 CAN_IF_MCONT_TXRQXT);
656 pch_can_check_if_busy(&priv->regs->if2_creq, mask);
657 } else if (priv->msg_obj[mask - 1] == MSG_OBJ_RX) {
658 /* Setting CMASK for clearing the reception interrupts. */
659 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_CTRL | CAN_CMASK_ARB,
660 &priv->regs->if1_cmask);
661
662 /* Clearing the Dir bit. */
663 pch_can_bit_clear(&priv->regs->if1_id2, CAN_ID2_DIR);
664
665 /* Clearing NewDat & IntPnd */
666 pch_can_bit_clear(&priv->regs->if1_mcont,
667 CAN_IF_MCONT_NEWDAT | CAN_IF_MCONT_INTPND);
668
669 pch_can_check_if_busy(&priv->regs->if1_creq, mask);
670 }
671}
672
673static int pch_can_get_buffer_status(struct pch_can_priv *priv)
674{
675 return (ioread32(&priv->regs->treq1) & 0xffff) |
676 ((ioread32(&priv->regs->treq2) & 0xffff) << 16);
677}
678
679static void pch_can_reset(struct pch_can_priv *priv)
680{
681 /* write to sw reset register */
682 iowrite32(1, &priv->regs->srst);
683 iowrite32(0, &priv->regs->srst);
684}
685
686static void pch_can_error(struct net_device *ndev, u32 status)
687{
688 struct sk_buff *skb;
689 struct pch_can_priv *priv = netdev_priv(ndev);
690 struct can_frame *cf;
691 u32 errc;
692 struct net_device_stats *stats = &(priv->ndev->stats);
693 enum can_state state = priv->can.state;
694
695 skb = alloc_can_err_skb(ndev, &cf);
696 if (!skb)
697 return;
698
699 if (status & PCH_BUS_OFF) {
700 pch_can_tx_disable_all(priv);
701 pch_can_rx_disable_all(priv);
702 state = CAN_STATE_BUS_OFF;
703 cf->can_id |= CAN_ERR_BUSOFF;
704 can_bus_off(ndev);
705 pch_can_set_run_mode(priv, PCH_CAN_RUN);
706 dev_err(&ndev->dev, "%s -> Bus Off occurres.\n", __func__);
707 }
708
709 /* Warning interrupt. */
710 if (status & PCH_EWARN) {
711 state = CAN_STATE_ERROR_WARNING;
712 priv->can.can_stats.error_warning++;
713 cf->can_id |= CAN_ERR_CRTL;
714 errc = ioread32(&priv->regs->errc);
715 if (((errc & CAN_REC) >> 8) > 96)
716 cf->data[1] |= CAN_ERR_CRTL_RX_WARNING;
717 if ((errc & CAN_TEC) > 96)
718 cf->data[1] |= CAN_ERR_CRTL_TX_WARNING;
719 dev_warn(&ndev->dev,
720 "%s -> Error Counter is more than 96.\n", __func__);
721 }
722 /* Error passive interrupt. */
723 if (status & PCH_EPASSIV) {
724 priv->can.can_stats.error_passive++;
725 state = CAN_STATE_ERROR_PASSIVE;
726 cf->can_id |= CAN_ERR_CRTL;
727 errc = ioread32(&priv->regs->errc);
728 if (((errc & CAN_REC) >> 8) > 127)
729 cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
730 if ((errc & CAN_TEC) > 127)
731 cf->data[1] |= CAN_ERR_CRTL_TX_PASSIVE;
732 dev_err(&ndev->dev,
733 "%s -> CAN controller is ERROR PASSIVE .\n", __func__);
734 }
735
736 if (status & PCH_LEC_ALL) {
737 priv->can.can_stats.bus_error++;
738 stats->rx_errors++;
739 switch (status & PCH_LEC_ALL) {
740 case PCH_STUF_ERR:
741 cf->data[2] |= CAN_ERR_PROT_STUFF;
742 break;
743 case PCH_FORM_ERR:
744 cf->data[2] |= CAN_ERR_PROT_FORM;
745 break;
746 case PCH_ACK_ERR:
747 cf->data[2] |= CAN_ERR_PROT_LOC_ACK |
748 CAN_ERR_PROT_LOC_ACK_DEL;
749 break;
750 case PCH_BIT1_ERR:
751 case PCH_BIT0_ERR:
752 cf->data[2] |= CAN_ERR_PROT_BIT;
753 break;
754 case PCH_CRC_ERR:
755 cf->data[2] |= CAN_ERR_PROT_LOC_CRC_SEQ |
756 CAN_ERR_PROT_LOC_CRC_DEL;
757 break;
758 default:
759 iowrite32(status | PCH_LEC_ALL, &priv->regs->stat);
760 break;
761 }
762
763 }
764
765 priv->can.state = state;
766 netif_rx(skb);
767
768 stats->rx_packets++;
769 stats->rx_bytes += cf->can_dlc;
770}
771
772static irqreturn_t pch_can_interrupt(int irq, void *dev_id)
773{
774 struct net_device *ndev = (struct net_device *)dev_id;
775 struct pch_can_priv *priv = netdev_priv(ndev);
776
777 pch_can_set_int_enables(priv, PCH_CAN_NONE);
778
779 napi_schedule(&priv->napi);
780
781 return IRQ_HANDLED;
782}
783
784static int pch_can_rx_normal(struct net_device *ndev, u32 int_stat)
785{
786 u32 reg;
787 canid_t id;
788 u32 ide;
789 u32 rtr;
790 int i, j, k;
791 int rcv_pkts = 0;
792 struct sk_buff *skb;
793 struct can_frame *cf;
794 struct pch_can_priv *priv = netdev_priv(ndev);
795 struct net_device_stats *stats = &(priv->ndev->stats);
796
797 /* Reading the messsage object from the Message RAM */
798 iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
799 pch_can_check_if_busy(&priv->regs->if1_creq, int_stat);
800
801 /* Reading the MCONT register. */
802 reg = ioread32(&priv->regs->if1_mcont);
803 reg &= 0xffff;
804
805 for (k = int_stat; !(reg & CAN_IF_MCONT_EOB); k++) {
806 /* If MsgLost bit set. */
807 if (reg & CAN_IF_MCONT_MSGLOST) {
808 dev_err(&priv->ndev->dev, "Msg Obj is overwritten.\n");
809 pch_can_bit_clear(&priv->regs->if1_mcont,
810 CAN_IF_MCONT_MSGLOST);
811 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_CTRL,
812 &priv->regs->if1_cmask);
813 pch_can_check_if_busy(&priv->regs->if1_creq, k);
814
815 skb = alloc_can_err_skb(ndev, &cf);
816 if (!skb)
817 return -ENOMEM;
818
819 priv->can.can_stats.error_passive++;
820 priv->can.state = CAN_STATE_ERROR_PASSIVE;
821 cf->can_id |= CAN_ERR_CRTL;
822 cf->data[1] |= CAN_ERR_CRTL_RX_OVERFLOW;
823 cf->data[2] |= CAN_ERR_PROT_OVERLOAD;
824 stats->rx_packets++;
825 stats->rx_bytes += cf->can_dlc;
826
827 netif_receive_skb(skb);
828 rcv_pkts++;
829 goto RX_NEXT;
830 }
831 if (!(reg & CAN_IF_MCONT_NEWDAT))
832 goto RX_NEXT;
833
834 skb = alloc_can_skb(priv->ndev, &cf);
835 if (!skb)
836 return -ENOMEM;
837
838 /* Get Received data */
839 ide = ((ioread32(&priv->regs->if1_id2)) & CAN_ID2_XTD) >> 14;
840 if (ide) {
841 id = (ioread32(&priv->regs->if1_id1) & 0xffff);
842 id |= (((ioread32(&priv->regs->if1_id2)) &
843 0x1fff) << 16);
844 cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG;
845 } else {
846 id = (((ioread32(&priv->regs->if1_id2)) &
847 (CAN_SFF_MASK << 2)) >> 2);
848 cf->can_id = (id & CAN_SFF_MASK);
849 }
850
851 rtr = (ioread32(&priv->regs->if1_id2) & CAN_ID2_DIR);
852 if (rtr) {
853 cf->can_dlc = 0;
854 cf->can_id |= CAN_RTR_FLAG;
855 } else {
856 cf->can_dlc = ((ioread32(&priv->regs->if1_mcont)) &
857 0x0f);
858 }
859
860 for (i = 0, j = 0; i < cf->can_dlc; j++) {
861 reg = ioread32(&priv->regs->if1_dataa1 + j*4);
862 cf->data[i++] = cpu_to_le32(reg & 0xff);
863 if (i == cf->can_dlc)
864 break;
865 cf->data[i++] = cpu_to_le32((reg >> 8) & 0xff);
866 }
867
868 netif_receive_skb(skb);
869 rcv_pkts++;
870 stats->rx_packets++;
871 stats->rx_bytes += cf->can_dlc;
872
873 if (k < PCH_FIFO_THRESH) {
874 iowrite32(CAN_CMASK_RDWR | CAN_CMASK_CTRL |
875 CAN_CMASK_ARB, &priv->regs->if1_cmask);
876
877 /* Clearing the Dir bit. */
878 pch_can_bit_clear(&priv->regs->if1_id2, CAN_ID2_DIR);
879
880 /* Clearing NewDat & IntPnd */
881 pch_can_bit_clear(&priv->regs->if1_mcont,
882 CAN_IF_MCONT_INTPND);
883 pch_can_check_if_busy(&priv->regs->if1_creq, k);
884 } else if (k > PCH_FIFO_THRESH) {
885 pch_can_int_clr(priv, k);
886 } else if (k == PCH_FIFO_THRESH) {
887 int cnt;
888 for (cnt = 0; cnt < PCH_FIFO_THRESH; cnt++)
889 pch_can_int_clr(priv, cnt+1);
890 }
891RX_NEXT:
892 /* Reading the messsage object from the Message RAM */
893 iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
894 pch_can_check_if_busy(&priv->regs->if1_creq, k + 1);
895 reg = ioread32(&priv->regs->if1_mcont);
896 }
897
898 return rcv_pkts;
899}
900static int pch_can_rx_poll(struct napi_struct *napi, int quota)
901{
902 struct net_device *ndev = napi->dev;
903 struct pch_can_priv *priv = netdev_priv(ndev);
904 struct net_device_stats *stats = &(priv->ndev->stats);
905 u32 dlc;
906 u32 int_stat;
907 int rcv_pkts = 0;
908 u32 reg_stat;
909 unsigned long flags;
910
911 int_stat = pch_can_int_pending(priv);
912 if (!int_stat)
913 return 0;
914
915INT_STAT:
916 if (int_stat == CAN_STATUS_INT) {
917 reg_stat = ioread32(&priv->regs->stat);
918 if (reg_stat & (PCH_BUS_OFF | PCH_LEC_ALL)) {
919 if ((reg_stat & PCH_LEC_ALL) != PCH_LEC_ALL)
920 pch_can_error(ndev, reg_stat);
921 }
922
923 if (reg_stat & PCH_TX_OK) {
924 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
925 iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
926 pch_can_check_if_busy(&priv->regs->if2_creq,
927 ioread32(&priv->regs->intr));
928 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
929 pch_can_bit_clear(&priv->regs->stat, PCH_TX_OK);
930 }
931
932 if (reg_stat & PCH_RX_OK)
933 pch_can_bit_clear(&priv->regs->stat, PCH_RX_OK);
934
935 int_stat = pch_can_int_pending(priv);
936 if (int_stat == CAN_STATUS_INT)
937 goto INT_STAT;
938 }
939
940MSG_OBJ:
941 if ((int_stat >= 1) && (int_stat <= PCH_RX_OBJ_NUM)) {
942 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
943 rcv_pkts = pch_can_rx_normal(ndev, int_stat);
944 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
945 if (rcv_pkts < 0)
946 return 0;
947 } else if ((int_stat > PCH_RX_OBJ_NUM) && (int_stat <= PCH_OBJ_NUM)) {
948 if (priv->msg_obj[int_stat - 1] == MSG_OBJ_TX) {
949 /* Handle transmission interrupt */
950 can_get_echo_skb(ndev, int_stat - PCH_RX_OBJ_NUM - 1);
951 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
952 iowrite32(CAN_CMASK_RX_TX_GET | CAN_CMASK_CLRINTPND,
953 &priv->regs->if2_cmask);
954 dlc = ioread32(&priv->regs->if2_mcont) &
955 CAN_IF_MCONT_DLC;
956 pch_can_check_if_busy(&priv->regs->if2_creq, int_stat);
957 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
958 if (dlc > 8)
959 dlc = 8;
960 stats->tx_bytes += dlc;
961 stats->tx_packets++;
962 }
963 }
964
965 int_stat = pch_can_int_pending(priv);
966 if (int_stat == CAN_STATUS_INT)
967 goto INT_STAT;
968 else if (int_stat >= 1 && int_stat <= 32)
969 goto MSG_OBJ;
970
971 napi_complete(napi);
972 pch_can_set_int_enables(priv, PCH_CAN_ALL);
973
974 return rcv_pkts;
975}
976
977static int pch_set_bittiming(struct net_device *ndev)
978{
979 struct pch_can_priv *priv = netdev_priv(ndev);
980 const struct can_bittiming *bt = &priv->can.bittiming;
981 u32 canbit;
982 u32 bepe;
983 u32 brp;
984
985 /* Setting the CCE bit for accessing the Can Timing register. */
986 pch_can_bit_set(&priv->regs->cont, CAN_CTRL_CCE);
987
988 brp = (bt->tq) / (1000000000/PCH_CAN_CLK) - 1;
989 canbit = brp & MSK_BITT_BRP;
990 canbit |= (bt->sjw - 1) << BIT_BITT_SJW;
991 canbit |= (bt->phase_seg1 + bt->prop_seg - 1) << BIT_BITT_TSEG1;
992 canbit |= (bt->phase_seg2 - 1) << BIT_BITT_TSEG2;
993 bepe = (brp & MSK_BRPE_BRPE) >> BIT_BRPE_BRPE;
994 iowrite32(canbit, &priv->regs->bitt);
995 iowrite32(bepe, &priv->regs->brpe);
996 pch_can_bit_clear(&priv->regs->cont, CAN_CTRL_CCE);
997
998 return 0;
999}
1000
1001static void pch_can_start(struct net_device *ndev)
1002{
1003 struct pch_can_priv *priv = netdev_priv(ndev);
1004
1005 if (priv->can.state != CAN_STATE_STOPPED)
1006 pch_can_reset(priv);
1007
1008 pch_set_bittiming(ndev);
1009 pch_can_set_optmode(priv);
1010
1011 pch_can_tx_enable_all(priv);
1012 pch_can_rx_enable_all(priv);
1013
1014 /* Setting the CAN to run mode. */
1015 pch_can_set_run_mode(priv, PCH_CAN_RUN);
1016
1017 priv->can.state = CAN_STATE_ERROR_ACTIVE;
1018
1019 return;
1020}
1021
1022static int pch_can_do_set_mode(struct net_device *ndev, enum can_mode mode)
1023{
1024 int ret = 0;
1025
1026 switch (mode) {
1027 case CAN_MODE_START:
1028 pch_can_start(ndev);
1029 netif_wake_queue(ndev);
1030 break;
1031 default:
1032 ret = -EOPNOTSUPP;
1033 break;
1034 }
1035
1036 return ret;
1037}
1038
1039static int pch_can_open(struct net_device *ndev)
1040{
1041 struct pch_can_priv *priv = netdev_priv(ndev);
1042 int retval;
1043
1044 retval = pci_enable_msi(priv->dev);
1045 if (retval) {
1046 dev_info(&ndev->dev, "PCH CAN opened without MSI\n");
1047 priv->use_msi = 0;
1048 } else {
1049 dev_info(&ndev->dev, "PCH CAN opened with MSI\n");
1050 priv->use_msi = 1;
1051 }
1052
1053 /* Regsitering the interrupt. */
1054 retval = request_irq(priv->dev->irq, pch_can_interrupt, IRQF_SHARED,
1055 ndev->name, ndev);
1056 if (retval) {
1057 dev_err(&ndev->dev, "request_irq failed.\n");
1058 goto req_irq_err;
1059 }
1060
1061 /* Open common can device */
1062 retval = open_candev(ndev);
1063 if (retval) {
1064 dev_err(ndev->dev.parent, "open_candev() failed %d\n", retval);
1065 goto err_open_candev;
1066 }
1067
1068 pch_can_init(priv);
1069 pch_can_start(ndev);
1070 napi_enable(&priv->napi);
1071 netif_start_queue(ndev);
1072
1073 return 0;
1074
1075err_open_candev:
1076 free_irq(priv->dev->irq, ndev);
1077req_irq_err:
1078 if (priv->use_msi)
1079 pci_disable_msi(priv->dev);
1080
1081 pch_can_release(priv);
1082
1083 return retval;
1084}
1085
1086static int pch_close(struct net_device *ndev)
1087{
1088 struct pch_can_priv *priv = netdev_priv(ndev);
1089
1090 netif_stop_queue(ndev);
1091 napi_disable(&priv->napi);
1092 pch_can_release(priv);
1093 free_irq(priv->dev->irq, ndev);
1094 if (priv->use_msi)
1095 pci_disable_msi(priv->dev);
1096 close_candev(ndev);
1097 priv->can.state = CAN_STATE_STOPPED;
1098 return 0;
1099}
1100
1101static int pch_get_msg_obj_sts(struct net_device *ndev, u32 obj_id)
1102{
1103 u32 buffer_status = 0;
1104 struct pch_can_priv *priv = netdev_priv(ndev);
1105
1106 /* Getting the message object status. */
1107 buffer_status = (u32) pch_can_get_buffer_status(priv);
1108
1109 return buffer_status & obj_id;
1110}
1111
1112
1113static netdev_tx_t pch_xmit(struct sk_buff *skb, struct net_device *ndev)
1114{
1115 int i, j;
1116 unsigned long flags;
1117 struct pch_can_priv *priv = netdev_priv(ndev);
1118 struct can_frame *cf = (struct can_frame *)skb->data;
1119 int tx_buffer_avail = 0;
1120
1121 if (can_dropped_invalid_skb(ndev, skb))
1122 return NETDEV_TX_OK;
1123
1124 if (priv->tx_obj == (PCH_OBJ_NUM + 1)) { /* Point tail Obj */
1125 while (pch_get_msg_obj_sts(ndev, (((1 << PCH_TX_OBJ_NUM)-1) <<
1126 PCH_RX_OBJ_NUM)))
1127 udelay(500);
1128
1129 priv->tx_obj = PCH_RX_OBJ_NUM + 1; /* Point head of Tx Obj ID */
1130 tx_buffer_avail = priv->tx_obj; /* Point Tail of Tx Obj */
1131 } else {
1132 tx_buffer_avail = priv->tx_obj;
1133 }
1134 priv->tx_obj++;
1135
1136 /* Attaining the lock. */
1137 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
1138
1139 /* Reading the Msg Obj from the Msg RAM to the Interface register. */
1140 iowrite32(CAN_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
1141 pch_can_check_if_busy(&priv->regs->if2_creq, tx_buffer_avail);
1142
1143 /* Setting the CMASK register. */
1144 pch_can_bit_set(&priv->regs->if2_cmask, CAN_CMASK_ALL);
1145
1146 /* If ID extended is set. */
1147 pch_can_bit_clear(&priv->regs->if2_id1, 0xffff);
1148 pch_can_bit_clear(&priv->regs->if2_id2, 0x1fff | CAN_ID2_XTD);
1149 if (cf->can_id & CAN_EFF_FLAG) {
1150 pch_can_bit_set(&priv->regs->if2_id1, cf->can_id & 0xffff);
1151 pch_can_bit_set(&priv->regs->if2_id2,
1152 ((cf->can_id >> 16) & 0x1fff) | CAN_ID2_XTD);
1153 } else {
1154 pch_can_bit_set(&priv->regs->if2_id1, 0);
1155 pch_can_bit_set(&priv->regs->if2_id2,
1156 (cf->can_id & CAN_SFF_MASK) << 2);
1157 }
1158
1159 /* If remote frame has to be transmitted.. */
1160 if (cf->can_id & CAN_RTR_FLAG)
1161 pch_can_bit_clear(&priv->regs->if2_id2, CAN_ID2_DIR);
1162
1163 for (i = 0, j = 0; i < cf->can_dlc; j++) {
1164 iowrite32(le32_to_cpu(cf->data[i++]),
1165 (&priv->regs->if2_dataa1) + j*4);
1166 if (i == cf->can_dlc)
1167 break;
1168 iowrite32(le32_to_cpu(cf->data[i++] << 8),
1169 (&priv->regs->if2_dataa1) + j*4);
1170 }
1171
1172 can_put_echo_skb(skb, ndev, tx_buffer_avail - PCH_RX_OBJ_NUM - 1);
1173
1174 /* Updating the size of the data. */
1175 pch_can_bit_clear(&priv->regs->if2_mcont, 0x0f);
1176 pch_can_bit_set(&priv->regs->if2_mcont, cf->can_dlc);
1177
1178 /* Clearing IntPend, NewDat & TxRqst */
1179 pch_can_bit_clear(&priv->regs->if2_mcont,
1180 CAN_IF_MCONT_NEWDAT | CAN_IF_MCONT_INTPND |
1181 CAN_IF_MCONT_TXRQXT);
1182
1183 /* Setting NewDat, TxRqst bits */
1184 pch_can_bit_set(&priv->regs->if2_mcont,
1185 CAN_IF_MCONT_NEWDAT | CAN_IF_MCONT_TXRQXT);
1186
1187 pch_can_check_if_busy(&priv->regs->if2_creq, tx_buffer_avail);
1188
1189 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
1190
1191 return NETDEV_TX_OK;
1192}
1193
1194static const struct net_device_ops pch_can_netdev_ops = {
1195 .ndo_open = pch_can_open,
1196 .ndo_stop = pch_close,
1197 .ndo_start_xmit = pch_xmit,
1198};
1199
1200static void __devexit pch_can_remove(struct pci_dev *pdev)
1201{
1202 struct net_device *ndev = pci_get_drvdata(pdev);
1203 struct pch_can_priv *priv = netdev_priv(ndev);
1204
1205 unregister_candev(priv->ndev);
1206 free_candev(priv->ndev);
1207 pci_iounmap(pdev, priv->regs);
1208 pci_release_regions(pdev);
1209 pci_disable_device(pdev);
1210 pci_set_drvdata(pdev, NULL);
1211 pch_can_reset(priv);
1212}
1213
1214#ifdef CONFIG_PM
1215static int pch_can_suspend(struct pci_dev *pdev, pm_message_t state)
1216{
1217 int i; /* Counter variable. */
1218 int retval; /* Return value. */
1219 u32 buf_stat; /* Variable for reading the transmit buffer status. */
1220 u32 counter = 0xFFFFFF;
1221
1222 struct net_device *dev = pci_get_drvdata(pdev);
1223 struct pch_can_priv *priv = netdev_priv(dev);
1224
1225 /* Stop the CAN controller */
1226 pch_can_set_run_mode(priv, PCH_CAN_STOP);
1227
1228 /* Indicate that we are aboutto/in suspend */
1229 priv->can.state = CAN_STATE_SLEEPING;
1230
1231 /* Waiting for all transmission to complete. */
1232 while (counter) {
1233 buf_stat = pch_can_get_buffer_status(priv);
1234 if (!buf_stat)
1235 break;
1236 counter--;
1237 udelay(1);
1238 }
1239 if (!counter)
1240 dev_err(&pdev->dev, "%s -> Transmission time out.\n", __func__);
1241
1242 /* Save interrupt configuration and then disable them */
1243 pch_can_get_int_enables(priv, &(priv->int_enables));
1244 pch_can_set_int_enables(priv, PCH_CAN_DISABLE);
1245
1246 /* Save Tx buffer enable state */
1247 for (i = 0; i < PCH_OBJ_NUM; i++) {
1248 if (priv->msg_obj[i] == MSG_OBJ_TX)
1249 pch_can_get_tx_enable(priv, i + 1,
1250 &(priv->tx_enable[i]));
1251 }
1252
1253 /* Disable all Transmit buffers */
1254 pch_can_tx_disable_all(priv);
1255
1256 /* Save Rx buffer enable state */
1257 for (i = 0; i < PCH_OBJ_NUM; i++) {
1258 if (priv->msg_obj[i] == MSG_OBJ_RX) {
1259 pch_can_get_rx_enable(priv, i + 1,
1260 &(priv->rx_enable[i]));
1261 pch_can_get_rx_buffer_link(priv, i + 1,
1262 &(priv->rx_link[i]));
1263 }
1264 }
1265
1266 /* Disable all Receive buffers */
1267 pch_can_rx_disable_all(priv);
1268 retval = pci_save_state(pdev);
1269 if (retval) {
1270 dev_err(&pdev->dev, "pci_save_state failed.\n");
1271 } else {
1272 pci_enable_wake(pdev, PCI_D3hot, 0);
1273 pci_disable_device(pdev);
1274 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1275 }
1276
1277 return retval;
1278}
1279
1280static int pch_can_resume(struct pci_dev *pdev)
1281{
1282 int i; /* Counter variable. */
1283 int retval; /* Return variable. */
1284 struct net_device *dev = pci_get_drvdata(pdev);
1285 struct pch_can_priv *priv = netdev_priv(dev);
1286
1287 pci_set_power_state(pdev, PCI_D0);
1288 pci_restore_state(pdev);
1289 retval = pci_enable_device(pdev);
1290 if (retval) {
1291 dev_err(&pdev->dev, "pci_enable_device failed.\n");
1292 return retval;
1293 }
1294
1295 pci_enable_wake(pdev, PCI_D3hot, 0);
1296
1297 priv->can.state = CAN_STATE_ERROR_ACTIVE;
1298
1299 /* Disabling all interrupts. */
1300 pch_can_set_int_enables(priv, PCH_CAN_DISABLE);
1301
1302 /* Setting the CAN device in Stop Mode. */
1303 pch_can_set_run_mode(priv, PCH_CAN_STOP);
1304
1305 /* Configuring the transmit and receive buffers. */
1306 pch_can_config_rx_tx_buffers(priv);
1307
1308 /* Restore the CAN state */
1309 pch_set_bittiming(dev);
1310
1311 /* Listen/Active */
1312 pch_can_set_optmode(priv);
1313
1314 /* Enabling the transmit buffer. */
1315 for (i = 0; i < PCH_OBJ_NUM; i++) {
1316 if (priv->msg_obj[i] == MSG_OBJ_TX) {
1317 pch_can_set_tx_enable(priv, i + 1,
1318 priv->tx_enable[i]);
1319 }
1320 }
1321
1322 /* Configuring the receive buffer and enabling them. */
1323 for (i = 0; i < PCH_OBJ_NUM; i++) {
1324 if (priv->msg_obj[i] == MSG_OBJ_RX) {
1325 /* Restore buffer link */
1326 pch_can_set_rx_buffer_link(priv, i + 1,
1327 priv->rx_link[i]);
1328
1329 /* Restore buffer enables */
1330 pch_can_set_rx_enable(priv, i + 1, priv->rx_enable[i]);
1331 }
1332 }
1333
1334 /* Enable CAN Interrupts */
1335 pch_can_set_int_custom(priv);
1336
1337 /* Restore Run Mode */
1338 pch_can_set_run_mode(priv, PCH_CAN_RUN);
1339
1340 return retval;
1341}
1342#else
1343#define pch_can_suspend NULL
1344#define pch_can_resume NULL
1345#endif
1346
1347static int pch_can_get_berr_counter(const struct net_device *dev,
1348 struct can_berr_counter *bec)
1349{
1350 struct pch_can_priv *priv = netdev_priv(dev);
1351
1352 bec->txerr = ioread32(&priv->regs->errc) & CAN_TEC;
1353 bec->rxerr = (ioread32(&priv->regs->errc) & CAN_REC) >> 8;
1354
1355 return 0;
1356}
1357
1358static int __devinit pch_can_probe(struct pci_dev *pdev,
1359 const struct pci_device_id *id)
1360{
1361 struct net_device *ndev;
1362 struct pch_can_priv *priv;
1363 int rc;
1364 int index;
1365 void __iomem *addr;
1366
1367 rc = pci_enable_device(pdev);
1368 if (rc) {
1369 dev_err(&pdev->dev, "Failed pci_enable_device %d\n", rc);
1370 goto probe_exit_endev;
1371 }
1372
1373 rc = pci_request_regions(pdev, KBUILD_MODNAME);
1374 if (rc) {
1375 dev_err(&pdev->dev, "Failed pci_request_regions %d\n", rc);
1376 goto probe_exit_pcireq;
1377 }
1378
1379 addr = pci_iomap(pdev, 1, 0);
1380 if (!addr) {
1381 rc = -EIO;
1382 dev_err(&pdev->dev, "Failed pci_iomap\n");
1383 goto probe_exit_ipmap;
1384 }
1385
1386 ndev = alloc_candev(sizeof(struct pch_can_priv), PCH_TX_OBJ_NUM);
1387 if (!ndev) {
1388 rc = -ENOMEM;
1389 dev_err(&pdev->dev, "Failed alloc_candev\n");
1390 goto probe_exit_alloc_candev;
1391 }
1392
1393 priv = netdev_priv(ndev);
1394 priv->ndev = ndev;
1395 priv->regs = addr;
1396 priv->dev = pdev;
1397 priv->can.bittiming_const = &pch_can_bittiming_const;
1398 priv->can.do_set_mode = pch_can_do_set_mode;
1399 priv->can.do_get_berr_counter = pch_can_get_berr_counter;
1400 priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |
1401 CAN_CTRLMODE_LOOPBACK;
1402 priv->tx_obj = PCH_RX_OBJ_NUM + 1; /* Point head of Tx Obj */
1403
1404 ndev->irq = pdev->irq;
1405 ndev->flags |= IFF_ECHO;
1406
1407 pci_set_drvdata(pdev, ndev);
1408 SET_NETDEV_DEV(ndev, &pdev->dev);
1409 ndev->netdev_ops = &pch_can_netdev_ops;
1410
1411 priv->can.clock.freq = PCH_CAN_CLK; /* Hz */
1412 for (index = 0; index < PCH_RX_OBJ_NUM;)
1413 priv->msg_obj[index++] = MSG_OBJ_RX;
1414
1415 for (index = index; index < PCH_OBJ_NUM;)
1416 priv->msg_obj[index++] = MSG_OBJ_TX;
1417
1418 netif_napi_add(ndev, &priv->napi, pch_can_rx_poll, PCH_RX_OBJ_NUM);
1419
1420 rc = register_candev(ndev);
1421 if (rc) {
1422 dev_err(&pdev->dev, "Failed register_candev %d\n", rc);
1423 goto probe_exit_reg_candev;
1424 }
1425
1426 return 0;
1427
1428probe_exit_reg_candev:
1429 free_candev(ndev);
1430probe_exit_alloc_candev:
1431 pci_iounmap(pdev, addr);
1432probe_exit_ipmap:
1433 pci_release_regions(pdev);
1434probe_exit_pcireq:
1435 pci_disable_device(pdev);
1436probe_exit_endev:
1437 return rc;
1438}
1439
1440static struct pci_driver pch_can_pcidev = {
1441 .name = "pch_can",
1442 .id_table = pch_pci_tbl,
1443 .probe = pch_can_probe,
1444 .remove = __devexit_p(pch_can_remove),
1445 .suspend = pch_can_suspend,
1446 .resume = pch_can_resume,
1447};
1448
1449static int __init pch_can_pci_init(void)
1450{
1451 return pci_register_driver(&pch_can_pcidev);
1452}
1453module_init(pch_can_pci_init);
1454
1455static void __exit pch_can_pci_exit(void)
1456{
1457 pci_unregister_driver(&pch_can_pcidev);
1458}
1459module_exit(pch_can_pci_exit);
1460
1461MODULE_DESCRIPTION("Controller Area Network Driver");
1462MODULE_LICENSE("GPL v2");
1463MODULE_VERSION("0.94");
diff --git a/drivers/net/can/sja1000/Kconfig b/drivers/net/can/sja1000/Kconfig
index ae3505afd682..6fdc031daaae 100644
--- a/drivers/net/can/sja1000/Kconfig
+++ b/drivers/net/can/sja1000/Kconfig
@@ -58,4 +58,16 @@ config CAN_PLX_PCI
58 - esd CAN-PCIe/2000 58 - esd CAN-PCIe/2000
59 - Marathon CAN-bus-PCI card (http://www.marathon.ru/) 59 - Marathon CAN-bus-PCI card (http://www.marathon.ru/)
60 - TEWS TECHNOLOGIES TPMC810 card (http://www.tews.com/) 60 - TEWS TECHNOLOGIES TPMC810 card (http://www.tews.com/)
61
62config CAN_TSCAN1
63 tristate "TS-CAN1 PC104 boards"
64 depends on ISA
65 help
66 This driver is for Technologic Systems' TSCAN-1 PC104 boards.
67 http://www.embeddedarm.com/products/board-detail.php?product=TS-CAN1
68 The driver supports multiple boards and automatically configures them:
69 PLD IO base addresses are read from jumpers JP1 and JP2,
70 IRQ numbers are read from jumpers JP4 and JP5,
71 SJA1000 IO base addresses are chosen heuristically (first that works).
72
61endif 73endif
diff --git a/drivers/net/can/sja1000/Makefile b/drivers/net/can/sja1000/Makefile
index ce924553995d..2c591eb321c7 100644
--- a/drivers/net/can/sja1000/Makefile
+++ b/drivers/net/can/sja1000/Makefile
@@ -9,5 +9,6 @@ obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o
9obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o 9obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o
10obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o 10obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o
11obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o 11obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o
12obj-$(CONFIG_CAN_TSCAN1) += tscan1.o
12 13
13ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG 14ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
diff --git a/drivers/net/can/sja1000/tscan1.c b/drivers/net/can/sja1000/tscan1.c
new file mode 100644
index 000000000000..9756099a883a
--- /dev/null
+++ b/drivers/net/can/sja1000/tscan1.c
@@ -0,0 +1,216 @@
1/*
2 * tscan1.c: driver for Technologic Systems TS-CAN1 PC104 boards
3 *
4 * Copyright 2010 Andre B. Oliveira
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * References:
22 * - Getting started with TS-CAN1, Technologic Systems, Jun 2009
23 * http://www.embeddedarm.com/documentation/ts-can1-manual.pdf
24 */
25
26#include <linux/init.h>
27#include <linux/io.h>
28#include <linux/ioport.h>
29#include <linux/isa.h>
30#include <linux/module.h>
31#include <linux/netdevice.h>
32#include "sja1000.h"
33
34MODULE_DESCRIPTION("Driver for Technologic Systems TS-CAN1 PC104 boards");
35MODULE_AUTHOR("Andre B. Oliveira <anbadeol@gmail.com>");
36MODULE_LICENSE("GPL");
37
38/* Maximum number of boards (one in each JP1:JP2 setting of IO address) */
39#define TSCAN1_MAXDEV 4
40
41/* PLD registers address offsets */
42#define TSCAN1_ID1 0
43#define TSCAN1_ID2 1
44#define TSCAN1_VERSION 2
45#define TSCAN1_LED 3
46#define TSCAN1_PAGE 4
47#define TSCAN1_MODE 5
48#define TSCAN1_JUMPERS 6
49
50/* PLD board identifier registers magic values */
51#define TSCAN1_ID1_VALUE 0xf6
52#define TSCAN1_ID2_VALUE 0xb9
53
54/* PLD mode register SJA1000 IO enable bit */
55#define TSCAN1_MODE_ENABLE 0x40
56
57/* PLD jumpers register bits */
58#define TSCAN1_JP4 0x10
59#define TSCAN1_JP5 0x20
60
61/* PLD IO base addresses start */
62#define TSCAN1_PLD_ADDRESS 0x150
63
64/* PLD register space size */
65#define TSCAN1_PLD_SIZE 8
66
67/* SJA1000 register space size */
68#define TSCAN1_SJA1000_SIZE 32
69
70/* SJA1000 crystal frequency (16MHz) */
71#define TSCAN1_SJA1000_XTAL 16000000
72
73/* SJA1000 IO base addresses */
74static const unsigned short tscan1_sja1000_addresses[] __devinitconst = {
75 0x100, 0x120, 0x180, 0x1a0, 0x200, 0x240, 0x280, 0x320
76};
77
78/* Read SJA1000 register */
79static u8 tscan1_read(const struct sja1000_priv *priv, int reg)
80{
81 return inb((unsigned long)priv->reg_base + reg);
82}
83
84/* Write SJA1000 register */
85static void tscan1_write(const struct sja1000_priv *priv, int reg, u8 val)
86{
87 outb(val, (unsigned long)priv->reg_base + reg);
88}
89
90/* Probe for a TS-CAN1 board with JP2:JP1 jumper setting ID */
91static int __devinit tscan1_probe(struct device *dev, unsigned id)
92{
93 struct net_device *netdev;
94 struct sja1000_priv *priv;
95 unsigned long pld_base, sja1000_base;
96 int irq, i;
97
98 pld_base = TSCAN1_PLD_ADDRESS + id * TSCAN1_PLD_SIZE;
99 if (!request_region(pld_base, TSCAN1_PLD_SIZE, dev_name(dev)))
100 return -EBUSY;
101
102 if (inb(pld_base + TSCAN1_ID1) != TSCAN1_ID1_VALUE ||
103 inb(pld_base + TSCAN1_ID2) != TSCAN1_ID2_VALUE) {
104 release_region(pld_base, TSCAN1_PLD_SIZE);
105 return -ENODEV;
106 }
107
108 switch (inb(pld_base + TSCAN1_JUMPERS) & (TSCAN1_JP4 | TSCAN1_JP5)) {
109 case TSCAN1_JP4:
110 irq = 6;
111 break;
112 case TSCAN1_JP5:
113 irq = 7;
114 break;
115 case TSCAN1_JP4 | TSCAN1_JP5:
116 irq = 5;
117 break;
118 default:
119 dev_err(dev, "invalid JP4:JP5 setting (no IRQ)\n");
120 release_region(pld_base, TSCAN1_PLD_SIZE);
121 return -EINVAL;
122 }
123
124 netdev = alloc_sja1000dev(0);
125 if (!netdev) {
126 release_region(pld_base, TSCAN1_PLD_SIZE);
127 return -ENOMEM;
128 }
129
130 dev_set_drvdata(dev, netdev);
131 SET_NETDEV_DEV(netdev, dev);
132
133 netdev->base_addr = pld_base;
134 netdev->irq = irq;
135
136 priv = netdev_priv(netdev);
137 priv->read_reg = tscan1_read;
138 priv->write_reg = tscan1_write;
139 priv->can.clock.freq = TSCAN1_SJA1000_XTAL / 2;
140 priv->cdr = CDR_CBP | CDR_CLK_OFF;
141 priv->ocr = OCR_TX0_PUSHPULL;
142
143 /* Select the first SJA1000 IO address that is free and that works */
144 for (i = 0; i < ARRAY_SIZE(tscan1_sja1000_addresses); i++) {
145 sja1000_base = tscan1_sja1000_addresses[i];
146 if (!request_region(sja1000_base, TSCAN1_SJA1000_SIZE,
147 dev_name(dev)))
148 continue;
149
150 /* Set SJA1000 IO base address and enable it */
151 outb(TSCAN1_MODE_ENABLE | i, pld_base + TSCAN1_MODE);
152
153 priv->reg_base = (void __iomem *)sja1000_base;
154 if (!register_sja1000dev(netdev)) {
155 /* SJA1000 probe succeeded; turn LED off and return */
156 outb(0, pld_base + TSCAN1_LED);
157 netdev_info(netdev, "TS-CAN1 at 0x%lx 0x%lx irq %d\n",
158 pld_base, sja1000_base, irq);
159 return 0;
160 }
161
162 /* SJA1000 probe failed; release and try next address */
163 outb(0, pld_base + TSCAN1_MODE);
164 release_region(sja1000_base, TSCAN1_SJA1000_SIZE);
165 }
166
167 dev_err(dev, "failed to assign SJA1000 IO address\n");
168 dev_set_drvdata(dev, NULL);
169 free_sja1000dev(netdev);
170 release_region(pld_base, TSCAN1_PLD_SIZE);
171 return -ENXIO;
172}
173
174static int __devexit tscan1_remove(struct device *dev, unsigned id /*unused*/)
175{
176 struct net_device *netdev;
177 struct sja1000_priv *priv;
178 unsigned long pld_base, sja1000_base;
179
180 netdev = dev_get_drvdata(dev);
181 unregister_sja1000dev(netdev);
182 dev_set_drvdata(dev, NULL);
183
184 priv = netdev_priv(netdev);
185 pld_base = netdev->base_addr;
186 sja1000_base = (unsigned long)priv->reg_base;
187
188 outb(0, pld_base + TSCAN1_MODE); /* disable SJA1000 IO space */
189
190 release_region(sja1000_base, TSCAN1_SJA1000_SIZE);
191 release_region(pld_base, TSCAN1_PLD_SIZE);
192
193 free_sja1000dev(netdev);
194
195 return 0;
196}
197
198static struct isa_driver tscan1_isa_driver = {
199 .probe = tscan1_probe,
200 .remove = __devexit_p(tscan1_remove),
201 .driver = {
202 .name = "tscan1",
203 },
204};
205
206static int __init tscan1_init(void)
207{
208 return isa_register_driver(&tscan1_isa_driver, TSCAN1_MAXDEV);
209}
210module_init(tscan1_init);
211
212static void __exit tscan1_exit(void)
213{
214 isa_unregister_driver(&tscan1_isa_driver);
215}
216module_exit(tscan1_exit);
diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c
index a04ce6a5f637..4e3c12371aae 100644
--- a/drivers/net/cxgb3/cxgb3_main.c
+++ b/drivers/net/cxgb3/cxgb3_main.c
@@ -1266,11 +1266,13 @@ static int cxgb_up(struct adapter *adap)
1266 } 1266 }
1267 1267
1268 if (!(adap->flags & QUEUES_BOUND)) { 1268 if (!(adap->flags & QUEUES_BOUND)) {
1269 err = bind_qsets(adap); 1269 int ret = bind_qsets(adap);
1270 if (err) { 1270
1271 CH_ERR(adap, "failed to bind qsets, err %d\n", err); 1271 if (ret < 0) {
1272 CH_ERR(adap, "failed to bind qsets, err %d\n", ret);
1272 t3_intr_disable(adap); 1273 t3_intr_disable(adap);
1273 free_irq_resources(adap); 1274 free_irq_resources(adap);
1275 err = ret;
1274 goto out; 1276 goto out;
1275 } 1277 }
1276 adap->flags |= QUEUES_BOUND; 1278 adap->flags |= QUEUES_BOUND;
diff --git a/drivers/net/cxgb4/cxgb4.h b/drivers/net/cxgb4/cxgb4.h
index eaa49e4119f1..3d4253d311eb 100644
--- a/drivers/net/cxgb4/cxgb4.h
+++ b/drivers/net/cxgb4/cxgb4.h
@@ -281,7 +281,6 @@ struct sge_rspq;
281 281
282struct port_info { 282struct port_info {
283 struct adapter *adapter; 283 struct adapter *adapter;
284 struct vlan_group *vlan_grp;
285 u16 viid; 284 u16 viid;
286 s16 xact_addr_filt; /* index of exact MAC address filter */ 285 s16 xact_addr_filt; /* index of exact MAC address filter */
287 u16 rss_size; /* size of VI's RSS table slice */ 286 u16 rss_size; /* size of VI's RSS table slice */
diff --git a/drivers/net/cxgb4/cxgb4_main.c b/drivers/net/cxgb4/cxgb4_main.c
index 87054e0a5746..f17703f410b3 100644
--- a/drivers/net/cxgb4/cxgb4_main.c
+++ b/drivers/net/cxgb4/cxgb4_main.c
@@ -403,7 +403,7 @@ static int link_start(struct net_device *dev)
403 * that step explicitly. 403 * that step explicitly.
404 */ 404 */
405 ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1, 405 ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1,
406 pi->vlan_grp != NULL, true); 406 !!(dev->features & NETIF_F_HW_VLAN_RX), true);
407 if (ret == 0) { 407 if (ret == 0) {
408 ret = t4_change_mac(pi->adapter, mb, pi->viid, 408 ret = t4_change_mac(pi->adapter, mb, pi->viid,
409 pi->xact_addr_filt, dev->dev_addr, true, 409 pi->xact_addr_filt, dev->dev_addr, true,
@@ -1881,7 +1881,24 @@ static int set_tso(struct net_device *dev, u32 value)
1881 1881
1882static int set_flags(struct net_device *dev, u32 flags) 1882static int set_flags(struct net_device *dev, u32 flags)
1883{ 1883{
1884 return ethtool_op_set_flags(dev, flags, ETH_FLAG_RXHASH); 1884 int err;
1885 unsigned long old_feat = dev->features;
1886
1887 err = ethtool_op_set_flags(dev, flags, ETH_FLAG_RXHASH |
1888 ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN);
1889 if (err)
1890 return err;
1891
1892 if ((old_feat ^ dev->features) & NETIF_F_HW_VLAN_RX) {
1893 const struct port_info *pi = netdev_priv(dev);
1894
1895 err = t4_set_rxmode(pi->adapter, pi->adapter->fn, pi->viid, -1,
1896 -1, -1, -1, !!(flags & ETH_FLAG_RXVLAN),
1897 true);
1898 if (err)
1899 dev->features = old_feat;
1900 }
1901 return err;
1885} 1902}
1886 1903
1887static int get_rss_table(struct net_device *dev, struct ethtool_rxfh_indir *p) 1904static int get_rss_table(struct net_device *dev, struct ethtool_rxfh_indir *p)
@@ -2842,15 +2859,6 @@ static int cxgb_set_mac_addr(struct net_device *dev, void *p)
2842 return 0; 2859 return 0;
2843} 2860}
2844 2861
2845static void vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
2846{
2847 struct port_info *pi = netdev_priv(dev);
2848
2849 pi->vlan_grp = grp;
2850 t4_set_rxmode(pi->adapter, pi->adapter->fn, pi->viid, -1, -1, -1, -1,
2851 grp != NULL, true);
2852}
2853
2854#ifdef CONFIG_NET_POLL_CONTROLLER 2862#ifdef CONFIG_NET_POLL_CONTROLLER
2855static void cxgb_netpoll(struct net_device *dev) 2863static void cxgb_netpoll(struct net_device *dev)
2856{ 2864{
@@ -2878,7 +2886,6 @@ static const struct net_device_ops cxgb4_netdev_ops = {
2878 .ndo_validate_addr = eth_validate_addr, 2886 .ndo_validate_addr = eth_validate_addr,
2879 .ndo_do_ioctl = cxgb_ioctl, 2887 .ndo_do_ioctl = cxgb_ioctl,
2880 .ndo_change_mtu = cxgb_change_mtu, 2888 .ndo_change_mtu = cxgb_change_mtu,
2881 .ndo_vlan_rx_register = vlan_rx_register,
2882#ifdef CONFIG_NET_POLL_CONTROLLER 2889#ifdef CONFIG_NET_POLL_CONTROLLER
2883 .ndo_poll_controller = cxgb_netpoll, 2890 .ndo_poll_controller = cxgb_netpoll,
2884#endif 2891#endif
@@ -3658,7 +3665,6 @@ static int __devinit init_one(struct pci_dev *pdev,
3658 pi->rx_offload = RX_CSO; 3665 pi->rx_offload = RX_CSO;
3659 pi->port_id = i; 3666 pi->port_id = i;
3660 netif_carrier_off(netdev); 3667 netif_carrier_off(netdev);
3661 netif_tx_stop_all_queues(netdev);
3662 netdev->irq = pdev->irq; 3668 netdev->irq = pdev->irq;
3663 3669
3664 netdev->features |= NETIF_F_SG | TSO_FLAGS; 3670 netdev->features |= NETIF_F_SG | TSO_FLAGS;
@@ -3730,6 +3736,7 @@ static int __devinit init_one(struct pci_dev *pdev,
3730 3736
3731 __set_bit(i, &adapter->registered_device_map); 3737 __set_bit(i, &adapter->registered_device_map);
3732 adapter->chan_map[adap2pinfo(adapter, i)->tx_chan] = i; 3738 adapter->chan_map[adap2pinfo(adapter, i)->tx_chan] = i;
3739 netif_tx_stop_all_queues(adapter->port[i]);
3733 } 3740 }
3734 } 3741 }
3735 if (!adapter->registered_device_map) { 3742 if (!adapter->registered_device_map) {
diff --git a/drivers/net/cxgb4/sge.c b/drivers/net/cxgb4/sge.c
index 9967f3debce7..17022258ed68 100644
--- a/drivers/net/cxgb4/sge.c
+++ b/drivers/net/cxgb4/sge.c
@@ -1530,18 +1530,11 @@ static void do_gro(struct sge_eth_rxq *rxq, const struct pkt_gl *gl,
1530 skb->rxhash = (__force u32)pkt->rsshdr.hash_val; 1530 skb->rxhash = (__force u32)pkt->rsshdr.hash_val;
1531 1531
1532 if (unlikely(pkt->vlan_ex)) { 1532 if (unlikely(pkt->vlan_ex)) {
1533 struct port_info *pi = netdev_priv(rxq->rspq.netdev); 1533 __vlan_hwaccel_put_tag(skb, ntohs(pkt->vlan));
1534 struct vlan_group *grp = pi->vlan_grp;
1535
1536 rxq->stats.vlan_ex++; 1534 rxq->stats.vlan_ex++;
1537 if (likely(grp)) {
1538 ret = vlan_gro_frags(&rxq->rspq.napi, grp,
1539 ntohs(pkt->vlan));
1540 goto stats;
1541 }
1542 } 1535 }
1543 ret = napi_gro_frags(&rxq->rspq.napi); 1536 ret = napi_gro_frags(&rxq->rspq.napi);
1544stats: if (ret == GRO_HELD) 1537 if (ret == GRO_HELD)
1545 rxq->stats.lro_pkts++; 1538 rxq->stats.lro_pkts++;
1546 else if (ret == GRO_MERGED || ret == GRO_MERGED_FREE) 1539 else if (ret == GRO_MERGED || ret == GRO_MERGED_FREE)
1547 rxq->stats.lro_merged++; 1540 rxq->stats.lro_merged++;
@@ -1608,16 +1601,10 @@ int t4_ethrx_handler(struct sge_rspq *q, const __be64 *rsp,
1608 skb_checksum_none_assert(skb); 1601 skb_checksum_none_assert(skb);
1609 1602
1610 if (unlikely(pkt->vlan_ex)) { 1603 if (unlikely(pkt->vlan_ex)) {
1611 struct vlan_group *grp = pi->vlan_grp; 1604 __vlan_hwaccel_put_tag(skb, ntohs(pkt->vlan));
1612
1613 rxq->stats.vlan_ex++; 1605 rxq->stats.vlan_ex++;
1614 if (likely(grp)) 1606 }
1615 vlan_hwaccel_receive_skb(skb, grp, ntohs(pkt->vlan)); 1607 netif_receive_skb(skb);
1616 else
1617 dev_kfree_skb_any(skb);
1618 } else
1619 netif_receive_skb(skb);
1620
1621 return 0; 1608 return 0;
1622} 1609}
1623 1610
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index a117f2a0252e..4686c3983fc3 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -521,7 +521,7 @@ void e1000_down(struct e1000_adapter *adapter)
521 e1000_clean_all_rx_rings(adapter); 521 e1000_clean_all_rx_rings(adapter);
522} 522}
523 523
524void e1000_reinit_safe(struct e1000_adapter *adapter) 524static void e1000_reinit_safe(struct e1000_adapter *adapter)
525{ 525{
526 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) 526 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
527 msleep(1); 527 msleep(1);
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index 1321cb6401cf..8e745e74828d 100644
--- a/drivers/net/ehea/ehea.h
+++ b/drivers/net/ehea/ehea.h
@@ -396,7 +396,9 @@ struct ehea_port_res {
396 int swqe_ll_count; 396 int swqe_ll_count;
397 u32 swqe_id_counter; 397 u32 swqe_id_counter;
398 u64 tx_packets; 398 u64 tx_packets;
399 u64 tx_bytes;
399 u64 rx_packets; 400 u64 rx_packets;
401 u64 rx_bytes;
400 u32 poll_counter; 402 u32 poll_counter;
401 struct net_lro_mgr lro_mgr; 403 struct net_lro_mgr lro_mgr;
402 struct net_lro_desc lro_desc[MAX_LRO_DESCRIPTORS]; 404 struct net_lro_desc lro_desc[MAX_LRO_DESCRIPTORS];
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index bb7d306fb446..182b2a7be8dc 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -330,7 +330,7 @@ static struct net_device_stats *ehea_get_stats(struct net_device *dev)
330 struct ehea_port *port = netdev_priv(dev); 330 struct ehea_port *port = netdev_priv(dev);
331 struct net_device_stats *stats = &port->stats; 331 struct net_device_stats *stats = &port->stats;
332 struct hcp_ehea_port_cb2 *cb2; 332 struct hcp_ehea_port_cb2 *cb2;
333 u64 hret, rx_packets, tx_packets; 333 u64 hret, rx_packets, tx_packets, rx_bytes = 0, tx_bytes = 0;
334 int i; 334 int i;
335 335
336 memset(stats, 0, sizeof(*stats)); 336 memset(stats, 0, sizeof(*stats));
@@ -353,18 +353,22 @@ static struct net_device_stats *ehea_get_stats(struct net_device *dev)
353 ehea_dump(cb2, sizeof(*cb2), "net_device_stats"); 353 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
354 354
355 rx_packets = 0; 355 rx_packets = 0;
356 for (i = 0; i < port->num_def_qps; i++) 356 for (i = 0; i < port->num_def_qps; i++) {
357 rx_packets += port->port_res[i].rx_packets; 357 rx_packets += port->port_res[i].rx_packets;
358 rx_bytes += port->port_res[i].rx_bytes;
359 }
358 360
359 tx_packets = 0; 361 tx_packets = 0;
360 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) 362 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
361 tx_packets += port->port_res[i].tx_packets; 363 tx_packets += port->port_res[i].tx_packets;
364 tx_bytes += port->port_res[i].tx_bytes;
365 }
362 366
363 stats->tx_packets = tx_packets; 367 stats->tx_packets = tx_packets;
364 stats->multicast = cb2->rxmcp; 368 stats->multicast = cb2->rxmcp;
365 stats->rx_errors = cb2->rxuerr; 369 stats->rx_errors = cb2->rxuerr;
366 stats->rx_bytes = cb2->rxo; 370 stats->rx_bytes = rx_bytes;
367 stats->tx_bytes = cb2->txo; 371 stats->tx_bytes = tx_bytes;
368 stats->rx_packets = rx_packets; 372 stats->rx_packets = rx_packets;
369 373
370out_herr: 374out_herr:
@@ -703,6 +707,7 @@ static int ehea_proc_rwqes(struct net_device *dev,
703 int skb_arr_rq2_len = pr->rq2_skba.len; 707 int skb_arr_rq2_len = pr->rq2_skba.len;
704 int skb_arr_rq3_len = pr->rq3_skba.len; 708 int skb_arr_rq3_len = pr->rq3_skba.len;
705 int processed, processed_rq1, processed_rq2, processed_rq3; 709 int processed, processed_rq1, processed_rq2, processed_rq3;
710 u64 processed_bytes = 0;
706 int wqe_index, last_wqe_index, rq, port_reset; 711 int wqe_index, last_wqe_index, rq, port_reset;
707 712
708 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0; 713 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
@@ -760,6 +765,7 @@ static int ehea_proc_rwqes(struct net_device *dev,
760 processed_rq3++; 765 processed_rq3++;
761 } 766 }
762 767
768 processed_bytes += skb->len;
763 ehea_proc_skb(pr, cqe, skb); 769 ehea_proc_skb(pr, cqe, skb);
764 } else { 770 } else {
765 pr->p_stats.poll_receive_errors++; 771 pr->p_stats.poll_receive_errors++;
@@ -775,6 +781,7 @@ static int ehea_proc_rwqes(struct net_device *dev,
775 lro_flush_all(&pr->lro_mgr); 781 lro_flush_all(&pr->lro_mgr);
776 782
777 pr->rx_packets += processed; 783 pr->rx_packets += processed;
784 pr->rx_bytes += processed_bytes;
778 785
779 ehea_refill_rq1(pr, last_wqe_index, processed_rq1); 786 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
780 ehea_refill_rq2(pr, processed_rq2); 787 ehea_refill_rq2(pr, processed_rq2);
@@ -1509,9 +1516,20 @@ static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1509 enum ehea_eq_type eq_type = EHEA_EQ; 1516 enum ehea_eq_type eq_type = EHEA_EQ;
1510 struct ehea_qp_init_attr *init_attr = NULL; 1517 struct ehea_qp_init_attr *init_attr = NULL;
1511 int ret = -EIO; 1518 int ret = -EIO;
1519 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1520
1521 tx_bytes = pr->tx_bytes;
1522 tx_packets = pr->tx_packets;
1523 rx_bytes = pr->rx_bytes;
1524 rx_packets = pr->rx_packets;
1512 1525
1513 memset(pr, 0, sizeof(struct ehea_port_res)); 1526 memset(pr, 0, sizeof(struct ehea_port_res));
1514 1527
1528 pr->tx_bytes = rx_bytes;
1529 pr->tx_packets = tx_packets;
1530 pr->rx_bytes = rx_bytes;
1531 pr->rx_packets = rx_packets;
1532
1515 pr->port = port; 1533 pr->port = port;
1516 spin_lock_init(&pr->xmit_lock); 1534 spin_lock_init(&pr->xmit_lock);
1517 spin_lock_init(&pr->netif_queue); 1535 spin_lock_init(&pr->netif_queue);
@@ -2249,6 +2267,14 @@ static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2249 memset(swqe, 0, SWQE_HEADER_SIZE); 2267 memset(swqe, 0, SWQE_HEADER_SIZE);
2250 atomic_dec(&pr->swqe_avail); 2268 atomic_dec(&pr->swqe_avail);
2251 2269
2270 if (vlan_tx_tag_present(skb)) {
2271 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2272 swqe->vlan_tag = vlan_tx_tag_get(skb);
2273 }
2274
2275 pr->tx_packets++;
2276 pr->tx_bytes += skb->len;
2277
2252 if (skb->len <= SWQE3_MAX_IMM) { 2278 if (skb->len <= SWQE3_MAX_IMM) {
2253 u32 sig_iv = port->sig_comp_iv; 2279 u32 sig_iv = port->sig_comp_iv;
2254 u32 swqe_num = pr->swqe_id_counter; 2280 u32 swqe_num = pr->swqe_id_counter;
@@ -2279,11 +2305,6 @@ static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2279 } 2305 }
2280 pr->swqe_id_counter += 1; 2306 pr->swqe_id_counter += 1;
2281 2307
2282 if (vlan_tx_tag_present(skb)) {
2283 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2284 swqe->vlan_tag = vlan_tx_tag_get(skb);
2285 }
2286
2287 if (netif_msg_tx_queued(port)) { 2308 if (netif_msg_tx_queued(port)) {
2288 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr); 2309 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
2289 ehea_dump(swqe, 512, "swqe"); 2310 ehea_dump(swqe, 512, "swqe");
@@ -2295,7 +2316,6 @@ static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2295 } 2316 }
2296 2317
2297 ehea_post_swqe(pr->qp, swqe); 2318 ehea_post_swqe(pr->qp, swqe);
2298 pr->tx_packets++;
2299 2319
2300 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) { 2320 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2301 spin_lock_irqsave(&pr->netif_queue, flags); 2321 spin_lock_irqsave(&pr->netif_queue, flags);
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 4c4cc80ec0a1..49e4ce1246a7 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -2511,7 +2511,7 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
2511 skb_recycle_check(skb, priv->rx_buffer_size + 2511 skb_recycle_check(skb, priv->rx_buffer_size +
2512 RXBUF_ALIGNMENT)) { 2512 RXBUF_ALIGNMENT)) {
2513 gfar_align_skb(skb); 2513 gfar_align_skb(skb);
2514 __skb_queue_head(&priv->rx_recycle, skb); 2514 skb_queue_head(&priv->rx_recycle, skb);
2515 } else 2515 } else
2516 dev_kfree_skb_any(skb); 2516 dev_kfree_skb_any(skb);
2517 2517
@@ -2594,7 +2594,7 @@ struct sk_buff * gfar_new_skb(struct net_device *dev)
2594 struct gfar_private *priv = netdev_priv(dev); 2594 struct gfar_private *priv = netdev_priv(dev);
2595 struct sk_buff *skb = NULL; 2595 struct sk_buff *skb = NULL;
2596 2596
2597 skb = __skb_dequeue(&priv->rx_recycle); 2597 skb = skb_dequeue(&priv->rx_recycle);
2598 if (!skb) 2598 if (!skb)
2599 skb = gfar_alloc_skb(dev); 2599 skb = gfar_alloc_skb(dev);
2600 2600
@@ -2750,7 +2750,7 @@ int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit)
2750 if (unlikely(!newskb)) 2750 if (unlikely(!newskb))
2751 newskb = skb; 2751 newskb = skb;
2752 else if (skb) 2752 else if (skb)
2753 __skb_queue_head(&priv->rx_recycle, skb); 2753 skb_queue_head(&priv->rx_recycle, skb);
2754 } else { 2754 } else {
2755 /* Increment the number of packets */ 2755 /* Increment the number of packets */
2756 rx_queue->stats.rx_packets++; 2756 rx_queue->stats.rx_packets++;
diff --git a/drivers/net/jme.c b/drivers/net/jme.c
index d7a975ee2add..d85edf3119c2 100644
--- a/drivers/net/jme.c
+++ b/drivers/net/jme.c
@@ -1623,12 +1623,12 @@ err_out:
1623 return rc; 1623 return rc;
1624} 1624}
1625 1625
1626#ifdef CONFIG_PM
1627static void 1626static void
1628jme_set_100m_half(struct jme_adapter *jme) 1627jme_set_100m_half(struct jme_adapter *jme)
1629{ 1628{
1630 u32 bmcr, tmp; 1629 u32 bmcr, tmp;
1631 1630
1631 jme_phy_on(jme);
1632 bmcr = jme_mdio_read(jme->dev, jme->mii_if.phy_id, MII_BMCR); 1632 bmcr = jme_mdio_read(jme->dev, jme->mii_if.phy_id, MII_BMCR);
1633 tmp = bmcr & ~(BMCR_ANENABLE | BMCR_SPEED100 | 1633 tmp = bmcr & ~(BMCR_ANENABLE | BMCR_SPEED100 |
1634 BMCR_SPEED1000 | BMCR_FULLDPLX); 1634 BMCR_SPEED1000 | BMCR_FULLDPLX);
@@ -1656,7 +1656,6 @@ jme_wait_link(struct jme_adapter *jme)
1656 phylink = jme_linkstat_from_phy(jme); 1656 phylink = jme_linkstat_from_phy(jme);
1657 } 1657 }
1658} 1658}
1659#endif
1660 1659
1661static inline void 1660static inline void
1662jme_phy_off(struct jme_adapter *jme) 1661jme_phy_off(struct jme_adapter *jme)
@@ -1664,6 +1663,21 @@ jme_phy_off(struct jme_adapter *jme)
1664 jme_mdio_write(jme->dev, jme->mii_if.phy_id, MII_BMCR, BMCR_PDOWN); 1663 jme_mdio_write(jme->dev, jme->mii_if.phy_id, MII_BMCR, BMCR_PDOWN);
1665} 1664}
1666 1665
1666static void
1667jme_powersave_phy(struct jme_adapter *jme)
1668{
1669 if (jme->reg_pmcs) {
1670 jme_set_100m_half(jme);
1671
1672 if (jme->reg_pmcs & (PMCS_LFEN | PMCS_LREN))
1673 jme_wait_link(jme);
1674
1675 jwrite32(jme, JME_PMCS, jme->reg_pmcs);
1676 } else {
1677 jme_phy_off(jme);
1678 }
1679}
1680
1667static int 1681static int
1668jme_close(struct net_device *netdev) 1682jme_close(struct net_device *netdev)
1669{ 1683{
@@ -2991,6 +3005,16 @@ jme_remove_one(struct pci_dev *pdev)
2991 3005
2992} 3006}
2993 3007
3008static void
3009jme_shutdown(struct pci_dev *pdev)
3010{
3011 struct net_device *netdev = pci_get_drvdata(pdev);
3012 struct jme_adapter *jme = netdev_priv(netdev);
3013
3014 jme_powersave_phy(jme);
3015 pci_pme_active(pdev, true);
3016}
3017
2994#ifdef CONFIG_PM 3018#ifdef CONFIG_PM
2995static int 3019static int
2996jme_suspend(struct pci_dev *pdev, pm_message_t state) 3020jme_suspend(struct pci_dev *pdev, pm_message_t state)
@@ -3028,19 +3052,9 @@ jme_suspend(struct pci_dev *pdev, pm_message_t state)
3028 tasklet_hi_enable(&jme->rxempty_task); 3052 tasklet_hi_enable(&jme->rxempty_task);
3029 3053
3030 pci_save_state(pdev); 3054 pci_save_state(pdev);
3031 if (jme->reg_pmcs) { 3055 jme_powersave_phy(jme);
3032 jme_set_100m_half(jme); 3056 pci_enable_wake(jme->pdev, PCI_D3hot, true);
3033 3057 pci_set_power_state(pdev, PCI_D3hot);
3034 if (jme->reg_pmcs & (PMCS_LFEN | PMCS_LREN))
3035 jme_wait_link(jme);
3036
3037 jwrite32(jme, JME_PMCS, jme->reg_pmcs);
3038
3039 pci_enable_wake(pdev, PCI_D3cold, true);
3040 } else {
3041 jme_phy_off(jme);
3042 }
3043 pci_set_power_state(pdev, PCI_D3cold);
3044 3058
3045 return 0; 3059 return 0;
3046} 3060}
@@ -3087,6 +3101,7 @@ static struct pci_driver jme_driver = {
3087 .suspend = jme_suspend, 3101 .suspend = jme_suspend,
3088 .resume = jme_resume, 3102 .resume = jme_resume,
3089#endif /* CONFIG_PM */ 3103#endif /* CONFIG_PM */
3104 .shutdown = jme_shutdown,
3090}; 3105};
3091 3106
3092static int __init 3107static int __init
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 4297f6e8c4bc..f69e73e2191e 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -515,14 +515,15 @@ static int macb_poll(struct napi_struct *napi, int budget)
515 (unsigned long)status, budget); 515 (unsigned long)status, budget);
516 516
517 work_done = macb_rx(bp, budget); 517 work_done = macb_rx(bp, budget);
518 if (work_done < budget) 518 if (work_done < budget) {
519 napi_complete(napi); 519 napi_complete(napi);
520 520
521 /* 521 /*
522 * We've done what we can to clean the buffers. Make sure we 522 * We've done what we can to clean the buffers. Make sure we
523 * get notified when new packets arrive. 523 * get notified when new packets arrive.
524 */ 524 */
525 macb_writel(bp, IER, MACB_RX_INT_FLAGS); 525 macb_writel(bp, IER, MACB_RX_INT_FLAGS);
526 }
526 527
527 /* TODO: Handle errors */ 528 /* TODO: Handle errors */
528 529
@@ -550,12 +551,16 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
550 } 551 }
551 552
552 if (status & MACB_RX_INT_FLAGS) { 553 if (status & MACB_RX_INT_FLAGS) {
554 /*
555 * There's no point taking any more interrupts
556 * until we have processed the buffers. The
557 * scheduling call may fail if the poll routine
558 * is already scheduled, so disable interrupts
559 * now.
560 */
561 macb_writel(bp, IDR, MACB_RX_INT_FLAGS);
562
553 if (napi_schedule_prep(&bp->napi)) { 563 if (napi_schedule_prep(&bp->napi)) {
554 /*
555 * There's no point taking any more interrupts
556 * until we have processed the buffers
557 */
558 macb_writel(bp, IDR, MACB_RX_INT_FLAGS);
559 dev_dbg(&bp->pdev->dev, 564 dev_dbg(&bp->pdev->dev,
560 "scheduling RX softirq\n"); 565 "scheduling RX softirq\n");
561 __napi_schedule(&bp->napi); 566 __napi_schedule(&bp->napi);
diff --git a/drivers/net/mlx4/icm.c b/drivers/net/mlx4/icm.c
index b07e4dee80aa..02393fdf44c1 100644
--- a/drivers/net/mlx4/icm.c
+++ b/drivers/net/mlx4/icm.c
@@ -210,38 +210,12 @@ static int mlx4_MAP_ICM(struct mlx4_dev *dev, struct mlx4_icm *icm, u64 virt)
210 return mlx4_map_cmd(dev, MLX4_CMD_MAP_ICM, icm, virt); 210 return mlx4_map_cmd(dev, MLX4_CMD_MAP_ICM, icm, virt);
211} 211}
212 212
213int mlx4_UNMAP_ICM(struct mlx4_dev *dev, u64 virt, u32 page_count) 213static int mlx4_UNMAP_ICM(struct mlx4_dev *dev, u64 virt, u32 page_count)
214{ 214{
215 return mlx4_cmd(dev, virt, page_count, 0, MLX4_CMD_UNMAP_ICM, 215 return mlx4_cmd(dev, virt, page_count, 0, MLX4_CMD_UNMAP_ICM,
216 MLX4_CMD_TIME_CLASS_B); 216 MLX4_CMD_TIME_CLASS_B);
217} 217}
218 218
219int mlx4_MAP_ICM_page(struct mlx4_dev *dev, u64 dma_addr, u64 virt)
220{
221 struct mlx4_cmd_mailbox *mailbox;
222 __be64 *inbox;
223 int err;
224
225 mailbox = mlx4_alloc_cmd_mailbox(dev);
226 if (IS_ERR(mailbox))
227 return PTR_ERR(mailbox);
228 inbox = mailbox->buf;
229
230 inbox[0] = cpu_to_be64(virt);
231 inbox[1] = cpu_to_be64(dma_addr);
232
233 err = mlx4_cmd(dev, mailbox->dma, 1, 0, MLX4_CMD_MAP_ICM,
234 MLX4_CMD_TIME_CLASS_B);
235
236 mlx4_free_cmd_mailbox(dev, mailbox);
237
238 if (!err)
239 mlx4_dbg(dev, "Mapped page at %llx to %llx for ICM.\n",
240 (unsigned long long) dma_addr, (unsigned long long) virt);
241
242 return err;
243}
244
245int mlx4_MAP_ICM_AUX(struct mlx4_dev *dev, struct mlx4_icm *icm) 219int mlx4_MAP_ICM_AUX(struct mlx4_dev *dev, struct mlx4_icm *icm)
246{ 220{
247 return mlx4_map_cmd(dev, MLX4_CMD_MAP_ICM_AUX, icm, -1); 221 return mlx4_map_cmd(dev, MLX4_CMD_MAP_ICM_AUX, icm, -1);
diff --git a/drivers/net/mlx4/icm.h b/drivers/net/mlx4/icm.h
index ab56a2f89b65..b10c07a1dc1a 100644
--- a/drivers/net/mlx4/icm.h
+++ b/drivers/net/mlx4/icm.h
@@ -128,8 +128,6 @@ static inline unsigned long mlx4_icm_size(struct mlx4_icm_iter *iter)
128 return sg_dma_len(&iter->chunk->mem[iter->page_idx]); 128 return sg_dma_len(&iter->chunk->mem[iter->page_idx]);
129} 129}
130 130
131int mlx4_UNMAP_ICM(struct mlx4_dev *dev, u64 virt, u32 page_count);
132int mlx4_MAP_ICM_page(struct mlx4_dev *dev, u64 dma_addr, u64 virt);
133int mlx4_MAP_ICM_AUX(struct mlx4_dev *dev, struct mlx4_icm *icm); 131int mlx4_MAP_ICM_AUX(struct mlx4_dev *dev, struct mlx4_icm *icm);
134int mlx4_UNMAP_ICM_AUX(struct mlx4_dev *dev); 132int mlx4_UNMAP_ICM_AUX(struct mlx4_dev *dev);
135 133
diff --git a/drivers/net/mlx4/port.c b/drivers/net/mlx4/port.c
index 56371ef328ef..451339559bdc 100644
--- a/drivers/net/mlx4/port.c
+++ b/drivers/net/mlx4/port.c
@@ -111,6 +111,12 @@ int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac, int *index)
111 goto out; 111 goto out;
112 } 112 }
113 } 113 }
114
115 if (free < 0) {
116 err = -ENOMEM;
117 goto out;
118 }
119
114 mlx4_dbg(dev, "Free MAC index is %d\n", free); 120 mlx4_dbg(dev, "Free MAC index is %d\n", free);
115 121
116 if (table->total == table->max) { 122 if (table->total == table->max) {
@@ -224,6 +230,11 @@ int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index)
224 } 230 }
225 } 231 }
226 232
233 if (free < 0) {
234 err = -ENOMEM;
235 goto out;
236 }
237
227 if (table->total == table->max) { 238 if (table->total == table->max) {
228 /* No free vlan entries */ 239 /* No free vlan entries */
229 err = -ENOSPC; 240 err = -ENOSPC;
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 1bb16cb79433..7670aac0e93f 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -65,7 +65,7 @@ EXPORT_SYMBOL(phy_print_status);
65 * 65 *
66 * Returns 0 on success on < 0 on error. 66 * Returns 0 on success on < 0 on error.
67 */ 67 */
68int phy_clear_interrupt(struct phy_device *phydev) 68static int phy_clear_interrupt(struct phy_device *phydev)
69{ 69{
70 int err = 0; 70 int err = 0;
71 71
@@ -82,7 +82,7 @@ int phy_clear_interrupt(struct phy_device *phydev)
82 * 82 *
83 * Returns 0 on success on < 0 on error. 83 * Returns 0 on success on < 0 on error.
84 */ 84 */
85int phy_config_interrupt(struct phy_device *phydev, u32 interrupts) 85static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts)
86{ 86{
87 int err = 0; 87 int err = 0;
88 88
@@ -208,7 +208,7 @@ static inline int phy_find_valid(int idx, u32 features)
208 * duplexes. Drop down by one in this order: 1000/FULL, 208 * duplexes. Drop down by one in this order: 1000/FULL,
209 * 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF. 209 * 1000/HALF, 100/FULL, 100/HALF, 10/FULL, 10/HALF.
210 */ 210 */
211void phy_sanitize_settings(struct phy_device *phydev) 211static void phy_sanitize_settings(struct phy_device *phydev)
212{ 212{
213 u32 features = phydev->supported; 213 u32 features = phydev->supported;
214 int idx; 214 int idx;
@@ -223,7 +223,6 @@ void phy_sanitize_settings(struct phy_device *phydev)
223 phydev->speed = settings[idx].speed; 223 phydev->speed = settings[idx].speed;
224 phydev->duplex = settings[idx].duplex; 224 phydev->duplex = settings[idx].duplex;
225} 225}
226EXPORT_SYMBOL(phy_sanitize_settings);
227 226
228/** 227/**
229 * phy_ethtool_sset - generic ethtool sset function, handles all the details 228 * phy_ethtool_sset - generic ethtool sset function, handles all the details
@@ -532,7 +531,7 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
532 * phy_enable_interrupts - Enable the interrupts from the PHY side 531 * phy_enable_interrupts - Enable the interrupts from the PHY side
533 * @phydev: target phy_device struct 532 * @phydev: target phy_device struct
534 */ 533 */
535int phy_enable_interrupts(struct phy_device *phydev) 534static int phy_enable_interrupts(struct phy_device *phydev)
536{ 535{
537 int err; 536 int err;
538 537
@@ -545,13 +544,12 @@ int phy_enable_interrupts(struct phy_device *phydev)
545 544
546 return err; 545 return err;
547} 546}
548EXPORT_SYMBOL(phy_enable_interrupts);
549 547
550/** 548/**
551 * phy_disable_interrupts - Disable the PHY interrupts from the PHY side 549 * phy_disable_interrupts - Disable the PHY interrupts from the PHY side
552 * @phydev: target phy_device struct 550 * @phydev: target phy_device struct
553 */ 551 */
554int phy_disable_interrupts(struct phy_device *phydev) 552static int phy_disable_interrupts(struct phy_device *phydev)
555{ 553{
556 int err; 554 int err;
557 555
@@ -574,7 +572,6 @@ phy_err:
574 572
575 return err; 573 return err;
576} 574}
577EXPORT_SYMBOL(phy_disable_interrupts);
578 575
579/** 576/**
580 * phy_start_interrupts - request and enable interrupts for a PHY device 577 * phy_start_interrupts - request and enable interrupts for a PHY device
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 16ddc77313cb..993c52c82aeb 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -57,6 +57,9 @@ extern void mdio_bus_exit(void);
57static LIST_HEAD(phy_fixup_list); 57static LIST_HEAD(phy_fixup_list);
58static DEFINE_MUTEX(phy_fixup_lock); 58static DEFINE_MUTEX(phy_fixup_lock);
59 59
60static int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
61 u32 flags, phy_interface_t interface);
62
60/* 63/*
61 * Creates a new phy_fixup and adds it to the list 64 * Creates a new phy_fixup and adds it to the list
62 * @bus_id: A string which matches phydev->dev.bus_id (or PHY_ANY_ID) 65 * @bus_id: A string which matches phydev->dev.bus_id (or PHY_ANY_ID)
@@ -146,7 +149,8 @@ int phy_scan_fixups(struct phy_device *phydev)
146} 149}
147EXPORT_SYMBOL(phy_scan_fixups); 150EXPORT_SYMBOL(phy_scan_fixups);
148 151
149struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id) 152static struct phy_device* phy_device_create(struct mii_bus *bus,
153 int addr, int phy_id)
150{ 154{
151 struct phy_device *dev; 155 struct phy_device *dev;
152 156
@@ -193,7 +197,6 @@ struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
193 197
194 return dev; 198 return dev;
195} 199}
196EXPORT_SYMBOL(phy_device_create);
197 200
198/** 201/**
199 * get_phy_id - reads the specified addr for its ID. 202 * get_phy_id - reads the specified addr for its ID.
@@ -316,7 +319,7 @@ EXPORT_SYMBOL(phy_find_first);
316 * If you want to monitor your own link state, don't call 319 * If you want to monitor your own link state, don't call
317 * this function. 320 * this function.
318 */ 321 */
319void phy_prepare_link(struct phy_device *phydev, 322static void phy_prepare_link(struct phy_device *phydev,
320 void (*handler)(struct net_device *)) 323 void (*handler)(struct net_device *))
321{ 324{
322 phydev->adjust_link = handler; 325 phydev->adjust_link = handler;
@@ -435,8 +438,8 @@ int phy_init_hw(struct phy_device *phydev)
435 * the attaching device, and given a callback for link status 438 * the attaching device, and given a callback for link status
436 * change. The phy_device is returned to the attaching driver. 439 * change. The phy_device is returned to the attaching driver.
437 */ 440 */
438int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, 441static int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
439 u32 flags, phy_interface_t interface) 442 u32 flags, phy_interface_t interface)
440{ 443{
441 struct device *d = &phydev->dev; 444 struct device *d = &phydev->dev;
442 445
@@ -473,7 +476,6 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
473 * (dev_flags and interface) */ 476 * (dev_flags and interface) */
474 return phy_init_hw(phydev); 477 return phy_init_hw(phydev);
475} 478}
476EXPORT_SYMBOL(phy_attach_direct);
477 479
478/** 480/**
479 * phy_attach - attach a network device to a particular PHY device 481 * phy_attach - attach a network device to a particular PHY device
@@ -540,7 +542,7 @@ EXPORT_SYMBOL(phy_detach);
540 * what is supported. Returns < 0 on error, 0 if the PHY's advertisement 542 * what is supported. Returns < 0 on error, 0 if the PHY's advertisement
541 * hasn't changed, and > 0 if it has changed. 543 * hasn't changed, and > 0 if it has changed.
542 */ 544 */
543int genphy_config_advert(struct phy_device *phydev) 545static int genphy_config_advert(struct phy_device *phydev)
544{ 546{
545 u32 advertise; 547 u32 advertise;
546 int oldadv, adv; 548 int oldadv, adv;
@@ -605,7 +607,6 @@ int genphy_config_advert(struct phy_device *phydev)
605 607
606 return changed; 608 return changed;
607} 609}
608EXPORT_SYMBOL(genphy_config_advert);
609 610
610/** 611/**
611 * genphy_setup_forced - configures/forces speed/duplex from @phydev 612 * genphy_setup_forced - configures/forces speed/duplex from @phydev
@@ -615,7 +616,7 @@ EXPORT_SYMBOL(genphy_config_advert);
615 * to the values in phydev. Assumes that the values are valid. 616 * to the values in phydev. Assumes that the values are valid.
616 * Please see phy_sanitize_settings(). 617 * Please see phy_sanitize_settings().
617 */ 618 */
618int genphy_setup_forced(struct phy_device *phydev) 619static int genphy_setup_forced(struct phy_device *phydev)
619{ 620{
620 int err; 621 int err;
621 int ctl = 0; 622 int ctl = 0;
diff --git a/drivers/net/qlcnic/qlcnic.h b/drivers/net/qlcnic/qlcnic.h
index 26c37d3a5868..8ecc170c9b74 100644
--- a/drivers/net/qlcnic/qlcnic.h
+++ b/drivers/net/qlcnic/qlcnic.h
@@ -146,11 +146,13 @@
146#define MAX_CMD_DESCRIPTORS 1024 146#define MAX_CMD_DESCRIPTORS 1024
147#define MAX_RCV_DESCRIPTORS_1G 4096 147#define MAX_RCV_DESCRIPTORS_1G 4096
148#define MAX_RCV_DESCRIPTORS_10G 8192 148#define MAX_RCV_DESCRIPTORS_10G 8192
149#define MAX_RCV_DESCRIPTORS_VF 2048
149#define MAX_JUMBO_RCV_DESCRIPTORS_1G 512 150#define MAX_JUMBO_RCV_DESCRIPTORS_1G 512
150#define MAX_JUMBO_RCV_DESCRIPTORS_10G 1024 151#define MAX_JUMBO_RCV_DESCRIPTORS_10G 1024
151 152
152#define DEFAULT_RCV_DESCRIPTORS_1G 2048 153#define DEFAULT_RCV_DESCRIPTORS_1G 2048
153#define DEFAULT_RCV_DESCRIPTORS_10G 4096 154#define DEFAULT_RCV_DESCRIPTORS_10G 4096
155#define DEFAULT_RCV_DESCRIPTORS_VF 1024
154#define MAX_RDS_RINGS 2 156#define MAX_RDS_RINGS 2
155 157
156#define get_next_index(index, length) \ 158#define get_next_index(index, length) \
@@ -942,6 +944,7 @@ struct qlcnic_ipaddr {
942#define QLCNIC_LOOPBACK_TEST 2 944#define QLCNIC_LOOPBACK_TEST 2
943 945
944#define QLCNIC_FILTER_AGE 80 946#define QLCNIC_FILTER_AGE 80
947#define QLCNIC_READD_AGE 20
945#define QLCNIC_LB_MAX_FILTERS 64 948#define QLCNIC_LB_MAX_FILTERS 64
946 949
947struct qlcnic_filter { 950struct qlcnic_filter {
@@ -970,6 +973,8 @@ struct qlcnic_adapter {
970 u16 num_txd; 973 u16 num_txd;
971 u16 num_rxd; 974 u16 num_rxd;
972 u16 num_jumbo_rxd; 975 u16 num_jumbo_rxd;
976 u16 max_rxd;
977 u16 max_jumbo_rxd;
973 978
974 u8 max_rds_rings; 979 u8 max_rds_rings;
975 u8 max_sds_rings; 980 u8 max_sds_rings;
@@ -1129,7 +1134,7 @@ struct qlcnic_eswitch {
1129#define MAX_RX_QUEUES 4 1134#define MAX_RX_QUEUES 4
1130#define DEFAULT_MAC_LEARN 1 1135#define DEFAULT_MAC_LEARN 1
1131 1136
1132#define IS_VALID_VLAN(vlan) (vlan >= MIN_VLAN_ID && vlan <= MAX_VLAN_ID) 1137#define IS_VALID_VLAN(vlan) (vlan >= MIN_VLAN_ID && vlan < MAX_VLAN_ID)
1133#define IS_VALID_BW(bw) (bw >= MIN_BW && bw <= MAX_BW) 1138#define IS_VALID_BW(bw) (bw >= MIN_BW && bw <= MAX_BW)
1134#define IS_VALID_TX_QUEUES(que) (que > 0 && que <= MAX_TX_QUEUES) 1139#define IS_VALID_TX_QUEUES(que) (que > 0 && que <= MAX_TX_QUEUES)
1135#define IS_VALID_RX_QUEUES(que) (que > 0 && que <= MAX_RX_QUEUES) 1140#define IS_VALID_RX_QUEUES(que) (que > 0 && que <= MAX_RX_QUEUES)
diff --git a/drivers/net/qlcnic/qlcnic_ethtool.c b/drivers/net/qlcnic/qlcnic_ethtool.c
index 25e93a53fca0..ec21d24015c4 100644
--- a/drivers/net/qlcnic/qlcnic_ethtool.c
+++ b/drivers/net/qlcnic/qlcnic_ethtool.c
@@ -437,14 +437,8 @@ qlcnic_get_ringparam(struct net_device *dev,
437 ring->rx_jumbo_pending = adapter->num_jumbo_rxd; 437 ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
438 ring->tx_pending = adapter->num_txd; 438 ring->tx_pending = adapter->num_txd;
439 439
440 if (adapter->ahw.port_type == QLCNIC_GBE) { 440 ring->rx_max_pending = adapter->max_rxd;
441 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G; 441 ring->rx_jumbo_max_pending = adapter->max_jumbo_rxd;
442 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G;
443 } else {
444 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
445 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G;
446 }
447
448 ring->tx_max_pending = MAX_CMD_DESCRIPTORS; 442 ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
449 443
450 ring->rx_mini_max_pending = 0; 444 ring->rx_mini_max_pending = 0;
@@ -472,24 +466,17 @@ qlcnic_set_ringparam(struct net_device *dev,
472 struct ethtool_ringparam *ring) 466 struct ethtool_ringparam *ring)
473{ 467{
474 struct qlcnic_adapter *adapter = netdev_priv(dev); 468 struct qlcnic_adapter *adapter = netdev_priv(dev);
475 u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G;
476 u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
477 u16 num_rxd, num_jumbo_rxd, num_txd; 469 u16 num_rxd, num_jumbo_rxd, num_txd;
478 470
479
480 if (ring->rx_mini_pending) 471 if (ring->rx_mini_pending)
481 return -EOPNOTSUPP; 472 return -EOPNOTSUPP;
482 473
483 if (adapter->ahw.port_type == QLCNIC_GBE) {
484 max_rcv_desc = MAX_RCV_DESCRIPTORS_1G;
485 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
486 }
487
488 num_rxd = qlcnic_validate_ringparam(ring->rx_pending, 474 num_rxd = qlcnic_validate_ringparam(ring->rx_pending,
489 MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx"); 475 MIN_RCV_DESCRIPTORS, adapter->max_rxd, "rx");
490 476
491 num_jumbo_rxd = qlcnic_validate_ringparam(ring->rx_jumbo_pending, 477 num_jumbo_rxd = qlcnic_validate_ringparam(ring->rx_jumbo_pending,
492 MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo"); 478 MIN_JUMBO_DESCRIPTORS, adapter->max_jumbo_rxd,
479 "rx jumbo");
493 480
494 num_txd = qlcnic_validate_ringparam(ring->tx_pending, 481 num_txd = qlcnic_validate_ringparam(ring->tx_pending,
495 MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx"); 482 MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
diff --git a/drivers/net/qlcnic/qlcnic_main.c b/drivers/net/qlcnic/qlcnic_main.c
index f047c7c48314..7a298cdf9ab3 100644
--- a/drivers/net/qlcnic/qlcnic_main.c
+++ b/drivers/net/qlcnic/qlcnic_main.c
@@ -656,13 +656,23 @@ qlcnic_check_options(struct qlcnic_adapter *adapter)
656 656
657 dev_info(&pdev->dev, "firmware v%d.%d.%d\n", 657 dev_info(&pdev->dev, "firmware v%d.%d.%d\n",
658 fw_major, fw_minor, fw_build); 658 fw_major, fw_minor, fw_build);
659
660 if (adapter->ahw.port_type == QLCNIC_XGBE) { 659 if (adapter->ahw.port_type == QLCNIC_XGBE) {
661 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; 660 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
661 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
662 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
663 } else {
664 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
665 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
666 }
667
662 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 668 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
669 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
670
663 } else if (adapter->ahw.port_type == QLCNIC_GBE) { 671 } else if (adapter->ahw.port_type == QLCNIC_GBE) {
664 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; 672 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
665 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 673 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
674 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
675 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
666 } 676 }
667 677
668 adapter->msix_supported = !!use_msi_x; 678 adapter->msix_supported = !!use_msi_x;
@@ -1860,6 +1870,11 @@ qlcnic_send_filter(struct qlcnic_adapter *adapter,
1860 hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) { 1870 hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) {
1861 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) && 1871 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) &&
1862 tmp_fil->vlan_id == vlan_id) { 1872 tmp_fil->vlan_id == vlan_id) {
1873
1874 if (jiffies >
1875 (QLCNIC_READD_AGE * HZ + tmp_fil->ftime))
1876 qlcnic_change_filter(adapter, src_addr, vlan_id,
1877 tx_ring);
1863 tmp_fil->ftime = jiffies; 1878 tmp_fil->ftime = jiffies;
1864 return; 1879 return;
1865 } 1880 }
diff --git a/drivers/net/qlge/qlge.h b/drivers/net/qlge/qlge.h
index a478786840a6..22821398fc63 100644
--- a/drivers/net/qlge/qlge.h
+++ b/drivers/net/qlge/qlge.h
@@ -2226,7 +2226,6 @@ int ql_dump_risc_ram_area(struct ql_adapter *qdev, void *buf,
2226int ql_core_dump(struct ql_adapter *qdev, 2226int ql_core_dump(struct ql_adapter *qdev,
2227 struct ql_mpi_coredump *mpi_coredump); 2227 struct ql_mpi_coredump *mpi_coredump);
2228int ql_mb_about_fw(struct ql_adapter *qdev); 2228int ql_mb_about_fw(struct ql_adapter *qdev);
2229int ql_wol(struct ql_adapter *qdev);
2230int ql_mb_wol_set_magic(struct ql_adapter *qdev, u32 enable_wol); 2229int ql_mb_wol_set_magic(struct ql_adapter *qdev, u32 enable_wol);
2231int ql_mb_wol_mode(struct ql_adapter *qdev, u32 wol); 2230int ql_mb_wol_mode(struct ql_adapter *qdev, u32 wol);
2232int ql_mb_set_led_cfg(struct ql_adapter *qdev, u32 led_config); 2231int ql_mb_set_led_cfg(struct ql_adapter *qdev, u32 led_config);
@@ -2243,16 +2242,13 @@ netdev_tx_t ql_lb_send(struct sk_buff *skb, struct net_device *ndev);
2243void ql_check_lb_frame(struct ql_adapter *, struct sk_buff *); 2242void ql_check_lb_frame(struct ql_adapter *, struct sk_buff *);
2244int ql_own_firmware(struct ql_adapter *qdev); 2243int ql_own_firmware(struct ql_adapter *qdev);
2245int ql_clean_lb_rx_ring(struct rx_ring *rx_ring, int budget); 2244int ql_clean_lb_rx_ring(struct rx_ring *rx_ring, int budget);
2246void qlge_set_multicast_list(struct net_device *ndev);
2247 2245
2248#if 1 2246/* #define QL_ALL_DUMP */
2249#define QL_ALL_DUMP 2247/* #define QL_REG_DUMP */
2250#define QL_REG_DUMP 2248/* #define QL_DEV_DUMP */
2251#define QL_DEV_DUMP 2249/* #define QL_CB_DUMP */
2252#define QL_CB_DUMP
2253/* #define QL_IB_DUMP */ 2250/* #define QL_IB_DUMP */
2254/* #define QL_OB_DUMP */ 2251/* #define QL_OB_DUMP */
2255#endif
2256 2252
2257#ifdef QL_REG_DUMP 2253#ifdef QL_REG_DUMP
2258extern void ql_dump_xgmac_control_regs(struct ql_adapter *qdev); 2254extern void ql_dump_xgmac_control_regs(struct ql_adapter *qdev);
diff --git a/drivers/net/qlge/qlge_main.c b/drivers/net/qlge/qlge_main.c
index ba0053d8515e..c30e0fe55a31 100644
--- a/drivers/net/qlge/qlge_main.c
+++ b/drivers/net/qlge/qlge_main.c
@@ -94,6 +94,9 @@ static DEFINE_PCI_DEVICE_TABLE(qlge_pci_tbl) = {
94 94
95MODULE_DEVICE_TABLE(pci, qlge_pci_tbl); 95MODULE_DEVICE_TABLE(pci, qlge_pci_tbl);
96 96
97static int ql_wol(struct ql_adapter *qdev);
98static void qlge_set_multicast_list(struct net_device *ndev);
99
97/* This hardware semaphore causes exclusive access to 100/* This hardware semaphore causes exclusive access to
98 * resources shared between the NIC driver, MPI firmware, 101 * resources shared between the NIC driver, MPI firmware,
99 * FCOE firmware and the FC driver. 102 * FCOE firmware and the FC driver.
@@ -2382,6 +2385,20 @@ static void qlge_vlan_rx_kill_vid(struct net_device *ndev, u16 vid)
2382 2385
2383} 2386}
2384 2387
2388static void qlge_restore_vlan(struct ql_adapter *qdev)
2389{
2390 qlge_vlan_rx_register(qdev->ndev, qdev->vlgrp);
2391
2392 if (qdev->vlgrp) {
2393 u16 vid;
2394 for (vid = 0; vid < VLAN_N_VID; vid++) {
2395 if (!vlan_group_get_device(qdev->vlgrp, vid))
2396 continue;
2397 qlge_vlan_rx_add_vid(qdev->ndev, vid);
2398 }
2399 }
2400}
2401
2385/* MSI-X Multiple Vector Interrupt Handler for inbound completions. */ 2402/* MSI-X Multiple Vector Interrupt Handler for inbound completions. */
2386static irqreturn_t qlge_msix_rx_isr(int irq, void *dev_id) 2403static irqreturn_t qlge_msix_rx_isr(int irq, void *dev_id)
2387{ 2404{
@@ -3842,7 +3859,7 @@ static void ql_display_dev_info(struct net_device *ndev)
3842 "MAC address %pM\n", ndev->dev_addr); 3859 "MAC address %pM\n", ndev->dev_addr);
3843} 3860}
3844 3861
3845int ql_wol(struct ql_adapter *qdev) 3862static int ql_wol(struct ql_adapter *qdev)
3846{ 3863{
3847 int status = 0; 3864 int status = 0;
3848 u32 wol = MB_WOL_DISABLE; 3865 u32 wol = MB_WOL_DISABLE;
@@ -3957,6 +3974,9 @@ static int ql_adapter_up(struct ql_adapter *qdev)
3957 clear_bit(QL_PROMISCUOUS, &qdev->flags); 3974 clear_bit(QL_PROMISCUOUS, &qdev->flags);
3958 qlge_set_multicast_list(qdev->ndev); 3975 qlge_set_multicast_list(qdev->ndev);
3959 3976
3977 /* Restore vlan setting. */
3978 qlge_restore_vlan(qdev);
3979
3960 ql_enable_interrupts(qdev); 3980 ql_enable_interrupts(qdev);
3961 ql_enable_all_completion_interrupts(qdev); 3981 ql_enable_all_completion_interrupts(qdev);
3962 netif_tx_start_all_queues(qdev->ndev); 3982 netif_tx_start_all_queues(qdev->ndev);
@@ -4242,7 +4262,7 @@ static struct net_device_stats *qlge_get_stats(struct net_device
4242 return &ndev->stats; 4262 return &ndev->stats;
4243} 4263}
4244 4264
4245void qlge_set_multicast_list(struct net_device *ndev) 4265static void qlge_set_multicast_list(struct net_device *ndev)
4246{ 4266{
4247 struct ql_adapter *qdev = (struct ql_adapter *)netdev_priv(ndev); 4267 struct ql_adapter *qdev = (struct ql_adapter *)netdev_priv(ndev);
4248 struct netdev_hw_addr *ha; 4268 struct netdev_hw_addr *ha;
diff --git a/drivers/net/qlge/qlge_mpi.c b/drivers/net/qlge/qlge_mpi.c
index f84e8570c7cb..0e7c7c7ee164 100644
--- a/drivers/net/qlge/qlge_mpi.c
+++ b/drivers/net/qlge/qlge_mpi.c
@@ -87,7 +87,7 @@ exit:
87 return status; 87 return status;
88} 88}
89 89
90int ql_soft_reset_mpi_risc(struct ql_adapter *qdev) 90static int ql_soft_reset_mpi_risc(struct ql_adapter *qdev)
91{ 91{
92 int status; 92 int status;
93 status = ql_write_mpi_reg(qdev, 0x00001010, 1); 93 status = ql_write_mpi_reg(qdev, 0x00001010, 1);
@@ -681,7 +681,7 @@ int ql_mb_get_fw_state(struct ql_adapter *qdev)
681/* Send and ACK mailbox command to the firmware to 681/* Send and ACK mailbox command to the firmware to
682 * let it continue with the change. 682 * let it continue with the change.
683 */ 683 */
684int ql_mb_idc_ack(struct ql_adapter *qdev) 684static int ql_mb_idc_ack(struct ql_adapter *qdev)
685{ 685{
686 struct mbox_params mbc; 686 struct mbox_params mbc;
687 struct mbox_params *mbcp = &mbc; 687 struct mbox_params *mbcp = &mbc;
@@ -744,7 +744,7 @@ int ql_mb_set_port_cfg(struct ql_adapter *qdev)
744 return status; 744 return status;
745} 745}
746 746
747int ql_mb_dump_ram(struct ql_adapter *qdev, u64 req_dma, u32 addr, 747static int ql_mb_dump_ram(struct ql_adapter *qdev, u64 req_dma, u32 addr,
748 u32 size) 748 u32 size)
749{ 749{
750 int status = 0; 750 int status = 0;
diff --git a/drivers/net/sb1000.c b/drivers/net/sb1000.c
index a9ae505e1baf..66c2f1a01963 100644
--- a/drivers/net/sb1000.c
+++ b/drivers/net/sb1000.c
@@ -961,9 +961,9 @@ sb1000_open(struct net_device *dev)
961 lp->rx_error_count = 0; 961 lp->rx_error_count = 0;
962 lp->rx_error_dpc_count = 0; 962 lp->rx_error_dpc_count = 0;
963 lp->rx_session_id[0] = 0x50; 963 lp->rx_session_id[0] = 0x50;
964 lp->rx_session_id[0] = 0x48; 964 lp->rx_session_id[1] = 0x48;
965 lp->rx_session_id[0] = 0x44; 965 lp->rx_session_id[2] = 0x44;
966 lp->rx_session_id[0] = 0x42; 966 lp->rx_session_id[3] = 0x42;
967 lp->rx_frame_id[0] = 0; 967 lp->rx_frame_id[0] = 0;
968 lp->rx_frame_id[1] = 0; 968 lp->rx_frame_id[1] = 0;
969 lp->rx_frame_id[2] = 0; 969 lp->rx_frame_id[2] = 0;
diff --git a/drivers/net/sgiseeq.c b/drivers/net/sgiseeq.c
index 9265315baa0b..3a0cc63428ee 100644
--- a/drivers/net/sgiseeq.c
+++ b/drivers/net/sgiseeq.c
@@ -531,7 +531,7 @@ static int sgiseeq_open(struct net_device *dev)
531 531
532 if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) { 532 if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) {
533 printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq); 533 printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq);
534 err = -EAGAIN; 534 return -EAGAIN;
535 } 535 }
536 536
537 err = init_seeq(dev, sp, sregs); 537 err = init_seeq(dev, sp, sregs);
diff --git a/drivers/net/slhc.c b/drivers/net/slhc.c
index ac279fad9d45..ab9e3b785b5b 100644
--- a/drivers/net/slhc.c
+++ b/drivers/net/slhc.c
@@ -688,18 +688,8 @@ slhc_toss(struct slcompress *comp)
688 return 0; 688 return 0;
689} 689}
690 690
691
692/* VJ header compression */
693EXPORT_SYMBOL(slhc_init);
694EXPORT_SYMBOL(slhc_free);
695EXPORT_SYMBOL(slhc_remember);
696EXPORT_SYMBOL(slhc_compress);
697EXPORT_SYMBOL(slhc_uncompress);
698EXPORT_SYMBOL(slhc_toss);
699
700#else /* CONFIG_INET */ 691#else /* CONFIG_INET */
701 692
702
703int 693int
704slhc_toss(struct slcompress *comp) 694slhc_toss(struct slcompress *comp)
705{ 695{
@@ -738,6 +728,10 @@ slhc_init(int rslots, int tslots)
738 printk(KERN_DEBUG "Called IP function on non IP-system: slhc_init"); 728 printk(KERN_DEBUG "Called IP function on non IP-system: slhc_init");
739 return NULL; 729 return NULL;
740} 730}
731
732#endif /* CONFIG_INET */
733
734/* VJ header compression */
741EXPORT_SYMBOL(slhc_init); 735EXPORT_SYMBOL(slhc_init);
742EXPORT_SYMBOL(slhc_free); 736EXPORT_SYMBOL(slhc_free);
743EXPORT_SYMBOL(slhc_remember); 737EXPORT_SYMBOL(slhc_remember);
@@ -745,5 +739,4 @@ EXPORT_SYMBOL(slhc_compress);
745EXPORT_SYMBOL(slhc_uncompress); 739EXPORT_SYMBOL(slhc_uncompress);
746EXPORT_SYMBOL(slhc_toss); 740EXPORT_SYMBOL(slhc_toss);
747 741
748#endif /* CONFIG_INET */
749MODULE_LICENSE("Dual BSD/GPL"); 742MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 852e917778f8..30ccbb6d097a 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -9948,16 +9948,16 @@ static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
9948 !((tp->tg3_flags & TG3_FLAG_WOL_CAP) && device_can_wakeup(dp))) 9948 !((tp->tg3_flags & TG3_FLAG_WOL_CAP) && device_can_wakeup(dp)))
9949 return -EINVAL; 9949 return -EINVAL;
9950 9950
9951 device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC);
9952
9951 spin_lock_bh(&tp->lock); 9953 spin_lock_bh(&tp->lock);
9952 if (wol->wolopts & WAKE_MAGIC) { 9954 if (device_may_wakeup(dp))
9953 tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; 9955 tp->tg3_flags |= TG3_FLAG_WOL_ENABLE;
9954 device_set_wakeup_enable(dp, true); 9956 else
9955 } else {
9956 tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE; 9957 tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE;
9957 device_set_wakeup_enable(dp, false);
9958 }
9959 spin_unlock_bh(&tp->lock); 9958 spin_unlock_bh(&tp->lock);
9960 9959
9960
9961 return 0; 9961 return 0;
9962} 9962}
9963 9963
diff --git a/drivers/net/tokenring/tms380tr.c b/drivers/net/tokenring/tms380tr.c
index 663b8860a531..793020347e54 100644
--- a/drivers/net/tokenring/tms380tr.c
+++ b/drivers/net/tokenring/tms380tr.c
@@ -1220,7 +1220,7 @@ void tms380tr_wait(unsigned long time)
1220 tmp = schedule_timeout_interruptible(tmp); 1220 tmp = schedule_timeout_interruptible(tmp);
1221 } while(time_after(tmp, jiffies)); 1221 } while(time_after(tmp, jiffies));
1222#else 1222#else
1223 udelay(time); 1223 mdelay(time / 1000);
1224#endif 1224#endif
1225} 1225}
1226 1226
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index 1cc67138adbf..5b83c3f35f47 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -24,10 +24,6 @@
24 3XP Processor. It has been tested on x86 and sparc64. 24 3XP Processor. It has been tested on x86 and sparc64.
25 25
26 KNOWN ISSUES: 26 KNOWN ISSUES:
27 *) The current firmware always strips the VLAN tag off, even if
28 we tell it not to. You should filter VLANs at the switch
29 as a workaround (good practice in any event) until we can
30 get this fixed.
31 *) Cannot DMA Rx packets to a 2 byte aligned address. Also firmware 27 *) Cannot DMA Rx packets to a 2 byte aligned address. Also firmware
32 issue. Hopefully 3Com will fix it. 28 issue. Hopefully 3Com will fix it.
33 *) Waiting for a command response takes 8ms due to non-preemptable 29 *) Waiting for a command response takes 8ms due to non-preemptable
@@ -280,8 +276,6 @@ struct typhoon {
280 struct pci_dev * pdev; 276 struct pci_dev * pdev;
281 struct net_device * dev; 277 struct net_device * dev;
282 struct napi_struct napi; 278 struct napi_struct napi;
283 spinlock_t state_lock;
284 struct vlan_group * vlgrp;
285 struct basic_ring rxHiRing; 279 struct basic_ring rxHiRing;
286 struct basic_ring rxBuffRing; 280 struct basic_ring rxBuffRing;
287 struct rxbuff_ent rxbuffers[RXENT_ENTRIES]; 281 struct rxbuff_ent rxbuffers[RXENT_ENTRIES];
@@ -695,44 +689,6 @@ out:
695 return err; 689 return err;
696} 690}
697 691
698static void
699typhoon_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
700{
701 struct typhoon *tp = netdev_priv(dev);
702 struct cmd_desc xp_cmd;
703 int err;
704
705 spin_lock_bh(&tp->state_lock);
706 if(!tp->vlgrp != !grp) {
707 /* We've either been turned on for the first time, or we've
708 * been turned off. Update the 3XP.
709 */
710 if(grp)
711 tp->offload |= TYPHOON_OFFLOAD_VLAN;
712 else
713 tp->offload &= ~TYPHOON_OFFLOAD_VLAN;
714
715 /* If the interface is up, the runtime is running -- and we
716 * must be up for the vlan core to call us.
717 *
718 * Do the command outside of the spin lock, as it is slow.
719 */
720 INIT_COMMAND_WITH_RESPONSE(&xp_cmd,
721 TYPHOON_CMD_SET_OFFLOAD_TASKS);
722 xp_cmd.parm2 = tp->offload;
723 xp_cmd.parm3 = tp->offload;
724 spin_unlock_bh(&tp->state_lock);
725 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
726 if(err < 0)
727 netdev_err(tp->dev, "vlan offload error %d\n", -err);
728 spin_lock_bh(&tp->state_lock);
729 }
730
731 /* now make the change visible */
732 tp->vlgrp = grp;
733 spin_unlock_bh(&tp->state_lock);
734}
735
736static inline void 692static inline void
737typhoon_tso_fill(struct sk_buff *skb, struct transmit_ring *txRing, 693typhoon_tso_fill(struct sk_buff *skb, struct transmit_ring *txRing,
738 u32 ring_dma) 694 u32 ring_dma)
@@ -818,7 +774,7 @@ typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
818 first_txd->processFlags |= 774 first_txd->processFlags |=
819 TYPHOON_TX_PF_INSERT_VLAN | TYPHOON_TX_PF_VLAN_PRIORITY; 775 TYPHOON_TX_PF_INSERT_VLAN | TYPHOON_TX_PF_VLAN_PRIORITY;
820 first_txd->processFlags |= 776 first_txd->processFlags |=
821 cpu_to_le32(ntohs(vlan_tx_tag_get(skb)) << 777 cpu_to_le32(htons(vlan_tx_tag_get(skb)) <<
822 TYPHOON_TX_PF_VLAN_TAG_SHIFT); 778 TYPHOON_TX_PF_VLAN_TAG_SHIFT);
823 } 779 }
824 780
@@ -936,7 +892,7 @@ typhoon_set_rx_mode(struct net_device *dev)
936 filter |= TYPHOON_RX_FILTER_MCAST_HASH; 892 filter |= TYPHOON_RX_FILTER_MCAST_HASH;
937 } 893 }
938 894
939 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_RX_FILTER); 895 INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_RX_FILTER);
940 xp_cmd.parm1 = filter; 896 xp_cmd.parm1 = filter;
941 typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL); 897 typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
942} 898}
@@ -1198,6 +1154,20 @@ typhoon_get_rx_csum(struct net_device *dev)
1198 return 1; 1154 return 1;
1199} 1155}
1200 1156
1157static int
1158typhoon_set_flags(struct net_device *dev, u32 data)
1159{
1160 /* There's no way to turn off the RX VLAN offloading and stripping
1161 * on the current 3XP firmware -- it does not respect the offload
1162 * settings -- so we only allow the user to toggle the TX processing.
1163 */
1164 if (!(data & ETH_FLAG_RXVLAN))
1165 return -EINVAL;
1166
1167 return ethtool_op_set_flags(dev, data,
1168 ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN);
1169}
1170
1201static void 1171static void
1202typhoon_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) 1172typhoon_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
1203{ 1173{
@@ -1224,6 +1194,8 @@ static const struct ethtool_ops typhoon_ethtool_ops = {
1224 .set_sg = ethtool_op_set_sg, 1194 .set_sg = ethtool_op_set_sg,
1225 .set_tso = ethtool_op_set_tso, 1195 .set_tso = ethtool_op_set_tso,
1226 .get_ringparam = typhoon_get_ringparam, 1196 .get_ringparam = typhoon_get_ringparam,
1197 .set_flags = typhoon_set_flags,
1198 .get_flags = ethtool_op_get_flags,
1227}; 1199};
1228 1200
1229static int 1201static int
@@ -1309,9 +1281,9 @@ typhoon_init_interface(struct typhoon *tp)
1309 1281
1310 tp->offload = TYPHOON_OFFLOAD_IP_CHKSUM | TYPHOON_OFFLOAD_TCP_CHKSUM; 1282 tp->offload = TYPHOON_OFFLOAD_IP_CHKSUM | TYPHOON_OFFLOAD_TCP_CHKSUM;
1311 tp->offload |= TYPHOON_OFFLOAD_UDP_CHKSUM | TSO_OFFLOAD_ON; 1283 tp->offload |= TYPHOON_OFFLOAD_UDP_CHKSUM | TSO_OFFLOAD_ON;
1284 tp->offload |= TYPHOON_OFFLOAD_VLAN;
1312 1285
1313 spin_lock_init(&tp->command_lock); 1286 spin_lock_init(&tp->command_lock);
1314 spin_lock_init(&tp->state_lock);
1315 1287
1316 /* Force the writes to the shared memory area out before continuing. */ 1288 /* Force the writes to the shared memory area out before continuing. */
1317 wmb(); 1289 wmb();
@@ -1328,7 +1300,7 @@ typhoon_init_rings(struct typhoon *tp)
1328 tp->rxHiRing.lastWrite = 0; 1300 tp->rxHiRing.lastWrite = 0;
1329 tp->rxBuffRing.lastWrite = 0; 1301 tp->rxBuffRing.lastWrite = 0;
1330 tp->cmdRing.lastWrite = 0; 1302 tp->cmdRing.lastWrite = 0;
1331 tp->cmdRing.lastWrite = 0; 1303 tp->respRing.lastWrite = 0;
1332 1304
1333 tp->txLoRing.lastRead = 0; 1305 tp->txLoRing.lastRead = 0;
1334 tp->txHiRing.lastRead = 0; 1306 tp->txHiRing.lastRead = 0;
@@ -1762,13 +1734,10 @@ typhoon_rx(struct typhoon *tp, struct basic_ring *rxRing, volatile __le32 * read
1762 } else 1734 } else
1763 skb_checksum_none_assert(new_skb); 1735 skb_checksum_none_assert(new_skb);
1764 1736
1765 spin_lock(&tp->state_lock); 1737 if (rx->rxStatus & TYPHOON_RX_VLAN)
1766 if(tp->vlgrp != NULL && rx->rxStatus & TYPHOON_RX_VLAN) 1738 __vlan_hwaccel_put_tag(new_skb,
1767 vlan_hwaccel_receive_skb(new_skb, tp->vlgrp, 1739 ntohl(rx->vlanTag) & 0xffff);
1768 ntohl(rx->vlanTag) & 0xffff); 1740 netif_receive_skb(new_skb);
1769 else
1770 netif_receive_skb(new_skb);
1771 spin_unlock(&tp->state_lock);
1772 1741
1773 received++; 1742 received++;
1774 budget--; 1743 budget--;
@@ -1989,11 +1958,9 @@ typhoon_start_runtime(struct typhoon *tp)
1989 goto error_out; 1958 goto error_out;
1990 1959
1991 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_OFFLOAD_TASKS); 1960 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_OFFLOAD_TASKS);
1992 spin_lock_bh(&tp->state_lock);
1993 xp_cmd.parm2 = tp->offload; 1961 xp_cmd.parm2 = tp->offload;
1994 xp_cmd.parm3 = tp->offload; 1962 xp_cmd.parm3 = tp->offload;
1995 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL); 1963 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1996 spin_unlock_bh(&tp->state_lock);
1997 if(err < 0) 1964 if(err < 0)
1998 goto error_out; 1965 goto error_out;
1999 1966
@@ -2231,13 +2198,9 @@ typhoon_suspend(struct pci_dev *pdev, pm_message_t state)
2231 if(!netif_running(dev)) 2198 if(!netif_running(dev))
2232 return 0; 2199 return 0;
2233 2200
2234 spin_lock_bh(&tp->state_lock); 2201 /* TYPHOON_OFFLOAD_VLAN is always on now, so this doesn't work */
2235 if(tp->vlgrp && tp->wol_events & TYPHOON_WAKE_MAGIC_PKT) { 2202 if(tp->wol_events & TYPHOON_WAKE_MAGIC_PKT)
2236 spin_unlock_bh(&tp->state_lock); 2203 netdev_warn(dev, "cannot do WAKE_MAGIC with VLAN offloading\n");
2237 netdev_err(dev, "cannot do WAKE_MAGIC with VLANS\n");
2238 return -EBUSY;
2239 }
2240 spin_unlock_bh(&tp->state_lock);
2241 2204
2242 netif_device_detach(dev); 2205 netif_device_detach(dev);
2243 2206
@@ -2338,7 +2301,6 @@ static const struct net_device_ops typhoon_netdev_ops = {
2338 .ndo_validate_addr = eth_validate_addr, 2301 .ndo_validate_addr = eth_validate_addr,
2339 .ndo_set_mac_address = typhoon_set_mac_address, 2302 .ndo_set_mac_address = typhoon_set_mac_address,
2340 .ndo_change_mtu = eth_change_mtu, 2303 .ndo_change_mtu = eth_change_mtu,
2341 .ndo_vlan_rx_register = typhoon_vlan_rx_register,
2342}; 2304};
2343 2305
2344static int __devinit 2306static int __devinit
diff --git a/drivers/net/vmxnet3/upt1_defs.h b/drivers/net/vmxnet3/upt1_defs.h
index 37108fb226d3..969c751ee404 100644
--- a/drivers/net/vmxnet3/upt1_defs.h
+++ b/drivers/net/vmxnet3/upt1_defs.h
@@ -88,9 +88,9 @@ struct UPT1_RSSConf {
88 88
89/* features */ 89/* features */
90enum { 90enum {
91 UPT1_F_RXCSUM = 0x0001, /* rx csum verification */ 91 UPT1_F_RXCSUM = cpu_to_le64(0x0001), /* rx csum verification */
92 UPT1_F_RSS = 0x0002, 92 UPT1_F_RSS = cpu_to_le64(0x0002),
93 UPT1_F_RXVLAN = 0x0004, /* VLAN tag stripping */ 93 UPT1_F_RXVLAN = cpu_to_le64(0x0004), /* VLAN tag stripping */
94 UPT1_F_LRO = 0x0008, 94 UPT1_F_LRO = cpu_to_le64(0x0008),
95}; 95};
96#endif 96#endif
diff --git a/drivers/net/vmxnet3/vmxnet3_defs.h b/drivers/net/vmxnet3/vmxnet3_defs.h
index ca7727b940ad..4d84912c99ba 100644
--- a/drivers/net/vmxnet3/vmxnet3_defs.h
+++ b/drivers/net/vmxnet3/vmxnet3_defs.h
@@ -523,9 +523,9 @@ struct Vmxnet3_RxFilterConf {
523#define VMXNET3_PM_MAX_PATTERN_SIZE 128 523#define VMXNET3_PM_MAX_PATTERN_SIZE 128
524#define VMXNET3_PM_MAX_MASK_SIZE (VMXNET3_PM_MAX_PATTERN_SIZE / 8) 524#define VMXNET3_PM_MAX_MASK_SIZE (VMXNET3_PM_MAX_PATTERN_SIZE / 8)
525 525
526#define VMXNET3_PM_WAKEUP_MAGIC 0x01 /* wake up on magic pkts */ 526#define VMXNET3_PM_WAKEUP_MAGIC cpu_to_le16(0x01) /* wake up on magic pkts */
527#define VMXNET3_PM_WAKEUP_FILTER 0x02 /* wake up on pkts matching 527#define VMXNET3_PM_WAKEUP_FILTER cpu_to_le16(0x02) /* wake up on pkts matching
528 * filters */ 528 * filters */
529 529
530 530
531struct Vmxnet3_PM_PktFilter { 531struct Vmxnet3_PM_PktFilter {
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
index 3f60e0e3097b..e3658e10db39 100644
--- a/drivers/net/vmxnet3/vmxnet3_drv.c
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -1563,8 +1563,7 @@ vmxnet3_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
1563 adapter->vlan_grp = grp; 1563 adapter->vlan_grp = grp;
1564 1564
1565 /* update FEATURES to device */ 1565 /* update FEATURES to device */
1566 set_flag_le64(&devRead->misc.uptFeatures, 1566 devRead->misc.uptFeatures |= UPT1_F_RXVLAN;
1567 UPT1_F_RXVLAN);
1568 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, 1567 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1569 VMXNET3_CMD_UPDATE_FEATURE); 1568 VMXNET3_CMD_UPDATE_FEATURE);
1570 /* 1569 /*
@@ -1587,7 +1586,7 @@ vmxnet3_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
1587 struct Vmxnet3_DSDevRead *devRead = &shared->devRead; 1586 struct Vmxnet3_DSDevRead *devRead = &shared->devRead;
1588 adapter->vlan_grp = NULL; 1587 adapter->vlan_grp = NULL;
1589 1588
1590 if (le64_to_cpu(devRead->misc.uptFeatures) & UPT1_F_RXVLAN) { 1589 if (devRead->misc.uptFeatures & UPT1_F_RXVLAN) {
1591 int i; 1590 int i;
1592 1591
1593 for (i = 0; i < VMXNET3_VFT_SIZE; i++) { 1592 for (i = 0; i < VMXNET3_VFT_SIZE; i++) {
@@ -1600,8 +1599,7 @@ vmxnet3_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
1600 VMXNET3_CMD_UPDATE_VLAN_FILTERS); 1599 VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1601 1600
1602 /* update FEATURES to device */ 1601 /* update FEATURES to device */
1603 reset_flag_le64(&devRead->misc.uptFeatures, 1602 devRead->misc.uptFeatures &= ~UPT1_F_RXVLAN;
1604 UPT1_F_RXVLAN);
1605 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, 1603 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1606 VMXNET3_CMD_UPDATE_FEATURE); 1604 VMXNET3_CMD_UPDATE_FEATURE);
1607 } 1605 }
@@ -1762,15 +1760,15 @@ vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter)
1762 1760
1763 /* set up feature flags */ 1761 /* set up feature flags */
1764 if (adapter->rxcsum) 1762 if (adapter->rxcsum)
1765 set_flag_le64(&devRead->misc.uptFeatures, UPT1_F_RXCSUM); 1763 devRead->misc.uptFeatures |= UPT1_F_RXCSUM;
1766 1764
1767 if (adapter->lro) { 1765 if (adapter->lro) {
1768 set_flag_le64(&devRead->misc.uptFeatures, UPT1_F_LRO); 1766 devRead->misc.uptFeatures |= UPT1_F_LRO;
1769 devRead->misc.maxNumRxSG = cpu_to_le16(1 + MAX_SKB_FRAGS); 1767 devRead->misc.maxNumRxSG = cpu_to_le16(1 + MAX_SKB_FRAGS);
1770 } 1768 }
1771 if ((adapter->netdev->features & NETIF_F_HW_VLAN_RX) && 1769 if ((adapter->netdev->features & NETIF_F_HW_VLAN_RX) &&
1772 adapter->vlan_grp) { 1770 adapter->vlan_grp) {
1773 set_flag_le64(&devRead->misc.uptFeatures, UPT1_F_RXVLAN); 1771 devRead->misc.uptFeatures |= UPT1_F_RXVLAN;
1774 } 1772 }
1775 1773
1776 devRead->misc.mtu = cpu_to_le32(adapter->netdev->mtu); 1774 devRead->misc.mtu = cpu_to_le32(adapter->netdev->mtu);
@@ -2577,7 +2575,7 @@ vmxnet3_suspend(struct device *device)
2577 memcpy(pmConf->filters[i].pattern, netdev->dev_addr, ETH_ALEN); 2575 memcpy(pmConf->filters[i].pattern, netdev->dev_addr, ETH_ALEN);
2578 pmConf->filters[i].mask[0] = 0x3F; /* LSB ETH_ALEN bits */ 2576 pmConf->filters[i].mask[0] = 0x3F; /* LSB ETH_ALEN bits */
2579 2577
2580 set_flag_le16(&pmConf->wakeUpEvents, VMXNET3_PM_WAKEUP_FILTER); 2578 pmConf->wakeUpEvents |= VMXNET3_PM_WAKEUP_FILTER;
2581 i++; 2579 i++;
2582 } 2580 }
2583 2581
@@ -2619,13 +2617,13 @@ vmxnet3_suspend(struct device *device)
2619 pmConf->filters[i].mask[5] = 0x03; /* IPv4 TIP */ 2617 pmConf->filters[i].mask[5] = 0x03; /* IPv4 TIP */
2620 in_dev_put(in_dev); 2618 in_dev_put(in_dev);
2621 2619
2622 set_flag_le16(&pmConf->wakeUpEvents, VMXNET3_PM_WAKEUP_FILTER); 2620 pmConf->wakeUpEvents |= VMXNET3_PM_WAKEUP_FILTER;
2623 i++; 2621 i++;
2624 } 2622 }
2625 2623
2626skip_arp: 2624skip_arp:
2627 if (adapter->wol & WAKE_MAGIC) 2625 if (adapter->wol & WAKE_MAGIC)
2628 set_flag_le16(&pmConf->wakeUpEvents, VMXNET3_PM_WAKEUP_MAGIC); 2626 pmConf->wakeUpEvents |= VMXNET3_PM_WAKEUP_MAGIC;
2629 2627
2630 pmConf->numFilters = i; 2628 pmConf->numFilters = i;
2631 2629
@@ -2667,7 +2665,7 @@ vmxnet3_resume(struct device *device)
2667 adapter->shared->devRead.pmConfDesc.confVer = cpu_to_le32(1); 2665 adapter->shared->devRead.pmConfDesc.confVer = cpu_to_le32(1);
2668 adapter->shared->devRead.pmConfDesc.confLen = cpu_to_le32(sizeof( 2666 adapter->shared->devRead.pmConfDesc.confLen = cpu_to_le32(sizeof(
2669 *pmConf)); 2667 *pmConf));
2670 adapter->shared->devRead.pmConfDesc.confPA = cpu_to_le32(virt_to_phys( 2668 adapter->shared->devRead.pmConfDesc.confPA = cpu_to_le64(virt_to_phys(
2671 pmConf)); 2669 pmConf));
2672 2670
2673 netif_device_attach(netdev); 2671 netif_device_attach(netdev);
diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
index 7e4b5a89165a..b79070bcc92e 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
@@ -50,13 +50,11 @@ vmxnet3_set_rx_csum(struct net_device *netdev, u32 val)
50 adapter->rxcsum = val; 50 adapter->rxcsum = val;
51 if (netif_running(netdev)) { 51 if (netif_running(netdev)) {
52 if (val) 52 if (val)
53 set_flag_le64( 53 adapter->shared->devRead.misc.uptFeatures |=
54 &adapter->shared->devRead.misc.uptFeatures, 54 UPT1_F_RXCSUM;
55 UPT1_F_RXCSUM);
56 else 55 else
57 reset_flag_le64( 56 adapter->shared->devRead.misc.uptFeatures &=
58 &adapter->shared->devRead.misc.uptFeatures, 57 ~UPT1_F_RXCSUM;
59 UPT1_F_RXCSUM);
60 58
61 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, 59 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
62 VMXNET3_CMD_UPDATE_FEATURE); 60 VMXNET3_CMD_UPDATE_FEATURE);
@@ -292,10 +290,10 @@ vmxnet3_set_flags(struct net_device *netdev, u32 data)
292 /* update harware LRO capability accordingly */ 290 /* update harware LRO capability accordingly */
293 if (lro_requested) 291 if (lro_requested)
294 adapter->shared->devRead.misc.uptFeatures |= 292 adapter->shared->devRead.misc.uptFeatures |=
295 cpu_to_le64(UPT1_F_LRO); 293 UPT1_F_LRO;
296 else 294 else
297 adapter->shared->devRead.misc.uptFeatures &= 295 adapter->shared->devRead.misc.uptFeatures &=
298 cpu_to_le64(~UPT1_F_LRO); 296 ~UPT1_F_LRO;
299 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, 297 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
300 VMXNET3_CMD_UPDATE_FEATURE); 298 VMXNET3_CMD_UPDATE_FEATURE);
301 } 299 }
diff --git a/drivers/net/vmxnet3/vmxnet3_int.h b/drivers/net/vmxnet3/vmxnet3_int.h
index c88ea5cbba0d..8a2f4712284c 100644
--- a/drivers/net/vmxnet3/vmxnet3_int.h
+++ b/drivers/net/vmxnet3/vmxnet3_int.h
@@ -301,8 +301,8 @@ struct vmxnet3_adapter {
301 struct net_device *netdev; 301 struct net_device *netdev;
302 struct pci_dev *pdev; 302 struct pci_dev *pdev;
303 303
304 u8 *hw_addr0; /* for BAR 0 */ 304 u8 __iomem *hw_addr0; /* for BAR 0 */
305 u8 *hw_addr1; /* for BAR 1 */ 305 u8 __iomem *hw_addr1; /* for BAR 1 */
306 306
307 /* feature control */ 307 /* feature control */
308 bool rxcsum; 308 bool rxcsum;
@@ -353,21 +353,6 @@ struct vmxnet3_adapter {
353#define VMXNET3_MAX_ETH_HDR_SIZE 22 353#define VMXNET3_MAX_ETH_HDR_SIZE 22
354#define VMXNET3_MAX_SKB_BUF_SIZE (3*1024) 354#define VMXNET3_MAX_SKB_BUF_SIZE (3*1024)
355 355
356static inline void set_flag_le16(__le16 *data, u16 flag)
357{
358 *data = cpu_to_le16(le16_to_cpu(*data) | flag);
359}
360
361static inline void set_flag_le64(__le64 *data, u64 flag)
362{
363 *data = cpu_to_le64(le64_to_cpu(*data) | flag);
364}
365
366static inline void reset_flag_le64(__le64 *data, u64 flag)
367{
368 *data = cpu_to_le64(le64_to_cpu(*data) & ~flag);
369}
370
371int 356int
372vmxnet3_quiesce_dev(struct vmxnet3_adapter *adapter); 357vmxnet3_quiesce_dev(struct vmxnet3_adapter *adapter);
373 358
diff --git a/drivers/net/vxge/vxge-config.c b/drivers/net/vxge/vxge-config.c
index 0e6db5935609..906a3ca3676b 100644
--- a/drivers/net/vxge/vxge-config.c
+++ b/drivers/net/vxge/vxge-config.c
@@ -20,6 +20,179 @@
20#include "vxge-traffic.h" 20#include "vxge-traffic.h"
21#include "vxge-config.h" 21#include "vxge-config.h"
22 22
23static enum vxge_hw_status
24__vxge_hw_fifo_create(
25 struct __vxge_hw_vpath_handle *vpath_handle,
26 struct vxge_hw_fifo_attr *attr);
27
28static enum vxge_hw_status
29__vxge_hw_fifo_abort(
30 struct __vxge_hw_fifo *fifoh);
31
32static enum vxge_hw_status
33__vxge_hw_fifo_reset(
34 struct __vxge_hw_fifo *ringh);
35
36static enum vxge_hw_status
37__vxge_hw_fifo_delete(
38 struct __vxge_hw_vpath_handle *vpath_handle);
39
40static struct __vxge_hw_blockpool_entry *
41__vxge_hw_blockpool_block_allocate(struct __vxge_hw_device *hldev,
42 u32 size);
43
44static void
45__vxge_hw_blockpool_block_free(struct __vxge_hw_device *hldev,
46 struct __vxge_hw_blockpool_entry *entry);
47
48static void vxge_hw_blockpool_block_add(struct __vxge_hw_device *devh,
49 void *block_addr,
50 u32 length,
51 struct pci_dev *dma_h,
52 struct pci_dev *acc_handle);
53
54static enum vxge_hw_status
55__vxge_hw_blockpool_create(struct __vxge_hw_device *hldev,
56 struct __vxge_hw_blockpool *blockpool,
57 u32 pool_size,
58 u32 pool_max);
59
60static void
61__vxge_hw_blockpool_destroy(struct __vxge_hw_blockpool *blockpool);
62
63static void *
64__vxge_hw_blockpool_malloc(struct __vxge_hw_device *hldev,
65 u32 size,
66 struct vxge_hw_mempool_dma *dma_object);
67
68static void
69__vxge_hw_blockpool_free(struct __vxge_hw_device *hldev,
70 void *memblock,
71 u32 size,
72 struct vxge_hw_mempool_dma *dma_object);
73
74
75static struct __vxge_hw_channel*
76__vxge_hw_channel_allocate(struct __vxge_hw_vpath_handle *vph,
77 enum __vxge_hw_channel_type type, u32 length,
78 u32 per_dtr_space, void *userdata);
79
80static void
81__vxge_hw_channel_free(
82 struct __vxge_hw_channel *channel);
83
84static enum vxge_hw_status
85__vxge_hw_channel_initialize(
86 struct __vxge_hw_channel *channel);
87
88static enum vxge_hw_status
89__vxge_hw_channel_reset(
90 struct __vxge_hw_channel *channel);
91
92static enum vxge_hw_status __vxge_hw_ring_delete(struct __vxge_hw_vpath_handle *vp);
93
94static enum vxge_hw_status
95__vxge_hw_device_fifo_config_check(struct vxge_hw_fifo_config *fifo_config);
96
97static enum vxge_hw_status
98__vxge_hw_device_config_check(struct vxge_hw_device_config *new_config);
99
100static void
101__vxge_hw_device_id_get(struct __vxge_hw_device *hldev);
102
103static void
104__vxge_hw_device_host_info_get(struct __vxge_hw_device *hldev);
105
106static enum vxge_hw_status
107__vxge_hw_vpath_card_info_get(
108 u32 vp_id,
109 struct vxge_hw_vpath_reg __iomem *vpath_reg,
110 struct vxge_hw_device_hw_info *hw_info);
111
112static enum vxge_hw_status
113__vxge_hw_device_initialize(struct __vxge_hw_device *hldev);
114
115static void
116__vxge_hw_device_pci_e_init(struct __vxge_hw_device *hldev);
117
118static enum vxge_hw_status
119__vxge_hw_device_reg_addr_get(struct __vxge_hw_device *hldev);
120
121static enum vxge_hw_status
122__vxge_hw_device_register_poll(
123 void __iomem *reg,
124 u64 mask, u32 max_millis);
125
126static inline enum vxge_hw_status
127__vxge_hw_pio_mem_write64(u64 val64, void __iomem *addr,
128 u64 mask, u32 max_millis)
129{
130 __vxge_hw_pio_mem_write32_lower((u32)vxge_bVALn(val64, 32, 32), addr);
131 wmb();
132
133 __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32), addr);
134 wmb();
135
136 return __vxge_hw_device_register_poll(addr, mask, max_millis);
137}
138
139static struct vxge_hw_mempool*
140__vxge_hw_mempool_create(struct __vxge_hw_device *devh, u32 memblock_size,
141 u32 item_size, u32 private_size, u32 items_initial,
142 u32 items_max, struct vxge_hw_mempool_cbs *mp_callback,
143 void *userdata);
144static void __vxge_hw_mempool_destroy(struct vxge_hw_mempool *mempool);
145
146static enum vxge_hw_status
147__vxge_hw_vpath_stats_get(struct __vxge_hw_virtualpath *vpath,
148 struct vxge_hw_vpath_stats_hw_info *hw_stats);
149
150static enum vxge_hw_status
151vxge_hw_vpath_stats_enable(struct __vxge_hw_vpath_handle *vpath_handle);
152
153static enum vxge_hw_status
154__vxge_hw_legacy_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg);
155
156static u64
157__vxge_hw_vpath_pci_func_mode_get(u32 vp_id,
158 struct vxge_hw_vpath_reg __iomem *vpath_reg);
159
160static u32
161__vxge_hw_vpath_func_id_get(u32 vp_id, struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg);
162
163static enum vxge_hw_status
164__vxge_hw_vpath_addr_get(u32 vp_id, struct vxge_hw_vpath_reg __iomem *vpath_reg,
165 u8 (macaddr)[ETH_ALEN], u8 (macaddr_mask)[ETH_ALEN]);
166
167static enum vxge_hw_status
168__vxge_hw_vpath_reset_check(struct __vxge_hw_virtualpath *vpath);
169
170
171static enum vxge_hw_status
172__vxge_hw_vpath_sw_reset(struct __vxge_hw_device *devh, u32 vp_id);
173
174static enum vxge_hw_status
175__vxge_hw_vpath_fw_ver_get(u32 vp_id, struct vxge_hw_vpath_reg __iomem *vpath_reg,
176 struct vxge_hw_device_hw_info *hw_info);
177
178static enum vxge_hw_status
179__vxge_hw_vpath_mac_configure(struct __vxge_hw_device *devh, u32 vp_id);
180
181static void
182__vxge_hw_vp_terminate(struct __vxge_hw_device *devh, u32 vp_id);
183
184static enum vxge_hw_status
185__vxge_hw_vpath_stats_access(struct __vxge_hw_virtualpath *vpath,
186 u32 operation, u32 offset, u64 *stat);
187
188static enum vxge_hw_status
189__vxge_hw_vpath_xmac_tx_stats_get(struct __vxge_hw_virtualpath *vpath,
190 struct vxge_hw_xmac_vpath_tx_stats *vpath_tx_stats);
191
192static enum vxge_hw_status
193__vxge_hw_vpath_xmac_rx_stats_get(struct __vxge_hw_virtualpath *vpath,
194 struct vxge_hw_xmac_vpath_rx_stats *vpath_rx_stats);
195
23/* 196/*
24 * __vxge_hw_channel_allocate - Allocate memory for channel 197 * __vxge_hw_channel_allocate - Allocate memory for channel
25 * This function allocates required memory for the channel and various arrays 198 * This function allocates required memory for the channel and various arrays
@@ -190,7 +363,7 @@ __vxge_hw_device_pci_e_init(struct __vxge_hw_device *hldev)
190 * Will poll certain register for specified amount of time. 363 * Will poll certain register for specified amount of time.
191 * Will poll until masked bit is not cleared. 364 * Will poll until masked bit is not cleared.
192 */ 365 */
193enum vxge_hw_status 366static enum vxge_hw_status
194__vxge_hw_device_register_poll(void __iomem *reg, u64 mask, u32 max_millis) 367__vxge_hw_device_register_poll(void __iomem *reg, u64 mask, u32 max_millis)
195{ 368{
196 u64 val64; 369 u64 val64;
@@ -221,7 +394,7 @@ __vxge_hw_device_register_poll(void __iomem *reg, u64 mask, u32 max_millis)
221 * in progress 394 * in progress
222 * This routine checks the vpath reset in progress register is turned zero 395 * This routine checks the vpath reset in progress register is turned zero
223 */ 396 */
224enum vxge_hw_status 397static enum vxge_hw_status
225__vxge_hw_device_vpath_reset_in_prog_check(u64 __iomem *vpath_rst_in_prog) 398__vxge_hw_device_vpath_reset_in_prog_check(u64 __iomem *vpath_rst_in_prog)
226{ 399{
227 enum vxge_hw_status status; 400 enum vxge_hw_status status;
@@ -236,7 +409,7 @@ __vxge_hw_device_vpath_reset_in_prog_check(u64 __iomem *vpath_rst_in_prog)
236 * This routine sets the swapper and reads the toc pointer and returns the 409 * This routine sets the swapper and reads the toc pointer and returns the
237 * memory mapped address of the toc 410 * memory mapped address of the toc
238 */ 411 */
239struct vxge_hw_toc_reg __iomem * 412static struct vxge_hw_toc_reg __iomem *
240__vxge_hw_device_toc_get(void __iomem *bar0) 413__vxge_hw_device_toc_get(void __iomem *bar0)
241{ 414{
242 u64 val64; 415 u64 val64;
@@ -779,7 +952,7 @@ exit:
779 * vxge_hw_device_xmac_aggr_stats_get - Get the Statistics on aggregate port 952 * vxge_hw_device_xmac_aggr_stats_get - Get the Statistics on aggregate port
780 * Get the Statistics on aggregate port 953 * Get the Statistics on aggregate port
781 */ 954 */
782enum vxge_hw_status 955static enum vxge_hw_status
783vxge_hw_device_xmac_aggr_stats_get(struct __vxge_hw_device *hldev, u32 port, 956vxge_hw_device_xmac_aggr_stats_get(struct __vxge_hw_device *hldev, u32 port,
784 struct vxge_hw_xmac_aggr_stats *aggr_stats) 957 struct vxge_hw_xmac_aggr_stats *aggr_stats)
785{ 958{
@@ -814,7 +987,7 @@ exit:
814 * vxge_hw_device_xmac_port_stats_get - Get the Statistics on a port 987 * vxge_hw_device_xmac_port_stats_get - Get the Statistics on a port
815 * Get the Statistics on port 988 * Get the Statistics on port
816 */ 989 */
817enum vxge_hw_status 990static enum vxge_hw_status
818vxge_hw_device_xmac_port_stats_get(struct __vxge_hw_device *hldev, u32 port, 991vxge_hw_device_xmac_port_stats_get(struct __vxge_hw_device *hldev, u32 port,
819 struct vxge_hw_xmac_port_stats *port_stats) 992 struct vxge_hw_xmac_port_stats *port_stats)
820{ 993{
@@ -952,20 +1125,6 @@ u32 vxge_hw_device_trace_level_get(struct __vxge_hw_device *hldev)
952 return 0; 1125 return 0;
953#endif 1126#endif
954} 1127}
955/*
956 * vxge_hw_device_debug_mask_get - Get the debug mask
957 * This routine returns the current debug mask set
958 */
959u32 vxge_hw_device_debug_mask_get(struct __vxge_hw_device *hldev)
960{
961#if defined(VXGE_DEBUG_TRACE_MASK) || defined(VXGE_DEBUG_ERR_MASK)
962 if (hldev == NULL)
963 return 0;
964 return hldev->debug_module_mask;
965#else
966 return 0;
967#endif
968}
969 1128
970/* 1129/*
971 * vxge_hw_getpause_data -Pause frame frame generation and reception. 1130 * vxge_hw_getpause_data -Pause frame frame generation and reception.
@@ -1090,7 +1249,7 @@ __vxge_hw_ring_block_next_pointer_set(u8 *block, dma_addr_t dma_next)
1090 * first block 1249 * first block
1091 * Returns the dma address of the first RxD block 1250 * Returns the dma address of the first RxD block
1092 */ 1251 */
1093u64 __vxge_hw_ring_first_block_address_get(struct __vxge_hw_ring *ring) 1252static u64 __vxge_hw_ring_first_block_address_get(struct __vxge_hw_ring *ring)
1094{ 1253{
1095 struct vxge_hw_mempool_dma *dma_object; 1254 struct vxge_hw_mempool_dma *dma_object;
1096 1255
@@ -1252,7 +1411,7 @@ exit:
1252 * This function creates Ring and initializes it. 1411 * This function creates Ring and initializes it.
1253 * 1412 *
1254 */ 1413 */
1255enum vxge_hw_status 1414static enum vxge_hw_status
1256__vxge_hw_ring_create(struct __vxge_hw_vpath_handle *vp, 1415__vxge_hw_ring_create(struct __vxge_hw_vpath_handle *vp,
1257 struct vxge_hw_ring_attr *attr) 1416 struct vxge_hw_ring_attr *attr)
1258{ 1417{
@@ -1363,7 +1522,7 @@ exit:
1363 * __vxge_hw_ring_abort - Returns the RxD 1522 * __vxge_hw_ring_abort - Returns the RxD
1364 * This function terminates the RxDs of ring 1523 * This function terminates the RxDs of ring
1365 */ 1524 */
1366enum vxge_hw_status __vxge_hw_ring_abort(struct __vxge_hw_ring *ring) 1525static enum vxge_hw_status __vxge_hw_ring_abort(struct __vxge_hw_ring *ring)
1367{ 1526{
1368 void *rxdh; 1527 void *rxdh;
1369 struct __vxge_hw_channel *channel; 1528 struct __vxge_hw_channel *channel;
@@ -1392,7 +1551,7 @@ enum vxge_hw_status __vxge_hw_ring_abort(struct __vxge_hw_ring *ring)
1392 * __vxge_hw_ring_reset - Resets the ring 1551 * __vxge_hw_ring_reset - Resets the ring
1393 * This function resets the ring during vpath reset operation 1552 * This function resets the ring during vpath reset operation
1394 */ 1553 */
1395enum vxge_hw_status __vxge_hw_ring_reset(struct __vxge_hw_ring *ring) 1554static enum vxge_hw_status __vxge_hw_ring_reset(struct __vxge_hw_ring *ring)
1396{ 1555{
1397 enum vxge_hw_status status = VXGE_HW_OK; 1556 enum vxge_hw_status status = VXGE_HW_OK;
1398 struct __vxge_hw_channel *channel; 1557 struct __vxge_hw_channel *channel;
@@ -1419,7 +1578,7 @@ exit:
1419 * __vxge_hw_ring_delete - Removes the ring 1578 * __vxge_hw_ring_delete - Removes the ring
1420 * This function freeup the memory pool and removes the ring 1579 * This function freeup the memory pool and removes the ring
1421 */ 1580 */
1422enum vxge_hw_status __vxge_hw_ring_delete(struct __vxge_hw_vpath_handle *vp) 1581static enum vxge_hw_status __vxge_hw_ring_delete(struct __vxge_hw_vpath_handle *vp)
1423{ 1582{
1424 struct __vxge_hw_ring *ring = vp->vpath->ringh; 1583 struct __vxge_hw_ring *ring = vp->vpath->ringh;
1425 1584
@@ -1438,7 +1597,7 @@ enum vxge_hw_status __vxge_hw_ring_delete(struct __vxge_hw_vpath_handle *vp)
1438 * __vxge_hw_mempool_grow 1597 * __vxge_hw_mempool_grow
1439 * Will resize mempool up to %num_allocate value. 1598 * Will resize mempool up to %num_allocate value.
1440 */ 1599 */
1441enum vxge_hw_status 1600static enum vxge_hw_status
1442__vxge_hw_mempool_grow(struct vxge_hw_mempool *mempool, u32 num_allocate, 1601__vxge_hw_mempool_grow(struct vxge_hw_mempool *mempool, u32 num_allocate,
1443 u32 *num_allocated) 1602 u32 *num_allocated)
1444{ 1603{
@@ -1527,7 +1686,7 @@ exit:
1527 * with size enough to hold %items_initial number of items. Memory is 1686 * with size enough to hold %items_initial number of items. Memory is
1528 * DMA-able but client must map/unmap before interoperating with the device. 1687 * DMA-able but client must map/unmap before interoperating with the device.
1529 */ 1688 */
1530struct vxge_hw_mempool* 1689static struct vxge_hw_mempool*
1531__vxge_hw_mempool_create( 1690__vxge_hw_mempool_create(
1532 struct __vxge_hw_device *devh, 1691 struct __vxge_hw_device *devh,
1533 u32 memblock_size, 1692 u32 memblock_size,
@@ -1644,7 +1803,7 @@ exit:
1644/* 1803/*
1645 * vxge_hw_mempool_destroy 1804 * vxge_hw_mempool_destroy
1646 */ 1805 */
1647void __vxge_hw_mempool_destroy(struct vxge_hw_mempool *mempool) 1806static void __vxge_hw_mempool_destroy(struct vxge_hw_mempool *mempool)
1648{ 1807{
1649 u32 i, j; 1808 u32 i, j;
1650 struct __vxge_hw_device *devh = mempool->devh; 1809 struct __vxge_hw_device *devh = mempool->devh;
@@ -1700,7 +1859,7 @@ __vxge_hw_device_fifo_config_check(struct vxge_hw_fifo_config *fifo_config)
1700 * __vxge_hw_device_vpath_config_check - Check vpath configuration. 1859 * __vxge_hw_device_vpath_config_check - Check vpath configuration.
1701 * Check the vpath configuration 1860 * Check the vpath configuration
1702 */ 1861 */
1703enum vxge_hw_status 1862static enum vxge_hw_status
1704__vxge_hw_device_vpath_config_check(struct vxge_hw_vp_config *vp_config) 1863__vxge_hw_device_vpath_config_check(struct vxge_hw_vp_config *vp_config)
1705{ 1864{
1706 enum vxge_hw_status status; 1865 enum vxge_hw_status status;
@@ -1922,7 +2081,7 @@ vxge_hw_device_config_default_get(struct vxge_hw_device_config *device_config)
1922 * _hw_legacy_swapper_set - Set the swapper bits for the legacy secion. 2081 * _hw_legacy_swapper_set - Set the swapper bits for the legacy secion.
1923 * Set the swapper bits appropriately for the lagacy section. 2082 * Set the swapper bits appropriately for the lagacy section.
1924 */ 2083 */
1925enum vxge_hw_status 2084static enum vxge_hw_status
1926__vxge_hw_legacy_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg) 2085__vxge_hw_legacy_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg)
1927{ 2086{
1928 u64 val64; 2087 u64 val64;
@@ -1977,7 +2136,7 @@ __vxge_hw_legacy_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg)
1977 * __vxge_hw_vpath_swapper_set - Set the swapper bits for the vpath. 2136 * __vxge_hw_vpath_swapper_set - Set the swapper bits for the vpath.
1978 * Set the swapper bits appropriately for the vpath. 2137 * Set the swapper bits appropriately for the vpath.
1979 */ 2138 */
1980enum vxge_hw_status 2139static enum vxge_hw_status
1981__vxge_hw_vpath_swapper_set(struct vxge_hw_vpath_reg __iomem *vpath_reg) 2140__vxge_hw_vpath_swapper_set(struct vxge_hw_vpath_reg __iomem *vpath_reg)
1982{ 2141{
1983#ifndef __BIG_ENDIAN 2142#ifndef __BIG_ENDIAN
@@ -1996,7 +2155,7 @@ __vxge_hw_vpath_swapper_set(struct vxge_hw_vpath_reg __iomem *vpath_reg)
1996 * __vxge_hw_kdfc_swapper_set - Set the swapper bits for the kdfc. 2155 * __vxge_hw_kdfc_swapper_set - Set the swapper bits for the kdfc.
1997 * Set the swapper bits appropriately for the vpath. 2156 * Set the swapper bits appropriately for the vpath.
1998 */ 2157 */
1999enum vxge_hw_status 2158static enum vxge_hw_status
2000__vxge_hw_kdfc_swapper_set( 2159__vxge_hw_kdfc_swapper_set(
2001 struct vxge_hw_legacy_reg __iomem *legacy_reg, 2160 struct vxge_hw_legacy_reg __iomem *legacy_reg,
2002 struct vxge_hw_vpath_reg __iomem *vpath_reg) 2161 struct vxge_hw_vpath_reg __iomem *vpath_reg)
@@ -2021,28 +2180,6 @@ __vxge_hw_kdfc_swapper_set(
2021} 2180}
2022 2181
2023/* 2182/*
2024 * vxge_hw_mgmt_device_config - Retrieve device configuration.
2025 * Get device configuration. Permits to retrieve at run-time configuration
2026 * values that were used to initialize and configure the device.
2027 */
2028enum vxge_hw_status
2029vxge_hw_mgmt_device_config(struct __vxge_hw_device *hldev,
2030 struct vxge_hw_device_config *dev_config, int size)
2031{
2032
2033 if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC))
2034 return VXGE_HW_ERR_INVALID_DEVICE;
2035
2036 if (size != sizeof(struct vxge_hw_device_config))
2037 return VXGE_HW_ERR_VERSION_CONFLICT;
2038
2039 memcpy(dev_config, &hldev->config,
2040 sizeof(struct vxge_hw_device_config));
2041
2042 return VXGE_HW_OK;
2043}
2044
2045/*
2046 * vxge_hw_mgmt_reg_read - Read Titan register. 2183 * vxge_hw_mgmt_reg_read - Read Titan register.
2047 */ 2184 */
2048enum vxge_hw_status 2185enum vxge_hw_status
@@ -2438,7 +2575,7 @@ exit:
2438 * __vxge_hw_fifo_abort - Returns the TxD 2575 * __vxge_hw_fifo_abort - Returns the TxD
2439 * This function terminates the TxDs of fifo 2576 * This function terminates the TxDs of fifo
2440 */ 2577 */
2441enum vxge_hw_status __vxge_hw_fifo_abort(struct __vxge_hw_fifo *fifo) 2578static enum vxge_hw_status __vxge_hw_fifo_abort(struct __vxge_hw_fifo *fifo)
2442{ 2579{
2443 void *txdlh; 2580 void *txdlh;
2444 2581
@@ -2466,7 +2603,7 @@ enum vxge_hw_status __vxge_hw_fifo_abort(struct __vxge_hw_fifo *fifo)
2466 * __vxge_hw_fifo_reset - Resets the fifo 2603 * __vxge_hw_fifo_reset - Resets the fifo
2467 * This function resets the fifo during vpath reset operation 2604 * This function resets the fifo during vpath reset operation
2468 */ 2605 */
2469enum vxge_hw_status __vxge_hw_fifo_reset(struct __vxge_hw_fifo *fifo) 2606static enum vxge_hw_status __vxge_hw_fifo_reset(struct __vxge_hw_fifo *fifo)
2470{ 2607{
2471 enum vxge_hw_status status = VXGE_HW_OK; 2608 enum vxge_hw_status status = VXGE_HW_OK;
2472 2609
@@ -2501,7 +2638,7 @@ enum vxge_hw_status __vxge_hw_fifo_delete(struct __vxge_hw_vpath_handle *vp)
2501 * in pci config space. 2638 * in pci config space.
2502 * Read from the vpath pci config space. 2639 * Read from the vpath pci config space.
2503 */ 2640 */
2504enum vxge_hw_status 2641static enum vxge_hw_status
2505__vxge_hw_vpath_pci_read(struct __vxge_hw_virtualpath *vpath, 2642__vxge_hw_vpath_pci_read(struct __vxge_hw_virtualpath *vpath,
2506 u32 phy_func_0, u32 offset, u32 *val) 2643 u32 phy_func_0, u32 offset, u32 *val)
2507{ 2644{
@@ -2542,7 +2679,7 @@ exit:
2542 * __vxge_hw_vpath_func_id_get - Get the function id of the vpath. 2679 * __vxge_hw_vpath_func_id_get - Get the function id of the vpath.
2543 * Returns the function number of the vpath. 2680 * Returns the function number of the vpath.
2544 */ 2681 */
2545u32 2682static u32
2546__vxge_hw_vpath_func_id_get(u32 vp_id, 2683__vxge_hw_vpath_func_id_get(u32 vp_id,
2547 struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg) 2684 struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg)
2548{ 2685{
@@ -2573,7 +2710,7 @@ __vxge_hw_read_rts_ds(struct vxge_hw_vpath_reg __iomem *vpath_reg,
2573 * __vxge_hw_vpath_card_info_get - Get the serial numbers, 2710 * __vxge_hw_vpath_card_info_get - Get the serial numbers,
2574 * part number and product description. 2711 * part number and product description.
2575 */ 2712 */
2576enum vxge_hw_status 2713static enum vxge_hw_status
2577__vxge_hw_vpath_card_info_get( 2714__vxge_hw_vpath_card_info_get(
2578 u32 vp_id, 2715 u32 vp_id,
2579 struct vxge_hw_vpath_reg __iomem *vpath_reg, 2716 struct vxge_hw_vpath_reg __iomem *vpath_reg,
@@ -2695,7 +2832,7 @@ __vxge_hw_vpath_card_info_get(
2695 * __vxge_hw_vpath_fw_ver_get - Get the fw version 2832 * __vxge_hw_vpath_fw_ver_get - Get the fw version
2696 * Returns FW Version 2833 * Returns FW Version
2697 */ 2834 */
2698enum vxge_hw_status 2835static enum vxge_hw_status
2699__vxge_hw_vpath_fw_ver_get( 2836__vxge_hw_vpath_fw_ver_get(
2700 u32 vp_id, 2837 u32 vp_id,
2701 struct vxge_hw_vpath_reg __iomem *vpath_reg, 2838 struct vxge_hw_vpath_reg __iomem *vpath_reg,
@@ -2789,7 +2926,7 @@ exit:
2789 * __vxge_hw_vpath_pci_func_mode_get - Get the pci mode 2926 * __vxge_hw_vpath_pci_func_mode_get - Get the pci mode
2790 * Returns pci function mode 2927 * Returns pci function mode
2791 */ 2928 */
2792u64 2929static u64
2793__vxge_hw_vpath_pci_func_mode_get( 2930__vxge_hw_vpath_pci_func_mode_get(
2794 u32 vp_id, 2931 u32 vp_id,
2795 struct vxge_hw_vpath_reg __iomem *vpath_reg) 2932 struct vxge_hw_vpath_reg __iomem *vpath_reg)
@@ -2995,7 +3132,7 @@ exit:
2995 * __vxge_hw_vpath_addr_get - Get the hw address entry for this vpath 3132 * __vxge_hw_vpath_addr_get - Get the hw address entry for this vpath
2996 * from MAC address table. 3133 * from MAC address table.
2997 */ 3134 */
2998enum vxge_hw_status 3135static enum vxge_hw_status
2999__vxge_hw_vpath_addr_get( 3136__vxge_hw_vpath_addr_get(
3000 u32 vp_id, struct vxge_hw_vpath_reg __iomem *vpath_reg, 3137 u32 vp_id, struct vxge_hw_vpath_reg __iomem *vpath_reg,
3001 u8 (macaddr)[ETH_ALEN], u8 (macaddr_mask)[ETH_ALEN]) 3138 u8 (macaddr)[ETH_ALEN], u8 (macaddr_mask)[ETH_ALEN])
@@ -3347,7 +3484,7 @@ __vxge_hw_vpath_mgmt_read(
3347 * This routine checks the vpath_rst_in_prog register to see if 3484 * This routine checks the vpath_rst_in_prog register to see if
3348 * adapter completed the reset process for the vpath 3485 * adapter completed the reset process for the vpath
3349 */ 3486 */
3350enum vxge_hw_status 3487static enum vxge_hw_status
3351__vxge_hw_vpath_reset_check(struct __vxge_hw_virtualpath *vpath) 3488__vxge_hw_vpath_reset_check(struct __vxge_hw_virtualpath *vpath)
3352{ 3489{
3353 enum vxge_hw_status status; 3490 enum vxge_hw_status status;
@@ -3365,7 +3502,7 @@ __vxge_hw_vpath_reset_check(struct __vxge_hw_virtualpath *vpath)
3365 * __vxge_hw_vpath_reset 3502 * __vxge_hw_vpath_reset
3366 * This routine resets the vpath on the device 3503 * This routine resets the vpath on the device
3367 */ 3504 */
3368enum vxge_hw_status 3505static enum vxge_hw_status
3369__vxge_hw_vpath_reset(struct __vxge_hw_device *hldev, u32 vp_id) 3506__vxge_hw_vpath_reset(struct __vxge_hw_device *hldev, u32 vp_id)
3370{ 3507{
3371 u64 val64; 3508 u64 val64;
@@ -3383,7 +3520,7 @@ __vxge_hw_vpath_reset(struct __vxge_hw_device *hldev, u32 vp_id)
3383 * __vxge_hw_vpath_sw_reset 3520 * __vxge_hw_vpath_sw_reset
3384 * This routine resets the vpath structures 3521 * This routine resets the vpath structures
3385 */ 3522 */
3386enum vxge_hw_status 3523static enum vxge_hw_status
3387__vxge_hw_vpath_sw_reset(struct __vxge_hw_device *hldev, u32 vp_id) 3524__vxge_hw_vpath_sw_reset(struct __vxge_hw_device *hldev, u32 vp_id)
3388{ 3525{
3389 enum vxge_hw_status status = VXGE_HW_OK; 3526 enum vxge_hw_status status = VXGE_HW_OK;
@@ -3408,7 +3545,7 @@ exit:
3408 * This routine configures the prc registers of virtual path using the config 3545 * This routine configures the prc registers of virtual path using the config
3409 * passed 3546 * passed
3410 */ 3547 */
3411void 3548static void
3412__vxge_hw_vpath_prc_configure(struct __vxge_hw_device *hldev, u32 vp_id) 3549__vxge_hw_vpath_prc_configure(struct __vxge_hw_device *hldev, u32 vp_id)
3413{ 3550{
3414 u64 val64; 3551 u64 val64;
@@ -3480,7 +3617,7 @@ __vxge_hw_vpath_prc_configure(struct __vxge_hw_device *hldev, u32 vp_id)
3480 * This routine configures the kdfc registers of virtual path using the 3617 * This routine configures the kdfc registers of virtual path using the
3481 * config passed 3618 * config passed
3482 */ 3619 */
3483enum vxge_hw_status 3620static enum vxge_hw_status
3484__vxge_hw_vpath_kdfc_configure(struct __vxge_hw_device *hldev, u32 vp_id) 3621__vxge_hw_vpath_kdfc_configure(struct __vxge_hw_device *hldev, u32 vp_id)
3485{ 3622{
3486 u64 val64; 3623 u64 val64;
@@ -3553,7 +3690,7 @@ exit:
3553 * __vxge_hw_vpath_mac_configure 3690 * __vxge_hw_vpath_mac_configure
3554 * This routine configures the mac of virtual path using the config passed 3691 * This routine configures the mac of virtual path using the config passed
3555 */ 3692 */
3556enum vxge_hw_status 3693static enum vxge_hw_status
3557__vxge_hw_vpath_mac_configure(struct __vxge_hw_device *hldev, u32 vp_id) 3694__vxge_hw_vpath_mac_configure(struct __vxge_hw_device *hldev, u32 vp_id)
3558{ 3695{
3559 u64 val64; 3696 u64 val64;
@@ -3621,7 +3758,7 @@ __vxge_hw_vpath_mac_configure(struct __vxge_hw_device *hldev, u32 vp_id)
3621 * This routine configures the tim registers of virtual path using the config 3758 * This routine configures the tim registers of virtual path using the config
3622 * passed 3759 * passed
3623 */ 3760 */
3624enum vxge_hw_status 3761static enum vxge_hw_status
3625__vxge_hw_vpath_tim_configure(struct __vxge_hw_device *hldev, u32 vp_id) 3762__vxge_hw_vpath_tim_configure(struct __vxge_hw_device *hldev, u32 vp_id)
3626{ 3763{
3627 u64 val64; 3764 u64 val64;
@@ -3897,7 +4034,7 @@ vxge_hw_vpath_tti_ci_set(struct __vxge_hw_device *hldev, u32 vp_id)
3897 * This routine is the final phase of init which initializes the 4034 * This routine is the final phase of init which initializes the
3898 * registers of the vpath using the configuration passed. 4035 * registers of the vpath using the configuration passed.
3899 */ 4036 */
3900enum vxge_hw_status 4037static enum vxge_hw_status
3901__vxge_hw_vpath_initialize(struct __vxge_hw_device *hldev, u32 vp_id) 4038__vxge_hw_vpath_initialize(struct __vxge_hw_device *hldev, u32 vp_id)
3902{ 4039{
3903 u64 val64; 4040 u64 val64;
@@ -3966,7 +4103,7 @@ exit:
3966 * This routine is the initial phase of init which resets the vpath and 4103 * This routine is the initial phase of init which resets the vpath and
3967 * initializes the software support structures. 4104 * initializes the software support structures.
3968 */ 4105 */
3969enum vxge_hw_status 4106static enum vxge_hw_status
3970__vxge_hw_vp_initialize(struct __vxge_hw_device *hldev, u32 vp_id, 4107__vxge_hw_vp_initialize(struct __vxge_hw_device *hldev, u32 vp_id,
3971 struct vxge_hw_vp_config *config) 4108 struct vxge_hw_vp_config *config)
3972{ 4109{
@@ -4022,7 +4159,7 @@ exit:
4022 * __vxge_hw_vp_terminate - Terminate Virtual Path structure 4159 * __vxge_hw_vp_terminate - Terminate Virtual Path structure
4023 * This routine closes all channels it opened and freeup memory 4160 * This routine closes all channels it opened and freeup memory
4024 */ 4161 */
4025void 4162static void
4026__vxge_hw_vp_terminate(struct __vxge_hw_device *hldev, u32 vp_id) 4163__vxge_hw_vp_terminate(struct __vxge_hw_device *hldev, u32 vp_id)
4027{ 4164{
4028 struct __vxge_hw_virtualpath *vpath; 4165 struct __vxge_hw_virtualpath *vpath;
@@ -4384,7 +4521,7 @@ vxge_hw_vpath_enable(struct __vxge_hw_vpath_handle *vp)
4384 * Enable the DMA vpath statistics. The function is to be called to re-enable 4521 * Enable the DMA vpath statistics. The function is to be called to re-enable
4385 * the adapter to update stats into the host memory 4522 * the adapter to update stats into the host memory
4386 */ 4523 */
4387enum vxge_hw_status 4524static enum vxge_hw_status
4388vxge_hw_vpath_stats_enable(struct __vxge_hw_vpath_handle *vp) 4525vxge_hw_vpath_stats_enable(struct __vxge_hw_vpath_handle *vp)
4389{ 4526{
4390 enum vxge_hw_status status = VXGE_HW_OK; 4527 enum vxge_hw_status status = VXGE_HW_OK;
@@ -4409,7 +4546,7 @@ exit:
4409 * __vxge_hw_vpath_stats_access - Get the statistics from the given location 4546 * __vxge_hw_vpath_stats_access - Get the statistics from the given location
4410 * and offset and perform an operation 4547 * and offset and perform an operation
4411 */ 4548 */
4412enum vxge_hw_status 4549static enum vxge_hw_status
4413__vxge_hw_vpath_stats_access(struct __vxge_hw_virtualpath *vpath, 4550__vxge_hw_vpath_stats_access(struct __vxge_hw_virtualpath *vpath,
4414 u32 operation, u32 offset, u64 *stat) 4551 u32 operation, u32 offset, u64 *stat)
4415{ 4552{
@@ -4445,7 +4582,7 @@ vpath_stats_access_exit:
4445/* 4582/*
4446 * __vxge_hw_vpath_xmac_tx_stats_get - Get the TX Statistics of a vpath 4583 * __vxge_hw_vpath_xmac_tx_stats_get - Get the TX Statistics of a vpath
4447 */ 4584 */
4448enum vxge_hw_status 4585static enum vxge_hw_status
4449__vxge_hw_vpath_xmac_tx_stats_get( 4586__vxge_hw_vpath_xmac_tx_stats_get(
4450 struct __vxge_hw_virtualpath *vpath, 4587 struct __vxge_hw_virtualpath *vpath,
4451 struct vxge_hw_xmac_vpath_tx_stats *vpath_tx_stats) 4588 struct vxge_hw_xmac_vpath_tx_stats *vpath_tx_stats)
@@ -4478,9 +4615,9 @@ exit:
4478/* 4615/*
4479 * __vxge_hw_vpath_xmac_rx_stats_get - Get the RX Statistics of a vpath 4616 * __vxge_hw_vpath_xmac_rx_stats_get - Get the RX Statistics of a vpath
4480 */ 4617 */
4481enum vxge_hw_status 4618static enum vxge_hw_status
4482__vxge_hw_vpath_xmac_rx_stats_get(struct __vxge_hw_virtualpath *vpath, 4619__vxge_hw_vpath_xmac_rx_stats_get(struct __vxge_hw_virtualpath *vpath,
4483 struct vxge_hw_xmac_vpath_rx_stats *vpath_rx_stats) 4620 struct vxge_hw_xmac_vpath_rx_stats *vpath_rx_stats)
4484{ 4621{
4485 u64 *val64; 4622 u64 *val64;
4486 enum vxge_hw_status status = VXGE_HW_OK; 4623 enum vxge_hw_status status = VXGE_HW_OK;
@@ -4509,9 +4646,9 @@ exit:
4509/* 4646/*
4510 * __vxge_hw_vpath_stats_get - Get the vpath hw statistics. 4647 * __vxge_hw_vpath_stats_get - Get the vpath hw statistics.
4511 */ 4648 */
4512enum vxge_hw_status __vxge_hw_vpath_stats_get( 4649static enum vxge_hw_status
4513 struct __vxge_hw_virtualpath *vpath, 4650__vxge_hw_vpath_stats_get(struct __vxge_hw_virtualpath *vpath,
4514 struct vxge_hw_vpath_stats_hw_info *hw_stats) 4651 struct vxge_hw_vpath_stats_hw_info *hw_stats)
4515{ 4652{
4516 u64 val64; 4653 u64 val64;
4517 enum vxge_hw_status status = VXGE_HW_OK; 4654 enum vxge_hw_status status = VXGE_HW_OK;
@@ -4643,6 +4780,32 @@ exit:
4643 return status; 4780 return status;
4644} 4781}
4645 4782
4783
4784static void vxge_os_dma_malloc_async(struct pci_dev *pdev, void *devh,
4785 unsigned long size)
4786{
4787 gfp_t flags;
4788 void *vaddr;
4789
4790 if (in_interrupt())
4791 flags = GFP_ATOMIC | GFP_DMA;
4792 else
4793 flags = GFP_KERNEL | GFP_DMA;
4794
4795 vaddr = kmalloc((size), flags);
4796
4797 vxge_hw_blockpool_block_add(devh, vaddr, size, pdev, pdev);
4798}
4799
4800static void vxge_os_dma_free(struct pci_dev *pdev, const void *vaddr,
4801 struct pci_dev **p_dma_acch)
4802{
4803 unsigned long misaligned = *(unsigned long *)p_dma_acch;
4804 u8 *tmp = (u8 *)vaddr;
4805 tmp -= misaligned;
4806 kfree((void *)tmp);
4807}
4808
4646/* 4809/*
4647 * __vxge_hw_blockpool_create - Create block pool 4810 * __vxge_hw_blockpool_create - Create block pool
4648 */ 4811 */
@@ -4845,12 +5008,11 @@ void __vxge_hw_blockpool_blocks_remove(struct __vxge_hw_blockpool *blockpool)
4845 * vxge_hw_blockpool_block_add - callback for vxge_os_dma_malloc_async 5008 * vxge_hw_blockpool_block_add - callback for vxge_os_dma_malloc_async
4846 * Adds a block to block pool 5009 * Adds a block to block pool
4847 */ 5010 */
4848void vxge_hw_blockpool_block_add( 5011static void vxge_hw_blockpool_block_add(struct __vxge_hw_device *devh,
4849 struct __vxge_hw_device *devh, 5012 void *block_addr,
4850 void *block_addr, 5013 u32 length,
4851 u32 length, 5014 struct pci_dev *dma_h,
4852 struct pci_dev *dma_h, 5015 struct pci_dev *acc_handle)
4853 struct pci_dev *acc_handle)
4854{ 5016{
4855 struct __vxge_hw_blockpool *blockpool; 5017 struct __vxge_hw_blockpool *blockpool;
4856 struct __vxge_hw_blockpool_entry *entry = NULL; 5018 struct __vxge_hw_blockpool_entry *entry = NULL;
diff --git a/drivers/net/vxge/vxge-config.h b/drivers/net/vxge/vxge-config.h
index 1a94343023cb..5c00861b6c2c 100644
--- a/drivers/net/vxge/vxge-config.h
+++ b/drivers/net/vxge/vxge-config.h
@@ -183,11 +183,6 @@ struct vxge_hw_device_version {
183 char version[VXGE_HW_FW_STRLEN]; 183 char version[VXGE_HW_FW_STRLEN];
184}; 184};
185 185
186u64
187__vxge_hw_vpath_pci_func_mode_get(
188 u32 vp_id,
189 struct vxge_hw_vpath_reg __iomem *vpath_reg);
190
191/** 186/**
192 * struct vxge_hw_fifo_config - Configuration of fifo. 187 * struct vxge_hw_fifo_config - Configuration of fifo.
193 * @enable: Is this fifo to be commissioned 188 * @enable: Is this fifo to be commissioned
@@ -1426,9 +1421,6 @@ struct vxge_hw_rth_hash_types {
1426 u8 hash_type_ipv6ex_en; 1421 u8 hash_type_ipv6ex_en;
1427}; 1422};
1428 1423
1429u32
1430vxge_hw_device_debug_mask_get(struct __vxge_hw_device *devh);
1431
1432void vxge_hw_device_debug_set( 1424void vxge_hw_device_debug_set(
1433 struct __vxge_hw_device *devh, 1425 struct __vxge_hw_device *devh,
1434 enum vxge_debug_level level, 1426 enum vxge_debug_level level,
@@ -1440,9 +1432,6 @@ vxge_hw_device_error_level_get(struct __vxge_hw_device *devh);
1440u32 1432u32
1441vxge_hw_device_trace_level_get(struct __vxge_hw_device *devh); 1433vxge_hw_device_trace_level_get(struct __vxge_hw_device *devh);
1442 1434
1443u32
1444vxge_hw_device_debug_mask_get(struct __vxge_hw_device *devh);
1445
1446/** 1435/**
1447 * vxge_hw_ring_rxd_size_get - Get the size of ring descriptor. 1436 * vxge_hw_ring_rxd_size_get - Get the size of ring descriptor.
1448 * @buf_mode: Buffer mode (1, 3 or 5) 1437 * @buf_mode: Buffer mode (1, 3 or 5)
@@ -1817,60 +1806,10 @@ struct vxge_hw_vpath_attr {
1817 struct vxge_hw_fifo_attr fifo_attr; 1806 struct vxge_hw_fifo_attr fifo_attr;
1818}; 1807};
1819 1808
1820enum vxge_hw_status
1821__vxge_hw_blockpool_create(struct __vxge_hw_device *hldev,
1822 struct __vxge_hw_blockpool *blockpool,
1823 u32 pool_size,
1824 u32 pool_max);
1825
1826void
1827__vxge_hw_blockpool_destroy(struct __vxge_hw_blockpool *blockpool);
1828
1829struct __vxge_hw_blockpool_entry *
1830__vxge_hw_blockpool_block_allocate(struct __vxge_hw_device *hldev,
1831 u32 size);
1832
1833void
1834__vxge_hw_blockpool_block_free(struct __vxge_hw_device *hldev,
1835 struct __vxge_hw_blockpool_entry *entry);
1836
1837void *
1838__vxge_hw_blockpool_malloc(struct __vxge_hw_device *hldev,
1839 u32 size,
1840 struct vxge_hw_mempool_dma *dma_object);
1841
1842void
1843__vxge_hw_blockpool_free(struct __vxge_hw_device *hldev,
1844 void *memblock,
1845 u32 size,
1846 struct vxge_hw_mempool_dma *dma_object);
1847
1848enum vxge_hw_status
1849__vxge_hw_device_fifo_config_check(struct vxge_hw_fifo_config *fifo_config);
1850
1851enum vxge_hw_status
1852__vxge_hw_device_config_check(struct vxge_hw_device_config *new_config);
1853
1854enum vxge_hw_status
1855vxge_hw_mgmt_device_config(struct __vxge_hw_device *devh,
1856 struct vxge_hw_device_config *dev_config, int size);
1857
1858enum vxge_hw_status __devinit vxge_hw_device_hw_info_get( 1809enum vxge_hw_status __devinit vxge_hw_device_hw_info_get(
1859 void __iomem *bar0, 1810 void __iomem *bar0,
1860 struct vxge_hw_device_hw_info *hw_info); 1811 struct vxge_hw_device_hw_info *hw_info);
1861 1812
1862enum vxge_hw_status
1863__vxge_hw_vpath_fw_ver_get(
1864 u32 vp_id,
1865 struct vxge_hw_vpath_reg __iomem *vpath_reg,
1866 struct vxge_hw_device_hw_info *hw_info);
1867
1868enum vxge_hw_status
1869__vxge_hw_vpath_card_info_get(
1870 u32 vp_id,
1871 struct vxge_hw_vpath_reg __iomem *vpath_reg,
1872 struct vxge_hw_device_hw_info *hw_info);
1873
1874enum vxge_hw_status __devinit vxge_hw_device_config_default_get( 1813enum vxge_hw_status __devinit vxge_hw_device_config_default_get(
1875 struct vxge_hw_device_config *device_config); 1814 struct vxge_hw_device_config *device_config);
1876 1815
@@ -1954,38 +1893,6 @@ out:
1954 return vaddr; 1893 return vaddr;
1955} 1894}
1956 1895
1957extern void vxge_hw_blockpool_block_add(
1958 struct __vxge_hw_device *devh,
1959 void *block_addr,
1960 u32 length,
1961 struct pci_dev *dma_h,
1962 struct pci_dev *acc_handle);
1963
1964static inline void vxge_os_dma_malloc_async(struct pci_dev *pdev, void *devh,
1965 unsigned long size)
1966{
1967 gfp_t flags;
1968 void *vaddr;
1969
1970 if (in_interrupt())
1971 flags = GFP_ATOMIC | GFP_DMA;
1972 else
1973 flags = GFP_KERNEL | GFP_DMA;
1974
1975 vaddr = kmalloc((size), flags);
1976
1977 vxge_hw_blockpool_block_add(devh, vaddr, size, pdev, pdev);
1978}
1979
1980static inline void vxge_os_dma_free(struct pci_dev *pdev, const void *vaddr,
1981 struct pci_dev **p_dma_acch)
1982{
1983 unsigned long misaligned = *(unsigned long *)p_dma_acch;
1984 u8 *tmp = (u8 *)vaddr;
1985 tmp -= misaligned;
1986 kfree((void *)tmp);
1987}
1988
1989/* 1896/*
1990 * __vxge_hw_mempool_item_priv - will return pointer on per item private space 1897 * __vxge_hw_mempool_item_priv - will return pointer on per item private space
1991 */ 1898 */
@@ -2010,40 +1917,6 @@ __vxge_hw_mempool_item_priv(
2010 (*memblock_item_idx) * mempool->items_priv_size; 1917 (*memblock_item_idx) * mempool->items_priv_size;
2011} 1918}
2012 1919
2013enum vxge_hw_status
2014__vxge_hw_mempool_grow(
2015 struct vxge_hw_mempool *mempool,
2016 u32 num_allocate,
2017 u32 *num_allocated);
2018
2019struct vxge_hw_mempool*
2020__vxge_hw_mempool_create(
2021 struct __vxge_hw_device *devh,
2022 u32 memblock_size,
2023 u32 item_size,
2024 u32 private_size,
2025 u32 items_initial,
2026 u32 items_max,
2027 struct vxge_hw_mempool_cbs *mp_callback,
2028 void *userdata);
2029
2030struct __vxge_hw_channel*
2031__vxge_hw_channel_allocate(struct __vxge_hw_vpath_handle *vph,
2032 enum __vxge_hw_channel_type type, u32 length,
2033 u32 per_dtr_space, void *userdata);
2034
2035void
2036__vxge_hw_channel_free(
2037 struct __vxge_hw_channel *channel);
2038
2039enum vxge_hw_status
2040__vxge_hw_channel_initialize(
2041 struct __vxge_hw_channel *channel);
2042
2043enum vxge_hw_status
2044__vxge_hw_channel_reset(
2045 struct __vxge_hw_channel *channel);
2046
2047/* 1920/*
2048 * __vxge_hw_fifo_txdl_priv - Return the max fragments allocated 1921 * __vxge_hw_fifo_txdl_priv - Return the max fragments allocated
2049 * for the fifo. 1922 * for the fifo.
@@ -2065,9 +1938,6 @@ enum vxge_hw_status vxge_hw_vpath_open(
2065 struct vxge_hw_vpath_attr *attr, 1938 struct vxge_hw_vpath_attr *attr,
2066 struct __vxge_hw_vpath_handle **vpath_handle); 1939 struct __vxge_hw_vpath_handle **vpath_handle);
2067 1940
2068enum vxge_hw_status
2069__vxge_hw_device_vpath_reset_in_prog_check(u64 __iomem *vpath_rst_in_prog);
2070
2071enum vxge_hw_status vxge_hw_vpath_close( 1941enum vxge_hw_status vxge_hw_vpath_close(
2072 struct __vxge_hw_vpath_handle *vpath_handle); 1942 struct __vxge_hw_vpath_handle *vpath_handle);
2073 1943
@@ -2089,54 +1959,9 @@ enum vxge_hw_status vxge_hw_vpath_mtu_set(
2089 struct __vxge_hw_vpath_handle *vpath_handle, 1959 struct __vxge_hw_vpath_handle *vpath_handle,
2090 u32 new_mtu); 1960 u32 new_mtu);
2091 1961
2092enum vxge_hw_status vxge_hw_vpath_stats_enable(
2093 struct __vxge_hw_vpath_handle *vpath_handle);
2094
2095enum vxge_hw_status
2096__vxge_hw_vpath_stats_access(
2097 struct __vxge_hw_virtualpath *vpath,
2098 u32 operation,
2099 u32 offset,
2100 u64 *stat);
2101
2102enum vxge_hw_status
2103__vxge_hw_vpath_xmac_tx_stats_get(
2104 struct __vxge_hw_virtualpath *vpath,
2105 struct vxge_hw_xmac_vpath_tx_stats *vpath_tx_stats);
2106
2107enum vxge_hw_status
2108__vxge_hw_vpath_xmac_rx_stats_get(
2109 struct __vxge_hw_virtualpath *vpath,
2110 struct vxge_hw_xmac_vpath_rx_stats *vpath_rx_stats);
2111
2112enum vxge_hw_status
2113__vxge_hw_vpath_stats_get(
2114 struct __vxge_hw_virtualpath *vpath,
2115 struct vxge_hw_vpath_stats_hw_info *hw_stats);
2116
2117void 1962void
2118vxge_hw_vpath_rx_doorbell_init(struct __vxge_hw_vpath_handle *vp); 1963vxge_hw_vpath_rx_doorbell_init(struct __vxge_hw_vpath_handle *vp);
2119 1964
2120enum vxge_hw_status
2121__vxge_hw_device_vpath_config_check(struct vxge_hw_vp_config *vp_config);
2122
2123void
2124__vxge_hw_device_pci_e_init(struct __vxge_hw_device *hldev);
2125
2126enum vxge_hw_status
2127__vxge_hw_legacy_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg);
2128
2129enum vxge_hw_status
2130__vxge_hw_vpath_swapper_set(struct vxge_hw_vpath_reg __iomem *vpath_reg);
2131
2132enum vxge_hw_status
2133__vxge_hw_kdfc_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg,
2134 struct vxge_hw_vpath_reg __iomem *vpath_reg);
2135
2136enum vxge_hw_status
2137__vxge_hw_device_register_poll(
2138 void __iomem *reg,
2139 u64 mask, u32 max_millis);
2140 1965
2141#ifndef readq 1966#ifndef readq
2142static inline u64 readq(void __iomem *addr) 1967static inline u64 readq(void __iomem *addr)
@@ -2168,62 +1993,12 @@ static inline void __vxge_hw_pio_mem_write32_lower(u32 val, void __iomem *addr)
2168 writel(val, addr); 1993 writel(val, addr);
2169} 1994}
2170 1995
2171static inline enum vxge_hw_status
2172__vxge_hw_pio_mem_write64(u64 val64, void __iomem *addr,
2173 u64 mask, u32 max_millis)
2174{
2175 enum vxge_hw_status status = VXGE_HW_OK;
2176
2177 __vxge_hw_pio_mem_write32_lower((u32)vxge_bVALn(val64, 32, 32), addr);
2178 wmb();
2179 __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32), addr);
2180 wmb();
2181
2182 status = __vxge_hw_device_register_poll(addr, mask, max_millis);
2183 return status;
2184}
2185
2186struct vxge_hw_toc_reg __iomem *
2187__vxge_hw_device_toc_get(void __iomem *bar0);
2188
2189enum vxge_hw_status
2190__vxge_hw_device_reg_addr_get(struct __vxge_hw_device *hldev);
2191
2192void
2193__vxge_hw_device_id_get(struct __vxge_hw_device *hldev);
2194
2195void
2196__vxge_hw_device_host_info_get(struct __vxge_hw_device *hldev);
2197
2198enum vxge_hw_status 1996enum vxge_hw_status
2199vxge_hw_device_flick_link_led(struct __vxge_hw_device *devh, u64 on_off); 1997vxge_hw_device_flick_link_led(struct __vxge_hw_device *devh, u64 on_off);
2200 1998
2201enum vxge_hw_status 1999enum vxge_hw_status
2202__vxge_hw_device_initialize(struct __vxge_hw_device *hldev);
2203
2204enum vxge_hw_status
2205__vxge_hw_vpath_pci_read(
2206 struct __vxge_hw_virtualpath *vpath,
2207 u32 phy_func_0,
2208 u32 offset,
2209 u32 *val);
2210
2211enum vxge_hw_status
2212__vxge_hw_vpath_addr_get(
2213 u32 vp_id,
2214 struct vxge_hw_vpath_reg __iomem *vpath_reg,
2215 u8 (macaddr)[ETH_ALEN],
2216 u8 (macaddr_mask)[ETH_ALEN]);
2217
2218u32
2219__vxge_hw_vpath_func_id_get(
2220 u32 vp_id, struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg);
2221
2222enum vxge_hw_status
2223__vxge_hw_vpath_reset_check(struct __vxge_hw_virtualpath *vpath);
2224
2225enum vxge_hw_status
2226vxge_hw_vpath_strip_fcs_check(struct __vxge_hw_device *hldev, u64 vpath_mask); 2000vxge_hw_vpath_strip_fcs_check(struct __vxge_hw_device *hldev, u64 vpath_mask);
2001
2227/** 2002/**
2228 * vxge_debug 2003 * vxge_debug
2229 * @level: level of debug verbosity. 2004 * @level: level of debug verbosity.
diff --git a/drivers/net/vxge/vxge-ethtool.c b/drivers/net/vxge/vxge-ethtool.c
index 05679e306fdd..b67746eef923 100644
--- a/drivers/net/vxge/vxge-ethtool.c
+++ b/drivers/net/vxge/vxge-ethtool.c
@@ -1142,7 +1142,7 @@ static const struct ethtool_ops vxge_ethtool_ops = {
1142 .get_ethtool_stats = vxge_get_ethtool_stats, 1142 .get_ethtool_stats = vxge_get_ethtool_stats,
1143}; 1143};
1144 1144
1145void initialize_ethtool_ops(struct net_device *ndev) 1145void vxge_initialize_ethtool_ops(struct net_device *ndev)
1146{ 1146{
1147 SET_ETHTOOL_OPS(ndev, &vxge_ethtool_ops); 1147 SET_ETHTOOL_OPS(ndev, &vxge_ethtool_ops);
1148} 1148}
diff --git a/drivers/net/vxge/vxge-main.c b/drivers/net/vxge/vxge-main.c
index a69542ecb68d..813829f3d024 100644
--- a/drivers/net/vxge/vxge-main.c
+++ b/drivers/net/vxge/vxge-main.c
@@ -82,6 +82,16 @@ module_param_array(bw_percentage, uint, NULL, 0);
82 82
83static struct vxge_drv_config *driver_config; 83static struct vxge_drv_config *driver_config;
84 84
85static enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev,
86 struct macInfo *mac);
87static enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev,
88 struct macInfo *mac);
89static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac);
90static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac);
91static enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath);
92static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath);
93static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev);
94
85static inline int is_vxge_card_up(struct vxgedev *vdev) 95static inline int is_vxge_card_up(struct vxgedev *vdev)
86{ 96{
87 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state); 97 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
@@ -138,7 +148,7 @@ static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
138 * This function is called during interrupt context to notify link up state 148 * This function is called during interrupt context to notify link up state
139 * change. 149 * change.
140 */ 150 */
141void 151static void
142vxge_callback_link_up(struct __vxge_hw_device *hldev) 152vxge_callback_link_up(struct __vxge_hw_device *hldev)
143{ 153{
144 struct net_device *dev = hldev->ndev; 154 struct net_device *dev = hldev->ndev;
@@ -162,7 +172,7 @@ vxge_callback_link_up(struct __vxge_hw_device *hldev)
162 * This function is called during interrupt context to notify link down state 172 * This function is called during interrupt context to notify link down state
163 * change. 173 * change.
164 */ 174 */
165void 175static void
166vxge_callback_link_down(struct __vxge_hw_device *hldev) 176vxge_callback_link_down(struct __vxge_hw_device *hldev)
167{ 177{
168 struct net_device *dev = hldev->ndev; 178 struct net_device *dev = hldev->ndev;
@@ -354,7 +364,7 @@ static inline void vxge_post(int *dtr_cnt, void **first_dtr,
354 * If the interrupt is because of a received frame or if the receive ring 364 * If the interrupt is because of a received frame or if the receive ring
355 * contains fresh as yet un-processed frames, this function is called. 365 * contains fresh as yet un-processed frames, this function is called.
356 */ 366 */
357enum vxge_hw_status 367static enum vxge_hw_status
358vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr, 368vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
359 u8 t_code, void *userdata) 369 u8 t_code, void *userdata)
360{ 370{
@@ -531,7 +541,7 @@ vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
531 * freed and frees all skbs whose data have already DMA'ed into the NICs 541 * freed and frees all skbs whose data have already DMA'ed into the NICs
532 * internal memory. 542 * internal memory.
533 */ 543 */
534enum vxge_hw_status 544static enum vxge_hw_status
535vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr, 545vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
536 enum vxge_hw_fifo_tcode t_code, void *userdata, 546 enum vxge_hw_fifo_tcode t_code, void *userdata,
537 struct sk_buff ***skb_ptr, int nr_skb, int *more) 547 struct sk_buff ***skb_ptr, int nr_skb, int *more)
@@ -1246,7 +1256,7 @@ static int vxge_set_mac_addr(struct net_device *dev, void *p)
1246 * 1256 *
1247 * Enables the interrupts for the vpath 1257 * Enables the interrupts for the vpath
1248*/ 1258*/
1249void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id) 1259static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1250{ 1260{
1251 struct vxge_vpath *vpath = &vdev->vpaths[vp_id]; 1261 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1252 int msix_id = 0; 1262 int msix_id = 0;
@@ -1279,7 +1289,7 @@ void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1279 * 1289 *
1280 * Disables the interrupts for the vpath 1290 * Disables the interrupts for the vpath
1281*/ 1291*/
1282void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id) 1292static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1283{ 1293{
1284 struct vxge_vpath *vpath = &vdev->vpaths[vp_id]; 1294 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1285 int msix_id; 1295 int msix_id;
@@ -1553,7 +1563,7 @@ out:
1553 * 1563 *
1554 * driver may reset the chip on events of serr, eccerr, etc 1564 * driver may reset the chip on events of serr, eccerr, etc
1555 */ 1565 */
1556int vxge_reset(struct vxgedev *vdev) 1566static int vxge_reset(struct vxgedev *vdev)
1557{ 1567{
1558 return do_vxge_reset(vdev, VXGE_LL_FULL_RESET); 1568 return do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1559} 1569}
@@ -1724,7 +1734,7 @@ static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1724 return status; 1734 return status;
1725} 1735}
1726 1736
1727int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac) 1737static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
1728{ 1738{
1729 struct vxge_mac_addrs *new_mac_entry; 1739 struct vxge_mac_addrs *new_mac_entry;
1730 u8 *mac_address = NULL; 1740 u8 *mac_address = NULL;
@@ -1757,7 +1767,8 @@ int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
1757} 1767}
1758 1768
1759/* Add a mac address to DA table */ 1769/* Add a mac address to DA table */
1760enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac) 1770static enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev,
1771 struct macInfo *mac)
1761{ 1772{
1762 enum vxge_hw_status status = VXGE_HW_OK; 1773 enum vxge_hw_status status = VXGE_HW_OK;
1763 struct vxge_vpath *vpath; 1774 struct vxge_vpath *vpath;
@@ -1782,7 +1793,7 @@ enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1782 return status; 1793 return status;
1783} 1794}
1784 1795
1785int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac) 1796static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1786{ 1797{
1787 struct list_head *entry, *next; 1798 struct list_head *entry, *next;
1788 u64 del_mac = 0; 1799 u64 del_mac = 0;
@@ -1807,7 +1818,8 @@ int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1807 return FALSE; 1818 return FALSE;
1808} 1819}
1809/* delete a mac address from DA table */ 1820/* delete a mac address from DA table */
1810enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac) 1821static enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev,
1822 struct macInfo *mac)
1811{ 1823{
1812 enum vxge_hw_status status = VXGE_HW_OK; 1824 enum vxge_hw_status status = VXGE_HW_OK;
1813 struct vxge_vpath *vpath; 1825 struct vxge_vpath *vpath;
@@ -1854,7 +1866,7 @@ static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath,
1854} 1866}
1855 1867
1856/* Store all vlan ids from the list to the vid table */ 1868/* Store all vlan ids from the list to the vid table */
1857enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath) 1869static enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1858{ 1870{
1859 enum vxge_hw_status status = VXGE_HW_OK; 1871 enum vxge_hw_status status = VXGE_HW_OK;
1860 struct vxgedev *vdev = vpath->vdev; 1872 struct vxgedev *vdev = vpath->vdev;
@@ -1874,7 +1886,7 @@ enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1874} 1886}
1875 1887
1876/* Store all mac addresses from the list to the DA table */ 1888/* Store all mac addresses from the list to the DA table */
1877enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath) 1889static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1878{ 1890{
1879 enum vxge_hw_status status = VXGE_HW_OK; 1891 enum vxge_hw_status status = VXGE_HW_OK;
1880 struct macInfo mac_info; 1892 struct macInfo mac_info;
@@ -1916,7 +1928,7 @@ enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1916} 1928}
1917 1929
1918/* reset vpaths */ 1930/* reset vpaths */
1919enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev) 1931static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
1920{ 1932{
1921 enum vxge_hw_status status = VXGE_HW_OK; 1933 enum vxge_hw_status status = VXGE_HW_OK;
1922 struct vxge_vpath *vpath; 1934 struct vxge_vpath *vpath;
@@ -1948,7 +1960,7 @@ enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
1948} 1960}
1949 1961
1950/* close vpaths */ 1962/* close vpaths */
1951void vxge_close_vpaths(struct vxgedev *vdev, int index) 1963static void vxge_close_vpaths(struct vxgedev *vdev, int index)
1952{ 1964{
1953 struct vxge_vpath *vpath; 1965 struct vxge_vpath *vpath;
1954 int i; 1966 int i;
@@ -1966,7 +1978,7 @@ void vxge_close_vpaths(struct vxgedev *vdev, int index)
1966} 1978}
1967 1979
1968/* open vpaths */ 1980/* open vpaths */
1969int vxge_open_vpaths(struct vxgedev *vdev) 1981static int vxge_open_vpaths(struct vxgedev *vdev)
1970{ 1982{
1971 struct vxge_hw_vpath_attr attr; 1983 struct vxge_hw_vpath_attr attr;
1972 enum vxge_hw_status status; 1984 enum vxge_hw_status status;
@@ -2517,7 +2529,7 @@ static void vxge_poll_vp_lockup(unsigned long data)
2517 * Return value: '0' on success and an appropriate (-)ve integer as 2529 * Return value: '0' on success and an appropriate (-)ve integer as
2518 * defined in errno.h file on failure. 2530 * defined in errno.h file on failure.
2519 */ 2531 */
2520int 2532static int
2521vxge_open(struct net_device *dev) 2533vxge_open(struct net_device *dev)
2522{ 2534{
2523 enum vxge_hw_status status; 2535 enum vxge_hw_status status;
@@ -2721,7 +2733,7 @@ out0:
2721} 2733}
2722 2734
2723/* Loop throught the mac address list and delete all the entries */ 2735/* Loop throught the mac address list and delete all the entries */
2724void vxge_free_mac_add_list(struct vxge_vpath *vpath) 2736static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2725{ 2737{
2726 2738
2727 struct list_head *entry, *next; 2739 struct list_head *entry, *next;
@@ -2745,7 +2757,7 @@ static void vxge_napi_del_all(struct vxgedev *vdev)
2745 } 2757 }
2746} 2758}
2747 2759
2748int do_vxge_close(struct net_device *dev, int do_io) 2760static int do_vxge_close(struct net_device *dev, int do_io)
2749{ 2761{
2750 enum vxge_hw_status status; 2762 enum vxge_hw_status status;
2751 struct vxgedev *vdev; 2763 struct vxgedev *vdev;
@@ -2856,7 +2868,7 @@ int do_vxge_close(struct net_device *dev, int do_io)
2856 * Return value: '0' on success and an appropriate (-)ve integer as 2868 * Return value: '0' on success and an appropriate (-)ve integer as
2857 * defined in errno.h file on failure. 2869 * defined in errno.h file on failure.
2858 */ 2870 */
2859int 2871static int
2860vxge_close(struct net_device *dev) 2872vxge_close(struct net_device *dev)
2861{ 2873{
2862 do_vxge_close(dev, 1); 2874 do_vxge_close(dev, 1);
@@ -3113,10 +3125,10 @@ static const struct net_device_ops vxge_netdev_ops = {
3113#endif 3125#endif
3114}; 3126};
3115 3127
3116int __devinit vxge_device_register(struct __vxge_hw_device *hldev, 3128static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3117 struct vxge_config *config, 3129 struct vxge_config *config,
3118 int high_dma, int no_of_vpath, 3130 int high_dma, int no_of_vpath,
3119 struct vxgedev **vdev_out) 3131 struct vxgedev **vdev_out)
3120{ 3132{
3121 struct net_device *ndev; 3133 struct net_device *ndev;
3122 enum vxge_hw_status status = VXGE_HW_OK; 3134 enum vxge_hw_status status = VXGE_HW_OK;
@@ -3164,7 +3176,7 @@ int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3164 3176
3165 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT; 3177 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3166 3178
3167 initialize_ethtool_ops(ndev); 3179 vxge_initialize_ethtool_ops(ndev);
3168 3180
3169 /* Allocate memory for vpath */ 3181 /* Allocate memory for vpath */
3170 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) * 3182 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
@@ -3249,7 +3261,7 @@ _out0:
3249 * 3261 *
3250 * This function will unregister and free network device 3262 * This function will unregister and free network device
3251 */ 3263 */
3252void 3264static void
3253vxge_device_unregister(struct __vxge_hw_device *hldev) 3265vxge_device_unregister(struct __vxge_hw_device *hldev)
3254{ 3266{
3255 struct vxgedev *vdev; 3267 struct vxgedev *vdev;
diff --git a/drivers/net/vxge/vxge-main.h b/drivers/net/vxge/vxge-main.h
index d4be07eaacd7..de64536cb7d0 100644
--- a/drivers/net/vxge/vxge-main.h
+++ b/drivers/net/vxge/vxge-main.h
@@ -396,64 +396,7 @@ struct vxge_tx_priv {
396 mod_timer(&timer, (jiffies + exp)); \ 396 mod_timer(&timer, (jiffies + exp)); \
397 } while (0); 397 } while (0);
398 398
399int __devinit vxge_device_register(struct __vxge_hw_device *devh, 399extern void vxge_initialize_ethtool_ops(struct net_device *ndev);
400 struct vxge_config *config,
401 int high_dma, int no_of_vpath,
402 struct vxgedev **vdev);
403
404void vxge_device_unregister(struct __vxge_hw_device *devh);
405
406void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id);
407
408void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id);
409
410void vxge_callback_link_up(struct __vxge_hw_device *devh);
411
412void vxge_callback_link_down(struct __vxge_hw_device *devh);
413
414enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev,
415 struct macInfo *mac);
416
417int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac);
418
419int vxge_reset(struct vxgedev *vdev);
420
421enum vxge_hw_status
422vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
423 u8 t_code, void *userdata);
424
425enum vxge_hw_status
426vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
427 enum vxge_hw_fifo_tcode t_code, void *userdata,
428 struct sk_buff ***skb_ptr, int nr_skbs, int *more);
429
430int vxge_close(struct net_device *dev);
431
432int vxge_open(struct net_device *dev);
433
434void vxge_close_vpaths(struct vxgedev *vdev, int index);
435
436int vxge_open_vpaths(struct vxgedev *vdev);
437
438enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev);
439
440enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev,
441 struct macInfo *mac);
442
443enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev,
444 struct macInfo *mac);
445
446int vxge_mac_list_add(struct vxge_vpath *vpath,
447 struct macInfo *mac);
448
449void vxge_free_mac_add_list(struct vxge_vpath *vpath);
450
451enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath);
452
453enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath);
454
455int do_vxge_close(struct net_device *dev, int do_io);
456extern void initialize_ethtool_ops(struct net_device *ndev);
457/** 400/**
458 * #define VXGE_DEBUG_INIT: debug for initialization functions 401 * #define VXGE_DEBUG_INIT: debug for initialization functions
459 * #define VXGE_DEBUG_TX : debug transmit related functions 402 * #define VXGE_DEBUG_TX : debug transmit related functions
diff --git a/drivers/net/vxge/vxge-traffic.c b/drivers/net/vxge/vxge-traffic.c
index cedf08f99cb3..4bdb611a6842 100644
--- a/drivers/net/vxge/vxge-traffic.c
+++ b/drivers/net/vxge/vxge-traffic.c
@@ -17,6 +17,13 @@
17#include "vxge-config.h" 17#include "vxge-config.h"
18#include "vxge-main.h" 18#include "vxge-main.h"
19 19
20static enum vxge_hw_status
21__vxge_hw_device_handle_error(struct __vxge_hw_device *hldev,
22 u32 vp_id, enum vxge_hw_event type);
23static enum vxge_hw_status
24__vxge_hw_vpath_alarm_process(struct __vxge_hw_virtualpath *vpath,
25 u32 skip_alarms);
26
20/* 27/*
21 * vxge_hw_vpath_intr_enable - Enable vpath interrupts. 28 * vxge_hw_vpath_intr_enable - Enable vpath interrupts.
22 * @vp: Virtual Path handle. 29 * @vp: Virtual Path handle.
@@ -513,7 +520,7 @@ exit:
513 * Link up indication handler. The function is invoked by HW when 520 * Link up indication handler. The function is invoked by HW when
514 * Titan indicates that the link is up for programmable amount of time. 521 * Titan indicates that the link is up for programmable amount of time.
515 */ 522 */
516enum vxge_hw_status 523static enum vxge_hw_status
517__vxge_hw_device_handle_link_up_ind(struct __vxge_hw_device *hldev) 524__vxge_hw_device_handle_link_up_ind(struct __vxge_hw_device *hldev)
518{ 525{
519 /* 526 /*
@@ -538,7 +545,7 @@ exit:
538 * Link down indication handler. The function is invoked by HW when 545 * Link down indication handler. The function is invoked by HW when
539 * Titan indicates that the link is down. 546 * Titan indicates that the link is down.
540 */ 547 */
541enum vxge_hw_status 548static enum vxge_hw_status
542__vxge_hw_device_handle_link_down_ind(struct __vxge_hw_device *hldev) 549__vxge_hw_device_handle_link_down_ind(struct __vxge_hw_device *hldev)
543{ 550{
544 /* 551 /*
@@ -564,7 +571,7 @@ exit:
564 * 571 *
565 * Handle error. 572 * Handle error.
566 */ 573 */
567enum vxge_hw_status 574static enum vxge_hw_status
568__vxge_hw_device_handle_error( 575__vxge_hw_device_handle_error(
569 struct __vxge_hw_device *hldev, 576 struct __vxge_hw_device *hldev,
570 u32 vp_id, 577 u32 vp_id,
@@ -646,7 +653,7 @@ void vxge_hw_device_clear_tx_rx(struct __vxge_hw_device *hldev)
646 * it swaps the reserve and free arrays. 653 * it swaps the reserve and free arrays.
647 * 654 *
648 */ 655 */
649enum vxge_hw_status 656static enum vxge_hw_status
650vxge_hw_channel_dtr_alloc(struct __vxge_hw_channel *channel, void **dtrh) 657vxge_hw_channel_dtr_alloc(struct __vxge_hw_channel *channel, void **dtrh)
651{ 658{
652 void **tmp_arr; 659 void **tmp_arr;
@@ -692,7 +699,8 @@ _alloc_after_swap:
692 * Posts a dtr to work array. 699 * Posts a dtr to work array.
693 * 700 *
694 */ 701 */
695void vxge_hw_channel_dtr_post(struct __vxge_hw_channel *channel, void *dtrh) 702static void vxge_hw_channel_dtr_post(struct __vxge_hw_channel *channel,
703 void *dtrh)
696{ 704{
697 vxge_assert(channel->work_arr[channel->post_index] == NULL); 705 vxge_assert(channel->work_arr[channel->post_index] == NULL);
698 706
@@ -1658,37 +1666,6 @@ exit:
1658} 1666}
1659 1667
1660/** 1668/**
1661 * vxge_hw_vpath_vid_get_next - Get the next vid entry for this vpath
1662 * from vlan id table.
1663 * @vp: Vpath handle.
1664 * @vid: Buffer to return vlan id
1665 *
1666 * Returns the next vlan id in the list for this vpath.
1667 * see also: vxge_hw_vpath_vid_get
1668 *
1669 */
1670enum vxge_hw_status
1671vxge_hw_vpath_vid_get_next(struct __vxge_hw_vpath_handle *vp, u64 *vid)
1672{
1673 u64 data;
1674 enum vxge_hw_status status = VXGE_HW_OK;
1675
1676 if (vp == NULL) {
1677 status = VXGE_HW_ERR_INVALID_HANDLE;
1678 goto exit;
1679 }
1680
1681 status = __vxge_hw_vpath_rts_table_get(vp,
1682 VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_NEXT_ENTRY,
1683 VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_VID,
1684 0, vid, &data);
1685
1686 *vid = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_VLAN_ID(*vid);
1687exit:
1688 return status;
1689}
1690
1691/**
1692 * vxge_hw_vpath_vid_delete - Delete the vlan id entry for this vpath 1669 * vxge_hw_vpath_vid_delete - Delete the vlan id entry for this vpath
1693 * to vlan id table. 1670 * to vlan id table.
1694 * @vp: Vpath handle. 1671 * @vp: Vpath handle.
@@ -1898,9 +1875,9 @@ exit:
1898 * Process vpath alarms. 1875 * Process vpath alarms.
1899 * 1876 *
1900 */ 1877 */
1901enum vxge_hw_status __vxge_hw_vpath_alarm_process( 1878static enum vxge_hw_status
1902 struct __vxge_hw_virtualpath *vpath, 1879__vxge_hw_vpath_alarm_process(struct __vxge_hw_virtualpath *vpath,
1903 u32 skip_alarms) 1880 u32 skip_alarms)
1904{ 1881{
1905 u64 val64; 1882 u64 val64;
1906 u64 alarm_status; 1883 u64 alarm_status;
@@ -2265,36 +2242,6 @@ vxge_hw_vpath_msix_mask(struct __vxge_hw_vpath_handle *vp, int msix_id)
2265} 2242}
2266 2243
2267/** 2244/**
2268 * vxge_hw_vpath_msix_clear - Clear MSIX Vector.
2269 * @vp: Virtual Path handle.
2270 * @msix_id: MSI ID
2271 *
2272 * The function clears the msix interrupt for the given msix_id
2273 *
2274 * Returns: 0,
2275 * Otherwise, VXGE_HW_ERR_WRONG_IRQ if the msix index is out of range
2276 * status.
2277 * See also:
2278 */
2279void
2280vxge_hw_vpath_msix_clear(struct __vxge_hw_vpath_handle *vp, int msix_id)
2281{
2282 struct __vxge_hw_device *hldev = vp->vpath->hldev;
2283 if (hldev->config.intr_mode ==
2284 VXGE_HW_INTR_MODE_MSIX_ONE_SHOT) {
2285 __vxge_hw_pio_mem_write32_upper(
2286 (u32)vxge_bVALn(vxge_mBIT(msix_id >> 2), 0, 32),
2287 &hldev->common_reg->
2288 clr_msix_one_shot_vec[msix_id%4]);
2289 } else {
2290 __vxge_hw_pio_mem_write32_upper(
2291 (u32)vxge_bVALn(vxge_mBIT(msix_id >> 2), 0, 32),
2292 &hldev->common_reg->
2293 clear_msix_mask_vect[msix_id%4]);
2294 }
2295}
2296
2297/**
2298 * vxge_hw_vpath_msix_unmask - Unmask the MSIX Vector. 2245 * vxge_hw_vpath_msix_unmask - Unmask the MSIX Vector.
2299 * @vp: Virtual Path handle. 2246 * @vp: Virtual Path handle.
2300 * @msix_id: MSI ID 2247 * @msix_id: MSI ID
@@ -2316,22 +2263,6 @@ vxge_hw_vpath_msix_unmask(struct __vxge_hw_vpath_handle *vp, int msix_id)
2316} 2263}
2317 2264
2318/** 2265/**
2319 * vxge_hw_vpath_msix_mask_all - Mask all MSIX vectors for the vpath.
2320 * @vp: Virtual Path handle.
2321 *
2322 * The function masks all msix interrupt for the given vpath
2323 *
2324 */
2325void
2326vxge_hw_vpath_msix_mask_all(struct __vxge_hw_vpath_handle *vp)
2327{
2328
2329 __vxge_hw_pio_mem_write32_upper(
2330 (u32)vxge_bVALn(vxge_mBIT(vp->vpath->vp_id), 0, 32),
2331 &vp->vpath->hldev->common_reg->set_msix_mask_all_vect);
2332}
2333
2334/**
2335 * vxge_hw_vpath_inta_mask_tx_rx - Mask Tx and Rx interrupts. 2266 * vxge_hw_vpath_inta_mask_tx_rx - Mask Tx and Rx interrupts.
2336 * @vp: Virtual Path handle. 2267 * @vp: Virtual Path handle.
2337 * 2268 *
diff --git a/drivers/net/vxge/vxge-traffic.h b/drivers/net/vxge/vxge-traffic.h
index 6fa07d13798e..9890d4d596d0 100644
--- a/drivers/net/vxge/vxge-traffic.h
+++ b/drivers/net/vxge/vxge-traffic.h
@@ -1749,14 +1749,6 @@ vxge_hw_mrpcim_stats_access(
1749 u64 *stat); 1749 u64 *stat);
1750 1750
1751enum vxge_hw_status 1751enum vxge_hw_status
1752vxge_hw_device_xmac_aggr_stats_get(struct __vxge_hw_device *devh, u32 port,
1753 struct vxge_hw_xmac_aggr_stats *aggr_stats);
1754
1755enum vxge_hw_status
1756vxge_hw_device_xmac_port_stats_get(struct __vxge_hw_device *devh, u32 port,
1757 struct vxge_hw_xmac_port_stats *port_stats);
1758
1759enum vxge_hw_status
1760vxge_hw_device_xmac_stats_get(struct __vxge_hw_device *devh, 1752vxge_hw_device_xmac_stats_get(struct __vxge_hw_device *devh,
1761 struct vxge_hw_xmac_stats *xmac_stats); 1753 struct vxge_hw_xmac_stats *xmac_stats);
1762 1754
@@ -2117,49 +2109,10 @@ struct __vxge_hw_ring_rxd_priv {
2117#endif 2109#endif
2118}; 2110};
2119 2111
2120/* ========================= RING PRIVATE API ============================= */
2121u64
2122__vxge_hw_ring_first_block_address_get(
2123 struct __vxge_hw_ring *ringh);
2124
2125enum vxge_hw_status
2126__vxge_hw_ring_create(
2127 struct __vxge_hw_vpath_handle *vpath_handle,
2128 struct vxge_hw_ring_attr *attr);
2129
2130enum vxge_hw_status
2131__vxge_hw_ring_abort(
2132 struct __vxge_hw_ring *ringh);
2133
2134enum vxge_hw_status
2135__vxge_hw_ring_reset(
2136 struct __vxge_hw_ring *ringh);
2137
2138enum vxge_hw_status
2139__vxge_hw_ring_delete(
2140 struct __vxge_hw_vpath_handle *vpath_handle);
2141
2142/* ========================= FIFO PRIVATE API ============================= */ 2112/* ========================= FIFO PRIVATE API ============================= */
2143 2113
2144struct vxge_hw_fifo_attr; 2114struct vxge_hw_fifo_attr;
2145 2115
2146enum vxge_hw_status
2147__vxge_hw_fifo_create(
2148 struct __vxge_hw_vpath_handle *vpath_handle,
2149 struct vxge_hw_fifo_attr *attr);
2150
2151enum vxge_hw_status
2152__vxge_hw_fifo_abort(
2153 struct __vxge_hw_fifo *fifoh);
2154
2155enum vxge_hw_status
2156__vxge_hw_fifo_reset(
2157 struct __vxge_hw_fifo *ringh);
2158
2159enum vxge_hw_status
2160__vxge_hw_fifo_delete(
2161 struct __vxge_hw_vpath_handle *vpath_handle);
2162
2163struct vxge_hw_mempool_cbs { 2116struct vxge_hw_mempool_cbs {
2164 void (*item_func_alloc)( 2117 void (*item_func_alloc)(
2165 struct vxge_hw_mempool *mempoolh, 2118 struct vxge_hw_mempool *mempoolh,
@@ -2169,10 +2122,6 @@ struct vxge_hw_mempool_cbs {
2169 u32 is_last); 2122 u32 is_last);
2170}; 2123};
2171 2124
2172void
2173__vxge_hw_mempool_destroy(
2174 struct vxge_hw_mempool *mempool);
2175
2176#define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \ 2125#define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
2177 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next) 2126 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
2178 2127
@@ -2195,61 +2144,10 @@ __vxge_hw_vpath_rts_table_set(
2195 u64 data2); 2144 u64 data2);
2196 2145
2197enum vxge_hw_status 2146enum vxge_hw_status
2198__vxge_hw_vpath_reset(
2199 struct __vxge_hw_device *devh,
2200 u32 vp_id);
2201
2202enum vxge_hw_status
2203__vxge_hw_vpath_sw_reset(
2204 struct __vxge_hw_device *devh,
2205 u32 vp_id);
2206
2207enum vxge_hw_status
2208__vxge_hw_vpath_enable( 2147__vxge_hw_vpath_enable(
2209 struct __vxge_hw_device *devh, 2148 struct __vxge_hw_device *devh,
2210 u32 vp_id); 2149 u32 vp_id);
2211 2150
2212void
2213__vxge_hw_vpath_prc_configure(
2214 struct __vxge_hw_device *devh,
2215 u32 vp_id);
2216
2217enum vxge_hw_status
2218__vxge_hw_vpath_kdfc_configure(
2219 struct __vxge_hw_device *devh,
2220 u32 vp_id);
2221
2222enum vxge_hw_status
2223__vxge_hw_vpath_mac_configure(
2224 struct __vxge_hw_device *devh,
2225 u32 vp_id);
2226
2227enum vxge_hw_status
2228__vxge_hw_vpath_tim_configure(
2229 struct __vxge_hw_device *devh,
2230 u32 vp_id);
2231
2232enum vxge_hw_status
2233__vxge_hw_vpath_initialize(
2234 struct __vxge_hw_device *devh,
2235 u32 vp_id);
2236
2237enum vxge_hw_status
2238__vxge_hw_vp_initialize(
2239 struct __vxge_hw_device *devh,
2240 u32 vp_id,
2241 struct vxge_hw_vp_config *config);
2242
2243void
2244__vxge_hw_vp_terminate(
2245 struct __vxge_hw_device *devh,
2246 u32 vp_id);
2247
2248enum vxge_hw_status
2249__vxge_hw_vpath_alarm_process(
2250 struct __vxge_hw_virtualpath *vpath,
2251 u32 skip_alarms);
2252
2253void vxge_hw_device_intr_enable( 2151void vxge_hw_device_intr_enable(
2254 struct __vxge_hw_device *devh); 2152 struct __vxge_hw_device *devh);
2255 2153
@@ -2321,11 +2219,6 @@ vxge_hw_vpath_vid_get(
2321 u64 *vid); 2219 u64 *vid);
2322 2220
2323enum vxge_hw_status 2221enum vxge_hw_status
2324vxge_hw_vpath_vid_get_next(
2325 struct __vxge_hw_vpath_handle *vpath_handle,
2326 u64 *vid);
2327
2328enum vxge_hw_status
2329vxge_hw_vpath_vid_delete( 2222vxge_hw_vpath_vid_delete(
2330 struct __vxge_hw_vpath_handle *vpath_handle, 2223 struct __vxge_hw_vpath_handle *vpath_handle,
2331 u64 vid); 2224 u64 vid);
@@ -2387,16 +2280,9 @@ vxge_hw_vpath_msix_mask(struct __vxge_hw_vpath_handle *vpath_handle,
2387void vxge_hw_device_flush_io(struct __vxge_hw_device *devh); 2280void vxge_hw_device_flush_io(struct __vxge_hw_device *devh);
2388 2281
2389void 2282void
2390vxge_hw_vpath_msix_clear(struct __vxge_hw_vpath_handle *vpath_handle,
2391 int msix_id);
2392
2393void
2394vxge_hw_vpath_msix_unmask(struct __vxge_hw_vpath_handle *vpath_handle, 2283vxge_hw_vpath_msix_unmask(struct __vxge_hw_vpath_handle *vpath_handle,
2395 int msix_id); 2284 int msix_id);
2396 2285
2397void
2398vxge_hw_vpath_msix_mask_all(struct __vxge_hw_vpath_handle *vpath_handle);
2399
2400enum vxge_hw_status vxge_hw_vpath_intr_enable( 2286enum vxge_hw_status vxge_hw_vpath_intr_enable(
2401 struct __vxge_hw_vpath_handle *vpath_handle); 2287 struct __vxge_hw_vpath_handle *vpath_handle);
2402 2288
@@ -2415,12 +2301,6 @@ vxge_hw_channel_msix_mask(struct __vxge_hw_channel *channelh, int msix_id);
2415void 2301void
2416vxge_hw_channel_msix_unmask(struct __vxge_hw_channel *channelh, int msix_id); 2302vxge_hw_channel_msix_unmask(struct __vxge_hw_channel *channelh, int msix_id);
2417 2303
2418enum vxge_hw_status
2419vxge_hw_channel_dtr_alloc(struct __vxge_hw_channel *channel, void **dtrh);
2420
2421void
2422vxge_hw_channel_dtr_post(struct __vxge_hw_channel *channel, void *dtrh);
2423
2424void 2304void
2425vxge_hw_channel_dtr_try_complete(struct __vxge_hw_channel *channel, 2305vxge_hw_channel_dtr_try_complete(struct __vxge_hw_channel *channel,
2426 void **dtrh); 2306 void **dtrh);
@@ -2436,18 +2316,4 @@ vxge_hw_channel_dtr_count(struct __vxge_hw_channel *channel);
2436void 2316void
2437vxge_hw_vpath_tti_ci_set(struct __vxge_hw_device *hldev, u32 vp_id); 2317vxge_hw_vpath_tti_ci_set(struct __vxge_hw_device *hldev, u32 vp_id);
2438 2318
2439/* ========================== PRIVATE API ================================= */
2440
2441enum vxge_hw_status
2442__vxge_hw_device_handle_link_up_ind(struct __vxge_hw_device *hldev);
2443
2444enum vxge_hw_status
2445__vxge_hw_device_handle_link_down_ind(struct __vxge_hw_device *hldev);
2446
2447enum vxge_hw_status
2448__vxge_hw_device_handle_error(
2449 struct __vxge_hw_device *hldev,
2450 u32 vp_id,
2451 enum vxge_hw_event type);
2452
2453#endif 2319#endif
diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
index f1ae75d35d5d..8251946842e6 100644
--- a/drivers/net/wireless/ath/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -3580,6 +3580,7 @@ ath5k_pci_probe(struct pci_dev *pdev,
3580 common->ah = sc->ah; 3580 common->ah = sc->ah;
3581 common->hw = hw; 3581 common->hw = hw;
3582 common->cachelsz = csz << 2; /* convert to bytes */ 3582 common->cachelsz = csz << 2; /* convert to bytes */
3583 spin_lock_init(&common->cc_lock);
3583 3584
3584 /* Initialize device */ 3585 /* Initialize device */
3585 ret = ath5k_hw_attach(sc); 3586 ret = ath5k_hw_attach(sc);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_2p2_initvals.h b/drivers/net/wireless/ath/ath9k/ar9003_2p2_initvals.h
index ec98ab50748a..a14a5e43cf56 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_2p2_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar9003_2p2_initvals.h
@@ -34,6 +34,10 @@ static const u32 ar9300_2p2_radio_postamble[][5] = {
34 34
35static const u32 ar9300Modes_lowest_ob_db_tx_gain_table_2p2[][5] = { 35static const u32 ar9300Modes_lowest_ob_db_tx_gain_table_2p2[][5] = {
36 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ 36 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
37 {0x0000a2dc, 0x0380c7fc, 0x0380c7fc, 0x00637800, 0x00637800},
38 {0x0000a2e0, 0x0000f800, 0x0000f800, 0x03838000, 0x03838000},
39 {0x0000a2e4, 0x03ff0000, 0x03ff0000, 0x03fc0000, 0x03fc0000},
40 {0x0000a2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
37 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d9, 0x000050d9}, 41 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d9, 0x000050d9},
38 {0x0000a500, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 42 {0x0000a500, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
39 {0x0000a504, 0x06000003, 0x06000003, 0x04000002, 0x04000002}, 43 {0x0000a504, 0x06000003, 0x06000003, 0x04000002, 0x04000002},
@@ -99,6 +103,30 @@ static const u32 ar9300Modes_lowest_ob_db_tx_gain_table_2p2[][5] = {
99 {0x0000a5f4, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec}, 103 {0x0000a5f4, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec},
100 {0x0000a5f8, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec}, 104 {0x0000a5f8, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec},
101 {0x0000a5fc, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec}, 105 {0x0000a5fc, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec},
106 {0x0000a600, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
107 {0x0000a604, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
108 {0x0000a608, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
109 {0x0000a60c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
110 {0x0000a610, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
111 {0x0000a614, 0x01404000, 0x01404000, 0x01404000, 0x01404000},
112 {0x0000a618, 0x01404501, 0x01404501, 0x01404501, 0x01404501},
113 {0x0000a61c, 0x02008802, 0x02008802, 0x02008501, 0x02008501},
114 {0x0000a620, 0x0300cc03, 0x0300cc03, 0x0280ca03, 0x0280ca03},
115 {0x0000a624, 0x0300cc03, 0x0300cc03, 0x03010c04, 0x03010c04},
116 {0x0000a628, 0x0300cc03, 0x0300cc03, 0x04014c04, 0x04014c04},
117 {0x0000a62c, 0x03810c03, 0x03810c03, 0x04015005, 0x04015005},
118 {0x0000a630, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
119 {0x0000a634, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
120 {0x0000a638, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
121 {0x0000a63c, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
122 {0x0000b2dc, 0x0380c7fc, 0x0380c7fc, 0x00637800, 0x00637800},
123 {0x0000b2e0, 0x0000f800, 0x0000f800, 0x03838000, 0x03838000},
124 {0x0000b2e4, 0x03ff0000, 0x03ff0000, 0x03fc0000, 0x03fc0000},
125 {0x0000b2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
126 {0x0000c2dc, 0x0380c7fc, 0x0380c7fc, 0x00637800, 0x00637800},
127 {0x0000c2e0, 0x0000f800, 0x0000f800, 0x03838000, 0x03838000},
128 {0x0000c2e4, 0x03ff0000, 0x03ff0000, 0x03fc0000, 0x03fc0000},
129 {0x0000c2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
102 {0x00016044, 0x012492d4, 0x012492d4, 0x012492d4, 0x012492d4}, 130 {0x00016044, 0x012492d4, 0x012492d4, 0x012492d4, 0x012492d4},
103 {0x00016048, 0x62480001, 0x62480001, 0x62480001, 0x62480001}, 131 {0x00016048, 0x62480001, 0x62480001, 0x62480001, 0x62480001},
104 {0x00016068, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c}, 132 {0x00016068, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c},
@@ -118,7 +146,7 @@ static const u32 ar9300Modes_fast_clock_2p2[][3] = {
118 {0x00008014, 0x044c044c, 0x08980898}, 146 {0x00008014, 0x044c044c, 0x08980898},
119 {0x0000801c, 0x148ec02b, 0x148ec057}, 147 {0x0000801c, 0x148ec02b, 0x148ec057},
120 {0x00008318, 0x000044c0, 0x00008980}, 148 {0x00008318, 0x000044c0, 0x00008980},
121 {0x00009e00, 0x03721821, 0x03721821}, 149 {0x00009e00, 0x0372131c, 0x0372131c},
122 {0x0000a230, 0x0000000b, 0x00000016}, 150 {0x0000a230, 0x0000000b, 0x00000016},
123 {0x0000a254, 0x00000898, 0x00001130}, 151 {0x0000a254, 0x00000898, 0x00001130},
124}; 152};
@@ -595,15 +623,16 @@ static const u32 ar9300_2p2_baseband_postamble[][5] = {
595 {0x0000982c, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4}, 623 {0x0000982c, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4},
596 {0x00009830, 0x0000059c, 0x0000059c, 0x0000119c, 0x0000119c}, 624 {0x00009830, 0x0000059c, 0x0000059c, 0x0000119c, 0x0000119c},
597 {0x00009c00, 0x000000c4, 0x000000c4, 0x000000c4, 0x000000c4}, 625 {0x00009c00, 0x000000c4, 0x000000c4, 0x000000c4, 0x000000c4},
598 {0x00009e00, 0x0372161e, 0x0372161e, 0x037216a0, 0x037216a0}, 626 {0x00009e00, 0x0372111a, 0x0372111a, 0x037216a0, 0x037216a0},
599 {0x00009e04, 0x00802020, 0x00802020, 0x00802020, 0x00802020}, 627 {0x00009e04, 0x001c2020, 0x001c2020, 0x001c2020, 0x001c2020},
600 {0x00009e0c, 0x6c4000e2, 0x6d4000e2, 0x6d4000e2, 0x6c4000e2}, 628 {0x00009e0c, 0x6c4000e2, 0x6d4000e2, 0x6d4000e2, 0x6c4000e2},
601 {0x00009e10, 0x7ec88d2e, 0x7ec88d2e, 0x7ec84d2e, 0x7ec84d2e}, 629 {0x00009e10, 0x7ec88d2e, 0x7ec88d2e, 0x7ec84d2e, 0x7ec84d2e},
602 {0x00009e14, 0x31395d5e, 0x3139605e, 0x3139605e, 0x31395d5e}, 630 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3379605e, 0x33795d5e},
603 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 631 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
604 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c}, 632 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c},
605 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003ce, 0x000003ce}, 633 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003ce, 0x000003ce},
606 {0x00009e2c, 0x0000001c, 0x0000001c, 0x00000021, 0x00000021}, 634 {0x00009e2c, 0x0000001c, 0x0000001c, 0x00000021, 0x00000021},
635 {0x00009e3c, 0xcf946220, 0xcf946220, 0xcf946222, 0xcf946222},
607 {0x00009e44, 0x02321e27, 0x02321e27, 0x02291e27, 0x02291e27}, 636 {0x00009e44, 0x02321e27, 0x02321e27, 0x02291e27, 0x02291e27},
608 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302012, 0x50302012}, 637 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302012, 0x50302012},
609 {0x00009fc8, 0x0003f000, 0x0003f000, 0x0001a000, 0x0001a000}, 638 {0x00009fc8, 0x0003f000, 0x0003f000, 0x0001a000, 0x0001a000},
@@ -624,16 +653,16 @@ static const u32 ar9300_2p2_baseband_postamble[][5] = {
624 {0x0000a28c, 0x00022222, 0x00022222, 0x00022222, 0x00022222}, 653 {0x0000a28c, 0x00022222, 0x00022222, 0x00022222, 0x00022222},
625 {0x0000a2c4, 0x00158d18, 0x00158d18, 0x00158d18, 0x00158d18}, 654 {0x0000a2c4, 0x00158d18, 0x00158d18, 0x00158d18, 0x00158d18},
626 {0x0000a2d0, 0x00071981, 0x00071981, 0x00071981, 0x00071982}, 655 {0x0000a2d0, 0x00071981, 0x00071981, 0x00071981, 0x00071982},
627 {0x0000a2d8, 0xf999a83a, 0xf999a83a, 0xf999a83a, 0xf999a83a}, 656 {0x0000a2d8, 0x7999a83a, 0x7999a83a, 0x7999a83a, 0x7999a83a},
628 {0x0000a358, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 657 {0x0000a358, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
629 {0x0000a830, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c}, 658 {0x0000a830, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c},
630 {0x0000ae04, 0x00800000, 0x00800000, 0x00800000, 0x00800000}, 659 {0x0000ae04, 0x001c0000, 0x001c0000, 0x001c0000, 0x001c0000},
631 {0x0000ae18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 660 {0x0000ae18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
632 {0x0000ae1c, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c}, 661 {0x0000ae1c, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c},
633 {0x0000ae20, 0x000001b5, 0x000001b5, 0x000001ce, 0x000001ce}, 662 {0x0000ae20, 0x000001b5, 0x000001b5, 0x000001ce, 0x000001ce},
634 {0x0000b284, 0x00000000, 0x00000000, 0x00000150, 0x00000150}, 663 {0x0000b284, 0x00000000, 0x00000000, 0x00000150, 0x00000150},
635 {0x0000b830, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c}, 664 {0x0000b830, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c},
636 {0x0000be04, 0x00800000, 0x00800000, 0x00800000, 0x00800000}, 665 {0x0000be04, 0x001c0000, 0x001c0000, 0x001c0000, 0x001c0000},
637 {0x0000be18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 666 {0x0000be18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
638 {0x0000be1c, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c}, 667 {0x0000be1c, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c},
639 {0x0000be20, 0x000001b5, 0x000001b5, 0x000001ce, 0x000001ce}, 668 {0x0000be20, 0x000001b5, 0x000001b5, 0x000001ce, 0x000001ce},
@@ -649,13 +678,13 @@ static const u32 ar9300_2p2_baseband_core[][2] = {
649 {0x00009814, 0x9280c00a}, 678 {0x00009814, 0x9280c00a},
650 {0x00009818, 0x00000000}, 679 {0x00009818, 0x00000000},
651 {0x0000981c, 0x00020028}, 680 {0x0000981c, 0x00020028},
652 {0x00009834, 0x5f3ca3de}, 681 {0x00009834, 0x6400a290},
653 {0x00009838, 0x0108ecff}, 682 {0x00009838, 0x0108ecff},
654 {0x0000983c, 0x14750600}, 683 {0x0000983c, 0x14750600},
655 {0x00009880, 0x201fff00}, 684 {0x00009880, 0x201fff00},
656 {0x00009884, 0x00001042}, 685 {0x00009884, 0x00001042},
657 {0x000098a4, 0x00200400}, 686 {0x000098a4, 0x00200400},
658 {0x000098b0, 0x52440bbe}, 687 {0x000098b0, 0x32840bbe},
659 {0x000098d0, 0x004b6a8e}, 688 {0x000098d0, 0x004b6a8e},
660 {0x000098d4, 0x00000820}, 689 {0x000098d4, 0x00000820},
661 {0x000098dc, 0x00000000}, 690 {0x000098dc, 0x00000000},
@@ -681,7 +710,6 @@ static const u32 ar9300_2p2_baseband_core[][2] = {
681 {0x00009e30, 0x06336f77}, 710 {0x00009e30, 0x06336f77},
682 {0x00009e34, 0x6af6532f}, 711 {0x00009e34, 0x6af6532f},
683 {0x00009e38, 0x0cc80c00}, 712 {0x00009e38, 0x0cc80c00},
684 {0x00009e3c, 0xcf946222},
685 {0x00009e40, 0x0d261820}, 713 {0x00009e40, 0x0d261820},
686 {0x00009e4c, 0x00001004}, 714 {0x00009e4c, 0x00001004},
687 {0x00009e50, 0x00ff03f1}, 715 {0x00009e50, 0x00ff03f1},
@@ -694,7 +722,7 @@ static const u32 ar9300_2p2_baseband_core[][2] = {
694 {0x0000a220, 0x00000000}, 722 {0x0000a220, 0x00000000},
695 {0x0000a224, 0x00000000}, 723 {0x0000a224, 0x00000000},
696 {0x0000a228, 0x10002310}, 724 {0x0000a228, 0x10002310},
697 {0x0000a22c, 0x01036a1e}, 725 {0x0000a22c, 0x01036a27},
698 {0x0000a23c, 0x00000000}, 726 {0x0000a23c, 0x00000000},
699 {0x0000a244, 0x0c000000}, 727 {0x0000a244, 0x0c000000},
700 {0x0000a2a0, 0x00000001}, 728 {0x0000a2a0, 0x00000001},
@@ -702,10 +730,6 @@ static const u32 ar9300_2p2_baseband_core[][2] = {
702 {0x0000a2c8, 0x00000000}, 730 {0x0000a2c8, 0x00000000},
703 {0x0000a2cc, 0x18c43433}, 731 {0x0000a2cc, 0x18c43433},
704 {0x0000a2d4, 0x00000000}, 732 {0x0000a2d4, 0x00000000},
705 {0x0000a2dc, 0x00000000},
706 {0x0000a2e0, 0x00000000},
707 {0x0000a2e4, 0x00000000},
708 {0x0000a2e8, 0x00000000},
709 {0x0000a2ec, 0x00000000}, 733 {0x0000a2ec, 0x00000000},
710 {0x0000a2f0, 0x00000000}, 734 {0x0000a2f0, 0x00000000},
711 {0x0000a2f4, 0x00000000}, 735 {0x0000a2f4, 0x00000000},
@@ -753,33 +777,17 @@ static const u32 ar9300_2p2_baseband_core[][2] = {
753 {0x0000a430, 0x1ce739ce}, 777 {0x0000a430, 0x1ce739ce},
754 {0x0000a434, 0x00000000}, 778 {0x0000a434, 0x00000000},
755 {0x0000a438, 0x00001801}, 779 {0x0000a438, 0x00001801},
756 {0x0000a43c, 0x00000000}, 780 {0x0000a43c, 0x00100000},
757 {0x0000a440, 0x00000000}, 781 {0x0000a440, 0x00000000},
758 {0x0000a444, 0x00000000}, 782 {0x0000a444, 0x00000000},
759 {0x0000a448, 0x06000080}, 783 {0x0000a448, 0x06000080},
760 {0x0000a44c, 0x00000001}, 784 {0x0000a44c, 0x00000001},
761 {0x0000a450, 0x00010000}, 785 {0x0000a450, 0x00010000},
762 {0x0000a458, 0x00000000}, 786 {0x0000a458, 0x00000000},
763 {0x0000a600, 0x00000000},
764 {0x0000a604, 0x00000000},
765 {0x0000a608, 0x00000000},
766 {0x0000a60c, 0x00000000},
767 {0x0000a610, 0x00000000},
768 {0x0000a614, 0x00000000},
769 {0x0000a618, 0x00000000},
770 {0x0000a61c, 0x00000000},
771 {0x0000a620, 0x00000000},
772 {0x0000a624, 0x00000000},
773 {0x0000a628, 0x00000000},
774 {0x0000a62c, 0x00000000},
775 {0x0000a630, 0x00000000},
776 {0x0000a634, 0x00000000},
777 {0x0000a638, 0x00000000},
778 {0x0000a63c, 0x00000000},
779 {0x0000a640, 0x00000000}, 787 {0x0000a640, 0x00000000},
780 {0x0000a644, 0x3fad9d74}, 788 {0x0000a644, 0x3fad9d74},
781 {0x0000a648, 0x0048060a}, 789 {0x0000a648, 0x0048060a},
782 {0x0000a64c, 0x00000637}, 790 {0x0000a64c, 0x00003c37},
783 {0x0000a670, 0x03020100}, 791 {0x0000a670, 0x03020100},
784 {0x0000a674, 0x09080504}, 792 {0x0000a674, 0x09080504},
785 {0x0000a678, 0x0d0c0b0a}, 793 {0x0000a678, 0x0d0c0b0a},
@@ -802,10 +810,6 @@ static const u32 ar9300_2p2_baseband_core[][2] = {
802 {0x0000a8f4, 0x00000000}, 810 {0x0000a8f4, 0x00000000},
803 {0x0000b2d0, 0x00000080}, 811 {0x0000b2d0, 0x00000080},
804 {0x0000b2d4, 0x00000000}, 812 {0x0000b2d4, 0x00000000},
805 {0x0000b2dc, 0x00000000},
806 {0x0000b2e0, 0x00000000},
807 {0x0000b2e4, 0x00000000},
808 {0x0000b2e8, 0x00000000},
809 {0x0000b2ec, 0x00000000}, 813 {0x0000b2ec, 0x00000000},
810 {0x0000b2f0, 0x00000000}, 814 {0x0000b2f0, 0x00000000},
811 {0x0000b2f4, 0x00000000}, 815 {0x0000b2f4, 0x00000000},
@@ -820,10 +824,6 @@ static const u32 ar9300_2p2_baseband_core[][2] = {
820 {0x0000b8f4, 0x00000000}, 824 {0x0000b8f4, 0x00000000},
821 {0x0000c2d0, 0x00000080}, 825 {0x0000c2d0, 0x00000080},
822 {0x0000c2d4, 0x00000000}, 826 {0x0000c2d4, 0x00000000},
823 {0x0000c2dc, 0x00000000},
824 {0x0000c2e0, 0x00000000},
825 {0x0000c2e4, 0x00000000},
826 {0x0000c2e8, 0x00000000},
827 {0x0000c2ec, 0x00000000}, 827 {0x0000c2ec, 0x00000000},
828 {0x0000c2f0, 0x00000000}, 828 {0x0000c2f0, 0x00000000},
829 {0x0000c2f4, 0x00000000}, 829 {0x0000c2f4, 0x00000000},
@@ -835,6 +835,10 @@ static const u32 ar9300_2p2_baseband_core[][2] = {
835 835
836static const u32 ar9300Modes_high_power_tx_gain_table_2p2[][5] = { 836static const u32 ar9300Modes_high_power_tx_gain_table_2p2[][5] = {
837 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ 837 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
838 {0x0000a2dc, 0x0380c7fc, 0x0380c7fc, 0x00637800, 0x00637800},
839 {0x0000a2e0, 0x0000f800, 0x0000f800, 0x03838000, 0x03838000},
840 {0x0000a2e4, 0x03ff0000, 0x03ff0000, 0x03fc0000, 0x03fc0000},
841 {0x0000a2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
838 {0x0000a410, 0x000050d8, 0x000050d8, 0x000050d9, 0x000050d9}, 842 {0x0000a410, 0x000050d8, 0x000050d8, 0x000050d9, 0x000050d9},
839 {0x0000a500, 0x00002220, 0x00002220, 0x00000000, 0x00000000}, 843 {0x0000a500, 0x00002220, 0x00002220, 0x00000000, 0x00000000},
840 {0x0000a504, 0x04002222, 0x04002222, 0x04000002, 0x04000002}, 844 {0x0000a504, 0x04002222, 0x04002222, 0x04000002, 0x04000002},
@@ -855,7 +859,7 @@ static const u32 ar9300Modes_high_power_tx_gain_table_2p2[][5] = {
855 {0x0000a540, 0x49005e72, 0x49005e72, 0x38001660, 0x38001660}, 859 {0x0000a540, 0x49005e72, 0x49005e72, 0x38001660, 0x38001660},
856 {0x0000a544, 0x4e005eb2, 0x4e005eb2, 0x3b001861, 0x3b001861}, 860 {0x0000a544, 0x4e005eb2, 0x4e005eb2, 0x3b001861, 0x3b001861},
857 {0x0000a548, 0x53005f12, 0x53005f12, 0x3e001a81, 0x3e001a81}, 861 {0x0000a548, 0x53005f12, 0x53005f12, 0x3e001a81, 0x3e001a81},
858 {0x0000a54c, 0x59025eb5, 0x59025eb5, 0x42001a83, 0x42001a83}, 862 {0x0000a54c, 0x59025eb2, 0x59025eb2, 0x42001a83, 0x42001a83},
859 {0x0000a550, 0x5e025f12, 0x5e025f12, 0x44001c84, 0x44001c84}, 863 {0x0000a550, 0x5e025f12, 0x5e025f12, 0x44001c84, 0x44001c84},
860 {0x0000a554, 0x61027f12, 0x61027f12, 0x48001ce3, 0x48001ce3}, 864 {0x0000a554, 0x61027f12, 0x61027f12, 0x48001ce3, 0x48001ce3},
861 {0x0000a558, 0x6702bf12, 0x6702bf12, 0x4c001ce5, 0x4c001ce5}, 865 {0x0000a558, 0x6702bf12, 0x6702bf12, 0x4c001ce5, 0x4c001ce5},
@@ -900,6 +904,30 @@ static const u32 ar9300Modes_high_power_tx_gain_table_2p2[][5] = {
900 {0x0000a5f4, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec}, 904 {0x0000a5f4, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec},
901 {0x0000a5f8, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec}, 905 {0x0000a5f8, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec},
902 {0x0000a5fc, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec}, 906 {0x0000a5fc, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec},
907 {0x0000a600, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
908 {0x0000a604, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
909 {0x0000a608, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
910 {0x0000a60c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
911 {0x0000a610, 0x00804000, 0x00804000, 0x00000000, 0x00000000},
912 {0x0000a614, 0x00804201, 0x00804201, 0x01404000, 0x01404000},
913 {0x0000a618, 0x0280c802, 0x0280c802, 0x01404501, 0x01404501},
914 {0x0000a61c, 0x0280ca03, 0x0280ca03, 0x02008501, 0x02008501},
915 {0x0000a620, 0x04c15104, 0x04c15104, 0x0280ca03, 0x0280ca03},
916 {0x0000a624, 0x04c15305, 0x04c15305, 0x03010c04, 0x03010c04},
917 {0x0000a628, 0x04c15305, 0x04c15305, 0x04014c04, 0x04014c04},
918 {0x0000a62c, 0x04c15305, 0x04c15305, 0x04015005, 0x04015005},
919 {0x0000a630, 0x04c15305, 0x04c15305, 0x04015005, 0x04015005},
920 {0x0000a634, 0x04c15305, 0x04c15305, 0x04015005, 0x04015005},
921 {0x0000a638, 0x04c15305, 0x04c15305, 0x04015005, 0x04015005},
922 {0x0000a63c, 0x04c15305, 0x04c15305, 0x04015005, 0x04015005},
923 {0x0000b2dc, 0x0380c7fc, 0x0380c7fc, 0x00637800, 0x00637800},
924 {0x0000b2e0, 0x0000f800, 0x0000f800, 0x03838000, 0x03838000},
925 {0x0000b2e4, 0x03ff0000, 0x03ff0000, 0x03fc0000, 0x03fc0000},
926 {0x0000b2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
927 {0x0000c2dc, 0x0380c7fc, 0x0380c7fc, 0x00637800, 0x00637800},
928 {0x0000c2e0, 0x0000f800, 0x0000f800, 0x03838000, 0x03838000},
929 {0x0000c2e4, 0x03ff0000, 0x03ff0000, 0x03fc0000, 0x03fc0000},
930 {0x0000c2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
903 {0x00016044, 0x056db2e6, 0x056db2e6, 0x056db2e6, 0x056db2e6}, 931 {0x00016044, 0x056db2e6, 0x056db2e6, 0x056db2e6, 0x056db2e6},
904 {0x00016048, 0xae480001, 0xae480001, 0xae480001, 0xae480001}, 932 {0x00016048, 0xae480001, 0xae480001, 0xae480001, 0xae480001},
905 {0x00016068, 0x6eb6db6c, 0x6eb6db6c, 0x6eb6db6c, 0x6eb6db6c}, 933 {0x00016068, 0x6eb6db6c, 0x6eb6db6c, 0x6eb6db6c, 0x6eb6db6c},
@@ -913,6 +941,10 @@ static const u32 ar9300Modes_high_power_tx_gain_table_2p2[][5] = {
913 941
914static const u32 ar9300Modes_high_ob_db_tx_gain_table_2p2[][5] = { 942static const u32 ar9300Modes_high_ob_db_tx_gain_table_2p2[][5] = {
915 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ 943 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
944 {0x0000a2dc, 0x01feee00, 0x01feee00, 0x00637800, 0x00637800},
945 {0x0000a2e0, 0x0000f000, 0x0000f000, 0x03838000, 0x03838000},
946 {0x0000a2e4, 0x01ff0000, 0x01ff0000, 0x03fc0000, 0x03fc0000},
947 {0x0000a2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
916 {0x0000a410, 0x000050d8, 0x000050d8, 0x000050d9, 0x000050d9}, 948 {0x0000a410, 0x000050d8, 0x000050d8, 0x000050d9, 0x000050d9},
917 {0x0000a500, 0x00002220, 0x00002220, 0x00000000, 0x00000000}, 949 {0x0000a500, 0x00002220, 0x00002220, 0x00000000, 0x00000000},
918 {0x0000a504, 0x04002222, 0x04002222, 0x04000002, 0x04000002}, 950 {0x0000a504, 0x04002222, 0x04002222, 0x04000002, 0x04000002},
@@ -933,7 +965,7 @@ static const u32 ar9300Modes_high_ob_db_tx_gain_table_2p2[][5] = {
933 {0x0000a540, 0x49005e72, 0x49005e72, 0x38001660, 0x38001660}, 965 {0x0000a540, 0x49005e72, 0x49005e72, 0x38001660, 0x38001660},
934 {0x0000a544, 0x4e005eb2, 0x4e005eb2, 0x3b001861, 0x3b001861}, 966 {0x0000a544, 0x4e005eb2, 0x4e005eb2, 0x3b001861, 0x3b001861},
935 {0x0000a548, 0x53005f12, 0x53005f12, 0x3e001a81, 0x3e001a81}, 967 {0x0000a548, 0x53005f12, 0x53005f12, 0x3e001a81, 0x3e001a81},
936 {0x0000a54c, 0x59025eb5, 0x59025eb5, 0x42001a83, 0x42001a83}, 968 {0x0000a54c, 0x59025eb2, 0x59025eb2, 0x42001a83, 0x42001a83},
937 {0x0000a550, 0x5e025f12, 0x5e025f12, 0x44001c84, 0x44001c84}, 969 {0x0000a550, 0x5e025f12, 0x5e025f12, 0x44001c84, 0x44001c84},
938 {0x0000a554, 0x61027f12, 0x61027f12, 0x48001ce3, 0x48001ce3}, 970 {0x0000a554, 0x61027f12, 0x61027f12, 0x48001ce3, 0x48001ce3},
939 {0x0000a558, 0x6702bf12, 0x6702bf12, 0x4c001ce5, 0x4c001ce5}, 971 {0x0000a558, 0x6702bf12, 0x6702bf12, 0x4c001ce5, 0x4c001ce5},
@@ -978,6 +1010,30 @@ static const u32 ar9300Modes_high_ob_db_tx_gain_table_2p2[][5] = {
978 {0x0000a5f4, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec}, 1010 {0x0000a5f4, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec},
979 {0x0000a5f8, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec}, 1011 {0x0000a5f8, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec},
980 {0x0000a5fc, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec}, 1012 {0x0000a5fc, 0x6f82bf16, 0x6f82bf16, 0x56801eec, 0x56801eec},
1013 {0x0000a600, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1014 {0x0000a604, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1015 {0x0000a608, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1016 {0x0000a60c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1017 {0x0000a610, 0x00804000, 0x00804000, 0x00000000, 0x00000000},
1018 {0x0000a614, 0x00804201, 0x00804201, 0x01404000, 0x01404000},
1019 {0x0000a618, 0x0280c802, 0x0280c802, 0x01404501, 0x01404501},
1020 {0x0000a61c, 0x0280ca03, 0x0280ca03, 0x02008501, 0x02008501},
1021 {0x0000a620, 0x04c15104, 0x04c15104, 0x0280ca03, 0x0280ca03},
1022 {0x0000a624, 0x04c15305, 0x04c15305, 0x03010c04, 0x03010c04},
1023 {0x0000a628, 0x04c15305, 0x04c15305, 0x04014c04, 0x04014c04},
1024 {0x0000a62c, 0x04c15305, 0x04c15305, 0x04015005, 0x04015005},
1025 {0x0000a630, 0x04c15305, 0x04c15305, 0x04015005, 0x04015005},
1026 {0x0000a634, 0x04c15305, 0x04c15305, 0x04015005, 0x04015005},
1027 {0x0000a638, 0x04c15305, 0x04c15305, 0x04015005, 0x04015005},
1028 {0x0000a63c, 0x04c15305, 0x04c15305, 0x04015005, 0x04015005},
1029 {0x0000b2dc, 0x01feee00, 0x01feee00, 0x00637800, 0x00637800},
1030 {0x0000b2e0, 0x0000f000, 0x0000f000, 0x03838000, 0x03838000},
1031 {0x0000b2e4, 0x01ff0000, 0x01ff0000, 0x03fc0000, 0x03fc0000},
1032 {0x0000b2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1033 {0x0000c2dc, 0x01feee00, 0x01feee00, 0x00637800, 0x00637800},
1034 {0x0000c2e0, 0x0000f000, 0x0000f000, 0x03838000, 0x03838000},
1035 {0x0000c2e4, 0x01ff0000, 0x01ff0000, 0x03fc0000, 0x03fc0000},
1036 {0x0000c2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
981 {0x00016044, 0x056db2e4, 0x056db2e4, 0x056db2e4, 0x056db2e4}, 1037 {0x00016044, 0x056db2e4, 0x056db2e4, 0x056db2e4, 0x056db2e4},
982 {0x00016048, 0x8e480001, 0x8e480001, 0x8e480001, 0x8e480001}, 1038 {0x00016048, 0x8e480001, 0x8e480001, 0x8e480001, 0x8e480001},
983 {0x00016068, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c}, 1039 {0x00016068, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c},
@@ -1151,14 +1207,14 @@ static const u32 ar9300Common_rx_gain_table_2p2[][2] = {
1151 {0x0000b074, 0x00000000}, 1207 {0x0000b074, 0x00000000},
1152 {0x0000b078, 0x00000000}, 1208 {0x0000b078, 0x00000000},
1153 {0x0000b07c, 0x00000000}, 1209 {0x0000b07c, 0x00000000},
1154 {0x0000b080, 0x32323232}, 1210 {0x0000b080, 0x2a2d2f32},
1155 {0x0000b084, 0x2f2f3232}, 1211 {0x0000b084, 0x21232328},
1156 {0x0000b088, 0x23282a2d}, 1212 {0x0000b088, 0x19191c1e},
1157 {0x0000b08c, 0x1c1e2123}, 1213 {0x0000b08c, 0x12141417},
1158 {0x0000b090, 0x14171919}, 1214 {0x0000b090, 0x07070e0e},
1159 {0x0000b094, 0x0e0e1214}, 1215 {0x0000b094, 0x03030305},
1160 {0x0000b098, 0x03050707}, 1216 {0x0000b098, 0x00000003},
1161 {0x0000b09c, 0x00030303}, 1217 {0x0000b09c, 0x00000000},
1162 {0x0000b0a0, 0x00000000}, 1218 {0x0000b0a0, 0x00000000},
1163 {0x0000b0a4, 0x00000000}, 1219 {0x0000b0a4, 0x00000000},
1164 {0x0000b0a8, 0x00000000}, 1220 {0x0000b0a8, 0x00000000},
@@ -1251,6 +1307,10 @@ static const u32 ar9300Common_rx_gain_table_2p2[][2] = {
1251 1307
1252static const u32 ar9300Modes_low_ob_db_tx_gain_table_2p2[][5] = { 1308static const u32 ar9300Modes_low_ob_db_tx_gain_table_2p2[][5] = {
1253 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ 1309 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
1310 {0x0000a2dc, 0x0380c7fc, 0x0380c7fc, 0x00637800, 0x00637800},
1311 {0x0000a2e0, 0x0000f800, 0x0000f800, 0x03838000, 0x03838000},
1312 {0x0000a2e4, 0x03ff0000, 0x03ff0000, 0x03fc0000, 0x03fc0000},
1313 {0x0000a2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1254 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d9, 0x000050d9}, 1314 {0x0000a410, 0x000050d9, 0x000050d9, 0x000050d9, 0x000050d9},
1255 {0x0000a500, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 1315 {0x0000a500, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1256 {0x0000a504, 0x06000003, 0x06000003, 0x04000002, 0x04000002}, 1316 {0x0000a504, 0x06000003, 0x06000003, 0x04000002, 0x04000002},
@@ -1316,6 +1376,30 @@ static const u32 ar9300Modes_low_ob_db_tx_gain_table_2p2[][5] = {
1316 {0x0000a5f4, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec}, 1376 {0x0000a5f4, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec},
1317 {0x0000a5f8, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec}, 1377 {0x0000a5f8, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec},
1318 {0x0000a5fc, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec}, 1378 {0x0000a5fc, 0x7782b08c, 0x7782b08c, 0x5d801eec, 0x5d801eec},
1379 {0x0000a600, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1380 {0x0000a604, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1381 {0x0000a608, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1382 {0x0000a60c, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1383 {0x0000a610, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1384 {0x0000a614, 0x01404000, 0x01404000, 0x01404000, 0x01404000},
1385 {0x0000a618, 0x01404501, 0x01404501, 0x01404501, 0x01404501},
1386 {0x0000a61c, 0x02008802, 0x02008802, 0x02008501, 0x02008501},
1387 {0x0000a620, 0x0300cc03, 0x0300cc03, 0x0280ca03, 0x0280ca03},
1388 {0x0000a624, 0x0300cc03, 0x0300cc03, 0x03010c04, 0x03010c04},
1389 {0x0000a628, 0x0300cc03, 0x0300cc03, 0x04014c04, 0x04014c04},
1390 {0x0000a62c, 0x03810c03, 0x03810c03, 0x04015005, 0x04015005},
1391 {0x0000a630, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
1392 {0x0000a634, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
1393 {0x0000a638, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
1394 {0x0000a63c, 0x03810e04, 0x03810e04, 0x04015005, 0x04015005},
1395 {0x0000b2dc, 0x0380c7fc, 0x0380c7fc, 0x00637800, 0x00637800},
1396 {0x0000b2e0, 0x0000f800, 0x0000f800, 0x03838000, 0x03838000},
1397 {0x0000b2e4, 0x03ff0000, 0x03ff0000, 0x03fc0000, 0x03fc0000},
1398 {0x0000b2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1399 {0x0000c2dc, 0x0380c7fc, 0x0380c7fc, 0x00637800, 0x00637800},
1400 {0x0000c2e0, 0x0000f800, 0x0000f800, 0x03838000, 0x03838000},
1401 {0x0000c2e4, 0x03ff0000, 0x03ff0000, 0x03fc0000, 0x03fc0000},
1402 {0x0000c2e8, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1319 {0x00016044, 0x012492d4, 0x012492d4, 0x012492d4, 0x012492d4}, 1403 {0x00016044, 0x012492d4, 0x012492d4, 0x012492d4, 0x012492d4},
1320 {0x00016048, 0x66480001, 0x66480001, 0x66480001, 0x66480001}, 1404 {0x00016048, 0x66480001, 0x66480001, 0x66480001, 0x66480001},
1321 {0x00016068, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c}, 1405 {0x00016068, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c, 0x6db6db6c},
@@ -1414,15 +1498,10 @@ static const u32 ar9300_2p2_mac_core[][2] = {
1414 {0x00008144, 0xffffffff}, 1498 {0x00008144, 0xffffffff},
1415 {0x00008168, 0x00000000}, 1499 {0x00008168, 0x00000000},
1416 {0x0000816c, 0x00000000}, 1500 {0x0000816c, 0x00000000},
1417 {0x00008170, 0x18486200},
1418 {0x00008174, 0x33332210},
1419 {0x00008178, 0x00000000},
1420 {0x0000817c, 0x00020000},
1421 {0x000081c0, 0x00000000}, 1501 {0x000081c0, 0x00000000},
1422 {0x000081c4, 0x33332210}, 1502 {0x000081c4, 0x33332210},
1423 {0x000081c8, 0x00000000}, 1503 {0x000081c8, 0x00000000},
1424 {0x000081cc, 0x00000000}, 1504 {0x000081cc, 0x00000000},
1425 {0x000081d4, 0x00000000},
1426 {0x000081ec, 0x00000000}, 1505 {0x000081ec, 0x00000000},
1427 {0x000081f0, 0x00000000}, 1506 {0x000081f0, 0x00000000},
1428 {0x000081f4, 0x00000000}, 1507 {0x000081f4, 0x00000000},
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
index 7c38229ba670..716db414c258 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
@@ -347,6 +347,10 @@ static bool create_pa_curve(u32 *data_L, u32 *data_U, u32 *pa_table, u16 *gain)
347 (((Y[6] - Y[3]) * 1 << scale_factor) + 347 (((Y[6] - Y[3]) * 1 << scale_factor) +
348 (x_est[6] - x_est[3])) / (x_est[6] - x_est[3]); 348 (x_est[6] - x_est[3])) / (x_est[6] - x_est[3]);
349 349
350 /* prevent division by zero */
351 if (G_fxp == 0)
352 return false;
353
350 Y_intercept = 354 Y_intercept =
351 (G_fxp * (x_est[0] - x_est[3]) + 355 (G_fxp * (x_est[0] - x_est[3]) +
352 (1 << scale_factor)) / (1 << scale_factor) + Y[3]; 356 (1 << scale_factor)) / (1 << scale_factor) + Y[3];
@@ -356,14 +360,12 @@ static bool create_pa_curve(u32 *data_L, u32 *data_U, u32 *pa_table, u16 *gain)
356 360
357 for (i = 0; i <= 3; i++) { 361 for (i = 0; i <= 3; i++) {
358 y_est[i] = i * 32; 362 y_est[i] = i * 32;
359
360 /* prevent division by zero */
361 if (G_fxp == 0)
362 return false;
363
364 x_est[i] = ((y_est[i] * 1 << scale_factor) + G_fxp) / G_fxp; 363 x_est[i] = ((y_est[i] * 1 << scale_factor) + G_fxp) / G_fxp;
365 } 364 }
366 365
366 if (y_est[max_index] == 0)
367 return false;
368
367 x_est_fxp1_nonlin = 369 x_est_fxp1_nonlin =
368 x_est[max_index] - ((1 << scale_factor) * y_est[max_index] + 370 x_est[max_index] - ((1 << scale_factor) * y_est[max_index] +
369 G_fxp) / G_fxp; 371 G_fxp) / G_fxp;
@@ -457,6 +459,8 @@ static bool create_pa_curve(u32 *data_L, u32 *data_U, u32 *pa_table, u16 *gain)
457 459
458 Q_scale_B = find_proper_scale(find_expn(abs(scale_B)), 10); 460 Q_scale_B = find_proper_scale(find_expn(abs(scale_B)), 10);
459 scale_B = scale_B / (1 << Q_scale_B); 461 scale_B = scale_B / (1 << Q_scale_B);
462 if (scale_B == 0)
463 return false;
460 Q_beta = find_proper_scale(find_expn(abs(beta_raw)), 10); 464 Q_beta = find_proper_scale(find_expn(abs(beta_raw)), 10);
461 Q_alpha = find_proper_scale(find_expn(abs(alpha_raw)), 10); 465 Q_alpha = find_proper_scale(find_expn(abs(alpha_raw)), 10);
462 beta_raw = beta_raw / (1 << Q_beta); 466 beta_raw = beta_raw / (1 << Q_beta);
diff --git a/drivers/net/wireless/ath/ath9k/beacon.c b/drivers/net/wireless/ath/ath9k/beacon.c
index 4ed010d4ef96..19891e7d49ae 100644
--- a/drivers/net/wireless/ath/ath9k/beacon.c
+++ b/drivers/net/wireless/ath/ath9k/beacon.c
@@ -370,7 +370,7 @@ void ath_beacon_tasklet(unsigned long data)
370 ath_print(common, ATH_DBG_BSTUCK, 370 ath_print(common, ATH_DBG_BSTUCK,
371 "beacon is officially stuck\n"); 371 "beacon is officially stuck\n");
372 sc->sc_flags |= SC_OP_TSF_RESET; 372 sc->sc_flags |= SC_OP_TSF_RESET;
373 ath_reset(sc, false); 373 ath_reset(sc, true);
374 } 374 }
375 375
376 return; 376 return;
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index bc6c4df9712c..95b41db0d86b 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -577,6 +577,7 @@ static int ath9k_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
577 common->hw = sc->hw; 577 common->hw = sc->hw;
578 common->priv = sc; 578 common->priv = sc;
579 common->debug_mask = ath9k_debug; 579 common->debug_mask = ath9k_debug;
580 spin_lock_init(&common->cc_lock);
580 581
581 spin_lock_init(&sc->wiphy_lock); 582 spin_lock_init(&sc->wiphy_lock);
582 spin_lock_init(&sc->sc_resetlock); 583 spin_lock_init(&sc->sc_resetlock);
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 3ff0e476c2b3..c6ec800d7a6b 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -182,6 +182,9 @@ static void ath_update_survey_stats(struct ath_softc *sc)
182 struct ath_cycle_counters *cc = &common->cc_survey; 182 struct ath_cycle_counters *cc = &common->cc_survey;
183 unsigned int div = common->clockrate * 1000; 183 unsigned int div = common->clockrate * 1000;
184 184
185 if (!ah->curchan)
186 return;
187
185 if (ah->power_mode == ATH9K_PM_AWAKE) 188 if (ah->power_mode == ATH9K_PM_AWAKE)
186 ath_hw_cycle_counters_update(common); 189 ath_hw_cycle_counters_update(common);
187 190
@@ -577,7 +580,7 @@ void ath_hw_check(struct work_struct *work)
577 580
578 msleep(1); 581 msleep(1);
579 } 582 }
580 ath_reset(sc, false); 583 ath_reset(sc, true);
581 584
582out: 585out:
583 ath9k_ps_restore(sc); 586 ath9k_ps_restore(sc);
@@ -595,7 +598,7 @@ void ath9k_tasklet(unsigned long data)
595 ath9k_ps_wakeup(sc); 598 ath9k_ps_wakeup(sc);
596 599
597 if (status & ATH9K_INT_FATAL) { 600 if (status & ATH9K_INT_FATAL) {
598 ath_reset(sc, false); 601 ath_reset(sc, true);
599 ath9k_ps_restore(sc); 602 ath9k_ps_restore(sc);
600 return; 603 return;
601 } 604 }
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index d077186da870..30ef2dfc1ed2 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -673,6 +673,7 @@ static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
673 u16 aggr_limit = 0, al = 0, bpad = 0, 673 u16 aggr_limit = 0, al = 0, bpad = 0,
674 al_delta, h_baw = tid->baw_size / 2; 674 al_delta, h_baw = tid->baw_size / 2;
675 enum ATH_AGGR_STATUS status = ATH_AGGR_DONE; 675 enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
676 struct ieee80211_tx_info *tx_info;
676 677
677 bf_first = list_first_entry(&tid->buf_q, struct ath_buf, list); 678 bf_first = list_first_entry(&tid->buf_q, struct ath_buf, list);
678 679
@@ -699,6 +700,11 @@ static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
699 break; 700 break;
700 } 701 }
701 702
703 tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
704 if (nframes && ((tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) ||
705 !(tx_info->control.rates[0].flags & IEEE80211_TX_RC_MCS)))
706 break;
707
702 /* do not exceed subframe limit */ 708 /* do not exceed subframe limit */
703 if (nframes >= min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) { 709 if (nframes >= min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) {
704 status = ATH_AGGR_LIMITED; 710 status = ATH_AGGR_LIMITED;
@@ -2157,7 +2163,7 @@ static void ath_tx_complete_poll_work(struct work_struct *work)
2157 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_RESET, 2163 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_RESET,
2158 "tx hung, resetting the chip\n"); 2164 "tx hung, resetting the chip\n");
2159 ath9k_ps_wakeup(sc); 2165 ath9k_ps_wakeup(sc);
2160 ath_reset(sc, false); 2166 ath_reset(sc, true);
2161 ath9k_ps_restore(sc); 2167 ath9k_ps_restore(sc);
2162 } 2168 }
2163 2169
diff --git a/drivers/net/wireless/ath/carl9170/cmd.h b/drivers/net/wireless/ath/carl9170/cmd.h
index f78728c38294..568174c71b94 100644
--- a/drivers/net/wireless/ath/carl9170/cmd.h
+++ b/drivers/net/wireless/ath/carl9170/cmd.h
@@ -116,8 +116,9 @@ __regwrite_out : \
116} while (0); 116} while (0);
117 117
118 118
119#define carl9170_async_get_buf() \ 119#define carl9170_async_regwrite_get_buf() \
120do { \ 120do { \
121 __nreg = 0; \
121 __cmd = carl9170_cmd_buf(__carl, CARL9170_CMD_WREG_ASYNC, \ 122 __cmd = carl9170_cmd_buf(__carl, CARL9170_CMD_WREG_ASYNC, \
122 CARL9170_MAX_CMD_PAYLOAD_LEN); \ 123 CARL9170_MAX_CMD_PAYLOAD_LEN); \
123 if (__cmd == NULL) { \ 124 if (__cmd == NULL) { \
@@ -128,38 +129,42 @@ do { \
128 129
129#define carl9170_async_regwrite_begin(carl) \ 130#define carl9170_async_regwrite_begin(carl) \
130do { \ 131do { \
131 int __nreg = 0, __err = 0; \
132 struct ar9170 *__carl = carl; \ 132 struct ar9170 *__carl = carl; \
133 struct carl9170_cmd *__cmd; \ 133 struct carl9170_cmd *__cmd; \
134 carl9170_async_get_buf(); \ 134 unsigned int __nreg; \
135 int __err = 0; \
136 carl9170_async_regwrite_get_buf(); \
137
138#define carl9170_async_regwrite_flush() \
139do { \
140 if (__cmd == NULL || __nreg == 0) \
141 break; \
142 \
143 if (IS_ACCEPTING_CMD(__carl) && __nreg) { \
144 __cmd->hdr.len = 8 * __nreg; \
145 __err = __carl9170_exec_cmd(__carl, __cmd, true); \
146 __cmd = NULL; \
147 break; \
148 } \
149 goto __async_regwrite_out; \
150} while (0)
135 151
136#define carl9170_async_regwrite(r, v) do { \ 152#define carl9170_async_regwrite(r, v) do { \
153 if (__cmd == NULL) \
154 carl9170_async_regwrite_get_buf(); \
137 __cmd->wreg.regs[__nreg].addr = cpu_to_le32(r); \ 155 __cmd->wreg.regs[__nreg].addr = cpu_to_le32(r); \
138 __cmd->wreg.regs[__nreg].val = cpu_to_le32(v); \ 156 __cmd->wreg.regs[__nreg].val = cpu_to_le32(v); \
139 __nreg++; \ 157 __nreg++; \
140 if ((__nreg >= PAYLOAD_MAX/2)) { \ 158 if ((__nreg >= PAYLOAD_MAX / 2)) \
141 if (IS_ACCEPTING_CMD(__carl)) { \ 159 carl9170_async_regwrite_flush(); \
142 __cmd->hdr.len = 8 * __nreg; \
143 __err = __carl9170_exec_cmd(__carl, __cmd, true);\
144 __cmd = NULL; \
145 carl9170_async_get_buf(); \
146 } else { \
147 goto __async_regwrite_out; \
148 } \
149 __nreg = 0; \
150 if (__err) \
151 goto __async_regwrite_out; \
152 } \
153} while (0) 160} while (0)
154 161
155#define carl9170_async_regwrite_finish() \ 162#define carl9170_async_regwrite_finish() do { \
156__async_regwrite_out : \ 163__async_regwrite_out : \
157 if (__err == 0 && __nreg) { \ 164 if (__cmd != NULL && __err == 0) \
158 __cmd->hdr.len = 8 * __nreg; \ 165 carl9170_async_regwrite_flush(); \
159 if (IS_ACCEPTING_CMD(__carl)) \ 166 kfree(__cmd); \
160 __err = __carl9170_exec_cmd(__carl, __cmd, true);\ 167} while (0) \
161 __nreg = 0; \
162 }
163 168
164#define carl9170_async_regwrite_result() \ 169#define carl9170_async_regwrite_result() \
165 __err; \ 170 __err; \
diff --git a/drivers/net/wireless/ath/carl9170/main.c b/drivers/net/wireless/ath/carl9170/main.c
index 3cc99f3f7ab5..980ae70ea424 100644
--- a/drivers/net/wireless/ath/carl9170/main.c
+++ b/drivers/net/wireless/ath/carl9170/main.c
@@ -639,8 +639,8 @@ init:
639 if (err) 639 if (err)
640 goto unlock; 640 goto unlock;
641 } else { 641 } else {
642 err = carl9170_mod_virtual_mac(ar, vif_id, vif->addr);
643 rcu_read_unlock(); 642 rcu_read_unlock();
643 err = carl9170_mod_virtual_mac(ar, vif_id, vif->addr);
644 644
645 if (err) 645 if (err)
646 goto unlock; 646 goto unlock;
diff --git a/drivers/net/wireless/ath/carl9170/usb.c b/drivers/net/wireless/ath/carl9170/usb.c
index c7f6193934ea..d8607f4c144d 100644
--- a/drivers/net/wireless/ath/carl9170/usb.c
+++ b/drivers/net/wireless/ath/carl9170/usb.c
@@ -591,16 +591,23 @@ int __carl9170_exec_cmd(struct ar9170 *ar, struct carl9170_cmd *cmd,
591 const bool free_buf) 591 const bool free_buf)
592{ 592{
593 struct urb *urb; 593 struct urb *urb;
594 int err = 0;
594 595
595 if (!IS_INITIALIZED(ar)) 596 if (!IS_INITIALIZED(ar)) {
596 return -EPERM; 597 err = -EPERM;
598 goto err_free;
599 }
597 600
598 if (WARN_ON(cmd->hdr.len > CARL9170_MAX_CMD_LEN - 4)) 601 if (WARN_ON(cmd->hdr.len > CARL9170_MAX_CMD_LEN - 4)) {
599 return -EINVAL; 602 err = -EINVAL;
603 goto err_free;
604 }
600 605
601 urb = usb_alloc_urb(0, GFP_ATOMIC); 606 urb = usb_alloc_urb(0, GFP_ATOMIC);
602 if (!urb) 607 if (!urb) {
603 return -ENOMEM; 608 err = -ENOMEM;
609 goto err_free;
610 }
604 611
605 usb_fill_int_urb(urb, ar->udev, usb_sndintpipe(ar->udev, 612 usb_fill_int_urb(urb, ar->udev, usb_sndintpipe(ar->udev,
606 AR9170_USB_EP_CMD), cmd, cmd->hdr.len + 4, 613 AR9170_USB_EP_CMD), cmd, cmd->hdr.len + 4,
@@ -613,6 +620,12 @@ int __carl9170_exec_cmd(struct ar9170 *ar, struct carl9170_cmd *cmd,
613 usb_free_urb(urb); 620 usb_free_urb(urb);
614 621
615 return carl9170_usb_submit_cmd_urb(ar); 622 return carl9170_usb_submit_cmd_urb(ar);
623
624err_free:
625 if (free_buf)
626 kfree(cmd);
627
628 return err;
616} 629}
617 630
618int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids cmd, 631int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids cmd,
diff --git a/drivers/net/wireless/b43/phy_n.c b/drivers/net/wireless/b43/phy_n.c
index dfec5496055e..e0f2d122e124 100644
--- a/drivers/net/wireless/b43/phy_n.c
+++ b/drivers/net/wireless/b43/phy_n.c
@@ -2964,7 +2964,7 @@ static int b43_nphy_rev2_cal_rx_iq(struct b43_wldev *dev,
2964 (2 - i)); 2964 (2 - i));
2965 } 2965 }
2966 2966
2967 for (j = 0; i < 4; j++) { 2967 for (j = 0; j < 4; j++) {
2968 if (j < 3) { 2968 if (j < 3) {
2969 cur_lna = lna[j]; 2969 cur_lna = lna[j];
2970 cur_hpf1 = hpf1[j]; 2970 cur_hpf1 = hpf1[j];
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
index db57aea629d9..2b078a995729 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
@@ -1227,7 +1227,8 @@ static int iwlagn_tx_status_reply_compressed_ba(struct iwl_priv *priv,
1227 struct ieee80211_tx_info *info; 1227 struct ieee80211_tx_info *info;
1228 1228
1229 if (unlikely(!agg->wait_for_ba)) { 1229 if (unlikely(!agg->wait_for_ba)) {
1230 IWL_ERR(priv, "Received BA when not expected\n"); 1230 if (unlikely(ba_resp->bitmap))
1231 IWL_ERR(priv, "Received BA when not expected\n");
1231 return -EINVAL; 1232 return -EINVAL;
1232 } 1233 }
1233 1234
diff --git a/drivers/net/wireless/wl1251/Makefile b/drivers/net/wireless/wl1251/Makefile
index 4fe246824db3..58b4f935a3f6 100644
--- a/drivers/net/wireless/wl1251/Makefile
+++ b/drivers/net/wireless/wl1251/Makefile
@@ -1,6 +1,8 @@
1wl1251-objs = main.o event.o tx.o rx.o ps.o cmd.o \ 1wl1251-objs = main.o event.o tx.o rx.o ps.o cmd.o \
2 acx.o boot.o init.o debugfs.o io.o 2 acx.o boot.o init.o debugfs.o io.o
3wl1251_spi-objs += spi.o
4wl1251_sdio-objs += sdio.o
3 5
4obj-$(CONFIG_WL1251) += wl1251.o 6obj-$(CONFIG_WL1251) += wl1251.o
5obj-$(CONFIG_WL1251_SPI) += spi.o 7obj-$(CONFIG_WL1251_SPI) += wl1251_spi.o
6obj-$(CONFIG_WL1251_SDIO) += sdio.o 8obj-$(CONFIG_WL1251_SDIO) += wl1251_sdio.o
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 01f0306525a5..895136f13edc 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -212,8 +212,6 @@ static long proc_bus_pci_ioctl(struct file *file, unsigned int cmd,
212#endif /* HAVE_PCI_MMAP */ 212#endif /* HAVE_PCI_MMAP */
213 int ret = 0; 213 int ret = 0;
214 214
215 lock_kernel();
216
217 switch (cmd) { 215 switch (cmd) {
218 case PCIIOC_CONTROLLER: 216 case PCIIOC_CONTROLLER:
219 ret = pci_domain_nr(dev->bus); 217 ret = pci_domain_nr(dev->bus);
@@ -242,7 +240,6 @@ static long proc_bus_pci_ioctl(struct file *file, unsigned int cmd,
242 break; 240 break;
243 }; 241 };
244 242
245 unlock_kernel();
246 return ret; 243 return ret;
247} 244}
248 245
diff --git a/drivers/platform/x86/intel_pmic_gpio.c b/drivers/platform/x86/intel_pmic_gpio.c
index f540ff96c53f..e61db9dfebef 100644
--- a/drivers/platform/x86/intel_pmic_gpio.c
+++ b/drivers/platform/x86/intel_pmic_gpio.c
@@ -29,7 +29,6 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/io.h> 30#include <linux/io.h>
31#include <linux/gpio.h> 31#include <linux/gpio.h>
32#include <linux/interrupt.h>
33#include <asm/intel_scu_ipc.h> 32#include <asm/intel_scu_ipc.h>
34#include <linux/device.h> 33#include <linux/device.h>
35#include <linux/intel_pmic_gpio.h> 34#include <linux/intel_pmic_gpio.h>
diff --git a/drivers/rapidio/rio-driver.c b/drivers/rapidio/rio-driver.c
index 3222fa3c808c..0f4a53bdaa3c 100644
--- a/drivers/rapidio/rio-driver.c
+++ b/drivers/rapidio/rio-driver.c
@@ -192,7 +192,7 @@ static int rio_match_bus(struct device *dev, struct device_driver *drv)
192 out:return 0; 192 out:return 0;
193} 193}
194 194
195static struct device rio_bus = { 195struct device rio_bus = {
196 .init_name = "rapidio", 196 .init_name = "rapidio",
197}; 197};
198 198
diff --git a/drivers/rapidio/rio-scan.c b/drivers/rapidio/rio-scan.c
index 8070e074c739..1eb82c4c712e 100644
--- a/drivers/rapidio/rio-scan.c
+++ b/drivers/rapidio/rio-scan.c
@@ -48,7 +48,7 @@ DEFINE_SPINLOCK(rio_global_list_lock);
48static int next_destid = 0; 48static int next_destid = 0;
49static int next_switchid = 0; 49static int next_switchid = 0;
50static int next_net = 0; 50static int next_net = 0;
51static int next_comptag; 51static int next_comptag = 1;
52 52
53static struct timer_list rio_enum_timer = 53static struct timer_list rio_enum_timer =
54TIMER_INITIALIZER(rio_enum_timeout, 0, 0); 54TIMER_INITIALIZER(rio_enum_timeout, 0, 0);
@@ -121,27 +121,6 @@ static int rio_clear_locks(struct rio_mport *port)
121 u32 result; 121 u32 result;
122 int ret = 0; 122 int ret = 0;
123 123
124 /* Assign component tag to all devices */
125 next_comptag = 1;
126 rio_local_write_config_32(port, RIO_COMPONENT_TAG_CSR, next_comptag++);
127
128 list_for_each_entry(rdev, &rio_devices, global_list) {
129 /* Mark device as discovered */
130 rio_read_config_32(rdev,
131 rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR,
132 &result);
133 rio_write_config_32(rdev,
134 rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR,
135 result | RIO_PORT_GEN_DISCOVERED);
136
137 rio_write_config_32(rdev, RIO_COMPONENT_TAG_CSR, next_comptag);
138 rdev->comp_tag = next_comptag++;
139 if (next_comptag >= 0x10000) {
140 pr_err("RIO: Component Tag Counter Overflow\n");
141 break;
142 }
143 }
144
145 /* Release host device id locks */ 124 /* Release host device id locks */
146 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR, 125 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR,
147 port->host_deviceid); 126 port->host_deviceid);
@@ -162,6 +141,15 @@ static int rio_clear_locks(struct rio_mport *port)
162 rdev->vid, rdev->did); 141 rdev->vid, rdev->did);
163 ret = -EINVAL; 142 ret = -EINVAL;
164 } 143 }
144
145 /* Mark device as discovered and enable master */
146 rio_read_config_32(rdev,
147 rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR,
148 &result);
149 result |= RIO_PORT_GEN_DISCOVERED | RIO_PORT_GEN_MASTER;
150 rio_write_config_32(rdev,
151 rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR,
152 result);
165 } 153 }
166 154
167 return ret; 155 return ret;
@@ -420,11 +408,27 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
420 hopcount, RIO_EFB_ERR_MGMNT); 408 hopcount, RIO_EFB_ERR_MGMNT);
421 } 409 }
422 410
411 if (rdev->pef & (RIO_PEF_SWITCH | RIO_PEF_MULTIPORT)) {
412 rio_mport_read_config_32(port, destid, hopcount,
413 RIO_SWP_INFO_CAR, &rdev->swpinfo);
414 }
415
423 rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR, 416 rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR,
424 &rdev->src_ops); 417 &rdev->src_ops);
425 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR, 418 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR,
426 &rdev->dst_ops); 419 &rdev->dst_ops);
427 420
421 if (do_enum) {
422 /* Assign component tag to device */
423 if (next_comptag >= 0x10000) {
424 pr_err("RIO: Component Tag Counter Overflow\n");
425 goto cleanup;
426 }
427 rio_mport_write_config_32(port, destid, hopcount,
428 RIO_COMPONENT_TAG_CSR, next_comptag);
429 rdev->comp_tag = next_comptag++;
430 }
431
428 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) { 432 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) {
429 if (do_enum) { 433 if (do_enum) {
430 rio_set_device_id(port, destid, hopcount, next_destid); 434 rio_set_device_id(port, destid, hopcount, next_destid);
@@ -439,9 +443,10 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
439 443
440 /* If a PE has both switch and other functions, show it as a switch */ 444 /* If a PE has both switch and other functions, show it as a switch */
441 if (rio_is_switch(rdev)) { 445 if (rio_is_switch(rdev)) {
442 rio_mport_read_config_32(port, destid, hopcount, 446 rswitch = kzalloc(sizeof(*rswitch) +
443 RIO_SWP_INFO_CAR, &rdev->swpinfo); 447 RIO_GET_TOTAL_PORTS(rdev->swpinfo) *
444 rswitch = kzalloc(sizeof(struct rio_switch), GFP_KERNEL); 448 sizeof(rswitch->nextdev[0]),
449 GFP_KERNEL);
445 if (!rswitch) 450 if (!rswitch)
446 goto cleanup; 451 goto cleanup;
447 rswitch->switchid = next_switchid; 452 rswitch->switchid = next_switchid;
@@ -458,6 +463,7 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
458 rdid++) 463 rdid++)
459 rswitch->route_table[rdid] = RIO_INVALID_ROUTE; 464 rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
460 rdev->rswitch = rswitch; 465 rdev->rswitch = rswitch;
466 rswitch->rdev = rdev;
461 dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id, 467 dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id,
462 rdev->rswitch->switchid); 468 rdev->rswitch->switchid);
463 rio_switch_init(rdev, do_enum); 469 rio_switch_init(rdev, do_enum);
@@ -478,6 +484,7 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
478 } 484 }
479 485
480 rdev->dev.bus = &rio_bus_type; 486 rdev->dev.bus = &rio_bus_type;
487 rdev->dev.parent = &rio_bus;
481 488
482 device_initialize(&rdev->dev); 489 device_initialize(&rdev->dev);
483 rdev->dev.release = rio_release_dev; 490 rdev->dev.release = rio_release_dev;
@@ -718,86 +725,53 @@ static u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount)
718} 725}
719 726
720/** 727/**
721 * rio_get_swpinfo_inport- Gets the ingress port number
722 * @mport: Master port to send transaction
723 * @destid: Destination ID associated with the switch
724 * @hopcount: Number of hops to the device
725 *
726 * Returns port number being used to access the switch device.
727 */
728static u8
729rio_get_swpinfo_inport(struct rio_mport *mport, u16 destid, u8 hopcount)
730{
731 u32 result;
732
733 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
734 &result);
735
736 return (u8) (result & 0xff);
737}
738
739/**
740 * rio_get_swpinfo_tports- Gets total number of ports on the switch
741 * @mport: Master port to send transaction
742 * @destid: Destination ID associated with the switch
743 * @hopcount: Number of hops to the device
744 *
745 * Returns total numbers of ports implemented by the switch device.
746 */
747static u8 rio_get_swpinfo_tports(struct rio_mport *mport, u16 destid,
748 u8 hopcount)
749{
750 u32 result;
751
752 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
753 &result);
754
755 return RIO_GET_TOTAL_PORTS(result);
756}
757
758/**
759 * rio_net_add_mport- Add a master port to a RIO network
760 * @net: RIO network
761 * @port: Master port to add
762 *
763 * Adds a master port to the network list of associated master
764 * ports..
765 */
766static void rio_net_add_mport(struct rio_net *net, struct rio_mport *port)
767{
768 spin_lock(&rio_global_list_lock);
769 list_add_tail(&port->nnode, &net->mports);
770 spin_unlock(&rio_global_list_lock);
771}
772
773/**
774 * rio_enum_peer- Recursively enumerate a RIO network through a master port 728 * rio_enum_peer- Recursively enumerate a RIO network through a master port
775 * @net: RIO network being enumerated 729 * @net: RIO network being enumerated
776 * @port: Master port to send transactions 730 * @port: Master port to send transactions
777 * @hopcount: Number of hops into the network 731 * @hopcount: Number of hops into the network
732 * @prev: Previous RIO device connected to the enumerated one
733 * @prev_port: Port on previous RIO device
778 * 734 *
779 * Recursively enumerates a RIO network. Transactions are sent via the 735 * Recursively enumerates a RIO network. Transactions are sent via the
780 * master port passed in @port. 736 * master port passed in @port.
781 */ 737 */
782static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port, 738static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
783 u8 hopcount) 739 u8 hopcount, struct rio_dev *prev, int prev_port)
784{ 740{
785 int port_num; 741 int port_num;
786 int num_ports;
787 int cur_destid; 742 int cur_destid;
788 int sw_destid; 743 int sw_destid;
789 int sw_inport; 744 int sw_inport;
790 struct rio_dev *rdev; 745 struct rio_dev *rdev;
791 u16 destid; 746 u16 destid;
747 u32 regval;
792 int tmp; 748 int tmp;
793 749
750 if (rio_mport_chk_dev_access(port,
751 RIO_ANY_DESTID(port->sys_size), hopcount)) {
752 pr_debug("RIO: device access check failed\n");
753 return -1;
754 }
755
794 if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) { 756 if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) {
795 pr_debug("RIO: PE already discovered by this host\n"); 757 pr_debug("RIO: PE already discovered by this host\n");
796 /* 758 /*
797 * Already discovered by this host. Add it as another 759 * Already discovered by this host. Add it as another
798 * master port for the current network. 760 * link to the existing device.
799 */ 761 */
800 rio_net_add_mport(net, port); 762 rio_mport_read_config_32(port, RIO_ANY_DESTID(port->sys_size),
763 hopcount, RIO_COMPONENT_TAG_CSR, &regval);
764
765 if (regval) {
766 rdev = rio_get_comptag((regval & 0xffff), NULL);
767
768 if (rdev && prev && rio_is_switch(prev)) {
769 pr_debug("RIO: redundant path to %s\n",
770 rio_name(rdev));
771 prev->rswitch->nextdev[prev_port] = rdev;
772 }
773 }
774
801 return 0; 775 return 0;
802 } 776 }
803 777
@@ -828,13 +802,15 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
828 if (rdev) { 802 if (rdev) {
829 /* Add device to the global and bus/net specific list. */ 803 /* Add device to the global and bus/net specific list. */
830 list_add_tail(&rdev->net_list, &net->devices); 804 list_add_tail(&rdev->net_list, &net->devices);
805 rdev->prev = prev;
806 if (prev && rio_is_switch(prev))
807 prev->rswitch->nextdev[prev_port] = rdev;
831 } else 808 } else
832 return -1; 809 return -1;
833 810
834 if (rio_is_switch(rdev)) { 811 if (rio_is_switch(rdev)) {
835 next_switchid++; 812 next_switchid++;
836 sw_inport = rio_get_swpinfo_inport(port, 813 sw_inport = RIO_GET_PORT_NUM(rdev->swpinfo);
837 RIO_ANY_DESTID(port->sys_size), hopcount);
838 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE, 814 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE,
839 port->host_deviceid, sw_inport, 0); 815 port->host_deviceid, sw_inport, 0);
840 rdev->rswitch->route_table[port->host_deviceid] = sw_inport; 816 rdev->rswitch->route_table[port->host_deviceid] = sw_inport;
@@ -847,14 +823,14 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
847 rdev->rswitch->route_table[destid] = sw_inport; 823 rdev->rswitch->route_table[destid] = sw_inport;
848 } 824 }
849 825
850 num_ports =
851 rio_get_swpinfo_tports(port, RIO_ANY_DESTID(port->sys_size),
852 hopcount);
853 pr_debug( 826 pr_debug(
854 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n", 827 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
855 rio_name(rdev), rdev->vid, rdev->did, num_ports); 828 rio_name(rdev), rdev->vid, rdev->did,
829 RIO_GET_TOTAL_PORTS(rdev->swpinfo));
856 sw_destid = next_destid; 830 sw_destid = next_destid;
857 for (port_num = 0; port_num < num_ports; port_num++) { 831 for (port_num = 0;
832 port_num < RIO_GET_TOTAL_PORTS(rdev->swpinfo);
833 port_num++) {
858 /*Enable Input Output Port (transmitter reviever)*/ 834 /*Enable Input Output Port (transmitter reviever)*/
859 rio_enable_rx_tx_port(port, 0, 835 rio_enable_rx_tx_port(port, 0,
860 RIO_ANY_DESTID(port->sys_size), 836 RIO_ANY_DESTID(port->sys_size),
@@ -879,7 +855,8 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
879 RIO_ANY_DESTID(port->sys_size), 855 RIO_ANY_DESTID(port->sys_size),
880 port_num, 0); 856 port_num, 0);
881 857
882 if (rio_enum_peer(net, port, hopcount + 1) < 0) 858 if (rio_enum_peer(net, port, hopcount + 1,
859 rdev, port_num) < 0)
883 return -1; 860 return -1;
884 861
885 /* Update routing tables */ 862 /* Update routing tables */
@@ -945,10 +922,11 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
945 */ 922 */
946static int rio_enum_complete(struct rio_mport *port) 923static int rio_enum_complete(struct rio_mport *port)
947{ 924{
948 u32 tag_csr; 925 u32 regval;
949 926
950 rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr); 927 rio_local_read_config_32(port, port->phys_efptr + RIO_PORT_GEN_CTL_CSR,
951 return (tag_csr & 0xffff) ? 1 : 0; 928 &regval);
929 return (regval & RIO_PORT_GEN_MASTER) ? 1 : 0;
952} 930}
953 931
954/** 932/**
@@ -966,7 +944,6 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
966 u8 hopcount) 944 u8 hopcount)
967{ 945{
968 u8 port_num, route_port; 946 u8 port_num, route_port;
969 int num_ports;
970 struct rio_dev *rdev; 947 struct rio_dev *rdev;
971 u16 ndestid; 948 u16 ndestid;
972 949
@@ -983,13 +960,14 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
983 /* Associated destid is how we accessed this switch */ 960 /* Associated destid is how we accessed this switch */
984 rdev->rswitch->destid = destid; 961 rdev->rswitch->destid = destid;
985 962
986 num_ports = rio_get_swpinfo_tports(port, destid, hopcount);
987 pr_debug( 963 pr_debug(
988 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n", 964 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
989 rio_name(rdev), rdev->vid, rdev->did, num_ports); 965 rio_name(rdev), rdev->vid, rdev->did,
990 for (port_num = 0; port_num < num_ports; port_num++) { 966 RIO_GET_TOTAL_PORTS(rdev->swpinfo));
991 if (rio_get_swpinfo_inport(port, destid, hopcount) == 967 for (port_num = 0;
992 port_num) 968 port_num < RIO_GET_TOTAL_PORTS(rdev->swpinfo);
969 port_num++) {
970 if (RIO_GET_PORT_NUM(rdev->swpinfo) == port_num)
993 continue; 971 continue;
994 972
995 if (rio_sport_is_active 973 if (rio_sport_is_active
@@ -1011,6 +989,8 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
1011 break; 989 break;
1012 } 990 }
1013 991
992 if (ndestid == RIO_ANY_DESTID(port->sys_size))
993 continue;
1014 rio_unlock_device(port, destid, hopcount); 994 rio_unlock_device(port, destid, hopcount);
1015 if (rio_disc_peer 995 if (rio_disc_peer
1016 (net, port, ndestid, hopcount + 1) < 0) 996 (net, port, ndestid, hopcount + 1) < 0)
@@ -1108,8 +1088,7 @@ static void rio_update_route_tables(struct rio_mport *port)
1108 if (rswitch->destid == destid) 1088 if (rswitch->destid == destid)
1109 continue; 1089 continue;
1110 1090
1111 sport = rio_get_swpinfo_inport(port, 1091 sport = RIO_GET_PORT_NUM(rswitch->rdev->swpinfo);
1112 rswitch->destid, rswitch->hopcount);
1113 1092
1114 if (rswitch->add_entry) { 1093 if (rswitch->add_entry) {
1115 rio_route_add_entry(port, rswitch, 1094 rio_route_add_entry(port, rswitch,
@@ -1184,7 +1163,11 @@ int __devinit rio_enum_mport(struct rio_mport *mport)
1184 /* Enable Input Output Port (transmitter reviever) */ 1163 /* Enable Input Output Port (transmitter reviever) */
1185 rio_enable_rx_tx_port(mport, 1, 0, 0, 0); 1164 rio_enable_rx_tx_port(mport, 1, 0, 0, 0);
1186 1165
1187 if (rio_enum_peer(net, mport, 0) < 0) { 1166 /* Set component tag for host */
1167 rio_local_write_config_32(mport, RIO_COMPONENT_TAG_CSR,
1168 next_comptag++);
1169
1170 if (rio_enum_peer(net, mport, 0, NULL, 0) < 0) {
1188 /* A higher priority host won enumeration, bail. */ 1171 /* A higher priority host won enumeration, bail. */
1189 printk(KERN_INFO 1172 printk(KERN_INFO
1190 "RIO: master port %d device has lost enumeration to a remote host\n", 1173 "RIO: master port %d device has lost enumeration to a remote host\n",
diff --git a/drivers/rapidio/rio-sysfs.c b/drivers/rapidio/rio-sysfs.c
index 00b475658356..137ed93ee33f 100644
--- a/drivers/rapidio/rio-sysfs.c
+++ b/drivers/rapidio/rio-sysfs.c
@@ -40,9 +40,6 @@ static ssize_t routes_show(struct device *dev, struct device_attribute *attr, ch
40 char *str = buf; 40 char *str = buf;
41 int i; 41 int i;
42 42
43 if (!rdev->rswitch)
44 goto out;
45
46 for (i = 0; i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size); 43 for (i = 0; i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size);
47 i++) { 44 i++) {
48 if (rdev->rswitch->route_table[i] == RIO_INVALID_ROUTE) 45 if (rdev->rswitch->route_table[i] == RIO_INVALID_ROUTE)
@@ -52,7 +49,6 @@ static ssize_t routes_show(struct device *dev, struct device_attribute *attr, ch
52 rdev->rswitch->route_table[i]); 49 rdev->rswitch->route_table[i]);
53 } 50 }
54 51
55 out:
56 return (str - buf); 52 return (str - buf);
57} 53}
58 54
@@ -63,10 +59,11 @@ struct device_attribute rio_dev_attrs[] = {
63 __ATTR_RO(asm_did), 59 __ATTR_RO(asm_did),
64 __ATTR_RO(asm_vid), 60 __ATTR_RO(asm_vid),
65 __ATTR_RO(asm_rev), 61 __ATTR_RO(asm_rev),
66 __ATTR_RO(routes),
67 __ATTR_NULL, 62 __ATTR_NULL,
68}; 63};
69 64
65static DEVICE_ATTR(routes, S_IRUGO, routes_show, NULL);
66
70static ssize_t 67static ssize_t
71rio_read_config(struct file *filp, struct kobject *kobj, 68rio_read_config(struct file *filp, struct kobject *kobj,
72 struct bin_attribute *bin_attr, 69 struct bin_attribute *bin_attr,
@@ -218,7 +215,17 @@ int rio_create_sysfs_dev_files(struct rio_dev *rdev)
218{ 215{
219 int err = 0; 216 int err = 0;
220 217
221 err = sysfs_create_bin_file(&rdev->dev.kobj, &rio_config_attr); 218 err = device_create_bin_file(&rdev->dev, &rio_config_attr);
219
220 if (!err && rdev->rswitch) {
221 err = device_create_file(&rdev->dev, &dev_attr_routes);
222 if (!err && rdev->rswitch->sw_sysfs)
223 err = rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_CREATE);
224 }
225
226 if (err)
227 pr_warning("RIO: Failed to create attribute file(s) for %s\n",
228 rio_name(rdev));
222 229
223 return err; 230 return err;
224} 231}
@@ -231,5 +238,10 @@ int rio_create_sysfs_dev_files(struct rio_dev *rdev)
231 */ 238 */
232void rio_remove_sysfs_dev_files(struct rio_dev *rdev) 239void rio_remove_sysfs_dev_files(struct rio_dev *rdev)
233{ 240{
234 sysfs_remove_bin_file(&rdev->dev.kobj, &rio_config_attr); 241 device_remove_bin_file(&rdev->dev, &rio_config_attr);
242 if (rdev->rswitch) {
243 device_remove_file(&rdev->dev, &dev_attr_routes);
244 if (rdev->rswitch->sw_sysfs)
245 rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_REMOVE);
246 }
235} 247}
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
index 74e9d22d95fb..68cf0c99138a 100644
--- a/drivers/rapidio/rio.c
+++ b/drivers/rapidio/rio.c
@@ -443,7 +443,7 @@ rio_mport_get_physefb(struct rio_mport *port, int local,
443 * @from is not %NULL, searches continue from next device on the global 443 * @from is not %NULL, searches continue from next device on the global
444 * list. 444 * list.
445 */ 445 */
446static struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from) 446struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from)
447{ 447{
448 struct list_head *n; 448 struct list_head *n;
449 struct rio_dev *rdev; 449 struct rio_dev *rdev;
@@ -495,6 +495,232 @@ int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
495} 495}
496 496
497/** 497/**
498 * rio_chk_dev_route - Validate route to the specified device.
499 * @rdev: RIO device failed to respond
500 * @nrdev: Last active device on the route to rdev
501 * @npnum: nrdev's port number on the route to rdev
502 *
503 * Follows a route to the specified RIO device to determine the last available
504 * device (and corresponding RIO port) on the route.
505 */
506static int
507rio_chk_dev_route(struct rio_dev *rdev, struct rio_dev **nrdev, int *npnum)
508{
509 u32 result;
510 int p_port, dstid, rc = -EIO;
511 struct rio_dev *prev = NULL;
512
513 /* Find switch with failed RIO link */
514 while (rdev->prev && (rdev->prev->pef & RIO_PEF_SWITCH)) {
515 if (!rio_read_config_32(rdev->prev, RIO_DEV_ID_CAR, &result)) {
516 prev = rdev->prev;
517 break;
518 }
519 rdev = rdev->prev;
520 }
521
522 if (prev == NULL)
523 goto err_out;
524
525 dstid = (rdev->pef & RIO_PEF_SWITCH) ?
526 rdev->rswitch->destid : rdev->destid;
527 p_port = prev->rswitch->route_table[dstid];
528
529 if (p_port != RIO_INVALID_ROUTE) {
530 pr_debug("RIO: link failed on [%s]-P%d\n",
531 rio_name(prev), p_port);
532 *nrdev = prev;
533 *npnum = p_port;
534 rc = 0;
535 } else
536 pr_debug("RIO: failed to trace route to %s\n", rio_name(rdev));
537err_out:
538 return rc;
539}
540
541/**
542 * rio_mport_chk_dev_access - Validate access to the specified device.
543 * @mport: Master port to send transactions
544 * @destid: Device destination ID in network
545 * @hopcount: Number of hops into the network
546 */
547int
548rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid, u8 hopcount)
549{
550 int i = 0;
551 u32 tmp;
552
553 while (rio_mport_read_config_32(mport, destid, hopcount,
554 RIO_DEV_ID_CAR, &tmp)) {
555 i++;
556 if (i == RIO_MAX_CHK_RETRY)
557 return -EIO;
558 mdelay(1);
559 }
560
561 return 0;
562}
563
564/**
565 * rio_chk_dev_access - Validate access to the specified device.
566 * @rdev: Pointer to RIO device control structure
567 */
568static int rio_chk_dev_access(struct rio_dev *rdev)
569{
570 u8 hopcount = 0xff;
571 u16 destid = rdev->destid;
572
573 if (rdev->rswitch) {
574 destid = rdev->rswitch->destid;
575 hopcount = rdev->rswitch->hopcount;
576 }
577
578 return rio_mport_chk_dev_access(rdev->net->hport, destid, hopcount);
579}
580
581/**
582 * rio_get_input_status - Sends a Link-Request/Input-Status control symbol and
583 * returns link-response (if requested).
584 * @rdev: RIO devive to issue Input-status command
585 * @pnum: Device port number to issue the command
586 * @lnkresp: Response from a link partner
587 */
588static int
589rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp)
590{
591 struct rio_mport *mport = rdev->net->hport;
592 u16 destid = rdev->rswitch->destid;
593 u8 hopcount = rdev->rswitch->hopcount;
594 u32 regval;
595 int checkcount;
596
597 if (lnkresp) {
598 /* Read from link maintenance response register
599 * to clear valid bit */
600 rio_mport_read_config_32(mport, destid, hopcount,
601 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
602 &regval);
603 udelay(50);
604 }
605
606 /* Issue Input-status command */
607 rio_mport_write_config_32(mport, destid, hopcount,
608 rdev->phys_efptr + RIO_PORT_N_MNT_REQ_CSR(pnum),
609 RIO_MNT_REQ_CMD_IS);
610
611 /* Exit if the response is not expected */
612 if (lnkresp == NULL)
613 return 0;
614
615 checkcount = 3;
616 while (checkcount--) {
617 udelay(50);
618 rio_mport_read_config_32(mport, destid, hopcount,
619 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
620 &regval);
621 if (regval & RIO_PORT_N_MNT_RSP_RVAL) {
622 *lnkresp = regval;
623 return 0;
624 }
625 }
626
627 return -EIO;
628}
629
630/**
631 * rio_clr_err_stopped - Clears port Error-stopped states.
632 * @rdev: Pointer to RIO device control structure
633 * @pnum: Switch port number to clear errors
634 * @err_status: port error status (if 0 reads register from device)
635 */
636static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)
637{
638 struct rio_mport *mport = rdev->net->hport;
639 u16 destid = rdev->rswitch->destid;
640 u8 hopcount = rdev->rswitch->hopcount;
641 struct rio_dev *nextdev = rdev->rswitch->nextdev[pnum];
642 u32 regval;
643 u32 far_ackid, far_linkstat, near_ackid;
644
645 if (err_status == 0)
646 rio_mport_read_config_32(mport, destid, hopcount,
647 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
648 &err_status);
649
650 if (err_status & RIO_PORT_N_ERR_STS_PW_OUT_ES) {
651 pr_debug("RIO_EM: servicing Output Error-Stopped state\n");
652 /*
653 * Send a Link-Request/Input-Status control symbol
654 */
655 if (rio_get_input_status(rdev, pnum, &regval)) {
656 pr_debug("RIO_EM: Input-status response timeout\n");
657 goto rd_err;
658 }
659
660 pr_debug("RIO_EM: SP%d Input-status response=0x%08x\n",
661 pnum, regval);
662 far_ackid = (regval & RIO_PORT_N_MNT_RSP_ASTAT) >> 5;
663 far_linkstat = regval & RIO_PORT_N_MNT_RSP_LSTAT;
664 rio_mport_read_config_32(mport, destid, hopcount,
665 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
666 &regval);
667 pr_debug("RIO_EM: SP%d_ACK_STS_CSR=0x%08x\n", pnum, regval);
668 near_ackid = (regval & RIO_PORT_N_ACK_INBOUND) >> 24;
669 pr_debug("RIO_EM: SP%d far_ackID=0x%02x far_linkstat=0x%02x" \
670 " near_ackID=0x%02x\n",
671 pnum, far_ackid, far_linkstat, near_ackid);
672
673 /*
674 * If required, synchronize ackIDs of near and
675 * far sides.
676 */
677 if ((far_ackid != ((regval & RIO_PORT_N_ACK_OUTSTAND) >> 8)) ||
678 (far_ackid != (regval & RIO_PORT_N_ACK_OUTBOUND))) {
679 /* Align near outstanding/outbound ackIDs with
680 * far inbound.
681 */
682 rio_mport_write_config_32(mport, destid,
683 hopcount, rdev->phys_efptr +
684 RIO_PORT_N_ACK_STS_CSR(pnum),
685 (near_ackid << 24) |
686 (far_ackid << 8) | far_ackid);
687 /* Align far outstanding/outbound ackIDs with
688 * near inbound.
689 */
690 far_ackid++;
691 if (nextdev)
692 rio_write_config_32(nextdev,
693 nextdev->phys_efptr +
694 RIO_PORT_N_ACK_STS_CSR(RIO_GET_PORT_NUM(nextdev->swpinfo)),
695 (far_ackid << 24) |
696 (near_ackid << 8) | near_ackid);
697 else
698 pr_debug("RIO_EM: Invalid nextdev pointer (NULL)\n");
699 }
700rd_err:
701 rio_mport_read_config_32(mport, destid, hopcount,
702 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
703 &err_status);
704 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
705 }
706
707 if ((err_status & RIO_PORT_N_ERR_STS_PW_INP_ES) && nextdev) {
708 pr_debug("RIO_EM: servicing Input Error-Stopped state\n");
709 rio_get_input_status(nextdev,
710 RIO_GET_PORT_NUM(nextdev->swpinfo), NULL);
711 udelay(50);
712
713 rio_mport_read_config_32(mport, destid, hopcount,
714 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
715 &err_status);
716 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
717 }
718
719 return (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
720 RIO_PORT_N_ERR_STS_PW_INP_ES)) ? 1 : 0;
721}
722
723/**
498 * rio_inb_pwrite_handler - process inbound port-write message 724 * rio_inb_pwrite_handler - process inbound port-write message
499 * @pw_msg: pointer to inbound port-write message 725 * @pw_msg: pointer to inbound port-write message
500 * 726 *
@@ -507,13 +733,13 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
507 struct rio_mport *mport; 733 struct rio_mport *mport;
508 u8 hopcount; 734 u8 hopcount;
509 u16 destid; 735 u16 destid;
510 u32 err_status; 736 u32 err_status, em_perrdet, em_ltlerrdet;
511 int rc, portnum; 737 int rc, portnum;
512 738
513 rdev = rio_get_comptag(pw_msg->em.comptag, NULL); 739 rdev = rio_get_comptag(pw_msg->em.comptag, NULL);
514 if (rdev == NULL) { 740 if (rdev == NULL) {
515 /* Someting bad here (probably enumeration error) */ 741 /* Device removed or enumeration error */
516 pr_err("RIO: %s No matching device for CTag 0x%08x\n", 742 pr_debug("RIO: %s No matching device for CTag 0x%08x\n",
517 __func__, pw_msg->em.comptag); 743 __func__, pw_msg->em.comptag);
518 return -EIO; 744 return -EIO;
519 } 745 }
@@ -524,12 +750,11 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
524 { 750 {
525 u32 i; 751 u32 i;
526 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32);) { 752 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32);) {
527 pr_debug("0x%02x: %08x %08x %08x %08x", 753 pr_debug("0x%02x: %08x %08x %08x %08x\n",
528 i*4, pw_msg->raw[i], pw_msg->raw[i + 1], 754 i*4, pw_msg->raw[i], pw_msg->raw[i + 1],
529 pw_msg->raw[i + 2], pw_msg->raw[i + 3]); 755 pw_msg->raw[i + 2], pw_msg->raw[i + 3]);
530 i += 4; 756 i += 4;
531 } 757 }
532 pr_debug("\n");
533 } 758 }
534#endif 759#endif
535 760
@@ -545,6 +770,26 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
545 return 0; 770 return 0;
546 } 771 }
547 772
773 portnum = pw_msg->em.is_port & 0xFF;
774
775 /* Check if device and route to it are functional:
776 * Sometimes devices may send PW message(s) just before being
777 * powered down (or link being lost).
778 */
779 if (rio_chk_dev_access(rdev)) {
780 pr_debug("RIO: device access failed - get link partner\n");
781 /* Scan route to the device and identify failed link.
782 * This will replace device and port reported in PW message.
783 * PW message should not be used after this point.
784 */
785 if (rio_chk_dev_route(rdev, &rdev, &portnum)) {
786 pr_err("RIO: Route trace for %s failed\n",
787 rio_name(rdev));
788 return -EIO;
789 }
790 pw_msg = NULL;
791 }
792
548 /* For End-point devices processing stops here */ 793 /* For End-point devices processing stops here */
549 if (!(rdev->pef & RIO_PEF_SWITCH)) 794 if (!(rdev->pef & RIO_PEF_SWITCH))
550 return 0; 795 return 0;
@@ -562,9 +807,6 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
562 /* 807 /*
563 * Process the port-write notification from switch 808 * Process the port-write notification from switch
564 */ 809 */
565
566 portnum = pw_msg->em.is_port & 0xFF;
567
568 if (rdev->rswitch->em_handle) 810 if (rdev->rswitch->em_handle)
569 rdev->rswitch->em_handle(rdev, portnum); 811 rdev->rswitch->em_handle(rdev, portnum);
570 812
@@ -573,29 +815,28 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
573 &err_status); 815 &err_status);
574 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status); 816 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status);
575 817
576 if (pw_msg->em.errdetect) { 818 if (err_status & RIO_PORT_N_ERR_STS_PORT_OK) {
577 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
578 portnum, pw_msg->em.errdetect);
579 /* Clear EM Port N Error Detect CSR */
580 rio_mport_write_config_32(mport, destid, hopcount,
581 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0);
582 }
583 819
584 if (pw_msg->em.ltlerrdet) { 820 if (!(rdev->rswitch->port_ok & (1 << portnum))) {
585 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n", 821 rdev->rswitch->port_ok |= (1 << portnum);
586 pw_msg->em.ltlerrdet); 822 rio_set_port_lockout(rdev, portnum, 0);
587 /* Clear EM L/T Layer Error Detect CSR */ 823 /* Schedule Insertion Service */
588 rio_mport_write_config_32(mport, destid, hopcount, 824 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n",
589 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0); 825 rio_name(rdev), portnum);
590 } 826 }
591 827
592 /* Clear Port Errors */ 828 /* Clear error-stopped states (if reported).
593 rio_mport_write_config_32(mport, destid, hopcount, 829 * Depending on the link partner state, two attempts
594 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), 830 * may be needed for successful recovery.
595 err_status & RIO_PORT_N_ERR_STS_CLR_MASK); 831 */
832 if (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
833 RIO_PORT_N_ERR_STS_PW_INP_ES)) {
834 if (rio_clr_err_stopped(rdev, portnum, err_status))
835 rio_clr_err_stopped(rdev, portnum, 0);
836 }
837 } else { /* if (err_status & RIO_PORT_N_ERR_STS_PORT_UNINIT) */
596 838
597 if (rdev->rswitch->port_ok & (1 << portnum)) { 839 if (rdev->rswitch->port_ok & (1 << portnum)) {
598 if (err_status & RIO_PORT_N_ERR_STS_PORT_UNINIT) {
599 rdev->rswitch->port_ok &= ~(1 << portnum); 840 rdev->rswitch->port_ok &= ~(1 << portnum);
600 rio_set_port_lockout(rdev, portnum, 1); 841 rio_set_port_lockout(rdev, portnum, 1);
601 842
@@ -608,21 +849,32 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
608 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n", 849 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n",
609 rio_name(rdev), portnum); 850 rio_name(rdev), portnum);
610 } 851 }
611 } else { 852 }
612 if (err_status & RIO_PORT_N_ERR_STS_PORT_OK) {
613 rdev->rswitch->port_ok |= (1 << portnum);
614 rio_set_port_lockout(rdev, portnum, 0);
615 853
616 /* Schedule Insertion Service */ 854 rio_mport_read_config_32(mport, destid, hopcount,
617 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n", 855 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
618 rio_name(rdev), portnum); 856 if (em_perrdet) {
619 } 857 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
858 portnum, em_perrdet);
859 /* Clear EM Port N Error Detect CSR */
860 rio_mport_write_config_32(mport, destid, hopcount,
861 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0);
862 }
863
864 rio_mport_read_config_32(mport, destid, hopcount,
865 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
866 if (em_ltlerrdet) {
867 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
868 em_ltlerrdet);
869 /* Clear EM L/T Layer Error Detect CSR */
870 rio_mport_write_config_32(mport, destid, hopcount,
871 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0);
620 } 872 }
621 873
622 /* Clear Port-Write Pending bit */ 874 /* Clear remaining error bits and Port-Write Pending bit */
623 rio_mport_write_config_32(mport, destid, hopcount, 875 rio_mport_write_config_32(mport, destid, hopcount,
624 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), 876 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
625 RIO_PORT_N_ERR_STS_PW_PEND); 877 err_status);
626 878
627 return 0; 879 return 0;
628} 880}
diff --git a/drivers/rapidio/rio.h b/drivers/rapidio/rio.h
index f27b7a9c47d2..b1af414f15e6 100644
--- a/drivers/rapidio/rio.h
+++ b/drivers/rapidio/rio.h
@@ -14,6 +14,8 @@
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/rio.h> 15#include <linux/rio.h>
16 16
17#define RIO_MAX_CHK_RETRY 3
18
17/* Functions internal to the RIO core code */ 19/* Functions internal to the RIO core code */
18 20
19extern u32 rio_mport_get_feature(struct rio_mport *mport, int local, u16 destid, 21extern u32 rio_mport_get_feature(struct rio_mport *mport, int local, u16 destid,
@@ -22,6 +24,8 @@ extern u32 rio_mport_get_physefb(struct rio_mport *port, int local,
22 u16 destid, u8 hopcount); 24 u16 destid, u8 hopcount);
23extern u32 rio_mport_get_efb(struct rio_mport *port, int local, u16 destid, 25extern u32 rio_mport_get_efb(struct rio_mport *port, int local, u16 destid,
24 u8 hopcount, u32 from); 26 u8 hopcount, u32 from);
27extern int rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid,
28 u8 hopcount);
25extern int rio_create_sysfs_dev_files(struct rio_dev *rdev); 29extern int rio_create_sysfs_dev_files(struct rio_dev *rdev);
26extern int rio_enum_mport(struct rio_mport *mport); 30extern int rio_enum_mport(struct rio_mport *mport);
27extern int rio_disc_mport(struct rio_mport *mport); 31extern int rio_disc_mport(struct rio_mport *mport);
@@ -34,6 +38,7 @@ extern int rio_std_route_get_entry(struct rio_mport *mport, u16 destid,
34extern int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, 38extern int rio_std_route_clr_table(struct rio_mport *mport, u16 destid,
35 u8 hopcount, u16 table); 39 u8 hopcount, u16 table);
36extern int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock); 40extern int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock);
41extern struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from);
37 42
38/* Structures internal to the RIO core code */ 43/* Structures internal to the RIO core code */
39extern struct device_attribute rio_dev_attrs[]; 44extern struct device_attribute rio_dev_attrs[];
diff --git a/drivers/rapidio/switches/Kconfig b/drivers/rapidio/switches/Kconfig
index 2b4e9b2b6631..f47fee5d4563 100644
--- a/drivers/rapidio/switches/Kconfig
+++ b/drivers/rapidio/switches/Kconfig
@@ -20,6 +20,13 @@ config RAPIDIO_TSI568
20 ---help--- 20 ---help---
21 Includes support for IDT Tsi568 serial RapidIO switch. 21 Includes support for IDT Tsi568 serial RapidIO switch.
22 22
23config RAPIDIO_CPS_GEN2
24 bool "IDT CPS Gen.2 SRIO switch support"
25 depends on RAPIDIO
26 default n
27 ---help---
28 Includes support for ITD CPS Gen.2 serial RapidIO switches.
29
23config RAPIDIO_TSI500 30config RAPIDIO_TSI500
24 bool "Tsi500 Parallel RapidIO switch support" 31 bool "Tsi500 Parallel RapidIO switch support"
25 depends on RAPIDIO 32 depends on RAPIDIO
diff --git a/drivers/rapidio/switches/Makefile b/drivers/rapidio/switches/Makefile
index fe4adc3e8d5f..48d67a6b98c8 100644
--- a/drivers/rapidio/switches/Makefile
+++ b/drivers/rapidio/switches/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_RAPIDIO_TSI57X) += tsi57x.o
6obj-$(CONFIG_RAPIDIO_CPS_XX) += idtcps.o 6obj-$(CONFIG_RAPIDIO_CPS_XX) += idtcps.o
7obj-$(CONFIG_RAPIDIO_TSI568) += tsi568.o 7obj-$(CONFIG_RAPIDIO_TSI568) += tsi568.o
8obj-$(CONFIG_RAPIDIO_TSI500) += tsi500.o 8obj-$(CONFIG_RAPIDIO_TSI500) += tsi500.o
9obj-$(CONFIG_RAPIDIO_CPS_GEN2) += idt_gen2.o
9 10
10ifeq ($(CONFIG_RAPIDIO_DEBUG),y) 11ifeq ($(CONFIG_RAPIDIO_DEBUG),y)
11EXTRA_CFLAGS += -DDEBUG 12EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/rapidio/switches/idt_gen2.c b/drivers/rapidio/switches/idt_gen2.c
new file mode 100644
index 000000000000..0bb871cb5c40
--- /dev/null
+++ b/drivers/rapidio/switches/idt_gen2.c
@@ -0,0 +1,447 @@
1/*
2 * IDT CPS Gen.2 Serial RapidIO switch family support
3 *
4 * Copyright 2010 Integrated Device Technology, Inc.
5 * Alexandre Bounine <alexandre.bounine@idt.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/rio.h>
14#include <linux/rio_drv.h>
15#include <linux/rio_ids.h>
16#include <linux/delay.h>
17#include "../rio.h"
18
19#define LOCAL_RTE_CONF_DESTID_SEL 0x010070
20#define LOCAL_RTE_CONF_DESTID_SEL_PSEL 0x0000001f
21
22#define IDT_LT_ERR_REPORT_EN 0x03100c
23
24#define IDT_PORT_ERR_REPORT_EN(n) (0x031044 + (n)*0x40)
25#define IDT_PORT_ERR_REPORT_EN_BC 0x03ff04
26
27#define IDT_PORT_ISERR_REPORT_EN(n) (0x03104C + (n)*0x40)
28#define IDT_PORT_ISERR_REPORT_EN_BC 0x03ff0c
29#define IDT_PORT_INIT_TX_ACQUIRED 0x00000020
30
31#define IDT_LANE_ERR_REPORT_EN(n) (0x038010 + (n)*0x100)
32#define IDT_LANE_ERR_REPORT_EN_BC 0x03ff10
33
34#define IDT_DEV_CTRL_1 0xf2000c
35#define IDT_DEV_CTRL_1_GENPW 0x02000000
36#define IDT_DEV_CTRL_1_PRSTBEH 0x00000001
37
38#define IDT_CFGBLK_ERR_CAPTURE_EN 0x020008
39#define IDT_CFGBLK_ERR_REPORT 0xf20014
40#define IDT_CFGBLK_ERR_REPORT_GENPW 0x00000002
41
42#define IDT_AUX_PORT_ERR_CAP_EN 0x020000
43#define IDT_AUX_ERR_REPORT_EN 0xf20018
44#define IDT_AUX_PORT_ERR_LOG_I2C 0x00000002
45#define IDT_AUX_PORT_ERR_LOG_JTAG 0x00000001
46
47#define IDT_ISLTL_ADDRESS_CAP 0x021014
48
49#define IDT_RIO_DOMAIN 0xf20020
50#define IDT_RIO_DOMAIN_MASK 0x000000ff
51
52#define IDT_PW_INFO_CSR 0xf20024
53
54#define IDT_SOFT_RESET 0xf20040
55#define IDT_SOFT_RESET_REQ 0x00030097
56
57#define IDT_I2C_MCTRL 0xf20050
58#define IDT_I2C_MCTRL_GENPW 0x04000000
59
60#define IDT_JTAG_CTRL 0xf2005c
61#define IDT_JTAG_CTRL_GENPW 0x00000002
62
63#define IDT_LANE_CTRL(n) (0xff8000 + (n)*0x100)
64#define IDT_LANE_CTRL_BC 0xffff00
65#define IDT_LANE_CTRL_GENPW 0x00200000
66#define IDT_LANE_DFE_1_BC 0xffff18
67#define IDT_LANE_DFE_2_BC 0xffff1c
68
69#define IDT_PORT_OPS(n) (0xf40004 + (n)*0x100)
70#define IDT_PORT_OPS_GENPW 0x08000000
71#define IDT_PORT_OPS_PL_ELOG 0x00000040
72#define IDT_PORT_OPS_LL_ELOG 0x00000020
73#define IDT_PORT_OPS_LT_ELOG 0x00000010
74#define IDT_PORT_OPS_BC 0xf4ff04
75
76#define IDT_PORT_ISERR_DET(n) (0xf40008 + (n)*0x100)
77
78#define IDT_ERR_CAP 0xfd0000
79#define IDT_ERR_CAP_LOG_OVERWR 0x00000004
80
81#define IDT_ERR_RD 0xfd0004
82
83#define IDT_DEFAULT_ROUTE 0xde
84#define IDT_NO_ROUTE 0xdf
85
86static int
87idtg2_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
88 u16 table, u16 route_destid, u8 route_port)
89{
90 /*
91 * Select routing table to update
92 */
93 if (table == RIO_GLOBAL_TABLE)
94 table = 0;
95 else
96 table++;
97
98 rio_mport_write_config_32(mport, destid, hopcount,
99 LOCAL_RTE_CONF_DESTID_SEL, table);
100
101 /*
102 * Program destination port for the specified destID
103 */
104 rio_mport_write_config_32(mport, destid, hopcount,
105 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
106 (u32)route_destid);
107
108 rio_mport_write_config_32(mport, destid, hopcount,
109 RIO_STD_RTE_CONF_PORT_SEL_CSR,
110 (u32)route_port);
111 udelay(10);
112
113 return 0;
114}
115
116static int
117idtg2_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
118 u16 table, u16 route_destid, u8 *route_port)
119{
120 u32 result;
121
122 /*
123 * Select routing table to read
124 */
125 if (table == RIO_GLOBAL_TABLE)
126 table = 0;
127 else
128 table++;
129
130 rio_mport_write_config_32(mport, destid, hopcount,
131 LOCAL_RTE_CONF_DESTID_SEL, table);
132
133 rio_mport_write_config_32(mport, destid, hopcount,
134 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
135 route_destid);
136
137 rio_mport_read_config_32(mport, destid, hopcount,
138 RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
139
140 if (IDT_DEFAULT_ROUTE == (u8)result || IDT_NO_ROUTE == (u8)result)
141 *route_port = RIO_INVALID_ROUTE;
142 else
143 *route_port = (u8)result;
144
145 return 0;
146}
147
148static int
149idtg2_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
150 u16 table)
151{
152 u32 i;
153
154 /*
155 * Select routing table to read
156 */
157 if (table == RIO_GLOBAL_TABLE)
158 table = 0;
159 else
160 table++;
161
162 rio_mport_write_config_32(mport, destid, hopcount,
163 LOCAL_RTE_CONF_DESTID_SEL, table);
164
165 for (i = RIO_STD_RTE_CONF_EXTCFGEN;
166 i <= (RIO_STD_RTE_CONF_EXTCFGEN | 0xff);) {
167 rio_mport_write_config_32(mport, destid, hopcount,
168 RIO_STD_RTE_CONF_DESTID_SEL_CSR, i);
169 rio_mport_write_config_32(mport, destid, hopcount,
170 RIO_STD_RTE_CONF_PORT_SEL_CSR,
171 (IDT_DEFAULT_ROUTE << 24) | (IDT_DEFAULT_ROUTE << 16) |
172 (IDT_DEFAULT_ROUTE << 8) | IDT_DEFAULT_ROUTE);
173 i += 4;
174 }
175
176 return 0;
177}
178
179
180static int
181idtg2_set_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
182 u8 sw_domain)
183{
184 /*
185 * Switch domain configuration operates only at global level
186 */
187 rio_mport_write_config_32(mport, destid, hopcount,
188 IDT_RIO_DOMAIN, (u32)sw_domain);
189 return 0;
190}
191
192static int
193idtg2_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
194 u8 *sw_domain)
195{
196 u32 regval;
197
198 /*
199 * Switch domain configuration operates only at global level
200 */
201 rio_mport_read_config_32(mport, destid, hopcount,
202 IDT_RIO_DOMAIN, &regval);
203
204 *sw_domain = (u8)(regval & 0xff);
205
206 return 0;
207}
208
209static int
210idtg2_em_init(struct rio_dev *rdev)
211{
212 struct rio_mport *mport = rdev->net->hport;
213 u16 destid = rdev->rswitch->destid;
214 u8 hopcount = rdev->rswitch->hopcount;
215 u32 regval;
216 int i, tmp;
217
218 /*
219 * This routine performs device-specific initialization only.
220 * All standard EM configuration should be performed at upper level.
221 */
222
223 pr_debug("RIO: %s [%d:%d]\n", __func__, destid, hopcount);
224
225 /* Set Port-Write info CSR: PRIO=3 and CRF=1 */
226 rio_mport_write_config_32(mport, destid, hopcount,
227 IDT_PW_INFO_CSR, 0x0000e000);
228
229 /*
230 * Configure LT LAYER error reporting.
231 */
232
233 /* Enable standard (RIO.p8) error reporting */
234 rio_mport_write_config_32(mport, destid, hopcount,
235 IDT_LT_ERR_REPORT_EN,
236 REM_LTL_ERR_ILLTRAN | REM_LTL_ERR_UNSOLR |
237 REM_LTL_ERR_UNSUPTR);
238
239 /* Use Port-Writes for LT layer error reporting.
240 * Enable per-port reset
241 */
242 rio_mport_read_config_32(mport, destid, hopcount,
243 IDT_DEV_CTRL_1, &regval);
244 rio_mport_write_config_32(mport, destid, hopcount,
245 IDT_DEV_CTRL_1,
246 regval | IDT_DEV_CTRL_1_GENPW | IDT_DEV_CTRL_1_PRSTBEH);
247
248 /*
249 * Configure PORT error reporting.
250 */
251
252 /* Report all RIO.p8 errors supported by device */
253 rio_mport_write_config_32(mport, destid, hopcount,
254 IDT_PORT_ERR_REPORT_EN_BC, 0x807e8037);
255
256 /* Configure reporting of implementation specific errors/events */
257 rio_mport_write_config_32(mport, destid, hopcount,
258 IDT_PORT_ISERR_REPORT_EN_BC, IDT_PORT_INIT_TX_ACQUIRED);
259
260 /* Use Port-Writes for port error reporting and enable error logging */
261 tmp = RIO_GET_TOTAL_PORTS(rdev->swpinfo);
262 for (i = 0; i < tmp; i++) {
263 rio_mport_read_config_32(mport, destid, hopcount,
264 IDT_PORT_OPS(i), &regval);
265 rio_mport_write_config_32(mport, destid, hopcount,
266 IDT_PORT_OPS(i), regval | IDT_PORT_OPS_GENPW |
267 IDT_PORT_OPS_PL_ELOG |
268 IDT_PORT_OPS_LL_ELOG |
269 IDT_PORT_OPS_LT_ELOG);
270 }
271 /* Overwrite error log if full */
272 rio_mport_write_config_32(mport, destid, hopcount,
273 IDT_ERR_CAP, IDT_ERR_CAP_LOG_OVERWR);
274
275 /*
276 * Configure LANE error reporting.
277 */
278
279 /* Disable line error reporting */
280 rio_mport_write_config_32(mport, destid, hopcount,
281 IDT_LANE_ERR_REPORT_EN_BC, 0);
282
283 /* Use Port-Writes for lane error reporting (when enabled)
284 * (do per-lane update because lanes may have different configuration)
285 */
286 tmp = (rdev->did == RIO_DID_IDTCPS1848) ? 48 : 16;
287 for (i = 0; i < tmp; i++) {
288 rio_mport_read_config_32(mport, destid, hopcount,
289 IDT_LANE_CTRL(i), &regval);
290 rio_mport_write_config_32(mport, destid, hopcount,
291 IDT_LANE_CTRL(i), regval | IDT_LANE_CTRL_GENPW);
292 }
293
294 /*
295 * Configure AUX error reporting.
296 */
297
298 /* Disable JTAG and I2C Error capture */
299 rio_mport_write_config_32(mport, destid, hopcount,
300 IDT_AUX_PORT_ERR_CAP_EN, 0);
301
302 /* Disable JTAG and I2C Error reporting/logging */
303 rio_mport_write_config_32(mport, destid, hopcount,
304 IDT_AUX_ERR_REPORT_EN, 0);
305
306 /* Disable Port-Write notification from JTAG */
307 rio_mport_write_config_32(mport, destid, hopcount,
308 IDT_JTAG_CTRL, 0);
309
310 /* Disable Port-Write notification from I2C */
311 rio_mport_read_config_32(mport, destid, hopcount,
312 IDT_I2C_MCTRL, &regval);
313 rio_mport_write_config_32(mport, destid, hopcount,
314 IDT_I2C_MCTRL,
315 regval & ~IDT_I2C_MCTRL_GENPW);
316
317 /*
318 * Configure CFG_BLK error reporting.
319 */
320
321 /* Disable Configuration Block error capture */
322 rio_mport_write_config_32(mport, destid, hopcount,
323 IDT_CFGBLK_ERR_CAPTURE_EN, 0);
324
325 /* Disable Port-Writes for Configuration Block error reporting */
326 rio_mport_read_config_32(mport, destid, hopcount,
327 IDT_CFGBLK_ERR_REPORT, &regval);
328 rio_mport_write_config_32(mport, destid, hopcount,
329 IDT_CFGBLK_ERR_REPORT,
330 regval & ~IDT_CFGBLK_ERR_REPORT_GENPW);
331
332 /* set TVAL = ~50us */
333 rio_mport_write_config_32(mport, destid, hopcount,
334 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
335
336 return 0;
337}
338
339static int
340idtg2_em_handler(struct rio_dev *rdev, u8 portnum)
341{
342 struct rio_mport *mport = rdev->net->hport;
343 u16 destid = rdev->rswitch->destid;
344 u8 hopcount = rdev->rswitch->hopcount;
345 u32 regval, em_perrdet, em_ltlerrdet;
346
347 rio_mport_read_config_32(mport, destid, hopcount,
348 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
349 if (em_ltlerrdet) {
350 /* Service Logical/Transport Layer Error(s) */
351 if (em_ltlerrdet & REM_LTL_ERR_IMPSPEC) {
352 /* Implementation specific error reported */
353 rio_mport_read_config_32(mport, destid, hopcount,
354 IDT_ISLTL_ADDRESS_CAP, &regval);
355
356 pr_debug("RIO: %s Implementation Specific LTL errors" \
357 " 0x%x @(0x%x)\n",
358 rio_name(rdev), em_ltlerrdet, regval);
359
360 /* Clear implementation specific address capture CSR */
361 rio_mport_write_config_32(mport, destid, hopcount,
362 IDT_ISLTL_ADDRESS_CAP, 0);
363
364 }
365 }
366
367 rio_mport_read_config_32(mport, destid, hopcount,
368 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
369 if (em_perrdet) {
370 /* Service Port-Level Error(s) */
371 if (em_perrdet & REM_PED_IMPL_SPEC) {
372 /* Implementation Specific port error reported */
373
374 /* Get IS errors reported */
375 rio_mport_read_config_32(mport, destid, hopcount,
376 IDT_PORT_ISERR_DET(portnum), &regval);
377
378 pr_debug("RIO: %s Implementation Specific Port" \
379 " errors 0x%x\n", rio_name(rdev), regval);
380
381 /* Clear all implementation specific events */
382 rio_mport_write_config_32(mport, destid, hopcount,
383 IDT_PORT_ISERR_DET(portnum), 0);
384 }
385 }
386
387 return 0;
388}
389
390static ssize_t
391idtg2_show_errlog(struct device *dev, struct device_attribute *attr, char *buf)
392{
393 struct rio_dev *rdev = to_rio_dev(dev);
394 struct rio_mport *mport = rdev->net->hport;
395 u16 destid = rdev->rswitch->destid;
396 u8 hopcount = rdev->rswitch->hopcount;
397 ssize_t len = 0;
398 u32 regval;
399
400 while (!rio_mport_read_config_32(mport, destid, hopcount,
401 IDT_ERR_RD, &regval)) {
402 if (!regval) /* 0 = end of log */
403 break;
404 len += snprintf(buf + len, PAGE_SIZE - len,
405 "%08x\n", regval);
406 if (len >= (PAGE_SIZE - 10))
407 break;
408 }
409
410 return len;
411}
412
413static DEVICE_ATTR(errlog, S_IRUGO, idtg2_show_errlog, NULL);
414
415static int idtg2_sysfs(struct rio_dev *rdev, int create)
416{
417 struct device *dev = &rdev->dev;
418 int err = 0;
419
420 if (create == RIO_SW_SYSFS_CREATE) {
421 /* Initialize sysfs entries */
422 err = device_create_file(dev, &dev_attr_errlog);
423 if (err)
424 dev_err(dev, "Unable create sysfs errlog file\n");
425 } else
426 device_remove_file(dev, &dev_attr_errlog);
427
428 return err;
429}
430
431static int idtg2_switch_init(struct rio_dev *rdev, int do_enum)
432{
433 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
434 rdev->rswitch->add_entry = idtg2_route_add_entry;
435 rdev->rswitch->get_entry = idtg2_route_get_entry;
436 rdev->rswitch->clr_table = idtg2_route_clr_table;
437 rdev->rswitch->set_domain = idtg2_set_domain;
438 rdev->rswitch->get_domain = idtg2_get_domain;
439 rdev->rswitch->em_init = idtg2_em_init;
440 rdev->rswitch->em_handle = idtg2_em_handler;
441 rdev->rswitch->sw_sysfs = idtg2_sysfs;
442
443 return 0;
444}
445
446DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1848, idtg2_switch_init);
447DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1616, idtg2_switch_init);
diff --git a/drivers/rapidio/switches/idtcps.c b/drivers/rapidio/switches/idtcps.c
index 2c790c144f89..fc9f6374f759 100644
--- a/drivers/rapidio/switches/idtcps.c
+++ b/drivers/rapidio/switches/idtcps.c
@@ -117,6 +117,10 @@ idtcps_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
117 117
118static int idtcps_switch_init(struct rio_dev *rdev, int do_enum) 118static int idtcps_switch_init(struct rio_dev *rdev, int do_enum)
119{ 119{
120 struct rio_mport *mport = rdev->net->hport;
121 u16 destid = rdev->rswitch->destid;
122 u8 hopcount = rdev->rswitch->hopcount;
123
120 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev)); 124 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
121 rdev->rswitch->add_entry = idtcps_route_add_entry; 125 rdev->rswitch->add_entry = idtcps_route_add_entry;
122 rdev->rswitch->get_entry = idtcps_route_get_entry; 126 rdev->rswitch->get_entry = idtcps_route_get_entry;
@@ -126,6 +130,12 @@ static int idtcps_switch_init(struct rio_dev *rdev, int do_enum)
126 rdev->rswitch->em_init = NULL; 130 rdev->rswitch->em_init = NULL;
127 rdev->rswitch->em_handle = NULL; 131 rdev->rswitch->em_handle = NULL;
128 132
133 if (do_enum) {
134 /* set TVAL = ~50us */
135 rio_mport_write_config_32(mport, destid, hopcount,
136 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
137 }
138
129 return 0; 139 return 0;
130} 140}
131 141
diff --git a/drivers/rapidio/switches/tsi568.c b/drivers/rapidio/switches/tsi568.c
index f7fd7898606e..b9a389b9f812 100644
--- a/drivers/rapidio/switches/tsi568.c
+++ b/drivers/rapidio/switches/tsi568.c
@@ -29,7 +29,7 @@
29#define SPP_ROUTE_CFG_DESTID(n) (0x11070 + 0x100*n) 29#define SPP_ROUTE_CFG_DESTID(n) (0x11070 + 0x100*n)
30#define SPP_ROUTE_CFG_PORT(n) (0x11074 + 0x100*n) 30#define SPP_ROUTE_CFG_PORT(n) (0x11074 + 0x100*n)
31 31
32#define TSI568_SP_MODE_BC 0x10004 32#define TSI568_SP_MODE(n) (0x11004 + 0x100*n)
33#define TSI568_SP_MODE_PW_DIS 0x08000000 33#define TSI568_SP_MODE_PW_DIS 0x08000000
34 34
35static int 35static int
@@ -117,14 +117,19 @@ tsi568_em_init(struct rio_dev *rdev)
117 u16 destid = rdev->rswitch->destid; 117 u16 destid = rdev->rswitch->destid;
118 u8 hopcount = rdev->rswitch->hopcount; 118 u8 hopcount = rdev->rswitch->hopcount;
119 u32 regval; 119 u32 regval;
120 int portnum;
120 121
121 pr_debug("TSI568 %s [%d:%d]\n", __func__, destid, hopcount); 122 pr_debug("TSI568 %s [%d:%d]\n", __func__, destid, hopcount);
122 123
123 /* Make sure that Port-Writes are disabled (for all ports) */ 124 /* Make sure that Port-Writes are disabled (for all ports) */
124 rio_mport_read_config_32(mport, destid, hopcount, 125 for (portnum = 0;
125 TSI568_SP_MODE_BC, &regval); 126 portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
126 rio_mport_write_config_32(mport, destid, hopcount, 127 rio_mport_read_config_32(mport, destid, hopcount,
127 TSI568_SP_MODE_BC, regval | TSI568_SP_MODE_PW_DIS); 128 TSI568_SP_MODE(portnum), &regval);
129 rio_mport_write_config_32(mport, destid, hopcount,
130 TSI568_SP_MODE(portnum),
131 regval | TSI568_SP_MODE_PW_DIS);
132 }
128 133
129 return 0; 134 return 0;
130} 135}
diff --git a/drivers/rapidio/switches/tsi57x.c b/drivers/rapidio/switches/tsi57x.c
index d34df722d95f..2003fb63c404 100644
--- a/drivers/rapidio/switches/tsi57x.c
+++ b/drivers/rapidio/switches/tsi57x.c
@@ -166,7 +166,8 @@ tsi57x_em_init(struct rio_dev *rdev)
166 166
167 pr_debug("TSI578 %s [%d:%d]\n", __func__, destid, hopcount); 167 pr_debug("TSI578 %s [%d:%d]\n", __func__, destid, hopcount);
168 168
169 for (portnum = 0; portnum < 16; portnum++) { 169 for (portnum = 0;
170 portnum < RIO_GET_TOTAL_PORTS(rdev->swpinfo); portnum++) {
170 /* Make sure that Port-Writes are enabled (for all ports) */ 171 /* Make sure that Port-Writes are enabled (for all ports) */
171 rio_mport_read_config_32(mport, destid, hopcount, 172 rio_mport_read_config_32(mport, destid, hopcount,
172 TSI578_SP_MODE(portnum), &regval); 173 TSI578_SP_MODE(portnum), &regval);
@@ -205,6 +206,10 @@ tsi57x_em_init(struct rio_dev *rdev)
205 portnum++; 206 portnum++;
206 } 207 }
207 208
209 /* set TVAL = ~50us */
210 rio_mport_write_config_32(mport, destid, hopcount,
211 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x9a << 8);
212
208 return 0; 213 return 0;
209} 214}
210 215
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 2785a0f16c9f..6a77437d4f5a 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -171,7 +171,8 @@ config RTC_DRV_DS3232
171 depends on RTC_CLASS && I2C 171 depends on RTC_CLASS && I2C
172 help 172 help
173 If you say yes here you get support for Dallas Semiconductor 173 If you say yes here you get support for Dallas Semiconductor
174 DS3232 real-time clock chips. 174 DS3232 real-time clock chips. If an interrupt is associated
175 with the device, the alarm functionality is supported.
175 176
176 This driver can also be built as a module. If so, the module 177 This driver can also be built as a module. If so, the module
177 will be called rtc-ds3232. 178 will be called rtc-ds3232.
@@ -952,4 +953,13 @@ config RTC_DRV_JZ4740
952 This driver can also be buillt as a module. If so, the module 953 This driver can also be buillt as a module. If so, the module
953 will be called rtc-jz4740. 954 will be called rtc-jz4740.
954 955
956config RTC_DRV_LPC32XX
957 depends on ARCH_LPC32XX
958 tristate "NXP LPC32XX RTC"
959 help
960 This enables support for the NXP RTC in the LPC32XX
961
962 This driver can also be buillt as a module. If so, the module
963 will be called rtc-lpc32xx.
964
955endif # RTC_CLASS 965endif # RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 0f207b3b5833..7a7cb3228a1d 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o
51obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 51obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
52obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o 52obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o
53obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o 53obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o
54obj-$(CONFIG_RTC_DRV_LPC32XX) += rtc-lpc32xx.o
54obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o 55obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
55obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o 56obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o
56obj-$(CONFIG_RTC_DRV_M48T35) += rtc-m48t35.o 57obj-$(CONFIG_RTC_DRV_M48T35) += rtc-m48t35.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 565562ba6ac9..e6539cbabb35 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -158,8 +158,10 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
158 rtc_dev_prepare(rtc); 158 rtc_dev_prepare(rtc);
159 159
160 err = device_register(&rtc->dev); 160 err = device_register(&rtc->dev);
161 if (err) 161 if (err) {
162 put_device(&rtc->dev);
162 goto exit_kfree; 163 goto exit_kfree;
164 }
163 165
164 rtc_dev_add_device(rtc); 166 rtc_dev_add_device(rtc);
165 rtc_sysfs_add_device(rtc); 167 rtc_sysfs_add_device(rtc);
diff --git a/drivers/rtc/rtc-bfin.c b/drivers/rtc/rtc-bfin.c
index d4fb82d85e9b..b4b6087f2234 100644
--- a/drivers/rtc/rtc-bfin.c
+++ b/drivers/rtc/rtc-bfin.c
@@ -2,7 +2,7 @@
2 * Blackfin On-Chip Real Time Clock Driver 2 * Blackfin On-Chip Real Time Clock Driver
3 * Supports BF51x/BF52x/BF53[123]/BF53[467]/BF54x 3 * Supports BF51x/BF52x/BF53[123]/BF53[467]/BF54x
4 * 4 *
5 * Copyright 2004-2009 Analog Devices Inc. 5 * Copyright 2004-2010 Analog Devices Inc.
6 * 6 *
7 * Enter bugs at http://blackfin.uclinux.org/ 7 * Enter bugs at http://blackfin.uclinux.org/
8 * 8 *
@@ -183,29 +183,33 @@ static irqreturn_t bfin_rtc_interrupt(int irq, void *dev_id)
183 struct bfin_rtc *rtc = dev_get_drvdata(dev); 183 struct bfin_rtc *rtc = dev_get_drvdata(dev);
184 unsigned long events = 0; 184 unsigned long events = 0;
185 bool write_complete = false; 185 bool write_complete = false;
186 u16 rtc_istat, rtc_ictl; 186 u16 rtc_istat, rtc_istat_clear, rtc_ictl, bits;
187 187
188 dev_dbg_stamp(dev); 188 dev_dbg_stamp(dev);
189 189
190 rtc_istat = bfin_read_RTC_ISTAT(); 190 rtc_istat = bfin_read_RTC_ISTAT();
191 rtc_ictl = bfin_read_RTC_ICTL(); 191 rtc_ictl = bfin_read_RTC_ICTL();
192 rtc_istat_clear = 0;
192 193
193 if (rtc_istat & RTC_ISTAT_WRITE_COMPLETE) { 194 bits = RTC_ISTAT_WRITE_COMPLETE;
194 bfin_write_RTC_ISTAT(RTC_ISTAT_WRITE_COMPLETE); 195 if (rtc_istat & bits) {
196 rtc_istat_clear |= bits;
195 write_complete = true; 197 write_complete = true;
196 complete(&bfin_write_complete); 198 complete(&bfin_write_complete);
197 } 199 }
198 200
199 if (rtc_ictl & (RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY)) { 201 bits = (RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY);
200 if (rtc_istat & (RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY)) { 202 if (rtc_ictl & bits) {
201 bfin_write_RTC_ISTAT(RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY); 203 if (rtc_istat & bits) {
204 rtc_istat_clear |= bits;
202 events |= RTC_AF | RTC_IRQF; 205 events |= RTC_AF | RTC_IRQF;
203 } 206 }
204 } 207 }
205 208
206 if (rtc_ictl & RTC_ISTAT_SEC) { 209 bits = RTC_ISTAT_SEC;
207 if (rtc_istat & RTC_ISTAT_SEC) { 210 if (rtc_ictl & bits) {
208 bfin_write_RTC_ISTAT(RTC_ISTAT_SEC); 211 if (rtc_istat & bits) {
212 rtc_istat_clear |= bits;
209 events |= RTC_UF | RTC_IRQF; 213 events |= RTC_UF | RTC_IRQF;
210 } 214 }
211 } 215 }
@@ -213,9 +217,10 @@ static irqreturn_t bfin_rtc_interrupt(int irq, void *dev_id)
213 if (events) 217 if (events)
214 rtc_update_irq(rtc->rtc_dev, 1, events); 218 rtc_update_irq(rtc->rtc_dev, 1, events);
215 219
216 if (write_complete || events) 220 if (write_complete || events) {
221 bfin_write_RTC_ISTAT(rtc_istat_clear);
217 return IRQ_HANDLED; 222 return IRQ_HANDLED;
218 else 223 } else
219 return IRQ_NONE; 224 return IRQ_NONE;
220} 225}
221 226
@@ -422,9 +427,13 @@ static int __devexit bfin_rtc_remove(struct platform_device *pdev)
422#ifdef CONFIG_PM 427#ifdef CONFIG_PM
423static int bfin_rtc_suspend(struct platform_device *pdev, pm_message_t state) 428static int bfin_rtc_suspend(struct platform_device *pdev, pm_message_t state)
424{ 429{
425 if (device_may_wakeup(&pdev->dev)) { 430 struct device *dev = &pdev->dev;
431
432 dev_dbg_stamp(dev);
433
434 if (device_may_wakeup(dev)) {
426 enable_irq_wake(IRQ_RTC); 435 enable_irq_wake(IRQ_RTC);
427 bfin_rtc_sync_pending(&pdev->dev); 436 bfin_rtc_sync_pending(dev);
428 } else 437 } else
429 bfin_rtc_int_clear(0); 438 bfin_rtc_int_clear(0);
430 439
@@ -433,7 +442,11 @@ static int bfin_rtc_suspend(struct platform_device *pdev, pm_message_t state)
433 442
434static int bfin_rtc_resume(struct platform_device *pdev) 443static int bfin_rtc_resume(struct platform_device *pdev)
435{ 444{
436 if (device_may_wakeup(&pdev->dev)) 445 struct device *dev = &pdev->dev;
446
447 dev_dbg_stamp(dev);
448
449 if (device_may_wakeup(dev))
437 disable_irq_wake(IRQ_RTC); 450 disable_irq_wake(IRQ_RTC);
438 451
439 /* 452 /*
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
index 9de8516e3531..57063552d3b7 100644
--- a/drivers/rtc/rtc-ds3232.c
+++ b/drivers/rtc/rtc-ds3232.c
@@ -2,6 +2,7 @@
2 * RTC client/driver for the Maxim/Dallas DS3232 Real-Time Clock over I2C 2 * RTC client/driver for the Maxim/Dallas DS3232 Real-Time Clock over I2C
3 * 3 *
4 * Copyright (C) 2009-2010 Freescale Semiconductor. 4 * Copyright (C) 2009-2010 Freescale Semiconductor.
5 * Author: Jack Lan <jack.lan@freescale.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the 8 * under the terms of the GNU General Public License as published by the
@@ -175,6 +176,182 @@ static int ds3232_set_time(struct device *dev, struct rtc_time *time)
175 DS3232_REG_SECONDS, 7, buf); 176 DS3232_REG_SECONDS, 7, buf);
176} 177}
177 178
179/*
180 * DS3232 has two alarm, we only use alarm1
181 * According to linux specification, only support one-shot alarm
182 * no periodic alarm mode
183 */
184static int ds3232_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
185{
186 struct i2c_client *client = to_i2c_client(dev);
187 struct ds3232 *ds3232 = i2c_get_clientdata(client);
188 int control, stat;
189 int ret;
190 u8 buf[4];
191
192 mutex_lock(&ds3232->mutex);
193
194 ret = i2c_smbus_read_byte_data(client, DS3232_REG_SR);
195 if (ret < 0)
196 goto out;
197 stat = ret;
198 ret = i2c_smbus_read_byte_data(client, DS3232_REG_CR);
199 if (ret < 0)
200 goto out;
201 control = ret;
202 ret = i2c_smbus_read_i2c_block_data(client, DS3232_REG_ALARM1, 4, buf);
203 if (ret < 0)
204 goto out;
205
206 alarm->time.tm_sec = bcd2bin(buf[0] & 0x7F);
207 alarm->time.tm_min = bcd2bin(buf[1] & 0x7F);
208 alarm->time.tm_hour = bcd2bin(buf[2] & 0x7F);
209 alarm->time.tm_mday = bcd2bin(buf[3] & 0x7F);
210
211 alarm->time.tm_mon = -1;
212 alarm->time.tm_year = -1;
213 alarm->time.tm_wday = -1;
214 alarm->time.tm_yday = -1;
215 alarm->time.tm_isdst = -1;
216
217 alarm->enabled = !!(control & DS3232_REG_CR_A1IE);
218 alarm->pending = !!(stat & DS3232_REG_SR_A1F);
219
220 ret = 0;
221out:
222 mutex_unlock(&ds3232->mutex);
223 return ret;
224}
225
226/*
227 * linux rtc-module does not support wday alarm
228 * and only 24h time mode supported indeed
229 */
230static int ds3232_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
231{
232 struct i2c_client *client = to_i2c_client(dev);
233 struct ds3232 *ds3232 = i2c_get_clientdata(client);
234 int control, stat;
235 int ret;
236 u8 buf[4];
237
238 if (client->irq <= 0)
239 return -EINVAL;
240
241 mutex_lock(&ds3232->mutex);
242
243 buf[0] = bin2bcd(alarm->time.tm_sec);
244 buf[1] = bin2bcd(alarm->time.tm_min);
245 buf[2] = bin2bcd(alarm->time.tm_hour);
246 buf[3] = bin2bcd(alarm->time.tm_mday);
247
248 /* clear alarm interrupt enable bit */
249 ret = i2c_smbus_read_byte_data(client, DS3232_REG_CR);
250 if (ret < 0)
251 goto out;
252 control = ret;
253 control &= ~(DS3232_REG_CR_A1IE | DS3232_REG_CR_A2IE);
254 ret = i2c_smbus_write_byte_data(client, DS3232_REG_CR, control);
255 if (ret < 0)
256 goto out;
257
258 /* clear any pending alarm flag */
259 ret = i2c_smbus_read_byte_data(client, DS3232_REG_SR);
260 if (ret < 0)
261 goto out;
262 stat = ret;
263 stat &= ~(DS3232_REG_SR_A1F | DS3232_REG_SR_A2F);
264 ret = i2c_smbus_write_byte_data(client, DS3232_REG_SR, stat);
265 if (ret < 0)
266 goto out;
267
268 ret = i2c_smbus_write_i2c_block_data(client, DS3232_REG_ALARM1, 4, buf);
269
270 if (alarm->enabled) {
271 control |= DS3232_REG_CR_A1IE;
272 ret = i2c_smbus_write_byte_data(client, DS3232_REG_CR, control);
273 }
274out:
275 mutex_unlock(&ds3232->mutex);
276 return ret;
277}
278
279static void ds3232_update_alarm(struct i2c_client *client)
280{
281 struct ds3232 *ds3232 = i2c_get_clientdata(client);
282 int control;
283 int ret;
284 u8 buf[4];
285
286 mutex_lock(&ds3232->mutex);
287
288 ret = i2c_smbus_read_i2c_block_data(client, DS3232_REG_ALARM1, 4, buf);
289 if (ret < 0)
290 goto unlock;
291
292 buf[0] = bcd2bin(buf[0]) < 0 || (ds3232->rtc->irq_data & RTC_UF) ?
293 0x80 : buf[0];
294 buf[1] = bcd2bin(buf[1]) < 0 || (ds3232->rtc->irq_data & RTC_UF) ?
295 0x80 : buf[1];
296 buf[2] = bcd2bin(buf[2]) < 0 || (ds3232->rtc->irq_data & RTC_UF) ?
297 0x80 : buf[2];
298 buf[3] = bcd2bin(buf[3]) < 0 || (ds3232->rtc->irq_data & RTC_UF) ?
299 0x80 : buf[3];
300
301 ret = i2c_smbus_write_i2c_block_data(client, DS3232_REG_ALARM1, 4, buf);
302 if (ret < 0)
303 goto unlock;
304
305 control = i2c_smbus_read_byte_data(client, DS3232_REG_CR);
306 if (control < 0)
307 goto unlock;
308
309 if (ds3232->rtc->irq_data & (RTC_AF | RTC_UF))
310 /* enable alarm1 interrupt */
311 control |= DS3232_REG_CR_A1IE;
312 else
313 /* disable alarm1 interrupt */
314 control &= ~(DS3232_REG_CR_A1IE);
315 i2c_smbus_write_byte_data(client, DS3232_REG_CR, control);
316
317unlock:
318 mutex_unlock(&ds3232->mutex);
319}
320
321static int ds3232_alarm_irq_enable(struct device *dev, unsigned int enabled)
322{
323 struct i2c_client *client = to_i2c_client(dev);
324 struct ds3232 *ds3232 = i2c_get_clientdata(client);
325
326 if (client->irq <= 0)
327 return -EINVAL;
328
329 if (enabled)
330 ds3232->rtc->irq_data |= RTC_AF;
331 else
332 ds3232->rtc->irq_data &= ~RTC_AF;
333
334 ds3232_update_alarm(client);
335 return 0;
336}
337
338static int ds3232_update_irq_enable(struct device *dev, unsigned int enabled)
339{
340 struct i2c_client *client = to_i2c_client(dev);
341 struct ds3232 *ds3232 = i2c_get_clientdata(client);
342
343 if (client->irq <= 0)
344 return -EINVAL;
345
346 if (enabled)
347 ds3232->rtc->irq_data |= RTC_UF;
348 else
349 ds3232->rtc->irq_data &= ~RTC_UF;
350
351 ds3232_update_alarm(client);
352 return 0;
353}
354
178static irqreturn_t ds3232_irq(int irq, void *dev_id) 355static irqreturn_t ds3232_irq(int irq, void *dev_id)
179{ 356{
180 struct i2c_client *client = dev_id; 357 struct i2c_client *client = dev_id;
@@ -222,6 +399,10 @@ unlock:
222static const struct rtc_class_ops ds3232_rtc_ops = { 399static const struct rtc_class_ops ds3232_rtc_ops = {
223 .read_time = ds3232_read_time, 400 .read_time = ds3232_read_time,
224 .set_time = ds3232_set_time, 401 .set_time = ds3232_set_time,
402 .read_alarm = ds3232_read_alarm,
403 .set_alarm = ds3232_set_alarm,
404 .alarm_irq_enable = ds3232_alarm_irq_enable,
405 .update_irq_enable = ds3232_update_irq_enable,
225}; 406};
226 407
227static int __devinit ds3232_probe(struct i2c_client *client, 408static int __devinit ds3232_probe(struct i2c_client *client,
diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index 2619d57b91d7..2e16f72c9056 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de> 2 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
3 * Copyright (C) 2010, Paul Cercueil <paul@crapouillou.net>
3 * JZ4740 SoC RTC driver 4 * JZ4740 SoC RTC driver
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
@@ -161,7 +162,8 @@ static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
161 162
162 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs); 163 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs);
163 if (!ret) 164 if (!ret)
164 ret = jz4740_rtc_ctrl_set_bits(rtc, JZ_RTC_CTRL_AE, alrm->enabled); 165 ret = jz4740_rtc_ctrl_set_bits(rtc,
166 JZ_RTC_CTRL_AE | JZ_RTC_CTRL_AF_IRQ, alrm->enabled);
165 167
166 return ret; 168 return ret;
167} 169}
@@ -258,6 +260,8 @@ static int __devinit jz4740_rtc_probe(struct platform_device *pdev)
258 260
259 platform_set_drvdata(pdev, rtc); 261 platform_set_drvdata(pdev, rtc);
260 262
263 device_init_wakeup(&pdev->dev, 1);
264
261 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, &jz4740_rtc_ops, 265 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, &jz4740_rtc_ops,
262 THIS_MODULE); 266 THIS_MODULE);
263 if (IS_ERR(rtc->rtc)) { 267 if (IS_ERR(rtc->rtc)) {
@@ -318,12 +322,43 @@ static int __devexit jz4740_rtc_remove(struct platform_device *pdev)
318 return 0; 322 return 0;
319} 323}
320 324
325
326#ifdef CONFIG_PM
327static int jz4740_rtc_suspend(struct device *dev)
328{
329 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
330
331 if (device_may_wakeup(dev))
332 enable_irq_wake(rtc->irq);
333 return 0;
334}
335
336static int jz4740_rtc_resume(struct device *dev)
337{
338 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
339
340 if (device_may_wakeup(dev))
341 disable_irq_wake(rtc->irq);
342 return 0;
343}
344
345static const struct dev_pm_ops jz4740_pm_ops = {
346 .suspend = jz4740_rtc_suspend,
347 .resume = jz4740_rtc_resume,
348};
349#define JZ4740_RTC_PM_OPS (&jz4740_pm_ops)
350
351#else
352#define JZ4740_RTC_PM_OPS NULL
353#endif /* CONFIG_PM */
354
321struct platform_driver jz4740_rtc_driver = { 355struct platform_driver jz4740_rtc_driver = {
322 .probe = jz4740_rtc_probe, 356 .probe = jz4740_rtc_probe,
323 .remove = __devexit_p(jz4740_rtc_remove), 357 .remove = __devexit_p(jz4740_rtc_remove),
324 .driver = { 358 .driver = {
325 .name = "jz4740-rtc", 359 .name = "jz4740-rtc",
326 .owner = THIS_MODULE, 360 .owner = THIS_MODULE,
361 .pm = JZ4740_RTC_PM_OPS,
327 }, 362 },
328}; 363};
329 364
diff --git a/drivers/rtc/rtc-lpc32xx.c b/drivers/rtc/rtc-lpc32xx.c
new file mode 100644
index 000000000000..ec8701ce99f9
--- /dev/null
+++ b/drivers/rtc/rtc-lpc32xx.c
@@ -0,0 +1,414 @@
1/*
2 * Copyright (C) 2010 NXP Semiconductors
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 * You should have received a copy of the GNU General Public License along
10 * with this program; if not, write to the Free Software Foundation, Inc.,
11 * 675 Mass Ave, Cambridge, MA 02139, USA.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/platform_device.h>
18#include <linux/spinlock.h>
19#include <linux/rtc.h>
20#include <linux/slab.h>
21#include <linux/io.h>
22
23/*
24 * Clock and Power control register offsets
25 */
26#define LPC32XX_RTC_UCOUNT 0x00
27#define LPC32XX_RTC_DCOUNT 0x04
28#define LPC32XX_RTC_MATCH0 0x08
29#define LPC32XX_RTC_MATCH1 0x0C
30#define LPC32XX_RTC_CTRL 0x10
31#define LPC32XX_RTC_INTSTAT 0x14
32#define LPC32XX_RTC_KEY 0x18
33#define LPC32XX_RTC_SRAM 0x80
34
35#define LPC32XX_RTC_CTRL_MATCH0 (1 << 0)
36#define LPC32XX_RTC_CTRL_MATCH1 (1 << 1)
37#define LPC32XX_RTC_CTRL_ONSW_MATCH0 (1 << 2)
38#define LPC32XX_RTC_CTRL_ONSW_MATCH1 (1 << 3)
39#define LPC32XX_RTC_CTRL_SW_RESET (1 << 4)
40#define LPC32XX_RTC_CTRL_CNTR_DIS (1 << 6)
41#define LPC32XX_RTC_CTRL_ONSW_FORCE_HI (1 << 7)
42
43#define LPC32XX_RTC_INTSTAT_MATCH0 (1 << 0)
44#define LPC32XX_RTC_INTSTAT_MATCH1 (1 << 1)
45#define LPC32XX_RTC_INTSTAT_ONSW (1 << 2)
46
47#define LPC32XX_RTC_KEY_ONSW_LOADVAL 0xB5C13F27
48
49#define RTC_NAME "rtc-lpc32xx"
50
51#define rtc_readl(dev, reg) \
52 __raw_readl((dev)->rtc_base + (reg))
53#define rtc_writel(dev, reg, val) \
54 __raw_writel((val), (dev)->rtc_base + (reg))
55
56struct lpc32xx_rtc {
57 void __iomem *rtc_base;
58 int irq;
59 unsigned char alarm_enabled;
60 struct rtc_device *rtc;
61 spinlock_t lock;
62};
63
64static int lpc32xx_rtc_read_time(struct device *dev, struct rtc_time *time)
65{
66 unsigned long elapsed_sec;
67 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
68
69 elapsed_sec = rtc_readl(rtc, LPC32XX_RTC_UCOUNT);
70 rtc_time_to_tm(elapsed_sec, time);
71
72 return rtc_valid_tm(time);
73}
74
75static int lpc32xx_rtc_set_mmss(struct device *dev, unsigned long secs)
76{
77 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
78 u32 tmp;
79
80 spin_lock_irq(&rtc->lock);
81
82 /* RTC must be disabled during count update */
83 tmp = rtc_readl(rtc, LPC32XX_RTC_CTRL);
84 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp | LPC32XX_RTC_CTRL_CNTR_DIS);
85 rtc_writel(rtc, LPC32XX_RTC_UCOUNT, secs);
86 rtc_writel(rtc, LPC32XX_RTC_DCOUNT, 0xFFFFFFFF - secs);
87 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp &= ~LPC32XX_RTC_CTRL_CNTR_DIS);
88
89 spin_unlock_irq(&rtc->lock);
90
91 return 0;
92}
93
94static int lpc32xx_rtc_read_alarm(struct device *dev,
95 struct rtc_wkalrm *wkalrm)
96{
97 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
98
99 rtc_time_to_tm(rtc_readl(rtc, LPC32XX_RTC_MATCH0), &wkalrm->time);
100 wkalrm->enabled = rtc->alarm_enabled;
101 wkalrm->pending = !!(rtc_readl(rtc, LPC32XX_RTC_INTSTAT) &
102 LPC32XX_RTC_INTSTAT_MATCH0);
103
104 return rtc_valid_tm(&wkalrm->time);
105}
106
107static int lpc32xx_rtc_set_alarm(struct device *dev,
108 struct rtc_wkalrm *wkalrm)
109{
110 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
111 unsigned long alarmsecs;
112 u32 tmp;
113 int ret;
114
115 ret = rtc_tm_to_time(&wkalrm->time, &alarmsecs);
116 if (ret < 0) {
117 dev_warn(dev, "Failed to convert time: %d\n", ret);
118 return ret;
119 }
120
121 spin_lock_irq(&rtc->lock);
122
123 /* Disable alarm during update */
124 tmp = rtc_readl(rtc, LPC32XX_RTC_CTRL);
125 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp & ~LPC32XX_RTC_CTRL_MATCH0);
126
127 rtc_writel(rtc, LPC32XX_RTC_MATCH0, alarmsecs);
128
129 rtc->alarm_enabled = wkalrm->enabled;
130 if (wkalrm->enabled) {
131 rtc_writel(rtc, LPC32XX_RTC_INTSTAT,
132 LPC32XX_RTC_INTSTAT_MATCH0);
133 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp |
134 LPC32XX_RTC_CTRL_MATCH0);
135 }
136
137 spin_unlock_irq(&rtc->lock);
138
139 return 0;
140}
141
142static int lpc32xx_rtc_alarm_irq_enable(struct device *dev,
143 unsigned int enabled)
144{
145 struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
146 u32 tmp;
147
148 spin_lock_irq(&rtc->lock);
149 tmp = rtc_readl(rtc, LPC32XX_RTC_CTRL);
150
151 if (enabled) {
152 rtc->alarm_enabled = 1;
153 tmp |= LPC32XX_RTC_CTRL_MATCH0;
154 } else {
155 rtc->alarm_enabled = 0;
156 tmp &= ~LPC32XX_RTC_CTRL_MATCH0;
157 }
158
159 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp);
160 spin_unlock_irq(&rtc->lock);
161
162 return 0;
163}
164
165static irqreturn_t lpc32xx_rtc_alarm_interrupt(int irq, void *dev)
166{
167 struct lpc32xx_rtc *rtc = dev;
168
169 spin_lock(&rtc->lock);
170
171 /* Disable alarm interrupt */
172 rtc_writel(rtc, LPC32XX_RTC_CTRL,
173 rtc_readl(rtc, LPC32XX_RTC_CTRL) &
174 ~LPC32XX_RTC_CTRL_MATCH0);
175 rtc->alarm_enabled = 0;
176
177 /*
178 * Write a large value to the match value so the RTC won't
179 * keep firing the match status
180 */
181 rtc_writel(rtc, LPC32XX_RTC_MATCH0, 0xFFFFFFFF);
182 rtc_writel(rtc, LPC32XX_RTC_INTSTAT, LPC32XX_RTC_INTSTAT_MATCH0);
183
184 spin_unlock(&rtc->lock);
185
186 rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF);
187
188 return IRQ_HANDLED;
189}
190
191static const struct rtc_class_ops lpc32xx_rtc_ops = {
192 .read_time = lpc32xx_rtc_read_time,
193 .set_mmss = lpc32xx_rtc_set_mmss,
194 .read_alarm = lpc32xx_rtc_read_alarm,
195 .set_alarm = lpc32xx_rtc_set_alarm,
196 .alarm_irq_enable = lpc32xx_rtc_alarm_irq_enable,
197};
198
199static int __devinit lpc32xx_rtc_probe(struct platform_device *pdev)
200{
201 struct resource *res;
202 struct lpc32xx_rtc *rtc;
203 resource_size_t size;
204 int rtcirq;
205 u32 tmp;
206
207 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
208 if (!res) {
209 dev_err(&pdev->dev, "Can't get memory resource\n");
210 return -ENOENT;
211 }
212
213 rtcirq = platform_get_irq(pdev, 0);
214 if (rtcirq < 0 || rtcirq >= NR_IRQS) {
215 dev_warn(&pdev->dev, "Can't get interrupt resource\n");
216 rtcirq = -1;
217 }
218
219 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
220 if (unlikely(!rtc)) {
221 dev_err(&pdev->dev, "Can't allocate memory\n");
222 return -ENOMEM;
223 }
224 rtc->irq = rtcirq;
225
226 size = resource_size(res);
227
228 if (!devm_request_mem_region(&pdev->dev, res->start, size,
229 pdev->name)) {
230 dev_err(&pdev->dev, "RTC registers are not free\n");
231 return -EBUSY;
232 }
233
234 rtc->rtc_base = devm_ioremap(&pdev->dev, res->start, size);
235 if (!rtc->rtc_base) {
236 dev_err(&pdev->dev, "Can't map memory\n");
237 return -ENOMEM;
238 }
239
240 spin_lock_init(&rtc->lock);
241
242 /*
243 * The RTC is on a seperate power domain and can keep it's state
244 * across a chip power cycle. If the RTC has never been previously
245 * setup, then set it up now for the first time.
246 */
247 tmp = rtc_readl(rtc, LPC32XX_RTC_CTRL);
248 if (rtc_readl(rtc, LPC32XX_RTC_KEY) != LPC32XX_RTC_KEY_ONSW_LOADVAL) {
249 tmp &= ~(LPC32XX_RTC_CTRL_SW_RESET |
250 LPC32XX_RTC_CTRL_CNTR_DIS |
251 LPC32XX_RTC_CTRL_MATCH0 |
252 LPC32XX_RTC_CTRL_MATCH1 |
253 LPC32XX_RTC_CTRL_ONSW_MATCH0 |
254 LPC32XX_RTC_CTRL_ONSW_MATCH1 |
255 LPC32XX_RTC_CTRL_ONSW_FORCE_HI);
256 rtc_writel(rtc, LPC32XX_RTC_CTRL, tmp);
257
258 /* Clear latched interrupt states */
259 rtc_writel(rtc, LPC32XX_RTC_MATCH0, 0xFFFFFFFF);
260 rtc_writel(rtc, LPC32XX_RTC_INTSTAT,
261 LPC32XX_RTC_INTSTAT_MATCH0 |
262 LPC32XX_RTC_INTSTAT_MATCH1 |
263 LPC32XX_RTC_INTSTAT_ONSW);
264
265 /* Write key value to RTC so it won't reload on reset */
266 rtc_writel(rtc, LPC32XX_RTC_KEY,
267 LPC32XX_RTC_KEY_ONSW_LOADVAL);
268 } else {
269 rtc_writel(rtc, LPC32XX_RTC_CTRL,
270 tmp & ~LPC32XX_RTC_CTRL_MATCH0);
271 }
272
273 platform_set_drvdata(pdev, rtc);
274
275 rtc->rtc = rtc_device_register(RTC_NAME, &pdev->dev, &lpc32xx_rtc_ops,
276 THIS_MODULE);
277 if (IS_ERR(rtc->rtc)) {
278 dev_err(&pdev->dev, "Can't get RTC\n");
279 platform_set_drvdata(pdev, NULL);
280 return PTR_ERR(rtc->rtc);
281 }
282
283 /*
284 * IRQ is enabled after device registration in case alarm IRQ
285 * is pending upon suspend exit.
286 */
287 if (rtc->irq >= 0) {
288 if (devm_request_irq(&pdev->dev, rtc->irq,
289 lpc32xx_rtc_alarm_interrupt,
290 IRQF_DISABLED, pdev->name, rtc) < 0) {
291 dev_warn(&pdev->dev, "Can't request interrupt.\n");
292 rtc->irq = -1;
293 } else {
294 device_init_wakeup(&pdev->dev, 1);
295 }
296 }
297
298 return 0;
299}
300
301static int __devexit lpc32xx_rtc_remove(struct platform_device *pdev)
302{
303 struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev);
304
305 if (rtc->irq >= 0)
306 device_init_wakeup(&pdev->dev, 0);
307
308 platform_set_drvdata(pdev, NULL);
309 rtc_device_unregister(rtc->rtc);
310
311 return 0;
312}
313
314#ifdef CONFIG_PM
315static int lpc32xx_rtc_suspend(struct device *dev)
316{
317 struct platform_device *pdev = to_platform_device(dev);
318 struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev);
319
320 if (rtc->irq >= 0) {
321 if (device_may_wakeup(&pdev->dev))
322 enable_irq_wake(rtc->irq);
323 else
324 disable_irq_wake(rtc->irq);
325 }
326
327 return 0;
328}
329
330static int lpc32xx_rtc_resume(struct device *dev)
331{
332 struct platform_device *pdev = to_platform_device(dev);
333 struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev);
334
335 if (rtc->irq >= 0 && device_may_wakeup(&pdev->dev))
336 disable_irq_wake(rtc->irq);
337
338 return 0;
339}
340
341/* Unconditionally disable the alarm */
342static int lpc32xx_rtc_freeze(struct device *dev)
343{
344 struct platform_device *pdev = to_platform_device(dev);
345 struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev);
346
347 spin_lock_irq(&rtc->lock);
348
349 rtc_writel(rtc, LPC32XX_RTC_CTRL,
350 rtc_readl(rtc, LPC32XX_RTC_CTRL) &
351 ~LPC32XX_RTC_CTRL_MATCH0);
352
353 spin_unlock_irq(&rtc->lock);
354
355 return 0;
356}
357
358static int lpc32xx_rtc_thaw(struct device *dev)
359{
360 struct platform_device *pdev = to_platform_device(dev);
361 struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev);
362
363 if (rtc->alarm_enabled) {
364 spin_lock_irq(&rtc->lock);
365
366 rtc_writel(rtc, LPC32XX_RTC_CTRL,
367 rtc_readl(rtc, LPC32XX_RTC_CTRL) |
368 LPC32XX_RTC_CTRL_MATCH0);
369
370 spin_unlock_irq(&rtc->lock);
371 }
372
373 return 0;
374}
375
376static const struct dev_pm_ops lpc32xx_rtc_pm_ops = {
377 .suspend = lpc32xx_rtc_suspend,
378 .resume = lpc32xx_rtc_resume,
379 .freeze = lpc32xx_rtc_freeze,
380 .thaw = lpc32xx_rtc_thaw,
381 .restore = lpc32xx_rtc_resume
382};
383
384#define LPC32XX_RTC_PM_OPS (&lpc32xx_rtc_pm_ops)
385#else
386#define LPC32XX_RTC_PM_OPS NULL
387#endif
388
389static struct platform_driver lpc32xx_rtc_driver = {
390 .probe = lpc32xx_rtc_probe,
391 .remove = __devexit_p(lpc32xx_rtc_remove),
392 .driver = {
393 .name = RTC_NAME,
394 .owner = THIS_MODULE,
395 .pm = LPC32XX_RTC_PM_OPS
396 },
397};
398
399static int __init lpc32xx_rtc_init(void)
400{
401 return platform_driver_register(&lpc32xx_rtc_driver);
402}
403module_init(lpc32xx_rtc_init);
404
405static void __exit lpc32xx_rtc_exit(void)
406{
407 platform_driver_unregister(&lpc32xx_rtc_driver);
408}
409module_exit(lpc32xx_rtc_exit);
410
411MODULE_AUTHOR("Kevin Wells <wellsk40@gmail.com");
412MODULE_DESCRIPTION("RTC driver for the LPC32xx SoC");
413MODULE_LICENSE("GPL");
414MODULE_ALIAS("platform:rtc-lpc32xx");
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 64d9727b7229..73377b0d65da 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -34,7 +34,8 @@
34 * Board-specific wiring options include using split power mode with 34 * Board-specific wiring options include using split power mode with
35 * RTC_OFF_NOFF used as the reset signal (so the RTC won't be reset), 35 * RTC_OFF_NOFF used as the reset signal (so the RTC won't be reset),
36 * and wiring RTC_WAKE_INT (so the RTC alarm can wake the system from 36 * and wiring RTC_WAKE_INT (so the RTC alarm can wake the system from
37 * low power modes). See the BOARD-SPECIFIC CUSTOMIZATION comment. 37 * low power modes) for OMAP1 boards (OMAP-L138 has this built into
38 * the SoC). See the BOARD-SPECIFIC CUSTOMIZATION comment.
38 */ 39 */
39 40
40#define OMAP_RTC_BASE 0xfffb4800 41#define OMAP_RTC_BASE 0xfffb4800
@@ -401,16 +402,17 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
401 402
402 /* BOARD-SPECIFIC CUSTOMIZATION CAN GO HERE: 403 /* BOARD-SPECIFIC CUSTOMIZATION CAN GO HERE:
403 * 404 *
404 * - Boards wired so that RTC_WAKE_INT does something, and muxed 405 * - Device wake-up capability setting should come through chip
405 * right (W13_1610_RTC_WAKE_INT is the default after chip reset), 406 * init logic. OMAP1 boards should initialize the "wakeup capable"
406 * should initialize the device wakeup flag appropriately. 407 * flag in the platform device if the board is wired right for
408 * being woken up by RTC alarm. For OMAP-L138, this capability
409 * is built into the SoC by the "Deep Sleep" capability.
407 * 410 *
408 * - Boards wired so RTC_ON_nOFF is used as the reset signal, 411 * - Boards wired so RTC_ON_nOFF is used as the reset signal,
409 * rather than nPWRON_RESET, should forcibly enable split 412 * rather than nPWRON_RESET, should forcibly enable split
410 * power mode. (Some chip errata report that RTC_CTRL_SPLIT 413 * power mode. (Some chip errata report that RTC_CTRL_SPLIT
411 * is write-only, and always reads as zero...) 414 * is write-only, and always reads as zero...)
412 */ 415 */
413 device_init_wakeup(&pdev->dev, 0);
414 416
415 if (new_ctrl & (u8) OMAP_RTC_CTRL_SPLIT) 417 if (new_ctrl & (u8) OMAP_RTC_CTRL_SPLIT)
416 pr_info("%s: split power mode\n", pdev->name); 418 pr_info("%s: split power mode\n", pdev->name);
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index f57a87f4ae96..cf953ecbfca9 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -100,7 +100,7 @@ static int s3c_rtc_setpie(struct device *dev, int enabled)
100 spin_lock_irq(&s3c_rtc_pie_lock); 100 spin_lock_irq(&s3c_rtc_pie_lock);
101 101
102 if (s3c_rtc_cpu_type == TYPE_S3C64XX) { 102 if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
103 tmp = readb(s3c_rtc_base + S3C2410_RTCCON); 103 tmp = readw(s3c_rtc_base + S3C2410_RTCCON);
104 tmp &= ~S3C64XX_RTCCON_TICEN; 104 tmp &= ~S3C64XX_RTCCON_TICEN;
105 105
106 if (enabled) 106 if (enabled)
@@ -171,8 +171,8 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
171 goto retry_get_time; 171 goto retry_get_time;
172 } 172 }
173 173
174 pr_debug("read time %02x.%02x.%02x %02x/%02x/%02x\n", 174 pr_debug("read time %04d.%02d.%02d %02d:%02d:%02d\n",
175 rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, 175 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
176 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 176 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
177 177
178 rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); 178 rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec);
@@ -185,7 +185,7 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
185 rtc_tm->tm_year += 100; 185 rtc_tm->tm_year += 100;
186 rtc_tm->tm_mon -= 1; 186 rtc_tm->tm_mon -= 1;
187 187
188 return 0; 188 return rtc_valid_tm(rtc_tm);
189} 189}
190 190
191static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm) 191static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
@@ -193,8 +193,8 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
193 void __iomem *base = s3c_rtc_base; 193 void __iomem *base = s3c_rtc_base;
194 int year = tm->tm_year - 100; 194 int year = tm->tm_year - 100;
195 195
196 pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n", 196 pr_debug("set time %04d.%02d.%02d %02d:%02d:%02d\n",
197 tm->tm_year, tm->tm_mon, tm->tm_mday, 197 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
198 tm->tm_hour, tm->tm_min, tm->tm_sec); 198 tm->tm_hour, tm->tm_min, tm->tm_sec);
199 199
200 /* we get around y2k by simply not supporting it */ 200 /* we get around y2k by simply not supporting it */
@@ -231,9 +231,9 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
231 231
232 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; 232 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0;
233 233
234 pr_debug("read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n", 234 pr_debug("read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n",
235 alm_en, 235 alm_en,
236 alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, 236 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
237 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); 237 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
238 238
239 239
@@ -242,34 +242,34 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
242 if (alm_en & S3C2410_RTCALM_SECEN) 242 if (alm_en & S3C2410_RTCALM_SECEN)
243 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); 243 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec);
244 else 244 else
245 alm_tm->tm_sec = 0xff; 245 alm_tm->tm_sec = -1;
246 246
247 if (alm_en & S3C2410_RTCALM_MINEN) 247 if (alm_en & S3C2410_RTCALM_MINEN)
248 alm_tm->tm_min = bcd2bin(alm_tm->tm_min); 248 alm_tm->tm_min = bcd2bin(alm_tm->tm_min);
249 else 249 else
250 alm_tm->tm_min = 0xff; 250 alm_tm->tm_min = -1;
251 251
252 if (alm_en & S3C2410_RTCALM_HOUREN) 252 if (alm_en & S3C2410_RTCALM_HOUREN)
253 alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour); 253 alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour);
254 else 254 else
255 alm_tm->tm_hour = 0xff; 255 alm_tm->tm_hour = -1;
256 256
257 if (alm_en & S3C2410_RTCALM_DAYEN) 257 if (alm_en & S3C2410_RTCALM_DAYEN)
258 alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday); 258 alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday);
259 else 259 else
260 alm_tm->tm_mday = 0xff; 260 alm_tm->tm_mday = -1;
261 261
262 if (alm_en & S3C2410_RTCALM_MONEN) { 262 if (alm_en & S3C2410_RTCALM_MONEN) {
263 alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon); 263 alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon);
264 alm_tm->tm_mon -= 1; 264 alm_tm->tm_mon -= 1;
265 } else { 265 } else {
266 alm_tm->tm_mon = 0xff; 266 alm_tm->tm_mon = -1;
267 } 267 }
268 268
269 if (alm_en & S3C2410_RTCALM_YEAREN) 269 if (alm_en & S3C2410_RTCALM_YEAREN)
270 alm_tm->tm_year = bcd2bin(alm_tm->tm_year); 270 alm_tm->tm_year = bcd2bin(alm_tm->tm_year);
271 else 271 else
272 alm_tm->tm_year = 0xffff; 272 alm_tm->tm_year = -1;
273 273
274 return 0; 274 return 0;
275} 275}
@@ -280,10 +280,10 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
280 void __iomem *base = s3c_rtc_base; 280 void __iomem *base = s3c_rtc_base;
281 unsigned int alrm_en; 281 unsigned int alrm_en;
282 282
283 pr_debug("s3c_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02x\n", 283 pr_debug("s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
284 alrm->enabled, 284 alrm->enabled,
285 tm->tm_mday & 0xff, tm->tm_mon & 0xff, tm->tm_year & 0xff, 285 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
286 tm->tm_hour & 0xff, tm->tm_min & 0xff, tm->tm_sec); 286 tm->tm_hour, tm->tm_min, tm->tm_sec);
287 287
288 288
289 alrm_en = readb(base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; 289 alrm_en = readb(base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
@@ -318,7 +318,7 @@ static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
318 unsigned int ticnt; 318 unsigned int ticnt;
319 319
320 if (s3c_rtc_cpu_type == TYPE_S3C64XX) { 320 if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
321 ticnt = readb(s3c_rtc_base + S3C2410_RTCCON); 321 ticnt = readw(s3c_rtc_base + S3C2410_RTCCON);
322 ticnt &= S3C64XX_RTCCON_TICEN; 322 ticnt &= S3C64XX_RTCCON_TICEN;
323 } else { 323 } else {
324 ticnt = readb(s3c_rtc_base + S3C2410_TICNT); 324 ticnt = readb(s3c_rtc_base + S3C2410_TICNT);
@@ -379,7 +379,8 @@ static const struct rtc_class_ops s3c_rtcops = {
379 .set_alarm = s3c_rtc_setalarm, 379 .set_alarm = s3c_rtc_setalarm,
380 .irq_set_freq = s3c_rtc_setfreq, 380 .irq_set_freq = s3c_rtc_setfreq,
381 .irq_set_state = s3c_rtc_setpie, 381 .irq_set_state = s3c_rtc_setpie,
382 .proc = s3c_rtc_proc, 382 .proc = s3c_rtc_proc,
383 .alarm_irq_enable = s3c_rtc_setaie,
383}; 384};
384 385
385static void s3c_rtc_enable(struct platform_device *pdev, int en) 386static void s3c_rtc_enable(struct platform_device *pdev, int en)
@@ -391,11 +392,11 @@ static void s3c_rtc_enable(struct platform_device *pdev, int en)
391 return; 392 return;
392 393
393 if (!en) { 394 if (!en) {
394 tmp = readb(base + S3C2410_RTCCON); 395 tmp = readw(base + S3C2410_RTCCON);
395 if (s3c_rtc_cpu_type == TYPE_S3C64XX) 396 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
396 tmp &= ~S3C64XX_RTCCON_TICEN; 397 tmp &= ~S3C64XX_RTCCON_TICEN;
397 tmp &= ~S3C2410_RTCCON_RTCEN; 398 tmp &= ~S3C2410_RTCCON_RTCEN;
398 writeb(tmp, base + S3C2410_RTCCON); 399 writew(tmp, base + S3C2410_RTCCON);
399 400
400 if (s3c_rtc_cpu_type == TYPE_S3C2410) { 401 if (s3c_rtc_cpu_type == TYPE_S3C2410) {
401 tmp = readb(base + S3C2410_TICNT); 402 tmp = readb(base + S3C2410_TICNT);
@@ -405,25 +406,28 @@ static void s3c_rtc_enable(struct platform_device *pdev, int en)
405 } else { 406 } else {
406 /* re-enable the device, and check it is ok */ 407 /* re-enable the device, and check it is ok */
407 408
408 if ((readb(base+S3C2410_RTCCON) & S3C2410_RTCCON_RTCEN) == 0){ 409 if ((readw(base+S3C2410_RTCCON) & S3C2410_RTCCON_RTCEN) == 0) {
409 dev_info(&pdev->dev, "rtc disabled, re-enabling\n"); 410 dev_info(&pdev->dev, "rtc disabled, re-enabling\n");
410 411
411 tmp = readb(base + S3C2410_RTCCON); 412 tmp = readw(base + S3C2410_RTCCON);
412 writeb(tmp|S3C2410_RTCCON_RTCEN, base+S3C2410_RTCCON); 413 writew(tmp | S3C2410_RTCCON_RTCEN,
414 base + S3C2410_RTCCON);
413 } 415 }
414 416
415 if ((readb(base + S3C2410_RTCCON) & S3C2410_RTCCON_CNTSEL)){ 417 if ((readw(base + S3C2410_RTCCON) & S3C2410_RTCCON_CNTSEL)) {
416 dev_info(&pdev->dev, "removing RTCCON_CNTSEL\n"); 418 dev_info(&pdev->dev, "removing RTCCON_CNTSEL\n");
417 419
418 tmp = readb(base + S3C2410_RTCCON); 420 tmp = readw(base + S3C2410_RTCCON);
419 writeb(tmp& ~S3C2410_RTCCON_CNTSEL, base+S3C2410_RTCCON); 421 writew(tmp & ~S3C2410_RTCCON_CNTSEL,
422 base + S3C2410_RTCCON);
420 } 423 }
421 424
422 if ((readb(base + S3C2410_RTCCON) & S3C2410_RTCCON_CLKRST)){ 425 if ((readw(base + S3C2410_RTCCON) & S3C2410_RTCCON_CLKRST)) {
423 dev_info(&pdev->dev, "removing RTCCON_CLKRST\n"); 426 dev_info(&pdev->dev, "removing RTCCON_CLKRST\n");
424 427
425 tmp = readb(base + S3C2410_RTCCON); 428 tmp = readw(base + S3C2410_RTCCON);
426 writeb(tmp & ~S3C2410_RTCCON_CLKRST, base+S3C2410_RTCCON); 429 writew(tmp & ~S3C2410_RTCCON_CLKRST,
430 base + S3C2410_RTCCON);
427 } 431 }
428 } 432 }
429} 433}
@@ -452,8 +456,8 @@ static int __devexit s3c_rtc_remove(struct platform_device *dev)
452static int __devinit s3c_rtc_probe(struct platform_device *pdev) 456static int __devinit s3c_rtc_probe(struct platform_device *pdev)
453{ 457{
454 struct rtc_device *rtc; 458 struct rtc_device *rtc;
459 struct rtc_time rtc_tm;
455 struct resource *res; 460 struct resource *res;
456 unsigned int tmp, i;
457 int ret; 461 int ret;
458 462
459 pr_debug("%s: probe=%p\n", __func__, pdev); 463 pr_debug("%s: probe=%p\n", __func__, pdev);
@@ -514,8 +518,8 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
514 518
515 s3c_rtc_enable(pdev, 1); 519 s3c_rtc_enable(pdev, 1);
516 520
517 pr_debug("s3c2410_rtc: RTCCON=%02x\n", 521 pr_debug("s3c2410_rtc: RTCCON=%02x\n",
518 readb(s3c_rtc_base + S3C2410_RTCCON)); 522 readw(s3c_rtc_base + S3C2410_RTCCON));
519 523
520 device_init_wakeup(&pdev->dev, 1); 524 device_init_wakeup(&pdev->dev, 1);
521 525
@@ -534,11 +538,19 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
534 538
535 /* Check RTC Time */ 539 /* Check RTC Time */
536 540
537 for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) { 541 s3c_rtc_gettime(NULL, &rtc_tm);
538 tmp = readb(s3c_rtc_base + i); 542
543 if (rtc_valid_tm(&rtc_tm)) {
544 rtc_tm.tm_year = 100;
545 rtc_tm.tm_mon = 0;
546 rtc_tm.tm_mday = 1;
547 rtc_tm.tm_hour = 0;
548 rtc_tm.tm_min = 0;
549 rtc_tm.tm_sec = 0;
550
551 s3c_rtc_settime(NULL, &rtc_tm);
539 552
540 if ((tmp & 0xf) > 0x9 || ((tmp >> 4) & 0xf) > 0x9) 553 dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n");
541 writeb(0, s3c_rtc_base + i);
542 } 554 }
543 555
544 if (s3c_rtc_cpu_type == TYPE_S3C64XX) 556 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
@@ -578,7 +590,7 @@ static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
578 /* save TICNT for anyone using periodic interrupts */ 590 /* save TICNT for anyone using periodic interrupts */
579 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT); 591 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
580 if (s3c_rtc_cpu_type == TYPE_S3C64XX) { 592 if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
581 ticnt_en_save = readb(s3c_rtc_base + S3C2410_RTCCON); 593 ticnt_en_save = readw(s3c_rtc_base + S3C2410_RTCCON);
582 ticnt_en_save &= S3C64XX_RTCCON_TICEN; 594 ticnt_en_save &= S3C64XX_RTCCON_TICEN;
583 } 595 }
584 s3c_rtc_enable(pdev, 0); 596 s3c_rtc_enable(pdev, 0);
@@ -596,8 +608,8 @@ static int s3c_rtc_resume(struct platform_device *pdev)
596 s3c_rtc_enable(pdev, 1); 608 s3c_rtc_enable(pdev, 1);
597 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT); 609 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
598 if (s3c_rtc_cpu_type == TYPE_S3C64XX && ticnt_en_save) { 610 if (s3c_rtc_cpu_type == TYPE_S3C64XX && ticnt_en_save) {
599 tmp = readb(s3c_rtc_base + S3C2410_RTCCON); 611 tmp = readw(s3c_rtc_base + S3C2410_RTCCON);
600 writeb(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON); 612 writew(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON);
601 } 613 }
602 614
603 if (device_may_wakeup(&pdev->dev)) 615 if (device_may_wakeup(&pdev->dev))
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 42e303ff862a..0e6aa3d96a42 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -697,9 +697,9 @@ fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
697 struct inode *inode = file->f_path.dentry->d_inode; 697 struct inode *inode = file->f_path.dentry->d_inode;
698 int fbidx = iminor(inode); 698 int fbidx = iminor(inode);
699 struct fb_info *info = registered_fb[fbidx]; 699 struct fb_info *info = registered_fb[fbidx];
700 u32 *buffer, *dst; 700 u8 *buffer, *dst;
701 u32 __iomem *src; 701 u8 __iomem *src;
702 int c, i, cnt = 0, err = 0; 702 int c, cnt = 0, err = 0;
703 unsigned long total_size; 703 unsigned long total_size;
704 704
705 if (!info || ! info->screen_base) 705 if (!info || ! info->screen_base)
@@ -730,7 +730,7 @@ fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
730 if (!buffer) 730 if (!buffer)
731 return -ENOMEM; 731 return -ENOMEM;
732 732
733 src = (u32 __iomem *) (info->screen_base + p); 733 src = (u8 __iomem *) (info->screen_base + p);
734 734
735 if (info->fbops->fb_sync) 735 if (info->fbops->fb_sync)
736 info->fbops->fb_sync(info); 736 info->fbops->fb_sync(info);
@@ -738,17 +738,9 @@ fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
738 while (count) { 738 while (count) {
739 c = (count > PAGE_SIZE) ? PAGE_SIZE : count; 739 c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
740 dst = buffer; 740 dst = buffer;
741 for (i = c >> 2; i--; ) 741 fb_memcpy_fromfb(dst, src, c);
742 *dst++ = fb_readl(src++); 742 dst += c;
743 if (c & 3) { 743 src += c;
744 u8 *dst8 = (u8 *) dst;
745 u8 __iomem *src8 = (u8 __iomem *) src;
746
747 for (i = c & 3; i--;)
748 *dst8++ = fb_readb(src8++);
749
750 src = (u32 __iomem *) src8;
751 }
752 744
753 if (copy_to_user(buf, buffer, c)) { 745 if (copy_to_user(buf, buffer, c)) {
754 err = -EFAULT; 746 err = -EFAULT;
@@ -772,9 +764,9 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
772 struct inode *inode = file->f_path.dentry->d_inode; 764 struct inode *inode = file->f_path.dentry->d_inode;
773 int fbidx = iminor(inode); 765 int fbidx = iminor(inode);
774 struct fb_info *info = registered_fb[fbidx]; 766 struct fb_info *info = registered_fb[fbidx];
775 u32 *buffer, *src; 767 u8 *buffer, *src;
776 u32 __iomem *dst; 768 u8 __iomem *dst;
777 int c, i, cnt = 0, err = 0; 769 int c, cnt = 0, err = 0;
778 unsigned long total_size; 770 unsigned long total_size;
779 771
780 if (!info || !info->screen_base) 772 if (!info || !info->screen_base)
@@ -811,7 +803,7 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
811 if (!buffer) 803 if (!buffer)
812 return -ENOMEM; 804 return -ENOMEM;
813 805
814 dst = (u32 __iomem *) (info->screen_base + p); 806 dst = (u8 __iomem *) (info->screen_base + p);
815 807
816 if (info->fbops->fb_sync) 808 if (info->fbops->fb_sync)
817 info->fbops->fb_sync(info); 809 info->fbops->fb_sync(info);
@@ -825,19 +817,9 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
825 break; 817 break;
826 } 818 }
827 819
828 for (i = c >> 2; i--; ) 820 fb_memcpy_tofb(dst, src, c);
829 fb_writel(*src++, dst++); 821 dst += c;
830 822 src += c;
831 if (c & 3) {
832 u8 *src8 = (u8 *) src;
833 u8 __iomem *dst8 = (u8 __iomem *) dst;
834
835 for (i = c & 3; i--; )
836 fb_writeb(*src8++, dst8++);
837
838 dst = (u32 __iomem *) dst8;
839 }
840
841 *ppos += c; 823 *ppos += c;
842 buf += c; 824 buf += c;
843 cnt += c; 825 cnt += c;
@@ -877,13 +859,13 @@ fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
877 859
878 if ((err = info->fbops->fb_pan_display(var, info))) 860 if ((err = info->fbops->fb_pan_display(var, info)))
879 return err; 861 return err;
880 info->var.xoffset = var->xoffset; 862 info->var.xoffset = var->xoffset;
881 info->var.yoffset = var->yoffset; 863 info->var.yoffset = var->yoffset;
882 if (var->vmode & FB_VMODE_YWRAP) 864 if (var->vmode & FB_VMODE_YWRAP)
883 info->var.vmode |= FB_VMODE_YWRAP; 865 info->var.vmode |= FB_VMODE_YWRAP;
884 else 866 else
885 info->var.vmode &= ~FB_VMODE_YWRAP; 867 info->var.vmode &= ~FB_VMODE_YWRAP;
886 return 0; 868 return 0;
887} 869}
888 870
889static int fb_check_caps(struct fb_info *info, struct fb_var_screeninfo *var, 871static int fb_check_caps(struct fb_info *info, struct fb_var_screeninfo *var,
diff --git a/drivers/video/gbefb.c b/drivers/video/gbefb.c
index ca3355e430bf..933899dca33a 100644
--- a/drivers/video/gbefb.c
+++ b/drivers/video/gbefb.c
@@ -1143,8 +1143,10 @@ static int __devinit gbefb_probe(struct platform_device *p_dev)
1143 return -ENOMEM; 1143 return -ENOMEM;
1144 1144
1145#ifndef MODULE 1145#ifndef MODULE
1146 if (fb_get_options("gbefb", &options)) 1146 if (fb_get_options("gbefb", &options)) {
1147 return -ENODEV; 1147 ret = -ENODEV;
1148 goto out_release_framebuffer;
1149 }
1148 gbefb_setup(options); 1150 gbefb_setup(options);
1149#endif 1151#endif
1150 1152
diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
index f9fa0fd00292..1717623aabc0 100644
--- a/drivers/video/matrox/matroxfb_DAC1064.c
+++ b/drivers/video/matrox/matroxfb_DAC1064.c
@@ -869,12 +869,9 @@ static int MGAG100_preinit(struct matrox_fb_info *minfo)
869 minfo->capable.plnwt = minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG100 869 minfo->capable.plnwt = minfo->devflags.accelerator == FB_ACCEL_MATROX_MGAG100
870 ? minfo->devflags.sgram : 1; 870 ? minfo->devflags.sgram : 1;
871 871
872#ifdef CONFIG_FB_MATROX_G
873 if (minfo->devflags.g450dac) { 872 if (minfo->devflags.g450dac) {
874 minfo->outputs[0].output = &g450out; 873 minfo->outputs[0].output = &g450out;
875 } else 874 } else {
876#endif
877 {
878 minfo->outputs[0].output = &m1064; 875 minfo->outputs[0].output = &m1064;
879 } 876 }
880 minfo->outputs[0].src = minfo->outputs[0].default_src; 877 minfo->outputs[0].src = minfo->outputs[0].default_src;
diff --git a/drivers/video/matrox/matroxfb_maven.c b/drivers/video/matrox/matroxfb_maven.c
index 1e3e8f19783e..31b8f67477b7 100644
--- a/drivers/video/matrox/matroxfb_maven.c
+++ b/drivers/video/matrox/matroxfb_maven.c
@@ -280,7 +280,7 @@ static int matroxfb_PLL_mavenclock(const struct matrox_pll_features2* pll,
280 return fxtal * (*feed) / (*in) * ctl->den; 280 return fxtal * (*feed) / (*in) * ctl->den;
281} 281}
282 282
283static unsigned int matroxfb_mavenclock(const struct matrox_pll_ctl* ctl, 283static int matroxfb_mavenclock(const struct matrox_pll_ctl *ctl,
284 unsigned int htotal, unsigned int vtotal, 284 unsigned int htotal, unsigned int vtotal,
285 unsigned int* in, unsigned int* feed, unsigned int* post, 285 unsigned int* in, unsigned int* feed, unsigned int* post,
286 unsigned int* htotal2) { 286 unsigned int* htotal2) {
diff --git a/drivers/video/omap/blizzard.c b/drivers/video/omap/blizzard.c
index 2ffb34af4c59..87785c215a52 100644
--- a/drivers/video/omap/blizzard.c
+++ b/drivers/video/omap/blizzard.c
@@ -1590,7 +1590,7 @@ static int blizzard_init(struct omapfb_device *fbdev, int ext_mode,
1590 blizzard.auto_update_window.width = fbdev->panel->x_res; 1590 blizzard.auto_update_window.width = fbdev->panel->x_res;
1591 blizzard.auto_update_window.height = fbdev->panel->y_res; 1591 blizzard.auto_update_window.height = fbdev->panel->y_res;
1592 blizzard.auto_update_window.out_x = 0; 1592 blizzard.auto_update_window.out_x = 0;
1593 blizzard.auto_update_window.out_x = 0; 1593 blizzard.auto_update_window.out_y = 0;
1594 blizzard.auto_update_window.out_width = fbdev->panel->x_res; 1594 blizzard.auto_update_window.out_width = fbdev->panel->x_res;
1595 blizzard.auto_update_window.out_height = fbdev->panel->y_res; 1595 blizzard.auto_update_window.out_height = fbdev->panel->y_res;
1596 blizzard.auto_update_window.format = 0; 1596 blizzard.auto_update_window.format = 0;
diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c
index ed371c868b3a..b16e6138fdd4 100644
--- a/drivers/video/savage/savagefb-i2c.c
+++ b/drivers/video/savage/savagefb-i2c.c
@@ -181,6 +181,15 @@ void savagefb_create_i2c_busses(struct fb_info *info)
181 par->chan.algo.getscl = prosavage_gpio_getscl; 181 par->chan.algo.getscl = prosavage_gpio_getscl;
182 break; 182 break;
183 case FB_ACCEL_SAVAGE4: 183 case FB_ACCEL_SAVAGE4:
184 par->chan.reg = CR_SERIAL1;
185 if (par->pcidev->revision > 1 && !(VGArCR(0xa6, par) & 0x40))
186 par->chan.reg = CR_SERIAL2;
187 par->chan.ioaddr = par->mmio.vbase;
188 par->chan.algo.setsda = prosavage_gpio_setsda;
189 par->chan.algo.setscl = prosavage_gpio_setscl;
190 par->chan.algo.getsda = prosavage_gpio_getsda;
191 par->chan.algo.getscl = prosavage_gpio_getscl;
192 break;
184 case FB_ACCEL_SAVAGE2000: 193 case FB_ACCEL_SAVAGE2000:
185 par->chan.reg = 0xff20; 194 par->chan.reg = 0xff20;
186 par->chan.ioaddr = par->mmio.vbase; 195 par->chan.ioaddr = par->mmio.vbase;
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 2839e281cd65..b7b5014ff714 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -517,10 +517,10 @@ static W1_MASTER_ATTR_RO(max_slave_count, S_IRUGO);
517static W1_MASTER_ATTR_RO(attempts, S_IRUGO); 517static W1_MASTER_ATTR_RO(attempts, S_IRUGO);
518static W1_MASTER_ATTR_RO(timeout, S_IRUGO); 518static W1_MASTER_ATTR_RO(timeout, S_IRUGO);
519static W1_MASTER_ATTR_RO(pointer, S_IRUGO); 519static W1_MASTER_ATTR_RO(pointer, S_IRUGO);
520static W1_MASTER_ATTR_RW(search, S_IRUGO | S_IWUGO); 520static W1_MASTER_ATTR_RW(search, S_IRUGO | S_IWUSR | S_IWGRP);
521static W1_MASTER_ATTR_RW(pullup, S_IRUGO | S_IWUGO); 521static W1_MASTER_ATTR_RW(pullup, S_IRUGO | S_IWUSR | S_IWGRP);
522static W1_MASTER_ATTR_RW(add, S_IRUGO | S_IWUGO); 522static W1_MASTER_ATTR_RW(add, S_IRUGO | S_IWUSR | S_IWGRP);
523static W1_MASTER_ATTR_RW(remove, S_IRUGO | S_IWUGO); 523static W1_MASTER_ATTR_RW(remove, S_IRUGO | S_IWUSR | S_IWGRP);
524 524
525static struct attribute *w1_master_default_attrs[] = { 525static struct attribute *w1_master_default_attrs[] = {
526 &w1_master_attribute_name.attr, 526 &w1_master_attribute_name.attr,
diff --git a/fs/Kconfig b/fs/Kconfig
index b5e582bd769d..97673c955484 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -53,7 +53,6 @@ config EXPORTFS
53config FILE_LOCKING 53config FILE_LOCKING
54 bool "Enable POSIX file locking API" if EMBEDDED 54 bool "Enable POSIX file locking API" if EMBEDDED
55 default y 55 default y
56 select BKL # while lockd still uses it.
57 help 56 help
58 This option enables standard file locking support, required 57 This option enables standard file locking support, required
59 for filesystems like NFS and for the flock() system 58 for filesystems like NFS and for the flock() system
diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
index bb4cc5b8abc8..79e2ca7973b7 100644
--- a/fs/Kconfig.binfmt
+++ b/fs/Kconfig.binfmt
@@ -42,7 +42,7 @@ config BINFMT_ELF_FDPIC
42 42
43config CORE_DUMP_DEFAULT_ELF_HEADERS 43config CORE_DUMP_DEFAULT_ELF_HEADERS
44 bool "Write ELF core dumps with partial segments" 44 bool "Write ELF core dumps with partial segments"
45 default n 45 default y
46 depends on BINFMT_ELF && ELF_CORE 46 depends on BINFMT_ELF && ELF_CORE
47 help 47 help
48 ELF core dump files describe each memory mapping of the crashed 48 ELF core dump files describe each memory mapping of the crashed
@@ -60,7 +60,7 @@ config CORE_DUMP_DEFAULT_ELF_HEADERS
60 inherited. See Documentation/filesystems/proc.txt for details. 60 inherited. See Documentation/filesystems/proc.txt for details.
61 61
62 This config option changes the default setting of coredump_filter 62 This config option changes the default setting of coredump_filter
63 seen at boot time. If unsure, say N. 63 seen at boot time. If unsure, say Y.
64 64
65config BINFMT_FLAT 65config BINFMT_FLAT
66 bool "Kernel support for flat binaries" 66 bool "Kernel support for flat binaries"
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 256bb7bb102a..8cf07242067d 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -77,9 +77,6 @@
77/* Maximum number of nesting allowed inside epoll sets */ 77/* Maximum number of nesting allowed inside epoll sets */
78#define EP_MAX_NESTS 4 78#define EP_MAX_NESTS 4
79 79
80/* Maximum msec timeout value storeable in a long int */
81#define EP_MAX_MSTIMEO min(1000ULL * MAX_SCHEDULE_TIMEOUT / HZ, (LONG_MAX - 999ULL) / HZ)
82
83#define EP_MAX_EVENTS (INT_MAX / sizeof(struct epoll_event)) 80#define EP_MAX_EVENTS (INT_MAX / sizeof(struct epoll_event))
84 81
85#define EP_UNACTIVE_PTR ((void *) -1L) 82#define EP_UNACTIVE_PTR ((void *) -1L)
@@ -1117,18 +1114,22 @@ static int ep_send_events(struct eventpoll *ep,
1117static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, 1114static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
1118 int maxevents, long timeout) 1115 int maxevents, long timeout)
1119{ 1116{
1120 int res, eavail; 1117 int res, eavail, timed_out = 0;
1121 unsigned long flags; 1118 unsigned long flags;
1122 long jtimeout; 1119 long slack;
1123 wait_queue_t wait; 1120 wait_queue_t wait;
1124 1121 struct timespec end_time;
1125 /* 1122 ktime_t expires, *to = NULL;
1126 * Calculate the timeout by checking for the "infinite" value (-1) 1123
1127 * and the overflow condition. The passed timeout is in milliseconds, 1124 if (timeout > 0) {
1128 * that why (t * HZ) / 1000. 1125 ktime_get_ts(&end_time);
1129 */ 1126 timespec_add_ns(&end_time, (u64)timeout * NSEC_PER_MSEC);
1130 jtimeout = (timeout < 0 || timeout >= EP_MAX_MSTIMEO) ? 1127 slack = select_estimate_accuracy(&end_time);
1131 MAX_SCHEDULE_TIMEOUT : (timeout * HZ + 999) / 1000; 1128 to = &expires;
1129 *to = timespec_to_ktime(end_time);
1130 } else if (timeout == 0) {
1131 timed_out = 1;
1132 }
1132 1133
1133retry: 1134retry:
1134 spin_lock_irqsave(&ep->lock, flags); 1135 spin_lock_irqsave(&ep->lock, flags);
@@ -1150,7 +1151,7 @@ retry:
1150 * to TASK_INTERRUPTIBLE before doing the checks. 1151 * to TASK_INTERRUPTIBLE before doing the checks.
1151 */ 1152 */
1152 set_current_state(TASK_INTERRUPTIBLE); 1153 set_current_state(TASK_INTERRUPTIBLE);
1153 if (!list_empty(&ep->rdllist) || !jtimeout) 1154 if (!list_empty(&ep->rdllist) || timed_out)
1154 break; 1155 break;
1155 if (signal_pending(current)) { 1156 if (signal_pending(current)) {
1156 res = -EINTR; 1157 res = -EINTR;
@@ -1158,7 +1159,9 @@ retry:
1158 } 1159 }
1159 1160
1160 spin_unlock_irqrestore(&ep->lock, flags); 1161 spin_unlock_irqrestore(&ep->lock, flags);
1161 jtimeout = schedule_timeout(jtimeout); 1162 if (!schedule_hrtimeout_range(to, slack, HRTIMER_MODE_ABS))
1163 timed_out = 1;
1164
1162 spin_lock_irqsave(&ep->lock, flags); 1165 spin_lock_irqsave(&ep->lock, flags);
1163 } 1166 }
1164 __remove_wait_queue(&ep->wq, &wait); 1167 __remove_wait_queue(&ep->wq, &wait);
@@ -1176,7 +1179,7 @@ retry:
1176 * more luck. 1179 * more luck.
1177 */ 1180 */
1178 if (!res && eavail && 1181 if (!res && eavail &&
1179 !(res = ep_send_events(ep, events, maxevents)) && jtimeout) 1182 !(res = ep_send_events(ep, events, maxevents)) && !timed_out)
1180 goto retry; 1183 goto retry;
1181 1184
1182 return res; 1185 return res;
diff --git a/fs/exec.c b/fs/exec.c
index 3aa75b8888a1..99d33a1371e9 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -66,6 +66,12 @@ char core_pattern[CORENAME_MAX_SIZE] = "core";
66unsigned int core_pipe_limit; 66unsigned int core_pipe_limit;
67int suid_dumpable = 0; 67int suid_dumpable = 0;
68 68
69struct core_name {
70 char *corename;
71 int used, size;
72};
73static atomic_t call_count = ATOMIC_INIT(1);
74
69/* The maximal length of core_pattern is also specified in sysctl.c */ 75/* The maximal length of core_pattern is also specified in sysctl.c */
70 76
71static LIST_HEAD(formats); 77static LIST_HEAD(formats);
@@ -1003,7 +1009,7 @@ int flush_old_exec(struct linux_binprm * bprm)
1003 1009
1004 bprm->mm = NULL; /* We're using it now */ 1010 bprm->mm = NULL; /* We're using it now */
1005 1011
1006 current->flags &= ~PF_RANDOMIZE; 1012 current->flags &= ~(PF_RANDOMIZE | PF_KTHREAD);
1007 flush_thread(); 1013 flush_thread();
1008 current->personality &= ~bprm->per_clear; 1014 current->personality &= ~bprm->per_clear;
1009 1015
@@ -1083,14 +1089,14 @@ EXPORT_SYMBOL(setup_new_exec);
1083 */ 1089 */
1084int prepare_bprm_creds(struct linux_binprm *bprm) 1090int prepare_bprm_creds(struct linux_binprm *bprm)
1085{ 1091{
1086 if (mutex_lock_interruptible(&current->cred_guard_mutex)) 1092 if (mutex_lock_interruptible(&current->signal->cred_guard_mutex))
1087 return -ERESTARTNOINTR; 1093 return -ERESTARTNOINTR;
1088 1094
1089 bprm->cred = prepare_exec_creds(); 1095 bprm->cred = prepare_exec_creds();
1090 if (likely(bprm->cred)) 1096 if (likely(bprm->cred))
1091 return 0; 1097 return 0;
1092 1098
1093 mutex_unlock(&current->cred_guard_mutex); 1099 mutex_unlock(&current->signal->cred_guard_mutex);
1094 return -ENOMEM; 1100 return -ENOMEM;
1095} 1101}
1096 1102
@@ -1098,7 +1104,7 @@ void free_bprm(struct linux_binprm *bprm)
1098{ 1104{
1099 free_arg_pages(bprm); 1105 free_arg_pages(bprm);
1100 if (bprm->cred) { 1106 if (bprm->cred) {
1101 mutex_unlock(&current->cred_guard_mutex); 1107 mutex_unlock(&current->signal->cred_guard_mutex);
1102 abort_creds(bprm->cred); 1108 abort_creds(bprm->cred);
1103 } 1109 }
1104 kfree(bprm); 1110 kfree(bprm);
@@ -1119,13 +1125,13 @@ void install_exec_creds(struct linux_binprm *bprm)
1119 * credentials; any time after this it may be unlocked. 1125 * credentials; any time after this it may be unlocked.
1120 */ 1126 */
1121 security_bprm_committed_creds(bprm); 1127 security_bprm_committed_creds(bprm);
1122 mutex_unlock(&current->cred_guard_mutex); 1128 mutex_unlock(&current->signal->cred_guard_mutex);
1123} 1129}
1124EXPORT_SYMBOL(install_exec_creds); 1130EXPORT_SYMBOL(install_exec_creds);
1125 1131
1126/* 1132/*
1127 * determine how safe it is to execute the proposed program 1133 * determine how safe it is to execute the proposed program
1128 * - the caller must hold current->cred_guard_mutex to protect against 1134 * - the caller must hold ->cred_guard_mutex to protect against
1129 * PTRACE_ATTACH 1135 * PTRACE_ATTACH
1130 */ 1136 */
1131int check_unsafe_exec(struct linux_binprm *bprm) 1137int check_unsafe_exec(struct linux_binprm *bprm)
@@ -1406,7 +1412,6 @@ int do_execve(const char * filename,
1406 if (retval < 0) 1412 if (retval < 0)
1407 goto out; 1413 goto out;
1408 1414
1409 current->flags &= ~PF_KTHREAD;
1410 retval = search_binary_handler(bprm,regs); 1415 retval = search_binary_handler(bprm,regs);
1411 if (retval < 0) 1416 if (retval < 0)
1412 goto out; 1417 goto out;
@@ -1459,127 +1464,148 @@ void set_binfmt(struct linux_binfmt *new)
1459 1464
1460EXPORT_SYMBOL(set_binfmt); 1465EXPORT_SYMBOL(set_binfmt);
1461 1466
1467static int expand_corename(struct core_name *cn)
1468{
1469 char *old_corename = cn->corename;
1470
1471 cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
1472 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
1473
1474 if (!cn->corename) {
1475 kfree(old_corename);
1476 return -ENOMEM;
1477 }
1478
1479 return 0;
1480}
1481
1482static int cn_printf(struct core_name *cn, const char *fmt, ...)
1483{
1484 char *cur;
1485 int need;
1486 int ret;
1487 va_list arg;
1488
1489 va_start(arg, fmt);
1490 need = vsnprintf(NULL, 0, fmt, arg);
1491 va_end(arg);
1492
1493 if (likely(need < cn->size - cn->used - 1))
1494 goto out_printf;
1495
1496 ret = expand_corename(cn);
1497 if (ret)
1498 goto expand_fail;
1499
1500out_printf:
1501 cur = cn->corename + cn->used;
1502 va_start(arg, fmt);
1503 vsnprintf(cur, need + 1, fmt, arg);
1504 va_end(arg);
1505 cn->used += need;
1506 return 0;
1507
1508expand_fail:
1509 return ret;
1510}
1511
1462/* format_corename will inspect the pattern parameter, and output a 1512/* format_corename will inspect the pattern parameter, and output a
1463 * name into corename, which must have space for at least 1513 * name into corename, which must have space for at least
1464 * CORENAME_MAX_SIZE bytes plus one byte for the zero terminator. 1514 * CORENAME_MAX_SIZE bytes plus one byte for the zero terminator.
1465 */ 1515 */
1466static int format_corename(char *corename, long signr) 1516static int format_corename(struct core_name *cn, long signr)
1467{ 1517{
1468 const struct cred *cred = current_cred(); 1518 const struct cred *cred = current_cred();
1469 const char *pat_ptr = core_pattern; 1519 const char *pat_ptr = core_pattern;
1470 int ispipe = (*pat_ptr == '|'); 1520 int ispipe = (*pat_ptr == '|');
1471 char *out_ptr = corename;
1472 char *const out_end = corename + CORENAME_MAX_SIZE;
1473 int rc;
1474 int pid_in_pattern = 0; 1521 int pid_in_pattern = 0;
1522 int err = 0;
1523
1524 cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
1525 cn->corename = kmalloc(cn->size, GFP_KERNEL);
1526 cn->used = 0;
1527
1528 if (!cn->corename)
1529 return -ENOMEM;
1475 1530
1476 /* Repeat as long as we have more pattern to process and more output 1531 /* Repeat as long as we have more pattern to process and more output
1477 space */ 1532 space */
1478 while (*pat_ptr) { 1533 while (*pat_ptr) {
1479 if (*pat_ptr != '%') { 1534 if (*pat_ptr != '%') {
1480 if (out_ptr == out_end) 1535 if (*pat_ptr == 0)
1481 goto out; 1536 goto out;
1482 *out_ptr++ = *pat_ptr++; 1537 err = cn_printf(cn, "%c", *pat_ptr++);
1483 } else { 1538 } else {
1484 switch (*++pat_ptr) { 1539 switch (*++pat_ptr) {
1540 /* single % at the end, drop that */
1485 case 0: 1541 case 0:
1486 goto out; 1542 goto out;
1487 /* Double percent, output one percent */ 1543 /* Double percent, output one percent */
1488 case '%': 1544 case '%':
1489 if (out_ptr == out_end) 1545 err = cn_printf(cn, "%c", '%');
1490 goto out;
1491 *out_ptr++ = '%';
1492 break; 1546 break;
1493 /* pid */ 1547 /* pid */
1494 case 'p': 1548 case 'p':
1495 pid_in_pattern = 1; 1549 pid_in_pattern = 1;
1496 rc = snprintf(out_ptr, out_end - out_ptr, 1550 err = cn_printf(cn, "%d",
1497 "%d", task_tgid_vnr(current)); 1551 task_tgid_vnr(current));
1498 if (rc > out_end - out_ptr)
1499 goto out;
1500 out_ptr += rc;
1501 break; 1552 break;
1502 /* uid */ 1553 /* uid */
1503 case 'u': 1554 case 'u':
1504 rc = snprintf(out_ptr, out_end - out_ptr, 1555 err = cn_printf(cn, "%d", cred->uid);
1505 "%d", cred->uid);
1506 if (rc > out_end - out_ptr)
1507 goto out;
1508 out_ptr += rc;
1509 break; 1556 break;
1510 /* gid */ 1557 /* gid */
1511 case 'g': 1558 case 'g':
1512 rc = snprintf(out_ptr, out_end - out_ptr, 1559 err = cn_printf(cn, "%d", cred->gid);
1513 "%d", cred->gid);
1514 if (rc > out_end - out_ptr)
1515 goto out;
1516 out_ptr += rc;
1517 break; 1560 break;
1518 /* signal that caused the coredump */ 1561 /* signal that caused the coredump */
1519 case 's': 1562 case 's':
1520 rc = snprintf(out_ptr, out_end - out_ptr, 1563 err = cn_printf(cn, "%ld", signr);
1521 "%ld", signr);
1522 if (rc > out_end - out_ptr)
1523 goto out;
1524 out_ptr += rc;
1525 break; 1564 break;
1526 /* UNIX time of coredump */ 1565 /* UNIX time of coredump */
1527 case 't': { 1566 case 't': {
1528 struct timeval tv; 1567 struct timeval tv;
1529 do_gettimeofday(&tv); 1568 do_gettimeofday(&tv);
1530 rc = snprintf(out_ptr, out_end - out_ptr, 1569 err = cn_printf(cn, "%lu", tv.tv_sec);
1531 "%lu", tv.tv_sec);
1532 if (rc > out_end - out_ptr)
1533 goto out;
1534 out_ptr += rc;
1535 break; 1570 break;
1536 } 1571 }
1537 /* hostname */ 1572 /* hostname */
1538 case 'h': 1573 case 'h':
1539 down_read(&uts_sem); 1574 down_read(&uts_sem);
1540 rc = snprintf(out_ptr, out_end - out_ptr, 1575 err = cn_printf(cn, "%s",
1541 "%s", utsname()->nodename); 1576 utsname()->nodename);
1542 up_read(&uts_sem); 1577 up_read(&uts_sem);
1543 if (rc > out_end - out_ptr)
1544 goto out;
1545 out_ptr += rc;
1546 break; 1578 break;
1547 /* executable */ 1579 /* executable */
1548 case 'e': 1580 case 'e':
1549 rc = snprintf(out_ptr, out_end - out_ptr, 1581 err = cn_printf(cn, "%s", current->comm);
1550 "%s", current->comm);
1551 if (rc > out_end - out_ptr)
1552 goto out;
1553 out_ptr += rc;
1554 break; 1582 break;
1555 /* core limit size */ 1583 /* core limit size */
1556 case 'c': 1584 case 'c':
1557 rc = snprintf(out_ptr, out_end - out_ptr, 1585 err = cn_printf(cn, "%lu",
1558 "%lu", rlimit(RLIMIT_CORE)); 1586 rlimit(RLIMIT_CORE));
1559 if (rc > out_end - out_ptr)
1560 goto out;
1561 out_ptr += rc;
1562 break; 1587 break;
1563 default: 1588 default:
1564 break; 1589 break;
1565 } 1590 }
1566 ++pat_ptr; 1591 ++pat_ptr;
1567 } 1592 }
1593
1594 if (err)
1595 return err;
1568 } 1596 }
1597
1569 /* Backward compatibility with core_uses_pid: 1598 /* Backward compatibility with core_uses_pid:
1570 * 1599 *
1571 * If core_pattern does not include a %p (as is the default) 1600 * If core_pattern does not include a %p (as is the default)
1572 * and core_uses_pid is set, then .%pid will be appended to 1601 * and core_uses_pid is set, then .%pid will be appended to
1573 * the filename. Do not do this for piped commands. */ 1602 * the filename. Do not do this for piped commands. */
1574 if (!ispipe && !pid_in_pattern && core_uses_pid) { 1603 if (!ispipe && !pid_in_pattern && core_uses_pid) {
1575 rc = snprintf(out_ptr, out_end - out_ptr, 1604 err = cn_printf(cn, ".%d", task_tgid_vnr(current));
1576 ".%d", task_tgid_vnr(current)); 1605 if (err)
1577 if (rc > out_end - out_ptr) 1606 return err;
1578 goto out;
1579 out_ptr += rc;
1580 } 1607 }
1581out: 1608out:
1582 *out_ptr = 0;
1583 return ispipe; 1609 return ispipe;
1584} 1610}
1585 1611
@@ -1856,7 +1882,7 @@ static int umh_pipe_setup(struct subprocess_info *info)
1856void do_coredump(long signr, int exit_code, struct pt_regs *regs) 1882void do_coredump(long signr, int exit_code, struct pt_regs *regs)
1857{ 1883{
1858 struct core_state core_state; 1884 struct core_state core_state;
1859 char corename[CORENAME_MAX_SIZE + 1]; 1885 struct core_name cn;
1860 struct mm_struct *mm = current->mm; 1886 struct mm_struct *mm = current->mm;
1861 struct linux_binfmt * binfmt; 1887 struct linux_binfmt * binfmt;
1862 const struct cred *old_cred; 1888 const struct cred *old_cred;
@@ -1911,7 +1937,13 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
1911 */ 1937 */
1912 clear_thread_flag(TIF_SIGPENDING); 1938 clear_thread_flag(TIF_SIGPENDING);
1913 1939
1914 ispipe = format_corename(corename, signr); 1940 ispipe = format_corename(&cn, signr);
1941
1942 if (ispipe == -ENOMEM) {
1943 printk(KERN_WARNING "format_corename failed\n");
1944 printk(KERN_WARNING "Aborting core\n");
1945 goto fail_corename;
1946 }
1915 1947
1916 if (ispipe) { 1948 if (ispipe) {
1917 int dump_count; 1949 int dump_count;
@@ -1948,7 +1980,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
1948 goto fail_dropcount; 1980 goto fail_dropcount;
1949 } 1981 }
1950 1982
1951 helper_argv = argv_split(GFP_KERNEL, corename+1, NULL); 1983 helper_argv = argv_split(GFP_KERNEL, cn.corename+1, NULL);
1952 if (!helper_argv) { 1984 if (!helper_argv) {
1953 printk(KERN_WARNING "%s failed to allocate memory\n", 1985 printk(KERN_WARNING "%s failed to allocate memory\n",
1954 __func__); 1986 __func__);
@@ -1961,7 +1993,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
1961 argv_free(helper_argv); 1993 argv_free(helper_argv);
1962 if (retval) { 1994 if (retval) {
1963 printk(KERN_INFO "Core dump to %s pipe failed\n", 1995 printk(KERN_INFO "Core dump to %s pipe failed\n",
1964 corename); 1996 cn.corename);
1965 goto close_fail; 1997 goto close_fail;
1966 } 1998 }
1967 } else { 1999 } else {
@@ -1970,7 +2002,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
1970 if (cprm.limit < binfmt->min_coredump) 2002 if (cprm.limit < binfmt->min_coredump)
1971 goto fail_unlock; 2003 goto fail_unlock;
1972 2004
1973 cprm.file = filp_open(corename, 2005 cprm.file = filp_open(cn.corename,
1974 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag, 2006 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
1975 0600); 2007 0600);
1976 if (IS_ERR(cprm.file)) 2008 if (IS_ERR(cprm.file))
@@ -2012,6 +2044,8 @@ fail_dropcount:
2012 if (ispipe) 2044 if (ispipe)
2013 atomic_dec(&core_dump_count); 2045 atomic_dec(&core_dump_count);
2014fail_unlock: 2046fail_unlock:
2047 kfree(cn.corename);
2048fail_corename:
2015 coredump_finish(mm); 2049 coredump_finish(mm);
2016 revert_creds(old_cred); 2050 revert_creds(old_cred);
2017fail_creds: 2051fail_creds:
diff --git a/fs/fcntl.c b/fs/fcntl.c
index f8cc34f542c3..ecc8b3954ed6 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -640,7 +640,7 @@ static void fasync_free_rcu(struct rcu_head *head)
640 * match the state "is the filp on a fasync list". 640 * match the state "is the filp on a fasync list".
641 * 641 *
642 */ 642 */
643static int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp) 643int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp)
644{ 644{
645 struct fasync_struct *fa, **fp; 645 struct fasync_struct *fa, **fp;
646 int result = 0; 646 int result = 0;
@@ -666,21 +666,31 @@ static int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp)
666 return result; 666 return result;
667} 667}
668 668
669struct fasync_struct *fasync_alloc(void)
670{
671 return kmem_cache_alloc(fasync_cache, GFP_KERNEL);
672}
673
669/* 674/*
670 * Add a fasync entry. Return negative on error, positive if 675 * NOTE! This can be used only for unused fasync entries:
671 * added, and zero if did nothing but change an existing one. 676 * entries that actually got inserted on the fasync list
677 * need to be released by rcu - see fasync_remove_entry.
678 */
679void fasync_free(struct fasync_struct *new)
680{
681 kmem_cache_free(fasync_cache, new);
682}
683
684/*
685 * Insert a new entry into the fasync list. Return the pointer to the
686 * old one if we didn't use the new one.
672 * 687 *
673 * NOTE! It is very important that the FASYNC flag always 688 * NOTE! It is very important that the FASYNC flag always
674 * match the state "is the filp on a fasync list". 689 * match the state "is the filp on a fasync list".
675 */ 690 */
676static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fapp) 691struct fasync_struct *fasync_insert_entry(int fd, struct file *filp, struct fasync_struct **fapp, struct fasync_struct *new)
677{ 692{
678 struct fasync_struct *new, *fa, **fp; 693 struct fasync_struct *fa, **fp;
679 int result = 0;
680
681 new = kmem_cache_alloc(fasync_cache, GFP_KERNEL);
682 if (!new)
683 return -ENOMEM;
684 694
685 spin_lock(&filp->f_lock); 695 spin_lock(&filp->f_lock);
686 spin_lock(&fasync_lock); 696 spin_lock(&fasync_lock);
@@ -691,8 +701,6 @@ static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fa
691 spin_lock_irq(&fa->fa_lock); 701 spin_lock_irq(&fa->fa_lock);
692 fa->fa_fd = fd; 702 fa->fa_fd = fd;
693 spin_unlock_irq(&fa->fa_lock); 703 spin_unlock_irq(&fa->fa_lock);
694
695 kmem_cache_free(fasync_cache, new);
696 goto out; 704 goto out;
697 } 705 }
698 706
@@ -702,13 +710,39 @@ static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fa
702 new->fa_fd = fd; 710 new->fa_fd = fd;
703 new->fa_next = *fapp; 711 new->fa_next = *fapp;
704 rcu_assign_pointer(*fapp, new); 712 rcu_assign_pointer(*fapp, new);
705 result = 1;
706 filp->f_flags |= FASYNC; 713 filp->f_flags |= FASYNC;
707 714
708out: 715out:
709 spin_unlock(&fasync_lock); 716 spin_unlock(&fasync_lock);
710 spin_unlock(&filp->f_lock); 717 spin_unlock(&filp->f_lock);
711 return result; 718 return fa;
719}
720
721/*
722 * Add a fasync entry. Return negative on error, positive if
723 * added, and zero if did nothing but change an existing one.
724 */
725static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fapp)
726{
727 struct fasync_struct *new;
728
729 new = fasync_alloc();
730 if (!new)
731 return -ENOMEM;
732
733 /*
734 * fasync_insert_entry() returns the old (update) entry if
735 * it existed.
736 *
737 * So free the (unused) new entry and return 0 to let the
738 * caller know that we didn't add any new fasync entries.
739 */
740 if (fasync_insert_entry(fd, filp, fapp, new)) {
741 fasync_free(new);
742 return 0;
743 }
744
745 return 1;
712} 746}
713 747
714/* 748/*
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index b98664275f02..6e07696308dc 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1334,12 +1334,7 @@ out_finish:
1334 1334
1335static void fuse_retrieve_end(struct fuse_conn *fc, struct fuse_req *req) 1335static void fuse_retrieve_end(struct fuse_conn *fc, struct fuse_req *req)
1336{ 1336{
1337 int i; 1337 release_pages(req->pages, req->num_pages, 0);
1338
1339 for (i = 0; i < req->num_pages; i++) {
1340 struct page *page = req->pages[i];
1341 page_cache_release(page);
1342 }
1343} 1338}
1344 1339
1345static int fuse_retrieve(struct fuse_conn *fc, struct inode *inode, 1340static int fuse_retrieve(struct fuse_conn *fc, struct inode *inode,
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index 60c2b944d762..79cf7f616bbe 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -544,6 +544,34 @@ static unsigned int isofs_get_last_session(struct super_block *sb, s32 session)
544} 544}
545 545
546/* 546/*
547 * Check if root directory is empty (has less than 3 files).
548 *
549 * Used to detect broken CDs where ISO root directory is empty but Joliet root
550 * directory is OK. If such CD has Rock Ridge extensions, they will be disabled
551 * (and Joliet used instead) or else no files would be visible.
552 */
553static bool rootdir_empty(struct super_block *sb, unsigned long block)
554{
555 int offset = 0, files = 0, de_len;
556 struct iso_directory_record *de;
557 struct buffer_head *bh;
558
559 bh = sb_bread(sb, block);
560 if (!bh)
561 return true;
562 while (files < 3) {
563 de = (struct iso_directory_record *) (bh->b_data + offset);
564 de_len = *(unsigned char *) de;
565 if (de_len == 0)
566 break;
567 files++;
568 offset += de_len;
569 }
570 brelse(bh);
571 return files < 3;
572}
573
574/*
547 * Initialize the superblock and read the root inode. 575 * Initialize the superblock and read the root inode.
548 * 576 *
549 * Note: a check_disk_change() has been done immediately prior 577 * Note: a check_disk_change() has been done immediately prior
@@ -843,6 +871,18 @@ root_found:
843 goto out_no_root; 871 goto out_no_root;
844 872
845 /* 873 /*
874 * Fix for broken CDs with Rock Ridge and empty ISO root directory but
875 * correct Joliet root directory.
876 */
877 if (sbi->s_rock == 1 && joliet_level &&
878 rootdir_empty(s, sbi->s_firstdatazone)) {
879 printk(KERN_NOTICE
880 "ISOFS: primary root directory is empty. "
881 "Disabling Rock Ridge and switching to Joliet.");
882 sbi->s_rock = 0;
883 }
884
885 /*
846 * If this disk has both Rock Ridge and Joliet on it, then we 886 * If this disk has both Rock Ridge and Joliet on it, then we
847 * want to use Rock Ridge by default. This can be overridden 887 * want to use Rock Ridge by default. This can be overridden
848 * by using the norock mount option. There is still one other 888 * by using the norock mount option. There is still one other
diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
index b13aabc12298..abfff9d7979d 100644
--- a/fs/lockd/svc.c
+++ b/fs/lockd/svc.c
@@ -22,7 +22,6 @@
22#include <linux/in.h> 22#include <linux/in.h>
23#include <linux/uio.h> 23#include <linux/uio.h>
24#include <linux/smp.h> 24#include <linux/smp.h>
25#include <linux/smp_lock.h>
26#include <linux/mutex.h> 25#include <linux/mutex.h>
27#include <linux/kthread.h> 26#include <linux/kthread.h>
28#include <linux/freezer.h> 27#include <linux/freezer.h>
@@ -130,15 +129,6 @@ lockd(void *vrqstp)
130 129
131 dprintk("NFS locking service started (ver " LOCKD_VERSION ").\n"); 130 dprintk("NFS locking service started (ver " LOCKD_VERSION ").\n");
132 131
133 /*
134 * FIXME: it would be nice if lockd didn't spend its entire life
135 * running under the BKL. At the very least, it would be good to
136 * have someone clarify what it's intended to protect here. I've
137 * seen some handwavy posts about posix locking needing to be
138 * done under the BKL, but it's far from clear.
139 */
140 lock_kernel();
141
142 if (!nlm_timeout) 132 if (!nlm_timeout)
143 nlm_timeout = LOCKD_DFLT_TIMEO; 133 nlm_timeout = LOCKD_DFLT_TIMEO;
144 nlmsvc_timeout = nlm_timeout * HZ; 134 nlmsvc_timeout = nlm_timeout * HZ;
@@ -195,7 +185,6 @@ lockd(void *vrqstp)
195 if (nlmsvc_ops) 185 if (nlmsvc_ops)
196 nlmsvc_invalidate_all(); 186 nlmsvc_invalidate_all();
197 nlm_shutdown_hosts(); 187 nlm_shutdown_hosts();
198 unlock_kernel();
199 return 0; 188 return 0;
200} 189}
201 190
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 6f1ef000975a..c462d346acbd 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -700,14 +700,16 @@ nlmsvc_notify_blocked(struct file_lock *fl)
700 struct nlm_block *block; 700 struct nlm_block *block;
701 701
702 dprintk("lockd: VFS unblock notification for block %p\n", fl); 702 dprintk("lockd: VFS unblock notification for block %p\n", fl);
703 spin_lock(&nlm_blocked_lock);
703 list_for_each_entry(block, &nlm_blocked, b_list) { 704 list_for_each_entry(block, &nlm_blocked, b_list) {
704 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) { 705 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) {
705 nlmsvc_insert_block(block, 0); 706 nlmsvc_insert_block_locked(block, 0);
707 spin_unlock(&nlm_blocked_lock);
706 svc_wake_up(block->b_daemon); 708 svc_wake_up(block->b_daemon);
707 return; 709 return;
708 } 710 }
709 } 711 }
710 712 spin_unlock(&nlm_blocked_lock);
711 printk(KERN_WARNING "lockd: notification for unknown block!\n"); 713 printk(KERN_WARNING "lockd: notification for unknown block!\n");
712} 714}
713 715
diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c
index d0ef94cfb3da..1ca0679c80bf 100644
--- a/fs/lockd/svcsubs.c
+++ b/fs/lockd/svcsubs.c
@@ -170,6 +170,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
170 170
171again: 171again:
172 file->f_locks = 0; 172 file->f_locks = 0;
173 lock_flocks(); /* protects i_flock list */
173 for (fl = inode->i_flock; fl; fl = fl->fl_next) { 174 for (fl = inode->i_flock; fl; fl = fl->fl_next) {
174 if (fl->fl_lmops != &nlmsvc_lock_operations) 175 if (fl->fl_lmops != &nlmsvc_lock_operations)
175 continue; 176 continue;
@@ -181,6 +182,7 @@ again:
181 if (match(lockhost, host)) { 182 if (match(lockhost, host)) {
182 struct file_lock lock = *fl; 183 struct file_lock lock = *fl;
183 184
185 unlock_flocks();
184 lock.fl_type = F_UNLCK; 186 lock.fl_type = F_UNLCK;
185 lock.fl_start = 0; 187 lock.fl_start = 0;
186 lock.fl_end = OFFSET_MAX; 188 lock.fl_end = OFFSET_MAX;
@@ -192,6 +194,7 @@ again:
192 goto again; 194 goto again;
193 } 195 }
194 } 196 }
197 unlock_flocks();
195 198
196 return 0; 199 return 0;
197} 200}
@@ -226,10 +229,14 @@ nlm_file_inuse(struct nlm_file *file)
226 if (file->f_count || !list_empty(&file->f_blocks) || file->f_shares) 229 if (file->f_count || !list_empty(&file->f_blocks) || file->f_shares)
227 return 1; 230 return 1;
228 231
232 lock_flocks();
229 for (fl = inode->i_flock; fl; fl = fl->fl_next) { 233 for (fl = inode->i_flock; fl; fl = fl->fl_next) {
230 if (fl->fl_lmops == &nlmsvc_lock_operations) 234 if (fl->fl_lmops == &nlmsvc_lock_operations) {
235 unlock_flocks();
231 return 1; 236 return 1;
237 }
232 } 238 }
239 unlock_flocks();
233 file->f_locks = 0; 240 file->f_locks = 0;
234 return 0; 241 return 0;
235} 242}
diff --git a/fs/locks.c b/fs/locks.c
index 4de3a2666810..50ec15927aab 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -142,6 +142,7 @@ int lease_break_time = 45;
142 142
143static LIST_HEAD(file_lock_list); 143static LIST_HEAD(file_lock_list);
144static LIST_HEAD(blocked_list); 144static LIST_HEAD(blocked_list);
145static DEFINE_SPINLOCK(file_lock_lock);
145 146
146/* 147/*
147 * Protects the two list heads above, plus the inode->i_flock list 148 * Protects the two list heads above, plus the inode->i_flock list
@@ -149,23 +150,24 @@ static LIST_HEAD(blocked_list);
149 */ 150 */
150void lock_flocks(void) 151void lock_flocks(void)
151{ 152{
152 lock_kernel(); 153 spin_lock(&file_lock_lock);
153} 154}
154EXPORT_SYMBOL_GPL(lock_flocks); 155EXPORT_SYMBOL_GPL(lock_flocks);
155 156
156void unlock_flocks(void) 157void unlock_flocks(void)
157{ 158{
158 unlock_kernel(); 159 spin_unlock(&file_lock_lock);
159} 160}
160EXPORT_SYMBOL_GPL(unlock_flocks); 161EXPORT_SYMBOL_GPL(unlock_flocks);
161 162
162static struct kmem_cache *filelock_cache __read_mostly; 163static struct kmem_cache *filelock_cache __read_mostly;
163 164
164/* Allocate an empty lock structure. */ 165/* Allocate an empty lock structure. */
165static struct file_lock *locks_alloc_lock(void) 166struct file_lock *locks_alloc_lock(void)
166{ 167{
167 return kmem_cache_alloc(filelock_cache, GFP_KERNEL); 168 return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
168} 169}
170EXPORT_SYMBOL_GPL(locks_alloc_lock);
169 171
170void locks_release_private(struct file_lock *fl) 172void locks_release_private(struct file_lock *fl)
171{ 173{
@@ -1365,7 +1367,6 @@ int fcntl_getlease(struct file *filp)
1365int generic_setlease(struct file *filp, long arg, struct file_lock **flp) 1367int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1366{ 1368{
1367 struct file_lock *fl, **before, **my_before = NULL, *lease; 1369 struct file_lock *fl, **before, **my_before = NULL, *lease;
1368 struct file_lock *new_fl = NULL;
1369 struct dentry *dentry = filp->f_path.dentry; 1370 struct dentry *dentry = filp->f_path.dentry;
1370 struct inode *inode = dentry->d_inode; 1371 struct inode *inode = dentry->d_inode;
1371 int error, rdlease_count = 0, wrlease_count = 0; 1372 int error, rdlease_count = 0, wrlease_count = 0;
@@ -1385,11 +1386,6 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1385 lease = *flp; 1386 lease = *flp;
1386 1387
1387 if (arg != F_UNLCK) { 1388 if (arg != F_UNLCK) {
1388 error = -ENOMEM;
1389 new_fl = locks_alloc_lock();
1390 if (new_fl == NULL)
1391 goto out;
1392
1393 error = -EAGAIN; 1389 error = -EAGAIN;
1394 if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0)) 1390 if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0))
1395 goto out; 1391 goto out;
@@ -1434,7 +1430,6 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1434 goto out; 1430 goto out;
1435 } 1431 }
1436 1432
1437 error = 0;
1438 if (arg == F_UNLCK) 1433 if (arg == F_UNLCK)
1439 goto out; 1434 goto out;
1440 1435
@@ -1442,15 +1437,11 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
1442 if (!leases_enable) 1437 if (!leases_enable)
1443 goto out; 1438 goto out;
1444 1439
1445 locks_copy_lock(new_fl, lease); 1440 locks_insert_lock(before, lease);
1446 locks_insert_lock(before, new_fl);
1447
1448 *flp = new_fl;
1449 return 0; 1441 return 0;
1450 1442
1451out: 1443out:
1452 if (new_fl != NULL) 1444 locks_free_lock(lease);
1453 locks_free_lock(new_fl);
1454 return error; 1445 return error;
1455} 1446}
1456EXPORT_SYMBOL(generic_setlease); 1447EXPORT_SYMBOL(generic_setlease);
@@ -1514,26 +1505,38 @@ EXPORT_SYMBOL_GPL(vfs_setlease);
1514 */ 1505 */
1515int fcntl_setlease(unsigned int fd, struct file *filp, long arg) 1506int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
1516{ 1507{
1517 struct file_lock fl, *flp = &fl; 1508 struct file_lock *fl;
1509 struct fasync_struct *new;
1518 struct inode *inode = filp->f_path.dentry->d_inode; 1510 struct inode *inode = filp->f_path.dentry->d_inode;
1519 int error; 1511 int error;
1520 1512
1521 locks_init_lock(&fl); 1513 fl = lease_alloc(filp, arg);
1522 error = lease_init(filp, arg, &fl); 1514 if (IS_ERR(fl))
1523 if (error) 1515 return PTR_ERR(fl);
1524 return error;
1525 1516
1517 new = fasync_alloc();
1518 if (!new) {
1519 locks_free_lock(fl);
1520 return -ENOMEM;
1521 }
1526 lock_flocks(); 1522 lock_flocks();
1527 1523 error = __vfs_setlease(filp, arg, &fl);
1528 error = __vfs_setlease(filp, arg, &flp);
1529 if (error || arg == F_UNLCK) 1524 if (error || arg == F_UNLCK)
1530 goto out_unlock; 1525 goto out_unlock;
1531 1526
1532 error = fasync_helper(fd, filp, 1, &flp->fl_fasync); 1527 /*
1528 * fasync_insert_entry() returns the old entry if any.
1529 * If there was no old entry, then it used 'new' and
1530 * inserted it into the fasync list. Clear new so that
1531 * we don't release it here.
1532 */
1533 if (!fasync_insert_entry(fd, filp, &fl->fl_fasync, new))
1534 new = NULL;
1535
1533 if (error < 0) { 1536 if (error < 0) {
1534 /* remove lease just inserted by setlease */ 1537 /* remove lease just inserted by setlease */
1535 flp->fl_type = F_UNLCK | F_INPROGRESS; 1538 fl->fl_type = F_UNLCK | F_INPROGRESS;
1536 flp->fl_break_time = jiffies - 10; 1539 fl->fl_break_time = jiffies - 10;
1537 time_out_leases(inode); 1540 time_out_leases(inode);
1538 goto out_unlock; 1541 goto out_unlock;
1539 } 1542 }
@@ -1541,6 +1544,8 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
1541 error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); 1544 error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
1542out_unlock: 1545out_unlock:
1543 unlock_flocks(); 1546 unlock_flocks();
1547 if (new)
1548 fasync_free(new);
1544 return error; 1549 return error;
1545} 1550}
1546 1551
diff --git a/fs/nfs/Kconfig b/fs/nfs/Kconfig
index fd667652c502..ba306658a6db 100644
--- a/fs/nfs/Kconfig
+++ b/fs/nfs/Kconfig
@@ -1,7 +1,6 @@
1config NFS_FS 1config NFS_FS
2 tristate "NFS client support" 2 tristate "NFS client support"
3 depends on INET && FILE_LOCKING 3 depends on INET && FILE_LOCKING
4 depends on BKL # fix as soon as lockd is done
5 select LOCKD 4 select LOCKD
6 select SUNRPC 5 select SUNRPC
7 select NFS_ACL_SUPPORT if NFS_V3_ACL 6 select NFS_ACL_SUPPORT if NFS_V3_ACL
diff --git a/fs/nfsd/Kconfig b/fs/nfsd/Kconfig
index 31a78fce4732..18b3e8975fe0 100644
--- a/fs/nfsd/Kconfig
+++ b/fs/nfsd/Kconfig
@@ -2,7 +2,6 @@ config NFSD
2 tristate "NFS server support" 2 tristate "NFS server support"
3 depends on INET 3 depends on INET
4 depends on FILE_LOCKING 4 depends on FILE_LOCKING
5 depends on BKL # fix as soon as lockd is done
6 select LOCKD 5 select LOCKD
7 select SUNRPC 6 select SUNRPC
8 select EXPORTFS 7 select EXPORTFS
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 9019e8ec9dc8..56347e0ac88d 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2614,7 +2614,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
2614 struct nfs4_delegation *dp; 2614 struct nfs4_delegation *dp;
2615 struct nfs4_stateowner *sop = stp->st_stateowner; 2615 struct nfs4_stateowner *sop = stp->st_stateowner;
2616 int cb_up = atomic_read(&sop->so_client->cl_cb_set); 2616 int cb_up = atomic_read(&sop->so_client->cl_cb_set);
2617 struct file_lock fl, *flp = &fl; 2617 struct file_lock *fl;
2618 int status, flag = 0; 2618 int status, flag = 0;
2619 2619
2620 flag = NFS4_OPEN_DELEGATE_NONE; 2620 flag = NFS4_OPEN_DELEGATE_NONE;
@@ -2648,20 +2648,24 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
2648 flag = NFS4_OPEN_DELEGATE_NONE; 2648 flag = NFS4_OPEN_DELEGATE_NONE;
2649 goto out; 2649 goto out;
2650 } 2650 }
2651 locks_init_lock(&fl); 2651 status = -ENOMEM;
2652 fl.fl_lmops = &nfsd_lease_mng_ops; 2652 fl = locks_alloc_lock();
2653 fl.fl_flags = FL_LEASE; 2653 if (!fl)
2654 fl.fl_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK; 2654 goto out;
2655 fl.fl_end = OFFSET_MAX; 2655 locks_init_lock(fl);
2656 fl.fl_owner = (fl_owner_t)dp; 2656 fl->fl_lmops = &nfsd_lease_mng_ops;
2657 fl.fl_file = find_readable_file(stp->st_file); 2657 fl->fl_flags = FL_LEASE;
2658 BUG_ON(!fl.fl_file); 2658 fl->fl_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK;
2659 fl.fl_pid = current->tgid; 2659 fl->fl_end = OFFSET_MAX;
2660 fl->fl_owner = (fl_owner_t)dp;
2661 fl->fl_file = find_readable_file(stp->st_file);
2662 BUG_ON(!fl->fl_file);
2663 fl->fl_pid = current->tgid;
2660 2664
2661 /* vfs_setlease checks to see if delegation should be handed out. 2665 /* vfs_setlease checks to see if delegation should be handed out.
2662 * the lock_manager callbacks fl_mylease and fl_change are used 2666 * the lock_manager callbacks fl_mylease and fl_change are used
2663 */ 2667 */
2664 if ((status = vfs_setlease(fl.fl_file, fl.fl_type, &flp))) { 2668 if ((status = vfs_setlease(fl->fl_file, fl->fl_type, &fl))) {
2665 dprintk("NFSD: setlease failed [%d], no delegation\n", status); 2669 dprintk("NFSD: setlease failed [%d], no delegation\n", status);
2666 unhash_delegation(dp); 2670 unhash_delegation(dp);
2667 flag = NFS4_OPEN_DELEGATE_NONE; 2671 flag = NFS4_OPEN_DELEGATE_NONE;
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 9b094c1c8465..f3d02ca461ec 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -226,7 +226,7 @@ struct mm_struct *mm_for_maps(struct task_struct *task)
226{ 226{
227 struct mm_struct *mm; 227 struct mm_struct *mm;
228 228
229 if (mutex_lock_killable(&task->cred_guard_mutex)) 229 if (mutex_lock_killable(&task->signal->cred_guard_mutex))
230 return NULL; 230 return NULL;
231 231
232 mm = get_task_mm(task); 232 mm = get_task_mm(task);
@@ -235,7 +235,7 @@ struct mm_struct *mm_for_maps(struct task_struct *task)
235 mmput(mm); 235 mmput(mm);
236 mm = NULL; 236 mm = NULL;
237 } 237 }
238 mutex_unlock(&task->cred_guard_mutex); 238 mutex_unlock(&task->signal->cred_guard_mutex);
239 239
240 return mm; 240 return mm;
241} 241}
@@ -2354,14 +2354,14 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
2354 goto out_free; 2354 goto out_free;
2355 2355
2356 /* Guard against adverse ptrace interaction */ 2356 /* Guard against adverse ptrace interaction */
2357 length = mutex_lock_interruptible(&task->cred_guard_mutex); 2357 length = mutex_lock_interruptible(&task->signal->cred_guard_mutex);
2358 if (length < 0) 2358 if (length < 0)
2359 goto out_free; 2359 goto out_free;
2360 2360
2361 length = security_setprocattr(task, 2361 length = security_setprocattr(task,
2362 (char*)file->f_path.dentry->d_name.name, 2362 (char*)file->f_path.dentry->d_name.name,
2363 (void*)page, count); 2363 (void*)page, count);
2364 mutex_unlock(&task->cred_guard_mutex); 2364 mutex_unlock(&task->signal->cred_guard_mutex);
2365out_free: 2365out_free:
2366 free_page((unsigned long) page); 2366 free_page((unsigned long) page);
2367out: 2367out:
diff --git a/fs/proc/softirqs.c b/fs/proc/softirqs.c
index 1807c2419f17..37994737c983 100644
--- a/fs/proc/softirqs.c
+++ b/fs/proc/softirqs.c
@@ -10,13 +10,13 @@ static int show_softirqs(struct seq_file *p, void *v)
10{ 10{
11 int i, j; 11 int i, j;
12 12
13 seq_printf(p, " "); 13 seq_printf(p, " ");
14 for_each_possible_cpu(i) 14 for_each_possible_cpu(i)
15 seq_printf(p, "CPU%-8d", i); 15 seq_printf(p, "CPU%-8d", i);
16 seq_printf(p, "\n"); 16 seq_printf(p, "\n");
17 17
18 for (i = 0; i < NR_SOFTIRQS; i++) { 18 for (i = 0; i < NR_SOFTIRQS; i++) {
19 seq_printf(p, "%8s:", softirq_to_name[i]); 19 seq_printf(p, "%12s:", softirq_to_name[i]);
20 for_each_possible_cpu(j) 20 for_each_possible_cpu(j)
21 seq_printf(p, " %10u", kstat_softirqs_cpu(i, j)); 21 seq_printf(p, " %10u", kstat_softirqs_cpu(i, j));
22 seq_printf(p, "\n"); 22 seq_printf(p, "\n");
diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index bf31b03fc275..e15a19c93bae 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -31,7 +31,6 @@ static int show_stat(struct seq_file *p, void *v)
31 u64 sum_softirq = 0; 31 u64 sum_softirq = 0;
32 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0}; 32 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
33 struct timespec boottime; 33 struct timespec boottime;
34 unsigned int per_irq_sum;
35 34
36 user = nice = system = idle = iowait = 35 user = nice = system = idle = iowait =
37 irq = softirq = steal = cputime64_zero; 36 irq = softirq = steal = cputime64_zero;
@@ -52,9 +51,7 @@ static int show_stat(struct seq_file *p, void *v)
52 guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest); 51 guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
53 guest_nice = cputime64_add(guest_nice, 52 guest_nice = cputime64_add(guest_nice,
54 kstat_cpu(i).cpustat.guest_nice); 53 kstat_cpu(i).cpustat.guest_nice);
55 for_each_irq_nr(j) { 54 sum += kstat_cpu_irqs_sum(i);
56 sum += kstat_irqs_cpu(j, i);
57 }
58 sum += arch_irq_stat_cpu(i); 55 sum += arch_irq_stat_cpu(i);
59 56
60 for (j = 0; j < NR_SOFTIRQS; j++) { 57 for (j = 0; j < NR_SOFTIRQS; j++) {
@@ -110,13 +107,8 @@ static int show_stat(struct seq_file *p, void *v)
110 seq_printf(p, "intr %llu", (unsigned long long)sum); 107 seq_printf(p, "intr %llu", (unsigned long long)sum);
111 108
112 /* sum again ? it could be updated? */ 109 /* sum again ? it could be updated? */
113 for_each_irq_nr(j) { 110 for_each_irq_nr(j)
114 per_irq_sum = 0; 111 seq_printf(p, " %u", kstat_irqs(j));
115 for_each_possible_cpu(i)
116 per_irq_sum += kstat_irqs_cpu(j, i);
117
118 seq_printf(p, " %u", per_irq_sum);
119 }
120 112
121 seq_printf(p, 113 seq_printf(p,
122 "\nctxt %llu\n" 114 "\nctxt %llu\n"
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 871e25ed0069..da6b01d70f01 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -327,6 +327,7 @@ struct mem_size_stats {
327 unsigned long private_clean; 327 unsigned long private_clean;
328 unsigned long private_dirty; 328 unsigned long private_dirty;
329 unsigned long referenced; 329 unsigned long referenced;
330 unsigned long anonymous;
330 unsigned long swap; 331 unsigned long swap;
331 u64 pss; 332 u64 pss;
332}; 333};
@@ -357,6 +358,9 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
357 if (!page) 358 if (!page)
358 continue; 359 continue;
359 360
361 if (PageAnon(page))
362 mss->anonymous += PAGE_SIZE;
363
360 mss->resident += PAGE_SIZE; 364 mss->resident += PAGE_SIZE;
361 /* Accumulate the size in pages that have been accessed. */ 365 /* Accumulate the size in pages that have been accessed. */
362 if (pte_young(ptent) || PageReferenced(page)) 366 if (pte_young(ptent) || PageReferenced(page))
@@ -410,6 +414,7 @@ static int show_smap(struct seq_file *m, void *v)
410 "Private_Clean: %8lu kB\n" 414 "Private_Clean: %8lu kB\n"
411 "Private_Dirty: %8lu kB\n" 415 "Private_Dirty: %8lu kB\n"
412 "Referenced: %8lu kB\n" 416 "Referenced: %8lu kB\n"
417 "Anonymous: %8lu kB\n"
413 "Swap: %8lu kB\n" 418 "Swap: %8lu kB\n"
414 "KernelPageSize: %8lu kB\n" 419 "KernelPageSize: %8lu kB\n"
415 "MMUPageSize: %8lu kB\n", 420 "MMUPageSize: %8lu kB\n",
@@ -421,6 +426,7 @@ static int show_smap(struct seq_file *m, void *v)
421 mss.private_clean >> 10, 426 mss.private_clean >> 10,
422 mss.private_dirty >> 10, 427 mss.private_dirty >> 10,
423 mss.referenced >> 10, 428 mss.referenced >> 10,
429 mss.anonymous >> 10,
424 mss.swap >> 10, 430 mss.swap >> 10,
425 vma_kernel_pagesize(vma) >> 10, 431 vma_kernel_pagesize(vma) >> 10,
426 vma_mmu_pagesize(vma) >> 10); 432 vma_mmu_pagesize(vma) >> 10);
diff --git a/fs/select.c b/fs/select.c
index 500a669f7790..b7b10aa30861 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -67,7 +67,7 @@ static long __estimate_accuracy(struct timespec *tv)
67 return slack; 67 return slack;
68} 68}
69 69
70static long estimate_accuracy(struct timespec *tv) 70long select_estimate_accuracy(struct timespec *tv)
71{ 71{
72 unsigned long ret; 72 unsigned long ret;
73 struct timespec now; 73 struct timespec now;
@@ -417,7 +417,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
417 } 417 }
418 418
419 if (end_time && !timed_out) 419 if (end_time && !timed_out)
420 slack = estimate_accuracy(end_time); 420 slack = select_estimate_accuracy(end_time);
421 421
422 retval = 0; 422 retval = 0;
423 for (;;) { 423 for (;;) {
@@ -769,7 +769,7 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
769 } 769 }
770 770
771 if (end_time && !timed_out) 771 if (end_time && !timed_out)
772 slack = estimate_accuracy(end_time); 772 slack = select_estimate_accuracy(end_time);
773 773
774 for (;;) { 774 for (;;) {
775 struct poll_list *walk; 775 struct poll_list *walk;
diff --git a/include/asm-generic/cputime.h b/include/asm-generic/cputime.h
index ca0f239f0e13..2bcc5c7c22a6 100644
--- a/include/asm-generic/cputime.h
+++ b/include/asm-generic/cputime.h
@@ -33,10 +33,10 @@ typedef u64 cputime64_t;
33 33
34 34
35/* 35/*
36 * Convert cputime to milliseconds and back. 36 * Convert cputime to microseconds and back.
37 */ 37 */
38#define cputime_to_msecs(__ct) jiffies_to_msecs(__ct) 38#define cputime_to_usecs(__ct) jiffies_to_usecs(__ct);
39#define msecs_to_cputime(__msecs) msecs_to_jiffies(__msecs) 39#define usecs_to_cputime(__msecs) usecs_to_jiffies(__msecs);
40 40
41/* 41/*
42 * Convert cputime to seconds and back. 42 * Convert cputime to seconds and back.
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 8ca18e26d7e3..ff5c66080c8c 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -210,7 +210,7 @@ extern void gpio_unexport(unsigned gpio);
210 210
211#endif /* CONFIG_GPIO_SYSFS */ 211#endif /* CONFIG_GPIO_SYSFS */
212 212
213#else /* !CONFIG_HAVE_GPIO_LIB */ 213#else /* !CONFIG_GPIOLIB */
214 214
215static inline int gpio_is_valid(int number) 215static inline int gpio_is_valid(int number)
216{ 216{
@@ -239,7 +239,7 @@ static inline void gpio_set_value_cansleep(unsigned gpio, int value)
239 gpio_set_value(gpio, value); 239 gpio_set_value(gpio, value);
240} 240}
241 241
242#endif /* !CONFIG_HAVE_GPIO_LIB */ 242#endif /* !CONFIG_GPIOLIB */
243 243
244#ifndef CONFIG_GPIO_SYSFS 244#ifndef CONFIG_GPIO_SYSFS
245 245
diff --git a/include/linux/basic_mmio_gpio.h b/include/linux/basic_mmio_gpio.h
new file mode 100644
index 000000000000..198087a16fc4
--- /dev/null
+++ b/include/linux/basic_mmio_gpio.h
@@ -0,0 +1,20 @@
1/*
2 * Basic memory-mapped GPIO controllers.
3 *
4 * Copyright 2008 MontaVista Software, Inc.
5 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#ifndef __BASIC_MMIO_GPIO_H
14#define __BASIC_MMIO_GPIO_H
15
16struct bgpio_pdata {
17 int base;
18};
19
20#endif /* __BASIC_MMIO_GPIO_H */
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 709dfb901d11..ed4ba111bc8d 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -154,6 +154,10 @@ enum {
154 * A thread in rmdir() is wating for this cgroup. 154 * A thread in rmdir() is wating for this cgroup.
155 */ 155 */
156 CGRP_WAIT_ON_RMDIR, 156 CGRP_WAIT_ON_RMDIR,
157 /*
158 * Clone cgroup values when creating a new child cgroup
159 */
160 CGRP_CLONE_CHILDREN,
157}; 161};
158 162
159/* which pidlist file are we talking about? */ 163/* which pidlist file are we talking about? */
diff --git a/include/linux/connector.h b/include/linux/connector.h
index 3a779ffba60b..7e8ca75d2dad 100644
--- a/include/linux/connector.h
+++ b/include/linux/connector.h
@@ -88,12 +88,6 @@ struct cn_queue_dev {
88 unsigned char name[CN_CBQ_NAMELEN]; 88 unsigned char name[CN_CBQ_NAMELEN];
89 89
90 struct workqueue_struct *cn_queue; 90 struct workqueue_struct *cn_queue;
91 /* Sent to kevent to create cn_queue only when needed */
92 struct work_struct wq_creation;
93 /* Tell if the wq_creation job is pending/completed */
94 atomic_t wq_requested;
95 /* Wait for cn_queue to be created */
96 wait_queue_head_t wq_created;
97 91
98 struct list_head queue_list; 92 struct list_head queue_list;
99 spinlock_t queue_lock; 93 spinlock_t queue_lock;
@@ -141,8 +135,6 @@ int cn_netlink_send(struct cn_msg *, u32, gfp_t);
141int cn_queue_add_callback(struct cn_queue_dev *dev, char *name, struct cb_id *id, void (*callback)(struct cn_msg *, struct netlink_skb_parms *)); 135int cn_queue_add_callback(struct cn_queue_dev *dev, char *name, struct cb_id *id, void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
142void cn_queue_del_callback(struct cn_queue_dev *dev, struct cb_id *id); 136void cn_queue_del_callback(struct cn_queue_dev *dev, struct cb_id *id);
143 137
144int queue_cn_work(struct cn_callback_entry *cbq, struct work_struct *work);
145
146struct cn_queue_dev *cn_queue_alloc_dev(char *name, struct sock *); 138struct cn_queue_dev *cn_queue_alloc_dev(char *name, struct sock *);
147void cn_queue_free_dev(struct cn_queue_dev *dev); 139void cn_queue_free_dev(struct cn_queue_dev *dev);
148 140
diff --git a/include/linux/fb.h b/include/linux/fb.h
index f0268deca658..7fca3dc4e475 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -931,6 +931,8 @@ static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
931#define fb_writel sbus_writel 931#define fb_writel sbus_writel
932#define fb_writeq sbus_writeq 932#define fb_writeq sbus_writeq
933#define fb_memset sbus_memset_io 933#define fb_memset sbus_memset_io
934#define fb_memcpy_fromfb sbus_memcpy_fromio
935#define fb_memcpy_tofb sbus_memcpy_toio
934 936
935#elif defined(__i386__) || defined(__alpha__) || defined(__x86_64__) || defined(__hppa__) || defined(__sh__) || defined(__powerpc__) || defined(__avr32__) || defined(__bfin__) 937#elif defined(__i386__) || defined(__alpha__) || defined(__x86_64__) || defined(__hppa__) || defined(__sh__) || defined(__powerpc__) || defined(__avr32__) || defined(__bfin__)
936 938
@@ -943,6 +945,8 @@ static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
943#define fb_writel __raw_writel 945#define fb_writel __raw_writel
944#define fb_writeq __raw_writeq 946#define fb_writeq __raw_writeq
945#define fb_memset memset_io 947#define fb_memset memset_io
948#define fb_memcpy_fromfb memcpy_fromio
949#define fb_memcpy_tofb memcpy_toio
946 950
947#else 951#else
948 952
@@ -955,6 +959,8 @@ static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
955#define fb_writel(b,addr) (*(volatile u32 *) (addr) = (b)) 959#define fb_writel(b,addr) (*(volatile u32 *) (addr) = (b))
956#define fb_writeq(b,addr) (*(volatile u64 *) (addr) = (b)) 960#define fb_writeq(b,addr) (*(volatile u64 *) (addr) = (b))
957#define fb_memset memset 961#define fb_memset memset
962#define fb_memcpy_fromfb memcpy
963#define fb_memcpy_tofb memcpy
958 964
959#endif 965#endif
960 966
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 240eb1d4f876..b2a6009cba10 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1122,6 +1122,7 @@ extern int fcntl_getlease(struct file *filp);
1122 1122
1123/* fs/locks.c */ 1123/* fs/locks.c */
1124extern void locks_init_lock(struct file_lock *); 1124extern void locks_init_lock(struct file_lock *);
1125extern struct file_lock * locks_alloc_lock(void);
1125extern void locks_copy_lock(struct file_lock *, struct file_lock *); 1126extern void locks_copy_lock(struct file_lock *, struct file_lock *);
1126extern void __locks_copy_lock(struct file_lock *, const struct file_lock *); 1127extern void __locks_copy_lock(struct file_lock *, const struct file_lock *);
1127extern void locks_remove_posix(struct file *, fl_owner_t); 1128extern void locks_remove_posix(struct file *, fl_owner_t);
@@ -1310,6 +1311,11 @@ struct fasync_struct {
1310 1311
1311/* SMP safe fasync helpers: */ 1312/* SMP safe fasync helpers: */
1312extern int fasync_helper(int, struct file *, int, struct fasync_struct **); 1313extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
1314extern struct fasync_struct *fasync_insert_entry(int, struct file *, struct fasync_struct **, struct fasync_struct *);
1315extern int fasync_remove_entry(struct file *, struct fasync_struct **);
1316extern struct fasync_struct *fasync_alloc(void);
1317extern void fasync_free(struct fasync_struct *);
1318
1313/* can be called from interrupts */ 1319/* can be called from interrupts */
1314extern void kill_fasync(struct fasync_struct **, int, int); 1320extern void kill_fasync(struct fasync_struct **, int, int);
1315 1321
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 8a85ec109a3a..e9138198e823 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -37,27 +37,6 @@ extern unsigned long totalhigh_pages;
37 37
38void kmap_flush_unused(void); 38void kmap_flush_unused(void);
39 39
40DECLARE_PER_CPU(int, __kmap_atomic_idx);
41
42static inline int kmap_atomic_idx_push(void)
43{
44 int idx = __get_cpu_var(__kmap_atomic_idx)++;
45#ifdef CONFIG_DEBUG_HIGHMEM
46 WARN_ON_ONCE(in_irq() && !irqs_disabled());
47 BUG_ON(idx > KM_TYPE_NR);
48#endif
49 return idx;
50}
51
52static inline int kmap_atomic_idx_pop(void)
53{
54 int idx = --__get_cpu_var(__kmap_atomic_idx);
55#ifdef CONFIG_DEBUG_HIGHMEM
56 BUG_ON(idx < 0);
57#endif
58 return idx;
59}
60
61#else /* CONFIG_HIGHMEM */ 40#else /* CONFIG_HIGHMEM */
62 41
63static inline unsigned int nr_free_highpages(void) { return 0; } 42static inline unsigned int nr_free_highpages(void) { return 0; }
@@ -95,6 +74,36 @@ static inline void __kunmap_atomic(void *addr)
95 74
96#endif /* CONFIG_HIGHMEM */ 75#endif /* CONFIG_HIGHMEM */
97 76
77#if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
78
79DECLARE_PER_CPU(int, __kmap_atomic_idx);
80
81static inline int kmap_atomic_idx_push(void)
82{
83 int idx = __get_cpu_var(__kmap_atomic_idx)++;
84#ifdef CONFIG_DEBUG_HIGHMEM
85 WARN_ON_ONCE(in_irq() && !irqs_disabled());
86 BUG_ON(idx > KM_TYPE_NR);
87#endif
88 return idx;
89}
90
91static inline int kmap_atomic_idx(void)
92{
93 return __get_cpu_var(__kmap_atomic_idx) - 1;
94}
95
96static inline int kmap_atomic_idx_pop(void)
97{
98 int idx = --__get_cpu_var(__kmap_atomic_idx);
99#ifdef CONFIG_DEBUG_HIGHMEM
100 BUG_ON(idx < 0);
101#endif
102 return idx;
103}
104
105#endif
106
98/* 107/*
99 * Make both: kmap_atomic(page, idx) and kmap_atomic(page) work. 108 * Make both: kmap_atomic(page, idx) and kmap_atomic(page) work.
100 */ 109 */
diff --git a/include/linux/i2c/adp5588.h b/include/linux/i2c/adp5588.h
index 269181b8f623..3c5d6b6e765c 100644
--- a/include/linux/i2c/adp5588.h
+++ b/include/linux/i2c/adp5588.h
@@ -74,6 +74,20 @@
74 74
75#define ADP5588_DEVICE_ID_MASK 0xF 75#define ADP5588_DEVICE_ID_MASK 0xF
76 76
77 /* Configuration Register1 */
78#define ADP5588_AUTO_INC (1 << 7)
79#define ADP5588_GPIEM_CFG (1 << 6)
80#define ADP5588_INT_CFG (1 << 4)
81#define ADP5588_GPI_IEN (1 << 1)
82
83/* Interrupt Status Register */
84#define ADP5588_GPI_INT (1 << 1)
85#define ADP5588_KE_INT (1 << 0)
86
87#define ADP5588_MAXGPIO 18
88#define ADP5588_BANK(offs) ((offs) >> 3)
89#define ADP5588_BIT(offs) (1u << ((offs) & 0x7))
90
77/* Put one of these structures in i2c_board_info platform_data */ 91/* Put one of these structures in i2c_board_info platform_data */
78 92
79#define ADP5588_KEYMAPSIZE 80 93#define ADP5588_KEYMAPSIZE 80
@@ -126,9 +140,12 @@ struct adp5588_kpad_platform_data {
126 const struct adp5588_gpio_platform_data *gpio_data; 140 const struct adp5588_gpio_platform_data *gpio_data;
127}; 141};
128 142
143struct i2c_client; /* forward declaration */
144
129struct adp5588_gpio_platform_data { 145struct adp5588_gpio_platform_data {
130 unsigned gpio_start; /* GPIO Chip base # */ 146 int gpio_start; /* GPIO Chip base # */
131 unsigned pullup_dis_mask; /* Pull-Up Disable Mask */ 147 unsigned irq_base; /* interrupt base # */
148 unsigned pullup_dis_mask; /* Pull-Up Disable Mask */
132 int (*setup)(struct i2c_client *client, 149 int (*setup)(struct i2c_client *client,
133 int gpio, unsigned ngpio, 150 int gpio, unsigned ngpio,
134 void *context); 151 void *context);
diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index 2fea6c8ef6ba..1f8c06ce0fa6 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -29,6 +29,8 @@ extern struct fs_struct init_fs;
29 .running = 0, \ 29 .running = 0, \
30 .lock = __SPIN_LOCK_UNLOCKED(sig.cputimer.lock), \ 30 .lock = __SPIN_LOCK_UNLOCKED(sig.cputimer.lock), \
31 }, \ 31 }, \
32 .cred_guard_mutex = \
33 __MUTEX_INITIALIZER(sig.cred_guard_mutex), \
32} 34}
33 35
34extern struct nsproxy init_nsproxy; 36extern struct nsproxy init_nsproxy;
@@ -145,8 +147,6 @@ extern struct cred init_cred;
145 .group_leader = &tsk, \ 147 .group_leader = &tsk, \
146 RCU_INIT_POINTER(.real_cred, &init_cred), \ 148 RCU_INIT_POINTER(.real_cred, &init_cred), \
147 RCU_INIT_POINTER(.cred, &init_cred), \ 149 RCU_INIT_POINTER(.cred, &init_cred), \
148 .cred_guard_mutex = \
149 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
150 .comm = "swapper", \ 150 .comm = "swapper", \
151 .thread = INIT_THREAD, \ 151 .thread = INIT_THREAD, \
152 .fs = &init_fs, \ 152 .fs = &init_fs, \
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 01b281646251..79d0c4f6d071 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -410,7 +410,7 @@ extern void open_softirq(int nr, void (*action)(struct softirq_action *));
410extern void softirq_init(void); 410extern void softirq_init(void);
411static inline void __raise_softirq_irqoff(unsigned int nr) 411static inline void __raise_softirq_irqoff(unsigned int nr)
412{ 412{
413 trace_softirq_raise((struct softirq_action *)(unsigned long)nr, NULL); 413 trace_softirq_raise(nr);
414 or_softirq_pending(1UL << nr); 414 or_softirq_pending(1UL << nr);
415} 415}
416 416
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index c059044bc6dc..ad54c846911b 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -33,6 +33,7 @@ struct kernel_stat {
33#ifndef CONFIG_GENERIC_HARDIRQS 33#ifndef CONFIG_GENERIC_HARDIRQS
34 unsigned int irqs[NR_IRQS]; 34 unsigned int irqs[NR_IRQS];
35#endif 35#endif
36 unsigned long irqs_sum;
36 unsigned int softirqs[NR_SOFTIRQS]; 37 unsigned int softirqs[NR_SOFTIRQS];
37}; 38};
38 39
@@ -54,6 +55,7 @@ static inline void kstat_incr_irqs_this_cpu(unsigned int irq,
54 struct irq_desc *desc) 55 struct irq_desc *desc)
55{ 56{
56 kstat_this_cpu.irqs[irq]++; 57 kstat_this_cpu.irqs[irq]++;
58 kstat_this_cpu.irqs_sum++;
57} 59}
58 60
59static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) 61static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
@@ -65,8 +67,9 @@ static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
65extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu); 67extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu);
66#define kstat_irqs_this_cpu(DESC) \ 68#define kstat_irqs_this_cpu(DESC) \
67 ((DESC)->kstat_irqs[smp_processor_id()]) 69 ((DESC)->kstat_irqs[smp_processor_id()])
68#define kstat_incr_irqs_this_cpu(irqno, DESC) \ 70#define kstat_incr_irqs_this_cpu(irqno, DESC) do {\
69 ((DESC)->kstat_irqs[smp_processor_id()]++) 71 ((DESC)->kstat_irqs[smp_processor_id()]++);\
72 kstat_this_cpu.irqs_sum++; } while (0)
70 73
71#endif 74#endif
72 75
@@ -83,6 +86,7 @@ static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu)
83/* 86/*
84 * Number of interrupts per specific IRQ source, since bootup 87 * Number of interrupts per specific IRQ source, since bootup
85 */ 88 */
89#ifndef CONFIG_GENERIC_HARDIRQS
86static inline unsigned int kstat_irqs(unsigned int irq) 90static inline unsigned int kstat_irqs(unsigned int irq)
87{ 91{
88 unsigned int sum = 0; 92 unsigned int sum = 0;
@@ -93,7 +97,17 @@ static inline unsigned int kstat_irqs(unsigned int irq)
93 97
94 return sum; 98 return sum;
95} 99}
100#else
101extern unsigned int kstat_irqs(unsigned int irq);
102#endif
96 103
104/*
105 * Number of interrupts per cpu, since bootup
106 */
107static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
108{
109 return kstat_cpu(cpu).irqs_sum;
110}
97 111
98/* 112/*
99 * Lock/unlock the current runqueue - to extract task statistics: 113 * Lock/unlock the current runqueue - to extract task statistics:
diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
index c238ad2f82ea..10308c6a3d1c 100644
--- a/include/linux/kfifo.h
+++ b/include/linux/kfifo.h
@@ -171,8 +171,17 @@ struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void);
171 } 171 }
172 172
173 173
174/* __kfifo_must_check_helper() is temporarily disabled because it was faulty */ 174static inline unsigned int __must_check
175#define __kfifo_must_check_helper(x) (x) 175__kfifo_uint_must_check_helper(unsigned int val)
176{
177 return val;
178}
179
180static inline int __must_check
181__kfifo_int_must_check_helper(int val)
182{
183 return val;
184}
176 185
177/** 186/**
178 * kfifo_initialized - Check if the fifo is initialized 187 * kfifo_initialized - Check if the fifo is initialized
@@ -264,7 +273,7 @@ struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void);
264 * @fifo: address of the fifo to be used 273 * @fifo: address of the fifo to be used
265 */ 274 */
266#define kfifo_avail(fifo) \ 275#define kfifo_avail(fifo) \
267__kfifo_must_check_helper( \ 276__kfifo_uint_must_check_helper( \
268({ \ 277({ \
269 typeof((fifo) + 1) __tmpq = (fifo); \ 278 typeof((fifo) + 1) __tmpq = (fifo); \
270 const size_t __recsize = sizeof(*__tmpq->rectype); \ 279 const size_t __recsize = sizeof(*__tmpq->rectype); \
@@ -297,7 +306,7 @@ __kfifo_must_check_helper( \
297 * This function returns the size of the next fifo record in number of bytes. 306 * This function returns the size of the next fifo record in number of bytes.
298 */ 307 */
299#define kfifo_peek_len(fifo) \ 308#define kfifo_peek_len(fifo) \
300__kfifo_must_check_helper( \ 309__kfifo_uint_must_check_helper( \
301({ \ 310({ \
302 typeof((fifo) + 1) __tmp = (fifo); \ 311 typeof((fifo) + 1) __tmp = (fifo); \
303 const size_t __recsize = sizeof(*__tmp->rectype); \ 312 const size_t __recsize = sizeof(*__tmp->rectype); \
@@ -320,7 +329,7 @@ __kfifo_must_check_helper( \
320 * Return 0 if no error, otherwise an error code. 329 * Return 0 if no error, otherwise an error code.
321 */ 330 */
322#define kfifo_alloc(fifo, size, gfp_mask) \ 331#define kfifo_alloc(fifo, size, gfp_mask) \
323__kfifo_must_check_helper( \ 332__kfifo_int_must_check_helper( \
324({ \ 333({ \
325 typeof((fifo) + 1) __tmp = (fifo); \ 334 typeof((fifo) + 1) __tmp = (fifo); \
326 struct __kfifo *__kfifo = &__tmp->kfifo; \ 335 struct __kfifo *__kfifo = &__tmp->kfifo; \
@@ -416,7 +425,7 @@ __kfifo_must_check_helper( \
416 * writer, you don't need extra locking to use these macro. 425 * writer, you don't need extra locking to use these macro.
417 */ 426 */
418#define kfifo_get(fifo, val) \ 427#define kfifo_get(fifo, val) \
419__kfifo_must_check_helper( \ 428__kfifo_uint_must_check_helper( \
420({ \ 429({ \
421 typeof((fifo) + 1) __tmp = (fifo); \ 430 typeof((fifo) + 1) __tmp = (fifo); \
422 typeof((val) + 1) __val = (val); \ 431 typeof((val) + 1) __val = (val); \
@@ -457,7 +466,7 @@ __kfifo_must_check_helper( \
457 * writer, you don't need extra locking to use these macro. 466 * writer, you don't need extra locking to use these macro.
458 */ 467 */
459#define kfifo_peek(fifo, val) \ 468#define kfifo_peek(fifo, val) \
460__kfifo_must_check_helper( \ 469__kfifo_uint_must_check_helper( \
461({ \ 470({ \
462 typeof((fifo) + 1) __tmp = (fifo); \ 471 typeof((fifo) + 1) __tmp = (fifo); \
463 typeof((val) + 1) __val = (val); \ 472 typeof((val) + 1) __val = (val); \
@@ -549,7 +558,7 @@ __kfifo_must_check_helper( \
549 * writer, you don't need extra locking to use these macro. 558 * writer, you don't need extra locking to use these macro.
550 */ 559 */
551#define kfifo_out(fifo, buf, n) \ 560#define kfifo_out(fifo, buf, n) \
552__kfifo_must_check_helper( \ 561__kfifo_uint_must_check_helper( \
553({ \ 562({ \
554 typeof((fifo) + 1) __tmp = (fifo); \ 563 typeof((fifo) + 1) __tmp = (fifo); \
555 typeof((buf) + 1) __buf = (buf); \ 564 typeof((buf) + 1) __buf = (buf); \
@@ -577,7 +586,7 @@ __kfifo_must_check_helper( \
577 * copied. 586 * copied.
578 */ 587 */
579#define kfifo_out_spinlocked(fifo, buf, n, lock) \ 588#define kfifo_out_spinlocked(fifo, buf, n, lock) \
580__kfifo_must_check_helper( \ 589__kfifo_uint_must_check_helper( \
581({ \ 590({ \
582 unsigned long __flags; \ 591 unsigned long __flags; \
583 unsigned int __ret; \ 592 unsigned int __ret; \
@@ -606,7 +615,7 @@ __kfifo_must_check_helper( \
606 * writer, you don't need extra locking to use these macro. 615 * writer, you don't need extra locking to use these macro.
607 */ 616 */
608#define kfifo_from_user(fifo, from, len, copied) \ 617#define kfifo_from_user(fifo, from, len, copied) \
609__kfifo_must_check_helper( \ 618__kfifo_uint_must_check_helper( \
610({ \ 619({ \
611 typeof((fifo) + 1) __tmp = (fifo); \ 620 typeof((fifo) + 1) __tmp = (fifo); \
612 const void __user *__from = (from); \ 621 const void __user *__from = (from); \
@@ -634,7 +643,7 @@ __kfifo_must_check_helper( \
634 * writer, you don't need extra locking to use these macro. 643 * writer, you don't need extra locking to use these macro.
635 */ 644 */
636#define kfifo_to_user(fifo, to, len, copied) \ 645#define kfifo_to_user(fifo, to, len, copied) \
637__kfifo_must_check_helper( \ 646__kfifo_uint_must_check_helper( \
638({ \ 647({ \
639 typeof((fifo) + 1) __tmp = (fifo); \ 648 typeof((fifo) + 1) __tmp = (fifo); \
640 void __user *__to = (to); \ 649 void __user *__to = (to); \
@@ -761,7 +770,7 @@ __kfifo_must_check_helper( \
761 * writer, you don't need extra locking to use these macro. 770 * writer, you don't need extra locking to use these macro.
762 */ 771 */
763#define kfifo_out_peek(fifo, buf, n) \ 772#define kfifo_out_peek(fifo, buf, n) \
764__kfifo_must_check_helper( \ 773__kfifo_uint_must_check_helper( \
765({ \ 774({ \
766 typeof((fifo) + 1) __tmp = (fifo); \ 775 typeof((fifo) + 1) __tmp = (fifo); \
767 typeof((buf) + 1) __buf = (buf); \ 776 typeof((buf) + 1) __buf = (buf); \
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index fcd3dda86322..072652d94d9f 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -585,15 +585,15 @@ static inline void rps_reset_sock_flow(struct rps_sock_flow_table *table,
585 table->ents[hash & table->mask] = RPS_NO_CPU; 585 table->ents[hash & table->mask] = RPS_NO_CPU;
586} 586}
587 587
588extern struct rps_sock_flow_table *rps_sock_flow_table; 588extern struct rps_sock_flow_table __rcu *rps_sock_flow_table;
589 589
590/* This structure contains an instance of an RX queue. */ 590/* This structure contains an instance of an RX queue. */
591struct netdev_rx_queue { 591struct netdev_rx_queue {
592 struct rps_map *rps_map; 592 struct rps_map __rcu *rps_map;
593 struct rps_dev_flow_table *rps_flow_table; 593 struct rps_dev_flow_table __rcu *rps_flow_table;
594 struct kobject kobj; 594 struct kobject kobj;
595 struct netdev_rx_queue *first; 595 struct netdev_rx_queue *first;
596 atomic_t count; 596 atomic_t count;
597} ____cacheline_aligned_in_smp; 597} ____cacheline_aligned_in_smp;
598#endif /* CONFIG_RPS */ 598#endif /* CONFIG_RPS */
599 599
@@ -944,7 +944,7 @@ struct net_device {
944 /* Protocol specific pointers */ 944 /* Protocol specific pointers */
945 945
946#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) 946#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
947 struct vlan_group *vlgrp; /* VLAN group */ 947 struct vlan_group __rcu *vlgrp; /* VLAN group */
948#endif 948#endif
949#ifdef CONFIG_NET_DSA 949#ifdef CONFIG_NET_DSA
950 void *dsa_ptr; /* dsa specific data */ 950 void *dsa_ptr; /* dsa specific data */
@@ -952,7 +952,7 @@ struct net_device {
952 void *atalk_ptr; /* AppleTalk link */ 952 void *atalk_ptr; /* AppleTalk link */
953 struct in_device __rcu *ip_ptr; /* IPv4 specific data */ 953 struct in_device __rcu *ip_ptr; /* IPv4 specific data */
954 void *dn_ptr; /* DECnet specific data */ 954 void *dn_ptr; /* DECnet specific data */
955 void *ip6_ptr; /* IPv6 specific data */ 955 struct inet6_dev __rcu *ip6_ptr; /* IPv6 specific data */
956 void *ec_ptr; /* Econet specific data */ 956 void *ec_ptr; /* Econet specific data */
957 void *ax25_ptr; /* AX.25 specific data */ 957 void *ax25_ptr; /* AX.25 specific data */
958 struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data, 958 struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
@@ -1072,7 +1072,7 @@ struct net_device {
1072 struct pcpu_dstats __percpu *dstats; /* dummy stats */ 1072 struct pcpu_dstats __percpu *dstats; /* dummy stats */
1073 }; 1073 };
1074 /* GARP */ 1074 /* GARP */
1075 struct garp_port *garp_port; 1075 struct garp_port __rcu *garp_port;
1076 1076
1077 /* class/net/name entry */ 1077 /* class/net/name entry */
1078 struct device dev; 1078 struct device dev;
diff --git a/include/linux/percpu-defs.h b/include/linux/percpu-defs.h
index 018db9a62ffe..27ef6b190ea6 100644
--- a/include/linux/percpu-defs.h
+++ b/include/linux/percpu-defs.h
@@ -148,18 +148,6 @@
148 DEFINE_PER_CPU_SECTION(type, name, "..readmostly") 148 DEFINE_PER_CPU_SECTION(type, name, "..readmostly")
149 149
150/* 150/*
151 * Declaration/definition used for large per-CPU variables that must be
152 * aligned to something larger than the pagesize.
153 */
154#define DECLARE_PER_CPU_MULTIPAGE_ALIGNED(type, name, size) \
155 DECLARE_PER_CPU_SECTION(type, name, "..page_aligned") \
156 __aligned(size)
157
158#define DEFINE_PER_CPU_MULTIPAGE_ALIGNED(type, name, size) \
159 DEFINE_PER_CPU_SECTION(type, name, "..page_aligned") \
160 __aligned(size)
161
162/*
163 * Intermodule exports for per-CPU variables. sparse forgets about 151 * Intermodule exports for per-CPU variables. sparse forgets about
164 * address space across EXPORT_SYMBOL(), change EXPORT_SYMBOL() to 152 * address space across EXPORT_SYMBOL(), change EXPORT_SYMBOL() to
165 * noop if __CHECKER__. 153 * noop if __CHECKER__.
diff --git a/include/linux/phy.h b/include/linux/phy.h
index a6e047a04f79..7da5fa845959 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -472,11 +472,7 @@ static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)
472int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id); 472int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id);
473struct phy_device* get_phy_device(struct mii_bus *bus, int addr); 473struct phy_device* get_phy_device(struct mii_bus *bus, int addr);
474int phy_device_register(struct phy_device *phy); 474int phy_device_register(struct phy_device *phy);
475int phy_clear_interrupt(struct phy_device *phydev);
476int phy_config_interrupt(struct phy_device *phydev, u32 interrupts);
477int phy_init_hw(struct phy_device *phydev); 475int phy_init_hw(struct phy_device *phydev);
478int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
479 u32 flags, phy_interface_t interface);
480struct phy_device * phy_attach(struct net_device *dev, 476struct phy_device * phy_attach(struct net_device *dev,
481 const char *bus_id, u32 flags, phy_interface_t interface); 477 const char *bus_id, u32 flags, phy_interface_t interface);
482struct phy_device *phy_find_first(struct mii_bus *bus); 478struct phy_device *phy_find_first(struct mii_bus *bus);
@@ -492,17 +488,12 @@ void phy_start(struct phy_device *phydev);
492void phy_stop(struct phy_device *phydev); 488void phy_stop(struct phy_device *phydev);
493int phy_start_aneg(struct phy_device *phydev); 489int phy_start_aneg(struct phy_device *phydev);
494 490
495void phy_sanitize_settings(struct phy_device *phydev);
496int phy_stop_interrupts(struct phy_device *phydev); 491int phy_stop_interrupts(struct phy_device *phydev);
497int phy_enable_interrupts(struct phy_device *phydev);
498int phy_disable_interrupts(struct phy_device *phydev);
499 492
500static inline int phy_read_status(struct phy_device *phydev) { 493static inline int phy_read_status(struct phy_device *phydev) {
501 return phydev->drv->read_status(phydev); 494 return phydev->drv->read_status(phydev);
502} 495}
503 496
504int genphy_config_advert(struct phy_device *phydev);
505int genphy_setup_forced(struct phy_device *phydev);
506int genphy_restart_aneg(struct phy_device *phydev); 497int genphy_restart_aneg(struct phy_device *phydev);
507int genphy_config_aneg(struct phy_device *phydev); 498int genphy_config_aneg(struct phy_device *phydev);
508int genphy_update_link(struct phy_device *phydev); 499int genphy_update_link(struct phy_device *phydev);
@@ -511,8 +502,6 @@ int genphy_suspend(struct phy_device *phydev);
511int genphy_resume(struct phy_device *phydev); 502int genphy_resume(struct phy_device *phydev);
512void phy_driver_unregister(struct phy_driver *drv); 503void phy_driver_unregister(struct phy_driver *drv);
513int phy_driver_register(struct phy_driver *new_driver); 504int phy_driver_register(struct phy_driver *new_driver);
514void phy_prepare_link(struct phy_device *phydev,
515 void (*adjust_link)(struct net_device *));
516void phy_state_machine(struct work_struct *work); 505void phy_state_machine(struct work_struct *work);
517void phy_start_machine(struct phy_device *phydev, 506void phy_start_machine(struct phy_device *phydev,
518 void (*handler)(struct net_device *)); 507 void (*handler)(struct net_device *));
@@ -523,7 +512,6 @@ int phy_mii_ioctl(struct phy_device *phydev,
523 struct ifreq *ifr, int cmd); 512 struct ifreq *ifr, int cmd);
524int phy_start_interrupts(struct phy_device *phydev); 513int phy_start_interrupts(struct phy_device *phydev);
525void phy_print_status(struct phy_device *phydev); 514void phy_print_status(struct phy_device *phydev);
526struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id);
527void phy_device_free(struct phy_device *phydev); 515void phy_device_free(struct phy_device *phydev);
528 516
529int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask, 517int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
diff --git a/include/linux/poll.h b/include/linux/poll.h
index 600cc1fde64d..56e76af78102 100644
--- a/include/linux/poll.h
+++ b/include/linux/poll.h
@@ -73,6 +73,8 @@ extern void poll_initwait(struct poll_wqueues *pwq);
73extern void poll_freewait(struct poll_wqueues *pwq); 73extern void poll_freewait(struct poll_wqueues *pwq);
74extern int poll_schedule_timeout(struct poll_wqueues *pwq, int state, 74extern int poll_schedule_timeout(struct poll_wqueues *pwq, int state,
75 ktime_t *expires, unsigned long slack); 75 ktime_t *expires, unsigned long slack);
76extern long select_estimate_accuracy(struct timespec *tv);
77
76 78
77static inline int poll_schedule(struct poll_wqueues *pwq, int state) 79static inline int poll_schedule(struct poll_wqueues *pwq, int state)
78{ 80{
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
index 4272521e29e9..092a04f874a8 100644
--- a/include/linux/ptrace.h
+++ b/include/linux/ptrace.h
@@ -100,7 +100,8 @@
100#include <linux/sched.h> /* For struct task_struct. */ 100#include <linux/sched.h> /* For struct task_struct. */
101 101
102 102
103extern long arch_ptrace(struct task_struct *child, long request, long addr, long data); 103extern long arch_ptrace(struct task_struct *child, long request,
104 unsigned long addr, unsigned long data);
104extern int ptrace_traceme(void); 105extern int ptrace_traceme(void);
105extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len); 106extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len);
106extern int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len); 107extern int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len);
@@ -108,7 +109,8 @@ extern int ptrace_attach(struct task_struct *tsk);
108extern int ptrace_detach(struct task_struct *, unsigned int); 109extern int ptrace_detach(struct task_struct *, unsigned int);
109extern void ptrace_disable(struct task_struct *); 110extern void ptrace_disable(struct task_struct *);
110extern int ptrace_check_attach(struct task_struct *task, int kill); 111extern int ptrace_check_attach(struct task_struct *task, int kill);
111extern int ptrace_request(struct task_struct *child, long request, long addr, long data); 112extern int ptrace_request(struct task_struct *child, long request,
113 unsigned long addr, unsigned long data);
112extern void ptrace_notify(int exit_code); 114extern void ptrace_notify(int exit_code);
113extern void __ptrace_link(struct task_struct *child, 115extern void __ptrace_link(struct task_struct *child,
114 struct task_struct *new_parent); 116 struct task_struct *new_parent);
@@ -132,8 +134,10 @@ static inline void ptrace_unlink(struct task_struct *child)
132 __ptrace_unlink(child); 134 __ptrace_unlink(child);
133} 135}
134 136
135int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data); 137int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
136int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data); 138 unsigned long data);
139int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
140 unsigned long data);
137 141
138/** 142/**
139 * task_ptrace - return %PT_* flags that apply to a task 143 * task_ptrace - return %PT_* flags that apply to a task
diff --git a/include/linux/ramoops.h b/include/linux/ramoops.h
new file mode 100644
index 000000000000..0ae68a2c1212
--- /dev/null
+++ b/include/linux/ramoops.h
@@ -0,0 +1,15 @@
1#ifndef __RAMOOPS_H
2#define __RAMOOPS_H
3
4/*
5 * Ramoops platform data
6 * @mem_size memory size for ramoops
7 * @mem_address physical memory address to contain ramoops
8 */
9
10struct ramoops_platform_data {
11 unsigned long mem_size;
12 unsigned long mem_address;
13};
14
15#endif
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
index 25b4f686d918..8d3a2486544d 100644
--- a/include/linux/ring_buffer.h
+++ b/include/linux/ring_buffer.h
@@ -62,18 +62,6 @@ enum ring_buffer_type {
62unsigned ring_buffer_event_length(struct ring_buffer_event *event); 62unsigned ring_buffer_event_length(struct ring_buffer_event *event);
63void *ring_buffer_event_data(struct ring_buffer_event *event); 63void *ring_buffer_event_data(struct ring_buffer_event *event);
64 64
65/**
66 * ring_buffer_event_time_delta - return the delta timestamp of the event
67 * @event: the event to get the delta timestamp of
68 *
69 * The delta timestamp is the 27 bit timestamp since the last event.
70 */
71static inline unsigned
72ring_buffer_event_time_delta(struct ring_buffer_event *event)
73{
74 return event->time_delta;
75}
76
77/* 65/*
78 * ring_buffer_discard_commit will remove an event that has not 66 * ring_buffer_discard_commit will remove an event that has not
79 * ben committed yet. If this is used, then ring_buffer_unlock_commit 67 * ben committed yet. If this is used, then ring_buffer_unlock_commit
diff --git a/include/linux/rio.h b/include/linux/rio.h
index bd6eb0ed34a7..0bed941f9b13 100644
--- a/include/linux/rio.h
+++ b/include/linux/rio.h
@@ -67,6 +67,7 @@
67#define RIO_PW_MSG_SIZE 64 67#define RIO_PW_MSG_SIZE 64
68 68
69extern struct bus_type rio_bus_type; 69extern struct bus_type rio_bus_type;
70extern struct device rio_bus;
70extern struct list_head rio_devices; /* list of all devices */ 71extern struct list_head rio_devices; /* list of all devices */
71 72
72struct rio_mport; 73struct rio_mport;
@@ -98,6 +99,7 @@ union rio_pw_msg;
98 * @riores: RIO resources this device owns 99 * @riores: RIO resources this device owns
99 * @pwcback: port-write callback function for this device 100 * @pwcback: port-write callback function for this device
100 * @destid: Network destination ID 101 * @destid: Network destination ID
102 * @prev: Previous RIO device connected to the current one
101 */ 103 */
102struct rio_dev { 104struct rio_dev {
103 struct list_head global_list; /* node in list of all RIO devices */ 105 struct list_head global_list; /* node in list of all RIO devices */
@@ -111,7 +113,7 @@ struct rio_dev {
111 u16 asm_rev; 113 u16 asm_rev;
112 u16 efptr; 114 u16 efptr;
113 u32 pef; 115 u32 pef;
114 u32 swpinfo; /* Only used for switches */ 116 u32 swpinfo;
115 u32 src_ops; 117 u32 src_ops;
116 u32 dst_ops; 118 u32 dst_ops;
117 u32 comp_tag; 119 u32 comp_tag;
@@ -124,6 +126,7 @@ struct rio_dev {
124 struct resource riores[RIO_MAX_DEV_RESOURCES]; 126 struct resource riores[RIO_MAX_DEV_RESOURCES];
125 int (*pwcback) (struct rio_dev *rdev, union rio_pw_msg *msg, int step); 127 int (*pwcback) (struct rio_dev *rdev, union rio_pw_msg *msg, int step);
126 u16 destid; 128 u16 destid;
129 struct rio_dev *prev;
127}; 130};
128 131
129#define rio_dev_g(n) list_entry(n, struct rio_dev, global_list) 132#define rio_dev_g(n) list_entry(n, struct rio_dev, global_list)
@@ -174,6 +177,7 @@ enum rio_phy_type {
174 * @index: Port index, unique among all port interfaces of the same type 177 * @index: Port index, unique among all port interfaces of the same type
175 * @sys_size: RapidIO common transport system size 178 * @sys_size: RapidIO common transport system size
176 * @phy_type: RapidIO phy type 179 * @phy_type: RapidIO phy type
180 * @phys_efptr: RIO port extended features pointer
177 * @name: Port name string 181 * @name: Port name string
178 * @priv: Master port private data 182 * @priv: Master port private data
179 */ 183 */
@@ -195,6 +199,7 @@ struct rio_mport {
195 * 1 - Large size, 65536 devices. 199 * 1 - Large size, 65536 devices.
196 */ 200 */
197 enum rio_phy_type phy_type; /* RapidIO phy type */ 201 enum rio_phy_type phy_type; /* RapidIO phy type */
202 u32 phys_efptr;
198 unsigned char name[40]; 203 unsigned char name[40];
199 void *priv; /* Master port private data */ 204 void *priv; /* Master port private data */
200}; 205};
@@ -215,9 +220,14 @@ struct rio_net {
215 unsigned char id; /* RIO network ID */ 220 unsigned char id; /* RIO network ID */
216}; 221};
217 222
223/* Definitions used by switch sysfs initialization callback */
224#define RIO_SW_SYSFS_CREATE 1 /* Create switch attributes */
225#define RIO_SW_SYSFS_REMOVE 0 /* Remove switch attributes */
226
218/** 227/**
219 * struct rio_switch - RIO switch info 228 * struct rio_switch - RIO switch info
220 * @node: Node in global list of switches 229 * @node: Node in global list of switches
230 * @rdev: Associated RIO device structure
221 * @switchid: Switch ID that is unique across a network 231 * @switchid: Switch ID that is unique across a network
222 * @hopcount: Hopcount to this switch 232 * @hopcount: Hopcount to this switch
223 * @destid: Associated destid in the path 233 * @destid: Associated destid in the path
@@ -230,9 +240,12 @@ struct rio_net {
230 * @get_domain: Callback for switch-specific domain get function 240 * @get_domain: Callback for switch-specific domain get function
231 * @em_init: Callback for switch-specific error management initialization function 241 * @em_init: Callback for switch-specific error management initialization function
232 * @em_handle: Callback for switch-specific error management handler function 242 * @em_handle: Callback for switch-specific error management handler function
243 * @sw_sysfs: Callback that initializes switch-specific sysfs attributes
244 * @nextdev: Array of per-port pointers to the next attached device
233 */ 245 */
234struct rio_switch { 246struct rio_switch {
235 struct list_head node; 247 struct list_head node;
248 struct rio_dev *rdev;
236 u16 switchid; 249 u16 switchid;
237 u16 hopcount; 250 u16 hopcount;
238 u16 destid; 251 u16 destid;
@@ -250,6 +263,8 @@ struct rio_switch {
250 u8 *sw_domain); 263 u8 *sw_domain);
251 int (*em_init) (struct rio_dev *dev); 264 int (*em_init) (struct rio_dev *dev);
252 int (*em_handle) (struct rio_dev *dev, u8 swport); 265 int (*em_handle) (struct rio_dev *dev, u8 swport);
266 int (*sw_sysfs) (struct rio_dev *dev, int create);
267 struct rio_dev *nextdev[0];
253}; 268};
254 269
255/* Low-level architecture-dependent routines */ 270/* Low-level architecture-dependent routines */
diff --git a/include/linux/rio_ids.h b/include/linux/rio_ids.h
index db50e1c288b7..ee7b6ada188f 100644
--- a/include/linux/rio_ids.h
+++ b/include/linux/rio_ids.h
@@ -34,5 +34,7 @@
34#define RIO_DID_IDTCPS16 0x035b 34#define RIO_DID_IDTCPS16 0x035b
35#define RIO_DID_IDTCPS6Q 0x035f 35#define RIO_DID_IDTCPS6Q 0x035f
36#define RIO_DID_IDTCPS10Q 0x035e 36#define RIO_DID_IDTCPS10Q 0x035e
37#define RIO_DID_IDTCPS1848 0x0374
38#define RIO_DID_IDTCPS1616 0x0379
37 39
38#endif /* LINUX_RIO_IDS_H */ 40#endif /* LINUX_RIO_IDS_H */
diff --git a/include/linux/rio_regs.h b/include/linux/rio_regs.h
index aedee0489fb4..d63dcbaea169 100644
--- a/include/linux/rio_regs.h
+++ b/include/linux/rio_regs.h
@@ -33,6 +33,7 @@
33#define RIO_PEF_MEMORY 0x40000000 /* [I] MMIO */ 33#define RIO_PEF_MEMORY 0x40000000 /* [I] MMIO */
34#define RIO_PEF_PROCESSOR 0x20000000 /* [I] Processor */ 34#define RIO_PEF_PROCESSOR 0x20000000 /* [I] Processor */
35#define RIO_PEF_SWITCH 0x10000000 /* [I] Switch */ 35#define RIO_PEF_SWITCH 0x10000000 /* [I] Switch */
36#define RIO_PEF_MULTIPORT 0x08000000 /* [VI, 2.1] Multiport */
36#define RIO_PEF_INB_MBOX 0x00f00000 /* [II] Mailboxes */ 37#define RIO_PEF_INB_MBOX 0x00f00000 /* [II] Mailboxes */
37#define RIO_PEF_INB_MBOX0 0x00800000 /* [II] Mailbox 0 */ 38#define RIO_PEF_INB_MBOX0 0x00800000 /* [II] Mailbox 0 */
38#define RIO_PEF_INB_MBOX1 0x00400000 /* [II] Mailbox 1 */ 39#define RIO_PEF_INB_MBOX1 0x00400000 /* [II] Mailbox 1 */
@@ -51,6 +52,7 @@
51#define RIO_SWP_INFO_PORT_TOTAL_MASK 0x0000ff00 /* [I] Total number of ports */ 52#define RIO_SWP_INFO_PORT_TOTAL_MASK 0x0000ff00 /* [I] Total number of ports */
52#define RIO_SWP_INFO_PORT_NUM_MASK 0x000000ff /* [I] Maintenance transaction port number */ 53#define RIO_SWP_INFO_PORT_NUM_MASK 0x000000ff /* [I] Maintenance transaction port number */
53#define RIO_GET_TOTAL_PORTS(x) ((x & RIO_SWP_INFO_PORT_TOTAL_MASK) >> 8) 54#define RIO_GET_TOTAL_PORTS(x) ((x & RIO_SWP_INFO_PORT_TOTAL_MASK) >> 8)
55#define RIO_GET_PORT_NUM(x) (x & RIO_SWP_INFO_PORT_NUM_MASK)
54 56
55#define RIO_SRC_OPS_CAR 0x18 /* [I] Source Operations CAR */ 57#define RIO_SRC_OPS_CAR 0x18 /* [I] Source Operations CAR */
56#define RIO_SRC_OPS_READ 0x00008000 /* [I] Read op */ 58#define RIO_SRC_OPS_READ 0x00008000 /* [I] Read op */
@@ -159,6 +161,7 @@
159#define RIO_COMPONENT_TAG_CSR 0x6c /* [III] Component Tag CSR */ 161#define RIO_COMPONENT_TAG_CSR 0x6c /* [III] Component Tag CSR */
160 162
161#define RIO_STD_RTE_CONF_DESTID_SEL_CSR 0x70 163#define RIO_STD_RTE_CONF_DESTID_SEL_CSR 0x70
164#define RIO_STD_RTE_CONF_EXTCFGEN 0x80000000
162#define RIO_STD_RTE_CONF_PORT_SEL_CSR 0x74 165#define RIO_STD_RTE_CONF_PORT_SEL_CSR 0x74
163#define RIO_STD_RTE_DEFAULT_PORT 0x78 166#define RIO_STD_RTE_DEFAULT_PORT 0x78
164 167
@@ -222,15 +225,17 @@
222#define RIO_PORT_GEN_MASTER 0x40000000 225#define RIO_PORT_GEN_MASTER 0x40000000
223#define RIO_PORT_GEN_DISCOVERED 0x20000000 226#define RIO_PORT_GEN_DISCOVERED 0x20000000
224#define RIO_PORT_N_MNT_REQ_CSR(x) (0x0040 + x*0x20) /* 0x0002 */ 227#define RIO_PORT_N_MNT_REQ_CSR(x) (0x0040 + x*0x20) /* 0x0002 */
228#define RIO_MNT_REQ_CMD_RD 0x03 /* Reset-device command */
229#define RIO_MNT_REQ_CMD_IS 0x04 /* Input-status command */
225#define RIO_PORT_N_MNT_RSP_CSR(x) (0x0044 + x*0x20) /* 0x0002 */ 230#define RIO_PORT_N_MNT_RSP_CSR(x) (0x0044 + x*0x20) /* 0x0002 */
226#define RIO_PORT_N_MNT_RSP_RVAL 0x80000000 /* Response Valid */ 231#define RIO_PORT_N_MNT_RSP_RVAL 0x80000000 /* Response Valid */
227#define RIO_PORT_N_MNT_RSP_ASTAT 0x000003e0 /* ackID Status */ 232#define RIO_PORT_N_MNT_RSP_ASTAT 0x000007e0 /* ackID Status */
228#define RIO_PORT_N_MNT_RSP_LSTAT 0x0000001f /* Link Status */ 233#define RIO_PORT_N_MNT_RSP_LSTAT 0x0000001f /* Link Status */
229#define RIO_PORT_N_ACK_STS_CSR(x) (0x0048 + x*0x20) /* 0x0002 */ 234#define RIO_PORT_N_ACK_STS_CSR(x) (0x0048 + x*0x20) /* 0x0002 */
230#define RIO_PORT_N_ACK_CLEAR 0x80000000 235#define RIO_PORT_N_ACK_CLEAR 0x80000000
231#define RIO_PORT_N_ACK_INBOUND 0x1f000000 236#define RIO_PORT_N_ACK_INBOUND 0x3f000000
232#define RIO_PORT_N_ACK_OUTSTAND 0x00001f00 237#define RIO_PORT_N_ACK_OUTSTAND 0x00003f00
233#define RIO_PORT_N_ACK_OUTBOUND 0x0000001f 238#define RIO_PORT_N_ACK_OUTBOUND 0x0000003f
234#define RIO_PORT_N_ERR_STS_CSR(x) (0x0058 + x*0x20) 239#define RIO_PORT_N_ERR_STS_CSR(x) (0x0058 + x*0x20)
235#define RIO_PORT_N_ERR_STS_PW_OUT_ES 0x00010000 /* Output Error-stopped */ 240#define RIO_PORT_N_ERR_STS_PW_OUT_ES 0x00010000 /* Output Error-stopped */
236#define RIO_PORT_N_ERR_STS_PW_INP_ES 0x00000100 /* Input Error-stopped */ 241#define RIO_PORT_N_ERR_STS_PW_INP_ES 0x00000100 /* Input Error-stopped */
@@ -238,7 +243,6 @@
238#define RIO_PORT_N_ERR_STS_PORT_ERR 0x00000004 243#define RIO_PORT_N_ERR_STS_PORT_ERR 0x00000004
239#define RIO_PORT_N_ERR_STS_PORT_OK 0x00000002 244#define RIO_PORT_N_ERR_STS_PORT_OK 0x00000002
240#define RIO_PORT_N_ERR_STS_PORT_UNINIT 0x00000001 245#define RIO_PORT_N_ERR_STS_PORT_UNINIT 0x00000001
241#define RIO_PORT_N_ERR_STS_CLR_MASK 0x07120204
242#define RIO_PORT_N_CTL_CSR(x) (0x005c + x*0x20) 246#define RIO_PORT_N_CTL_CSR(x) (0x005c + x*0x20)
243#define RIO_PORT_N_CTL_PWIDTH 0xc0000000 247#define RIO_PORT_N_CTL_PWIDTH 0xc0000000
244#define RIO_PORT_N_CTL_PWIDTH_1 0x00000000 248#define RIO_PORT_N_CTL_PWIDTH_1 0x00000000
@@ -261,6 +265,10 @@
261#define RIO_EM_EFB_HEADER 0x000 /* Error Management Extensions Block Header */ 265#define RIO_EM_EFB_HEADER 0x000 /* Error Management Extensions Block Header */
262#define RIO_EM_LTL_ERR_DETECT 0x008 /* Logical/Transport Layer Error Detect CSR */ 266#define RIO_EM_LTL_ERR_DETECT 0x008 /* Logical/Transport Layer Error Detect CSR */
263#define RIO_EM_LTL_ERR_EN 0x00c /* Logical/Transport Layer Error Enable CSR */ 267#define RIO_EM_LTL_ERR_EN 0x00c /* Logical/Transport Layer Error Enable CSR */
268#define REM_LTL_ERR_ILLTRAN 0x08000000 /* Illegal Transaction decode */
269#define REM_LTL_ERR_UNSOLR 0x00800000 /* Unsolicited Response */
270#define REM_LTL_ERR_UNSUPTR 0x00400000 /* Unsupported Transaction */
271#define REM_LTL_ERR_IMPSPEC 0x000000ff /* Implementation Specific */
264#define RIO_EM_LTL_HIADDR_CAP 0x010 /* Logical/Transport Layer High Address Capture CSR */ 272#define RIO_EM_LTL_HIADDR_CAP 0x010 /* Logical/Transport Layer High Address Capture CSR */
265#define RIO_EM_LTL_ADDR_CAP 0x014 /* Logical/Transport Layer Address Capture CSR */ 273#define RIO_EM_LTL_ADDR_CAP 0x014 /* Logical/Transport Layer Address Capture CSR */
266#define RIO_EM_LTL_DEVID_CAP 0x018 /* Logical/Transport Layer Device ID Capture CSR */ 274#define RIO_EM_LTL_DEVID_CAP 0x018 /* Logical/Transport Layer Device ID Capture CSR */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 393ce94e54b7..be7adb7588e5 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -626,6 +626,10 @@ struct signal_struct {
626 626
627 int oom_adj; /* OOM kill score adjustment (bit shift) */ 627 int oom_adj; /* OOM kill score adjustment (bit shift) */
628 int oom_score_adj; /* OOM kill score adjustment */ 628 int oom_score_adj; /* OOM kill score adjustment */
629
630 struct mutex cred_guard_mutex; /* guard against foreign influences on
631 * credential calculations
632 * (notably. ptrace) */
629}; 633};
630 634
631/* Context switch must be unlocked if interrupts are to be enabled */ 635/* Context switch must be unlocked if interrupts are to be enabled */
@@ -1305,9 +1309,6 @@ struct task_struct {
1305 * credentials (COW) */ 1309 * credentials (COW) */
1306 const struct cred __rcu *cred; /* effective (overridable) subjective task 1310 const struct cred __rcu *cred; /* effective (overridable) subjective task
1307 * credentials (COW) */ 1311 * credentials (COW) */
1308 struct mutex cred_guard_mutex; /* guard against foreign influences on
1309 * credential calculations
1310 * (notably. ptrace) */
1311 struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */ 1312 struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
1312 1313
1313 char comm[TASK_COMM_LEN]; /* executable name excluding path 1314 char comm[TASK_COMM_LEN]; /* executable name excluding path
@@ -2236,9 +2237,16 @@ static inline void task_unlock(struct task_struct *p)
2236 spin_unlock(&p->alloc_lock); 2237 spin_unlock(&p->alloc_lock);
2237} 2238}
2238 2239
2239extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk, 2240extern struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
2240 unsigned long *flags); 2241 unsigned long *flags);
2241 2242
2243#define lock_task_sighand(tsk, flags) \
2244({ struct sighand_struct *__ss; \
2245 __cond_lock(&(tsk)->sighand->siglock, \
2246 (__ss = __lock_task_sighand(tsk, flags))); \
2247 __ss; \
2248}) \
2249
2242static inline void unlock_task_sighand(struct task_struct *tsk, 2250static inline void unlock_task_sighand(struct task_struct *tsk,
2243 unsigned long *flags) 2251 unsigned long *flags)
2244{ 2252{
diff --git a/include/linux/spi/74x164.h b/include/linux/spi/74x164.h
new file mode 100644
index 000000000000..d85c52f294a0
--- /dev/null
+++ b/include/linux/spi/74x164.h
@@ -0,0 +1,11 @@
1#ifndef LINUX_SPI_74X164_H
2#define LINUX_SPI_74X164_H
3
4#define GEN_74X164_DRIVER_NAME "74x164"
5
6struct gen_74x164_chip_platform_data {
7 /* number assigned to the first GPIO */
8 unsigned base;
9};
10
11#endif
diff --git a/include/linux/synclink.h b/include/linux/synclink.h
index 0ff2779c44d0..2e7d81c4e5ad 100644
--- a/include/linux/synclink.h
+++ b/include/linux/synclink.h
@@ -126,6 +126,7 @@
126#define MGSL_MODE_BISYNC 4 126#define MGSL_MODE_BISYNC 4
127#define MGSL_MODE_RAW 6 127#define MGSL_MODE_RAW 6
128#define MGSL_MODE_BASE_CLOCK 7 128#define MGSL_MODE_BASE_CLOCK 7
129#define MGSL_MODE_XSYNC 8
129 130
130#define MGSL_BUS_TYPE_ISA 1 131#define MGSL_BUS_TYPE_ISA 1
131#define MGSL_BUS_TYPE_EISA 2 132#define MGSL_BUS_TYPE_EISA 2
@@ -290,6 +291,10 @@ struct gpio_desc {
290#define MGSL_IOCSGPIO _IOW(MGSL_MAGIC_IOC,16,struct gpio_desc) 291#define MGSL_IOCSGPIO _IOW(MGSL_MAGIC_IOC,16,struct gpio_desc)
291#define MGSL_IOCGGPIO _IOR(MGSL_MAGIC_IOC,17,struct gpio_desc) 292#define MGSL_IOCGGPIO _IOR(MGSL_MAGIC_IOC,17,struct gpio_desc)
292#define MGSL_IOCWAITGPIO _IOWR(MGSL_MAGIC_IOC,18,struct gpio_desc) 293#define MGSL_IOCWAITGPIO _IOWR(MGSL_MAGIC_IOC,18,struct gpio_desc)
294#define MGSL_IOCSXSYNC _IO(MGSL_MAGIC_IOC, 19)
295#define MGSL_IOCGXSYNC _IO(MGSL_MAGIC_IOC, 20)
296#define MGSL_IOCSXCTRL _IO(MGSL_MAGIC_IOC, 21)
297#define MGSL_IOCGXCTRL _IO(MGSL_MAGIC_IOC, 22)
293 298
294#ifdef __KERNEL__ 299#ifdef __KERNEL__
295/* provide 32 bit ioctl compatibility on 64 bit systems */ 300/* provide 32 bit ioctl compatibility on 64 bit systems */
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index e6319d18a55d..cacc27a0e285 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -701,7 +701,8 @@ asmlinkage long sys_nfsservctl(int cmd,
701asmlinkage long sys_syslog(int type, char __user *buf, int len); 701asmlinkage long sys_syslog(int type, char __user *buf, int len);
702asmlinkage long sys_uselib(const char __user *library); 702asmlinkage long sys_uselib(const char __user *library);
703asmlinkage long sys_ni_syscall(void); 703asmlinkage long sys_ni_syscall(void);
704asmlinkage long sys_ptrace(long request, long pid, long addr, long data); 704asmlinkage long sys_ptrace(long request, long pid, unsigned long addr,
705 unsigned long data);
705 706
706asmlinkage long sys_add_key(const char __user *_type, 707asmlinkage long sys_add_key(const char __user *_type,
707 const char __user *_description, 708 const char __user *_description,
diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
index 10db0102a890..3a2e66d88a32 100644
--- a/include/linux/tracehook.h
+++ b/include/linux/tracehook.h
@@ -150,7 +150,7 @@ static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
150 * 150 *
151 * Return %LSM_UNSAFE_* bits applied to an exec because of tracing. 151 * Return %LSM_UNSAFE_* bits applied to an exec because of tracing.
152 * 152 *
153 * @task->cred_guard_mutex is held by the caller through the do_execve(). 153 * @task->signal->cred_guard_mutex is held by the caller through the do_execve().
154 */ 154 */
155static inline int tracehook_unsafe_exec(struct task_struct *task) 155static inline int tracehook_unsafe_exec(struct task_struct *task)
156{ 156{
diff --git a/include/linux/virtio_9p.h b/include/linux/virtio_9p.h
index 1faa80d92f05..e68b439b2860 100644
--- a/include/linux/virtio_9p.h
+++ b/include/linux/virtio_9p.h
@@ -5,7 +5,6 @@
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/virtio_ids.h> 6#include <linux/virtio_ids.h>
7#include <linux/virtio_config.h> 7#include <linux/virtio_config.h>
8#include <linux/types.h>
9 8
10/* The feature bitmap for virtio 9P */ 9/* The feature bitmap for virtio 9P */
11 10
diff --git a/include/net/caif/caif_shm.h b/include/net/caif/caif_shm.h
new file mode 100644
index 000000000000..5bcce55438cf
--- /dev/null
+++ b/include/net/caif/caif_shm.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright (C) ST-Ericsson AB 2010
3 * Contact: Sjur Brendeland / sjur.brandeland@stericsson.com
4 * Author: Amarnath Revanna / amarnath.bangalore.revanna@stericsson.com
5 * License terms: GNU General Public License (GPL) version 2
6 */
7
8#ifndef CAIF_SHM_H_
9#define CAIF_SHM_H_
10
11struct shmdev_layer {
12 u32 shm_base_addr;
13 u32 shm_total_sz;
14 u32 shm_id;
15 u32 shm_loopback;
16 void *hmbx;
17 int (*pshmdev_mbxsend) (u32 shm_id, u32 mbx_msg);
18 int (*pshmdev_mbxsetup) (void *pshmdrv_cb,
19 struct shmdev_layer *pshm_dev, void *pshm_drv);
20 struct net_device *pshm_netdev;
21};
22
23extern int caif_shmcore_probe(struct shmdev_layer *pshm_dev);
24extern void caif_shmcore_remove(struct net_device *pshm_netdev);
25
26#endif
diff --git a/include/net/dst.h b/include/net/dst.h
index a217c838ec0d..ffe9cb719c0e 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -95,7 +95,7 @@ struct dst_entry {
95 unsigned long lastuse; 95 unsigned long lastuse;
96 union { 96 union {
97 struct dst_entry *next; 97 struct dst_entry *next;
98 struct rtable *rt_next; 98 struct rtable __rcu *rt_next;
99 struct rt6_info *rt6_next; 99 struct rt6_info *rt6_next;
100 struct dn_route *dn_next; 100 struct dn_route *dn_next;
101 }; 101 };
diff --git a/include/net/fib_rules.h b/include/net/fib_rules.h
index 106f3097d384..075f1e3a0fed 100644
--- a/include/net/fib_rules.h
+++ b/include/net/fib_rules.h
@@ -20,7 +20,7 @@ struct fib_rule {
20 u32 table; 20 u32 table;
21 u8 action; 21 u8 action;
22 u32 target; 22 u32 target;
23 struct fib_rule * ctarget; 23 struct fib_rule __rcu *ctarget;
24 char iifname[IFNAMSIZ]; 24 char iifname[IFNAMSIZ];
25 char oifname[IFNAMSIZ]; 25 char oifname[IFNAMSIZ];
26 struct rcu_head rcu; 26 struct rcu_head rcu;
diff --git a/include/net/garp.h b/include/net/garp.h
index 825f172caba9..f4c295984c45 100644
--- a/include/net/garp.h
+++ b/include/net/garp.h
@@ -107,7 +107,7 @@ struct garp_applicant {
107}; 107};
108 108
109struct garp_port { 109struct garp_port {
110 struct garp_applicant *applicants[GARP_APPLICATION_MAX + 1]; 110 struct garp_applicant __rcu *applicants[GARP_APPLICATION_MAX + 1];
111}; 111};
112 112
113extern int garp_register_application(struct garp_application *app); 113extern int garp_register_application(struct garp_application *app);
diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
index 417d0c894f29..fe239bfe5f7f 100644
--- a/include/net/inetpeer.h
+++ b/include/net/inetpeer.h
@@ -15,7 +15,7 @@
15 15
16struct inet_peer { 16struct inet_peer {
17 /* group together avl_left,avl_right,v4daddr to speedup lookups */ 17 /* group together avl_left,avl_right,v4daddr to speedup lookups */
18 struct inet_peer *avl_left, *avl_right; 18 struct inet_peer __rcu *avl_left, *avl_right;
19 __be32 v4daddr; /* peer's address */ 19 __be32 v4daddr; /* peer's address */
20 __u32 avl_height; 20 __u32 avl_height;
21 struct list_head unused; 21 struct list_head unused;
diff --git a/include/net/ip.h b/include/net/ip.h
index dbee3fe260e1..86e2b182a0c0 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -59,7 +59,7 @@ struct ipcm_cookie {
59#define IPCB(skb) ((struct inet_skb_parm*)((skb)->cb)) 59#define IPCB(skb) ((struct inet_skb_parm*)((skb)->cb))
60 60
61struct ip_ra_chain { 61struct ip_ra_chain {
62 struct ip_ra_chain *next; 62 struct ip_ra_chain __rcu *next;
63 struct sock *sk; 63 struct sock *sk;
64 union { 64 union {
65 void (*destructor)(struct sock *); 65 void (*destructor)(struct sock *);
@@ -68,7 +68,7 @@ struct ip_ra_chain {
68 struct rcu_head rcu; 68 struct rcu_head rcu;
69}; 69};
70 70
71extern struct ip_ra_chain *ip_ra_chain; 71extern struct ip_ra_chain __rcu *ip_ra_chain;
72 72
73/* IP flags. */ 73/* IP flags. */
74#define IP_CE 0x8000 /* Flag: "Congestion" */ 74#define IP_CE 0x8000 /* Flag: "Congestion" */
diff --git a/include/net/ip6_tunnel.h b/include/net/ip6_tunnel.h
index fc94ec568a50..fc73e667b50e 100644
--- a/include/net/ip6_tunnel.h
+++ b/include/net/ip6_tunnel.h
@@ -13,7 +13,7 @@
13/* IPv6 tunnel */ 13/* IPv6 tunnel */
14 14
15struct ip6_tnl { 15struct ip6_tnl {
16 struct ip6_tnl *next; /* next tunnel in list */ 16 struct ip6_tnl __rcu *next; /* next tunnel in list */
17 struct net_device *dev; /* virtual device associated with tunnel */ 17 struct net_device *dev; /* virtual device associated with tunnel */
18 struct ip6_tnl_parm parms; /* tunnel configuration parameters */ 18 struct ip6_tnl_parm parms; /* tunnel configuration parameters */
19 struct flowi fl; /* flowi template for xmit */ 19 struct flowi fl; /* flowi template for xmit */
diff --git a/include/net/ipip.h b/include/net/ipip.h
index 58abbf966b0c..a32654d52730 100644
--- a/include/net/ipip.h
+++ b/include/net/ipip.h
@@ -16,7 +16,7 @@ struct ip_tunnel_6rd_parm {
16}; 16};
17 17
18struct ip_tunnel { 18struct ip_tunnel {
19 struct ip_tunnel *next; 19 struct ip_tunnel __rcu *next;
20 struct net_device *dev; 20 struct net_device *dev;
21 21
22 int err_count; /* Number of arrived ICMP errors */ 22 int err_count; /* Number of arrived ICMP errors */
@@ -34,12 +34,12 @@ struct ip_tunnel {
34#ifdef CONFIG_IPV6_SIT_6RD 34#ifdef CONFIG_IPV6_SIT_6RD
35 struct ip_tunnel_6rd_parm ip6rd; 35 struct ip_tunnel_6rd_parm ip6rd;
36#endif 36#endif
37 struct ip_tunnel_prl_entry *prl; /* potential router list */ 37 struct ip_tunnel_prl_entry __rcu *prl; /* potential router list */
38 unsigned int prl_count; /* # of entries in PRL */ 38 unsigned int prl_count; /* # of entries in PRL */
39}; 39};
40 40
41struct ip_tunnel_prl_entry { 41struct ip_tunnel_prl_entry {
42 struct ip_tunnel_prl_entry *next; 42 struct ip_tunnel_prl_entry __rcu *next;
43 __be32 addr; 43 __be32 addr;
44 u16 flags; 44 u16 flags;
45 struct rcu_head rcu_head; 45 struct rcu_head rcu_head;
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 65af9a07cf76..1bf812b21fb7 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -88,7 +88,7 @@ struct net {
88#ifdef CONFIG_WEXT_CORE 88#ifdef CONFIG_WEXT_CORE
89 struct sk_buff_head wext_nlevents; 89 struct sk_buff_head wext_nlevents;
90#endif 90#endif
91 struct net_generic *gen; 91 struct net_generic __rcu *gen;
92 92
93 /* Note : following structs are cache line aligned */ 93 /* Note : following structs are cache line aligned */
94#ifdef CONFIG_XFRM 94#ifdef CONFIG_XFRM
diff --git a/include/net/protocol.h b/include/net/protocol.h
index f1effdd3c265..dc07495bce4c 100644
--- a/include/net/protocol.h
+++ b/include/net/protocol.h
@@ -89,10 +89,10 @@ struct inet_protosw {
89#define INET_PROTOSW_PERMANENT 0x02 /* Permanent protocols are unremovable. */ 89#define INET_PROTOSW_PERMANENT 0x02 /* Permanent protocols are unremovable. */
90#define INET_PROTOSW_ICSK 0x04 /* Is this an inet_connection_sock? */ 90#define INET_PROTOSW_ICSK 0x04 /* Is this an inet_connection_sock? */
91 91
92extern const struct net_protocol *inet_protos[MAX_INET_PROTOS]; 92extern const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS];
93 93
94#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) 94#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
95extern const struct inet6_protocol *inet6_protos[MAX_INET_PROTOS]; 95extern const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS];
96#endif 96#endif
97 97
98extern int inet_add_protocol(const struct net_protocol *prot, unsigned char num); 98extern int inet_add_protocol(const struct net_protocol *prot, unsigned char num);
diff --git a/include/net/sock.h b/include/net/sock.h
index 73a4f9702a65..c7a736228ca2 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -301,7 +301,7 @@ struct sock {
301 const struct cred *sk_peer_cred; 301 const struct cred *sk_peer_cred;
302 long sk_rcvtimeo; 302 long sk_rcvtimeo;
303 long sk_sndtimeo; 303 long sk_sndtimeo;
304 struct sk_filter *sk_filter; 304 struct sk_filter __rcu *sk_filter;
305 void *sk_protinfo; 305 void *sk_protinfo;
306 struct timer_list sk_timer; 306 struct timer_list sk_timer;
307 ktime_t sk_stamp; 307 ktime_t sk_stamp;
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index f28d7c9b9f8d..bcfb6b24b019 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -1264,7 +1264,7 @@ struct xfrm_tunnel {
1264 int (*handler)(struct sk_buff *skb); 1264 int (*handler)(struct sk_buff *skb);
1265 int (*err_handler)(struct sk_buff *skb, u32 info); 1265 int (*err_handler)(struct sk_buff *skb, u32 info);
1266 1266
1267 struct xfrm_tunnel *next; 1267 struct xfrm_tunnel __rcu *next;
1268 int priority; 1268 int priority;
1269}; 1269};
1270 1270
@@ -1272,7 +1272,7 @@ struct xfrm6_tunnel {
1272 int (*handler)(struct sk_buff *skb); 1272 int (*handler)(struct sk_buff *skb);
1273 int (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt, 1273 int (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt,
1274 u8 type, u8 code, int offset, __be32 info); 1274 u8 type, u8 code, int offset, __be32 info);
1275 struct xfrm6_tunnel *next; 1275 struct xfrm6_tunnel __rcu *next;
1276 int priority; 1276 int priority;
1277}; 1277};
1278 1278
diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
index 6fa7cbab7d93..1c09820df585 100644
--- a/include/trace/events/irq.h
+++ b/include/trace/events/irq.h
@@ -86,76 +86,62 @@ TRACE_EVENT(irq_handler_exit,
86 86
87DECLARE_EVENT_CLASS(softirq, 87DECLARE_EVENT_CLASS(softirq,
88 88
89 TP_PROTO(struct softirq_action *h, struct softirq_action *vec), 89 TP_PROTO(unsigned int vec_nr),
90 90
91 TP_ARGS(h, vec), 91 TP_ARGS(vec_nr),
92 92
93 TP_STRUCT__entry( 93 TP_STRUCT__entry(
94 __field( int, vec ) 94 __field( unsigned int, vec )
95 ), 95 ),
96 96
97 TP_fast_assign( 97 TP_fast_assign(
98 if (vec) 98 __entry->vec = vec_nr;
99 __entry->vec = (int)(h - vec);
100 else
101 __entry->vec = (int)(long)h;
102 ), 99 ),
103 100
104 TP_printk("vec=%d [action=%s]", __entry->vec, 101 TP_printk("vec=%u [action=%s]", __entry->vec,
105 show_softirq_name(__entry->vec)) 102 show_softirq_name(__entry->vec))
106); 103);
107 104
108/** 105/**
109 * softirq_entry - called immediately before the softirq handler 106 * softirq_entry - called immediately before the softirq handler
110 * @h: pointer to struct softirq_action 107 * @vec_nr: softirq vector number
111 * @vec: pointer to first struct softirq_action in softirq_vec array
112 * 108 *
113 * The @h parameter, contains a pointer to the struct softirq_action 109 * When used in combination with the softirq_exit tracepoint
114 * which has a pointer to the action handler that is called. By subtracting 110 * we can determine the softirq handler runtine.
115 * the @vec pointer from the @h pointer, we can determine the softirq
116 * number. Also, when used in combination with the softirq_exit tracepoint
117 * we can determine the softirq latency.
118 */ 111 */
119DEFINE_EVENT(softirq, softirq_entry, 112DEFINE_EVENT(softirq, softirq_entry,
120 113
121 TP_PROTO(struct softirq_action *h, struct softirq_action *vec), 114 TP_PROTO(unsigned int vec_nr),
122 115
123 TP_ARGS(h, vec) 116 TP_ARGS(vec_nr)
124); 117);
125 118
126/** 119/**
127 * softirq_exit - called immediately after the softirq handler returns 120 * softirq_exit - called immediately after the softirq handler returns
128 * @h: pointer to struct softirq_action 121 * @vec_nr: softirq vector number
129 * @vec: pointer to first struct softirq_action in softirq_vec array
130 * 122 *
131 * The @h parameter contains a pointer to the struct softirq_action 123 * When used in combination with the softirq_entry tracepoint
132 * that has handled the softirq. By subtracting the @vec pointer from 124 * we can determine the softirq handler runtine.
133 * the @h pointer, we can determine the softirq number. Also, when used in
134 * combination with the softirq_entry tracepoint we can determine the softirq
135 * latency.
136 */ 125 */
137DEFINE_EVENT(softirq, softirq_exit, 126DEFINE_EVENT(softirq, softirq_exit,
138 127
139 TP_PROTO(struct softirq_action *h, struct softirq_action *vec), 128 TP_PROTO(unsigned int vec_nr),
140 129
141 TP_ARGS(h, vec) 130 TP_ARGS(vec_nr)
142); 131);
143 132
144/** 133/**
145 * softirq_raise - called immediately when a softirq is raised 134 * softirq_raise - called immediately when a softirq is raised
146 * @h: pointer to struct softirq_action 135 * @vec_nr: softirq vector number
147 * @vec: pointer to first struct softirq_action in softirq_vec array
148 * 136 *
149 * The @h parameter contains a pointer to the softirq vector number which is 137 * When used in combination with the softirq_entry tracepoint
150 * raised. @vec is NULL and it means @h includes vector number not 138 * we can determine the softirq raise to run latency.
151 * softirq_action. When used in combination with the softirq_entry tracepoint
152 * we can determine the softirq raise latency.
153 */ 139 */
154DEFINE_EVENT(softirq, softirq_raise, 140DEFINE_EVENT(softirq, softirq_raise,
155 141
156 TP_PROTO(struct softirq_action *h, struct softirq_action *vec), 142 TP_PROTO(unsigned int vec_nr),
157 143
158 TP_ARGS(h, vec) 144 TP_ARGS(vec_nr)
159); 145);
160 146
161#endif /* _TRACE_IRQ_H */ 147#endif /* _TRACE_IRQ_H */
diff --git a/init/Kconfig b/init/Kconfig
index 3ae8ffe738eb..88c10468db46 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -518,7 +518,6 @@ if CGROUPS
518 518
519config CGROUP_DEBUG 519config CGROUP_DEBUG
520 bool "Example debug cgroup subsystem" 520 bool "Example debug cgroup subsystem"
521 depends on CGROUPS
522 default n 521 default n
523 help 522 help
524 This option enables a simple cgroup subsystem that 523 This option enables a simple cgroup subsystem that
@@ -529,7 +528,6 @@ config CGROUP_DEBUG
529 528
530config CGROUP_NS 529config CGROUP_NS
531 bool "Namespace cgroup subsystem" 530 bool "Namespace cgroup subsystem"
532 depends on CGROUPS
533 help 531 help
534 Provides a simple namespace cgroup subsystem to 532 Provides a simple namespace cgroup subsystem to
535 provide hierarchical naming of sets of namespaces, 533 provide hierarchical naming of sets of namespaces,
@@ -538,21 +536,18 @@ config CGROUP_NS
538 536
539config CGROUP_FREEZER 537config CGROUP_FREEZER
540 bool "Freezer cgroup subsystem" 538 bool "Freezer cgroup subsystem"
541 depends on CGROUPS
542 help 539 help
543 Provides a way to freeze and unfreeze all tasks in a 540 Provides a way to freeze and unfreeze all tasks in a
544 cgroup. 541 cgroup.
545 542
546config CGROUP_DEVICE 543config CGROUP_DEVICE
547 bool "Device controller for cgroups" 544 bool "Device controller for cgroups"
548 depends on CGROUPS && EXPERIMENTAL
549 help 545 help
550 Provides a cgroup implementing whitelists for devices which 546 Provides a cgroup implementing whitelists for devices which
551 a process in the cgroup can mknod or open. 547 a process in the cgroup can mknod or open.
552 548
553config CPUSETS 549config CPUSETS
554 bool "Cpuset support" 550 bool "Cpuset support"
555 depends on CGROUPS
556 help 551 help
557 This option will let you create and manage CPUSETs which 552 This option will let you create and manage CPUSETs which
558 allow dynamically partitioning a system into sets of CPUs and 553 allow dynamically partitioning a system into sets of CPUs and
@@ -568,7 +563,6 @@ config PROC_PID_CPUSET
568 563
569config CGROUP_CPUACCT 564config CGROUP_CPUACCT
570 bool "Simple CPU accounting cgroup subsystem" 565 bool "Simple CPU accounting cgroup subsystem"
571 depends on CGROUPS
572 help 566 help
573 Provides a simple Resource Controller for monitoring the 567 Provides a simple Resource Controller for monitoring the
574 total CPU consumed by the tasks in a cgroup. 568 total CPU consumed by the tasks in a cgroup.
@@ -578,11 +572,10 @@ config RESOURCE_COUNTERS
578 help 572 help
579 This option enables controller independent resource accounting 573 This option enables controller independent resource accounting
580 infrastructure that works with cgroups. 574 infrastructure that works with cgroups.
581 depends on CGROUPS
582 575
583config CGROUP_MEM_RES_CTLR 576config CGROUP_MEM_RES_CTLR
584 bool "Memory Resource Controller for Control Groups" 577 bool "Memory Resource Controller for Control Groups"
585 depends on CGROUPS && RESOURCE_COUNTERS 578 depends on RESOURCE_COUNTERS
586 select MM_OWNER 579 select MM_OWNER
587 help 580 help
588 Provides a memory resource controller that manages both anonymous 581 Provides a memory resource controller that manages both anonymous
@@ -623,7 +616,7 @@ config CGROUP_MEM_RES_CTLR_SWAP
623 616
624menuconfig CGROUP_SCHED 617menuconfig CGROUP_SCHED
625 bool "Group CPU scheduler" 618 bool "Group CPU scheduler"
626 depends on EXPERIMENTAL && CGROUPS 619 depends on EXPERIMENTAL
627 default n 620 default n
628 help 621 help
629 This feature lets CPU scheduler recognize task groups and control CPU 622 This feature lets CPU scheduler recognize task groups and control CPU
@@ -652,7 +645,7 @@ endif #CGROUP_SCHED
652 645
653config BLK_CGROUP 646config BLK_CGROUP
654 tristate "Block IO controller" 647 tristate "Block IO controller"
655 depends on CGROUPS && BLOCK 648 depends on BLOCK
656 default n 649 default n
657 ---help--- 650 ---help---
658 Generic block IO controller cgroup interface. This is the common 651 Generic block IO controller cgroup interface. This is the common
@@ -682,6 +675,59 @@ config DEBUG_BLK_CGROUP
682 675
683endif # CGROUPS 676endif # CGROUPS
684 677
678menuconfig NAMESPACES
679 bool "Namespaces support" if EMBEDDED
680 default !EMBEDDED
681 help
682 Provides the way to make tasks work with different objects using
683 the same id. For example same IPC id may refer to different objects
684 or same user id or pid may refer to different tasks when used in
685 different namespaces.
686
687if NAMESPACES
688
689config UTS_NS
690 bool "UTS namespace"
691 default y
692 help
693 In this namespace tasks see different info provided with the
694 uname() system call
695
696config IPC_NS
697 bool "IPC namespace"
698 depends on (SYSVIPC || POSIX_MQUEUE)
699 default y
700 help
701 In this namespace tasks work with IPC ids which correspond to
702 different IPC objects in different namespaces.
703
704config USER_NS
705 bool "User namespace (EXPERIMENTAL)"
706 depends on EXPERIMENTAL
707 default y
708 help
709 This allows containers, i.e. vservers, to use user namespaces
710 to provide different user info for different servers.
711 If unsure, say N.
712
713config PID_NS
714 bool "PID Namespaces"
715 default y
716 help
717 Support process id namespaces. This allows having multiple
718 processes with the same pid as long as they are in different
719 pid namespaces. This is a building block of containers.
720
721config NET_NS
722 bool "Network namespace"
723 depends on NET
724 default y
725 help
726 Allow user space to create what appear to be multiple instances
727 of the network stack.
728
729endif # NAMESPACES
730
685config MM_OWNER 731config MM_OWNER
686 bool 732 bool
687 733
@@ -734,57 +780,6 @@ config RELAY
734 780
735 If unsure, say N. 781 If unsure, say N.
736 782
737config NAMESPACES
738 bool "Namespaces support" if EMBEDDED
739 default !EMBEDDED
740 help
741 Provides the way to make tasks work with different objects using
742 the same id. For example same IPC id may refer to different objects
743 or same user id or pid may refer to different tasks when used in
744 different namespaces.
745
746config UTS_NS
747 bool "UTS namespace"
748 depends on NAMESPACES
749 help
750 In this namespace tasks see different info provided with the
751 uname() system call
752
753config IPC_NS
754 bool "IPC namespace"
755 depends on NAMESPACES && (SYSVIPC || POSIX_MQUEUE)
756 help
757 In this namespace tasks work with IPC ids which correspond to
758 different IPC objects in different namespaces.
759
760config USER_NS
761 bool "User namespace (EXPERIMENTAL)"
762 depends on NAMESPACES && EXPERIMENTAL
763 help
764 This allows containers, i.e. vservers, to use user namespaces
765 to provide different user info for different servers.
766 If unsure, say N.
767
768config PID_NS
769 bool "PID Namespaces (EXPERIMENTAL)"
770 default n
771 depends on NAMESPACES && EXPERIMENTAL
772 help
773 Support process id namespaces. This allows having multiple
774 processes with the same pid as long as they are in different
775 pid namespaces. This is a building block of containers.
776
777 Unless you want to work with an experimental feature
778 say N here.
779
780config NET_NS
781 bool "Network namespace"
782 default n
783 depends on NAMESPACES && EXPERIMENTAL && NET
784 help
785 Allow user space to create what appear to be multiple instances
786 of the network stack.
787
788config BLK_DEV_INITRD 783config BLK_DEV_INITRD
789 bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support" 784 bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support"
790 depends on BROKEN || !FRV 785 depends on BROKEN || !FRV
diff --git a/ipc/compat.c b/ipc/compat.c
index 9dc2c7d3c9e6..845a28738d3a 100644
--- a/ipc/compat.c
+++ b/ipc/compat.c
@@ -241,6 +241,8 @@ long compat_sys_semctl(int first, int second, int third, void __user *uptr)
241 struct semid64_ds __user *up64; 241 struct semid64_ds __user *up64;
242 int version = compat_ipc_parse_version(&third); 242 int version = compat_ipc_parse_version(&third);
243 243
244 memset(&s64, 0, sizeof(s64));
245
244 if (!uptr) 246 if (!uptr)
245 return -EINVAL; 247 return -EINVAL;
246 if (get_user(pad, (u32 __user *) uptr)) 248 if (get_user(pad, (u32 __user *) uptr))
@@ -421,6 +423,8 @@ long compat_sys_msgctl(int first, int second, void __user *uptr)
421 int version = compat_ipc_parse_version(&second); 423 int version = compat_ipc_parse_version(&second);
422 void __user *p; 424 void __user *p;
423 425
426 memset(&m64, 0, sizeof(m64));
427
424 switch (second & (~IPC_64)) { 428 switch (second & (~IPC_64)) {
425 case IPC_INFO: 429 case IPC_INFO:
426 case IPC_RMID: 430 case IPC_RMID:
@@ -594,6 +598,8 @@ long compat_sys_shmctl(int first, int second, void __user *uptr)
594 int err, err2; 598 int err, err2;
595 int version = compat_ipc_parse_version(&second); 599 int version = compat_ipc_parse_version(&second);
596 600
601 memset(&s64, 0, sizeof(s64));
602
597 switch (second & (~IPC_64)) { 603 switch (second & (~IPC_64)) {
598 case IPC_RMID: 604 case IPC_RMID:
599 case SHM_LOCK: 605 case SHM_LOCK:
diff --git a/ipc/compat_mq.c b/ipc/compat_mq.c
index d8d1e9ff4e88..380ea4fe08e7 100644
--- a/ipc/compat_mq.c
+++ b/ipc/compat_mq.c
@@ -53,6 +53,9 @@ asmlinkage long compat_sys_mq_open(const char __user *u_name,
53 void __user *p = NULL; 53 void __user *p = NULL;
54 if (u_attr && oflag & O_CREAT) { 54 if (u_attr && oflag & O_CREAT) {
55 struct mq_attr attr; 55 struct mq_attr attr;
56
57 memset(&attr, 0, sizeof(attr));
58
56 p = compat_alloc_user_space(sizeof(attr)); 59 p = compat_alloc_user_space(sizeof(attr));
57 if (get_compat_mq_attr(&attr, u_attr) || 60 if (get_compat_mq_attr(&attr, u_attr) ||
58 copy_to_user(p, &attr, sizeof(attr))) 61 copy_to_user(p, &attr, sizeof(attr)))
@@ -127,6 +130,8 @@ asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
127 struct mq_attr __user *p = compat_alloc_user_space(2 * sizeof(*p)); 130 struct mq_attr __user *p = compat_alloc_user_space(2 * sizeof(*p));
128 long ret; 131 long ret;
129 132
133 memset(&mqstat, 0, sizeof(mqstat));
134
130 if (u_mqstat) { 135 if (u_mqstat) {
131 if (get_compat_mq_attr(&mqstat, u_mqstat) || 136 if (get_compat_mq_attr(&mqstat, u_mqstat) ||
132 copy_to_user(p, &mqstat, sizeof(mqstat))) 137 copy_to_user(p, &mqstat, sizeof(mqstat)))
diff --git a/ipc/shm.c b/ipc/shm.c
index 7bc46a9fe1f8..fd658a1c2b88 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -108,7 +108,11 @@ void __init shm_init (void)
108{ 108{
109 shm_init_ns(&init_ipc_ns); 109 shm_init_ns(&init_ipc_ns);
110 ipc_init_proc_interface("sysvipc/shm", 110 ipc_init_proc_interface("sysvipc/shm",
111 " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime\n", 111#if BITS_PER_LONG <= 32
112 " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime rss swap\n",
113#else
114 " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime rss swap\n",
115#endif
112 IPC_SHM_IDS, sysvipc_shm_proc_show); 116 IPC_SHM_IDS, sysvipc_shm_proc_show);
113} 117}
114 118
@@ -544,6 +548,34 @@ static inline unsigned long copy_shminfo_to_user(void __user *buf, struct shminf
544} 548}
545 549
546/* 550/*
551 * Calculate and add used RSS and swap pages of a shm.
552 * Called with shm_ids.rw_mutex held as a reader
553 */
554static void shm_add_rss_swap(struct shmid_kernel *shp,
555 unsigned long *rss_add, unsigned long *swp_add)
556{
557 struct inode *inode;
558
559 inode = shp->shm_file->f_path.dentry->d_inode;
560
561 if (is_file_hugepages(shp->shm_file)) {
562 struct address_space *mapping = inode->i_mapping;
563 struct hstate *h = hstate_file(shp->shm_file);
564 *rss_add += pages_per_huge_page(h) * mapping->nrpages;
565 } else {
566#ifdef CONFIG_SHMEM
567 struct shmem_inode_info *info = SHMEM_I(inode);
568 spin_lock(&info->lock);
569 *rss_add += inode->i_mapping->nrpages;
570 *swp_add += info->swapped;
571 spin_unlock(&info->lock);
572#else
573 *rss_add += inode->i_mapping->nrpages;
574#endif
575 }
576}
577
578/*
547 * Called with shm_ids.rw_mutex held as a reader 579 * Called with shm_ids.rw_mutex held as a reader
548 */ 580 */
549static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss, 581static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,
@@ -560,30 +592,13 @@ static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,
560 for (total = 0, next_id = 0; total < in_use; next_id++) { 592 for (total = 0, next_id = 0; total < in_use; next_id++) {
561 struct kern_ipc_perm *ipc; 593 struct kern_ipc_perm *ipc;
562 struct shmid_kernel *shp; 594 struct shmid_kernel *shp;
563 struct inode *inode;
564 595
565 ipc = idr_find(&shm_ids(ns).ipcs_idr, next_id); 596 ipc = idr_find(&shm_ids(ns).ipcs_idr, next_id);
566 if (ipc == NULL) 597 if (ipc == NULL)
567 continue; 598 continue;
568 shp = container_of(ipc, struct shmid_kernel, shm_perm); 599 shp = container_of(ipc, struct shmid_kernel, shm_perm);
569 600
570 inode = shp->shm_file->f_path.dentry->d_inode; 601 shm_add_rss_swap(shp, rss, swp);
571
572 if (is_file_hugepages(shp->shm_file)) {
573 struct address_space *mapping = inode->i_mapping;
574 struct hstate *h = hstate_file(shp->shm_file);
575 *rss += pages_per_huge_page(h) * mapping->nrpages;
576 } else {
577#ifdef CONFIG_SHMEM
578 struct shmem_inode_info *info = SHMEM_I(inode);
579 spin_lock(&info->lock);
580 *rss += inode->i_mapping->nrpages;
581 *swp += info->swapped;
582 spin_unlock(&info->lock);
583#else
584 *rss += inode->i_mapping->nrpages;
585#endif
586 }
587 602
588 total++; 603 total++;
589 } 604 }
@@ -1072,6 +1087,9 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
1072static int sysvipc_shm_proc_show(struct seq_file *s, void *it) 1087static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
1073{ 1088{
1074 struct shmid_kernel *shp = it; 1089 struct shmid_kernel *shp = it;
1090 unsigned long rss = 0, swp = 0;
1091
1092 shm_add_rss_swap(shp, &rss, &swp);
1075 1093
1076#if BITS_PER_LONG <= 32 1094#if BITS_PER_LONG <= 32
1077#define SIZE_SPEC "%10lu" 1095#define SIZE_SPEC "%10lu"
@@ -1081,7 +1099,8 @@ static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
1081 1099
1082 return seq_printf(s, 1100 return seq_printf(s,
1083 "%10d %10d %4o " SIZE_SPEC " %5u %5u " 1101 "%10d %10d %4o " SIZE_SPEC " %5u %5u "
1084 "%5lu %5u %5u %5u %5u %10lu %10lu %10lu\n", 1102 "%5lu %5u %5u %5u %5u %10lu %10lu %10lu "
1103 SIZE_SPEC " " SIZE_SPEC "\n",
1085 shp->shm_perm.key, 1104 shp->shm_perm.key,
1086 shp->shm_perm.id, 1105 shp->shm_perm.id,
1087 shp->shm_perm.mode, 1106 shp->shm_perm.mode,
@@ -1095,6 +1114,8 @@ static int sysvipc_shm_proc_show(struct seq_file *s, void *it)
1095 shp->shm_perm.cgid, 1114 shp->shm_perm.cgid,
1096 shp->shm_atim, 1115 shp->shm_atim,
1097 shp->shm_dtim, 1116 shp->shm_dtim,
1098 shp->shm_ctim); 1117 shp->shm_ctim,
1118 rss * PAGE_SIZE,
1119 swp * PAGE_SIZE);
1099} 1120}
1100#endif 1121#endif
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 9270d532ec3c..5cf366965d0c 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -243,6 +243,11 @@ static int notify_on_release(const struct cgroup *cgrp)
243 return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); 243 return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
244} 244}
245 245
246static int clone_children(const struct cgroup *cgrp)
247{
248 return test_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
249}
250
246/* 251/*
247 * for_each_subsys() allows you to iterate on each subsystem attached to 252 * for_each_subsys() allows you to iterate on each subsystem attached to
248 * an active hierarchy 253 * an active hierarchy
@@ -1040,6 +1045,8 @@ static int cgroup_show_options(struct seq_file *seq, struct vfsmount *vfs)
1040 seq_puts(seq, ",noprefix"); 1045 seq_puts(seq, ",noprefix");
1041 if (strlen(root->release_agent_path)) 1046 if (strlen(root->release_agent_path))
1042 seq_printf(seq, ",release_agent=%s", root->release_agent_path); 1047 seq_printf(seq, ",release_agent=%s", root->release_agent_path);
1048 if (clone_children(&root->top_cgroup))
1049 seq_puts(seq, ",clone_children");
1043 if (strlen(root->name)) 1050 if (strlen(root->name))
1044 seq_printf(seq, ",name=%s", root->name); 1051 seq_printf(seq, ",name=%s", root->name);
1045 mutex_unlock(&cgroup_mutex); 1052 mutex_unlock(&cgroup_mutex);
@@ -1050,6 +1057,7 @@ struct cgroup_sb_opts {
1050 unsigned long subsys_bits; 1057 unsigned long subsys_bits;
1051 unsigned long flags; 1058 unsigned long flags;
1052 char *release_agent; 1059 char *release_agent;
1060 bool clone_children;
1053 char *name; 1061 char *name;
1054 /* User explicitly requested empty subsystem */ 1062 /* User explicitly requested empty subsystem */
1055 bool none; 1063 bool none;
@@ -1066,7 +1074,8 @@ struct cgroup_sb_opts {
1066 */ 1074 */
1067static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) 1075static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1068{ 1076{
1069 char *token, *o = data ?: "all"; 1077 char *token, *o = data;
1078 bool all_ss = false, one_ss = false;
1070 unsigned long mask = (unsigned long)-1; 1079 unsigned long mask = (unsigned long)-1;
1071 int i; 1080 int i;
1072 bool module_pin_failed = false; 1081 bool module_pin_failed = false;
@@ -1082,22 +1091,27 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1082 while ((token = strsep(&o, ",")) != NULL) { 1091 while ((token = strsep(&o, ",")) != NULL) {
1083 if (!*token) 1092 if (!*token)
1084 return -EINVAL; 1093 return -EINVAL;
1085 if (!strcmp(token, "all")) { 1094 if (!strcmp(token, "none")) {
1086 /* Add all non-disabled subsystems */
1087 opts->subsys_bits = 0;
1088 for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
1089 struct cgroup_subsys *ss = subsys[i];
1090 if (ss == NULL)
1091 continue;
1092 if (!ss->disabled)
1093 opts->subsys_bits |= 1ul << i;
1094 }
1095 } else if (!strcmp(token, "none")) {
1096 /* Explicitly have no subsystems */ 1095 /* Explicitly have no subsystems */
1097 opts->none = true; 1096 opts->none = true;
1098 } else if (!strcmp(token, "noprefix")) { 1097 continue;
1098 }
1099 if (!strcmp(token, "all")) {
1100 /* Mutually exclusive option 'all' + subsystem name */
1101 if (one_ss)
1102 return -EINVAL;
1103 all_ss = true;
1104 continue;
1105 }
1106 if (!strcmp(token, "noprefix")) {
1099 set_bit(ROOT_NOPREFIX, &opts->flags); 1107 set_bit(ROOT_NOPREFIX, &opts->flags);
1100 } else if (!strncmp(token, "release_agent=", 14)) { 1108 continue;
1109 }
1110 if (!strcmp(token, "clone_children")) {
1111 opts->clone_children = true;
1112 continue;
1113 }
1114 if (!strncmp(token, "release_agent=", 14)) {
1101 /* Specifying two release agents is forbidden */ 1115 /* Specifying two release agents is forbidden */
1102 if (opts->release_agent) 1116 if (opts->release_agent)
1103 return -EINVAL; 1117 return -EINVAL;
@@ -1105,7 +1119,9 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1105 kstrndup(token + 14, PATH_MAX - 1, GFP_KERNEL); 1119 kstrndup(token + 14, PATH_MAX - 1, GFP_KERNEL);
1106 if (!opts->release_agent) 1120 if (!opts->release_agent)
1107 return -ENOMEM; 1121 return -ENOMEM;
1108 } else if (!strncmp(token, "name=", 5)) { 1122 continue;
1123 }
1124 if (!strncmp(token, "name=", 5)) {
1109 const char *name = token + 5; 1125 const char *name = token + 5;
1110 /* Can't specify an empty name */ 1126 /* Can't specify an empty name */
1111 if (!strlen(name)) 1127 if (!strlen(name))
@@ -1127,20 +1143,44 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
1127 GFP_KERNEL); 1143 GFP_KERNEL);
1128 if (!opts->name) 1144 if (!opts->name)
1129 return -ENOMEM; 1145 return -ENOMEM;
1130 } else { 1146
1131 struct cgroup_subsys *ss; 1147 continue;
1132 for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { 1148 }
1133 ss = subsys[i]; 1149
1134 if (ss == NULL) 1150 for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
1135 continue; 1151 struct cgroup_subsys *ss = subsys[i];
1136 if (!strcmp(token, ss->name)) { 1152 if (ss == NULL)
1137 if (!ss->disabled) 1153 continue;
1138 set_bit(i, &opts->subsys_bits); 1154 if (strcmp(token, ss->name))
1139 break; 1155 continue;
1140 } 1156 if (ss->disabled)
1141 } 1157 continue;
1142 if (i == CGROUP_SUBSYS_COUNT) 1158
1143 return -ENOENT; 1159 /* Mutually exclusive option 'all' + subsystem name */
1160 if (all_ss)
1161 return -EINVAL;
1162 set_bit(i, &opts->subsys_bits);
1163 one_ss = true;
1164
1165 break;
1166 }
1167 if (i == CGROUP_SUBSYS_COUNT)
1168 return -ENOENT;
1169 }
1170
1171 /*
1172 * If the 'all' option was specified select all the subsystems,
1173 * otherwise 'all, 'none' and a subsystem name options were not
1174 * specified, let's default to 'all'
1175 */
1176 if (all_ss || (!all_ss && !one_ss && !opts->none)) {
1177 for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
1178 struct cgroup_subsys *ss = subsys[i];
1179 if (ss == NULL)
1180 continue;
1181 if (ss->disabled)
1182 continue;
1183 set_bit(i, &opts->subsys_bits);
1144 } 1184 }
1145 } 1185 }
1146 1186
@@ -1355,6 +1395,8 @@ static struct cgroupfs_root *cgroup_root_from_opts(struct cgroup_sb_opts *opts)
1355 strcpy(root->release_agent_path, opts->release_agent); 1395 strcpy(root->release_agent_path, opts->release_agent);
1356 if (opts->name) 1396 if (opts->name)
1357 strcpy(root->name, opts->name); 1397 strcpy(root->name, opts->name);
1398 if (opts->clone_children)
1399 set_bit(CGRP_CLONE_CHILDREN, &root->top_cgroup.flags);
1358 return root; 1400 return root;
1359} 1401}
1360 1402
@@ -1880,6 +1922,8 @@ static int cgroup_release_agent_write(struct cgroup *cgrp, struct cftype *cft,
1880 const char *buffer) 1922 const char *buffer)
1881{ 1923{
1882 BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX); 1924 BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
1925 if (strlen(buffer) >= PATH_MAX)
1926 return -EINVAL;
1883 if (!cgroup_lock_live_group(cgrp)) 1927 if (!cgroup_lock_live_group(cgrp))
1884 return -ENODEV; 1928 return -ENODEV;
1885 strcpy(cgrp->root->release_agent_path, buffer); 1929 strcpy(cgrp->root->release_agent_path, buffer);
@@ -3173,6 +3217,23 @@ fail:
3173 return ret; 3217 return ret;
3174} 3218}
3175 3219
3220static u64 cgroup_clone_children_read(struct cgroup *cgrp,
3221 struct cftype *cft)
3222{
3223 return clone_children(cgrp);
3224}
3225
3226static int cgroup_clone_children_write(struct cgroup *cgrp,
3227 struct cftype *cft,
3228 u64 val)
3229{
3230 if (val)
3231 set_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
3232 else
3233 clear_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
3234 return 0;
3235}
3236
3176/* 3237/*
3177 * for the common functions, 'private' gives the type of file 3238 * for the common functions, 'private' gives the type of file
3178 */ 3239 */
@@ -3203,6 +3264,11 @@ static struct cftype files[] = {
3203 .write_string = cgroup_write_event_control, 3264 .write_string = cgroup_write_event_control,
3204 .mode = S_IWUGO, 3265 .mode = S_IWUGO,
3205 }, 3266 },
3267 {
3268 .name = "cgroup.clone_children",
3269 .read_u64 = cgroup_clone_children_read,
3270 .write_u64 = cgroup_clone_children_write,
3271 },
3206}; 3272};
3207 3273
3208static struct cftype cft_release_agent = { 3274static struct cftype cft_release_agent = {
@@ -3332,6 +3398,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
3332 if (notify_on_release(parent)) 3398 if (notify_on_release(parent))
3333 set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags); 3399 set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
3334 3400
3401 if (clone_children(parent))
3402 set_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
3403
3335 for_each_subsys(root, ss) { 3404 for_each_subsys(root, ss) {
3336 struct cgroup_subsys_state *css = ss->create(ss, cgrp); 3405 struct cgroup_subsys_state *css = ss->create(ss, cgrp);
3337 3406
@@ -3346,6 +3415,8 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
3346 goto err_destroy; 3415 goto err_destroy;
3347 } 3416 }
3348 /* At error, ->destroy() callback has to free assigned ID. */ 3417 /* At error, ->destroy() callback has to free assigned ID. */
3418 if (clone_children(parent) && ss->post_clone)
3419 ss->post_clone(ss, cgrp);
3349 } 3420 }
3350 3421
3351 cgroup_lock_hierarchy(root); 3422 cgroup_lock_hierarchy(root);
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index ce71ed53e88f..e7bebb7c6c38 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -48,20 +48,19 @@ static inline struct freezer *task_freezer(struct task_struct *task)
48 struct freezer, css); 48 struct freezer, css);
49} 49}
50 50
51int cgroup_freezing_or_frozen(struct task_struct *task) 51static inline int __cgroup_freezing_or_frozen(struct task_struct *task)
52{ 52{
53 struct freezer *freezer; 53 enum freezer_state state = task_freezer(task)->state;
54 enum freezer_state state; 54 return (state == CGROUP_FREEZING) || (state == CGROUP_FROZEN);
55}
55 56
57int cgroup_freezing_or_frozen(struct task_struct *task)
58{
59 int result;
56 task_lock(task); 60 task_lock(task);
57 freezer = task_freezer(task); 61 result = __cgroup_freezing_or_frozen(task);
58 if (!freezer->css.cgroup->parent)
59 state = CGROUP_THAWED; /* root cgroup can't be frozen */
60 else
61 state = freezer->state;
62 task_unlock(task); 62 task_unlock(task);
63 63 return result;
64 return (state == CGROUP_FREEZING) || (state == CGROUP_FROZEN);
65} 64}
66 65
67/* 66/*
@@ -154,13 +153,6 @@ static void freezer_destroy(struct cgroup_subsys *ss,
154 kfree(cgroup_freezer(cgroup)); 153 kfree(cgroup_freezer(cgroup));
155} 154}
156 155
157/* Task is frozen or will freeze immediately when next it gets woken */
158static bool is_task_frozen_enough(struct task_struct *task)
159{
160 return frozen(task) ||
161 (task_is_stopped_or_traced(task) && freezing(task));
162}
163
164/* 156/*
165 * The call to cgroup_lock() in the freezer.state write method prevents 157 * The call to cgroup_lock() in the freezer.state write method prevents
166 * a write to that file racing against an attach, and hence the 158 * a write to that file racing against an attach, and hence the
@@ -174,24 +166,25 @@ static int freezer_can_attach(struct cgroup_subsys *ss,
174 166
175 /* 167 /*
176 * Anything frozen can't move or be moved to/from. 168 * Anything frozen can't move or be moved to/from.
177 *
178 * Since orig_freezer->state == FROZEN means that @task has been
179 * frozen, so it's sufficient to check the latter condition.
180 */ 169 */
181 170
182 if (is_task_frozen_enough(task)) 171 freezer = cgroup_freezer(new_cgroup);
172 if (freezer->state != CGROUP_THAWED)
183 return -EBUSY; 173 return -EBUSY;
184 174
185 freezer = cgroup_freezer(new_cgroup); 175 rcu_read_lock();
186 if (freezer->state == CGROUP_FROZEN) 176 if (__cgroup_freezing_or_frozen(task)) {
177 rcu_read_unlock();
187 return -EBUSY; 178 return -EBUSY;
179 }
180 rcu_read_unlock();
188 181
189 if (threadgroup) { 182 if (threadgroup) {
190 struct task_struct *c; 183 struct task_struct *c;
191 184
192 rcu_read_lock(); 185 rcu_read_lock();
193 list_for_each_entry_rcu(c, &task->thread_group, thread_group) { 186 list_for_each_entry_rcu(c, &task->thread_group, thread_group) {
194 if (is_task_frozen_enough(c)) { 187 if (__cgroup_freezing_or_frozen(c)) {
195 rcu_read_unlock(); 188 rcu_read_unlock();
196 return -EBUSY; 189 return -EBUSY;
197 } 190 }
@@ -236,31 +229,30 @@ static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
236/* 229/*
237 * caller must hold freezer->lock 230 * caller must hold freezer->lock
238 */ 231 */
239static void update_freezer_state(struct cgroup *cgroup, 232static void update_if_frozen(struct cgroup *cgroup,
240 struct freezer *freezer) 233 struct freezer *freezer)
241{ 234{
242 struct cgroup_iter it; 235 struct cgroup_iter it;
243 struct task_struct *task; 236 struct task_struct *task;
244 unsigned int nfrozen = 0, ntotal = 0; 237 unsigned int nfrozen = 0, ntotal = 0;
238 enum freezer_state old_state = freezer->state;
245 239
246 cgroup_iter_start(cgroup, &it); 240 cgroup_iter_start(cgroup, &it);
247 while ((task = cgroup_iter_next(cgroup, &it))) { 241 while ((task = cgroup_iter_next(cgroup, &it))) {
248 ntotal++; 242 ntotal++;
249 if (is_task_frozen_enough(task)) 243 if (frozen(task))
250 nfrozen++; 244 nfrozen++;
251 } 245 }
252 246
253 /* 247 if (old_state == CGROUP_THAWED) {
254 * Transition to FROZEN when no new tasks can be added ensures 248 BUG_ON(nfrozen > 0);
255 * that we never exist in the FROZEN state while there are unfrozen 249 } else if (old_state == CGROUP_FREEZING) {
256 * tasks. 250 if (nfrozen == ntotal)
257 */ 251 freezer->state = CGROUP_FROZEN;
258 if (nfrozen == ntotal) 252 } else { /* old_state == CGROUP_FROZEN */
259 freezer->state = CGROUP_FROZEN; 253 BUG_ON(nfrozen != ntotal);
260 else if (nfrozen > 0) 254 }
261 freezer->state = CGROUP_FREEZING; 255
262 else
263 freezer->state = CGROUP_THAWED;
264 cgroup_iter_end(cgroup, &it); 256 cgroup_iter_end(cgroup, &it);
265} 257}
266 258
@@ -279,7 +271,7 @@ static int freezer_read(struct cgroup *cgroup, struct cftype *cft,
279 if (state == CGROUP_FREEZING) { 271 if (state == CGROUP_FREEZING) {
280 /* We change from FREEZING to FROZEN lazily if the cgroup was 272 /* We change from FREEZING to FROZEN lazily if the cgroup was
281 * only partially frozen when we exitted write. */ 273 * only partially frozen when we exitted write. */
282 update_freezer_state(cgroup, freezer); 274 update_if_frozen(cgroup, freezer);
283 state = freezer->state; 275 state = freezer->state;
284 } 276 }
285 spin_unlock_irq(&freezer->lock); 277 spin_unlock_irq(&freezer->lock);
@@ -301,7 +293,7 @@ static int try_to_freeze_cgroup(struct cgroup *cgroup, struct freezer *freezer)
301 while ((task = cgroup_iter_next(cgroup, &it))) { 293 while ((task = cgroup_iter_next(cgroup, &it))) {
302 if (!freeze_task(task, true)) 294 if (!freeze_task(task, true))
303 continue; 295 continue;
304 if (is_task_frozen_enough(task)) 296 if (frozen(task))
305 continue; 297 continue;
306 if (!freezing(task) && !freezer_should_skip(task)) 298 if (!freezing(task) && !freezer_should_skip(task))
307 num_cant_freeze_now++; 299 num_cant_freeze_now++;
@@ -335,7 +327,7 @@ static int freezer_change_state(struct cgroup *cgroup,
335 327
336 spin_lock_irq(&freezer->lock); 328 spin_lock_irq(&freezer->lock);
337 329
338 update_freezer_state(cgroup, freezer); 330 update_if_frozen(cgroup, freezer);
339 if (goal_state == freezer->state) 331 if (goal_state == freezer->state)
340 goto out; 332 goto out;
341 333
diff --git a/kernel/cred.c b/kernel/cred.c
index 9a3e22641fe7..6a1aa004e376 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -325,7 +325,7 @@ EXPORT_SYMBOL(prepare_creds);
325 325
326/* 326/*
327 * Prepare credentials for current to perform an execve() 327 * Prepare credentials for current to perform an execve()
328 * - The caller must hold current->cred_guard_mutex 328 * - The caller must hold ->cred_guard_mutex
329 */ 329 */
330struct cred *prepare_exec_creds(void) 330struct cred *prepare_exec_creds(void)
331{ 331{
@@ -384,8 +384,6 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
384 struct cred *new; 384 struct cred *new;
385 int ret; 385 int ret;
386 386
387 mutex_init(&p->cred_guard_mutex);
388
389 if ( 387 if (
390#ifdef CONFIG_KEYS 388#ifdef CONFIG_KEYS
391 !p->cred->thread_keyring && 389 !p->cred->thread_keyring &&
diff --git a/kernel/exit.c b/kernel/exit.c
index 894179a32ec1..b194febf5799 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -703,6 +703,8 @@ static void exit_mm(struct task_struct * tsk)
703 * space. 703 * space.
704 */ 704 */
705static struct task_struct *find_new_reaper(struct task_struct *father) 705static struct task_struct *find_new_reaper(struct task_struct *father)
706 __releases(&tasklist_lock)
707 __acquires(&tasklist_lock)
706{ 708{
707 struct pid_namespace *pid_ns = task_active_pid_ns(father); 709 struct pid_namespace *pid_ns = task_active_pid_ns(father);
708 struct task_struct *thread; 710 struct task_struct *thread;
diff --git a/kernel/fork.c b/kernel/fork.c
index e87aaaaf5131..3b159c5991b7 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -908,6 +908,8 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
908 sig->oom_adj = current->signal->oom_adj; 908 sig->oom_adj = current->signal->oom_adj;
909 sig->oom_score_adj = current->signal->oom_score_adj; 909 sig->oom_score_adj = current->signal->oom_score_adj;
910 910
911 mutex_init(&sig->cred_guard_mutex);
912
911 return 0; 913 return 0;
912} 914}
913 915
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 9d917ff72675..9988d03797f5 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -393,3 +393,18 @@ unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
393 struct irq_desc *desc = irq_to_desc(irq); 393 struct irq_desc *desc = irq_to_desc(irq);
394 return desc ? desc->kstat_irqs[cpu] : 0; 394 return desc ? desc->kstat_irqs[cpu] : 0;
395} 395}
396
397#ifdef CONFIG_GENERIC_HARDIRQS
398unsigned int kstat_irqs(unsigned int irq)
399{
400 struct irq_desc *desc = irq_to_desc(irq);
401 int cpu;
402 int sum = 0;
403
404 if (!desc)
405 return 0;
406 for_each_possible_cpu(cpu)
407 sum += desc->kstat_irqs[cpu];
408 return sum;
409}
410#endif /* CONFIG_GENERIC_HARDIRQS */
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 56a891914273..99865c33a60d 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -74,7 +74,8 @@ static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
74/* NOTE: change this value only with kprobe_mutex held */ 74/* NOTE: change this value only with kprobe_mutex held */
75static bool kprobes_all_disarmed; 75static bool kprobes_all_disarmed;
76 76
77static DEFINE_MUTEX(kprobe_mutex); /* Protects kprobe_table */ 77/* This protects kprobe_table and optimizing_list */
78static DEFINE_MUTEX(kprobe_mutex);
78static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL; 79static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL;
79static struct { 80static struct {
80 spinlock_t lock ____cacheline_aligned_in_smp; 81 spinlock_t lock ____cacheline_aligned_in_smp;
@@ -595,6 +596,7 @@ static __kprobes void try_to_optimize_kprobe(struct kprobe *p)
595} 596}
596 597
597#ifdef CONFIG_SYSCTL 598#ifdef CONFIG_SYSCTL
599/* This should be called with kprobe_mutex locked */
598static void __kprobes optimize_all_kprobes(void) 600static void __kprobes optimize_all_kprobes(void)
599{ 601{
600 struct hlist_head *head; 602 struct hlist_head *head;
@@ -607,17 +609,16 @@ static void __kprobes optimize_all_kprobes(void)
607 return; 609 return;
608 610
609 kprobes_allow_optimization = true; 611 kprobes_allow_optimization = true;
610 mutex_lock(&text_mutex);
611 for (i = 0; i < KPROBE_TABLE_SIZE; i++) { 612 for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
612 head = &kprobe_table[i]; 613 head = &kprobe_table[i];
613 hlist_for_each_entry_rcu(p, node, head, hlist) 614 hlist_for_each_entry_rcu(p, node, head, hlist)
614 if (!kprobe_disabled(p)) 615 if (!kprobe_disabled(p))
615 optimize_kprobe(p); 616 optimize_kprobe(p);
616 } 617 }
617 mutex_unlock(&text_mutex);
618 printk(KERN_INFO "Kprobes globally optimized\n"); 618 printk(KERN_INFO "Kprobes globally optimized\n");
619} 619}
620 620
621/* This should be called with kprobe_mutex locked */
621static void __kprobes unoptimize_all_kprobes(void) 622static void __kprobes unoptimize_all_kprobes(void)
622{ 623{
623 struct hlist_head *head; 624 struct hlist_head *head;
diff --git a/kernel/module.c b/kernel/module.c
index 2df46301a7a4..437a74a7524a 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2037,7 +2037,7 @@ static inline void layout_symtab(struct module *mod, struct load_info *info)
2037{ 2037{
2038} 2038}
2039 2039
2040static void add_kallsyms(struct module *mod, struct load_info *info) 2040static void add_kallsyms(struct module *mod, const struct load_info *info)
2041{ 2041{
2042} 2042}
2043#endif /* CONFIG_KALLSYMS */ 2043#endif /* CONFIG_KALLSYMS */
diff --git a/kernel/ns_cgroup.c b/kernel/ns_cgroup.c
index 2a5dfec8efe0..2c98ad94ba0e 100644
--- a/kernel/ns_cgroup.c
+++ b/kernel/ns_cgroup.c
@@ -85,6 +85,14 @@ static struct cgroup_subsys_state *ns_create(struct cgroup_subsys *ss,
85 return ERR_PTR(-EPERM); 85 return ERR_PTR(-EPERM);
86 if (!cgroup_is_descendant(cgroup, current)) 86 if (!cgroup_is_descendant(cgroup, current))
87 return ERR_PTR(-EPERM); 87 return ERR_PTR(-EPERM);
88 if (test_bit(CGRP_CLONE_CHILDREN, &cgroup->flags)) {
89 printk("ns_cgroup can't be created with parent "
90 "'clone_children' set.\n");
91 return ERR_PTR(-EINVAL);
92 }
93
94 printk_once("ns_cgroup deprecated: consider using the "
95 "'clone_children' flag without the ns_cgroup.\n");
88 96
89 ns_cgroup = kzalloc(sizeof(*ns_cgroup), GFP_KERNEL); 97 ns_cgroup = kzalloc(sizeof(*ns_cgroup), GFP_KERNEL);
90 if (!ns_cgroup) 98 if (!ns_cgroup)
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index f309e8014c78..517d827f4982 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -417,8 +417,8 @@ event_filter_match(struct perf_event *event)
417 return event->cpu == -1 || event->cpu == smp_processor_id(); 417 return event->cpu == -1 || event->cpu == smp_processor_id();
418} 418}
419 419
420static int 420static void
421__event_sched_out(struct perf_event *event, 421event_sched_out(struct perf_event *event,
422 struct perf_cpu_context *cpuctx, 422 struct perf_cpu_context *cpuctx,
423 struct perf_event_context *ctx) 423 struct perf_event_context *ctx)
424{ 424{
@@ -437,13 +437,14 @@ __event_sched_out(struct perf_event *event,
437 } 437 }
438 438
439 if (event->state != PERF_EVENT_STATE_ACTIVE) 439 if (event->state != PERF_EVENT_STATE_ACTIVE)
440 return 0; 440 return;
441 441
442 event->state = PERF_EVENT_STATE_INACTIVE; 442 event->state = PERF_EVENT_STATE_INACTIVE;
443 if (event->pending_disable) { 443 if (event->pending_disable) {
444 event->pending_disable = 0; 444 event->pending_disable = 0;
445 event->state = PERF_EVENT_STATE_OFF; 445 event->state = PERF_EVENT_STATE_OFF;
446 } 446 }
447 event->tstamp_stopped = ctx->time;
447 event->pmu->del(event, 0); 448 event->pmu->del(event, 0);
448 event->oncpu = -1; 449 event->oncpu = -1;
449 450
@@ -452,19 +453,6 @@ __event_sched_out(struct perf_event *event,
452 ctx->nr_active--; 453 ctx->nr_active--;
453 if (event->attr.exclusive || !cpuctx->active_oncpu) 454 if (event->attr.exclusive || !cpuctx->active_oncpu)
454 cpuctx->exclusive = 0; 455 cpuctx->exclusive = 0;
455 return 1;
456}
457
458static void
459event_sched_out(struct perf_event *event,
460 struct perf_cpu_context *cpuctx,
461 struct perf_event_context *ctx)
462{
463 int ret;
464
465 ret = __event_sched_out(event, cpuctx, ctx);
466 if (ret)
467 event->tstamp_stopped = ctx->time;
468} 456}
469 457
470static void 458static void
@@ -664,7 +652,7 @@ retry:
664} 652}
665 653
666static int 654static int
667__event_sched_in(struct perf_event *event, 655event_sched_in(struct perf_event *event,
668 struct perf_cpu_context *cpuctx, 656 struct perf_cpu_context *cpuctx,
669 struct perf_event_context *ctx) 657 struct perf_event_context *ctx)
670{ 658{
@@ -684,6 +672,8 @@ __event_sched_in(struct perf_event *event,
684 return -EAGAIN; 672 return -EAGAIN;
685 } 673 }
686 674
675 event->tstamp_running += ctx->time - event->tstamp_stopped;
676
687 if (!is_software_event(event)) 677 if (!is_software_event(event))
688 cpuctx->active_oncpu++; 678 cpuctx->active_oncpu++;
689 ctx->nr_active++; 679 ctx->nr_active++;
@@ -694,35 +684,6 @@ __event_sched_in(struct perf_event *event,
694 return 0; 684 return 0;
695} 685}
696 686
697static inline int
698event_sched_in(struct perf_event *event,
699 struct perf_cpu_context *cpuctx,
700 struct perf_event_context *ctx)
701{
702 int ret = __event_sched_in(event, cpuctx, ctx);
703 if (ret)
704 return ret;
705 event->tstamp_running += ctx->time - event->tstamp_stopped;
706 return 0;
707}
708
709static void
710group_commit_event_sched_in(struct perf_event *group_event,
711 struct perf_cpu_context *cpuctx,
712 struct perf_event_context *ctx)
713{
714 struct perf_event *event;
715 u64 now = ctx->time;
716
717 group_event->tstamp_running += now - group_event->tstamp_stopped;
718 /*
719 * Schedule in siblings as one group (if any):
720 */
721 list_for_each_entry(event, &group_event->sibling_list, group_entry) {
722 event->tstamp_running += now - event->tstamp_stopped;
723 }
724}
725
726static int 687static int
727group_sched_in(struct perf_event *group_event, 688group_sched_in(struct perf_event *group_event,
728 struct perf_cpu_context *cpuctx, 689 struct perf_cpu_context *cpuctx,
@@ -730,19 +691,15 @@ group_sched_in(struct perf_event *group_event,
730{ 691{
731 struct perf_event *event, *partial_group = NULL; 692 struct perf_event *event, *partial_group = NULL;
732 struct pmu *pmu = group_event->pmu; 693 struct pmu *pmu = group_event->pmu;
694 u64 now = ctx->time;
695 bool simulate = false;
733 696
734 if (group_event->state == PERF_EVENT_STATE_OFF) 697 if (group_event->state == PERF_EVENT_STATE_OFF)
735 return 0; 698 return 0;
736 699
737 pmu->start_txn(pmu); 700 pmu->start_txn(pmu);
738 701
739 /* 702 if (event_sched_in(group_event, cpuctx, ctx)) {
740 * use __event_sched_in() to delay updating tstamp_running
741 * until the transaction is committed. In case of failure
742 * we will keep an unmodified tstamp_running which is a
743 * requirement to get correct timing information
744 */
745 if (__event_sched_in(group_event, cpuctx, ctx)) {
746 pmu->cancel_txn(pmu); 703 pmu->cancel_txn(pmu);
747 return -EAGAIN; 704 return -EAGAIN;
748 } 705 }
@@ -751,31 +708,42 @@ group_sched_in(struct perf_event *group_event,
751 * Schedule in siblings as one group (if any): 708 * Schedule in siblings as one group (if any):
752 */ 709 */
753 list_for_each_entry(event, &group_event->sibling_list, group_entry) { 710 list_for_each_entry(event, &group_event->sibling_list, group_entry) {
754 if (__event_sched_in(event, cpuctx, ctx)) { 711 if (event_sched_in(event, cpuctx, ctx)) {
755 partial_group = event; 712 partial_group = event;
756 goto group_error; 713 goto group_error;
757 } 714 }
758 } 715 }
759 716
760 if (!pmu->commit_txn(pmu)) { 717 if (!pmu->commit_txn(pmu))
761 /* commit tstamp_running */
762 group_commit_event_sched_in(group_event, cpuctx, ctx);
763 return 0; 718 return 0;
764 } 719
765group_error: 720group_error:
766 /* 721 /*
767 * Groups can be scheduled in as one unit only, so undo any 722 * Groups can be scheduled in as one unit only, so undo any
768 * partial group before returning: 723 * partial group before returning:
724 * The events up to the failed event are scheduled out normally,
725 * tstamp_stopped will be updated.
769 * 726 *
770 * use __event_sched_out() to avoid updating tstamp_stopped 727 * The failed events and the remaining siblings need to have
771 * because the event never actually ran 728 * their timings updated as if they had gone thru event_sched_in()
729 * and event_sched_out(). This is required to get consistent timings
730 * across the group. This also takes care of the case where the group
731 * could never be scheduled by ensuring tstamp_stopped is set to mark
732 * the time the event was actually stopped, such that time delta
733 * calculation in update_event_times() is correct.
772 */ 734 */
773 list_for_each_entry(event, &group_event->sibling_list, group_entry) { 735 list_for_each_entry(event, &group_event->sibling_list, group_entry) {
774 if (event == partial_group) 736 if (event == partial_group)
775 break; 737 simulate = true;
776 __event_sched_out(event, cpuctx, ctx); 738
739 if (simulate) {
740 event->tstamp_running += now - event->tstamp_stopped;
741 event->tstamp_stopped = now;
742 } else {
743 event_sched_out(event, cpuctx, ctx);
744 }
777 } 745 }
778 __event_sched_out(group_event, cpuctx, ctx); 746 event_sched_out(group_event, cpuctx, ctx);
779 747
780 pmu->cancel_txn(pmu); 748 pmu->cancel_txn(pmu);
781 749
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index f34d798ef4a2..99bbaa3e5b0d 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -181,7 +181,7 @@ int ptrace_attach(struct task_struct *task)
181 * under ptrace. 181 * under ptrace.
182 */ 182 */
183 retval = -ERESTARTNOINTR; 183 retval = -ERESTARTNOINTR;
184 if (mutex_lock_interruptible(&task->cred_guard_mutex)) 184 if (mutex_lock_interruptible(&task->signal->cred_guard_mutex))
185 goto out; 185 goto out;
186 186
187 task_lock(task); 187 task_lock(task);
@@ -208,7 +208,7 @@ int ptrace_attach(struct task_struct *task)
208unlock_tasklist: 208unlock_tasklist:
209 write_unlock_irq(&tasklist_lock); 209 write_unlock_irq(&tasklist_lock);
210unlock_creds: 210unlock_creds:
211 mutex_unlock(&task->cred_guard_mutex); 211 mutex_unlock(&task->signal->cred_guard_mutex);
212out: 212out:
213 return retval; 213 return retval;
214} 214}
@@ -329,6 +329,8 @@ int ptrace_detach(struct task_struct *child, unsigned int data)
329 * and reacquire the lock. 329 * and reacquire the lock.
330 */ 330 */
331void exit_ptrace(struct task_struct *tracer) 331void exit_ptrace(struct task_struct *tracer)
332 __releases(&tasklist_lock)
333 __acquires(&tasklist_lock)
332{ 334{
333 struct task_struct *p, *n; 335 struct task_struct *p, *n;
334 LIST_HEAD(ptrace_dead); 336 LIST_HEAD(ptrace_dead);
@@ -402,7 +404,7 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
402 return copied; 404 return copied;
403} 405}
404 406
405static int ptrace_setoptions(struct task_struct *child, long data) 407static int ptrace_setoptions(struct task_struct *child, unsigned long data)
406{ 408{
407 child->ptrace &= ~PT_TRACE_MASK; 409 child->ptrace &= ~PT_TRACE_MASK;
408 410
@@ -481,7 +483,8 @@ static int ptrace_setsiginfo(struct task_struct *child, const siginfo_t *info)
481#define is_sysemu_singlestep(request) 0 483#define is_sysemu_singlestep(request) 0
482#endif 484#endif
483 485
484static int ptrace_resume(struct task_struct *child, long request, long data) 486static int ptrace_resume(struct task_struct *child, long request,
487 unsigned long data)
485{ 488{
486 if (!valid_signal(data)) 489 if (!valid_signal(data))
487 return -EIO; 490 return -EIO;
@@ -558,10 +561,12 @@ static int ptrace_regset(struct task_struct *task, int req, unsigned int type,
558#endif 561#endif
559 562
560int ptrace_request(struct task_struct *child, long request, 563int ptrace_request(struct task_struct *child, long request,
561 long addr, long data) 564 unsigned long addr, unsigned long data)
562{ 565{
563 int ret = -EIO; 566 int ret = -EIO;
564 siginfo_t siginfo; 567 siginfo_t siginfo;
568 void __user *datavp = (void __user *) data;
569 unsigned long __user *datalp = datavp;
565 570
566 switch (request) { 571 switch (request) {
567 case PTRACE_PEEKTEXT: 572 case PTRACE_PEEKTEXT:
@@ -578,19 +583,17 @@ int ptrace_request(struct task_struct *child, long request,
578 ret = ptrace_setoptions(child, data); 583 ret = ptrace_setoptions(child, data);
579 break; 584 break;
580 case PTRACE_GETEVENTMSG: 585 case PTRACE_GETEVENTMSG:
581 ret = put_user(child->ptrace_message, (unsigned long __user *) data); 586 ret = put_user(child->ptrace_message, datalp);
582 break; 587 break;
583 588
584 case PTRACE_GETSIGINFO: 589 case PTRACE_GETSIGINFO:
585 ret = ptrace_getsiginfo(child, &siginfo); 590 ret = ptrace_getsiginfo(child, &siginfo);
586 if (!ret) 591 if (!ret)
587 ret = copy_siginfo_to_user((siginfo_t __user *) data, 592 ret = copy_siginfo_to_user(datavp, &siginfo);
588 &siginfo);
589 break; 593 break;
590 594
591 case PTRACE_SETSIGINFO: 595 case PTRACE_SETSIGINFO:
592 if (copy_from_user(&siginfo, (siginfo_t __user *) data, 596 if (copy_from_user(&siginfo, datavp, sizeof siginfo))
593 sizeof siginfo))
594 ret = -EFAULT; 597 ret = -EFAULT;
595 else 598 else
596 ret = ptrace_setsiginfo(child, &siginfo); 599 ret = ptrace_setsiginfo(child, &siginfo);
@@ -621,7 +624,7 @@ int ptrace_request(struct task_struct *child, long request,
621 } 624 }
622 mmput(mm); 625 mmput(mm);
623 626
624 ret = put_user(tmp, (unsigned long __user *) data); 627 ret = put_user(tmp, datalp);
625 break; 628 break;
626 } 629 }
627#endif 630#endif
@@ -650,7 +653,7 @@ int ptrace_request(struct task_struct *child, long request,
650 case PTRACE_SETREGSET: 653 case PTRACE_SETREGSET:
651 { 654 {
652 struct iovec kiov; 655 struct iovec kiov;
653 struct iovec __user *uiov = (struct iovec __user *) data; 656 struct iovec __user *uiov = datavp;
654 657
655 if (!access_ok(VERIFY_WRITE, uiov, sizeof(*uiov))) 658 if (!access_ok(VERIFY_WRITE, uiov, sizeof(*uiov)))
656 return -EFAULT; 659 return -EFAULT;
@@ -691,7 +694,8 @@ static struct task_struct *ptrace_get_task_struct(pid_t pid)
691#define arch_ptrace_attach(child) do { } while (0) 694#define arch_ptrace_attach(child) do { } while (0)
692#endif 695#endif
693 696
694SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data) 697SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
698 unsigned long, data)
695{ 699{
696 struct task_struct *child; 700 struct task_struct *child;
697 long ret; 701 long ret;
@@ -732,7 +736,8 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
732 return ret; 736 return ret;
733} 737}
734 738
735int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data) 739int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
740 unsigned long data)
736{ 741{
737 unsigned long tmp; 742 unsigned long tmp;
738 int copied; 743 int copied;
@@ -743,7 +748,8 @@ int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
743 return put_user(tmp, (unsigned long __user *)data); 748 return put_user(tmp, (unsigned long __user *)data);
744} 749}
745 750
746int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data) 751int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
752 unsigned long data)
747{ 753{
748 int copied; 754 int copied;
749 755
diff --git a/kernel/resource.c b/kernel/resource.c
index 7b36976e5dea..9c9841cb6902 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -453,6 +453,8 @@ static struct resource * __insert_resource(struct resource *parent, struct resou
453 453
454 if (first == parent) 454 if (first == parent)
455 return first; 455 return first;
456 if (WARN_ON(first == new)) /* duplicated insertion */
457 return first;
456 458
457 if ((first->start > new->start) || (first->end < new->end)) 459 if ((first->start > new->start) || (first->end < new->end))
458 break; 460 break;
diff --git a/kernel/signal.c b/kernel/signal.c
index 919562c3d6b7..4e3cff10fdce 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1105,7 +1105,8 @@ int zap_other_threads(struct task_struct *p)
1105 return count; 1105 return count;
1106} 1106}
1107 1107
1108struct sighand_struct *lock_task_sighand(struct task_struct *tsk, unsigned long *flags) 1108struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
1109 unsigned long *flags)
1109{ 1110{
1110 struct sighand_struct *sighand; 1111 struct sighand_struct *sighand;
1111 1112
@@ -1617,6 +1618,8 @@ static int sigkill_pending(struct task_struct *tsk)
1617 * is gone, we keep current->exit_code unless clear_code. 1618 * is gone, we keep current->exit_code unless clear_code.
1618 */ 1619 */
1619static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info) 1620static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info)
1621 __releases(&current->sighand->siglock)
1622 __acquires(&current->sighand->siglock)
1620{ 1623{
1621 if (arch_ptrace_stop_needed(exit_code, info)) { 1624 if (arch_ptrace_stop_needed(exit_code, info)) {
1622 /* 1625 /*
diff --git a/kernel/softirq.c b/kernel/softirq.c
index f02a9dfa19bc..18f4be0d5fe0 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -229,18 +229,20 @@ restart:
229 229
230 do { 230 do {
231 if (pending & 1) { 231 if (pending & 1) {
232 unsigned int vec_nr = h - softirq_vec;
232 int prev_count = preempt_count(); 233 int prev_count = preempt_count();
233 kstat_incr_softirqs_this_cpu(h - softirq_vec);
234 234
235 trace_softirq_entry(h, softirq_vec); 235 kstat_incr_softirqs_this_cpu(vec_nr);
236
237 trace_softirq_entry(vec_nr);
236 h->action(h); 238 h->action(h);
237 trace_softirq_exit(h, softirq_vec); 239 trace_softirq_exit(vec_nr);
238 if (unlikely(prev_count != preempt_count())) { 240 if (unlikely(prev_count != preempt_count())) {
239 printk(KERN_ERR "huh, entered softirq %td %s %p" 241 printk(KERN_ERR "huh, entered softirq %u %s %p"
240 "with preempt_count %08x," 242 "with preempt_count %08x,"
241 " exited with %08x?\n", h - softirq_vec, 243 " exited with %08x?\n", vec_nr,
242 softirq_to_name[h - softirq_vec], 244 softirq_to_name[vec_nr], h->action,
243 h->action, prev_count, preempt_count()); 245 prev_count, preempt_count());
244 preempt_count() = prev_count; 246 preempt_count() = prev_count;
245 } 247 }
246 248
diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 11281d5792bd..c8231fb15708 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -175,22 +175,8 @@ static void send_cpu_listeners(struct sk_buff *skb,
175 up_write(&listeners->sem); 175 up_write(&listeners->sem);
176} 176}
177 177
178static int fill_pid(pid_t pid, struct task_struct *tsk, 178static void fill_stats(struct task_struct *tsk, struct taskstats *stats)
179 struct taskstats *stats)
180{ 179{
181 int rc = 0;
182
183 if (!tsk) {
184 rcu_read_lock();
185 tsk = find_task_by_vpid(pid);
186 if (tsk)
187 get_task_struct(tsk);
188 rcu_read_unlock();
189 if (!tsk)
190 return -ESRCH;
191 } else
192 get_task_struct(tsk);
193
194 memset(stats, 0, sizeof(*stats)); 180 memset(stats, 0, sizeof(*stats));
195 /* 181 /*
196 * Each accounting subsystem adds calls to its functions to 182 * Each accounting subsystem adds calls to its functions to
@@ -209,17 +195,27 @@ static int fill_pid(pid_t pid, struct task_struct *tsk,
209 195
210 /* fill in extended acct fields */ 196 /* fill in extended acct fields */
211 xacct_add_tsk(stats, tsk); 197 xacct_add_tsk(stats, tsk);
198}
212 199
213 /* Define err: label here if needed */ 200static int fill_stats_for_pid(pid_t pid, struct taskstats *stats)
214 put_task_struct(tsk); 201{
215 return rc; 202 struct task_struct *tsk;
216 203
204 rcu_read_lock();
205 tsk = find_task_by_vpid(pid);
206 if (tsk)
207 get_task_struct(tsk);
208 rcu_read_unlock();
209 if (!tsk)
210 return -ESRCH;
211 fill_stats(tsk, stats);
212 put_task_struct(tsk);
213 return 0;
217} 214}
218 215
219static int fill_tgid(pid_t tgid, struct task_struct *first, 216static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats)
220 struct taskstats *stats)
221{ 217{
222 struct task_struct *tsk; 218 struct task_struct *tsk, *first;
223 unsigned long flags; 219 unsigned long flags;
224 int rc = -ESRCH; 220 int rc = -ESRCH;
225 221
@@ -228,8 +224,7 @@ static int fill_tgid(pid_t tgid, struct task_struct *first,
228 * leaders who are already counted with the dead tasks 224 * leaders who are already counted with the dead tasks
229 */ 225 */
230 rcu_read_lock(); 226 rcu_read_lock();
231 if (!first) 227 first = find_task_by_vpid(tgid);
232 first = find_task_by_vpid(tgid);
233 228
234 if (!first || !lock_task_sighand(first, &flags)) 229 if (!first || !lock_task_sighand(first, &flags))
235 goto out; 230 goto out;
@@ -268,7 +263,6 @@ out:
268 return rc; 263 return rc;
269} 264}
270 265
271
272static void fill_tgid_exit(struct task_struct *tsk) 266static void fill_tgid_exit(struct task_struct *tsk)
273{ 267{
274 unsigned long flags; 268 unsigned long flags;
@@ -360,6 +354,12 @@ static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
360 struct nlattr *na, *ret; 354 struct nlattr *na, *ret;
361 int aggr; 355 int aggr;
362 356
357 /* If we don't pad, we end up with alignment on a 4 byte boundary.
358 * This causes lots of runtime warnings on systems requiring 8 byte
359 * alignment */
360 u32 pids[2] = { pid, 0 };
361 int pid_size = ALIGN(sizeof(pid), sizeof(long));
362
363 aggr = (type == TASKSTATS_TYPE_PID) 363 aggr = (type == TASKSTATS_TYPE_PID)
364 ? TASKSTATS_TYPE_AGGR_PID 364 ? TASKSTATS_TYPE_AGGR_PID
365 : TASKSTATS_TYPE_AGGR_TGID; 365 : TASKSTATS_TYPE_AGGR_TGID;
@@ -367,7 +367,7 @@ static struct taskstats *mk_reply(struct sk_buff *skb, int type, u32 pid)
367 na = nla_nest_start(skb, aggr); 367 na = nla_nest_start(skb, aggr);
368 if (!na) 368 if (!na)
369 goto err; 369 goto err;
370 if (nla_put(skb, type, sizeof(pid), &pid) < 0) 370 if (nla_put(skb, type, pid_size, pids) < 0)
371 goto err; 371 goto err;
372 ret = nla_reserve(skb, TASKSTATS_TYPE_STATS, sizeof(struct taskstats)); 372 ret = nla_reserve(skb, TASKSTATS_TYPE_STATS, sizeof(struct taskstats));
373 if (!ret) 373 if (!ret)
@@ -424,39 +424,46 @@ err:
424 return rc; 424 return rc;
425} 425}
426 426
427static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info) 427static int cmd_attr_register_cpumask(struct genl_info *info)
428{ 428{
429 int rc;
430 struct sk_buff *rep_skb;
431 struct taskstats *stats;
432 size_t size;
433 cpumask_var_t mask; 429 cpumask_var_t mask;
430 int rc;
434 431
435 if (!alloc_cpumask_var(&mask, GFP_KERNEL)) 432 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
436 return -ENOMEM; 433 return -ENOMEM;
437
438 rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], mask); 434 rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], mask);
439 if (rc < 0) 435 if (rc < 0)
440 goto free_return_rc; 436 goto out;
441 if (rc == 0) { 437 rc = add_del_listener(info->snd_pid, mask, REGISTER);
442 rc = add_del_listener(info->snd_pid, mask, REGISTER); 438out:
443 goto free_return_rc; 439 free_cpumask_var(mask);
444 } 440 return rc;
441}
442
443static int cmd_attr_deregister_cpumask(struct genl_info *info)
444{
445 cpumask_var_t mask;
446 int rc;
445 447
448 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
449 return -ENOMEM;
446 rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], mask); 450 rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], mask);
447 if (rc < 0) 451 if (rc < 0)
448 goto free_return_rc; 452 goto out;
449 if (rc == 0) { 453 rc = add_del_listener(info->snd_pid, mask, DEREGISTER);
450 rc = add_del_listener(info->snd_pid, mask, DEREGISTER); 454out:
451free_return_rc:
452 free_cpumask_var(mask);
453 return rc;
454 }
455 free_cpumask_var(mask); 455 free_cpumask_var(mask);
456 return rc;
457}
458
459static int cmd_attr_pid(struct genl_info *info)
460{
461 struct taskstats *stats;
462 struct sk_buff *rep_skb;
463 size_t size;
464 u32 pid;
465 int rc;
456 466
457 /*
458 * Size includes space for nested attributes
459 */
460 size = nla_total_size(sizeof(u32)) + 467 size = nla_total_size(sizeof(u32)) +
461 nla_total_size(sizeof(struct taskstats)) + nla_total_size(0); 468 nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
462 469
@@ -465,33 +472,64 @@ free_return_rc:
465 return rc; 472 return rc;
466 473
467 rc = -EINVAL; 474 rc = -EINVAL;
468 if (info->attrs[TASKSTATS_CMD_ATTR_PID]) { 475 pid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_PID]);
469 u32 pid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_PID]); 476 stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, pid);
470 stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, pid); 477 if (!stats)
471 if (!stats) 478 goto err;
472 goto err; 479
473 480 rc = fill_stats_for_pid(pid, stats);
474 rc = fill_pid(pid, NULL, stats); 481 if (rc < 0)
475 if (rc < 0) 482 goto err;
476 goto err; 483 return send_reply(rep_skb, info);
477 } else if (info->attrs[TASKSTATS_CMD_ATTR_TGID]) { 484err:
478 u32 tgid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_TGID]); 485 nlmsg_free(rep_skb);
479 stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tgid); 486 return rc;
480 if (!stats) 487}
481 goto err; 488
482 489static int cmd_attr_tgid(struct genl_info *info)
483 rc = fill_tgid(tgid, NULL, stats); 490{
484 if (rc < 0) 491 struct taskstats *stats;
485 goto err; 492 struct sk_buff *rep_skb;
486 } else 493 size_t size;
494 u32 tgid;
495 int rc;
496
497 size = nla_total_size(sizeof(u32)) +
498 nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
499
500 rc = prepare_reply(info, TASKSTATS_CMD_NEW, &rep_skb, size);
501 if (rc < 0)
502 return rc;
503
504 rc = -EINVAL;
505 tgid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_TGID]);
506 stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tgid);
507 if (!stats)
487 goto err; 508 goto err;
488 509
510 rc = fill_stats_for_tgid(tgid, stats);
511 if (rc < 0)
512 goto err;
489 return send_reply(rep_skb, info); 513 return send_reply(rep_skb, info);
490err: 514err:
491 nlmsg_free(rep_skb); 515 nlmsg_free(rep_skb);
492 return rc; 516 return rc;
493} 517}
494 518
519static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
520{
521 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
522 return cmd_attr_register_cpumask(info);
523 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
524 return cmd_attr_deregister_cpumask(info);
525 else if (info->attrs[TASKSTATS_CMD_ATTR_PID])
526 return cmd_attr_pid(info);
527 else if (info->attrs[TASKSTATS_CMD_ATTR_TGID])
528 return cmd_attr_tgid(info);
529 else
530 return -EINVAL;
531}
532
495static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk) 533static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk)
496{ 534{
497 struct signal_struct *sig = tsk->signal; 535 struct signal_struct *sig = tsk->signal;
@@ -555,9 +593,7 @@ void taskstats_exit(struct task_struct *tsk, int group_dead)
555 if (!stats) 593 if (!stats)
556 goto err; 594 goto err;
557 595
558 rc = fill_pid(-1, tsk, stats); 596 fill_stats(tsk, stats);
559 if (rc < 0)
560 goto err;
561 597
562 /* 598 /*
563 * Doesn't matter if tsk is the leader or the last group member leaving 599 * Doesn't matter if tsk is the leader or the last group member leaving
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index c3dab054d18e..9ed509a015d8 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -224,6 +224,9 @@ enum {
224 RB_LEN_TIME_STAMP = 16, 224 RB_LEN_TIME_STAMP = 16,
225}; 225};
226 226
227#define skip_time_extend(event) \
228 ((struct ring_buffer_event *)((char *)event + RB_LEN_TIME_EXTEND))
229
227static inline int rb_null_event(struct ring_buffer_event *event) 230static inline int rb_null_event(struct ring_buffer_event *event)
228{ 231{
229 return event->type_len == RINGBUF_TYPE_PADDING && !event->time_delta; 232 return event->type_len == RINGBUF_TYPE_PADDING && !event->time_delta;
@@ -248,8 +251,12 @@ rb_event_data_length(struct ring_buffer_event *event)
248 return length + RB_EVNT_HDR_SIZE; 251 return length + RB_EVNT_HDR_SIZE;
249} 252}
250 253
251/* inline for ring buffer fast paths */ 254/*
252static unsigned 255 * Return the length of the given event. Will return
256 * the length of the time extend if the event is a
257 * time extend.
258 */
259static inline unsigned
253rb_event_length(struct ring_buffer_event *event) 260rb_event_length(struct ring_buffer_event *event)
254{ 261{
255 switch (event->type_len) { 262 switch (event->type_len) {
@@ -274,13 +281,41 @@ rb_event_length(struct ring_buffer_event *event)
274 return 0; 281 return 0;
275} 282}
276 283
284/*
285 * Return total length of time extend and data,
286 * or just the event length for all other events.
287 */
288static inline unsigned
289rb_event_ts_length(struct ring_buffer_event *event)
290{
291 unsigned len = 0;
292
293 if (event->type_len == RINGBUF_TYPE_TIME_EXTEND) {
294 /* time extends include the data event after it */
295 len = RB_LEN_TIME_EXTEND;
296 event = skip_time_extend(event);
297 }
298 return len + rb_event_length(event);
299}
300
277/** 301/**
278 * ring_buffer_event_length - return the length of the event 302 * ring_buffer_event_length - return the length of the event
279 * @event: the event to get the length of 303 * @event: the event to get the length of
304 *
305 * Returns the size of the data load of a data event.
306 * If the event is something other than a data event, it
307 * returns the size of the event itself. With the exception
308 * of a TIME EXTEND, where it still returns the size of the
309 * data load of the data event after it.
280 */ 310 */
281unsigned ring_buffer_event_length(struct ring_buffer_event *event) 311unsigned ring_buffer_event_length(struct ring_buffer_event *event)
282{ 312{
283 unsigned length = rb_event_length(event); 313 unsigned length;
314
315 if (event->type_len == RINGBUF_TYPE_TIME_EXTEND)
316 event = skip_time_extend(event);
317
318 length = rb_event_length(event);
284 if (event->type_len > RINGBUF_TYPE_DATA_TYPE_LEN_MAX) 319 if (event->type_len > RINGBUF_TYPE_DATA_TYPE_LEN_MAX)
285 return length; 320 return length;
286 length -= RB_EVNT_HDR_SIZE; 321 length -= RB_EVNT_HDR_SIZE;
@@ -294,6 +329,8 @@ EXPORT_SYMBOL_GPL(ring_buffer_event_length);
294static void * 329static void *
295rb_event_data(struct ring_buffer_event *event) 330rb_event_data(struct ring_buffer_event *event)
296{ 331{
332 if (event->type_len == RINGBUF_TYPE_TIME_EXTEND)
333 event = skip_time_extend(event);
297 BUG_ON(event->type_len > RINGBUF_TYPE_DATA_TYPE_LEN_MAX); 334 BUG_ON(event->type_len > RINGBUF_TYPE_DATA_TYPE_LEN_MAX);
298 /* If length is in len field, then array[0] has the data */ 335 /* If length is in len field, then array[0] has the data */
299 if (event->type_len) 336 if (event->type_len)
@@ -404,9 +441,6 @@ static inline int test_time_stamp(u64 delta)
404/* Max payload is BUF_PAGE_SIZE - header (8bytes) */ 441/* Max payload is BUF_PAGE_SIZE - header (8bytes) */
405#define BUF_MAX_DATA_SIZE (BUF_PAGE_SIZE - (sizeof(u32) * 2)) 442#define BUF_MAX_DATA_SIZE (BUF_PAGE_SIZE - (sizeof(u32) * 2))
406 443
407/* Max number of timestamps that can fit on a page */
408#define RB_TIMESTAMPS_PER_PAGE (BUF_PAGE_SIZE / RB_LEN_TIME_EXTEND)
409
410int ring_buffer_print_page_header(struct trace_seq *s) 444int ring_buffer_print_page_header(struct trace_seq *s)
411{ 445{
412 struct buffer_data_page field; 446 struct buffer_data_page field;
@@ -1546,6 +1580,25 @@ static void rb_inc_iter(struct ring_buffer_iter *iter)
1546 iter->head = 0; 1580 iter->head = 0;
1547} 1581}
1548 1582
1583/* Slow path, do not inline */
1584static noinline struct ring_buffer_event *
1585rb_add_time_stamp(struct ring_buffer_event *event, u64 delta)
1586{
1587 event->type_len = RINGBUF_TYPE_TIME_EXTEND;
1588
1589 /* Not the first event on the page? */
1590 if (rb_event_index(event)) {
1591 event->time_delta = delta & TS_MASK;
1592 event->array[0] = delta >> TS_SHIFT;
1593 } else {
1594 /* nope, just zero it */
1595 event->time_delta = 0;
1596 event->array[0] = 0;
1597 }
1598
1599 return skip_time_extend(event);
1600}
1601
1549/** 1602/**
1550 * ring_buffer_update_event - update event type and data 1603 * ring_buffer_update_event - update event type and data
1551 * @event: the even to update 1604 * @event: the even to update
@@ -1558,28 +1611,31 @@ static void rb_inc_iter(struct ring_buffer_iter *iter)
1558 * data field. 1611 * data field.
1559 */ 1612 */
1560static void 1613static void
1561rb_update_event(struct ring_buffer_event *event, 1614rb_update_event(struct ring_buffer_per_cpu *cpu_buffer,
1562 unsigned type, unsigned length) 1615 struct ring_buffer_event *event, unsigned length,
1616 int add_timestamp, u64 delta)
1563{ 1617{
1564 event->type_len = type; 1618 /* Only a commit updates the timestamp */
1565 1619 if (unlikely(!rb_event_is_commit(cpu_buffer, event)))
1566 switch (type) { 1620 delta = 0;
1567
1568 case RINGBUF_TYPE_PADDING:
1569 case RINGBUF_TYPE_TIME_EXTEND:
1570 case RINGBUF_TYPE_TIME_STAMP:
1571 break;
1572 1621
1573 case 0: 1622 /*
1574 length -= RB_EVNT_HDR_SIZE; 1623 * If we need to add a timestamp, then we
1575 if (length > RB_MAX_SMALL_DATA || RB_FORCE_8BYTE_ALIGNMENT) 1624 * add it to the start of the resevered space.
1576 event->array[0] = length; 1625 */
1577 else 1626 if (unlikely(add_timestamp)) {
1578 event->type_len = DIV_ROUND_UP(length, RB_ALIGNMENT); 1627 event = rb_add_time_stamp(event, delta);
1579 break; 1628 length -= RB_LEN_TIME_EXTEND;
1580 default: 1629 delta = 0;
1581 BUG();
1582 } 1630 }
1631
1632 event->time_delta = delta;
1633 length -= RB_EVNT_HDR_SIZE;
1634 if (length > RB_MAX_SMALL_DATA || RB_FORCE_8BYTE_ALIGNMENT) {
1635 event->type_len = 0;
1636 event->array[0] = length;
1637 } else
1638 event->type_len = DIV_ROUND_UP(length, RB_ALIGNMENT);
1583} 1639}
1584 1640
1585/* 1641/*
@@ -1823,10 +1879,13 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
1823 local_sub(length, &tail_page->write); 1879 local_sub(length, &tail_page->write);
1824} 1880}
1825 1881
1826static struct ring_buffer_event * 1882/*
1883 * This is the slow path, force gcc not to inline it.
1884 */
1885static noinline struct ring_buffer_event *
1827rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer, 1886rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
1828 unsigned long length, unsigned long tail, 1887 unsigned long length, unsigned long tail,
1829 struct buffer_page *tail_page, u64 *ts) 1888 struct buffer_page *tail_page, u64 ts)
1830{ 1889{
1831 struct buffer_page *commit_page = cpu_buffer->commit_page; 1890 struct buffer_page *commit_page = cpu_buffer->commit_page;
1832 struct ring_buffer *buffer = cpu_buffer->buffer; 1891 struct ring_buffer *buffer = cpu_buffer->buffer;
@@ -1909,8 +1968,8 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
1909 * Nested commits always have zero deltas, so 1968 * Nested commits always have zero deltas, so
1910 * just reread the time stamp 1969 * just reread the time stamp
1911 */ 1970 */
1912 *ts = rb_time_stamp(buffer); 1971 ts = rb_time_stamp(buffer);
1913 next_page->page->time_stamp = *ts; 1972 next_page->page->time_stamp = ts;
1914 } 1973 }
1915 1974
1916 out_again: 1975 out_again:
@@ -1929,12 +1988,21 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
1929 1988
1930static struct ring_buffer_event * 1989static struct ring_buffer_event *
1931__rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer, 1990__rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
1932 unsigned type, unsigned long length, u64 *ts) 1991 unsigned long length, u64 ts,
1992 u64 delta, int add_timestamp)
1933{ 1993{
1934 struct buffer_page *tail_page; 1994 struct buffer_page *tail_page;
1935 struct ring_buffer_event *event; 1995 struct ring_buffer_event *event;
1936 unsigned long tail, write; 1996 unsigned long tail, write;
1937 1997
1998 /*
1999 * If the time delta since the last event is too big to
2000 * hold in the time field of the event, then we append a
2001 * TIME EXTEND event ahead of the data event.
2002 */
2003 if (unlikely(add_timestamp))
2004 length += RB_LEN_TIME_EXTEND;
2005
1938 tail_page = cpu_buffer->tail_page; 2006 tail_page = cpu_buffer->tail_page;
1939 write = local_add_return(length, &tail_page->write); 2007 write = local_add_return(length, &tail_page->write);
1940 2008
@@ -1943,7 +2011,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
1943 tail = write - length; 2011 tail = write - length;
1944 2012
1945 /* See if we shot pass the end of this buffer page */ 2013 /* See if we shot pass the end of this buffer page */
1946 if (write > BUF_PAGE_SIZE) 2014 if (unlikely(write > BUF_PAGE_SIZE))
1947 return rb_move_tail(cpu_buffer, length, tail, 2015 return rb_move_tail(cpu_buffer, length, tail,
1948 tail_page, ts); 2016 tail_page, ts);
1949 2017
@@ -1951,18 +2019,16 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
1951 2019
1952 event = __rb_page_index(tail_page, tail); 2020 event = __rb_page_index(tail_page, tail);
1953 kmemcheck_annotate_bitfield(event, bitfield); 2021 kmemcheck_annotate_bitfield(event, bitfield);
1954 rb_update_event(event, type, length); 2022 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
1955 2023
1956 /* The passed in type is zero for DATA */ 2024 local_inc(&tail_page->entries);
1957 if (likely(!type))
1958 local_inc(&tail_page->entries);
1959 2025
1960 /* 2026 /*
1961 * If this is the first commit on the page, then update 2027 * If this is the first commit on the page, then update
1962 * its timestamp. 2028 * its timestamp.
1963 */ 2029 */
1964 if (!tail) 2030 if (!tail)
1965 tail_page->page->time_stamp = *ts; 2031 tail_page->page->time_stamp = ts;
1966 2032
1967 return event; 2033 return event;
1968} 2034}
@@ -1977,7 +2043,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
1977 unsigned long addr; 2043 unsigned long addr;
1978 2044
1979 new_index = rb_event_index(event); 2045 new_index = rb_event_index(event);
1980 old_index = new_index + rb_event_length(event); 2046 old_index = new_index + rb_event_ts_length(event);
1981 addr = (unsigned long)event; 2047 addr = (unsigned long)event;
1982 addr &= PAGE_MASK; 2048 addr &= PAGE_MASK;
1983 2049
@@ -2003,76 +2069,13 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
2003 return 0; 2069 return 0;
2004} 2070}
2005 2071
2006static int
2007rb_add_time_stamp(struct ring_buffer_per_cpu *cpu_buffer,
2008 u64 *ts, u64 *delta)
2009{
2010 struct ring_buffer_event *event;
2011 int ret;
2012
2013 WARN_ONCE(*delta > (1ULL << 59),
2014 KERN_WARNING "Delta way too big! %llu ts=%llu write stamp = %llu\n",
2015 (unsigned long long)*delta,
2016 (unsigned long long)*ts,
2017 (unsigned long long)cpu_buffer->write_stamp);
2018
2019 /*
2020 * The delta is too big, we to add a
2021 * new timestamp.
2022 */
2023 event = __rb_reserve_next(cpu_buffer,
2024 RINGBUF_TYPE_TIME_EXTEND,
2025 RB_LEN_TIME_EXTEND,
2026 ts);
2027 if (!event)
2028 return -EBUSY;
2029
2030 if (PTR_ERR(event) == -EAGAIN)
2031 return -EAGAIN;
2032
2033 /* Only a commited time event can update the write stamp */
2034 if (rb_event_is_commit(cpu_buffer, event)) {
2035 /*
2036 * If this is the first on the page, then it was
2037 * updated with the page itself. Try to discard it
2038 * and if we can't just make it zero.
2039 */
2040 if (rb_event_index(event)) {
2041 event->time_delta = *delta & TS_MASK;
2042 event->array[0] = *delta >> TS_SHIFT;
2043 } else {
2044 /* try to discard, since we do not need this */
2045 if (!rb_try_to_discard(cpu_buffer, event)) {
2046 /* nope, just zero it */
2047 event->time_delta = 0;
2048 event->array[0] = 0;
2049 }
2050 }
2051 cpu_buffer->write_stamp = *ts;
2052 /* let the caller know this was the commit */
2053 ret = 1;
2054 } else {
2055 /* Try to discard the event */
2056 if (!rb_try_to_discard(cpu_buffer, event)) {
2057 /* Darn, this is just wasted space */
2058 event->time_delta = 0;
2059 event->array[0] = 0;
2060 }
2061 ret = 0;
2062 }
2063
2064 *delta = 0;
2065
2066 return ret;
2067}
2068
2069static void rb_start_commit(struct ring_buffer_per_cpu *cpu_buffer) 2072static void rb_start_commit(struct ring_buffer_per_cpu *cpu_buffer)
2070{ 2073{
2071 local_inc(&cpu_buffer->committing); 2074 local_inc(&cpu_buffer->committing);
2072 local_inc(&cpu_buffer->commits); 2075 local_inc(&cpu_buffer->commits);
2073} 2076}
2074 2077
2075static void rb_end_commit(struct ring_buffer_per_cpu *cpu_buffer) 2078static inline void rb_end_commit(struct ring_buffer_per_cpu *cpu_buffer)
2076{ 2079{
2077 unsigned long commits; 2080 unsigned long commits;
2078 2081
@@ -2110,9 +2113,10 @@ rb_reserve_next_event(struct ring_buffer *buffer,
2110 unsigned long length) 2113 unsigned long length)
2111{ 2114{
2112 struct ring_buffer_event *event; 2115 struct ring_buffer_event *event;
2113 u64 ts, delta = 0; 2116 u64 ts, delta;
2114 int commit = 0;
2115 int nr_loops = 0; 2117 int nr_loops = 0;
2118 int add_timestamp;
2119 u64 diff;
2116 2120
2117 rb_start_commit(cpu_buffer); 2121 rb_start_commit(cpu_buffer);
2118 2122
@@ -2133,6 +2137,9 @@ rb_reserve_next_event(struct ring_buffer *buffer,
2133 2137
2134 length = rb_calculate_event_length(length); 2138 length = rb_calculate_event_length(length);
2135 again: 2139 again:
2140 add_timestamp = 0;
2141 delta = 0;
2142
2136 /* 2143 /*
2137 * We allow for interrupts to reenter here and do a trace. 2144 * We allow for interrupts to reenter here and do a trace.
2138 * If one does, it will cause this original code to loop 2145 * If one does, it will cause this original code to loop
@@ -2146,56 +2153,32 @@ rb_reserve_next_event(struct ring_buffer *buffer,
2146 goto out_fail; 2153 goto out_fail;
2147 2154
2148 ts = rb_time_stamp(cpu_buffer->buffer); 2155 ts = rb_time_stamp(cpu_buffer->buffer);
2156 diff = ts - cpu_buffer->write_stamp;
2149 2157
2150 /* 2158 /* make sure this diff is calculated here */
2151 * Only the first commit can update the timestamp. 2159 barrier();
2152 * Yes there is a race here. If an interrupt comes in
2153 * just after the conditional and it traces too, then it
2154 * will also check the deltas. More than one timestamp may
2155 * also be made. But only the entry that did the actual
2156 * commit will be something other than zero.
2157 */
2158 if (likely(cpu_buffer->tail_page == cpu_buffer->commit_page &&
2159 rb_page_write(cpu_buffer->tail_page) ==
2160 rb_commit_index(cpu_buffer))) {
2161 u64 diff;
2162
2163 diff = ts - cpu_buffer->write_stamp;
2164
2165 /* make sure this diff is calculated here */
2166 barrier();
2167
2168 /* Did the write stamp get updated already? */
2169 if (unlikely(ts < cpu_buffer->write_stamp))
2170 goto get_event;
2171 2160
2161 /* Did the write stamp get updated already? */
2162 if (likely(ts >= cpu_buffer->write_stamp)) {
2172 delta = diff; 2163 delta = diff;
2173 if (unlikely(test_time_stamp(delta))) { 2164 if (unlikely(test_time_stamp(delta))) {
2174 2165 WARN_ONCE(delta > (1ULL << 59),
2175 commit = rb_add_time_stamp(cpu_buffer, &ts, &delta); 2166 KERN_WARNING "Delta way too big! %llu ts=%llu write stamp = %llu\n",
2176 if (commit == -EBUSY) 2167 (unsigned long long)delta,
2177 goto out_fail; 2168 (unsigned long long)ts,
2178 2169 (unsigned long long)cpu_buffer->write_stamp);
2179 if (commit == -EAGAIN) 2170 add_timestamp = 1;
2180 goto again;
2181
2182 RB_WARN_ON(cpu_buffer, commit < 0);
2183 } 2171 }
2184 } 2172 }
2185 2173
2186 get_event: 2174 event = __rb_reserve_next(cpu_buffer, length, ts,
2187 event = __rb_reserve_next(cpu_buffer, 0, length, &ts); 2175 delta, add_timestamp);
2188 if (unlikely(PTR_ERR(event) == -EAGAIN)) 2176 if (unlikely(PTR_ERR(event) == -EAGAIN))
2189 goto again; 2177 goto again;
2190 2178
2191 if (!event) 2179 if (!event)
2192 goto out_fail; 2180 goto out_fail;
2193 2181
2194 if (!rb_event_is_commit(cpu_buffer, event))
2195 delta = 0;
2196
2197 event->time_delta = delta;
2198
2199 return event; 2182 return event;
2200 2183
2201 out_fail: 2184 out_fail:
@@ -2207,13 +2190,9 @@ rb_reserve_next_event(struct ring_buffer *buffer,
2207 2190
2208#define TRACE_RECURSIVE_DEPTH 16 2191#define TRACE_RECURSIVE_DEPTH 16
2209 2192
2210static int trace_recursive_lock(void) 2193/* Keep this code out of the fast path cache */
2194static noinline void trace_recursive_fail(void)
2211{ 2195{
2212 current->trace_recursion++;
2213
2214 if (likely(current->trace_recursion < TRACE_RECURSIVE_DEPTH))
2215 return 0;
2216
2217 /* Disable all tracing before we do anything else */ 2196 /* Disable all tracing before we do anything else */
2218 tracing_off_permanent(); 2197 tracing_off_permanent();
2219 2198
@@ -2225,10 +2204,21 @@ static int trace_recursive_lock(void)
2225 in_nmi()); 2204 in_nmi());
2226 2205
2227 WARN_ON_ONCE(1); 2206 WARN_ON_ONCE(1);
2207}
2208
2209static inline int trace_recursive_lock(void)
2210{
2211 current->trace_recursion++;
2212
2213 if (likely(current->trace_recursion < TRACE_RECURSIVE_DEPTH))
2214 return 0;
2215
2216 trace_recursive_fail();
2217
2228 return -1; 2218 return -1;
2229} 2219}
2230 2220
2231static void trace_recursive_unlock(void) 2221static inline void trace_recursive_unlock(void)
2232{ 2222{
2233 WARN_ON_ONCE(!current->trace_recursion); 2223 WARN_ON_ONCE(!current->trace_recursion);
2234 2224
@@ -2308,12 +2298,28 @@ static void
2308rb_update_write_stamp(struct ring_buffer_per_cpu *cpu_buffer, 2298rb_update_write_stamp(struct ring_buffer_per_cpu *cpu_buffer,
2309 struct ring_buffer_event *event) 2299 struct ring_buffer_event *event)
2310{ 2300{
2301 u64 delta;
2302
2311 /* 2303 /*
2312 * The event first in the commit queue updates the 2304 * The event first in the commit queue updates the
2313 * time stamp. 2305 * time stamp.
2314 */ 2306 */
2315 if (rb_event_is_commit(cpu_buffer, event)) 2307 if (rb_event_is_commit(cpu_buffer, event)) {
2316 cpu_buffer->write_stamp += event->time_delta; 2308 /*
2309 * A commit event that is first on a page
2310 * updates the write timestamp with the page stamp
2311 */
2312 if (!rb_event_index(event))
2313 cpu_buffer->write_stamp =
2314 cpu_buffer->commit_page->page->time_stamp;
2315 else if (event->type_len == RINGBUF_TYPE_TIME_EXTEND) {
2316 delta = event->array[0];
2317 delta <<= TS_SHIFT;
2318 delta += event->time_delta;
2319 cpu_buffer->write_stamp += delta;
2320 } else
2321 cpu_buffer->write_stamp += event->time_delta;
2322 }
2317} 2323}
2318 2324
2319static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer, 2325static void rb_commit(struct ring_buffer_per_cpu *cpu_buffer,
@@ -2353,6 +2359,9 @@ EXPORT_SYMBOL_GPL(ring_buffer_unlock_commit);
2353 2359
2354static inline void rb_event_discard(struct ring_buffer_event *event) 2360static inline void rb_event_discard(struct ring_buffer_event *event)
2355{ 2361{
2362 if (event->type_len == RINGBUF_TYPE_TIME_EXTEND)
2363 event = skip_time_extend(event);
2364
2356 /* array[0] holds the actual length for the discarded event */ 2365 /* array[0] holds the actual length for the discarded event */
2357 event->array[0] = rb_event_data_length(event) - RB_EVNT_HDR_SIZE; 2366 event->array[0] = rb_event_data_length(event) - RB_EVNT_HDR_SIZE;
2358 event->type_len = RINGBUF_TYPE_PADDING; 2367 event->type_len = RINGBUF_TYPE_PADDING;
@@ -3049,12 +3058,12 @@ rb_buffer_peek(struct ring_buffer_per_cpu *cpu_buffer, u64 *ts,
3049 3058
3050 again: 3059 again:
3051 /* 3060 /*
3052 * We repeat when a timestamp is encountered. It is possible 3061 * We repeat when a time extend is encountered.
3053 * to get multiple timestamps from an interrupt entering just 3062 * Since the time extend is always attached to a data event,
3054 * as one timestamp is about to be written, or from discarded 3063 * we should never loop more than once.
3055 * commits. The most that we can have is the number on a single page. 3064 * (We never hit the following condition more than twice).
3056 */ 3065 */
3057 if (RB_WARN_ON(cpu_buffer, ++nr_loops > RB_TIMESTAMPS_PER_PAGE)) 3066 if (RB_WARN_ON(cpu_buffer, ++nr_loops > 2))
3058 return NULL; 3067 return NULL;
3059 3068
3060 reader = rb_get_reader_page(cpu_buffer); 3069 reader = rb_get_reader_page(cpu_buffer);
@@ -3130,14 +3139,12 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
3130 return NULL; 3139 return NULL;
3131 3140
3132 /* 3141 /*
3133 * We repeat when a timestamp is encountered. 3142 * We repeat when a time extend is encountered.
3134 * We can get multiple timestamps by nested interrupts or also 3143 * Since the time extend is always attached to a data event,
3135 * if filtering is on (discarding commits). Since discarding 3144 * we should never loop more than once.
3136 * commits can be frequent we can get a lot of timestamps. 3145 * (We never hit the following condition more than twice).
3137 * But we limit them by not adding timestamps if they begin
3138 * at the start of a page.
3139 */ 3146 */
3140 if (RB_WARN_ON(cpu_buffer, ++nr_loops > RB_TIMESTAMPS_PER_PAGE)) 3147 if (RB_WARN_ON(cpu_buffer, ++nr_loops > 2))
3141 return NULL; 3148 return NULL;
3142 3149
3143 if (rb_per_cpu_empty(cpu_buffer)) 3150 if (rb_per_cpu_empty(cpu_buffer))
@@ -3835,7 +3842,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
3835 if (len > (commit - read)) 3842 if (len > (commit - read))
3836 len = (commit - read); 3843 len = (commit - read);
3837 3844
3838 size = rb_event_length(event); 3845 /* Always keep the time extend and data together */
3846 size = rb_event_ts_length(event);
3839 3847
3840 if (len < size) 3848 if (len < size)
3841 goto out_unlock; 3849 goto out_unlock;
@@ -3857,7 +3865,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
3857 break; 3865 break;
3858 3866
3859 event = rb_reader_event(cpu_buffer); 3867 event = rb_reader_event(cpu_buffer);
3860 size = rb_event_length(event); 3868 /* Always keep the time extend and data together */
3869 size = rb_event_ts_length(event);
3861 } while (len > size); 3870 } while (len > size);
3862 3871
3863 /* update bpage */ 3872 /* update bpage */
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 001bcd2ccf4a..82d9b8106cd0 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3996,13 +3996,9 @@ static void tracing_init_debugfs_percpu(long cpu)
3996{ 3996{
3997 struct dentry *d_percpu = tracing_dentry_percpu(); 3997 struct dentry *d_percpu = tracing_dentry_percpu();
3998 struct dentry *d_cpu; 3998 struct dentry *d_cpu;
3999 /* strlen(cpu) + MAX(log10(cpu)) + '\0' */ 3999 char cpu_dir[30]; /* 30 characters should be more than enough */
4000 char cpu_dir[7];
4001 4000
4002 if (cpu > 999 || cpu < 0) 4001 snprintf(cpu_dir, 30, "cpu%ld", cpu);
4003 return;
4004
4005 sprintf(cpu_dir, "cpu%ld", cpu);
4006 d_cpu = debugfs_create_dir(cpu_dir, d_percpu); 4002 d_cpu = debugfs_create_dir(cpu_dir, d_percpu);
4007 if (!d_cpu) { 4003 if (!d_cpu) {
4008 pr_warning("Could not create debugfs '%s' entry\n", cpu_dir); 4004 pr_warning("Could not create debugfs '%s' entry\n", cpu_dir);
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index b8d2852baa4a..2dec9bcde8b4 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -31,7 +31,6 @@
31#include <linux/perf_event.h> 31#include <linux/perf_event.h>
32#include <linux/stringify.h> 32#include <linux/stringify.h>
33#include <linux/limits.h> 33#include <linux/limits.h>
34#include <linux/uaccess.h>
35#include <asm/bitsperlong.h> 34#include <asm/bitsperlong.h>
36 35
37#include "trace.h" 36#include "trace.h"
diff --git a/kernel/tsacct.c b/kernel/tsacct.c
index 0a67e041edf8..24dc60d9fa1f 100644
--- a/kernel/tsacct.c
+++ b/kernel/tsacct.c
@@ -63,12 +63,10 @@ void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
63 stats->ac_ppid = pid_alive(tsk) ? 63 stats->ac_ppid = pid_alive(tsk) ?
64 rcu_dereference(tsk->real_parent)->tgid : 0; 64 rcu_dereference(tsk->real_parent)->tgid : 0;
65 rcu_read_unlock(); 65 rcu_read_unlock();
66 stats->ac_utime = cputime_to_msecs(tsk->utime) * USEC_PER_MSEC; 66 stats->ac_utime = cputime_to_usecs(tsk->utime);
67 stats->ac_stime = cputime_to_msecs(tsk->stime) * USEC_PER_MSEC; 67 stats->ac_stime = cputime_to_usecs(tsk->stime);
68 stats->ac_utimescaled = 68 stats->ac_utimescaled = cputime_to_usecs(tsk->utimescaled);
69 cputime_to_msecs(tsk->utimescaled) * USEC_PER_MSEC; 69 stats->ac_stimescaled = cputime_to_usecs(tsk->stimescaled);
70 stats->ac_stimescaled =
71 cputime_to_msecs(tsk->stimescaled) * USEC_PER_MSEC;
72 stats->ac_minflt = tsk->min_flt; 70 stats->ac_minflt = tsk->min_flt;
73 stats->ac_majflt = tsk->maj_flt; 71 stats->ac_majflt = tsk->maj_flt;
74 72
diff --git a/mm/highmem.c b/mm/highmem.c
index 781e754a75ac..693394daa2ed 100644
--- a/mm/highmem.c
+++ b/mm/highmem.c
@@ -29,6 +29,11 @@
29#include <linux/kgdb.h> 29#include <linux/kgdb.h>
30#include <asm/tlbflush.h> 30#include <asm/tlbflush.h>
31 31
32
33#if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
34DEFINE_PER_CPU(int, __kmap_atomic_idx);
35#endif
36
32/* 37/*
33 * Virtual_count is not a pure "count". 38 * Virtual_count is not a pure "count".
34 * 0 means that it is not mapped, and has not been mapped 39 * 0 means that it is not mapped, and has not been mapped
@@ -43,7 +48,6 @@ unsigned long totalhigh_pages __read_mostly;
43EXPORT_SYMBOL(totalhigh_pages); 48EXPORT_SYMBOL(totalhigh_pages);
44 49
45 50
46DEFINE_PER_CPU(int, __kmap_atomic_idx);
47EXPORT_PER_CPU_SYMBOL(__kmap_atomic_idx); 51EXPORT_PER_CPU_SYMBOL(__kmap_atomic_idx);
48 52
49unsigned int nr_free_highpages (void) 53unsigned int nr_free_highpages (void)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9be3cf8a5da4..9a99cfaf0a19 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -89,7 +89,10 @@ enum mem_cgroup_stat_index {
89 MEM_CGROUP_STAT_PGPGIN_COUNT, /* # of pages paged in */ 89 MEM_CGROUP_STAT_PGPGIN_COUNT, /* # of pages paged in */
90 MEM_CGROUP_STAT_PGPGOUT_COUNT, /* # of pages paged out */ 90 MEM_CGROUP_STAT_PGPGOUT_COUNT, /* # of pages paged out */
91 MEM_CGROUP_STAT_SWAPOUT, /* # of pages, swapped out */ 91 MEM_CGROUP_STAT_SWAPOUT, /* # of pages, swapped out */
92 MEM_CGROUP_EVENTS, /* incremented at every pagein/pageout */ 92 MEM_CGROUP_STAT_DATA, /* end of data requires synchronization */
93 /* incremented at every pagein/pageout */
94 MEM_CGROUP_EVENTS = MEM_CGROUP_STAT_DATA,
95 MEM_CGROUP_ON_MOVE, /* someone is moving account between groups */
93 96
94 MEM_CGROUP_STAT_NSTATS, 97 MEM_CGROUP_STAT_NSTATS,
95}; 98};
@@ -254,6 +257,12 @@ struct mem_cgroup {
254 * percpu counter. 257 * percpu counter.
255 */ 258 */
256 struct mem_cgroup_stat_cpu *stat; 259 struct mem_cgroup_stat_cpu *stat;
260 /*
261 * used when a cpu is offlined or other synchronizations
262 * See mem_cgroup_read_stat().
263 */
264 struct mem_cgroup_stat_cpu nocpu_base;
265 spinlock_t pcp_counter_lock;
257}; 266};
258 267
259/* Stuffs for move charges at task migration. */ 268/* Stuffs for move charges at task migration. */
@@ -530,14 +539,40 @@ mem_cgroup_largest_soft_limit_node(struct mem_cgroup_tree_per_zone *mctz)
530 return mz; 539 return mz;
531} 540}
532 541
542/*
543 * Implementation Note: reading percpu statistics for memcg.
544 *
545 * Both of vmstat[] and percpu_counter has threshold and do periodic
546 * synchronization to implement "quick" read. There are trade-off between
547 * reading cost and precision of value. Then, we may have a chance to implement
548 * a periodic synchronizion of counter in memcg's counter.
549 *
550 * But this _read() function is used for user interface now. The user accounts
551 * memory usage by memory cgroup and he _always_ requires exact value because
552 * he accounts memory. Even if we provide quick-and-fuzzy read, we always
553 * have to visit all online cpus and make sum. So, for now, unnecessary
554 * synchronization is not implemented. (just implemented for cpu hotplug)
555 *
556 * If there are kernel internal actions which can make use of some not-exact
557 * value, and reading all cpu value can be performance bottleneck in some
558 * common workload, threashold and synchonization as vmstat[] should be
559 * implemented.
560 */
533static s64 mem_cgroup_read_stat(struct mem_cgroup *mem, 561static s64 mem_cgroup_read_stat(struct mem_cgroup *mem,
534 enum mem_cgroup_stat_index idx) 562 enum mem_cgroup_stat_index idx)
535{ 563{
536 int cpu; 564 int cpu;
537 s64 val = 0; 565 s64 val = 0;
538 566
539 for_each_possible_cpu(cpu) 567 get_online_cpus();
568 for_each_online_cpu(cpu)
540 val += per_cpu(mem->stat->count[idx], cpu); 569 val += per_cpu(mem->stat->count[idx], cpu);
570#ifdef CONFIG_HOTPLUG_CPU
571 spin_lock(&mem->pcp_counter_lock);
572 val += mem->nocpu_base.count[idx];
573 spin_unlock(&mem->pcp_counter_lock);
574#endif
575 put_online_cpus();
541 return val; 576 return val;
542} 577}
543 578
@@ -659,40 +694,83 @@ static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
659 return mem; 694 return mem;
660} 695}
661 696
662/* 697/* The caller has to guarantee "mem" exists before calling this */
663 * Call callback function against all cgroup under hierarchy tree. 698static struct mem_cgroup *mem_cgroup_start_loop(struct mem_cgroup *mem)
664 */
665static int mem_cgroup_walk_tree(struct mem_cgroup *root, void *data,
666 int (*func)(struct mem_cgroup *, void *))
667{ 699{
668 int found, ret, nextid;
669 struct cgroup_subsys_state *css; 700 struct cgroup_subsys_state *css;
670 struct mem_cgroup *mem; 701 int found;
671
672 if (!root->use_hierarchy)
673 return (*func)(root, data);
674 702
675 nextid = 1; 703 if (!mem) /* ROOT cgroup has the smallest ID */
676 do { 704 return root_mem_cgroup; /*css_put/get against root is ignored*/
677 ret = 0; 705 if (!mem->use_hierarchy) {
706 if (css_tryget(&mem->css))
707 return mem;
708 return NULL;
709 }
710 rcu_read_lock();
711 /*
712 * searching a memory cgroup which has the smallest ID under given
713 * ROOT cgroup. (ID >= 1)
714 */
715 css = css_get_next(&mem_cgroup_subsys, 1, &mem->css, &found);
716 if (css && css_tryget(css))
717 mem = container_of(css, struct mem_cgroup, css);
718 else
678 mem = NULL; 719 mem = NULL;
720 rcu_read_unlock();
721 return mem;
722}
723
724static struct mem_cgroup *mem_cgroup_get_next(struct mem_cgroup *iter,
725 struct mem_cgroup *root,
726 bool cond)
727{
728 int nextid = css_id(&iter->css) + 1;
729 int found;
730 int hierarchy_used;
731 struct cgroup_subsys_state *css;
732
733 hierarchy_used = iter->use_hierarchy;
679 734
735 css_put(&iter->css);
736 /* If no ROOT, walk all, ignore hierarchy */
737 if (!cond || (root && !hierarchy_used))
738 return NULL;
739
740 if (!root)
741 root = root_mem_cgroup;
742
743 do {
744 iter = NULL;
680 rcu_read_lock(); 745 rcu_read_lock();
681 css = css_get_next(&mem_cgroup_subsys, nextid, &root->css, 746
682 &found); 747 css = css_get_next(&mem_cgroup_subsys, nextid,
748 &root->css, &found);
683 if (css && css_tryget(css)) 749 if (css && css_tryget(css))
684 mem = container_of(css, struct mem_cgroup, css); 750 iter = container_of(css, struct mem_cgroup, css);
685 rcu_read_unlock(); 751 rcu_read_unlock();
686 752 /* If css is NULL, no more cgroups will be found */
687 if (mem) {
688 ret = (*func)(mem, data);
689 css_put(&mem->css);
690 }
691 nextid = found + 1; 753 nextid = found + 1;
692 } while (!ret && css); 754 } while (css && !iter);
693 755
694 return ret; 756 return iter;
695} 757}
758/*
759 * for_eacn_mem_cgroup_tree() for visiting all cgroup under tree. Please
760 * be careful that "break" loop is not allowed. We have reference count.
761 * Instead of that modify "cond" to be false and "continue" to exit the loop.
762 */
763#define for_each_mem_cgroup_tree_cond(iter, root, cond) \
764 for (iter = mem_cgroup_start_loop(root);\
765 iter != NULL;\
766 iter = mem_cgroup_get_next(iter, root, cond))
767
768#define for_each_mem_cgroup_tree(iter, root) \
769 for_each_mem_cgroup_tree_cond(iter, root, true)
770
771#define for_each_mem_cgroup_all(iter) \
772 for_each_mem_cgroup_tree_cond(iter, NULL, true)
773
696 774
697static inline bool mem_cgroup_is_root(struct mem_cgroup *mem) 775static inline bool mem_cgroup_is_root(struct mem_cgroup *mem)
698{ 776{
@@ -1051,7 +1129,52 @@ static unsigned int get_swappiness(struct mem_cgroup *memcg)
1051 return swappiness; 1129 return swappiness;
1052} 1130}
1053 1131
1054/* A routine for testing mem is not under move_account */ 1132static void mem_cgroup_start_move(struct mem_cgroup *mem)
1133{
1134 int cpu;
1135
1136 get_online_cpus();
1137 spin_lock(&mem->pcp_counter_lock);
1138 for_each_online_cpu(cpu)
1139 per_cpu(mem->stat->count[MEM_CGROUP_ON_MOVE], cpu) += 1;
1140 mem->nocpu_base.count[MEM_CGROUP_ON_MOVE] += 1;
1141 spin_unlock(&mem->pcp_counter_lock);
1142 put_online_cpus();
1143
1144 synchronize_rcu();
1145}
1146
1147static void mem_cgroup_end_move(struct mem_cgroup *mem)
1148{
1149 int cpu;
1150
1151 if (!mem)
1152 return;
1153 get_online_cpus();
1154 spin_lock(&mem->pcp_counter_lock);
1155 for_each_online_cpu(cpu)
1156 per_cpu(mem->stat->count[MEM_CGROUP_ON_MOVE], cpu) -= 1;
1157 mem->nocpu_base.count[MEM_CGROUP_ON_MOVE] -= 1;
1158 spin_unlock(&mem->pcp_counter_lock);
1159 put_online_cpus();
1160}
1161/*
1162 * 2 routines for checking "mem" is under move_account() or not.
1163 *
1164 * mem_cgroup_stealed() - checking a cgroup is mc.from or not. This is used
1165 * for avoiding race in accounting. If true,
1166 * pc->mem_cgroup may be overwritten.
1167 *
1168 * mem_cgroup_under_move() - checking a cgroup is mc.from or mc.to or
1169 * under hierarchy of moving cgroups. This is for
1170 * waiting at hith-memory prressure caused by "move".
1171 */
1172
1173static bool mem_cgroup_stealed(struct mem_cgroup *mem)
1174{
1175 VM_BUG_ON(!rcu_read_lock_held());
1176 return this_cpu_read(mem->stat->count[MEM_CGROUP_ON_MOVE]) > 0;
1177}
1055 1178
1056static bool mem_cgroup_under_move(struct mem_cgroup *mem) 1179static bool mem_cgroup_under_move(struct mem_cgroup *mem)
1057{ 1180{
@@ -1092,13 +1215,6 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *mem)
1092 return false; 1215 return false;
1093} 1216}
1094 1217
1095static int mem_cgroup_count_children_cb(struct mem_cgroup *mem, void *data)
1096{
1097 int *val = data;
1098 (*val)++;
1099 return 0;
1100}
1101
1102/** 1218/**
1103 * mem_cgroup_print_oom_info: Called from OOM with tasklist_lock held in read mode. 1219 * mem_cgroup_print_oom_info: Called from OOM with tasklist_lock held in read mode.
1104 * @memcg: The memory cgroup that went over limit 1220 * @memcg: The memory cgroup that went over limit
@@ -1173,7 +1289,10 @@ done:
1173static int mem_cgroup_count_children(struct mem_cgroup *mem) 1289static int mem_cgroup_count_children(struct mem_cgroup *mem)
1174{ 1290{
1175 int num = 0; 1291 int num = 0;
1176 mem_cgroup_walk_tree(mem, &num, mem_cgroup_count_children_cb); 1292 struct mem_cgroup *iter;
1293
1294 for_each_mem_cgroup_tree(iter, mem)
1295 num++;
1177 return num; 1296 return num;
1178} 1297}
1179 1298
@@ -1322,49 +1441,39 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem,
1322 return total; 1441 return total;
1323} 1442}
1324 1443
1325static int mem_cgroup_oom_lock_cb(struct mem_cgroup *mem, void *data)
1326{
1327 int *val = (int *)data;
1328 int x;
1329 /*
1330 * Logically, we can stop scanning immediately when we find
1331 * a memcg is already locked. But condidering unlock ops and
1332 * creation/removal of memcg, scan-all is simple operation.
1333 */
1334 x = atomic_inc_return(&mem->oom_lock);
1335 *val = max(x, *val);
1336 return 0;
1337}
1338/* 1444/*
1339 * Check OOM-Killer is already running under our hierarchy. 1445 * Check OOM-Killer is already running under our hierarchy.
1340 * If someone is running, return false. 1446 * If someone is running, return false.
1341 */ 1447 */
1342static bool mem_cgroup_oom_lock(struct mem_cgroup *mem) 1448static bool mem_cgroup_oom_lock(struct mem_cgroup *mem)
1343{ 1449{
1344 int lock_count = 0; 1450 int x, lock_count = 0;
1451 struct mem_cgroup *iter;
1345 1452
1346 mem_cgroup_walk_tree(mem, &lock_count, mem_cgroup_oom_lock_cb); 1453 for_each_mem_cgroup_tree(iter, mem) {
1454 x = atomic_inc_return(&iter->oom_lock);
1455 lock_count = max(x, lock_count);
1456 }
1347 1457
1348 if (lock_count == 1) 1458 if (lock_count == 1)
1349 return true; 1459 return true;
1350 return false; 1460 return false;
1351} 1461}
1352 1462
1353static int mem_cgroup_oom_unlock_cb(struct mem_cgroup *mem, void *data) 1463static int mem_cgroup_oom_unlock(struct mem_cgroup *mem)
1354{ 1464{
1465 struct mem_cgroup *iter;
1466
1355 /* 1467 /*
1356 * When a new child is created while the hierarchy is under oom, 1468 * When a new child is created while the hierarchy is under oom,
1357 * mem_cgroup_oom_lock() may not be called. We have to use 1469 * mem_cgroup_oom_lock() may not be called. We have to use
1358 * atomic_add_unless() here. 1470 * atomic_add_unless() here.
1359 */ 1471 */
1360 atomic_add_unless(&mem->oom_lock, -1, 0); 1472 for_each_mem_cgroup_tree(iter, mem)
1473 atomic_add_unless(&iter->oom_lock, -1, 0);
1361 return 0; 1474 return 0;
1362} 1475}
1363 1476
1364static void mem_cgroup_oom_unlock(struct mem_cgroup *mem)
1365{
1366 mem_cgroup_walk_tree(mem, NULL, mem_cgroup_oom_unlock_cb);
1367}
1368 1477
1369static DEFINE_MUTEX(memcg_oom_mutex); 1478static DEFINE_MUTEX(memcg_oom_mutex);
1370static DECLARE_WAIT_QUEUE_HEAD(memcg_oom_waitq); 1479static DECLARE_WAIT_QUEUE_HEAD(memcg_oom_waitq);
@@ -1462,34 +1571,73 @@ bool mem_cgroup_handle_oom(struct mem_cgroup *mem, gfp_t mask)
1462/* 1571/*
1463 * Currently used to update mapped file statistics, but the routine can be 1572 * Currently used to update mapped file statistics, but the routine can be
1464 * generalized to update other statistics as well. 1573 * generalized to update other statistics as well.
1574 *
1575 * Notes: Race condition
1576 *
1577 * We usually use page_cgroup_lock() for accessing page_cgroup member but
1578 * it tends to be costly. But considering some conditions, we doesn't need
1579 * to do so _always_.
1580 *
1581 * Considering "charge", lock_page_cgroup() is not required because all
1582 * file-stat operations happen after a page is attached to radix-tree. There
1583 * are no race with "charge".
1584 *
1585 * Considering "uncharge", we know that memcg doesn't clear pc->mem_cgroup
1586 * at "uncharge" intentionally. So, we always see valid pc->mem_cgroup even
1587 * if there are race with "uncharge". Statistics itself is properly handled
1588 * by flags.
1589 *
1590 * Considering "move", this is an only case we see a race. To make the race
1591 * small, we check MEM_CGROUP_ON_MOVE percpu value and detect there are
1592 * possibility of race condition. If there is, we take a lock.
1465 */ 1593 */
1466void mem_cgroup_update_file_mapped(struct page *page, int val) 1594
1595static void mem_cgroup_update_file_stat(struct page *page, int idx, int val)
1467{ 1596{
1468 struct mem_cgroup *mem; 1597 struct mem_cgroup *mem;
1469 struct page_cgroup *pc; 1598 struct page_cgroup *pc = lookup_page_cgroup(page);
1599 bool need_unlock = false;
1470 1600
1471 pc = lookup_page_cgroup(page);
1472 if (unlikely(!pc)) 1601 if (unlikely(!pc))
1473 return; 1602 return;
1474 1603
1475 lock_page_cgroup(pc); 1604 rcu_read_lock();
1476 mem = pc->mem_cgroup; 1605 mem = pc->mem_cgroup;
1477 if (!mem || !PageCgroupUsed(pc)) 1606 if (unlikely(!mem || !PageCgroupUsed(pc)))
1478 goto done; 1607 goto out;
1608 /* pc->mem_cgroup is unstable ? */
1609 if (unlikely(mem_cgroup_stealed(mem))) {
1610 /* take a lock against to access pc->mem_cgroup */
1611 lock_page_cgroup(pc);
1612 need_unlock = true;
1613 mem = pc->mem_cgroup;
1614 if (!mem || !PageCgroupUsed(pc))
1615 goto out;
1616 }
1479 1617
1480 /* 1618 this_cpu_add(mem->stat->count[idx], val);
1481 * Preemption is already disabled. We can use __this_cpu_xxx 1619
1482 */ 1620 switch (idx) {
1483 if (val > 0) { 1621 case MEM_CGROUP_STAT_FILE_MAPPED:
1484 __this_cpu_inc(mem->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]); 1622 if (val > 0)
1485 SetPageCgroupFileMapped(pc); 1623 SetPageCgroupFileMapped(pc);
1486 } else { 1624 else if (!page_mapped(page))
1487 __this_cpu_dec(mem->stat->count[MEM_CGROUP_STAT_FILE_MAPPED]); 1625 ClearPageCgroupFileMapped(pc);
1488 ClearPageCgroupFileMapped(pc); 1626 break;
1627 default:
1628 BUG();
1489 } 1629 }
1490 1630
1491done: 1631out:
1492 unlock_page_cgroup(pc); 1632 if (unlikely(need_unlock))
1633 unlock_page_cgroup(pc);
1634 rcu_read_unlock();
1635 return;
1636}
1637
1638void mem_cgroup_update_file_mapped(struct page *page, int val)
1639{
1640 mem_cgroup_update_file_stat(page, MEM_CGROUP_STAT_FILE_MAPPED, val);
1493} 1641}
1494 1642
1495/* 1643/*
@@ -1605,15 +1753,55 @@ static void drain_all_stock_sync(void)
1605 atomic_dec(&memcg_drain_count); 1753 atomic_dec(&memcg_drain_count);
1606} 1754}
1607 1755
1608static int __cpuinit memcg_stock_cpu_callback(struct notifier_block *nb, 1756/*
1757 * This function drains percpu counter value from DEAD cpu and
1758 * move it to local cpu. Note that this function can be preempted.
1759 */
1760static void mem_cgroup_drain_pcp_counter(struct mem_cgroup *mem, int cpu)
1761{
1762 int i;
1763
1764 spin_lock(&mem->pcp_counter_lock);
1765 for (i = 0; i < MEM_CGROUP_STAT_DATA; i++) {
1766 s64 x = per_cpu(mem->stat->count[i], cpu);
1767
1768 per_cpu(mem->stat->count[i], cpu) = 0;
1769 mem->nocpu_base.count[i] += x;
1770 }
1771 /* need to clear ON_MOVE value, works as a kind of lock. */
1772 per_cpu(mem->stat->count[MEM_CGROUP_ON_MOVE], cpu) = 0;
1773 spin_unlock(&mem->pcp_counter_lock);
1774}
1775
1776static void synchronize_mem_cgroup_on_move(struct mem_cgroup *mem, int cpu)
1777{
1778 int idx = MEM_CGROUP_ON_MOVE;
1779
1780 spin_lock(&mem->pcp_counter_lock);
1781 per_cpu(mem->stat->count[idx], cpu) = mem->nocpu_base.count[idx];
1782 spin_unlock(&mem->pcp_counter_lock);
1783}
1784
1785static int __cpuinit memcg_cpu_hotplug_callback(struct notifier_block *nb,
1609 unsigned long action, 1786 unsigned long action,
1610 void *hcpu) 1787 void *hcpu)
1611{ 1788{
1612 int cpu = (unsigned long)hcpu; 1789 int cpu = (unsigned long)hcpu;
1613 struct memcg_stock_pcp *stock; 1790 struct memcg_stock_pcp *stock;
1791 struct mem_cgroup *iter;
1792
1793 if ((action == CPU_ONLINE)) {
1794 for_each_mem_cgroup_all(iter)
1795 synchronize_mem_cgroup_on_move(iter, cpu);
1796 return NOTIFY_OK;
1797 }
1614 1798
1615 if (action != CPU_DEAD) 1799 if ((action != CPU_DEAD) || action != CPU_DEAD_FROZEN)
1616 return NOTIFY_OK; 1800 return NOTIFY_OK;
1801
1802 for_each_mem_cgroup_all(iter)
1803 mem_cgroup_drain_pcp_counter(iter, cpu);
1804
1617 stock = &per_cpu(memcg_stock, cpu); 1805 stock = &per_cpu(memcg_stock, cpu);
1618 drain_stock(stock); 1806 drain_stock(stock);
1619 return NOTIFY_OK; 1807 return NOTIFY_OK;
@@ -3038,6 +3226,7 @@ move_account:
3038 lru_add_drain_all(); 3226 lru_add_drain_all();
3039 drain_all_stock_sync(); 3227 drain_all_stock_sync();
3040 ret = 0; 3228 ret = 0;
3229 mem_cgroup_start_move(mem);
3041 for_each_node_state(node, N_HIGH_MEMORY) { 3230 for_each_node_state(node, N_HIGH_MEMORY) {
3042 for (zid = 0; !ret && zid < MAX_NR_ZONES; zid++) { 3231 for (zid = 0; !ret && zid < MAX_NR_ZONES; zid++) {
3043 enum lru_list l; 3232 enum lru_list l;
@@ -3051,6 +3240,7 @@ move_account:
3051 if (ret) 3240 if (ret)
3052 break; 3241 break;
3053 } 3242 }
3243 mem_cgroup_end_move(mem);
3054 memcg_oom_recover(mem); 3244 memcg_oom_recover(mem);
3055 /* it seems parent cgroup doesn't have enough mem */ 3245 /* it seems parent cgroup doesn't have enough mem */
3056 if (ret == -ENOMEM) 3246 if (ret == -ENOMEM)
@@ -3137,33 +3327,25 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft,
3137 return retval; 3327 return retval;
3138} 3328}
3139 3329
3140struct mem_cgroup_idx_data {
3141 s64 val;
3142 enum mem_cgroup_stat_index idx;
3143};
3144 3330
3145static int 3331static u64 mem_cgroup_get_recursive_idx_stat(struct mem_cgroup *mem,
3146mem_cgroup_get_idx_stat(struct mem_cgroup *mem, void *data) 3332 enum mem_cgroup_stat_index idx)
3147{ 3333{
3148 struct mem_cgroup_idx_data *d = data; 3334 struct mem_cgroup *iter;
3149 d->val += mem_cgroup_read_stat(mem, d->idx); 3335 s64 val = 0;
3150 return 0;
3151}
3152 3336
3153static void 3337 /* each per cpu's value can be minus.Then, use s64 */
3154mem_cgroup_get_recursive_idx_stat(struct mem_cgroup *mem, 3338 for_each_mem_cgroup_tree(iter, mem)
3155 enum mem_cgroup_stat_index idx, s64 *val) 3339 val += mem_cgroup_read_stat(iter, idx);
3156{ 3340
3157 struct mem_cgroup_idx_data d; 3341 if (val < 0) /* race ? */
3158 d.idx = idx; 3342 val = 0;
3159 d.val = 0; 3343 return val;
3160 mem_cgroup_walk_tree(mem, &d, mem_cgroup_get_idx_stat);
3161 *val = d.val;
3162} 3344}
3163 3345
3164static inline u64 mem_cgroup_usage(struct mem_cgroup *mem, bool swap) 3346static inline u64 mem_cgroup_usage(struct mem_cgroup *mem, bool swap)
3165{ 3347{
3166 u64 idx_val, val; 3348 u64 val;
3167 3349
3168 if (!mem_cgroup_is_root(mem)) { 3350 if (!mem_cgroup_is_root(mem)) {
3169 if (!swap) 3351 if (!swap)
@@ -3172,16 +3354,12 @@ static inline u64 mem_cgroup_usage(struct mem_cgroup *mem, bool swap)
3172 return res_counter_read_u64(&mem->memsw, RES_USAGE); 3354 return res_counter_read_u64(&mem->memsw, RES_USAGE);
3173 } 3355 }
3174 3356
3175 mem_cgroup_get_recursive_idx_stat(mem, MEM_CGROUP_STAT_CACHE, &idx_val); 3357 val = mem_cgroup_get_recursive_idx_stat(mem, MEM_CGROUP_STAT_CACHE);
3176 val = idx_val; 3358 val += mem_cgroup_get_recursive_idx_stat(mem, MEM_CGROUP_STAT_RSS);
3177 mem_cgroup_get_recursive_idx_stat(mem, MEM_CGROUP_STAT_RSS, &idx_val);
3178 val += idx_val;
3179 3359
3180 if (swap) { 3360 if (swap)
3181 mem_cgroup_get_recursive_idx_stat(mem, 3361 val += mem_cgroup_get_recursive_idx_stat(mem,
3182 MEM_CGROUP_STAT_SWAPOUT, &idx_val); 3362 MEM_CGROUP_STAT_SWAPOUT);
3183 val += idx_val;
3184 }
3185 3363
3186 return val << PAGE_SHIFT; 3364 return val << PAGE_SHIFT;
3187} 3365}
@@ -3389,9 +3567,9 @@ struct {
3389}; 3567};
3390 3568
3391 3569
3392static int mem_cgroup_get_local_stat(struct mem_cgroup *mem, void *data) 3570static void
3571mem_cgroup_get_local_stat(struct mem_cgroup *mem, struct mcs_total_stat *s)
3393{ 3572{
3394 struct mcs_total_stat *s = data;
3395 s64 val; 3573 s64 val;
3396 3574
3397 /* per cpu stat */ 3575 /* per cpu stat */
@@ -3421,13 +3599,15 @@ static int mem_cgroup_get_local_stat(struct mem_cgroup *mem, void *data)
3421 s->stat[MCS_ACTIVE_FILE] += val * PAGE_SIZE; 3599 s->stat[MCS_ACTIVE_FILE] += val * PAGE_SIZE;
3422 val = mem_cgroup_get_local_zonestat(mem, LRU_UNEVICTABLE); 3600 val = mem_cgroup_get_local_zonestat(mem, LRU_UNEVICTABLE);
3423 s->stat[MCS_UNEVICTABLE] += val * PAGE_SIZE; 3601 s->stat[MCS_UNEVICTABLE] += val * PAGE_SIZE;
3424 return 0;
3425} 3602}
3426 3603
3427static void 3604static void
3428mem_cgroup_get_total_stat(struct mem_cgroup *mem, struct mcs_total_stat *s) 3605mem_cgroup_get_total_stat(struct mem_cgroup *mem, struct mcs_total_stat *s)
3429{ 3606{
3430 mem_cgroup_walk_tree(mem, s, mem_cgroup_get_local_stat); 3607 struct mem_cgroup *iter;
3608
3609 for_each_mem_cgroup_tree(iter, mem)
3610 mem_cgroup_get_local_stat(iter, s);
3431} 3611}
3432 3612
3433static int mem_control_stat_show(struct cgroup *cont, struct cftype *cft, 3613static int mem_control_stat_show(struct cgroup *cont, struct cftype *cft,
@@ -3604,7 +3784,7 @@ static int compare_thresholds(const void *a, const void *b)
3604 return _a->threshold - _b->threshold; 3784 return _a->threshold - _b->threshold;
3605} 3785}
3606 3786
3607static int mem_cgroup_oom_notify_cb(struct mem_cgroup *mem, void *data) 3787static int mem_cgroup_oom_notify_cb(struct mem_cgroup *mem)
3608{ 3788{
3609 struct mem_cgroup_eventfd_list *ev; 3789 struct mem_cgroup_eventfd_list *ev;
3610 3790
@@ -3615,7 +3795,10 @@ static int mem_cgroup_oom_notify_cb(struct mem_cgroup *mem, void *data)
3615 3795
3616static void mem_cgroup_oom_notify(struct mem_cgroup *mem) 3796static void mem_cgroup_oom_notify(struct mem_cgroup *mem)
3617{ 3797{
3618 mem_cgroup_walk_tree(mem, NULL, mem_cgroup_oom_notify_cb); 3798 struct mem_cgroup *iter;
3799
3800 for_each_mem_cgroup_tree(iter, mem)
3801 mem_cgroup_oom_notify_cb(iter);
3619} 3802}
3620 3803
3621static int mem_cgroup_usage_register_event(struct cgroup *cgrp, 3804static int mem_cgroup_usage_register_event(struct cgroup *cgrp,
@@ -4032,6 +4215,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
4032 vfree(mem); 4215 vfree(mem);
4033 mem = NULL; 4216 mem = NULL;
4034 } 4217 }
4218 spin_lock_init(&mem->pcp_counter_lock);
4035 return mem; 4219 return mem;
4036} 4220}
4037 4221
@@ -4158,7 +4342,7 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
4158 &per_cpu(memcg_stock, cpu); 4342 &per_cpu(memcg_stock, cpu);
4159 INIT_WORK(&stock->work, drain_local_stock); 4343 INIT_WORK(&stock->work, drain_local_stock);
4160 } 4344 }
4161 hotcpu_notifier(memcg_stock_cpu_callback, 0); 4345 hotcpu_notifier(memcg_cpu_hotplug_callback, 0);
4162 } else { 4346 } else {
4163 parent = mem_cgroup_from_cont(cont->parent); 4347 parent = mem_cgroup_from_cont(cont->parent);
4164 mem->use_hierarchy = parent->use_hierarchy; 4348 mem->use_hierarchy = parent->use_hierarchy;
@@ -4513,6 +4697,7 @@ static void mem_cgroup_clear_mc(void)
4513 mc.to = NULL; 4697 mc.to = NULL;
4514 mc.moving_task = NULL; 4698 mc.moving_task = NULL;
4515 spin_unlock(&mc.lock); 4699 spin_unlock(&mc.lock);
4700 mem_cgroup_end_move(from);
4516 memcg_oom_recover(from); 4701 memcg_oom_recover(from);
4517 memcg_oom_recover(to); 4702 memcg_oom_recover(to);
4518 wake_up_all(&mc.waitq); 4703 wake_up_all(&mc.waitq);
@@ -4543,6 +4728,7 @@ static int mem_cgroup_can_attach(struct cgroup_subsys *ss,
4543 VM_BUG_ON(mc.moved_charge); 4728 VM_BUG_ON(mc.moved_charge);
4544 VM_BUG_ON(mc.moved_swap); 4729 VM_BUG_ON(mc.moved_swap);
4545 VM_BUG_ON(mc.moving_task); 4730 VM_BUG_ON(mc.moving_task);
4731 mem_cgroup_start_move(from);
4546 spin_lock(&mc.lock); 4732 spin_lock(&mc.lock);
4547 mc.from = from; 4733 mc.from = from;
4548 mc.to = mem; 4734 mc.to = mem;
diff --git a/mm/swap.c b/mm/swap.c
index 3ce7bc373a52..3f4854205b16 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -378,6 +378,7 @@ void release_pages(struct page **pages, int nr, int cold)
378 378
379 pagevec_free(&pages_to_free); 379 pagevec_free(&pages_to_free);
380} 380}
381EXPORT_SYMBOL(release_pages);
381 382
382/* 383/*
383 * The pages which we're about to release may be in the deferred lru-addition 384 * The pages which we're about to release may be in the deferred lru-addition
diff --git a/net/802/garp.c b/net/802/garp.c
index 941f2a324d3a..c1df2dad8c6b 100644
--- a/net/802/garp.c
+++ b/net/802/garp.c
@@ -346,8 +346,8 @@ int garp_request_join(const struct net_device *dev,
346 const struct garp_application *appl, 346 const struct garp_application *appl,
347 const void *data, u8 len, u8 type) 347 const void *data, u8 len, u8 type)
348{ 348{
349 struct garp_port *port = dev->garp_port; 349 struct garp_port *port = rtnl_dereference(dev->garp_port);
350 struct garp_applicant *app = port->applicants[appl->type]; 350 struct garp_applicant *app = rtnl_dereference(port->applicants[appl->type]);
351 struct garp_attr *attr; 351 struct garp_attr *attr;
352 352
353 spin_lock_bh(&app->lock); 353 spin_lock_bh(&app->lock);
@@ -366,8 +366,8 @@ void garp_request_leave(const struct net_device *dev,
366 const struct garp_application *appl, 366 const struct garp_application *appl,
367 const void *data, u8 len, u8 type) 367 const void *data, u8 len, u8 type)
368{ 368{
369 struct garp_port *port = dev->garp_port; 369 struct garp_port *port = rtnl_dereference(dev->garp_port);
370 struct garp_applicant *app = port->applicants[appl->type]; 370 struct garp_applicant *app = rtnl_dereference(port->applicants[appl->type]);
371 struct garp_attr *attr; 371 struct garp_attr *attr;
372 372
373 spin_lock_bh(&app->lock); 373 spin_lock_bh(&app->lock);
@@ -546,11 +546,11 @@ static int garp_init_port(struct net_device *dev)
546 546
547static void garp_release_port(struct net_device *dev) 547static void garp_release_port(struct net_device *dev)
548{ 548{
549 struct garp_port *port = dev->garp_port; 549 struct garp_port *port = rtnl_dereference(dev->garp_port);
550 unsigned int i; 550 unsigned int i;
551 551
552 for (i = 0; i <= GARP_APPLICATION_MAX; i++) { 552 for (i = 0; i <= GARP_APPLICATION_MAX; i++) {
553 if (port->applicants[i]) 553 if (rtnl_dereference(port->applicants[i]))
554 return; 554 return;
555 } 555 }
556 rcu_assign_pointer(dev->garp_port, NULL); 556 rcu_assign_pointer(dev->garp_port, NULL);
@@ -565,7 +565,7 @@ int garp_init_applicant(struct net_device *dev, struct garp_application *appl)
565 565
566 ASSERT_RTNL(); 566 ASSERT_RTNL();
567 567
568 if (!dev->garp_port) { 568 if (!rtnl_dereference(dev->garp_port)) {
569 err = garp_init_port(dev); 569 err = garp_init_port(dev);
570 if (err < 0) 570 if (err < 0)
571 goto err1; 571 goto err1;
@@ -601,8 +601,8 @@ EXPORT_SYMBOL_GPL(garp_init_applicant);
601 601
602void garp_uninit_applicant(struct net_device *dev, struct garp_application *appl) 602void garp_uninit_applicant(struct net_device *dev, struct garp_application *appl)
603{ 603{
604 struct garp_port *port = dev->garp_port; 604 struct garp_port *port = rtnl_dereference(dev->garp_port);
605 struct garp_applicant *app = port->applicants[appl->type]; 605 struct garp_applicant *app = rtnl_dereference(port->applicants[appl->type]);
606 606
607 ASSERT_RTNL(); 607 ASSERT_RTNL();
608 608
diff --git a/net/802/stp.c b/net/802/stp.c
index 53c8f77f0ccd..978c30b1b36b 100644
--- a/net/802/stp.c
+++ b/net/802/stp.c
@@ -21,8 +21,8 @@
21#define GARP_ADDR_MAX 0x2F 21#define GARP_ADDR_MAX 0x2F
22#define GARP_ADDR_RANGE (GARP_ADDR_MAX - GARP_ADDR_MIN) 22#define GARP_ADDR_RANGE (GARP_ADDR_MAX - GARP_ADDR_MIN)
23 23
24static const struct stp_proto *garp_protos[GARP_ADDR_RANGE + 1] __read_mostly; 24static const struct stp_proto __rcu *garp_protos[GARP_ADDR_RANGE + 1] __read_mostly;
25static const struct stp_proto *stp_proto __read_mostly; 25static const struct stp_proto __rcu *stp_proto __read_mostly;
26 26
27static struct llc_sap *sap __read_mostly; 27static struct llc_sap *sap __read_mostly;
28static unsigned int sap_registered; 28static unsigned int sap_registered;
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 05b867e43757..52077ca22072 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -112,7 +112,7 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
112 112
113 ASSERT_RTNL(); 113 ASSERT_RTNL();
114 114
115 grp = real_dev->vlgrp; 115 grp = rtnl_dereference(real_dev->vlgrp);
116 BUG_ON(!grp); 116 BUG_ON(!grp);
117 117
118 /* Take it out of our own structures, but be sure to interlock with 118 /* Take it out of our own structures, but be sure to interlock with
@@ -177,7 +177,7 @@ int register_vlan_dev(struct net_device *dev)
177 struct vlan_group *grp, *ngrp = NULL; 177 struct vlan_group *grp, *ngrp = NULL;
178 int err; 178 int err;
179 179
180 grp = real_dev->vlgrp; 180 grp = rtnl_dereference(real_dev->vlgrp);
181 if (!grp) { 181 if (!grp) {
182 ngrp = grp = vlan_group_alloc(real_dev); 182 ngrp = grp = vlan_group_alloc(real_dev);
183 if (!grp) 183 if (!grp)
@@ -385,7 +385,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
385 dev->netdev_ops->ndo_vlan_rx_add_vid(dev, 0); 385 dev->netdev_ops->ndo_vlan_rx_add_vid(dev, 0);
386 } 386 }
387 387
388 grp = dev->vlgrp; 388 grp = rtnl_dereference(dev->vlgrp);
389 if (!grp) 389 if (!grp)
390 goto out; 390 goto out;
391 391
diff --git a/net/core/dev.c b/net/core/dev.c
index 78b5a89b0f40..35dfb8318483 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1685,10 +1685,10 @@ EXPORT_SYMBOL(netif_device_attach);
1685 1685
1686static bool can_checksum_protocol(unsigned long features, __be16 protocol) 1686static bool can_checksum_protocol(unsigned long features, __be16 protocol)
1687{ 1687{
1688 return ((features & NETIF_F_GEN_CSUM) || 1688 return ((features & NETIF_F_NO_CSUM) ||
1689 ((features & NETIF_F_IP_CSUM) && 1689 ((features & NETIF_F_V4_CSUM) &&
1690 protocol == htons(ETH_P_IP)) || 1690 protocol == htons(ETH_P_IP)) ||
1691 ((features & NETIF_F_IPV6_CSUM) && 1691 ((features & NETIF_F_V6_CSUM) &&
1692 protocol == htons(ETH_P_IPV6)) || 1692 protocol == htons(ETH_P_IPV6)) ||
1693 ((features & NETIF_F_FCOE_CRC) && 1693 ((features & NETIF_F_FCOE_CRC) &&
1694 protocol == htons(ETH_P_FCOE))); 1694 protocol == htons(ETH_P_FCOE)));
@@ -1696,22 +1696,18 @@ static bool can_checksum_protocol(unsigned long features, __be16 protocol)
1696 1696
1697static bool dev_can_checksum(struct net_device *dev, struct sk_buff *skb) 1697static bool dev_can_checksum(struct net_device *dev, struct sk_buff *skb)
1698{ 1698{
1699 __be16 protocol = skb->protocol;
1699 int features = dev->features; 1700 int features = dev->features;
1700 1701
1701 if (vlan_tx_tag_present(skb)) 1702 if (vlan_tx_tag_present(skb)) {
1702 features &= dev->vlan_features; 1703 features &= dev->vlan_features;
1703 1704 } else if (protocol == htons(ETH_P_8021Q)) {
1704 if (can_checksum_protocol(features, skb->protocol))
1705 return true;
1706
1707 if (skb->protocol == htons(ETH_P_8021Q)) {
1708 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; 1705 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
1709 if (can_checksum_protocol(dev->features & dev->vlan_features, 1706 protocol = veh->h_vlan_encapsulated_proto;
1710 veh->h_vlan_encapsulated_proto)) 1707 features &= dev->vlan_features;
1711 return true;
1712 } 1708 }
1713 1709
1714 return false; 1710 return can_checksum_protocol(features, protocol);
1715} 1711}
1716 1712
1717/** 1713/**
@@ -2213,7 +2209,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
2213} 2209}
2214 2210
2215static DEFINE_PER_CPU(int, xmit_recursion); 2211static DEFINE_PER_CPU(int, xmit_recursion);
2216#define RECURSION_LIMIT 3 2212#define RECURSION_LIMIT 10
2217 2213
2218/** 2214/**
2219 * dev_queue_xmit - transmit a buffer 2215 * dev_queue_xmit - transmit a buffer
@@ -2413,7 +2409,7 @@ EXPORT_SYMBOL(__skb_get_rxhash);
2413#ifdef CONFIG_RPS 2409#ifdef CONFIG_RPS
2414 2410
2415/* One global table that all flow-based protocols share. */ 2411/* One global table that all flow-based protocols share. */
2416struct rps_sock_flow_table *rps_sock_flow_table __read_mostly; 2412struct rps_sock_flow_table __rcu *rps_sock_flow_table __read_mostly;
2417EXPORT_SYMBOL(rps_sock_flow_table); 2413EXPORT_SYMBOL(rps_sock_flow_table);
2418 2414
2419/* 2415/*
@@ -2425,7 +2421,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
2425 struct rps_dev_flow **rflowp) 2421 struct rps_dev_flow **rflowp)
2426{ 2422{
2427 struct netdev_rx_queue *rxqueue; 2423 struct netdev_rx_queue *rxqueue;
2428 struct rps_map *map = NULL; 2424 struct rps_map *map;
2429 struct rps_dev_flow_table *flow_table; 2425 struct rps_dev_flow_table *flow_table;
2430 struct rps_sock_flow_table *sock_flow_table; 2426 struct rps_sock_flow_table *sock_flow_table;
2431 int cpu = -1; 2427 int cpu = -1;
@@ -2444,15 +2440,15 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
2444 } else 2440 } else
2445 rxqueue = dev->_rx; 2441 rxqueue = dev->_rx;
2446 2442
2447 if (rxqueue->rps_map) { 2443 map = rcu_dereference(rxqueue->rps_map);
2448 map = rcu_dereference(rxqueue->rps_map); 2444 if (map) {
2449 if (map && map->len == 1) { 2445 if (map->len == 1) {
2450 tcpu = map->cpus[0]; 2446 tcpu = map->cpus[0];
2451 if (cpu_online(tcpu)) 2447 if (cpu_online(tcpu))
2452 cpu = tcpu; 2448 cpu = tcpu;
2453 goto done; 2449 goto done;
2454 } 2450 }
2455 } else if (!rxqueue->rps_flow_table) { 2451 } else if (!rcu_dereference_raw(rxqueue->rps_flow_table)) {
2456 goto done; 2452 goto done;
2457 } 2453 }
2458 2454
@@ -5416,7 +5412,7 @@ void netdev_run_todo(void)
5416 /* paranoia */ 5412 /* paranoia */
5417 BUG_ON(netdev_refcnt_read(dev)); 5413 BUG_ON(netdev_refcnt_read(dev));
5418 WARN_ON(rcu_dereference_raw(dev->ip_ptr)); 5414 WARN_ON(rcu_dereference_raw(dev->ip_ptr));
5419 WARN_ON(dev->ip6_ptr); 5415 WARN_ON(rcu_dereference_raw(dev->ip6_ptr));
5420 WARN_ON(dev->dn_ptr); 5416 WARN_ON(dev->dn_ptr);
5421 5417
5422 if (dev->destructor) 5418 if (dev->destructor)
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 1bc3f253ba6c..82a4369ae150 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -351,12 +351,12 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
351 351
352 list_for_each_entry(r, &ops->rules_list, list) { 352 list_for_each_entry(r, &ops->rules_list, list) {
353 if (r->pref == rule->target) { 353 if (r->pref == rule->target) {
354 rule->ctarget = r; 354 RCU_INIT_POINTER(rule->ctarget, r);
355 break; 355 break;
356 } 356 }
357 } 357 }
358 358
359 if (rule->ctarget == NULL) 359 if (rcu_dereference_protected(rule->ctarget, 1) == NULL)
360 unresolved = 1; 360 unresolved = 1;
361 } else if (rule->action == FR_ACT_GOTO) 361 } else if (rule->action == FR_ACT_GOTO)
362 goto errout_free; 362 goto errout_free;
@@ -373,6 +373,11 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
373 373
374 fib_rule_get(rule); 374 fib_rule_get(rule);
375 375
376 if (last)
377 list_add_rcu(&rule->list, &last->list);
378 else
379 list_add_rcu(&rule->list, &ops->rules_list);
380
376 if (ops->unresolved_rules) { 381 if (ops->unresolved_rules) {
377 /* 382 /*
378 * There are unresolved goto rules in the list, check if 383 * There are unresolved goto rules in the list, check if
@@ -381,7 +386,7 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
381 list_for_each_entry(r, &ops->rules_list, list) { 386 list_for_each_entry(r, &ops->rules_list, list) {
382 if (r->action == FR_ACT_GOTO && 387 if (r->action == FR_ACT_GOTO &&
383 r->target == rule->pref) { 388 r->target == rule->pref) {
384 BUG_ON(r->ctarget != NULL); 389 BUG_ON(rtnl_dereference(r->ctarget) != NULL);
385 rcu_assign_pointer(r->ctarget, rule); 390 rcu_assign_pointer(r->ctarget, rule);
386 if (--ops->unresolved_rules == 0) 391 if (--ops->unresolved_rules == 0)
387 break; 392 break;
@@ -395,11 +400,6 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
395 if (unresolved) 400 if (unresolved)
396 ops->unresolved_rules++; 401 ops->unresolved_rules++;
397 402
398 if (last)
399 list_add_rcu(&rule->list, &last->list);
400 else
401 list_add_rcu(&rule->list, &ops->rules_list);
402
403 notify_rule_change(RTM_NEWRULE, rule, ops, nlh, NETLINK_CB(skb).pid); 403 notify_rule_change(RTM_NEWRULE, rule, ops, nlh, NETLINK_CB(skb).pid);
404 flush_route_cache(ops); 404 flush_route_cache(ops);
405 rules_ops_put(ops); 405 rules_ops_put(ops);
@@ -487,7 +487,7 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
487 */ 487 */
488 if (ops->nr_goto_rules > 0) { 488 if (ops->nr_goto_rules > 0) {
489 list_for_each_entry(tmp, &ops->rules_list, list) { 489 list_for_each_entry(tmp, &ops->rules_list, list) {
490 if (tmp->ctarget == rule) { 490 if (rtnl_dereference(tmp->ctarget) == rule) {
491 rcu_assign_pointer(tmp->ctarget, NULL); 491 rcu_assign_pointer(tmp->ctarget, NULL);
492 ops->unresolved_rules++; 492 ops->unresolved_rules++;
493 } 493 }
@@ -545,7 +545,8 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule,
545 frh->action = rule->action; 545 frh->action = rule->action;
546 frh->flags = rule->flags; 546 frh->flags = rule->flags;
547 547
548 if (rule->action == FR_ACT_GOTO && rule->ctarget == NULL) 548 if (rule->action == FR_ACT_GOTO &&
549 rcu_dereference_raw(rule->ctarget) == NULL)
549 frh->flags |= FIB_RULE_UNRESOLVED; 550 frh->flags |= FIB_RULE_UNRESOLVED;
550 551
551 if (rule->iifname[0]) { 552 if (rule->iifname[0]) {
diff --git a/net/core/filter.c b/net/core/filter.c
index 7adf50352918..7beaec36b541 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -89,8 +89,8 @@ int sk_filter(struct sock *sk, struct sk_buff *skb)
89 rcu_read_lock_bh(); 89 rcu_read_lock_bh();
90 filter = rcu_dereference_bh(sk->sk_filter); 90 filter = rcu_dereference_bh(sk->sk_filter);
91 if (filter) { 91 if (filter) {
92 unsigned int pkt_len = sk_run_filter(skb, filter->insns, 92 unsigned int pkt_len = sk_run_filter(skb, filter->insns, filter->len);
93 filter->len); 93
94 err = pkt_len ? pskb_trim(skb, pkt_len) : -EPERM; 94 err = pkt_len ? pskb_trim(skb, pkt_len) : -EPERM;
95 } 95 }
96 rcu_read_unlock_bh(); 96 rcu_read_unlock_bh();
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index b143173e3eb2..a5ff5a89f376 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -598,7 +598,8 @@ static ssize_t store_rps_map(struct netdev_rx_queue *queue,
598 } 598 }
599 599
600 spin_lock(&rps_map_lock); 600 spin_lock(&rps_map_lock);
601 old_map = queue->rps_map; 601 old_map = rcu_dereference_protected(queue->rps_map,
602 lockdep_is_held(&rps_map_lock));
602 rcu_assign_pointer(queue->rps_map, map); 603 rcu_assign_pointer(queue->rps_map, map);
603 spin_unlock(&rps_map_lock); 604 spin_unlock(&rps_map_lock);
604 605
@@ -677,7 +678,8 @@ static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
677 table = NULL; 678 table = NULL;
678 679
679 spin_lock(&rps_dev_flow_lock); 680 spin_lock(&rps_dev_flow_lock);
680 old_table = queue->rps_flow_table; 681 old_table = rcu_dereference_protected(queue->rps_flow_table,
682 lockdep_is_held(&rps_dev_flow_lock));
681 rcu_assign_pointer(queue->rps_flow_table, table); 683 rcu_assign_pointer(queue->rps_flow_table, table);
682 spin_unlock(&rps_dev_flow_lock); 684 spin_unlock(&rps_dev_flow_lock);
683 685
@@ -705,13 +707,17 @@ static void rx_queue_release(struct kobject *kobj)
705{ 707{
706 struct netdev_rx_queue *queue = to_rx_queue(kobj); 708 struct netdev_rx_queue *queue = to_rx_queue(kobj);
707 struct netdev_rx_queue *first = queue->first; 709 struct netdev_rx_queue *first = queue->first;
710 struct rps_map *map;
711 struct rps_dev_flow_table *flow_table;
708 712
709 if (queue->rps_map)
710 call_rcu(&queue->rps_map->rcu, rps_map_release);
711 713
712 if (queue->rps_flow_table) 714 map = rcu_dereference_raw(queue->rps_map);
713 call_rcu(&queue->rps_flow_table->rcu, 715 if (map)
714 rps_dev_flow_table_release); 716 call_rcu(&map->rcu, rps_map_release);
717
718 flow_table = rcu_dereference_raw(queue->rps_flow_table);
719 if (flow_table)
720 call_rcu(&flow_table->rcu, rps_dev_flow_table_release);
715 721
716 if (atomic_dec_and_test(&first->count)) 722 if (atomic_dec_and_test(&first->count))
717 kfree(first); 723 kfree(first);
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index c988e685433a..3f860261c5ee 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -42,7 +42,9 @@ static int net_assign_generic(struct net *net, int id, void *data)
42 BUG_ON(!mutex_is_locked(&net_mutex)); 42 BUG_ON(!mutex_is_locked(&net_mutex));
43 BUG_ON(id == 0); 43 BUG_ON(id == 0);
44 44
45 ng = old_ng = net->gen; 45 old_ng = rcu_dereference_protected(net->gen,
46 lockdep_is_held(&net_mutex));
47 ng = old_ng;
46 if (old_ng->len >= id) 48 if (old_ng->len >= id)
47 goto assign; 49 goto assign;
48 50
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 2c0df0f95b3d..679b797d06b1 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -771,10 +771,10 @@ done:
771static unsigned long num_arg(const char __user * user_buffer, 771static unsigned long num_arg(const char __user * user_buffer,
772 unsigned long maxlen, unsigned long *num) 772 unsigned long maxlen, unsigned long *num)
773{ 773{
774 int i = 0; 774 int i;
775 *num = 0; 775 *num = 0;
776 776
777 for (; i < maxlen; i++) { 777 for (i = 0; i < maxlen; i++) {
778 char c; 778 char c;
779 if (get_user(c, &user_buffer[i])) 779 if (get_user(c, &user_buffer[i]))
780 return -EFAULT; 780 return -EFAULT;
@@ -789,9 +789,9 @@ static unsigned long num_arg(const char __user * user_buffer,
789 789
790static int strn_len(const char __user * user_buffer, unsigned int maxlen) 790static int strn_len(const char __user * user_buffer, unsigned int maxlen)
791{ 791{
792 int i = 0; 792 int i;
793 793
794 for (; i < maxlen; i++) { 794 for (i = 0; i < maxlen; i++) {
795 char c; 795 char c;
796 if (get_user(c, &user_buffer[i])) 796 if (get_user(c, &user_buffer[i]))
797 return -EFAULT; 797 return -EFAULT;
@@ -846,7 +846,7 @@ static ssize_t pktgen_if_write(struct file *file,
846{ 846{
847 struct seq_file *seq = file->private_data; 847 struct seq_file *seq = file->private_data;
848 struct pktgen_dev *pkt_dev = seq->private; 848 struct pktgen_dev *pkt_dev = seq->private;
849 int i = 0, max, len; 849 int i, max, len;
850 char name[16], valstr[32]; 850 char name[16], valstr[32];
851 unsigned long value = 0; 851 unsigned long value = 0;
852 char *pg_result = NULL; 852 char *pg_result = NULL;
@@ -860,13 +860,13 @@ static ssize_t pktgen_if_write(struct file *file,
860 return -EINVAL; 860 return -EINVAL;
861 } 861 }
862 862
863 max = count - i; 863 max = count;
864 tmp = count_trail_chars(&user_buffer[i], max); 864 tmp = count_trail_chars(user_buffer, max);
865 if (tmp < 0) { 865 if (tmp < 0) {
866 pr_warning("illegal format\n"); 866 pr_warning("illegal format\n");
867 return tmp; 867 return tmp;
868 } 868 }
869 i += tmp; 869 i = tmp;
870 870
871 /* Read variable name */ 871 /* Read variable name */
872 872
@@ -1764,7 +1764,7 @@ static ssize_t pktgen_thread_write(struct file *file,
1764{ 1764{
1765 struct seq_file *seq = file->private_data; 1765 struct seq_file *seq = file->private_data;
1766 struct pktgen_thread *t = seq->private; 1766 struct pktgen_thread *t = seq->private;
1767 int i = 0, max, len, ret; 1767 int i, max, len, ret;
1768 char name[40]; 1768 char name[40];
1769 char *pg_result; 1769 char *pg_result;
1770 1770
@@ -1773,12 +1773,12 @@ static ssize_t pktgen_thread_write(struct file *file,
1773 return -EINVAL; 1773 return -EINVAL;
1774 } 1774 }
1775 1775
1776 max = count - i; 1776 max = count;
1777 len = count_trail_chars(&user_buffer[i], max); 1777 len = count_trail_chars(user_buffer, max);
1778 if (len < 0) 1778 if (len < 0)
1779 return len; 1779 return len;
1780 1780
1781 i += len; 1781 i = len;
1782 1782
1783 /* Read variable name */ 1783 /* Read variable name */
1784 1784
@@ -1975,7 +1975,7 @@ static struct net_device *pktgen_dev_get_by_name(struct pktgen_dev *pkt_dev,
1975 const char *ifname) 1975 const char *ifname)
1976{ 1976{
1977 char b[IFNAMSIZ+5]; 1977 char b[IFNAMSIZ+5];
1978 int i = 0; 1978 int i;
1979 1979
1980 for (i = 0; ifname[i] != '@'; i++) { 1980 for (i = 0; ifname[i] != '@'; i++) {
1981 if (i == IFNAMSIZ) 1981 if (i == IFNAMSIZ)
@@ -2519,8 +2519,8 @@ static void free_SAs(struct pktgen_dev *pkt_dev)
2519{ 2519{
2520 if (pkt_dev->cflows) { 2520 if (pkt_dev->cflows) {
2521 /* let go of the SAs if we have them */ 2521 /* let go of the SAs if we have them */
2522 int i = 0; 2522 int i;
2523 for (; i < pkt_dev->cflows; i++) { 2523 for (i = 0; i < pkt_dev->cflows; i++) {
2524 struct xfrm_state *x = pkt_dev->flows[i].x; 2524 struct xfrm_state *x = pkt_dev->flows[i].x;
2525 if (x) { 2525 if (x) {
2526 xfrm_state_put(x); 2526 xfrm_state_put(x);
diff --git a/net/core/sock.c b/net/core/sock.c
index 11db43632df8..3eed5424e659 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1225,7 +1225,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
1225 sock_reset_flag(newsk, SOCK_DONE); 1225 sock_reset_flag(newsk, SOCK_DONE);
1226 skb_queue_head_init(&newsk->sk_error_queue); 1226 skb_queue_head_init(&newsk->sk_error_queue);
1227 1227
1228 filter = newsk->sk_filter; 1228 filter = rcu_dereference_protected(newsk->sk_filter, 1);
1229 if (filter != NULL) 1229 if (filter != NULL)
1230 sk_filter_charge(newsk, filter); 1230 sk_filter_charge(newsk, filter);
1231 1231
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 01eee5d984be..385b6095fdc4 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -34,7 +34,8 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
34 34
35 mutex_lock(&sock_flow_mutex); 35 mutex_lock(&sock_flow_mutex);
36 36
37 orig_sock_table = rps_sock_flow_table; 37 orig_sock_table = rcu_dereference_protected(rps_sock_flow_table,
38 lockdep_is_held(&sock_flow_mutex));
38 size = orig_size = orig_sock_table ? orig_sock_table->mask + 1 : 0; 39 size = orig_size = orig_sock_table ? orig_sock_table->mask + 1 : 0;
39 40
40 ret = proc_dointvec(&tmp, write, buffer, lenp, ppos); 41 ret = proc_dointvec(&tmp, write, buffer, lenp, ppos);
diff --git a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c
index 43e1c594ce8f..b232375a0b75 100644
--- a/net/ipv4/fib_hash.c
+++ b/net/ipv4/fib_hash.c
@@ -120,11 +120,12 @@ static inline void fn_rebuild_zone(struct fn_zone *fz,
120 struct fib_node *f; 120 struct fib_node *f;
121 121
122 hlist_for_each_entry_safe(f, node, n, &old_ht[i], fn_hash) { 122 hlist_for_each_entry_safe(f, node, n, &old_ht[i], fn_hash) {
123 struct hlist_head __rcu *new_head; 123 struct hlist_head *new_head;
124 124
125 hlist_del_rcu(&f->fn_hash); 125 hlist_del_rcu(&f->fn_hash);
126 126
127 new_head = &fz->fz_hash[fn_hash(f->fn_key, fz)]; 127 new_head = rcu_dereference_protected(fz->fz_hash, 1) +
128 fn_hash(f->fn_key, fz);
128 hlist_add_head_rcu(&f->fn_hash, new_head); 129 hlist_add_head_rcu(&f->fn_hash, new_head);
129 } 130 }
130 } 131 }
@@ -179,8 +180,8 @@ static void fn_rehash_zone(struct fn_zone *fz)
179 memcpy(&nfz, fz, sizeof(nfz)); 180 memcpy(&nfz, fz, sizeof(nfz));
180 181
181 write_seqlock_bh(&fz->fz_lock); 182 write_seqlock_bh(&fz->fz_lock);
182 old_ht = fz->fz_hash; 183 old_ht = rcu_dereference_protected(fz->fz_hash, 1);
183 nfz.fz_hash = ht; 184 RCU_INIT_POINTER(nfz.fz_hash, ht);
184 nfz.fz_hashmask = new_hashmask; 185 nfz.fz_hashmask = new_hashmask;
185 nfz.fz_divisor = new_divisor; 186 nfz.fz_divisor = new_divisor;
186 fn_rebuild_zone(&nfz, old_ht, old_divisor); 187 fn_rebuild_zone(&nfz, old_ht, old_divisor);
@@ -236,7 +237,7 @@ fn_new_zone(struct fn_hash *table, int z)
236 seqlock_init(&fz->fz_lock); 237 seqlock_init(&fz->fz_lock);
237 fz->fz_divisor = z ? EMBEDDED_HASH_SIZE : 1; 238 fz->fz_divisor = z ? EMBEDDED_HASH_SIZE : 1;
238 fz->fz_hashmask = fz->fz_divisor - 1; 239 fz->fz_hashmask = fz->fz_divisor - 1;
239 fz->fz_hash = fz->fz_embedded_hash; 240 RCU_INIT_POINTER(fz->fz_hash, fz->fz_embedded_hash);
240 fz->fz_order = z; 241 fz->fz_order = z;
241 fz->fz_revorder = 32 - z; 242 fz->fz_revorder = 32 - z;
242 fz->fz_mask = inet_make_mask(z); 243 fz->fz_mask = inet_make_mask(z);
@@ -272,7 +273,7 @@ int fib_table_lookup(struct fib_table *tb,
272 for (fz = rcu_dereference(t->fn_zone_list); 273 for (fz = rcu_dereference(t->fn_zone_list);
273 fz != NULL; 274 fz != NULL;
274 fz = rcu_dereference(fz->fz_next)) { 275 fz = rcu_dereference(fz->fz_next)) {
275 struct hlist_head __rcu *head; 276 struct hlist_head *head;
276 struct hlist_node *node; 277 struct hlist_node *node;
277 struct fib_node *f; 278 struct fib_node *f;
278 __be32 k; 279 __be32 k;
@@ -282,7 +283,7 @@ int fib_table_lookup(struct fib_table *tb,
282 seq = read_seqbegin(&fz->fz_lock); 283 seq = read_seqbegin(&fz->fz_lock);
283 k = fz_key(flp->fl4_dst, fz); 284 k = fz_key(flp->fl4_dst, fz);
284 285
285 head = &fz->fz_hash[fn_hash(k, fz)]; 286 head = rcu_dereference(fz->fz_hash) + fn_hash(k, fz);
286 hlist_for_each_entry_rcu(f, node, head, fn_hash) { 287 hlist_for_each_entry_rcu(f, node, head, fn_hash) {
287 if (f->fn_key != k) 288 if (f->fn_key != k)
288 continue; 289 continue;
@@ -311,6 +312,7 @@ void fib_table_select_default(struct fib_table *tb,
311 struct fib_info *last_resort; 312 struct fib_info *last_resort;
312 struct fn_hash *t = (struct fn_hash *)tb->tb_data; 313 struct fn_hash *t = (struct fn_hash *)tb->tb_data;
313 struct fn_zone *fz = t->fn_zones[0]; 314 struct fn_zone *fz = t->fn_zones[0];
315 struct hlist_head *head;
314 316
315 if (fz == NULL) 317 if (fz == NULL)
316 return; 318 return;
@@ -320,7 +322,8 @@ void fib_table_select_default(struct fib_table *tb,
320 order = -1; 322 order = -1;
321 323
322 rcu_read_lock(); 324 rcu_read_lock();
323 hlist_for_each_entry_rcu(f, node, &fz->fz_hash[0], fn_hash) { 325 head = rcu_dereference(fz->fz_hash);
326 hlist_for_each_entry_rcu(f, node, head, fn_hash) {
324 struct fib_alias *fa; 327 struct fib_alias *fa;
325 328
326 list_for_each_entry_rcu(fa, &f->fn_alias, fa_list) { 329 list_for_each_entry_rcu(fa, &f->fn_alias, fa_list) {
@@ -374,7 +377,7 @@ out:
374/* Insert node F to FZ. */ 377/* Insert node F to FZ. */
375static inline void fib_insert_node(struct fn_zone *fz, struct fib_node *f) 378static inline void fib_insert_node(struct fn_zone *fz, struct fib_node *f)
376{ 379{
377 struct hlist_head *head = &fz->fz_hash[fn_hash(f->fn_key, fz)]; 380 struct hlist_head *head = rtnl_dereference(fz->fz_hash) + fn_hash(f->fn_key, fz);
378 381
379 hlist_add_head_rcu(&f->fn_hash, head); 382 hlist_add_head_rcu(&f->fn_hash, head);
380} 383}
@@ -382,7 +385,7 @@ static inline void fib_insert_node(struct fn_zone *fz, struct fib_node *f)
382/* Return the node in FZ matching KEY. */ 385/* Return the node in FZ matching KEY. */
383static struct fib_node *fib_find_node(struct fn_zone *fz, __be32 key) 386static struct fib_node *fib_find_node(struct fn_zone *fz, __be32 key)
384{ 387{
385 struct hlist_head *head = &fz->fz_hash[fn_hash(key, fz)]; 388 struct hlist_head *head = rtnl_dereference(fz->fz_hash) + fn_hash(key, fz);
386 struct hlist_node *node; 389 struct hlist_node *node;
387 struct fib_node *f; 390 struct fib_node *f;
388 391
@@ -662,7 +665,7 @@ int fib_table_delete(struct fib_table *tb, struct fib_config *cfg)
662 665
663static int fn_flush_list(struct fn_zone *fz, int idx) 666static int fn_flush_list(struct fn_zone *fz, int idx)
664{ 667{
665 struct hlist_head *head = &fz->fz_hash[idx]; 668 struct hlist_head *head = rtnl_dereference(fz->fz_hash) + idx;
666 struct hlist_node *node, *n; 669 struct hlist_node *node, *n;
667 struct fib_node *f; 670 struct fib_node *f;
668 int found = 0; 671 int found = 0;
@@ -761,14 +764,15 @@ fn_hash_dump_zone(struct sk_buff *skb, struct netlink_callback *cb,
761 struct fn_zone *fz) 764 struct fn_zone *fz)
762{ 765{
763 int h, s_h; 766 int h, s_h;
767 struct hlist_head *head = rcu_dereference(fz->fz_hash);
764 768
765 if (fz->fz_hash == NULL) 769 if (head == NULL)
766 return skb->len; 770 return skb->len;
767 s_h = cb->args[3]; 771 s_h = cb->args[3];
768 for (h = s_h; h < fz->fz_divisor; h++) { 772 for (h = s_h; h < fz->fz_divisor; h++) {
769 if (hlist_empty(&fz->fz_hash[h])) 773 if (hlist_empty(head + h))
770 continue; 774 continue;
771 if (fn_hash_dump_bucket(skb, cb, tb, fz, &fz->fz_hash[h]) < 0) { 775 if (fn_hash_dump_bucket(skb, cb, tb, fz, head + h) < 0) {
772 cb->args[3] = h; 776 cb->args[3] = h;
773 return -1; 777 return -1;
774 } 778 }
@@ -872,7 +876,7 @@ static struct fib_alias *fib_get_first(struct seq_file *seq)
872 if (!iter->zone->fz_nent) 876 if (!iter->zone->fz_nent)
873 continue; 877 continue;
874 878
875 iter->hash_head = iter->zone->fz_hash; 879 iter->hash_head = rcu_dereference(iter->zone->fz_hash);
876 maxslot = iter->zone->fz_divisor; 880 maxslot = iter->zone->fz_divisor;
877 881
878 for (iter->bucket = 0; iter->bucket < maxslot; 882 for (iter->bucket = 0; iter->bucket < maxslot;
@@ -957,7 +961,7 @@ static struct fib_alias *fib_get_next(struct seq_file *seq)
957 goto out; 961 goto out;
958 962
959 iter->bucket = 0; 963 iter->bucket = 0;
960 iter->hash_head = iter->zone->fz_hash; 964 iter->hash_head = rcu_dereference(iter->zone->fz_hash);
961 965
962 hlist_for_each_entry(fn, node, iter->hash_head, fn_hash) { 966 hlist_for_each_entry(fn, node, iter->hash_head, fn_hash) {
963 list_for_each_entry(fa, &fn->fn_alias, fa_list) { 967 list_for_each_entry(fa, &fn->fn_alias, fa_list) {
diff --git a/net/ipv4/gre.c b/net/ipv4/gre.c
index caea6885fdbd..c6933f2ea310 100644
--- a/net/ipv4/gre.c
+++ b/net/ipv4/gre.c
@@ -22,7 +22,7 @@
22#include <net/gre.h> 22#include <net/gre.h>
23 23
24 24
25static const struct gre_protocol *gre_proto[GREPROTO_MAX] __read_mostly; 25static const struct gre_protocol __rcu *gre_proto[GREPROTO_MAX] __read_mostly;
26static DEFINE_SPINLOCK(gre_proto_lock); 26static DEFINE_SPINLOCK(gre_proto_lock);
27 27
28int gre_add_protocol(const struct gre_protocol *proto, u8 version) 28int gre_add_protocol(const struct gre_protocol *proto, u8 version)
@@ -51,7 +51,8 @@ int gre_del_protocol(const struct gre_protocol *proto, u8 version)
51 goto err_out; 51 goto err_out;
52 52
53 spin_lock(&gre_proto_lock); 53 spin_lock(&gre_proto_lock);
54 if (gre_proto[version] != proto) 54 if (rcu_dereference_protected(gre_proto[version],
55 lockdep_is_held(&gre_proto_lock)) != proto)
55 goto err_out_unlock; 56 goto err_out_unlock;
56 rcu_assign_pointer(gre_proto[version], NULL); 57 rcu_assign_pointer(gre_proto[version], NULL);
57 spin_unlock(&gre_proto_lock); 58 spin_unlock(&gre_proto_lock);
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index 9ffa24b9a804..9e94d7cf4f8a 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -72,18 +72,19 @@ static struct kmem_cache *peer_cachep __read_mostly;
72#define node_height(x) x->avl_height 72#define node_height(x) x->avl_height
73 73
74#define peer_avl_empty ((struct inet_peer *)&peer_fake_node) 74#define peer_avl_empty ((struct inet_peer *)&peer_fake_node)
75#define peer_avl_empty_rcu ((struct inet_peer __rcu __force *)&peer_fake_node)
75static const struct inet_peer peer_fake_node = { 76static const struct inet_peer peer_fake_node = {
76 .avl_left = peer_avl_empty, 77 .avl_left = peer_avl_empty_rcu,
77 .avl_right = peer_avl_empty, 78 .avl_right = peer_avl_empty_rcu,
78 .avl_height = 0 79 .avl_height = 0
79}; 80};
80 81
81static struct { 82static struct {
82 struct inet_peer *root; 83 struct inet_peer __rcu *root;
83 spinlock_t lock; 84 spinlock_t lock;
84 int total; 85 int total;
85} peers = { 86} peers = {
86 .root = peer_avl_empty, 87 .root = peer_avl_empty_rcu,
87 .lock = __SPIN_LOCK_UNLOCKED(peers.lock), 88 .lock = __SPIN_LOCK_UNLOCKED(peers.lock),
88 .total = 0, 89 .total = 0,
89}; 90};
@@ -156,11 +157,14 @@ static void unlink_from_unused(struct inet_peer *p)
156 */ 157 */
157#define lookup(_daddr, _stack) \ 158#define lookup(_daddr, _stack) \
158({ \ 159({ \
159 struct inet_peer *u, **v; \ 160 struct inet_peer *u; \
161 struct inet_peer __rcu **v; \
160 \ 162 \
161 stackptr = _stack; \ 163 stackptr = _stack; \
162 *stackptr++ = &peers.root; \ 164 *stackptr++ = &peers.root; \
163 for (u = peers.root; u != peer_avl_empty; ) { \ 165 for (u = rcu_dereference_protected(peers.root, \
166 lockdep_is_held(&peers.lock)); \
167 u != peer_avl_empty; ) { \
164 if (_daddr == u->v4daddr) \ 168 if (_daddr == u->v4daddr) \
165 break; \ 169 break; \
166 if ((__force __u32)_daddr < (__force __u32)u->v4daddr) \ 170 if ((__force __u32)_daddr < (__force __u32)u->v4daddr) \
@@ -168,7 +172,8 @@ static void unlink_from_unused(struct inet_peer *p)
168 else \ 172 else \
169 v = &u->avl_right; \ 173 v = &u->avl_right; \
170 *stackptr++ = v; \ 174 *stackptr++ = v; \
171 u = *v; \ 175 u = rcu_dereference_protected(*v, \
176 lockdep_is_held(&peers.lock)); \
172 } \ 177 } \
173 u; \ 178 u; \
174}) 179})
@@ -209,13 +214,17 @@ static struct inet_peer *lookup_rcu_bh(__be32 daddr)
209/* Called with local BH disabled and the pool lock held. */ 214/* Called with local BH disabled and the pool lock held. */
210#define lookup_rightempty(start) \ 215#define lookup_rightempty(start) \
211({ \ 216({ \
212 struct inet_peer *u, **v; \ 217 struct inet_peer *u; \
218 struct inet_peer __rcu **v; \
213 *stackptr++ = &start->avl_left; \ 219 *stackptr++ = &start->avl_left; \
214 v = &start->avl_left; \ 220 v = &start->avl_left; \
215 for (u = *v; u->avl_right != peer_avl_empty; ) { \ 221 for (u = rcu_dereference_protected(*v, \
222 lockdep_is_held(&peers.lock)); \
223 u->avl_right != peer_avl_empty_rcu; ) { \
216 v = &u->avl_right; \ 224 v = &u->avl_right; \
217 *stackptr++ = v; \ 225 *stackptr++ = v; \
218 u = *v; \ 226 u = rcu_dereference_protected(*v, \
227 lockdep_is_held(&peers.lock)); \
219 } \ 228 } \
220 u; \ 229 u; \
221}) 230})
@@ -224,74 +233,86 @@ static struct inet_peer *lookup_rcu_bh(__be32 daddr)
224 * Variable names are the proof of operation correctness. 233 * Variable names are the proof of operation correctness.
225 * Look into mm/map_avl.c for more detail description of the ideas. 234 * Look into mm/map_avl.c for more detail description of the ideas.
226 */ 235 */
227static void peer_avl_rebalance(struct inet_peer **stack[], 236static void peer_avl_rebalance(struct inet_peer __rcu **stack[],
228 struct inet_peer ***stackend) 237 struct inet_peer __rcu ***stackend)
229{ 238{
230 struct inet_peer **nodep, *node, *l, *r; 239 struct inet_peer __rcu **nodep;
240 struct inet_peer *node, *l, *r;
231 int lh, rh; 241 int lh, rh;
232 242
233 while (stackend > stack) { 243 while (stackend > stack) {
234 nodep = *--stackend; 244 nodep = *--stackend;
235 node = *nodep; 245 node = rcu_dereference_protected(*nodep,
236 l = node->avl_left; 246 lockdep_is_held(&peers.lock));
237 r = node->avl_right; 247 l = rcu_dereference_protected(node->avl_left,
248 lockdep_is_held(&peers.lock));
249 r = rcu_dereference_protected(node->avl_right,
250 lockdep_is_held(&peers.lock));
238 lh = node_height(l); 251 lh = node_height(l);
239 rh = node_height(r); 252 rh = node_height(r);
240 if (lh > rh + 1) { /* l: RH+2 */ 253 if (lh > rh + 1) { /* l: RH+2 */
241 struct inet_peer *ll, *lr, *lrl, *lrr; 254 struct inet_peer *ll, *lr, *lrl, *lrr;
242 int lrh; 255 int lrh;
243 ll = l->avl_left; 256 ll = rcu_dereference_protected(l->avl_left,
244 lr = l->avl_right; 257 lockdep_is_held(&peers.lock));
258 lr = rcu_dereference_protected(l->avl_right,
259 lockdep_is_held(&peers.lock));
245 lrh = node_height(lr); 260 lrh = node_height(lr);
246 if (lrh <= node_height(ll)) { /* ll: RH+1 */ 261 if (lrh <= node_height(ll)) { /* ll: RH+1 */
247 node->avl_left = lr; /* lr: RH or RH+1 */ 262 RCU_INIT_POINTER(node->avl_left, lr); /* lr: RH or RH+1 */
248 node->avl_right = r; /* r: RH */ 263 RCU_INIT_POINTER(node->avl_right, r); /* r: RH */
249 node->avl_height = lrh + 1; /* RH+1 or RH+2 */ 264 node->avl_height = lrh + 1; /* RH+1 or RH+2 */
250 l->avl_left = ll; /* ll: RH+1 */ 265 RCU_INIT_POINTER(l->avl_left, ll); /* ll: RH+1 */
251 l->avl_right = node; /* node: RH+1 or RH+2 */ 266 RCU_INIT_POINTER(l->avl_right, node); /* node: RH+1 or RH+2 */
252 l->avl_height = node->avl_height + 1; 267 l->avl_height = node->avl_height + 1;
253 *nodep = l; 268 RCU_INIT_POINTER(*nodep, l);
254 } else { /* ll: RH, lr: RH+1 */ 269 } else { /* ll: RH, lr: RH+1 */
255 lrl = lr->avl_left; /* lrl: RH or RH-1 */ 270 lrl = rcu_dereference_protected(lr->avl_left,
256 lrr = lr->avl_right; /* lrr: RH or RH-1 */ 271 lockdep_is_held(&peers.lock)); /* lrl: RH or RH-1 */
257 node->avl_left = lrr; /* lrr: RH or RH-1 */ 272 lrr = rcu_dereference_protected(lr->avl_right,
258 node->avl_right = r; /* r: RH */ 273 lockdep_is_held(&peers.lock)); /* lrr: RH or RH-1 */
274 RCU_INIT_POINTER(node->avl_left, lrr); /* lrr: RH or RH-1 */
275 RCU_INIT_POINTER(node->avl_right, r); /* r: RH */
259 node->avl_height = rh + 1; /* node: RH+1 */ 276 node->avl_height = rh + 1; /* node: RH+1 */
260 l->avl_left = ll; /* ll: RH */ 277 RCU_INIT_POINTER(l->avl_left, ll); /* ll: RH */
261 l->avl_right = lrl; /* lrl: RH or RH-1 */ 278 RCU_INIT_POINTER(l->avl_right, lrl); /* lrl: RH or RH-1 */
262 l->avl_height = rh + 1; /* l: RH+1 */ 279 l->avl_height = rh + 1; /* l: RH+1 */
263 lr->avl_left = l; /* l: RH+1 */ 280 RCU_INIT_POINTER(lr->avl_left, l); /* l: RH+1 */
264 lr->avl_right = node; /* node: RH+1 */ 281 RCU_INIT_POINTER(lr->avl_right, node); /* node: RH+1 */
265 lr->avl_height = rh + 2; 282 lr->avl_height = rh + 2;
266 *nodep = lr; 283 RCU_INIT_POINTER(*nodep, lr);
267 } 284 }
268 } else if (rh > lh + 1) { /* r: LH+2 */ 285 } else if (rh > lh + 1) { /* r: LH+2 */
269 struct inet_peer *rr, *rl, *rlr, *rll; 286 struct inet_peer *rr, *rl, *rlr, *rll;
270 int rlh; 287 int rlh;
271 rr = r->avl_right; 288 rr = rcu_dereference_protected(r->avl_right,
272 rl = r->avl_left; 289 lockdep_is_held(&peers.lock));
290 rl = rcu_dereference_protected(r->avl_left,
291 lockdep_is_held(&peers.lock));
273 rlh = node_height(rl); 292 rlh = node_height(rl);
274 if (rlh <= node_height(rr)) { /* rr: LH+1 */ 293 if (rlh <= node_height(rr)) { /* rr: LH+1 */
275 node->avl_right = rl; /* rl: LH or LH+1 */ 294 RCU_INIT_POINTER(node->avl_right, rl); /* rl: LH or LH+1 */
276 node->avl_left = l; /* l: LH */ 295 RCU_INIT_POINTER(node->avl_left, l); /* l: LH */
277 node->avl_height = rlh + 1; /* LH+1 or LH+2 */ 296 node->avl_height = rlh + 1; /* LH+1 or LH+2 */
278 r->avl_right = rr; /* rr: LH+1 */ 297 RCU_INIT_POINTER(r->avl_right, rr); /* rr: LH+1 */
279 r->avl_left = node; /* node: LH+1 or LH+2 */ 298 RCU_INIT_POINTER(r->avl_left, node); /* node: LH+1 or LH+2 */
280 r->avl_height = node->avl_height + 1; 299 r->avl_height = node->avl_height + 1;
281 *nodep = r; 300 RCU_INIT_POINTER(*nodep, r);
282 } else { /* rr: RH, rl: RH+1 */ 301 } else { /* rr: RH, rl: RH+1 */
283 rlr = rl->avl_right; /* rlr: LH or LH-1 */ 302 rlr = rcu_dereference_protected(rl->avl_right,
284 rll = rl->avl_left; /* rll: LH or LH-1 */ 303 lockdep_is_held(&peers.lock)); /* rlr: LH or LH-1 */
285 node->avl_right = rll; /* rll: LH or LH-1 */ 304 rll = rcu_dereference_protected(rl->avl_left,
286 node->avl_left = l; /* l: LH */ 305 lockdep_is_held(&peers.lock)); /* rll: LH or LH-1 */
306 RCU_INIT_POINTER(node->avl_right, rll); /* rll: LH or LH-1 */
307 RCU_INIT_POINTER(node->avl_left, l); /* l: LH */
287 node->avl_height = lh + 1; /* node: LH+1 */ 308 node->avl_height = lh + 1; /* node: LH+1 */
288 r->avl_right = rr; /* rr: LH */ 309 RCU_INIT_POINTER(r->avl_right, rr); /* rr: LH */
289 r->avl_left = rlr; /* rlr: LH or LH-1 */ 310 RCU_INIT_POINTER(r->avl_left, rlr); /* rlr: LH or LH-1 */
290 r->avl_height = lh + 1; /* r: LH+1 */ 311 r->avl_height = lh + 1; /* r: LH+1 */
291 rl->avl_right = r; /* r: LH+1 */ 312 RCU_INIT_POINTER(rl->avl_right, r); /* r: LH+1 */
292 rl->avl_left = node; /* node: LH+1 */ 313 RCU_INIT_POINTER(rl->avl_left, node); /* node: LH+1 */
293 rl->avl_height = lh + 2; 314 rl->avl_height = lh + 2;
294 *nodep = rl; 315 RCU_INIT_POINTER(*nodep, rl);
295 } 316 }
296 } else { 317 } else {
297 node->avl_height = (lh > rh ? lh : rh) + 1; 318 node->avl_height = (lh > rh ? lh : rh) + 1;
@@ -303,10 +324,10 @@ static void peer_avl_rebalance(struct inet_peer **stack[],
303#define link_to_pool(n) \ 324#define link_to_pool(n) \
304do { \ 325do { \
305 n->avl_height = 1; \ 326 n->avl_height = 1; \
306 n->avl_left = peer_avl_empty; \ 327 n->avl_left = peer_avl_empty_rcu; \
307 n->avl_right = peer_avl_empty; \ 328 n->avl_right = peer_avl_empty_rcu; \
308 smp_wmb(); /* lockless readers can catch us now */ \ 329 /* lockless readers can catch us now */ \
309 **--stackptr = n; \ 330 rcu_assign_pointer(**--stackptr, n); \
310 peer_avl_rebalance(stack, stackptr); \ 331 peer_avl_rebalance(stack, stackptr); \
311} while (0) 332} while (0)
312 333
@@ -330,24 +351,25 @@ static void unlink_from_pool(struct inet_peer *p)
330 * We use refcnt=-1 to alert lockless readers this entry is deleted. 351 * We use refcnt=-1 to alert lockless readers this entry is deleted.
331 */ 352 */
332 if (atomic_cmpxchg(&p->refcnt, 1, -1) == 1) { 353 if (atomic_cmpxchg(&p->refcnt, 1, -1) == 1) {
333 struct inet_peer **stack[PEER_MAXDEPTH]; 354 struct inet_peer __rcu **stack[PEER_MAXDEPTH];
334 struct inet_peer ***stackptr, ***delp; 355 struct inet_peer __rcu ***stackptr, ***delp;
335 if (lookup(p->v4daddr, stack) != p) 356 if (lookup(p->v4daddr, stack) != p)
336 BUG(); 357 BUG();
337 delp = stackptr - 1; /* *delp[0] == p */ 358 delp = stackptr - 1; /* *delp[0] == p */
338 if (p->avl_left == peer_avl_empty) { 359 if (p->avl_left == peer_avl_empty_rcu) {
339 *delp[0] = p->avl_right; 360 *delp[0] = p->avl_right;
340 --stackptr; 361 --stackptr;
341 } else { 362 } else {
342 /* look for a node to insert instead of p */ 363 /* look for a node to insert instead of p */
343 struct inet_peer *t; 364 struct inet_peer *t;
344 t = lookup_rightempty(p); 365 t = lookup_rightempty(p);
345 BUG_ON(*stackptr[-1] != t); 366 BUG_ON(rcu_dereference_protected(*stackptr[-1],
367 lockdep_is_held(&peers.lock)) != t);
346 **--stackptr = t->avl_left; 368 **--stackptr = t->avl_left;
347 /* t is removed, t->v4daddr > x->v4daddr for any 369 /* t is removed, t->v4daddr > x->v4daddr for any
348 * x in p->avl_left subtree. 370 * x in p->avl_left subtree.
349 * Put t in the old place of p. */ 371 * Put t in the old place of p. */
350 *delp[0] = t; 372 RCU_INIT_POINTER(*delp[0], t);
351 t->avl_left = p->avl_left; 373 t->avl_left = p->avl_left;
352 t->avl_right = p->avl_right; 374 t->avl_right = p->avl_right;
353 t->avl_height = p->avl_height; 375 t->avl_height = p->avl_height;
@@ -414,7 +436,7 @@ static int cleanup_once(unsigned long ttl)
414struct inet_peer *inet_getpeer(__be32 daddr, int create) 436struct inet_peer *inet_getpeer(__be32 daddr, int create)
415{ 437{
416 struct inet_peer *p; 438 struct inet_peer *p;
417 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr; 439 struct inet_peer __rcu **stack[PEER_MAXDEPTH], ***stackptr;
418 440
419 /* Look up for the address quickly, lockless. 441 /* Look up for the address quickly, lockless.
420 * Because of a concurrent writer, we might not find an existing entry. 442 * Because of a concurrent writer, we might not find an existing entry.
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index d0ffcbe369b7..01087e035b7d 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -1072,6 +1072,7 @@ ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
1072 break; 1072 break;
1073 } 1073 }
1074 ipgre_tunnel_unlink(ign, t); 1074 ipgre_tunnel_unlink(ign, t);
1075 synchronize_net();
1075 t->parms.iph.saddr = p.iph.saddr; 1076 t->parms.iph.saddr = p.iph.saddr;
1076 t->parms.iph.daddr = p.iph.daddr; 1077 t->parms.iph.daddr = p.iph.daddr;
1077 t->parms.i_key = p.i_key; 1078 t->parms.i_key = p.i_key;
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 64b70ad162e3..3948c86e59ca 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -238,7 +238,7 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc)
238 but receiver should be enough clever f.e. to forward mtrace requests, 238 but receiver should be enough clever f.e. to forward mtrace requests,
239 sent to multicast group to reach destination designated router. 239 sent to multicast group to reach destination designated router.
240 */ 240 */
241struct ip_ra_chain *ip_ra_chain; 241struct ip_ra_chain __rcu *ip_ra_chain;
242static DEFINE_SPINLOCK(ip_ra_lock); 242static DEFINE_SPINLOCK(ip_ra_lock);
243 243
244 244
@@ -253,7 +253,8 @@ static void ip_ra_destroy_rcu(struct rcu_head *head)
253int ip_ra_control(struct sock *sk, unsigned char on, 253int ip_ra_control(struct sock *sk, unsigned char on,
254 void (*destructor)(struct sock *)) 254 void (*destructor)(struct sock *))
255{ 255{
256 struct ip_ra_chain *ra, *new_ra, **rap; 256 struct ip_ra_chain *ra, *new_ra;
257 struct ip_ra_chain __rcu **rap;
257 258
258 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num == IPPROTO_RAW) 259 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num == IPPROTO_RAW)
259 return -EINVAL; 260 return -EINVAL;
@@ -261,7 +262,10 @@ int ip_ra_control(struct sock *sk, unsigned char on,
261 new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL; 262 new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
262 263
263 spin_lock_bh(&ip_ra_lock); 264 spin_lock_bh(&ip_ra_lock);
264 for (rap = &ip_ra_chain; (ra = *rap) != NULL; rap = &ra->next) { 265 for (rap = &ip_ra_chain;
266 (ra = rcu_dereference_protected(*rap,
267 lockdep_is_held(&ip_ra_lock))) != NULL;
268 rap = &ra->next) {
265 if (ra->sk == sk) { 269 if (ra->sk == sk) {
266 if (on) { 270 if (on) {
267 spin_unlock_bh(&ip_ra_lock); 271 spin_unlock_bh(&ip_ra_lock);
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index e9b816e6cd73..cd300aaee78f 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -676,6 +676,7 @@ ipip_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
676 } 676 }
677 t = netdev_priv(dev); 677 t = netdev_priv(dev);
678 ipip_tunnel_unlink(ipn, t); 678 ipip_tunnel_unlink(ipn, t);
679 synchronize_net();
679 t->parms.iph.saddr = p.iph.saddr; 680 t->parms.iph.saddr = p.iph.saddr;
680 t->parms.iph.daddr = p.iph.daddr; 681 t->parms.iph.daddr = p.iph.daddr;
681 memcpy(dev->dev_addr, &p.iph.saddr, 4); 682 memcpy(dev->dev_addr, &p.iph.saddr, 4);
diff --git a/net/ipv4/protocol.c b/net/ipv4/protocol.c
index 65699c24411c..9ae5c01cd0b2 100644
--- a/net/ipv4/protocol.c
+++ b/net/ipv4/protocol.c
@@ -28,7 +28,7 @@
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <net/protocol.h> 29#include <net/protocol.h>
30 30
31const struct net_protocol *inet_protos[MAX_INET_PROTOS] __read_mostly; 31const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS] __read_mostly;
32 32
33/* 33/*
34 * Add a protocol handler to the hash tables 34 * Add a protocol handler to the hash tables
@@ -38,7 +38,8 @@ int inet_add_protocol(const struct net_protocol *prot, unsigned char protocol)
38{ 38{
39 int hash = protocol & (MAX_INET_PROTOS - 1); 39 int hash = protocol & (MAX_INET_PROTOS - 1);
40 40
41 return !cmpxchg(&inet_protos[hash], NULL, prot) ? 0 : -1; 41 return !cmpxchg((const struct net_protocol **)&inet_protos[hash],
42 NULL, prot) ? 0 : -1;
42} 43}
43EXPORT_SYMBOL(inet_add_protocol); 44EXPORT_SYMBOL(inet_add_protocol);
44 45
@@ -50,7 +51,8 @@ int inet_del_protocol(const struct net_protocol *prot, unsigned char protocol)
50{ 51{
51 int ret, hash = protocol & (MAX_INET_PROTOS - 1); 52 int ret, hash = protocol & (MAX_INET_PROTOS - 1);
52 53
53 ret = (cmpxchg(&inet_protos[hash], prot, NULL) == prot) ? 0 : -1; 54 ret = (cmpxchg((const struct net_protocol **)&inet_protos[hash],
55 prot, NULL) == prot) ? 0 : -1;
54 56
55 synchronize_net(); 57 synchronize_net();
56 58
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index d6cb2bfcd8e1..987bf9adb318 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -198,7 +198,7 @@ const __u8 ip_tos2prio[16] = {
198 */ 198 */
199 199
200struct rt_hash_bucket { 200struct rt_hash_bucket {
201 struct rtable *chain; 201 struct rtable __rcu *chain;
202}; 202};
203 203
204#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) || \ 204#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) || \
@@ -280,7 +280,7 @@ static struct rtable *rt_cache_get_first(struct seq_file *seq)
280 struct rtable *r = NULL; 280 struct rtable *r = NULL;
281 281
282 for (st->bucket = rt_hash_mask; st->bucket >= 0; --st->bucket) { 282 for (st->bucket = rt_hash_mask; st->bucket >= 0; --st->bucket) {
283 if (!rt_hash_table[st->bucket].chain) 283 if (!rcu_dereference_raw(rt_hash_table[st->bucket].chain))
284 continue; 284 continue;
285 rcu_read_lock_bh(); 285 rcu_read_lock_bh();
286 r = rcu_dereference_bh(rt_hash_table[st->bucket].chain); 286 r = rcu_dereference_bh(rt_hash_table[st->bucket].chain);
@@ -300,17 +300,17 @@ static struct rtable *__rt_cache_get_next(struct seq_file *seq,
300{ 300{
301 struct rt_cache_iter_state *st = seq->private; 301 struct rt_cache_iter_state *st = seq->private;
302 302
303 r = r->dst.rt_next; 303 r = rcu_dereference_bh(r->dst.rt_next);
304 while (!r) { 304 while (!r) {
305 rcu_read_unlock_bh(); 305 rcu_read_unlock_bh();
306 do { 306 do {
307 if (--st->bucket < 0) 307 if (--st->bucket < 0)
308 return NULL; 308 return NULL;
309 } while (!rt_hash_table[st->bucket].chain); 309 } while (!rcu_dereference_raw(rt_hash_table[st->bucket].chain));
310 rcu_read_lock_bh(); 310 rcu_read_lock_bh();
311 r = rt_hash_table[st->bucket].chain; 311 r = rcu_dereference_bh(rt_hash_table[st->bucket].chain);
312 } 312 }
313 return rcu_dereference_bh(r); 313 return r;
314} 314}
315 315
316static struct rtable *rt_cache_get_next(struct seq_file *seq, 316static struct rtable *rt_cache_get_next(struct seq_file *seq,
@@ -721,19 +721,23 @@ static void rt_do_flush(int process_context)
721 for (i = 0; i <= rt_hash_mask; i++) { 721 for (i = 0; i <= rt_hash_mask; i++) {
722 if (process_context && need_resched()) 722 if (process_context && need_resched())
723 cond_resched(); 723 cond_resched();
724 rth = rt_hash_table[i].chain; 724 rth = rcu_dereference_raw(rt_hash_table[i].chain);
725 if (!rth) 725 if (!rth)
726 continue; 726 continue;
727 727
728 spin_lock_bh(rt_hash_lock_addr(i)); 728 spin_lock_bh(rt_hash_lock_addr(i));
729#ifdef CONFIG_NET_NS 729#ifdef CONFIG_NET_NS
730 { 730 {
731 struct rtable ** prev, * p; 731 struct rtable __rcu **prev;
732 struct rtable *p;
732 733
733 rth = rt_hash_table[i].chain; 734 rth = rcu_dereference_protected(rt_hash_table[i].chain,
735 lockdep_is_held(rt_hash_lock_addr(i)));
734 736
735 /* defer releasing the head of the list after spin_unlock */ 737 /* defer releasing the head of the list after spin_unlock */
736 for (tail = rth; tail; tail = tail->dst.rt_next) 738 for (tail = rth; tail;
739 tail = rcu_dereference_protected(tail->dst.rt_next,
740 lockdep_is_held(rt_hash_lock_addr(i))))
737 if (!rt_is_expired(tail)) 741 if (!rt_is_expired(tail))
738 break; 742 break;
739 if (rth != tail) 743 if (rth != tail)
@@ -741,8 +745,12 @@ static void rt_do_flush(int process_context)
741 745
742 /* call rt_free on entries after the tail requiring flush */ 746 /* call rt_free on entries after the tail requiring flush */
743 prev = &rt_hash_table[i].chain; 747 prev = &rt_hash_table[i].chain;
744 for (p = *prev; p; p = next) { 748 for (p = rcu_dereference_protected(*prev,
745 next = p->dst.rt_next; 749 lockdep_is_held(rt_hash_lock_addr(i)));
750 p != NULL;
751 p = next) {
752 next = rcu_dereference_protected(p->dst.rt_next,
753 lockdep_is_held(rt_hash_lock_addr(i)));
746 if (!rt_is_expired(p)) { 754 if (!rt_is_expired(p)) {
747 prev = &p->dst.rt_next; 755 prev = &p->dst.rt_next;
748 } else { 756 } else {
@@ -752,14 +760,15 @@ static void rt_do_flush(int process_context)
752 } 760 }
753 } 761 }
754#else 762#else
755 rth = rt_hash_table[i].chain; 763 rth = rcu_dereference_protected(rt_hash_table[i].chain,
756 rt_hash_table[i].chain = NULL; 764 lockdep_is_held(rt_hash_lock_addr(i)));
765 rcu_assign_pointer(rt_hash_table[i].chain, NULL);
757 tail = NULL; 766 tail = NULL;
758#endif 767#endif
759 spin_unlock_bh(rt_hash_lock_addr(i)); 768 spin_unlock_bh(rt_hash_lock_addr(i));
760 769
761 for (; rth != tail; rth = next) { 770 for (; rth != tail; rth = next) {
762 next = rth->dst.rt_next; 771 next = rcu_dereference_protected(rth->dst.rt_next, 1);
763 rt_free(rth); 772 rt_free(rth);
764 } 773 }
765 } 774 }
@@ -790,7 +799,7 @@ static int has_noalias(const struct rtable *head, const struct rtable *rth)
790 while (aux != rth) { 799 while (aux != rth) {
791 if (compare_hash_inputs(&aux->fl, &rth->fl)) 800 if (compare_hash_inputs(&aux->fl, &rth->fl))
792 return 0; 801 return 0;
793 aux = aux->dst.rt_next; 802 aux = rcu_dereference_protected(aux->dst.rt_next, 1);
794 } 803 }
795 return ONE; 804 return ONE;
796} 805}
@@ -799,7 +808,8 @@ static void rt_check_expire(void)
799{ 808{
800 static unsigned int rover; 809 static unsigned int rover;
801 unsigned int i = rover, goal; 810 unsigned int i = rover, goal;
802 struct rtable *rth, **rthp; 811 struct rtable *rth;
812 struct rtable __rcu **rthp;
803 unsigned long samples = 0; 813 unsigned long samples = 0;
804 unsigned long sum = 0, sum2 = 0; 814 unsigned long sum = 0, sum2 = 0;
805 unsigned long delta; 815 unsigned long delta;
@@ -825,11 +835,12 @@ static void rt_check_expire(void)
825 835
826 samples++; 836 samples++;
827 837
828 if (*rthp == NULL) 838 if (rcu_dereference_raw(*rthp) == NULL)
829 continue; 839 continue;
830 length = 0; 840 length = 0;
831 spin_lock_bh(rt_hash_lock_addr(i)); 841 spin_lock_bh(rt_hash_lock_addr(i));
832 while ((rth = *rthp) != NULL) { 842 while ((rth = rcu_dereference_protected(*rthp,
843 lockdep_is_held(rt_hash_lock_addr(i)))) != NULL) {
833 prefetch(rth->dst.rt_next); 844 prefetch(rth->dst.rt_next);
834 if (rt_is_expired(rth)) { 845 if (rt_is_expired(rth)) {
835 *rthp = rth->dst.rt_next; 846 *rthp = rth->dst.rt_next;
@@ -941,7 +952,8 @@ static int rt_garbage_collect(struct dst_ops *ops)
941 static unsigned long last_gc; 952 static unsigned long last_gc;
942 static int rover; 953 static int rover;
943 static int equilibrium; 954 static int equilibrium;
944 struct rtable *rth, **rthp; 955 struct rtable *rth;
956 struct rtable __rcu **rthp;
945 unsigned long now = jiffies; 957 unsigned long now = jiffies;
946 int goal; 958 int goal;
947 int entries = dst_entries_get_fast(&ipv4_dst_ops); 959 int entries = dst_entries_get_fast(&ipv4_dst_ops);
@@ -995,7 +1007,8 @@ static int rt_garbage_collect(struct dst_ops *ops)
995 k = (k + 1) & rt_hash_mask; 1007 k = (k + 1) & rt_hash_mask;
996 rthp = &rt_hash_table[k].chain; 1008 rthp = &rt_hash_table[k].chain;
997 spin_lock_bh(rt_hash_lock_addr(k)); 1009 spin_lock_bh(rt_hash_lock_addr(k));
998 while ((rth = *rthp) != NULL) { 1010 while ((rth = rcu_dereference_protected(*rthp,
1011 lockdep_is_held(rt_hash_lock_addr(k)))) != NULL) {
999 if (!rt_is_expired(rth) && 1012 if (!rt_is_expired(rth) &&
1000 !rt_may_expire(rth, tmo, expire)) { 1013 !rt_may_expire(rth, tmo, expire)) {
1001 tmo >>= 1; 1014 tmo >>= 1;
@@ -1071,7 +1084,7 @@ static int slow_chain_length(const struct rtable *head)
1071 1084
1072 while (rth) { 1085 while (rth) {
1073 length += has_noalias(head, rth); 1086 length += has_noalias(head, rth);
1074 rth = rth->dst.rt_next; 1087 rth = rcu_dereference_protected(rth->dst.rt_next, 1);
1075 } 1088 }
1076 return length >> FRACT_BITS; 1089 return length >> FRACT_BITS;
1077} 1090}
@@ -1079,9 +1092,9 @@ static int slow_chain_length(const struct rtable *head)
1079static int rt_intern_hash(unsigned hash, struct rtable *rt, 1092static int rt_intern_hash(unsigned hash, struct rtable *rt,
1080 struct rtable **rp, struct sk_buff *skb, int ifindex) 1093 struct rtable **rp, struct sk_buff *skb, int ifindex)
1081{ 1094{
1082 struct rtable *rth, **rthp; 1095 struct rtable *rth, *cand;
1096 struct rtable __rcu **rthp, **candp;
1083 unsigned long now; 1097 unsigned long now;
1084 struct rtable *cand, **candp;
1085 u32 min_score; 1098 u32 min_score;
1086 int chain_length; 1099 int chain_length;
1087 int attempts = !in_softirq(); 1100 int attempts = !in_softirq();
@@ -1128,7 +1141,8 @@ restart:
1128 rthp = &rt_hash_table[hash].chain; 1141 rthp = &rt_hash_table[hash].chain;
1129 1142
1130 spin_lock_bh(rt_hash_lock_addr(hash)); 1143 spin_lock_bh(rt_hash_lock_addr(hash));
1131 while ((rth = *rthp) != NULL) { 1144 while ((rth = rcu_dereference_protected(*rthp,
1145 lockdep_is_held(rt_hash_lock_addr(hash)))) != NULL) {
1132 if (rt_is_expired(rth)) { 1146 if (rt_is_expired(rth)) {
1133 *rthp = rth->dst.rt_next; 1147 *rthp = rth->dst.rt_next;
1134 rt_free(rth); 1148 rt_free(rth);
@@ -1324,12 +1338,14 @@ EXPORT_SYMBOL(__ip_select_ident);
1324 1338
1325static void rt_del(unsigned hash, struct rtable *rt) 1339static void rt_del(unsigned hash, struct rtable *rt)
1326{ 1340{
1327 struct rtable **rthp, *aux; 1341 struct rtable __rcu **rthp;
1342 struct rtable *aux;
1328 1343
1329 rthp = &rt_hash_table[hash].chain; 1344 rthp = &rt_hash_table[hash].chain;
1330 spin_lock_bh(rt_hash_lock_addr(hash)); 1345 spin_lock_bh(rt_hash_lock_addr(hash));
1331 ip_rt_put(rt); 1346 ip_rt_put(rt);
1332 while ((aux = *rthp) != NULL) { 1347 while ((aux = rcu_dereference_protected(*rthp,
1348 lockdep_is_held(rt_hash_lock_addr(hash)))) != NULL) {
1333 if (aux == rt || rt_is_expired(aux)) { 1349 if (aux == rt || rt_is_expired(aux)) {
1334 *rthp = aux->dst.rt_next; 1350 *rthp = aux->dst.rt_next;
1335 rt_free(aux); 1351 rt_free(aux);
@@ -1346,7 +1362,8 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1346{ 1362{
1347 int i, k; 1363 int i, k;
1348 struct in_device *in_dev = __in_dev_get_rcu(dev); 1364 struct in_device *in_dev = __in_dev_get_rcu(dev);
1349 struct rtable *rth, **rthp; 1365 struct rtable *rth;
1366 struct rtable __rcu **rthp;
1350 __be32 skeys[2] = { saddr, 0 }; 1367 __be32 skeys[2] = { saddr, 0 };
1351 int ikeys[2] = { dev->ifindex, 0 }; 1368 int ikeys[2] = { dev->ifindex, 0 };
1352 struct netevent_redirect netevent; 1369 struct netevent_redirect netevent;
@@ -1379,7 +1396,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
1379 unsigned hash = rt_hash(daddr, skeys[i], ikeys[k], 1396 unsigned hash = rt_hash(daddr, skeys[i], ikeys[k],
1380 rt_genid(net)); 1397 rt_genid(net));
1381 1398
1382 rthp=&rt_hash_table[hash].chain; 1399 rthp = &rt_hash_table[hash].chain;
1383 1400
1384 while ((rth = rcu_dereference(*rthp)) != NULL) { 1401 while ((rth = rcu_dereference(*rthp)) != NULL) {
1385 struct rtable *rt; 1402 struct rtable *rt;
diff --git a/net/ipv4/tunnel4.c b/net/ipv4/tunnel4.c
index 9a17bd2a0a37..ac3b3ee4b07c 100644
--- a/net/ipv4/tunnel4.c
+++ b/net/ipv4/tunnel4.c
@@ -14,27 +14,32 @@
14#include <net/protocol.h> 14#include <net/protocol.h>
15#include <net/xfrm.h> 15#include <net/xfrm.h>
16 16
17static struct xfrm_tunnel *tunnel4_handlers __read_mostly; 17static struct xfrm_tunnel __rcu *tunnel4_handlers __read_mostly;
18static struct xfrm_tunnel *tunnel64_handlers __read_mostly; 18static struct xfrm_tunnel __rcu *tunnel64_handlers __read_mostly;
19static DEFINE_MUTEX(tunnel4_mutex); 19static DEFINE_MUTEX(tunnel4_mutex);
20 20
21static inline struct xfrm_tunnel **fam_handlers(unsigned short family) 21static inline struct xfrm_tunnel __rcu **fam_handlers(unsigned short family)
22{ 22{
23 return (family == AF_INET) ? &tunnel4_handlers : &tunnel64_handlers; 23 return (family == AF_INET) ? &tunnel4_handlers : &tunnel64_handlers;
24} 24}
25 25
26int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family) 26int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family)
27{ 27{
28 struct xfrm_tunnel **pprev; 28 struct xfrm_tunnel __rcu **pprev;
29 struct xfrm_tunnel *t;
30
29 int ret = -EEXIST; 31 int ret = -EEXIST;
30 int priority = handler->priority; 32 int priority = handler->priority;
31 33
32 mutex_lock(&tunnel4_mutex); 34 mutex_lock(&tunnel4_mutex);
33 35
34 for (pprev = fam_handlers(family); *pprev; pprev = &(*pprev)->next) { 36 for (pprev = fam_handlers(family);
35 if ((*pprev)->priority > priority) 37 (t = rcu_dereference_protected(*pprev,
38 lockdep_is_held(&tunnel4_mutex))) != NULL;
39 pprev = &t->next) {
40 if (t->priority > priority)
36 break; 41 break;
37 if ((*pprev)->priority == priority) 42 if (t->priority == priority)
38 goto err; 43 goto err;
39 } 44 }
40 45
@@ -52,13 +57,17 @@ EXPORT_SYMBOL(xfrm4_tunnel_register);
52 57
53int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family) 58int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family)
54{ 59{
55 struct xfrm_tunnel **pprev; 60 struct xfrm_tunnel __rcu **pprev;
61 struct xfrm_tunnel *t;
56 int ret = -ENOENT; 62 int ret = -ENOENT;
57 63
58 mutex_lock(&tunnel4_mutex); 64 mutex_lock(&tunnel4_mutex);
59 65
60 for (pprev = fam_handlers(family); *pprev; pprev = &(*pprev)->next) { 66 for (pprev = fam_handlers(family);
61 if (*pprev == handler) { 67 (t = rcu_dereference_protected(*pprev,
68 lockdep_is_held(&tunnel4_mutex))) != NULL;
69 pprev = &t->next) {
70 if (t == handler) {
62 *pprev = handler->next; 71 *pprev = handler->next;
63 ret = 0; 72 ret = 0;
64 break; 73 break;
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index b3f7e8cf18ac..28cb2d733a3c 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1413,7 +1413,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
1413 } 1413 }
1414 } 1414 }
1415 1415
1416 if (sk->sk_filter) { 1416 if (rcu_dereference_raw(sk->sk_filter)) {
1417 if (udp_lib_checksum_complete(skb)) 1417 if (udp_lib_checksum_complete(skb))
1418 goto drop; 1418 goto drop;
1419 } 1419 }
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index ec7a91d9e865..e048ec62d109 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -836,7 +836,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, struct inet6_ifaddr *i
836{ 836{
837 struct inet6_dev *idev = ifp->idev; 837 struct inet6_dev *idev = ifp->idev;
838 struct in6_addr addr, *tmpaddr; 838 struct in6_addr addr, *tmpaddr;
839 unsigned long tmp_prefered_lft, tmp_valid_lft, tmp_cstamp, tmp_tstamp; 839 unsigned long tmp_prefered_lft, tmp_valid_lft, tmp_cstamp, tmp_tstamp, age;
840 unsigned long regen_advance; 840 unsigned long regen_advance;
841 int tmp_plen; 841 int tmp_plen;
842 int ret = 0; 842 int ret = 0;
@@ -886,12 +886,13 @@ retry:
886 goto out; 886 goto out;
887 } 887 }
888 memcpy(&addr.s6_addr[8], idev->rndid, 8); 888 memcpy(&addr.s6_addr[8], idev->rndid, 8);
889 age = (jiffies - ifp->tstamp) / HZ;
889 tmp_valid_lft = min_t(__u32, 890 tmp_valid_lft = min_t(__u32,
890 ifp->valid_lft, 891 ifp->valid_lft,
891 idev->cnf.temp_valid_lft); 892 idev->cnf.temp_valid_lft + age);
892 tmp_prefered_lft = min_t(__u32, 893 tmp_prefered_lft = min_t(__u32,
893 ifp->prefered_lft, 894 ifp->prefered_lft,
894 idev->cnf.temp_prefered_lft - 895 idev->cnf.temp_prefered_lft + age -
895 idev->cnf.max_desync_factor); 896 idev->cnf.max_desync_factor);
896 tmp_plen = ifp->prefix_len; 897 tmp_plen = ifp->prefix_len;
897 max_addresses = idev->cnf.max_addresses; 898 max_addresses = idev->cnf.max_addresses;
@@ -1426,8 +1427,10 @@ void addrconf_dad_failure(struct inet6_ifaddr *ifp)
1426{ 1427{
1427 struct inet6_dev *idev = ifp->idev; 1428 struct inet6_dev *idev = ifp->idev;
1428 1429
1429 if (addrconf_dad_end(ifp)) 1430 if (addrconf_dad_end(ifp)) {
1431 in6_ifa_put(ifp);
1430 return; 1432 return;
1433 }
1431 1434
1432 if (net_ratelimit()) 1435 if (net_ratelimit())
1433 printk(KERN_INFO "%s: IPv6 duplicate address %pI6c detected!\n", 1436 printk(KERN_INFO "%s: IPv6 duplicate address %pI6c detected!\n",
@@ -2021,10 +2024,11 @@ ok:
2021 ipv6_ifa_notify(0, ift); 2024 ipv6_ifa_notify(0, ift);
2022 } 2025 }
2023 2026
2024 if (create && in6_dev->cnf.use_tempaddr > 0) { 2027 if ((create || list_empty(&in6_dev->tempaddr_list)) && in6_dev->cnf.use_tempaddr > 0) {
2025 /* 2028 /*
2026 * When a new public address is created as described in [ADDRCONF], 2029 * When a new public address is created as described in [ADDRCONF],
2027 * also create a new temporary address. 2030 * also create a new temporary address. Also create a temporary
2031 * address if it's enabled but no temporary address currently exists.
2028 */ 2032 */
2029 read_unlock_bh(&in6_dev->lock); 2033 read_unlock_bh(&in6_dev->lock);
2030 ipv6_create_tempaddr(ifp, NULL); 2034 ipv6_create_tempaddr(ifp, NULL);
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index c2c0f89397b1..2a59610c2a58 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1284,6 +1284,7 @@ ip6_tnl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1284 t = netdev_priv(dev); 1284 t = netdev_priv(dev);
1285 1285
1286 ip6_tnl_unlink(ip6n, t); 1286 ip6_tnl_unlink(ip6n, t);
1287 synchronize_net();
1287 err = ip6_tnl_change(t, &p); 1288 err = ip6_tnl_change(t, &p);
1288 ip6_tnl_link(ip6n, t); 1289 ip6_tnl_link(ip6n, t);
1289 netdev_state_change(dev); 1290 netdev_state_change(dev);
@@ -1371,6 +1372,7 @@ static void ip6_tnl_dev_setup(struct net_device *dev)
1371 dev->flags |= IFF_NOARP; 1372 dev->flags |= IFF_NOARP;
1372 dev->addr_len = sizeof(struct in6_addr); 1373 dev->addr_len = sizeof(struct in6_addr);
1373 dev->features |= NETIF_F_NETNS_LOCAL; 1374 dev->features |= NETIF_F_NETNS_LOCAL;
1375 dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
1374} 1376}
1375 1377
1376 1378
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 0553867a317f..d1770e061c08 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -343,6 +343,10 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
343 break; 343 break;
344 344
345 case IPV6_TRANSPARENT: 345 case IPV6_TRANSPARENT:
346 if (!capable(CAP_NET_ADMIN)) {
347 retv = -EPERM;
348 break;
349 }
346 if (optlen < sizeof(int)) 350 if (optlen < sizeof(int))
347 goto e_inval; 351 goto e_inval;
348 /* we don't have a separate transparent bit for IPV6 we use the one in the IPv4 socket */ 352 /* we don't have a separate transparent bit for IPV6 we use the one in the IPv4 socket */
diff --git a/net/ipv6/netfilter/Kconfig b/net/ipv6/netfilter/Kconfig
index 44d2eeac089b..448464844a25 100644
--- a/net/ipv6/netfilter/Kconfig
+++ b/net/ipv6/netfilter/Kconfig
@@ -5,10 +5,15 @@
5menu "IPv6: Netfilter Configuration" 5menu "IPv6: Netfilter Configuration"
6 depends on INET && IPV6 && NETFILTER 6 depends on INET && IPV6 && NETFILTER
7 7
8config NF_DEFRAG_IPV6
9 tristate
10 default n
11
8config NF_CONNTRACK_IPV6 12config NF_CONNTRACK_IPV6
9 tristate "IPv6 connection tracking support" 13 tristate "IPv6 connection tracking support"
10 depends on INET && IPV6 && NF_CONNTRACK 14 depends on INET && IPV6 && NF_CONNTRACK
11 default m if NETFILTER_ADVANCED=n 15 default m if NETFILTER_ADVANCED=n
16 select NF_DEFRAG_IPV6
12 ---help--- 17 ---help---
13 Connection tracking keeps a record of what packets have passed 18 Connection tracking keeps a record of what packets have passed
14 through your machine, in order to figure out how they are related 19 through your machine, in order to figure out how they are related
diff --git a/net/ipv6/netfilter/Makefile b/net/ipv6/netfilter/Makefile
index 3f8e4a3d83ce..0a432c9b0795 100644
--- a/net/ipv6/netfilter/Makefile
+++ b/net/ipv6/netfilter/Makefile
@@ -12,11 +12,14 @@ obj-$(CONFIG_IP6_NF_SECURITY) += ip6table_security.o
12 12
13# objects for l3 independent conntrack 13# objects for l3 independent conntrack
14nf_conntrack_ipv6-objs := nf_conntrack_l3proto_ipv6.o nf_conntrack_proto_icmpv6.o 14nf_conntrack_ipv6-objs := nf_conntrack_l3proto_ipv6.o nf_conntrack_proto_icmpv6.o
15nf_defrag_ipv6-objs := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o
16 15
17# l3 independent conntrack 16# l3 independent conntrack
18obj-$(CONFIG_NF_CONNTRACK_IPV6) += nf_conntrack_ipv6.o nf_defrag_ipv6.o 17obj-$(CONFIG_NF_CONNTRACK_IPV6) += nf_conntrack_ipv6.o nf_defrag_ipv6.o
19 18
19# defrag
20nf_defrag_ipv6-objs := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o
21obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o
22
20# matches 23# matches
21obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o 24obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
22obj-$(CONFIG_IP6_NF_MATCH_EUI64) += ip6t_eui64.o 25obj-$(CONFIG_IP6_NF_MATCH_EUI64) += ip6t_eui64.o
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index 489d71b844ac..3a3f129a44cb 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -625,21 +625,24 @@ int nf_ct_frag6_init(void)
625 inet_frags_init_net(&nf_init_frags); 625 inet_frags_init_net(&nf_init_frags);
626 inet_frags_init(&nf_frags); 626 inet_frags_init(&nf_frags);
627 627
628#ifdef CONFIG_SYSCTL
628 nf_ct_frag6_sysctl_header = register_sysctl_paths(nf_net_netfilter_sysctl_path, 629 nf_ct_frag6_sysctl_header = register_sysctl_paths(nf_net_netfilter_sysctl_path,
629 nf_ct_frag6_sysctl_table); 630 nf_ct_frag6_sysctl_table);
630 if (!nf_ct_frag6_sysctl_header) { 631 if (!nf_ct_frag6_sysctl_header) {
631 inet_frags_fini(&nf_frags); 632 inet_frags_fini(&nf_frags);
632 return -ENOMEM; 633 return -ENOMEM;
633 } 634 }
635#endif
634 636
635 return 0; 637 return 0;
636} 638}
637 639
638void nf_ct_frag6_cleanup(void) 640void nf_ct_frag6_cleanup(void)
639{ 641{
642#ifdef CONFIG_SYSCTL
640 unregister_sysctl_table(nf_ct_frag6_sysctl_header); 643 unregister_sysctl_table(nf_ct_frag6_sysctl_header);
641 nf_ct_frag6_sysctl_header = NULL; 644 nf_ct_frag6_sysctl_header = NULL;
642 645#endif
643 inet_frags_fini(&nf_frags); 646 inet_frags_fini(&nf_frags);
644 647
645 nf_init_frags.low_thresh = 0; 648 nf_init_frags.low_thresh = 0;
diff --git a/net/ipv6/protocol.c b/net/ipv6/protocol.c
index 9bb936ae2452..9a7978fdc02a 100644
--- a/net/ipv6/protocol.c
+++ b/net/ipv6/protocol.c
@@ -25,13 +25,14 @@
25#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <net/protocol.h> 26#include <net/protocol.h>
27 27
28const struct inet6_protocol *inet6_protos[MAX_INET_PROTOS] __read_mostly; 28const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS] __read_mostly;
29 29
30int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol) 30int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol)
31{ 31{
32 int hash = protocol & (MAX_INET_PROTOS - 1); 32 int hash = protocol & (MAX_INET_PROTOS - 1);
33 33
34 return !cmpxchg(&inet6_protos[hash], NULL, prot) ? 0 : -1; 34 return !cmpxchg((const struct inet6_protocol **)&inet6_protos[hash],
35 NULL, prot) ? 0 : -1;
35} 36}
36EXPORT_SYMBOL(inet6_add_protocol); 37EXPORT_SYMBOL(inet6_add_protocol);
37 38
@@ -43,7 +44,8 @@ int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char protocol
43{ 44{
44 int ret, hash = protocol & (MAX_INET_PROTOS - 1); 45 int ret, hash = protocol & (MAX_INET_PROTOS - 1);
45 46
46 ret = (cmpxchg(&inet6_protos[hash], prot, NULL) == prot) ? 0 : -1; 47 ret = (cmpxchg((const struct inet6_protocol **)&inet6_protos[hash],
48 prot, NULL) == prot) ? 0 : -1;
47 49
48 synchronize_net(); 50 synchronize_net();
49 51
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 45e6efb7f171..86c39526ba5e 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -373,7 +373,7 @@ void raw6_icmp_error(struct sk_buff *skb, int nexthdr,
373 373
374static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb) 374static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
375{ 375{
376 if ((raw6_sk(sk)->checksum || sk->sk_filter) && 376 if ((raw6_sk(sk)->checksum || rcu_dereference_raw(sk->sk_filter)) &&
377 skb_checksum_complete(skb)) { 377 skb_checksum_complete(skb)) {
378 atomic_inc(&sk->sk_drops); 378 atomic_inc(&sk->sk_drops);
379 kfree_skb(skb); 379 kfree_skb(skb);
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 367a6cc584cc..d6bfaec3bbbf 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -963,6 +963,7 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
963 } 963 }
964 t = netdev_priv(dev); 964 t = netdev_priv(dev);
965 ipip6_tunnel_unlink(sitn, t); 965 ipip6_tunnel_unlink(sitn, t);
966 synchronize_net();
966 t->parms.iph.saddr = p.iph.saddr; 967 t->parms.iph.saddr = p.iph.saddr;
967 t->parms.iph.daddr = p.iph.daddr; 968 t->parms.iph.daddr = p.iph.daddr;
968 memcpy(dev->dev_addr, &p.iph.saddr, 4); 969 memcpy(dev->dev_addr, &p.iph.saddr, 4);
diff --git a/net/ipv6/tunnel6.c b/net/ipv6/tunnel6.c
index d9864725d0c6..4f3cec12aa85 100644
--- a/net/ipv6/tunnel6.c
+++ b/net/ipv6/tunnel6.c
@@ -30,23 +30,26 @@
30#include <net/protocol.h> 30#include <net/protocol.h>
31#include <net/xfrm.h> 31#include <net/xfrm.h>
32 32
33static struct xfrm6_tunnel *tunnel6_handlers __read_mostly; 33static struct xfrm6_tunnel __rcu *tunnel6_handlers __read_mostly;
34static struct xfrm6_tunnel *tunnel46_handlers __read_mostly; 34static struct xfrm6_tunnel __rcu *tunnel46_handlers __read_mostly;
35static DEFINE_MUTEX(tunnel6_mutex); 35static DEFINE_MUTEX(tunnel6_mutex);
36 36
37int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family) 37int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family)
38{ 38{
39 struct xfrm6_tunnel **pprev; 39 struct xfrm6_tunnel __rcu **pprev;
40 struct xfrm6_tunnel *t;
40 int ret = -EEXIST; 41 int ret = -EEXIST;
41 int priority = handler->priority; 42 int priority = handler->priority;
42 43
43 mutex_lock(&tunnel6_mutex); 44 mutex_lock(&tunnel6_mutex);
44 45
45 for (pprev = (family == AF_INET6) ? &tunnel6_handlers : &tunnel46_handlers; 46 for (pprev = (family == AF_INET6) ? &tunnel6_handlers : &tunnel46_handlers;
46 *pprev; pprev = &(*pprev)->next) { 47 (t = rcu_dereference_protected(*pprev,
47 if ((*pprev)->priority > priority) 48 lockdep_is_held(&tunnel6_mutex))) != NULL;
49 pprev = &t->next) {
50 if (t->priority > priority)
48 break; 51 break;
49 if ((*pprev)->priority == priority) 52 if (t->priority == priority)
50 goto err; 53 goto err;
51 } 54 }
52 55
@@ -65,14 +68,17 @@ EXPORT_SYMBOL(xfrm6_tunnel_register);
65 68
66int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family) 69int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family)
67{ 70{
68 struct xfrm6_tunnel **pprev; 71 struct xfrm6_tunnel __rcu **pprev;
72 struct xfrm6_tunnel *t;
69 int ret = -ENOENT; 73 int ret = -ENOENT;
70 74
71 mutex_lock(&tunnel6_mutex); 75 mutex_lock(&tunnel6_mutex);
72 76
73 for (pprev = (family == AF_INET6) ? &tunnel6_handlers : &tunnel46_handlers; 77 for (pprev = (family == AF_INET6) ? &tunnel6_handlers : &tunnel46_handlers;
74 *pprev; pprev = &(*pprev)->next) { 78 (t = rcu_dereference_protected(*pprev,
75 if (*pprev == handler) { 79 lockdep_is_held(&tunnel6_mutex))) != NULL;
80 pprev = &t->next) {
81 if (t == handler) {
76 *pprev = handler->next; 82 *pprev = handler->next;
77 ret = 0; 83 ret = 0;
78 break; 84 break;
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index c84dad432114..91def93bec85 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -527,7 +527,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
527 } 527 }
528 } 528 }
529 529
530 if (sk->sk_filter) { 530 if (rcu_dereference_raw(sk->sk_filter)) {
531 if (udp_lib_checksum_complete(skb)) 531 if (udp_lib_checksum_complete(skb))
532 goto drop; 532 goto drop;
533 } 533 }
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index 1712af1c7b3f..c64ce0a0bb03 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -111,6 +111,10 @@ struct l2tp_net {
111 spinlock_t l2tp_session_hlist_lock; 111 spinlock_t l2tp_session_hlist_lock;
112}; 112};
113 113
114static void l2tp_session_set_header_len(struct l2tp_session *session, int version);
115static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel);
116static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel);
117
114static inline struct l2tp_net *l2tp_pernet(struct net *net) 118static inline struct l2tp_net *l2tp_pernet(struct net *net)
115{ 119{
116 BUG_ON(!net); 120 BUG_ON(!net);
@@ -118,6 +122,34 @@ static inline struct l2tp_net *l2tp_pernet(struct net *net)
118 return net_generic(net, l2tp_net_id); 122 return net_generic(net, l2tp_net_id);
119} 123}
120 124
125
126/* Tunnel reference counts. Incremented per session that is added to
127 * the tunnel.
128 */
129static inline void l2tp_tunnel_inc_refcount_1(struct l2tp_tunnel *tunnel)
130{
131 atomic_inc(&tunnel->ref_count);
132}
133
134static inline void l2tp_tunnel_dec_refcount_1(struct l2tp_tunnel *tunnel)
135{
136 if (atomic_dec_and_test(&tunnel->ref_count))
137 l2tp_tunnel_free(tunnel);
138}
139#ifdef L2TP_REFCNT_DEBUG
140#define l2tp_tunnel_inc_refcount(_t) do { \
141 printk(KERN_DEBUG "l2tp_tunnel_inc_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_t)->name, atomic_read(&_t->ref_count)); \
142 l2tp_tunnel_inc_refcount_1(_t); \
143 } while (0)
144#define l2tp_tunnel_dec_refcount(_t) do { \
145 printk(KERN_DEBUG "l2tp_tunnel_dec_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_t)->name, atomic_read(&_t->ref_count)); \
146 l2tp_tunnel_dec_refcount_1(_t); \
147 } while (0)
148#else
149#define l2tp_tunnel_inc_refcount(t) l2tp_tunnel_inc_refcount_1(t)
150#define l2tp_tunnel_dec_refcount(t) l2tp_tunnel_dec_refcount_1(t)
151#endif
152
121/* Session hash global list for L2TPv3. 153/* Session hash global list for L2TPv3.
122 * The session_id SHOULD be random according to RFC3931, but several 154 * The session_id SHOULD be random according to RFC3931, but several
123 * L2TP implementations use incrementing session_ids. So we do a real 155 * L2TP implementations use incrementing session_ids. So we do a real
@@ -699,8 +731,8 @@ EXPORT_SYMBOL(l2tp_recv_common);
699 * Returns 1 if the packet was not a good data packet and could not be 731 * Returns 1 if the packet was not a good data packet and could not be
700 * forwarded. All such packets are passed up to userspace to deal with. 732 * forwarded. All such packets are passed up to userspace to deal with.
701 */ 733 */
702int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb, 734static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb,
703 int (*payload_hook)(struct sk_buff *skb)) 735 int (*payload_hook)(struct sk_buff *skb))
704{ 736{
705 struct l2tp_session *session = NULL; 737 struct l2tp_session *session = NULL;
706 unsigned char *ptr, *optr; 738 unsigned char *ptr, *optr;
@@ -812,7 +844,6 @@ error:
812 844
813 return 1; 845 return 1;
814} 846}
815EXPORT_SYMBOL_GPL(l2tp_udp_recv_core);
816 847
817/* UDP encapsulation receive handler. See net/ipv4/udp.c. 848/* UDP encapsulation receive handler. See net/ipv4/udp.c.
818 * Return codes: 849 * Return codes:
@@ -922,7 +953,8 @@ static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf)
922 return bufp - optr; 953 return bufp - optr;
923} 954}
924 955
925int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, size_t data_len) 956static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
957 size_t data_len)
926{ 958{
927 struct l2tp_tunnel *tunnel = session->tunnel; 959 struct l2tp_tunnel *tunnel = session->tunnel;
928 unsigned int len = skb->len; 960 unsigned int len = skb->len;
@@ -970,7 +1002,6 @@ int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, size_t dat
970 1002
971 return 0; 1003 return 0;
972} 1004}
973EXPORT_SYMBOL_GPL(l2tp_xmit_core);
974 1005
975/* Automatically called when the skb is freed. 1006/* Automatically called when the skb is freed.
976 */ 1007 */
@@ -1089,7 +1120,7 @@ EXPORT_SYMBOL_GPL(l2tp_xmit_skb);
1089 * The tunnel context is deleted only when all session sockets have been 1120 * The tunnel context is deleted only when all session sockets have been
1090 * closed. 1121 * closed.
1091 */ 1122 */
1092void l2tp_tunnel_destruct(struct sock *sk) 1123static void l2tp_tunnel_destruct(struct sock *sk)
1093{ 1124{
1094 struct l2tp_tunnel *tunnel; 1125 struct l2tp_tunnel *tunnel;
1095 1126
@@ -1128,11 +1159,10 @@ void l2tp_tunnel_destruct(struct sock *sk)
1128end: 1159end:
1129 return; 1160 return;
1130} 1161}
1131EXPORT_SYMBOL(l2tp_tunnel_destruct);
1132 1162
1133/* When the tunnel is closed, all the attached sessions need to go too. 1163/* When the tunnel is closed, all the attached sessions need to go too.
1134 */ 1164 */
1135void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) 1165static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)
1136{ 1166{
1137 int hash; 1167 int hash;
1138 struct hlist_node *walk; 1168 struct hlist_node *walk;
@@ -1193,12 +1223,11 @@ again:
1193 } 1223 }
1194 write_unlock_bh(&tunnel->hlist_lock); 1224 write_unlock_bh(&tunnel->hlist_lock);
1195} 1225}
1196EXPORT_SYMBOL_GPL(l2tp_tunnel_closeall);
1197 1226
1198/* Really kill the tunnel. 1227/* Really kill the tunnel.
1199 * Come here only when all sessions have been cleared from the tunnel. 1228 * Come here only when all sessions have been cleared from the tunnel.
1200 */ 1229 */
1201void l2tp_tunnel_free(struct l2tp_tunnel *tunnel) 1230static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel)
1202{ 1231{
1203 struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); 1232 struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net);
1204 1233
@@ -1217,7 +1246,6 @@ void l2tp_tunnel_free(struct l2tp_tunnel *tunnel)
1217 atomic_dec(&l2tp_tunnel_count); 1246 atomic_dec(&l2tp_tunnel_count);
1218 kfree(tunnel); 1247 kfree(tunnel);
1219} 1248}
1220EXPORT_SYMBOL_GPL(l2tp_tunnel_free);
1221 1249
1222/* Create a socket for the tunnel, if one isn't set up by 1250/* Create a socket for the tunnel, if one isn't set up by
1223 * userspace. This is used for static tunnels where there is no 1251 * userspace. This is used for static tunnels where there is no
@@ -1512,7 +1540,7 @@ EXPORT_SYMBOL_GPL(l2tp_session_delete);
1512/* We come here whenever a session's send_seq, cookie_len or 1540/* We come here whenever a session's send_seq, cookie_len or
1513 * l2specific_len parameters are set. 1541 * l2specific_len parameters are set.
1514 */ 1542 */
1515void l2tp_session_set_header_len(struct l2tp_session *session, int version) 1543static void l2tp_session_set_header_len(struct l2tp_session *session, int version)
1516{ 1544{
1517 if (version == L2TP_HDR_VER_2) { 1545 if (version == L2TP_HDR_VER_2) {
1518 session->hdr_len = 6; 1546 session->hdr_len = 6;
@@ -1525,7 +1553,6 @@ void l2tp_session_set_header_len(struct l2tp_session *session, int version)
1525 } 1553 }
1526 1554
1527} 1555}
1528EXPORT_SYMBOL_GPL(l2tp_session_set_header_len);
1529 1556
1530struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg) 1557struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg)
1531{ 1558{
diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
index f0f318edd3f1..a16a48e79fab 100644
--- a/net/l2tp/l2tp_core.h
+++ b/net/l2tp/l2tp_core.h
@@ -231,48 +231,15 @@ extern int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_i
231extern int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel); 231extern int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel);
232extern struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg); 232extern struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg);
233extern int l2tp_session_delete(struct l2tp_session *session); 233extern int l2tp_session_delete(struct l2tp_session *session);
234extern void l2tp_tunnel_free(struct l2tp_tunnel *tunnel);
235extern void l2tp_session_free(struct l2tp_session *session); 234extern void l2tp_session_free(struct l2tp_session *session);
236extern void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, unsigned char *ptr, unsigned char *optr, u16 hdrflags, int length, int (*payload_hook)(struct sk_buff *skb)); 235extern void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, unsigned char *ptr, unsigned char *optr, u16 hdrflags, int length, int (*payload_hook)(struct sk_buff *skb));
237extern int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb, int (*payload_hook)(struct sk_buff *skb));
238extern int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb); 236extern int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb);
239 237
240extern int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, size_t data_len);
241extern int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len); 238extern int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len);
242extern void l2tp_tunnel_destruct(struct sock *sk);
243extern void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel);
244extern void l2tp_session_set_header_len(struct l2tp_session *session, int version);
245 239
246extern int l2tp_nl_register_ops(enum l2tp_pwtype pw_type, const struct l2tp_nl_cmd_ops *ops); 240extern int l2tp_nl_register_ops(enum l2tp_pwtype pw_type, const struct l2tp_nl_cmd_ops *ops);
247extern void l2tp_nl_unregister_ops(enum l2tp_pwtype pw_type); 241extern void l2tp_nl_unregister_ops(enum l2tp_pwtype pw_type);
248 242
249/* Tunnel reference counts. Incremented per session that is added to
250 * the tunnel.
251 */
252static inline void l2tp_tunnel_inc_refcount_1(struct l2tp_tunnel *tunnel)
253{
254 atomic_inc(&tunnel->ref_count);
255}
256
257static inline void l2tp_tunnel_dec_refcount_1(struct l2tp_tunnel *tunnel)
258{
259 if (atomic_dec_and_test(&tunnel->ref_count))
260 l2tp_tunnel_free(tunnel);
261}
262#ifdef L2TP_REFCNT_DEBUG
263#define l2tp_tunnel_inc_refcount(_t) do { \
264 printk(KERN_DEBUG "l2tp_tunnel_inc_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_t)->name, atomic_read(&_t->ref_count)); \
265 l2tp_tunnel_inc_refcount_1(_t); \
266 } while (0)
267#define l2tp_tunnel_dec_refcount(_t) do { \
268 printk(KERN_DEBUG "l2tp_tunnel_dec_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_t)->name, atomic_read(&_t->ref_count)); \
269 l2tp_tunnel_dec_refcount_1(_t); \
270 } while (0)
271#else
272#define l2tp_tunnel_inc_refcount(t) l2tp_tunnel_inc_refcount_1(t)
273#define l2tp_tunnel_dec_refcount(t) l2tp_tunnel_dec_refcount_1(t)
274#endif
275
276/* Session reference counts. Incremented when code obtains a reference 243/* Session reference counts. Incremented when code obtains a reference
277 * to a session. 244 * to a session.
278 */ 245 */
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 1c770c0644d1..0bf6a59545ab 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -576,7 +576,7 @@ out:
576 return copied; 576 return copied;
577} 577}
578 578
579struct proto l2tp_ip_prot = { 579static struct proto l2tp_ip_prot = {
580 .name = "L2TP/IP", 580 .name = "L2TP/IP",
581 .owner = THIS_MODULE, 581 .owner = THIS_MODULE,
582 .init = l2tp_ip_open, 582 .init = l2tp_ip_open,
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index ff60c022f51d..239c4836a946 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -456,6 +456,7 @@ struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
456 if (!sta) 456 if (!sta)
457 return NULL; 457 return NULL;
458 458
459 sta->last_rx = jiffies;
459 set_sta_flags(sta, WLAN_STA_AUTHORIZED); 460 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
460 461
461 /* make sure mandatory rates are always added */ 462 /* make sure mandatory rates are always added */
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 22bc42b18991..6b322fa681f5 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -748,7 +748,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
748 hw->queues = IEEE80211_MAX_QUEUES; 748 hw->queues = IEEE80211_MAX_QUEUES;
749 749
750 local->workqueue = 750 local->workqueue =
751 create_singlethread_workqueue(wiphy_name(local->hw.wiphy)); 751 alloc_ordered_workqueue(wiphy_name(local->hw.wiphy), 0);
752 if (!local->workqueue) { 752 if (!local->workqueue) {
753 result = -ENOMEM; 753 result = -ENOMEM;
754 goto fail_workqueue; 754 goto fail_workqueue;
@@ -962,12 +962,6 @@ static void __exit ieee80211_exit(void)
962 rc80211_minstrel_ht_exit(); 962 rc80211_minstrel_ht_exit();
963 rc80211_minstrel_exit(); 963 rc80211_minstrel_exit();
964 964
965 /*
966 * For key todo, it'll be empty by now but the work
967 * might still be scheduled.
968 */
969 flush_scheduled_work();
970
971 if (mesh_allocated) 965 if (mesh_allocated)
972 ieee80211s_stop(); 966 ieee80211s_stop();
973 967
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
index 809cf230d251..33f76993da08 100644
--- a/net/mac80211/rate.c
+++ b/net/mac80211/rate.c
@@ -329,6 +329,9 @@ void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
329 * if needed. 329 * if needed.
330 */ 330 */
331 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { 331 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
332 /* Skip invalid rates */
333 if (info->control.rates[i].idx < 0)
334 break;
332 /* Rate masking supports only legacy rates for now */ 335 /* Rate masking supports only legacy rates for now */
333 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) 336 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS)
334 continue; 337 continue;
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index 43288259f4a1..1534f2b44caf 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -525,6 +525,7 @@ config NETFILTER_XT_TARGET_TPROXY
525 depends on NETFILTER_XTABLES 525 depends on NETFILTER_XTABLES
526 depends on NETFILTER_ADVANCED 526 depends on NETFILTER_ADVANCED
527 select NF_DEFRAG_IPV4 527 select NF_DEFRAG_IPV4
528 select NF_DEFRAG_IPV6 if IP6_NF_IPTABLES
528 help 529 help
529 This option adds a `TPROXY' target, which is somewhat similar to 530 This option adds a `TPROXY' target, which is somewhat similar to
530 REDIRECT. It can only be used in the mangle table and is useful 531 REDIRECT. It can only be used in the mangle table and is useful
@@ -927,6 +928,7 @@ config NETFILTER_XT_MATCH_SOCKET
927 depends on NETFILTER_ADVANCED 928 depends on NETFILTER_ADVANCED
928 depends on !NF_CONNTRACK || NF_CONNTRACK 929 depends on !NF_CONNTRACK || NF_CONNTRACK
929 select NF_DEFRAG_IPV4 930 select NF_DEFRAG_IPV4
931 select NF_DEFRAG_IPV6 if IP6_NF_IPTABLES
930 help 932 help
931 This option adds a `socket' match, which can be used to match 933 This option adds a `socket' match, which can be used to match
932 packets for which a TCP or UDP socket lookup finds a valid socket. 934 packets for which a TCP or UDP socket lookup finds a valid socket.
diff --git a/net/netfilter/xt_TPROXY.c b/net/netfilter/xt_TPROXY.c
index 19c482caf30b..640678f47a2a 100644
--- a/net/netfilter/xt_TPROXY.c
+++ b/net/netfilter/xt_TPROXY.c
@@ -21,7 +21,9 @@
21#include <linux/netfilter_ipv4/ip_tables.h> 21#include <linux/netfilter_ipv4/ip_tables.h>
22 22
23#include <net/netfilter/ipv4/nf_defrag_ipv4.h> 23#include <net/netfilter/ipv4/nf_defrag_ipv4.h>
24#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 24
25#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
26#define XT_TPROXY_HAVE_IPV6 1
25#include <net/if_inet6.h> 27#include <net/if_inet6.h>
26#include <net/addrconf.h> 28#include <net/addrconf.h>
27#include <linux/netfilter_ipv6/ip6_tables.h> 29#include <linux/netfilter_ipv6/ip6_tables.h>
@@ -172,7 +174,7 @@ tproxy_tg4_v1(struct sk_buff *skb, const struct xt_action_param *par)
172 return tproxy_tg4(skb, tgi->laddr.ip, tgi->lport, tgi->mark_mask, tgi->mark_value); 174 return tproxy_tg4(skb, tgi->laddr.ip, tgi->lport, tgi->mark_mask, tgi->mark_value);
173} 175}
174 176
175#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 177#ifdef XT_TPROXY_HAVE_IPV6
176 178
177static inline const struct in6_addr * 179static inline const struct in6_addr *
178tproxy_laddr6(struct sk_buff *skb, const struct in6_addr *user_laddr, 180tproxy_laddr6(struct sk_buff *skb, const struct in6_addr *user_laddr,
@@ -372,7 +374,7 @@ static struct xt_target tproxy_tg_reg[] __read_mostly = {
372 .hooks = 1 << NF_INET_PRE_ROUTING, 374 .hooks = 1 << NF_INET_PRE_ROUTING,
373 .me = THIS_MODULE, 375 .me = THIS_MODULE,
374 }, 376 },
375#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 377#ifdef XT_TPROXY_HAVE_IPV6
376 { 378 {
377 .name = "TPROXY", 379 .name = "TPROXY",
378 .family = NFPROTO_IPV6, 380 .family = NFPROTO_IPV6,
@@ -391,7 +393,7 @@ static struct xt_target tproxy_tg_reg[] __read_mostly = {
391static int __init tproxy_tg_init(void) 393static int __init tproxy_tg_init(void)
392{ 394{
393 nf_defrag_ipv4_enable(); 395 nf_defrag_ipv4_enable();
394#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 396#ifdef XT_TPROXY_HAVE_IPV6
395 nf_defrag_ipv6_enable(); 397 nf_defrag_ipv6_enable();
396#endif 398#endif
397 399
diff --git a/net/netfilter/xt_socket.c b/net/netfilter/xt_socket.c
index 2dbd4c857735..d94a858dc52a 100644
--- a/net/netfilter/xt_socket.c
+++ b/net/netfilter/xt_socket.c
@@ -14,7 +14,6 @@
14#include <linux/skbuff.h> 14#include <linux/skbuff.h>
15#include <linux/netfilter/x_tables.h> 15#include <linux/netfilter/x_tables.h>
16#include <linux/netfilter_ipv4/ip_tables.h> 16#include <linux/netfilter_ipv4/ip_tables.h>
17#include <linux/netfilter_ipv6/ip6_tables.h>
18#include <net/tcp.h> 17#include <net/tcp.h>
19#include <net/udp.h> 18#include <net/udp.h>
20#include <net/icmp.h> 19#include <net/icmp.h>
@@ -22,7 +21,12 @@
22#include <net/inet_sock.h> 21#include <net/inet_sock.h>
23#include <net/netfilter/nf_tproxy_core.h> 22#include <net/netfilter/nf_tproxy_core.h>
24#include <net/netfilter/ipv4/nf_defrag_ipv4.h> 23#include <net/netfilter/ipv4/nf_defrag_ipv4.h>
24
25#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
26#define XT_SOCKET_HAVE_IPV6 1
27#include <linux/netfilter_ipv6/ip6_tables.h>
25#include <net/netfilter/ipv6/nf_defrag_ipv6.h> 28#include <net/netfilter/ipv6/nf_defrag_ipv6.h>
29#endif
26 30
27#include <linux/netfilter/xt_socket.h> 31#include <linux/netfilter/xt_socket.h>
28 32
@@ -186,7 +190,7 @@ socket_mt4_v1(const struct sk_buff *skb, struct xt_action_param *par)
186 return socket_match(skb, par, par->matchinfo); 190 return socket_match(skb, par, par->matchinfo);
187} 191}
188 192
189#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 193#ifdef XT_SOCKET_HAVE_IPV6
190 194
191static int 195static int
192extract_icmp6_fields(const struct sk_buff *skb, 196extract_icmp6_fields(const struct sk_buff *skb,
@@ -331,7 +335,7 @@ static struct xt_match socket_mt_reg[] __read_mostly = {
331 (1 << NF_INET_LOCAL_IN), 335 (1 << NF_INET_LOCAL_IN),
332 .me = THIS_MODULE, 336 .me = THIS_MODULE,
333 }, 337 },
334#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 338#ifdef XT_SOCKET_HAVE_IPV6
335 { 339 {
336 .name = "socket", 340 .name = "socket",
337 .revision = 1, 341 .revision = 1,
@@ -348,7 +352,7 @@ static struct xt_match socket_mt_reg[] __read_mostly = {
348static int __init socket_mt_init(void) 352static int __init socket_mt_init(void)
349{ 353{
350 nf_defrag_ipv4_enable(); 354 nf_defrag_ipv4_enable();
351#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 355#ifdef XT_SOCKET_HAVE_IPV6
352 nf_defrag_ipv6_enable(); 356 nf_defrag_ipv6_enable();
353#endif 357#endif
354 358
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index cd96ed3ccee4..478181d53c55 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -83,9 +83,9 @@ struct netlink_sock {
83 struct module *module; 83 struct module *module;
84}; 84};
85 85
86struct listeners_rcu_head { 86struct listeners {
87 struct rcu_head rcu_head; 87 struct rcu_head rcu;
88 void *ptr; 88 unsigned long masks[0];
89}; 89};
90 90
91#define NETLINK_KERNEL_SOCKET 0x1 91#define NETLINK_KERNEL_SOCKET 0x1
@@ -119,7 +119,7 @@ struct nl_pid_hash {
119struct netlink_table { 119struct netlink_table {
120 struct nl_pid_hash hash; 120 struct nl_pid_hash hash;
121 struct hlist_head mc_list; 121 struct hlist_head mc_list;
122 unsigned long *listeners; 122 struct listeners __rcu *listeners;
123 unsigned int nl_nonroot; 123 unsigned int nl_nonroot;
124 unsigned int groups; 124 unsigned int groups;
125 struct mutex *cb_mutex; 125 struct mutex *cb_mutex;
@@ -338,7 +338,7 @@ netlink_update_listeners(struct sock *sk)
338 if (i < NLGRPLONGS(nlk_sk(sk)->ngroups)) 338 if (i < NLGRPLONGS(nlk_sk(sk)->ngroups))
339 mask |= nlk_sk(sk)->groups[i]; 339 mask |= nlk_sk(sk)->groups[i];
340 } 340 }
341 tbl->listeners[i] = mask; 341 tbl->listeners->masks[i] = mask;
342 } 342 }
343 /* this function is only called with the netlink table "grabbed", which 343 /* this function is only called with the netlink table "grabbed", which
344 * makes sure updates are visible before bind or setsockopt return. */ 344 * makes sure updates are visible before bind or setsockopt return. */
@@ -936,7 +936,7 @@ EXPORT_SYMBOL(netlink_unicast);
936int netlink_has_listeners(struct sock *sk, unsigned int group) 936int netlink_has_listeners(struct sock *sk, unsigned int group)
937{ 937{
938 int res = 0; 938 int res = 0;
939 unsigned long *listeners; 939 struct listeners *listeners;
940 940
941 BUG_ON(!netlink_is_kernel(sk)); 941 BUG_ON(!netlink_is_kernel(sk));
942 942
@@ -944,7 +944,7 @@ int netlink_has_listeners(struct sock *sk, unsigned int group)
944 listeners = rcu_dereference(nl_table[sk->sk_protocol].listeners); 944 listeners = rcu_dereference(nl_table[sk->sk_protocol].listeners);
945 945
946 if (group - 1 < nl_table[sk->sk_protocol].groups) 946 if (group - 1 < nl_table[sk->sk_protocol].groups)
947 res = test_bit(group - 1, listeners); 947 res = test_bit(group - 1, listeners->masks);
948 948
949 rcu_read_unlock(); 949 rcu_read_unlock();
950 950
@@ -1498,7 +1498,7 @@ netlink_kernel_create(struct net *net, int unit, unsigned int groups,
1498 struct socket *sock; 1498 struct socket *sock;
1499 struct sock *sk; 1499 struct sock *sk;
1500 struct netlink_sock *nlk; 1500 struct netlink_sock *nlk;
1501 unsigned long *listeners = NULL; 1501 struct listeners *listeners = NULL;
1502 1502
1503 BUG_ON(!nl_table); 1503 BUG_ON(!nl_table);
1504 1504
@@ -1523,8 +1523,7 @@ netlink_kernel_create(struct net *net, int unit, unsigned int groups,
1523 if (groups < 32) 1523 if (groups < 32)
1524 groups = 32; 1524 groups = 32;
1525 1525
1526 listeners = kzalloc(NLGRPSZ(groups) + sizeof(struct listeners_rcu_head), 1526 listeners = kzalloc(sizeof(*listeners) + NLGRPSZ(groups), GFP_KERNEL);
1527 GFP_KERNEL);
1528 if (!listeners) 1527 if (!listeners)
1529 goto out_sock_release; 1528 goto out_sock_release;
1530 1529
@@ -1541,7 +1540,7 @@ netlink_kernel_create(struct net *net, int unit, unsigned int groups,
1541 netlink_table_grab(); 1540 netlink_table_grab();
1542 if (!nl_table[unit].registered) { 1541 if (!nl_table[unit].registered) {
1543 nl_table[unit].groups = groups; 1542 nl_table[unit].groups = groups;
1544 nl_table[unit].listeners = listeners; 1543 rcu_assign_pointer(nl_table[unit].listeners, listeners);
1545 nl_table[unit].cb_mutex = cb_mutex; 1544 nl_table[unit].cb_mutex = cb_mutex;
1546 nl_table[unit].module = module; 1545 nl_table[unit].module = module;
1547 nl_table[unit].registered = 1; 1546 nl_table[unit].registered = 1;
@@ -1572,43 +1571,28 @@ netlink_kernel_release(struct sock *sk)
1572EXPORT_SYMBOL(netlink_kernel_release); 1571EXPORT_SYMBOL(netlink_kernel_release);
1573 1572
1574 1573
1575static void netlink_free_old_listeners(struct rcu_head *rcu_head) 1574static void listeners_free_rcu(struct rcu_head *head)
1576{ 1575{
1577 struct listeners_rcu_head *lrh; 1576 kfree(container_of(head, struct listeners, rcu));
1578
1579 lrh = container_of(rcu_head, struct listeners_rcu_head, rcu_head);
1580 kfree(lrh->ptr);
1581} 1577}
1582 1578
1583int __netlink_change_ngroups(struct sock *sk, unsigned int groups) 1579int __netlink_change_ngroups(struct sock *sk, unsigned int groups)
1584{ 1580{
1585 unsigned long *listeners, *old = NULL; 1581 struct listeners *new, *old;
1586 struct listeners_rcu_head *old_rcu_head;
1587 struct netlink_table *tbl = &nl_table[sk->sk_protocol]; 1582 struct netlink_table *tbl = &nl_table[sk->sk_protocol];
1588 1583
1589 if (groups < 32) 1584 if (groups < 32)
1590 groups = 32; 1585 groups = 32;
1591 1586
1592 if (NLGRPSZ(tbl->groups) < NLGRPSZ(groups)) { 1587 if (NLGRPSZ(tbl->groups) < NLGRPSZ(groups)) {
1593 listeners = kzalloc(NLGRPSZ(groups) + 1588 new = kzalloc(sizeof(*new) + NLGRPSZ(groups), GFP_ATOMIC);
1594 sizeof(struct listeners_rcu_head), 1589 if (!new)
1595 GFP_ATOMIC);
1596 if (!listeners)
1597 return -ENOMEM; 1590 return -ENOMEM;
1598 old = tbl->listeners; 1591 old = rcu_dereference_raw(tbl->listeners);
1599 memcpy(listeners, old, NLGRPSZ(tbl->groups)); 1592 memcpy(new->masks, old->masks, NLGRPSZ(tbl->groups));
1600 rcu_assign_pointer(tbl->listeners, listeners); 1593 rcu_assign_pointer(tbl->listeners, new);
1601 /* 1594
1602 * Free the old memory after an RCU grace period so we 1595 call_rcu(&old->rcu, listeners_free_rcu);
1603 * don't leak it. We use call_rcu() here in order to be
1604 * able to call this function from atomic contexts. The
1605 * allocation of this memory will have reserved enough
1606 * space for struct listeners_rcu_head at the end.
1607 */
1608 old_rcu_head = (void *)(tbl->listeners +
1609 NLGRPLONGS(tbl->groups));
1610 old_rcu_head->ptr = old;
1611 call_rcu(&old_rcu_head->rcu_head, netlink_free_old_listeners);
1612 } 1596 }
1613 tbl->groups = groups; 1597 tbl->groups = groups;
1614 1598
@@ -2104,18 +2088,17 @@ static void __net_exit netlink_net_exit(struct net *net)
2104 2088
2105static void __init netlink_add_usersock_entry(void) 2089static void __init netlink_add_usersock_entry(void)
2106{ 2090{
2107 unsigned long *listeners; 2091 struct listeners *listeners;
2108 int groups = 32; 2092 int groups = 32;
2109 2093
2110 listeners = kzalloc(NLGRPSZ(groups) + sizeof(struct listeners_rcu_head), 2094 listeners = kzalloc(sizeof(*listeners) + NLGRPSZ(groups), GFP_KERNEL);
2111 GFP_KERNEL);
2112 if (!listeners) 2095 if (!listeners)
2113 panic("netlink_add_usersock_entry: Cannot allocate listneres\n"); 2096 panic("netlink_add_usersock_entry: Cannot allocate listeners\n");
2114 2097
2115 netlink_table_grab(); 2098 netlink_table_grab();
2116 2099
2117 nl_table[NETLINK_USERSOCK].groups = groups; 2100 nl_table[NETLINK_USERSOCK].groups = groups;
2118 nl_table[NETLINK_USERSOCK].listeners = listeners; 2101 rcu_assign_pointer(nl_table[NETLINK_USERSOCK].listeners, listeners);
2119 nl_table[NETLINK_USERSOCK].module = THIS_MODULE; 2102 nl_table[NETLINK_USERSOCK].module = THIS_MODULE;
2120 nl_table[NETLINK_USERSOCK].registered = 1; 2103 nl_table[NETLINK_USERSOCK].registered = 1;
2121 2104
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index d14bbf960c18..4b9f8912526c 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -1167,7 +1167,7 @@ static int ignore_request(struct wiphy *wiphy,
1167 return 0; 1167 return 0;
1168 return -EALREADY; 1168 return -EALREADY;
1169 } 1169 }
1170 return REG_INTERSECT; 1170 return 0;
1171 case NL80211_REGDOM_SET_BY_DRIVER: 1171 case NL80211_REGDOM_SET_BY_DRIVER:
1172 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) { 1172 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) {
1173 if (regdom_changes(pending_request->alpha2)) 1173 if (regdom_changes(pending_request->alpha2))
diff --git a/sound/oss/sb_ess.c b/sound/oss/sb_ess.c
index 51a3d381a59e..9890cf2066ff 100644
--- a/sound/oss/sb_ess.c
+++ b/sound/oss/sb_ess.c
@@ -1722,7 +1722,6 @@ printk (KERN_INFO "FKS: es_rec_set_recmask mask = %x\n", mask);
1722 right = (value & 0x0000ff00) >> 8; 1722 right = (value & 0x0000ff00) >> 8;
1723 } else { /* Turn it off (3) */ 1723 } else { /* Turn it off (3) */
1724 left = 0; 1724 left = 0;
1725 left = 0;
1726 right = 0; 1725 right = 0;
1727 } 1726 }
1728 sb_common_mixer_set(devc, i + ES_REC_MIXER_RECDIFF, left, right); 1727 sb_common_mixer_set(devc, i + ES_REC_MIXER_RECDIFF, left, right);
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 82ebeb9544fe..93fa59cc60ef 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -5326,6 +5326,82 @@ again:
5326 return 0; 5326 return 0;
5327} 5327}
5328 5328
5329static int stac92hd83xxx_set_system_btl_amp(struct hda_codec *codec)
5330{
5331 if (codec->vendor_id != 0x111d7605 &&
5332 codec->vendor_id != 0x111d76d1)
5333 return 0;
5334
5335 switch (codec->subsystem_id) {
5336 case 0x103c1618:
5337 case 0x103c1619:
5338 case 0x103c161a:
5339 case 0x103c161b:
5340 case 0x103c161c:
5341 case 0x103c161d:
5342 case 0x103c161e:
5343 case 0x103c161f:
5344 case 0x103c1620:
5345 case 0x103c1621:
5346 case 0x103c1622:
5347 case 0x103c1623:
5348
5349 case 0x103c162a:
5350 case 0x103c162b:
5351
5352 case 0x103c1630:
5353 case 0x103c1631:
5354
5355 case 0x103c1633:
5356
5357 case 0x103c1635:
5358
5359 case 0x103c164f:
5360
5361 case 0x103c1676:
5362 case 0x103c1677:
5363 case 0x103c1678:
5364 case 0x103c1679:
5365 case 0x103c167a:
5366 case 0x103c167b:
5367 case 0x103c167c:
5368 case 0x103c167d:
5369 case 0x103c167e:
5370 case 0x103c167f:
5371 case 0x103c1680:
5372 case 0x103c1681:
5373 case 0x103c1682:
5374 case 0x103c1683:
5375 case 0x103c1684:
5376 case 0x103c1685:
5377 case 0x103c1686:
5378 case 0x103c1687:
5379 case 0x103c1688:
5380 case 0x103c1689:
5381 case 0x103c168a:
5382 case 0x103c168b:
5383 case 0x103c168c:
5384 case 0x103c168d:
5385 case 0x103c168e:
5386 case 0x103c168f:
5387 case 0x103c1690:
5388 case 0x103c1691:
5389 case 0x103c1692:
5390
5391 case 0x103c3587:
5392 case 0x103c3588:
5393 case 0x103c3589:
5394 case 0x103c358a:
5395
5396 case 0x103c3667:
5397 case 0x103c3668:
5398 /* set BTL amp level to 13.43dB for louder speaker output */
5399 return snd_hda_codec_write_cache(codec, codec->afg, 0,
5400 0x7F4, 0x14);
5401 }
5402 return 0;
5403}
5404
5329static int patch_stac92hd83xxx(struct hda_codec *codec) 5405static int patch_stac92hd83xxx(struct hda_codec *codec)
5330{ 5406{
5331 struct sigmatel_spec *spec; 5407 struct sigmatel_spec *spec;
@@ -5452,6 +5528,8 @@ again:
5452 AC_VERB_SET_CONNECT_SEL, num_dacs); 5528 AC_VERB_SET_CONNECT_SEL, num_dacs);
5453 } 5529 }
5454 5530
5531 stac92hd83xxx_set_system_btl_amp(codec);
5532
5455 codec->proc_widget_hook = stac92hd_proc_hook; 5533 codec->proc_widget_hook = stac92hd_proc_hook;
5456 5534
5457 return 0; 5535 return 0;
diff --git a/sound/soc/codecs/ad73311.c b/sound/soc/codecs/ad73311.c
index c53955fe17b6..de799cd1ba72 100644
--- a/sound/soc/codecs/ad73311.c
+++ b/sound/soc/codecs/ad73311.c
@@ -47,7 +47,7 @@ static int ad73311_probe(struct platform_device *pdev)
47 &soc_codec_dev_ad73311, &ad73311_dai, 1); 47 &soc_codec_dev_ad73311, &ad73311_dai, 1);
48} 48}
49 49
50static int ad73311_remove(struct platform_device *pdev) 50static int __devexit ad73311_remove(struct platform_device *pdev)
51{ 51{
52 snd_soc_unregister_codec(&pdev->dev); 52 snd_soc_unregister_codec(&pdev->dev);
53 return 0; 53 return 0;
diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index e7a40d16df90..bc22ee93a75d 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -2051,7 +2051,7 @@ static int max98088_i2c_probe(struct i2c_client *i2c,
2051 return ret; 2051 return ret;
2052} 2052}
2053 2053
2054static int max98088_i2c_remove(struct i2c_client *client) 2054static int __devexit max98088_i2c_remove(struct i2c_client *client)
2055{ 2055{
2056 snd_soc_unregister_codec(&client->dev); 2056 snd_soc_unregister_codec(&client->dev);
2057 kfree(i2c_get_clientdata(client)); 2057 kfree(i2c_get_clientdata(client));
diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c
index 7a1825418ee4..99c046ba46bb 100644
--- a/sound/soc/codecs/wm9090.c
+++ b/sound/soc/codecs/wm9090.c
@@ -665,7 +665,7 @@ static int wm9090_i2c_probe(struct i2c_client *i2c,
665 return ret; 665 return ret;
666} 666}
667 667
668static int wm9090_i2c_remove(struct i2c_client *i2c) 668static int __devexit wm9090_i2c_remove(struct i2c_client *i2c)
669{ 669{
670 struct wm9090_priv *wm9090 = i2c_get_clientdata(i2c); 670 struct wm9090_priv *wm9090 = i2c_get_clientdata(i2c);
671 671
diff --git a/sound/soc/fsl/pcm030-audio-fabric.c b/sound/soc/fsl/pcm030-audio-fabric.c
index fe15bb26e484..25f27ec1dd6e 100644
--- a/sound/soc/fsl/pcm030-audio-fabric.c
+++ b/sound/soc/fsl/pcm030-audio-fabric.c
@@ -24,7 +24,6 @@
24#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
25#include <sound/initval.h> 25#include <sound/initval.h>
26#include <sound/soc.h> 26#include <sound/soc.h>
27#include <sound/soc-of-simple.h>
28 27
29#include "mpc5200_dma.h" 28#include "mpc5200_dma.h"
30#include "mpc5200_psc_ac97.h" 29#include "mpc5200_psc_ac97.h"
@@ -49,7 +48,7 @@ static struct snd_soc_dai_link pcm030_fabric_dai[] = {
49 .codec_dai_name = "wm9712-aux", 48 .codec_dai_name = "wm9712-aux",
50 .cpu_dai_name = "mpc5200-psc-ac97.1", 49 .cpu_dai_name = "mpc5200-psc-ac97.1",
51 .platform_name = "mpc5200-pcm-audio", 50 .platform_name = "mpc5200-pcm-audio",
52 ..codec_name = "wm9712-codec", 51 .codec_name = "wm9712-codec",
53}, 52},
54}; 53};
55 54
diff --git a/sound/usb/card.h b/sound/usb/card.h
index 1febf2f23754..ae4251d5abf7 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -62,12 +62,14 @@ struct snd_usb_substream {
62 unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ 62 unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */
63 unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */ 63 unsigned int freqn; /* nominal sampling rate in fs/fps in Q16.16 format */
64 unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */ 64 unsigned int freqm; /* momentary sampling rate in fs/fps in Q16.16 format */
65 int freqshift; /* how much to shift the feedback value to get Q16.16 */
65 unsigned int freqmax; /* maximum sampling rate, used for buffer management */ 66 unsigned int freqmax; /* maximum sampling rate, used for buffer management */
66 unsigned int phase; /* phase accumulator */ 67 unsigned int phase; /* phase accumulator */
67 unsigned int maxpacksize; /* max packet size in bytes */ 68 unsigned int maxpacksize; /* max packet size in bytes */
68 unsigned int maxframesize; /* max packet size in frames */ 69 unsigned int maxframesize; /* max packet size in frames */
69 unsigned int curpacksize; /* current packet size in bytes (for capture) */ 70 unsigned int curpacksize; /* current packet size in bytes (for capture) */
70 unsigned int curframesize; /* current packet size in frames (for capture) */ 71 unsigned int curframesize; /* current packet size in frames (for capture) */
72 unsigned int syncmaxsize; /* sync endpoint packet size */
71 unsigned int fill_max: 1; /* fill max packet size always */ 73 unsigned int fill_max: 1; /* fill max packet size always */
72 unsigned int txfr_quirk:1; /* allow sub-frame alignment */ 74 unsigned int txfr_quirk:1; /* allow sub-frame alignment */
73 unsigned int fmt_type; /* USB audio format type (1-3) */ 75 unsigned int fmt_type; /* USB audio format type (1-3) */
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index f49756c1b837..cff3a3c465d7 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -237,6 +237,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
237 subs->datainterval = fmt->datainterval; 237 subs->datainterval = fmt->datainterval;
238 subs->syncpipe = subs->syncinterval = 0; 238 subs->syncpipe = subs->syncinterval = 0;
239 subs->maxpacksize = fmt->maxpacksize; 239 subs->maxpacksize = fmt->maxpacksize;
240 subs->syncmaxsize = 0;
240 subs->fill_max = 0; 241 subs->fill_max = 0;
241 242
242 /* we need a sync pipe in async OUT or adaptive IN mode */ 243 /* we need a sync pipe in async OUT or adaptive IN mode */
@@ -283,6 +284,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
283 subs->syncinterval = get_endpoint(alts, 1)->bInterval - 1; 284 subs->syncinterval = get_endpoint(alts, 1)->bInterval - 1;
284 else 285 else
285 subs->syncinterval = 3; 286 subs->syncinterval = 3;
287 subs->syncmaxsize = le16_to_cpu(get_endpoint(alts, 1)->wMaxPacketSize);
286 } 288 }
287 289
288 /* always fill max packet size */ 290 /* always fill max packet size */
diff --git a/sound/usb/proc.c b/sound/usb/proc.c
index 3c650ab3c91d..961c9a250686 100644
--- a/sound/usb/proc.c
+++ b/sound/usb/proc.c
@@ -132,6 +132,11 @@ static void proc_dump_substream_status(struct snd_usb_substream *subs, struct sn
132 ? get_full_speed_hz(subs->freqm) 132 ? get_full_speed_hz(subs->freqm)
133 : get_high_speed_hz(subs->freqm), 133 : get_high_speed_hz(subs->freqm),
134 subs->freqm >> 16, subs->freqm & 0xffff); 134 subs->freqm >> 16, subs->freqm & 0xffff);
135 if (subs->freqshift != INT_MIN)
136 snd_iprintf(buffer, " Feedback Format = %d.%d\n",
137 (subs->syncmaxsize > 3 ? 32 : 24)
138 - (16 - subs->freqshift),
139 16 - subs->freqshift);
135 } else { 140 } else {
136 snd_iprintf(buffer, " Status: Stop\n"); 141 snd_iprintf(buffer, " Status: Stop\n");
137 } 142 }
diff --git a/sound/usb/urb.c b/sound/usb/urb.c
index 8deeaad10f10..e184349aee83 100644
--- a/sound/usb/urb.c
+++ b/sound/usb/urb.c
@@ -225,6 +225,7 @@ int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
225 else 225 else
226 subs->freqn = get_usb_high_speed_rate(rate); 226 subs->freqn = get_usb_high_speed_rate(rate);
227 subs->freqm = subs->freqn; 227 subs->freqm = subs->freqn;
228 subs->freqshift = INT_MIN;
228 /* calculate max. frequency */ 229 /* calculate max. frequency */
229 if (subs->maxpacksize) { 230 if (subs->maxpacksize) {
230 /* whatever fits into a max. size packet */ 231 /* whatever fits into a max. size packet */
@@ -513,11 +514,10 @@ static int retire_paused_capture_urb(struct snd_usb_substream *subs,
513 514
514 515
515/* 516/*
516 * prepare urb for full speed playback sync pipe 517 * prepare urb for playback sync pipe
517 * 518 *
518 * set up the offset and length to receive the current frequency. 519 * set up the offset and length to receive the current frequency.
519 */ 520 */
520
521static int prepare_playback_sync_urb(struct snd_usb_substream *subs, 521static int prepare_playback_sync_urb(struct snd_usb_substream *subs,
522 struct snd_pcm_runtime *runtime, 522 struct snd_pcm_runtime *runtime,
523 struct urb *urb) 523 struct urb *urb)
@@ -525,103 +525,78 @@ static int prepare_playback_sync_urb(struct snd_usb_substream *subs,
525 struct snd_urb_ctx *ctx = urb->context; 525 struct snd_urb_ctx *ctx = urb->context;
526 526
527 urb->dev = ctx->subs->dev; /* we need to set this at each time */ 527 urb->dev = ctx->subs->dev; /* we need to set this at each time */
528 urb->iso_frame_desc[0].length = 3; 528 urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize);
529 urb->iso_frame_desc[0].offset = 0; 529 urb->iso_frame_desc[0].offset = 0;
530 return 0; 530 return 0;
531} 531}
532 532
533/* 533/*
534 * prepare urb for high speed playback sync pipe 534 * process after playback sync complete
535 * 535 *
536 * set up the offset and length to receive the current frequency. 536 * Full speed devices report feedback values in 10.14 format as samples per
537 */ 537 * frame, high speed devices in 16.16 format as samples per microframe.
538 538 * Because the Audio Class 1 spec was written before USB 2.0, many high speed
539static int prepare_playback_sync_urb_hs(struct snd_usb_substream *subs, 539 * devices use a wrong interpretation, some others use an entirely different
540 struct snd_pcm_runtime *runtime, 540 * format. Therefore, we cannot predict what format any particular device uses
541 struct urb *urb) 541 * and must detect it automatically.
542{
543 struct snd_urb_ctx *ctx = urb->context;
544
545 urb->dev = ctx->subs->dev; /* we need to set this at each time */
546 urb->iso_frame_desc[0].length = 4;
547 urb->iso_frame_desc[0].offset = 0;
548 return 0;
549}
550
551/*
552 * process after full speed playback sync complete
553 *
554 * retrieve the current 10.14 frequency from pipe, and set it.
555 * the value is referred in prepare_playback_urb().
556 */ 542 */
557static int retire_playback_sync_urb(struct snd_usb_substream *subs, 543static int retire_playback_sync_urb(struct snd_usb_substream *subs,
558 struct snd_pcm_runtime *runtime, 544 struct snd_pcm_runtime *runtime,
559 struct urb *urb) 545 struct urb *urb)
560{ 546{
561 unsigned int f; 547 unsigned int f;
548 int shift;
562 unsigned long flags; 549 unsigned long flags;
563 550
564 if (urb->iso_frame_desc[0].status == 0 && 551 if (urb->iso_frame_desc[0].status != 0 ||
565 urb->iso_frame_desc[0].actual_length == 3) { 552 urb->iso_frame_desc[0].actual_length < 3)
566 f = combine_triple((u8*)urb->transfer_buffer) << 2; 553 return 0;
567 if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) {
568 spin_lock_irqsave(&subs->lock, flags);
569 subs->freqm = f;
570 spin_unlock_irqrestore(&subs->lock, flags);
571 }
572 }
573
574 return 0;
575}
576 554
577/* 555 f = le32_to_cpup(urb->transfer_buffer);
578 * process after high speed playback sync complete 556 if (urb->iso_frame_desc[0].actual_length == 3)
579 * 557 f &= 0x00ffffff;
580 * retrieve the current 12.13 frequency from pipe, and set it. 558 else
581 * the value is referred in prepare_playback_urb(). 559 f &= 0x0fffffff;
582 */ 560 if (f == 0)
583static int retire_playback_sync_urb_hs(struct snd_usb_substream *subs, 561 return 0;
584 struct snd_pcm_runtime *runtime,
585 struct urb *urb)
586{
587 unsigned int f;
588 unsigned long flags;
589 562
590 if (urb->iso_frame_desc[0].status == 0 && 563 if (unlikely(subs->freqshift == INT_MIN)) {
591 urb->iso_frame_desc[0].actual_length == 4) { 564 /*
592 f = combine_quad((u8*)urb->transfer_buffer) & 0x0fffffff; 565 * The first time we see a feedback value, determine its format
593 if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) { 566 * by shifting it left or right until it matches the nominal
594 spin_lock_irqsave(&subs->lock, flags); 567 * frequency value. This assumes that the feedback does not
595 subs->freqm = f; 568 * differ from the nominal value more than +50% or -25%.
596 spin_unlock_irqrestore(&subs->lock, flags); 569 */
570 shift = 0;
571 while (f < subs->freqn - subs->freqn / 4) {
572 f <<= 1;
573 shift++;
574 }
575 while (f > subs->freqn + subs->freqn / 2) {
576 f >>= 1;
577 shift--;
597 } 578 }
579 subs->freqshift = shift;
598 } 580 }
581 else if (subs->freqshift >= 0)
582 f <<= subs->freqshift;
583 else
584 f >>= -subs->freqshift;
599 585
600 return 0; 586 if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) {
601} 587 /*
602 588 * If the frequency looks valid, set it.
603/* 589 * This value is referred to in prepare_playback_urb().
604 * process after E-Mu 0202/0404/Tracker Pre high speed playback sync complete 590 */
605 * 591 spin_lock_irqsave(&subs->lock, flags);
606 * These devices return the number of samples per packet instead of the number 592 subs->freqm = f;
607 * of samples per microframe. 593 spin_unlock_irqrestore(&subs->lock, flags);
608 */ 594 } else {
609static int retire_playback_sync_urb_hs_emu(struct snd_usb_substream *subs, 595 /*
610 struct snd_pcm_runtime *runtime, 596 * Out of range; maybe the shift value is wrong.
611 struct urb *urb) 597 * Reset it so that we autodetect again the next time.
612{ 598 */
613 unsigned int f; 599 subs->freqshift = INT_MIN;
614 unsigned long flags;
615
616 if (urb->iso_frame_desc[0].status == 0 &&
617 urb->iso_frame_desc[0].actual_length == 4) {
618 f = combine_quad((u8*)urb->transfer_buffer) & 0x0fffffff;
619 f >>= subs->datainterval;
620 if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) {
621 spin_lock_irqsave(&subs->lock, flags);
622 subs->freqm = f;
623 spin_unlock_irqrestore(&subs->lock, flags);
624 }
625 } 600 }
626 601
627 return 0; 602 return 0;
@@ -878,21 +853,6 @@ static struct snd_urb_ops audio_urb_ops[2] = {
878 }, 853 },
879}; 854};
880 855
881static struct snd_urb_ops audio_urb_ops_high_speed[2] = {
882 {
883 .prepare = prepare_nodata_playback_urb,
884 .retire = retire_playback_urb,
885 .prepare_sync = prepare_playback_sync_urb_hs,
886 .retire_sync = retire_playback_sync_urb_hs,
887 },
888 {
889 .prepare = prepare_capture_urb,
890 .retire = retire_capture_urb,
891 .prepare_sync = prepare_capture_sync_urb_hs,
892 .retire_sync = retire_capture_sync_urb,
893 },
894};
895
896/* 856/*
897 * initialize the substream instance. 857 * initialize the substream instance.
898 */ 858 */
@@ -909,23 +869,9 @@ void snd_usb_init_substream(struct snd_usb_stream *as,
909 subs->direction = stream; 869 subs->direction = stream;
910 subs->dev = as->chip->dev; 870 subs->dev = as->chip->dev;
911 subs->txfr_quirk = as->chip->txfr_quirk; 871 subs->txfr_quirk = as->chip->txfr_quirk;
912 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) { 872 subs->ops = audio_urb_ops[stream];
913 subs->ops = audio_urb_ops[stream]; 873 if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH)
914 } else { 874 subs->ops.prepare_sync = prepare_capture_sync_urb_hs;
915 subs->ops = audio_urb_ops_high_speed[stream];
916 switch (as->chip->usb_id) {
917 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
918 case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
919 case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
920 subs->ops.retire_sync = retire_playback_sync_urb_hs_emu;
921 break;
922 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra 8 */
923 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
924 subs->ops.prepare_sync = prepare_playback_sync_urb;
925 subs->ops.retire_sync = retire_playback_sync_urb;
926 break;
927 }
928 }
929 875
930 snd_usb_set_pcm_ops(as->pcm, stream); 876 snd_usb_set_pcm_ops(as->pcm, stream);
931 877
diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
index 43e3dd284b90..399751befeed 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -15,6 +15,23 @@ DESCRIPTION
15This command displays the symbolic event types which can be selected in the 15This command displays the symbolic event types which can be selected in the
16various perf commands with the -e option. 16various perf commands with the -e option.
17 17
18EVENT MODIFIERS
19---------------
20
21Events can optionally have a modifer by appending a colon and one or
22more modifiers. Modifiers allow the user to restrict when events are
23counted with 'u' for user-space, 'k' for kernel, 'h' for hypervisor.
24
25The 'p' modifier can be used for specifying how precise the instruction
26address should be. The 'p' modifier is currently only implemented for
27Intel PEBS and can be specified multiple times:
28 0 - SAMPLE_IP can have arbitrary skid
29 1 - SAMPLE_IP must have constant skid
30 2 - SAMPLE_IP requested to have 0 skid
31 3 - SAMPLE_IP must have 0 skid
32
33The PEBS implementation now supports up to 2.
34
18RAW HARDWARE EVENT DESCRIPTOR 35RAW HARDWARE EVENT DESCRIPTOR
19----------------------------- 36-----------------------------
20Even when an event is not available in a symbolic form within perf right now, 37Even when an event is not available in a symbolic form within perf right now,
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 27d52dae5a43..62de1b7f4e76 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -16,7 +16,9 @@ or
16or 16or
17'perf probe' --list 17'perf probe' --list
18or 18or
19'perf probe' --line='FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]' 19'perf probe' [options] --line='FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]'
20or
21'perf probe' [options] --vars='PROBEPOINT'
20 22
21DESCRIPTION 23DESCRIPTION
22----------- 24-----------
@@ -31,6 +33,11 @@ OPTIONS
31--vmlinux=PATH:: 33--vmlinux=PATH::
32 Specify vmlinux path which has debuginfo (Dwarf binary). 34 Specify vmlinux path which has debuginfo (Dwarf binary).
33 35
36-m::
37--module=MODNAME::
38 Specify module name in which perf-probe searches probe points
39 or lines.
40
34-s:: 41-s::
35--source=PATH:: 42--source=PATH::
36 Specify path to kernel source. 43 Specify path to kernel source.
@@ -57,6 +64,15 @@ OPTIONS
57 Show source code lines which can be probed. This needs an argument 64 Show source code lines which can be probed. This needs an argument
58 which specifies a range of the source code. (see LINE SYNTAX for detail) 65 which specifies a range of the source code. (see LINE SYNTAX for detail)
59 66
67-V::
68--vars=::
69 Show available local variables at given probe point. The argument
70 syntax is same as PROBE SYNTAX, but NO ARGs.
71
72--externs::
73 (Only for --vars) Show external defined variables in addition to local
74 variables.
75
60-f:: 76-f::
61--force:: 77--force::
62 Forcibly add events with existing name. 78 Forcibly add events with existing name.
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 3ee27dccfde9..a91f9f9e6e5c 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -83,6 +83,10 @@ OPTIONS
83--call-graph:: 83--call-graph::
84 Do call-graph (stack chain/backtrace) recording. 84 Do call-graph (stack chain/backtrace) recording.
85 85
86-q::
87--quiet::
88 Don't print any message, useful for scripting.
89
86-v:: 90-v::
87--verbose:: 91--verbose::
88 Be more verbose (show counter open errors, etc). 92 Be more verbose (show counter open errors, etc).
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 199d5e19554f..2e000c068cc5 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -50,14 +50,17 @@ static struct {
50 bool list_events; 50 bool list_events;
51 bool force_add; 51 bool force_add;
52 bool show_lines; 52 bool show_lines;
53 bool show_vars;
54 bool show_ext_vars;
55 bool mod_events;
53 int nevents; 56 int nevents;
54 struct perf_probe_event events[MAX_PROBES]; 57 struct perf_probe_event events[MAX_PROBES];
55 struct strlist *dellist; 58 struct strlist *dellist;
56 struct line_range line_range; 59 struct line_range line_range;
60 const char *target_module;
57 int max_probe_points; 61 int max_probe_points;
58} params; 62} params;
59 63
60
61/* Parse an event definition. Note that any error must die. */ 64/* Parse an event definition. Note that any error must die. */
62static int parse_probe_event(const char *str) 65static int parse_probe_event(const char *str)
63{ 66{
@@ -92,6 +95,7 @@ static int parse_probe_event_argv(int argc, const char **argv)
92 len = 0; 95 len = 0;
93 for (i = 0; i < argc; i++) 96 for (i = 0; i < argc; i++)
94 len += sprintf(&buf[len], "%s ", argv[i]); 97 len += sprintf(&buf[len], "%s ", argv[i]);
98 params.mod_events = true;
95 ret = parse_probe_event(buf); 99 ret = parse_probe_event(buf);
96 free(buf); 100 free(buf);
97 return ret; 101 return ret;
@@ -100,9 +104,10 @@ static int parse_probe_event_argv(int argc, const char **argv)
100static int opt_add_probe_event(const struct option *opt __used, 104static int opt_add_probe_event(const struct option *opt __used,
101 const char *str, int unset __used) 105 const char *str, int unset __used)
102{ 106{
103 if (str) 107 if (str) {
108 params.mod_events = true;
104 return parse_probe_event(str); 109 return parse_probe_event(str);
105 else 110 } else
106 return 0; 111 return 0;
107} 112}
108 113
@@ -110,6 +115,7 @@ static int opt_del_probe_event(const struct option *opt __used,
110 const char *str, int unset __used) 115 const char *str, int unset __used)
111{ 116{
112 if (str) { 117 if (str) {
118 params.mod_events = true;
113 if (!params.dellist) 119 if (!params.dellist)
114 params.dellist = strlist__new(true, NULL); 120 params.dellist = strlist__new(true, NULL);
115 strlist__add(params.dellist, str); 121 strlist__add(params.dellist, str);
@@ -130,6 +136,25 @@ static int opt_show_lines(const struct option *opt __used,
130 136
131 return ret; 137 return ret;
132} 138}
139
140static int opt_show_vars(const struct option *opt __used,
141 const char *str, int unset __used)
142{
143 struct perf_probe_event *pev = &params.events[params.nevents];
144 int ret;
145
146 if (!str)
147 return 0;
148
149 ret = parse_probe_event(str);
150 if (!ret && pev->nargs != 0) {
151 pr_err(" Error: '--vars' doesn't accept arguments.\n");
152 return -EINVAL;
153 }
154 params.show_vars = true;
155
156 return ret;
157}
133#endif 158#endif
134 159
135static const char * const probe_usage[] = { 160static const char * const probe_usage[] = {
@@ -138,7 +163,8 @@ static const char * const probe_usage[] = {
138 "perf probe [<options>] --del '[GROUP:]EVENT' ...", 163 "perf probe [<options>] --del '[GROUP:]EVENT' ...",
139 "perf probe --list", 164 "perf probe --list",
140#ifdef DWARF_SUPPORT 165#ifdef DWARF_SUPPORT
141 "perf probe --line 'LINEDESC'", 166 "perf probe [<options>] --line 'LINEDESC'",
167 "perf probe [<options>] --vars 'PROBEPOINT'",
142#endif 168#endif
143 NULL 169 NULL
144}; 170};
@@ -180,10 +206,17 @@ static const struct option options[] = {
180 OPT_CALLBACK('L', "line", NULL, 206 OPT_CALLBACK('L', "line", NULL,
181 "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]", 207 "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]",
182 "Show source code lines.", opt_show_lines), 208 "Show source code lines.", opt_show_lines),
209 OPT_CALLBACK('V', "vars", NULL,
210 "FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT",
211 "Show accessible variables on PROBEDEF", opt_show_vars),
212 OPT_BOOLEAN('\0', "externs", &params.show_ext_vars,
213 "Show external variables too (with --vars only)"),
183 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, 214 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
184 "file", "vmlinux pathname"), 215 "file", "vmlinux pathname"),
185 OPT_STRING('s', "source", &symbol_conf.source_prefix, 216 OPT_STRING('s', "source", &symbol_conf.source_prefix,
186 "directory", "path to kernel source"), 217 "directory", "path to kernel source"),
218 OPT_STRING('m', "module", &params.target_module,
219 "modname", "target module name"),
187#endif 220#endif
188 OPT__DRY_RUN(&probe_event_dry_run), 221 OPT__DRY_RUN(&probe_event_dry_run),
189 OPT_INTEGER('\0', "max-probes", &params.max_probe_points, 222 OPT_INTEGER('\0', "max-probes", &params.max_probe_points,
@@ -217,7 +250,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
217 usage_with_options(probe_usage, options); 250 usage_with_options(probe_usage, options);
218 251
219 if (params.list_events) { 252 if (params.list_events) {
220 if (params.nevents != 0 || params.dellist) { 253 if (params.mod_events) {
221 pr_err(" Error: Don't use --list with --add/--del.\n"); 254 pr_err(" Error: Don't use --list with --add/--del.\n");
222 usage_with_options(probe_usage, options); 255 usage_with_options(probe_usage, options);
223 } 256 }
@@ -225,6 +258,10 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
225 pr_err(" Error: Don't use --list with --line.\n"); 258 pr_err(" Error: Don't use --list with --line.\n");
226 usage_with_options(probe_usage, options); 259 usage_with_options(probe_usage, options);
227 } 260 }
261 if (params.show_vars) {
262 pr_err(" Error: Don't use --list with --vars.\n");
263 usage_with_options(probe_usage, options);
264 }
228 ret = show_perf_probe_events(); 265 ret = show_perf_probe_events();
229 if (ret < 0) 266 if (ret < 0)
230 pr_err(" Error: Failed to show event list. (%d)\n", 267 pr_err(" Error: Failed to show event list. (%d)\n",
@@ -234,17 +271,35 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
234 271
235#ifdef DWARF_SUPPORT 272#ifdef DWARF_SUPPORT
236 if (params.show_lines) { 273 if (params.show_lines) {
237 if (params.nevents != 0 || params.dellist) { 274 if (params.mod_events) {
238 pr_warning(" Error: Don't use --line with" 275 pr_err(" Error: Don't use --line with"
239 " --add/--del.\n"); 276 " --add/--del.\n");
277 usage_with_options(probe_usage, options);
278 }
279 if (params.show_vars) {
280 pr_err(" Error: Don't use --line with --vars.\n");
240 usage_with_options(probe_usage, options); 281 usage_with_options(probe_usage, options);
241 } 282 }
242 283
243 ret = show_line_range(&params.line_range); 284 ret = show_line_range(&params.line_range, params.target_module);
244 if (ret < 0) 285 if (ret < 0)
245 pr_err(" Error: Failed to show lines. (%d)\n", ret); 286 pr_err(" Error: Failed to show lines. (%d)\n", ret);
246 return ret; 287 return ret;
247 } 288 }
289 if (params.show_vars) {
290 if (params.mod_events) {
291 pr_err(" Error: Don't use --vars with"
292 " --add/--del.\n");
293 usage_with_options(probe_usage, options);
294 }
295 ret = show_available_vars(params.events, params.nevents,
296 params.max_probe_points,
297 params.target_module,
298 params.show_ext_vars);
299 if (ret < 0)
300 pr_err(" Error: Failed to show vars. (%d)\n", ret);
301 return ret;
302 }
248#endif 303#endif
249 304
250 if (params.dellist) { 305 if (params.dellist) {
@@ -258,8 +313,9 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
258 313
259 if (params.nevents) { 314 if (params.nevents) {
260 ret = add_perf_probe_events(params.events, params.nevents, 315 ret = add_perf_probe_events(params.events, params.nevents,
261 params.force_add, 316 params.max_probe_points,
262 params.max_probe_points); 317 params.target_module,
318 params.force_add);
263 if (ret < 0) { 319 if (ret < 0) {
264 pr_err(" Error: Failed to add events. (%d)\n", ret); 320 pr_err(" Error: Failed to add events. (%d)\n", ret);
265 return ret; 321 return ret;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index ff77b805de71..4e75583ddd6d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -353,7 +353,7 @@ try_again:
353 } 353 }
354 354
355 if (read(fd[nr_cpu][counter][thread_index], &read_data, sizeof(read_data)) == -1) { 355 if (read(fd[nr_cpu][counter][thread_index], &read_data, sizeof(read_data)) == -1) {
356 perror("Unable to read perf file descriptor\n"); 356 perror("Unable to read perf file descriptor");
357 exit(-1); 357 exit(-1);
358 } 358 }
359 359
@@ -626,7 +626,7 @@ static int __cmd_record(int argc, const char **argv)
626 626
627 nr_cpus = read_cpu_map(cpu_list); 627 nr_cpus = read_cpu_map(cpu_list);
628 if (nr_cpus < 1) { 628 if (nr_cpus < 1) {
629 perror("failed to collect number of CPUs\n"); 629 perror("failed to collect number of CPUs");
630 return -1; 630 return -1;
631 } 631 }
632 632
@@ -761,6 +761,9 @@ static int __cmd_record(int argc, const char **argv)
761 } 761 }
762 } 762 }
763 763
764 if (quiet)
765 return 0;
766
764 fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking); 767 fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking);
765 768
766 /* 769 /*
@@ -820,6 +823,7 @@ static const struct option options[] = {
820 "do call-graph (stack chain/backtrace) recording"), 823 "do call-graph (stack chain/backtrace) recording"),
821 OPT_INCR('v', "verbose", &verbose, 824 OPT_INCR('v', "verbose", &verbose,
822 "be more verbose (show counter open errors, etc)"), 825 "be more verbose (show counter open errors, etc)"),
826 OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"),
823 OPT_BOOLEAN('s', "stat", &inherit_stat, 827 OPT_BOOLEAN('s', "stat", &inherit_stat,
824 "per thread counts"), 828 "per thread counts"),
825 OPT_BOOLEAN('d', "data", &sample_address, 829 OPT_BOOLEAN('d', "data", &sample_address,
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 40a6a2992d15..2f8df45c4dcb 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -46,9 +46,6 @@ static struct scripting_ops *scripting_ops;
46 46
47static void setup_scripting(void) 47static void setup_scripting(void)
48{ 48{
49 /* make sure PERF_EXEC_PATH is set for scripts */
50 perf_set_argv_exec_path(perf_exec_path());
51
52 setup_perl_scripting(); 49 setup_perl_scripting();
53 setup_python_scripting(); 50 setup_python_scripting();
54 51
@@ -285,7 +282,7 @@ static int parse_scriptname(const struct option *opt __used,
285 script++; 282 script++;
286 } else { 283 } else {
287 script = str; 284 script = str;
288 ext = strchr(script, '.'); 285 ext = strrchr(script, '.');
289 if (!ext) { 286 if (!ext) {
290 fprintf(stderr, "invalid script extension"); 287 fprintf(stderr, "invalid script extension");
291 return -1; 288 return -1;
@@ -593,6 +590,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
593 suffix = REPORT_SUFFIX; 590 suffix = REPORT_SUFFIX;
594 } 591 }
595 592
593 /* make sure PERF_EXEC_PATH is set for scripts */
594 perf_set_argv_exec_path(perf_exec_path());
595
596 if (!suffix && argc >= 2 && strncmp(argv[1], "-", strlen("-")) != 0) { 596 if (!suffix && argc >= 2 && strncmp(argv[1], "-", strlen("-")) != 0) {
597 char *record_script_path, *report_script_path; 597 char *record_script_path, *report_script_path;
598 int live_pipe[2]; 598 int live_pipe[2];
@@ -625,12 +625,13 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
625 dup2(live_pipe[1], 1); 625 dup2(live_pipe[1], 1);
626 close(live_pipe[0]); 626 close(live_pipe[0]);
627 627
628 __argv = malloc(5 * sizeof(const char *)); 628 __argv = malloc(6 * sizeof(const char *));
629 __argv[0] = "/bin/sh"; 629 __argv[0] = "/bin/sh";
630 __argv[1] = record_script_path; 630 __argv[1] = record_script_path;
631 __argv[2] = "-o"; 631 __argv[2] = "-q";
632 __argv[3] = "-"; 632 __argv[3] = "-o";
633 __argv[4] = NULL; 633 __argv[4] = "-";
634 __argv[5] = NULL;
634 635
635 execvp("/bin/sh", (char **)__argv); 636 execvp("/bin/sh", (char **)__argv);
636 exit(-1); 637 exit(-1);
diff --git a/tools/perf/scripts/perl/bin/failed-syscalls-report b/tools/perf/scripts/perl/bin/failed-syscalls-report
index e3a5e55d54ff..4028d92dc4ae 100644
--- a/tools/perf/scripts/perl/bin/failed-syscalls-report
+++ b/tools/perf/scripts/perl/bin/failed-syscalls-report
@@ -7,4 +7,4 @@ if [ $# -gt 0 ] ; then
7 shift 7 shift
8 fi 8 fi
9fi 9fi
10perf trace $@ -s ~/libexec/perf-core/scripts/perl/failed-syscalls.pl $comm 10perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/failed-syscalls.pl $comm
diff --git a/tools/perf/scripts/perl/bin/rw-by-file-report b/tools/perf/scripts/perl/bin/rw-by-file-report
index d83070b7eeb5..ba25f4d41fb0 100644
--- a/tools/perf/scripts/perl/bin/rw-by-file-report
+++ b/tools/perf/scripts/perl/bin/rw-by-file-report
@@ -7,7 +7,7 @@ if [ $# -lt 1 ] ; then
7fi 7fi
8comm=$1 8comm=$1
9shift 9shift
10perf trace $@ -s ~/libexec/perf-core/scripts/perl/rw-by-file.pl $comm 10perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/rw-by-file.pl $comm
11 11
12 12
13 13
diff --git a/tools/perf/scripts/perl/bin/rw-by-pid-report b/tools/perf/scripts/perl/bin/rw-by-pid-report
index 7ef46983f62f..641a3f5d085c 100644
--- a/tools/perf/scripts/perl/bin/rw-by-pid-report
+++ b/tools/perf/scripts/perl/bin/rw-by-pid-report
@@ -1,6 +1,6 @@
1#!/bin/bash 1#!/bin/bash
2# description: system-wide r/w activity 2# description: system-wide r/w activity
3perf trace $@ -s ~/libexec/perf-core/scripts/perl/rw-by-pid.pl 3perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/rw-by-pid.pl
4 4
5 5
6 6
diff --git a/tools/perf/scripts/perl/bin/rwtop-report b/tools/perf/scripts/perl/bin/rwtop-report
index 93e698cd3f38..4918dba77021 100644
--- a/tools/perf/scripts/perl/bin/rwtop-report
+++ b/tools/perf/scripts/perl/bin/rwtop-report
@@ -17,7 +17,7 @@ if [ "$n_args" -gt 0 ] ; then
17 interval=$1 17 interval=$1
18 shift 18 shift
19fi 19fi
20perf trace $@ -s ~/libexec/perf-core/scripts/perl/rwtop.pl $interval 20perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/rwtop.pl $interval
21 21
22 22
23 23
diff --git a/tools/perf/scripts/perl/bin/wakeup-latency-report b/tools/perf/scripts/perl/bin/wakeup-latency-report
index a0d898f9ca1d..49052ebcb632 100644
--- a/tools/perf/scripts/perl/bin/wakeup-latency-report
+++ b/tools/perf/scripts/perl/bin/wakeup-latency-report
@@ -1,6 +1,6 @@
1#!/bin/bash 1#!/bin/bash
2# description: system-wide min/max/avg wakeup latency 2# description: system-wide min/max/avg wakeup latency
3perf trace $@ -s ~/libexec/perf-core/scripts/perl/wakeup-latency.pl 3perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/wakeup-latency.pl
4 4
5 5
6 6
diff --git a/tools/perf/scripts/perl/bin/workqueue-stats-report b/tools/perf/scripts/perl/bin/workqueue-stats-report
index 35081132ef97..df0c65f4ca93 100644
--- a/tools/perf/scripts/perl/bin/workqueue-stats-report
+++ b/tools/perf/scripts/perl/bin/workqueue-stats-report
@@ -1,6 +1,6 @@
1#!/bin/bash 1#!/bin/bash
2# description: workqueue stats (ins/exe/create/destroy) 2# description: workqueue stats (ins/exe/create/destroy)
3perf trace $@ -s ~/libexec/perf-core/scripts/perl/workqueue-stats.pl 3perf trace $@ -s "$PERF_EXEC_PATH"/scripts/perl/workqueue-stats.pl
4 4
5 5
6 6
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
index 9689bc0acd9f..13cc02b5893a 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
+++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
@@ -6,6 +6,14 @@
6# Public License ("GPL") version 2 as published by the Free Software 6# Public License ("GPL") version 2 as published by the Free Software
7# Foundation. 7# Foundation.
8 8
9import errno, os
10
11FUTEX_WAIT = 0
12FUTEX_WAKE = 1
13FUTEX_PRIVATE_FLAG = 128
14FUTEX_CLOCK_REALTIME = 256
15FUTEX_CMD_MASK = ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
16
9NSECS_PER_SEC = 1000000000 17NSECS_PER_SEC = 1000000000
10 18
11def avg(total, n): 19def avg(total, n):
@@ -24,5 +32,55 @@ def nsecs_str(nsecs):
24 str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)), 32 str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
25 return str 33 return str
26 34
35def add_stats(dict, key, value):
36 if not dict.has_key(key):
37 dict[key] = (value, value, value, 1)
38 else:
39 min, max, avg, count = dict[key]
40 if value < min:
41 min = value
42 if value > max:
43 max = value
44 avg = (avg + value) / 2
45 dict[key] = (min, max, avg, count + 1)
46
27def clear_term(): 47def clear_term():
28 print("\x1b[H\x1b[2J") 48 print("\x1b[H\x1b[2J")
49
50audit_package_warned = False
51
52try:
53 import audit
54 machine_to_id = {
55 'x86_64': audit.MACH_86_64,
56 'alpha' : audit.MACH_ALPHA,
57 'ia64' : audit.MACH_IA64,
58 'ppc' : audit.MACH_PPC,
59 'ppc64' : audit.MACH_PPC64,
60 's390' : audit.MACH_S390,
61 's390x' : audit.MACH_S390X,
62 'i386' : audit.MACH_X86,
63 'i586' : audit.MACH_X86,
64 'i686' : audit.MACH_X86,
65 }
66 try:
67 machine_to_id['armeb'] = audit.MACH_ARMEB
68 except:
69 pass
70 machine_id = machine_to_id[os.uname()[4]]
71except:
72 if not audit_package_warned:
73 audit_package_warned = True
74 print "Install the audit-libs-python package to get syscall names"
75
76def syscall_name(id):
77 try:
78 return audit.audit_syscall_to_name(id, machine_id)
79 except:
80 return str(id)
81
82def strerror(nr):
83 try:
84 return errno.errorcode[abs(nr)]
85 except:
86 return "Unknown %d errno" % nr
diff --git a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report
index 30293545fcc2..03587021463d 100644
--- a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report
+++ b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report
@@ -7,4 +7,4 @@ if [ $# -gt 0 ] ; then
7 shift 7 shift
8 fi 8 fi
9fi 9fi
10perf trace $@ -s ~/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py $comm 10perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/failed-syscalls-by-pid.py $comm
diff --git a/tools/perf/scripts/python/bin/futex-contention-record b/tools/perf/scripts/python/bin/futex-contention-record
new file mode 100644
index 000000000000..5ecbb433caf4
--- /dev/null
+++ b/tools/perf/scripts/python/bin/futex-contention-record
@@ -0,0 +1,2 @@
1#!/bin/bash
2perf record -a -e syscalls:sys_enter_futex -e syscalls:sys_exit_futex $@
diff --git a/tools/perf/scripts/python/bin/futex-contention-report b/tools/perf/scripts/python/bin/futex-contention-report
new file mode 100644
index 000000000000..c8268138fb7e
--- /dev/null
+++ b/tools/perf/scripts/python/bin/futex-contention-report
@@ -0,0 +1,4 @@
1#!/bin/bash
2# description: futext contention measurement
3
4perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/futex-contention.py
diff --git a/tools/perf/scripts/python/bin/netdev-times-report b/tools/perf/scripts/python/bin/netdev-times-report
index c3d0a638123d..4ad361b31249 100644
--- a/tools/perf/scripts/python/bin/netdev-times-report
+++ b/tools/perf/scripts/python/bin/netdev-times-report
@@ -2,4 +2,4 @@
2# description: display a process of packet and processing time 2# description: display a process of packet and processing time
3# args: [tx] [rx] [dev=] [debug] 3# args: [tx] [rx] [dev=] [debug]
4 4
5perf trace -s ~/libexec/perf-core/scripts/python/netdev-times.py $@ 5perf trace -s "$PERF_EXEC_PATH"/scripts/python/netdev-times.py $@
diff --git a/tools/perf/scripts/python/bin/sched-migration-report b/tools/perf/scripts/python/bin/sched-migration-report
index 61d05f72e443..df1791f07c24 100644
--- a/tools/perf/scripts/python/bin/sched-migration-report
+++ b/tools/perf/scripts/python/bin/sched-migration-report
@@ -1,3 +1,3 @@
1#!/bin/bash 1#!/bin/bash
2# description: sched migration overview 2# description: sched migration overview
3perf trace $@ -s ~/libexec/perf-core/scripts/python/sched-migration.py 3perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/sched-migration.py
diff --git a/tools/perf/scripts/python/bin/sctop-report b/tools/perf/scripts/python/bin/sctop-report
index b01c842ae7b4..36b409c05e50 100644
--- a/tools/perf/scripts/python/bin/sctop-report
+++ b/tools/perf/scripts/python/bin/sctop-report
@@ -21,4 +21,4 @@ elif [ "$n_args" -gt 0 ] ; then
21 interval=$1 21 interval=$1
22 shift 22 shift
23fi 23fi
24perf trace $@ -s ~/libexec/perf-core/scripts/python/sctop.py $comm $interval 24perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/sctop.py $comm $interval
diff --git a/tools/perf/scripts/python/bin/syscall-counts-by-pid-report b/tools/perf/scripts/python/bin/syscall-counts-by-pid-report
index 9e9d8ddd72ce..4eb88c9fc83c 100644
--- a/tools/perf/scripts/python/bin/syscall-counts-by-pid-report
+++ b/tools/perf/scripts/python/bin/syscall-counts-by-pid-report
@@ -7,4 +7,4 @@ if [ $# -gt 0 ] ; then
7 shift 7 shift
8 fi 8 fi
9fi 9fi
10perf trace $@ -s ~/libexec/perf-core/scripts/python/syscall-counts-by-pid.py $comm 10perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/syscall-counts-by-pid.py $comm
diff --git a/tools/perf/scripts/python/bin/syscall-counts-report b/tools/perf/scripts/python/bin/syscall-counts-report
index dc076b618796..cb2f9c5cf17e 100644
--- a/tools/perf/scripts/python/bin/syscall-counts-report
+++ b/tools/perf/scripts/python/bin/syscall-counts-report
@@ -7,4 +7,4 @@ if [ $# -gt 0 ] ; then
7 shift 7 shift
8 fi 8 fi
9fi 9fi
10perf trace $@ -s ~/libexec/perf-core/scripts/python/syscall-counts.py $comm 10perf trace $@ -s "$PERF_EXEC_PATH"/scripts/python/syscall-counts.py $comm
diff --git a/tools/perf/scripts/python/failed-syscalls-by-pid.py b/tools/perf/scripts/python/failed-syscalls-by-pid.py
index 0ca02278fe69..acd7848717b3 100644
--- a/tools/perf/scripts/python/failed-syscalls-by-pid.py
+++ b/tools/perf/scripts/python/failed-syscalls-by-pid.py
@@ -13,21 +13,26 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \
13 13
14from perf_trace_context import * 14from perf_trace_context import *
15from Core import * 15from Core import *
16from Util import *
16 17
17usage = "perf trace -s syscall-counts-by-pid.py [comm]\n"; 18usage = "perf trace -s syscall-counts-by-pid.py [comm|pid]\n";
18 19
19for_comm = None 20for_comm = None
21for_pid = None
20 22
21if len(sys.argv) > 2: 23if len(sys.argv) > 2:
22 sys.exit(usage) 24 sys.exit(usage)
23 25
24if len(sys.argv) > 1: 26if len(sys.argv) > 1:
25 for_comm = sys.argv[1] 27 try:
28 for_pid = int(sys.argv[1])
29 except:
30 for_comm = sys.argv[1]
26 31
27syscalls = autodict() 32syscalls = autodict()
28 33
29def trace_begin(): 34def trace_begin():
30 pass 35 print "Press control+C to stop and show the summary"
31 36
32def trace_end(): 37def trace_end():
33 print_error_totals() 38 print_error_totals()
@@ -35,9 +40,9 @@ def trace_end():
35def raw_syscalls__sys_exit(event_name, context, common_cpu, 40def raw_syscalls__sys_exit(event_name, context, common_cpu,
36 common_secs, common_nsecs, common_pid, common_comm, 41 common_secs, common_nsecs, common_pid, common_comm,
37 id, ret): 42 id, ret):
38 if for_comm is not None: 43 if (for_comm and common_comm != for_comm) or \
39 if common_comm != for_comm: 44 (for_pid and common_pid != for_pid ):
40 return 45 return
41 46
42 if ret < 0: 47 if ret < 0:
43 try: 48 try:
@@ -62,7 +67,7 @@ def print_error_totals():
62 print "\n%s [%d]\n" % (comm, pid), 67 print "\n%s [%d]\n" % (comm, pid),
63 id_keys = syscalls[comm][pid].keys() 68 id_keys = syscalls[comm][pid].keys()
64 for id in id_keys: 69 for id in id_keys:
65 print " syscall: %-16d\n" % (id), 70 print " syscall: %-16s\n" % syscall_name(id),
66 ret_keys = syscalls[comm][pid][id].keys() 71 ret_keys = syscalls[comm][pid][id].keys()
67 for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True): 72 for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True):
68 print " err = %-20d %10d\n" % (ret, val), 73 print " err = %-20s %10d\n" % (strerror(ret), val),
diff --git a/tools/perf/scripts/python/futex-contention.py b/tools/perf/scripts/python/futex-contention.py
new file mode 100644
index 000000000000..11e70a388d41
--- /dev/null
+++ b/tools/perf/scripts/python/futex-contention.py
@@ -0,0 +1,50 @@
1# futex contention
2# (c) 2010, Arnaldo Carvalho de Melo <acme@redhat.com>
3# Licensed under the terms of the GNU GPL License version 2
4#
5# Translation of:
6#
7# http://sourceware.org/systemtap/wiki/WSFutexContention
8#
9# to perf python scripting.
10#
11# Measures futex contention
12
13import os, sys
14sys.path.append(os.environ['PERF_EXEC_PATH'] + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
15from Util import *
16
17process_names = {}
18thread_thislock = {}
19thread_blocktime = {}
20
21lock_waits = {} # long-lived stats on (tid,lock) blockage elapsed time
22process_names = {} # long-lived pid-to-execname mapping
23
24def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm,
25 nr, uaddr, op, val, utime, uaddr2, val3):
26 cmd = op & FUTEX_CMD_MASK
27 if cmd != FUTEX_WAIT:
28 return # we don't care about originators of WAKE events
29
30 process_names[tid] = comm
31 thread_thislock[tid] = uaddr
32 thread_blocktime[tid] = nsecs(s, ns)
33
34def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm,
35 nr, ret):
36 if thread_blocktime.has_key(tid):
37 elapsed = nsecs(s, ns) - thread_blocktime[tid]
38 add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed)
39 del thread_blocktime[tid]
40 del thread_thislock[tid]
41
42def trace_begin():
43 print "Press control+C to stop and show the summary"
44
45def trace_end():
46 for (tid, lock) in lock_waits:
47 min, max, avg, count = lock_waits[tid, lock]
48 print "%s[%d] lock %x contended %d times, %d avg ns" % \
49 (process_names[tid], tid, lock, count, avg)
50
diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py
index 6cafad40c296..7a6ec2c7d8ab 100644
--- a/tools/perf/scripts/python/sctop.py
+++ b/tools/perf/scripts/python/sctop.py
@@ -8,10 +8,7 @@
8# will be refreshed every [interval] seconds. The default interval is 8# will be refreshed every [interval] seconds. The default interval is
9# 3 seconds. 9# 3 seconds.
10 10
11import thread 11import os, sys, thread, time
12import time
13import os
14import sys
15 12
16sys.path.append(os.environ['PERF_EXEC_PATH'] + \ 13sys.path.append(os.environ['PERF_EXEC_PATH'] + \
17 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') 14 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
@@ -20,7 +17,7 @@ from perf_trace_context import *
20from Core import * 17from Core import *
21from Util import * 18from Util import *
22 19
23usage = "perf trace -s syscall-counts.py [comm] [interval]\n"; 20usage = "perf trace -s sctop.py [comm] [interval]\n";
24 21
25for_comm = None 22for_comm = None
26default_interval = 3 23default_interval = 3
@@ -71,7 +68,7 @@ def print_syscall_totals(interval):
71 for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ 68 for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
72 reverse = True): 69 reverse = True):
73 try: 70 try:
74 print "%-40d %10d\n" % (id, val), 71 print "%-40s %10d\n" % (syscall_name(id), val),
75 except TypeError: 72 except TypeError:
76 pass 73 pass
77 syscalls.clear() 74 syscalls.clear()
diff --git a/tools/perf/scripts/python/syscall-counts-by-pid.py b/tools/perf/scripts/python/syscall-counts-by-pid.py
index af722d6a4b3f..d1ee3ec10cf2 100644
--- a/tools/perf/scripts/python/syscall-counts-by-pid.py
+++ b/tools/perf/scripts/python/syscall-counts-by-pid.py
@@ -5,29 +5,33 @@
5# Displays system-wide system call totals, broken down by syscall. 5# Displays system-wide system call totals, broken down by syscall.
6# If a [comm] arg is specified, only syscalls called by [comm] are displayed. 6# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
7 7
8import os 8import os, sys
9import sys
10 9
11sys.path.append(os.environ['PERF_EXEC_PATH'] + \ 10sys.path.append(os.environ['PERF_EXEC_PATH'] + \
12 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') 11 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
13 12
14from perf_trace_context import * 13from perf_trace_context import *
15from Core import * 14from Core import *
15from Util import syscall_name
16 16
17usage = "perf trace -s syscall-counts-by-pid.py [comm]\n"; 17usage = "perf trace -s syscall-counts-by-pid.py [comm]\n";
18 18
19for_comm = None 19for_comm = None
20for_pid = None
20 21
21if len(sys.argv) > 2: 22if len(sys.argv) > 2:
22 sys.exit(usage) 23 sys.exit(usage)
23 24
24if len(sys.argv) > 1: 25if len(sys.argv) > 1:
25 for_comm = sys.argv[1] 26 try:
27 for_pid = int(sys.argv[1])
28 except:
29 for_comm = sys.argv[1]
26 30
27syscalls = autodict() 31syscalls = autodict()
28 32
29def trace_begin(): 33def trace_begin():
30 pass 34 print "Press control+C to stop and show the summary"
31 35
32def trace_end(): 36def trace_end():
33 print_syscall_totals() 37 print_syscall_totals()
@@ -35,9 +39,10 @@ def trace_end():
35def raw_syscalls__sys_enter(event_name, context, common_cpu, 39def raw_syscalls__sys_enter(event_name, context, common_cpu,
36 common_secs, common_nsecs, common_pid, common_comm, 40 common_secs, common_nsecs, common_pid, common_comm,
37 id, args): 41 id, args):
38 if for_comm is not None: 42
39 if common_comm != for_comm: 43 if (for_comm and common_comm != for_comm) or \
40 return 44 (for_pid and common_pid != for_pid ):
45 return
41 try: 46 try:
42 syscalls[common_comm][common_pid][id] += 1 47 syscalls[common_comm][common_pid][id] += 1
43 except TypeError: 48 except TypeError:
@@ -61,4 +66,4 @@ def print_syscall_totals():
61 id_keys = syscalls[comm][pid].keys() 66 id_keys = syscalls[comm][pid].keys()
62 for id, val in sorted(syscalls[comm][pid].iteritems(), \ 67 for id, val in sorted(syscalls[comm][pid].iteritems(), \
63 key = lambda(k, v): (v, k), reverse = True): 68 key = lambda(k, v): (v, k), reverse = True):
64 print " %-38d %10d\n" % (id, val), 69 print " %-38s %10d\n" % (syscall_name(id), val),
diff --git a/tools/perf/scripts/python/syscall-counts.py b/tools/perf/scripts/python/syscall-counts.py
index f977e85ff049..ea183dc82d29 100644
--- a/tools/perf/scripts/python/syscall-counts.py
+++ b/tools/perf/scripts/python/syscall-counts.py
@@ -13,6 +13,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \
13 13
14from perf_trace_context import * 14from perf_trace_context import *
15from Core import * 15from Core import *
16from Util import syscall_name
16 17
17usage = "perf trace -s syscall-counts.py [comm]\n"; 18usage = "perf trace -s syscall-counts.py [comm]\n";
18 19
@@ -27,7 +28,7 @@ if len(sys.argv) > 1:
27syscalls = autodict() 28syscalls = autodict()
28 29
29def trace_begin(): 30def trace_begin():
30 pass 31 print "Press control+C to stop and show the summary"
31 32
32def trace_end(): 33def trace_end():
33 print_syscall_totals() 34 print_syscall_totals()
@@ -55,4 +56,4 @@ def print_syscall_totals():
55 56
56 for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ 57 for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
57 reverse = True): 58 reverse = True):
58 print "%-40d %10d\n" % (id, val), 59 print "%-40s %10d\n" % (syscall_name(id), val),
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index f9c7e3ad1aa7..c8d81b00089d 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -12,8 +12,8 @@
12#include "debug.h" 12#include "debug.h"
13#include "util.h" 13#include "util.h"
14 14
15int verbose = 0; 15int verbose;
16bool dump_trace = false; 16bool dump_trace = false, quiet = false;
17 17
18int eprintf(int level, const char *fmt, ...) 18int eprintf(int level, const char *fmt, ...)
19{ 19{
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index 7a17ee061bcb..7b514082bbaf 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -6,7 +6,7 @@
6#include "event.h" 6#include "event.h"
7 7
8extern int verbose; 8extern int verbose;
9extern bool dump_trace; 9extern bool quiet, dump_trace;
10 10
11int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); 11int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
12void trace_event(event_t *event); 12void trace_event(event_t *event);
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 78575796d5f3..b397c0383728 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -215,6 +215,16 @@ struct symbol *map_groups__find_function_by_name(struct map_groups *self,
215 return map_groups__find_symbol_by_name(self, MAP__FUNCTION, name, mapp, filter); 215 return map_groups__find_symbol_by_name(self, MAP__FUNCTION, name, mapp, filter);
216} 216}
217 217
218static inline
219struct symbol *machine__find_kernel_function_by_name(struct machine *self,
220 const char *name,
221 struct map **mapp,
222 symbol_filter_t filter)
223{
224 return map_groups__find_function_by_name(&self->kmaps, name, mapp,
225 filter);
226}
227
218int map_groups__fixup_overlappings(struct map_groups *self, struct map *map, 228int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
219 int verbose, FILE *fp); 229 int verbose, FILE *fp);
220 230
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index fcc16e4349df..3b6a5297bf16 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -74,10 +74,9 @@ static int e_snprintf(char *str, size_t size, const char *format, ...)
74static char *synthesize_perf_probe_point(struct perf_probe_point *pp); 74static char *synthesize_perf_probe_point(struct perf_probe_point *pp);
75static struct machine machine; 75static struct machine machine;
76 76
77/* Initialize symbol maps and path of vmlinux */ 77/* Initialize symbol maps and path of vmlinux/modules */
78static int init_vmlinux(void) 78static int init_vmlinux(void)
79{ 79{
80 struct dso *kernel;
81 int ret; 80 int ret;
82 81
83 symbol_conf.sort_by_name = true; 82 symbol_conf.sort_by_name = true;
@@ -91,33 +90,61 @@ static int init_vmlinux(void)
91 goto out; 90 goto out;
92 } 91 }
93 92
94 ret = machine__init(&machine, "/", 0); 93 ret = machine__init(&machine, "", HOST_KERNEL_ID);
95 if (ret < 0) 94 if (ret < 0)
96 goto out; 95 goto out;
97 96
98 kernel = dso__new_kernel(symbol_conf.vmlinux_name); 97 if (machine__create_kernel_maps(&machine) < 0) {
99 if (kernel == NULL) 98 pr_debug("machine__create_kernel_maps ");
100 die("Failed to create kernel dso."); 99 goto out;
101 100 }
102 ret = __machine__create_kernel_maps(&machine, kernel);
103 if (ret < 0)
104 pr_debug("Failed to create kernel maps.\n");
105
106out: 101out:
107 if (ret < 0) 102 if (ret < 0)
108 pr_warning("Failed to init vmlinux path.\n"); 103 pr_warning("Failed to init vmlinux path.\n");
109 return ret; 104 return ret;
110} 105}
111 106
107static struct symbol *__find_kernel_function_by_name(const char *name,
108 struct map **mapp)
109{
110 return machine__find_kernel_function_by_name(&machine, name, mapp,
111 NULL);
112}
113
114const char *kernel_get_module_path(const char *module)
115{
116 struct dso *dso;
117
118 if (module) {
119 list_for_each_entry(dso, &machine.kernel_dsos, node) {
120 if (strncmp(dso->short_name + 1, module,
121 dso->short_name_len - 2) == 0)
122 goto found;
123 }
124 pr_debug("Failed to find module %s.\n", module);
125 return NULL;
126 } else {
127 dso = machine.vmlinux_maps[MAP__FUNCTION]->dso;
128 if (dso__load_vmlinux_path(dso,
129 machine.vmlinux_maps[MAP__FUNCTION], NULL) < 0) {
130 pr_debug("Failed to load kernel map.\n");
131 return NULL;
132 }
133 }
134found:
135 return dso->long_name;
136}
137
112#ifdef DWARF_SUPPORT 138#ifdef DWARF_SUPPORT
113static int open_vmlinux(void) 139static int open_vmlinux(const char *module)
114{ 140{
115 if (map__load(machine.vmlinux_maps[MAP__FUNCTION], NULL) < 0) { 141 const char *path = kernel_get_module_path(module);
116 pr_debug("Failed to load kernel map.\n"); 142 if (!path) {
117 return -EINVAL; 143 pr_err("Failed to find path of %s module", module ?: "kernel");
144 return -ENOENT;
118 } 145 }
119 pr_debug("Try to open %s\n", machine.vmlinux_maps[MAP__FUNCTION]->dso->long_name); 146 pr_debug("Try to open %s\n", path);
120 return open(machine.vmlinux_maps[MAP__FUNCTION]->dso->long_name, O_RDONLY); 147 return open(path, O_RDONLY);
121} 148}
122 149
123/* 150/*
@@ -125,20 +152,19 @@ static int open_vmlinux(void)
125 * Currently only handles kprobes. 152 * Currently only handles kprobes.
126 */ 153 */
127static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, 154static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
128 struct perf_probe_point *pp) 155 struct perf_probe_point *pp)
129{ 156{
130 struct symbol *sym; 157 struct symbol *sym;
131 int fd, ret = -ENOENT; 158 struct map *map;
159 u64 addr;
160 int ret = -ENOENT;
132 161
133 sym = map__find_symbol_by_name(machine.vmlinux_maps[MAP__FUNCTION], 162 sym = __find_kernel_function_by_name(tp->symbol, &map);
134 tp->symbol, NULL);
135 if (sym) { 163 if (sym) {
136 fd = open_vmlinux(); 164 addr = map->unmap_ip(map, sym->start + tp->offset);
137 if (fd >= 0) { 165 pr_debug("try to find %s+%ld@%llx\n", tp->symbol,
138 ret = find_perf_probe_point(fd, 166 tp->offset, addr);
139 sym->start + tp->offset, pp); 167 ret = find_perf_probe_point((unsigned long)addr, pp);
140 close(fd);
141 }
142 } 168 }
143 if (ret <= 0) { 169 if (ret <= 0) {
144 pr_debug("Failed to find corresponding probes from " 170 pr_debug("Failed to find corresponding probes from "
@@ -156,12 +182,12 @@ static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
156/* Try to find perf_probe_event with debuginfo */ 182/* Try to find perf_probe_event with debuginfo */
157static int try_to_find_probe_trace_events(struct perf_probe_event *pev, 183static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
158 struct probe_trace_event **tevs, 184 struct probe_trace_event **tevs,
159 int max_tevs) 185 int max_tevs, const char *module)
160{ 186{
161 bool need_dwarf = perf_probe_event_need_dwarf(pev); 187 bool need_dwarf = perf_probe_event_need_dwarf(pev);
162 int fd, ntevs; 188 int fd, ntevs;
163 189
164 fd = open_vmlinux(); 190 fd = open_vmlinux(module);
165 if (fd < 0) { 191 if (fd < 0) {
166 if (need_dwarf) { 192 if (need_dwarf) {
167 pr_warning("Failed to open debuginfo file.\n"); 193 pr_warning("Failed to open debuginfo file.\n");
@@ -300,7 +326,7 @@ error:
300 * Show line-range always requires debuginfo to find source file and 326 * Show line-range always requires debuginfo to find source file and
301 * line number. 327 * line number.
302 */ 328 */
303int show_line_range(struct line_range *lr) 329int show_line_range(struct line_range *lr, const char *module)
304{ 330{
305 int l = 1; 331 int l = 1;
306 struct line_node *ln; 332 struct line_node *ln;
@@ -313,7 +339,7 @@ int show_line_range(struct line_range *lr)
313 if (ret < 0) 339 if (ret < 0)
314 return ret; 340 return ret;
315 341
316 fd = open_vmlinux(); 342 fd = open_vmlinux(module);
317 if (fd < 0) { 343 if (fd < 0) {
318 pr_warning("Failed to open debuginfo file.\n"); 344 pr_warning("Failed to open debuginfo file.\n");
319 return fd; 345 return fd;
@@ -378,11 +404,84 @@ end:
378 return ret; 404 return ret;
379} 405}
380 406
407static int show_available_vars_at(int fd, struct perf_probe_event *pev,
408 int max_vls, bool externs)
409{
410 char *buf;
411 int ret, i;
412 struct str_node *node;
413 struct variable_list *vls = NULL, *vl;
414
415 buf = synthesize_perf_probe_point(&pev->point);
416 if (!buf)
417 return -EINVAL;
418 pr_debug("Searching variables at %s\n", buf);
419
420 ret = find_available_vars_at(fd, pev, &vls, max_vls, externs);
421 if (ret > 0) {
422 /* Some variables were found */
423 fprintf(stdout, "Available variables at %s\n", buf);
424 for (i = 0; i < ret; i++) {
425 vl = &vls[i];
426 /*
427 * A probe point might be converted to
428 * several trace points.
429 */
430 fprintf(stdout, "\t@<%s+%lu>\n", vl->point.symbol,
431 vl->point.offset);
432 free(vl->point.symbol);
433 if (vl->vars) {
434 strlist__for_each(node, vl->vars)
435 fprintf(stdout, "\t\t%s\n", node->s);
436 strlist__delete(vl->vars);
437 } else
438 fprintf(stdout, "(No variables)\n");
439 }
440 free(vls);
441 } else
442 pr_err("Failed to find variables at %s (%d)\n", buf, ret);
443
444 free(buf);
445 return ret;
446}
447
448/* Show available variables on given probe point */
449int show_available_vars(struct perf_probe_event *pevs, int npevs,
450 int max_vls, const char *module, bool externs)
451{
452 int i, fd, ret = 0;
453
454 ret = init_vmlinux();
455 if (ret < 0)
456 return ret;
457
458 fd = open_vmlinux(module);
459 if (fd < 0) {
460 pr_warning("Failed to open debuginfo file.\n");
461 return fd;
462 }
463
464 setup_pager();
465
466 for (i = 0; i < npevs && ret >= 0; i++)
467 ret = show_available_vars_at(fd, &pevs[i], max_vls, externs);
468
469 close(fd);
470 return ret;
471}
472
381#else /* !DWARF_SUPPORT */ 473#else /* !DWARF_SUPPORT */
382 474
383static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp, 475static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
384 struct perf_probe_point *pp) 476 struct perf_probe_point *pp)
385{ 477{
478 struct symbol *sym;
479
480 sym = __find_kernel_function_by_name(tp->symbol, NULL);
481 if (!sym) {
482 pr_err("Failed to find symbol %s in kernel.\n", tp->symbol);
483 return -ENOENT;
484 }
386 pp->function = strdup(tp->symbol); 485 pp->function = strdup(tp->symbol);
387 if (pp->function == NULL) 486 if (pp->function == NULL)
388 return -ENOMEM; 487 return -ENOMEM;
@@ -394,7 +493,7 @@ static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
394 493
395static int try_to_find_probe_trace_events(struct perf_probe_event *pev, 494static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
396 struct probe_trace_event **tevs __unused, 495 struct probe_trace_event **tevs __unused,
397 int max_tevs __unused) 496 int max_tevs __unused, const char *mod __unused)
398{ 497{
399 if (perf_probe_event_need_dwarf(pev)) { 498 if (perf_probe_event_need_dwarf(pev)) {
400 pr_warning("Debuginfo-analysis is not supported.\n"); 499 pr_warning("Debuginfo-analysis is not supported.\n");
@@ -403,12 +502,19 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
403 return 0; 502 return 0;
404} 503}
405 504
406int show_line_range(struct line_range *lr __unused) 505int show_line_range(struct line_range *lr __unused, const char *module __unused)
407{ 506{
408 pr_warning("Debuginfo-analysis is not supported.\n"); 507 pr_warning("Debuginfo-analysis is not supported.\n");
409 return -ENOSYS; 508 return -ENOSYS;
410} 509}
411 510
511int show_available_vars(struct perf_probe_event *pevs __unused,
512 int npevs __unused, int max_vls __unused,
513 const char *module __unused, bool externs __unused)
514{
515 pr_warning("Debuginfo-analysis is not supported.\n");
516 return -ENOSYS;
517}
412#endif 518#endif
413 519
414int parse_line_range_desc(const char *arg, struct line_range *lr) 520int parse_line_range_desc(const char *arg, struct line_range *lr)
@@ -1087,7 +1193,7 @@ error:
1087} 1193}
1088 1194
1089static int convert_to_perf_probe_event(struct probe_trace_event *tev, 1195static int convert_to_perf_probe_event(struct probe_trace_event *tev,
1090 struct perf_probe_event *pev) 1196 struct perf_probe_event *pev)
1091{ 1197{
1092 char buf[64] = ""; 1198 char buf[64] = "";
1093 int i, ret; 1199 int i, ret;
@@ -1516,14 +1622,14 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
1516 1622
1517static int convert_to_probe_trace_events(struct perf_probe_event *pev, 1623static int convert_to_probe_trace_events(struct perf_probe_event *pev,
1518 struct probe_trace_event **tevs, 1624 struct probe_trace_event **tevs,
1519 int max_tevs) 1625 int max_tevs, const char *module)
1520{ 1626{
1521 struct symbol *sym; 1627 struct symbol *sym;
1522 int ret = 0, i; 1628 int ret = 0, i;
1523 struct probe_trace_event *tev; 1629 struct probe_trace_event *tev;
1524 1630
1525 /* Convert perf_probe_event with debuginfo */ 1631 /* Convert perf_probe_event with debuginfo */
1526 ret = try_to_find_probe_trace_events(pev, tevs, max_tevs); 1632 ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, module);
1527 if (ret != 0) 1633 if (ret != 0)
1528 return ret; 1634 return ret;
1529 1635
@@ -1572,8 +1678,7 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,
1572 } 1678 }
1573 1679
1574 /* Currently just checking function name from symbol map */ 1680 /* Currently just checking function name from symbol map */
1575 sym = map__find_symbol_by_name(machine.vmlinux_maps[MAP__FUNCTION], 1681 sym = __find_kernel_function_by_name(tev->point.symbol, NULL);
1576 tev->point.symbol, NULL);
1577 if (!sym) { 1682 if (!sym) {
1578 pr_warning("Kernel symbol \'%s\' not found.\n", 1683 pr_warning("Kernel symbol \'%s\' not found.\n",
1579 tev->point.symbol); 1684 tev->point.symbol);
@@ -1596,7 +1701,7 @@ struct __event_package {
1596}; 1701};
1597 1702
1598int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, 1703int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
1599 bool force_add, int max_tevs) 1704 int max_tevs, const char *module, bool force_add)
1600{ 1705{
1601 int i, j, ret; 1706 int i, j, ret;
1602 struct __event_package *pkgs; 1707 struct __event_package *pkgs;
@@ -1617,7 +1722,9 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
1617 pkgs[i].pev = &pevs[i]; 1722 pkgs[i].pev = &pevs[i];
1618 /* Convert with or without debuginfo */ 1723 /* Convert with or without debuginfo */
1619 ret = convert_to_probe_trace_events(pkgs[i].pev, 1724 ret = convert_to_probe_trace_events(pkgs[i].pev,
1620 &pkgs[i].tevs, max_tevs); 1725 &pkgs[i].tevs,
1726 max_tevs,
1727 module);
1621 if (ret < 0) 1728 if (ret < 0)
1622 goto end; 1729 goto end;
1623 pkgs[i].ntevs = ret; 1730 pkgs[i].ntevs = ret;
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 5af39243a25b..5accbedfea37 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -90,6 +90,12 @@ struct line_range {
90 struct list_head line_list; /* Visible lines */ 90 struct list_head line_list; /* Visible lines */
91}; 91};
92 92
93/* List of variables */
94struct variable_list {
95 struct probe_trace_point point; /* Actual probepoint */
96 struct strlist *vars; /* Available variables */
97};
98
93/* Command string to events */ 99/* Command string to events */
94extern int parse_perf_probe_command(const char *cmd, 100extern int parse_perf_probe_command(const char *cmd,
95 struct perf_probe_event *pev); 101 struct perf_probe_event *pev);
@@ -109,12 +115,18 @@ extern void clear_perf_probe_event(struct perf_probe_event *pev);
109/* Command string to line-range */ 115/* Command string to line-range */
110extern int parse_line_range_desc(const char *cmd, struct line_range *lr); 116extern int parse_line_range_desc(const char *cmd, struct line_range *lr);
111 117
118/* Internal use: Return kernel/module path */
119extern const char *kernel_get_module_path(const char *module);
112 120
113extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, 121extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
114 bool force_add, int max_probe_points); 122 int max_probe_points, const char *module,
123 bool force_add);
115extern int del_perf_probe_events(struct strlist *dellist); 124extern int del_perf_probe_events(struct strlist *dellist);
116extern int show_perf_probe_events(void); 125extern int show_perf_probe_events(void);
117extern int show_line_range(struct line_range *lr); 126extern int show_line_range(struct line_range *lr, const char *module);
127extern int show_available_vars(struct perf_probe_event *pevs, int npevs,
128 int max_probe_points, const char *module,
129 bool externs);
118 130
119 131
120/* Maximum index number of event-name postfix */ 132/* Maximum index number of event-name postfix */
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 32b81f707ff5..3991d73d1cff 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -116,6 +116,101 @@ static void line_list__free(struct list_head *head)
116 } 116 }
117} 117}
118 118
119/* Dwarf FL wrappers */
120
121static int __linux_kernel_find_elf(Dwfl_Module *mod,
122 void **userdata,
123 const char *module_name,
124 Dwarf_Addr base,
125 char **file_name, Elf **elfp)
126{
127 int fd;
128 const char *path = kernel_get_module_path(module_name);
129
130 if (path) {
131 fd = open(path, O_RDONLY);
132 if (fd >= 0) {
133 *file_name = strdup(path);
134 return fd;
135 }
136 }
137 /* If failed, try to call standard method */
138 return dwfl_linux_kernel_find_elf(mod, userdata, module_name, base,
139 file_name, elfp);
140}
141
142static char *debuginfo_path; /* Currently dummy */
143
144static const Dwfl_Callbacks offline_callbacks = {
145 .find_debuginfo = dwfl_standard_find_debuginfo,
146 .debuginfo_path = &debuginfo_path,
147
148 .section_address = dwfl_offline_section_address,
149
150 /* We use this table for core files too. */
151 .find_elf = dwfl_build_id_find_elf,
152};
153
154static const Dwfl_Callbacks kernel_callbacks = {
155 .find_debuginfo = dwfl_standard_find_debuginfo,
156 .debuginfo_path = &debuginfo_path,
157
158 .find_elf = __linux_kernel_find_elf,
159 .section_address = dwfl_linux_kernel_module_section_address,
160};
161
162/* Get a Dwarf from offline image */
163static Dwarf *dwfl_init_offline_dwarf(int fd, Dwfl **dwflp, Dwarf_Addr *bias)
164{
165 Dwfl_Module *mod;
166 Dwarf *dbg = NULL;
167
168 if (!dwflp)
169 return NULL;
170
171 *dwflp = dwfl_begin(&offline_callbacks);
172 if (!*dwflp)
173 return NULL;
174
175 mod = dwfl_report_offline(*dwflp, "", "", fd);
176 if (!mod)
177 goto error;
178
179 dbg = dwfl_module_getdwarf(mod, bias);
180 if (!dbg) {
181error:
182 dwfl_end(*dwflp);
183 *dwflp = NULL;
184 }
185 return dbg;
186}
187
188/* Get a Dwarf from live kernel image */
189static Dwarf *dwfl_init_live_kernel_dwarf(Dwarf_Addr addr, Dwfl **dwflp,
190 Dwarf_Addr *bias)
191{
192 Dwarf *dbg;
193
194 if (!dwflp)
195 return NULL;
196
197 *dwflp = dwfl_begin(&kernel_callbacks);
198 if (!*dwflp)
199 return NULL;
200
201 /* Load the kernel dwarves: Don't care the result here */
202 dwfl_linux_kernel_report_kernel(*dwflp);
203 dwfl_linux_kernel_report_modules(*dwflp);
204
205 dbg = dwfl_addrdwarf(*dwflp, addr, bias);
206 /* Here, check whether we could get a real dwarf */
207 if (!dbg) {
208 dwfl_end(*dwflp);
209 *dwflp = NULL;
210 }
211 return dbg;
212}
213
119/* Dwarf wrappers */ 214/* Dwarf wrappers */
120 215
121/* Find the realpath of the target file. */ 216/* Find the realpath of the target file. */
@@ -160,26 +255,44 @@ static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
160 return name ? (strcmp(tname, name) == 0) : false; 255 return name ? (strcmp(tname, name) == 0) : false;
161} 256}
162 257
163/* Get type die, but skip qualifiers and typedef */ 258/* Get type die */
164static Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) 259static Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
165{ 260{
166 Dwarf_Attribute attr; 261 Dwarf_Attribute attr;
262
263 if (dwarf_attr_integrate(vr_die, DW_AT_type, &attr) &&
264 dwarf_formref_die(&attr, die_mem))
265 return die_mem;
266 else
267 return NULL;
268}
269
270/* Get a type die, but skip qualifiers */
271static Dwarf_Die *__die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
272{
167 int tag; 273 int tag;
168 274
169 do { 275 do {
170 if (dwarf_attr(vr_die, DW_AT_type, &attr) == NULL || 276 vr_die = die_get_type(vr_die, die_mem);
171 dwarf_formref_die(&attr, die_mem) == NULL) 277 if (!vr_die)
172 return NULL; 278 break;
173 279 tag = dwarf_tag(vr_die);
174 tag = dwarf_tag(die_mem);
175 vr_die = die_mem;
176 } while (tag == DW_TAG_const_type || 280 } while (tag == DW_TAG_const_type ||
177 tag == DW_TAG_restrict_type || 281 tag == DW_TAG_restrict_type ||
178 tag == DW_TAG_volatile_type || 282 tag == DW_TAG_volatile_type ||
179 tag == DW_TAG_shared_type || 283 tag == DW_TAG_shared_type);
180 tag == DW_TAG_typedef); 284
285 return vr_die;
286}
181 287
182 return die_mem; 288/* Get a type die, but skip qualifiers and typedef */
289static Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
290{
291 do {
292 vr_die = __die_get_real_type(vr_die, die_mem);
293 } while (vr_die && dwarf_tag(vr_die) == DW_TAG_typedef);
294
295 return vr_die;
183} 296}
184 297
185static bool die_is_signed_type(Dwarf_Die *tp_die) 298static bool die_is_signed_type(Dwarf_Die *tp_die)
@@ -320,25 +433,35 @@ static Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
320 return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem); 433 return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem);
321} 434}
322 435
436struct __find_variable_param {
437 const char *name;
438 Dwarf_Addr addr;
439};
440
323static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data) 441static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data)
324{ 442{
325 const char *name = data; 443 struct __find_variable_param *fvp = data;
326 int tag; 444 int tag;
327 445
328 tag = dwarf_tag(die_mem); 446 tag = dwarf_tag(die_mem);
329 if ((tag == DW_TAG_formal_parameter || 447 if ((tag == DW_TAG_formal_parameter ||
330 tag == DW_TAG_variable) && 448 tag == DW_TAG_variable) &&
331 die_compare_name(die_mem, name)) 449 die_compare_name(die_mem, fvp->name))
332 return DIE_FIND_CB_FOUND; 450 return DIE_FIND_CB_FOUND;
333 451
334 return DIE_FIND_CB_CONTINUE; 452 if (dwarf_haspc(die_mem, fvp->addr))
453 return DIE_FIND_CB_CONTINUE;
454 else
455 return DIE_FIND_CB_SIBLING;
335} 456}
336 457
337/* Find a variable called 'name' */ 458/* Find a variable called 'name' at given address */
338static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name, 459static Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name,
339 Dwarf_Die *die_mem) 460 Dwarf_Addr addr, Dwarf_Die *die_mem)
340{ 461{
341 return die_find_child(sp_die, __die_find_variable_cb, (void *)name, 462 struct __find_variable_param fvp = { .name = name, .addr = addr};
463
464 return die_find_child(sp_die, __die_find_variable_cb, (void *)&fvp,
342 die_mem); 465 die_mem);
343} 466}
344 467
@@ -361,6 +484,60 @@ static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
361 die_mem); 484 die_mem);
362} 485}
363 486
487/* Get the name of given variable DIE */
488static int die_get_typename(Dwarf_Die *vr_die, char *buf, int len)
489{
490 Dwarf_Die type;
491 int tag, ret, ret2;
492 const char *tmp = "";
493
494 if (__die_get_real_type(vr_die, &type) == NULL)
495 return -ENOENT;
496
497 tag = dwarf_tag(&type);
498 if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)
499 tmp = "*";
500 else if (tag == DW_TAG_subroutine_type) {
501 /* Function pointer */
502 ret = snprintf(buf, len, "(function_type)");
503 return (ret >= len) ? -E2BIG : ret;
504 } else {
505 if (!dwarf_diename(&type))
506 return -ENOENT;
507 if (tag == DW_TAG_union_type)
508 tmp = "union ";
509 else if (tag == DW_TAG_structure_type)
510 tmp = "struct ";
511 /* Write a base name */
512 ret = snprintf(buf, len, "%s%s", tmp, dwarf_diename(&type));
513 return (ret >= len) ? -E2BIG : ret;
514 }
515 ret = die_get_typename(&type, buf, len);
516 if (ret > 0) {
517 ret2 = snprintf(buf + ret, len - ret, "%s", tmp);
518 ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret;
519 }
520 return ret;
521}
522
523/* Get the name and type of given variable DIE, stored as "type\tname" */
524static int die_get_varname(Dwarf_Die *vr_die, char *buf, int len)
525{
526 int ret, ret2;
527
528 ret = die_get_typename(vr_die, buf, len);
529 if (ret < 0) {
530 pr_debug("Failed to get type, make it unknown.\n");
531 ret = snprintf(buf, len, "(unknown_type)");
532 }
533 if (ret > 0) {
534 ret2 = snprintf(buf + ret, len - ret, "\t%s",
535 dwarf_diename(vr_die));
536 ret = (ret2 >= len - ret) ? -E2BIG : ret2 + ret;
537 }
538 return ret;
539}
540
364/* 541/*
365 * Probe finder related functions 542 * Probe finder related functions
366 */ 543 */
@@ -374,8 +551,13 @@ static struct probe_trace_arg_ref *alloc_trace_arg_ref(long offs)
374 return ref; 551 return ref;
375} 552}
376 553
377/* Show a location */ 554/*
378static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf) 555 * Convert a location into trace_arg.
556 * If tvar == NULL, this just checks variable can be converted.
557 */
558static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr,
559 Dwarf_Op *fb_ops,
560 struct probe_trace_arg *tvar)
379{ 561{
380 Dwarf_Attribute attr; 562 Dwarf_Attribute attr;
381 Dwarf_Op *op; 563 Dwarf_Op *op;
@@ -384,20 +566,23 @@ static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf)
384 Dwarf_Word offs = 0; 566 Dwarf_Word offs = 0;
385 bool ref = false; 567 bool ref = false;
386 const char *regs; 568 const char *regs;
387 struct probe_trace_arg *tvar = pf->tvar;
388 int ret; 569 int ret;
389 570
571 if (dwarf_attr(vr_die, DW_AT_external, &attr) != NULL)
572 goto static_var;
573
390 /* TODO: handle more than 1 exprs */ 574 /* TODO: handle more than 1 exprs */
391 if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL || 575 if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL ||
392 dwarf_getlocation_addr(&attr, pf->addr, &op, &nops, 1) <= 0 || 576 dwarf_getlocation_addr(&attr, addr, &op, &nops, 1) <= 0 ||
393 nops == 0) { 577 nops == 0) {
394 /* TODO: Support const_value */ 578 /* TODO: Support const_value */
395 pr_err("Failed to find the location of %s at this address.\n"
396 " Perhaps, it has been optimized out.\n", pf->pvar->var);
397 return -ENOENT; 579 return -ENOENT;
398 } 580 }
399 581
400 if (op->atom == DW_OP_addr) { 582 if (op->atom == DW_OP_addr) {
583static_var:
584 if (!tvar)
585 return 0;
401 /* Static variables on memory (not stack), make @varname */ 586 /* Static variables on memory (not stack), make @varname */
402 ret = strlen(dwarf_diename(vr_die)); 587 ret = strlen(dwarf_diename(vr_die));
403 tvar->value = zalloc(ret + 2); 588 tvar->value = zalloc(ret + 2);
@@ -412,14 +597,11 @@ static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf)
412 597
413 /* If this is based on frame buffer, set the offset */ 598 /* If this is based on frame buffer, set the offset */
414 if (op->atom == DW_OP_fbreg) { 599 if (op->atom == DW_OP_fbreg) {
415 if (pf->fb_ops == NULL) { 600 if (fb_ops == NULL)
416 pr_warning("The attribute of frame base is not "
417 "supported.\n");
418 return -ENOTSUP; 601 return -ENOTSUP;
419 }
420 ref = true; 602 ref = true;
421 offs = op->number; 603 offs = op->number;
422 op = &pf->fb_ops[0]; 604 op = &fb_ops[0];
423 } 605 }
424 606
425 if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) { 607 if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) {
@@ -435,13 +617,18 @@ static int convert_variable_location(Dwarf_Die *vr_die, struct probe_finder *pf)
435 } else if (op->atom == DW_OP_regx) { 617 } else if (op->atom == DW_OP_regx) {
436 regn = op->number; 618 regn = op->number;
437 } else { 619 } else {
438 pr_warning("DW_OP %x is not supported.\n", op->atom); 620 pr_debug("DW_OP %x is not supported.\n", op->atom);
439 return -ENOTSUP; 621 return -ENOTSUP;
440 } 622 }
441 623
624 if (!tvar)
625 return 0;
626
442 regs = get_arch_regstr(regn); 627 regs = get_arch_regstr(regn);
443 if (!regs) { 628 if (!regs) {
444 pr_warning("Mapping for DWARF register number %u missing on this architecture.", regn); 629 /* This should be a bug in DWARF or this tool */
630 pr_warning("Mapping for DWARF register number %u "
631 "missing on this architecture.", regn);
445 return -ERANGE; 632 return -ERANGE;
446 } 633 }
447 634
@@ -666,8 +853,14 @@ static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
666 pr_debug("Converting variable %s into trace event.\n", 853 pr_debug("Converting variable %s into trace event.\n",
667 dwarf_diename(vr_die)); 854 dwarf_diename(vr_die));
668 855
669 ret = convert_variable_location(vr_die, pf); 856 ret = convert_variable_location(vr_die, pf->addr, pf->fb_ops,
670 if (ret == 0 && pf->pvar->field) { 857 pf->tvar);
858 if (ret == -ENOENT)
859 pr_err("Failed to find the location of %s at this address.\n"
860 " Perhaps, it has been optimized out.\n", pf->pvar->var);
861 else if (ret == -ENOTSUP)
862 pr_err("Sorry, we don't support this variable location yet.\n");
863 else if (pf->pvar->field) {
671 ret = convert_variable_fields(vr_die, pf->pvar->var, 864 ret = convert_variable_fields(vr_die, pf->pvar->var,
672 pf->pvar->field, &pf->tvar->ref, 865 pf->pvar->field, &pf->tvar->ref,
673 &die_mem); 866 &die_mem);
@@ -722,56 +915,39 @@ static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
722 pr_debug("Searching '%s' variable in context.\n", 915 pr_debug("Searching '%s' variable in context.\n",
723 pf->pvar->var); 916 pf->pvar->var);
724 /* Search child die for local variables and parameters. */ 917 /* Search child die for local variables and parameters. */
725 if (die_find_variable(sp_die, pf->pvar->var, &vr_die)) 918 if (die_find_variable_at(sp_die, pf->pvar->var, pf->addr, &vr_die))
726 ret = convert_variable(&vr_die, pf); 919 ret = convert_variable(&vr_die, pf);
727 else { 920 else {
728 /* Search upper class */ 921 /* Search upper class */
729 nscopes = dwarf_getscopes_die(sp_die, &scopes); 922 nscopes = dwarf_getscopes_die(sp_die, &scopes);
730 if (nscopes > 0) { 923 while (nscopes-- > 1) {
731 ret = dwarf_getscopevar(scopes, nscopes, pf->pvar->var, 924 pr_debug("Searching variables in %s\n",
732 0, NULL, 0, 0, &vr_die); 925 dwarf_diename(&scopes[nscopes]));
733 if (ret >= 0) 926 /* We should check this scope, so give dummy address */
927 if (die_find_variable_at(&scopes[nscopes],
928 pf->pvar->var, 0,
929 &vr_die)) {
734 ret = convert_variable(&vr_die, pf); 930 ret = convert_variable(&vr_die, pf);
735 else 931 goto found;
736 ret = -ENOENT; 932 }
933 }
934 if (scopes)
737 free(scopes); 935 free(scopes);
738 } else 936 ret = -ENOENT;
739 ret = -ENOENT;
740 } 937 }
938found:
741 if (ret < 0) 939 if (ret < 0)
742 pr_warning("Failed to find '%s' in this function.\n", 940 pr_warning("Failed to find '%s' in this function.\n",
743 pf->pvar->var); 941 pf->pvar->var);
744 return ret; 942 return ret;
745} 943}
746 944
747/* Show a probe point to output buffer */ 945/* Convert subprogram DIE to trace point */
748static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) 946static int convert_to_trace_point(Dwarf_Die *sp_die, Dwarf_Addr paddr,
947 bool retprobe, struct probe_trace_point *tp)
749{ 948{
750 struct probe_trace_event *tev;
751 Dwarf_Addr eaddr; 949 Dwarf_Addr eaddr;
752 Dwarf_Die die_mem;
753 const char *name; 950 const char *name;
754 int ret, i;
755 Dwarf_Attribute fb_attr;
756 size_t nops;
757
758 if (pf->ntevs == pf->max_tevs) {
759 pr_warning("Too many( > %d) probe point found.\n",
760 pf->max_tevs);
761 return -ERANGE;
762 }
763 tev = &pf->tevs[pf->ntevs++];
764
765 /* If no real subprogram, find a real one */
766 if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) {
767 sp_die = die_find_real_subprogram(&pf->cu_die,
768 pf->addr, &die_mem);
769 if (!sp_die) {
770 pr_warning("Failed to find probe point in any "
771 "functions.\n");
772 return -ENOENT;
773 }
774 }
775 951
776 /* Copy the name of probe point */ 952 /* Copy the name of probe point */
777 name = dwarf_diename(sp_die); 953 name = dwarf_diename(sp_die);
@@ -781,26 +957,45 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
781 dwarf_diename(sp_die)); 957 dwarf_diename(sp_die));
782 return -ENOENT; 958 return -ENOENT;
783 } 959 }
784 tev->point.symbol = strdup(name); 960 tp->symbol = strdup(name);
785 if (tev->point.symbol == NULL) 961 if (tp->symbol == NULL)
786 return -ENOMEM; 962 return -ENOMEM;
787 tev->point.offset = (unsigned long)(pf->addr - eaddr); 963 tp->offset = (unsigned long)(paddr - eaddr);
788 } else 964 } else
789 /* This function has no name. */ 965 /* This function has no name. */
790 tev->point.offset = (unsigned long)pf->addr; 966 tp->offset = (unsigned long)paddr;
791 967
792 /* Return probe must be on the head of a subprogram */ 968 /* Return probe must be on the head of a subprogram */
793 if (pf->pev->point.retprobe) { 969 if (retprobe) {
794 if (tev->point.offset != 0) { 970 if (eaddr != paddr) {
795 pr_warning("Return probe must be on the head of" 971 pr_warning("Return probe must be on the head of"
796 " a real function\n"); 972 " a real function\n");
797 return -EINVAL; 973 return -EINVAL;
798 } 974 }
799 tev->point.retprobe = true; 975 tp->retprobe = true;
800 } 976 }
801 977
802 pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, 978 return 0;
803 tev->point.offset); 979}
980
981/* Call probe_finder callback with real subprogram DIE */
982static int call_probe_finder(Dwarf_Die *sp_die, struct probe_finder *pf)
983{
984 Dwarf_Die die_mem;
985 Dwarf_Attribute fb_attr;
986 size_t nops;
987 int ret;
988
989 /* If no real subprogram, find a real one */
990 if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) {
991 sp_die = die_find_real_subprogram(&pf->cu_die,
992 pf->addr, &die_mem);
993 if (!sp_die) {
994 pr_warning("Failed to find probe point in any "
995 "functions.\n");
996 return -ENOENT;
997 }
998 }
804 999
805 /* Get the frame base attribute/ops */ 1000 /* Get the frame base attribute/ops */
806 dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr); 1001 dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr);
@@ -820,22 +1015,13 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
820#endif 1015#endif
821 } 1016 }
822 1017
823 /* Find each argument */ 1018 /* Call finder's callback handler */
824 tev->nargs = pf->pev->nargs; 1019 ret = pf->callback(sp_die, pf);
825 tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
826 if (tev->args == NULL)
827 return -ENOMEM;
828 for (i = 0; i < pf->pev->nargs; i++) {
829 pf->pvar = &pf->pev->args[i];
830 pf->tvar = &tev->args[i];
831 ret = find_variable(sp_die, pf);
832 if (ret != 0)
833 return ret;
834 }
835 1020
836 /* *pf->fb_ops will be cached in libdw. Don't free it. */ 1021 /* *pf->fb_ops will be cached in libdw. Don't free it. */
837 pf->fb_ops = NULL; 1022 pf->fb_ops = NULL;
838 return 0; 1023
1024 return ret;
839} 1025}
840 1026
841/* Find probe point from its line number */ 1027/* Find probe point from its line number */
@@ -871,7 +1057,7 @@ static int find_probe_point_by_line(struct probe_finder *pf)
871 (int)i, lineno, (uintmax_t)addr); 1057 (int)i, lineno, (uintmax_t)addr);
872 pf->addr = addr; 1058 pf->addr = addr;
873 1059
874 ret = convert_probe_point(NULL, pf); 1060 ret = call_probe_finder(NULL, pf);
875 /* Continuing, because target line might be inlined. */ 1061 /* Continuing, because target line might be inlined. */
876 } 1062 }
877 return ret; 1063 return ret;
@@ -984,7 +1170,7 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
984 (int)i, lineno, (unsigned long long)addr); 1170 (int)i, lineno, (unsigned long long)addr);
985 pf->addr = addr; 1171 pf->addr = addr;
986 1172
987 ret = convert_probe_point(sp_die, pf); 1173 ret = call_probe_finder(sp_die, pf);
988 /* Continuing, because target line might be inlined. */ 1174 /* Continuing, because target line might be inlined. */
989 } 1175 }
990 /* TODO: deallocate lines, but how? */ 1176 /* TODO: deallocate lines, but how? */
@@ -1019,7 +1205,7 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, void *data)
1019 pr_debug("found inline addr: 0x%jx\n", 1205 pr_debug("found inline addr: 0x%jx\n",
1020 (uintmax_t)pf->addr); 1206 (uintmax_t)pf->addr);
1021 1207
1022 param->retval = convert_probe_point(in_die, pf); 1208 param->retval = call_probe_finder(in_die, pf);
1023 if (param->retval < 0) 1209 if (param->retval < 0)
1024 return DWARF_CB_ABORT; 1210 return DWARF_CB_ABORT;
1025 } 1211 }
@@ -1057,7 +1243,7 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
1057 } 1243 }
1058 pf->addr += pp->offset; 1244 pf->addr += pp->offset;
1059 /* TODO: Check the address in this function */ 1245 /* TODO: Check the address in this function */
1060 param->retval = convert_probe_point(sp_die, pf); 1246 param->retval = call_probe_finder(sp_die, pf);
1061 } 1247 }
1062 } else { 1248 } else {
1063 struct dwarf_callback_param _param = {.data = (void *)pf, 1249 struct dwarf_callback_param _param = {.data = (void *)pf,
@@ -1079,90 +1265,276 @@ static int find_probe_point_by_func(struct probe_finder *pf)
1079 return _param.retval; 1265 return _param.retval;
1080} 1266}
1081 1267
1082/* Find probe_trace_events specified by perf_probe_event from debuginfo */ 1268/* Find probe points from debuginfo */
1083int find_probe_trace_events(int fd, struct perf_probe_event *pev, 1269static int find_probes(int fd, struct probe_finder *pf)
1084 struct probe_trace_event **tevs, int max_tevs)
1085{ 1270{
1086 struct probe_finder pf = {.pev = pev, .max_tevs = max_tevs}; 1271 struct perf_probe_point *pp = &pf->pev->point;
1087 struct perf_probe_point *pp = &pev->point;
1088 Dwarf_Off off, noff; 1272 Dwarf_Off off, noff;
1089 size_t cuhl; 1273 size_t cuhl;
1090 Dwarf_Die *diep; 1274 Dwarf_Die *diep;
1091 Dwarf *dbg; 1275 Dwarf *dbg = NULL;
1276 Dwfl *dwfl;
1277 Dwarf_Addr bias; /* Currently ignored */
1092 int ret = 0; 1278 int ret = 0;
1093 1279
1094 pf.tevs = zalloc(sizeof(struct probe_trace_event) * max_tevs); 1280 dbg = dwfl_init_offline_dwarf(fd, &dwfl, &bias);
1095 if (pf.tevs == NULL)
1096 return -ENOMEM;
1097 *tevs = pf.tevs;
1098 pf.ntevs = 0;
1099
1100 dbg = dwarf_begin(fd, DWARF_C_READ);
1101 if (!dbg) { 1281 if (!dbg) {
1102 pr_warning("No dwarf info found in the vmlinux - " 1282 pr_warning("No dwarf info found in the vmlinux - "
1103 "please rebuild with CONFIG_DEBUG_INFO=y.\n"); 1283 "please rebuild with CONFIG_DEBUG_INFO=y.\n");
1104 free(pf.tevs);
1105 *tevs = NULL;
1106 return -EBADF; 1284 return -EBADF;
1107 } 1285 }
1108 1286
1109#if _ELFUTILS_PREREQ(0, 142) 1287#if _ELFUTILS_PREREQ(0, 142)
1110 /* Get the call frame information from this dwarf */ 1288 /* Get the call frame information from this dwarf */
1111 pf.cfi = dwarf_getcfi(dbg); 1289 pf->cfi = dwarf_getcfi(dbg);
1112#endif 1290#endif
1113 1291
1114 off = 0; 1292 off = 0;
1115 line_list__init(&pf.lcache); 1293 line_list__init(&pf->lcache);
1116 /* Loop on CUs (Compilation Unit) */ 1294 /* Loop on CUs (Compilation Unit) */
1117 while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) && 1295 while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) &&
1118 ret >= 0) { 1296 ret >= 0) {
1119 /* Get the DIE(Debugging Information Entry) of this CU */ 1297 /* Get the DIE(Debugging Information Entry) of this CU */
1120 diep = dwarf_offdie(dbg, off + cuhl, &pf.cu_die); 1298 diep = dwarf_offdie(dbg, off + cuhl, &pf->cu_die);
1121 if (!diep) 1299 if (!diep)
1122 continue; 1300 continue;
1123 1301
1124 /* Check if target file is included. */ 1302 /* Check if target file is included. */
1125 if (pp->file) 1303 if (pp->file)
1126 pf.fname = cu_find_realpath(&pf.cu_die, pp->file); 1304 pf->fname = cu_find_realpath(&pf->cu_die, pp->file);
1127 else 1305 else
1128 pf.fname = NULL; 1306 pf->fname = NULL;
1129 1307
1130 if (!pp->file || pf.fname) { 1308 if (!pp->file || pf->fname) {
1131 if (pp->function) 1309 if (pp->function)
1132 ret = find_probe_point_by_func(&pf); 1310 ret = find_probe_point_by_func(pf);
1133 else if (pp->lazy_line) 1311 else if (pp->lazy_line)
1134 ret = find_probe_point_lazy(NULL, &pf); 1312 ret = find_probe_point_lazy(NULL, pf);
1135 else { 1313 else {
1136 pf.lno = pp->line; 1314 pf->lno = pp->line;
1137 ret = find_probe_point_by_line(&pf); 1315 ret = find_probe_point_by_line(pf);
1138 } 1316 }
1139 } 1317 }
1140 off = noff; 1318 off = noff;
1141 } 1319 }
1142 line_list__free(&pf.lcache); 1320 line_list__free(&pf->lcache);
1143 dwarf_end(dbg); 1321 if (dwfl)
1322 dwfl_end(dwfl);
1144 1323
1145 return (ret < 0) ? ret : pf.ntevs; 1324 return ret;
1325}
1326
1327/* Add a found probe point into trace event list */
1328static int add_probe_trace_event(Dwarf_Die *sp_die, struct probe_finder *pf)
1329{
1330 struct trace_event_finder *tf =
1331 container_of(pf, struct trace_event_finder, pf);
1332 struct probe_trace_event *tev;
1333 int ret, i;
1334
1335 /* Check number of tevs */
1336 if (tf->ntevs == tf->max_tevs) {
1337 pr_warning("Too many( > %d) probe point found.\n",
1338 tf->max_tevs);
1339 return -ERANGE;
1340 }
1341 tev = &tf->tevs[tf->ntevs++];
1342
1343 ret = convert_to_trace_point(sp_die, pf->addr, pf->pev->point.retprobe,
1344 &tev->point);
1345 if (ret < 0)
1346 return ret;
1347
1348 pr_debug("Probe point found: %s+%lu\n", tev->point.symbol,
1349 tev->point.offset);
1350
1351 /* Find each argument */
1352 tev->nargs = pf->pev->nargs;
1353 tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
1354 if (tev->args == NULL)
1355 return -ENOMEM;
1356 for (i = 0; i < pf->pev->nargs; i++) {
1357 pf->pvar = &pf->pev->args[i];
1358 pf->tvar = &tev->args[i];
1359 ret = find_variable(sp_die, pf);
1360 if (ret != 0)
1361 return ret;
1362 }
1363
1364 return 0;
1365}
1366
1367/* Find probe_trace_events specified by perf_probe_event from debuginfo */
1368int find_probe_trace_events(int fd, struct perf_probe_event *pev,
1369 struct probe_trace_event **tevs, int max_tevs)
1370{
1371 struct trace_event_finder tf = {
1372 .pf = {.pev = pev, .callback = add_probe_trace_event},
1373 .max_tevs = max_tevs};
1374 int ret;
1375
1376 /* Allocate result tevs array */
1377 *tevs = zalloc(sizeof(struct probe_trace_event) * max_tevs);
1378 if (*tevs == NULL)
1379 return -ENOMEM;
1380
1381 tf.tevs = *tevs;
1382 tf.ntevs = 0;
1383
1384 ret = find_probes(fd, &tf.pf);
1385 if (ret < 0) {
1386 free(*tevs);
1387 *tevs = NULL;
1388 return ret;
1389 }
1390
1391 return (ret < 0) ? ret : tf.ntevs;
1392}
1393
1394#define MAX_VAR_LEN 64
1395
1396/* Collect available variables in this scope */
1397static int collect_variables_cb(Dwarf_Die *die_mem, void *data)
1398{
1399 struct available_var_finder *af = data;
1400 struct variable_list *vl;
1401 char buf[MAX_VAR_LEN];
1402 int tag, ret;
1403
1404 vl = &af->vls[af->nvls - 1];
1405
1406 tag = dwarf_tag(die_mem);
1407 if (tag == DW_TAG_formal_parameter ||
1408 tag == DW_TAG_variable) {
1409 ret = convert_variable_location(die_mem, af->pf.addr,
1410 af->pf.fb_ops, NULL);
1411 if (ret == 0) {
1412 ret = die_get_varname(die_mem, buf, MAX_VAR_LEN);
1413 pr_debug2("Add new var: %s\n", buf);
1414 if (ret > 0)
1415 strlist__add(vl->vars, buf);
1416 }
1417 }
1418
1419 if (af->child && dwarf_haspc(die_mem, af->pf.addr))
1420 return DIE_FIND_CB_CONTINUE;
1421 else
1422 return DIE_FIND_CB_SIBLING;
1423}
1424
1425/* Add a found vars into available variables list */
1426static int add_available_vars(Dwarf_Die *sp_die, struct probe_finder *pf)
1427{
1428 struct available_var_finder *af =
1429 container_of(pf, struct available_var_finder, pf);
1430 struct variable_list *vl;
1431 Dwarf_Die die_mem, *scopes = NULL;
1432 int ret, nscopes;
1433
1434 /* Check number of tevs */
1435 if (af->nvls == af->max_vls) {
1436 pr_warning("Too many( > %d) probe point found.\n", af->max_vls);
1437 return -ERANGE;
1438 }
1439 vl = &af->vls[af->nvls++];
1440
1441 ret = convert_to_trace_point(sp_die, pf->addr, pf->pev->point.retprobe,
1442 &vl->point);
1443 if (ret < 0)
1444 return ret;
1445
1446 pr_debug("Probe point found: %s+%lu\n", vl->point.symbol,
1447 vl->point.offset);
1448
1449 /* Find local variables */
1450 vl->vars = strlist__new(true, NULL);
1451 if (vl->vars == NULL)
1452 return -ENOMEM;
1453 af->child = true;
1454 die_find_child(sp_die, collect_variables_cb, (void *)af, &die_mem);
1455
1456 /* Find external variables */
1457 if (!af->externs)
1458 goto out;
1459 /* Don't need to search child DIE for externs. */
1460 af->child = false;
1461 nscopes = dwarf_getscopes_die(sp_die, &scopes);
1462 while (nscopes-- > 1)
1463 die_find_child(&scopes[nscopes], collect_variables_cb,
1464 (void *)af, &die_mem);
1465 if (scopes)
1466 free(scopes);
1467
1468out:
1469 if (strlist__empty(vl->vars)) {
1470 strlist__delete(vl->vars);
1471 vl->vars = NULL;
1472 }
1473
1474 return ret;
1475}
1476
1477/* Find available variables at given probe point */
1478int find_available_vars_at(int fd, struct perf_probe_event *pev,
1479 struct variable_list **vls, int max_vls,
1480 bool externs)
1481{
1482 struct available_var_finder af = {
1483 .pf = {.pev = pev, .callback = add_available_vars},
1484 .max_vls = max_vls, .externs = externs};
1485 int ret;
1486
1487 /* Allocate result vls array */
1488 *vls = zalloc(sizeof(struct variable_list) * max_vls);
1489 if (*vls == NULL)
1490 return -ENOMEM;
1491
1492 af.vls = *vls;
1493 af.nvls = 0;
1494
1495 ret = find_probes(fd, &af.pf);
1496 if (ret < 0) {
1497 /* Free vlist for error */
1498 while (af.nvls--) {
1499 if (af.vls[af.nvls].point.symbol)
1500 free(af.vls[af.nvls].point.symbol);
1501 if (af.vls[af.nvls].vars)
1502 strlist__delete(af.vls[af.nvls].vars);
1503 }
1504 free(af.vls);
1505 *vls = NULL;
1506 return ret;
1507 }
1508
1509 return (ret < 0) ? ret : af.nvls;
1146} 1510}
1147 1511
1148/* Reverse search */ 1512/* Reverse search */
1149int find_perf_probe_point(int fd, unsigned long addr, 1513int find_perf_probe_point(unsigned long addr, struct perf_probe_point *ppt)
1150 struct perf_probe_point *ppt)
1151{ 1514{
1152 Dwarf_Die cudie, spdie, indie; 1515 Dwarf_Die cudie, spdie, indie;
1153 Dwarf *dbg; 1516 Dwarf *dbg = NULL;
1517 Dwfl *dwfl = NULL;
1154 Dwarf_Line *line; 1518 Dwarf_Line *line;
1155 Dwarf_Addr laddr, eaddr; 1519 Dwarf_Addr laddr, eaddr, bias = 0;
1156 const char *tmp; 1520 const char *tmp;
1157 int lineno, ret = 0; 1521 int lineno, ret = 0;
1158 bool found = false; 1522 bool found = false;
1159 1523
1160 dbg = dwarf_begin(fd, DWARF_C_READ); 1524 /* Open the live linux kernel */
1161 if (!dbg) 1525 dbg = dwfl_init_live_kernel_dwarf(addr, &dwfl, &bias);
1162 return -EBADF; 1526 if (!dbg) {
1527 pr_warning("No dwarf info found in the vmlinux - "
1528 "please rebuild with CONFIG_DEBUG_INFO=y.\n");
1529 ret = -EINVAL;
1530 goto end;
1531 }
1163 1532
1533 /* Adjust address with bias */
1534 addr += bias;
1164 /* Find cu die */ 1535 /* Find cu die */
1165 if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr, &cudie)) { 1536 if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr - bias, &cudie)) {
1537 pr_warning("No CU DIE is found at %lx\n", addr);
1166 ret = -EINVAL; 1538 ret = -EINVAL;
1167 goto end; 1539 goto end;
1168 } 1540 }
@@ -1225,7 +1597,8 @@ found:
1225 } 1597 }
1226 1598
1227end: 1599end:
1228 dwarf_end(dbg); 1600 if (dwfl)
1601 dwfl_end(dwfl);
1229 if (ret >= 0) 1602 if (ret >= 0)
1230 ret = found ? 1 : 0; 1603 ret = found ? 1 : 0;
1231 return ret; 1604 return ret;
@@ -1358,6 +1731,9 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
1358 struct line_finder *lf = param->data; 1731 struct line_finder *lf = param->data;
1359 struct line_range *lr = lf->lr; 1732 struct line_range *lr = lf->lr;
1360 1733
1734 pr_debug("find (%llx) %s\n",
1735 (unsigned long long)dwarf_dieoffset(sp_die),
1736 dwarf_diename(sp_die));
1361 if (dwarf_tag(sp_die) == DW_TAG_subprogram && 1737 if (dwarf_tag(sp_die) == DW_TAG_subprogram &&
1362 die_compare_name(sp_die, lr->function)) { 1738 die_compare_name(sp_die, lr->function)) {
1363 lf->fname = dwarf_decl_file(sp_die); 1739 lf->fname = dwarf_decl_file(sp_die);
@@ -1401,10 +1777,12 @@ int find_line_range(int fd, struct line_range *lr)
1401 Dwarf_Off off = 0, noff; 1777 Dwarf_Off off = 0, noff;
1402 size_t cuhl; 1778 size_t cuhl;
1403 Dwarf_Die *diep; 1779 Dwarf_Die *diep;
1404 Dwarf *dbg; 1780 Dwarf *dbg = NULL;
1781 Dwfl *dwfl;
1782 Dwarf_Addr bias; /* Currently ignored */
1405 const char *comp_dir; 1783 const char *comp_dir;
1406 1784
1407 dbg = dwarf_begin(fd, DWARF_C_READ); 1785 dbg = dwfl_init_offline_dwarf(fd, &dwfl, &bias);
1408 if (!dbg) { 1786 if (!dbg) {
1409 pr_warning("No dwarf info found in the vmlinux - " 1787 pr_warning("No dwarf info found in the vmlinux - "
1410 "please rebuild with CONFIG_DEBUG_INFO=y.\n"); 1788 "please rebuild with CONFIG_DEBUG_INFO=y.\n");
@@ -1450,8 +1828,7 @@ int find_line_range(int fd, struct line_range *lr)
1450 } 1828 }
1451 1829
1452 pr_debug("path: %s\n", lr->path); 1830 pr_debug("path: %s\n", lr->path);
1453 dwarf_end(dbg); 1831 dwfl_end(dwfl);
1454
1455 return (ret < 0) ? ret : lf.found; 1832 return (ret < 0) ? ret : lf.found;
1456} 1833}
1457 1834
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 4507d519f183..bba69d455699 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -22,20 +22,27 @@ extern int find_probe_trace_events(int fd, struct perf_probe_event *pev,
22 int max_tevs); 22 int max_tevs);
23 23
24/* Find a perf_probe_point from debuginfo */ 24/* Find a perf_probe_point from debuginfo */
25extern int find_perf_probe_point(int fd, unsigned long addr, 25extern int find_perf_probe_point(unsigned long addr,
26 struct perf_probe_point *ppt); 26 struct perf_probe_point *ppt);
27 27
28/* Find a line range */
28extern int find_line_range(int fd, struct line_range *lr); 29extern int find_line_range(int fd, struct line_range *lr);
29 30
31/* Find available variables */
32extern int find_available_vars_at(int fd, struct perf_probe_event *pev,
33 struct variable_list **vls, int max_points,
34 bool externs);
35
30#include <dwarf.h> 36#include <dwarf.h>
31#include <libdw.h> 37#include <libdw.h>
38#include <libdwfl.h>
32#include <version.h> 39#include <version.h>
33 40
34struct probe_finder { 41struct probe_finder {
35 struct perf_probe_event *pev; /* Target probe event */ 42 struct perf_probe_event *pev; /* Target probe event */
36 struct probe_trace_event *tevs; /* Result trace events */ 43
37 int ntevs; /* Number of trace events */ 44 /* Callback when a probe point is found */
38 int max_tevs; /* Max number of trace events */ 45 int (*callback)(Dwarf_Die *sp_die, struct probe_finder *pf);
39 46
40 /* For function searching */ 47 /* For function searching */
41 int lno; /* Line number */ 48 int lno; /* Line number */
@@ -53,6 +60,22 @@ struct probe_finder {
53 struct probe_trace_arg *tvar; /* Current result variable */ 60 struct probe_trace_arg *tvar; /* Current result variable */
54}; 61};
55 62
63struct trace_event_finder {
64 struct probe_finder pf;
65 struct probe_trace_event *tevs; /* Found trace events */
66 int ntevs; /* Number of trace events */
67 int max_tevs; /* Max number of trace events */
68};
69
70struct available_var_finder {
71 struct probe_finder pf;
72 struct variable_list *vls; /* Found variable lists */
73 int nvls; /* Number of variable lists */
74 int max_vls; /* Max no. of variable lists */
75 bool externs; /* Find external vars too */
76 bool child; /* Search child scopes */
77};
78
56struct line_finder { 79struct line_finder {
57 struct line_range *lr; /* Target line range */ 80 struct line_range *lr; /* Target line range */
58 81
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c
index 6d0df809a2ed..8bc010edca25 100644
--- a/tools/perf/util/ui/browser.c
+++ b/tools/perf/util/ui/browser.c
@@ -1,4 +1,3 @@
1#include <slang.h>
2#include "libslang.h" 1#include "libslang.h"
3#include <linux/compiler.h> 2#include <linux/compiler.h>
4#include <linux/list.h> 3#include <linux/list.h>